Search in sources :

Example 31 with TreeObject

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

the class Bean2EObjUtilTest method testWrapEObjWithTreeObject2Args.

/**
 * test wrapEObjWithTreeObject with two input parameters
 */
@Test
public void testWrapEObjWithTreeObject2Args() {
    EObject eobj = null;
    Object wsObj = null;
    Bean2EObjUtil util = Bean2EObjUtil.getInstance();
    TreeObject treeObject = util.wrapEObjWithTreeObject(eobj, wsObj);
    assertNull(treeObject);
    MDMServerObject mdmServerObject = PowerMockito.mock(MDMServerObject.class);
    when(mdmServerObject.getName()).thenReturn("name");
    when(mdmServerObject.getType()).thenReturn(2);
    eobj = mdmServerObject;
    treeObject = util.wrapEObjWithTreeObject(eobj, wsObj);
    assertNotNull(treeObject);
    Mockito.verify(mdmServerObject, Mockito.atLeastOnce()).getName();
    Mockito.verify(mdmServerObject, Mockito.atLeastOnce()).getType();
    assertEquals("name", treeObject.getName());
    assertEquals(2, treeObject.getType());
}
Also used : EObject(org.eclipse.emf.ecore.EObject) TreeObject(com.amalto.workbench.models.TreeObject) EObject(org.eclipse.emf.ecore.EObject) TreeObject(com.amalto.workbench.models.TreeObject) MDMServerObject(org.talend.mdm.repository.model.mdmserverobject.MDMServerObject) MDMServerObject(org.talend.mdm.repository.model.mdmserverobject.MDMServerObject) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 32 with TreeObject

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

the class ResourcesUtilTest method testGetResourcesMapFromURI.

@Test
public void testGetResourcesMapFromURI() {
    // $NON-NLS-1$
    String method_private_getXMLString = "getXMLString";
    // $NON-NLS-1$
    String method_private_parsXMLString = "parsXMLString";
    // $NON-NLS-1$
    String responseBody = "responseBody";
    // $NON-NLS-1$
    String uri = "uri";
    TreeObject treeObj = new TreeObject();
    try {
        PowerMockito.mockStatic(ResourcesUtil.class);
        PowerMockito.when(ResourcesUtil.class, method_private_getXMLString, anyString(), any(TreeObject.class)).thenReturn(responseBody);
        Document doc = null;
        PowerMockito.when(ResourcesUtil.class, method_private_parsXMLString, anyString()).thenReturn(doc);
        PowerMockito.when(ResourcesUtil.getResourcesMapFromURI(anyString(), any(TreeObject.class))).thenCallRealMethod();
        HashMap<String, String> resourcesMapFromURI = ResourcesUtil.getResourcesMapFromURI(uri, treeObj);
        assertTrue(resourcesMapFromURI.isEmpty());
        doc = DocumentHelper.createDocument();
        // $NON-NLS-1$
        Element rootElement = DocumentHelper.createElement("root");
        doc.setRootElement(rootElement);
        PowerMockito.when(ResourcesUtil.class, method_private_parsXMLString, anyString()).thenReturn(doc);
        boolean[][] ownNameURIElement = { { true, true }, { true, false }, { false, true }, { false, false } };
        // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$ //$NON-NLS-7$ //$NON-NLS-8$
        String[][] localNameUris = { { "name0", "uri0" }, { "name1", "uri1" }, { "name2", "uri2" }, { "name3", "uri3" } };
        // $NON-NLS-1$
        String entry = "entry";
        for (int i = 0; i < ownNameURIElement.length; i++) {
            createChildElement(rootElement, entry + i, localNameUris[i], ownNameURIElement[i][0], ownNameURIElement[i][1]);
        }
        resourcesMapFromURI = ResourcesUtil.getResourcesMapFromURI(uri, treeObj);
        assertNotNull(resourcesMapFromURI);
        assertEquals(4, resourcesMapFromURI.size());
        Map<String, String> resourcesMap_expected = new HashMap<String, String>();
        // $NON-NLS-1$ //$NON-NLS-2$
        resourcesMap_expected.put("name0", "uri0");
        // $NON-NLS-1$ //$NON-NLS-2$
        resourcesMap_expected.put("entry1name1", "uri/entry1name1");
        // $NON-NLS-1$ //$NON-NLS-2$
        resourcesMap_expected.put("entry2uri2", "uri/entry2uri2");
        // $NON-NLS-1$ //$NON-NLS-2$
        resourcesMap_expected.put("entry3", "uri/entry3");
        assertEquals(resourcesMap_expected, resourcesMapFromURI);
    } catch (Exception e) {
        log.error(e.getMessage(), e);
    }
}
Also used : HashMap(java.util.HashMap) Element(org.dom4j.Element) TreeObject(com.amalto.workbench.models.TreeObject) Document(org.dom4j.Document) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 33 with TreeObject

use of com.amalto.workbench.models.TreeObject 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 34 with TreeObject

use of com.amalto.workbench.models.TreeObject 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 35 with TreeObject

use of com.amalto.workbench.models.TreeObject 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

TreeObject (com.amalto.workbench.models.TreeObject)66 TreeParent (com.amalto.workbench.models.TreeParent)21 IRepositoryViewObject (org.talend.core.model.repository.IRepositoryViewObject)14 ArrayList (java.util.ArrayList)12 MDMServerObject (org.talend.mdm.repository.model.mdmserverobject.MDMServerObject)12 TMDMService (com.amalto.workbench.webservices.TMDMService)6 WSDataModel (com.amalto.workbench.webservices.WSDataModel)5 WSDataModelPK (com.amalto.workbench.webservices.WSDataModelPK)5 WSGetDataModel (com.amalto.workbench.webservices.WSGetDataModel)5 Document (org.dom4j.Document)5 Element (org.dom4j.Element)5 EObject (org.eclipse.emf.ecore.EObject)5 MDMServerObjectItem (org.talend.mdm.repository.model.mdmproperties.MDMServerObjectItem)5 WSDataClusterPK (com.amalto.workbench.webservices.WSDataClusterPK)4 InvocationTargetException (java.lang.reflect.InvocationTargetException)4 IAvailableModel (com.amalto.workbench.availablemodel.IAvailableModel)3 UserInfo (com.amalto.workbench.utils.UserInfo)3 WSDataCluster (com.amalto.workbench.webservices.WSDataCluster)3 WSDigest (com.amalto.workbench.webservices.WSDigest)3 WSDigestKey (com.amalto.workbench.webservices.WSDigestKey)3