Search in sources :

Example 6 with XSDIdentityConstraintDefinition

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

the class RepositoryResourceUtil method getBusinessConceptKey.

public static WSConceptKey getBusinessConceptKey(WSGetBusinessConceptKey businessConcepKey) throws XtentisException {
    String pk = businessConcepKey.getWsDataModelPK().getPk();
    String concept = businessConcepKey.getConcept();
    WSDataModelE dataModel = RepositoryQueryService.findDataModelByName(pk);
    if (dataModel != null) {
        try {
            XSDSchema xsdSchema = Util.getXSDSchema(dataModel.getXsdSchema());
            for (XSDIdentityConstraintDefinition idDef : xsdSchema.getIdentityConstraintDefinitions()) {
                if (idDef.getName().equals(concept)) {
                    WSConceptKey key = new WSConceptKey();
                    // 
                    XSDXPathDefinition selector = idDef.getSelector();
                    key.setSelector(selector.getValue());
                    // 
                    EList<XSDXPathDefinition> fields = idDef.getFields();
                    List<String> keyFields = new ArrayList<String>();
                    for (XSDXPathDefinition pathDef : fields) {
                        keyFields.add(pathDef.getValue());
                    }
                    key.getFields().clear();
                    key.getFields().addAll(keyFields);
                    return key;
                }
            }
        } catch (Exception e) {
            log.error(e.getMessage(), e);
        }
    }
    return null;
}
Also used : WSDataModelE(org.talend.mdm.repository.model.mdmserverobject.WSDataModelE) ArrayList(java.util.ArrayList) XSDIdentityConstraintDefinition(org.eclipse.xsd.XSDIdentityConstraintDefinition) XSDXPathDefinition(org.eclipse.xsd.XSDXPathDefinition) WSConceptKey(com.amalto.workbench.webservices.WSConceptKey) CoreException(org.eclipse.core.runtime.CoreException) PartInitException(org.eclipse.ui.PartInitException) LoginException(org.talend.commons.exception.LoginException) InvocationTargetException(java.lang.reflect.InvocationTargetException) IOException(java.io.IOException) XtentisException(com.amalto.workbench.utils.XtentisException) FileNotFoundException(java.io.FileNotFoundException) PersistenceException(org.talend.commons.exception.PersistenceException) XSDSchema(org.eclipse.xsd.XSDSchema)

Example 7 with XSDIdentityConstraintDefinition

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

the class XSDDeleteConceptWrapAction method doAction.

