CCM NG/ccm-cms: Some progress for the ContentItemPage

git-svn-id: https://svn.libreccm.org/ccm/ccm_ng@4730 8810af33-2d31-482b-a856-94f89814c4df
jensp 2017-05-11 18:01:30 +00:00
parent 4248d0073b
commit 6c7022eafc
3 changed files with 40 additions and 37 deletions

View File

@ -19,13 +19,21 @@ import org.libreccm.modules.ShutdownEvent;
import org.libreccm.modules.UnInstallEvent; import org.libreccm.modules.UnInstallEvent;
import org.libreccm.web.ApplicationType; import org.libreccm.web.ApplicationType;
import org.libreccm.web.CcmApplication; import org.libreccm.web.CcmApplication;
import org.librecms.assets.*; import org.librecms.assets.AssetTypes;
import org.librecms.assets.Bookmark;
import org.librecms.assets.ExternalAudioAsset;
import org.librecms.assets.ExternalVideoAsset;
import org.librecms.assets.FileAsset;
import org.librecms.assets.Image;
import org.librecms.assets.LegalMetadata;
import org.librecms.assets.SideNote;
import org.librecms.contentsection.ContentSection; import org.librecms.contentsection.ContentSection;
import org.librecms.contentsection.ContentSectionCreator; import org.librecms.contentsection.ContentSectionCreator;
import org.librecms.contentsection.ContentSectionSetup; import org.librecms.contentsection.ContentSectionSetup;
import org.librecms.contentsection.ui.admin.ApplicationInstanceForm; import org.librecms.contentsection.ui.admin.ApplicationInstanceForm;
import org.librecms.contentsection.ui.admin.SettingsPane; import org.librecms.contentsection.ui.admin.SettingsPane;
import org.librecms.contenttypes.Article; import org.librecms.contenttypes.Article;
import org.librecms.contenttypes.ContentTypes;
import org.librecms.contenttypes.Event; import org.librecms.contenttypes.Event;
import org.librecms.contenttypes.MultiPartArticle; import org.librecms.contenttypes.MultiPartArticle;
import org.librecms.contenttypes.News; import org.librecms.contenttypes.News;

View File

@ -1,35 +0,0 @@
/*
* Copyright (C) 2016 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;
import org.librecms.contentsection.ContentItem;
/**
* Annotation for modules to describe the content types provided by a module.
* The content types - classes which extend the {@link ContentItem} class - must
* be annotated with the {@link ContentType} annotation.
*
*
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
*/
public @interface ContentTypes {
Class<? extends ContentItem>[] value();
}

View File

@ -30,6 +30,8 @@ import org.libreccm.categorization.ObjectNotAssignedToCategoryException;
import org.libreccm.core.CcmObject; import org.libreccm.core.CcmObject;
import org.libreccm.core.CcmObjectRepository; import org.libreccm.core.CcmObjectRepository;
import org.libreccm.core.UnexpectedErrorException; import org.libreccm.core.UnexpectedErrorException;
import org.libreccm.security.PermissionChecker;
import org.libreccm.security.Role;
import java.util.List; import java.util.List;
import java.util.Optional; import java.util.Optional;
@ -41,8 +43,12 @@ import javax.persistence.NoResultException;
import javax.persistence.TypedQuery; import javax.persistence.TypedQuery;
import org.libreccm.security.Shiro; import org.libreccm.security.Shiro;
import org.libreccm.security.User;
import org.libreccm.workflow.Workflow; import org.libreccm.workflow.Workflow;
import java.util.Collections;
import java.util.stream.Collectors;
import javax.transaction.Transactional; import javax.transaction.Transactional;
/** /**
@ -69,6 +75,9 @@ public class ContentItemRepository
@Inject @Inject
private Shiro shiro; private Shiro shiro;
@Inject
private PermissionChecker permissionChecker;
@Override @Override
public Long getEntityId(final ContentItem item) { public Long getEntityId(final ContentItem item) {
return item.getObjectId(); return item.getObjectId();
@ -222,13 +231,34 @@ public class ContentItemRepository
return query.getSingleResult(); return query.getSingleResult();
} }
@Transactional(Transactional.TxType.REQUIRED)
public Optional<ContentItem> findByNameInFolder(final Category folder, public Optional<ContentItem> findByNameInFolder(final Category folder,
final String name) { final String name) {
final Optional<User> user = shiro.getUser();
final List<Role> roles;
if (user.isPresent()) {
roles = user
.get()
.getRoleMemberships()
.stream()
.map(membership -> membership.getRole())
.collect(Collectors.toList());
} else {
roles = Collections.emptyList();
}
final boolean isSystemUser = shiro.isSystemUser();
final boolean isAdmin = permissionChecker.isPermitted("*");
final TypedQuery<ContentItem> query = getEntityManager() final TypedQuery<ContentItem> query = getEntityManager()
.createNamedQuery("ContentItem.findByNameInFolder", .createNamedQuery("ContentItem.findByNameInFolder",
ContentItem.class); ContentItem.class);
query.setParameter("folder", folder); query.setParameter("folder", folder);
query.setParameter("name", name); query.setParameter("name", name);
query.setParameter("roles", roles);
query.setParameter("isSystemUser", isSystemUser);
query.setParameter("isAdmin", isAdmin);
try { try {
return Optional.of(query.getSingleResult()); return Optional.of(query.getSingleResult());