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