Search in sources :

Example 31 with TreeParent

use of com.amalto.workbench.models.TreeParent 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();
}
Also used : TreeParent(com.amalto.workbench.models.TreeParent) Element(org.dom4j.Element) TreeObject(com.amalto.workbench.models.TreeObject) Document(org.dom4j.Document)

Example 32 with TreeParent

use of com.amalto.workbench.models.TreeParent 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;
}
Also used : TreeParent(com.amalto.workbench.models.TreeParent) Element(org.dom4j.Element) TreeObject(com.amalto.workbench.models.TreeObject) Document(org.dom4j.Document)

Example 33 with TreeParent

use of com.amalto.workbench.models.TreeParent in project tmdm-studio-se by Talend.

the class LocalTreeObjectRepository method registerNewTreeObject.

public TreeObject registerNewTreeObject(TreeObject treeObject) {
    if (treeObject.getType() == TreeObject.CATEGORY_FOLDER) {
        String xpath = getXPathForTreeObject(treeObject);
        Document doc = credentials.get(UnifyUrl(treeObject.getServerRoot().getWsKey().toString())).doc;
        List<Element> elems = doc.selectNodes(xpath);
        if (!elems.isEmpty()) {
            if (catalogTreeObj == null) {
                catalogTreeObj = elems.get(0);
            }
        }
        treeObject = treeObject.getParent();
        treeObject = registerNewTreeObject(treeObject);
    } else if (!(treeObject instanceof TreeParent) && treeObject.getParent().getType() == TreeObject.CATEGORY_FOLDER) {
        registerNewTreeObject(treeObject.getParent());
        treeObject = treeObject.getParent().getParent();
    }
    return treeObject;
}
Also used : TreeParent(com.amalto.workbench.models.TreeParent) Element(org.dom4j.Element) Document(org.dom4j.Document)

Example 34 with TreeParent

use of com.amalto.workbench.models.TreeParent in project tmdm-studio-se by Talend.

the class RepositoryCheckTreeViewer method expandParent.

private void expandParent(TreeViewer viewer, TreeObject node) {
    TreeParent parent = node.getParent();
    if (parent != null) {
        expandParent(viewer, parent);
        viewer.setExpandedState(parent, true);
    }
}
Also used : TreeParent(com.amalto.workbench.models.TreeParent)

Example 35 with TreeParent

use of com.amalto.workbench.models.TreeParent in project tmdm-studio-se by Talend.

the class ImportServerObjectWizard method showLockedObjDialog.

private boolean showLockedObjDialog(Object[] objs) {
    if (objs == null) {
        return true;
    }
    List<IRepositoryViewObject> viewObjs = new LinkedList<IRepositoryViewObject>();
    boolean forceContinueResetOperation = false;
    Map<IRepositoryViewObject, TreeObject> objMap = new HashMap<IRepositoryViewObject, TreeObject>();
    for (Object obj : objs) {
        TreeObject treeObj = (TreeObject) obj;
        if (treeObj != null && treeObj instanceof TreeParent) {
            continue;
        }
        String treeObjName = treeObj.getName();
        ERepositoryObjectType type = RepositoryQueryService.getRepositoryObjectType(treeObj.getType());
        if (type != null && treeObjName != null) {
            String uniqueName = getUniqueName(treeObj, treeObjName);
            IRepositoryViewObject viewObject = RepositoryResourceUtil.findViewObjectByName(type, uniqueName);
            if (viewObject != null) {
                viewObjs.add(viewObject);
                objMap.put(viewObject, treeObj);
            } else {
                // not exist in local
                forceContinueResetOperation = true;
            }
        }
    }
    LockedObjectDialog lockDialog = new LockedObjectDialog(getShell(), Messages.ImportServerObjectWizard_lockedObjectMessage, Messages.ImportServerObjectWizard_cancelImportingObjectMessage, viewObjs, forceContinueResetOperation);
    if (lockDialog.needShowDialog()) {
        int open = lockDialog.open();
        if (open == IDialogConstants.OK_ID) {
            if (lockDialog.canContinueRestOperation()) {
                selectedObjects = lockDialog.getUnlockedTreeObject(selectedObjects, objMap);
                return true;
            }
        }
        return false;
    }
    return true;
}
Also used : LockedObjectDialog(org.talend.mdm.repository.ui.dialogs.lock.LockedObjectDialog) HashMap(java.util.HashMap) TreeParent(com.amalto.workbench.models.TreeParent) LinkedList(java.util.LinkedList) IRepositoryViewObject(org.talend.core.model.repository.IRepositoryViewObject) TreeObject(com.amalto.workbench.models.TreeObject) MDMServerObject(org.talend.mdm.repository.model.mdmserverobject.MDMServerObject) IRepositoryViewObject(org.talend.core.model.repository.IRepositoryViewObject) TreeObject(com.amalto.workbench.models.TreeObject) ERepositoryObjectType(org.talend.core.model.repository.ERepositoryObjectType)

Aggregations

TreeParent (com.amalto.workbench.models.TreeParent)38 TreeObject (com.amalto.workbench.models.TreeObject)21 Document (org.dom4j.Document)7 Element (org.dom4j.Element)7 GridData (org.eclipse.swt.layout.GridData)7 UserInfo (com.amalto.workbench.utils.UserInfo)6 ArrayList (java.util.ArrayList)6 GridLayout (org.eclipse.swt.layout.GridLayout)6 InvocationTargetException (java.lang.reflect.InvocationTargetException)5 Composite (org.eclipse.swt.widgets.Composite)5 WSDataClusterPK (com.amalto.workbench.webservices.WSDataClusterPK)4 HashMap (java.util.HashMap)4 SelectionListener (org.eclipse.swt.events.SelectionListener)4 Combo (org.eclipse.swt.widgets.Combo)4 Label (org.eclipse.swt.widgets.Label)4 XtentisException (com.amalto.workbench.utils.XtentisException)3 WSDataModel (com.amalto.workbench.webservices.WSDataModel)3 WSDataModelPK (com.amalto.workbench.webservices.WSDataModelPK)3 WSGetDataModel (com.amalto.workbench.webservices.WSGetDataModel)3 ModifyEvent (org.eclipse.swt.events.ModifyEvent)3