Search in sources :

Example 6 with FieldMetadata

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

the class PermissionValidationRule method validateComplexTypePermission.

private boolean validateComplexTypePermission(ComplexTypeMetadata cTypeMetadata, ValidationHandler handler) {
    // entity
    String name = cTypeMetadata.getName();
    XSDElementDeclaration element = cTypeMetadata.getData(MetadataRepository.XSD_ELEMENT);
    if (element == null || element.getAnnotation() == null) {
        return true;
    }
    XSDAnnotation annotation = element.getAnnotation();
    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> denyDeleteLogical = new ArrayList<FieldMetadata>();
    List<FieldMetadata> denyDeletePhysical = 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_Deny_LogicalDelete".equals(source)) {
            // $NON-NLS-1$
            denyDeleteLogical.add(getFieldMetadata(appInfo, permissionRole));
        } else if ("X_Deny_PhysicalDelete".equals(source)) {
            // $NON-NLS-1$
            denyDeletePhysical.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));
        }
    }
    boolean valid = doValidation(handler, ELEMENT_TYPE_ENTITY, name, PermissionConstants.PERMISSIONTYPE_WRITE, writeUsers);
    valid &= doValidation(handler, ELEMENT_TYPE_ENTITY, name, PermissionConstants.PERMISSIONTYPE_HIDE, hideUsers);
    valid &= doValidation(handler, ELEMENT_TYPE_ENTITY, name, PermissionConstants.PERMISSIONTYPE_DENY_CREATE, denyCreate);
    valid &= doValidation(handler, ELEMENT_TYPE_ENTITY, name, PermissionConstants.PERMISSIONTYPE_DENY_DELETE_PHYSICAL, denyDeletePhysical);
    valid &= doValidation(handler, ELEMENT_TYPE_ENTITY, name, PermissionConstants.PERMISSIONTYPE_DENY_DELETE_LOGICAL, denyDeleteLogical);
    valid &= doValidation(handler, ELEMENT_TYPE_ENTITY, name, PermissionConstants.PERMISSIONTYPE_WORKFLOW_ACCESS, workflowAccessRights);
    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) XSDAnnotation(org.eclipse.xsd.XSDAnnotation)

Example 7 with FieldMetadata

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

the class PermissionValidationRule method doValidation.

private boolean doValidation(ValidationHandler handler, String elementType, String elementName, String permissionType, List<FieldMetadata> roles) {
    boolean valid = true;
    for (FieldMetadata roleMetadata : roles) {
        String lowerCaseRoleName = roleMetadata.getName().toLowerCase();
        if (lowerCaseRoleName.startsWith(ICoreConstants.SYSTEM_ROLE_PREFIX.toLowerCase()) || lowerCaseRoleName.equals(ICoreConstants.ADMIN_PERMISSION)) {
            String message = // $NON-NLS-1$ //$NON-NLS-2$
            "System role \"" + roleMetadata.getName() + "\" shouldn't be used to set \"" + permissionType + "\" permission on " + elementType + " \"" + elementName + // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
            "\" .";
            Element data = roleMetadata.<Element>getData(MetadataRepository.XSD_DOM_ELEMENT);
            Integer lineNum = roleMetadata.<Integer>getData(MetadataRepository.XSD_LINE_NUMBER);
            Integer colNum = roleMetadata.<Integer>getData(MetadataRepository.XSD_COLUMN_NUMBER);
            if (complexTypeMetadata != null) {
                handler.error(complexTypeMetadata, message, data, lineNum, colNum, ValidationError.PERMISSION_SYSTEM_ROLE_NOT_SETTABLE);
            } else {
                handler.error(field, message, data, lineNum, colNum, ValidationError.PERMISSION_SYSTEM_ROLE_NOT_SETTABLE);
            }
            valid &= false;
        }
    }
    return valid;
}
Also used : FieldMetadata(org.talend.mdm.commmon.metadata.FieldMetadata) ContainedTypeFieldMetadata(org.talend.mdm.commmon.metadata.ContainedTypeFieldMetadata) Element(org.w3c.dom.Element)

Example 8 with FieldMetadata

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

the class ForeignKeyProcessor method handleForeignKey.

private void handleForeignKey(MetadataRepository repository, ComplexTypeMetadata type, XmlSchemaAnnotationProcessorState state, Element appInfo) {
    state.markAsReference();
    String path = appInfo.getTextContent();
    FieldMetadata fieldMetadata = getFieldMetadata(repository, type, appInfo, path, false);
    state.setReferencedField(fieldMetadata);
    // Only reference instantiable types.
    state.setReferencedType(new SoftTypeRef(repository, repository.getUserNamespace(), getTypeName(type, path), true));
}
Also used : FieldMetadata(org.talend.mdm.commmon.metadata.FieldMetadata) SoftTypeRef(org.talend.mdm.commmon.metadata.SoftTypeRef)

Aggregations

FieldMetadata (org.talend.mdm.commmon.metadata.FieldMetadata)8 ContainedTypeFieldMetadata (org.talend.mdm.commmon.metadata.ContainedTypeFieldMetadata)5 ArrayList (java.util.ArrayList)3 Element (org.w3c.dom.Element)3 XSDAnnotation (org.eclipse.xsd.XSDAnnotation)2 XSDElementDeclaration (org.eclipse.xsd.XSDElementDeclaration)2 ComplexTypeMetadata (org.talend.mdm.commmon.metadata.ComplexTypeMetadata)2 SoftFieldRef (org.talend.mdm.commmon.metadata.SoftFieldRef)2 HashMap (java.util.HashMap)1 ContainedComplexTypeMetadata (org.talend.mdm.commmon.metadata.ContainedComplexTypeMetadata)1 EnumerationFieldMetadata (org.talend.mdm.commmon.metadata.EnumerationFieldMetadata)1 MetadataVisitable (org.talend.mdm.commmon.metadata.MetadataVisitable)1 ReferenceFieldMetadata (org.talend.mdm.commmon.metadata.ReferenceFieldMetadata)1 SimpleTypeFieldMetadata (org.talend.mdm.commmon.metadata.SimpleTypeFieldMetadata)1 SimpleTypeMetadata (org.talend.mdm.commmon.metadata.SimpleTypeMetadata)1 SoftIdFieldRef (org.talend.mdm.commmon.metadata.SoftIdFieldRef)1 SoftTypeRef (org.talend.mdm.commmon.metadata.SoftTypeRef)1 TypeMetadata (org.talend.mdm.commmon.metadata.TypeMetadata)1