Search in sources :

Example 11 with TreeParent

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

the class ImportItemsWizard method parses.

protected void parses(boolean importFromArchieve, String zipFilePath, IProgressMonitor monitor) {
    // init var for progressMonitor
    int total = 500, zipCount = 200, readCount = 100;
    int step = 1, interval = 1;
    // 
    monitor.beginTask(Messages.ImportItemsWizard_7, total);
    if (importFromArchieve) {
        checkUpExchangeImport(true);
        try {
            Util.unZipFile(zipFilePath, importFolder, zipCount, monitor);
        } catch (Exception e) {
            log.error(e.getMessage(), e);
        }
    }
    monitor.worked(zipCount);
    monitor.setTaskName(Messages.ImportItemsWizard_8);
    InputStreamReader reader = null;
    try {
        // $NON-NLS-1$//$NON-NLS-2$
        reader = new InputStreamReader(new FileInputStream(importFolder + "/exportitems.xml"), "UTF-8");
        final Exports exports = (Exports) Unmarshaller.unmarshal(Exports.class, reader);
        String[] orgSchemas = exports.getSchemas();
        int idx = 0;
        if (orgSchemas != null) {
            for (String orgSchema : orgSchemas) {
                String orgSchemaCpy = new String(orgSchema);
                for (Map.Entry<String, String> pair : ICoreConstants.rolesConvert.oldRoleToNewRoleMap.entrySet()) {
                    orgSchemaCpy = orgSchemaCpy.replaceAll(pair.getKey().toString(), pair.getValue().toString());
                }
                if (!orgSchemaCpy.equals(orgSchema)) {
                    orgSchemas[idx] = orgSchemaCpy;
                }
                idx++;
            }
        }
        try {
            LocalTreeObjectRepository.getInstance().makeUpDocWithImportCategory(orgSchemas, serverRoot);
        } catch (Exception e) {
        }
        // import autoincrement
        if (exports.getAutoIncrement() != null) {
            try {
                service.getAutoIncrement(new WSAutoIncrement(exports.getAutoIncrement()));
            } catch (Exception e) {
            }
        }
        // new server root
        final TreeParent reserverRoot = new TreeParent(serverRoot.getDisplayName(), null, TreeObject._SERVER_, serverRoot.getWsKey(), serverRoot.getWsObject());
        reserverRoot.setUser(serverRoot.getUser());
        // serverRoot=reserverRoot;
        TreeParent clusters = new TreeParent(EXtentisObjects.DataCluster.getDisplayName(), reserverRoot, TreeObject.DATA_CLUSTER, null, null);
        TreeParent models = new TreeParent(EXtentisObjects.DataMODEL.getDisplayName(), reserverRoot, TreeObject.DATA_MODEL, null, null);
        TreeParent menus = new TreeParent(EXtentisObjects.Menu.getDisplayName(), reserverRoot, TreeObject.MENU, null, null);
        TreeParent roles = new TreeParent(EXtentisObjects.Role.getDisplayName(), reserverRoot, TreeObject.ROLE, null, null);
        TreeParent eventManager = new TreeParent(EXtentisObjects.EventManagement.getDisplayName(), reserverRoot, TreeObject.EVENT_MANAGEMENT, null, null);
        TreeParent routingrules = new TreeParent(EXtentisObjects.RoutingRule.getDisplayName(), reserverRoot, TreeObject.ROUTING_RULE, null, null);
        TreeParent storeprocedures = new TreeParent(EXtentisObjects.StoredProcedure.getDisplayName(), reserverRoot, TreeObject.STORED_PROCEDURE, null, null);
        TreeParent transformers = new TreeParent(EXtentisObjects.Transformer.getDisplayName(), reserverRoot, TreeObject.TRANSFORMER, null, null);
        TreeParent pictures = new TreeParent(EXtentisObjects.PICTURESRESOURCE.getDisplayName(), reserverRoot, TreeObject.PICTURES_RESOURCE, null, null);
        // add by ymli
        TreeParent workflow = new TreeParent(EXtentisObjects.Workflow.getDisplayName(), reserverRoot, TreeObject.WORKFLOW, null, null);
        TreeParent views = new TreeParent(EXtentisObjects.View.getDisplayName(), reserverRoot, TreeObject.VIEW, null, null);
        reserverRoot.addChild(clusters);
        reserverRoot.addChild(models);
        reserverRoot.addChild(menus);
        reserverRoot.addChild(roles);
        reserverRoot.addChild(storeprocedures);
        eventManager.addChild(transformers);
        eventManager.addChild(routingrules);
        reserverRoot.addChild(eventManager);
        reserverRoot.addChild(pictures);
        reserverRoot.addChild(workflow);
        reserverRoot.addChild(views);
        monitor.worked(readCount);
        // caculate step and interval
        float val = (total - zipCount - readCount) / exports.getItems().length;
        if (val > 0) {
            interval = 1;
            step = Math.round(val);
        } else {
            step = 1;
            interval = Math.round(exports.getItems().length / (total - zipCount - readCount) + 0.5f);
        }
        // System.out.println("count:" + exports.getItems().length + "\tinterval:" + interval + "\tstep:" + step);
        monitor.setTaskName(Messages.ImportItemsWizard_9);
        // 
        int tmp = 1;
        for (TreeObject obj : exports.getItems()) {
            obj.setServerRoot(reserverRoot);
            switch(obj.getType()) {
                case TreeObject.DATA_CLUSTER:
                    clusters.addChild(obj);
                    break;
                case TreeObject.DATA_MODEL:
                    models.addChild(obj);
                    break;
                case TreeObject.MENU:
                    menus.addChild(obj);
                    break;
                case TreeObject.ROLE:
                    roles.addChild(obj);
                    break;
                case TreeObject.ROUTING_RULE:
                    routingrules.addChild(obj);
                    break;
                case TreeObject.STORED_PROCEDURE:
                    storeprocedures.addChild(obj);
                    break;
                case TreeObject.TRANSFORMER:
                    transformers.addChild(obj);
                    break;
                case TreeObject.PICTURES_RESOURCE:
                    pictures.addChild(obj);
                    break;
                case TreeObject.WORKFLOW_PROCESS:
                    workflow.addChild(obj);
                    break;
                case TreeObject.VIEW:
                    views.addChild(obj);
                    break;
                default:
                    if (obj.getItems() != null && obj.getItems().length > 0) {
                        for (int i = 0; i < obj.getItems().length; i++) {
                            if (obj.getItems()[i].split(Messages.ImportItemsWizard_10)[1] != null) {
                                dataClusterContent.put(obj.getItems()[i].split(Messages.ImportItemsWizard_11)[1], obj.getItems());
                            }
                        }
                    }
            }
            // update monitor
            if (interval == 1) {
                monitor.worked(step);
            } else {
                if (tmp >= interval) {
                    monitor.worked(step);
                    tmp = 1;
                } else {
                    tmp++;
                }
            }
        }
        Display.getDefault().syncExec(new Runnable() {

            public void run() {
                treeViewer.setRoot(reserverRoot);
                treeViewer.getViewer().setInput(null);
                treeViewer.setCheckItems(Arrays.asList(exports.getItems()));
                GridData gd = (GridData) treeViewer.getViewer().getControl().getLayoutData();
                gd.heightHint = 300;
                treeViewer.getViewer().getControl().getParent().layout(true);
                treeViewer.getViewer().getControl().getShell().layout(true);
                try {
                    Object[] checkNodes = treeViewer.getCheckNodes();
                    if (checkNodes != null) {
                        LocalTreeObjectRepository.getInstance().setOriginalXobjectsToImport((TreeObject[]) checkNodes);
                    }
                } catch (Exception e) {
                }
            }
        });
    } catch (Exception e) {
        log.error(e.getMessage(), e);
    } finally {
        try {
            if (reader != null) {
                reader.close();
            }
        } catch (Exception e) {
        }
        monitor.done();
    }
}
Also used : InputStreamReader(java.io.InputStreamReader) WSAutoIncrement(com.amalto.workbench.webservices.WSAutoIncrement) TreeParent(com.amalto.workbench.models.TreeParent) FileNotFoundException(java.io.FileNotFoundException) InvocationTargetException(java.lang.reflect.InvocationTargetException) DocumentException(org.dom4j.DocumentException) FileInputStream(java.io.FileInputStream) GridData(org.eclipse.swt.layout.GridData) TreeObject(com.amalto.workbench.models.TreeObject) Map(java.util.Map) HashMap(java.util.HashMap)

