Search in sources :

Example 1 with ContainedTypeFieldMetadata

use of org.talend.mdm.commmon.metadata.ContainedTypeFieldMetadata in project tmdm-common by Talend.

the class PermissionValidationRule method validateFieldRefPermission.

private boolean validateFieldRefPermission(FieldMetadata fieldMetadata, ValidationHandler handler) {
    fieldMetadata.setData(PermissionConstants.VALIDATION_PERMISSION_MARKER, true);
    String name = fieldMetadata.getName();
    XSDElementDeclaration element = fieldMetadata.getData(MetadataRepository.XSD_ELEMENT);
    if (element == null) {
        return true;
    }
    boolean valid = true;
    XSDAnnotation annotation = element.getAnnotation();
    if (annotation != null) {
        EList<Element> appInfoElements = annotation.getApplicationInformation();
        List<FieldMetadata> writeUsers = new ArrayList<FieldMetadata>();
        List<FieldMetadata> hideUsers = new ArrayList<FieldMetadata>();
        List<FieldMetadata> denyCreate = new ArrayList<FieldMetadata>();
        List<FieldMetadata> workflowAccessRights = new ArrayList<FieldMetadata>();
        for (Element appInfo : appInfoElements) {
            // $NON-NLS-1$
            String source = appInfo.getAttribute("source");
            String permissionRole = appInfo.getTextContent();
            if ("X_Write".equals(source)) {
                // $NON-NLS-1$
                writeUsers.add(getFieldMetadata(appInfo, permissionRole));
            } else if ("X_Hide".equals(source)) {
                // $NON-NLS-1$
                hideUsers.add(getFieldMetadata(appInfo, permissionRole));
            } else if ("X_Deny_Create".equals(source)) {
                // $NON-NLS-1$ )
                denyCreate.add(getFieldMetadata(appInfo, permissionRole));
            } else if ("X_Workflow".equals(source)) {
                // $NON-NLS-1$
                // $NON-NLS-1$
                permissionRole = permissionRole.substring(0, permissionRole.indexOf("#"));
                workflowAccessRights.add(getFieldMetadata(appInfo, permissionRole));
            }
        }
        valid = doValidation(handler, ELEMENT_TYPE_FIELD, name, PermissionConstants.PERMISSIONTYPE_WRITE, writeUsers);
        valid &= doValidation(handler, ELEMENT_TYPE_FIELD, name, PermissionConstants.PERMISSIONTYPE_HIDE, hideUsers);
        valid &= doValidation(handler, ELEMENT_TYPE_FIELD, name, PermissionConstants.PERMISSIONTYPE_DENY_CREATE, denyCreate);
        valid &= doValidation(handler, ELEMENT_TYPE_FIELD, name, PermissionConstants.PERMISSIONTYPE_WORKFLOW_ACCESS, workflowAccessRights);
    }
    if (fieldMetadata instanceof ContainedTypeFieldMetadata) {
        ContainedTypeFieldMetadata containedField = (ContainedTypeFieldMetadata) fieldMetadata;
        ComplexTypeMetadata cTypeMetadata = containedField.getContainedType();
        Collection<FieldMetadata> fieldMetadatas = cTypeMetadata.getFields();
        for (FieldMetadata fMetadata : fieldMetadatas) {
            boolean validateMarked = BooleanUtils.isTrue(fMetadata.<Boolean>getData(PermissionConstants.VALIDATION_PERMISSION_MARKER));
            if (!validateMarked) {
                valid &= validateFieldRefPermission(fMetadata, handler);
            }
        }
    }
    return valid;
}
Also used : FieldMetadata(org.talend.mdm.commmon.metadata.FieldMetadata) ContainedTypeFieldMetadata(org.talend.mdm.commmon.metadata.ContainedTypeFieldMetadata) XSDElementDeclaration(org.eclipse.xsd.XSDElementDeclaration) Element(org.w3c.dom.Element) ArrayList(java.util.ArrayList) ContainedTypeFieldMetadata(org.talend.mdm.commmon.metadata.ContainedTypeFieldMetadata) XSDAnnotation(org.eclipse.xsd.XSDAnnotation) ComplexTypeMetadata(org.talend.mdm.commmon.metadata.ComplexTypeMetadata)

Aggregations

ArrayList (java.util.ArrayList)1 XSDAnnotation (org.eclipse.xsd.XSDAnnotation)1 XSDElementDeclaration (org.eclipse.xsd.XSDElementDeclaration)1 ComplexTypeMetadata (org.talend.mdm.commmon.metadata.ComplexTypeMetadata)1 ContainedTypeFieldMetadata (org.talend.mdm.commmon.metadata.ContainedTypeFieldMetadata)1 FieldMetadata (org.talend.mdm.commmon.metadata.FieldMetadata)1 Element (org.w3c.dom.Element)1