From 2ab4b0c5ed136e146f13bff3e42a766fb65a7265 Mon Sep 17 00:00:00 2001 From: Jens Pelzetter Date: Wed, 14 Apr 2021 20:52:36 +0200 Subject: [PATCH] Create step is now found --- .../contentsection/FolderManager.java | 4 + .../AbstractMvcDocumentCreateStep.java | 60 +++++--- .../documents/DocumentController.java | 39 ++++-- .../documents/MvcDocumentCreateStep.java | 33 ++++- .../ui/contenttypes/MvcArticleCreateStep.java | 34 ++--- .../documentfolder-not-found.xhtml | 2 +- .../contenttypes/article/create-article.xhtml | 128 +++++++++--------- .../ui/contenttypes/ArticleBundle.properties | 2 + .../contenttypes/ArticleBundle_de.properties | 2 + 9 files changed, 195 insertions(+), 109 deletions(-) diff --git a/ccm-cms/src/main/java/org/librecms/contentsection/FolderManager.java b/ccm-cms/src/main/java/org/librecms/contentsection/FolderManager.java index 80a0e76ad..2fe145c35 100644 --- a/ccm-cms/src/main/java/org/librecms/contentsection/FolderManager.java +++ b/ccm-cms/src/main/java/org/librecms/contentsection/FolderManager.java @@ -76,6 +76,7 @@ public class FolderManager { * @see #folderIsDeletable(org.librecms.contentsection.Folder) */ public enum FolderIsDeletable { + /** * Folder can be deleted. */ @@ -92,12 +93,14 @@ public class FolderManager { * Folder can't be deleted because the folder is a root folder. */ IS_ROOT_FOLDER + } /** * Describes if a folder is movable to another folder or not and why. */ public enum FolderIsMovable { + /** * The folder can be moved to the specified target folder. */ @@ -127,6 +130,7 @@ public class FolderManager { * The folder to contains assets which are in use. */ HAS_IN_USE_ASSETS + } @Transactional(Transactional.TxType.REQUIRED) diff --git a/ccm-cms/src/main/java/org/librecms/ui/contentsections/documents/AbstractMvcDocumentCreateStep.java b/ccm-cms/src/main/java/org/librecms/ui/contentsections/documents/AbstractMvcDocumentCreateStep.java index b1be45a8c..3d9c147ed 100644 --- a/ccm-cms/src/main/java/org/librecms/ui/contentsections/documents/AbstractMvcDocumentCreateStep.java +++ b/ccm-cms/src/main/java/org/librecms/ui/contentsections/documents/AbstractMvcDocumentCreateStep.java @@ -18,7 +18,6 @@ */ package org.librecms.ui.contentsections.documents; -import org.libreccm.api.Identifier; import org.libreccm.api.IdentifierParser; import org.libreccm.l10n.GlobalizationHelper; import org.libreccm.l10n.LocalizedString; @@ -28,17 +27,18 @@ import org.librecms.contentsection.ContentSectionRepository; import org.librecms.contentsection.Folder; import org.librecms.contentsection.FolderManager; import org.librecms.contentsection.FolderRepository; -import org.librecms.contentsection.FolderType; -import org.librecms.ui.contentsections.ItemPermissionChecker; import java.util.Collections; +import java.util.LinkedHashMap; import java.util.Map; -import java.util.Optional; +import java.util.NavigableMap; import java.util.SortedMap; import java.util.TreeMap; +import java.util.stream.Collectors; import javax.enterprise.context.Dependent; import javax.inject.Inject; +import javax.transaction.Transactional; /** * @@ -49,12 +49,6 @@ import javax.inject.Inject; public abstract class AbstractMvcDocumentCreateStep implements MvcDocumentCreateStep { - @Inject - private ContentSectionRepository sectionRepo; - - @Inject - private FolderRepository folderRepository; - /** * Provides operations for folders. */ @@ -67,9 +61,6 @@ public abstract class AbstractMvcDocumentCreateStep @Inject private GlobalizationHelper globalizationHelper; - @Inject - private IdentifierParser identifierParser; - private boolean canCreate; /** @@ -82,6 +73,8 @@ public abstract class AbstractMvcDocumentCreateStep */ private ContentSection section; + private Map availableWorkflows; + /** * Messages to be shown to the user. */ @@ -91,21 +84,41 @@ public abstract class AbstractMvcDocumentCreateStep messages = new TreeMap<>(); } + @Transactional(Transactional.TxType.REQUIRED) + @Override + public Map getAvailableLocales() { + return globalizationHelper + .getAvailableLocales() + .stream() + .collect( + Collectors.toMap( + locale -> locale.toString(), + locale -> locale.toString(), + (value1, value2) -> value1, + () -> new LinkedHashMap() + ) + ); + } + + @Transactional(Transactional.TxType.REQUIRED) @Override public ContentSection getContentSection() { return section; } - + + @Transactional(Transactional.TxType.REQUIRED) @Override public void setContentSection(final ContentSection section) { this.section = section; } + @Transactional(Transactional.TxType.REQUIRED) @Override public String getContentSectionLabel() { return section.getLabel(); } + @Transactional(Transactional.TxType.REQUIRED) @Override public String getContentSectionTitle() { return globalizationHelper.getValueFromLocalizedString( @@ -113,6 +126,18 @@ public abstract class AbstractMvcDocumentCreateStep ); } + @Override + public Map getAvailableWorkflows() { + return Collections.unmodifiableMap(availableWorkflows); + } + + @Override + public void setAvailableWorkflows( + final Map availableWorkflows + ) { + this.availableWorkflows = new LinkedHashMap<>(availableWorkflows); + } + // protected final void setContentSectionByIdentifier( // final String sectionIdentifierParam // ) { @@ -146,7 +171,6 @@ public abstract class AbstractMvcDocumentCreateStep // canCreate = false; // } // } - // protected final void setFolderByPath(final String folderPath) { // final Optional folderResult = folderRepository.findByPath( // section, @@ -183,7 +207,11 @@ public abstract class AbstractMvcDocumentCreateStep @Override public String getFolderPath() { - return folderManager.getFolderPath(folder); + if (folder.getParentFolder() == null) { + return ""; + } else { + return folderManager.getFolderPath(folder); + } } @Override diff --git a/ccm-cms/src/main/java/org/librecms/ui/contentsections/documents/DocumentController.java b/ccm-cms/src/main/java/org/librecms/ui/contentsections/documents/DocumentController.java index 597814ef5..09d5fd63f 100644 --- a/ccm-cms/src/main/java/org/librecms/ui/contentsections/documents/DocumentController.java +++ b/ccm-cms/src/main/java/org/librecms/ui/contentsections/documents/DocumentController.java @@ -40,22 +40,27 @@ import org.librecms.ui.contentsections.ItemPermissionChecker; import java.time.ZoneId; import java.time.format.DateTimeFormatter; import java.util.Collections; +import java.util.LinkedHashMap; import java.util.Optional; import java.util.stream.Collectors; import javax.enterprise.context.RequestScoped; +import javax.enterprise.inject.Any; import javax.enterprise.inject.Instance; import javax.enterprise.util.AnnotationLiteral; import javax.inject.Inject; import javax.mvc.Controller; import javax.mvc.Models; import javax.transaction.Transactional; +import javax.ws.rs.Consumes; import javax.ws.rs.DefaultValue; import javax.ws.rs.FormParam; import javax.ws.rs.GET; import javax.ws.rs.POST; import javax.ws.rs.Path; import javax.ws.rs.PathParam; +import javax.ws.rs.core.Form; +import javax.ws.rs.core.MediaType; import javax.ws.rs.core.MultivaluedMap; /** @@ -76,7 +81,7 @@ public class DocumentController { @Inject private ContentSectionModel sectionModel; - + /** * {@link ContentSectionsUi} instance providing for helper functions for * dealing with {@link ContentSection}s. @@ -112,6 +117,7 @@ public class DocumentController { * All available {@link MvcDocumentCreateStep}s. */ @Inject + @Any private Instance> createSteps; /** @@ -253,23 +259,28 @@ public class DocumentController { @POST @Path("/@create/{documentType}") + @Consumes(MediaType.APPLICATION_FORM_URLENCODED) @AuthorizationRequired @Transactional(Transactional.TxType.REQUIRED) public String createDocument( @PathParam("sectionIdentifier") final String sectionIdentifier, @PathParam("documentType") final String documentType, - final MultivaluedMap formParameters + //final MultivaluedMap formParameters + final Form form ) { return createDocument( sectionIdentifier, - "", documentType, - formParameters + "", + documentType, + //formParameters + form.asMap() ); } @POST @Path("/{folderPath:(.+)?}/@create/{documentType}") @AuthorizationRequired + @Consumes(MediaType.APPLICATION_FORM_URLENCODED) @Transactional(Transactional.TxType.REQUIRED) @SuppressWarnings({"unchecked", "unchecked"}) public String createDocument( @@ -925,12 +936,8 @@ public class DocumentController { ); } - //final Class documentClass; final Class clazz; try { -// documentClass = (Class) Class.forName( -// documentType -// ); clazz = Class.forName(documentType); } catch (ClassNotFoundException ex) { return new CreateStepResult( @@ -964,6 +971,22 @@ public class DocumentController { .get(); createStep.setContentSection(section); + createStep.setAvailableWorkflows( + section + .getWorkflowTemplates() + .stream() + .collect( + Collectors.toMap( + workflow -> workflow.getUuid(), + workflow -> globalizationHelper + .getValueFromLocalizedString( + workflow.getName() + ), + (value1, value2) -> value1, + () -> new LinkedHashMap() + ) + ) + ); createStep.setFolder(folder); return new CreateStepResult(createStep); diff --git a/ccm-cms/src/main/java/org/librecms/ui/contentsections/documents/MvcDocumentCreateStep.java b/ccm-cms/src/main/java/org/librecms/ui/contentsections/documents/MvcDocumentCreateStep.java index 1a3a343b3..65b4845b6 100644 --- a/ccm-cms/src/main/java/org/librecms/ui/contentsections/documents/MvcDocumentCreateStep.java +++ b/ccm-cms/src/main/java/org/librecms/ui/contentsections/documents/MvcDocumentCreateStep.java @@ -26,7 +26,6 @@ import org.librecms.contentsection.Folder; import java.util.Map; import java.util.ResourceBundle; -import javax.ws.rs.core.Form; import javax.ws.rs.core.MultivaluedMap; /** @@ -38,10 +37,10 @@ import javax.ws.rs.core.MultivaluedMap; * } to provide the current current content section and folder. After that, * depending on the request method, either {@link #showCreateStep} or {@link #createItem(javax.ws.rs.core.Form)] * will be called. - * + * * In most cases, {@link AbstractMvcDocumentCreateStep} should be used as * base for implementations. {@link AbstractMvcDocumentCreateStep} implements - * several common operations. + * several common operations. * * @author Jens Pelzetter * @@ -64,7 +63,7 @@ public interface MvcDocumentCreateStep { * * @return A redirect to the first authoring step of the new document. */ - String createItem(MultivaluedMap formParams); + String createItem(MultivaluedMap formParams); /** * Should be set by the implementing class to indicate if the current user @@ -80,7 +79,7 @@ public interface MvcDocumentCreateStep { * * @return Document type generated. */ - Class getDocumentType(); + String getDocumentType(); /** * Localized description of the create step. The current locale as returned @@ -100,6 +99,13 @@ public interface MvcDocumentCreateStep { */ String getBundle(); + /** + * The locales that can be used for documents. + * + * @return The locales that can be used for documents. + */ + Map getAvailableLocales(); + /** * The current content section. * @@ -129,6 +135,23 @@ public interface MvcDocumentCreateStep { */ void setContentSection(final ContentSection section); + /** + * Retrieves the workflows available for the current content section. + * + * @return A map of the available workflows. The key is the UUID of the + * workflow, the value is the name of the workflow. + */ + Map getAvailableWorkflows(); + + /** + * Used by the {@link DocumentController} to provide the available + * workflows. + * + * @param availableWorkflows + */ + void setAvailableWorkflows( + final Map availableWorkflows); + /** * The parent folder of the new item. * diff --git a/ccm-cms/src/main/java/org/librecms/ui/contenttypes/MvcArticleCreateStep.java b/ccm-cms/src/main/java/org/librecms/ui/contenttypes/MvcArticleCreateStep.java index aaea54ebb..8d17cbbec 100644 --- a/ccm-cms/src/main/java/org/librecms/ui/contenttypes/MvcArticleCreateStep.java +++ b/ccm-cms/src/main/java/org/librecms/ui/contenttypes/MvcArticleCreateStep.java @@ -20,6 +20,7 @@ package org.librecms.ui.contenttypes; import org.libreccm.l10n.GlobalizationHelper; import org.libreccm.l10n.LocalizedString; +import org.libreccm.security.AuthorizationRequired; import org.libreccm.workflow.Workflow; import org.librecms.contentsection.ContentItemManager; import org.librecms.contentsection.ContentItemRepository; @@ -35,6 +36,7 @@ import javax.inject.Named; import javax.inject.Inject; import javax.mvc.Models; +import javax.transaction.Transactional; import javax.ws.rs.core.MultivaluedMap; /** @@ -109,8 +111,8 @@ public class MvcArticleCreateStep private String selectedWorkflow; @Override - public Class
getDocumentType() { - return Article.class; + public String getDocumentType() { + return Article.class.getName(); } @Override @@ -141,6 +143,7 @@ public class MvcArticleCreateStep return initialLocale; } + @Transactional(Transactional.TxType.REQUIRED) public String getSelectedWorkflow() { if (selectedWorkflow == null || selectedWorkflow.isEmpty()) { return getContentSection() @@ -169,6 +172,8 @@ public class MvcArticleCreateStep return "org/librecms/ui/contenttypes/article/create-article.xhtml"; } + @AuthorizationRequired + @Transactional(Transactional.TxType.REQUIRED) @Override public String createItem(final MultivaluedMap formParams) { if (!formParams.containsKey(FORM_PARAM_NAME) @@ -180,6 +185,7 @@ public class MvcArticleCreateStep getBundle() ).getText("createstep.name.error.missing") ); + return showCreateStep(); } name = formParams.getFirst(FORM_PARAM_NAME); @@ -190,6 +196,7 @@ public class MvcArticleCreateStep getBundle() ).getText("createstep.name.error.invalid") ); + return showCreateStep(); } if (!formParams.containsKey(FORM_PARAM_TITLE) @@ -201,6 +208,7 @@ public class MvcArticleCreateStep getBundle() ).getText("createstep.title.error.missing") ); + return showCreateStep(); } title = formParams.getFirst(FORM_PARAM_TITLE); @@ -213,6 +221,7 @@ public class MvcArticleCreateStep getBundle() ).getText("createstep.summary.error.missing") ); + return showCreateStep(); } summary = formParams.getFirst(FORM_PARAM_SUMMARY); @@ -225,6 +234,7 @@ public class MvcArticleCreateStep getBundle() ).getText("createstep.initial_locale.error.missing") ); + return showCreateStep(); } final Locale locale = new Locale( formParams.getFirst(FORM_PARAM_INITIAL_LOCALE) @@ -239,6 +249,7 @@ public class MvcArticleCreateStep getBundle() ).getText("createstep.workflow.none_selected") ); + return showCreateStep(); } selectedWorkflow = formParams.getFirst(FORM_PARAM_SELECTED_WORKFLOW); @@ -255,24 +266,11 @@ public class MvcArticleCreateStep getBundle() ).getText("createstep.workflow.error.not_available") ); + return showCreateStep(); } if (!getMessages().isEmpty()) { - final String folderPath = getFolderPath(); - if (folderPath.isEmpty() || "/".equals(folderPath)) { - return String.format( - "/@contentsections/%s/documents/@create/%s", - getContentSectionLabel(), - getDocumentType().getName() - ); - } else { - return String.format( - "/@contentsections/%s/documents/%s/@create/%s", - getContentSectionLabel(), - folderPath, - getDocumentType().getName() - ); - } + return showCreateStep(); } final Article article = itemManager.createContentItem( @@ -296,4 +294,6 @@ public class MvcArticleCreateStep ); } + + } diff --git a/ccm-cms/src/main/resources/WEB-INF/views/org/librecms/ui/contentsection/documentfolder/documentfolder-not-found.xhtml b/ccm-cms/src/main/resources/WEB-INF/views/org/librecms/ui/contentsection/documentfolder/documentfolder-not-found.xhtml index 22f911fa4..c406353bb 100644 --- a/ccm-cms/src/main/resources/WEB-INF/views/org/librecms/ui/contentsection/documentfolder/documentfolder-not-found.xhtml +++ b/ccm-cms/src/main/resources/WEB-INF/views/org/librecms/ui/contentsection/documentfolder/documentfolder-not-found.xhtml @@ -4,7 +4,7 @@ xmlns:c="http://xmlns.jcp.org/jsp/jstl/core" xmlns:libreccm="http://xmlns.jcp.org/jsf/composite/components/libreccm" xmlns:ui="http://xmlns.jcp.org/jsf/facelets"> - + diff --git a/ccm-cms/src/main/resources/WEB-INF/views/org/librecms/ui/contenttypes/article/create-article.xhtml b/ccm-cms/src/main/resources/WEB-INF/views/org/librecms/ui/contenttypes/article/create-article.xhtml index aff9bdb22..80d54de34 100644 --- a/ccm-cms/src/main/resources/WEB-INF/views/org/librecms/ui/contenttypes/article/create-article.xhtml +++ b/ccm-cms/src/main/resources/WEB-INF/views/org/librecms/ui/contenttypes/article/create-article.xhtml @@ -7,71 +7,75 @@ - - - - - -
- - - - - - - +
+

