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

View File

@ -115,6 +115,11 @@ public class ContentItemRepository
public Class<ContentItem> getEntityClass() { public Class<ContentItem> getEntityClass() {
return ContentItem.class; return ContentItem.class;
} }
@Override
public String getIdAttributeName() {
return "objectId";
}
@Override @Override
public boolean isNew(final ContentItem item) { public boolean isNew(final ContentItem item) {

View File

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

View File

@ -54,6 +54,11 @@ public class ContentTypeRepository
public Class<ContentType> getEntityClass() { public Class<ContentType> getEntityClass() {
return ContentType.class; return ContentType.class;
} }
@Override
public String getIdAttributeName() {
return "objectId";
}
@Override @Override
public boolean isNew(final ContentType type) { public boolean isNew(final ContentType type) {

View File

@ -43,6 +43,8 @@ import javax.transaction.Transactional;
@RequestScoped @RequestScoped
public class FolderRepository extends AbstractEntityRepository<Long, Folder> { public class FolderRepository extends AbstractEntityRepository<Long, Folder> {
private static final long serialVersionUID = -2588848483908283604L;
private static final Logger LOGGER = LogManager.getLogger( private static final Logger LOGGER = LogManager.getLogger(
FolderRepository.class); FolderRepository.class);
@ -54,6 +56,11 @@ public class FolderRepository extends AbstractEntityRepository<Long, Folder> {
return Folder.class; return Folder.class;
} }
@Override
public String getIdAttributeName() {
return "objectId";
}
@Override @Override
public boolean isNew(final Folder folder) { public boolean isNew(final Folder folder) {
return folder.getObjectId() == 0; return folder.getObjectId() == 0;
@ -200,14 +207,14 @@ public class FolderRepository extends AbstractEntityRepository<Long, Folder> {
} }
public List<Folder> findSubFolders(final Folder parent) { public List<Folder> findSubFolders(final Folder parent) {
final TypedQuery<Folder> query = getEntityManager() final TypedQuery<Folder> query = getEntityManager()
.createNamedQuery("Folder.findSubFolders", Folder.class); .createNamedQuery("Folder.findSubFolders", Folder.class);
query.setParameter("parent", parent); query.setParameter("parent", parent);
return query.getResultList(); return query.getResultList();
} }
@AuthorizationRequired @AuthorizationRequired
@Transactional(Transactional.TxType.REQUIRED) @Transactional(Transactional.TxType.REQUIRED)
@Override @Override

View File

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

View File

@ -27,19 +27,24 @@ import javax.enterprise.context.RequestScoped;
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a> * @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
*/ */
@RequestScoped @RequestScoped
public class LifecycleDefinitionRepository public class LifecycleDefinitionRepository
extends AbstractEntityRepository<Long, LifecycleDefinition>{ extends AbstractEntityRepository<Long, LifecycleDefinition> {
private static final long serialVersionUID = -6388883975391235155L;
@Override @Override
public Class<LifecycleDefinition> getEntityClass() { public Class<LifecycleDefinition> getEntityClass() {
return LifecycleDefinition.class; return LifecycleDefinition.class;
} }
@Override
public String getIdAttributeName() {
return "definitionId";
}
@Override @Override
public boolean isNew(final LifecycleDefinition lifecycleDefinition) { public boolean isNew(final LifecycleDefinition lifecycleDefinition) {
return lifecycleDefinition.getDefinitionId() == 0; return lifecycleDefinition.getDefinitionId() == 0;
} }
} }

View File

@ -33,6 +33,11 @@ public class LifecycleRepository extends AbstractEntityRepository<Long, Lifecycl
public Class<Lifecycle> getEntityClass() { public Class<Lifecycle> getEntityClass() {
return Lifecycle.class; return Lifecycle.class;
} }
@Override
public String getIdAttributeName() {
return "lifecycleId";
}
@Override @Override
public boolean isNew(final Lifecycle lifecycle) { public boolean isNew(final Lifecycle lifecycle) {

View File

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

View File

@ -27,7 +27,7 @@ import javax.enterprise.context.RequestScoped;
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a> * @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
*/ */
@RequestScoped @RequestScoped
public class PhaseRepository extends AbstractEntityRepository<Long, Phase>{ public class PhaseRepository extends AbstractEntityRepository<Long, Phase> {
private static final long serialVersionUID = 1010039772043186415L; private static final long serialVersionUID = 1010039772043186415L;
@ -36,9 +36,14 @@ public class PhaseRepository extends AbstractEntityRepository<Long, Phase>{
return Phase.class; return Phase.class;
} }
@Override
public String getIdAttributeName() {
return "phaseId";
}
@Override @Override
public boolean isNew(final Phase phase) { public boolean isNew(final Phase phase) {
return phase.getPhaseId() == 0; return phase.getPhaseId() == 0;
} }
} }

View File

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

View File

@ -82,16 +82,21 @@ public class PagesRepository extends AbstractEntityRepository<Long, Pages> {
return Pages.class; return Pages.class;
} }
@Override
public String getIdAttributeName() {
return "objectId";
}
@Override @Override
public boolean isNew(final Pages pages) { public boolean isNew(final Pages pages) {
return pages.getObjectId() == 0; return pages.getObjectId() == 0;
} }
@Override @Override
public void initNewEntity(final Pages pages) { public void initNewEntity(final Pages pages) {
super.initNewEntity(pages); super.initNewEntity(pages);
pages.setUuid(UUID.randomUUID().toString()); pages.setUuid(UUID.randomUUID().toString());
pages.setApplicationType(Pages.class.getName()); pages.setApplicationType(Pages.class.getName());
} }

View File

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

View File

@ -51,6 +51,11 @@ public class DomainRepository extends AbstractEntityRepository<Long, Domain> {
return Domain.class; return Domain.class;
} }
@Override
public String getIdAttributeName() {
return "objectId";
}
@Override @Override
public boolean isNew(final Domain entity) { public boolean isNew(final Domain entity) {
return entity.getObjectId() == 0; return entity.getObjectId() == 0;
@ -79,11 +84,11 @@ public class DomainRepository extends AbstractEntityRepository<Long, Domain> {
*/ */
public Optional<Domain> findByDomainKey(final String domainKey) { public Optional<Domain> findByDomainKey(final String domainKey) {
final TypedQuery<Domain> query = getEntityManager() final TypedQuery<Domain> query = getEntityManager()
.createNamedQuery("Domain.findByKey", Domain.class); .createNamedQuery("Domain.findByKey", Domain.class);
query.setParameter("key", domainKey); query.setParameter("key", domainKey);
final EntityGraph<?> graph = getEntityManager() final EntityGraph<?> graph = getEntityManager()
.getEntityGraph( "Domain.allCategories"); .getEntityGraph("Domain.allCategories");
query.setHint("javax.persistence.fetchgraph", graph); query.setHint("javax.persistence.fetchgraph", graph);
try { try {
@ -103,7 +108,7 @@ public class DomainRepository extends AbstractEntityRepository<Long, Domain> {
*/ */
public Domain findByUri(final URI uri) { public Domain findByUri(final URI uri) {
final TypedQuery<Domain> query = getEntityManager() final TypedQuery<Domain> query = getEntityManager()
.createNamedQuery("Domain.findByUri", Domain.class); .createNamedQuery("Domain.findByUri", Domain.class);
query.setParameter("uri", uri); query.setParameter("uri", uri);
return query.getSingleResult(); return query.getSingleResult();
@ -118,7 +123,7 @@ public class DomainRepository extends AbstractEntityRepository<Long, Domain> {
*/ */
public Optional<Domain> findByUuid(final String uuid) { public Optional<Domain> findByUuid(final String uuid) {
final TypedQuery<Domain> query = getEntityManager() final TypedQuery<Domain> query = getEntityManager()
.createNamedQuery("Domain.findByUuid", Domain.class); .createNamedQuery("Domain.findByUuid", Domain.class);
query.setParameter("uuid", uuid); query.setParameter("uuid", uuid);
try { try {
@ -130,10 +135,10 @@ public class DomainRepository extends AbstractEntityRepository<Long, Domain> {
public List<Domain> search(final String term) { public List<Domain> search(final String term) {
final TypedQuery<Domain> query = getEntityManager() final TypedQuery<Domain> query = getEntityManager()
.createNamedQuery("Domain.search", Domain.class); .createNamedQuery("Domain.search", Domain.class);
query.setParameter("term", term); query.setParameter("term", term);
final EntityGraph<?> graph = getEntityManager() final EntityGraph<?> graph = getEntityManager()
.getEntityGraph("Domain.withOwners"); .getEntityGraph("Domain.withOwners");
query.setHint("javax.persistence.fetchgraph", graph); query.setHint("javax.persistence.fetchgraph", graph);
return query.getResultList(); return query.getResultList();

View File

@ -123,6 +123,14 @@ public abstract class AbstractEntityRepository<K, E> implements Serializable {
* repository. * repository.
*/ */
public abstract Class<E> getEntityClass(); 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. * Finds an entity by it ID.

View File

@ -50,6 +50,11 @@ public class CcmObjectRepository extends AbstractEntityRepository<Long, CcmObjec
public Class<CcmObject> getEntityClass() { public Class<CcmObject> getEntityClass() {
return CcmObject.class; return CcmObject.class;
} }
@Override
public String getIdAttributeName() {
return "objectId";
}
@Override @Override
public boolean isNew(final CcmObject entity) { public boolean isNew(final CcmObject entity) {

View File

@ -44,6 +44,11 @@ public class ResourceRepository extends AbstractEntityRepository<Long,
public Class<Resource> getEntityClass() { public Class<Resource> getEntityClass() {
return Resource.class; return Resource.class;
} }
@Override
public String getIdAttributeName() {
return "objectId";
}
@Override @Override
public boolean isNew(final Resource entity) { public boolean isNew(final Resource entity) {

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -33,7 +33,7 @@ import java.util.Optional;
*/ */
@RequestScoped @RequestScoped
public class PermissionRepository public class PermissionRepository
extends AbstractEntityRepository<Long, Permission> { extends AbstractEntityRepository<Long, Permission> {
private static final long serialVersionUID = -4240674229117593486L; private static final long serialVersionUID = -4240674229117593486L;
@ -42,6 +42,11 @@ public class PermissionRepository
return Permission.class; return Permission.class;
} }
@Override
public String getIdAttributeName() {
return "permissionId";
}
@Override @Override
public boolean isNew(Permission entity) { public boolean isNew(Permission entity) {
if (entity == null) { if (entity == null) {
@ -51,25 +56,27 @@ public class PermissionRepository
} }
/** /**
* Finds a {@link Permission} by the privilege, the grantee and the * Finds a {@link Permission} by the privilege, the grantee and the object.
* object. Where the grantee has been granted the given privilege on the * Where the grantee has been granted the given privilege on the given
* given object. * object.
* *
* @param privilege The privilege, beeing granted * @param privilege The privilege, beeing granted
* @param grantee The grantee, having the privilege * @param grantee The grantee, having the privilege
* @param object The object, the privilege has been granted on * @param object The object, the privilege has been granted on
* *
* @return An optional either with the found item or empty * @return An optional either with the found item or empty
*/ */
public Optional<Permission> findByCustomPermId(final String privilege, public Optional<Permission> findByCustomPermId(final String privilege,
final Role grantee, final Role grantee,
final Object object) { final Object object) {
final TypedQuery<Permission> query = getEntityManager().createNamedQuery( final TypedQuery<Permission> query = getEntityManager()
.createNamedQuery(
"Permission.findByCustomPermId", Permission.class); "Permission.findByCustomPermId", Permission.class);
query.setParameter("privilege", privilege); query.setParameter("privilege", privilege);
query.setParameter("grantee", grantee); query.setParameter("grantee", grantee);
if (object != null) if (object != null) {
query.setParameter("object", object); query.setParameter("object", object);
}
try { try {
return Optional.of(query.getSingleResult()); return Optional.of(query.getSingleResult());
@ -77,4 +84,5 @@ public class PermissionRepository
return Optional.empty(); return Optional.empty();
} }
} }
} }

View File

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

View File

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

View File

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

View File

@ -47,6 +47,11 @@ public class ApplicationRepository
return CcmApplication.class; return CcmApplication.class;
} }
@Override
public String getIdAttributeName() {
return "objectId";
}
@Override @Override
public boolean isNew(final CcmApplication application) { public boolean isNew(final CcmApplication application) {
return application.getObjectId() == 0; return application.getObjectId() == 0;
@ -54,12 +59,12 @@ public class ApplicationRepository
@Override @Override
public void initNewEntity(final CcmApplication application) { public void initNewEntity(final CcmApplication application) {
super.initNewEntity(application); super.initNewEntity(application);
application.setUuid(UUID.randomUUID().toString()); application.setUuid(UUID.randomUUID().toString());
application.setApplicationType(application.getClass().getName()); application.setApplicationType(application.getClass().getName());
} }
/** /**
* Retrieve the application mounted at the provided {@code path}. * Retrieve the application mounted at the provided {@code path}.
* *
@ -108,8 +113,8 @@ public class ApplicationRepository
*/ */
public Optional<CcmApplication> findByUuid(final String uuid) { public Optional<CcmApplication> findByUuid(final String uuid) {
final TypedQuery<CcmApplication> query = getEntityManager() final TypedQuery<CcmApplication> query = getEntityManager()
.createNamedQuery("CcmApplication.findByUuid", .createNamedQuery("CcmApplication.findByUuid",
CcmApplication.class); CcmApplication.class);
query.setParameter("uuid", uuid); query.setParameter("uuid", uuid);
try { try {
@ -118,7 +123,7 @@ public class ApplicationRepository
return Optional.empty(); return Optional.empty();
} }
} }
@AuthorizationRequired @AuthorizationRequired
@RequiresPrivilege(CoreConstants.PRIVILEGE_ADMIN) @RequiresPrivilege(CoreConstants.PRIVILEGE_ADMIN)
@Transactional(Transactional.TxType.REQUIRED) @Transactional(Transactional.TxType.REQUIRED)
@ -126,7 +131,7 @@ public class ApplicationRepository
public void save(final CcmApplication application) { public void save(final CcmApplication application) {
super.save(application); super.save(application);
} }
@AuthorizationRequired @AuthorizationRequired
@RequiresPrivilege(CoreConstants.PRIVILEGE_ADMIN) @RequiresPrivilege(CoreConstants.PRIVILEGE_ADMIN)
@Transactional(Transactional.TxType.REQUIRED) @Transactional(Transactional.TxType.REQUIRED)

View File

@ -36,8 +36,9 @@ import java.util.stream.Collectors;
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a> * @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
*/ */
@RequestScoped @RequestScoped
public class AssignableTaskRepository extends AbstractEntityRepository<Long, public class AssignableTaskRepository
AssignableTask> { extends AbstractEntityRepository<Long, AssignableTask> {
private static final long serialVersionUID = 2657793145163510103L; private static final long serialVersionUID = 2657793145163510103L;
@Override @Override
@ -45,6 +46,11 @@ public class AssignableTaskRepository extends AbstractEntityRepository<Long,
return AssignableTask.class; return AssignableTask.class;
} }
@Override
public String getIdAttributeName() {
return "taskId";
}
@Override @Override
public boolean isNew(final AssignableTask task) { public boolean isNew(final AssignableTask task) {
return task.getTaskId() == 0; 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> * @author <a href="mailto:tosmers@uni-bremen.de>Tobias Osmers<\a>
* @version created the 9/27/17 *
*/ */
@RequestScoped @RequestScoped
public class TaskCommentRepository extends AbstractEntityRepository<Long, public class TaskCommentRepository
TaskComment> { extends AbstractEntityRepository<Long, TaskComment> {
private static final long serialVersionUID = -420902242220205847L; private static final long serialVersionUID = -420902242220205847L;
@Override @Override
@ -39,6 +40,11 @@ public class TaskCommentRepository extends AbstractEntityRepository<Long,
return TaskComment.class; return TaskComment.class;
} }
@Override
public String getIdAttributeName() {
return "commentId";
}
@Override @Override
public boolean isNew(TaskComment entity) { public boolean isNew(TaskComment entity) {
return entity.getCommentId() == 0; return entity.getCommentId() == 0;
@ -62,4 +68,5 @@ public class TaskCommentRepository extends AbstractEntityRepository<Long,
return Optional.empty(); return Optional.empty();
} }
} }
} }

View File

@ -29,11 +29,12 @@ import java.util.UUID;
/** /**
* Repository for {@link Task}s. * Repository for {@link Task}s.
* *
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a> * @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
*/ */
@RequestScoped @RequestScoped
public class TaskRepository extends AbstractEntityRepository<Long, Task> { public class TaskRepository extends AbstractEntityRepository<Long, Task> {
private static final long serialVersionUID = -8366096936911158514L; private static final long serialVersionUID = -8366096936911158514L;
@Override @Override
@ -41,6 +42,11 @@ public class TaskRepository extends AbstractEntityRepository<Long, Task> {
return Task.class; return Task.class;
} }
@Override
public String getIdAttributeName() {
return "taskId";
}
@Override @Override
public boolean isNew(final Task task) { public boolean isNew(final Task task) {
return task.getTaskId() == 0; return task.getTaskId() == 0;
@ -62,7 +68,7 @@ public class TaskRepository extends AbstractEntityRepository<Long, Task> {
@Transactional(Transactional.TxType.REQUIRED) @Transactional(Transactional.TxType.REQUIRED)
public Optional<Task> findByUuid(final String uuid) { public Optional<Task> findByUuid(final String uuid) {
final TypedQuery<Task> query = getEntityManager().createNamedQuery( final TypedQuery<Task> query = getEntityManager().createNamedQuery(
"Task.findByUuid", Task.class); "Task.findByUuid", Task.class);
query.setParameter("uuid", uuid); query.setParameter("uuid", uuid);
try { try {
@ -71,4 +77,5 @@ public class TaskRepository extends AbstractEntityRepository<Long, Task> {
return Optional.empty(); return Optional.empty();
} }
} }
} }

View File

@ -34,6 +34,7 @@ import java.util.UUID;
*/ */
@RequestScoped @RequestScoped
public class WorkflowRepository extends AbstractEntityRepository<Long, Workflow> { public class WorkflowRepository extends AbstractEntityRepository<Long, Workflow> {
private static final long serialVersionUID = -8811728904958517569L; private static final long serialVersionUID = -8811728904958517569L;
@Override @Override
@ -41,6 +42,11 @@ public class WorkflowRepository extends AbstractEntityRepository<Long, Workflow>
return Workflow.class; return Workflow.class;
} }
@Override
public String getIdAttributeName() {
return "workflowId";
}
@Override @Override
public boolean isNew(final Workflow workflow) { public boolean isNew(final Workflow workflow) {
return workflow.getWorkflowId() == 0; return workflow.getWorkflowId() == 0;
@ -65,14 +71,14 @@ public class WorkflowRepository extends AbstractEntityRepository<Long, Workflow>
throw new IllegalArgumentException( throw new IllegalArgumentException(
"The UUID of the Workflow to retrieve can't be null or empty."); "The UUID of the Workflow to retrieve can't be null or empty.");
} }
final TypedQuery<Workflow> query = getEntityManager() final TypedQuery<Workflow> query = getEntityManager()
.createNamedQuery("Workflow.findByUuid", Workflow.class); .createNamedQuery("Workflow.findByUuid", Workflow.class);
query.setParameter("uuid", uuid); query.setParameter("uuid", uuid);
try { try {
return Optional.of(query.getSingleResult()); return Optional.of(query.getSingleResult());
} catch(NoResultException ex) { } catch (NoResultException ex) {
return Optional.empty(); return Optional.empty();
} }
} }

View File

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

View File

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

View File

@ -34,27 +34,33 @@ public class FileRepository extends AbstractResourceRepository<File> {
classOfT = File.class; classOfT = File.class;
} }
@Override
public String getIdAttributeName() {
return "objectId";
}
@Override @Override
public TypedQuery<File> getFindByNameQuery() { public TypedQuery<File> getFindByNameQuery() {
return entityManager.createNamedQuery( return entityManager.createNamedQuery(
"DocRepo.findFileByName", File.class); "DocRepo.findFileByName", File.class);
} }
@Override @Override
public TypedQuery<File> getFindByPathNameQuery() { public TypedQuery<File> getFindByPathNameQuery() {
return entityManager.createNamedQuery( return entityManager.createNamedQuery(
"DocRepo.findFileByPath", File.class); "DocRepo.findFileByPath", File.class);
} }
@Override @Override
public TypedQuery<File> getFindForCreatorQuery() { public TypedQuery<File> getFindForCreatorQuery() {
return entityManager.createNamedQuery( return entityManager.createNamedQuery(
"DocRepo.findCreatedFileFromUser", File.class); "DocRepo.findCreatedFileFromUser", File.class);
} }
@Override @Override
public TypedQuery<File> getFindForModifierQuery() { public TypedQuery<File> getFindForModifierQuery() {
return entityManager.createNamedQuery( return entityManager.createNamedQuery(
"DocRepo.findModifiedFileFromUser", File.class); "DocRepo.findModifiedFileFromUser", File.class);
} }
} }

View File

@ -34,27 +34,33 @@ public class FolderRepository extends AbstractResourceRepository<Folder> {
classOfT = Folder.class; classOfT = Folder.class;
} }
@Override
public String getIdAttributeName() {
return "objectId";
}
@Override @Override
public TypedQuery<Folder> getFindByNameQuery() { public TypedQuery<Folder> getFindByNameQuery() {
return entityManager.createNamedQuery( return entityManager.createNamedQuery(
"DocRepo.findFolderByName", Folder.class); "DocRepo.findFolderByName", Folder.class);
} }
@Override @Override
public TypedQuery<Folder> getFindByPathNameQuery() { public TypedQuery<Folder> getFindByPathNameQuery() {
return entityManager.createNamedQuery( return entityManager.createNamedQuery(
"DocRepo.findFolderByPath", Folder.class); "DocRepo.findFolderByPath", Folder.class);
} }
@Override @Override
public TypedQuery<Folder> getFindForCreatorQuery() { public TypedQuery<Folder> getFindForCreatorQuery() {
return entityManager.createNamedQuery( return entityManager.createNamedQuery(
"DocRepo.findCreatedFolderFromUser", Folder.class); "DocRepo.findCreatedFolderFromUser", Folder.class);
} }
@Override @Override
public TypedQuery<Folder> getFindForModifierQuery() { public TypedQuery<Folder> getFindForModifierQuery() {
return entityManager.createNamedQuery( return entityManager.createNamedQuery(
"DocRepo.findModifiedFolderFromUser", Folder.class); "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. * Repository class for retrieving, storing and deleting {@code Repository}s.
* *
* @author <a href="mailto:tosmers@uni-bremen.de">Tobias Osmers</a> * @author <a href="mailto:tosmers@uni-bremen.de">Tobias Osmers</a>
* @version 25/11/2015
*/ */
@RequestScoped @RequestScoped
public class RepositoryRepository extends public class RepositoryRepository
AbstractAuditedEntityRepository<Long, Repository> { extends AbstractAuditedEntityRepository<Long, Repository> {
@Inject @Inject
private EntityManager entityManager; private EntityManager entityManager;
@ -48,6 +47,11 @@ public class RepositoryRepository extends
return entity.getObjectId(); return entity.getObjectId();
} }
@Override
public String getIdAttributeName() {
return "objectId";
}
@Override @Override
public Class<Repository> getEntityClass() { public Class<Repository> getEntityClass() {
return Repository.class; return Repository.class;

View File

@ -34,7 +34,7 @@ import javax.transaction.Transactional;
/** /**
* Repository class for {@link Shortcut} entities. * Repository class for {@link Shortcut} entities.
* *
* @author <a href="konerman@tzi.de">Alexander Konermann</a> * @author <a href="konerman@tzi.de">Alexander Konermann</a>
*/ */
@RequestScoped @RequestScoped
@ -48,6 +48,11 @@ public class ShortcutRepository extends AbstractEntityRepository<Long, Shortcut>
return Shortcut.class; return Shortcut.class;
} }
@Override
public String getIdAttributeName() {
return "shortcutId";
}
@Override @Override
public boolean isNew(final Shortcut entity) { public boolean isNew(final Shortcut entity) {
return entity.getShortcutId() == 0; return entity.getShortcutId() == 0;