From 83e65415de8c5449d8096ff7cd94f826959c32aa Mon Sep 17 00:00:00 2001 From: Jens Pelzetter Date: Sat, 22 May 2021 16:54:54 +0200 Subject: [PATCH] MVC Controllers should be named beans --- .../assets/AbstractMvcAssetEditStep.java | 64 ++--- .../assets/MvcAssetEditStepModel.java | 80 ++++++ .../assets/PostalAddressEditStep.java | 100 +++++--- .../assets/PostalAddressEditStepModel.java | 106 ++++++++ .../assets/SideNoteEditStep.java | 109 +++++---- .../assets/SideNoteEditStepModel.java | 70 ++++++ .../documents/PublishStepModel.java | 2 +- .../MvcArticlePropertiesStep.java | 229 ++++++++++-------- .../MvcArticlePropertiesStepModel.java | 104 ++++++++ .../contenttypes/MvcArticleTextBodyStep.java | 129 +++++----- .../MvcArticleTextBodyStepModel.java | 102 ++++++++ .../postaladdress/edit-postaladdress.xhtml | 20 +- .../assets/sidenote/edit-sidenote.xhtml | 30 +-- 13 files changed, 845 insertions(+), 300 deletions(-) create mode 100644 ccm-cms/src/main/java/org/librecms/ui/contentsections/assets/MvcAssetEditStepModel.java create mode 100644 ccm-cms/src/main/java/org/librecms/ui/contentsections/assets/PostalAddressEditStepModel.java create mode 100644 ccm-cms/src/main/java/org/librecms/ui/contentsections/assets/SideNoteEditStepModel.java create mode 100644 ccm-cms/src/main/java/org/librecms/ui/contenttypes/MvcArticlePropertiesStepModel.java create mode 100644 ccm-cms/src/main/java/org/librecms/ui/contenttypes/MvcArticleTextBodyStepModel.java diff --git a/ccm-cms/src/main/java/org/librecms/ui/contentsections/assets/AbstractMvcAssetEditStep.java b/ccm-cms/src/main/java/org/librecms/ui/contentsections/assets/AbstractMvcAssetEditStep.java index 0eeaa48ce..3bb2f76d6 100644 --- a/ccm-cms/src/main/java/org/librecms/ui/contentsections/assets/AbstractMvcAssetEditStep.java +++ b/ccm-cms/src/main/java/org/librecms/ui/contentsections/assets/AbstractMvcAssetEditStep.java @@ -88,6 +88,9 @@ public abstract class AbstractMvcAssetEditStep implements MvcAssetEditStep { @Inject private Models models; + @Inject + private MvcAssetEditStepModel mvcAssetEditStepModel; + @Inject private SelectedAssetModel assetModel; @@ -105,10 +108,9 @@ public abstract class AbstractMvcAssetEditStep implements MvcAssetEditStep { private String stepPath; - private Map titleValues; - - private List unusedTitleLocales; - +// private Map titleValues; +// +// private List unusedTitleLocales; protected void init() throws ContentSectionNotFoundException, AssetNotFoundException { contentSection = sectionsUi @@ -162,28 +164,35 @@ public abstract class AbstractMvcAssetEditStep implements MvcAssetEditStep { ) .orElse(""); - titleValues = getAsset() - .getTitle() - .getValues() - .entrySet() - .stream() - .collect( - Collectors.toMap( - entry -> entry.getKey().toString(), - entry -> entry.getValue() + mvcAssetEditStepModel.setName(getName()); + mvcAssetEditStepModel.setCanEdit(getCanEdit()); + + mvcAssetEditStepModel.setTitleValues( + getAsset() + .getTitle() + .getValues() + .entrySet() + .stream() + .collect( + Collectors.toMap( + entry -> entry.getKey().toString(), + entry -> entry.getValue() + ) ) - ); + ); final Set titleLocales = getAsset() .getTitle() .getAvailableLocales(); - unusedTitleLocales = globalizationHelper - .getAvailableLocales() - .stream() - .filter(locale -> !titleLocales.contains(locale)) - .map(Locale::toString) - .collect(Collectors.toList()); + mvcAssetEditStepModel.setUnusedTitleLocales( + globalizationHelper + .getAvailableLocales() + .stream() + .filter(locale -> !titleLocales.contains(locale)) + .map(Locale::toString) + .collect(Collectors.toList()) + ); models.put("activeAssetTab", "editTab"); models.put("stepPath", stepPath); @@ -397,14 +406,13 @@ public abstract class AbstractMvcAssetEditStep implements MvcAssetEditStep { } } - public Map getTitleValues() { - return Collections.unmodifiableMap(titleValues); - } - - public List getUnusedTitleLocales() { - return Collections.unmodifiableList(unusedTitleLocales); - } - +// public Map getTitleValues() { +// return Collections.unmodifiableMap(titleValues); +// } +// +// public List getUnusedTitleLocales() { +// return Collections.unmodifiableList(unusedTitleLocales); +// } @POST @Path("/title/@add") @AuthorizationRequired diff --git a/ccm-cms/src/main/java/org/librecms/ui/contentsections/assets/MvcAssetEditStepModel.java b/ccm-cms/src/main/java/org/librecms/ui/contentsections/assets/MvcAssetEditStepModel.java new file mode 100644 index 000000000..3ca936154 --- /dev/null +++ b/ccm-cms/src/main/java/org/librecms/ui/contentsections/assets/MvcAssetEditStepModel.java @@ -0,0 +1,80 @@ +/* + * Copyright (C) 2021 LibreCCM Foundation. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, + * MA 02110-1301 USA + */ +package org.librecms.ui.contentsections.assets; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import javax.enterprise.context.RequestScoped; +import javax.inject.Named; + +/** + * + * @author Jens Pelzetter + */ +@RequestScoped +@Named("MvcAssetEditStepModel") +public class MvcAssetEditStepModel { + + private boolean canEdit; + + private String name; + + private Map titleValues; + + private List unusedTitleLocales; + + public boolean getCanEdit() { + return canEdit; + } + + protected void setCanEdit(final boolean canEdit) { + this.canEdit = canEdit; + } + + public String getName() { + return name; + } + + protected void setName(final String name) { + this.name = name; + } + + public Map getTitleValues() { + return Collections.unmodifiableMap(titleValues); + } + + protected void setTitleValues(final Map titleValues) { + this.titleValues = new HashMap<>(titleValues); + } + + public List getUnusedTitleLocales() { + return Collections.unmodifiableList(unusedTitleLocales); + } + + protected void setUnusedTitleLocales( + final List unusedTitleLocales + ) { + this.unusedTitleLocales = new ArrayList<>(unusedTitleLocales); + } + +} diff --git a/ccm-cms/src/main/java/org/librecms/ui/contentsections/assets/PostalAddressEditStep.java b/ccm-cms/src/main/java/org/librecms/ui/contentsections/assets/PostalAddressEditStep.java index b96b82d38..0c66e9fce 100644 --- a/ccm-cms/src/main/java/org/librecms/ui/contentsections/assets/PostalAddressEditStep.java +++ b/ccm-cms/src/main/java/org/librecms/ui/contentsections/assets/PostalAddressEditStep.java @@ -30,12 +30,12 @@ import java.util.LinkedHashMap; import java.util.LinkedHashSet; import java.util.Locale; import java.util.Map; +import java.util.Optional; import java.util.Set; import java.util.stream.Collectors; import javax.enterprise.context.RequestScoped; import javax.inject.Inject; -import javax.inject.Named; import javax.mvc.Controller; import javax.mvc.Models; import javax.transaction.Transactional; @@ -52,7 +52,6 @@ import javax.ws.rs.PathParam; @RequestScoped @Path(MvcAssetEditSteps.PATH_PREFIX + "postaladdress-edit") @Controller -@Named("CmsPostalAddressEditStep") @MvcAssetEditStepDef( bundle = MvcAssetStepsConstants.BUNDLE, descriptionKey = "postaladdress.editstep.description", @@ -76,11 +75,13 @@ public class PostalAddressEditStep extends AbstractMvcAssetEditStep { @Inject private AssetPermissionsChecker assetPermissionsChecker; + @Inject + private PostalAddressEditStepModel postalAddressEditStepModel; + @Inject private Models models; - private Map countries; - +// private Map countries; @Override public Class getStepClass() { return PostalAddressEditStep.class; @@ -118,9 +119,32 @@ public class PostalAddressEditStep extends AbstractMvcAssetEditStep { ) ); - countries = new LinkedHashMap<>(); + final Map countries = new LinkedHashMap<>(); countries.put("", ""); countries.putAll(countriesMap); + postalAddressEditStepModel.setCountries(countries); + + postalAddressEditStepModel.setAddress(getPostalAddress().getAddress()); + postalAddressEditStepModel.setPostalCode( + getPostalAddress().getPostalCode() + ); + postalAddressEditStepModel.setCity(getPostalAddress().getCity()); + postalAddressEditStepModel.setState(postalAddressEditStepModel + .getState() + ); + postalAddressEditStepModel.setIsoCountryCode( + getPostalAddress().getIsoCountryCode() + ); + postalAddressEditStepModel.setCountry( + Optional + .ofNullable(getPostalAddress().getIsoCountryCode()) + .map(code -> new Locale("", code)) + .map( + locale -> locale.getDisplayCountry( + globalizationHelper.getNegotiatedLocale() + ) + ).orElse("") + ); } @GET @@ -160,34 +184,34 @@ public class PostalAddressEditStep extends AbstractMvcAssetEditStep { return (PostalAddress) getAsset(); } - public String getAddress() { - return getPostalAddress().getAddress(); - } - - public String getPostalCode() { - return getPostalAddress().getPostalCode(); - } - - public String getCity() { - return getPostalAddress().getCity(); - } - - public String getState() { - return getPostalAddress().getState(); - } - - public String getIsoCountryCode() { - return getPostalAddress().getIsoCountryCode(); - } - - public String getCountry() { - if (getPostalAddress().getIsoCountryCode() == null) { - return ""; - } else { - return new Locale("", getPostalAddress().getIsoCountryCode()) - .getDisplayCountry(globalizationHelper.getNegotiatedLocale()); - } - } +// public String getAddress() { +// return getPostalAddress().getAddress(); +// } +// +// public String getPostalCode() { +// return getPostalAddress().getPostalCode(); +// } +// +// public String getCity() { +// return getPostalAddress().getCity(); +// } +// +// public String getState() { +// return getPostalAddress().getState(); +// } +// +// public String getIsoCountryCode() { +// return getPostalAddress().getIsoCountryCode(); +// } +// +// public String getCountry() { +// if (getPostalAddress().getIsoCountryCode() == null) { +// return ""; +// } else { +// return new Locale("", getPostalAddress().getIsoCountryCode()) +// .getDisplayCountry(globalizationHelper.getNegotiatedLocale()); +// } +// } @POST @Path("/properties") @@ -231,10 +255,10 @@ public class PostalAddressEditStep extends AbstractMvcAssetEditStep { } } - public Map getCountries() { - final LinkedHashMap result = new LinkedHashMap<>(); - result.putAll(countries); - return result; - } +// public Map getCountries() { +// final LinkedHashMap result = new LinkedHashMap<>(); +// result.putAll(countries); +// return result; +// } } diff --git a/ccm-cms/src/main/java/org/librecms/ui/contentsections/assets/PostalAddressEditStepModel.java b/ccm-cms/src/main/java/org/librecms/ui/contentsections/assets/PostalAddressEditStepModel.java new file mode 100644 index 000000000..f5f4c3d25 --- /dev/null +++ b/ccm-cms/src/main/java/org/librecms/ui/contentsections/assets/PostalAddressEditStepModel.java @@ -0,0 +1,106 @@ +/* + * Copyright (C) 2021 LibreCCM Foundation. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, + * MA 02110-1301 USA + */ +package org.librecms.ui.contentsections.assets; + +import java.util.Collections; +import java.util.HashMap; +import java.util.Map; + +import javax.enterprise.context.RequestScoped; +import javax.inject.Named; + +/** + * + * @author Jens Pelzetter + */ +@RequestScoped +@Named("CmsPostalAddressEditStep") +public class PostalAddressEditStepModel { + + private String address; + + private String postalCode; + + private String city; + + private String state; + + private String isoCountryCode; + + private String country; + + private Map countries; + + public String getAddress() { + return address; + } + + protected void setAddress(final String address) { + this.address = address; + } + + public String getPostalCode() { + return postalCode; + } + + protected void setPostalCode(final String postalCode) { + this.postalCode = postalCode; + } + + public String getCity() { + return city; + } + + protected void setCity(final String city) { + this.city = city; + } + + public String getState() { + return state; + } + + protected void setState(final String state) { + this.state = state; + } + + public String getIsoCountryCode() { + return isoCountryCode; + } + + protected void setIsoCountryCode(final String isoCountryCode) { + this.isoCountryCode = isoCountryCode; + } + + public String getCountry() { + return country; + } + + protected void setCountry(final String country) { + this.country = country; + } + + public Map getCountries() { + return Collections.unmodifiableMap(countries); + } + + public void setCountries(final Map countries) { + this.countries = new HashMap<>(countries); + } + +} diff --git a/ccm-cms/src/main/java/org/librecms/ui/contentsections/assets/SideNoteEditStep.java b/ccm-cms/src/main/java/org/librecms/ui/contentsections/assets/SideNoteEditStep.java index b48ddc73b..a23823953 100644 --- a/ccm-cms/src/main/java/org/librecms/ui/contentsections/assets/SideNoteEditStep.java +++ b/ccm-cms/src/main/java/org/librecms/ui/contentsections/assets/SideNoteEditStep.java @@ -38,7 +38,6 @@ import java.util.stream.Collectors; import javax.enterprise.context.RequestScoped; import javax.inject.Inject; -import javax.inject.Named; import javax.mvc.Controller; import javax.transaction.Transactional; import javax.ws.rs.FormParam; @@ -54,7 +53,6 @@ import javax.ws.rs.PathParam; @RequestScoped @Path(MvcAssetEditSteps.PATH_PREFIX + "sidenote-edit") @Controller -@Named("CmsSideNoteEditStep") @MvcAssetEditStepDef( bundle = MvcAssetStepsConstants.BUNDLE, descriptionKey = "postaladdress.editstep.description", @@ -78,17 +76,61 @@ public class SideNoteEditStep extends AbstractMvcAssetEditStep { @Inject private AssetPermissionsChecker assetPermissionsChecker; - private Map textValues; - - private List variants; - - private List unusedTextLocales; + @Inject + private SideNoteEditStepModel sideNoteEditStepModel; +// private Map textValues; +// +// private List variants; +// +// private List unusedTextLocales; @Override public Class getStepClass() { return SideNoteEditStep.class; } + @Override + protected void init() throws ContentSectionNotFoundException, + AssetNotFoundException { + super.init(); + + sideNoteEditStepModel.setTextValues( + getSideNote() + .getText() + .getValues() + .entrySet() + .stream() + .collect( + Collectors.toMap( + entry -> entry.getKey().toString(), + entry -> entry.getValue() + ) + ) + ); + + final Set textLocales = getSideNote() + .getText() + .getAvailableLocales(); + sideNoteEditStepModel.setUnusedTextLocales( + globalizationHelper + .getAvailableLocales() + .stream() + .filter(locale -> !textLocales.contains(locale)) + .map(Locale::toString) + .collect(Collectors.toList()) + ); + + sideNoteEditStepModel.setVariants( + getSideNote() + .getText() + .getValues() + .entrySet() + .stream() + .map(this::buildVariantRow) + .collect(Collectors.toList()) + ); + } + @GET @Path("/") @AuthorizationRequired @@ -109,35 +151,6 @@ public class SideNoteEditStep extends AbstractMvcAssetEditStep { } if (assetPermissionsChecker.canEditAsset(getAsset())) { - textValues = getSideNote() - .getText() - .getValues() - .entrySet() - .stream() - .collect( - Collectors.toMap( - entry -> entry.getKey().toString(), - entry -> entry.getValue() - ) - ); - - final Set textLocales = getSideNote() - .getText() - .getAvailableLocales(); - unusedTextLocales = globalizationHelper - .getAvailableLocales() - .stream() - .filter(locale -> !textLocales.contains(locale)) - .map(Locale::toString) - .collect(Collectors.toList()); - - variants = getSideNote() - .getText() - .getValues() - .entrySet() - .stream() - .map(this::buildVariantRow) - .collect(Collectors.toList()); return "org/librecms/ui/contentsection/assets/sidenote/edit-sidenote.xhtml"; } else { @@ -151,18 +164,18 @@ public class SideNoteEditStep extends AbstractMvcAssetEditStep { public SideNote getSideNote() { return (SideNote) getAsset(); } - - public Map getTextValues() { - return Collections.unmodifiableMap(textValues); - } - - public List getVariants() { - return Collections.unmodifiableList(variants); - } - - public List getUnusedTextLocales() { - return Collections.unmodifiableList(unusedTextLocales); - } +// +// public Map getTextValues() { +// return Collections.unmodifiableMap(textValues); +// } +// +// public List getVariants() { +// return Collections.unmodifiableList(variants); +// } +// +// public List getUnusedTextLocales() { +// return Collections.unmodifiableList(unusedTextLocales); +// } @POST @Path("/text/add") diff --git a/ccm-cms/src/main/java/org/librecms/ui/contentsections/assets/SideNoteEditStepModel.java b/ccm-cms/src/main/java/org/librecms/ui/contentsections/assets/SideNoteEditStepModel.java new file mode 100644 index 000000000..d324aa5cc --- /dev/null +++ b/ccm-cms/src/main/java/org/librecms/ui/contentsections/assets/SideNoteEditStepModel.java @@ -0,0 +1,70 @@ +/* + * Copyright (C) 2021 LibreCCM Foundation. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, + * MA 02110-1301 USA + */ +package org.librecms.ui.contentsections.assets; + +import org.librecms.ui.contentsections.documents.CmsEditorLocaleVariantRow; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import javax.enterprise.context.RequestScoped; +import javax.inject.Named; + +/** + * + * @author Jens Pelzetter + */ +@RequestScoped +@Named("CmsSideNoteEditStep") +public class SideNoteEditStepModel { + + private Map textValues; + + private List variants; + + private List unusedTextLocales; + + public Map getTextValues() { + return Collections.unmodifiableMap(textValues); + } + + protected void setTextValues(final Map textValues) { + this.textValues = new HashMap<>(textValues); + } + + public List getVariants() { + return Collections.unmodifiableList(variants); + } + + protected void setVariants(final List variants) { + this.variants = new ArrayList<>(variants); + } + + public List getUnusedTextLocales() { + return Collections.unmodifiableList(unusedTextLocales); + } + + protected void setUnusedTextLocales(final List unusedTextLocales) { + this.unusedTextLocales = new ArrayList<>(unusedTextLocales); + } + +} diff --git a/ccm-cms/src/main/java/org/librecms/ui/contentsections/documents/PublishStepModel.java b/ccm-cms/src/main/java/org/librecms/ui/contentsections/documents/PublishStepModel.java index 5759d0b4a..0018088d0 100644 --- a/ccm-cms/src/main/java/org/librecms/ui/contentsections/documents/PublishStepModel.java +++ b/ccm-cms/src/main/java/org/librecms/ui/contentsections/documents/PublishStepModel.java @@ -92,7 +92,7 @@ public class PublishStepModel { return assignedLifecycleDescription; } - protected void setAssignedLifecylceDescription( + protected void setAssignedLifecycleDescription( final String assignedLifecycleDescription ) { this.assignedLifecycleDescription = assignedLifecycleDescription; diff --git a/ccm-cms/src/main/java/org/librecms/ui/contenttypes/MvcArticlePropertiesStep.java b/ccm-cms/src/main/java/org/librecms/ui/contenttypes/MvcArticlePropertiesStep.java index 24a2fc693..ee3e10c79 100644 --- a/ccm-cms/src/main/java/org/librecms/ui/contenttypes/MvcArticlePropertiesStep.java +++ b/ccm-cms/src/main/java/org/librecms/ui/contenttypes/MvcArticlePropertiesStep.java @@ -33,15 +33,11 @@ import org.librecms.ui.contentsections.documents.DocumentUi; import org.librecms.ui.contentsections.documents.MvcAuthoringStepDef; import org.librecms.ui.contentsections.documents.MvcAuthoringSteps; -import java.util.Collections; - import javax.enterprise.context.RequestScoped; import javax.inject.Inject; import javax.ws.rs.Path; -import java.util.List; import java.util.Locale; -import java.util.Map; import java.util.Set; import java.util.stream.Collectors; @@ -63,7 +59,6 @@ import javax.ws.rs.PathParam; @RequestScoped @Path(MvcAuthoringSteps.PATH_PREFIX + "article-basicproperties") @Controller -@Named("CmsArticlePropertiesStep") @MvcAuthoringStepDef( bundle = ArticleStepsConstants.BUNDLE, descriptionKey = "authoringsteps.basicproperties.description", @@ -105,22 +100,90 @@ public class MvcArticlePropertiesStep extends AbstractMvcAuthoringStep { @Inject private ItemPermissionChecker itemPermissionChecker; + @Inject + private MvcArticlePropertiesStepModel articlePropertiesStepModel; + @Inject private Models models; - private Map titleValues; - - private List unusedTitleLocales; - - private Map descriptionValues; - - private List unusedDescriptionLocales; +// private Map titleValues; +// +// private List unusedTitleLocales; +// +// private Map descriptionValues; +// +// private List unusedDescriptionLocales; @Override public Class getStepClass() { return MvcArticlePropertiesStep.class; } + @Override + @Transactional(Transactional.TxType.REQUIRED) + protected void init() throws ContentSectionNotFoundException, + DocumentNotFoundException { + super.init(); + + articlePropertiesStepModel.setName(getDocument().getDisplayName()); + + articlePropertiesStepModel.setCanEdit(getCanEdit()); + + final Set titleLocales = getDocument() + .getTitle() + .getAvailableLocales(); + + articlePropertiesStepModel.setTitleValues( + getDocument() + .getTitle() + .getValues() + .entrySet() + .stream() + .collect( + Collectors.toMap( + entry -> entry.getKey().toString(), + entry -> entry.getValue() + ) + ) + ); + + articlePropertiesStepModel.setUnusedTitleLocales( + globalizationHelper + .getAvailableLocales() + .stream() + .filter(locale -> !titleLocales.contains(locale)) + .map(Locale::toString) + .collect(Collectors.toList()) + ); + + articlePropertiesStepModel.setDescriptionValues( + getDocument() + .getDescription() + .getValues() + .entrySet() + .stream() + .collect( + Collectors.toMap( + entry -> entry.getKey().toString(), + entry -> entry.getValue() + ) + ) + ); + + final Set descriptionLocales = getDocument() + .getDescription() + .getAvailableLocales(); + + articlePropertiesStepModel.setUnusedDescriptionLocales( + globalizationHelper + .getAvailableLocales() + .stream() + .filter(locale -> !descriptionLocales.contains(locale)) + .map(Locale::toString) + .collect(Collectors.toList()) + ); + } + @GET @Path("/") @AuthorizationRequired @@ -140,52 +203,51 @@ public class MvcArticlePropertiesStep extends AbstractMvcAuthoringStep { } if (itemPermissionChecker.canEditItem(getDocument())) { - titleValues = getDocument() - .getTitle() - .getValues() - .entrySet() - .stream() - .collect( - Collectors.toMap( - entry -> entry.getKey().toString(), - entry -> entry.getValue() - ) - ); - - final Set titleLocales = getDocument() - .getTitle() - .getAvailableLocales(); - - unusedTitleLocales = globalizationHelper - .getAvailableLocales() - .stream() - .filter(locale -> !titleLocales.contains(locale)) - .map(Locale::toString) - .collect(Collectors.toList()); - - descriptionValues = getDocument() - .getDescription() - .getValues() - .entrySet() - .stream() - .collect( - Collectors.toMap( - entry -> entry.getKey().toString(), - entry -> entry.getValue() - ) - ); - - final Set descriptionLocales = getDocument() - .getDescription() - .getAvailableLocales(); - - unusedDescriptionLocales = globalizationHelper - .getAvailableLocales() - .stream() - .filter(locale -> !descriptionLocales.contains(locale)) - .map(Locale::toString) - .collect(Collectors.toList()); +// titleValues = getDocument() +// .getTitle() +// .getValues() +// .entrySet() +// .stream() +// .collect( +// Collectors.toMap( +// entry -> entry.getKey().toString(), +// entry -> entry.getValue() +// ) +// ); +// final Set titleLocales = getDocument() +// .getTitle() +// .getAvailableLocales(); +// +// unusedTitleLocales = globalizationHelper +// .getAvailableLocales() +// .stream() +// .filter(locale -> !titleLocales.contains(locale)) +// .map(Locale::toString) +// .collect(Collectors.toList()); +// +// descriptionValues = getDocument() +// .getDescription() +// .getValues() +// .entrySet() +// .stream() +// .collect( +// Collectors.toMap( +// entry -> entry.getKey().toString(), +// entry -> entry.getValue() +// ) +// ); +// +// final Set descriptionLocales = getDocument() +// .getDescription() +// .getAvailableLocales(); +// +// unusedDescriptionLocales = globalizationHelper +// .getAvailableLocales() +// .stream() +// .filter(locale -> !descriptionLocales.contains(locale)) +// .map(Locale::toString) +// .collect(Collectors.toList()); return "org/librecms/ui/contenttypes/article/article-basic-properties.xhtml"; } else { return documentUi.showAccessDenied( @@ -197,14 +259,14 @@ public class MvcArticlePropertiesStep extends AbstractMvcAuthoringStep { } - /** - * Gets the display name of the current article. - * - * @return The display name of the current article. - */ - public String getName() { - return getDocument().getDisplayName(); - } +// /** +// * Gets the display name of the current article. +// * +// * @return The display name of the current article. +// */ +// public String getName() { +// return getDocument().getDisplayName(); +// } /** * Updates the name of the current article. @@ -256,23 +318,7 @@ public class MvcArticlePropertiesStep extends AbstractMvcAuthoringStep { } } - /** - * Get the values of the localized title of the article. - * - * @return The values of the localized title of the article. - */ - public Map getTitleValues() { - return Collections.unmodifiableMap(titleValues); - } - - /** - * Get the locales for which no localized title has been defined yet. - * - * @return The locales for which no localized title has been defined yet. - */ - public List getUnusedTitleLocales() { - return Collections.unmodifiableList(unusedTitleLocales); - } + /** * Updates a localized title of the article. @@ -407,24 +453,7 @@ public class MvcArticlePropertiesStep extends AbstractMvcAuthoringStep { } } - /** - * Get the locales for which no localized description has been defined yet. - * - * @return The locales for which no localized description has been defined - * yet. - */ - public List getUnusedDescriptionLocales() { - return Collections.unmodifiableList(unusedDescriptionLocales); - } - - /** - * Get the values of the localized decrription of the article. - * - * @return The values of the localized description of the article. - */ - public Map getDescriptionValues() { - return Collections.unmodifiableMap(descriptionValues); - } + /** * Adds a localized description to the article. diff --git a/ccm-cms/src/main/java/org/librecms/ui/contenttypes/MvcArticlePropertiesStepModel.java b/ccm-cms/src/main/java/org/librecms/ui/contenttypes/MvcArticlePropertiesStepModel.java new file mode 100644 index 000000000..6d5b7e1c0 --- /dev/null +++ b/ccm-cms/src/main/java/org/librecms/ui/contenttypes/MvcArticlePropertiesStepModel.java @@ -0,0 +1,104 @@ +/* + * Copyright (C) 2021 LibreCCM Foundation. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, + * MA 02110-1301 USA + */ +package org.librecms.ui.contenttypes; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import javax.enterprise.context.RequestScoped; +import javax.inject.Named; + +/** + * + * @author Jens Pelzetter + */ +@RequestScoped +@Named("CmsArticlePropertiesStep") +public class MvcArticlePropertiesStepModel { + + private String name; + + private boolean canEdit; + + private Map titleValues; + + private List unusedTitleLocales; + + private Map descriptionValues; + + private List unusedDescriptionLocales; + + public String getName() { + return name; + } + + public void setName(final String name) { + this.name = name; + } + + public boolean getCanEdit() { + return canEdit; + } + + public void setCanEdit(final boolean canEdit) { + this.canEdit = canEdit; + } + + public Map getTitleValues() { + return Collections.unmodifiableMap(titleValues); + } + + public void setTitleValues(final Map titleValues) { + this.titleValues = new HashMap<>(titleValues); + } + + public List getUnusedTitleLocales() { + return Collections.unmodifiableList(unusedTitleLocales); + } + + public void setUnusedTitleLocales(List unusedTitleLocales) { + this.unusedTitleLocales = new ArrayList<>(unusedTitleLocales); + } + + public Map getDescriptionValues() { + return Collections.unmodifiableMap(descriptionValues); + } + + public void setDescriptionValues( + final Map descriptionValues + ) { + this.descriptionValues = new HashMap<>(descriptionValues); + } + + public List getUnusedDescriptionLocales() { + return Collections.unmodifiableList(unusedDescriptionLocales); + } + + public void setUnusedDescriptionLocales( + final List unusedDescriptionLocales + ) { + this.unusedDescriptionLocales = new ArrayList<>( + unusedDescriptionLocales + ); + } + +} 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 8ba577b10..894626ce8 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 @@ -39,7 +39,6 @@ import javax.ws.rs.Path; import org.librecms.ui.contentsections.documents.MvcAuthoringSteps; -import java.util.List; import java.util.Locale; import java.util.Map; import java.util.Set; @@ -47,7 +46,6 @@ import java.util.stream.Collectors; import javax.enterprise.context.RequestScoped; import javax.inject.Inject; -import javax.inject.Named; import javax.transaction.Transactional; import javax.ws.rs.FormParam; import javax.ws.rs.GET; @@ -56,7 +54,6 @@ import javax.ws.rs.PathParam; import org.librecms.ui.contentsections.documents.MvcAuthoringStepDef; -import java.util.Collections; import java.util.StringTokenizer; /** @@ -67,7 +64,6 @@ import java.util.StringTokenizer; @RequestScoped @Path(MvcAuthoringSteps.PATH_PREFIX + "article-text") @Controller -@Named("CmsArticleTextBodyStep") @MvcAuthoringStepDef( bundle = ArticleStepsConstants.BUNDLE, descriptionKey = "authoringsteps.text.description", @@ -100,14 +96,16 @@ public class MvcArticleTextBodyStep extends AbstractMvcAuthoringStep { @Inject private ItemPermissionChecker itemPermissionChecker; - private Map textValues; - - private List variants; - - private List unusedLocales; - - private String selectedLocale; + @Inject + private MvcArticleTextBodyStepModel articleTextBodyStepModel; +// private Map textValues; +// +// private List variants; +// +// private List unusedLocales; +// +// private String selectedLocale; @Override public Class getStepClass() { return MvcArticleTextBodyStep.class; @@ -142,31 +140,31 @@ public class MvcArticleTextBodyStep extends AbstractMvcAuthoringStep { } } - /** - * Get all localized values of the main text. - * - * @return The localized values of the main text. - */ - public Map getTextValues() { - return Collections.unmodifiableMap(textValues); - } - - public List getVariants() { - return Collections.unmodifiableList(variants); - } - - /** - * Gets the locales for which the main text has not been defined yet. - * - * @return The locales for which the main text has not been defined yet. - */ - public List getUnusedLocales() { - return Collections.unmodifiableList(unusedLocales); - } - - public String getSelectedLocale() { - return selectedLocale; - } +// /** +// * Get all localized values of the main text. +// * +// * @return The localized values of the main text. +// */ +// public Map getTextValues() { +// return Collections.unmodifiableMap(textValues); +// } +// +// public List getVariants() { +// return Collections.unmodifiableList(variants); +// } +// +// /** +// * Gets the locales for which the main text has not been defined yet. +// * +// * @return The locales for which the main text has not been defined yet. +// */ +// public List getUnusedLocales() { +// return Collections.unmodifiableList(unusedLocales); +// } +// +// public String getSelectedLocale() { +// return selectedLocale; +// } /** * Adds a localized main text. @@ -274,7 +272,9 @@ public class MvcArticleTextBodyStep extends AbstractMvcAuthoringStep { } if (itemPermissionChecker.canEditItem(getArticle())) { - selectedLocale = new Locale(localeParam).toString(); + articleTextBodyStepModel.setSelectedLocale( + new Locale(localeParam).toString() + ); return "org/librecms/ui/contenttypes/article/article-text/edit.xhtml"; } else { @@ -379,35 +379,44 @@ public class MvcArticleTextBodyStep extends AbstractMvcAuthoringStep { super.init(); if (itemPermissionChecker.canEditItem(getArticle())) { - textValues = getArticle() - .getText() - .getValues() - .entrySet() - .stream() - .collect( - Collectors.toMap( - entry -> entry.getKey().toString(), - entry -> entry.getValue() + articleTextBodyStepModel.setCanEdit( + itemPermissionChecker.canEditItem(getArticle()) + ); + articleTextBodyStepModel.setTextValues( + getArticle() + .getText() + .getValues() + .entrySet() + .stream() + .collect( + Collectors.toMap( + entry -> entry.getKey().toString(), + entry -> entry.getValue() + ) ) - ); + ); - variants = getArticle() - .getText() - .getValues() - .entrySet() - .stream() - .map(this::buildVariantRow) - .collect(Collectors.toList()); + articleTextBodyStepModel.setVariants( + getArticle() + .getText() + .getValues() + .entrySet() + .stream() + .map(this::buildVariantRow) + .collect(Collectors.toList()) + ); final Set locales = getArticle() .getText() .getAvailableLocales(); - unusedLocales = globalizationHelper - .getAvailableLocales() - .stream() - .filter(locale -> !locales.contains(locale)) - .map(Locale::toString) - .collect(Collectors.toList()); + articleTextBodyStepModel.setUnusedLocales( + globalizationHelper + .getAvailableLocales() + .stream() + .filter(locale -> !locales.contains(locale)) + .map(Locale::toString) + .collect(Collectors.toList()) + ); } } diff --git a/ccm-cms/src/main/java/org/librecms/ui/contenttypes/MvcArticleTextBodyStepModel.java b/ccm-cms/src/main/java/org/librecms/ui/contenttypes/MvcArticleTextBodyStepModel.java new file mode 100644 index 000000000..7163725a5 --- /dev/null +++ b/ccm-cms/src/main/java/org/librecms/ui/contenttypes/MvcArticleTextBodyStepModel.java @@ -0,0 +1,102 @@ +/* + * Copyright (C) 2021 LibreCCM Foundation. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, + * MA 02110-1301 USA + */ +package org.librecms.ui.contenttypes; + +import org.librecms.ui.contentsections.documents.CmsEditorLocaleVariantRow; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import javax.enterprise.context.RequestScoped; +import javax.inject.Named; + +/** + * + * @author Jens Pelzetter + */ +@RequestScoped +@Named("CmsArticleTextBodyStep") +public class MvcArticleTextBodyStepModel { + + private boolean canEdit; + + private Map textValues; + + private List variants; + + private List unusedLocales; + + private String selectedLocale; + + /** + * Get all localized values of the main text. + * + * @return The localized values of the main text. + */ + public Map getTextValues() { + return Collections.unmodifiableMap(textValues); + } + + protected void setTextValues(final Map textValues) { + this.textValues = new HashMap<>(textValues); + } + + /** + * Gets the locales for which the main text has not been defined yet. + * + * @return The locales for which the main text has not been defined yet. + */ + public List getVariants() { + return Collections.unmodifiableList(variants); + } + + protected void setVariants(final List variants) { + this.variants = new ArrayList<>(variants); + } + + public List getUnusedLocales() { + return Collections.unmodifiableList(unusedLocales); + } + + protected void setUnusedLocales(final List unusedLocales) { + this.unusedLocales = new ArrayList<>(unusedLocales); + } + + public String getSelectedLocale() { + return selectedLocale; + } + + protected void setSelectedLocale(final String selectedLocale) { + this.selectedLocale = selectedLocale; + } + + public boolean getCanEdit() { + return canEdit; + } + + protected void setCanEdit(final boolean canEdit) { + this.canEdit = canEdit; + } + + + +} diff --git a/ccm-cms/src/main/resources/WEB-INF/views/org/librecms/ui/contentsection/assets/postaladdress/edit-postaladdress.xhtml b/ccm-cms/src/main/resources/WEB-INF/views/org/librecms/ui/contentsection/assets/postaladdress/edit-postaladdress.xhtml index c70365706..b571bb294 100644 --- a/ccm-cms/src/main/resources/WEB-INF/views/org/librecms/ui/contentsection/assets/postaladdress/edit-postaladdress.xhtml +++ b/ccm-cms/src/main/resources/WEB-INF/views/org/librecms/ui/contentsection/assets/postaladdress/edit-postaladdress.xhtml @@ -9,12 +9,12 @@
-

#{CmsAssetsStepsDefaultMessagesBundle.getMessage('postaladdress.editstep.header', [CmsPostalAddressEditStep.name])}

+

#{CmsAssetsStepsDefaultMessagesBundle.getMessage('postaladdress.editstep.header', [MvcAssetEditStepModel.name])}

#{CmsAssetsStepsDefaultMessagesBundle['editstep.name.header']}

-
#{CmsPostalAddressEditStep.name}
- +
#{MvcAssetEditStepModel.name}
+
- +