@Override
public IStatus doAction() {
    List<IStatus> results = new ArrayList<IStatus>();
    try {
        IStructuredSelection selection = (IStructuredSelection) page.getTreeViewer().getSelection();
        if (delObjs.isEmpty()) {
            return Status.CANCEL_STATUS;
        } else {
            boolean sameType = checkInSameClassType(delObjs.toArray(), delObjs.get(0).getClass());
            String deleteLabel = Messages.DelLabel1;
            String elemDesc = ((Action) clsAction.get(delObjs.get(0).getClass())).getText();
            // $NON-NLS-1$
            int backPos = elemDesc.indexOf(" ");
            if (delObjs.size() > 1) {
                deleteLabel += elemDesc.substring(0, backPos) + Messages.DelLabel2 + delObjs.size() + Messages.DelLabel2A + (!sameType ? Messages.DelLabel2B : elemDesc.substring(backPos + 1));
                if (deleteLabel.endsWith("y")) {
                    // $NON-NLS-1$
                    deleteLabel = deleteLabel.substring(0, deleteLabel.length() - 1) + Messages.DelLabel3;
                } else {
                    deleteLabel = deleteLabel + Messages.XSDDeleteXX_DelLabel4;
                }
            } else {
                deleteLabel += elemDesc.substring(0, backPos) + Messages.XSDDeleteXX_DelLabel5 + (!sameType ? Messages.XSDDeleteXX_DelLabel5A : elemDesc.substring(backPos + 1));
            }
            if (!MessageDialog.openConfirm(page.getSite().getShell(), Messages.XSDDeleteXX_DialogTitle, deleteLabel)) {
                return Status.CANCEL_STATUS;
            }
        }
        for (Iterator iterator = delObjs.iterator(); iterator.hasNext(); ) {
            Object toDel = iterator.next();
            UndoAction delExecute = null;
            boolean isElem = true;
            if (toDel instanceof XSDElementDeclaration) {
                XSDElementDeclaration decl = (XSDElementDeclaration) toDel;
                EList l = decl.getIdentityConstraintDefinitions();
                for (Iterator iter = l.iterator(); iter.hasNext(); ) {
                    XSDIdentityConstraintDefinition icd = (XSDIdentityConstraintDefinition) iter.next();
                    if (icd.getIdentityConstraintCategory().equals(XSDIdentityConstraintCategory.UNIQUE_LITERAL)) {
                        isElem = false;
                        break;
                    }
                }
            }
            if (toDel instanceof XSDXPathDefinition) {
                XSDXPathDefinition xpath = (XSDXPathDefinition) toDel;
                if (!xpath.getVariety().equals(XSDXPathVariety.FIELD_LITERAL)) {
                    continue;
                }
            }
            delExecute = clsAction.get(toDel.getClass());
            if (isElem && toDel instanceof XSDElementDeclaration) {
                delExecute = clsAction.get(null);
            }
            if (delExecute instanceof XSDDeleteConceptAction && toDel instanceof XSDElementDeclaration) {
                ((XSDDeleteConceptAction) delExecute).setXSDTODel((XSDElementDeclaration) toDel);
            } else if (delExecute instanceof XSDDeleteElementAction && toDel instanceof XSDElementDeclaration) {
                ((XSDDeleteElementAction) delExecute).setXSDTODel((XSDElementDeclaration) toDel);
            } else if (delExecute instanceof XSDDeleteParticleAction && toDel instanceof XSDParticle) {
                ((XSDDeleteParticleAction) delExecute).setXSDTODel((XSDParticle) toDel);
            } else if (delExecute instanceof XSDDeleteXPathAction && toDel instanceof XSDXPathDefinition) {
                ((XSDDeleteXPathAction) delExecute).setXSDTODel((XSDXPathDefinition) toDel);
            } else if (delExecute instanceof XSDDeleteIdentityConstraintAction && toDel instanceof XSDIdentityConstraintDefinition) {
                ((XSDDeleteIdentityConstraintAction) delExecute).setXSDTODel((XSDIdentityConstraintDefinition) toDel);
            } else if (delExecute instanceof XSDDeleteTypeDefinition && toDel instanceof XSDComplexTypeDefinition) {
                ((XSDDeleteTypeDefinition) delExecute).setXSDTODel((XSDComplexTypeDefinition) toDel);
            } else if (delExecute instanceof XSDDeleteTypeDefinition && toDel instanceof XSDSimpleTypeDefinition) {
                ((XSDDeleteTypeDefinition) delExecute).setXSDTODel((XSDSimpleTypeDefinition) toDel);
            } else if (delExecute instanceof XSDDeleteAttributeAction && toDel instanceof XSDAttributeUse) {
                ((XSDDeleteAttributeAction) delExecute).setXSDAttributeUse((XSDAttributeUse) toDel);
            } else if (delExecute instanceof XSDDeleteAttributeAction && toDel instanceof XSDAttributeDeclaration) {
                ((XSDDeleteAttributeAction) delExecute).setXSDAttribute((XSDAttributeDeclaration) toDel);
            } else {
                return Status.CANCEL_STATUS;
            }
            results.add(delExecute.execute());
        }
    } catch (Exception e) {
        log.error(e.getMessage(), e);
        MessageDialog.openError(page.getSite().getShell(), Messages._Error, Messages.bind(Messages.XSDDeleteXX_ErrorMsg, e.getLocalizedMessage()));
        return (results.indexOf(Status.OK_STATUS) >= 0 ? Status.OK_STATUS : Status.CANCEL_STATUS);
    }
    return (results.indexOf(Status.OK_STATUS) >= 0 ? Status.OK_STATUS : Status.CANCEL_STATUS);
}
Also used : IStatus(org.eclipse.core.runtime.IStatus) Action(org.eclipse.jface.action.Action) XSDAttributeUse(org.eclipse.xsd.XSDAttributeUse) ArrayList(java.util.ArrayList) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) Iterator(java.util.Iterator) XSDXPathDefinition(org.eclipse.xsd.XSDXPathDefinition) XSDComplexTypeDefinition(org.eclipse.xsd.XSDComplexTypeDefinition) XSDParticle(org.eclipse.xsd.XSDParticle) XSDSimpleTypeDefinition(org.eclipse.xsd.XSDSimpleTypeDefinition) EList(org.eclipse.emf.common.util.EList) XSDElementDeclaration(org.eclipse.xsd.XSDElementDeclaration) XSDIdentityConstraintDefinition(org.eclipse.xsd.XSDIdentityConstraintDefinition) XSDAttributeDeclaration(org.eclipse.xsd.XSDAttributeDeclaration)

Example 8 with XSDIdentityConstraintDefinition

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

the class XSDDeleteIdentityConstraintAction method doAction.

