提交 88d3cc6c 编写于 作者: T tijsrademakers

Cleaned up simple workflow model

上级 2eb709ca
......@@ -14,10 +14,6 @@
</parent>
<dependencies>
<dependency>
<groupId>org.activiti</groupId>
<artifactId>activiti-engine</artifactId>
</dependency>
<!-- BPMN model conversion -->
<dependency>
<groupId>org.activiti</groupId>
......@@ -60,6 +56,11 @@
<artifactId>junit</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.activiti</groupId>
<artifactId>activiti-engine</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
......
......@@ -12,7 +12,6 @@
*/
package org.activiti.workflow.simple.converter;
import java.io.InputStream;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
......@@ -21,12 +20,11 @@ import org.activiti.bpmn.BpmnAutoLayout;
import org.activiti.bpmn.converter.BpmnXMLConverter;
import org.activiti.bpmn.model.BpmnModel;
import org.activiti.bpmn.model.Process;
import org.activiti.engine.ActivitiException;
import org.activiti.engine.impl.bpmn.diagram.ProcessDiagramGenerator;
import org.activiti.workflow.simple.converter.listener.WorkflowDefinitionConversionListener;
import org.activiti.workflow.simple.converter.step.StepDefinitionConverter;
import org.activiti.workflow.simple.definition.StepDefinition;
import org.activiti.workflow.simple.definition.WorkflowDefinition;
import org.activiti.workflow.simple.exception.SimpleWorkflowException;
/**
* Instances of this class are created by a {@link WorkflowDefinitionConversionFactory}.
......@@ -81,7 +79,7 @@ public class WorkflowDefinitionConversion {
public void convert() {
if (workflowDefinition == null) {
throw new ActivitiException("Cannot start conversion: need to set a WorkflowDefinition first!");
throw new SimpleWorkflowException("Cannot start conversion: need to set a WorkflowDefinition first!");
}
this.incrementalIdMapping = new HashMap<String, Integer>();
......@@ -210,23 +208,11 @@ public class WorkflowDefinitionConversion {
* Returns the BPMN 2.0 xml which is the converted version of the
* provided {@link WorkflowDefinition}.
*/
public String getbpm20Xml() {
public String getBpmn20Xml() {
if (bpmnModel == null) {
convert();
}
BpmnXMLConverter bpmnXMLConverter = new BpmnXMLConverter();
return new String(bpmnXMLConverter.convertToXML(bpmnModel));
}
/**
* Returns the BPMN 2.0 diagram which is the converted version of the
* provided {@link WorkflowDefinition}.
*/
public InputStream getWorkflowDiagramImage() {
if (bpmnModel == null) {
convert();
}
return ProcessDiagramGenerator.generatePngDiagram(bpmnModel);
}
}
......@@ -12,12 +12,10 @@
*/
package org.activiti.workflow.simple.converter.json;
import java.io.IOException;
import java.io.InputStream;
import java.io.Writer;
import java.util.List;
import org.activiti.engine.ActivitiException;
import org.activiti.workflow.simple.definition.FeedbackStepDefinition;
import org.activiti.workflow.simple.definition.HumanStepDefinition;
import org.activiti.workflow.simple.definition.ParallelStepsDefinition;
......@@ -28,8 +26,7 @@ import org.activiti.workflow.simple.definition.form.ListPropertyDefinition;
import org.activiti.workflow.simple.definition.form.NumberPropertyDefinition;
import org.activiti.workflow.simple.definition.form.ReferencePropertyDefinition;
import org.activiti.workflow.simple.definition.form.TextPropertyDefinition;
import org.codehaus.jackson.JsonParseException;
import org.codehaus.jackson.map.JsonMappingException;
import org.activiti.workflow.simple.exception.SimpleWorkflowException;
import org.codehaus.jackson.map.ObjectMapper;
/**
......@@ -50,14 +47,10 @@ public class SimpleWorkflowJsonConverter {
* @return The workflow definition instance, read from the given input-stream.
* @throws ActivitiException when an error occurs while reading or parsing the definition.
*/
public WorkflowDefinition readWorkflowDefinition(InputStream inputStream) throws ActivitiException {
public WorkflowDefinition readWorkflowDefinition(InputStream inputStream) throws SimpleWorkflowException {
try {
return getObjectMapper().readValue(inputStream, WorkflowDefinition.class);
} catch (JsonParseException e) {
throw wrapExceptionRead(e);
} catch (JsonMappingException e) {
throw wrapExceptionRead(e);
} catch (IOException e) {
} catch (Exception e) {
throw wrapExceptionRead(e);
}
}
......@@ -67,14 +60,10 @@ public class SimpleWorkflowJsonConverter {
* @return The workflow definition instance, parsed from the given array.
* @throws ActivitiException when an error occurs while parsing the definition.
*/
public WorkflowDefinition readWorkflowDefinition(byte[] bytes) throws ActivitiException {
public WorkflowDefinition readWorkflowDefinition(byte[] bytes) throws SimpleWorkflowException {
try {
return getObjectMapper().readValue(bytes, WorkflowDefinition.class);
} catch (JsonParseException e) {
throw wrapExceptionRead(e);
} catch (JsonMappingException e) {
throw wrapExceptionRead(e);
} catch (IOException e) {
} catch (Exception e) {
throw wrapExceptionRead(e);
}
}
......@@ -82,11 +71,7 @@ public class SimpleWorkflowJsonConverter {
public void writeWorkflowDefinition(WorkflowDefinition definition, Writer writer) {
try {
getObjectMapper().writeValue(writer, definition);
} catch (JsonParseException e) {
throw wrapExceptionWrite(e);
} catch (JsonMappingException e) {
throw wrapExceptionWrite(e);
} catch (IOException e) {
} catch (Exception e) {
throw wrapExceptionWrite(e);
}
}
......@@ -95,16 +80,16 @@ public class SimpleWorkflowJsonConverter {
* @param e exception to wrap
* @return an {@link ActivitiException} to throw, wrapping the given exception.
*/
protected ActivitiException wrapExceptionRead(Exception e) {
return new ActivitiException("Error while parsing JSON", e);
protected SimpleWorkflowException wrapExceptionRead(Exception e) {
return new SimpleWorkflowException("Error while parsing JSON", e);
}
/**
* @param e exception to wrap
* @return an {@link ActivitiException} to throw, wrapping the given exception.
*/
protected ActivitiException wrapExceptionWrite(Exception e) {
return new ActivitiException("Error while writing JSON", e);
protected SimpleWorkflowException wrapExceptionWrite(Exception e) {
return new SimpleWorkflowException("Error while writing JSON", e);
}
protected ObjectMapper getObjectMapper() {
......
......@@ -21,10 +21,19 @@ public abstract class AbstractNamedStepDefinition implements StepDefinition {
private static final long serialVersionUID = 1L;
protected String id;
protected String name;
protected String description;
protected boolean startsWithPrevious;
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public String getName() {
return name;
}
......
......@@ -26,12 +26,21 @@ public abstract class AbstractStepDefinitionContainer<T> implements StepDefiniti
private static final long serialVersionUID = 1L;
protected String id;
protected List<StepDefinition> steps;
public AbstractStepDefinitionContainer() {
this.steps = new ArrayList<StepDefinition>();
}
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public void addStep(StepDefinition stepDefinition) {
steps.add(stepDefinition);
}
......@@ -43,12 +52,20 @@ public abstract class AbstractStepDefinitionContainer<T> implements StepDefiniti
// Human step
public T addHumanStep(String id, String name, String assignee) {
return (T) addHumanStep(id, name, assignee, false);
}
public T addHumanStep(String name, String assignee) {
return (T) addHumanStep(name, assignee, false);
return (T) addHumanStep(null, name, assignee, false);
}
public T addHumanStepForWorkflowInitiator(String id, String name) {
return (T) addHumanStep(id, name, null, true);
}
public T addHumanStepForWorkflowInitiator(String name) {
return (T) addHumanStep(name, null, true);
return (T) addHumanStep(null, name, null, true);
}
public T addHumanStepForGroup(String name, List<String> groups) {
......@@ -57,11 +74,17 @@ public abstract class AbstractStepDefinitionContainer<T> implements StepDefiniti
return (T) this;
}
public T addHumanStepForGroup(String id, String name, List<String> groups) {
HumanStepDefinition humanStepDefinition = createHumanStepDefinition(name);
humanStepDefinition.setCandidateGroups(groups);
return (T) this;
}
public T addHumanStepForGroup(String name, String...groups) {
return addHumanStepForGroup(name, Arrays.asList(groups));
}
protected T addHumanStep(String name, String assignee, boolean initiator) {
protected T addHumanStep(String id, String name, String assignee, boolean initiator) {
createHumanStepDefinition(name, assignee, initiator);
return (T) this;
}
......@@ -75,17 +98,16 @@ public abstract class AbstractStepDefinitionContainer<T> implements StepDefiniti
}
protected HumanStepDefinition createHumanStepDefinition(String name, String assignee, boolean initiator) {
return createHumanStepDefinition(null, name, assignee, initiator);
}
protected HumanStepDefinition createHumanStepDefinition(String id, String name, String assignee, boolean initiator) {
HumanStepDefinition humanStepDefinition = new HumanStepDefinition();
if (name != null) {
humanStepDefinition.setName(name);
}
if (assignee != null) {
humanStepDefinition.setAssignee(assignee);
}
// TODO
// humanStepDefinition.setAssigneeIsInitiator(initiator);
humanStepDefinition.setId(id);
humanStepDefinition.setName(name);
humanStepDefinition.setAssignee(assignee);
// TODO
// humanStepDefinition.setAssigneeIsInitiator(initiator);
addStep(humanStepDefinition);
return humanStepDefinition;
......
......@@ -2,7 +2,7 @@ package org.activiti.workflow.simple.definition;
import java.util.List;
import org.activiti.engine.ActivitiIllegalArgumentException;
import org.activiti.workflow.simple.exception.SimpleWorkflowException;
import org.codehaus.jackson.annotate.JsonCreator;
import org.codehaus.jackson.annotate.JsonValue;
import org.codehaus.jackson.map.annotate.JsonSerialize;
......@@ -63,7 +63,7 @@ public class HumanStepAssignment {
}
}
throw new ActivitiIllegalArgumentException("Invalid assignment type for human step: " + name);
throw new SimpleWorkflowException("Invalid assignment type for human step: " + name);
}
}
......
......@@ -12,7 +12,7 @@
*/
package org.activiti.workflow.simple.definition;
import org.activiti.engine.ActivitiException;
import org.activiti.workflow.simple.exception.SimpleWorkflowException;
import org.codehaus.jackson.annotate.JsonTypeName;
/**
......@@ -37,7 +37,7 @@ public class ParallelStepsDefinition extends AbstractStepDefinitionContainer<Par
public WorkflowDefinition endParallel() {
if (workflowDefinition == null) {
throw new ActivitiException("Can only call endParallel when inParallel was called on a workflow definition first");
throw new SimpleWorkflowException("Can only call endParallel when inParallel was called on a workflow definition first");
}
return workflowDefinition;
}
......
......@@ -26,5 +26,7 @@ import org.codehaus.jackson.annotate.JsonTypeInfo.Id;
*/
@JsonTypeInfo(use=Id.NAME, include=As.PROPERTY, property="type")
public interface StepDefinition extends Serializable {
String getId();
void setId(String id);
}
......@@ -12,14 +12,13 @@
*/
package org.activiti.workflow.simple.definition;
import java.io.Serializable;
import java.util.List;
/**
* @author Joram Barrez
*/
public interface StepDefinitionContainer<T> extends Serializable {
public interface StepDefinitionContainer<T> extends StepDefinition {
List<StepDefinition> getSteps();
......
......@@ -15,7 +15,7 @@ package org.activiti.workflow.simple.definition.form;
import java.util.ArrayList;
import java.util.List;
import org.activiti.engine.ActivitiIllegalArgumentException;
import org.activiti.workflow.simple.exception.SimpleWorkflowException;
import org.codehaus.jackson.map.annotate.JsonSerialize;
/**
......@@ -52,7 +52,7 @@ public class FormPropertyGroup {
public FormPropertyGroup addFormPropertyDefinition(FormPropertyDefinition definition) {
if(definition == null) {
throw new ActivitiIllegalArgumentException("Definition to add cannot be null");
throw new SimpleWorkflowException("Definition to add cannot be null");
}
formPropertyDefinitions.add(definition);
......
package org.activiti.workflow.simple.exception;
/**
* Runtime exception that is the superclass of all Simple workflow exceptions.
*
* @author Tijs Rademakers
*/
public class SimpleWorkflowException extends RuntimeException {
private static final long serialVersionUID = 1L;
public SimpleWorkflowException(String message, Throwable cause) {
super(message, cause);
}
public SimpleWorkflowException(String message) {
super(message);
}
}
......@@ -311,7 +311,7 @@ public class WorkflowConversionTest {
WorkflowDefinitionConversion conversion = conversionFactory.createWorkflowDefinitionConversion(workflowDefinition);
conversion.convert();
log.info("Converted process : " + conversion.getbpm20Xml());
log.info("Converted process : " + conversion.getBpmn20Xml());
// InputStream is = conversion.getWorkflowDiagramImage();
// try {
......@@ -347,7 +347,7 @@ public class WorkflowConversionTest {
long nrOfDeployments = countNrOfDeployments();
activitiRule.getRepositoryService().createDeployment()
.addString(conversion.getProcess().getId() + ".bpmn20.xml", conversion.getbpm20Xml())
.addString(conversion.getProcess().getId() + ".bpmn20.xml", conversion.getBpmn20Xml())
.deploy();
assertEquals(nrOfDeployments + 1, countNrOfDeployments());
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册