First part of authoring step for related info
parent
1e3c3c3f61
commit
c2bce08eef
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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 <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
|
||||
*/
|
||||
@Dependent
|
||||
public class AttachmentListRepository
|
||||
extends AbstractEntityRepository<Long, AttachmentList> {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
@Override
|
||||
public Class<AttachmentList> 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());
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -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 <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
|
||||
*/
|
||||
public class AttachmentListDto {
|
||||
|
||||
private long listId;
|
||||
|
||||
private String uuid;
|
||||
|
||||
private String name;
|
||||
|
||||
private long order;
|
||||
|
||||
private String title;
|
||||
|
||||
private String description;
|
||||
|
||||
private List<ItemAttachmentDto> 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<ItemAttachmentDto> getAttachments() {
|
||||
return Collections.unmodifiableList(attachments);
|
||||
}
|
||||
|
||||
public void setAttachments(final List<ItemAttachmentDto> attachments) {
|
||||
this.attachments = new ArrayList<>(attachments);
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
|
@ -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 <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
|
||||
*/
|
||||
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;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -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 <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
|
||||
*/
|
||||
@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<? extends ContentItem> 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<AttachmentListDto> 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;
|
||||
}
|
||||
|
||||
}
|
||||
Loading…
Reference in New Issue