Skip to content
This repository has been archived by the owner on Feb 9, 2018. It is now read-only.

Commit

Permalink
decision buttons new style
Browse files Browse the repository at this point in the history
  • Loading branch information
tombaeyens committed Mar 13, 2015
1 parent 7f0b3dd commit 4f9ef1e
Show file tree
Hide file tree
Showing 10 changed files with 49 additions and 69 deletions.
Expand Up @@ -15,7 +15,6 @@
*/
package com.effektif.workflow.api.form;

import com.effektif.workflow.api.types.ChoiceType;



Expand All @@ -26,14 +25,12 @@ public class AbstractForm {

protected String description;
// TODO Map<String,String> descriptionI18n;
protected ChoiceType decisionButtons;

public AbstractForm() {
}
/** shallow copy constructor */
public AbstractForm(AbstractForm other) {
this.description = other.description;
this.decisionButtons = other.decisionButtons;
}

public String getDescription() {
Expand All @@ -46,28 +43,4 @@ public AbstractForm description(String description) {
this.description = description;
return this;
}

public ChoiceType getDecisionButtons() {
return this.decisionButtons;
}
public void setDecisionButtons(ChoiceType decisionButtons) {
this.decisionButtons = decisionButtons;
}
/** optional variable declaration defining decision buttons
* that will be rendered instead of the form-submit or task-completion button.
* When specifying this, you must also specify the the decisionVariableId */
public AbstractForm decisionButtons(ChoiceType decisionButtons) {
this.decisionButtons = decisionButtons;
return this;
}
/** adds a button to this form (requires you also set a {@link #decisionVariableId(String)} ).
* A default "Done" or "Submit" button will always be on this form. The decision
* buttons are intended to be used in combination with exclusive gateway conditions. */
public AbstractForm decisionButton(String decisionOption) {
if (decisionButtons==null) {
decisionButtons = new ChoiceType();
}
decisionButtons.option(decisionOption);
return this;
}
}
Expand Up @@ -15,13 +15,22 @@
*/
package com.effektif.workflow.api.form;

import java.util.Arrays;
import java.util.HashSet;
import java.util.Set;

import com.effektif.workflow.api.types.Type;
import com.effektif.workflow.api.workflow.Extensible;


/**
* @author Tom Baeyens
*/
public class AbstractFormField {
public class AbstractFormField extends Extensible {

public static final Set<String> INVALID_PROPERTY_KEYS = new HashSet<>(Arrays.asList(
"id", "name", "readOnly", "required", "properties"));


protected String id;

Expand Down Expand Up @@ -108,4 +117,9 @@ public Type getType() {
public void setType(Type type) {
this.type = type;
}

@Override
protected void checkPropertyKey(String key) {
checkPropertyKey(key, INVALID_PROPERTY_KEYS);
}
}
Expand Up @@ -18,8 +18,6 @@
import java.util.ArrayList;
import java.util.List;

import com.effektif.workflow.api.types.ChoiceType;


/**
* A form definition (aka declaration) that specifies the fields to display for
Expand All @@ -32,7 +30,6 @@
public class Form extends AbstractForm {

protected List<FormField> fields;
protected String decisionVariableId;

public List<FormField> getFields() {
return this.fields;
Expand All @@ -57,31 +54,4 @@ public Form description(String description) {
super.description(description);
return this;
}

public String getDecisionVariableId() {
return this.decisionVariableId;
}
public void setDecisionVariableId(String decisionVariableId) {
this.decisionVariableId = decisionVariableId;
}
/** specifies the variableId where the decision is stored when you want to
* use decision buttons. Only use this if you don't want the default "Done" or
* "Submit" button. The decision buttons are intended to be used in combination
* with exclusive gateway conditions. */
public Form decisionVariableId(String decisionVariableId) {
this.decisionVariableId = decisionVariableId;
return this;
}

@Override
public Form decisionButtons(ChoiceType decisionButtons) {
super.decisionButtons(decisionButtons);
return this;
}

@Override
public Form decisionButton(String decisionOption) {
super.decisionButton(decisionOption);
return this;
}
}
Expand Up @@ -69,4 +69,14 @@ public FormField required() {
super.required();
return this;
}
@Override
public FormField property(String key, Object value) {
super.property(key, value);
return this;
}
@Override
public FormField propertyOpt(String key, Object value) {
super.propertyOpt(key, value);
return this;
}
}
Expand Up @@ -379,10 +379,9 @@ public Task propertyOpt(String key, Object value) {
return this;
}

@Override
protected void checkPropertyKey(String key) {
if (key==null || INVALID_PROPERTY_KEYS.contains(key)) {
throw new RuntimeException("Invalid property '"+key+"'");
}
checkPropertyKey(key, INVALID_PROPERTY_KEYS);
}

public AccessControlList getAccess() {
Expand Down
Expand Up @@ -30,7 +30,7 @@
public class Element extends Extensible {

public static final Set<String> INVALID_PROPERTY_KEYS = new HashSet<>(Arrays.asList(
"id", "name", "description", "bpmn"));
"name", "description", "bpmn"));

protected String name;
protected String description;
Expand Down Expand Up @@ -75,9 +75,8 @@ public void setBpmn(XmlElement bpmn) {
this.bpmn = bpmn;
}

@Override
protected void checkPropertyKey(String key) {
if (key==null || INVALID_PROPERTY_KEYS.contains(key)) {
throw new RuntimeException("Invalid property '"+key+"'");
}
checkPropertyKey(key, INVALID_PROPERTY_KEYS);
}
}
Expand Up @@ -15,6 +15,7 @@

