diff --git a/ccm-core/src/main/java/org/libreccm/api/ApiConstants.java b/ccm-core/src/main/java/org/libreccm/api/ApiConstants.java new file mode 100644 index 000000000..b8e5c7d09 --- /dev/null +++ b/ccm-core/src/main/java/org/libreccm/api/ApiConstants.java @@ -0,0 +1,35 @@ +/* + * Copyright (C) 2020 LibreCCM Foundation. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, + * MA 02110-1301 USA + */ +package org.libreccm.api; + +/** + * + * @author Jens Pelzetter + */ +public final class ApiConstants { + + private ApiConstants() { + // Nothing + } + + public static final String IDENTIFIER_PREFIX_ID = "ID-"; + + public static final String IDENTIFIER_PREFIX_UUID = "UUID-"; + +} diff --git a/ccm-core/src/main/java/org/libreccm/api/Identifier.java b/ccm-core/src/main/java/org/libreccm/api/Identifier.java new file mode 100644 index 000000000..319ce1021 --- /dev/null +++ b/ccm-core/src/main/java/org/libreccm/api/Identifier.java @@ -0,0 +1,46 @@ +/* + * Copyright (C) 2020 LibreCCM Foundation. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, + * MA 02110-1301 USA + */ +package org.libreccm.api; + +/** + * + * @author Jens Pelzetter + */ +public class Identifier { + + private final IdentifierType type; + + private final String identifier; + + protected Identifier( + final IdentifierType type, final String identifier + ) { + this.type = type; + this.identifier = identifier; + } + + public IdentifierType getType() { + return type; + } + + public String getIdentifier() { + return identifier; + } + +} diff --git a/ccm-core/src/main/java/org/libreccm/api/IdentifierParser.java b/ccm-core/src/main/java/org/libreccm/api/IdentifierParser.java new file mode 100644 index 000000000..5919eea24 --- /dev/null +++ b/ccm-core/src/main/java/org/libreccm/api/IdentifierParser.java @@ -0,0 +1,51 @@ +/* + * Copyright (C) 2020 LibreCCM Foundation. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, + * MA 02110-1301 USA + */ +package org.libreccm.api; + +import java.util.Objects; + +import javax.enterprise.context.Dependent; + +/** + * + * @author Jens Pelzetter + */ +@Dependent +public class IdentifierParser { + + public Identifier parseIdentifier(final String identifierParam) { + Objects.requireNonNull(identifierParam, "identifier param is null."); + + if (identifierParam.startsWith(ApiConstants.IDENTIFIER_PREFIX_ID)) { + final String identifier = identifierParam + .substring(ApiConstants.IDENTIFIER_PREFIX_ID.length()); + return new Identifier(IdentifierType.ID, identifier); + } else if (identifierParam.startsWith( + ApiConstants.IDENTIFIER_PREFIX_UUID)) { + final String identifier = identifierParam + .substring(ApiConstants.IDENTIFIER_PREFIX_UUID.length()); + return new Identifier(IdentifierType.ID, identifier); + } else { + return new Identifier( + IdentifierType.PROPERTY, identifierParam + ); + } + } + +} diff --git a/ccm-core/src/main/java/org/libreccm/api/IdentifierType.java b/ccm-core/src/main/java/org/libreccm/api/IdentifierType.java new file mode 100644 index 000000000..eaf85737b --- /dev/null +++ b/ccm-core/src/main/java/org/libreccm/api/IdentifierType.java @@ -0,0 +1,29 @@ +/* + * Copyright (C) 2020 LibreCCM Foundation. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, + * MA 02110-1301 USA + */ +package org.libreccm.api; + +/** + * + * @author Jens Pelzetter + */ +public enum IdentifierType { + ID, + UUID, + PROPERTY +} diff --git a/ccm-core/src/main/java/org/libreccm/core/EmailAddress.java b/ccm-core/src/main/java/org/libreccm/core/EmailAddress.java index 3d012d596..c5dcfbdd6 100644 --- a/ccm-core/src/main/java/org/libreccm/core/EmailAddress.java +++ b/ccm-core/src/main/java/org/libreccm/core/EmailAddress.java @@ -18,8 +18,6 @@ */ package org.libreccm.core; -import org.hibernate.validator.constraints.Email; -import org.hibernate.validator.constraints.NotBlank; import javax.persistence.Column; import javax.persistence.Embeddable; @@ -33,6 +31,8 @@ import static org.libreccm.core.CoreConstants.CORE_XML_NS; import javax.json.Json; import javax.json.JsonObjectBuilder; +import javax.validation.constraints.Email; +import javax.validation.constraints.NotBlank; /** * An embeddable entity for storing email addresses. diff --git a/ccm-core/src/main/java/org/libreccm/ui/Message.java b/ccm-core/src/main/java/org/libreccm/ui/Message.java new file mode 100644 index 000000000..916aa2b29 --- /dev/null +++ b/ccm-core/src/main/java/org/libreccm/ui/Message.java @@ -0,0 +1,44 @@ +/* + * Copyright (C) 2020 LibreCCM Foundation. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, + * MA 02110-1301 USA + */ +package org.libreccm.ui; + +/** + * + * @author Jens Pelzetter + */ +public class Message { + + private final String message; + + private final MessageType messageType; + + public Message(String message, MessageType messageType) { + this.message = message; + this.messageType = messageType; + } + + public String getMessage() { + return message; + } + + public MessageType getMessageType() { + return messageType; + } + +} diff --git a/ccm-core/src/main/java/org/libreccm/ui/MessageType.java b/ccm-core/src/main/java/org/libreccm/ui/MessageType.java new file mode 100644 index 000000000..83f46f005 --- /dev/null +++ b/ccm-core/src/main/java/org/libreccm/ui/MessageType.java @@ -0,0 +1,36 @@ +/* + * Copyright (C) 2020 LibreCCM Foundation. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, + * MA 02110-1301 USA + */ +package org.libreccm.ui; + +/** + * + * @author Jens Pelzetter + */ +public enum MessageType { + + PRIMARY, + SECONDARY, + SUCCESS, + DANGER, + WARNING, + INFO, + LIGHT, + DARK, + +} diff --git a/ccm-core/src/main/java/org/libreccm/ui/admin/AdminMessages.java b/ccm-core/src/main/java/org/libreccm/ui/admin/AdminMessages.java index 6890af911..f0af45d4a 100644 --- a/ccm-core/src/main/java/org/libreccm/ui/admin/AdminMessages.java +++ b/ccm-core/src/main/java/org/libreccm/ui/admin/AdminMessages.java @@ -20,7 +20,9 @@ package org.libreccm.ui.admin; import org.libreccm.l10n.GlobalizationHelper; +import java.text.MessageFormat; import java.util.AbstractMap; +import java.util.List; import java.util.ResourceBundle; import java.util.Set; import java.util.stream.Collectors; @@ -43,8 +45,6 @@ public class AdminMessages extends AbstractMap { private ResourceBundle messages; - - @PostConstruct private void init() { messages = ResourceBundle.getBundle( @@ -57,21 +57,37 @@ public class AdminMessages extends AbstractMap { if (messages.containsKey(key)) { return messages.getString(key); } else { - return "???key???"; + return String.format("???%s???", key); } } - + + public String getMessage( + final String key, final List parameters + ) { + return getMessage(key, parameters.toArray()); + } + + public String getMessage( + final String key, final Object[] parameters + ) { + if (messages.containsKey(key)) { + return MessageFormat.format(messages.getString(key), parameters); + } else { + return String.format("???%s???", key); + } + } + public String get(final String key) { return getMessage(key); } - + @Override public Set> entrySet() { return messages .keySet() .stream() .collect( - Collectors.toMap(key -> key, key-> messages.getString(key)) + Collectors.toMap(key -> key, key -> messages.getString(key)) ) .entrySet(); } diff --git a/ccm-core/src/main/java/org/libreccm/ui/admin/AdminPage.java b/ccm-core/src/main/java/org/libreccm/ui/admin/AdminPage.java index 27e1ab4b4..9fcf96015 100644 --- a/ccm-core/src/main/java/org/libreccm/ui/admin/AdminPage.java +++ b/ccm-core/src/main/java/org/libreccm/ui/admin/AdminPage.java @@ -18,9 +18,10 @@ */ package org.libreccm.ui.admin; -import java.util.ResourceBundle; import java.util.Set; +import javax.mvc.MvcContext; + /** * * @author Jens Pelzetter @@ -35,14 +36,15 @@ public interface AdminPage { Set> getControllerClasses(); /** - * The entry point for the admin module. Used to generate the URL for an - * admin page in the navigation etc. For example, with the return value will - * {@code systeminformation} the generated link is - * {@code #{contextPath}/@admin/#{path}}. - * - * @return The path fragment of the entry point of the admin page/module. + * A identifier to use by {@link MvcContext#uri(java.lang.String)} to + * generate the URI of the page. The identifier has the same format as used in JavaDoc: + *
+     *     ControllerSimpleClassName#methodName
+     * 
+ * + * @return The identifier to use for generating the URL of the page */ - String getPath(); + String getUriIdentifier(); /** * Gets the resourcebundle which provides the label of the admin page. diff --git a/ccm-core/src/main/java/org/libreccm/ui/admin/AdminPageModel.java b/ccm-core/src/main/java/org/libreccm/ui/admin/AdminPageModel.java index 706fa3342..96a7899d3 100644 --- a/ccm-core/src/main/java/org/libreccm/ui/admin/AdminPageModel.java +++ b/ccm-core/src/main/java/org/libreccm/ui/admin/AdminPageModel.java @@ -24,7 +24,7 @@ package org.libreccm.ui.admin; */ public class AdminPageModel { - private String path; + private String uriIdentifier; private String label; @@ -32,19 +32,19 @@ public class AdminPageModel { private String icon; - public String getPath() { - return path; + public String getUriIdentifier() { + return uriIdentifier; } - public void setPath(String path) { - this.path = path; + public void setUriIdentifier(final String uriIdentifier) { + this.uriIdentifier = uriIdentifier; } public String getLabel() { return label; } - public void setLabel(String label) { + public void setLabel(final String label) { this.label = label; } @@ -52,7 +52,7 @@ public class AdminPageModel { return description; } - public void setDescription(String description) { + public void setDescription(final String description) { this.description = description; } @@ -60,7 +60,7 @@ public class AdminPageModel { return icon; } - public void setIcon(String icon) { + public void setIcon(final String icon) { this.icon = icon; } diff --git a/ccm-core/src/main/java/org/libreccm/ui/admin/AdminPagesModel.java b/ccm-core/src/main/java/org/libreccm/ui/admin/AdminPagesModel.java index 72f07e4df..08de0c083 100644 --- a/ccm-core/src/main/java/org/libreccm/ui/admin/AdminPagesModel.java +++ b/ccm-core/src/main/java/org/libreccm/ui/admin/AdminPagesModel.java @@ -71,7 +71,7 @@ public class AdminPagesModel { ); final AdminPageModel model = new AdminPageModel(); - model.setPath(fromAdminPage.getPath()); + model.setUriIdentifier(fromAdminPage.getUriIdentifier()); model.setLabel(labelBundle.getString(fromAdminPage.getLabelKey())); model.setDescription( descriptionBundle.getString( diff --git a/ccm-core/src/main/java/org/libreccm/ui/admin/applications/ApplicationsController.java b/ccm-core/src/main/java/org/libreccm/ui/admin/applications/ApplicationsController.java index 5245c612a..0a9eff521 100644 --- a/ccm-core/src/main/java/org/libreccm/ui/admin/applications/ApplicationsController.java +++ b/ccm-core/src/main/java/org/libreccm/ui/admin/applications/ApplicationsController.java @@ -40,7 +40,7 @@ public class ApplicationsController { @Path("/") @AuthorizationRequired @RequiresPrivilege(CoreConstants.PRIVILEGE_ADMIN) - public String getPlaceholder() { + public String getApplications() { return "org/libreccm/ui/admin/applications.xhtml"; } } diff --git a/ccm-core/src/main/java/org/libreccm/ui/admin/applications/ApplicationsPage.java b/ccm-core/src/main/java/org/libreccm/ui/admin/applications/ApplicationsPage.java index cedd9abc6..185670232 100644 --- a/ccm-core/src/main/java/org/libreccm/ui/admin/applications/ApplicationsPage.java +++ b/ccm-core/src/main/java/org/libreccm/ui/admin/applications/ApplicationsPage.java @@ -41,8 +41,10 @@ public class ApplicationsPage implements AdminPage { } @Override - public String getPath() { - return "applications"; + public String getUriIdentifier() { + return String.format( + "%s#getApplications", ApplicationsController.class.getSimpleName() + ); } @Override diff --git a/ccm-core/src/main/java/org/libreccm/ui/admin/categories/CategoriesController.java b/ccm-core/src/main/java/org/libreccm/ui/admin/categories/CategoriesController.java index e15766460..aebf65cf7 100644 --- a/ccm-core/src/main/java/org/libreccm/ui/admin/categories/CategoriesController.java +++ b/ccm-core/src/main/java/org/libreccm/ui/admin/categories/CategoriesController.java @@ -40,7 +40,7 @@ public class CategoriesController { @Path("/") @AuthorizationRequired @RequiresPrivilege(CoreConstants.PRIVILEGE_ADMIN) - public String getPlaceholder() { + public String getCategories() { return "org/libreccm/ui/admin/categories.xhtml"; } } diff --git a/ccm-core/src/main/java/org/libreccm/ui/admin/categories/CategoriesPage.java b/ccm-core/src/main/java/org/libreccm/ui/admin/categories/CategoriesPage.java index 666ac70e7..fa877b379 100644 --- a/ccm-core/src/main/java/org/libreccm/ui/admin/categories/CategoriesPage.java +++ b/ccm-core/src/main/java/org/libreccm/ui/admin/categories/CategoriesPage.java @@ -41,8 +41,10 @@ public class CategoriesPage implements AdminPage { } @Override - public String getPath() { - return "categories"; + public String getUriIdentifier() { + return String.format( + "%s#getCategories", CategoriesController.class.getSimpleName() + ); } @Override diff --git a/ccm-core/src/main/java/org/libreccm/ui/admin/configuration/ConfigurationController.java b/ccm-core/src/main/java/org/libreccm/ui/admin/configuration/ConfigurationController.java index 1e36e66c6..e36f7fdc7 100644 --- a/ccm-core/src/main/java/org/libreccm/ui/admin/configuration/ConfigurationController.java +++ b/ccm-core/src/main/java/org/libreccm/ui/admin/configuration/ConfigurationController.java @@ -40,7 +40,7 @@ public class ConfigurationController { @Path("/") @AuthorizationRequired @RequiresPrivilege(CoreConstants.PRIVILEGE_ADMIN) - public String getPlaceholder() { + public String getSettings() { return "org/libreccm/ui/admin/configuration.xhtml"; } } diff --git a/ccm-core/src/main/java/org/libreccm/ui/admin/configuration/ConfigurationPage.java b/ccm-core/src/main/java/org/libreccm/ui/admin/configuration/ConfigurationPage.java index 463c136e6..d9ebcb039 100644 --- a/ccm-core/src/main/java/org/libreccm/ui/admin/configuration/ConfigurationPage.java +++ b/ccm-core/src/main/java/org/libreccm/ui/admin/configuration/ConfigurationPage.java @@ -20,7 +20,6 @@ package org.libreccm.ui.admin.configuration; import org.libreccm.ui.admin.AdminConstants; import org.libreccm.ui.admin.AdminPage; -import org.libreccm.ui.admin.categories.CategoriesController; import java.util.HashSet; import java.util.Set; @@ -41,8 +40,10 @@ public class ConfigurationPage implements AdminPage { } @Override - public String getPath() { - return "configuration"; + public String getUriIdentifier() { + return String.format( + "%s#getSettings", ConfigurationController.class.getSimpleName() + ); } @Override diff --git a/ccm-core/src/main/java/org/libreccm/ui/admin/dashboard/DashboardController.java b/ccm-core/src/main/java/org/libreccm/ui/admin/dashboard/DashboardController.java index a3b72590b..d651b3453 100644 --- a/ccm-core/src/main/java/org/libreccm/ui/admin/dashboard/DashboardController.java +++ b/ccm-core/src/main/java/org/libreccm/ui/admin/dashboard/DashboardController.java @@ -40,7 +40,7 @@ public class DashboardController { @Path("/") @AuthorizationRequired @RequiresPrivilege(CoreConstants.PRIVILEGE_ADMIN) - public String getPlaceholder() { + public String getDashboard() { return "org/libreccm/ui/admin/dashboard.xhtml"; } } diff --git a/ccm-core/src/main/java/org/libreccm/ui/admin/dashboard/DashboardPage.java b/ccm-core/src/main/java/org/libreccm/ui/admin/dashboard/DashboardPage.java index 5620d3dd1..51276a54a 100644 --- a/ccm-core/src/main/java/org/libreccm/ui/admin/dashboard/DashboardPage.java +++ b/ccm-core/src/main/java/org/libreccm/ui/admin/dashboard/DashboardPage.java @@ -20,6 +20,7 @@ package org.libreccm.ui.admin.dashboard; import org.libreccm.ui.admin.AdminConstants; import org.libreccm.ui.admin.AdminPage; +import org.libreccm.ui.admin.configuration.ConfigurationController; import java.util.HashSet; import java.util.Set; @@ -40,8 +41,10 @@ public class DashboardPage implements AdminPage { } @Override - public String getPath() { - return "/"; + public String getUriIdentifier() { + return String.format( + "%s#getDashboard", DashboardController.class.getSimpleName() + ); } @Override diff --git a/ccm-core/src/main/java/org/libreccm/ui/admin/imexport/ImExportController.java b/ccm-core/src/main/java/org/libreccm/ui/admin/imexport/ImExportController.java index 9e2dfef7b..a89b01927 100644 --- a/ccm-core/src/main/java/org/libreccm/ui/admin/imexport/ImExportController.java +++ b/ccm-core/src/main/java/org/libreccm/ui/admin/imexport/ImExportController.java @@ -40,7 +40,7 @@ public class ImExportController { @Path("/") @AuthorizationRequired @RequiresPrivilege(CoreConstants.PRIVILEGE_ADMIN) - public String getPlaceholder() { + public String getImExportDashboard() { return "org/libreccm/ui/admin/imexport.xhtml"; } } diff --git a/ccm-core/src/main/java/org/libreccm/ui/admin/imexport/ImExportPage.java b/ccm-core/src/main/java/org/libreccm/ui/admin/imexport/ImExportPage.java index 4c758bd0e..e41b58555 100644 --- a/ccm-core/src/main/java/org/libreccm/ui/admin/imexport/ImExportPage.java +++ b/ccm-core/src/main/java/org/libreccm/ui/admin/imexport/ImExportPage.java @@ -40,8 +40,10 @@ public class ImExportPage implements AdminPage { } @Override - public String getPath() { - return "imexport"; + public String getUriIdentifier() { + return String.format( + "%s#getImExportDashboard", ImExportController.class.getSimpleName() + ); } @Override diff --git a/ccm-core/src/main/java/org/libreccm/ui/admin/sites/SitesController.java b/ccm-core/src/main/java/org/libreccm/ui/admin/sites/SitesController.java index 817821f05..e7bd0a708 100644 --- a/ccm-core/src/main/java/org/libreccm/ui/admin/sites/SitesController.java +++ b/ccm-core/src/main/java/org/libreccm/ui/admin/sites/SitesController.java @@ -40,7 +40,7 @@ public class SitesController { @Path("/") @AuthorizationRequired @RequiresPrivilege(CoreConstants.PRIVILEGE_ADMIN) - public String getPlaceholder() { + public String getSites() { return "org/libreccm/ui/admin/sites.xhtml"; } } diff --git a/ccm-core/src/main/java/org/libreccm/ui/admin/sites/SitesPage.java b/ccm-core/src/main/java/org/libreccm/ui/admin/sites/SitesPage.java index ae42934e7..a07f98a6f 100644 --- a/ccm-core/src/main/java/org/libreccm/ui/admin/sites/SitesPage.java +++ b/ccm-core/src/main/java/org/libreccm/ui/admin/sites/SitesPage.java @@ -40,8 +40,10 @@ public class SitesPage implements AdminPage { } @Override - public String getPath() { - return "sites"; + public String getUriIdentifier() { + return String.format( + "%s#getSites", SitesController.class.getSimpleName() + ); } @Override diff --git a/ccm-core/src/main/java/org/libreccm/ui/admin/systeminformation/SystemInformationPage.java b/ccm-core/src/main/java/org/libreccm/ui/admin/systeminformation/SystemInformationPage.java index 27af5ad63..bacaa0888 100644 --- a/ccm-core/src/main/java/org/libreccm/ui/admin/systeminformation/SystemInformationPage.java +++ b/ccm-core/src/main/java/org/libreccm/ui/admin/systeminformation/SystemInformationPage.java @@ -23,6 +23,7 @@ import java.util.Set; import org.libreccm.ui.admin.AdminConstants; import org.libreccm.ui.admin.AdminPage; +import org.libreccm.ui.admin.imexport.ImExportController; import javax.enterprise.context.ApplicationScoped; @@ -41,8 +42,11 @@ public class SystemInformationPage implements AdminPage { } @Override - public String getPath() { - return "systeminformation"; + public String getUriIdentifier() { + return String.format( + "%s#getSystemInformation", + SystemInformationController.class.getSimpleName() + ); } @Override diff --git a/ccm-core/src/main/java/org/libreccm/ui/admin/usersgroupsroles/GroupsController.java b/ccm-core/src/main/java/org/libreccm/ui/admin/usersgroupsroles/GroupsController.java new file mode 100644 index 000000000..5c9ddf910 --- /dev/null +++ b/ccm-core/src/main/java/org/libreccm/ui/admin/usersgroupsroles/GroupsController.java @@ -0,0 +1,47 @@ +/* + * Copyright (C) 2020 LibreCCM Foundation. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, + * MA 02110-1301 USA + */ +package org.libreccm.ui.admin.usersgroupsroles; + +import org.libreccm.core.CoreConstants; +import org.libreccm.security.AuthorizationRequired; +import org.libreccm.security.RequiresPrivilege; + +import javax.enterprise.context.RequestScoped; +import javax.mvc.Controller; +import javax.ws.rs.GET; +import javax.ws.rs.Path; + +/** + * + * @author Jens Pelzetter + */ +@RequestScoped +@Controller +@Path("/users-groups-roles/group") +public class GroupsController { + + @GET + @Path("/") + @AuthorizationRequired + @RequiresPrivilege(CoreConstants.PRIVILEGE_ADMIN) + public String getGroups() { + return "org/libreccm/ui/admin/users-groups-roles/groups.xhtml"; + } + +} diff --git a/ccm-core/src/main/java/org/libreccm/ui/admin/usersgroupsroles/PartyRoleMembership.java b/ccm-core/src/main/java/org/libreccm/ui/admin/usersgroupsroles/PartyRoleMembership.java new file mode 100644 index 000000000..46cbaeec1 --- /dev/null +++ b/ccm-core/src/main/java/org/libreccm/ui/admin/usersgroupsroles/PartyRoleMembership.java @@ -0,0 +1,74 @@ +/* + * Copyright (C) 2020 LibreCCM Foundation. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, + * MA 02110-1301 USA + */ +package org.libreccm.ui.admin.usersgroupsroles; + +import org.libreccm.security.Role; + +/** + * + * @author Jens Pelzetter + */ +public class PartyRoleMembership implements Comparable{ + + private long roleId; + + private String roleUuid; + + private String roleName; + + public PartyRoleMembership() { + // Nothing + } + + public PartyRoleMembership(final Role role) { + roleId = role.getRoleId(); + roleUuid = role.getUuid(); + roleName = role.getName(); + } + + public long getRoleId() { + return roleId; + } + + public void setRoleId(long roleId) { + this.roleId = roleId; + } + + public String getRoleUuid() { + return roleUuid; + } + + public void setRoleUuid(String roleUuid) { + this.roleUuid = roleUuid; + } + + public String getRoleName() { + return roleName; + } + + public void setRoleName(String roleName) { + this.roleName = roleName; + } + + @Override + public int compareTo(final PartyRoleMembership other) { + return roleName.compareTo(other.getRoleName()); + } + +} diff --git a/ccm-core/src/main/java/org/libreccm/ui/admin/usersgroupsroles/RolesController.java b/ccm-core/src/main/java/org/libreccm/ui/admin/usersgroupsroles/RolesController.java new file mode 100644 index 000000000..2154649eb --- /dev/null +++ b/ccm-core/src/main/java/org/libreccm/ui/admin/usersgroupsroles/RolesController.java @@ -0,0 +1,47 @@ +/* + * Copyright (C) 2020 LibreCCM Foundation. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, + * MA 02110-1301 USA + */ +package org.libreccm.ui.admin.usersgroupsroles; + +import org.libreccm.core.CoreConstants; +import org.libreccm.security.AuthorizationRequired; +import org.libreccm.security.RequiresPrivilege; + +import javax.enterprise.context.RequestScoped; +import javax.mvc.Controller; +import javax.ws.rs.GET; +import javax.ws.rs.Path; + +/** + * + * @author Jens Pelzetter + */ +@RequestScoped +@Controller +@Path("/users-groups-roles/roles") +public class RolesController { + + @GET + @Path("/") + @AuthorizationRequired + @RequiresPrivilege(CoreConstants.PRIVILEGE_ADMIN) + public String getRoles() { + return "org/libreccm/ui/admin/users-groups-roles/roles.xhtml"; + } + +} diff --git a/ccm-core/src/main/java/org/libreccm/ui/admin/usersgroupsroles/UserDetailsModel.java b/ccm-core/src/main/java/org/libreccm/ui/admin/usersgroupsroles/UserDetailsModel.java new file mode 100644 index 000000000..68b4a8a5a --- /dev/null +++ b/ccm-core/src/main/java/org/libreccm/ui/admin/usersgroupsroles/UserDetailsModel.java @@ -0,0 +1,156 @@ +/* + * Copyright (C) 2020 LibreCCM Foundation. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, + * MA 02110-1301 USA + */ +package org.libreccm.ui.admin.usersgroupsroles; + +import org.libreccm.core.EmailAddress; +import org.libreccm.security.GroupMembership; +import org.libreccm.security.RoleMembership; +import org.libreccm.security.User; +import org.libreccm.ui.Message; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; +import java.util.Objects; +import java.util.stream.Collectors; + +import javax.enterprise.context.RequestScoped; +import javax.inject.Named; +import javax.transaction.Transactional; + +/** + * + * @author Jens Pelzetter + */ +@RequestScoped +@Named("UserDetailsModel") +public class UserDetailsModel { + + private long userId; + + private String uuid; + + private String name; + + private String givenName; + + private String familyName; + + private EmailAddress primaryEmailAddress; + + private List emailAddresses; + + private boolean banned; + + private boolean passwordResetRequired; + + private List groupMemberships; + + private List roles; + + private final List messages; + + public UserDetailsModel() { + messages = new ArrayList<>(); + } + + @Transactional(Transactional.TxType.REQUIRED) + protected void setUser(final User user) { + Objects.requireNonNull(user); + + userId = user.getPartyId(); + uuid = user.getUuid(); + name = user.getName(); + givenName = user.getGivenName(); + familyName = user.getFamilyName(); + primaryEmailAddress = user.getPrimaryEmailAddress(); + // Ensure that we don't get a lazyily initalized list. + emailAddresses = user + .getEmailAddresses() + .stream() + .collect(Collectors.toList()); + banned = user.isBanned(); + passwordResetRequired = user.isPasswordResetRequired(); + groupMemberships = user + .getGroupMemberships() + .stream() + .map(GroupMembership::getGroup) + .map(UserGroupMembership::new) + .collect(Collectors.toList()); + roles = user + .getRoleMemberships() + .stream() + .map(RoleMembership::getRole) + .map(PartyRoleMembership::new) + .collect(Collectors.toList()); + } + + public List getMessages() { + return Collections.unmodifiableList(messages); + } + + public void addMessage(final Message message) { + messages.add(message); + } + + public long getUserId() { + return userId; + } + + public String getUuid() { + return uuid; + } + + public String getName() { + return name; + } + + public String getGivenName() { + return givenName; + } + + public String getFamilyName() { + return familyName; + } + + public EmailAddress getPrimaryEmailAddress() { + return primaryEmailAddress; + } + + public List getEmailAddresses() { + return Collections.unmodifiableList(emailAddresses); + } + + public boolean isBanned() { + return banned; + } + + public boolean isPasswordResetRequired() { + return passwordResetRequired; + } + + public List getGroupMemberships() { + return Collections.unmodifiableList(groupMemberships); + } + + public List getRoles() { + return Collections.unmodifiableList(roles); + } + +} diff --git a/ccm-core/src/main/java/org/libreccm/ui/admin/usersgroupsroles/UserGroupMembership.java b/ccm-core/src/main/java/org/libreccm/ui/admin/usersgroupsroles/UserGroupMembership.java new file mode 100644 index 000000000..31b48b3aa --- /dev/null +++ b/ccm-core/src/main/java/org/libreccm/ui/admin/usersgroupsroles/UserGroupMembership.java @@ -0,0 +1,74 @@ +/* + * Copyright (C) 2020 LibreCCM Foundation. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, + * MA 02110-1301 USA + */ +package org.libreccm.ui.admin.usersgroupsroles; + +import org.libreccm.security.Group; + +/** + * + * @author Jens Pelzetter + */ +public class UserGroupMembership implements Comparable { + + private long groupId; + + private String groupUuid; + + private String groupName; + + public UserGroupMembership() { + // Nothing + } + + public UserGroupMembership(final Group group) { + this.groupId = group.getPartyId(); + this.groupUuid = group.getUuid(); + this.groupName = group.getName(); + } + + public long getGroupId() { + return groupId; + } + + public void setGroupId(final long groupId) { + this.groupId = groupId; + } + + public String getGroupUuid() { + return groupUuid; + } + + public void setGroupUuid(final String groupUuid) { + this.groupUuid = groupUuid; + } + + public String getGroupName() { + return groupName; + } + + public void setGroupName(final String groupName) { + this.groupName = groupName; + } + + @Override + public int compareTo(final UserGroupMembership other) { + return groupName.compareTo(other.getGroupName()); + } + +} diff --git a/ccm-core/src/main/java/org/libreccm/ui/admin/usersgroupsroles/UsersController.java b/ccm-core/src/main/java/org/libreccm/ui/admin/usersgroupsroles/UsersController.java index ad6f27a62..3b079f3e4 100644 --- a/ccm-core/src/main/java/org/libreccm/ui/admin/usersgroupsroles/UsersController.java +++ b/ccm-core/src/main/java/org/libreccm/ui/admin/usersgroupsroles/UsersController.java @@ -18,13 +18,24 @@ */ package org.libreccm.ui.admin.usersgroupsroles; +import org.libreccm.api.Identifier; +import org.libreccm.api.IdentifierParser; import org.libreccm.core.CoreConstants; import org.libreccm.security.AuthorizationRequired; import org.libreccm.security.RequiresPrivilege; +import org.libreccm.security.User; +import org.libreccm.security.UserRepository; +import org.libreccm.ui.Message; +import org.libreccm.ui.MessageType; +import org.libreccm.ui.admin.AdminMessages; + +import java.util.Arrays; +import java.util.Optional; import javax.enterprise.context.RequestScoped; import javax.inject.Inject; import javax.mvc.Controller; +import javax.transaction.Transactional; import javax.ws.rs.DefaultValue; import javax.ws.rs.GET; import javax.ws.rs.POST; @@ -41,6 +52,18 @@ import javax.ws.rs.QueryParam; @Path("/users-groups-roles/users") public class UsersController { + @Inject + private AdminMessages adminMessages; + + @Inject + private IdentifierParser identifierParser; + + @Inject + private UserDetailsModel userDetailsModel; + + @Inject + private UserRepository userRepository; + @Inject private UsersTableModel usersTableModel; @@ -59,11 +82,45 @@ public class UsersController { @Path("/{userIdentifier}/details") @AuthorizationRequired @RequiresPrivilege(CoreConstants.PRIVILEGE_ADMIN) - public String getUser( - @PathParam("userIdentifier") final String userIdentifier + @Transactional(Transactional.TxType.REQUIRED) + public String getUserDetails( + @PathParam("userIdentifier") final String userIdentifierParam ) { + final Identifier identifier = identifierParser.parseIdentifier( + userIdentifierParam + ); + final Optional result; + switch (identifier.getType()) { + case ID: + result = userRepository.findById( + Long.parseLong(identifier.getIdentifier()) + ); + break; + case UUID: + result = userRepository.findByUuid( + identifier.getIdentifier() + ); + break; + default: + result = userRepository.findByName(identifier.getIdentifier()); + break; + } - throw new UnsupportedOperationException(); + if (result.isPresent()) { + userDetailsModel.setUser(result.get()); + return "org/libreccm/ui/admin/users-groups-roles/user-details.xhtml"; + } else { + userDetailsModel.addMessage( + new Message( + adminMessages.getMessage( + "usersgroupsroles.users.not_found.message", + Arrays.asList(userIdentifierParam) + ), + MessageType.WARNING + ) + ); + return "org/libreccm/ui/admin/users-groups-roles/user-not-found.xhtml"; + } } @POST diff --git a/ccm-core/src/main/java/org/libreccm/ui/admin/usersgroupsroles/UsersGroupsRolesController.java b/ccm-core/src/main/java/org/libreccm/ui/admin/usersgroupsroles/UsersGroupsRolesController.java index a61c9f4b2..5011f27a1 100644 --- a/ccm-core/src/main/java/org/libreccm/ui/admin/usersgroupsroles/UsersGroupsRolesController.java +++ b/ccm-core/src/main/java/org/libreccm/ui/admin/usersgroupsroles/UsersGroupsRolesController.java @@ -36,7 +36,6 @@ import javax.ws.rs.Path; @Path("/users-groups-roles") public class UsersGroupsRolesController { - @GET @Path("/") @AuthorizationRequired @@ -45,23 +44,4 @@ public class UsersGroupsRolesController { return "org/libreccm/ui/admin/users-groups-roles/overview.xhtml"; } - @GET - @Path("/groups") - @AuthorizationRequired - @RequiresPrivilege(CoreConstants.PRIVILEGE_ADMIN) - public String getGroups() { - return "org/libreccm/ui/admin/users-groups-roles/groups.xhtml"; - } - - @GET - @Path("/roles") - @AuthorizationRequired - @RequiresPrivilege(CoreConstants.PRIVILEGE_ADMIN) - public String getRoles() { - return "org/libreccm/ui/admin/users-groups-roles/roles.xhtml"; - } - - - - } diff --git a/ccm-core/src/main/java/org/libreccm/ui/admin/usersgroupsroles/UsersGroupsRolesPage.java b/ccm-core/src/main/java/org/libreccm/ui/admin/usersgroupsroles/UsersGroupsRolesPage.java index 4212574cb..bf32b3afd 100644 --- a/ccm-core/src/main/java/org/libreccm/ui/admin/usersgroupsroles/UsersGroupsRolesPage.java +++ b/ccm-core/src/main/java/org/libreccm/ui/admin/usersgroupsroles/UsersGroupsRolesPage.java @@ -32,17 +32,23 @@ import javax.enterprise.context.ApplicationScoped; */ @ApplicationScoped public class UsersGroupsRolesPage implements AdminPage { - @Override + + @Override public Set> getControllerClasses() { final Set> classes = new HashSet<>(); classes.add(UsersGroupsRolesController.class); + classes.add(GroupsController.class); + classes.add(RolesController.class); classes.add(UsersController.class); return classes; } @Override - public String getPath() { - return "users-groups-roles"; + public String getUriIdentifier() { + return String.format( + "%s#getOverview", + UsersGroupsRolesController.class.getSimpleName() + ); } @Override @@ -57,7 +63,7 @@ public class UsersGroupsRolesPage implements AdminPage { @Override public String getDescriptionBundle() { - return AdminConstants.ADMIN_BUNDLE; + return AdminConstants.ADMIN_BUNDLE; } @Override @@ -74,4 +80,5 @@ public class UsersGroupsRolesPage implements AdminPage { public int getPosition() { return 10; } + } diff --git a/ccm-core/src/main/resources/WEB-INF/views/org/libreccm/ui/admin/ccm-admin.xhtml b/ccm-core/src/main/resources/WEB-INF/views/org/libreccm/ui/admin/ccm-admin.xhtml index cd0d52d15..705e1dc97 100644 --- a/ccm-core/src/main/resources/WEB-INF/views/org/libreccm/ui/admin/ccm-admin.xhtml +++ b/ccm-core/src/main/resources/WEB-INF/views/org/libreccm/ui/admin/ccm-admin.xhtml @@ -29,8 +29,8 @@