use of org.eclipse.xsd.XSDAnnotation 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;
}
use of org.eclipse.xsd.XSDAnnotation in project tmdm-studio-se by Talend.
the class FKIntegrityComposite method updateModel.
private void updateModel() {
XSDAnnotation annotation = xsdComponent.getAnnotation();
if (annotation == null) {
annotation = XSDFactory.eINSTANCE.createXSDAnnotation();
xsdComponent.setAnnotation(annotation);
}
Element fkIntegrityElement = null;
Element fkIntegrityOverrideElement = null;
EList<Element> appInfo = annotation.getApplicationInformation();
for (Element currentElement : appInfo) {
// $NON-NLS-1$
String source = currentElement.getAttribute("source");
if (X_FK_INTEGRITY.endsWith(source)) {
fkIntegrityElement = currentElement;
} else if (X_FK_INTEGRITY_OVERRIDE.endsWith(source)) {
fkIntegrityOverrideElement = currentElement;
}
}
updateModelElement(xsdComponent, fkIntegrityElement, X_FK_INTEGRITY, btnEnforceFkIntegrity.getSelection());
updateModelElement(xsdComponent, fkIntegrityOverrideElement, X_FK_INTEGRITY_OVERRIDE, btnAllowFkIntegrity.getSelection());
this.elementFKSection.autoCommit();
}
use of org.eclipse.xsd.XSDAnnotation in project tmdm-studio-se by Talend.
the class XSDSetAnnotationLabelAction method doAction.
@Override
public IStatus doAction() {
try {
// IStructuredSelection selection = (IStructuredSelection)page.getTreeViewer().getSelection();
//
// XSDAnnotationsStructure struc = new XSDAnnotationsStructure((XSDComponent)selection.getFirstElement());
IStructuredSelection selection = (TreeSelection) page.getTreeViewer().getSelection();
XSDComponent xSDCom = null;
if (selection.getFirstElement() instanceof Element) {
TreePath tPath = ((TreeSelection) selection).getPaths()[0];
for (int i = 0; i < tPath.getSegmentCount(); i++) {
if (tPath.getSegment(i) instanceof XSDAnnotation) {
xSDCom = (XSDAnnotation) (tPath.getSegment(i));
}
}
} else {
xSDCom = (XSDComponent) selection.getFirstElement();
}
XSDAnnotationsStructure struc = new XSDAnnotationsStructure(xSDCom);
if (struc.getAnnotation() == null) {
throw new RuntimeException(Messages.bind(Messages.XSDSetAnnotationLabelAction_ExceptioInfo, xSDCom.getClass().getName()));
}
AnnotationLanguageLabelsDialog dlg = new AnnotationLanguageLabelsDialog(struc.getLabels(), new AnnotationLabelDialogSelectionListener(page), page.getEditorSite().getShell(), Messages.XSDSetAnnotationLabelAction_DialogTitle);
dlg.setBlockOnOpen(true);
dlg.open();
if (dlg.getReturnCode() == Window.OK) {
// remove existing annotations with labels
struc.removeAllLabels();
// add the new ones
LinkedHashMap<String, String> descriptions = dlg.getDescriptionsMap();
Set<String> isoCodes = descriptions.keySet();
for (Iterator iter = isoCodes.iterator(); iter.hasNext(); ) {
String isoCode = (String) iter.next();
struc.setLabel(isoCode, descriptions.get(isoCode));
}
} else {
return Status.CANCEL_STATUS;
}
if (struc.hasChanged()) {
page.markDirty();
page.refresh();
page.getTreeViewer().expandToLevel(xSDCom, 2);
}
} catch (Exception e) {
log.error(e.getMessage(), e);
MessageDialog.openError(page.getSite().getShell(), Messages._Error, Messages.bind(Messages.XSDSetAnnotationLabelAction_ErrorMsg, e.getLocalizedMessage()));
return Status.CANCEL_STATUS;
}
return Status.OK_STATUS;
}
use of org.eclipse.xsd.XSDAnnotation in project tmdm-studio-se by Talend.
the class XSDSetAnnotationTargetSystemsAction method doAction.
public IStatus doAction() {
try {
IStructuredSelection selection = (TreeSelection) page.getTreeViewer().getSelection();
XSDComponent xSDCom = null;
if (selection.getFirstElement() instanceof Element) {
TreePath tPath = ((TreeSelection) selection).getPaths()[0];
for (int i = 0; i < tPath.getSegmentCount(); i++) {
if (tPath.getSegment(i) instanceof XSDAnnotation)
xSDCom = (XSDAnnotation) (tPath.getSegment(i));
}
} else
xSDCom = (XSDComponent) selection.getFirstElement();
XSDAnnotationsStructure struc = new XSDAnnotationsStructure(xSDCom);
// XSDAnnotationsStructure struc = new XSDAnnotationsStructure((XSDComponent)selection.getFirstElement());
if (struc.getAnnotation() == null) {
throw new RuntimeException(Messages.bind(Messages.XSDSetAnnotationTargetSystemsAction_ExceptionInfo, xSDCom.getClass().getName()));
}
dlg = new AnnotationOrderedListsDialog(new ArrayList(struc.getTargetSystems().values()), new SelectionListener() {
public void widgetDefaultSelected(SelectionEvent e) {
}
public void widgetSelected(SelectionEvent e) {
dlg.close();
}
}, page.getSite().getShell(), Messages.XSDSetAnnotationTargetSystemsAction_DialogTitle, Messages.XSDSetAnnotationTargetSystemsAction_DialogTip, page, AnnotationOrderedListsDialog.AnnotationTargetSystems_ActionType, dataModelName);
dlg.setBlockOnOpen(true);
int ret = dlg.open();
if (ret == Window.CANCEL) {
return Status.CANCEL_STATUS;
}
struc.setTargetSystems(dlg.getXPaths());
if (struc.hasChanged()) {
page.refresh();
page.getTreeViewer().expandToLevel(xSDCom, 2);
page.markDirty();
}
} catch (Exception e) {
log.error(e.getMessage(), e);
MessageDialog.openError(page.getSite().getShell(), Messages._Error, Messages.bind(Messages.XSDSetAnnotationTargetSystemsAction_ErrorMsg, e.getLocalizedMessage()));
return Status.CANCEL_STATUS;
}
return Status.OK_STATUS;
}
use of org.eclipse.xsd.XSDAnnotation in project tmdm-studio-se by Talend.
the class XSDSetFacetMessageAction method doAction.
public IStatus doAction() {
try {
IStructuredSelection selection = (TreeSelection) page.getTreeViewer().getSelection();
XSDComponent xSDCom = null;
if (selection.getFirstElement() instanceof Element) {
TreePath tPath = ((TreeSelection) selection).getPaths()[0];
for (int i = 0; i < tPath.getSegmentCount(); i++) {
if (tPath.getSegment(i) instanceof XSDAnnotation)
xSDCom = (XSDAnnotation) (tPath.getSegment(i));
}
} else
xSDCom = (XSDComponent) selection.getFirstElement();
XSDAnnotationsStructure struc = new XSDAnnotationsStructure(xSDCom);
// XSDAnnotationsStructure struc = new XSDAnnotationsStructure((XSDComponent)selection.getFirstElement());
if (struc.getAnnotation() == null) {
throw new RuntimeException(Messages.bind(Messages.XSDSetFacetMessageAction_ExceptionInfo, selection.getFirstElement().getClass().getName()));
}
dlg = new AnnotationLanguageLabelsDialog(struc.getFactMessage(), new SelectionListener() {
public void widgetDefaultSelected(SelectionEvent e) {
}
public void widgetSelected(SelectionEvent e) {
dlg.close();
}
}, page.getSite().getShell(), Messages.XSDSetFacetMessageAction_DialogTip);
dlg.setBlockOnOpen(true);
int ret = dlg.open();
if (ret == Window.CANCEL) {
return Status.CANCEL_STATUS;
}
LinkedHashMap<String, String> facets = dlg.getDescriptionsMap();
struc.setFactMessage(facets);
if (struc.hasChanged()) {
page.refresh();
page.getTreeViewer().expandToLevel(selection.getFirstElement(), 2);
page.markDirty();
}
} catch (Exception e) {
log.error(e.getMessage(), e);
MessageDialog.openError(page.getSite().getShell(), Messages._Error, Messages.bind(Messages.XSDSetFacetMessageAction_ErrorMsg + e.getLocalizedMessage()));
return Status.CANCEL_STATUS;
}
return Status.OK_STATUS;
}
Aggregations