import java.util.HashMap;
import java.util.Map;
import java.util.Set;

import com.fasterxml.jackson.annotation.JsonAnyGetter;
import com.fasterxml.jackson.annotation.JsonAnySetter;
Expand Down Expand Up @@ -91,4 +92,11 @@ public Object removeProperty(String key) {
* serialized inside the containing object json.
* @see Extensible */
protected abstract void checkPropertyKey(String key);

/** convenience method to be use din checkPropertyKey implementations */
protected void checkPropertyKey(String key, Set<String> invalidPropertyKeys) {
if (key==null || invalidPropertyKeys.contains(key)) {
throw new RuntimeException("Invalid property '"+key+"'");
}
}
}
Expand Up @@ -135,6 +135,7 @@ public void execute(ActivityInstanceImpl activityInstance) {
task.setDescription(activity.getDescription());
task.setAssigneeId(assignee);
task.setCandidateIds(candidates);
task.setActivityNotify(true);
task.setActivityId(activity.getId());
task.setActivityInstanceId(activityInstance.id);
task.setWorkflowInstanceId(activityInstance.workflowInstance.id);
Expand Down
Expand Up @@ -15,7 +15,7 @@
*/
package com.effektif.workflow.test.api;

import static org.junit.Assert.*;
import static org.junit.Assert.assertNotNull;

import org.junit.Test;

Expand All @@ -27,6 +27,7 @@
import com.effektif.workflow.api.form.FormField;
import com.effektif.workflow.api.form.FormInstance;
import com.effektif.workflow.api.task.Task;
import com.effektif.workflow.api.types.ChoiceType;
import com.effektif.workflow.api.types.TextType;
import com.effektif.workflow.api.workflow.Workflow;
import com.effektif.workflow.api.workflowinstance.ActivityInstance;
Expand All @@ -43,6 +44,10 @@ public class DecisionButtonsTest extends WorkflowTest {
public void testExclusiveGateway() {
Workflow workflow = new Workflow()
.variable("Conclusion", new TextType())
.variable("Decision", new ChoiceType()
.option("Approve")
.option("Reject")
)
.activity("Start", new StartEvent()
.transitionToNext())
.activity("Submit conclusion", new UserTask()
Expand All @@ -54,9 +59,10 @@ public void testExclusiveGateway() {
.field(new FormField()
.binding("Conclusion")
.readOnly())
.decisionVariableId("Decision")
.decisionButton("Approve")
.decisionButton("Reject"))
.field(new FormField()
.binding("Decision")
.required()
.property("asButtons", true)))
.transitionToNext())
.activity("Approved?", new ExclusiveGateway()
.transitionWithConditionTo("Conclusion == 'Reject'", "Submit conclusion")
Expand Down
Binary file removed files/README-diagram.png
Binary file not shown.

0 comments on commit 4f9ef1e

Please sign in to comment.