diff --git a/ccm-cms/src/main/java/org/librecms/contentsection/AttachmentList.java b/ccm-cms/src/main/java/org/librecms/contentsection/AttachmentList.java index 3ca9862c3..bc0d784c6 100644 --- a/ccm-cms/src/main/java/org/librecms/contentsection/AttachmentList.java +++ b/ccm-cms/src/main/java/org/librecms/contentsection/AttachmentList.java @@ -46,7 +46,8 @@ import javax.persistence.OneToMany; import javax.persistence.OrderBy; import javax.persistence.Table; -import static org.librecms.CmsConstants.*; +import static org.librecms.CmsConstants.DB_SCHEMA; + /** * A list of assets attached a {@link ContentItem}. Each {@link ContentItem} may diff --git a/ccm-cms/src/main/java/org/librecms/contentsection/AttachmentListRepository.java b/ccm-cms/src/main/java/org/librecms/contentsection/AttachmentListRepository.java new file mode 100644 index 000000000..829e6aaba --- /dev/null +++ b/ccm-cms/src/main/java/org/librecms/contentsection/AttachmentListRepository.java @@ -0,0 +1,50 @@ +/* + * To change this license header, choose License Headers in Project Properties. + * To change this template file, choose Tools | Templates + * and open the template in the editor. + */ +package org.librecms.contentsection; + +import org.libreccm.core.AbstractEntityRepository; + +import java.util.UUID; + +import javax.enterprise.context.Dependent; + +/** + * + * @author Jens Pelzetter + */ +@Dependent +public class AttachmentListRepository + extends AbstractEntityRepository { + + private static final long serialVersionUID = 1L; + + @Override + public Class getEntityClass() { + return AttachmentList.class; + } + + @Override + public String getIdAttributeName() { + return "listId"; + } + + @Override + public Long getIdOfEntity(final AttachmentList entity) { + return entity.getListId(); + } + + @Override + public boolean isNew(final AttachmentList entity) { + return entity.getListId() == 0; + } + + @Override + protected void initNewEntity(final AttachmentList entity) { + super.initNewEntity(entity); + entity.setUuid(UUID.randomUUID().toString()); + } + +} diff --git a/ccm-cms/src/main/java/org/librecms/ui/contentsections/documents/AttachmentListDto.java b/ccm-cms/src/main/java/org/librecms/ui/contentsections/documents/AttachmentListDto.java new file mode 100644 index 000000000..12c68854c --- /dev/null +++ b/ccm-cms/src/main/java/org/librecms/ui/contentsections/documents/AttachmentListDto.java @@ -0,0 +1,90 @@ +/* + * To change this license header, choose License Headers in Project Properties. + * To change this template file, choose Tools | Templates + * and open the template in the editor. + */ +package org.librecms.ui.contentsections.documents; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; + +/** + * + * @author Jens Pelzetter + */ +public class AttachmentListDto { + + private long listId; + + private String uuid; + + private String name; + + private long order; + + private String title; + + private String description; + + private List attachments; + + public long getListId() { + return listId; + } + + public void setListId(final long listId) { + this.listId = listId; + } + + public String getUuid() { + return uuid; + } + + public void setUuid(final String uuid) { + this.uuid = uuid; + } + + public String getName() { + return name; + } + + public void setName(final String name) { + this.name = name; + } + + public long getOrder() { + return order; + } + + public void setOrder(long order) { + this.order = order; + } + + public String getTitle() { + return title; + } + + public void setTitle(final String title) { + this.title = title; + } + + public String getDescription() { + return description; + } + + public void setDescription(final String description) { + this.description = description; + } + + public List getAttachments() { + return Collections.unmodifiableList(attachments); + } + + public void setAttachments(final List attachments) { + this.attachments = new ArrayList<>(attachments); + } + + + +} diff --git a/ccm-cms/src/main/java/org/librecms/ui/contentsections/documents/ItemAttachmentDto.java b/ccm-cms/src/main/java/org/librecms/ui/contentsections/documents/ItemAttachmentDto.java new file mode 100644 index 000000000..b6a2e8d26 --- /dev/null +++ b/ccm-cms/src/main/java/org/librecms/ui/contentsections/documents/ItemAttachmentDto.java @@ -0,0 +1,64 @@ +/* + * To change this license header, choose License Headers in Project Properties. + * To change this template file, choose Tools | Templates + * and open the template in the editor. + */ +package org.librecms.ui.contentsections.documents; + +/** + * + * @author Jens Pelzetter + */ +public class ItemAttachmentDto { + + private long attachmentId; + + private String uuid; + + private long sortKey; + + private String assetType; + + private String title; + + public long getAttachmentId() { + return attachmentId; + } + + public void setAttachmentId(final long attachmentId) { + this.attachmentId = attachmentId; + } + + public String getUuid() { + return uuid; + } + + public void setUuid(final String uuid) { + this.uuid = uuid; + } + + public long getSortKey() { + return sortKey; + } + + public void setSortKey(long sortKey) { + this.sortKey = sortKey; + } + + public String getAssetType() { + return assetType; + } + + public void setAssetType(final String assetType) { + this.assetType = assetType; + } + + public String getTitle() { + return title; + } + + public void setTitle(final String title) { + this.title = title; + } + +} 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 new file mode 100644 index 000000000..b1b305652 --- /dev/null +++ b/ccm-cms/src/main/java/org/librecms/ui/contentsections/documents/RelatedInfoStep.java @@ -0,0 +1,237 @@ +/* + * To change this license header, choose License Headers in Project Properties. + * To change this template file, choose Tools | Templates + * and open the template in the editor. + */ +package org.librecms.ui.contentsections.documents; + +import org.libreccm.l10n.GlobalizationHelper; +import org.librecms.assets.AssetTypeInfo; +import org.librecms.assets.AssetTypesManager; +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.ContentItemManager; +import org.librecms.contentsection.ContentSection; +import org.librecms.contentsection.ItemAttachment; +import org.librecms.contentsection.ItemAttachmentManager; + +import java.util.List; +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; +import javax.ws.rs.POST; +import javax.ws.rs.Path; + +/** + * + * @author Jens Pelzetter + */ +@RequestScoped +@Controller +@Path("/") +@AuthoringStepPathFragment(RelatedInfoStep.PATH_FRAGMENT) +@Named("CmsRelatedInfoStep") +public class RelatedInfoStep implements MvcAuthoringStep { + + static final String PATH_FRAGMENT = "relatedinfo"; + + @Inject + private AssetTypesManager assetTypesManager; + + @Inject + private AttachmentListManager listManager; + + @Inject + private AttachmentListL10NManager listL10NManager; + + @Inject + private AttachmentListRepository listRepo; + + @Inject + private ContentItemManager itemManager; + + @Inject + private GlobalizationHelper globalizationHelper; + + @Inject + private ItemAttachmentManager attachmentManager; + + private ContentItem document; + + private ContentSection section; + + @Override + public Class supportedDocumentType() { + return ContentItem.class; + } + + @Override + public String getLabel() { + return globalizationHelper + .getLocalizedTextsUtil(getBundle()) + .getText("authoringsteps.relatedinfo.label"); + } + + @Override + public String getDescription() { + return globalizationHelper + .getLocalizedTextsUtil(getBundle()) + .getText("authoringsteps.relatedinfo.description"); + } + + @Override + public String getBundle() { + return DefaultAuthoringStepConstants.BUNDLE; + } + + @Override + public ContentSection getContentSection() { + return section; + } + + @Override + public void setContentSection(final ContentSection section) { + this.section = section; + } + + @Override + public String getContentSectionLabel() { + return section.getLabel(); + } + + @Override + public String getContentSectionTitle() { + return globalizationHelper + .getValueFromLocalizedString(section.getTitle()); + } + + @Override + public ContentItem getContentItem() { + return document; + } + + @Override + public void setContentItem(final ContentItem document) { + this.document = document; + } + + @Override + public String getContentItemPath() { + return itemManager.getItemPath(document); + } + + @Override + public String getContentItemTitle() { + return globalizationHelper + .getValueFromLocalizedString(document.getTitle()); + } + + @Override + public String showStep() { + return "org/librecms/ui/contenttypes/relatedinfo.xhtml"; + } + + @Transactional + public List getAttachmentLists() { + return document + .getAttachments() + .stream() + .filter(list -> !list.getName().startsWith(".")) + .map(this::buildAttachmentListDto) + .collect(Collectors.toList()); + } + + @POST + @Path("/attachmentlists/@add") + @Transactional(Transactional.TxType.REQUIRED) + public String addAttachmentList( + @FormParam("listName") final String name, + @FormParam("listTitle") final String title + ) { + final AttachmentList list = listManager.createAttachmentList( + document, name + ); + list.getTitle().addValue( + globalizationHelper.getNegotiatedLocale(), title + ); + listRepo.save(list); + return String.format( + "redirect:/%s/@documents/%s/@authoringsteps/%s", + section.getLabel(), + getContentItemPath(), + PATH_FRAGMENT + ); + } + + // ToDo Remove Attachment List + // Add attachment (attach asset) + // Add internal link + // Remove attachment + // ToDo Move attachment list to first position + // ToDo Move attachment list up + // ToDo Move attachment list down + // ToDo Move item attachment to first position + // ToDo Move item attachment up + // ToDo Move item attachment down + private AttachmentListDto buildAttachmentListDto( + final AttachmentList attachmentList + ) { + final AttachmentListDto dto = new AttachmentListDto(); + dto.setAttachments( + attachmentList + .getAttachments() + .stream() + .map(this::buildItemAttachmentDto) + .collect(Collectors.toList()) + ); + dto.setDescription( + globalizationHelper + .getValueFromLocalizedString( + attachmentList.getDescription() + ) + ); + dto.setListId(attachmentList.getListId()); + dto.setName(attachmentList.getName()); + dto.setOrder(attachmentList.getOrder()); + dto.setTitle( + globalizationHelper + .getValueFromLocalizedString( + attachmentList.getTitle() + ) + ); + dto.setUuid(attachmentList.getUuid()); + return dto; + } + + private ItemAttachmentDto buildItemAttachmentDto( + final ItemAttachment itemAttachment + ) { + final ItemAttachmentDto dto = new ItemAttachmentDto(); + final AssetTypeInfo assetTypeInfo = assetTypesManager + .getAssetTypeInfo(itemAttachment.getAsset().getClass()); + dto.setAssetType( + globalizationHelper + .getLocalizedTextsUtil(assetTypeInfo.getLabelBundle()) + .getText(assetTypeInfo.getLabelKey()) + ); + dto.setAttachmentId(itemAttachment.getAttachmentId()); + dto.setSortKey(itemAttachment.getSortKey()); + dto.setTitle( + globalizationHelper + .getValueFromLocalizedString( + itemAttachment.getAsset().getTitle() + ) + ); + dto.setUuid(itemAttachment.getUuid()); + return dto; + } + +}