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