Create steps now working

pull/10/head
Jens Pelzetter 2021-04-15 21:14:47 +02:00
parent 2ab4b0c5ed
commit 9dc794a5fb
7 changed files with 30 additions and 34 deletions

View File

@ -18,20 +18,16 @@
*/ */
package org.librecms.ui.contentsections.documents; package org.librecms.ui.contentsections.documents;
import org.libreccm.api.IdentifierParser;
import org.libreccm.l10n.GlobalizationHelper; import org.libreccm.l10n.GlobalizationHelper;
import org.libreccm.l10n.LocalizedString; import org.libreccm.l10n.LocalizedString;
import org.librecms.contentsection.ContentItem; import org.librecms.contentsection.ContentItem;
import org.librecms.contentsection.ContentSection; import org.librecms.contentsection.ContentSection;
import org.librecms.contentsection.ContentSectionRepository;
import org.librecms.contentsection.Folder; import org.librecms.contentsection.Folder;
import org.librecms.contentsection.FolderManager; import org.librecms.contentsection.FolderManager;
import org.librecms.contentsection.FolderRepository;
import java.util.Collections; import java.util.Collections;
import java.util.LinkedHashMap; import java.util.LinkedHashMap;
import java.util.Map; import java.util.Map;
import java.util.NavigableMap;
import java.util.SortedMap; import java.util.SortedMap;
import java.util.TreeMap; import java.util.TreeMap;
import java.util.stream.Collectors; import java.util.stream.Collectors;

View File

