Search in sources :

Example 51 with XSDAnnotation

use of org.eclipse.xsd.XSDAnnotation 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 52 with XSDAnnotation

use of org.eclipse.xsd.XSDAnnotation in project tmdm-studio-se by Talend.

the class XSDPasteConceptAction method addAnnotationForComplexType.

public void addAnnotationForComplexType(XSDComplexTypeDefinition fromType, XSDComplexTypeDefinition toType) {
    XSDComplexTypeContent tocomplexType = toType.getContent();
    XSDComplexTypeContent fromcomplexType = fromType.getContent();
    if (fromcomplexType instanceof XSDParticle) {
        XSDParticle fromxsdParticle = (XSDParticle) fromcomplexType;
        XSDParticle toxsdParticle = (XSDParticle) tocomplexType;
        if (fromxsdParticle.getTerm() instanceof XSDModelGroup) {
            XSDModelGroup frommodelGroup = ((XSDModelGroup) fromxsdParticle.getTerm());
            XSDModelGroup tomodelGroup = ((XSDModelGroup) toxsdParticle.getTerm());
            EList<XSDParticle> fromlist = frommodelGroup.getContents();
            EList<XSDParticle> tolist = tomodelGroup.getContents();
            Iterator<XSDParticle> toIt = tolist.iterator();
            for (XSDParticle fromel : fromlist.toArray(new XSDParticle[fromlist.size()])) {
                XSDParticle toel = toIt.next();
                XSDTerm totm = toel.getTerm();
                XSDTerm fromtm = fromel.getTerm();
                if (fromtm instanceof XSDElementDeclaration) {
                    XSDAnnotation fromannotation = ((XSDElementDeclaration) fromtm).getAnnotation();
                    if (fromannotation != null) {
                        XSDAnnotationsStructure struc = new XSDAnnotationsStructure(totm);
                        addAnnotion(struc, fromannotation);
                        if (this.typeList.containsKey(((XSDElementDeclaration) totm).getType().getName())) {
                            this.copyTypeSet.add(this.typeList.get(((XSDElementDeclaration) totm).getType().getName()));
                        }
                        addAnnotationForXSDElementDeclaration((XSDElementDeclaration) fromtm, (XSDElementDeclaration) totm);
                    }
                }
            }
        }
    }
}
Also used : XSDComplexTypeContent(org.eclipse.xsd.XSDComplexTypeContent) XSDModelGroup(org.eclipse.xsd.XSDModelGroup) XSDAnnotationsStructure(com.amalto.workbench.utils.XSDAnnotationsStructure) XSDElementDeclaration(org.eclipse.xsd.XSDElementDeclaration) XSDTerm(org.eclipse.xsd.XSDTerm) XSDAnnotation(org.eclipse.xsd.XSDAnnotation) XSDParticle(org.eclipse.xsd.XSDParticle)

Example 53 with XSDAnnotation

use of org.eclipse.xsd.XSDAnnotation in project tmdm-studio-se by Talend.

the class XSDSetAnnotationDescriptionsAction 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);
        if (struc.getAnnotation() == null) {
            throw new RuntimeException(Messages.bind(Messages.XSDSetAnnotationXX_ExceptionInfo2, xSDCom.getClass().getName()));
        }
        AnnotationLanguageLabelsDialog dlg = new AnnotationLanguageLabelsDialog(struc.getDescriptions(), new AnnotationLabelDialogSelectionListener(page), page.getEditorSite().getShell(), Messages.XSDSetAnnotationXX_SetDescOfThisItem);
        dlg.setBlockOnOpen(true);
        dlg.open();
        if (dlg.getReturnCode() == Window.OK) {
            // remove existing annotations with labels
            struc.removeAllDescriptions();
            // 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.setDescription(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.XSDSetAnnotationXX_ErrorMsg, e.getLocalizedMessage()));
        return Status.CANCEL_STATUS;
    }
    return Status.OK_STATUS;
}
Also used : XSDAnnotationsStructure(com.amalto.workbench.utils.XSDAnnotationsStructure) Element(org.w3c.dom.Element) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) XSDComponent(org.eclipse.xsd.XSDComponent) TreePath(org.eclipse.jface.viewers.TreePath) TreeSelection(org.eclipse.jface.viewers.TreeSelection) Iterator(java.util.Iterator) AnnotationLanguageLabelsDialog(com.amalto.workbench.dialogs.AnnotationLanguageLabelsDialog) XSDAnnotation(org.eclipse.xsd.XSDAnnotation)

Example 54 with XSDAnnotation

use of org.eclipse.xsd.XSDAnnotation in project tmdm-studio-se by Talend.

the class XSDSetAnnotationFKFilterAction method doAction.

