CCM NG: Abstrakte Methode getIdAttributeName in AbstractEntityRepository erstellen (#2804)

git-svn-id: https://svn.libreccm.org/ccm/ccm_ng@5253 8810af33-2d31-482b-a856-94f89814c4df
pull/2/head
jensp 2018-02-07 13:52:57 +00:00
parent 6e3e2fb8f3
commit 9dd1f85014
37 changed files with 271 additions and 68 deletions

View File

@ -60,6 +60,8 @@ import javax.transaction.Transactional;
public class AssetRepository
extends AbstractAuditedEntityRepository<Long, Asset> {
private static final long serialVersionUID = 7190032071018013125L;
private static final Logger LOGGER = LogManager
.getLogger(AssetRepository.class);
@ -97,6 +99,11 @@ public class AssetRepository
return Asset.class;
}
@Override
public String getIdAttributeName() {
return "objectId";
}
@Override
public boolean isNew(final Asset asset) {
return asset.getObjectId() == 0;
@ -200,7 +207,8 @@ public class AssetRepository
final List<Permission> permissions = asset.getPermissions();
for (final Permission permission : permissions) {
permissionManager.revokePrivilege(permission.getGrantedPrivilege(),
permissionManager.revokePrivilege(permission
.getGrantedPrivilege(),
permission.getGrantee(),
asset);
}

View File

@ -116,6 +116,11 @@ public class ContentItemRepository
return ContentItem.class;
}
@Override
public String getIdAttributeName() {
return "objectId";
}
@Override
public boolean isNew(final ContentItem item) {
return ccmObjectRepo.isNew(item);

View File

@ -39,6 +39,8 @@ import javax.transaction.Transactional;
public class ContentSectionRepository
extends AbstractEntityRepository<Long, ContentSection> {
private static final long serialVersionUID = 4616599498399330865L;
public Optional<ContentSection> findByLabel(final String label) {
if (label == null || label.isEmpty()) {
throw new IllegalArgumentException(
@ -62,6 +64,11 @@ public class ContentSectionRepository
return ContentSection.class;
}
@Override
public String getIdAttributeName() {
return "objectId";
}
@Override
public boolean isNew(final ContentSection section) {
return section.getObjectId() == 0;

View File

@ -55,6 +55,11 @@ public class ContentTypeRepository
return ContentType.class;
}
@Override
public String getIdAttributeName() {
return "objectId";
}
@Override
public boolean isNew(final ContentType type) {
return type.getObjectId() == 0;

View File

@ -43,6 +43,8 @@ import javax.transaction.Transactional;
@RequestScoped
public class FolderRepository extends AbstractEntityRepository<Long, Folder> {
private static final long serialVersionUID = -2588848483908283604L;
private static final Logger LOGGER = LogManager.getLogger(
FolderRepository.class);
@ -54,6 +56,11 @@ public class FolderRepository extends AbstractEntityRepository<Long, Folder> {
return Folder.class;
}
@Override
public String getIdAttributeName() {
return "objectId";
}
@Override
public boolean isNew(final Folder folder) {
return folder.getObjectId() == 0;

View File

@ -35,11 +35,18 @@ import javax.transaction.Transactional;
public class MultiPartArticleSectionRepository
extends AbstractAuditedEntityRepository<Long, MultiPartArticleSection> {
private static final long serialVersionUID = -3392120236224057234L;
@Override
public Long getEntityId(final MultiPartArticleSection entity) {
return entity.getSectionId();
}
@Override
public String getIdAttributeName() {
return "sectionId";
}
@Override
public Class<MultiPartArticleSection> getEntityClass() {
return MultiPartArticleSection.class;

View File

@ -30,16 +30,21 @@ import javax.enterprise.context.RequestScoped;
public class LifecycleDefinitionRepository
extends AbstractEntityRepository<Long, LifecycleDefinition> {
private static final long serialVersionUID = -6388883975391235155L;
@Override
public Class<LifecycleDefinition> getEntityClass() {
return LifecycleDefinition.class;
}
@Override
public String getIdAttributeName() {
return "definitionId";
}
@Override
public boolean isNew(final LifecycleDefinition lifecycleDefinition) {
return lifecycleDefinition.getDefinitionId() == 0;
}
}

View File

@ -34,6 +34,11 @@ public class LifecycleRepository extends AbstractEntityRepository<Long, Lifecycl
return Lifecycle.class;
}
@Override
public String getIdAttributeName() {
return "lifecycleId";
}
@Override
public boolean isNew(final Lifecycle lifecycle) {
return lifecycle.getLifecycleId() == 0;

View File

@ -35,6 +35,11 @@ public class PhaseDefinititionRepository
return PhaseDefinition.class;
}
@Override
public String getIdAttributeName() {
return "definitionId";
}
@Override
public boolean isNew(final PhaseDefinition phaseDefinition) {
return phaseDefinition.getDefinitionId() == 0;

View File

@ -36,6 +36,11 @@ public class PhaseRepository extends AbstractEntityRepository<Long, Phase>{
return Phase.class;
}
@Override
public String getIdAttributeName() {
return "phaseId";
}
@Override
public boolean isNew(final Phase phase) {
return phase.getPhaseId() == 0;

View File

@ -91,6 +91,11 @@ public class PageRepository extends AbstractEntityRepository<Long, Page> {
return Page.class;
}
@Override
public String getIdAttributeName() {
return "objectId";
}
@Override
public boolean isNew(final Page page) {
return page.getObjectId() == 0;

View File

@ -82,6 +82,11 @@ public class PagesRepository extends AbstractEntityRepository<Long, Pages> {
return Pages.class;
}
@Override
public String getIdAttributeName() {
return "objectId";
}
@Override
public boolean isNew(final Pages pages) {
return pages.getObjectId() == 0;

View File

@ -66,6 +66,11 @@ public class CategoryRepository extends AbstractEntityRepository<Long, Category>
return Category.class;
}
@Override
public String getIdAttributeName() {
return "objectId";
}
@Override
public boolean isNew(final Category entity) {
return entity.getObjectId() == 0;

View File

@ -51,6 +51,11 @@ public class DomainRepository extends AbstractEntityRepository<Long, Domain> {
return Domain.class;
}
@Override
public String getIdAttributeName() {
return "objectId";
}
@Override
public boolean isNew(final Domain entity) {
return entity.getObjectId() == 0;

View File

@ -124,6 +124,14 @@ public abstract class AbstractEntityRepository<K, E> implements Serializable {
*/
public abstract Class<E> getEntityClass();
/**
* Used by some methods to create queries using the JPA Criteria API.
*
* @return The name of the ID attribute/property for entities managed by
* a repository.
*/
public abstract String getIdAttributeName();
/**
* Finds an entity by it ID.
*

View File

@ -51,6 +51,11 @@ public class CcmObjectRepository extends AbstractEntityRepository<Long, CcmObjec
return CcmObject.class;
}
@Override
public String getIdAttributeName() {
return "objectId";
}
@Override
public boolean isNew(final CcmObject entity) {
if (entity == null) {

View File

@ -45,6 +45,11 @@ public class ResourceRepository extends AbstractEntityRepository<Long,
return Resource.class;
}
@Override
public String getIdAttributeName() {
return "objectId";
}
@Override
public boolean isNew(final Resource entity) {
return entity.getObjectId() == 0;

View File

@ -30,12 +30,12 @@ import java.util.Optional;
* {@link ResourceType}s from the database. This is the responsibility of the
* application using the {@link ResourceType}.
*
* @author <a href="mailto:tosmers@uni-bremen.de>Tobias Osmers<\a>
* @version created the 8/10/17
* @author <a href="mailto:tosmers@uni-bremen.de>Tobias Osmers</a>
*
*/
@RequestScoped
public class ResourceTypeRepository extends AbstractEntityRepository<Long,
ResourceType> {
public class ResourceTypeRepository
extends AbstractEntityRepository<Long, ResourceType> {
private static final long serialVersionUID = -6313169146990554867L;
@ -44,6 +44,11 @@ public class ResourceTypeRepository extends AbstractEntityRepository<Long,
return ResourceType.class;
}
@Override
public String getIdAttributeName() {
return "resourceTypeId";
}
@Override
public boolean isNew(final ResourceType entity) {
return entity.getTitle() == null;
@ -67,4 +72,5 @@ public class ResourceTypeRepository extends AbstractEntityRepository<Long,
return Optional.empty();
}
}
}

View File

@ -33,7 +33,8 @@ import java.util.UUID;
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
*/
@RequestScoped
public class ComponentModelRepository extends AbstractEntityRepository<Long, ComponentModel> {
public class ComponentModelRepository
extends AbstractEntityRepository<Long, ComponentModel> {
private static final long serialVersionUID = -6358512316472857971L;
@ -42,6 +43,11 @@ public class ComponentModelRepository extends AbstractEntityRepository<Long, Com
return ComponentModel.class;
}
@Override
public String getIdAttributeName() {
return "componentModelId";
}
@Override
public boolean isNew(final ComponentModel componentModel) {
return componentModel.getComponentModelId() == 0;

View File

@ -48,6 +48,11 @@ public class PageModelRepository extends AbstractEntityRepository<Long, PageMode
return PageModel.class;
}
@Override
public String getIdAttributeName() {
return "pageModelId";
}
@Override
public boolean isNew(final PageModel pageModel) {

View File

@ -42,6 +42,11 @@ public class GroupRepository extends AbstractEntityRepository<Long, Group> {
return Group.class;
}
@Override
public String getIdAttributeName() {
return "partyId";
}
@Override
public boolean isNew(final Group entity) {
if (entity == null) {

View File

@ -42,6 +42,11 @@ public class PartyRepository extends AbstractEntityRepository<Long, Party> {
return Party.class;
}
@Override
public String getIdAttributeName() {
return "partyId";
}
@Override
public boolean isNew(final Party entity) {
if (entity == null) {

View File

@ -42,6 +42,11 @@ public class PermissionRepository
return Permission.class;
}
@Override
public String getIdAttributeName() {
return "permissionId";
}
@Override
public boolean isNew(Permission entity) {
if (entity == null) {
@ -51,9 +56,9 @@ public class PermissionRepository
}
/**
* Finds a {@link Permission} by the privilege, the grantee and the
* object. Where the grantee has been granted the given privilege on the
* given object.
* Finds a {@link Permission} by the privilege, the grantee and the object.
* Where the grantee has been granted the given privilege on the given
* object.
*
* @param privilege The privilege, beeing granted
* @param grantee The grantee, having the privilege
@ -64,12 +69,14 @@ public class PermissionRepository
public Optional<Permission> findByCustomPermId(final String privilege,
final Role grantee,
final Object object) {
final TypedQuery<Permission> query = getEntityManager().createNamedQuery(
final TypedQuery<Permission> query = getEntityManager()
.createNamedQuery(
"Permission.findByCustomPermId", Permission.class);
query.setParameter("privilege", privilege);
query.setParameter("grantee", grantee);
if (object != null)
if (object != null) {
query.setParameter("object", object);
}
try {
return Optional.of(query.getSingleResult());
@ -77,4 +84,5 @@ public class PermissionRepository
return Optional.empty();
}
}
}

View File

@ -44,6 +44,11 @@ public class RoleRepository extends AbstractEntityRepository<Long, Role> {
return Role.class;
}
@Override
public String getIdAttributeName() {
return "roleId";
}
@Override
public boolean isNew(final Role entity) {
if (entity == null) {

View File

@ -43,6 +43,11 @@ public class UserRepository extends AbstractEntityRepository<Long, User> {
return User.class;
}
@Override
public String getIdAttributeName() {
return "partyId";
}
@Override
public boolean isNew(final User user) {
if (user == null) {

View File

@ -123,6 +123,11 @@ public class SiteRepository extends AbstractEntityRepository<Long, Site> {
return Site.class;
}
@Override
public String getIdAttributeName() {
return "objectId";
}
@Override
public boolean isNew(final Site site) {
return site.getObjectId() == 0;

View File

@ -47,6 +47,11 @@ public class ApplicationRepository
return CcmApplication.class;
}
@Override
public String getIdAttributeName() {
return "objectId";
}
@Override
public boolean isNew(final CcmApplication application) {
return application.getObjectId() == 0;

View File

@ -36,8 +36,9 @@ import java.util.stream.Collectors;
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
*/
@RequestScoped
public class AssignableTaskRepository extends AbstractEntityRepository<Long,
AssignableTask> {
public class AssignableTaskRepository
extends AbstractEntityRepository<Long, AssignableTask> {
private static final long serialVersionUID = 2657793145163510103L;
@Override
@ -45,6 +46,11 @@ public class AssignableTaskRepository extends AbstractEntityRepository<Long,
return AssignableTask.class;
}
@Override
public String getIdAttributeName() {
return "taskId";
}
@Override
public boolean isNew(final AssignableTask task) {
return task.getTaskId() == 0;

View File

@ -27,11 +27,12 @@ import java.util.Optional;
/**
* @author <a href="mailto:tosmers@uni-bremen.de>Tobias Osmers<\a>
* @version created the 9/27/17
*
*/
@RequestScoped
public class TaskCommentRepository extends AbstractEntityRepository<Long,
TaskComment> {
public class TaskCommentRepository
extends AbstractEntityRepository<Long, TaskComment> {
private static final long serialVersionUID = -420902242220205847L;
@Override
@ -39,6 +40,11 @@ public class TaskCommentRepository extends AbstractEntityRepository<Long,
return TaskComment.class;
}
@Override
public String getIdAttributeName() {
return "commentId";
}
@Override
public boolean isNew(TaskComment entity) {
return entity.getCommentId() == 0;
@ -62,4 +68,5 @@ public class TaskCommentRepository extends AbstractEntityRepository<Long,
return Optional.empty();
}
}
}

View File

@ -34,6 +34,7 @@ import java.util.UUID;
*/
@RequestScoped
public class TaskRepository extends AbstractEntityRepository<Long, Task> {
private static final long serialVersionUID = -8366096936911158514L;
@Override
@ -41,6 +42,11 @@ public class TaskRepository extends AbstractEntityRepository<Long, Task> {
return Task.class;
}
@Override
public String getIdAttributeName() {
return "taskId";
}
@Override
public boolean isNew(final Task task) {
return task.getTaskId() == 0;
@ -71,4 +77,5 @@ public class TaskRepository extends AbstractEntityRepository<Long, Task> {
return Optional.empty();
}
}
}

View File

@ -34,6 +34,7 @@ import java.util.UUID;
*/
@RequestScoped
public class WorkflowRepository extends AbstractEntityRepository<Long, Workflow> {
private static final long serialVersionUID = -8811728904958517569L;
@Override
@ -41,6 +42,11 @@ public class WorkflowRepository extends AbstractEntityRepository<Long, Workflow>
return Workflow.class;
}
@Override
public String getIdAttributeName() {
return "workflowId";
}
@Override
public boolean isNew(final Workflow workflow) {
return workflow.getWorkflowId() == 0;

View File

@ -32,9 +32,8 @@ import javax.persistence.Lob;
import javax.persistence.OneToOne;
import javax.persistence.Table;
import javax.validation.constraints.NotNull;
import javax.xml.bind.annotation.XmlElement;
import java.io.Serializable;
import java.sql.Blob;
import java.util.Arrays;
import java.util.Objects;

View File

@ -18,7 +18,6 @@
*/
package org.libreccm.docrepo;
import org.libreccm.auditing.AbstractAuditedEntityRepository;
import javax.enterprise.context.RequestScoped;
@ -43,6 +42,11 @@ public class BlobObjectRepository extends
return entity.getBlobObjectId();
}
@Override
public String getIdAttributeName() {
return "blobObjectId";
}
@Override
public Class<BlobObject> getEntityClass() {
return BlobObject.class;
@ -55,4 +59,5 @@ public class BlobObjectRepository extends
}
return entity.getBlobObjectId() == 0;
}
}

View File

@ -34,6 +34,11 @@ public class FileRepository extends AbstractResourceRepository<File> {
classOfT = File.class;
}
@Override
public String getIdAttributeName() {
return "objectId";
}
@Override
public TypedQuery<File> getFindByNameQuery() {
return entityManager.createNamedQuery(
@ -57,4 +62,5 @@ public class FileRepository extends AbstractResourceRepository<File> {
return entityManager.createNamedQuery(
"DocRepo.findModifiedFileFromUser", File.class);
}
}

View File

@ -34,6 +34,11 @@ public class FolderRepository extends AbstractResourceRepository<Folder> {
classOfT = Folder.class;
}
@Override
public String getIdAttributeName() {
return "objectId";
}
@Override
public TypedQuery<Folder> getFindByNameQuery() {
return entityManager.createNamedQuery(
@ -57,4 +62,5 @@ public class FolderRepository extends AbstractResourceRepository<Folder> {
return entityManager.createNamedQuery(
"DocRepo.findModifiedFolderFromUser", Folder.class);
}
}

View File

@ -34,11 +34,10 @@ import java.util.stream.Collectors;
* Repository class for retrieving, storing and deleting {@code Repository}s.
*
* @author <a href="mailto:tosmers@uni-bremen.de">Tobias Osmers</a>
* @version 25/11/2015
*/
@RequestScoped
public class RepositoryRepository extends
AbstractAuditedEntityRepository<Long, Repository> {
public class RepositoryRepository
extends AbstractAuditedEntityRepository<Long, Repository> {
@Inject
private EntityManager entityManager;
@ -48,6 +47,11 @@ public class RepositoryRepository extends
return entity.getObjectId();
}
@Override
public String getIdAttributeName() {
return "objectId";
}
@Override
public Class<Repository> getEntityClass() {
return Repository.class;

View File

@ -48,6 +48,11 @@ public class ShortcutRepository extends AbstractEntityRepository<Long, Shortcut>
return Shortcut.class;
}
@Override
public String getIdAttributeName() {
return "shortcutId";
}
@Override
public boolean isNew(final Shortcut entity) {
return entity.getShortcutId() == 0;