Controller for categories view in cms admin UI

Former-commit-id: 2d959e5ced3b027376a18134ad2941966ba0a63b
pull/10/head
Jens Pelzetter 2021-02-10 20:43:49 +01:00
parent 7bd424537e
commit 0f1f0fadd4
7 changed files with 587 additions and 0 deletions

View File

@ -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 <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
*/
@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<ContentSection> 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<DomainListEntryModel> 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<ContentSection> retrieveContentSection(
final String sectionIdentifier
) {
final Identifier identifier = identifierParser.parseIdentifier(
sectionIdentifier
);
final Optional<ContentSection> 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;
}
}

View File

@ -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 <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
*/
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;
}
}

View File

@ -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 <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
*/
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<CategoryModel> subCategories;
private List<CategorizedObjectModel> 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<CategoryModel> getSubCategories() {
return Collections.unmodifiableList(subCategories);
}
public void setSubCategories(final List<CategoryModel> subCategories) {
this.subCategories = new ArrayList<>(subCategories);
}
public List<CategorizedObjectModel> getObjects() {
return Collections.unmodifiableList(objects);
}
public void setObjects(final List<CategorizedObjectModel> objects) {
this.objects = new ArrayList<>();
}
public long getCategoryOrder() {
return categoryOrder;
}
public void setCategoryOrder(final long categoryOrder) {
this.categoryOrder = categoryOrder;
}
}

View File

@ -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 <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
*/
@RequestScoped
@Named("CategorySystemModel")
public class CategorySystemModel {
private List<DomainListEntryModel> categorySystems;
private DomainListEntryModel selectedCategorySystem;
private CategoryTreeNodeModel categoryTree;
private CategoryModel selectedCategory;
public CategorySystemModel() {
categorySystems = new ArrayList<>();
}
public List<DomainListEntryModel> getCategorySystems() {
return Collections.unmodifiableList(categorySystems);
}
public void setCategorySystems(
final List<DomainListEntryModel> 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;
}
}

View File

@ -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 <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
*/
public class CategoryTreeNodeModel {
private String path;
private String title;
private List<CategoryTreeNodeModel> 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<CategoryTreeNodeModel> getSubCategories() {
return Collections.unmodifiableList(subCategories);
}
public void setSubCategories(
final List<CategoryTreeNodeModel> subCategories
) {
this.subCategories = new ArrayList<>(subCategories);
}
}

View File

@ -25,9 +25,12 @@ public class ContentSectionApplication extends Application {
final Set<Class<?>> classes = new HashSet<>(); final Set<Class<?>> classes = new HashSet<>();
classes.add(AssetFolderController.class); classes.add(AssetFolderController.class);
classes.add(CategoriesController.class);
classes.add(ContentSectionController.class);
classes.add(DocumentFolderController.class); classes.add(DocumentFolderController.class);
classes.add(IsAuthenticatedFilter.class); classes.add(IsAuthenticatedFilter.class);
return classes; return classes;
} }

View File

@ -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 <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
*/
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;
}
}