@ -51,6 +51,7 @@ import javax.enterprise.util.AnnotationLiteral;
import javax.inject.Inject; import javax.inject.Inject;
import javax.mvc.Controller; import javax.mvc.Controller;
import javax.mvc.Models; import javax.mvc.Models;
import javax.servlet.http.HttpServletRequest;
import javax.transaction.Transactional; import javax.transaction.Transactional;
import javax.ws.rs.Consumes; import javax.ws.rs.Consumes;
import javax.ws.rs.DefaultValue; import javax.ws.rs.DefaultValue;
@ -59,9 +60,8 @@ import javax.ws.rs.GET;
import javax.ws.rs.POST; import javax.ws.rs.POST;
import javax.ws.rs.Path; import javax.ws.rs.Path;
import javax.ws.rs.PathParam; import javax.ws.rs.PathParam;
import javax.ws.rs.core.Form; import javax.ws.rs.core.Context;
import javax.ws.rs.core.MediaType; import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.MultivaluedMap;
/** /**
* Controller for the UI for managing documents ({@link ContentItem}s.) * Controller for the UI for managing documents ({@link ContentItem}s.)
@ -259,21 +259,19 @@ public class DocumentController {
@POST @POST
@Path("/@create/{documentType}") @Path("/@create/{documentType}")
@Consumes(MediaType.APPLICATION_FORM_URLENCODED)
@AuthorizationRequired @AuthorizationRequired
@Transactional(Transactional.TxType.REQUIRED) @Transactional(Transactional.TxType.REQUIRED)
public String createDocument( public String createDocument(
@PathParam("sectionIdentifier") final String sectionIdentifier, @PathParam("sectionIdentifier") final String sectionIdentifier,
@PathParam("documentType") final String documentType, @PathParam("documentType") final String documentType,
//final MultivaluedMap<String, String> formParameters @Context final HttpServletRequest request
final Form form
) { ) {
return createDocument( return createDocument(
sectionIdentifier, sectionIdentifier,
"", "",
documentType, documentType,
//formParameters //formParameters
form.asMap() request
); );
} }
@ -287,7 +285,7 @@ public class DocumentController {
@PathParam("sectionIdentifier") final String sectionIdentifier, @PathParam("sectionIdentifier") final String sectionIdentifier,
@PathParam("folderPath") final String folderPath, @PathParam("folderPath") final String folderPath,
@PathParam("documentType") final String documentType, @PathParam("documentType") final String documentType,
final MultivaluedMap<String, String> formParameters @Context final HttpServletRequest request
) { ) {
final CreateStepResult result = findCreateStep( final CreateStepResult result = findCreateStep(
sectionIdentifier, sectionIdentifier,
@ -295,7 +293,7 @@ public class DocumentController {
); );
if (result.isCreateStepAvailable()) { if (result.isCreateStepAvailable()) {
return result.getCreateStep().createItem(formParameters); return result.getCreateStep().createItem(request.getParameterMap());
} else { } else {
return result.getErrorTemplate(); return result.getErrorTemplate();
} }

View File

@ -26,7 +26,6 @@ import org.librecms.contentsection.Folder;
import java.util.Map; import java.util.Map;
import java.util.ResourceBundle; import java.util.ResourceBundle;
import javax.ws.rs.core.MultivaluedMap;
/** /**
* A create step for a document/content item. Implementing classes are MUST be * A create step for a document/content item. Implementing classes are MUST be
@ -63,7 +62,7 @@ public interface MvcDocumentCreateStep<T extends ContentItem> {
* *
* @return A redirect to the first authoring step of the new document. * @return A redirect to the first authoring step of the new document.
*/ */
String createItem(MultivaluedMap<String, String> formParams); String createItem(Map<String, String[]> formParams);
/** /**
* Should be set by the implementing class to indicate if the current user * Should be set by the implementing class to indicate if the current user

View File

@ -28,7 +28,9 @@ import org.librecms.contenttypes.Article;
import org.librecms.ui.contentsections.documents.AbstractMvcDocumentCreateStep; import org.librecms.ui.contentsections.documents.AbstractMvcDocumentCreateStep;
import org.librecms.ui.contentsections.documents.CreatesDocumentOfType; import org.librecms.ui.contentsections.documents.CreatesDocumentOfType;
import java.util.Arrays;
import java.util.Locale; import java.util.Locale;
import java.util.Map;
import java.util.Optional; import java.util.Optional;
import javax.enterprise.context.RequestScoped; import javax.enterprise.context.RequestScoped;
@ -37,7 +39,6 @@ import javax.inject.Named;
import javax.inject.Inject; import javax.inject.Inject;
import javax.mvc.Models; import javax.mvc.Models;
import javax.transaction.Transactional; import javax.transaction.Transactional;
import javax.ws.rs.core.MultivaluedMap;
/** /**
* Describes the create step for {@link Article}. * Describes the create step for {@link Article}.
@ -56,10 +57,10 @@ public class MvcArticleCreateStep
private static final String FORM_PARAM_SUMMARY = "summary"; private static final String FORM_PARAM_SUMMARY = "summary";
private static final String FORM_PARAM_INITIAL_LOCALE = "initialLocale"; private static final String FORM_PARAM_INITIAL_LOCALE = "locale";
private static final String FORM_PARAM_SELECTED_WORKFLOW private static final String FORM_PARAM_SELECTED_WORKFLOW
= "selectedWorkflow"; = "workflow";
/** /**
* Provides functions for working with content items. * Provides functions for working with content items.
@ -175,10 +176,10 @@ public class MvcArticleCreateStep
@AuthorizationRequired @AuthorizationRequired
@Transactional(Transactional.TxType.REQUIRED) @Transactional(Transactional.TxType.REQUIRED)
@Override @Override
public String createItem(final MultivaluedMap<String, String> formParams) { public String createItem(final Map<String, String[]> formParams) {
if (!formParams.containsKey(FORM_PARAM_NAME) if (!formParams.containsKey(FORM_PARAM_NAME)
|| formParams.getFirst(FORM_PARAM_NAME) == null || formParams.get(FORM_PARAM_NAME) == null
|| formParams.getFirst(FORM_PARAM_NAME).isEmpty()) { || formParams.get(FORM_PARAM_NAME).length == 0) {
addMessage( addMessage(
"danger", "danger",
globalizationHelper.getLocalizedTextsUtil( globalizationHelper.getLocalizedTextsUtil(
@ -188,7 +189,7 @@ public class MvcArticleCreateStep
return showCreateStep(); return showCreateStep();
} }
name = formParams.getFirst(FORM_PARAM_NAME); name = formParams.get(FORM_PARAM_NAME)[0];
if (!name.matches("^([a-zA-Z0-9_-]*)$")) { if (!name.matches("^([a-zA-Z0-9_-]*)$")) {
addMessage( addMessage(
"danger", "danger",
@ -200,8 +201,8 @@ public class MvcArticleCreateStep
} }
if (!formParams.containsKey(FORM_PARAM_TITLE) if (!formParams.containsKey(FORM_PARAM_TITLE)
|| formParams.getFirst(FORM_PARAM_TITLE) == null || formParams.get(FORM_PARAM_TITLE) == null
|| formParams.getFirst(FORM_PARAM_TITLE).isEmpty()) { || formParams.get(FORM_PARAM_TITLE).length == 0) {
addMessage( addMessage(
"danger", "danger",
globalizationHelper.getLocalizedTextsUtil( globalizationHelper.getLocalizedTextsUtil(
@ -210,11 +211,11 @@ public class MvcArticleCreateStep
); );
return showCreateStep(); return showCreateStep();
} }
title = formParams.getFirst(FORM_PARAM_TITLE); title = formParams.get(FORM_PARAM_TITLE)[0];
if (!formParams.containsKey(FORM_PARAM_SUMMARY) if (!formParams.containsKey(FORM_PARAM_SUMMARY)
|| formParams.getFirst(FORM_PARAM_SUMMARY) == null || formParams.get(FORM_PARAM_SUMMARY) == null
|| formParams.getFirst(FORM_PARAM_SUMMARY).isEmpty()) { || formParams.get(FORM_PARAM_SUMMARY).length == 0) {
addMessage( addMessage(
"danger", "danger",
globalizationHelper.getLocalizedTextsUtil( globalizationHelper.getLocalizedTextsUtil(
@ -223,11 +224,11 @@ public class MvcArticleCreateStep
); );
return showCreateStep(); return showCreateStep();
} }
summary = formParams.getFirst(FORM_PARAM_SUMMARY); summary = formParams.get(FORM_PARAM_SUMMARY)[0];
if (!formParams.containsKey(FORM_PARAM_INITIAL_LOCALE) if (!formParams.containsKey(FORM_PARAM_INITIAL_LOCALE)
|| formParams.getFirst(FORM_PARAM_INITIAL_LOCALE) == null || formParams.get(FORM_PARAM_INITIAL_LOCALE) == null
|| formParams.getFirst(FORM_PARAM_INITIAL_LOCALE).isEmpty()) { || formParams.get(FORM_PARAM_INITIAL_LOCALE).length == 0) {
addMessage( addMessage(
"danger", "danger",
globalizationHelper.getLocalizedTextsUtil( globalizationHelper.getLocalizedTextsUtil(
@ -237,12 +238,12 @@ public class MvcArticleCreateStep
return showCreateStep(); return showCreateStep();
} }
final Locale locale = new Locale( final Locale locale = new Locale(
formParams.getFirst(FORM_PARAM_INITIAL_LOCALE) formParams.get(FORM_PARAM_INITIAL_LOCALE)[0]
); );
if (!formParams.containsKey(FORM_PARAM_SELECTED_WORKFLOW) if (!formParams.containsKey(FORM_PARAM_SELECTED_WORKFLOW)
|| formParams.getFirst(FORM_PARAM_SELECTED_WORKFLOW) == null || formParams.get(FORM_PARAM_SELECTED_WORKFLOW) == null
|| formParams.getFirst(FORM_PARAM_SELECTED_WORKFLOW).isEmpty()) { || formParams.get(FORM_PARAM_SELECTED_WORKFLOW).length == 0) {
addMessage( addMessage(
"danger", "danger",
globalizationHelper.getLocalizedTextsUtil( globalizationHelper.getLocalizedTextsUtil(
@ -251,7 +252,7 @@ public class MvcArticleCreateStep
); );
return showCreateStep(); return showCreateStep();
} }
selectedWorkflow = formParams.getFirst(FORM_PARAM_SELECTED_WORKFLOW); selectedWorkflow = formParams.get(FORM_PARAM_SELECTED_WORKFLOW)[0];
final Optional<Workflow> workflowResult = getContentSection() final Optional<Workflow> workflowResult = getContentSection()
.getWorkflowTemplates() .getWorkflowTemplates()

View File

@ -10,7 +10,7 @@
<div class="container"> <div class="container">
<h1>#{CmsArticleMessageBundle['createform.title']}</h1> <h1>#{CmsArticleMessageBundle['createform.title']}</h1>
<c:forEach items="#{CmsArticleCreateStep.messages.entrySet}" <c:forEach items="#{CmsArticleCreateStep.messages.entrySet()}"
var="message"> var="message">
<div class="alert alert-#{message.key}" role="alert"> <div class="alert alert-#{message.key}" role="alert">
#{message.value} #{message.value}

View File

@ -30,3 +30,4 @@ basicproperties.title.header=Title
basicproperties.description.header=Summary basicproperties.description.header=Summary
createform.title=Create new article createform.title=Create new article
createform.summary.label=Summary createform.summary.label=Summary
createstep.workflow.none_selected=No workflow selected

View File

@ -30,3 +30,4 @@ basicproperties.title.header=Titel
basicproperties.description.header=Zusammenfassung basicproperties.description.header=Zusammenfassung
createform.title=Neuen Artikel anlegen createform.title=Neuen Artikel anlegen
createform.summary.label=Zusammenfassung createform.summary.label=Zusammenfassung
createstep.workflow.none_selected=Es wurde keine Arbeitsablauf ausgew\u00e4hlt