use of com.amalto.workbench.models.TreeObject in project tmdm-studio-se by Talend.
the class LocalTreeObjectRepository method parseElementForOutput.
public void parseElementForOutput(TreeObject[] xobjs) {
for (TreeObject xobj : xobjs) {
TreeObject subParent = xobj;
while (subParent.getParent().getType() != 0) {
subParent = subParent.getParent();
}
Element modelElem = getParentElement(subParent);
if (!outPutSchemas.containsKey(modelElem.getName())) {
Element copyElem = (Element) modelElem.clone();
copyElem.clearContent();
copyElem.setText(modelElem.getTextTrim());
outPutSchemas.put(modelElem.getName(), copyElem);
}
subParent = xobj;
TreeObject categorySubRoot = null;
while (subParent.getParent().getType() == TreeObject.CATEGORY_FOLDER) {
categorySubRoot = subParent.getParent();
subParent = subParent.getParent();
}
Element divisionElem = null;
Element copyModelElem = outPutSchemas.get(modelElem.getName());
Document doc = credentials.get(UnifyUrl(xobj.getServerRoot().getWsKey().toString())).doc;
// $NON-NLS-1$//$NON-NLS-2$
String division = xobj.getType() == TreeObject.TRANSFORMER ? "Process" : "Trigger";
// $NON-NLS-1$//$NON-NLS-2$//$NON-NLS-3$
String xpathForDivision = ".//child::" + division + "[text()='" + xobj.getType() + "']";
if (categorySubRoot != null) {
Element categoryElem = getParentElement(categorySubRoot);
if (categoryElem.getParent() != modelElem) {
divisionElem = pingElement(xpathForDivision, copyModelElem);
if (divisionElem == null) {
divisionElem = copyModelElem.addElement(categoryElem.getParent().getName());
divisionElem.setText(categoryElem.getParent().getTextTrim());
}
} else {
divisionElem = copyModelElem;
}
Element categoryElementClone = (Element) categoryElem.clone();
// $NON-NLS-1$//$NON-NLS-2$//$NON-NLS-3$
String xpath = "./child::" + categoryElem.getName() + "[text()='" + TreeObject.CATEGORY_FOLDER + "']";
if (divisionElem.selectNodes(xpath).size() == 0) {
divisionElem.add(categoryElementClone);
}
} else {
// individual xobject
Element xobjElem = pingElement(getXPathForTreeObject(xobj), doc.getRootElement());
Element parentElem = xobjElem.getParent();
if (parentElem == modelElem) {
parentElem = copyModelElem;
} else {
divisionElem = pingElement(xpathForDivision, copyModelElem);
if (divisionElem == null) {
divisionElem = copyModelElem.addElement(parentElem.getName());
divisionElem.setText(parentElem.getTextTrim());
}
}
// $NON-NLS-1$//$NON-NLS-2$//$NON-NLS-3$
String xpath = ".//child::" + xobjElem.getName() + "[text()='" + xobjElem.getTextTrim() + "']";
if (divisionElem != null && pingElement(xpath, divisionElem) == null) {
divisionElem.add((Element) xobjElem.clone());
}
}
}
// filter those excluded from xobjects out of categorys
// $NON-NLS-1$//$NON-NLS-2$
String xpath = ".//descendant::*[text() ='" + TreeObject.CATEGORY_FOLDER + "']";
Iterator<Element> iter = outPutSchemas.values().iterator();
while (iter.hasNext()) {
Element divisionElement = iter.next();
List<Element> categorys = divisionElement.selectNodes(xpath);
if (categorys != null) {
for (Element categoryElems : categorys) {
List objs = categoryElems.content();
List<Element> elemToDel = new ArrayList<Element>();
for (Object obj : objs) {
if (obj instanceof Element) {
Element categoryElement = (Element) obj;
if (categoryElement.getTextTrim().equals(TreeObject.CATEGORY_FOLDER + "")) {
continue;
}
boolean match = false;
for (TreeObject xobj : xobjs) {
if (filterOutBlank(xobj.getDisplayName()).equals(categoryElement.getName()) && categoryElement.getTextTrim().equals(xobj.getType() + "")) {
// $NON-NLS-1$
match = true;
break;
}
}
if (!match) {
elemToDel.add(categoryElement);
}
}
}
for (Element del : elemToDel) {
categoryElems.remove(del);
}
}
}
}
ArrayList<String> schemas = new ArrayList<String>();
Iterator<Element> iterd = outPutSchemas.values().iterator();
while (iterd.hasNext()) {
schemas.add(iterd.next().asXML());
}
}
use of com.amalto.workbench.models.TreeObject in project tmdm-studio-se by Talend.
the class LocalTreeObjectRepository method checkUpCatalogHavingNoChildren.
private void checkUpCatalogHavingNoChildren(TreeObject theObj, TreeParent folder) {
if (folder.getServerRoot() == folder || theObj.getServerRoot() == null) {
return;
}
if (folder.getServerRoot() == null) {
return;
}
Document doc = credentials.get(UnifyUrl(folder.getServerRoot().getWsKey().toString())).doc;
String path = this.getXPathForTreeObject(folder);
List<Element> topElems = doc.selectNodes(path);
if (topElems.size() > 0 && folder.getParent() != null) {
if (isAEXtentisObjects(topElems.get(0), folder) == XTENTIS_LEVEL && folder.getParent().getType() == 23) {
if (topElems.get(0).getParent() != null) {
if (isAEXtentisObjects(topElems.get(0).getParent(), folder) == MODEL_LEVEL && folder.getType() == 24) {
// $NON-NLS-1$
accommodations.add("Resources");
}
}
}
}
// $NON-NLS-1$
String accmds = "";
for (String accmd : accommodations) {
if (accmd == accommodations.get(0)) {
// $NON-NLS-1$
accmds = "/";
}
accmds += accmd;
if (accmd != accommodations.get(accommodations.size() - 1)) {
// $NON-NLS-1$
accmds += "//";
}
}
String username = theObj.getServerRoot().getUser().getUsername();
String xpath = // $NON-NLS-1$//$NON-NLS-2$
"//" + transformForXPath(username) + accmds + "/" + filterOutBlank(folder.getDisplayName()) + "//child::*[text() = '" + // $NON-NLS-1$
TreeObject.CATEGORY_FOLDER + "' and @Url='" + // $NON-NLS-1$
getURLFromTreeObject(theObj) + // $NON-NLS-1$
"' and count(child::*) = 0]";
TreeParent subFolder = folder;
List<Element> elems = doc.selectNodes(xpath);
for (Element elem : elems) {
String xpaths = getXPathForElem(elem);
int modelPos = xpaths.indexOf(filterOutBlank(folder.getDisplayName()));
if (modelPos == -1) {
// $NON-NLS-1$
System.err.println("elem.getName() is in wrong position !!!");
return;
}
xpaths = xpaths.substring(modelPos + filterOutBlank(folder.getDisplayName()).length() + 1);
// $NON-NLS-1$
modelPos = xpaths.indexOf("/");
String xpathTrack = getXPathForElem(elem).substring(0, getXPathForElem(elem).indexOf(xpaths) - 1);
while (modelPos != -1 || (!xpaths.equals("") && modelPos == -1)) {
// $NON-NLS-1$
String nodeName = modelPos != -1 ? xpaths.substring(0, modelPos) : xpaths;
// $NON-NLS-1$
xpathTrack += "/" + nodeName;
List<Element> parnts = doc.selectNodes(xpathTrack);
if (parnts.size() > 0 && parnts.get(0).attributeValue(REALNAME) != null) {
nodeName = parnts.get(0).attributeValue(REALNAME);
}
boolean catalogExist = false;
for (TreeObject child : subFolder.getChildren()) {
if (nodeName.equals(child.getDisplayName()) && child.getType() == TreeObject.CATEGORY_FOLDER) {
catalogExist = true;
subFolder = (TreeParent) child;
break;
}
}
if (!catalogExist) {
if (parnts.size() > 0 && parnts.get(0).getText().equals(TreeObject.CATEGORY_FOLDER)) {
TreeParent catalog = new TreeParent(nodeName, folder.getServerRoot(), TreeObject.CATEGORY_FOLDER, null, null);
subFolder.addChild(catalog);
subFolder = catalog;
}
}
if (xpaths.indexOf("/") != -1) {
// $NON-NLS-1$
xpaths = xpaths.substring(modelPos + 1);
// $NON-NLS-1$
modelPos = xpaths.indexOf("/");
} else {
// $NON-NLS-1$
xpaths = "";
}
}
subFolder = folder;
}
accommodations.clear();
}
use of com.amalto.workbench.models.TreeObject in project tmdm-studio-se by Talend.
the class LocalTreeObjectRepository method synchronizeWithElem.
private String synchronizeWithElem(TreeObject theObj, TreeParent folder, boolean fireEvent) {
internalCheck = fireEvent;
// $NON-NLS-1$
String catalogPath = "";
ArrayList<String> catalogs = checkUpCatalogRepositoryForTreeObject(theObj, folder);
if (catalogs != null && folder.getType() != TreeObject.CATEGORY_FOLDER) {
// create a catalog folder and insert the theObj into it
TreeParent subFolder = folder;
TreeParent category = null;
for (String catalogName : catalogs) {
// if (catalogName.equals(filterOutBlank(folder.getDisplayName())))
// continue;
category = null;
for (TreeObject child : subFolder.getChildren()) {
if (child.getDisplayName().equals(catalogName) && child.getType() == TreeObject.CATEGORY_FOLDER && child instanceof TreeParent) {
category = (TreeParent) child;
subFolder = category;
break;
}
}
if (category == null) {
category = new TreeParent(catalogName, folder.getServerRoot(), TreeObject.CATEGORY_FOLDER, null, null);
subFolder.addChild(category);
category.setServerRoot(folder.getServerRoot());
addAttributeToCategoryElem(category, URL, getURLFromTreeObject(folder));
saveDocument(folder);
subFolder = category;
}
}
boolean exist = false;
for (TreeObject obj : category.getChildren()) {
if (obj.getDisplayName().equals(theObj.getDisplayName()) && obj.getType() == theObj.getType()) {
exist = true;
break;
}
}
if (!exist) {
folder.removeChild(theObj);
category.addChild(theObj);
}
// $NON-NLS-1$
catalogPath = catalogs.isEmpty() ? "" : catalogs.get(0);
} else {
// into it if these objects are not categorized
if (XSystemObjects.isExist(theObj.getType(), theObj.getDisplayName())) {
TreeParent systemCatalog = null;
for (TreeObject xobj : folder.getChildren()) {
if (DEFAULT_CATALOG.equals(filterOutBlank(xobj.getDisplayName())) && xobj.getType() == TreeObject.CATEGORY_FOLDER) {
systemCatalog = (TreeParent) xobj;
break;
}
}
if (folder.getDisplayName().equals("System") && folder.getType() == TreeObject.CATEGORY_FOLDER) {
return DEFAULT_CATALOG;
}
if (theObj.getParent() == null) {
internalCheck = !fireEvent;
return DEFAULT_CATALOG;
}
if (theObj.getServerRoot() != null) {
String username = theObj.getServerRoot().getUser().getUsername();
String xpath = // $NON-NLS-1$//$NON-NLS-2$
"//" + transformForXPath(username) + "/" + filterOutBlank(folder.getDisplayName()) + // $NON-NLS-1$
"//child::*[name() = 'System'" + " and @Url='" + getURLFromTreeObject(theObj) + // $NON-NLS-1$//$NON-NLS-2$
"']";
Document doc = credentials.get(UnifyUrl(folder.getServerRoot().getWsKey().toString())).doc;
if (systemCatalog == null) {
List<Element> elems = doc.selectNodes(xpath);
if (elems.isEmpty()) {
systemCatalog = new TreeParent(DEFAULT_CATALOG, folder.getServerRoot(), TreeObject.CATEGORY_FOLDER, null, null);
folder.addChild(systemCatalog);
folder.removeChild(theObj);
systemCatalog.addChild(theObj);
systemCatalog.setServerRoot(folder.getServerRoot());
Element elemFolder = getParentElement(folder);
Element elemSystem = elemFolder.addElement(systemCatalog.getDisplayName());
// $NON-NLS-1$
elemSystem.setText(TreeObject.CATEGORY_FOLDER + "");
elemSystem.addAttribute(URL, getURLFromTreeObject(folder));
Element childElem = elemSystem.addElement(filterOutBlank(theObj.getDisplayName()));
// $NON-NLS-1$
childElem.setText(theObj.getType() + "");
saveDocument(folder);
}
} else {
boolean exist = false;
for (TreeObject xbj : systemCatalog.getChildren()) {
if (xbj.getDisplayName().equals(theObj.getDisplayName()) && xbj.getType() == theObj.getType()) {
exist = true;
break;
}
}
if (!exist) {
folder.removeChild(theObj);
systemCatalog.addChild(theObj);
List<Element> elems = doc.selectNodes(xpath);
if (!elems.isEmpty()) {
// $NON-NLS-1$
elems.get(0).addElement(filterOutBlank(theObj.getDisplayName())).setText(theObj.getType() + "");
saveDocument(folder);
}
}
}
}
catalogPath = DEFAULT_CATALOG;
}
}
// check up the catalog with none children
checkUpCatalogHavingNoChildren(theObj, folder);
if (theObj instanceof TreeParent) {
TreeParent subParent = (TreeParent) theObj;
for (TreeObject obj : subParent.getChildren()) {
synchronizeWithElem(obj, subParent, fireEvent);
}
}
internalCheck = !fireEvent;
return catalogPath;
}
use of com.amalto.workbench.models.TreeObject in project tmdm-studio-se by Talend.
the class LocalTreeObjectRepository method getTreeItemFromTreeObject.
private void getTreeItemFromTreeObject(TreeItem[] items, TreeObject xobj, ArrayList<TreeItem> ret) {
for (TreeItem o : items) {
TreeObject treeObj = (TreeObject) o.getData();
if (equalTermsWithTreeObject(treeObj, xobj)) {
ret.add(o);
return;
}
getTreeItemFromTreeObject(o.getItems(), xobj, ret);
}
}
use of com.amalto.workbench.models.TreeObject in project tmdm-studio-se by Talend.
the class Util method createCompDropTarget.
// add this method for the text drop action of all the texts available.
public static void createCompDropTarget(final Text text) {
DropTarget dropTarget = new DropTarget(text, DND.DROP_MOVE | DND.DROP_LINK);
dropTarget.setTransfer(new TreeObjectTransfer[] { TreeObjectTransfer.getInstance() });
dropTarget.addDropListener(new DropTargetAdapter() {
@Override
public void dragEnter(DropTargetEvent event) {
}
@Override
public void dragLeave(DropTargetEvent event) {
}
@Override
public void dragOver(DropTargetEvent event) {
event.feedback |= DND.FEEDBACK_EXPAND | DND.FEEDBACK_SCROLL;
}
@Override
public void drop(DropTargetEvent event) {
if (event.data instanceof TreeObject[]) {
text.setText(text.getText() + ((TreeObject[]) event.data)[0].getDisplayName());
}
}
});
}
Aggregations