Several bugfixes

deploy_packages_to_gitea
Jens Pelzetter 2023-02-16 20:57:36 +01:00
parent 9f6937352c
commit e150bd2509
36 changed files with 237 additions and 134 deletions

View File

@ -1,12 +1,12 @@
{
"name": "@librecms/ccm-cms",
"version": "7.0.0-SNAPSHOT.2023-02-06T182349",
"version": "7.0.0-SNAPSHOT.2023-02-16T191702",
"lockfileVersion": 2,
"requires": true,
"packages": {
"": {
"name": "@librecms/ccm-cms",
"version": "7.0.0-SNAPSHOT.2023-02-06T182349",
"version": "7.0.0-SNAPSHOT.2023-02-16T191702",
"license": "LGPL-3.0-or-later",
"dependencies": {
"@tiptap/core": "^2.0.0-beta.127",

View File

@ -1,6 +1,6 @@
{
"name": "@librecms/ccm-cms",
"version": "7.0.0-SNAPSHOT.2023-02-06T182349",
"version": "7.0.0-SNAPSHOT.2023-02-16T191702",
"description": "JavaScript stuff for ccm-cms",
"main": "target/generated-resources/assets/@content-sections/cms-admin.js",
"types": "target/generated-resources/assets/@content-sections/cms-admin.d.ts",

View File

@ -143,8 +143,7 @@ public class BinaryAssetRepository
public void initNewEntity(final BinaryAsset asset) {
super.initNewEntity(asset);
if (asset.getUuid() == null) {
final String uuid = UUID.randomUUID().toString();
asset.setUuid(uuid);
asset.setUuid(UUID.randomUUID().toString());
}
}

View File

@ -137,8 +137,7 @@ public class AssetRepository
public void initNewEntity(final Asset asset) {
super.initNewEntity(asset);
if (asset.getUuid() == null) {
final String uuid = UUID.randomUUID().toString();
asset.setUuid(uuid);
asset.setUuid(UUID.randomUUID().toString());
}
}

View File

@ -159,7 +159,9 @@ public class AttachmentListRepository
@Override
protected void initNewEntity(final AttachmentList entity) {
super.initNewEntity(entity);
entity.setUuid(UUID.randomUUID().toString());
if (entity.getUuid() == null) {
entity.setUuid(UUID.randomUUID().toString());
}
}
}

View File

@ -138,10 +138,11 @@ public class ContentItemRepository
@Override
public void initNewEntity(final ContentItem item) {
final String uuid = UUID.randomUUID().toString();
item.setUuid(uuid);
if (item.getUuid() == null) {
item.setUuid(UUID.randomUUID().toString());
}
if (item.getItemUuid() == null || item.getItemUuid().isEmpty()) {
item.setItemUuid(uuid);
item.setItemUuid(item.getUuid());
}
}

View File

@ -95,16 +95,19 @@ public class ContentSectionRepository
return section.getObjectId() == 0;
}
@Override
protected void initNewEntity(final ContentSection section) {
if (section.getUuid() == null) {
section.setUuid(UUID.randomUUID().toString());
}
section.setApplicationType(ContentSection.class.getName());
}
@AuthorizationRequired
@RequiresPrivilege(CoreConstants.PRIVILEGE_ADMIN)
@Transactional(Transactional.TxType.REQUIRED)
@Override
public void save(final ContentSection section) {
if (isNew(section)) {
section.setUuid(UUID.randomUUID().toString());
section.setApplicationType(ContentSection.class.getName());
}
super.save(section);
}

View File

@ -79,7 +79,9 @@ public class FolderRepository extends AbstractEntityRepository<Long, Folder> {
@Override
public void initNewEntity(final Folder folder) {
folder.setUuid(UUID.randomUUID().toString());
if (folder.getUuid() == null) {
folder.setUuid(UUID.randomUUID().toString());
}
}
@Transactional(Transactional.TxType.REQUIRED)
@ -102,13 +104,13 @@ public class FolderRepository extends AbstractEntityRepository<Long, Folder> {
@Transactional(Transactional.TxType.REQUIRED)
public Optional<Folder> findByUuid(final String uuid) {
try {
return Optional.of(
getEntityManager()
.createNamedQuery("Folder.findByUuid", Folder.class)
.setParameter("uuid", uuid)
.getSingleResult()
);
} catch(NoResultException ex) {
return Optional.of(
getEntityManager()
.createNamedQuery("Folder.findByUuid", Folder.class)
.setParameter("uuid", uuid)
.getSingleResult()
);
} catch (NoResultException ex) {
return Optional.empty();
}
}

View File

@ -57,7 +57,9 @@ public class ItemAttachmentRepository
@Override
protected void initNewEntity(final ItemAttachment entity) {
entity.setUuid(UUID.randomUUID().toString());
if (entity.getUuid() == null) {
entity.setUuid(UUID.randomUUID().toString());
}
}
public Optional<ItemAttachment> findByUuid(final String uuid) {

View File

@ -40,17 +40,17 @@ public class LifecycleDefinitionRepository
try {
return Optional.of(
getEntityManager()
.createNamedQuery(
"LifecycleDefinition.findByUuid",
LifecycleDefinition.class)
.setParameter("uuid", uuid)
.getSingleResult()
.createNamedQuery(
"LifecycleDefinition.findByUuid",
LifecycleDefinition.class)
.setParameter("uuid", uuid)
.getSingleResult()
);
} catch(NoResultException ex) {
} catch (NoResultException ex) {
return Optional.empty();
}
}
@Override
public Class<LifecycleDefinition> getEntityClass() {
return LifecycleDefinition.class;
@ -74,9 +74,9 @@ public class LifecycleDefinitionRepository
@Override
protected void initNewEntity(final LifecycleDefinition entity) {
super.initNewEntity(entity);
entity.setUuid(UUID.randomUUID().toString());
if (entity.getUuid() == null) {
entity.setUuid(UUID.randomUUID().toString());
}
}
}

View File

@ -59,7 +59,9 @@ public class LifecycleRepository
@Override
protected void initNewEntity(final Lifecycle entity) {
super.initNewEntity(entity);
entity.setUuid(UUID.randomUUID().toString());
if (entity.getUuid() == null) {
entity.setUuid(UUID.randomUUID().toString());
}
}
public Optional<Lifecycle> findByUuid(final String uuid) {

View File

@ -55,11 +55,13 @@ public class PhaseDefinititionRepository
public boolean isNew(final PhaseDefinition phaseDefinition) {
return phaseDefinition.getDefinitionId() == 0;
}
@Override
public void initNewEntity(final PhaseDefinition phaseDefinition) {
super.initNewEntity(phaseDefinition);
phaseDefinition.setUuid(UUID.randomUUID().toString());
if (phaseDefinition.getUuid() == null) {
phaseDefinition.setUuid(UUID.randomUUID().toString());
}
}
public Optional<PhaseDefinition> findByUuid(final String uuid) {

View File

@ -58,7 +58,9 @@ public class PhaseRepository extends AbstractEntityRepository<Long, Phase> {
@Override
public void initNewEntity(final Phase phase) {
super.initNewEntity(phase);
phase.setUuid(UUID.randomUUID().toString());
if (phase.getUuid() == null) {
phase.setUuid(UUID.randomUUID().toString());
}
}
public Optional<Phase> findByUuid(final String uuid) {

View File

@ -64,10 +64,8 @@ public class PageRepository extends AbstractEntityRepository<Long, Page> {
@Override
protected void initNewEntity(final Page entity) {
super.initNewEntity(entity);
if (isNew(entity)) {
if (entity.getUuid() == null) {
entity.setUuid(UUID.randomUUID().toString());
}
}

View File

@ -99,10 +99,11 @@ public class PagesRepository extends AbstractEntityRepository<Long, Pages> {
@Override
public void initNewEntity(final Pages pages) {
super.initNewEntity(pages);
pages.setUuid(UUID.randomUUID().toString());
if (pages.getUuid() == null) {
pages.setUuid(UUID.randomUUID().toString());
}
pages.setApplicationType(Pages.class.getName());
}

View File

@ -83,7 +83,9 @@ public class CategoryRepository extends AbstractEntityRepository<Long, Category>
@Override
public void initNewEntity(final Category category) {
category.setUuid(UUID.randomUUID().toString());
if (category.getUuid() == null) {
category.setUuid(UUID.randomUUID().toString());
}
}
/**

View File

@ -68,7 +68,9 @@ public class DomainRepository extends AbstractEntityRepository<Long, Domain> {
@Override
public void initNewEntity(final Domain domain) {
domain.setUuid(UUID.randomUUID().toString());
if (domain.getUuid() == null) {
domain.setUuid(UUID.randomUUID().toString());
}
}
@Override

View File

@ -78,7 +78,9 @@ public class CcmObjectRepository extends AbstractEntityRepository<Long, CcmObjec
@Override
public void initNewEntity(final CcmObject entity) {
entity.setUuid(UUID.randomUUID().toString());
if (entity.getUuid() == null) {
entity.setUuid(UUID.randomUUID().toString());
}
}
/**

View File

@ -35,8 +35,7 @@ import java.util.UUID;
* @version created the 8/10/17
*/
@RequestScoped
public class ResourceRepository extends AbstractEntityRepository<Long,
Resource> {
public class ResourceRepository extends AbstractEntityRepository<Long, Resource> {
private static final long serialVersionUID = 4593206445936878071L;
@ -44,12 +43,12 @@ public class ResourceRepository extends AbstractEntityRepository<Long,
public Class<Resource> getEntityClass() {
return Resource.class;
}
@Override
public String getIdAttributeName() {
return "objectId";
}
@Override
public Long getIdOfEntity(final Resource entity) {
return entity.getObjectId();
@ -62,7 +61,9 @@ public class ResourceRepository extends AbstractEntityRepository<Long,
@Override
public void initNewEntity(final Resource resource) {
resource.setUuid(UUID.randomUUID().toString());
if (resource.getUuid() == null) {
resource.setUuid(UUID.randomUUID().toString());
}
}
/**
@ -74,7 +75,7 @@ public class ResourceRepository extends AbstractEntityRepository<Long,
*/
public Optional<Resource> findByUuid(final String uuid) {
final TypedQuery<Resource> query = getEntityManager()
.createNamedQuery("Resource.findByUuid", Resource.class);
.createNamedQuery("Resource.findByUuid", Resource.class);
query.setParameter("uuid", uuid);
try {
@ -83,4 +84,5 @@ public class ResourceRepository extends AbstractEntityRepository<Long,
return Optional.empty();
}
}
}

View File

@ -18,11 +18,16 @@
*/
package org.libreccm.core;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.libreccm.imexport.AbstractEntityImExporter;
import org.libreccm.imexport.Processes;
import java.util.Comparator;
import java.util.List;
import java.util.Objects;
import java.util.Optional;
import java.util.stream.Collectors;
import javax.annotation.PostConstruct;
import javax.inject.Inject;
@ -35,6 +40,10 @@ import javax.inject.Inject;
public class ResourceTypeImExporter
extends AbstractEntityImExporter<ResourceType> {
private static final Logger LOGGER = LogManager.getLogger(
ResourceTypeImExporter.class
);
@Inject
private ResourceTypeRepository repository;
@ -56,7 +65,22 @@ public class ResourceTypeImExporter
@Override
protected void saveImportedEntity(final ResourceType entity) {
final List<ResourceType> types = repository
.findAll()
.stream()
.sorted(
Comparator.comparing(ResourceType::getResourceTypeId)
)
.collect(Collectors.toList());
final long lastId;
if (types.isEmpty()) {
lastId = 0;
} else {
lastId = types.get(types.size() - 1).getResourceTypeId();
}
entity.setResourceTypeId(lastId + 1);
repository.save(entity);
LOGGER.debug("Saved {}", entity.toString());
}
@Override
@ -94,18 +118,18 @@ public class ResourceTypeImExporter
importedEntity.isViewableAsFullPage()
);
}
if (existingEntity.isViewableAsEmbedded() != importedEntity
.isViewableAsEmbedded()) {
existingEntity.setViewableAsEmbedded(
importedEntity.isViewableAsEmbedded()
);
}
if (existingEntity.isSingleton() != importedEntity.isSingleton()) {
existingEntity.setSingleton(importedEntity.isSingleton());
}
repository.save(importedEntity);
}

View File

@ -33,7 +33,7 @@ import java.util.UUID;
* application using the {@link ResourceType}.
*
* @author <a href="mailto:tosmers@uni-bremen.de">Tobias Osmers</a>
*
*
*/
@RequestScoped
public class ResourceTypeRepository
@ -50,7 +50,7 @@ public class ResourceTypeRepository
public String getIdAttributeName() {
return "resourceTypeId";
}
@Override
public Long getIdOfEntity(final ResourceType entity) {
return entity.getResourceTypeId();
@ -58,31 +58,26 @@ public class ResourceTypeRepository
@Override
public boolean isNew(final ResourceType entity) {
return entity.getTitle() == null;
return entity.getResourceTypeId() == 0;
// return entity.getTitle() == null;
}
@Override
public void initNewEntity(final ResourceType entity) {
if (entity.getResourceTypeId() == 0) {
if (entity.getUuid() == null) {
entity.setUuid(UUID.randomUUID().toString());
}
if (entity.getUuid() == null) {
entity.setUuid(UUID.randomUUID().toString());
}
}
public Optional<ResourceType> findByUuid(final String uuid) {
final TypedQuery<ResourceType> query = getEntityManager()
.createNamedQuery("ResourceType.findByUuid", ResourceType.class);
.createNamedQuery("ResourceType.findByUuid", ResourceType.class);
query.setParameter("uuid", uuid);
return getSingleResult(query);
}
/**
* Finds a {@link ResourceType} by its title.
*

View File

@ -62,11 +62,11 @@ public class GroupRepository extends AbstractEntityRepository<Long, Group> {
return entity.getPartyId() == 0;
}
public Optional<Group> findByUuid(final String uuid) {
final TypedQuery<Group> query = getEntityManager()
.createNamedQuery("Group.findByUuid", Group.class);
.createNamedQuery("Group.findByUuid", Group.class);
query.setParameter("uuid", uuid);
final List<Group> result = query.getResultList();
if (result.isEmpty()) {
@ -134,11 +134,12 @@ public class GroupRepository extends AbstractEntityRepository<Long, Group> {
public void save(final Group group) {
super.save(group);
}
@Override
public void initNewEntity(final Group group) {
group.setUuid(UUID.randomUUID().toString());
if (group.getUuid() == null) {
group.setUuid(UUID.randomUUID().toString());
}
}
@AuthorizationRequired

View File

@ -64,10 +64,11 @@ public class PartyRepository extends AbstractEntityRepository<Long, Party> {
@Override
public void initNewEntity(final Party party) {
party.setUuid(UUID.randomUUID().toString());
if (party.getUuid() == null) {
party.setUuid(UUID.randomUUID().toString());
}
}
public Optional<Party> findByUuid(final String uuid) {
final TypedQuery<Party> query = getEntityManager().createNamedQuery(
"Party.findByUuid", Party.class);
@ -80,7 +81,7 @@ public class PartyRepository extends AbstractEntityRepository<Long, Party> {
return Optional.of(result.get(0));
}
}
/**
* Finds a {@link Party} (which can be a user or group) by its name.
*

View File

@ -63,19 +63,20 @@ public class PermissionRepository
}
@Override
public void initNewEntity(final Permission permission) {
permission.setUuid(UUID.randomUUID().toString());
public void initNewEntity(final Permission permission) {
if (permission.getUuid() == null) {
permission.setUuid(UUID.randomUUID().toString());
}
}
public Optional<Permission> findByUuid(final String uuid) {
final TypedQuery<Permission> query = getEntityManager()
.createNamedQuery("Permission.findByUuid", Permission.class);
.createNamedQuery("Permission.findByUuid", Permission.class);
query.setParameter("uuid", uuid);
return getSingleResult(query);
}
/**
* Finds a {@link Permission} by the privilege, the grantee and the object.
* Where the grantee has been granted the given privilege on the given

View File

@ -55,7 +55,7 @@ public class RoleRepository extends AbstractEntityRepository<Long, Role> {
public Long getIdOfEntity(final Role entity) {
return entity.getRoleId();
}
@Override
public boolean isNew(final Role entity) {
if (entity == null) {
@ -63,12 +63,12 @@ public class RoleRepository extends AbstractEntityRepository<Long, Role> {
}
return entity.getRoleId() == 0;
}
@Override
public void initNewEntity(final Role role) {
role.setUuid(UUID.randomUUID().toString());
if (role.getUuid() == null) {
role.setUuid(UUID.randomUUID().toString());
}
}
public long count() {
@ -76,13 +76,13 @@ public class RoleRepository extends AbstractEntityRepository<Long, Role> {
"Role.count", Long.class);
return query.getSingleResult();
}
public Optional<Role> findByUuid(final String uuid) {
final TypedQuery<Role> query = getEntityManager()
.createNamedQuery("Role.findByUuid", Role.class);
.createNamedQuery("Role.findByUuid", Role.class);
query.setParameter("uuid", uuid);
return getSingleResult(query);
}

View File

@ -49,7 +49,7 @@ public class UserRepository extends AbstractEntityRepository<Long, User> {
public String getIdAttributeName() {
return "partyId";
}
@Override
public Long getIdOfEntity(final User entity) {
return entity.getPartyId();
@ -70,7 +70,7 @@ public class UserRepository extends AbstractEntityRepository<Long, User> {
return getSingleResult(query);
}
/**
* Finds a user by its user name.
*
@ -103,7 +103,7 @@ public class UserRepository extends AbstractEntityRepository<Long, User> {
final String entityGraphName) {
@SuppressWarnings("unchecked")
final EntityGraph<User> entityGraph
= (EntityGraph<User>) getEntityManager()
= (EntityGraph<User>) getEntityManager()
.getEntityGraph(entityGraphName);
return findByName(name, entityGraph);
}
@ -149,7 +149,7 @@ public class UserRepository extends AbstractEntityRepository<Long, User> {
final String entityGraphName) {
@SuppressWarnings("unchecked")
final EntityGraph<User> entityGraph
= (EntityGraph<User>) getEntityManager()
= (EntityGraph<User>) getEntityManager()
.getEntityGraph(entityGraphName);
return findByEmailAddress(emailAddress, entityGraph);
}
@ -206,12 +206,11 @@ public class UserRepository extends AbstractEntityRepository<Long, User> {
@Override
protected void initNewEntity(final User entity) {
entity.setUuid(UUID.randomUUID().toString());
if (entity.getUuid() == null) {
entity.setUuid(UUID.randomUUID().toString());
}
}
@AuthorizationRequired
@RequiresPrivilege(CoreConstants.PRIVILEGE_ADMIN)
@Transactional(Transactional.TxType.REQUIRED)

View File

@ -162,7 +162,9 @@ public class SiteRepository extends AbstractEntityRepository<Long, Site> {
@Override
public void initNewEntity(final Site site) {
site.setUuid(UUID.randomUUID().toString());
if (site.getUuid() == null) {
site.setUuid(UUID.randomUUID().toString());
}
}
}

View File

@ -53,7 +53,7 @@ public class ApplicationIdResolver implements Serializable, ObjectIdResolver {
.orElseThrow(
() -> new IllegalArgumentException(
String.format(
"No ccmApplications with UUID %s in the database.",
"No CcmApplication with UUID %s in the database.",
id.key.toString()
)
)

View File

@ -34,7 +34,7 @@ import java.util.UUID;
/**
* Repository for applications.
*
*
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
*/
@RequestScoped
@ -52,7 +52,7 @@ public class ApplicationRepository
public String getIdAttributeName() {
return "objectId";
}
@Override
public Long getIdOfEntity(final CcmApplication entity) {
return entity.getObjectId();
@ -65,10 +65,13 @@ public class ApplicationRepository
@Override
public void initNewEntity(final CcmApplication application) {
super.initNewEntity(application);
application.setUuid(UUID.randomUUID().toString());
application.setApplicationType(application.getClass().getName());
if (application.getUuid() == null) {
application.setUuid(UUID.randomUUID().toString());
}
if (application.getApplicationType() == null) {
application.setApplicationType(application.getClass().getName());
}
}
/**

View File

@ -18,6 +18,8 @@
*/
package org.libreccm.workflow;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.libreccm.imexport.AbstractEntityImExporter;
import org.libreccm.imexport.Processes;
@ -28,6 +30,7 @@ import java.util.Set;
import javax.annotation.PostConstruct;
import javax.enterprise.context.RequestScoped;
import javax.inject.Inject;
import javax.persistence.EntityManager;
/**
* Exporter/Importer for {@link AssignableTask}s.
@ -40,10 +43,17 @@ import javax.inject.Inject;
@Processes(AssignableTask.class)
public class AssignableTaskImExporter
extends AbstractEntityImExporter<AssignableTask> {
private static final Logger LOGGER = LogManager.getLogger(
AssignableTaskImExporter.class
);
@Inject
private AssignableTaskRepository assignableTaskRepository;
@Inject
private EntityManager entityManager;
@Inject
private TaskManager taskManager;
@ -74,6 +84,11 @@ public class AssignableTaskImExporter
@Override
protected void saveImportedEntity(final AssignableTask entity) {
assignableTaskRepository.save(entity);
LOGGER.warn(
"Saved imported assignable task with UUID {} and ID {}.",
entity.getUuid(),
entity.getTaskId()
);
}
@Override
@ -140,7 +155,7 @@ public class AssignableTaskImExporter
importedEntity.getDurationMinutes()
);
}
if (!Objects.equals(
existingEntity.getNotificationSender(),
importedEntity.getNotificationSender()

View File

@ -32,6 +32,8 @@ import java.util.Optional;
import java.util.UUID;
import java.util.stream.Collectors;
import javax.transaction.Transactional;
/**
* Repository for assignable tasks.
*
@ -52,7 +54,7 @@ public class AssignableTaskRepository
public String getIdAttributeName() {
return "taskId";
}
@Override
public Long getIdOfEntity(final AssignableTask entity) {
return entity.getTaskId();
@ -62,10 +64,10 @@ public class AssignableTaskRepository
public boolean isNew(final AssignableTask task) {
return task.getTaskId() == 0;
}
@Override
protected void initNewEntity(final AssignableTask entity) {
if (isNew(entity)) {
if (entity.getUuid() == null) {
entity.setUuid(UUID.randomUUID().toString());
}
}
@ -77,6 +79,7 @@ public class AssignableTaskRepository
*
* @return An optional either with the found item or empty
*/
@Transactional(Transactional.TxType.REQUIRED)
public Optional<AssignableTask> findByUuid(final String uuid) {
final TypedQuery<AssignableTask> query = getEntityManager()
.createNamedQuery(
@ -90,6 +93,7 @@ public class AssignableTaskRepository
}
}
@Transactional(Transactional.TxType.REQUIRED)
public List<AssignableTask> findEnabledTasksForWorkflow(
final User user, final Workflow workflow) {
final TypedQuery<AssignableTask> query = getEntityManager()
@ -102,6 +106,7 @@ public class AssignableTaskRepository
return query.getResultList();
}
@Transactional(Transactional.TxType.REQUIRED)
public List<AssignableTask> getAssignedTasks(final User user,
final Workflow workflow) {
final TypedQuery<AssignableTask> query = getEntityManager()
@ -119,6 +124,4 @@ public class AssignableTaskRepository
return query.getResultList();
}
}

View File

@ -36,6 +36,8 @@ import java.util.Objects;
import static org.libreccm.core.CoreConstants.DB_SCHEMA;
import org.libreccm.imexport.Exportable;
import javax.persistence.AssociationOverride;
import javax.persistence.Column;
import javax.persistence.Embedded;
@ -119,10 +121,11 @@ import javax.xml.bind.annotation.XmlElementWrapper;
@JsonIdentityInfo(
generator = ObjectIdGenerators.PropertyGenerator.class,
resolver = TaskIdResolver.class,
property = "uuid",
scope = Task.class
property = "uuid"
// ,
// scope = Task.class
)
public class Task implements Identifiable, Serializable {
public class Task implements Exportable, Identifiable, Serializable {
private static final long serialVersionUID = 8161343036908150426L;

View File

@ -20,10 +20,12 @@ package org.libreccm.workflow;
import com.fasterxml.jackson.annotation.ObjectIdGenerator;
import com.fasterxml.jackson.annotation.ObjectIdResolver;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.libreccm.cdi.utils.CdiUtil;
import javax.enterprise.context.RequestScoped;
import java.io.Serializable;
import java.util.Optional;
/**
* Used to resolve {@link Task}s based on the UUIDs for export or import.
@ -31,11 +33,13 @@ import java.io.Serializable;
* @author <a href="mailto:tosmers@uni-bremen.de">Tobias Osmers</a>
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
*/
@RequestScoped
public class TaskIdResolver implements Serializable, ObjectIdResolver {
private static final long serialVersionUID = 1L;
private static final Logger LOGGER = LogManager.getLogger(
TaskIdResolver.class);
private static final long serialVersionUID = 1L;
@Override
public void bindItem(
final ObjectIdGenerator.IdKey id,
@ -48,6 +52,31 @@ public class TaskIdResolver implements Serializable, ObjectIdResolver {
@Override
public Object resolveId(final ObjectIdGenerator.IdKey id) {
// final Optional<Task> result = CdiUtil
// .createCdiUtil()
// .findBean(TaskRepository.class)
// .findByUuid(id.key.toString());
//
// if (result.isPresent()) {
// return result.get();
// }
//
// return Optional.ofNullable(
// CdiUtil
// .createCdiUtil()
// .findBean(AssignableTaskImExporter.class)
// .getImportedTask(id.key.toString())
// )
// .orElseThrow(
// () -> new IllegalArgumentException(
// String.format(
// "No task with UUID %s found.",
// id.key.toString()
// )
// )
// );
//
return CdiUtil
.createCdiUtil()
.findBean(TaskRepository.class)

View File

@ -46,7 +46,7 @@ public class TaskRepository extends AbstractEntityRepository<Long, Task> {
public String getIdAttributeName() {
return "taskId";
}
@Override
public Long getIdOfEntity(final Task entity) {
return entity.getTaskId();
@ -60,7 +60,9 @@ public class TaskRepository extends AbstractEntityRepository<Long, Task> {
@Override
protected void initNewEntity(final Task task) {
super.initNewEntity(task);
task.setUuid(UUID.randomUUID().toString());
if (task.getUuid() == null) {
task.setUuid(UUID.randomUUID().toString());
}
}
/**
@ -73,7 +75,9 @@ public class TaskRepository extends AbstractEntityRepository<Long, Task> {
@Transactional(Transactional.TxType.REQUIRED)
public Optional<Task> findByUuid(final String uuid) {
final TypedQuery<Task> query = getEntityManager().createNamedQuery(
"Task.findByUuid", Task.class);
"Task.findByUuid",
Task.class
);
query.setParameter("uuid", uuid);
try {

View File

@ -39,7 +39,7 @@ import javax.transaction.Transactional;
public class WorkflowRepository extends AbstractEntityRepository<Long, Workflow> {
private static final long serialVersionUID = -8811728904958517569L;
@Override
public Class<Workflow> getEntityClass() {
return Workflow.class;
@ -54,7 +54,7 @@ public class WorkflowRepository extends AbstractEntityRepository<Long, Workflow>
public Long getIdOfEntity(final Workflow entity) {
return entity.getWorkflowId();
}
@Override
public boolean isNew(final Workflow workflow) {
return workflow.getWorkflowId() == 0;
@ -63,10 +63,10 @@ public class WorkflowRepository extends AbstractEntityRepository<Long, Workflow>
@Override
protected void initNewEntity(final Workflow workflow) {
super.initNewEntity(workflow);
workflow.setUuid(UUID.randomUUID().toString());
if (workflow.getUuid() == null) {
workflow.setUuid(UUID.randomUUID().toString());
}
}
/**
* Find a {@link Workflow} by its UUID.

View File

@ -203,6 +203,8 @@ public abstract class AbstractResourceRepository<T extends AbstractResource>
//Todo
@Override
public void initNewEntity(final T entity) {
entity.setUuid(UUID.randomUUID().toString());
if (entity.getUuid() == null) {
entity.setUuid(UUID.randomUUID().toString());
}
}
}