- * The Item Search page.
- * - * @author Scott Seago (scott@arsdigita.com) - * @author Sören BernsteinItemSearchPopup component
- *
- * @param context the context for the retrieved items. Should
- * be {@link ContentItem#DRAFT} or
- * {@link ContentItem#LIVE}
- * @param limitToContentSection limit the search to the current content
- * section
- */
- public ItemSearchPopup(final String context,
- final boolean limitToContentSection) {
- super(context, limitToContentSection);
- }
-
- // Hide results by default
- @Override
- public void register(final Page page) {
- super.register(page);
- page.addGlobalStateParam(new StringParameter(WIDGET_PARAM));
- page.addGlobalStateParam(new StringParameter(URL_PARAM));
- page.addGlobalStateParam(new StringParameter(QUERY));
- }
-
- @Override
- protected ItemSearchSection createSearchSection(
- final String context, final boolean limitToContentSection) {
- return new ItemSearchSectionPopup(context, limitToContentSection);
- }
-
- private static class ItemSearchSectionPopup extends ItemSearchSection {
-
- public ItemSearchSectionPopup(final String context,
- final boolean limitToContentSection) {
- super(context, limitToContentSection);
- }
-
- @Override
- protected Component createResultsPane(final QueryGenerator generator) {
- return new PopupResultsPane(generator);
- }
-
- }
-
- /**
- * The default context is Live.No need to append &context=live explicitly.
- *
- * @param request
- * @param objectId
- *
- * @return
- */
- public static String getItemURL(final HttpServletRequest request,
- final Long objectId) {
- // redirect doesn't use /ccm prefix for some reason, so just returning the raw string.
- //ParameterMap map = new ParameterMap();
- //map.setParameter("oid", oid.toString());
- //return URL.there(request, "/redirect/", map).toString();
- // Always link directly to the live version.
- if (Web.getWebappContextPath() == null) {
- return "/redirect/?oid=" + objectId.toString();
- } else {
- return Web.getWebappContextPath() + "/redirect/?oid=" + objectId
- .toString();
- }
- }
-
- private static class PopupResultsPane extends ResultsPane {
-
- public PopupResultsPane(final QueryGenerator generator) {
- super(generator);
- setRelativeURLs(true);
- setSearchHelpMsg(new GlobalizedMessage("cms.ui.search.help",
- CmsConstants.CMS_BUNDLE));
- setNoResultsMsg(new GlobalizedMessage("cms.ui.search.no_results",
- CmsConstants.CMS_BUNDLE));
- }
-
- @Override
- protected Element generateDocumentXML(final PageState state,
- final CcmObject doc) {
- final Element element = super.generateDocumentXML(state, doc);
-
- element.addAttribute("class", "jsButton");
-
- final String widget = (String) state.getValue(new StringParameter(
- WIDGET_PARAM));
- final String searchWidget = (String) state.getValue(
- new StringParameter("searchWidget"));
-
- final boolean useURL = "true".equals(state.getValue(
- new StringParameter(URL_PARAM)));
-
- String fillString;
- if (useURL) {
- fillString = getItemURL(state.getRequest(), doc.getObjectId());
- } else {
- fillString = Long.toString(doc.getObjectId());
- }
-
- final String title = doc.getDisplayName();
-
- final Element jsLabel = new Element(
- SearchConstants.XML_PREFIX + "jsAction",
- SearchConstants.XML_NS);
- jsLabel.addAttribute(
- "name", "fillItem" + Long.toString(doc.getObjectId()) + "()");
- jsLabel.setText(generateJSLabel(doc.getObjectId(),
- widget,
- searchWidget,
- fillString,
- title));
- jsLabel.addAttribute("action",
- String.format(
- "window.opener.document.%s.value = \"%s\"; self.close(); return false;",
- widget,
- fillString));
- element.addContent(jsLabel);
-
- return element;
- }
-
- private String generateJSLabel(final Long docId,
- final String widget,
- final String searchWidget,
- final String fill,
- final String title) {
- return " ";
- }
-
- }
-
-}
diff --git a/ccm-cms/src/main/java/com/arsdigita/cms/ui/assets/AssetSearchWidget.java b/ccm-cms/src/main/java/com/arsdigita/cms/ui/assets/AssetSearchWidget.java
index c594b8862..95a91073a 100644
--- a/ccm-cms/src/main/java/com/arsdigita/cms/ui/assets/AssetSearchWidget.java
+++ b/ccm-cms/src/main/java/com/arsdigita/cms/ui/assets/AssetSearchWidget.java
@@ -37,7 +37,7 @@ import java.util.ResourceBundle;
/**
* A widget for selecting an asset. The widget does not contain any other
* widgets, only the information required to create an HTML/JavaScript dialog
- * for selecting an asset. To get the dialog the
+ * for selecting an asset. To create the dialog the
* {@link org.librecms.contentsection.rs.Assets} class can be used which
* provides several methods for getting the assets of an content section.
*
@@ -80,7 +80,7 @@ public class AssetSearchWidget extends Widget {
CMS.CMS_XML_NS);
widget.addAttribute("name", getName());
-
+
if (type != null) {
widget.addAttribute("asset-type", type.getName());
}
@@ -101,10 +101,10 @@ public class AssetSearchWidget extends Widget {
final Asset asset = assetRepo
.findById(value)
.orElseThrow(() -> new IllegalArgumentException(String.format(
- "No asset with ID %d in the database.", value)));
+ "No Asset with ID %d in the database.", value)));
- final Element selected = widget.newChildElement(
- "cms:selected-asset", CMS.CMS_XML_NS);
+ final Element selected = widget
+ .newChildElement("cms:selected-asset", CMS.CMS_XML_NS);
selected.addAttribute("assetId",
Long.toString(asset.getObjectId()));
selected.addAttribute(
diff --git a/ccm-cms/src/main/java/com/arsdigita/cms/ui/assets/ItemSearchWidget.java b/ccm-cms/src/main/java/com/arsdigita/cms/ui/assets/ItemSearchWidget.java
new file mode 100644
index 000000000..1ca0cd220
--- /dev/null
+++ b/ccm-cms/src/main/java/com/arsdigita/cms/ui/assets/ItemSearchWidget.java
@@ -0,0 +1,117 @@
+/*
+ * Copyright (C) 2017 LibreCCM Foundation.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
+ * MA 02110-1301 USA
+ */
+package com.arsdigita.cms.ui.assets;
+
+import com.arsdigita.bebop.PageState;
+import com.arsdigita.bebop.form.Widget;
+import com.arsdigita.bebop.parameters.LongParameter;
+import com.arsdigita.cms.CMS;
+import com.arsdigita.xml.Element;
+
+import org.libreccm.cdi.utils.CdiUtil;
+import org.libreccm.l10n.GlobalizationHelper;
+import org.librecms.contentsection.ContentItem;
+import org.librecms.contentsection.ContentItemRepository;
+import org.librecms.contentsection.ContentSection;
+import org.librecms.contenttypes.ContentTypeInfo;
+import org.librecms.contenttypes.ContentTypesManager;
+
+import java.util.ResourceBundle;
+
+/**
+ *
+ * @author Jens Pelzetter
+ */
+public class ItemSearchWidget extends Widget {
+
+ private Class extends ContentItem> type;
+
+ public ItemSearchWidget(final String name) {
+ super(new LongParameter(name));
+ }
+
+ @Override
+ public boolean isCompound() {
+ return true;
+ }
+
+ @Override
+ protected String getType() {
+ return "item-search-widget";
+ }
+
+ @Override
+ protected String getElementTag() {
+ return "cms:item-search-widget";
+ }
+
+ @Override
+ public void generateWidget(final PageState state,
+ final Element parent) {
+
+ final Element widget = parent.newChildElement(getElementTag(),
+ CMS.CMS_XML_NS);
+
+ widget.addAttribute("name", getName());
+
+ if (type != null) {
+ widget.addAttribute("asset-type", type.getName());
+ }
+
+ final ContentSection section = CMS.getContext().getContentSection();
+ widget.addAttribute("content-section", section.getLabel());
+
+ final Long value = (Long) getValue(state);
+ if (value != null) {
+ final CdiUtil cdiUtil = CdiUtil.createCdiUtil();
+ final ContentItemRepository itemRepo = cdiUtil
+ .findBean(ContentItemRepository.class);
+ final ContentTypesManager typesManager = cdiUtil
+ .findBean(ContentTypesManager.class);
+ final GlobalizationHelper globalizationHelper = cdiUtil
+ .findBean(GlobalizationHelper.class);
+
+ final ContentItem item = itemRepo
+ .findById(value)
+ .orElseThrow(() -> new IllegalArgumentException(String
+ .format("No ContentItem with ID %d in the database.", value)));
+
+ final Element selected = widget
+ .newChildElement("cms:selected-content-item", CMS.CMS_XML_NS);
+ selected.addAttribute("contentItemId",
+ Long.toString(item.getObjectId()));
+ selected.addAttribute("name", item.getDisplayName());
+ selected.addAttribute(
+ "title",
+ globalizationHelper.getValueFromLocalizedString(item.getTitle()));
+ final ContentTypeInfo typeInfo = typesManager
+ .getContentTypeInfo(item.getClass());
+ final ResourceBundle bundle = ResourceBundle
+ .getBundle(typeInfo.getLabelBundle(),
+ globalizationHelper.getNegotiatedLocale());
+ final String typeLabel = bundle.getString(typeInfo.getLabelKey());
+ selected.addAttribute("type", typeLabel);
+
+ exportAttributes(widget);
+
+ }
+
+ }
+
+}
diff --git a/ccm-cms/src/main/java/com/arsdigita/cms/ui/authoring/assets/relatedinfo/InternalLinkAddForm.java b/ccm-cms/src/main/java/com/arsdigita/cms/ui/authoring/assets/relatedinfo/InternalLinkAddForm.java
new file mode 100644
index 000000000..27abc6f24
--- /dev/null
+++ b/ccm-cms/src/main/java/com/arsdigita/cms/ui/authoring/assets/relatedinfo/InternalLinkAddForm.java
@@ -0,0 +1,89 @@
+/*
+ * Copyright (C) 2017 LibreCCM Foundation.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
+ * MA 02110-1301 USA
+ */
+package com.arsdigita.cms.ui.authoring.assets.relatedinfo;
+
+import com.arsdigita.bebop.Form;
+import com.arsdigita.bebop.FormProcessException;
+import com.arsdigita.bebop.SaveCancelSection;
+import com.arsdigita.bebop.event.FormInitListener;
+import com.arsdigita.bebop.event.FormProcessListener;
+import com.arsdigita.bebop.event.FormSectionEvent;
+import com.arsdigita.bebop.event.FormSubmissionListener;
+import com.arsdigita.bebop.form.TextArea;
+import com.arsdigita.bebop.form.TextField;
+import com.arsdigita.bebop.parameters.StringParameter;
+import com.arsdigita.cms.ItemSelectionModel;
+import com.arsdigita.cms.ui.assets.ItemSearchWidget;
+import com.arsdigita.cms.ui.authoring.assets.AttachmentListSelectionModel;
+
+/**
+ *
+ * @author Jens Pelzetter
+ */
+public class InternalLinkAddForm
+ extends Form
+ implements FormInitListener,
+ FormProcessListener,
+ FormSubmissionListener {
+
+ private final RelatedInfoStep relatedInfoStep;
+ private final ItemSelectionModel itemSelectionModel;
+ private final AttachmentListSelectionModel listSelectionModel;
+ private final StringParameter selectedLanguageParam;
+
+ private final TextField titleField;
+ private final TextArea descriptionArea;
+ private final ItemSearchWidget itemSearchWidget;
+ private final SaveCancelSection saveCancelSection;
+
+ public InternalLinkAddForm(
+ final RelatedInfoStep relatedInfoStep,
+ final ItemSelectionModel itemSelectionModel,
+ final AttachmentListSelectionModel listSelectionModel,
+ final StringParameter selectedLanguageParam) {
+
+ super("relatedinfo-attach-internallink-form");
+
+ this.relatedInfoStep = relatedInfoStep;
+ this.itemSelectionModel = itemSelectionModel;
+ this.listSelectionModel = listSelectionModel;
+ this.selectedLanguageParam = selectedLanguageParam;
+
+ titleField = new TextField("link-title");
+ descriptionArea = new TextArea("link-description");
+ itemSearchWidget = new ItemSearchWidget("link-item-search");
+ saveCancelSection = new SaveCancelSection();
+ }
+
+ @Override
+ public void init(FormSectionEvent e) throws FormProcessException {
+ throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
+ }
+
+ @Override
+ public void process(FormSectionEvent e) throws FormProcessException {
+ throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
+ }
+
+ @Override
+ public void submitted(FormSectionEvent e) throws FormProcessException {
+ throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
+ }
+
+}
diff --git a/ccm-cms/src/main/java/com/arsdigita/cms/ui/authoring/assets/relatedinfo/RelatedInfoAttachAssetForm.java b/ccm-cms/src/main/java/com/arsdigita/cms/ui/authoring/assets/relatedinfo/RelatedInfoAttachAssetForm.java
index 447410ff9..16cbd1b54 100644
--- a/ccm-cms/src/main/java/com/arsdigita/cms/ui/authoring/assets/relatedinfo/RelatedInfoAttachAssetForm.java
+++ b/ccm-cms/src/main/java/com/arsdigita/cms/ui/authoring/assets/relatedinfo/RelatedInfoAttachAssetForm.java
@@ -36,7 +36,6 @@ import org.libreccm.core.UnexpectedErrorException;
import org.librecms.contentsection.Asset;
import org.librecms.contentsection.AssetRepository;
import org.librecms.contentsection.AttachmentList;
-import org.librecms.contentsection.ContentItem;
import org.librecms.contentsection.ItemAttachmentManager;
/**
@@ -63,7 +62,7 @@ class RelatedInfoAttachAssetForm
final AttachmentListSelectionModel listSelectionModel,
final StringParameter selectedLangugeParam) {
- super("relatedinfo-attachasset-form");
+ super("relatedinfo-attach-asset-form");
this.relatedInfoStep = relatedInfoStep;
this.itemSelectionModel = itemSelectionModel;
diff --git a/ccm-cms/src/main/java/org/librecms/contentsection/Asset.java b/ccm-cms/src/main/java/org/librecms/contentsection/Asset.java
index 7ae983f53..2887b2bab 100644
--- a/ccm-cms/src/main/java/org/librecms/contentsection/Asset.java
+++ b/ccm-cms/src/main/java/org/librecms/contentsection/Asset.java
@@ -195,7 +195,7 @@ import static org.librecms.CmsConstants.*;
+ "JOIN a.title.values t "
+ "JOIN a.categories c "
+ "LEFT JOIN a.permissions p "
- + "WHERE LOWER(t) LIKE CONCAT('%s', :title, '%s') "
+ + "WHERE LOWER(t) LIKE CONCAT('%', :title, '%') "
+ "AND c.category.section = :section "
+ "AND ("
+ " ("
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 8eb1b1c92..381435267 100644
--- a/ccm-cms/src/main/java/org/librecms/contentsection/ContentItem.java
+++ b/ccm-cms/src/main/java/org/librecms/contentsection/ContentItem.java
@@ -170,6 +170,94 @@ import static org.librecms.CmsConstants.*;
+ " OR true = :isSystemUser OR true = :isAdmin"
+ " )")
,
+ @NamedQuery(
+ name = "ContentItem.findByContentSection",
+ query = "SELECT DISTINCT i "
+ + "FROM ContentItem i "
+ + "JOIN i.contentType t "
+ + "LEFT JOIN i.permissions p "
+ + "WHERE t.contentSection = :section "
+ + "AND ("
+ + " ("
+ + " p.grantee IN :roles "
+ + " AND p.grantedPrivileges = "
+ + " (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 "
+ + "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 ("
+ + " ("
+ + " p.grantee IN :roles "
+ + " AND p.grantedPrivileges = "
+ + " (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 "
+ + "FROM ContentItem i "
+ + "JOIN i.contentType t "
+ + "LEFT JOIN i.permissions p "
+ + "WHERE t.contentSection = :section "
+ + "AND TYPE(i) = :type "
+ + "AND ("
+ + " ("
+ + " p.grantee IN :roles "
+ + " AND p.grantedPrivileges = "
+ + " (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 "
+ + "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 ("
+ + " ("
+ + " p.grantee IN :roles "
+ + " AND p.grantedPrivileges = "
+ + " (CASE WHEN i.version = 'DRAFT' "
+ + " THEN '" + ItemPrivileges.PREVIEW + "' "
+ + " ELSE '" + ItemPrivileges.VIEW_PUBLISHED
+ + "' "
+ + " END"
+ + " )"
+ + " )"
+ + " OR true = :isSystemUser OR true = :isAdmin"
+ + ")")
+ ,
@NamedQuery(
name = "ContentItem.findByFolder",
query
@@ -304,6 +392,53 @@ import static org.librecms.CmsConstants.*;
+ " )"
)
,
+ @NamedQuery(
+ name = "ContentItem.filterByFolderAndType",
+ 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 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"
+ + " ) "
+ + "ORDER BY i.displayName")
+ ,
+ @NamedQuery(
+ name = "ContentItem.filterByFolderAndTypeAndName",
+ 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 LOWER(i.displayName) LIKE CONCAT(LOWER(:name), '%') "
+ + "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"
+ + " ) "
+ + "ORDER BY i.displayName")
+ ,
@NamedQuery(
name = "ContentItem.hasLiveVersion",
query = "SELECT (CASE WHEN COUNT(i) > 0 THEN true ELSE false END) "
diff --git a/ccm-cms/src/main/java/org/librecms/contentsection/ContentItemRepository.java b/ccm-cms/src/main/java/org/librecms/contentsection/ContentItemRepository.java
index ed21394df..13d41dac6 100644
--- a/ccm-cms/src/main/java/org/librecms/contentsection/ContentItemRepository.java
+++ b/ccm-cms/src/main/java/org/librecms/contentsection/ContentItemRepository.java
@@ -238,6 +238,68 @@ public class ContentItemRepository
}
}
+ @Transactional(Transactional.TxType.REQUIRED)
+ @SuppressWarnings("unchecked")
+ public