[NG][FEATURE]

- adds capability to import assignable tasks
- adds IdGenerator and Marshaller for TaskDependency
- import of TaskDependencies not working yet

git-svn-id: https://svn.libreccm.org/ccm/ccm_ng@5166 8810af33-2d31-482b-a856-94f89814c4df
ccm-docs
tosmers 2017-12-12 18:04:27 +00:00
parent 03effcb3bd
commit 439efa2e73
8 changed files with 184 additions and 92 deletions

View File

@ -18,20 +18,23 @@
*/
package org.libreccm.l10n;
import static org.libreccm.l10n.L10NConstants.*;
import com.fasterxml.jackson.annotation.JsonIgnore;
import org.hibernate.annotations.Type;
import org.hibernate.search.annotations.Field;
import org.libreccm.l10n.jaxb.LocalizedStringValuesAdapter;
import javax.persistence.Basic;
import javax.persistence.Column;
import javax.persistence.ElementCollection;
import javax.persistence.Embeddable;
import javax.persistence.FetchType;
import javax.persistence.Lob;
import javax.persistence.MapKeyColumn;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter;
import java.io.Serializable;
import java.util.Collections;
import java.util.HashMap;
@ -40,11 +43,7 @@ import java.util.Map;
import java.util.Objects;
import java.util.Set;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter;
import static org.libreccm.l10n.L10NConstants.L10N_XML_NS;
/**
* A helper class for localisable string properties. This class is declared as
@ -67,6 +66,7 @@ public class LocalizedString implements Serializable {
@ElementCollection(fetch = FetchType.EAGER)
@MapKeyColumn(name = "LOCALE")
@Column(name = "LOCALIZED_VALUE")
@Basic
@Lob
@Type(type = "org.hibernate.type.TextType")
@Field

View File

@ -18,12 +18,10 @@
*/
package org.libreccm.portation;
import com.fasterxml.jackson.databind.DeserializationFeature;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.SerializationFeature;
import com.fasterxml.jackson.dataformat.xml.JacksonXmlModule;
import com.fasterxml.jackson.dataformat.xml.XmlMapper;
import com.fasterxml.jackson.module.jaxb.JaxbAnnotationModule;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

View File