public IStatus doAction() {
    try {
        // xsdIdenty is to support the multiple delete action on key press,
        // which each delete action on identity must be explicit passed a xsd key to
        // delete
        XSDIdentityConstraintDefinition constraint = xsdIdenty;
        XSDElementDeclaration decl = null;
        if (constraint != null) {
            decl = (XSDElementDeclaration) constraint.getContainer();
            if (decl == null)
                return Status.CANCEL_STATUS;
        }
        if (decl == null) {
            IStructuredSelection selection = (IStructuredSelection) page.getTreeViewer().getSelection();
            constraint = (XSDIdentityConstraintDefinition) selection.getFirstElement();
            decl = (XSDElementDeclaration) constraint.getContainer();
        }
        /*
             * REMOVE so that simple elements can be made if (
             * (constraint.getIdentityConstraintCategory().equals(XSDIdentityConstraintCategory.UNIQUE_LITERAL)) &&
             * (decl.getContainer().equals(decl.getSchema())) ) { MessageDialog.openError(
             * this.page.getSite().getShell(), "Error", "Entities must have an unique key" ); return; }
             */
        decl.getIdentityConstraintDefinitions().remove(constraint);
        decl.updateElement();
        xsdIdenty = null;
        page.refresh();
        page.markDirty();
    } catch (Exception e) {
        log.error(e.getMessage(), e);
        MessageDialog.openError(page.getSite().getShell(), Messages._Error, Messages.bind(Messages.XSDDeleteXX_ErrorMsg, e.getLocalizedMessage()));
        return Status.CANCEL_STATUS;
    }
    return Status.OK_STATUS;
}
Also used : XSDElementDeclaration(org.eclipse.xsd.XSDElementDeclaration) XSDIdentityConstraintDefinition(org.eclipse.xsd.XSDIdentityConstraintDefinition) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection)

Example 9 with XSDIdentityConstraintDefinition

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

the class XSDDeleteXPathAction method doAction.

public IStatus doAction() {
    try {
        // xsdPath is to support the multiple delete action on key press,
        // which each delete action on xpath must be explicit passed a xsd path to
        // delete
        XSDXPathDefinition xpath = xsdPath;
        if (xpath == null) {
            ISelection selection = page.getTreeViewer().getSelection();
            xpath = (XSDXPathDefinition) ((IStructuredSelection) selection).getFirstElement();
        }
        XSDIdentityConstraintDefinition icd = (XSDIdentityConstraintDefinition) xpath.getContainer();
        if (icd == null)
            return Status.CANCEL_STATUS;
        if (xpath.getVariety().equals(XSDXPathVariety.SELECTOR_LITERAL)) {
            MessageDialog.openError(page.getSite().getShell(), Messages._Error, Messages.XSDDeleteXPathAction_SelectorCannotDel);
            return Status.CANCEL_STATUS;
        }
        if (icd.getFields().size() == 1) {
            MessageDialog.openError(page.getSite().getShell(), Messages._Error, Messages.XSDDeleteXPathAction_KeyMustContainOne);
            return Status.CANCEL_STATUS;
        }
        icd.getFields().remove(xpath);
        icd.updateElement();
        xsdPath = null;
        page.refresh();
        page.markDirty();
    } catch (Exception e) {
        log.error(e.getMessage(), e);
        MessageDialog.openError(page.getSite().getShell(), Messages._Error, Messages.bind(Messages.XSDDeleteXPathAction_ErrorRemoveAField, e.getLocalizedMessage()));
        return Status.CANCEL_STATUS;
    }
    return Status.OK_STATUS;
}
Also used : ISelection(org.eclipse.jface.viewers.ISelection) XSDIdentityConstraintDefinition(org.eclipse.xsd.XSDIdentityConstraintDefinition) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) XSDXPathDefinition(org.eclipse.xsd.XSDXPathDefinition)

Example 10 with XSDIdentityConstraintDefinition

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

the class XSDEditConceptAction method doAction.