Example 12 with TreeParent

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

the class AbstractNodeCheckTreeViewer method expandParent.

protected 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 13 with TreeParent

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

the class JobAvailableModel method addTreeObjects.

@Override
public void addTreeObjects(TMDMService service, IProgressMonitor monitor, TreeParent serverRoot) {
    monitor.subTask(Messages.JobAvailableModel_LoadingJobs);
    // MDM Job
    TreeParent jobs = serverRoot.findServerFolder(TreeObject.JOB_REGISTRY);
    if (jobs == null) {
        jobs = new TreeParent(EXtentisObjects.JobRegistry.getDisplayName(), serverRoot, TreeObject.JOB_REGISTRY, null, null);
    }
    TreeParent deployedJob = new TreeParent(Messages.JobAvailableModel_DeployedJobs, serverRoot, TreeObject.BUILT_IN_CATEGORY_FOLDER, null, null);
    try {
        List<WSMDMJob> jobPKs = service.getMDMJob(new WSMDMNULL()).getWsMDMJob();
        if (jobPKs != null) {
            for (WSMDMJob jobPK : jobPKs) {
                // $NON-NLS-1$
                String name = jobPK.getJobName() + "_" + jobPK.getJobVersion() + jobPK.getSuffix();
                TreeObject obj = new TreeObject(name, serverRoot, TreeObject.JOB, name, null);
                deployedJob.addChild(obj);
            }
        }
    } catch (Exception e) {
    }
    jobs.addChild(deployedJob);
    serverRoot.addChild(jobs);
    monitor.worked(1);
}
Also used : WSMDMJob(com.amalto.workbench.webservices.WSMDMJob) TreeParent(com.amalto.workbench.models.TreeParent) TreeObject(com.amalto.workbench.models.TreeObject) WSMDMNULL(com.amalto.workbench.webservices.WSMDMNULL)

