Search in sources :

Example 6 with FieldDefinition

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

the class RecordsManagementNodeFormFilter method protectRecordProperties.

/**
 * @param form
 * @param nodeRef
 */
protected void protectRecordProperties(Form form, NodeRef nodeRef) {
    List<FieldDefinition> fieldDefs = form.getFieldDefinitions();
    for (FieldDefinition fieldDef : fieldDefs) {
        if (!fieldDef.isProtectedField()) {
            String name = fieldDef.getName();
            String prefixName = null;
            if ("size".equals(name) || "mimetype".equals(name) || "encoding".equals(name)) {
                prefixName = "cm:content";
            } else {
                prefixName = fieldDef.getName();
            }
            if (logger.isDebugEnabled()) {
                logger.debug("Checking property " + prefixName + " is editable by user " + AuthenticationUtil.getFullyAuthenticatedUser());
            }
            QName qname = QName.createQName(prefixName, namespaceService);
            if (!recordService.isPropertyEditable(nodeRef, qname)) {
                if (logger.isDebugEnabled()) {
                    logger.debug("   ... protected property");
                }
                fieldDef.setProtectedField(true);
            }
        }
    }
}
Also used : QName(org.alfresco.service.namespace.QName) FieldDefinition(org.alfresco.repo.forms.FieldDefinition) PropertyFieldDefinition(org.alfresco.repo.forms.PropertyFieldDefinition)

Example 7 with FieldDefinition

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

the class RecordsManagementTypeFormFilterUnitTest method testDefaultFormValues.

/**
 * Test the default values for certain properties are being set correctly
 */
@Test
public void testDefaultFormValues() {
    List<FieldDefinition> defs = new ArrayList<>(3);
    FieldDefinition idDef = mockFieldDefinition("rma:identifier");
    defs.add(idDef);
    FieldDefinition vrDef = mockFieldDefinition("rma:vitalRecordIndicator");
    defs.add(vrDef);
    FieldDefinition rpDef = mockFieldDefinition("rma:reviewPeriod");
    defs.add(rpDef);
    when(mockForm.getFieldDefinitions()).thenReturn(defs);
    typeFormFilter.afterGenerate(mockTypeDefinition, null, null, mockForm, null);
    verify(mockedIdentifierService).generateIdentifier(any(QName.class), any(NodeRef.class));
    verify(idDef).setDefaultValue(anyString());
    verify(vrDef).setDefaultValue(Boolean.FALSE.toString());
    verify(rpDef).setDefaultValue("none|0");
}
Also used : NodeRef(org.alfresco.service.cmr.repository.NodeRef) AlfMock.generateQName(org.alfresco.module.org_alfresco_module_rm.test.util.AlfMock.generateQName) QName(org.alfresco.service.namespace.QName) FieldDefinition(org.alfresco.repo.forms.FieldDefinition) ArrayList(java.util.ArrayList) BaseUnitTest(org.alfresco.module.org_alfresco_module_rm.test.util.BaseUnitTest) Test(org.junit.Test)

Example 8 with FieldDefinition

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

the class RecordsManagementTypeFormFilterUnitTest method mockFieldDefinition.

/**
 * Helper to mock field definition
 */
private FieldDefinition mockFieldDefinition(String name) {
    FieldDefinition def = mock(FieldDefinition.class);
    when(def.getName()).thenReturn(name);
    return def;
}
Also used : 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