use of org.activiti.workflow.simple.alfresco.form.AlfrescoTransitionsPropertyDefinition in project Activiti by Activiti.
the class AlfrescoFormCreator method createForm.
public void createForm(M2Type contentType, Form formConfig, FormDefinition formDefinition, WorkflowDefinitionConversion conversion) {
if (formDefinition != null && formDefinition.getFormGroups() != null) {
for (FormPropertyGroup group : formDefinition.getFormGroups()) {
// Create a group in the form-config
String groupId = null;
if (group.getId() != null) {
groupId = AlfrescoConversionUtil.getValidIdString(group.getId());
} else {
groupId = AlfrescoConversionUtil.getValidIdString(group.getTitle());
}
FormSet formSet = formConfig.getFormAppearance().addFormSet(groupId, getAppearanceForGroup(group), group.getTitle(), getTemplateForGroup(group));
// Convert all properties
AlfrescoFormPropertyConverter converter = null;
for (FormPropertyDefinition property : group.getFormPropertyDefinitions()) {
converter = propertyConverters.get(property.getClass());
if (converter == null) {
throw new AlfrescoSimpleWorkflowException("Unsupported property type: " + property.getClass().getName());
}
converter.convertProperty(contentType, formSet.getId(), formConfig, property, conversion);
}
}
}
if (formDefinition != null && formDefinition.getFormPropertyDefinitions() != null && !formDefinition.getFormPropertyDefinitions().isEmpty()) {
for (FormPropertyDefinition def : formDefinition.getFormPropertyDefinitions()) {
if (def instanceof AlfrescoTransitionsPropertyDefinition) {
AlfrescoFormPropertyConverter converter = propertyConverters.get(def.getClass());
if (converter != null) {
converter.convertProperty(contentType, null, formConfig, def, conversion);
}
}
}
}
// Finally, add default "transitions" if not already added to the model
if (formConfig.getFormAppearance().getFormSet(AlfrescoConversionConstants.FORM_SET_RESPONSE) == null) {
formConfig.getFormAppearance().addFormSet(AlfrescoConversionConstants.FORM_SET_RESPONSE, null, null, null);
formConfig.getFormFieldVisibility().addShowFieldElement(AlfrescoConversionConstants.FORM_FIELD_TRANSITIONS);
formConfig.getFormAppearance().addFormField(AlfrescoConversionConstants.FORM_FIELD_TRANSITIONS, null, AlfrescoConversionConstants.FORM_SET_RESPONSE);
}
}
use of org.activiti.workflow.simple.alfresco.form.AlfrescoTransitionsPropertyDefinition in project Activiti by Activiti.
the class AlfrescoTransitionsPropertyConverter method convertProperty.
@Override
public void convertProperty(M2Type contentType, String formSet, Form form, FormPropertyDefinition propertyDefinition, WorkflowDefinitionConversion conversion) {
AlfrescoTransitionsPropertyDefinition def = (AlfrescoTransitionsPropertyDefinition) propertyDefinition;
String propertyName = contentType.getName() + AlfrescoConversionConstants.PROPERTY_TRANSITIONS_SUFFIX;
// Add to content model
M2Property property = new M2Property();
property.setMandatory(new M2Mandatory(def.isMandatory()));
property.setName(propertyName);
property.setPropertyType(AlfrescoConversionConstants.PROPERTY_TYPE_TEXT);
M2Model model = AlfrescoConversionUtil.getContentModel(conversion);
contentType.getProperties().add(property);
// Create constraint for the values
if (def.getTransitions() != null && !def.getTransitions().isEmpty()) {
M2Constraint valueConstraint = new M2Constraint();
valueConstraint.setType(AlfrescoConversionConstants.CONTENT_MODEL_CONSTRAINT_TYPE_LIST);
valueConstraint.setName(propertyName + AlfrescoConversionConstants.CONTENT_MODEL_CONSTRAINT_TYPE_LIST.toLowerCase());
List<String> values = new ArrayList<String>(def.getTransitions().size());
for (ListPropertyEntry entry : def.getTransitions()) {
values.add(entry.getValue());
}
valueConstraint.getParameters().add(new M2NamedValue(AlfrescoConversionConstants.CONTENT_MODEL_CONSTRAINT_ALLOWED_VALUES, null, values));
// Add constraint to the root model instead of the type itself and reference it from within the property
// for readability and reuse of the model
model.getConstraints().add(valueConstraint);
M2Constraint reference = new M2Constraint();
reference.setRef(valueConstraint.getName());
property.getConstraints().add(reference);
}
// Add a pointer to the transition-property as well, using an override
M2PropertyOverride override = new M2PropertyOverride();
override.setDefaultValue(AlfrescoConversionUtil.getUrlQualifiedPropertyName(propertyName, model.getNamespaces().get(0)));
override.setName(AlfrescoConversionConstants.PROPERTY_OUTCOME_PROPERTY_NAME);
contentType.getPropertyOverrides().add(override);
// Add the transition-set
form.getFormAppearance().addFormSet(AlfrescoConversionConstants.FORM_SET_RESPONSE, null, null, null);
form.getFormFieldVisibility().addShowFieldElement(propertyName);
FormField transitionsFormField = new FormField();
transitionsFormField.setId(propertyName);
transitionsFormField.setSet(AlfrescoConversionConstants.FORM_SET_RESPONSE);
transitionsFormField.setControl(new FormFieldControl(AlfrescoConversionConstants.FORM_TRANSITIONS_TEMPLATE));
form.getFormAppearance().addFormAppearanceElement(transitionsFormField);
}
use of org.activiti.workflow.simple.alfresco.form.AlfrescoTransitionsPropertyDefinition in project Activiti by Activiti.
the class AlfrescoReviewStepConverter method createTransitionsProperty.
protected AlfrescoTransitionsPropertyDefinition createTransitionsProperty() {
AlfrescoTransitionsPropertyDefinition prop = new AlfrescoTransitionsPropertyDefinition();
prop.addEntry(new ListPropertyEntry(AlfrescoConversionConstants.TRANSITION_APPROVE, AlfrescoConversionConstants.TRANSITION_APPROVE));
prop.addEntry(new ListPropertyEntry(AlfrescoConversionConstants.TRANSITION_REJECT, AlfrescoConversionConstants.TRANSITION_REJECT));
return prop;
}
use of org.activiti.workflow.simple.alfresco.form.AlfrescoTransitionsPropertyDefinition in project Activiti by Activiti.
the class WorkflowDefinitionConversionTest method testTransitionProperty.
@Test
public void testTransitionProperty() throws Exception {
WorkflowDefinition definition = new WorkflowDefinition();
definition.setId("process");
HumanStepDefinition humanStep = new HumanStepDefinition();
humanStep.setId("step1");
FormDefinition form = new FormDefinition();
humanStep.setForm(form);
AlfrescoTransitionsPropertyDefinition transition = new AlfrescoTransitionsPropertyDefinition();
transition.addEntry(new ListPropertyEntry("One", "One"));
transition.addEntry(new ListPropertyEntry("Two", "Two"));
humanStep.getForm().addFormProperty(transition);
definition.addStep(humanStep);
WorkflowDefinitionConversion conversion = conversionFactory.createWorkflowDefinitionConversion(definition);
conversion.convert();
M2Model model = AlfrescoConversionUtil.getContentModel(conversion);
assertEquals(1L, model.getTypes().size());
M2Type taskType = model.getTypes().get(0);
assertEquals(1L, taskType.getPropertyOverrides().size());
assertEquals("bpm:outcomePropertyName", taskType.getPropertyOverrides().get(0).getName());
assertTrue(taskType.getPropertyOverrides().get(0).getDefaultValue().contains("step1transitions"));
assertEquals(1L, taskType.getProperties().size());
assertEquals(1L, model.getConstraints().size());
}
Aggregations