Search in sources :

Example 1 with FieldDefinition

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

the class TransientFieldProcessor method generateTypedField.

/* (non-Javadoc)
     * @see org.alfresco.repo.forms.processor.AbstractFieldProcessor#generateTypedField(java.lang.String, org.alfresco.repo.forms.processor.node.FormCreationData, java.lang.Object)
     */
@Override
protected Field generateTypedField(String fieldName, FormCreationData formData, TransientValueGetter typedData) {
    FieldDefinition transientPropDef = makeTransientFieldDefinition();
    Field fieldInfo = null;
    Object value = getValue(fieldName, typedData);
    if (transientPropDef != null) {
        fieldInfo = new ContentModelField(transientPropDef, value);
    }
    return fieldInfo;
}
Also used : Field(org.alfresco.repo.forms.Field) FieldDefinition(org.alfresco.repo.forms.FieldDefinition)

Example 2 with FieldDefinition

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

the class ActionFormProcessorTest method testGenerateFormWithSpecificLocale.

/**
 * REPO-2253 Community: ALF-21854 Action parameter lookup for "de_DE" falls back to "root" locale instead of "de"
 */
@Test
public void testGenerateFormWithSpecificLocale() {
    final Locale originalLocale = I18NUtil.getLocale();
    try {
        // de-DE
        I18NUtil.setLocale(Locale.GERMANY);
        transactionHelper.doInTransaction(() -> {
            Form form = formService.getForm(new Item(ActionFormProcessor.ITEM_KIND, "transform"));
            // Field definitions keyed by name.
            Map<String, FieldDefinition> fieldDefMap = form.getFieldDefinitions().stream().collect(Collectors.toMap(FieldDefinition::getName, Function.identity()));
            assertEquals("Zielordner", fieldDefMap.get(TransformActionExecuter.PARAM_DESTINATION_FOLDER).getLabel());
            assertEquals("MIME-Type", fieldDefMap.get(TransformActionExecuter.PARAM_MIME_TYPE).getLabel());
            return null;
        });
    } finally {
        I18NUtil.setLocale(originalLocale);
    }
}
Also used : Locale(java.util.Locale) Item(org.alfresco.repo.forms.Item) Form(org.alfresco.repo.forms.Form) AssociationFieldDefinition(org.alfresco.repo.forms.AssociationFieldDefinition) FieldDefinition(org.alfresco.repo.forms.FieldDefinition) PropertyFieldDefinition(org.alfresco.repo.forms.PropertyFieldDefinition) BaseAlfrescoSpringTest(org.alfresco.util.BaseAlfrescoSpringTest) Test(org.junit.Test)

Example 3 with FieldDefinition

use of org.alfresco.repo.forms.FieldDefinition in project records-management by Alfresco.

the class RecordsManagementTypeFormFilter method afterGenerate.

/*
     * @see
     * org.alfresco.repo.forms.processor.Filter#afterGenerate(java.lang.Object,
     * java.util.List, java.util.List, org.alfresco.repo.forms.Form,
     * java.util.Map)
     */
public void afterGenerate(TypeDefinition type, List<String> fields, List<String> forcedFields, Form form, Map<String, Object> context) {
    QName typeName = type.getName();
    if (rmAdminService.isCustomisable(typeName)) {
        addCustomRMProperties(typeName, form);
    }
    // What about any mandatory aspects?
    Set<QName> aspects = type.getDefaultAspectNames();
    for (QName aspect : aspects) {
        if (rmAdminService.isCustomisable(aspect)) {
            addCustomRMProperties(aspect, form);
        }
    }
    // set the id
    List<FieldDefinition> fieldDefs = form.getFieldDefinitions();
    for (FieldDefinition fieldDef : fieldDefs) {
        String prefixName = fieldDef.getName();
        if (prefixName.equals("rma:identifier")) {
            String defaultId = identifierService.generateIdentifier(typeName, null);
            fieldDef.setDefaultValue(defaultId);
        } else // NOTE: we set these defaults in the form for backwards compatibility reasons (RM-753)
        if (prefixName.equals("rma:vitalRecordIndicator")) {
            fieldDef.setDefaultValue(Boolean.FALSE.toString());
        } else if (prefixName.equals("rma:reviewPeriod")) {
            fieldDef.setDefaultValue("none|0");
        }
    }
}
Also used : QName(org.alfresco.service.namespace.QName) FieldDefinition(org.alfresco.repo.forms.FieldDefinition)