@Override
public IStatus doAction() {
    try {
        ISelection selection = page.getTreeViewer().getSelection();
        XSDElementDeclaration decl = (XSDElementDeclaration) ((IStructuredSelection) selection).getFirstElement();
        ArrayList<Object> objList = new ArrayList<Object>();
        IStructuredContentProvider provider = (IStructuredContentProvider) page.getTreeViewer().getContentProvider();
        String oldName = decl.getName();
        InputDialog id = new InputDialog(page.getSite().getShell(), Messages.XSDEditConceptAction_Text, Messages.XSDEditConceptAction_DialogTip, oldName, new IInputValidator() {

            public String isValid(String newText) {
                if ((newText == null) || "".equals(newText)) {
                    return Messages.XSDEditConceptAction_NameCannotBeEmpty;
                }
                if (// $NON-NLS-1$
                Pattern.compile("^\\s+\\w+\\s*").matcher(newText).matches() || newText.trim().replaceAll("\\s", "").length() != newText.trim().length()) {
                    return Messages.XSDEditConceptAction_NameCannotContainEmpty;
                }
                if (!XSDUtil.isValidatedXSDName(newText)) {
                    return Messages.InvalidName_Message;
                }
                EList list = schema.getElementDeclarations();
                for (Iterator iter = list.iterator(); iter.hasNext(); ) {
                    XSDElementDeclaration d = (XSDElementDeclaration) iter.next();
                    if (d.getName().equalsIgnoreCase(newText.trim())) {
                        return Messages.XSDEditConceptAction_EntityAlreadyExist;
                    }
                }
                return null;
            }
        });
        id.setBlockOnOpen(true);
        int ret = id.open();
        if (ret == Dialog.CANCEL) {
            return Status.CANCEL_STATUS;
        }
        Object[] objs = Util.getAllObject(page.getSite(), objList, provider);
        Object[] allForeignKeyRelatedInfos = Util.getAllForeignKeyRelatedInfos(page.getSite(), new ArrayList<Object>(), provider, new HashSet<Object>());
        String newName = id.getValue().trim();
        decl.setName(newName);
        decl.updateElement();
        Util.updateReference(decl, objs, allForeignKeyRelatedInfos, oldName, newName);
        EntitySyncProcessor.syncNameForAnnotation(decl, oldName, newName);
        if (mapinfoExAdapter != null) {
            mapinfoExAdapter.renameEntityMapinfo(oldName, newName);
        }
        if (elementExAdapter != null) {
            elementExAdapter.renameEntityName(decl.getSchema(), oldName, newName);
        }
        // change unique key with new name of concept
        EList list = decl.getIdentityConstraintDefinitions();
        XSDIdentityConstraintDefinition toUpdate = null;
        for (Iterator iter = list.iterator(); iter.hasNext(); ) {
            XSDIdentityConstraintDefinition icd = (XSDIdentityConstraintDefinition) iter.next();
            if (icd.getName().equals(oldName)) {
                toUpdate = icd;
                break;
            }
        }
        if (toUpdate != null) {
            toUpdate.setName(newName);
            toUpdate.updateElement();
        }
        page.refresh();
        page.markDirty();
    // page.refreshPage();
    } catch (Exception e) {
        log.error(e.getMessage(), e);
        MessageDialog.openError(page.getSite().getShell(), Messages._Error, Messages.bind(Messages.XSDEditConceptAction_ErrorMsg, e.getLocalizedMessage()));
        return Status.CANCEL_STATUS;
    }
    return Status.OK_STATUS;
}
Also used : InputDialog(org.eclipse.jface.dialogs.InputDialog) ArrayList(java.util.ArrayList) EList(org.eclipse.emf.common.util.EList) XSDElementDeclaration(org.eclipse.xsd.XSDElementDeclaration) ISelection(org.eclipse.jface.viewers.ISelection) IStructuredContentProvider(org.eclipse.jface.viewers.IStructuredContentProvider) Iterator(java.util.Iterator) XSDIdentityConstraintDefinition(org.eclipse.xsd.XSDIdentityConstraintDefinition) IInputValidator(org.eclipse.jface.dialogs.IInputValidator)

Aggregations

XSDIdentityConstraintDefinition (org.eclipse.xsd.XSDIdentityConstraintDefinition)56 XSDElementDeclaration (org.eclipse.xsd.XSDElementDeclaration)38 XSDXPathDefinition (org.eclipse.xsd.XSDXPathDefinition)32 XSDComplexTypeDefinition (org.eclipse.xsd.XSDComplexTypeDefinition)21 ArrayList (java.util.ArrayList)20 XSDParticle (org.eclipse.xsd.XSDParticle)19 XSDModelGroup (org.eclipse.xsd.XSDModelGroup)18 XSDSimpleTypeDefinition (org.eclipse.xsd.XSDSimpleTypeDefinition)18 Iterator (java.util.Iterator)15 XSDTypeDefinition (org.eclipse.xsd.XSDTypeDefinition)14 XSDAnnotation (org.eclipse.xsd.XSDAnnotation)13 XSDAttributeGroupDefinition (org.eclipse.xsd.XSDAttributeGroupDefinition)13 XSDFactory (org.eclipse.xsd.XSDFactory)13 XSDSchema (org.eclipse.xsd.XSDSchema)13 EList (org.eclipse.emf.common.util.EList)12 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)11 XSDAttributeDeclaration (org.eclipse.xsd.XSDAttributeDeclaration)10 XSDTerm (org.eclipse.xsd.XSDTerm)10 Element (org.w3c.dom.Element)10 TreeObject (com.amalto.workbench.models.TreeObject)9