diff --git a/ccm-cms/src/main/java/com/arsdigita/cms/ui/authoring/assets/relatedinfo/RelatedInfoStepController.java b/ccm-cms/src/main/java/com/arsdigita/cms/ui/authoring/assets/relatedinfo/RelatedInfoStepController.java index 70a91dd6d..5a78c6df5 100644 --- a/ccm-cms/src/main/java/com/arsdigita/cms/ui/authoring/assets/relatedinfo/RelatedInfoStepController.java +++ b/ccm-cms/src/main/java/com/arsdigita/cms/ui/authoring/assets/relatedinfo/RelatedInfoStepController.java @@ -114,11 +114,11 @@ class RelatedInfoStepController { .sorted((list1, list2) -> list1.compareTo(list2)) .collect(Collectors.toList()); - toMove.setOrder(0); + toMove.setListOrder(0); lists .stream() .filter(current -> !current.equals(toMove)) - .forEach(current -> current.setOrder(current.getOrder() + 1)); + .forEach(current -> current.setListOrder(current.getListOrder() + 1)); lists.forEach(entityManager::merge); } @@ -207,11 +207,11 @@ class RelatedInfoStepController { final int afterIndex = lists.indexOf(after); for (int i = afterIndex + 1; i < lists.size(); i++) { final AttachmentList current = lists.get(i); - current.setOrder(current.getOrder() + 1); + current.setListOrder(current.getListOrder() + 1); entityManager.merge(current); } - toMove.setOrder(afterIndex + 1); + toMove.setListOrder(afterIndex + 1); entityManager.merge(toMove); } 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 bec2266c8..8e115194d 100644 --- a/ccm-cms/src/main/java/org/librecms/contentsection/AttachmentList.java +++ b/ccm-cms/src/main/java/org/librecms/contentsection/AttachmentList.java @@ -85,7 +85,7 @@ import static org.librecms.CmsConstants.DB_SCHEMA; query = "SELECT l FROM AttachmentList l " + "WHERE l.name = :name " + "AND l.item = :item " - + "ORDER BY l.order") + + "ORDER BY l.listOrder") }) public class AttachmentList implements Comparable, Identifiable, @@ -121,11 +121,11 @@ public class AttachmentList implements Comparable, private String name; /** - * A order index for ordering multiple attachment lists with the same - * {@link #name}. + * A listOrder index for ordering multiple attachment lists with the same + {@link #name}. */ @Column(name = "LIST_ORDER") - private long order; + private long listOrder; /** * The localised title of the list. @@ -201,12 +201,12 @@ public class AttachmentList implements Comparable, this.name = name; } - public long getOrder() { - return order; + public long getListOrder() { + return listOrder; } - public void setOrder(final long order) { - this.order = order; + public void setListOrder(final long listOrder) { + this.listOrder = listOrder; } public LocalizedString getTitle() { @@ -254,7 +254,7 @@ public class AttachmentList implements Comparable, final int nameCompare = name.compareTo(other.getName()); if (nameCompare == 0) { - return Long.compare(order, other.getOrder()); + return Long.compare(listOrder, other.getListOrder()); } else { return nameCompare; } @@ -266,7 +266,7 @@ public class AttachmentList implements Comparable, hash = 29 * hash + (int) (listId ^ (listId >>> 32)); hash = 29 * hash + Objects.hashCode(uuid); hash = 29 * hash + Objects.hashCode(name); - hash = 29 * hash + (int) (order ^ (order >>> 32)); + hash = 29 * hash + (int) (listOrder ^ (listOrder >>> 32)); hash = 29 * hash + Objects.hashCode(title); hash = 29 * hash + Objects.hashCode(description); hash = 29 * hash + Objects.hashCode(attachments); @@ -299,7 +299,7 @@ public class AttachmentList implements Comparable, System.out.println("uuid is not equal"); return false; } - if (order != other.getOrder()) { + if (listOrder != other.getListOrder()) { return false; } if (!Objects.equals(name, other.getName())) { @@ -344,7 +344,7 @@ public class AttachmentList implements Comparable, listId, uuid, name, - order, + listOrder, Objects.toString(title), Objects.toString(description), Objects.toString(attachments), diff --git a/ccm-cms/src/main/java/org/librecms/contentsection/AttachmentListManager.java b/ccm-cms/src/main/java/org/librecms/contentsection/AttachmentListManager.java index 303b435ac..11b7ba9f7 100644 --- a/ccm-cms/src/main/java/org/librecms/contentsection/AttachmentListManager.java +++ b/ccm-cms/src/main/java/org/librecms/contentsection/AttachmentListManager.java @@ -70,7 +70,7 @@ public class AttachmentListManager { */ private void normalizeOrder(final List lists) { for (int i = 0; i < lists.size(); i++) { - lists.get(i).setOrder(i); + lists.get(i).setListOrder(i); entityManager.merge(lists.get(i)); } } @@ -201,14 +201,14 @@ public class AttachmentListManager { if (lists.isEmpty()) { lastOrder = 0; } else { - lastOrder = lists.get(lists.size() - 1).getOrder(); + lastOrder = lists.get(lists.size() - 1).getListOrder(); } final AttachmentList list = new AttachmentList(); list.setItem(draft); list.setName(name); list.setUuid(UUID.randomUUID().toString()); - list.setOrder(lastOrder + 1); + list.setListOrder(lastOrder + 1); draft.addAttachmentList(list); @@ -270,10 +270,10 @@ public class AttachmentListManager { list.setItem(draft); list.setName(name); list.setUuid(UUID.randomUUID().toString()); - list.setOrder(listPos); + list.setListOrder(listPos); for (long i = listPos; i < lists.size(); i++) { - lists.get((int) i).setOrder(i + 1); + lists.get((int) i).setListOrder(i + 1); entityManager.merge(lists.get((int) i)); } @@ -336,21 +336,21 @@ public class AttachmentListManager { .getAttachments(); final Optional list1 = lists.stream() - .filter(list -> list.getOrder() == attachmentList.getOrder()) + .filter(list -> list.getListOrder() == attachmentList.getListOrder()) .findFirst(); final Optional list2 = lists.stream() - .filter(list -> list.getOrder() >= attachmentList.getOrder() + 1) + .filter(list -> list.getListOrder() >= attachmentList.getListOrder() + 1) .findFirst(); if (!list2.isPresent()) { return; } - final long order1 = list1.get().getOrder(); - final long order2 = list2.get().getOrder(); + final long order1 = list1.get().getListOrder(); + final long order2 = list2.get().getListOrder(); - list1.get().setOrder(order2); - list2.get().setOrder(order1); + list1.get().setListOrder(order2); + list2.get().setListOrder(order1); entityManager.merge(list1.get()); entityManager.merge(list2.get()); @@ -374,10 +374,10 @@ public class AttachmentListManager { .getAttachments(); final Optional list1 = lists.stream() - .filter(list -> list.getOrder() == attachmentList.getOrder()) + .filter(list -> list.getListOrder() == attachmentList.getListOrder()) .findFirst(); final List lower = lists.stream() - .filter(list -> list.getOrder() <= attachmentList.getOrder() - 1) + .filter(list -> list.getListOrder() <= attachmentList.getListOrder() - 1) .collect(Collectors.toList()); Collections.sort(lower); @@ -392,11 +392,11 @@ public class AttachmentListManager { return; } - final long order1 = list1.get().getOrder(); - final long order2 = list2.get().getOrder(); + final long order1 = list1.get().getListOrder(); + final long order2 = list2.get().getListOrder(); - list1.get().setOrder(order2); - list2.get().setOrder(order1); + list1.get().setListOrder(order2); + list2.get().setListOrder(order1); entityManager.merge(list1.get()); entityManager.merge(list2.get()); diff --git a/ccm-cms/src/main/java/org/librecms/contentsection/ContentItem.java b/ccm-cms/src/main/java/org/librecms/contentsection/ContentItem.java index 00e664e18..e9e4d6de9 100644 --- a/ccm-cms/src/main/java/org/librecms/contentsection/ContentItem.java +++ b/ccm-cms/src/main/java/org/librecms/contentsection/ContentItem.java @@ -65,7 +65,6 @@ import javax.persistence.OrderBy; import javax.xml.bind.annotation.XmlElement; import javax.xml.bind.annotation.XmlElementWrapper; - /** * Base type for all content item types. Specifies some common properties. * @@ -79,105 +78,100 @@ import javax.xml.bind.annotation.XmlElementWrapper; @NamedQuery( name = "ContentItem.findById", query - = "SELECT DISTINCT i " - + "FROM ContentItem i " - + "LEFT JOIN i.permissions p " - + "WHERE i.objectId = :objectId " - + "AND (" - + " (" - + " p.grantee IN :roles " - + " AND p.grantedPrivilege = " - + " (CASE WHEN i.version = 'DRAFT' " - + " THEN '" + ItemPrivileges.PREVIEW + "' " - + " ELSE '" + ItemPrivileges.VIEW_PUBLISHED + "' " - + " END" - + " )" - + " ) " - + " OR true = :isSystemUser OR true = :isAdmin" - + " )") - , + = "SELECT DISTINCT i " + + "FROM ContentItem i " + + "LEFT JOIN i.permissions p " + + "WHERE i.objectId = :objectId " + + "AND (" + + " (" + + " p.grantee IN :roles " + + " AND p.grantedPrivilege = " + + " (CASE WHEN i.version = 'DRAFT' " + + " THEN '" + ItemPrivileges.PREVIEW + "' " + + " ELSE '" + ItemPrivileges.VIEW_PUBLISHED + "' " + + " END" + + " )" + + " ) " + + " OR true = :isSystemUser OR true = :isAdmin" + + " )"), @NamedQuery( name = "ContentItem.findByUuid", query - = "SELECT DISTINCT i " - + "FROM ContentItem i " - + "LEFT JOIN i.permissions p " - + "WHERE i.uuid = :uuid " - + "AND (" - + " (" - + " p.grantee IN :roles " - + " AND p.grantedPrivilege = " - + " (CASE WHEN i.version = 'DRAFT' " - + " THEN '" + ItemPrivileges.PREVIEW + "' " - + " ELSE '" + ItemPrivileges.VIEW_PUBLISHED + "' " - + " END" - + " )" - + " ) " - + " OR true = :isSystemUser OR true = :isAdmin" - + " )") - , + = "SELECT DISTINCT i " + + "FROM ContentItem i " + + "LEFT JOIN i.permissions p " + + "WHERE i.uuid = :uuid " + + "AND (" + + " (" + + " p.grantee IN :roles " + + " AND p.grantedPrivilege = " + + " (CASE WHEN i.version = 'DRAFT' " + + " THEN '" + ItemPrivileges.PREVIEW + "' " + + " ELSE '" + ItemPrivileges.VIEW_PUBLISHED + "' " + + " END" + + " )" + + " ) " + + " OR true = :isSystemUser OR true = :isAdmin" + + " )"), @NamedQuery( name = "ContentItem.findByType", query - = "SELECT DISTINCT i " - + "FROM ContentItem i " - + "LEFT JOIN i.permissions p " - + "WHERE TYPE(i) = :type " - + "AND (" - + " (" - + " p.grantee IN :roles " - + " AND p.grantedPrivilege = " - + " (CASE WHEN i.version = 'DRAFT' " - + " THEN '" + ItemPrivileges.PREVIEW + "' " - + " ELSE '" + ItemPrivileges.VIEW_PUBLISHED + "' " - + " END" - + " )" - + " ) " - + " OR true = :isSystemUser OR true = :isAdmin" - + " )") - , + = "SELECT DISTINCT i " + + "FROM ContentItem i " + + "LEFT JOIN i.permissions p " + + "WHERE TYPE(i) = :type " + + "AND (" + + " (" + + " p.grantee IN :roles " + + " AND p.grantedPrivilege = " + + " (CASE WHEN i.version = 'DRAFT' " + + " THEN '" + ItemPrivileges.PREVIEW + "' " + + " ELSE '" + ItemPrivileges.VIEW_PUBLISHED + "' " + + " END" + + " )" + + " ) " + + " OR true = :isSystemUser OR true = :isAdmin" + + " )"), @NamedQuery( name = "ContentItem.findByIdAndType", query - = "SELECT DISTINCT i " - + "FROM ContentItem i " - + "LEFT JOIN i.permissions p " - + "WHERE i.objectId = :objectId " - + "AND TYPE(i) = :type " - + "AND (" - + " (" - + " p.grantee IN :roles " - + " AND p.grantedPrivilege = " - + " (CASE WHEN i.version = 'DRAFT' " - + " THEN '" + ItemPrivileges.PREVIEW + "' " - + " ELSE '" + ItemPrivileges.VIEW_PUBLISHED + "' " - + " END" - + " )" - + " ) " - + " OR true = :isSystemUser OR true = :isAdmin" - + " )") - , + = "SELECT DISTINCT i " + + "FROM ContentItem i " + + "LEFT JOIN i.permissions p " + + "WHERE i.objectId = :objectId " + + "AND TYPE(i) = :type " + + "AND (" + + " (" + + " p.grantee IN :roles " + + " AND p.grantedPrivilege = " + + " (CASE WHEN i.version = 'DRAFT' " + + " THEN '" + ItemPrivileges.PREVIEW + "' " + + " ELSE '" + ItemPrivileges.VIEW_PUBLISHED + "' " + + " END" + + " )" + + " ) " + + " OR true = :isSystemUser OR true = :isAdmin" + + " )"), @NamedQuery( name = "ContentItem.findByUuidAndType", query - = "SELECT DISTINCT i " - + "FROM ContentItem i " - + "LEFT JOIN i.permissions p " - + "WHERE i.uuid = :uuid " - + "AND TYPE(i) = :type " - + "AND (" - + " (" - + " p.grantee IN :roles " - + " AND p.grantedPrivilege = " - + " (CASE WHEN i.version = 'DRAFT' " - + " THEN '" + ItemPrivileges.PREVIEW + "' " - + " ELSE '" + ItemPrivileges.VIEW_PUBLISHED + "' " - + " END" - + " )" - + " ) " - + " OR true = :isSystemUser OR true = :isAdmin" - + " )") - , + = "SELECT DISTINCT i " + + "FROM ContentItem i " + + "LEFT JOIN i.permissions p " + + "WHERE i.uuid = :uuid " + + "AND TYPE(i) = :type " + + "AND (" + + " (" + + " p.grantee IN :roles " + + " AND p.grantedPrivilege = " + + " (CASE WHEN i.version = 'DRAFT' " + + " THEN '" + ItemPrivileges.PREVIEW + "' " + + " ELSE '" + ItemPrivileges.VIEW_PUBLISHED + "' " + + " END" + + " )" + + " ) " + + " OR true = :isSystemUser OR true = :isAdmin" + + " )"), @NamedQuery( name = "ContentItem.findByContentSection", query = "SELECT DISTINCT i " @@ -197,8 +191,7 @@ import javax.xml.bind.annotation.XmlElementWrapper; + " )" + " )" + " OR true = :isSystemUser OR true = :isAdmin" - + ")") - , + + ")"), @NamedQuery( name = "ContentItem.findByContentSectionAndVersion", query = "SELECT DISTINCT i " @@ -219,8 +212,7 @@ import javax.xml.bind.annotation.XmlElementWrapper; + " )" + " )" + " OR true = :isSystemUser OR true = :isAdmin" - + ")") - , + + ")"), @NamedQuery( name = "ContentItem.findByNameAndContentSection", query = "SELECT DISTINCT i " @@ -241,8 +233,7 @@ import javax.xml.bind.annotation.XmlElementWrapper; + " )" + " )" + " OR true = :isSystemUser OR true = :isAdmin" - + ")") - , + + ")"), @NamedQuery( name = "ContentItem.findByNameAndContentSectionAndVersion", query = "SELECT DISTINCT i " @@ -264,9 +255,7 @@ import javax.xml.bind.annotation.XmlElementWrapper; + " )" + " )" + " OR true = :isSystemUser OR true = :isAdmin" - + ")") - - , + + ")"), @NamedQuery( name = "ContentItem.findByTypeAndContentSection", query = "SELECT DISTINCT i " @@ -287,8 +276,7 @@ import javax.xml.bind.annotation.XmlElementWrapper; + " )" + " )" + " OR true = :isSystemUser OR true = :isAdmin" - + ")") - , + + ")"), @NamedQuery( name = "ContentItem.findByTypeAndContentSectionAndVersion", query = "SELECT DISTINCT i " @@ -311,9 +299,7 @@ import javax.xml.bind.annotation.XmlElementWrapper; + " )" + " OR true = :isSystemUser OR true = :isAdmin" + ")" - ) - - , + ), @NamedQuery( name = "ContentItem.findByNameAndTypeAndContentSection", query = "SELECT DISTINCT i " @@ -335,9 +321,8 @@ import javax.xml.bind.annotation.XmlElementWrapper; + " )" + " )" + " OR true = :isSystemUser OR true = :isAdmin" - + ")") - , - @NamedQuery( + + ")"), + @NamedQuery( name = "ContentItem.findByNameAndTypeAndContentSectionAndVersion", query = "SELECT DISTINCT i " + "FROM ContentItem i " @@ -359,77 +344,73 @@ import javax.xml.bind.annotation.XmlElementWrapper; + " )" + " )" + " OR true = :isSystemUser OR true = :isAdmin" - + ")") - , + + ")"), @NamedQuery( name = "ContentItem.findByFolder", query - = "SELECT DISTINCT i " - + "FROM ContentItem i " - + "JOIN i.categories c " - + "LEFT JOIN i.permissions p " - + "WHERE c.category = :folder " - + "AND c.type = '" + CATEGORIZATION_TYPE_FOLDER + "' " - + "AND (" - + " (" - + " p.grantee IN :roles " - + " AND p.grantedPrivilege = " - + " (CASE WHEN i.version = 'DRAFT' " - + " THEN '" + ItemPrivileges.PREVIEW + "' " - + " ELSE '" + ItemPrivileges.VIEW_PUBLISHED + "' " - + " END" - + " )" - + " )" - + " OR true = :isSystemUser OR true = :isAdmin" - + " )") - , + = "SELECT DISTINCT i " + + "FROM ContentItem i " + + "JOIN i.categories c " + + "LEFT JOIN i.permissions p " + + "WHERE c.category = :folder " + + "AND c.type = '" + CATEGORIZATION_TYPE_FOLDER + "' " + + "AND (" + + " (" + + " p.grantee IN :roles " + + " AND p.grantedPrivilege = " + + " (CASE WHEN i.version = 'DRAFT' " + + " THEN '" + ItemPrivileges.PREVIEW + "' " + + " ELSE '" + ItemPrivileges.VIEW_PUBLISHED + "' " + + " END" + + " )" + + " )" + + " OR true = :isSystemUser OR true = :isAdmin" + + " )"), @NamedQuery( name = "ContentItem.countItemsInFolder", query - = "SELECT COUNT(DISTINCT i) " - + "FROM ContentItem i " - + "JOIN i.categories c " - + "LEFT JOIN i.permissions p " - + "WHERE c.category = :folder " - + "AND c.type = '" + CATEGORIZATION_TYPE_FOLDER + "' " - + "AND (" - + " (" - + " p.grantee IN :roles " - + " AND p.grantedPrivilege = " - + " (CASE WHEN i.version = 'DRAFT' " - + " THEN '" + ItemPrivileges.PREVIEW + "' " - + " ELSE '" + ItemPrivileges.VIEW_PUBLISHED + "' " - + " END" - + " )" - + " )" - + " OR true = :isSystemUser OR true = :isAdmin" - + " )") - , + = "SELECT COUNT(DISTINCT i) " + + "FROM ContentItem i " + + "JOIN i.categories c " + + "LEFT JOIN i.permissions p " + + "WHERE c.category = :folder " + + "AND c.type = '" + CATEGORIZATION_TYPE_FOLDER + "' " + + "AND (" + + " (" + + " p.grantee IN :roles " + + " AND p.grantedPrivilege = " + + " (CASE WHEN i.version = 'DRAFT' " + + " THEN '" + ItemPrivileges.PREVIEW + "' " + + " ELSE '" + ItemPrivileges.VIEW_PUBLISHED + "' " + + " END" + + " )" + + " )" + + " OR true = :isSystemUser OR true = :isAdmin" + + " )"), @NamedQuery( name = "ContentItem.findByNameInFolder", query - = "SELECT DISTINCT i " - + "FROM ContentItem i " - + "JOIN i.categories c " - + "LEFT JOIN i.permissions p " - + "WHERE c.category = :folder " - + "AND c.type = '" + CATEGORIZATION_TYPE_FOLDER + "' " - + "AND i.displayName = :name " - + "AND i.version = 'DRAFT' " - + "AND (" - + " (" - + " p.grantee IN :roles " - + " AND p.grantedPrivilege = " - + " (CASE WHEN i.version = 'DRAFT' " - + " THEN '" + ItemPrivileges.PREVIEW + "' " - + " ELSE '" + ItemPrivileges.VIEW_PUBLISHED + "' " - + " END" - + " )" - + " )" - + " OR true = :isSystemUser OR true = :isAdmin" - + " )") - , + = "SELECT DISTINCT i " + + "FROM ContentItem i " + + "JOIN i.categories c " + + "LEFT JOIN i.permissions p " + + "WHERE c.category = :folder " + + "AND c.type = '" + CATEGORIZATION_TYPE_FOLDER + "' " + + "AND i.displayName = :name " + + "AND i.version = 'DRAFT' " + + "AND (" + + " (" + + " p.grantee IN :roles " + + " AND p.grantedPrivilege = " + + " (CASE WHEN i.version = 'DRAFT' " + + " THEN '" + ItemPrivileges.PREVIEW + "' " + + " ELSE '" + ItemPrivileges.VIEW_PUBLISHED + "' " + + " END" + + " )" + + " )" + + " OR true = :isSystemUser OR true = :isAdmin" + + " )"), @NamedQuery( name = "ContentItem.countByNameInFolder", query = "SELECT COUNT(DISTINCT i)" @@ -451,8 +432,7 @@ import javax.xml.bind.annotation.XmlElementWrapper; + " )" + " )" + " OR true = :isSystemUser OR true = :isAdmin" - + " )") - , + + " )"), @NamedQuery( name = "ContentItem.filterByFolderAndName", query = "SELECT DISTINCT i " @@ -474,8 +454,7 @@ import javax.xml.bind.annotation.XmlElementWrapper; + " )" + " OR true = :isSystemUser OR true = :isAdmin" + " ) " - + "ORDER BY i.displayName") - , + + "ORDER BY i.displayName"), @NamedQuery( name = "ContentItem.countFilterByFolderAndName", query = "SELECT COUNT(DISTINCT i) FROM ContentItem i " @@ -496,8 +475,7 @@ import javax.xml.bind.annotation.XmlElementWrapper; + " )" + " OR true = :isSystemUser OR true = :isAdmin" + " )" - ) - , + ), @NamedQuery( name = "ContentItem.filterByFolderAndType", query = "SELECT DISTINCT i " @@ -519,8 +497,7 @@ import javax.xml.bind.annotation.XmlElementWrapper; + " )" + " OR true = :isSystemUser OR true = :isAdmin" + " ) " - + "ORDER BY i.displayName") - , + + "ORDER BY i.displayName"), @NamedQuery( name = "ContentItem.filterByFolderAndTypeAndName", query = "SELECT DISTINCT i " @@ -543,44 +520,40 @@ import javax.xml.bind.annotation.XmlElementWrapper; + " )" + " OR true = :isSystemUser OR true = :isAdmin" + " ) " - + "ORDER BY i.displayName") - , + + "ORDER BY i.displayName"), @NamedQuery( name = "ContentItem.hasLiveVersion", query = "SELECT (CASE WHEN COUNT(i) > 0 THEN true ELSE false END) " + "FROM ContentItem i " + "WHERE i.itemUuid = :uuid " - + "AND i.version = org.librecms.contentsection.ContentItemVersion.LIVE") - , + + "AND i.version = org.librecms.contentsection.ContentItemVersion.LIVE"), @NamedQuery( name = "ContentItem.findDraftVersion", query - = "SELECT DISTINCT i " - + "FROM ContentItem i " - + "LEFT JOIN i.permissions p " - + "WHERE i.itemUuid = :uuid " - + "AND i.version = 'DRAFT' " - + "AND " - + "((p.grantee IN :roles " - + "AND p.grantedPrivilege = '" + ItemPrivileges.PREVIEW + "' " - + ") OR true = :isSystemUser OR true = :isAdmin)") - , + = "SELECT DISTINCT i " + + "FROM ContentItem i " + + "LEFT JOIN i.permissions p " + + "WHERE i.itemUuid = :uuid " + + "AND i.version = 'DRAFT' " + + "AND " + + "((p.grantee IN :roles " + + "AND p.grantedPrivilege = '" + ItemPrivileges.PREVIEW + "' " + + ") OR true = :isSystemUser OR true = :isAdmin)"), @NamedQuery( name = "ContentItem.findLiveVersion", query - = "SELECT DISTINCT i " - + "FROM ContentItem i " - + "LEFT JOIN i.permissions p " - + "WHERE i.itemUuid = :uuid " - + "AND i.version = 'LIVE' " - + "AND " - + "((p.grantee IN :roles " - + "AND p.grantedPrivilege = " - + "'" - + ItemPrivileges.VIEW_PUBLISHED - + "' " - + ") OR true = :isSystemUser OR true = :isAdmin)") - , + = "SELECT DISTINCT i " + + "FROM ContentItem i " + + "LEFT JOIN i.permissions p " + + "WHERE i.itemUuid = :uuid " + + "AND i.version = 'LIVE' " + + "AND " + + "((p.grantee IN :roles " + + "AND p.grantedPrivilege = " + + "'" + + ItemPrivileges.VIEW_PUBLISHED + + "' " + + ") OR true = :isSystemUser OR true = :isAdmin)"), @NamedQuery( name = "ContentItem.findItemWithWorkflow", query = "SELECT DISTINCT i " @@ -697,7 +670,7 @@ public class ContentItem extends CcmObject implements Serializable, Exportable { private String ancestors; @OneToMany(mappedBy = "item", fetch = FetchType.LAZY) - @OrderBy("order ASC") + @OrderBy("list_order ASC") @XmlElementWrapper(name = "attachments", namespace = CMS_XML_NS) @JsonIgnore private List attachments; @@ -850,7 +823,6 @@ public class ContentItem extends CcmObject implements Serializable, Exportable { } public List getAttachments() { - Collections.sort(attachments); return Collections.unmodifiableList(attachments); } diff --git a/ccm-cms/src/main/java/org/librecms/contentsection/ContentItemManager.java b/ccm-cms/src/main/java/org/librecms/contentsection/ContentItemManager.java index bbab650cc..87d932bc7 100644 --- a/ccm-cms/src/main/java/org/librecms/contentsection/ContentItemManager.java +++ b/ccm-cms/src/main/java/org/librecms/contentsection/ContentItemManager.java @@ -680,7 +680,7 @@ public class ContentItemManager { .getDescription()); targetList.setItem(target); targetList.setName(sourceList.getName()); - targetList.setOrder(sourceList.getOrder()); + targetList.setListOrder(sourceList.getListOrder()); copyLocalizedString(sourceList.getTitle(), targetList.getTitle()); targetList.setUuid(UUID.randomUUID().toString()); @@ -1116,7 +1116,7 @@ public class ContentItemManager { targetList.setName(sourceList.getName()); copyLocalizedString(sourceList.getTitle(), targetList.getTitle()); - targetList.setOrder(sourceList.getOrder()); + targetList.setListOrder(sourceList.getListOrder()); targetList.setUuid(UUID.randomUUID().toString()); } else { targetList = liveItem.getAttachments().get(i); diff --git a/ccm-cms/src/main/java/org/librecms/pagemodel/contentitems/AbstractContentItemRenderer.java b/ccm-cms/src/main/java/org/librecms/pagemodel/contentitems/AbstractContentItemRenderer.java index f176bdf09..19a781674 100644 --- a/ccm-cms/src/main/java/org/librecms/pagemodel/contentitems/AbstractContentItemRenderer.java +++ b/ccm-cms/src/main/java/org/librecms/pagemodel/contentitems/AbstractContentItemRenderer.java @@ -164,7 +164,7 @@ public abstract class AbstractContentItemRenderer implements Serializable { * "listId": {@link AttachmentList#getListId()} * "uuid": {@link AttachmentList#getUuid()} * "name": {@link AttachmentList#getName()} - * "order": {@link AttachmentList#getOrder()} + * "order": {@link AttachmentList#getListOrder()} * "title": {@link AttachmentList#getTitle()} * "description": {@link AttachmentList#getDescription()} * "attachments": {@link AttachmentList#getAttachments()} @@ -189,7 +189,7 @@ public abstract class AbstractContentItemRenderer implements Serializable { result.put("listId", attachmentList.getListId()); result.put("uuid", attachmentList.getUuid()); result.put("name", attachmentList.getName()); - result.put("order", attachmentList.getOrder()); + result.put("order", attachmentList.getListOrder()); result.put("title", attachmentList.getTitle().getValue(language)); result.put("description", attachmentList.getDescription().getValue(language)); diff --git a/ccm-cms/src/main/java/org/librecms/ui/contentsections/documents/relatedinfo/RelatedInfoStep.java b/ccm-cms/src/main/java/org/librecms/ui/contentsections/documents/relatedinfo/RelatedInfoStep.java index 054ca91cb..b4deaf0d8 100644 --- a/ccm-cms/src/main/java/org/librecms/ui/contentsections/documents/relatedinfo/RelatedInfoStep.java +++ b/ccm-cms/src/main/java/org/librecms/ui/contentsections/documents/relatedinfo/RelatedInfoStep.java @@ -2141,7 +2141,7 @@ public class RelatedInfoStep extends AbstractMvcAuthoringStep { ); dto.setListId(attachmentList.getListId()); dto.setName(attachmentList.getName()); - dto.setOrder(attachmentList.getOrder()); + dto.setOrder(attachmentList.getListOrder()); dto.setTitle( globalizationHelper .getValueFromLocalizedString( diff --git a/ccm-cms/src/main/java/org/librecms/ui/contentsections/documents/relatedinfo/RelatedInfoStepModel.java b/ccm-cms/src/main/java/org/librecms/ui/contentsections/documents/relatedinfo/RelatedInfoStepModel.java index 872a96831..72e870313 100644 --- a/ccm-cms/src/main/java/org/librecms/ui/contentsections/documents/relatedinfo/RelatedInfoStepModel.java +++ b/ccm-cms/src/main/java/org/librecms/ui/contentsections/documents/relatedinfo/RelatedInfoStepModel.java @@ -55,7 +55,7 @@ public class RelatedInfoStepModel { } public List getAttachmentsLists() { - return attachmentsLists; + return Collections.unmodifiableList(attachmentsLists); } public void setAttachmentsLists(List attachmentsLists) { diff --git a/ccm-cms/src/main/java/org/librecms/ui/contentsections/documents/relatedinfo/RelatedInfoStepService.java b/ccm-cms/src/main/java/org/librecms/ui/contentsections/documents/relatedinfo/RelatedInfoStepService.java index db04589da..f7080fbd1 100644 --- a/ccm-cms/src/main/java/org/librecms/ui/contentsections/documents/relatedinfo/RelatedInfoStepService.java +++ b/ccm-cms/src/main/java/org/librecms/ui/contentsections/documents/relatedinfo/RelatedInfoStepService.java @@ -22,62 +22,40 @@ import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; import org.libreccm.l10n.GlobalizationHelper; import org.libreccm.security.PermissionChecker; -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.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.contentsection.privileges.ItemPrivileges; -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.ContentSectionsUi; -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 org.librecms.ui.contentsections.documents.MvcAuthoringSteps; -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 java.util.Map; import javax.enterprise.context.RequestScoped; import javax.inject.Inject; import javax.transaction.Transactional; +import javax.ws.rs.BadRequestException; import javax.ws.rs.Consumes; -import javax.ws.rs.DefaultValue; -import javax.ws.rs.ForbiddenException; -import javax.ws.rs.GET; import javax.ws.rs.NotFoundException; 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; import javax.ws.rs.core.Response; @@ -170,683 +148,775 @@ public class RelatedInfoStepService { // ToDo LOGGER.info("order = {}", order); + final ContentSection contentSection = sectionsUi + .findContentSection(sectionIdentifier) + .orElseThrow( + () -> new NotFoundException( + String.format( + "No content identifed by %s found.", + sectionIdentifier + ) + ) + ); + + final ContentItem document = itemRepo + .findByPath(contentSection, documentPath) + .orElseThrow( + () -> new NotFoundException( + String.format( + "No document for path %s in section %s.", + documentPath, + contentSection.getLabel() + ) + ) + ); + + final List attachmentLists = document.getAttachments(); + final List attachmentListsOrder = order + .getAttachmentListsOrder(); + + if (attachmentListsOrder.size() != attachmentLists.size()) { + throw new BadRequestException( + String.format( + "Size of lists of attachment lists does not match list of " + + "attachment order list. attachmentLists.size = %d, " + + "attachmentListsOrder.size = %d.", + attachmentLists.size(), + attachmentListsOrder.size() + ) + ); + } + + for (int i = 0; i < attachmentListsOrder.size(); i++) { + final String listUuid = attachmentListsOrder.get(i); + final AttachmentList attachmentList = attachmentLists + .stream() + .filter(list -> listUuid.equals(list.getUuid())) + .findAny() + .orElseThrow( + () -> new BadRequestException( + String.format( + "attachmentListsOrder has an entry for attachment " + + "list %s, but there no attachment list with " + + "that UUID.", + listUuid + ) + ) + ); + + attachmentList.setListOrder(i); + attachmentListRepo.save(attachmentList); + } + + for (final Map.Entry> attachmentsOrder : order + .getAttachmentsOrder().entrySet()) { + final AttachmentList attachmentList = document + .getAttachments() + .stream() + .filter(list -> attachmentsOrder.getKey().equals(list.getUuid())) + .findAny() + .orElseThrow( + () -> new BadRequestException( + String.format( + "attachmentsOrder contains an entry for " + + "attachment list %s, but there no attachment " + + "list with that UUID.", + attachmentsOrder.getKey() + ) + ) + ); + + final List> attachments = attachmentList.getAttachments(); + if (attachments.size() != attachmentsOrder.getValue().size()) { + throw new BadRequestException( + String.format( + "Size of attachmentsOrder list does not match the size" + + "of the attachments list. " + + "attachmentsOrder.size = %d, " + + "attachmentsList.size = %d", + attachmentsOrder.getValue().size(), + attachments.size() + ) + ); + } + + for(int i = 0; i < attachmentsOrder.getValue().size(); i++) { + final String attachmentUuid = attachmentsOrder.getValue().get(i); + final ItemAttachment attachment = attachments + .stream() + .filter(current -> attachmentUuid.equals(current.getUuid())) + .findAny() + .orElseThrow( + () -> new BadRequestException( + String.format( + "attachmentOrder order for attachment list %s " + + "has an entry for attachment %s but " + + "there is attachment with that UUID in " + + "the list.", + attachmentList.getUuid(), + attachmentUuid + ) + ) + ); + attachment.setSortKey(i); + attachmentManager.save(attachment); + } + } + return Response.ok().build(); -// final ContentSection contentSection = sectionsUi -// .findContentSection(sectionIdentifier) -// .orElseThrow( -// () -> new NotFoundException( -// String.format( -// "No content identifed by %s found.", -// sectionIdentifier -// ) -// ) -// ); -// -// final ContentItem document = itemRepo -// .findByPath(contentSection, documentPath) -// .orElseThrow( -// () -> new NotFoundException( -// String.format( -// "No document for path %s in section %s.", -// documentPath, -// contentSection.getLabel() -// ) -// ) -// ); // // //final Map attachmentListIndexes = } - /** - * Gets the asset folder tree of the current content section as JSON data. - * - * @param sectionIdentifier - * @param documentPath - * - * @return The assets folder tree of the current content section as JSON - * data. - */ - @GET - @Path("/asset-folders") - @Produces(MediaType.APPLICATION_JSON) - @Transactional(Transactional.TxType.REQUIRED) - public List getAssetFolderTree( - @PathParam(MvcAuthoringSteps.SECTION_IDENTIFIER_PATH_PARAM) - final String sectionIdentifier, - @PathParam(MvcAuthoringSteps.DOCUMENT_PATH_PATH_PARAM_NAME) - final String documentPath - ) { - final ContentSection section = retrieveContentSection( - sectionIdentifier - ); - - if (permissionChecker.isPermitted( - ItemPrivileges.EDIT, retrieveDocument(section, documentPath) - )) { - return assetFolderTree.buildFolderTree( - section, section.getRootAssetsFolder() - ); - } else { - throw new ForbiddenException(); - } - } - - /** - * Gets the assets in the folder as JSON data. - * - * @param folderPath The path of the folder. - * @param firstResult The index of the firset result to show. - * @param maxResults The maximum number of results to show. - * @param filterTerm An optional filter term for filtering the assets - * in the folder by their name. - * @param documentPath - * @param sectionIdentifier - * - * @return A list of the assets in the folder as JSON data. - */ - @GET - @Path("/asset-folders/{folderPath}/assets") - @Produces(MediaType.APPLICATION_JSON) - @Transactional(Transactional.TxType.REQUIRED) - public List getAssetsInFolder( - @PathParam(MvcAuthoringSteps.SECTION_IDENTIFIER_PATH_PARAM) - final String sectionIdentifier, - @PathParam(MvcAuthoringSteps.DOCUMENT_PATH_PATH_PARAM_NAME) - final String documentPath, - @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 ContentSection section = retrieveContentSection(sectionIdentifier); - - if (permissionChecker.isPermitted( - ItemPrivileges.EDIT, retrieveDocument(section, documentPath) - )) { - 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()); - } else { - throw new ForbiddenException(); - } - } - - /** - * Show all assets of a content section filtered by their name. - * - * @param sectionIdentifier - * @param documentPath - * @param firstResult The index of the first result to show. - * @param maxResults The maximum number of results to show. - * @param searchTerm An optional search term applied to the names of - * the assets. - * - * @return A list of matching assets as JSON. - */ - @GET - @Path("/search-assets") - @Produces(MediaType.APPLICATION_JSON) - @Transactional(Transactional.TxType.REQUIRED) - public List findAssets( - @PathParam(MvcAuthoringSteps.SECTION_IDENTIFIER_PATH_PARAM) - final String sectionIdentifier, - @PathParam(MvcAuthoringSteps.DOCUMENT_PATH_PATH_PARAM_NAME) - final String documentPath, - @QueryParam("firstResult") - @DefaultValue("0") - final int firstResult, - @QueryParam("maxResults") - @DefaultValue("20") - final int maxResults, - @QueryParam("searchTerm") - @DefaultValue("") - final String searchTerm - ) { - final ContentSection section = retrieveContentSection(sectionIdentifier); - - if (permissionChecker.isPermitted( - ItemPrivileges.EDIT, retrieveDocument(section, documentPath) - )) { - return assetRepo.findByTitleAndContentSection(searchTerm, section) - .stream() - .map(asset -> buildAssetFolderRowModel(section, asset)) - .collect(Collectors.toList()); - } else { - throw new ForbiddenException(); - } - } - - private ContentSection retrieveContentSection( - final String sectionIdentifier - ) { - return sectionsUi.findContentSection( - sectionIdentifier - ).orElseThrow( - () -> new NotFoundException( - String.format( - "No content section identified by %s available.", - sectionIdentifier - ) - ) - ); - } - - /** - * Gets the document folder tree of the current content section as JSON - * data. - * - * @param sectionIdentifier - * @param documentPath - * - * @return The document folder tree of the current content section as JSON - * data. - */ - @GET - @Path("/document-folders") - @Produces(MediaType.APPLICATION_JSON) - @Transactional(Transactional.TxType.REQUIRED) - public List getDocumentFolderTree( - @PathParam(MvcAuthoringSteps.SECTION_IDENTIFIER_PATH_PARAM) - final String sectionIdentifier, - @PathParam(MvcAuthoringSteps.DOCUMENT_PATH_PATH_PARAM_NAME) - final String documentPath - ) { - final ContentSection section = retrieveContentSection(sectionIdentifier); - final ContentItem document = retrieveDocument(section, documentPath); - - if (permissionChecker.isPermitted( - ItemPrivileges.EDIT, document - )) { - return documentFolderTree.buildFolderTree( - section, section.getRootDocumentsFolder() - ); - } else { - throw new ForbiddenException(); - } - } - - /** - * Gets the documents in the folder as JSON data. - * - * @param sectionIdentifier - * @param documentPath - * @param folderPath The path of the folder. - * @param firstResult The index of the firset result to show. - * @param maxResults The maximum number of results to show. - * @param filterTerm An optional filter term for filtering the - * documents in the folder by their name. - * - * @return A list of the documents in the folder as JSON data. - */ - @GET - @Path("/document-folders/{folderPath}/documents") - @Produces(MediaType.APPLICATION_JSON) - @Transactional(Transactional.TxType.REQUIRED) - public List getDocumentsInFolder( - @PathParam(MvcAuthoringSteps.SECTION_IDENTIFIER_PATH_PARAM) - final String sectionIdentifier, - @PathParam(MvcAuthoringSteps.DOCUMENT_PATH_PATH_PARAM_NAME) - final String documentPath, - @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 ContentSection section = retrieveContentSection(sectionIdentifier); - final ContentItem document = retrieveDocument(section, documentPath); - - if (permissionChecker.isPermitted( - ItemPrivileges.EDIT, document - )) { - 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()); - } else { - throw new ForbiddenException(); - } - } - - /** - * Show all documents of a content section filtered by their name. - * - * @param sectionIdentifier - * @param documentPath - * @param firstResult The index of the first result to show. - * @param maxResults The maximum number of results to show. - * @param searchTerm An optional search term applied to the names of - * the docuemnts. - * - * @return A list of matching documents/content items as JSON. - */ - @GET - @Path("/search-documents") - @Produces(MediaType.APPLICATION_JSON) - @Transactional(Transactional.TxType.REQUIRED) - public List findDocuments( - @PathParam(MvcAuthoringSteps.SECTION_IDENTIFIER_PATH_PARAM) - final String sectionIdentifier, - @PathParam(MvcAuthoringSteps.DOCUMENT_PATH_PATH_PARAM_NAME) - final String documentPath, - @QueryParam("firstResult") - @DefaultValue("0") - final int firstResult, - @QueryParam("maxResults") - @DefaultValue("20") - final int maxResults, - @QueryParam("searchTerm") - @DefaultValue("") - final String searchTerm - ) { - final ContentSection section = retrieveContentSection(sectionIdentifier); - final ContentItem document = retrieveDocument(section, documentPath); - - if (permissionChecker.isPermitted( - ItemPrivileges.EDIT, document - )) { - return itemRepo.findByNameAndContentSection(searchTerm, section) - .stream() - .map(asset -> buildDocumentFolderRowModel(section, asset)) - .collect(Collectors.toList()); - } else { - throw new ForbiddenException(); - } - } - - private ContentItem retrieveDocument( - final ContentSection section, final String documentPath - ) { - return itemRepo - .findByPath(section, documentPath) - .orElseThrow( - () -> new NotFoundException( - String.format( - "No document with path %s found in content section %s.", - documentPath, - section.getLabel() - ) - ) - ); - } - - /** - * Build the model for a row in the asset folder listing. - * - * @param section The content section. - * @param entry The {@link AssetFolderEntry} from which the model is - * build. - * - * @return The {@link AssetFolderRowModel} for the provided {@code entry}. - */ - 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; - } - - /** - * Build the model for a row in the asset folder listing. - * - * @param section The content section. - * @param asset The {@link Asset} from which the model is build. - * - * @return The {@link AssetFolderRowModel} for the provided {@code asset}. - */ - 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; - } - - /** - * Build the model for a row in the document folder listing. - * - * @param section The content section. - * @param entry The {@link DocumentFolderEntry} from which the model is - * build. - * - * @return The {@link DocumentFolderRowModel} for the provided - * {@code entry}. - */ - 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; - } - - /** - * Build the model for a row in the document folder listing. - * - * @param section The content section. - * @param contentItem The {@link Contentitem} from which the model is build. - * - * @return The {@link DocumentFolderRowModel} for the provided - * {@code contentItem}. - */ - 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; - } - +// /** +// * Gets the asset folder tree of the current content section as JSON data. +// * +// * @param sectionIdentifier +// * @param documentPath +// * +// * @return The assets folder tree of the current content section as JSON +// * data. +// */ +// @GET +// @Path("/asset-folders") +// @Produces(MediaType.APPLICATION_JSON) +// @Transactional(Transactional.TxType.REQUIRED) +// public List getAssetFolderTree( +// @PathParam(MvcAuthoringSteps.SECTION_IDENTIFIER_PATH_PARAM) +// final String sectionIdentifier, +// @PathParam(MvcAuthoringSteps.DOCUMENT_PATH_PATH_PARAM_NAME) +// final String documentPath +// ) { +// final ContentSection section = retrieveContentSection( +// sectionIdentifier +// ); +// +// if (permissionChecker.isPermitted( +// ItemPrivileges.EDIT, retrieveDocument(section, documentPath) +// )) { +// return assetFolderTree.buildFolderTree( +// section, section.getRootAssetsFolder() +// ); +// } else { +// throw new ForbiddenException(); +// } +// } +// +// /** +// * Gets the assets in the folder as JSON data. +// * +// * @param folderPath The path of the folder. +// * @param firstResult The index of the firset result to show. +// * @param maxResults The maximum number of results to show. +// * @param filterTerm An optional filter term for filtering the assets +// * in the folder by their name. +// * @param documentPath +// * @param sectionIdentifier +// * +// * @return A list of the assets in the folder as JSON data. +// */ +// @GET +// @Path("/asset-folders/{folderPath}/assets") +// @Produces(MediaType.APPLICATION_JSON) +// @Transactional(Transactional.TxType.REQUIRED) +// public List getAssetsInFolder( +// @PathParam(MvcAuthoringSteps.SECTION_IDENTIFIER_PATH_PARAM) +// final String sectionIdentifier, +// @PathParam(MvcAuthoringSteps.DOCUMENT_PATH_PATH_PARAM_NAME) +// final String documentPath, +// @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 ContentSection section = retrieveContentSection(sectionIdentifier); +// +// if (permissionChecker.isPermitted( +// ItemPrivileges.EDIT, retrieveDocument(section, documentPath) +// )) { +// 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()); +// } else { +// throw new ForbiddenException(); +// } +// } +// +// /** +// * Show all assets of a content section filtered by their name. +// * +// * @param sectionIdentifier +// * @param documentPath +// * @param firstResult The index of the first result to show. +// * @param maxResults The maximum number of results to show. +// * @param searchTerm An optional search term applied to the names of +// * the assets. +// * +// * @return A list of matching assets as JSON. +// */ +// @GET +// @Path("/search-assets") +// @Produces(MediaType.APPLICATION_JSON) +// @Transactional(Transactional.TxType.REQUIRED) +// public List findAssets( +// @PathParam(MvcAuthoringSteps.SECTION_IDENTIFIER_PATH_PARAM) +// final String sectionIdentifier, +// @PathParam(MvcAuthoringSteps.DOCUMENT_PATH_PATH_PARAM_NAME) +// final String documentPath, +// @QueryParam("firstResult") +// @DefaultValue("0") +// final int firstResult, +// @QueryParam("maxResults") +// @DefaultValue("20") +// final int maxResults, +// @QueryParam("searchTerm") +// @DefaultValue("") +// final String searchTerm +// ) { +// final ContentSection section = retrieveContentSection(sectionIdentifier); +// +// if (permissionChecker.isPermitted( +// ItemPrivileges.EDIT, retrieveDocument(section, documentPath) +// )) { +// return assetRepo.findByTitleAndContentSection(searchTerm, section) +// .stream() +// .map(asset -> buildAssetFolderRowModel(section, asset)) +// .collect(Collectors.toList()); +// } else { +// throw new ForbiddenException(); +// } +// } +// +// private ContentSection retrieveContentSection( +// final String sectionIdentifier +// ) { +// return sectionsUi.findContentSection( +// sectionIdentifier +// ).orElseThrow( +// () -> new NotFoundException( +// String.format( +// "No content section identified by %s available.", +// sectionIdentifier +// ) +// ) +// ); +// } +// +// /** +// * Gets the document folder tree of the current content section as JSON +// * data. +// * +// * @param sectionIdentifier +// * @param documentPath +// * +// * @return The document folder tree of the current content section as JSON +// * data. +// */ +// @GET +// @Path("/document-folders") +// @Produces(MediaType.APPLICATION_JSON) +// @Transactional(Transactional.TxType.REQUIRED) +// public List getDocumentFolderTree( +// @PathParam(MvcAuthoringSteps.SECTION_IDENTIFIER_PATH_PARAM) +// final String sectionIdentifier, +// @PathParam(MvcAuthoringSteps.DOCUMENT_PATH_PATH_PARAM_NAME) +// final String documentPath +// ) { +// final ContentSection section = retrieveContentSection(sectionIdentifier); +// final ContentItem document = retrieveDocument(section, documentPath); +// +// if (permissionChecker.isPermitted( +// ItemPrivileges.EDIT, document +// )) { +// return documentFolderTree.buildFolderTree( +// section, section.getRootDocumentsFolder() +// ); +// } else { +// throw new ForbiddenException(); +// } +// } +// +// /** +// * Gets the documents in the folder as JSON data. +// * +// * @param sectionIdentifier +// * @param documentPath +// * @param folderPath The path of the folder. +// * @param firstResult The index of the firset result to show. +// * @param maxResults The maximum number of results to show. +// * @param filterTerm An optional filter term for filtering the +// * documents in the folder by their name. +// * +// * @return A list of the documents in the folder as JSON data. +// */ +// @GET +// @Path("/document-folders/{folderPath}/documents") +// @Produces(MediaType.APPLICATION_JSON) +// @Transactional(Transactional.TxType.REQUIRED) +// public List getDocumentsInFolder( +// @PathParam(MvcAuthoringSteps.SECTION_IDENTIFIER_PATH_PARAM) +// final String sectionIdentifier, +// @PathParam(MvcAuthoringSteps.DOCUMENT_PATH_PATH_PARAM_NAME) +// final String documentPath, +// @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 ContentSection section = retrieveContentSection(sectionIdentifier); +// final ContentItem document = retrieveDocument(section, documentPath); +// +// if (permissionChecker.isPermitted( +// ItemPrivileges.EDIT, document +// )) { +// 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()); +// } else { +// throw new ForbiddenException(); +// } +// } +// +// /** +// * Show all documents of a content section filtered by their name. +// * +// * @param sectionIdentifier +// * @param documentPath +// * @param firstResult The index of the first result to show. +// * @param maxResults The maximum number of results to show. +// * @param searchTerm An optional search term applied to the names of +// * the docuemnts. +// * +// * @return A list of matching documents/content items as JSON. +// */ +// @GET +// @Path("/search-documents") +// @Produces(MediaType.APPLICATION_JSON) +// @Transactional(Transactional.TxType.REQUIRED) +// public List findDocuments( +// @PathParam(MvcAuthoringSteps.SECTION_IDENTIFIER_PATH_PARAM) +// final String sectionIdentifier, +// @PathParam(MvcAuthoringSteps.DOCUMENT_PATH_PATH_PARAM_NAME) +// final String documentPath, +// @QueryParam("firstResult") +// @DefaultValue("0") +// final int firstResult, +// @QueryParam("maxResults") +// @DefaultValue("20") +// final int maxResults, +// @QueryParam("searchTerm") +// @DefaultValue("") +// final String searchTerm +// ) { +// final ContentSection section = retrieveContentSection(sectionIdentifier); +// final ContentItem document = retrieveDocument(section, documentPath); +// +// if (permissionChecker.isPermitted( +// ItemPrivileges.EDIT, document +// )) { +// return itemRepo.findByNameAndContentSection(searchTerm, section) +// .stream() +// .map(asset -> buildDocumentFolderRowModel(section, asset)) +// .collect(Collectors.toList()); +// } else { +// throw new ForbiddenException(); +// } +// } +// +// private ContentItem retrieveDocument( +// final ContentSection section, final String documentPath +// ) { +// return itemRepo +// .findByPath(section, documentPath) +// .orElseThrow( +// () -> new NotFoundException( +// String.format( +// "No document with path %s found in content section %s.", +// documentPath, +// section.getLabel() +// ) +// ) +// ); +// } +// +// /** +// * Build the model for a row in the asset folder listing. +// * +// * @param section The content section. +// * @param entry The {@link AssetFolderEntry} from which the model is +// * build. +// * +// * @return The {@link AssetFolderRowModel} for the provided {@code entry}. +// */ +// 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; +// } +// +// /** +// * Build the model for a row in the asset folder listing. +// * +// * @param section The content section. +// * @param asset The {@link Asset} from which the model is build. +// * +// * @return The {@link AssetFolderRowModel} for the provided {@code asset}. +// */ +// 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; +// } +// +// /** +// * Build the model for a row in the document folder listing. +// * +// * @param section The content section. +// * @param entry The {@link DocumentFolderEntry} from which the model is +// * build. +// * +// * @return The {@link DocumentFolderRowModel} for the provided +// * {@code entry}. +// */ +// 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; +// } +// +// /** +// * Build the model for a row in the document folder listing. +// * +// * @param section The content section. +// * @param contentItem The {@link Contentitem} from which the model is build. +// * +// * @return The {@link DocumentFolderRowModel} for the provided +// * {@code contentItem}. +// */ +// 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/assets/.LCKedit-contactable.xhtml~ b/ccm-cms/src/main/resources/WEB-INF/views/org/librecms/ui/contentsection/assets/.LCKedit-contactable.xhtml~ new file mode 100644 index 000000000..6518b71e4 --- /dev/null +++ b/ccm-cms/src/main/resources/WEB-INF/views/org/librecms/ui/contentsection/assets/.LCKedit-contactable.xhtml~ @@ -0,0 +1 @@ +/home/jensp/pwi/libreccm/git/libreccm/ccm-cms/src/main/resources/WEB-INF/views/org/librecms/ui/contentsection/assets/edit-contactable.xhtml \ No newline at end of file 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 77f92ef45..842c6050c 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 @@ -88,7 +88,15 @@ @@ -293,7 +301,15 @@ diff --git a/ccm-cms/src/main/resources/org/librecms/ui/DefaultAuthoringStepsBundle.properties b/ccm-cms/src/main/resources/org/librecms/ui/DefaultAuthoringStepsBundle.properties index cb8d26dbd..8dd4c6082 100644 --- a/ccm-cms/src/main/resources/org/librecms/ui/DefaultAuthoringStepsBundle.properties +++ b/ccm-cms/src/main/resources/org/librecms/ui/DefaultAuthoringStepsBundle.properties @@ -238,3 +238,4 @@ relatedinfo.attachments.info.dialog.title=Attachment {1} of list {0} relatedinfo.attachments.info.dialog.close=Close relatedinfo.attachments.info.dialog.title.label=Title relatedinfo.attachments.info.dialog.type.label=Type +relatedinfo.attachmentlists.order.save.inprogress=Saving... diff --git a/ccm-cms/src/main/resources/org/librecms/ui/DefaultAuthoringStepsBundle_de.properties b/ccm-cms/src/main/resources/org/librecms/ui/DefaultAuthoringStepsBundle_de.properties index a811bd788..bca383cda 100644 --- a/ccm-cms/src/main/resources/org/librecms/ui/DefaultAuthoringStepsBundle_de.properties +++ b/ccm-cms/src/main/resources/org/librecms/ui/DefaultAuthoringStepsBundle_de.properties @@ -238,3 +238,4 @@ relatedinfo.attachments.info.dialog.title=Anhang {1} der List {0} relatedinfo.attachments.info.dialog.close=Schlie\u00dfen relatedinfo.attachments.info.dialog.title.label=Titel relatedinfo.attachments.info.dialog.type.label=Typ +relatedinfo.attachmentlists.order.save.inprogress=Speichere... diff --git a/ccm-cms/src/main/typescript/content-sections/cms-attachment-lists.ts b/ccm-cms/src/main/typescript/content-sections/cms-attachment-lists.ts index b779036df..57464fe04 100644 --- a/ccm-cms/src/main/typescript/content-sections/cms-attachment-lists.ts +++ b/ccm-cms/src/main/typescript/content-sections/cms-attachment-lists.ts @@ -149,6 +149,17 @@ function saveOrder() { "data-baseUrl attribute on cms-attachment-lists container is missing or empty." ); } + + const saveOrderButtons = document.querySelectorAll(".save-order-button"); + for (let i = 0; i < saveOrderButtons.length; i++) { + const saveOrderButton: HTMLButtonElement = saveOrderButtons[i] as HTMLButtonElement; + saveOrderButton.disabled = true; + const saveIcon = saveOrderButton.querySelector(".save-icon"); + const spinner = saveOrderButton.querySelector(".save-spinner"); + saveIcon?.classList.toggle("d-none"); + spinner?.classList.toggle("d-none"); + } + const headers = new Headers(); headers.append("Content-Type", "application/json"); fetch(baseUrl, { @@ -159,15 +170,30 @@ function saveOrder() { }) .then(response => { if (response.ok) { - const saveOrderButtons = - document.querySelectorAll("save-order-button"); + // const saveOrderButtons = + // document.querySelectorAll(".save-order-button"); for (let i = 0; i < saveOrderButtons.length; i++) { const saveOrderButton: HTMLButtonElement = saveOrderButtons[ i ] as HTMLButtonElement; - saveOrderButton.disabled = true; + // saveOrderButton.disabled = true; + const saveIcon = saveOrderButton.querySelector(".save-icon"); + const spinner = saveOrderButton.querySelector(".save-spinner"); + saveIcon?.classList.toggle("d-none"); + spinner?.classList.toggle("d-none"); } } else { + showSaveError(); + for (let i = 0; i < saveOrderButtons.length; i++) { + const saveOrderButton: HTMLButtonElement = saveOrderButtons[ + i + ] as HTMLButtonElement; + saveOrderButton.disabled = false; + const saveIcon = saveOrderButton.querySelector(".save-icon"); + const spinner = saveOrderButton.querySelector(".save-spinner"); + saveIcon?.classList.toggle("d-none"); + spinner?.classList.toggle("d-none"); + } throw Error( `Failed to save attachments order. Response status: ${response.status}, statusText: ${response.statusText}` ); @@ -175,6 +201,16 @@ function saveOrder() { }) .catch(error => { showSaveError(); + for (let i = 0; i < saveOrderButtons.length; i++) { + const saveOrderButton: HTMLButtonElement = saveOrderButtons[ + i + ] as HTMLButtonElement; + saveOrderButton.disabled = false; + const saveIcon = saveOrderButton.querySelector(".save-icon"); + const spinner = saveOrderButton.querySelector(".save-spinner"); + saveIcon?.classList.toggle("d-none"); + spinner?.classList.toggle("d-none"); + } throw new Error(`Failed to save attachments order: ${error}`); }); }