Search in sources :

Example 11 with Form

use of org.alfresco.repo.forms.Form in project alfresco-repository by Alfresco.

the class ScriptFormService method getForm.

/**
 * Returns a form representation of the given item consisting
 * only of the given fields.
 *
 * @param itemKind The kind of item to retrieve a form for
 * @param itemId The identifier of the item to retrieve a form for
 * @param fields String array of fields to include, null
 *               indicates all possible fields for the item
 *               should be included
 * @param forcedFields List of field names from 'fields' list
 *                     that should be forcibly included, it is
 *                     up to the form processor implementation
 *                     to determine how to enforce this
 * @return The form
 */
public ScriptForm getForm(String itemKind, String itemId, String[] fields, String[] forcedFields) {
    // create List<String> representations of field params if necessary
    List<String> fieldsList = null;
    List<String> forcedFieldsList = null;
    if (fields != null) {
        fieldsList = Arrays.asList(fields);
    }
    if (forcedFields != null) {
        forcedFieldsList = Arrays.asList(forcedFields);
    }
    Form result = formService.getForm(new Item(itemKind, itemId), fieldsList, forcedFieldsList);
    return result == null ? null : new ScriptForm(result);
}
Also used : Item(org.alfresco.repo.forms.Item) Form(org.alfresco.repo.forms.Form)

Example 12 with Form

use of org.alfresco.repo.forms.Form in project alfresco-repository by Alfresco.

the class TaskFormProcessorTest method testGenerateSingleProperty.

public void testGenerateSingleProperty() {
    // Check Status field is added to Form.
    String fieldName = STATUS_NAME.toPrefixString(namespaceService);
    List<String> fields = Arrays.asList(fieldName);
    Form form = processForm(fields);
    checkSingleProperty(form, fieldName, WorkflowTaskState.IN_PROGRESS);
    // Check Status field is added to Form, when explicitly typed as a
    // property.
    String fullPropertyName = "prop:" + fieldName;
    fields = Arrays.asList(fullPropertyName);
    form = processForm(fields);
    checkSingleProperty(form, fieldName, WorkflowTaskState.IN_PROGRESS);
    checkPackageActionGroups(form.getFormData());
}
Also used : Form(org.alfresco.repo.forms.Form)

Example 13 with Form

use of org.alfresco.repo.forms.Form in project alfresco-repository by Alfresco.

the class TaskFormProcessorTest method testGeneratePackageItems.

public void testGeneratePackageItems() throws Exception {
    // Check empty package
    String fieldName = PackageItemsFieldProcessor.KEY;
    Form form = processForm(fieldName);
    Serializable packageItems = (Serializable) Collections.emptyList();
    checkSingleAssociation(form, fieldName, packageItems);
    // Effectively add 3 items to package.
    List<NodeRef> value = Arrays.asList(FAKE_NODE, FAKE_NODE2, FAKE_NODE3);
    when(workflowService.getPackageContents(TASK_ID)).thenReturn(value);
    form = processForm(fieldName);
    packageItems = (Serializable) Arrays.asList(FAKE_NODE.toString(), FAKE_NODE2.toString(), FAKE_NODE3.toString());
    checkSingleAssociation(form, fieldName, packageItems);
}
Also used : NodeRef(org.alfresco.service.cmr.repository.NodeRef) Serializable(java.io.Serializable) Form(org.alfresco.repo.forms.Form)

Example 14 with Form

use of org.alfresco.repo.forms.Form in project alfresco-repository by Alfresco.

the class TaskFormProcessorTest method testIgnoresUnknownFields.

public void testIgnoresUnknownFields() throws Exception {
    String fakeFieldName = NamespaceService.BPM_MODEL_PREFIX + ":" + "Fake Field";
    String statusFieldName = STATUS_NAME.toPrefixString(namespaceService);
    List<String> fields = Arrays.asList(fakeFieldName, statusFieldName);
    Form form = processForm(fields);
    checkSingleProperty(form, statusFieldName, WorkflowTaskState.IN_PROGRESS);
    checkPackageActionGroups(form.getFormData());
}
Also used : Form(org.alfresco.repo.forms.Form)

Example 15 with Form

use of org.alfresco.repo.forms.Form in project alfresco-repository by Alfresco.

the class TaskFormProcessorTest method testGenerateDefaultForm.

public void testGenerateDefaultForm() throws Exception {
    Form form = processForm();
    List<String> fieldDefs = form.getFieldDefinitionNames();
    assertTrue(fieldDefs.contains(ASSIGNEE_NAME.toPrefixString(namespaceService)));
    assertTrue(fieldDefs.contains(ASSOC_WITH_.toPrefixString(namespaceService)));
    assertTrue(fieldDefs.contains(DESC_NAME.toPrefixString(namespaceService)));
    assertTrue(fieldDefs.contains(STATUS_NAME.toPrefixString(namespaceService)));
    assertTrue(fieldDefs.contains(PROP_WITH_.toPrefixString(namespaceService)));
    assertTrue(fieldDefs.contains(PackageItemsFieldProcessor.KEY));
    assertTrue(fieldDefs.contains(TransitionFieldProcessor.KEY));
    // Check 'default ignored fields' are proerly removed from defaults.
    assertFalse(fieldDefs.contains(ACTORS_NAME.toPrefixString(namespaceService)));
    assertFalse(fieldDefs.contains(PROP_PACKAGE_ACTION_GROUP.toPrefixString(namespaceService)));
    assertFalse(fieldDefs.contains(PROP_PACKAGE_ITEM_ACTION_GROUP.toPrefixString(namespaceService)));
    Serializable fieldData = (Serializable) Arrays.asList(FAKE_NODE.toString());
    FormData formData = form.getFormData();
    assertEquals(fieldData, formData.getFieldData("assoc_bpm_assignee").getValue());
    checkPackageActionGroups(formData);
    assertEquals(WorkflowTaskState.IN_PROGRESS, formData.getFieldData("prop_bpm_status").getValue());
}
Also used : FormData(org.alfresco.repo.forms.FormData) Serializable(java.io.Serializable) Form(org.alfresco.repo.forms.Form)

Aggregations

Form (org.alfresco.repo.forms.Form)20 Serializable (java.io.Serializable)7 Item (org.alfresco.repo.forms.Item)5 FormData (org.alfresco.repo.forms.FormData)2 Locale (java.util.Locale)1 AssociationFieldDefinition (org.alfresco.repo.forms.AssociationFieldDefinition)1 FieldDefinition (org.alfresco.repo.forms.FieldDefinition)1 PropertyFieldDefinition (org.alfresco.repo.forms.PropertyFieldDefinition)1 NodeRef (org.alfresco.service.cmr.repository.NodeRef)1 WorkflowTransition (org.alfresco.service.cmr.workflow.WorkflowTransition)1 BaseAlfrescoSpringTest (org.alfresco.util.BaseAlfrescoSpringTest)1 Test (org.junit.Test)1