diff --git a/ccm-cms/src/main/java/org/librecms/ui/CmsUi.java b/ccm-cms/src/main/java/org/librecms/ui/CmsUi.java index 9d696fd3f..1d2d58937 100644 --- a/ccm-cms/src/main/java/org/librecms/ui/CmsUi.java +++ b/ccm-cms/src/main/java/org/librecms/ui/CmsUi.java @@ -26,6 +26,7 @@ public class CmsUi extends Application { classes.add(IsAuthenticatedFilter.class); classes.add(ContentSectionsController.class); + classes.add(ContentSectionController.class); return classes; } diff --git a/ccm-cms/src/main/java/org/librecms/ui/ContentSectionController.java b/ccm-cms/src/main/java/org/librecms/ui/ContentSectionController.java new file mode 100644 index 000000000..1f1ad7b33 --- /dev/null +++ b/ccm-cms/src/main/java/org/librecms/ui/ContentSectionController.java @@ -0,0 +1,106 @@ +/* + * 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; + +import org.libreccm.api.Identifier; +import org.libreccm.api.IdentifierParser; +import org.libreccm.security.AuthorizationRequired; +import org.librecms.contentsection.ContentSection; +import org.librecms.contentsection.ContentSectionRepository; + +import javax.enterprise.context.RequestScoped; +import javax.inject.Inject; +import javax.mvc.Controller; +import javax.mvc.Models; +import javax.ws.rs.GET; +import javax.ws.rs.Path; +import javax.ws.rs.PathParam; +import javax.ws.rs.WebApplicationException; + +/** + * + * @author Jens Pelzetter + */ +@RequestScoped +@Controller +@Path("/{sectionIdentifier}") +public class ContentSectionController { + + @Inject + private CmsAdminMessages cmsAdminMessages; + + @Inject + private ContentSectionModel contentSectionModel; + + @Inject + private FolderBrowserModel folderBrowserModel; + + @Inject + private Models models; + + @Inject + private ContentSectionRepository sectionRepo; + + @Inject + private IdentifierParser identifierParser; + + @GET + @Path("/folderbrowser") + @AuthorizationRequired + public String listItems( + @PathParam("sectionIdentifier") final String sectionIdentifier + ) { + final Identifier identifier = identifierParser.parseIdentifier( + sectionIdentifier + ); + final ContentSection section; + switch (identifier.getType()) { + case ID: + section = sectionRepo + .findById(Long.parseLong(identifier.getIdentifier())) + .orElseThrow( + () -> new WebApplicationException( + String.format( + "No ContentSection with ID %s found.", + identifier.getIdentifier() + ) + ) + ); + break; + case UUID: + section = sectionRepo + .findByUuid(identifier.getIdentifier()) + .orElseThrow( + () -> new WebApplicationException( + String.format( + "No ContentSection with UUID %s found.", + identifier.getIdentifier() + ) + ) + ); + break; + default: + section = sectionRepo + .findByLabel(identifier.getIdentifier()) + .orElseThrow( + () -> new WebApplicationException( + String.format( + "No ContentSection named %s found.", + identifier.getIdentifier() + ) + ) + ); + break; + } + + contentSectionModel.setSection(section); + folderBrowserModel.setSection(section); + + return "org/librecms/ui/content-section/folderbrowser.xhtml"; + + } + +} diff --git a/ccm-cms/src/main/java/org/librecms/ui/ContentSectionModel.java b/ccm-cms/src/main/java/org/librecms/ui/ContentSectionModel.java new file mode 100644 index 000000000..3f32477ae --- /dev/null +++ b/ccm-cms/src/main/java/org/librecms/ui/ContentSectionModel.java @@ -0,0 +1,35 @@ +/* + * 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; + +import org.librecms.contentsection.ContentSection; + +import java.util.Objects; + +import javax.enterprise.context.RequestScoped; +import javax.inject.Named; + +/** + * + * @author Jens Pelzetter + */ +@RequestScoped +@Named("ContentSectionModel") +public class ContentSectionModel { + + private ContentSection section; + + protected void setSection(final ContentSection section) { + this.section = Objects.requireNonNull( + section, "Parameter section can't be null" + ); + } + + public String getSectionName() { + return section.getLabel(); + } + +} diff --git a/ccm-cms/src/main/java/org/librecms/ui/ContentSectionsController.java b/ccm-cms/src/main/java/org/librecms/ui/ContentSectionsController.java index 12ff93d52..c7d0154a2 100644 --- a/ccm-cms/src/main/java/org/librecms/ui/ContentSectionsController.java +++ b/ccm-cms/src/main/java/org/librecms/ui/ContentSectionsController.java @@ -11,7 +11,6 @@ import org.libreccm.core.CoreConstants; import org.libreccm.security.AuthorizationRequired; import org.libreccm.security.PermissionChecker; import org.libreccm.security.RequiresPrivilege; -import org.libreccm.security.Shiro; import org.librecms.contentsection.ContentSection; import org.librecms.contentsection.ContentSectionManager; import org.librecms.contentsection.ContentSectionRepository; @@ -24,7 +23,6 @@ import java.util.Objects; import javax.enterprise.context.RequestScoped; import javax.inject.Inject; import javax.mvc.Controller; -import javax.servlet.ServletContext; import javax.servlet.http.HttpServletRequest; import javax.transaction.Transactional; import javax.ws.rs.FormParam; diff --git a/ccm-cms/src/main/java/org/librecms/ui/FolderBrowserModel.java b/ccm-cms/src/main/java/org/librecms/ui/FolderBrowserModel.java new file mode 100644 index 000000000..1a30f6a83 --- /dev/null +++ b/ccm-cms/src/main/java/org/librecms/ui/FolderBrowserModel.java @@ -0,0 +1,31 @@ +/* + * 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; + +import org.librecms.contentsection.ContentSection; + +import java.util.Objects; + +import javax.enterprise.context.RequestScoped; + +/** + * + * @author Jens Pelzetter + */ +@RequestScoped +public class FolderBrowserModel { + + private ContentSection section; + + protected void setSection(final ContentSection section) { + this.section = Objects.requireNonNull( + section, "Parameter section can't be null" + ); + } + + + +} diff --git a/ccm-cms/src/main/resources/WEB-INF/views/org/librecms/ui/content-section/contentsection.xhtml b/ccm-cms/src/main/resources/WEB-INF/views/org/librecms/ui/content-section/contentsection.xhtml new file mode 100644 index 000000000..7dcf337be --- /dev/null +++ b/ccm-cms/src/main/resources/WEB-INF/views/org/librecms/ui/content-section/contentsection.xhtml @@ -0,0 +1,57 @@ + + +
+placeholder
+