@ -20,6 +20,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;
import org.libreccm.core.Identifiable;
@ -188,34 +189,25 @@ public class Task implements Identifiable, Serializable {
@JsonIdentityReference(alwaysAsId = true)
private Workflow workflow;
// /**
// * Tasks which depend on this task.
// */
// @ManyToMany(mappedBy = "dependsOn", fetch = FetchType.LAZY)
// @JsonIgnore
// private List<Task> dependentTasks;
/**
* Tasks which depend on this task.
*/
@OneToMany(mappedBy = "blockingTask", fetch = FetchType.LAZY)
@XmlElementWrapper(name = "blocked-tasks")
@XmlElement(name = "task-dependency")
@JsonIgnore
private List<TaskDependency> blockedTasks;
/**
* The dependencies of this task.
*/
@OneToMany(mappedBy = "blockedTask", fetch = FetchType.LAZY)
@XmlElementWrapper(name = "blocking-tasks")
@XmlElement(name = "task-dependency")
@JsonIgnore
private List<TaskDependency> blockingTasks;
// /**
// * The dependencies of this task.
// */
// @ManyToMany(fetch = FetchType.LAZY)
// @JoinTable(name = "WORKFLOW_TASK_DEPENDENCIES",
// schema = DB_SCHEMA,
// joinColumns = {
// @JoinColumn(name = "DEPENDS_ON_TASK_ID")},
// inverseJoinColumns = {
// @JoinColumn(name = "DEPENDENT_TASK_ID")})
// @JsonIdentityReference(alwaysAsId = true)
// private List<Task> dependsOn;
/**
* Comments for the task.
*/
@ -229,8 +221,6 @@ public class Task implements Identifiable, Serializable {
label = new LocalizedString();
description = new LocalizedString();
// dependentTasks = new ArrayList<>();
// dependsOn = new ArrayList<>();
blockedTasks = new ArrayList<>();
blockingTasks = new ArrayList<>();
comments = new ArrayList<>();
@ -296,65 +286,6 @@ public class Task implements Identifiable, Serializable {
this.workflow = workflow;
}
// public List<Task> getDependentTasks() {
// if (dependentTasks == null) {
// return null;
// } else {
// return Collections.unmodifiableList(dependentTasks);
// }
// }
//
// protected void setDependentTasks(final List<Task> dependentTasks) {
// this.dependentTasks = dependentTasks;
// }
//
// protected void addDependentTask(final Task task) {
// dependentTasks.add(task);
// }
//
// protected void removeDependentTask(final Task task) {
// dependentTasks.remove(task);
// }
//
// public List<Task> getDependsOn() {
// if (dependsOn == null) {
// return null;
// } else {
// return Collections.unmodifiableList(dependsOn);
// }
// }
//
// protected void setDependsOn(final List<Task> dependsOn) {
// this.dependsOn = dependsOn;
// }
//
// protected void addDependsOn(final Task task) {
// dependsOn.add(task);
// }
//
// protected void removeDependsOn(final Task task) {
// dependsOn.remove(task);
// }
public List<TaskDependency> getBlockingTasks() {
if (blockingTasks == null) {
return null;
} else {
return Collections.unmodifiableList(blockingTasks);
}
}
protected void setBlockingTasks(final List<TaskDependency> blockingTasks) {
this.blockingTasks = blockingTasks;
}
protected void addBlockingTask(final TaskDependency taskDependency) {
blockingTasks.add(taskDependency);
}
protected void removeBlockingTask(final TaskDependency taskDependency) {
blockingTasks.remove(taskDependency);
}
public List<TaskDependency> getBlockedTasks() {
if (blockedTasks == null) {
return null;
@ -375,6 +306,26 @@ public class Task implements Identifiable, Serializable {
blockedTasks.remove(taskDependency);
}
public List<TaskDependency> getBlockingTasks() {
if (blockingTasks == null) {
return null;
} else {
return Collections.unmodifiableList(blockingTasks);
}
}
protected void setBlockingTasks(final List<TaskDependency> blockingTasks) {
this.blockingTasks = blockingTasks;
}
protected void addBlockingTask(final TaskDependency taskDependency) {
blockingTasks.add(taskDependency);
}
protected void removeBlockingTask(final TaskDependency taskDependency) {
blockingTasks.remove(taskDependency);
}
public List<TaskComment> getComments() {
if (comments == null) {
return null;

View File

@ -18,8 +18,10 @@
*/
package org.libreccm.workflow;
import com.fasterxml.jackson.annotation.JsonIdentityInfo;
import com.fasterxml.jackson.annotation.JsonIdentityReference;
import org.libreccm.core.CoreConstants;
import org.libreccm.portation.Portable;
import java.io.Serializable;
import java.util.Objects;
@ -39,7 +41,9 @@ import javax.persistence.Table;
*/
@Entity
@Table(name = "WORKFLOW_TASK_DEPENDENCIES", schema = CoreConstants.DB_SCHEMA)
public class TaskDependency implements Serializable {
@JsonIdentityInfo(generator = TaskDependencyIdGenerator.class,
property = "customDepId")
public class TaskDependency implements Serializable, Portable {
private static final long serialVersionUID = -4383255770131633943L;

View File

@ -0,0 +1,69 @@
/*
* 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;
/**
* @author <a href="mailto:tosmers@uni-bremen.de>Tobias Osmers<\a>
* @version created the 12/12/17
*/
public class TaskDependencyIdGenerator extends ObjectIdGenerator<String> {
@Override
public Class<?> getScope() {
return TaskDependency.class;
}
@Override
public boolean canUseFor(ObjectIdGenerator<?> gen) {
return gen instanceof TaskDependencyIdGenerator;
}
@Override
public ObjectIdGenerator<String> forScope(Class<?> scope) {
return this;
}
@Override
public ObjectIdGenerator<String> newForSerialization(Object context) {
return this;
}
@Override
public IdKey key(Object key) {
if (key == null) {
return null;
}
return new IdKey(TaskDependency.class, TaskDependency.class, key);
}
@Override
public String generateId(Object forPojo) {
if (!(forPojo instanceof TaskDependency)) {
throw new IllegalArgumentException(
"Only TaskDependency instances are supported.");
}
final TaskDependency dependency = (TaskDependency) forPojo;
return String.format("{%s}{%s}",
dependency.getBlockedTask().getUuid(),
dependency.getBlockingTask().getUuid());
}
}

View File

@ -0,0 +1,54 @@
/*
* 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;
import javax.persistence.EntityManager;
import javax.transaction.Transactional;
/**
* @author <a href="mailto:tosmers@uni-bremen.de>Tobias Osmers<\a>
* @version created the 12/12/17
*/
@RequestScoped
@Marshals(TaskDependency.class)
public class TaskDependencyMarshaller extends AbstractMarshaller<TaskDependency> {
@Inject
private EntityManager entityManager;
@Override
protected Class<TaskDependency> getObjectClass() {
return TaskDependency.class;
}
@Override
@Transactional(Transactional.TxType.REQUIRED)
protected void insertIntoDb(TaskDependency portableObject) {
portableObject.setTaskDependencyId(portableObject
.getTaskDependencyId() * -1);
entityManager.merge(portableObject);
entityManager.flush();
}
}

View File

@ -154,6 +154,7 @@ public class CoreDataImportTest {
Assert.assertFalse(importHelper.importWorkflows());
Assert.assertFalse(importHelper.importTaskComments());
Assert.assertFalse(importHelper.importAssignableTasks());
// Assert.assertFalse(importHelper.importTaskDependencies());
// Assert.assertFalse(importHelper.importTaskAssignments());
}

View File

@ -49,6 +49,8 @@ import org.libreccm.workflow.TaskAssignment;
import org.libreccm.workflow.TaskAssignmentMarshaller;
import org.libreccm.workflow.TaskComment;
import org.libreccm.workflow.TaskCommentMarshaller;
import org.libreccm.workflow.TaskDependency;
import org.libreccm.workflow.TaskDependencyMarshaller;
import org.libreccm.workflow.Workflow;
import org.libreccm.workflow.WorkflowMarshaller;
@ -65,8 +67,8 @@ import javax.inject.Inject;
@RequestScoped
class ImportHelper {
private String repoPath = "/home/jensp/pwi/libreccm/ccm/";
// private final String repoPath = "/home/tosmers/Svn/libreccm/";
//private String repoPath = "/home/jensp/pwi/libreccm/ccm/";
private final String repoPath = "/home/tosmers/Svn/libreccm/";
private final String projectPath = "ccm_ng/ccm-core/src/test/resources/" +
"portation/trunk-iaw-exports";
private final boolean indentation = false;
@ -130,6 +132,10 @@ class ImportHelper {
@Inject
@Marshals(AssignableTask.class)
private AssignableTaskMarshaller assignableTaskMarshaller;
@Inject
@Marshals(TaskDependency.class)
private TaskDependencyMarshaller taskDependencyMarshaller;
@Inject
@Marshals(TaskAssignment.class)
@ -273,6 +279,15 @@ class ImportHelper {
return assignableTaskMarshaller.importFile();
}
boolean importTaskDependencies() {
taskDependencyMarshaller.prepare(
Format.XML,
repoPath + projectPath,
"taskDependencies.xml",
indentation);
return taskDependencyMarshaller.importFile();
}
boolean importTaskAssignments() {
taskAssignmentMarshaller.prepare(
Format.XML,