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;
}
Aggregations