From a2e500e442f6e42c1769a435344a3e51c45c621d Mon Sep 17 00:00:00 2001 From: jensp Date: Wed, 12 Apr 2017 18:37:42 +0000 Subject: [PATCH] CCM NG/ccm-cms: AssetSearchService including JAX-RS methods to support assets in RichTextEditor git-svn-id: https://svn.libreccm.org/ccm/ccm_ng@4670 8810af33-2d31-482b-a856-94f89814c4df --- .../src/main/webapp/WEB-INF/beans.xml | 3 +- .../src/main/webapp/WEB-INF/web.xml | 24 ++ ccm-bundle-devel/pom.xml | 28 ++ .../cms/ui/assets/AssetSearchPage.java | 58 +++- .../librecms/assets/AssetSearchService.java | 321 ++++++++++++++++++ .../org/librecms/contentsection/Asset.java | 24 +- .../contentsection/AssetRepository.java | 52 ++- .../contentsection/FolderRepository.java | 58 ++-- .../contentsection/JaxRsContentSections.java | 45 +++ .../contentsection/AssetRepositoryTest.java | 18 +- ccm-core/pom.xml | 29 ++ .../src/main/resources/META-INF/beans.xml | 3 +- pom.xml | 22 ++ 13 files changed, 615 insertions(+), 70 deletions(-) create mode 100644 ccm-cms/src/main/java/org/librecms/assets/AssetSearchService.java create mode 100644 ccm-cms/src/main/java/org/librecms/contentsection/JaxRsContentSections.java diff --git a/ccm-bundle-devel-wildfly-web/src/main/webapp/WEB-INF/beans.xml b/ccm-bundle-devel-wildfly-web/src/main/webapp/WEB-INF/beans.xml index b83fc94b7..194f21e6e 100644 --- a/ccm-bundle-devel-wildfly-web/src/main/webapp/WEB-INF/beans.xml +++ b/ccm-bundle-devel-wildfly-web/src/main/webapp/WEB-INF/beans.xml @@ -1,6 +1,7 @@ + + bean-discovery-mode="all"> \ No newline at end of file diff --git a/ccm-bundle-devel-wildfly-web/src/main/webapp/WEB-INF/web.xml b/ccm-bundle-devel-wildfly-web/src/main/webapp/WEB-INF/web.xml index 42fb40ecd..08945269c 100644 --- a/ccm-bundle-devel-wildfly-web/src/main/webapp/WEB-INF/web.xml +++ b/ccm-bundle-devel-wildfly-web/src/main/webapp/WEB-INF/web.xml @@ -27,6 +27,15 @@ org.apache.shiro.web.env.EnvironmentLoaderListener + + + Faces Servlet javax.faces.webapp.FacesServlet @@ -46,4 +55,19 @@ javax.faces.FACELETS_SKIP_COMMENTS true + + + vaadin-servlet + com.vaadin.cdi.server.VaadinCDIServlet + + + + vaadin-servlet + /vaadin/ + + + vaadin-servlet + /VAADIN/ + + diff --git a/ccm-bundle-devel/pom.xml b/ccm-bundle-devel/pom.xml index a7d938add..cf08bcbd5 100644 --- a/ccm-bundle-devel/pom.xml +++ b/ccm-bundle-devel/pom.xml @@ -59,6 +59,34 @@ org.apache.logging.log4j log4j-api + + + + com.vaadin + vaadin-compatibility-server + + + com.vaadin + vaadin-compatibility-shared + + + + com.vaadin + vaadin-compatibility-themes + + + com.vaadin + vaadin-compatibility-client-compiled + 8.0.4 + + + com.vaadin + vaadin-cdi + diff --git a/ccm-cms/src/main/java/com/arsdigita/cms/ui/assets/AssetSearchPage.java b/ccm-cms/src/main/java/com/arsdigita/cms/ui/assets/AssetSearchPage.java index 7d3c85c3b..e40950dcd 100644 --- a/ccm-cms/src/main/java/com/arsdigita/cms/ui/assets/AssetSearchPage.java +++ b/ccm-cms/src/main/java/com/arsdigita/cms/ui/assets/AssetSearchPage.java @@ -24,15 +24,19 @@ import com.arsdigita.bebop.FormProcessException; import com.arsdigita.bebop.Label; import com.arsdigita.bebop.PageState; import com.arsdigita.bebop.SimpleContainer; +import com.arsdigita.bebop.Table; import com.arsdigita.bebop.event.FormInitListener; import com.arsdigita.bebop.event.FormSectionEvent; import com.arsdigita.bebop.form.Submit; import com.arsdigita.bebop.form.TextField; import com.arsdigita.bebop.parameters.LongParameter; import com.arsdigita.bebop.parameters.StringParameter; +import com.arsdigita.bebop.table.TableColumn; +import com.arsdigita.bebop.table.TableColumnModel; import com.arsdigita.cms.dispatcher.CMSPage; import com.arsdigita.globalization.GlobalizedMessage; import com.arsdigita.toolbox.ui.LayoutPanel; + import org.librecms.CmsConstants; /** @@ -46,6 +50,10 @@ public class AssetSearchPage extends CMSPage { private static final String WIDGET_PARAM = "widget"; private static final String ASSET_TYPE_PARAM = "assettype"; + private static final int RESULTS_TABLE_COL_TITLE = 0; + private static final int RESULTS_TABLE_COL_PLACE = 1; + private static final int RESULTS_TABLE_COL_TYPE = 2; + private final LongParameter contentSectionId; private TextField query; @@ -65,27 +73,59 @@ public class AssetSearchPage extends CMSPage { final Form queryForm = new Form("asset-search-page-query-form"); queryForm.add(new Label(new GlobalizedMessage( - "cms.ui.assets.search_page.query", - CmsConstants.CMS_BUNDLE))); + "cms.ui.assets.search_page.query", + CmsConstants.CMS_BUNDLE))); query = new TextField("asset-search-page-query-form"); queryForm.add(query); final Submit querySubmit = new Submit(new GlobalizedMessage( - "cms.ui.assets.search_page.query.submit")); + "cms.ui.assets.search_page.query.submit")); queryForm.add(querySubmit); - + queryForm.addInitListener(new FormInitListener() { + @Override - public void init(final FormSectionEvent event) - throws FormProcessException { - + public void init(final FormSectionEvent event) + throws FormProcessException { + final PageState state = event.getPageState(); final FormData data = event.getFormData(); - + final String query = (String) data.get(QUERY_PARAM); - + } + }); + mainPanel.setLeft(queryForm); + + final Table resultsTable = new Table(); + resultsTable.setEmptyView( + new Label( + new GlobalizedMessage( + "cms.ui.assets.search_page.none", + CmsConstants.CMS_BUNDLE))); + resultsTable.setClassAttr("dataTable"); + + final TableColumnModel columnModel = resultsTable.getColumnModel(); + columnModel.add(new TableColumn( + RESULTS_TABLE_COL_TITLE, + new GlobalizedMessage( + "cms.ui.assets.search_page.results_table.title", + CmsConstants.CMS_BUNDLE))); + columnModel.add(new TableColumn( + RESULTS_TABLE_COL_PLACE, + new GlobalizedMessage( + "cms.ui.assets.search_page.results_table.place", + CmsConstants.CMS_BUNDLE))); + columnModel.add(new TableColumn( + RESULTS_TABLE_COL_TYPE, + new GlobalizedMessage( + "cms.ui.assets.search_page.results_table.type", + CmsConstants.CMS_BUNDLE))); + + + mainPanel.setBody(resultsTable); + } } diff --git a/ccm-cms/src/main/java/org/librecms/assets/AssetSearchService.java b/ccm-cms/src/main/java/org/librecms/assets/AssetSearchService.java new file mode 100644 index 000000000..132a961f7 --- /dev/null +++ b/ccm-cms/src/main/java/org/librecms/assets/AssetSearchService.java @@ -0,0 +1,321 @@ +/* + * 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 org.librecms.assets; + +import com.arsdigita.kernel.KernelConfig; + +import org.libreccm.l10n.GlobalizationHelper; +import org.librecms.contentsection.Asset; +import org.librecms.contentsection.AssetRepository; + +import org.librecms.contentsection.ContentSection; +import org.librecms.contentsection.ContentSectionRepository; +import org.librecms.contentsection.Folder; +import org.librecms.contentsection.FolderRepository; +import org.librecms.contentsection.FolderType; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Optional; +import java.util.ResourceBundle; +import java.util.stream.Collectors; + +import javax.enterprise.context.RequestScoped; +import javax.inject.Inject; +import javax.transaction.Transactional; +import javax.ws.rs.GET; +import javax.ws.rs.Path; +import javax.ws.rs.PathParam; +import javax.ws.rs.Produces; +import javax.ws.rs.QueryParam; + +/** + * + * @author Jens Pelzetter + */ +@RequestScoped +@Path("/{content-section}/assets") +public class AssetSearchService { + + @Inject + private AssetRepository assetRepo; + + @Inject + private AssetTypesManager assetTypesManager; + + @Inject + private ContentSectionRepository sectionRepo; + + @Inject + private FolderRepository folderRepo; + + @Inject + private GlobalizationHelper globalizationHelper; + + private Class toAssetClass(final String type) { + final Class clazz; + try { + clazz = Class.forName(type); + } catch (ClassNotFoundException ex) { + throw new IllegalArgumentException(String.format( + "Type '%s' is not a valid class.", + type)); + } + + if (clazz.isAssignableFrom(Asset.class)) { + @SuppressWarnings("unchecked") + final Class typeClass + = (Class) clazz; + return typeClass; + } else { + throw new IllegalArgumentException(String.format( + "Type '%s is not a subclass of '%s'.", + type, + Asset.class.getName())); + } + } + + public List findAssetsByQuery(final String query) { + return assetRepo.findByTitle(query); + } + + public List findAssetsByType(final String type) { + return AssetSearchService.this.findAssets(toAssetClass(type)); + } + + public List findAssets(final Class type) { + return assetRepo.findByType(type); + } + + public List findAssets(final String query, final String type) { + + final Class clazz; + try { + clazz = Class.forName(type); + } catch (ClassNotFoundException ex) { + throw new IllegalArgumentException(String.format( + "Type '%s' is not a valid class.", + type)); + } + + if (clazz.isAssignableFrom(Asset.class)) { + @SuppressWarnings("unchecked") + final Class typeClass + = (Class) clazz; + return AssetSearchService.this.findAssets(query, typeClass); + } else { + throw new IllegalArgumentException(String.format( + "Type '%s is not a subclass of '%s'.", + type, + Asset.class.getName())); + } + + } + + public List findAssets(final ContentSection section, + final String path) { + final Optional folder = folderRepo + .findByPath(section, + path, + FolderType.ASSETS_FOLDER); + + if (!folder.isPresent()) { + return Collections.emptyList(); + } + + return assetRepo.findByFolder(folder.get()); + } + + public List findAssets(final String query, + final Class type) { + return assetRepo.findByTitleAndType(query, type); + + } + + @Transactional(Transactional.TxType.REQUIRED) + public List findAssetsByType(final ContentSection section, + final String path, + final String type) { + + final Optional folder = folderRepo + .findByPath(section, + path, + FolderType.ASSETS_FOLDER); + + if (!folder.isPresent()) { + return Collections.emptyList(); + } + + return assetRepo.filterByFolderAndType(folder.get(), + toAssetClass(type)); + } + + @Transactional(Transactional.TxType.REQUIRED) + public List findAssetsByQuery(final ContentSection section, + final String path, + final String query) { + + final Optional folder = folderRepo + .findByPath(section, + path, + FolderType.ASSETS_FOLDER); + + if (!folder.isPresent()) { + return Collections.emptyList(); + } + + return assetRepo.filterByFolderAndTitle(folder.get(), + query); + } + + @Transactional(Transactional.TxType.REQUIRED) + public List findAssets(final ContentSection section, + final String path, + final String query, + final String type) { + + final Optional folder = folderRepo + .findByPath(section, + path, + FolderType.ASSETS_FOLDER); + + if (!folder.isPresent()) { + return Collections.emptyList(); + } + + return assetRepo.filterByFolderAndTypeAndTitle(folder.get(), + toAssetClass(type), + query); + + } + + @GET + @Produces("text/json") + @Transactional(Transactional.TxType.REQUIRED) + public List> findAssets( + @PathParam("content-section") final String section, + @QueryParam("query") final String query, + @QueryParam("type") final String type) { + + return findAssets(section, "/", query, type); + } + + @GET + @Path("{folder}") + @Produces("text/json") + @Transactional(Transactional.TxType.REQUIRED) + public List> findAssets( + @PathParam("content-section") final String section, + @PathParam("folder") final String path, + @QueryParam("query") final String query, + @QueryParam("type") final String type) { + + final ContentSection contentSection = sectionRepo.findByLabel(section); + + final String folderPath; + if (path == null || path.trim().isEmpty() || "/".equals(path.trim())) { + folderPath = "/"; + } else { + folderPath = String.format("/%s", path); + } + + final String assetType; + if (type == null || type.trim().isEmpty()) { + assetType = Asset.class.getName(); + } else { + assetType = type; + } + + final Optional folder = folderRepo + .findByPath(contentSection, folderPath, FolderType.ASSETS_FOLDER); + if (!folder.isPresent()) { + return Collections.emptyList(); + } + final List> subFolders = folder + .get() + .getSubFolders() + .stream() + .map(current -> createAssetMapEntry(current)) + .collect(Collectors.toList()); + + final List assets; + if (query == null || query.trim().isEmpty()) { + if (Asset.class.getName().equals(assetType)) { + assets = findAssets(contentSection, folderPath); + } else { + assets = findAssetsByType(contentSection, folderPath, assetType); + } + } else { + if (Asset.class.getName().equals(assetType)) { + assets = findAssetsByQuery(contentSection, folderPath, query); + } else { + assets + = findAssets(contentSection, folderPath, query, assetType); + } + } + + final List> assetEntries = assets + .stream() + .map(asset -> createAssetMapEntry(asset)) + .collect(Collectors.toList()); + + final List> result = new ArrayList<>(); + result.addAll(subFolders); + result.addAll(assetEntries); + + return result; + } + + private Map createAssetMapEntry(final Folder folder) { + final Map result = new HashMap<>(); + + result.put("title", + folder + .getTitle() + .getValue(KernelConfig.getConfig().getDefaultLocale())); + result.put("type", + Folder.class.getName()); + + return result; + } + + private Map createAssetMapEntry(final Asset asset) { + final Map result = new HashMap<>(); + + result.put("title", + asset.getTitle().getValue(globalizationHelper + .getNegotiatedLocale())); + + result.put("type", + asset.getClass().getName()); + + final AssetTypeInfo typeInfo = assetTypesManager + .getAssetTypeInfo(asset.getClass()); + final ResourceBundle bundle = ResourceBundle + .getBundle(typeInfo.getLabelBundle(), + globalizationHelper.getNegotiatedLocale()); + result.put("typeLabel", bundle.getString(typeInfo.getLabelKey())); + + return result; + } + +} 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 9b75b4317..c45297ca3 100644 --- a/ccm-cms/src/main/java/org/librecms/contentsection/Asset.java +++ b/ccm-cms/src/main/java/org/librecms/contentsection/Asset.java @@ -68,6 +68,15 @@ import static org.librecms.CmsConstants.*; + "WHERE a.uuid = :uuid " + "AND TYPE(a) = :type") , + @NamedQuery(name = "Asset.findByTitle'", + query = "SELECT a FROM Asset a JOIN a.title.values t " + + "WHERE t LIKE :query") + , + @NamedQuery(name = "Asset.findByTitleAndType", + query = "SELECT a FROM Asset a " + + "WHERE :title MEMBER OF a.title.values " + + "AND TYPE(a) = :type") + , @NamedQuery( name = "Asset.findByFolder", query = "SELECT a FROM Asset a " @@ -83,20 +92,22 @@ import static org.librecms.CmsConstants.*; + "AND c.type = '" + CATEGORIZATION_TYPE_FOLDER + "'") , @NamedQuery( - name = "Asset.filterByFolderAndName", + name = "Asset.filterByFolderAndTitle", query = "SELECT a FROM Asset a " + "JOIN a.categories c " + + "JOIN a.title.values t " + "WHERE c.category = :folder " + "AND c.type = '" + CATEGORIZATION_TYPE_FOLDER + "' " - + "AND LOWER(a.displayName) LIKE CONCAT(LOWER(:name), '%')") + + "AND LOWER(t) LIKE CONCAT('%', LOWER(:title), '%')") , @NamedQuery( - name = "Asset.countFilterByFolderAndName", + name = "Asset.countFilterByFolderAndTitle", query = "SELECT COUNT(a) FROM Asset a " + "JOIN a.categories c " + + "JOIN a.title.values t " + "WHERE c.category = :folder " + "AND c.type = '" + CATEGORIZATION_TYPE_FOLDER + "' " - + "AND LOWER(a.displayName) LIKE CONCAT(LOWER(:name), '%')") + + "AND LOWER(t) LIKE CONCAT('%', LOWER(:title), '%')") , @NamedQuery( name = "Asset.filterByFolderAndType", @@ -124,12 +135,13 @@ import static org.librecms.CmsConstants.*; + "AND TYPE(a) = :type") , @NamedQuery( - name = "Asset.countFilterByFolderAndNameAndType", + name = "Asset.countFilterByFolderAndTitleAndType", query = "SELECT COUNT(a) FROM Asset a " + "JOIN a.categories c " + + "JOIN a.title.values t " + "WHERE c.category = :folder " + "AND c.type = '" + CATEGORIZATION_TYPE_FOLDER + "' " - + "AND LOWER(a.displayName) LIKE CONCAT(LOWER(:name), '%') " + + "AND LOWER(t) LIKE CONCAT('%', LOWER(:title), '%') " + "AND TYPE(a) = :type") }) public class Asset extends CcmObject { diff --git a/ccm-cms/src/main/java/org/librecms/contentsection/AssetRepository.java b/ccm-cms/src/main/java/org/librecms/contentsection/AssetRepository.java index 5f5be337d..1547ca7f1 100644 --- a/ccm-cms/src/main/java/org/librecms/contentsection/AssetRepository.java +++ b/ccm-cms/src/main/java/org/librecms/contentsection/AssetRepository.java @@ -189,6 +189,16 @@ public class AssetRepository return Optional.empty(); } } + + @Transactional(Transactional.TxType.REQUIRED) + public List findByTitle(final String title) { + + final TypedQuery query = entityManager.createNamedQuery( + "Asset.findByTitle", Asset.class); + query.setParameter("query", String.format("%%%s%%", title)); + + return query.getResultList(); + } /** * Finds all shared {@link Asset}s of the specified type. @@ -207,6 +217,18 @@ public class AssetRepository return query.getResultList(); } + + @Transactional(Transactional.TxType.REQUIRED) + public List findByTitleAndType(final String title, + final Class type) { + + final TypedQuery query = entityManager.createNamedQuery( + "Asset.findByTitle", Asset.class); + query.setParameter("query", title); + query.setParameter("type", type); + + return query.getResultList(); + } /** * Finds all shared {@link Asset}s in a specific {@link Folder}. @@ -246,19 +268,19 @@ public class AssetRepository * * @param folder The {@link Folder} which {@link Asset}s are filtered using * the provided {@code name}. - * @param name The string used to fiter the {@link Assets} in the provided + * @param title The string used to fiter the {@link Assets} in the provided * {@code folder}. * * @return A list with all {@link Asset}s in the provided {@link Folder} * which name starts with the provided string. */ @Transactional(Transactional.TxType.REQUIRED) - public List filterByFolderAndName(final Folder folder, - final String name) { + public List filterByFolderAndTitle(final Folder folder, + final String title) { final TypedQuery query = entityManager.createNamedQuery( - "Asset.filterByFolderAndName", Asset.class); + "Asset.filterByFolderAndTitle", Asset.class); query.setParameter("folder", folder); - query.setParameter("name", name); + query.setParameter("title", title); return query.getResultList(); } @@ -334,22 +356,22 @@ public class AssetRepository * * @param folder The {@link Folder} which contains the assets. * @param type The type of the {@link Asset}s. - * @param name The name to filter the {@link Asset}s for. + * @param title The name to filter the {@link Asset}s for. * * @return A list of all {@link Asset}s of the provided type which name * starts with the provided string in the provided folder. */ @Transactional(Transactional.TxType.REQUIRED) - public List filterByFolderAndTypeAndName( + public List filterByFolderAndTypeAndTitle( final Folder folder, final Class type, - final String name) { + final String title) { final TypedQuery query = entityManager.createNamedQuery( - "Asset.filterByFolderAndNameAndType", Asset.class); + "Asset.filterByFolderAndTitleAndType", Asset.class); query.setParameter("folder", folder); query.setParameter("type", type); - query.setParameter("name", name); + query.setParameter("title", title); return query.getResultList(); } @@ -360,22 +382,22 @@ public class AssetRepository * * @param folder The {@link Folder} which contains the assets. * @param type The type of the {@link Asset}s. - * @param name The name to filter the {@link Asset}s for. + * @param title The name to filter the {@link Asset}s for. * * @return The number of {@link Asset}s of the provided type which name * starts with the provided string in the provided folder. */ @Transactional(Transactional.TxType.REQUIRED) - public long countFilterByFolderAndTypeAndName( + public long countFilterByFolderAndTypeAndTitle( final Folder folder, final Class type, - final String name) { + final String title) { final TypedQuery query = entityManager.createNamedQuery( - "Asset.countFilterByFolderAndNameAndType", Long.class); + "Asset.countFilterByFolderAndTitleAndType", Long.class); query.setParameter("folder", folder); query.setParameter("type", type); - query.setParameter("name", name); + query.setParameter("title", title); return query.getSingleResult(); } diff --git a/ccm-cms/src/main/java/org/librecms/contentsection/FolderRepository.java b/ccm-cms/src/main/java/org/librecms/contentsection/FolderRepository.java index 908f7e0ea..70c6ba508 100644 --- a/ccm-cms/src/main/java/org/librecms/contentsection/FolderRepository.java +++ b/ccm-cms/src/main/java/org/librecms/contentsection/FolderRepository.java @@ -27,6 +27,7 @@ import org.libreccm.security.RequiresPrivilege; import org.librecms.contentsection.privileges.ItemPrivileges; import java.util.List; +import java.util.Objects; import java.util.Optional; import java.util.UUID; @@ -117,12 +118,12 @@ public class FolderRepository extends AbstractEntityRepository { public Optional findByPath(final ContentSection section, final String path, final FolderType type) { - if (section == null) { - throw new IllegalArgumentException("section can't be null"); - } - if (path == null || path.isEmpty()) { - throw new IllegalArgumentException("Path can't be null or empty."); + Objects.requireNonNull(section, "section can't be null"); + + Objects.requireNonNull(path, "Path can't be null."); + if (path.isEmpty()) { + throw new IllegalArgumentException("Path can't be empty."); } // String normalizedPath = path.replace('.', '/'); @@ -135,46 +136,45 @@ public class FolderRepository extends AbstractEntityRepository { // normalizedPath.length()); // } // + final ContentSection contentSection = sectionRepo + .findById(section.getObjectId()) + .get(); + final String normalizedPath = PathUtil.normalizePath(path); LOGGER.debug("Trying to find folder with path \"{}\" and type {} in" + "content section \"{}\".", normalizedPath, type, - section.getLabel()); + contentSection.getLabel()); final String[] tokens = normalizedPath.split("/"); Folder current; - switch(type) { + switch (type) { case ASSETS_FOLDER: - current = section.getRootAssetsFolder(); + current = contentSection.getRootAssetsFolder(); break; case DOCUMENTS_FOLDER: - current = section.getRootDocumentsFolder(); + current = contentSection.getRootDocumentsFolder(); break; default: throw new IllegalArgumentException(String.format( "Unexpected folder type %s", type)); } - for(final String token : tokens) { + if (normalizedPath.isEmpty()) { + return Optional.of(current); + } + for (final String token : tokens) { if (current.getSubCategories() == null) { return Optional.empty(); } - + final Optional result = current.getSubCategories() - .stream() - .filter( c -> { - LOGGER.debug("#findByPath(ContentSection, String, FolderType: c = {}", - c.toString()); - LOGGER.debug("#findByPath(ContentSection, String, FolderType: c.getName = \"{}\"", - c.getName()); - LOGGER.debug("#findByPath(ContentSection, String, FolderType: token = \"{}\"", - token); - return c.getName().equals(token); - }) - .findFirst(); - - if (result.isPresent() - && result.get() instanceof Folder) { + .stream() + .filter(category -> category.getName().equals(token)) + .findFirst(); + + if (result.isPresent() + && result.get() instanceof Folder) { current = (Folder) result.get(); } else { return Optional.empty(); @@ -183,24 +183,24 @@ public class FolderRepository extends AbstractEntityRepository { return Optional.of(current); } - + @AuthorizationRequired @Transactional(Transactional.TxType.REQUIRED) @Override public void save( @RequiresPrivilege(ItemPrivileges.CREATE_NEW) final Folder folder) { - + super.save(folder); } - + @AuthorizationRequired @Transactional(Transactional.TxType.REQUIRED) @Override public void delete( @RequiresPrivilege(ItemPrivileges.CREATE_NEW) final Folder folder) { - + super.delete(folder); } diff --git a/ccm-cms/src/main/java/org/librecms/contentsection/JaxRsContentSections.java b/ccm-cms/src/main/java/org/librecms/contentsection/JaxRsContentSections.java new file mode 100644 index 000000000..f1fdfb74c --- /dev/null +++ b/ccm-cms/src/main/java/org/librecms/contentsection/JaxRsContentSections.java @@ -0,0 +1,45 @@ +/* + * 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 org.librecms.contentsection; + +import org.librecms.assets.AssetSearchService; + +import java.util.HashSet; +import java.util.Set; + +import javax.ws.rs.ApplicationPath; +import javax.ws.rs.core.Application; + +/** + * + * @author Jens Pelzetter + */ +@ApplicationPath("/content-sections") +public class JaxRsContentSections extends Application{ + + @Override + public Set> getClasses() { + final Set> classes = new HashSet<>(); + + classes.add(AssetSearchService.class); + + return classes; + } + +} diff --git a/ccm-cms/src/test/java/org/librecms/contentsection/AssetRepositoryTest.java b/ccm-cms/src/test/java/org/librecms/contentsection/AssetRepositoryTest.java index 35f71bdb0..25f288458 100644 --- a/ccm-cms/src/test/java/org/librecms/contentsection/AssetRepositoryTest.java +++ b/ccm-cms/src/test/java/org/librecms/contentsection/AssetRepositoryTest.java @@ -349,7 +349,7 @@ public class AssetRepositoryTest { /** * Tries to find {@link Asset}s in a {@link Folder} by using - * {@link AssetRepository#filterByFolderAndName(org.librecms.contentsection.Folder, java.lang.String)}. + * {@link AssetRepository#filterByFolderAndTitle(org.librecms.contentsection.Folder, java.lang.String)}. */ @Test @InSequence(500) @@ -358,9 +358,9 @@ public class AssetRepositoryTest { public void filterAssetByFolderAndName() { final Folder media = folderRepo.findById(-400L).get(); - final List result1 = assetRepo.filterByFolderAndName(media, + final List result1 = assetRepo.filterByFolderAndTitle(media, "hea"); - final List result2 = assetRepo.filterByFolderAndName(media, + final List result2 = assetRepo.filterByFolderAndTitle(media, "photo"); assertThat(result1.size(), is(1)); @@ -443,7 +443,7 @@ public class AssetRepositoryTest { /** * Tries to filter the {@link Asset}s in a {@link Folder} by their type and * name using - * {@link AssetRepository#filterByFolderAndTypeAndName(org.librecms.contentsection.Folder, java.lang.Class, java.lang.String)}. + * {@link AssetRepository#filterByFolderAndTypeAndTitle(org.librecms.contentsection.Folder, java.lang.Class, java.lang.String)}. */ @Test @InSequence(600) @@ -452,9 +452,9 @@ public class AssetRepositoryTest { public void filterAssetsByFolderAndTypeAndName() { final Folder media = folderRepo.findById(-400L).get(); - final List result1 = assetRepo.filterByFolderAndTypeAndName( + final List result1 = assetRepo.filterByFolderAndTypeAndTitle( media, Image.class, "hea"); - final List result2 = assetRepo.filterByFolderAndTypeAndName( + final List result2 = assetRepo.filterByFolderAndTypeAndTitle( media, File.class, "hea"); assertThat(result1.size(), is(1)); @@ -465,7 +465,7 @@ public class AssetRepositoryTest { /** * Tries to count the {@link Asset}s in a {@link Folder} which are of a * specific type and which name matches a specific pattern using - * {@link AssetRepository#filterByFolderAndTypeAndName(org.librecms.contentsection.Folder, java.lang.Class, java.lang.String)}. + * {@link AssetRepository#filterByFolderAndTypeAndTitle(org.librecms.contentsection.Folder, java.lang.Class, java.lang.String)}. */ @Test @InSequence(610) @@ -474,10 +474,10 @@ public class AssetRepositoryTest { public void countFilterAssetsByFolderAndTypeAndName() { final Folder media = folderRepo.findById(-400L).get(); - assertThat(assetRepo.countFilterByFolderAndTypeAndName( + assertThat(assetRepo.countFilterByFolderAndTypeAndTitle( media, Image.class, "hea"), is(1L)); - assertThat(assetRepo.countFilterByFolderAndTypeAndName( + assertThat(assetRepo.countFilterByFolderAndTypeAndTitle( media, File.class, "hea"), is(0L)); } diff --git a/ccm-core/pom.xml b/ccm-core/pom.xml index 7bfeead76..7badfda41 100644 --- a/ccm-core/pom.xml +++ b/ccm-core/pom.xml @@ -193,6 +193,35 @@ org.primefaces primefaces + + + + com.vaadin + vaadin-compatibility-server + + + com.vaadin + vaadin-compatibility-shared + + + com.vaadin + vaadin-themes + 8.0.4 + + + com.vaadin + vaadin-client-compiled + 8.0.4 + + + com.vaadin + vaadin-compatibility-client-compiled + 8.0.4 + + + com.vaadin + vaadin-cdi + diff --git a/ccm-core/src/main/resources/META-INF/beans.xml b/ccm-core/src/main/resources/META-INF/beans.xml index d45765d18..295fa9e6c 100644 --- a/ccm-core/src/main/resources/META-INF/beans.xml +++ b/ccm-core/src/main/resources/META-INF/beans.xml @@ -1,8 +1,9 @@ + + bean-discovery-mode="all"> org.libreccm.security.AuthorizationInterceptor diff --git a/pom.xml b/pom.xml index 5a8fb748e..ffc50c0be 100644 --- a/pom.xml +++ b/pom.xml @@ -318,6 +318,28 @@ 6.0 + + + com.vaadin + vaadin-compatibility-server + 8.0.4 + + + com.vaadin + vaadin-compatibility-shared + 8.0.4 + + + com.vaadin + vaadin-compatibility-themes + 8.0.4 + + + com.vaadin + vaadin-cdi + 2.0.0 + +