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