Example 4 with FieldDefinition

use of org.alfresco.repo.forms.FieldDefinition in project records-management by Alfresco.

the class RecordsManagementNodeFormFilter method protectEmailExtractedFields.

/**
 * Marks all the fields that contain data extracted from an email
 * as protected fields.
 *
 * @param form The Form instance to add the property to
 * @param nodeRef The node the form is being generated for
 */
protected void protectEmailExtractedFields(Form form, NodeRef nodeRef) {
    // iterate round existing fields and set email fields as protected
    List<FieldDefinition> fieldDefs = form.getFieldDefinitions();
    for (FieldDefinition fieldDef : fieldDefs) {
        String prefixName = fieldDef.getName();
        // check the value of the property, if empty then do not mark property
        // as read only
        QName qname = QName.createQName(prefixName, namespaceService);
        Serializable value = nodeService.getProperty(nodeRef, qname);
        if (value != null && (prefixName.equals("cm:title") || prefixName.equals("cm:author") || prefixName.equals("dod:originator") || prefixName.equals("dod:publicationDate") || prefixName.equals("dod:dateReceived") || prefixName.equals("dod:address") || prefixName.equals("dod:otherAddress"))) {
            fieldDef.setProtectedField(true);
        }
    }
    if (logger.isDebugEnabled()) {
        logger.debug("Set email related fields to be protected");
    }
}
Also used : Serializable(java.io.Serializable) QName(org.alfresco.service.namespace.QName) FieldDefinition(org.alfresco.repo.forms.FieldDefinition) PropertyFieldDefinition(org.alfresco.repo.forms.PropertyFieldDefinition)

Example 5 with FieldDefinition

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

the class FormProcessorTest method checkSingleField.

protected void checkSingleField(Form form, String fieldName, Serializable fieldData, String expDataKey) {
    List<FieldDefinition> fieldDefs = form.getFieldDefinitions();
    assertEquals(1, fieldDefs.size());
    FieldDefinition fieldDef = fieldDefs.get(0);
    assertEquals(fieldName, fieldDef.getName());
    String dataKey = fieldDef.getDataKeyName();
    assertEquals(expDataKey, dataKey);
    FieldData data = form.getFormData().getFieldData(dataKey);
    if (fieldData != null && data != null) {
        assertEquals(fieldData, data.getValue());
    } else {
        assertNull(data);
    }
}
Also used : FieldData(org.alfresco.repo.forms.FormData.FieldData) FieldDefinition(org.alfresco.repo.forms.FieldDefinition)

Aggregations

FieldDefinition (org.alfresco.repo.forms.FieldDefinition)8 QName (org.alfresco.service.namespace.QName)4 PropertyFieldDefinition (org.alfresco.repo.forms.PropertyFieldDefinition)3 Test (org.junit.Test)2 Serializable (java.io.Serializable)1 ArrayList (java.util.ArrayList)1 Locale (java.util.Locale)1 AlfMock.generateQName (org.alfresco.module.org_alfresco_module_rm.test.util.AlfMock.generateQName)1 BaseUnitTest (org.alfresco.module.org_alfresco_module_rm.test.util.BaseUnitTest)1 AssociationFieldDefinition (org.alfresco.repo.forms.AssociationFieldDefinition)1 Field (org.alfresco.repo.forms.Field)1 Form (org.alfresco.repo.forms.Form)1 FieldData (org.alfresco.repo.forms.FormData.FieldData)1 Item (org.alfresco.repo.forms.Item)1 NodeRef (org.alfresco.service.cmr.repository.NodeRef)1 BaseAlfrescoSpringTest (org.alfresco.util.BaseAlfrescoSpringTest)1