diff --git a/ccm-cms/src/main/java/org/librecms/ui/contentsections/AssetPermissionsModelProvider.java b/ccm-cms/src/main/java/org/librecms/ui/contentsections/AssetPermissionsModelProvider.java index b18a48254..263e5d2e8 100644 --- a/ccm-cms/src/main/java/org/librecms/ui/contentsections/AssetPermissionsModelProvider.java +++ b/ccm-cms/src/main/java/org/librecms/ui/contentsections/AssetPermissionsModelProvider.java @@ -18,7 +18,7 @@ import javax.inject.Inject; * @author Jens Pelzetter */ @Dependent -class AssetPermissionsModelProvider { +public class AssetPermissionsModelProvider { /** * The {@link AssetPermissionsChecker} instance to use. diff --git a/ccm-cms/src/main/java/org/librecms/ui/contentsections/DocumentFolderController.java b/ccm-cms/src/main/java/org/librecms/ui/contentsections/DocumentFolderController.java index 55ed594b7..d75f4a646 100644 --- a/ccm-cms/src/main/java/org/librecms/ui/contentsections/DocumentFolderController.java +++ b/ccm-cms/src/main/java/org/librecms/ui/contentsections/DocumentFolderController.java @@ -7,10 +7,8 @@ package org.librecms.ui.contentsections; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; -import org.libreccm.api.IdentifierParser; import org.libreccm.l10n.GlobalizationHelper; import org.libreccm.security.AuthorizationRequired; -import org.libreccm.security.PermissionChecker; import org.libreccm.security.PermissionManager; import org.libreccm.security.Role; import org.libreccm.security.RoleRepository; diff --git a/ccm-cms/src/main/java/org/librecms/ui/contentsections/DocumentFolderRowModel.java b/ccm-cms/src/main/java/org/librecms/ui/contentsections/DocumentFolderRowModel.java index d0f0b5fab..0de442599 100644 --- a/ccm-cms/src/main/java/org/librecms/ui/contentsections/DocumentFolderRowModel.java +++ b/ccm-cms/src/main/java/org/librecms/ui/contentsections/DocumentFolderRowModel.java @@ -42,7 +42,7 @@ public class DocumentFolderRowModel { return created; } - protected void setCreated(final String created) { + public void setCreated(final String created) { this.created = created; } @@ -50,7 +50,7 @@ public class DocumentFolderRowModel { return deletable; } - protected void setDeletable(final boolean deletable) { + public void setDeletable(final boolean deletable) { this.deletable = deletable; } @@ -62,11 +62,11 @@ public class DocumentFolderRowModel { return folderPath; } - protected void setFolderPath(final String folderPath) { + public void setFolderPath(final String folderPath) { this.folderPath = folderPath; } - protected void setFolder(final boolean folder) { + public void setFolder(final boolean folder) { this.folder = folder; } @@ -78,7 +78,7 @@ public class DocumentFolderRowModel { return String.join(", ", languages); } - protected void setLanguages(final SortedSet languages) { + public void setLanguages(final SortedSet languages) { this.languages = languages; } @@ -86,7 +86,7 @@ public class DocumentFolderRowModel { return lastEdited; } - protected void setLastEdited(final String lastEdited) { + public void setLastEdited(final String lastEdited) { this.lastEdited = lastEdited; } @@ -94,7 +94,7 @@ public class DocumentFolderRowModel { return lastEditPublished; } - protected void setLastEditPublished(final boolean lastEditPublished) { + public void setLastEditPublished(final boolean lastEditPublished) { this.lastEditPublished = lastEditPublished; } @@ -102,7 +102,7 @@ public class DocumentFolderRowModel { return name; } - protected void setName(final String name) { + public void setName(final String name) { this.name = name; } @@ -118,7 +118,7 @@ public class DocumentFolderRowModel { return title; } - protected void setTitle(final String title) { + public void setTitle(final String title) { this.title = title; } @@ -126,7 +126,7 @@ public class DocumentFolderRowModel { return type; } - protected void setType(final String type) { + public void setType(final String type) { this.type = type; } @@ -134,7 +134,7 @@ public class DocumentFolderRowModel { return permissions; } - protected void setPermissions( + public void setPermissions( final DocumentPermissionsModel permissions ) { this.permissions = permissions; diff --git a/ccm-cms/src/main/java/org/librecms/ui/contentsections/DocumentPermissions.java b/ccm-cms/src/main/java/org/librecms/ui/contentsections/DocumentPermissions.java index 92a53d55d..97c4ca3e0 100644 --- a/ccm-cms/src/main/java/org/librecms/ui/contentsections/DocumentPermissions.java +++ b/ccm-cms/src/main/java/org/librecms/ui/contentsections/DocumentPermissions.java @@ -18,7 +18,7 @@ import javax.inject.Inject; * @author Jens Pelzetter */ @Dependent -class DocumentPermissions { +public class DocumentPermissions { @Inject private PermissionChecker permissionChecker; diff --git a/ccm-cms/src/main/java/org/librecms/ui/contentsections/documents/AttachmentListDetailsModel.java b/ccm-cms/src/main/java/org/librecms/ui/contentsections/documents/AttachmentListDetailsModel.java index f6a907538..9880cff26 100644 --- a/ccm-cms/src/main/java/org/librecms/ui/contentsections/documents/AttachmentListDetailsModel.java +++ b/ccm-cms/src/main/java/org/librecms/ui/contentsections/documents/AttachmentListDetailsModel.java @@ -5,14 +5,19 @@ */ package org.librecms.ui.contentsections.documents; +import org.libreccm.l10n.GlobalizationHelper; import org.librecms.contentsection.AttachmentList; import java.util.Collections; +import java.util.List; +import java.util.Locale; import java.util.Map; import java.util.Objects; +import java.util.Set; import java.util.stream.Collectors; import javax.enterprise.context.RequestScoped; +import javax.inject.Inject; import javax.inject.Named; /** @@ -22,20 +27,30 @@ import javax.inject.Named; @RequestScoped @Named("CmsAttachmentListDetailsModel") public class AttachmentListDetailsModel { + + @Inject + private GlobalizationHelper globalizationHelper; - private String uuid; - + private String name; private Map titles; private Map descriptions; + private List unusedTitleLocales; + + private List unusedDescriptionLocales; + public String getUuid() { return uuid; } + public String getName() { + return name; + } + public Map getTitles() { return Collections.unmodifiableMap(titles); } @@ -44,6 +59,14 @@ public class AttachmentListDetailsModel { return Collections.unmodifiableMap(descriptions); } + public List getUnusedTitleLocales() { + return Collections.unmodifiableList(unusedTitleLocales); + } + + public List getUnusedDescriptionLocales() { + return Collections.unmodifiableList(unusedDescriptionLocales); + } + protected void setAttachmentList(final AttachmentList list) { Objects.requireNonNull(list); uuid = list.getUuid(); @@ -70,6 +93,26 @@ public class AttachmentListDetailsModel { entry -> entry.getValue() ) ); + + final Set titleLocales = list + .getTitle() + .getAvailableLocales(); + unusedTitleLocales = globalizationHelper + .getAvailableLocales() + .stream() + .filter(locale -> !titleLocales.contains(locale)) + .map(Locale::toString) + .collect(Collectors.toList()); + + final Set descriptionLocales = list + .getDescription() + .getAvailableLocales(); + unusedDescriptionLocales = globalizationHelper + .getAvailableLocales() + .stream() + .filter(locale -> !descriptionLocales.contains(locale)) + .map(Locale::toString) + .collect(Collectors.toList()); } } diff --git a/ccm-cms/src/main/java/org/librecms/ui/contentsections/documents/InternalLinkDetailsModel.java b/ccm-cms/src/main/java/org/librecms/ui/contentsections/documents/InternalLinkDetailsModel.java index b1d22e23a..297e565d3 100644 --- a/ccm-cms/src/main/java/org/librecms/ui/contentsections/documents/InternalLinkDetailsModel.java +++ b/ccm-cms/src/main/java/org/librecms/ui/contentsections/documents/InternalLinkDetailsModel.java @@ -9,8 +9,11 @@ import org.libreccm.l10n.GlobalizationHelper; import org.librecms.assets.RelatedLink; import java.util.Collections; +import java.util.List; +import java.util.Locale; import java.util.Map; import java.util.Objects; +import java.util.Set; import java.util.stream.Collectors; import javax.enterprise.context.RequestScoped; @@ -32,8 +35,12 @@ public class InternalLinkDetailsModel { private String uuid; + private String label; + private Map title; + private List unusedTitleLocales; + private String targetItemUuid; private String targetItemName; @@ -52,10 +59,18 @@ public class InternalLinkDetailsModel { return uuid; } + public String getLabel() { + return label; + } + public Map getTitle() { return Collections.unmodifiableMap(title); } + public List getUnusedTitleLocales() { + return Collections.unmodifiableList(unusedTitleLocales); + } + public String getTargetItemUuid() { return targetItemUuid; } @@ -72,6 +87,9 @@ public class InternalLinkDetailsModel { Objects.requireNonNull(link); uuid = link.getUuid(); + label = globalizationHelper.getValueFromLocalizedString( + link.getTitle() + ); title = link .getTitle() .getValues() @@ -83,6 +101,13 @@ public class InternalLinkDetailsModel { entry -> entry.getValue() ) ); + final Set titleLocales = link.getTitle().getAvailableLocales(); + unusedTitleLocales = globalizationHelper + .getAvailableLocales() + .stream() + .filter(locale -> !titleLocales.contains(locale)) + .map(Locale::toString) + .collect(Collectors.toList()); targetItemUuid = link.getTargetItem().getItemUuid(); targetItemName = link.getTargetItem().getDisplayName(); targetItemTitle = globalizationHelper.getValueFromLocalizedString( diff --git a/ccm-cms/src/main/java/org/librecms/ui/contentsections/documents/RelatedInfoStep.java b/ccm-cms/src/main/java/org/librecms/ui/contentsections/documents/RelatedInfoStep.java index 7ab3fec98..0931c4839 100644 --- a/ccm-cms/src/main/java/org/librecms/ui/contentsections/documents/RelatedInfoStep.java +++ b/ccm-cms/src/main/java/org/librecms/ui/contentsections/documents/RelatedInfoStep.java @@ -12,21 +12,47 @@ import org.librecms.assets.AssetTypeInfo; import org.librecms.assets.AssetTypesManager; import org.librecms.assets.RelatedLink; import org.librecms.contentsection.Asset; +import org.librecms.contentsection.AssetFolderEntry; +import org.librecms.contentsection.AssetManager; import org.librecms.contentsection.AssetRepository; import org.librecms.contentsection.AttachmentList; import org.librecms.contentsection.AttachmentListL10NManager; import org.librecms.contentsection.AttachmentListManager; import org.librecms.contentsection.AttachmentListRepository; import org.librecms.contentsection.ContentItem; +import org.librecms.contentsection.ContentItemL10NManager; import org.librecms.contentsection.ContentItemManager; import org.librecms.contentsection.ContentItemRepository; import org.librecms.contentsection.ContentSection; +import org.librecms.contentsection.ContentType; +import org.librecms.contentsection.ContentTypeRepository; +import org.librecms.contentsection.DocumentFolderEntry; +import org.librecms.contentsection.Folder; +import org.librecms.contentsection.FolderManager; +import org.librecms.contentsection.FolderRepository; +import org.librecms.contentsection.FolderType; import org.librecms.contentsection.ItemAttachment; import org.librecms.contentsection.ItemAttachmentManager; +import org.librecms.ui.contentsections.AssetFolderRowModel; +import org.librecms.ui.contentsections.AssetFolderTree; +import org.librecms.ui.contentsections.AssetFolderTreeNode; +import org.librecms.ui.contentsections.AssetPermissionsModel; +import org.librecms.ui.contentsections.AssetPermissionsModelProvider; +import org.librecms.ui.contentsections.DocumentFolderRowModel; +import org.librecms.ui.contentsections.DocumentFolderTree; +import org.librecms.ui.contentsections.DocumentFolderTreeNode; +import org.librecms.ui.contentsections.DocumentPermissions; +import java.time.LocalDate; +import java.time.ZoneId; +import java.time.format.DateTimeFormatter; +import java.util.Collections; +import java.util.Date; import java.util.List; import java.util.Locale; +import java.util.Objects; import java.util.Optional; +import java.util.TreeSet; import java.util.stream.Collectors; import javax.enterprise.context.RequestScoped; @@ -35,11 +61,15 @@ import javax.inject.Named; import javax.mvc.Controller; import javax.mvc.Models; import javax.transaction.Transactional; +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.Produces; +import javax.ws.rs.QueryParam; +import javax.ws.rs.core.MediaType; /** * @@ -54,6 +84,18 @@ public class RelatedInfoStep implements MvcAuthoringStep { static final String PATH_FRAGMENT = "relatedinfo"; + @Inject + private AssetFolderTree assetFolderTree; + + /** + * Used to build the {@link AssetPermissionsModel}. + */ + @Inject + private AssetPermissionsModelProvider assetPermissions; + + @Inject + private AssetManager assetManager; + @Inject private AssetRepository assetRepo; @@ -72,14 +114,32 @@ public class RelatedInfoStep implements MvcAuthoringStep { @Inject private AttachmentListRepository listRepo; + @Inject + private DocumentFolderTree documentFolderTree; + + @Inject + private DocumentPermissions documentPermissions; + + @Inject + private FolderManager folderManager; + + @Inject + private FolderRepository folderRepo; + @Inject private InternalLinkDetailsModel internalLinkDetailsModel; - + + @Inject + private ContentItemL10NManager itemL10NManager; + + @Inject + private ContentItemManager itemManager; + @Inject private ContentItemRepository itemRepo; @Inject - private ContentItemManager itemManager; + private ContentTypeRepository contentTypeRepo; @Inject private GlobalizationHelper globalizationHelper; @@ -168,7 +228,7 @@ public class RelatedInfoStep implements MvcAuthoringStep { return "org/librecms/ui/documents/relatedinfo.xhtml"; } - @Transactional + @Transactional(Transactional.TxType.REQUIRED) public List getAttachmentLists() { return document .getAttachments() @@ -178,6 +238,125 @@ public class RelatedInfoStep implements MvcAuthoringStep { .collect(Collectors.toList()); } + @GET + @Path("/asset-folders") + @Produces(MediaType.APPLICATION_JSON) + @Transactional(Transactional.TxType.REQUIRED) + public List getAssetFolderTree() { + return assetFolderTree.buildFolderTree( + section, section.getRootAssetsFolder() + ); + } + + @GET + @Path("/asset-folders/{folderPath}/assets") + @Produces(MediaType.APPLICATION_JSON) + @Transactional(Transactional.TxType.REQUIRED) + public List getAssetsInFolder( + @PathParam("folderPath") final String folderPath, + @QueryParam("firstResult") @DefaultValue("0") final int firstResult, + @QueryParam("maxResults") @DefaultValue("20") final int maxResults, + @QueryParam("filterTerm") @DefaultValue("") final String filterTerm + ) { + final Folder folder; + if (folderPath.isEmpty()) { + folder = section.getRootAssetsFolder(); + } else { + final Optional folderResult = folderRepo.findByPath( + section, folderPath, FolderType.ASSETS_FOLDER + ); + if (folderResult.isPresent()) { + folder = folderResult.get(); + } else { + return Collections.emptyList(); + } + } + return folderRepo + .getAssetFolderEntries( + folder, firstResult, maxResults, filterTerm + ) + .stream() + .map(entry -> buildAssetFolderRowModel(section, entry)) + .collect(Collectors.toList()); + } + + @GET + @Path("/search-assets") + @Produces(MediaType.APPLICATION_JSON) + @Transactional(Transactional.TxType.REQUIRED) + public List findAssets( + @QueryParam("firstResult") @DefaultValue("0") final int firstResult, + @QueryParam("maxResults") @DefaultValue("20") final int maxResults, + @QueryParam("searchTerm") @DefaultValue("") final String searchTerm + ) { + return assetRepo.findByTitleAndContentSection(searchTerm, section) + .stream() + .map(asset -> buildAssetFolderRowModel(section, asset)) + .collect(Collectors.toList()); + + } + + @GET + @Path("/document-folders") + @Produces(MediaType.APPLICATION_JSON) + @Transactional(Transactional.TxType.REQUIRED) + public List getDocumentFolderTree() { + return documentFolderTree.buildFolderTree( + section, section.getRootDocumentsFolder() + ); + } + + @GET + @Path("/document-folders/{folderPath}/documents") + @Produces(MediaType.APPLICATION_JSON) + @Transactional(Transactional.TxType.REQUIRED) + public List getDocumentsInFolder( + @PathParam("folderPath") final String folderPath, + @QueryParam("firstResult") @DefaultValue("0") final int firstResult, + @QueryParam("maxResults") @DefaultValue("20") final int maxResults, + @QueryParam("filterTerm") @DefaultValue("") final String filterTerm + ) { + final Folder folder; + if (folderPath.isEmpty()) { + folder = section.getRootDocumentsFolder(); + } else { + final Optional folderResult = folderRepo.findByPath( + section, folderPath, FolderType.ASSETS_FOLDER + ); + if (folderResult.isPresent()) { + folder = folderResult.get(); + } else { + return Collections.emptyList(); + } + } + + return folderRepo + .getDocumentFolderEntries( + folder, + firstResult, + maxResults, + filterTerm + ) + .stream() + .map(entry -> buildDocumentFolderRowModel(section, entry)) + .collect(Collectors.toList()); + } + + @GET + @Path("/search-documents") + @Produces(MediaType.APPLICATION_JSON) + @Transactional(Transactional.TxType.REQUIRED) + public List findDocuments( + @QueryParam("firstResult") @DefaultValue("0") final int firstResult, + @QueryParam("maxResults") @DefaultValue("20") final int maxResults, + @QueryParam("searchTerm") @DefaultValue("") final String searchTerm + ) { + return itemRepo.findByNameAndContentSection(searchTerm, section) + .stream() + .map(asset -> buildDocumentFolderRowModel(section, asset)) + .collect(Collectors.toList()); + } + @POST @Path("/attachmentlists/@add") @Transactional(Transactional.TxType.REQUIRED) @@ -224,7 +403,7 @@ public class RelatedInfoStep implements MvcAuthoringStep { } @POST - @Path("/attachmentlists/{attachmentListIdentifier}/@remove") + @Path("/attachmentlists/{attachmentListIdentifier}/@update") @Transactional(Transactional.TxType.REQUIRED) public String updateAttachmentList( @PathParam("attachmentListIdentifier") final String listIdentifierParam, @@ -276,6 +455,176 @@ public class RelatedInfoStep implements MvcAuthoringStep { ); } + @POST + @Path("/attachmentlists/{attachmentListIdentifier}/title/@add") + @Transactional(Transactional.TxType.REQUIRED) + public String addAttachmentListTitle( + @PathParam("attachmentListIdentifier") final String listIdentifierParam, + @FormParam("locale") final String localeParam, + @FormParam("value") final String value + ) { + final Optional listResult = findAttachmentList( + listIdentifierParam + ); + if (!listResult.isPresent()) { + return showAttachmentListNotFound(listIdentifierParam); + } + + final AttachmentList list = listResult.get(); + list.getTitle().addValue(new Locale(localeParam), value); + listRepo.save(list); + + return String.format( + "redirect:/%s/@documents/%s/@authoringsteps/%s/attachmentslists/%s", + section.getLabel(), + getContentItemPath(), + PATH_FRAGMENT, + list.getName() + ); + } + + @POST + @Path("/attachmentlists/{attachmentListIdentifier}/title/@edit/{locale}") + @Transactional(Transactional.TxType.REQUIRED) + public String updateAttachmentListTitle( + @PathParam("attachmentListIdentifier") final String listIdentifierParam, + @PathParam("locale") final String localeParam, + @FormParam("value") final String value + ) { + final Optional listResult = findAttachmentList( + listIdentifierParam + ); + if (!listResult.isPresent()) { + return showAttachmentListNotFound(listIdentifierParam); + } + + final AttachmentList list = listResult.get(); + list.getTitle().addValue(new Locale(localeParam), value); + listRepo.save(list); + + return String.format( + "redirect:/%s/@documents/%s/@authoringsteps/%s/attachmentslists/%s", + section.getLabel(), + getContentItemPath(), + PATH_FRAGMENT, + list.getName() + ); + } + + @POST + @Path("/attachmentlists/{attachmentListIdentifier}/title/@remove/{locale}") + @Transactional(Transactional.TxType.REQUIRED) + public String removeAttachmentListTitle( + @PathParam("attachmentListIdentifier") final String listIdentifierParam, + @PathParam("locale") final String localeParam, + @FormParam("value") final String value + ) { + final Optional listResult = findAttachmentList( + listIdentifierParam + ); + if (!listResult.isPresent()) { + return showAttachmentListNotFound(listIdentifierParam); + } + + final AttachmentList list = listResult.get(); + list.getTitle().removeValue(new Locale(localeParam)); + listRepo.save(list); + + return String.format( + "redirect:/%s/@documents/%s/@authoringsteps/%s/attachmentslists/%s", + section.getLabel(), + getContentItemPath(), + PATH_FRAGMENT, + list.getName() + ); + } + + @POST + @Path("/attachmentlists/{attachmentListIdentifier}/description/@add") + @Transactional(Transactional.TxType.REQUIRED) + public String addAttachmentListDescription( + @PathParam("attachmentListIdentifier") final String listIdentifierParam, + @FormParam("locale") final String localeParam, + @FormParam("value") final String value + ) { + final Optional listResult = findAttachmentList( + listIdentifierParam + ); + if (!listResult.isPresent()) { + return showAttachmentListNotFound(listIdentifierParam); + } + + final AttachmentList list = listResult.get(); + list.getDescription().addValue(new Locale(localeParam), value); + listRepo.save(list); + + return String.format( + "redirect:/%s/@documents/%s/@authoringsteps/%s/attachmentslists/%s", + section.getLabel(), + getContentItemPath(), + PATH_FRAGMENT, + list.getName() + ); + } + + @POST + @Path( + "/attachmentlists/{attachmentListIdentifier}/description/@edit/{locale}") + @Transactional(Transactional.TxType.REQUIRED) + public String updateAttachmentListDescription( + @PathParam("attachmentListIdentifier") final String listIdentifierParam, + @PathParam("locale") final String localeParam, + @FormParam("value") final String value + ) { + final Optional listResult = findAttachmentList( + listIdentifierParam + ); + if (!listResult.isPresent()) { + return showAttachmentListNotFound(listIdentifierParam); + } + + final AttachmentList list = listResult.get(); + list.getDescription().addValue(new Locale(localeParam), value); + listRepo.save(list); + + return String.format( + "redirect:/%s/@documents/%s/@authoringsteps/%s/attachmentslists/%s", + section.getLabel(), + getContentItemPath(), + PATH_FRAGMENT, + list.getName() + ); + } + + @POST + @Path( + "/attachmentlists/{attachmentListIdentifier}/description/@remove/{locale}") + @Transactional(Transactional.TxType.REQUIRED) + public String removeAttachmentListDescription( + @PathParam("attachmentListIdentifier") final String listIdentifierParam, + @PathParam("locale") final String localeParam, + @FormParam("value") final String value + ) { + final Optional listResult = findAttachmentList( + listIdentifierParam + ); + if (!listResult.isPresent()) { + return showAttachmentListNotFound(listIdentifierParam); + } + + final AttachmentList list = listResult.get(); + list.getDescription().removeValue(new Locale(localeParam)); + listRepo.save(list); + + return String.format( + "redirect:/%s/@documents/%s/@authoringsteps/%s/attachmentslists/%s", + section.getLabel(), + getContentItemPath(), + PATH_FRAGMENT, + list.getName() + ); + } + @POST @Path("/attachmentlists/{attachmentListIdentifier}/attachments") @Transactional(Transactional.TxType.REQUIRED) @@ -315,10 +664,10 @@ public class RelatedInfoStep implements MvcAuthoringStep { @Path("/attachmentlists/{attachmentListIdentifier}/internal-links/@create") @Transactional(Transactional.TxType.REQUIRED) public String createInternalLink( - @PathParam("attachmentListIdentifier") + @PathParam("attachmentListIdentifier") final String listIdentifierParam ) { - final Optional listResult = findAttachmentList( + final Optional listResult = findAttachmentList( listIdentifierParam ); if (!listResult.isPresent()) { @@ -326,7 +675,7 @@ public class RelatedInfoStep implements MvcAuthoringStep { } final AttachmentList list = listResult.get(); models.put("attachmentList", list.getName()); - + return "org/librecms/ui/documents/relatedinfo-create-internallink.xhtml"; } @@ -369,25 +718,25 @@ public class RelatedInfoStep implements MvcAuthoringStep { PATH_FRAGMENT ); } - - @GET + + @GET @Path( "/attachmentlists/{attachmentListIdentifier}/internal-links/{interalLinkUuid}/@details") @Transactional(Transactional.TxType.REQUIRED) public String showInternalLinkDetails( - @PathParam("attachmentListIdentifier") + @PathParam("attachmentListIdentifier") final String listIdentifierParam, @PathParam("internalLinkUuid") final String internalLinkUuid ) { - final Optional listResult = findAttachmentList( + final Optional listResult = findAttachmentList( listIdentifierParam ); if (!listResult.isPresent()) { return showAttachmentListNotFound(listIdentifierParam); } final AttachmentList list = listResult.get(); - - final Optional linkResult = list + + final Optional linkResult = list .getAttachments() .stream() .map(ItemAttachment::getAsset) @@ -406,14 +755,14 @@ public class RelatedInfoStep implements MvcAuthoringStep { final RelatedLink link = linkResult.get(); internalLinkDetailsModel.setListIdentifier(list.getName()); internalLinkDetailsModel.setInternalLink(link); - - return "org/librecms/ui/documents/relatedinfo-create-internallink.xhtml"; - } + return "org/librecms/ui/documents/relatedinfo-internallink-details.xhtml"; + } @POST @Path( - "/attachmentlists/{attachmentListIdentifier}/internal-links/{interalLinkUuid}") + "/attachmentlists/{attachmentListIdentifier}/internal-links/{interalLinkUuid}" + ) @Transactional(Transactional.TxType.REQUIRED) public String updateInternalLinkTarget( @PathParam("attachmentListIdentifier") @@ -563,7 +912,8 @@ public class RelatedInfoStep implements MvcAuthoringStep { @POST @Path( - "/attachmentlists/{attachmentListIdentifier}/internal-links/{interalLinkUuid}/title/@edit/{locale}") + "/attachmentlists/{attachmentListIdentifier}/internal-links/{interalLinkUuid}/title/@remove/{locale}" + ) @Transactional(Transactional.TxType.REQUIRED) public String removeInternalLinkTitle( @PathParam("attachmentListIdentifier") @@ -856,7 +1206,8 @@ public class RelatedInfoStep implements MvcAuthoringStep { dto.setAttachmentId(itemAttachment.getAttachmentId()); dto.setInternalLink( itemAttachment.getAsset() instanceof RelatedLink - && ((RelatedLink) itemAttachment.getAsset()).getTargetItem() != null + && ((RelatedLink) itemAttachment.getAsset()).getTargetItem() + != null ); dto.setSortKey(itemAttachment.getSortKey()); dto.setTitle( @@ -869,4 +1220,296 @@ public class RelatedInfoStep implements MvcAuthoringStep { return dto; } + private AssetFolderRowModel buildAssetFolderRowModel( + final ContentSection section, final AssetFolderEntry entry + ) { + Objects.requireNonNull(section); + Objects.requireNonNull(entry); + + final AssetFolderRowModel row = new AssetFolderRowModel(); + if (entry.isFolder()) { + final Folder folder = folderRepo + .findById(entry.getEntryId()) + .get(); + row.setDeletable(false); + row.setFolder(true); + row.setFolderPath( + folderManager + .getFolderPath(folder) + .substring( + folderManager + .getFolderPath(section.getRootAssetsFolder()) + .length() + ) + ); + row.setName(entry.getDisplayName()); + row.setTitle( + globalizationHelper.getValueFromLocalizedString( + folder.getTitle() + ) + ); + row.setType( + globalizationHelper.getLocalizedTextsUtil( + "org.librecms.CmsAdminMessages" + ).getText("contentsection.assetfolder.types.folder") + ); + row.setPermissions( + assetPermissions.buildAssetPermissionsModel(folder) + ); + } else { + final Asset asset = assetRepo + .findById(entry.getEntryId()) + .get(); + row.setDeletable(!assetManager.isAssetInUse(asset)); + row.setFolder(false); + row.setName(entry.getDisplayName()); + row.setNoneCmsObject(false); + row.setTitle( + globalizationHelper.getValueFromLocalizedString( + asset.getTitle() + ) + ); + row.setType(asset.getClass().getName()); + row.setPermissions( + assetPermissions.buildAssetPermissionsModel(asset) + ); + } + + return row; + } + + private AssetFolderRowModel buildAssetFolderRowModel( + final ContentSection section, final Asset asset + ) { + Objects.requireNonNull(section); + Objects.requireNonNull(asset); + + final AssetFolderRowModel row = new AssetFolderRowModel(); + row.setDeletable(false); + row.setFolder(false); + row.setName(asset.getDisplayName()); + row.setNoneCmsObject(false); + row.setTitle( + globalizationHelper.getValueFromLocalizedString( + asset.getTitle() + ) + ); + row.setType(asset.getClass().getName()); + row.setPermissions( + assetPermissions.buildAssetPermissionsModel(asset) + ); + + return row; + } + + private DocumentFolderRowModel buildDocumentFolderRowModel( + final ContentSection section, final DocumentFolderEntry entry + ) { + Objects.requireNonNull(section); + Objects.requireNonNull(entry); + + final DocumentFolderRowModel row = new DocumentFolderRowModel(); + if (entry.isFolder()) { + final Folder folder = folderRepo + .findById(entry.getEntryId()) + .get(); + row.setCreated(""); + row.setDeletable( + folderManager + .folderIsDeletable(folder) + == FolderManager.FolderIsDeletable.YES + ); + row.setFolder(true); + row.setFolderPath( + folderManager + .getFolderPath(folder) + .substring( + folderManager + .getFolderPath(section.getRootDocumentsFolder()) + .length() + ) + ); + row.setLanguages(Collections.emptySortedSet()); + row.setLastEditPublished(false); + row.setLastEdited(""); + row.setName(entry.getDisplayName()); + row.setTitle( + globalizationHelper.getValueFromLocalizedString( + folder.getTitle() + ) + ); + row.setType( + globalizationHelper.getLocalizedTextsUtil( + "org.librecms.CmsAdminMessages" + ).getText("contentsection.documentfolder.types.folder") + ); + row.setPermissions( + documentPermissions.buildDocumentPermissionsModel(folder) + ); + } else { + final ContentItem contentItem = itemRepo + .findById(entry.getEntryId()) + .get(); + row.setCreated( + DateTimeFormatter.ISO_DATE.format( + LocalDate.ofInstant( + contentItem.getCreationDate().toInstant(), + ZoneId.systemDefault() + ) + ) + ); + row.setDeletable(!itemManager.isLive(contentItem)); + row.setFolder(false); + row.setFolderPath(itemManager.getItemPath(contentItem)); + row.setLanguages( + new TreeSet<>( + itemL10NManager + .availableLanguages(contentItem) + .stream() + .map(Locale::toString) + .collect(Collectors.toSet()) + ) + ); + if (itemManager.isLive(contentItem)) { + final LocalDate draftLastModified = LocalDate.ofInstant( + contentItem.getLastModified().toInstant(), + ZoneId.systemDefault() + ); + final LocalDate liveLastModified = LocalDate.ofInstant( + itemManager + .getLiveVersion(contentItem, contentItem.getClass()) + .map(ContentItem::getLastModified) + .map(Date::toInstant) + .get(), + ZoneId.systemDefault() + ); + row.setLastEditPublished( + liveLastModified.isBefore(draftLastModified) + ); + } else { + row.setLastEditPublished(false); + } + + row.setLastEdited( + DateTimeFormatter.ISO_DATE.format( + LocalDate.ofInstant( + contentItem.getLastModified().toInstant(), + ZoneId.systemDefault() + ) + ) + ); + row.setName(entry.getDisplayName()); + row.setNoneCmsObject(false); + row.setTitle( + globalizationHelper.getValueFromLocalizedString( + contentItem.getTitle() + ) + ); + row.setType( + contentTypeRepo + .findByContentSectionAndClass( + section, contentItem.getClass() + ) + .map(ContentType::getLabel) + .map( + label -> globalizationHelper + .getValueFromLocalizedString( + label + ) + ).orElse("?") + ); + row.setPermissions( + documentPermissions.buildDocumentPermissionsModel( + contentItem + ) + ); + } + + return row; + } + + private DocumentFolderRowModel buildDocumentFolderRowModel( + final ContentSection section, final ContentItem contentItem + ) { + Objects.requireNonNull(section); + Objects.requireNonNull(contentItem); + + final DocumentFolderRowModel row = new DocumentFolderRowModel(); + row.setCreated( + DateTimeFormatter.ISO_DATE.format( + LocalDate.ofInstant( + contentItem.getCreationDate().toInstant(), + ZoneId.systemDefault() + ) + ) + ); + row.setDeletable(!itemManager.isLive(contentItem)); + row.setFolder(false); + row.setFolderPath(itemManager.getItemPath(contentItem)); + row.setLanguages( + new TreeSet<>( + itemL10NManager + .availableLanguages(contentItem) + .stream() + .map(Locale::toString) + .collect(Collectors.toSet()) + ) + ); + if (itemManager.isLive(contentItem)) { + final LocalDate draftLastModified = LocalDate.ofInstant( + contentItem.getLastModified().toInstant(), + ZoneId.systemDefault() + ); + final LocalDate liveLastModified = LocalDate.ofInstant( + itemManager + .getLiveVersion(contentItem, contentItem.getClass()) + .map(ContentItem::getLastModified) + .map(Date::toInstant) + .get(), + ZoneId.systemDefault() + ); + row.setLastEditPublished( + liveLastModified.isBefore(draftLastModified) + ); + } else { + row.setLastEditPublished(false); + } + + row.setLastEdited( + DateTimeFormatter.ISO_DATE.format( + LocalDate.ofInstant( + contentItem.getLastModified().toInstant(), + ZoneId.systemDefault() + ) + ) + ); + row.setName(contentItem.getDisplayName()); + row.setNoneCmsObject(false); + row.setTitle( + globalizationHelper.getValueFromLocalizedString( + contentItem.getTitle() + ) + ); + row.setType( + contentTypeRepo + .findByContentSectionAndClass( + section, contentItem.getClass() + ) + .map(ContentType::getLabel) + .map( + label -> globalizationHelper + .getValueFromLocalizedString( + label + ) + ).orElse("?") + ); + row.setPermissions( + documentPermissions.buildDocumentPermissionsModel( + contentItem + ) + ); + + return row; + } + } diff --git a/ccm-cms/src/main/resources/WEB-INF/views/org/librecms/ui/contentsection/documents/relatedinfo-attachmentlist-details.xhtml b/ccm-cms/src/main/resources/WEB-INF/views/org/librecms/ui/contentsection/documents/relatedinfo-attachmentlist-details.xhtml new file mode 100644 index 000000000..d4cdc9e72 --- /dev/null +++ b/ccm-cms/src/main/resources/WEB-INF/views/org/librecms/ui/contentsection/documents/relatedinfo-attachmentlist-details.xhtml @@ -0,0 +1,103 @@ +]> + + + + + + + + + + + + +

+ #{CmsDefaultStepsMessageBundle.getMessage('relatedinfo.attachmentlist.details.title', [CmsAttachmentListDetailsModel.name])} +

+ +

+ #{CmsDefaultStepsMessageBundle['relatedinfo.attachmentlist.details.name.label']}: + #{CmsAttachmentListDetailsModel.name} + +

+ + + + + + +
+ +
+ diff --git a/ccm-cms/src/main/resources/WEB-INF/views/org/librecms/ui/contentsection/documents/relatedinfo-internallink-details.xhtml b/ccm-cms/src/main/resources/WEB-INF/views/org/librecms/ui/contentsection/documents/relatedinfo-internallink-details.xhtml new file mode 100644 index 000000000..d51b15e7c --- /dev/null +++ b/ccm-cms/src/main/resources/WEB-INF/views/org/librecms/ui/contentsection/documents/relatedinfo-internallink-details.xhtml @@ -0,0 +1,39 @@ +]> + + + + + + + + + + + + +

+ #{CmsDefaultStepsMessageBundle.getMessage('relatedinfo.internallink.details.title', [CmsInternalLinkDetailsModel.label])} +

+ + + +
+ +
+ + diff --git a/ccm-cms/src/main/resources/WEB-INF/views/org/librecms/ui/contentsection/documents/relatedinfo.xhtml b/ccm-cms/src/main/resources/WEB-INF/views/org/librecms/ui/contentsection/documents/relatedinfo.xhtml index 6c14e9a94..cb41dabc2 100644 --- a/ccm-cms/src/main/resources/WEB-INF/views/org/librecms/ui/contentsection/documents/relatedinfo.xhtml +++ b/ccm-cms/src/main/resources/WEB-INF/views/org/librecms/ui/contentsection/documents/relatedinfo.xhtml @@ -89,6 +89,13 @@ #{CmsDefaultStepsMessageBundle['relatedinfo.attachmentlists.attachment.add.label']} + - + + - - + +