@Override
public IStatus doAction() {
    try {
        IStructuredSelection selection = (TreeSelection) page.getTreeViewer().getSelection();
        XSDComponent xSDCom = null;
        String conceptName = 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();
        }
        if (xSDCom instanceof XSDElementDeclaration) {
            // $NON-NLS-1$
            conceptName = xSDCom.getElement().getAttributes().getNamedItem("name").getNodeValue();
        }
        if (xSDCom instanceof XSDParticle) {
        }
        XSDAnnotationsStructure struc = null;
        if (xSDCom != null) {
            struc = new XSDAnnotationsStructure(xSDCom);
        }
        if (struc == null || struc.getAnnotation() == null) {
            throw new RuntimeException(Messages.bind(Messages.UnableEditAnnotationType, xSDCom.getClass().getName()));
        }
        fkd = getNewFKFilterDialog(page.getSite().getShell(), struc.getFKFilter(), page, conceptName);
        fkd.setDataModel(dataModelName);
        fkd.setLock(true);
        fkd.setBlockOnOpen(true);
        int ret = fkd.open();
        if (ret == Window.CANCEL) {
            return Status.CANCEL_STATUS;
        }
        String fkfilter = fkd.getFilter();
        struc.setFKFilter(fkfilter);
        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.ErrorFKFilter, e.getLocalizedMessage()));
        return Status.CANCEL_STATUS;
    }
    return Status.OK_STATUS;
}
Also used : XSDAnnotationsStructure(com.amalto.workbench.utils.XSDAnnotationsStructure) Element(org.w3c.dom.Element) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) XSDComponent(org.eclipse.xsd.XSDComponent) TreePath(org.eclipse.jface.viewers.TreePath) TreeSelection(org.eclipse.jface.viewers.TreeSelection) XSDElementDeclaration(org.eclipse.xsd.XSDElementDeclaration) XSDAnnotation(org.eclipse.xsd.XSDAnnotation) XSDParticle(org.eclipse.xsd.XSDParticle)

Example 55 with XSDAnnotation

use of org.eclipse.xsd.XSDAnnotation in project tmdm-studio-se by Talend.

the class XSDSetAnnotationForeignKeyInfoAction method doAction.

@Override
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);
        if (struc.getAnnotation() == null) {
            throw new RuntimeException(Messages.bind(Messages.UnableEditAnnotationType, xSDCom.getClass().getName()));
        }
        dlg = getNewAnnotaionOrderedListsDialog(struc.getForeignKeyInfos().values());
        dlg.setLock(true);
        dlg.setRetrieveFKinfos(struc.getRetrieveFKinfos());
        dlg.setFormatFKInfo(struc.getFormatForeignKeyInfo());
        dlg.setBlockOnOpen(true);
        int ret = dlg.open();
        if (ret == Window.CANCEL) {
            return Status.CANCEL_STATUS;
        }
        struc.setForeignKeyInfos(dlg.getXPaths());
        struc.setRetrieveFKinfos(dlg.isRetrieveFKinfos());
        struc.setFormatForeignKeyInfo(dlg.getFormatFKInfo());
        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.ErrorForeignKey, e.getLocalizedMessage()));
        return Status.CANCEL_STATUS;
    }
    return Status.OK_STATUS;
}
Also used : TreePath(org.eclipse.jface.viewers.TreePath) TreeSelection(org.eclipse.jface.viewers.TreeSelection) XSDAnnotationsStructure(com.amalto.workbench.utils.XSDAnnotationsStructure) Element(org.w3c.dom.Element) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) XSDAnnotation(org.eclipse.xsd.XSDAnnotation) XSDComponent(org.eclipse.xsd.XSDComponent)

Aggregations

XSDAnnotation (org.eclipse.xsd.XSDAnnotation)55 Element (org.w3c.dom.Element)33 XSDElementDeclaration (org.eclipse.xsd.XSDElementDeclaration)28 XSDParticle (org.eclipse.xsd.XSDParticle)21 XSDComplexTypeDefinition (org.eclipse.xsd.XSDComplexTypeDefinition)20 XSDModelGroup (org.eclipse.xsd.XSDModelGroup)20 XSDAnnotationsStructure (com.amalto.workbench.utils.XSDAnnotationsStructure)17 ArrayList (java.util.ArrayList)16 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)16 XSDTerm (org.eclipse.xsd.XSDTerm)16 TreePath (org.eclipse.jface.viewers.TreePath)13 TreeSelection (org.eclipse.jface.viewers.TreeSelection)13 XSDComponent (org.eclipse.xsd.XSDComponent)13 XSDIdentityConstraintDefinition (org.eclipse.xsd.XSDIdentityConstraintDefinition)13 XSDSimpleTypeDefinition (org.eclipse.xsd.XSDSimpleTypeDefinition)12 XSDTypeDefinition (org.eclipse.xsd.XSDTypeDefinition)10 XSDXPathDefinition (org.eclipse.xsd.XSDXPathDefinition)10 EList (org.eclipse.emf.common.util.EList)9 XSDSchema (org.eclipse.xsd.XSDSchema)8 Iterator (java.util.Iterator)7