Example 14 with TreeParent

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

the class DataClusterBrowserMainPage method getRealTreeParent.

// The ending| bug:21784
private TreeParent getRealTreeParent() {
    TreeParent treeParent = null;
    TreeObject xObject = getXObject();
    if (xObject != null) {
        TreeParent serverRoot = xObject.getServerRoot();
        UserInfo user = serverRoot.getUser();
        String serverName = serverRoot.getName();
        String password = user.getPassword();
        String url = user.getServerUrl();
        String username = user.getUsername();
        final XtentisServerObjectsRetriever retriever = new XtentisServerObjectsRetriever(serverName, url, username, password);
        retriever.setRetriveWSObject(true);
        try {
            retriever.run(new NullProgressMonitor());
            // get the real server root as the treeParent
            treeParent = retriever.getServerRoot();
        } catch (InvocationTargetException e) {
            log.error(e.getMessage(), e);
        } catch (InterruptedException e) {
            log.error(e.getMessage(), e);
        }
    }
    return treeParent;
}
Also used : NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) XtentisServerObjectsRetriever(com.amalto.workbench.providers.XtentisServerObjectsRetriever) TreeParent(com.amalto.workbench.models.TreeParent) TreeObject(com.amalto.workbench.models.TreeObject) UserInfo(com.amalto.workbench.utils.UserInfo) InvocationTargetException(java.lang.reflect.InvocationTargetException)

Example 15 with TreeParent

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

the class DataClusterComposite method doSelectDataModelForEntityRecords.

/**
 * @param clusterName
 * @throws XtentisException
 * @throws Exception
 */
private boolean doSelectDataModelForEntityRecords(String clusterName) throws XtentisException, Exception {
    // if (false) {
    // Modified by hbhong,to fix bug 21784|
    TreeParent treeParent = (TreeParent) getAdapter(TreeParent.class);
    DataModelSelectDialog dialog = new DataModelSelectDialog(getSite(), treeParent, clusterName);
    // The ending| bug:21784
    dialog.setBlockOnOpen(true);
    dialog.open();
    if (dialog.getReturnCode() == Window.OK) {
        List<String> allConcept = new ArrayList<String>();
        String[] xpaths = dialog.getXpath();
        for (String xpath : xpaths) {
            WSDataModel dm = Util.getMDMService(this.getXObject()).getDataModel(new WSGetDataModel(new WSDataModelPK(xpath)));
            if (dm == null) {
                return false;
            }
            List<String> concepts = Util.getConcepts(Util.getXSDSchema(dm.getXsdSchema()));
            allConcept.addAll(concepts);
        }
        String[] concepts = allConcept.toArray(new String[0]);
        TreeObject object = null;
        TreeObject[] children = treeParent.getChildren();
        for (TreeObject element : children) {
            object = element;
            if (object.getType() == TreeObject.DATA_MODEL) {
                break;
            }
        }
        // $NON-NLS-1$
        String revision = "";
        if (object != null) {
            // revisions).
            if (object.getDisplayName().contains(Messages.DataClusterBrowserMainPage_16) && object.getDisplayName().contains(Messages.DataClusterBrowserMainPage_17)) {
                revision = // $NON-NLS-1$
                object.getDisplayName().substring(// $NON-NLS-1$
                object.getDisplayName().indexOf("[") + 1, // $NON-NLS-1$
                object.getDisplayName().indexOf("]"));
            }
        }
        for (int i = 0; i < concepts.length; i++) {
            String concept = concepts[i];
            if (revision == null || revision.equals("")) {
                // $NON-NLS-1$
                // $NON-NLS-1$
                revision = "HEAD";
            }
            // $NON-NLS-1$//$NON-NLS-2$//$NON-NLS-3$
            concepts[i] = concept + " " + "[" + revision + "]";
        }
        conceptCombo.removeAll();
        // $NON-NLS-1$
        conceptCombo.add("*");
        for (String concept : concepts) {
            conceptCombo.add(concept);
        }
    } else {
        // $NON-NLS-1$
        conceptCombo.add("*");
    }
    return true;
}
Also used : WSDataModel(com.amalto.workbench.webservices.WSDataModel) DataModelSelectDialog(com.amalto.workbench.dialogs.DataModelSelectDialog) TreeParent(com.amalto.workbench.models.TreeParent) ArrayList(java.util.ArrayList) TreeObject(com.amalto.workbench.models.TreeObject) WSGetDataModel(com.amalto.workbench.webservices.WSGetDataModel) WSDataModelPK(com.amalto.workbench.webservices.WSDataModelPK)

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