From 1abf3d96a1b7e830ad8e806680c7730ff5a6088a Mon Sep 17 00:00:00 2001 From: Jens Pelzetter Date: Tue, 4 May 2021 20:37:32 +0200 Subject: [PATCH] Some bugfixing --- .../documents/AbstractMvcAuthoringStep.java | 70 +++++++------------ .../contenttypes/MvcArticleTextBodyStep.java | 56 +++++++++------ .../documents/authoringstep.xhtml | 10 +-- .../contenttypes/article/article-text.xhtml | 36 +++++----- 4 files changed, 81 insertions(+), 91 deletions(-) diff --git a/ccm-cms/src/main/java/org/librecms/ui/contentsections/documents/AbstractMvcAuthoringStep.java b/ccm-cms/src/main/java/org/librecms/ui/contentsections/documents/AbstractMvcAuthoringStep.java index 2d3cba3db..46446278f 100644 --- a/ccm-cms/src/main/java/org/librecms/ui/contentsections/documents/AbstractMvcAuthoringStep.java +++ b/ccm-cms/src/main/java/org/librecms/ui/contentsections/documents/AbstractMvcAuthoringStep.java @@ -87,6 +87,8 @@ public abstract class AbstractMvcAuthoringStep implements MvcAuthoringStep { private ContentItem document; private String documentPath; + + private String stepPath; /** * Inits the step. This method MUST be called by all resource methods (all @@ -128,8 +130,29 @@ public abstract class AbstractMvcAuthoringStep implements MvcAuthoringStep { documentModel.setContentItem(document); this.documentPath = itemManager.getItemPath(document); + final Map values = new HashMap<>(); + values.put( + MvcAuthoringSteps.SECTION_IDENTIFIER_PATH_PARAM, + contentSection.getLabel() + ); + values.put( + MvcAuthoringSteps.DOCUMENT_PATH_PATH_PARAM_NAME, + documentPath + ); + + stepPath = Optional + .ofNullable(getStepClass().getAnnotation(Path.class)) + .map(Path::value) + .map( + path -> UriBuilder + .fromPath(path) + .buildFromMap(values) + .toString() + ) + .orElse(""); models.put("activeDocumentTab", "editTab"); + models.put("stepPath", stepPath); } @Override @@ -229,52 +252,7 @@ public abstract class AbstractMvcAuthoringStep implements MvcAuthoringStep { @Override public String getStepPath() { - final ContentSection section = Optional - .ofNullable(contentSection) - .orElseThrow( - () -> new WebApplicationException( - String.format( - "Authoring Step %s was not initalized properly. " - + "Did you forget to call %s#init()?", - getStepClass().getName(), - AbstractMvcAuthoringStep.class.getName() - ) - ) - ); - final String docPath = Optional - .ofNullable(documentPath) - .map(this::withoutLeadingSlash) - .orElseThrow( - () -> new WebApplicationException( - String.format( - "Authoring Step %s was not initalized properly. " - + "Did you forget to call %s#init()?", - getStepClass().getName(), - AbstractMvcAuthoringStep.class.getName() - ) - ) - ); - - final Map values = new HashMap<>(); - values.put( - MvcAuthoringSteps.SECTION_IDENTIFIER_PATH_PARAM, - section.getLabel() - ); - values.put( - MvcAuthoringSteps.DOCUMENT_PATH_PATH_PARAM_NAME, - docPath - ); - - return Optional - .ofNullable(getStepClass().getAnnotation(Path.class)) - .map(Path::value) - .map( - path -> UriBuilder - .fromPath(path) - .buildFromMap(values) - .toString() - ) - .orElse(""); + return stepPath; } @Override diff --git a/ccm-cms/src/main/java/org/librecms/ui/contenttypes/MvcArticleTextBodyStep.java b/ccm-cms/src/main/java/org/librecms/ui/contenttypes/MvcArticleTextBodyStep.java index 320f90d97..ac0bd3939 100644 --- a/ccm-cms/src/main/java/org/librecms/ui/contenttypes/MvcArticleTextBodyStep.java +++ b/ccm-cms/src/main/java/org/librecms/ui/contenttypes/MvcArticleTextBodyStep.java @@ -50,13 +50,15 @@ import javax.ws.rs.PathParam; import org.librecms.ui.contentsections.documents.MvcAuthoringStepDef; +import java.util.Collections; + /** * Authoring step for editing the main text of an {@link Article}. * * @author Jens Pelzetter */ @RequestScoped -@Path(MvcAuthoringSteps.PATH_PREFIX + "text") +@Path(MvcAuthoringSteps.PATH_PREFIX + "article-text") @Controller @Named("CmsArticleTextBodyStep") @MvcAuthoringStepDef( @@ -88,11 +90,15 @@ public class MvcArticleTextBodyStep extends AbstractMvcAuthoringStep { @Inject private ItemPermissionChecker itemPermissionChecker; + private Map textValues; + + private List unusedLocales; + @Override public Class getStepClass() { return MvcArticleTextBodyStep.class; } - + @GET @Path("/") @Transactional(Transactional.TxType.REQUIRED) @@ -111,6 +117,28 @@ public class MvcArticleTextBodyStep extends AbstractMvcAuthoringStep { } if (itemPermissionChecker.canEditItem(getArticle())) { + textValues = getArticle() + .getText() + .getValues() + .entrySet() + .stream() + .collect( + Collectors.toMap( + entry -> entry.getKey().toString(), + entry -> entry.getValue() + ) + ); + + final Set locales = getArticle() + .getText() + .getAvailableLocales(); + unusedLocales = globalizationHelper + .getAvailableLocales() + .stream() + .filter(locale -> !locales.contains(locale)) + .map(Locale::toString) + .collect(Collectors.toList()); + return "org/librecms/ui/contenttypes/article/article-text.xhtml"; } else { return documentUi.showAccessDenied( @@ -127,17 +155,7 @@ public class MvcArticleTextBodyStep extends AbstractMvcAuthoringStep { * @return The localized values of the main text. */ public Map getTextValues() { - return getArticle() - .getText() - .getValues() - .entrySet() - .stream() - .collect( - Collectors.toMap( - entry -> entry.getKey().toString(), - entry -> entry.getValue() - ) - ); + return Collections.unmodifiableMap(textValues); } /** @@ -146,15 +164,7 @@ public class MvcArticleTextBodyStep extends AbstractMvcAuthoringStep { * @return The locales for which the main text has not been defined yet. */ public List getUnusedLocales() { - final Set locales = getArticle() - .getText() - .getAvailableLocales(); - return globalizationHelper - .getAvailableLocales() - .stream() - .filter(locale -> !locales.contains(locale)) - .map(Locale::toString) - .collect(Collectors.toList()); + return Collections.unmodifiableList(unusedLocales); } /** @@ -257,7 +267,7 @@ public class MvcArticleTextBodyStep extends AbstractMvcAuthoringStep { @POST @Path("/@remove/{locale}") @Transactional(Transactional.TxType.REQUIRED) - public String remvoeTextValue( + public String removeTextValue( @PathParam(MvcAuthoringSteps.SECTION_IDENTIFIER_PATH_PARAM) final String sectionIdentifier, @PathParam(MvcAuthoringSteps.DOCUMENT_PATH_PATH_PARAM_NAME) diff --git a/ccm-cms/src/main/resources/WEB-INF/views/org/librecms/ui/contentsection/documents/authoringstep.xhtml b/ccm-cms/src/main/resources/WEB-INF/views/org/librecms/ui/contentsection/documents/authoringstep.xhtml index aaf8c8db7..8fa1f5634 100644 --- a/ccm-cms/src/main/resources/WEB-INF/views/org/librecms/ui/contentsection/documents/authoringstep.xhtml +++ b/ccm-cms/src/main/resources/WEB-INF/views/org/librecms/ui/contentsection/documents/authoringstep.xhtml @@ -46,7 +46,7 @@ method="post"> + value="#{stepPath}" />