[CCM][FEATURE]
- adds import capabilities for workflow templates, workflows and task comments - fixes problems in workflow imports git-svn-id: https://svn.libreccm.org/ccm/ccm_ng@5014 8810af33-2d31-482b-a856-94f89814c4dfccm-docs
parent
edea9cb9a9
commit
82c6b50d7c
|
|
@ -143,6 +143,7 @@ public class Permission implements Serializable, Portable {
|
|||
@ManyToOne
|
||||
@JoinColumn(name = "CREATION_USER_ID")
|
||||
@XmlElement(name = "creation-user", namespace = CORE_XML_NS)
|
||||
@JsonIdentityReference(alwaysAsId = true)
|
||||
private User creationUser;
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -19,6 +19,7 @@
|
|||
package org.libreccm.workflow;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonIdentityInfo;
|
||||
import com.fasterxml.jackson.annotation.JsonIdentityReference;
|
||||
import com.fasterxml.jackson.annotation.JsonIgnore;
|
||||
import com.fasterxml.jackson.annotation.ObjectIdGenerators;
|
||||
import org.libreccm.portation.Portable;
|
||||
|
|
@ -100,6 +101,7 @@ public class AssignableTask extends Task implements Serializable, Portable {
|
|||
*/
|
||||
@OneToOne
|
||||
@JoinColumn(name = "LOCKING_USER_ID")
|
||||
@JsonIdentityReference(alwaysAsId = true)
|
||||
private User lockingUser;
|
||||
|
||||
/**
|
||||
|
|
@ -128,6 +130,7 @@ public class AssignableTask extends Task implements Serializable, Portable {
|
|||
@OneToOne
|
||||
@JoinColumn(name = "NOTIFICATION_SENDER")
|
||||
@SuppressWarnings("PMD.LongVariable") //Shorter name would not be descriptive
|
||||
@JsonIdentityReference(alwaysAsId = true)
|
||||
private User notificationSender;
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -47,7 +47,7 @@ public class AssignableTaskIdResolver implements ObjectIdResolver {
|
|||
return assignableTaskRepository
|
||||
.findByUuid(id.key.toString())
|
||||
.orElseThrow(() -> new IllegalArgumentException(String
|
||||
.format("No assignableTasks with uuid %s in the " +
|
||||
.format("No assignable tasks with uuid %s in the " +
|
||||
"database.", id.key.toString())));
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -36,8 +36,8 @@ 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> {
|
||||
|
||||
@Override
|
||||
public Class<AssignableTask> getEntityClass() {
|
||||
|
|
|
|||
|
|
@ -18,9 +18,12 @@
|
|||
*/
|
||||
package org.libreccm.workflow;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonIdentityInfo;
|
||||
import com.fasterxml.jackson.annotation.ObjectIdGenerators;
|
||||
import org.hibernate.annotations.Type;
|
||||
import org.libreccm.core.CoreConstants;
|
||||
import org.libreccm.core.Identifiable;
|
||||
import org.libreccm.portation.Portable;
|
||||
import org.libreccm.security.User;
|
||||
|
||||
import javax.persistence.*;
|
||||
|
|
@ -36,7 +39,15 @@ import java.util.Objects;
|
|||
*/
|
||||
@Entity
|
||||
@Table(name = "WORKFLOW_TASK_COMMENTS", schema = CoreConstants.DB_SCHEMA)
|
||||
public class TaskComment implements Identifiable, Serializable {
|
||||
@NamedQueries({
|
||||
@NamedQuery(
|
||||
name = "TaskComment.findByUuid",
|
||||
query = "SELECT c FROM TaskComment c WHERE c.uuid = :uuid")
|
||||
})
|
||||
@JsonIdentityInfo(generator = ObjectIdGenerators.PropertyGenerator.class,
|
||||
resolver = TaskCommentIdResolver.class,
|
||||
property = "uuid")
|
||||
public class TaskComment implements Identifiable, Serializable, Portable {
|
||||
|
||||
private static final long serialVersionUID = 3842991529698351698L;
|
||||
|
||||
|
|
|
|||
|
|
@ -0,0 +1,60 @@
|
|||
/*
|
||||
* Copyright (C) 2015 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.libreccm.workflow;
|
||||
|
||||
import com.fasterxml.jackson.annotation.ObjectIdGenerator;
|
||||
import com.fasterxml.jackson.annotation.ObjectIdResolver;
|
||||
import org.libreccm.cdi.utils.CdiUtil;
|
||||
|
||||
/**
|
||||
* @author <a href="mailto:tosmers@uni-bremen.de>Tobias Osmers<\a>
|
||||
* @version created the 9/27/17
|
||||
*/
|
||||
public class TaskCommentIdResolver implements ObjectIdResolver {
|
||||
@Override
|
||||
public void bindItem(ObjectIdGenerator.IdKey id,
|
||||
Object pojo) {
|
||||
// According to the Jackson JavaDoc, this method can be used to keep
|
||||
// track of objects directly in a resolver implementation. We don't need
|
||||
// this here therefore this method is empty.
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object resolveId(ObjectIdGenerator.IdKey id) {
|
||||
final CdiUtil cdiUtil = CdiUtil.createCdiUtil();
|
||||
final TaskCommentRepository taskCommentRepository = cdiUtil
|
||||
.findBean(TaskCommentRepository.class);
|
||||
|
||||
return taskCommentRepository
|
||||
.findByUuid(id.key.toString())
|
||||
.orElseThrow(() -> new IllegalArgumentException(String
|
||||
.format("No task comments with uuid %s in the " +
|
||||
"database.", id.key.toString())));
|
||||
}
|
||||
|
||||
@Override
|
||||
public ObjectIdResolver newForDeserialization(Object context) {
|
||||
return new TaskCommentIdResolver();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canUseFor(ObjectIdResolver resolverType) {
|
||||
return resolverType instanceof TaskCommentIdResolver;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,47 @@
|
|||
/*
|
||||
* Copyright (C) 2015 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.libreccm.workflow;
|
||||
|
||||
import org.libreccm.portation.AbstractMarshaller;
|
||||
import org.libreccm.portation.Marshals;
|
||||
|
||||
import javax.enterprise.context.RequestScoped;
|
||||
import javax.inject.Inject;
|
||||
|
||||
/**
|
||||
* @author <a href="mailto:tosmers@uni-bremen.de>Tobias Osmers<\a>
|
||||
* @version created the 9/27/17
|
||||
*/
|
||||
@RequestScoped
|
||||
@Marshals(TaskComment.class)
|
||||
public class TaskCommentMarshaller extends AbstractMarshaller<TaskComment> {
|
||||
|
||||
@Inject
|
||||
private TaskCommentRepository taskCommentRepository;
|
||||
|
||||
@Override
|
||||
protected Class<TaskComment> getObjectClass() {
|
||||
return TaskComment.class;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void insertIntoDb(TaskComment portableObject) {
|
||||
taskCommentRepository.save(portableObject);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,63 @@
|
|||
/*
|
||||
* Copyright (C) 2015 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.libreccm.workflow;
|
||||
|
||||
import org.libreccm.core.AbstractEntityRepository;
|
||||
|
||||
import javax.enterprise.context.RequestScoped;
|
||||
import javax.persistence.NoResultException;
|
||||
import javax.persistence.TypedQuery;
|
||||
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> {
|
||||
@Override
|
||||
public Class<TaskComment> getEntityClass() {
|
||||
return TaskComment.class;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isNew(TaskComment entity) {
|
||||
return entity.getCommentId() == 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Finds a {@link TaskComment} by its uuid.
|
||||
*
|
||||
* @param uuid The uuid of the item to find
|
||||
*
|
||||
* @return An optional either with the found item or empty
|
||||
*/
|
||||
public Optional<TaskComment> findByUuid(final String uuid) {
|
||||
final TypedQuery<TaskComment> query = getEntityManager()
|
||||
.createNamedQuery("TaskComment.findByUuid", TaskComment.class);
|
||||
query.setParameter("uuid", uuid);
|
||||
|
||||
try {
|
||||
return Optional.of(query.getSingleResult());
|
||||
} catch (NoResultException ex) {
|
||||
return Optional.empty();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -19,6 +19,7 @@
|
|||
package org.libreccm.workflow;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonIdentityInfo;
|
||||
import com.fasterxml.jackson.annotation.JsonIdentityReference;
|
||||
import com.fasterxml.jackson.annotation.JsonIgnore;
|
||||
import com.fasterxml.jackson.annotation.ObjectIdGenerators;
|
||||
import org.libreccm.core.CcmObject;
|
||||
|
|
@ -48,12 +49,12 @@ import static org.libreccm.core.CoreConstants.DB_SCHEMA;
|
|||
@NamedQueries({
|
||||
@NamedQuery(
|
||||
name = "Workflow.findByUuid",
|
||||
query = "SELECT W FROM Workflow w WHERE w.uuid = :uuid")
|
||||
query = "SELECT w FROM Workflow w WHERE w.uuid = :uuid")
|
||||
,
|
||||
@NamedQuery(
|
||||
name = "Workflow.findForObject",
|
||||
query = "SELECT w FROM Workflow w "
|
||||
+ "WHERE W.object = :object")
|
||||
+ "WHERE w.object = :object")
|
||||
})
|
||||
@JsonIdentityInfo(generator = ObjectIdGenerators.PropertyGenerator.class,
|
||||
resolver = WorkflowIdResolver.class,
|
||||
|
|
@ -82,6 +83,7 @@ public class Workflow implements Identifiable, Serializable, Portable {
|
|||
*/
|
||||
@ManyToOne
|
||||
@JoinColumn(name = "TEMPLATE_ID")
|
||||
@JsonIdentityReference(alwaysAsId = true)
|
||||
private WorkflowTemplate template;
|
||||
|
||||
/**
|
||||
|
|
@ -136,6 +138,7 @@ public class Workflow implements Identifiable, Serializable, Portable {
|
|||
*/
|
||||
@OneToOne
|
||||
@JoinColumn(name = "OBJECT_ID")
|
||||
@JsonIdentityReference(alwaysAsId = true)
|
||||
private CcmObject object;
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -43,7 +43,8 @@ import static org.libreccm.core.CoreConstants.DB_SCHEMA;
|
|||
@NamedQueries({
|
||||
@NamedQuery(
|
||||
name = "WorkflowTemplate.findByUuid",
|
||||
query = "SELECT T FROM WorkflowTemplate t WHERE t.uuid = :uuid")
|
||||
query = "SELECT t FROM WorkflowTemplate t " +
|
||||
"WHERE t.uuid = :uuid")
|
||||
})
|
||||
@JsonIdentityInfo(generator = ObjectIdGenerators.PropertyGenerator.class,
|
||||
resolver = WorkflowTemplateIdResolver.class,
|
||||
|
|
|
|||
|
|
@ -38,16 +38,16 @@ public class WorkflowTemplateIdResolver implements ObjectIdResolver {
|
|||
}
|
||||
|
||||
@Override
|
||||
public Object resolveId(ObjectIdGenerator.IdKey idKey) {
|
||||
public Object resolveId(ObjectIdGenerator.IdKey id) {
|
||||
final CdiUtil cdiUtil = CdiUtil.createCdiUtil();
|
||||
final WorkflowTemplateRepository workflowTemplateRepository = cdiUtil
|
||||
.findBean(WorkflowTemplateRepository.class);
|
||||
|
||||
return workflowTemplateRepository
|
||||
.findByUuid(idKey.toString())
|
||||
.findByUuid(id.key.toString())
|
||||
.orElseThrow(() -> new IllegalArgumentException(String
|
||||
.format("No workflow templates with uuid %s in the " +
|
||||
"database.", idKey.toString())));
|
||||
"database.", id.key.toString())));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
|||
|
|
@ -127,24 +127,14 @@ public class CoreDataImportTest {
|
|||
|
||||
@Test
|
||||
@InSequence(100)
|
||||
public void objectsShouldBeImported() throws InterruptedException {
|
||||
public void objectsShouldBeImported() {
|
||||
// assert for no errors
|
||||
Assert.assertFalse(importHelper.importUsers());
|
||||
Assert.assertFalse(importHelper.importGroups());
|
||||
Assert.assertFalse(importHelper.importGroupMemberships());
|
||||
|
||||
Assert.assertFalse(importHelper.importRoles());
|
||||
Assert.assertFalse(importHelper.importRoleMemberships());
|
||||
|
||||
|
||||
/*final String name = "research_Administration_Publisher";
|
||||
Group group = groupRepository
|
||||
.findByName(name)
|
||||
.orElseThrow(() -> new IllegalArgumentException(String
|
||||
.format("No Group fount with the name: %s", name)));
|
||||
System.err.println(group.toString());*/
|
||||
|
||||
|
||||
Assert.assertFalse(importHelper.importCategories());
|
||||
Assert.assertFalse(importHelper.importCategorizations());
|
||||
Assert.assertFalse(importHelper.importResourceTypes());
|
||||
|
|
@ -155,9 +145,10 @@ public class CoreDataImportTest {
|
|||
Assert.assertFalse(importHelper.importPermissions());
|
||||
|
||||
Assert.assertFalse(importHelper.importWorkflowTemplates());
|
||||
//Assert.assertFalse(importHelper.importWorkflows());
|
||||
|
||||
|
||||
Assert.assertFalse(importHelper.importWorkflows());
|
||||
Assert.assertFalse(importHelper.importTaskComments());
|
||||
//Assert.assertFalse(importHelper.importAssignableTasks());
|
||||
//Assert.assertFalse(importHelper.importTaskAssignments());
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -79,6 +79,10 @@ class ImportHelper {
|
|||
@Marshals(DomainOwnership.class)
|
||||
private DomainOwnershipMarshaller domainOwnershipMarshaller;
|
||||
|
||||
@Inject
|
||||
@Marshals(Permission.class)
|
||||
private PermissionMarshaller permissionMarshaller;
|
||||
|
||||
@Inject
|
||||
@Marshals(WorkflowTemplate.class)
|
||||
private WorkflowTemplateMarshaller workflowTemplateMarshaller;
|
||||
|
|
@ -86,15 +90,15 @@ class ImportHelper {
|
|||
@Marshals(Workflow.class)
|
||||
private WorkflowMarshaller workflowMarshaller;
|
||||
@Inject
|
||||
@Marshals(TaskComment.class)
|
||||
private TaskCommentMarshaller taskCommentMarshaller;
|
||||
@Inject
|
||||
@Marshals(AssignableTask.class)
|
||||
private AssignableTaskMarshaller assignableTaskMarshaller;
|
||||
@Inject
|
||||
@Marshals(TaskAssignment.class)
|
||||
private TaskAssignmentMarshaller taskAssignmentMarshaller;
|
||||
|
||||
@Inject
|
||||
@Marshals(Permission.class)
|
||||
private PermissionMarshaller permissionMarshaller;
|
||||
|
||||
|
||||
boolean importUsers() {
|
||||
|
|
@ -223,6 +227,15 @@ class ImportHelper {
|
|||
return workflowMarshaller.importFile();
|
||||
}
|
||||
|
||||
boolean importTaskComments() {
|
||||
taskCommentMarshaller.prepare(
|
||||
Format.XML,
|
||||
repoPath + projectPath,
|
||||
"taskComments.xml",
|
||||
indentation);
|
||||
return taskCommentMarshaller.importFile();
|
||||
}
|
||||
|
||||
boolean importAssignableTasks() {
|
||||
assignableTaskMarshaller.prepare(
|
||||
Format.XML,
|
||||
|
|
|
|||
Loading…
Reference in New Issue