CCM NG/ccm-cms: Some bugfixes for the items RESTful service
git-svn-id: https://svn.libreccm.org/ccm/ccm_ng@5353 8810af33-2d31-482b-a856-94f89814c4df
parent
beb760fc50
commit
c9a431b3fc
|
|
@ -69,6 +69,8 @@ public class ItemSearchWidget extends Widget {
|
|||
CMS.CMS_XML_NS);
|
||||
|
||||
widget.addAttribute("name", getName());
|
||||
widget.addAttribute("content-section",
|
||||
CMS.getContext().getContentSection().getLabel());
|
||||
|
||||
if (type != null) {
|
||||
widget.addAttribute("asset-type", type.getName());
|
||||
|
|
|
|||
|
|
@ -193,6 +193,28 @@ import static org.librecms.CmsConstants.*;
|
|||
+ " OR true = :isSystemUser OR true = :isAdmin"
|
||||
+ ")")
|
||||
,
|
||||
@NamedQuery(
|
||||
name = "ContentItem.findByContentSectionAndVersion",
|
||||
query = "SELECT DISTINCT i "
|
||||
+ "FROM ContentItem i "
|
||||
+ "JOIN i.contentType t "
|
||||
+ "LEFT JOIN i.permissions p "
|
||||
+ "WHERE t.contentSection = :section "
|
||||
+ "AND version = :version "
|
||||
+ "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.findByNameAndContentSection",
|
||||
query = "SELECT DISTINCT i "
|
||||
|
|
@ -215,6 +237,30 @@ import static org.librecms.CmsConstants.*;
|
|||
+ " OR true = :isSystemUser OR true = :isAdmin"
|
||||
+ ")")
|
||||
,
|
||||
@NamedQuery(
|
||||
name = "ContentItem.findNameAndContentSectionAndVersion",
|
||||
query = "SELECT DISTINCT i "
|
||||
+ "FROM ContentItem i "
|
||||
+ "JOIN i.contentType t "
|
||||
+ "LEFT JOIN i.permissions p "
|
||||
+ "WHERE t.contentSection = :section "
|
||||
+ "AND lower(i.displayName) LIKE CONCAT('%', :name, '%s') "
|
||||
+ "AND version = :version "
|
||||
+ "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.findByTypeAndContentSection",
|
||||
query = "SELECT DISTINCT i "
|
||||
|
|
@ -237,6 +283,29 @@ import static org.librecms.CmsConstants.*;
|
|||
+ " OR true = :isSystemUser OR true = :isAdmin"
|
||||
+ ")")
|
||||
,
|
||||
@NamedQuery(
|
||||
name = "ContentItem.findByTypeAndContentSectionAndVersion",
|
||||
query = "SELECT DISTINCT i "
|
||||
+ "FROM ContentItem i "
|
||||
+ "JOIN i.contentType t "
|
||||
+ "LEFT JOIN i.permissions p "
|
||||
+ "WHERE t.contentSection = :section "
|
||||
+ "AND TYPE(i) = :type "
|
||||
+ "AND version = :version "
|
||||
+ "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.findByNameAndTypeAndContentSection",
|
||||
query = "SELECT DISTINCT i "
|
||||
|
|
@ -260,6 +329,31 @@ import static org.librecms.CmsConstants.*;
|
|||
+ " OR true = :isSystemUser OR true = :isAdmin"
|
||||
+ ")")
|
||||
,
|
||||
@NamedQuery(
|
||||
name = "ContentItem.findByNameAndTypeAndContentSectionAndVersion",
|
||||
query = "SELECT DISTINCT i "
|
||||
+ "FROM ContentItem i "
|
||||
+ "JOIN i.contentType t "
|
||||
+ "LEFT JOIN i.permissions p "
|
||||
+ "WHERE t.contentSection = :section "
|
||||
+ "AND TYPE(i) = :type "
|
||||
+ "AND lower(i.displayName) LIKE CONCAT('%', :name, '%s') "
|
||||
+ "AND version = :version "
|
||||
+ "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.findByFolder",
|
||||
query
|
||||
|
|
|
|||
|
|
@ -97,9 +97,6 @@ public class ContentItemRepository
|
|||
@Inject
|
||||
private TaskManager taskManager;
|
||||
|
||||
@Inject
|
||||
private TaskRepository taskRepo;
|
||||
|
||||
@Inject
|
||||
private UserRepository userRepository;
|
||||
|
||||
|
|
@ -270,6 +267,21 @@ public class ContentItemRepository
|
|||
return (List<T>) query.getResultList();
|
||||
}
|
||||
|
||||
@Transactional(Transactional.TxType.REQUIRED)
|
||||
@SuppressWarnings("unchecked")
|
||||
public <T extends ContentItem> List<T> findByContentSection(
|
||||
final ContentSection section, final ContentItemVersion version) {
|
||||
|
||||
final TypedQuery<ContentItem> query = getEntityManager()
|
||||
.createNamedQuery("ContentItem.findByContentSectionAndVersion",
|
||||
ContentItem.class);
|
||||
query.setParameter("section", section);
|
||||
query.setParameter("version", version.toString());
|
||||
setAuthorizationParameters(query);
|
||||
|
||||
return (List<T>) query.getResultList();
|
||||
}
|
||||
|
||||
@Transactional(Transactional.TxType.REQUIRED)
|
||||
@SuppressWarnings("unchecked")
|
||||
public <T extends ContentItem> List<T> findByNameAndContentSection(
|
||||
|
|
@ -285,6 +297,25 @@ public class ContentItemRepository
|
|||
return (List<T>) query.getResultList();
|
||||
}
|
||||
|
||||
@Transactional(Transactional.TxType.REQUIRED)
|
||||
@SuppressWarnings("unchecked")
|
||||
public <T extends ContentItem> List<T> findByNameAndContentSection(
|
||||
final String name,
|
||||
final ContentSection section,
|
||||
final ContentItemVersion version) {
|
||||
|
||||
final TypedQuery<ContentItem> query = getEntityManager()
|
||||
.createNamedQuery(
|
||||
"ContentItem.findByNameAndContentSectionAndVersion",
|
||||
ContentItem.class);
|
||||
query.setParameter("section", section);
|
||||
query.setParameter("name", name);
|
||||
query.setParameter("version", version.toString());
|
||||
setAuthorizationParameters(query);
|
||||
|
||||
return (List<T>) query.getResultList();
|
||||
}
|
||||
|
||||
@Transactional(Transactional.TxType.REQUIRED)
|
||||
@SuppressWarnings("unchecked")
|
||||
public <T extends ContentItem> List<T> findByTypeAndContentSection(
|
||||
|
|
@ -300,6 +331,25 @@ public class ContentItemRepository
|
|||
return (List<T>) query.getResultList();
|
||||
}
|
||||
|
||||
@Transactional(Transactional.TxType.REQUIRED)
|
||||
@SuppressWarnings("unchecked")
|
||||
public <T extends ContentItem> List<T> findByTypeAndContentSection(
|
||||
final Class<? extends ContentItem> type,
|
||||
final ContentSection section,
|
||||
final ContentItemVersion version) {
|
||||
|
||||
final TypedQuery<ContentItem> query = getEntityManager()
|
||||
.createNamedQuery(
|
||||
"ContentItem.findByNameAndContentSectionAndVersion",
|
||||
ContentItem.class);
|
||||
query.setParameter("section", section);
|
||||
query.setParameter("type", type);
|
||||
query.setParameter("version", version.toString());
|
||||
setAuthorizationParameters(query);
|
||||
|
||||
return (List<T>) query.getResultList();
|
||||
}
|
||||
|
||||
@Transactional(Transactional.TxType.REQUIRED)
|
||||
@SuppressWarnings("unchecked")
|
||||
public <T extends ContentItem> List<T> findByNameAndTypeAndContentSection(
|
||||
|
|
@ -318,6 +368,26 @@ public class ContentItemRepository
|
|||
return (List<T>) query.getResultList();
|
||||
}
|
||||
|
||||
@Transactional(Transactional.TxType.REQUIRED)
|
||||
@SuppressWarnings("unchecked")
|
||||
public <T extends ContentItem> List<T> findByNameAndTypeAndContentSection(
|
||||
final String name,
|
||||
final Class<? extends ContentItem> type,
|
||||
final ContentSection section,
|
||||
final ContentItemVersion version) {
|
||||
|
||||
final TypedQuery<ContentItem> query = getEntityManager()
|
||||
.createNamedQuery("ContentItem.findByNameAndContentSectionAndVersion",
|
||||
ContentItem.class);
|
||||
query.setParameter("section", section);
|
||||
query.setParameter("name", name);
|
||||
query.setParameter("type", type);
|
||||
query.setParameter("version", version.toString());
|
||||
setAuthorizationParameters(query);
|
||||
|
||||
return (List<T>) query.getResultList();
|
||||
}
|
||||
|
||||
/**
|
||||
* Finds all content items of a specific type.
|
||||
*
|
||||
|
|
|
|||
|
|
@ -20,8 +20,10 @@ package org.librecms.contentsection.rs;
|
|||
|
||||
import org.libreccm.l10n.GlobalizationHelper;
|
||||
import org.librecms.contentsection.ContentItem;
|
||||
import org.librecms.contentsection.ContentItemL10NManager;
|
||||
import org.librecms.contentsection.ContentItemManager;
|
||||
import org.librecms.contentsection.ContentItemRepository;
|
||||
import org.librecms.contentsection.ContentItemVersion;
|
||||
import org.librecms.contentsection.ContentSection;
|
||||
import org.librecms.contentsection.ContentSectionRepository;
|
||||
import org.librecms.contentsection.Folder;
|
||||
|
|
@ -131,8 +133,8 @@ public class ContentItems {
|
|||
result.put("name", item.getDisplayName());
|
||||
|
||||
result.put("title",
|
||||
item.getTitle().getValue(globalizationHelper
|
||||
.getNegotiatedLocale()));
|
||||
globalizationHelper
|
||||
.getValueFromLocalizedString(item.getTitle()));
|
||||
|
||||
result.put("type",
|
||||
item.getClass().getName());
|
||||
|
|
@ -162,38 +164,49 @@ public class ContentItems {
|
|||
public List<Map<String, String>> findItems(
|
||||
@PathParam("content-section") final String section,
|
||||
@QueryParam("query") final String query,
|
||||
@QueryParam("type") final String type) {
|
||||
@QueryParam("type") final String type,
|
||||
@QueryParam("version") final String version) {
|
||||
|
||||
final ContentSection contentSection = sectionRepo
|
||||
.findByLabel(section)
|
||||
.orElseThrow(() -> new NotFoundException(
|
||||
String.format("No content section '%s' found.", section)));
|
||||
|
||||
final ContentItemVersion itemVersion;
|
||||
if (version != null) {
|
||||
itemVersion = ContentItemVersion.valueOf(version.toUpperCase());
|
||||
} else {
|
||||
itemVersion = ContentItemVersion.LIVE;
|
||||
}
|
||||
|
||||
final List<ContentItem> items;
|
||||
if ((query == null || query.trim().isEmpty())
|
||||
&& (type == null || type.trim().isEmpty())) {
|
||||
items = itemRepo
|
||||
.findByContentSection(contentSection);
|
||||
.findByContentSection(contentSection, itemVersion);
|
||||
|
||||
} else if ((query != null && !query.trim().isEmpty())
|
||||
&& (type == null || type.trim().isEmpty())) {
|
||||
|
||||
items = itemRepo.findByNameAndContentSection(query,
|
||||
contentSection);
|
||||
contentSection,
|
||||
itemVersion);
|
||||
} else if ((query == null || query.trim().isEmpty())
|
||||
&& (type != null && !type.trim().isEmpty())) {
|
||||
|
||||
final Class<? extends ContentItem> itemType
|
||||
= toContentItemTypeClass(type);
|
||||
items = itemRepo.findByTypeAndContentSection(itemType,
|
||||
contentSection);
|
||||
contentSection,
|
||||
itemVersion);
|
||||
} else {
|
||||
final Class<? extends ContentItem> itemType
|
||||
= toContentItemTypeClass(type);
|
||||
items = itemRepo.findByNameAndTypeAndContentSection(
|
||||
query,
|
||||
itemType,
|
||||
contentSection);
|
||||
contentSection,
|
||||
itemVersion);
|
||||
}
|
||||
|
||||
return items
|
||||
|
|
|
|||
|
|
@ -102,7 +102,7 @@ function getItemsForSelectItemDialog(dialogId) {
|
|||
var dispatcherPrefix = dialog.getAttribute('data-dispatcherPrefix');
|
||||
|
||||
var request = new XMLHttpRequest();
|
||||
var url = dispatcherPrefix.substring(0, dispatcherPrefix.length - "/ccm".length) + "/content-sections/" + contentSection + "/items/";
|
||||
var url = dispatcherPrefix.substring(0, dispatcherPrefix.length - "/ccm".length) + "/content-sections/" + contentSection + "/items/?version=DRAFT";
|
||||
if (type !== null && type.length > 0) {
|
||||
url = url + "?type=" + type;
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue