Search in sources :

Example 1 with CommitException

use of com.amalto.workbench.detailtabs.exception.CommitException in project tmdm-studio-se by Talend.

the class ElementForeignKeyInfosCommitHandler method doSubmit.

@Override
protected boolean doSubmit() throws CommitException {
    XSDAnnotationsStructure xsdAnnoStruct = getXSDAnnotationStruct();
    try {
        xsdAnnoStruct.setForeignKeyInfos(Arrays.asList(getCommitedObj().getInfos()));
        xsdAnnoStruct.setFormatForeignKeyInfo(getCommitedObj().getFormatFkInfo());
        doUpdateFKAnnotationStructure(xsdAnnoStruct);
    } catch (Exception e) {
        throw new CommitException(e.getMessage(), e);
    }
    return true;
}
Also used : CommitException(com.amalto.workbench.detailtabs.exception.CommitException) XSDAnnotationsStructure(com.amalto.workbench.utils.XSDAnnotationsStructure) CommitException(com.amalto.workbench.detailtabs.exception.CommitException) CommitValidationException(com.amalto.workbench.detailtabs.exception.CommitValidationException)

Example 2 with CommitException

use of com.amalto.workbench.detailtabs.exception.CommitException in project tmdm-studio-se by Talend.

the class ElementWrapperCommitHandler method doSubmit.

@Override
protected boolean doSubmit() throws CommitException {
    try {
        String originalName = getCommitedObj().getSourceName();
        XSDElementDeclaration decl = getCommitedObj().getSourceXSDContent();
        XSDElementDeclaration ref = null;
        if (decl.isElementDeclarationReference()) {
            ref = decl.getResolvedElementDeclaration();
        }
        XSDAnnotationsStructure struct = new XSDAnnotationsStructure(getCommitedObj().getSourceElement());
        // remove first
        // struct.setAutoExpand(null);
        struct.setAutoExpand(String.valueOf(getCommitedObj().isAutoExpand()));
        // update validation rule
        Set<String> paths = new HashSet<String>();
        DataModelMainPage page = getPage();
        Util.collectElementPaths((IStructuredContentProvider) page.getElementsViewer().getContentProvider(), page.getSite(), getCommitedObj().getSourceElement(), paths, null);
        XSDElementDeclaration newRef = Util.findReference(getCommitedObj().getNewReference(), getCommitedObj().getSchema());
        XSDIdentityConstraintDefinition identify = null;
        XSDXPathDefinition keyPath = null;
        List<Object> keyInfo = Util.getKeyInfo(getCommitedObj().getSourceXSDContent());
        if (keyInfo != null && keyInfo.size() > 0) {
            identify = (XSDIdentityConstraintDefinition) keyInfo.get(0);
            keyPath = (XSDXPathDefinition) keyInfo.get(1);
            identify.getFields().remove(keyPath);
        }
        getCommitedObj().getSourceXSDContent().setName(// $NON-NLS-1$
        "".equals(getCommitedObj().getNewName()) ? null : getCommitedObj().getNewName());
        if (keyPath != null) {
            XSDFactory factory = XSDSchemaBuildingTools.getXSDFactory();
            XSDXPathDefinition field = factory.createXSDXPathDefinition();
            field.setVariety(keyPath.getVariety());
            field.setValue(getCommitedObj().getNewName());
            identify.getFields().add(field);
        }
        if (newRef != null) {
            decl.setResolvedElementDeclaration(newRef);
            decl.setTypeDefinition(null);
            Element elem = decl.getElement();
            if (elem.getAttributes().getNamedItem("type") != null) {
                // $NON-NLS-1$
                elem.getAttributes().removeNamedItem("type");
            }
            decl.updateElement();
        } else if (ref != null) {
            XSDElementDeclaration sourceXSDContent = getCommitedObj().getSourceXSDContent();
            sourceXSDContent.setTypeDefinition(getCommitedObj().getSchema().getSchemaForSchema().resolveSimpleTypeDefinition(XSDConstants.SCHEMA_FOR_SCHEMA_URI_2001, // $NON-NLS-1$
            "string"));
            sourceXSDContent.setResolvedElementDeclaration(sourceXSDContent);
        // XSDFactory factory = XSDSchemaBuildingTools.getXSDFactory();
        // XSDElementDeclaration newD = (XSDElementDeclaration) factory.createXSDElementDeclaration();
        // newD.setName(getCommitedObj().getNewName());
        // newD.updateElement();
        // XSDSimpleTypeDefinition stringType = getCommitedObj().getSchema().getSchemaForSchema()
        // .resolveSimpleTypeDefinition(XSDConstants.SCHEMA_FOR_SCHEMA_URI_2001, "string");
        // 
        // newD.setTypeDefinition(stringType);
        // if (getCommitedObj().getSourceElement().getContainer() instanceof XSDModelGroup) {
        // XSDModelGroup group = ((XSDModelGroup) getCommitedObj().getSourceElement().getContainer());
        // ((XSDModelGroup) getCommitedObj().getSourceElement().getContainer()).getContents().remove(
        // getCommitedObj().getSourceElement());
        // getCommitedObj().setSourceElement(factory.createXSDParticle());
        // getCommitedObj().getSourceElement().setContent(newD);
        // group.getContents().add(getCommitedObj().getSourceElement());
        // }
        }
        int newMaxOcur = getCommitedObj().getNewMaxOcur();
        if (Util.changeElementTypeToSequence(decl, newMaxOcur) == Status.CANCEL_STATUS) {
            return false;
        }
        int newMinOcur = getCommitedObj().getNewMinOcur();
        getCommitedObj().getSourceElement().setMinOccurs(newMinOcur);
        if (newMaxOcur == -1 || (newMaxOcur == 0 & newMinOcur == 0)) {
            if (!"unbounded".equals(getCommitedObj().getSourceElement().getElement().getAttribute("maxOccurs"))) {
                // $NON-NLS-1$//$NON-NLS-2$
                getCommitedObj().getSourceElement().getElement().setAttribute("maxOccurs", "unbounded");
            }
        } else {
            getCommitedObj().getSourceElement().setMaxOccurs(newMaxOcur);
        }
        getCommitedObj().getSourceElement().updateElement();
        updateReference(originalName);
        if (elementExAdapter != null) {
            elementExAdapter.renameElement(getCommitedObj().getSchema(), paths, getCommitedObj().getNewName());
        }
        if (mapinfoExAdapter != null) {
            mapinfoExAdapter.renameElementMapinfo(paths, decl.getName());
        }
    } catch (Exception e) {
        throw new CommitException(e.getMessage(), e);
    }
    return true;
}
Also used : CommitException(com.amalto.workbench.detailtabs.exception.CommitException) XSDFactory(org.eclipse.xsd.XSDFactory) XSDAnnotationsStructure(com.amalto.workbench.utils.XSDAnnotationsStructure) Element(org.w3c.dom.Element) DataModelMainPage(com.amalto.workbench.editors.DataModelMainPage) CommitValidationException(com.amalto.workbench.detailtabs.exception.CommitValidationException) CommitException(com.amalto.workbench.detailtabs.exception.CommitException) XSDElementDeclaration(org.eclipse.xsd.XSDElementDeclaration) XSDIdentityConstraintDefinition(org.eclipse.xsd.XSDIdentityConstraintDefinition) XSDXPathDefinition(org.eclipse.xsd.XSDXPathDefinition) HashSet(java.util.HashSet)

Example 3 with CommitException

use of com.amalto.workbench.detailtabs.exception.CommitException in project tmdm-studio-se by Talend.

the class ElementForeignKeyFilterCommitHandler method doSubmit.

@Override
protected boolean doSubmit() throws CommitException {
    XSDAnnotationsStructure xsdAnnoStruct = getXSDAnnotationStruct();
    try {
        xsdAnnoStruct.setFKFilter(getCommitedObj().getValue());
        doUpdateFKAnnotationStructure(xsdAnnoStruct);
    } catch (Exception e) {
        throw new CommitException(e.getMessage(), e);
    }
    return true;
}
Also used : CommitException(com.amalto.workbench.detailtabs.exception.CommitException) XSDAnnotationsStructure(com.amalto.workbench.utils.XSDAnnotationsStructure) CommitException(com.amalto.workbench.detailtabs.exception.CommitException) CommitValidationException(com.amalto.workbench.detailtabs.exception.CommitValidationException)

Aggregations

CommitException (com.amalto.workbench.detailtabs.exception.CommitException)3 CommitValidationException (com.amalto.workbench.detailtabs.exception.CommitValidationException)3 XSDAnnotationsStructure (com.amalto.workbench.utils.XSDAnnotationsStructure)3 DataModelMainPage (com.amalto.workbench.editors.DataModelMainPage)1 HashSet (java.util.HashSet)1 XSDElementDeclaration (org.eclipse.xsd.XSDElementDeclaration)1 XSDFactory (org.eclipse.xsd.XSDFactory)1 XSDIdentityConstraintDefinition (org.eclipse.xsd.XSDIdentityConstraintDefinition)1 XSDXPathDefinition (org.eclipse.xsd.XSDXPathDefinition)1 Element (org.w3c.dom.Element)1