#{CmsArticleMessageBundle['createform.title']}

- - - - #{CmsArticleMessageBundle['createform.cancel']} - - + + + - +
+ + + + + + + + + + + #{CmsArticleMessageBundle['createform.cancel']} + + + + +
diff --git a/ccm-cms/src/main/resources/org/librecms/ui/contenttypes/ArticleBundle.properties b/ccm-cms/src/main/resources/org/librecms/ui/contenttypes/ArticleBundle.properties index 9016c8a3b..487f551aa 100644 --- a/ccm-cms/src/main/resources/org/librecms/ui/contenttypes/ArticleBundle.properties +++ b/ccm-cms/src/main/resources/org/librecms/ui/contenttypes/ArticleBundle.properties @@ -28,3 +28,5 @@ basicproperties.name.header=Basic Properties basicproperties.name.edit=Edit basicproperties.title.header=Title basicproperties.description.header=Summary +createform.title=Create new article +createform.summary.label=Summary diff --git a/ccm-cms/src/main/resources/org/librecms/ui/contenttypes/ArticleBundle_de.properties b/ccm-cms/src/main/resources/org/librecms/ui/contenttypes/ArticleBundle_de.properties index 589d4e210..4f28e7a81 100644 --- a/ccm-cms/src/main/resources/org/librecms/ui/contenttypes/ArticleBundle_de.properties +++ b/ccm-cms/src/main/resources/org/librecms/ui/contenttypes/ArticleBundle_de.properties @@ -28,3 +28,5 @@ basicproperties.name.header=Basiseigenschaften basicproperties.name.edit=Bearbeiten basicproperties.title.header=Titel basicproperties.description.header=Zusammenfassung +createform.title=Neuen Artikel anlegen +createform.summary.label=Zusammenfassung