From 0f1f0fadd451daa3daf2c097950077446d2573df Mon Sep 17 00:00:00 2001 From: Jens Pelzetter Date: Wed, 10 Feb 2021 20:43:49 +0100 Subject: [PATCH] Controller for categories view in cms admin UI Former-commit-id: 2d959e5ced3b027376a18134ad2941966ba0a63b --- .../contentsections/CategoriesController.java | 175 ++++++++++++++++++ .../CategorizedObjectModel.java | 64 +++++++ .../ui/contentsections/CategoryModel.java | 145 +++++++++++++++ .../contentsections/CategorySystemModel.java | 71 +++++++ .../CategoryTreeNodeModel.java | 55 ++++++ .../ContentSectionApplication.java | 3 + .../contentsections/DomainListEntryModel.java | 74 ++++++++ 7 files changed, 587 insertions(+) create mode 100644 ccm-cms/src/main/java/org/librecms/ui/contentsections/CategoriesController.java create mode 100644 ccm-cms/src/main/java/org/librecms/ui/contentsections/CategorizedObjectModel.java create mode 100644 ccm-cms/src/main/java/org/librecms/ui/contentsections/CategoryModel.java create mode 100644 ccm-cms/src/main/java/org/librecms/ui/contentsections/CategorySystemModel.java create mode 100644 ccm-cms/src/main/java/org/librecms/ui/contentsections/CategoryTreeNodeModel.java create mode 100644 ccm-cms/src/main/java/org/librecms/ui/contentsections/DomainListEntryModel.java diff --git a/ccm-cms/src/main/java/org/librecms/ui/contentsections/CategoriesController.java b/ccm-cms/src/main/java/org/librecms/ui/contentsections/CategoriesController.java new file mode 100644 index 000000000..b8f68b89d --- /dev/null +++ b/ccm-cms/src/main/java/org/librecms/ui/contentsections/CategoriesController.java @@ -0,0 +1,175 @@ +/* + * To change this license header, choose License Headers in Project Properties. + * To change this template file, choose Tools | Templates + * and open the template in the editor. + */ +package org.librecms.ui.contentsections; + +import org.libreccm.api.Identifier; +import org.libreccm.api.IdentifierParser; +import org.libreccm.categorization.Domain; +import org.libreccm.categorization.DomainOwnership; +import org.libreccm.l10n.GlobalizationHelper; +import org.libreccm.security.AuthorizationRequired; +import org.librecms.contentsection.ContentSection; +import org.librecms.contentsection.ContentSectionRepository; + +import java.time.ZoneId; +import java.time.format.DateTimeFormatter; +import java.util.List; +import java.util.Optional; +import java.util.stream.Collectors; + +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.GET; +import javax.ws.rs.Path; +import javax.ws.rs.PathParam; + +/** + * + * @author Jens Pelzetter + */ +@RequestScoped +@Controller +@Path("/{sectionIdentifier}/categorysystems") +public class CategoriesController { + + @Inject + private ContentSectionRepository sectionRepo; + + @Inject + private GlobalizationHelper globalizationHelper; + + @Inject + private IdentifierParser identifierParser; + + @Inject + private Models models; + + @GET + @Path("/") + @AuthorizationRequired + @Transactional(Transactional.TxType.REQUIRED) + public String listCategorySystems( + @PathParam("sectionIdentifier") final String sectionIdentifier + ) { + final Optional sectionResult = retrieveContentSection( + sectionIdentifier); + if (!sectionResult.isPresent()) { + models.put("sectionIdentifier", sectionIdentifier); + return "org/librecms/ui/contentsection/contentsection-not-found.xhtml"; + } + final ContentSection section = sectionResult.get(); + + final List domains = section + .getDomains() + .stream() + .map(this::buildDomainListEntryModel) + .collect(Collectors.toList()); + + models.put("categorySystems", domains); + + return "org/librecms/ui/contentsection/categorysystems/categorysystems.xhtml"; + } + + @GET + @Path("/{key}") + @AuthorizationRequired + @Transactional(Transactional.TxType.REQUIRED) + public String showCategorySystem( + @PathParam("sectionIdentifier") final String sectionIdentifier, + @PathParam("key") final String domainKey + ) { + return showCategorySystem(sectionIdentifier, domainKey, ""); + } + + @GET + @Path("/{key}/{categoryPath:(.+)?}") + @AuthorizationRequired + @Transactional(Transactional.TxType.REQUIRED) + public String showCategorySystem( + @PathParam("sectionIdentifier") final String sectionIdentifier, + @PathParam("key") final String domainKey, + @PathParam("categoryPath") final String categoryPath + ) { + //ToDo: Category System Model with + //* List of category systems + //* Category tree + //* Display of active category (if none = root?) with edit options + // listed below + // + + throw new UnsupportedOperationException(); + } + + //ToDo: Show category details + // + //ToDo: Rename category (disabled for root category) + // + //ToDo: Add, update, remove localized title + // + //ToDo: Set enabled, visible, abstract + // + //ToDo: Set and unset index element + // + //ToDo: Move category (disabled for root category) + + //ToDo: Delete category (disabled for root category) + // + //ToDo: List subcategories + // + //ToDo: Order subcategories + // + //ToDo: Add subcategory + + private Optional retrieveContentSection( + final String sectionIdentifier + ) { + final Identifier identifier = identifierParser.parseIdentifier( + sectionIdentifier + ); + + final Optional sectionResult; + switch (identifier.getType()) { + case ID: + sectionResult = sectionRepo.findById( + Long.parseLong(identifier.getIdentifier()) + ); + break; + case UUID: + sectionResult = sectionRepo.findByUuid(identifier + .getIdentifier()); + break; + default: + sectionResult = sectionRepo.findByLabel(identifier + .getIdentifier()); + break; + } + return sectionResult; + } + + private DomainListEntryModel buildDomainListEntryModel( + final DomainOwnership ownership + ) { + final Domain domain = ownership.getDomain(); + + final DomainListEntryModel model = new DomainListEntryModel(); + model.setContext(ownership.getContext()); + model.setDomainKey(domain.getDomainKey()); + model.setReleased( + DateTimeFormatter.ISO_DATE.withZone(ZoneId.systemDefault()) + .format(domain.getReleased())); + model.setTitle( + globalizationHelper.getValueFromLocalizedString(domain.getTitle()) + ); + model.setUri(domain.getUri()); + model.setVersion(domain.getVersion()); + + return model; + } + +} diff --git a/ccm-cms/src/main/java/org/librecms/ui/contentsections/CategorizedObjectModel.java b/ccm-cms/src/main/java/org/librecms/ui/contentsections/CategorizedObjectModel.java new file mode 100644 index 000000000..280b827b9 --- /dev/null +++ b/ccm-cms/src/main/java/org/librecms/ui/contentsections/CategorizedObjectModel.java @@ -0,0 +1,64 @@ +/* + * To change this license header, choose License Headers in Project Properties. + * To change this template file, choose Tools | Templates + * and open the template in the editor. + */ +package org.librecms.ui.contentsections; + +/** + * + * @author Jens Pelzetter + */ +public class CategorizedObjectModel { + + private String displayName; + + private String title; + + private String type; + + private boolean indexObject; + + private long objectOrder; + + public String getDisplayName() { + return displayName; + } + + public void setDisplayName(final String displayName) { + this.displayName = displayName; + } + + public String getTitle() { + return title; + } + + public void setTitle(final String title) { + this.title = title; + } + + public String getType() { + return type; + } + + public void setType(final String type) { + this.type = type; + } + + public boolean isIndexObject() { + return indexObject; + } + + public void setIndexObject(final boolean indexObject) { + this.indexObject = indexObject; + } + + public long getObjectOrder() { + return objectOrder; + } + + public void setObjectOrder(final long objectOrder) { + this.objectOrder = objectOrder; + } + +} diff --git a/ccm-cms/src/main/java/org/librecms/ui/contentsections/CategoryModel.java b/ccm-cms/src/main/java/org/librecms/ui/contentsections/CategoryModel.java new file mode 100644 index 000000000..9ee776a6c --- /dev/null +++ b/ccm-cms/src/main/java/org/librecms/ui/contentsections/CategoryModel.java @@ -0,0 +1,145 @@ +/* + * To change this license header, choose License Headers in Project Properties. + * To change this template file, choose Tools | Templates + * and open the template in the editor. + */ +package org.librecms.ui.contentsections; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; + +/** + * + * @author Jens Pelzetter + */ +public class CategoryModel { + + private long categoryId; + + private String uniqueId; + + private String name; + + private String path; + + private String title; + + private String description; + + private boolean enabled; + + private boolean visible; + + private boolean abstractCategory; + + private List subCategories; + + private List objects; + + private long categoryOrder; + + public CategoryModel() { + subCategories = new ArrayList<>(); + objects = new ArrayList<>(); + } + + public long getCategoryId() { + return categoryId; + } + + public void setCategoryId(final long categoryId) { + this.categoryId = categoryId; + } + + public String getUniqueId() { + return uniqueId; + } + + public void setUniqueId(final String uniqueId) { + this.uniqueId = uniqueId; + } + + public String getName() { + return name; + } + + public void setName(final String name) { + this.name = name; + } + + public String getPath() { + return path; + } + + public void setPath(final String path) { + this.path = path; + } + + public String getTitle() { + return title; + } + + public void setTitle(final String title) { + this.title = title; + } + + public String getDescription() { + return description; + } + + public void setDescription(final String description) { + this.description = description; + } + + public boolean isEnabled() { + return enabled; + } + + public void setEnabled(final boolean enabled) { + this.enabled = enabled; + } + + public boolean isVisible() { + return visible; + } + + public void setVisible(final boolean visible) { + this.visible = visible; + } + + public boolean isAbstractCategory() { + return abstractCategory; + } + + public void setAbstractCategory(final boolean abstractCategory) { + this.abstractCategory = abstractCategory; + } + + public List getSubCategories() { + return Collections.unmodifiableList(subCategories); + } + + public void setSubCategories(final List subCategories) { + this.subCategories = new ArrayList<>(subCategories); + } + + public List getObjects() { + return Collections.unmodifiableList(objects); + } + + public void setObjects(final List objects) { + this.objects = new ArrayList<>(); + } + + public long getCategoryOrder() { + return categoryOrder; + } + + public void setCategoryOrder(final long categoryOrder) { + this.categoryOrder = categoryOrder; + } + + + +} diff --git a/ccm-cms/src/main/java/org/librecms/ui/contentsections/CategorySystemModel.java b/ccm-cms/src/main/java/org/librecms/ui/contentsections/CategorySystemModel.java new file mode 100644 index 000000000..0de42cc93 --- /dev/null +++ b/ccm-cms/src/main/java/org/librecms/ui/contentsections/CategorySystemModel.java @@ -0,0 +1,71 @@ +/* + * To change this license header, choose License Headers in Project Properties. + * To change this template file, choose Tools | Templates + * and open the template in the editor. + */ +package org.librecms.ui.contentsections; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; + +import javax.enterprise.context.RequestScoped; +import javax.inject.Named; + +/** + * + * @author Jens Pelzetter + */ +@RequestScoped +@Named("CategorySystemModel") +public class CategorySystemModel { + + private List categorySystems; + + private DomainListEntryModel selectedCategorySystem; + + private CategoryTreeNodeModel categoryTree; + + private CategoryModel selectedCategory; + + public CategorySystemModel() { + categorySystems = new ArrayList<>(); + } + + public List getCategorySystems() { + return Collections.unmodifiableList(categorySystems); + } + + public void setCategorySystems( + final List categorySystems + ) { + this.categorySystems = new ArrayList<>(categorySystems); + } + + public DomainListEntryModel getSelectedCategorySystem() { + return selectedCategorySystem; + } + + public void setSelectedCategorySystem( + final DomainListEntryModel selectedCategorySystem + ) { + this.selectedCategorySystem = selectedCategorySystem; + } + + public CategoryTreeNodeModel getCategoryTree() { + return categoryTree; + } + + public void setCategoryTree(final CategoryTreeNodeModel categoryTree) { + this.categoryTree = categoryTree; + } + + public CategoryModel getSelectedCategory() { + return selectedCategory; + } + + public void setSelectedCategory(final CategoryModel selectedCategory) { + this.selectedCategory = selectedCategory; + } + +} diff --git a/ccm-cms/src/main/java/org/librecms/ui/contentsections/CategoryTreeNodeModel.java b/ccm-cms/src/main/java/org/librecms/ui/contentsections/CategoryTreeNodeModel.java new file mode 100644 index 000000000..add2b1028 --- /dev/null +++ b/ccm-cms/src/main/java/org/librecms/ui/contentsections/CategoryTreeNodeModel.java @@ -0,0 +1,55 @@ +/* + * To change this license header, choose License Headers in Project Properties. + * To change this template file, choose Tools | Templates + * and open the template in the editor. + */ +package org.librecms.ui.contentsections; + +import java.util.ArrayList; + +import java.util.Collections; +import java.util.List; + +/** + * + * @author Jens Pelzetter + */ +public class CategoryTreeNodeModel { + + private String path; + + private String title; + + private List subCategories; + + public CategoryTreeNodeModel() { + subCategories = new ArrayList<>(); + } + + public String getPath() { + return path; + } + + public void setPath(final String path) { + this.path = path; + } + + public String getTitle() { + return title; + } + + public void setTitle(final String title) { + this.title = title; + } + + public List getSubCategories() { + return Collections.unmodifiableList(subCategories); + } + + public void setSubCategories( + final List subCategories + ) { + this.subCategories = new ArrayList<>(subCategories); + } + +} diff --git a/ccm-cms/src/main/java/org/librecms/ui/contentsections/ContentSectionApplication.java b/ccm-cms/src/main/java/org/librecms/ui/contentsections/ContentSectionApplication.java index 41c73f3a7..8148cfcb1 100644 --- a/ccm-cms/src/main/java/org/librecms/ui/contentsections/ContentSectionApplication.java +++ b/ccm-cms/src/main/java/org/librecms/ui/contentsections/ContentSectionApplication.java @@ -25,9 +25,12 @@ public class ContentSectionApplication extends Application { final Set> classes = new HashSet<>(); classes.add(AssetFolderController.class); + classes.add(CategoriesController.class); + classes.add(ContentSectionController.class); classes.add(DocumentFolderController.class); classes.add(IsAuthenticatedFilter.class); + return classes; } diff --git a/ccm-cms/src/main/java/org/librecms/ui/contentsections/DomainListEntryModel.java b/ccm-cms/src/main/java/org/librecms/ui/contentsections/DomainListEntryModel.java new file mode 100644 index 000000000..dbeb9e368 --- /dev/null +++ b/ccm-cms/src/main/java/org/librecms/ui/contentsections/DomainListEntryModel.java @@ -0,0 +1,74 @@ +/* + * To change this license header, choose License Headers in Project Properties. + * To change this template file, choose Tools | Templates + * and open the template in the editor. + */ +package org.librecms.ui.contentsections; + +/** + * + * @author Jens Pelzetter + */ +public class DomainListEntryModel { + + private String context; + + private String domainKey; + + private String uri; + + private String title; + + private String version; + + private String released; + + public String getContext() { + return context; + } + + public void setContext(String context) { + this.context = context; + } + + public String getDomainKey() { + return domainKey; + } + + public void setDomainKey(final String domainKey) { + this.domainKey = domainKey; + } + + public String getUri() { + return uri; + } + + public void setUri(final String uri) { + this.uri = uri; + } + + public String getTitle() { + return title; + } + + public void setTitle(final String title) { + this.title = title; + } + + public String getVersion() { + return version; + } + + public void setVersion(final String version) { + this.version = version; + } + + public String getReleased() { + return released; + } + + public void setReleased(final String released) { + this.released = released; + } + +}