Package org.activiti.workflow.simple.definition.form

Examples of org.activiti.workflow.simple.definition.form.ListPropertyDefinition


    return ListPropertyDefinition.class;
  }

  @Override
  public void convertProperty(M2Type contentType, String formSet, Form form, FormPropertyDefinition propertyDefinition, WorkflowDefinitionConversion conversion) {
    ListPropertyDefinition dateDefinition = (ListPropertyDefinition) propertyDefinition;
   
    String propertyName = getPropertyName(propertyDefinition, conversion);
   
    // Add to content model
    M2Property property = new M2Property();
    property.setMandatory(new M2Mandatory(dateDefinition.isMandatory()));
    property.setName(propertyName);
    property.setPropertyType(AlfrescoConversionConstants.PROPERTY_TYPE_TEXT);
   
    M2Model model = AlfrescoConversionUtil.getContentModel(conversion);
    M2Aspect aspect = model.getAspect(propertyName);
    if(aspect != null) {
      // In case the "shared" aspect doesn't have the actual property set yet, we
      // do this here
      if(aspect.getProperties().isEmpty()) {
        aspect.getProperties().add(property);
      }
      contentType.getMandatoryAspects().add(propertyName);
    } else {
      contentType.getProperties().add(property);
    }
   
    // Create constraint for the values
    if(dateDefinition.getEntries() != null && !dateDefinition.getEntries().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>(dateDefinition.getEntries().size());
      for(ListPropertyEntry entry : dateDefinition.getEntries()) {
        // TODO: i18n file using labels in properties-file, a part of deployment?
        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 form configuration
    form.getFormFieldVisibility().addShowFieldElement(propertyName);
    FormField formField = form.getFormAppearance().addFormField(propertyName, propertyDefinition.getName(), formSet);

    // Read-only properties should always be rendered using an info-template
    if(!dateDefinition.isWritable()) {
      FormFieldControl control = new FormFieldControl();
      control.setTemplate(AlfrescoConversionConstants.FORM_READONLY_TEMPLATE);
      formField.setControl(control);
    }
   
View Full Code Here


      } else if (propertyDefinition instanceof DatePropertyDefinition) {
        type = "date";
      } else if (propertyDefinition instanceof ListPropertyDefinition) {
       
        type = "enum";
        ListPropertyDefinition listDefinition = (ListPropertyDefinition) propertyDefinition;
       
        if (!listDefinition.getEntries().isEmpty()) {
          List<FormValue> formValues = new ArrayList<FormValue>(listDefinition.getEntries().size());
          for (ListPropertyEntry entry : listDefinition.getEntries()) {
            FormValue formValue = new FormValue();
            // We're using same value for id and name for the moment
            formValue.setId(entry.getValue());
            formValue.setName(entry.getName());
            formValues.add(formValue);
View Full Code Here

    reference.setName("referenceProp");
    reference.setWritable(false);
    reference.setType("referencedType");
    formDefinition.addFormProperty(reference);
   
    ListPropertyDefinition itemType = new ListPropertyDefinition();
    itemType.setMandatory(true);
    itemType.setName("referenceProp");
    itemType.setWritable(false);
    itemType.addEntry(new ListPropertyEntry("1", "Item 1"));
    itemType.addEntry(new ListPropertyEntry("2", "Item 2"));
    formDefinition.addFormProperty(itemType);
   
    // Write result to byte-array
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    Writer writer = new OutputStreamWriter(baos);
    converter.writeWorkflowDefinition(workflowDefinition, writer);
   
    // Parse definition based on written JSON
    WorkflowDefinition parsedDefinition = converter.readWorkflowDefinition(baos.toByteArray());
    assertEquals(workflowDefinition.getSteps().size(), parsedDefinition.getSteps().size());

    int index = 0;
    for(StepDefinition stepDefinition : parsedDefinition.getSteps()) {
      assertTrue(stepDefinition instanceof HumanStepDefinition);
      HumanStepDefinition humanStep = (HumanStepDefinition) stepDefinition;
      HumanStepDefinition originalStep = (HumanStepDefinition) workflowDefinition.getSteps().get(index);
     
      // Check general human-step fields
      assertEquals(originalStep.getAssignee(), humanStep.getAssignee());
      assertEquals(originalStep.getAssignmentType(), humanStep.getAssignmentType());
      assertEquals(originalStep.getCandidateGroups(), humanStep.getCandidateGroups());
      assertEquals(originalStep.getCandidateUsers(), humanStep.getCandidateUsers());
      assertEquals(originalStep.getName(), humanStep.getName());
      assertEquals(originalStep.getDescription(), humanStep.getDescription());
     
      if(originalStep.getForm() != null) {
        // Encountered step with form attached to it, should be last step
        assertEquals(3, index);
        assertEquals("123", humanStep.getForm().getFormKey());
        assertEquals(originalStep.getForm().getFormPropertyDefinitions().size(),
            humanStep.getForm().getFormPropertyDefinitions().size());
       
        // Check form-fields, generic fields
        for(int i=0; i<originalStep.getForm().getFormPropertyDefinitions().size(); i++) {
          FormPropertyDefinition origDef = originalStep.getForm().getFormPropertyDefinitions().get(i);
          FormPropertyDefinition parsedDef = humanStep.getForm().getFormPropertyDefinitions().get(i);
         
          assertEquals(origDef.getName(), parsedDef.getName());
          assertEquals(origDef.isMandatory(), parsedDef.isMandatory());
          assertEquals(origDef.isWritable(), parsedDef.isWritable());
          assertEquals(origDef.getClass(), parsedDef.getClass());
         
          if(parsedDef instanceof TextPropertyDefinition) {
            assertTrue(parsedDef.getParameters() != null);
            assertEquals(1L, parsedDef.getParameters().size());
            assertEquals("This is a test", parsedDef.getParameters().get("custom-parameter"));
          }
         
          if(parsedDef instanceof ListPropertyDefinition) {
              ListPropertyDefinition parsed = (ListPropertyDefinition) parsedDef;
              assertEquals(2L, parsed.getEntries().size());
          }
        }
      }
      index++;
    }
View Full Code Here

        // Create a form with two properties, one of which is a ListProperty

        FormDefinition formDefinition = new FormDefinition();

        ListPropertyDefinition approveEnum = new ListPropertyDefinition();
        approveEnum.setName("Approval");
        approveEnum.setType("enum");
        approveEnum.addEntry(new ListPropertyEntry("true", "Approve"));
        approveEnum.addEntry(new ListPropertyEntry("false", "Reject"));
        formDefinition.addFormProperty(approveEnum);

        TextPropertyDefinition reason = new TextPropertyDefinition();
        reason.setName("Reason");
        reason.setType("string");
View Full Code Here

    entries.add(entry);
  }
 
  @Override
  public FormPropertyDefinition clone() {
    ListPropertyDefinition clone = new ListPropertyDefinition();
    clone.setValues(this);
    return clone;
  }
View Full Code Here

TOP

Related Classes of org.activiti.workflow.simple.definition.form.ListPropertyDefinition

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.