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
new file mode 100644
index 000000000..c51537c66
--- /dev/null
+++ b/ccm-core/src/main/java/org/libreccm/ui/admin/categories/CategoriesController.java
@@ -0,0 +1,155 @@
+/*
+ * 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.categories;
+
+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.POST;
+import javax.ws.rs.Path;
+import javax.ws.rs.PathParam;
+
+/**
+ *
+ * @author Jens Pelzetter
+ */
+@RequestScoped
+@Controller
+@Path("/categorymanager/categories")
+public class CategoriesController {
+
+ @GET
+ @Path("/{categoryIdentifier}")
+ @AuthorizationRequired
+ @RequiresPrivilege(CoreConstants.PRIVILEGE_ADMIN)
+ public String getCategory(
+ @PathParam("categoryIdentifier") final String categoryIdentifier
+ ) {
+ throw new UnsupportedOperationException();
+ }
+
+ @GET
+ @Path("/{categoryIdentifier}/edit")
+ @AuthorizationRequired
+ @RequiresPrivilege(CoreConstants.PRIVILEGE_ADMIN)
+ public String editCategory(
+ @PathParam("categoryIdentifier") final String categoryIdentifier
+ ) {
+ throw new UnsupportedOperationException();
+ }
+
+ @GET
+ @Path("/{categoryIdentifier}/subcategories/new")
+ @AuthorizationRequired
+ @RequiresPrivilege(CoreConstants.PRIVILEGE_ADMIN)
+ public String newSubCategory(
+ @PathParam("categoryIdentifier") final String categoryIdentifier
+ ) {
+ throw new UnsupportedOperationException();
+ }
+
+ @POST
+ @Path("/{categoryIdentifier}/subcategories/move")
+ @AuthorizationRequired
+ @RequiresPrivilege(CoreConstants.PRIVILEGE_ADMIN)
+ public String moveSubCategory(
+ @PathParam("categoryIdentifier") final String categoryIdentifier
+ ) {
+ throw new UnsupportedOperationException();
+ }
+
+ @POST
+ @Path("/{categoryIdentifier}/subcategories/remove")
+ @AuthorizationRequired
+ @RequiresPrivilege(CoreConstants.PRIVILEGE_ADMIN)
+ public String removeSubCategory(
+ @PathParam("categoryIdentifier") final String categoryIdentifier
+ ) {
+ throw new UnsupportedOperationException();
+ }
+
+ @POST
+ @Path("/{categoryIdentifier}/title/add")
+ @AuthorizationRequired
+ public String addTitle(
+ @PathParam("categorySystemIdentifier")
+ final String categorySystemIdentifier
+ ) {
+ throw new UnsupportedOperationException();
+ }
+
+ @POST
+ @Path("/{categoryIdentifier}/title/${locale}/edit")
+ @AuthorizationRequired
+ public String editTitle(
+ @PathParam("categorySystemIdentifier")
+ final String categorySystemIdentifier,
+ @PathParam("locale") final String localeParam
+ ) {
+ throw new UnsupportedOperationException();
+ }
+
+ @POST
+ @Path("/{categoryIdentifier}/title/${locale}/remove")
+ @AuthorizationRequired
+ public String removeTitle(
+ @PathParam("categorySystemIdentifier")
+ final String categorySystemIdentifier,
+ @PathParam("locale") final String localeParam
+ ) {
+ throw new UnsupportedOperationException();
+ }
+
+ @POST
+ @Path("/{categoryIdentifier}description/add")
+ @AuthorizationRequired
+ public String addDescription(
+ @PathParam("categorySystemIdentifier")
+ final String categorySystemIdentifier
+ ) {
+ throw new UnsupportedOperationException();
+ }
+
+ @POST
+ @Path("/{categoryIdentifier}/description/${locale}/edit")
+ @AuthorizationRequired
+ public String editDescription(
+ @PathParam("categorySystemIdentifier")
+ final String categorySystemIdentifier,
+ @PathParam("locale") final String localeParam
+ ) {
+ throw new UnsupportedOperationException();
+ }
+
+ @POST
+ @Path("/{categoryIdentifier}/description/${locale}/remove")
+ @AuthorizationRequired
+ public String removeDescription(
+ @PathParam("categorySystemIdentifier")
+ final String categorySystemIdentifier,
+ @PathParam("locale") final String localeParam
+ ) {
+ throw new UnsupportedOperationException();
+ }
+
+}
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 d9dba20df..150bb5d73 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
@@ -38,6 +38,8 @@ public class CategoriesPage implements AdminPage {
final Set> classes = new HashSet<>();
classes.add(CategorySystemsController.class);
classes.add(CategorySystemFormController.class);
+ classes.add(CategoriesController.class);
+ classes.add(CategoryFormController.class);
return classes;
}
diff --git a/ccm-core/src/main/java/org/libreccm/ui/admin/categories/CategoryFormController.java b/ccm-core/src/main/java/org/libreccm/ui/admin/categories/CategoryFormController.java
new file mode 100644
index 000000000..7bac08a5d
--- /dev/null
+++ b/ccm-core/src/main/java/org/libreccm/ui/admin/categories/CategoryFormController.java
@@ -0,0 +1,58 @@
+/*
+ * 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.categories;
+
+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.transaction.Transactional;
+import javax.ws.rs.POST;
+import javax.ws.rs.Path;
+
+/**
+ *
+ * @author Jens Pelzetter
+ */
+@RequestScoped
+@Controller
+@Path("/categorymanager/categories")
+public class CategoryFormController {
+
+ @POST
+ @Path("/new")
+ @AuthorizationRequired
+ @RequiresPrivilege(CoreConstants.PRIVILEGE_ADMIN)
+ @Transactional(Transactional.TxType.REQUIRED)
+ public String createCategory() {
+ throw new UnsupportedOperationException();
+ }
+
+ @POST
+ @Path("/{categoryIdentifier}/edit")
+ @AuthorizationRequired
+ @RequiresPrivilege(CoreConstants.PRIVILEGE_ADMIN)
+ @Transactional(Transactional.TxType.REQUIRED)
+ public String updateCategory() {
+ throw new UnsupportedOperationException();
+ }
+
+}
diff --git a/ccm-core/src/main/java/org/libreccm/ui/admin/categories/CategorySystemDetailsModel.java b/ccm-core/src/main/java/org/libreccm/ui/admin/categories/CategorySystemDetailsModel.java
new file mode 100644
index 000000000..51b03d8a3
--- /dev/null
+++ b/ccm-core/src/main/java/org/libreccm/ui/admin/categories/CategorySystemDetailsModel.java
@@ -0,0 +1,151 @@
+/*
+ * 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.categories;
+
+import org.libreccm.categorization.Domain;
+import org.libreccm.categorization.DomainOwnership;
+import org.libreccm.ui.Message;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+import java.util.Map;
+import java.util.Objects;
+import java.util.stream.Collectors;
+
+import javax.transaction.Transactional;
+
+/**
+ *
+ * @author Jens Pelzetter
+ */
+public class CategorySystemDetailsModel {
+
+ private long categorySystemId;
+
+ private String uuid;
+
+ private String domainKey;
+
+ private String uri;
+
+ private Map title;
+
+ private Map description;
+
+ private List owners;
+
+ private final List messages;
+
+ public CategorySystemDetailsModel() {
+ messages = new ArrayList<>();
+ }
+
+ public long getCategorySystemId() {
+ return categorySystemId;
+ }
+
+ public String getUuid() {
+ return uuid;
+ }
+
+ public String getDomainKey() {
+ return domainKey;
+ }
+
+ public String getUri() {
+ return uri;
+ }
+
+ public Map getTitle() {
+ return Collections.unmodifiableMap(title);
+ }
+
+ public Map getDescription() {
+ return Collections.unmodifiableMap(description);
+ }
+
+ public List getOwners() {
+ return Collections.unmodifiableList(owners);
+ }
+
+ @Transactional(Transactional.TxType.REQUIRED)
+ protected void setCategorySystem(final Domain domain) {
+ Objects.requireNonNull(domain);
+
+ categorySystemId = domain.getObjectId();
+ uuid = domain.getUuid();
+ domainKey = domain.getDomainKey();
+ uri = domain.getUri();
+ title = domain
+ .getTitle()
+ .getValues()
+ .entrySet()
+ .stream()
+ .collect(
+ Collectors.toMap(
+ entry -> entry.getKey().toString(),
+ entry -> entry.getValue()
+ )
+ );
+ description = domain
+ .getDescription()
+ .getValues()
+ .entrySet()
+ .stream()
+ .collect(
+ Collectors.toMap(
+ entry -> entry.getKey().toString(),
+ entry -> entry.getValue()
+ )
+ );
+
+ owners = domain
+ .getOwners()
+ .stream()
+ .map(this::buildOwnerRow)
+ .sorted()
+ .collect(Collectors.toList());
+ }
+
+ public List getMessages() {
+ return Collections.unmodifiableList(messages);
+ }
+
+ public void addMessage(final Message message) {
+ messages.add(message);
+ }
+
+
+
+
+ private CategorySystemOwnerRow buildOwnerRow(
+ final DomainOwnership ownership
+ ) {
+ final CategorySystemOwnerRow ownerRow = new CategorySystemOwnerRow();
+ ownerRow.setOwnershipId(ownership.getOwnershipId());
+ ownerRow.setUuid(ownership.getUuid());
+ ownerRow.setContext(ownership.getContext());
+ ownerRow.setOwnerOrder(ownership.getOwnerOrder());
+ ownerRow.setOwnerAppName(ownership.getOwner().getDisplayName());
+
+ return ownerRow;
+ }
+
+}
diff --git a/ccm-core/src/main/java/org/libreccm/ui/admin/categories/CategorySystemFormController.java b/ccm-core/src/main/java/org/libreccm/ui/admin/categories/CategorySystemFormController.java
index 179f25fe2..d45df8c31 100644
--- a/ccm-core/src/main/java/org/libreccm/ui/admin/categories/CategorySystemFormController.java
+++ b/ccm-core/src/main/java/org/libreccm/ui/admin/categories/CategorySystemFormController.java
@@ -33,7 +33,7 @@ import javax.ws.rs.Path;
* @author Jens Pelzetter
*/
@Controller
-@Path("/categorysystems")
+@Path("/categorymanager/categorysystems")
@RequestScoped
public class CategorySystemFormController {
diff --git a/ccm-core/src/main/java/org/libreccm/ui/admin/categories/CategorySystemOwnerRow.java b/ccm-core/src/main/java/org/libreccm/ui/admin/categories/CategorySystemOwnerRow.java
new file mode 100644
index 000000000..a7ac37117
--- /dev/null
+++ b/ccm-core/src/main/java/org/libreccm/ui/admin/categories/CategorySystemOwnerRow.java
@@ -0,0 +1,83 @@
+/*
+ * 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.categories;
+
+/**
+ *
+ * @author Jens Pelzetter
+ */
+public class CategorySystemOwnerRow
+ implements Comparable{
+
+ private long ownershipId;
+
+ private String uuid;
+
+ private String ownerAppName;
+
+ private String context;
+
+ private long ownerOrder;
+
+ public long getOwnershipId() {
+ return ownershipId;
+ }
+
+ void setOwnershipId(final long ownershipId) {
+ this.ownershipId = ownershipId;
+ }
+
+ public String getUuid() {
+ return uuid;
+ }
+
+ void setUuid(final String uuid) {
+ this.uuid = uuid;
+ }
+
+ public String getOwnerAppName() {
+ return ownerAppName;
+ }
+
+ void setOwnerAppName(final String ownerAppName) {
+ this.ownerAppName = ownerAppName;
+ }
+
+ public String getContext() {
+ return context;
+ }
+
+ void setContext(final String context) {
+ this.context = context;
+ }
+
+ public long getOwnerOrder() {
+ return ownerOrder;
+ }
+
+ void setOwnerOrder(final long ownerOrder) {
+ this.ownerOrder = ownerOrder;
+ }
+
+ @Override
+ public int compareTo(final CategorySystemOwnerRow other) {
+ return Long.compare(ownerOrder, other.getOwnerOrder());
+ }
+
+}
diff --git a/ccm-core/src/main/java/org/libreccm/ui/admin/categories/CategorySystemTableRow.java b/ccm-core/src/main/java/org/libreccm/ui/admin/categories/CategorySystemTableRow.java
new file mode 100644
index 000000000..6a6839eb9
--- /dev/null
+++ b/ccm-core/src/main/java/org/libreccm/ui/admin/categories/CategorySystemTableRow.java
@@ -0,0 +1,113 @@
+/*
+ * 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.categories;
+
+import java.util.Collections;
+import java.util.Date;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Objects;
+
+/**
+ *
+ * @author Jens Pelzetter
+ */
+public class CategorySystemTableRow implements Comparable{
+
+ private long domainId;
+
+ private String domainKey;
+
+ private String uri;
+
+ private Map title;
+
+ private String version;
+
+ private String released;
+
+ public long getDomainId() {
+ return domainId;
+ }
+
+ void setDomainId(final long domainId) {
+ this.domainId = domainId;
+ }
+
+ public String getDomainKey() {
+ return domainKey;
+ }
+
+ void setDomainKey(final String domainKey) {
+ this.domainKey = domainKey;
+ }
+
+ public String getUri() {
+ return uri;
+ }
+
+ void setUri(final String uri) {
+ this.uri = uri;
+ }
+
+ public Map getTitle() {
+ return Collections.unmodifiableMap(title);
+ }
+
+ void setTitle(final Map title) {
+ this.title = new HashMap<>(title);
+ }
+
+ public String getVersion() {
+ return version;
+ }
+
+ void setVersion(final String version) {
+ this.version = version;
+ }
+
+ public String getReleased() {
+ return released;
+ }
+
+ void setReleased(final String released) {
+ this.released = released;
+ }
+
+ @Override
+ public int compareTo(final CategorySystemTableRow other) {
+ int result;
+ result = Objects.compare(
+ domainKey, other.getDomainKey(), String::compareTo
+ );
+
+ if (result == 0) {
+ result = Objects.compare(uri, uri, String::compareTo);
+ }
+
+ if (result == 0) {
+ result = Objects.compare(
+ domainId, other.getDomainId(), Long::compare
+ );
+ }
+
+ return result;
+ }
+
+}
diff --git a/ccm-core/src/main/java/org/libreccm/ui/admin/categories/CategorySystemsController.java b/ccm-core/src/main/java/org/libreccm/ui/admin/categories/CategorySystemsController.java
index c324456b6..d0874747f 100644
--- a/ccm-core/src/main/java/org/libreccm/ui/admin/categories/CategorySystemsController.java
+++ b/ccm-core/src/main/java/org/libreccm/ui/admin/categories/CategorySystemsController.java
@@ -18,12 +18,31 @@
*/
package org.libreccm.ui.admin.categories;
+import org.libreccm.api.Identifier;
+import org.libreccm.api.IdentifierParser;
+import org.libreccm.categorization.Domain;
+import org.libreccm.categorization.DomainManager;
+import org.libreccm.categorization.DomainRepository;
import org.libreccm.core.CoreConstants;
import org.libreccm.security.AuthorizationRequired;
import org.libreccm.security.RequiresPrivilege;
+import org.libreccm.ui.Message;
+import org.libreccm.ui.MessageType;
+import org.libreccm.ui.admin.AdminMessages;
+import org.libreccm.web.ApplicationRepository;
+import org.libreccm.web.CcmApplication;
+
+import java.util.Arrays;
+import java.util.Locale;
+import java.util.Objects;
+import java.util.Optional;
import javax.enterprise.context.RequestScoped;
+import javax.inject.Inject;
import javax.mvc.Controller;
+import javax.mvc.Models;
+import javax.transaction.Transactional;
+import javax.ws.rs.FormParam;
import javax.ws.rs.GET;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
@@ -38,6 +57,27 @@ import javax.ws.rs.PathParam;
@Path("/categorymanager")
public class CategorySystemsController {
+ @Inject
+ private AdminMessages adminMessages;
+
+ @Inject
+ private CategorySystemDetailsModel categorySystemDetailsModel;
+
+ @Inject
+ private ApplicationRepository applicationRepository;
+
+ @Inject
+ private DomainManager domainManager;
+
+ @Inject
+ private DomainRepository domainRepository;
+
+ @Inject
+ private IdentifierParser identifierParser;
+
+ @Inject
+ private Models models;
+
@GET
@Path("/")
@AuthorizationRequired
@@ -51,7 +91,6 @@ public class CategorySystemsController {
@AuthorizationRequired
@RequiresPrivilege(CoreConstants.PRIVILEGE_ADMIN)
public String getCategorySystems() {
- // ToDo
return "org/libreccm/ui/admin/categories/categorysystems.xhtml";
}
@@ -59,21 +98,56 @@ public class CategorySystemsController {
@Path("/categorysystems/{categorySystemIdentifier}/details")
@AuthorizationRequired
@RequiresPrivilege(CoreConstants.PRIVILEGE_ADMIN)
- public String getCategorySystem(
+ @Transactional(Transactional.TxType.REQUIRED)
+ public String getCategorySystemDetails(
@PathParam("categorySystemIdentifier")
final String categorySystemIdentifier
) {
- // ToDo
- return "org/libreccm/ui/admin/categories/categorysystem-details.xhtml";
+ final Identifier identifier = identifierParser.parseIdentifier(
+ categorySystemIdentifier
+ );
+ final Optional result;
+ switch (identifier.getType()) {
+ case ID:
+ result = domainRepository.findById(
+ Long.parseLong(identifier.getIdentifier()
+ )
+ );
+ break;
+ case UUID:
+ result = domainRepository.findByUuid(
+ identifier.getIdentifier()
+ );
+ break;
+ default:
+ result = domainRepository.findByDomainKey(
+ identifier.getIdentifier()
+ );
+ break;
+ }
+
+ if (result.isPresent()) {
+ categorySystemDetailsModel.setCategorySystem(result.get());
+ return "org/libreccm/ui/admin/categories/categorysystem-details.xhtml";
+ } else {
+ categorySystemDetailsModel.addMessage(
+ new Message(
+ adminMessages.getMessage(
+ "categorysystems.not_found.message",
+ Arrays.asList(categorySystemIdentifier)
+ ),
+ MessageType.WARNING
+ )
+ );
+ return "org/libreccm/ui/admin/categories/categorysystem-not-found.xhtml";
+ }
}
@GET
@Path("/categorysystems/new")
@AuthorizationRequired
@RequiresPrivilege(CoreConstants.PRIVILEGE_ADMIN)
- public String newCategorySystem(
- ) {
- // ToDo
+ public String newCategorySystem() {
return "org/libreccm/ui/admin/categories/categorysystem-form.xhtml";
}
@@ -81,54 +155,566 @@ public class CategorySystemsController {
@Path("/categorysystems/{categorySystemIdentifier}/edit")
@AuthorizationRequired
@RequiresPrivilege(CoreConstants.PRIVILEGE_ADMIN)
+ @Transactional(Transactional.TxType.REQUIRED)
public String editCategorySystem(
@PathParam("categorySystemIdentifier")
final String categorySystemIdentifier
) {
- // ToDo
- return "org/libreccm/ui/admin/categories/categorysystem-form.xhtml";
+ final Identifier identifier = identifierParser.parseIdentifier(
+ categorySystemIdentifier
+ );
+ final Optional result;
+ switch (identifier.getType()) {
+ case ID:
+ result = domainRepository.findById(
+ Long.parseLong(identifier.getIdentifier()
+ )
+ );
+ break;
+ case UUID:
+ result = domainRepository.findByUuid(
+ identifier.getIdentifier()
+ );
+ break;
+ default:
+ result = domainRepository.findByDomainKey(
+ identifier.getIdentifier()
+ );
+ break;
+ }
+
+ if (result.isPresent()) {
+ categorySystemDetailsModel.setCategorySystem(result.get());
+ return "org/libreccm/ui/admin/categories/categorysystem-form.xhtml";
+ } else {
+ categorySystemDetailsModel.addMessage(
+ new Message(
+ adminMessages.getMessage(
+ "categorysystems.not_found.message",
+ Arrays.asList(categorySystemIdentifier)
+ ),
+ MessageType.WARNING
+ )
+ );
+ return "org/libreccm/ui/admin/categories/categorysystem-not-found.xhtml";
+ }
}
@POST
@Path("/categorysystems/{categorySystemIdentifier}/delete")
@AuthorizationRequired
@RequiresPrivilege(CoreConstants.PRIVILEGE_ADMIN)
+ @Transactional(Transactional.TxType.REQUIRED)
public String deleteCategorySystem(
@PathParam("categorySystemIdentifier")
- final String categorySystemIdentifier
+ final String categorySystemIdentifier,
+ @FormParam("confirmed") final String confirmed
) {
- // ToDo
+ if (Objects.equals(confirmed, "true")) {
+ final Identifier identifier = identifierParser.parseIdentifier(
+ categorySystemIdentifier
+ );
+ final Optional result;
+ switch (identifier.getType()) {
+ case ID:
+ result = domainRepository.findById(
+ Long.parseLong(identifier.getIdentifier()
+ )
+ );
+ break;
+ case UUID:
+ result = domainRepository.findByUuid(
+ identifier.getIdentifier()
+ );
+ break;
+ default:
+ result = domainRepository.findByDomainKey(
+ identifier.getIdentifier()
+ );
+ break;
+ }
+
+ if (result.isPresent()) {
+ domainRepository.delete(result.get());
+ } else {
+ categorySystemDetailsModel.addMessage(
+ new Message(
+ adminMessages.getMessage(
+ "categorysystems.not_found.message",
+ Arrays.asList(categorySystemIdentifier)
+ ),
+ MessageType.WARNING
+ )
+ );
+ return "org/libreccm/ui/admin/categories/categorysystem-not-found.xhtml";
+ }
+ }
return "redirect:categorymanager/categorysystems";
}
-
+
+ @POST
+ @Path("/categorysystems/{categorySystemIdentifier}/title/add")
+ @AuthorizationRequired
+ @Transactional(Transactional.TxType.REQUIRED)
+ public String addTitle(
+ @PathParam("categorySystemIdentifier")
+ final String categorySystemIdentifier,
+ @FormParam("locale") final String localeParam,
+ @FormParam("value") final String value
+ ) {
+ final Identifier identifier = identifierParser.parseIdentifier(
+ categorySystemIdentifier
+ );
+ final Optional result;
+ switch (identifier.getType()) {
+ case ID:
+ result = domainRepository.findById(
+ Long.parseLong(identifier.getIdentifier()
+ )
+ );
+ break;
+ case UUID:
+ result = domainRepository.findByUuid(
+ identifier.getIdentifier()
+ );
+ break;
+ default:
+ result = domainRepository.findByDomainKey(
+ identifier.getIdentifier()
+ );
+ break;
+ }
+
+ if (result.isPresent()) {
+ final Domain domain = result.get();
+
+ final Locale locale = new Locale(localeParam);
+ domain.getTitle().addValue(locale, value);
+ categorySystemDetailsModel.setCategorySystem(domain);
+ return "org/libreccm/ui/admin/categories/categorysystem-form.xhtml";
+ } else {
+ categorySystemDetailsModel.addMessage(
+ new Message(
+ adminMessages.getMessage(
+ "categorysystems.not_found.message",
+ Arrays.asList(categorySystemIdentifier)
+ ),
+ MessageType.WARNING
+ )
+ );
+ return "org/libreccm/ui/admin/categories/categorysystem-not-found.xhtml";
+ }
+ }
+
+ @POST
+ @Path("/categorysystems/{categorySystemIdentifier}/title/${locale}/edit")
+ @AuthorizationRequired
+ public String editTitle(
+ @PathParam("categorySystemIdentifier")
+ final String categorySystemIdentifier,
+ @PathParam("locale") final String localeParam,
+ @FormParam("value") final String value
+ ) {
+ final Identifier identifier = identifierParser.parseIdentifier(
+ categorySystemIdentifier
+ );
+ final Optional result;
+ switch (identifier.getType()) {
+ case ID:
+ result = domainRepository.findById(
+ Long.parseLong(identifier.getIdentifier()
+ )
+ );
+ break;
+ case UUID:
+ result = domainRepository.findByUuid(
+ identifier.getIdentifier()
+ );
+ break;
+ default:
+ result = domainRepository.findByDomainKey(
+ identifier.getIdentifier()
+ );
+ break;
+ }
+
+ if (result.isPresent()) {
+ final Domain domain = result.get();
+
+ final Locale locale = new Locale(localeParam);
+ domain.getTitle().addValue(locale, value);
+ categorySystemDetailsModel.setCategorySystem(domain);
+ return "org/libreccm/ui/admin/categories/categorysystem-form.xhtml";
+ } else {
+ categorySystemDetailsModel.addMessage(
+ new Message(
+ adminMessages.getMessage(
+ "categorysystems.not_found.message",
+ Arrays.asList(categorySystemIdentifier)
+ ),
+ MessageType.WARNING
+ )
+ );
+ return "org/libreccm/ui/admin/categories/categorysystem-not-found.xhtml";
+ }
+ }
+
+ @POST
+ @Path("/categorysystems/{categorySystemIdentifier}/title/${locale}/remove")
+ @AuthorizationRequired
+ public String removeTitle(
+ @PathParam("categorySystemIdentifier")
+ final String categorySystemIdentifier,
+ @PathParam("locale") final String localeParam
+ ) {
+ final Identifier identifier = identifierParser.parseIdentifier(
+ categorySystemIdentifier
+ );
+ final Optional result;
+ switch (identifier.getType()) {
+ case ID:
+ result = domainRepository.findById(
+ Long.parseLong(identifier.getIdentifier()
+ )
+ );
+ break;
+ case UUID:
+ result = domainRepository.findByUuid(
+ identifier.getIdentifier()
+ );
+ break;
+ default:
+ result = domainRepository.findByDomainKey(
+ identifier.getIdentifier()
+ );
+ break;
+ }
+
+ if (result.isPresent()) {
+ final Domain domain = result.get();
+
+ final Locale locale = new Locale(localeParam);
+ domain.getTitle().removeValue(locale);
+ categorySystemDetailsModel.setCategorySystem(domain);
+ return "org/libreccm/ui/admin/categories/categorysystem-form.xhtml";
+ } else {
+ categorySystemDetailsModel.addMessage(
+ new Message(
+ adminMessages.getMessage(
+ "categorysystems.not_found.message",
+ Arrays.asList(categorySystemIdentifier)
+ ),
+ MessageType.WARNING
+ )
+ );
+ return "org/libreccm/ui/admin/categories/categorysystem-not-found.xhtml";
+ }
+ }
+
+ @POST
+ @Path("/categorysystems/{categorySystemIdentifier}/description/add")
+ @AuthorizationRequired
+ public String addDescription(
+ @PathParam("categorySystemIdentifier")
+ final String categorySystemIdentifier,
+ @FormParam("locale") final String localeParam,
+ @FormParam("value") final String value
+ ) {
+ final Identifier identifier = identifierParser.parseIdentifier(
+ categorySystemIdentifier
+ );
+ final Optional result;
+ switch (identifier.getType()) {
+ case ID:
+ result = domainRepository.findById(
+ Long.parseLong(identifier.getIdentifier()
+ )
+ );
+ break;
+ case UUID:
+ result = domainRepository.findByUuid(
+ identifier.getIdentifier()
+ );
+ break;
+ default:
+ result = domainRepository.findByDomainKey(
+ identifier.getIdentifier()
+ );
+ break;
+ }
+
+ if (result.isPresent()) {
+ final Domain domain = result.get();
+
+ final Locale locale = new Locale(localeParam);
+ domain.getDescription().addValue(locale, value);
+ categorySystemDetailsModel.setCategorySystem(domain);
+ return "org/libreccm/ui/admin/categories/categorysystem-form.xhtml";
+ } else {
+ categorySystemDetailsModel.addMessage(
+ new Message(
+ adminMessages.getMessage(
+ "categorysystems.not_found.message",
+ Arrays.asList(categorySystemIdentifier)
+ ),
+ MessageType.WARNING
+ )
+ );
+ return "org/libreccm/ui/admin/categories/categorysystem-not-found.xhtml";
+ }
+ }
+
+ @POST
+ @Path(
+ "/categorysystems/{categorySystemIdentifier}/description/${locale}/edit")
+ @AuthorizationRequired
+ public String editDescription(
+ @PathParam("categorySystemIdentifier")
+ final String categorySystemIdentifier,
+ @PathParam("locale") final String localeParam,
+ @FormParam("value") final String value
+ ) {
+ final Identifier identifier = identifierParser.parseIdentifier(
+ categorySystemIdentifier
+ );
+ final Optional result;
+ switch (identifier.getType()) {
+ case ID:
+ result = domainRepository.findById(
+ Long.parseLong(identifier.getIdentifier()
+ )
+ );
+ break;
+ case UUID:
+ result = domainRepository.findByUuid(
+ identifier.getIdentifier()
+ );
+ break;
+ default:
+ result = domainRepository.findByDomainKey(
+ identifier.getIdentifier()
+ );
+ break;
+ }
+
+ if (result.isPresent()) {
+ final Domain domain = result.get();
+
+ final Locale locale = new Locale(localeParam);
+ domain.getDescription().addValue(locale, value);
+ categorySystemDetailsModel.setCategorySystem(domain);
+ return "org/libreccm/ui/admin/categories/categorysystem-form.xhtml";
+ } else {
+ categorySystemDetailsModel.addMessage(
+ new Message(
+ adminMessages.getMessage(
+ "categorysystems.not_found.message",
+ Arrays.asList(categorySystemIdentifier)
+ ),
+ MessageType.WARNING
+ )
+ );
+ return "org/libreccm/ui/admin/categories/categorysystem-not-found.xhtml";
+ }
+ }
+
+ @POST
+ @Path(
+ "/categorysystems/{categorySystemIdentifier}/description/${locale}/remove")
+ @AuthorizationRequired
+ public String removeDescription(
+ @PathParam("categorySystemIdentifier")
+ final String categorySystemIdentifier,
+ @PathParam("locale") final String localeParam
+ ) {
+ final Identifier identifier = identifierParser.parseIdentifier(
+ categorySystemIdentifier
+ );
+ final Optional result;
+ switch (identifier.getType()) {
+ case ID:
+ result = domainRepository.findById(
+ Long.parseLong(identifier.getIdentifier()
+ )
+ );
+ break;
+ case UUID:
+ result = domainRepository.findByUuid(
+ identifier.getIdentifier()
+ );
+ break;
+ default:
+ result = domainRepository.findByDomainKey(
+ identifier.getIdentifier()
+ );
+ break;
+ }
+
+ if (result.isPresent()) {
+ final Domain domain = result.get();
+
+ final Locale locale = new Locale(localeParam);
+ domain.getDescription().removeValue(locale);
+ categorySystemDetailsModel.setCategorySystem(domain);
+ return "org/libreccm/ui/admin/categories/categorysystem-form.xhtml";
+ } else {
+ categorySystemDetailsModel.addMessage(
+ new Message(
+ adminMessages.getMessage(
+ "categorysystems.not_found.message",
+ Arrays.asList(categorySystemIdentifier)
+ ),
+ MessageType.WARNING
+ )
+ );
+ return "org/libreccm/ui/admin/categories/categorysystem-not-found.xhtml";
+ }
+ }
+
@POST
@Path("/categorysystems/{categorySystemIdentifier}/owners/add")
@AuthorizationRequired
@RequiresPrivilege(CoreConstants.PRIVILEGE_ADMIN)
public String addOwner(
@PathParam("categorySystemIdentifier")
- final String categorySystemIdentifier
+ final String categorySystemIdentifier,
+ @FormParam("applicationUuid") final String applicationUuid
) {
- // ToDo
- return String.format(
- "redirect:categorymanager/categorysystems/%s",
+ final Identifier identifier = identifierParser.parseIdentifier(
categorySystemIdentifier
);
+ final Optional domainResult;
+ switch (identifier.getType()) {
+ case ID:
+ domainResult = domainRepository.findById(
+ Long.parseLong(identifier.getIdentifier()
+ )
+ );
+ break;
+ case UUID:
+ domainResult = domainRepository.findByUuid(
+ identifier.getIdentifier()
+ );
+ break;
+ default:
+ domainResult = domainRepository.findByDomainKey(
+ identifier.getIdentifier()
+ );
+ break;
+ }
+
+ if (domainResult.isPresent()) {
+ final Domain domain = domainResult.get();
+
+ final Optional appResult = applicationRepository
+ .findByUuid(applicationUuid);
+ if (!appResult.isPresent()) {
+ categorySystemDetailsModel.addMessage(
+ new Message(
+ adminMessages.getMessage(
+ "categorysystems.add_owner.not_found.message",
+ Arrays.asList(applicationRepository)
+ ),
+ MessageType.WARNING
+ )
+ );
+ return "org/libreccm/ui/admin/categories/application-not-found.xhtml";
+ }
+
+ final CcmApplication owner = appResult.get();
+
+ domainManager.addDomainOwner(owner, domain);
+
+ return String.format(
+ "redirect:categorymanager/categorysystems/%s",
+ categorySystemIdentifier
+ );
+ } else {
+ categorySystemDetailsModel.addMessage(
+ new Message(
+ adminMessages.getMessage(
+ "categorysystems.not_found.message",
+ Arrays.asList(categorySystemIdentifier)
+ ),
+ MessageType.WARNING
+ )
+ );
+ return "org/libreccm/ui/admin/categories/categorysystem-not-found.xhtml";
+ }
+
+ // ToDo
}
-
+
@POST
@Path("/categorysystems/{categorySystemIdentifier}/owners/remove")
@AuthorizationRequired
@RequiresPrivilege(CoreConstants.PRIVILEGE_ADMIN)
public String removeOwner(
@PathParam("categorySystemIdentifier")
- final String categorySystemIdentifier
+ final String categorySystemIdentifier,
+ @FormParam("applicationUuid") final String applicationUuid
) {
- // ToDo
- return String.format(
- "redirect:categorymanager/categorysystems/%s",
+ final Identifier identifier = identifierParser.parseIdentifier(
categorySystemIdentifier
);
+ final Optional domainResult;
+ switch (identifier.getType()) {
+ case ID:
+ domainResult = domainRepository.findById(
+ Long.parseLong(identifier.getIdentifier()
+ )
+ );
+ break;
+ case UUID:
+ domainResult = domainRepository.findByUuid(
+ identifier.getIdentifier()
+ );
+ break;
+ default:
+ domainResult = domainRepository.findByDomainKey(
+ identifier.getIdentifier()
+ );
+ break;
+ }
+
+ if (domainResult.isPresent()) {
+ final Domain domain = domainResult.get();
+
+ final Optional appResult = applicationRepository
+ .findByUuid(applicationUuid);
+ if (!appResult.isPresent()) {
+ categorySystemDetailsModel.addMessage(
+ new Message(
+ adminMessages.getMessage(
+ "categorysystems.add_owner.not_found.message",
+ Arrays.asList(applicationRepository)
+ ),
+ MessageType.WARNING
+ )
+ );
+ return "org/libreccm/ui/admin/categories/application-not-found.xhtml";
+ }
+
+ final CcmApplication owner = appResult.get();
+
+ domainManager.removeDomainOwner(owner, domain);
+
+ return String.format(
+ "redirect:categorymanager/categorysystems/%s",
+ categorySystemIdentifier
+ );
+ } else {
+ categorySystemDetailsModel.addMessage(
+ new Message(
+ adminMessages.getMessage(
+ "categorysystems.not_found.message",
+ Arrays.asList(categorySystemIdentifier)
+ ),
+ MessageType.WARNING
+ )
+ );
+ return "org/libreccm/ui/admin/categories/categorysystem-not-found.xhtml";
+ }
}
}
diff --git a/ccm-core/src/main/java/org/libreccm/ui/admin/categories/CategorySystemsTableModel.java b/ccm-core/src/main/java/org/libreccm/ui/admin/categories/CategorySystemsTableModel.java
new file mode 100644
index 000000000..c46be2369
--- /dev/null
+++ b/ccm-core/src/main/java/org/libreccm/ui/admin/categories/CategorySystemsTableModel.java
@@ -0,0 +1,86 @@
+/*
+ * 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.categories;
+
+import org.libreccm.categorization.Domain;
+import org.libreccm.categorization.DomainRepository;
+import org.libreccm.core.CoreConstants;
+import org.libreccm.security.AuthorizationRequired;
+import org.libreccm.security.RequiresPrivilege;
+
+import java.time.format.DateTimeFormatter;
+import java.util.List;
+import java.util.stream.Collectors;
+
+import javax.enterprise.context.RequestScoped;
+import javax.inject.Inject;
+import javax.inject.Named;
+import javax.transaction.Transactional;
+
+/**
+ *
+ * @author Jens Pelzetter
+ */
+@RequestScoped
+@Named("CategorySystemsTableModel")
+public class CategorySystemsTableModel {
+
+ @Inject
+ private DomainRepository domainRepository;
+
+ @AuthorizationRequired
+ @RequiresPrivilege(CoreConstants.PRIVILEGE_ADMIN)
+ @Transactional
+ public List getCategorySystems() {
+ return domainRepository
+ .findAll()
+ .stream()
+ .map(this::buildTableRow)
+ .sorted()
+ .collect(Collectors.toList());
+ }
+
+ private CategorySystemTableRow buildTableRow(final Domain domain) {
+ final CategorySystemTableRow row = new CategorySystemTableRow();
+
+ row.setDomainId(domain.getObjectId());
+ row.setDomainKey(domain.getDomainKey());
+ row.setUri(domain.getUri());
+ row.setVersion(domain.getVersion());
+ row.setReleased(
+ DateTimeFormatter.ISO_DATE_TIME.format(
+ domain.getReleased().toInstant()
+ )
+ );
+ row.setTitle(
+ domain
+ .getTitle()
+ .getValues()
+ .entrySet()
+ .stream()
+ .collect(
+ Collectors.toMap(
+ entry -> entry.getKey().toString(),
+ entry -> entry.getValue()
+ )
+ )
+ );
+ return row;
+ }
+}