Search in sources :

Example 26 with TMDMService

use of com.amalto.workbench.webservices.TMDMService in project tmdm-studio-se by Talend.

the class AbstractInteractiveHandlerTest method testDeploy.

@Test
public void testDeploy() {
    MDMServerObject mockServerObject = PowerMockito.mock(MDMServerObject.class);
    MDMServerObjectItem mockServerObjectItem = PowerMockito.mock(MDMServerObjectItem.class);
    PowerMockito.when(mockServerObjectItem.getMDMServerObject()).thenReturn(mockServerObject);
    Property mockProperty = PowerMockito.mock(Property.class);
    PowerMockito.when(mockProperty.getItem()).thenReturn(mockServerObjectItem);
    IRepositoryViewObject mockViewObj = PowerMockito.mock(IRepositoryViewObject.class);
    PowerMockito.when(mockViewObj.getProperty()).thenReturn(mockProperty);
    AbstractDeployCommand mockDeployCommand = PowerMockito.mock(AbstractDeployCommand.class);
    PowerMockito.when(mockDeployCommand.getViewObject()).thenReturn(mockViewObj);
    AbstractInteractiveHandler mockInteractiveHandler = PowerMockito.mock(AbstractInteractiveHandler.class);
    try {
        PowerMockito.when(mockInteractiveHandler.deploy(any(AbstractDeployCommand.class))).thenCallRealMethod();
        PowerMockito.when(mockInteractiveHandler.doDeployWSObject(any(TMDMService.class), any())).thenReturn(true);
        TMDMService mockService = PowerMockito.mock(TMDMService.class);
        // $NON-NLS-1$
        PowerMockito.when(mockInteractiveHandler, "getService", any(MDMServerDef.class)).thenReturn(mockService);
        Object mockWsObj = new Object();
        PowerMockito.when(mockInteractiveHandler.convert(any(Item.class), any(MDMServerObject.class))).thenReturn(mockWsObj);
        boolean deployed = mockInteractiveHandler.deploy(mockDeployCommand);
        assertTrue(deployed);
    } catch (Exception e) {
        log.error(e.getMessage(), e);
    }
}
Also used : Item(org.talend.core.model.properties.Item) MDMServerObjectItem(org.talend.mdm.repository.model.mdmproperties.MDMServerObjectItem) TMDMService(com.amalto.workbench.webservices.TMDMService) MDMServerObjectItem(org.talend.mdm.repository.model.mdmproperties.MDMServerObjectItem) IRepositoryViewObject(org.talend.core.model.repository.IRepositoryViewObject) AbstractDeployCommand(org.talend.mdm.repository.core.command.deploy.AbstractDeployCommand) MDMServerObject(org.talend.mdm.repository.model.mdmserverobject.MDMServerObject) IRepositoryViewObject(org.talend.core.model.repository.IRepositoryViewObject) Property(org.talend.core.model.properties.Property) MDMServerObject(org.talend.mdm.repository.model.mdmserverobject.MDMServerObject) Test(org.junit.Test)

Example 27 with TMDMService

use of com.amalto.workbench.webservices.TMDMService in project tmdm-studio-se by Talend.

the class DataClusterComposite method getResults.

protected LineItem[] getResults(boolean showResultInfo) {
    Cursor waitCursor = null;
    try {
        waitCursor = new Cursor(Display.getCurrent(), SWT.CURSOR_WAIT);
        getSite().getShell().setCursor(waitCursor);
        TMDMService service = Util.getMDMService(getXObject());
        long from = -1;
        long to = -1;
        // $NON-NLS-1$
        Pattern pattern = Pattern.compile("^\\d{4}\\d{2}\\d{2} \\d{2}:\\d{2}:\\d{2}$");
        if (!"".equals(fromText.getText())) {
            // $NON-NLS-1$
            String dateTimeText = fromText.getText().trim();
            Matcher matcher = pattern.matcher(dateTimeText);
            if (!matcher.matches()) {
                MessageDialog.openWarning(this.getSite().getShell(), Messages.Warning, Messages.DataClusterBrowserMainPage_21);
                return new LineItem[0];
            }
            try {
                Date d = sdf.parse(fromText.getText());
                from = d.getTime();
            } catch (ParseException pe) {
            }
        }
        if (!"".equals(toText.getText())) {
            // $NON-NLS-1$
            String dateTimeText = toText.getText().trim();
            Matcher matcher = pattern.matcher(dateTimeText);
            if (!matcher.matches()) {
                MessageDialog.openWarning(this.getSite().getShell(), Messages.Warning, Messages.DataClusterBrowserMainPage_23);
                return new LineItem[0];
            }
            try {
                Date d = sdf.parse(toText.getText());
                to = d.getTime();
            } catch (ParseException pe) {
            }
        }
        String concept = conceptCombo.getText();
        if ("*".equals(concept) | "".equals(concept)) {
            // $NON-NLS-1$ //$NON-NLS-2$
            concept = null;
        }
        if (concept != null) {
            // $NON-NLS-1$//$NON-NLS-2$
            concept = concept.replaceAll("\\[.*\\]", "").trim();
        }
        String keys = keyText.getText();
        if ("*".equals(keys) | "".equals(keys)) {
            // $NON-NLS-1$ //$NON-NLS-2$
            keys = null;
        }
        boolean useFTSearch = isMaster ? checkFTSearchButton.getSelection() : false;
        String search = searchText.getText();
        if ("*".equals(search) | "".equals(search)) {
            // $NON-NLS-1$ //$NON-NLS-2$
            search = null;
        }
        int start = pageToolBar.getStart();
        int limit = pageToolBar.getLimit();
        // see 0015909
        // $NON-NLS-1$
        String clusterName = URLEncoder.encode(getXObject().toString(), "utf-8");
        WSDataClusterPK clusterPk = new WSDataClusterPK(clusterName + getPkAddition());
        // @temp yguo, get item with taskid or get taskid by specify wsitempk.
        List<WSItemPKsByCriteriaResponseResults> results = service.getItemPKsByFullCriteria(new WSGetItemPKsByFullCriteria(useFTSearch, new WSGetItemPKsByCriteria(concept, search, from, null, keys, limit, start, to, clusterPk))).getResults();
        if (showResultInfo && (results.size() == 1)) {
            MessageDialog.openInformation(this.getSite().getShell(), Messages.DataClusterBrowserMainPage_24, Messages.DataClusterBrowserMainPage_25);
            return new LineItem[0];
        }
        if (results.size() == 1) {
            return new LineItem[0];
        }
        int totalSize = 0;
        List<LineItem> ress = new ArrayList<LineItem>();
        for (int i = 0; i < results.size(); i++) {
            WSItemPKsByCriteriaResponseResults result = results.get(i);
            if (i == 0) {
                totalSize = Integer.parseInt(Util.parse(result.getWsItemPK().getConceptName()).getDocumentElement().getTextContent());
                continue;
            }
            ress.add(new LineItem(result.getDate(), result.getWsItemPK().getConceptName(), result.getWsItemPK().getIds().toArray(new String[0]), result.getTaskId()));
        }
        pageToolBar.setTotalsize(totalSize);
        pageToolBar.refreshUI();
        return ress.toArray(new LineItem[ress.size()]);
    } catch (Exception e) {
        log.error(e.getMessage(), e);
        if ((e.getLocalizedMessage() != null) && e.getLocalizedMessage().contains("10000")) {
            // $NON-NLS-1$
            MessageDialog.openError(this.getSite().getShell(), Messages.DataClusterBrowserMainPage_26, Messages.DataClusterBrowserMainPage_27);
        } else if (!Util.handleConnectionException(this.getSite().getShell(), e, Messages.DataClusterBrowserMainPage_28)) {
            MessageDialog.openError(this.getSite().getShell(), Messages.DataClusterBrowserMainPage_28, e.getLocalizedMessage());
        }
        return null;
    } finally {
        try {
            this.getSite().getShell().setCursor(null);
            waitCursor.dispose();
        } catch (Exception e) {
        }
    }
}
Also used : Pattern(java.util.regex.Pattern) Matcher(java.util.regex.Matcher) ArrayList(java.util.ArrayList) LineItem(com.amalto.workbench.utils.LineItem) Cursor(org.eclipse.swt.graphics.Cursor) Date(java.util.Date) XtentisException(com.amalto.workbench.utils.XtentisException) ServerException(java.rmi.ServerException) ParseException(java.text.ParseException) InvocationTargetException(java.lang.reflect.InvocationTargetException) WebServiceException(javax.xml.ws.WebServiceException) WSDataClusterPK(com.amalto.workbench.webservices.WSDataClusterPK) TMDMService(com.amalto.workbench.webservices.TMDMService) ParseException(java.text.ParseException) WSGetItemPKsByFullCriteria(com.amalto.workbench.webservices.WSGetItemPKsByFullCriteria) WSGetItemPKsByCriteria(com.amalto.workbench.webservices.WSGetItemPKsByCriteria) WSItemPKsByCriteriaResponseResults(com.amalto.workbench.webservices.WSItemPKsByCriteriaResponseResults)

Example 28 with TMDMService

use of com.amalto.workbench.webservices.TMDMService in project tmdm-studio-se by Talend.

the class DataClusterDialog method getAllDataContainers.

private boolean getAllDataContainers(List<TreeObject> dataContainers) {
    MDMServerDef serverDef = getSelectedMdmServerDef();
    String username = serverDef.getUser();
    String password = serverDef.getPasswd();
    String serverName = serverDef.getName();
    String endpointaddress = serverDef.getUrl();
    boolean canConnect = checkConnection(endpointaddress, username, password);
    if (!canConnect) {
        MessageDialog.openError(site.getShell(), Messages.DataClusterDialog_7, Messages.DataClusterDialog_8);
        return false;
    }
    List<WSDataClusterPK> xdcPKs = null;
    try {
        TMDMService service = Util.getMDMService(new URL(endpointaddress), username, password);
        TreeParent serverRoot = new TreeParent(serverName, null, TreeObject._SERVER_, endpointaddress, username + ":" + // $NON-NLS-1$//$NON-NLS-2$
        (password == null ? "" : password));
        // $NON-NLS-1$
        xdcPKs = service.getDataClusterPKs(new WSRegexDataClusterPKs("*")).getWsDataClusterPKs();
        for (WSDataClusterPK pk : xdcPKs) {
            String name = pk.getPk();
            if (!("CACHE".equals(name))) {
                // $NON-NLS-1$
                WSDataCluster wsObject = null;
                boolean retriveWSObject = false;
                try {
                    if (retriveWSObject) {
                        wsObject = service.getDataCluster(new WSGetDataCluster(pk));
                    }
                    TreeObject obj = new TreeObject(name, serverRoot, TreeObject.DATA_CLUSTER, pk, wsObject);
                    dataContainers.add(obj);
                } catch (Exception e) {
                    log.error(e.getMessage(), e);
                }
            }
        }
    } catch (Exception e) {
        log.error(e.getMessage(), e);
        return false;
    }
    return true;
}
Also used : TreeParent(com.amalto.workbench.models.TreeParent) URL(java.net.URL) XtentisException(com.amalto.workbench.utils.XtentisException) MalformedURLException(java.net.MalformedURLException) WebServiceException(javax.xml.ws.WebServiceException) WSDataCluster(com.amalto.workbench.webservices.WSDataCluster) WSGetDataCluster(com.amalto.workbench.webservices.WSGetDataCluster) WSDataClusterPK(com.amalto.workbench.webservices.WSDataClusterPK) TMDMService(com.amalto.workbench.webservices.TMDMService) TreeObject(com.amalto.workbench.models.TreeObject) MDMServerDef(com.amalto.workbench.utils.MDMServerDef) WSRegexDataClusterPKs(com.amalto.workbench.webservices.WSRegexDataClusterPKs)

Example 29 with TMDMService

use of com.amalto.workbench.webservices.TMDMService in project tmdm-studio-se by Talend.

the class ProjectDecisionDialog method createDialogArea.

@Override
protected Control createDialogArea(Composite parent) {
    // Should not really be here but well,....
    parent.getShell().setText(this.title);
    Composite composite = (Composite) super.createDialogArea(parent);
    GridLayout layout = (GridLayout) composite.getLayout();
    layout.numColumns = 2;
    try {
        // process the decision
        // $NON-NLS-1$
        String dataClusterName = "";
        // $NON-NLS-1$
        String dataModelName = "";
        boolean doOverwrite = true;
        Matcher m = dp.matcher(decision);
        if (m.matches()) {
            dataClusterName = m.group(1);
            dataModelName = m.group(2);
            if (m.groupCount() >= 4) {
                // $NON-NLS-1$
                doOverwrite = (!"false".equals(m.group(3)));
            }
        }
        TMDMService port = Util.getMDMService(new URL(transformerObject.getEndpointAddress()), transformerObject.getUsername(), transformerObject.getPassword());
        // Grab the available Clusters
        // $NON-NLS-1$
        List<WSDataClusterPK> dcpks = port.getDataClusterPKs(new WSRegexDataClusterPKs(".*")).getWsDataClusterPKs();
        Label dataClustersLabel = new Label(composite, SWT.NULL);
        dataClustersLabel.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false, 1, 1));
        dataClustersLabel.setText(Messages.ProjectDecisionDialog_DataContainers);
        dataClustersCombo = new Combo(composite, SWT.DROP_DOWN);
        dataClustersCombo.setLayoutData(new GridData(SWT.FILL, SWT.FILL, false, false, 1, 1));
        int dataClusterSelect = -1;
        if (dcpks != null) {
            int i = 0;
            for (WSDataClusterPK pk : dcpks) {
                dataClustersCombo.add(pk.getPk());
                if (pk.getPk().equals(dataClusterName)) {
                    dataClusterSelect = i;
                }
                i++;
            }
        }
        dataClustersCombo.select(dataClusterSelect);
        // Grab the available Models
        // $NON-NLS-1$
        List<WSDataModelPK> dmpks = port.getDataModelPKs(new WSRegexDataModelPKs(".*")).getWsDataModelPKs();
        Label dataModelsLabel = new Label(composite, SWT.NULL);
        dataModelsLabel.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false, 1, 1));
        dataModelsLabel.setText(Messages.ProjectDecisionDialog_DataModels);
        dataModelsCombo = new Combo(composite, SWT.DROP_DOWN);
        dataModelsCombo.setLayoutData(new GridData(SWT.FILL, SWT.FILL, false, false, 1, 1));
        int dataModelSelect = -1;
        if (dmpks != null) {
            int i = 0;
            for (WSDataModelPK pk : dmpks) {
                dataModelsCombo.add(pk.getPk());
                if (pk.getPk().equals(dataModelName)) {
                    dataModelSelect = i;
                }
                i++;
            }
        }
        dataModelsCombo.select(dataModelSelect);
        // Overwrite
        Label overwriteLabel = new Label(composite, SWT.NULL);
        overwriteLabel.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false, 1, 1));
        overwriteLabel.setText(Messages.ProjectDecisionDialog_Overwrite);
        overwriteButton = new Button(composite, SWT.CHECK);
        overwriteButton.setLayoutData(new GridData(SWT.FILL, SWT.FILL, false, false, 1, 1));
        overwriteButton.setSelection(doOverwrite);
    } catch (Exception e) {
        if (!Util.handleConnectionException(this.getShell(), e, null)) {
            MessageDialog.openError(ProjectDecisionDialog.this.getShell(), Messages.ProjectDecisionDialog_ErrorTitle, Messages.bind(Messages.ProjectDecisionDialog_ErrorMsg, e.getMessage()));
        }
    }
    return composite;
}
Also used : Composite(org.eclipse.swt.widgets.Composite) Matcher(java.util.regex.Matcher) Label(org.eclipse.swt.widgets.Label) Combo(org.eclipse.swt.widgets.Combo) URL(java.net.URL) GridLayout(org.eclipse.swt.layout.GridLayout) WSDataClusterPK(com.amalto.workbench.webservices.WSDataClusterPK) TMDMService(com.amalto.workbench.webservices.TMDMService) Button(org.eclipse.swt.widgets.Button) GridData(org.eclipse.swt.layout.GridData) WSRegexDataModelPKs(com.amalto.workbench.webservices.WSRegexDataModelPKs) WSRegexDataClusterPKs(com.amalto.workbench.webservices.WSRegexDataClusterPKs) WSDataModelPK(com.amalto.workbench.webservices.WSDataModelPK)

Example 30 with TMDMService

use of com.amalto.workbench.webservices.TMDMService in project tmdm-studio-se by Talend.

the class StoredProcedureMainPage method executeProcedure.

protected void executeProcedure() {
    boolean checkMissingJar = MissingJarService.getInstance().checkMissingJar(true);
    if (!checkMissingJar) {
        return;
    }
    BusyIndicator.showWhile(this.getPartControl().getDisplay(), new Runnable() {

        public void run() {
            WSDataClusterPK dcpk = null;
            if (!"[ALL]".equals(dataClusterCombo.getText())) {
                dcpk = new WSDataClusterPK(dataClusterCombo.getText());
            }
            try {
                String proc = procedureViewer.getDocument().get();
                // read parameters
                int number = 0;
                while (true) {
                    // $NON-NLS-1$//$NON-NLS-2$
                    Pattern p = Pattern.compile(".*[^\\\\]%" + number + "[^\\d]*.*", Pattern.DOTALL);
                    Matcher m = p.matcher(proc);
                    if (!m.matches()) {
                        break;
                    } else {
                        ++number;
                    }
                }
                String[] ps = null;
                if (number > 0) {
                    // transfer current parameters to new array
                    ps = new String[number];
                    for (int i = 0; i < number; i++) {
                        if (i < currentParameters.size()) {
                            ps[i] = currentParameters.get(i);
                        } else {
                            // $NON-NLS-1$
                            ps[i] = "";
                        }
                    }
                    // call parameters window
                    QueryParametersDialog dialog = new QueryParametersDialog(StoredProcedureMainPage.this.getSite().getShell(), ps);
                    dialog.setBlockOnOpen(true);
                    dialog.open();
                    if (dialog.getButtonPressed() == QueryParametersDialog.BUTTON_CANCEL) {
                        return;
                    }
                    ps = dialog.getParameters();
                    // Apply parameters
                    for (int i = 0; i < ps.length; i++) {
                        // transfer parameters back into current parameters
                        if (i < currentParameters.size()) {
                            currentParameters.set(i, ps[i]);
                        } else {
                            currentParameters.add(ps[i]);
                        }
                    }
                }
                // perform call
                TMDMService service = getMDMService();
                if (service != null) {
                    WSStoredProcedure wsStoredProcedure = (WSStoredProcedure) (getXObject().getWsObject());
                    service.putStoredProcedure(new WSPutStoredProcedure(wsStoredProcedure));
                    WSStringArray array = service.executeStoredProcedure(new WSExecuteStoredProcedure(currentParameters, dcpk, new WSStoredProcedurePK(wsStoredProcedure.getName())));
                    List<String> results = array.getStrings();
                    resultsLabel.setText(Messages.StoredProcedureMainPage_15 + results.size() + Messages.StoredProcedureMainPage_16);
                    resultsViewer.setInput(results);
                }
            } catch (Exception ex) {
                if (!Util.handleConnectionException(StoredProcedureMainPage.this.getSite().getShell(), ex, null)) {
                    String message = ex.getMessage();
                    Set<String> messages = getMessages(message);
                    StringBuilder builder = new StringBuilder();
                    for (String currentMessage : messages) {
                        builder.append(currentMessage + '\n');
                    }
                    MessageDialog.openError(StoredProcedureMainPage.this.getSite().getShell(), Messages._Error, builder.toString());
                }
            }
        }
    });
}
Also used : Pattern(java.util.regex.Pattern) Matcher(java.util.regex.Matcher) WSStoredProcedurePK(com.amalto.workbench.webservices.WSStoredProcedurePK) WSPutStoredProcedure(com.amalto.workbench.webservices.WSPutStoredProcedure) WSStringArray(com.amalto.workbench.webservices.WSStringArray) WSDataClusterPK(com.amalto.workbench.webservices.WSDataClusterPK) QueryParametersDialog(com.amalto.workbench.dialogs.QueryParametersDialog) TMDMService(com.amalto.workbench.webservices.TMDMService) WSExecuteStoredProcedure(com.amalto.workbench.webservices.WSExecuteStoredProcedure) List(java.util.List) LinkedList(java.util.LinkedList) WSStoredProcedure(com.amalto.workbench.webservices.WSStoredProcedure)

Aggregations

TMDMService (com.amalto.workbench.webservices.TMDMService)41 XtentisException (com.amalto.workbench.utils.XtentisException)18 WSDataClusterPK (com.amalto.workbench.webservices.WSDataClusterPK)10 URL (java.net.URL)10 WebServiceException (javax.xml.ws.WebServiceException)9 WSDataModelPK (com.amalto.workbench.webservices.WSDataModelPK)8 TreeObject (com.amalto.workbench.models.TreeObject)7 MalformedURLException (java.net.MalformedURLException)7 WSDataModel (com.amalto.workbench.webservices.WSDataModel)6 WSGetDataModel (com.amalto.workbench.webservices.WSGetDataModel)6 WSView (com.amalto.workbench.webservices.WSView)6 ParseException (java.text.ParseException)6 IRepositoryViewObject (org.talend.core.model.repository.IRepositoryViewObject)6 WSDataCluster (com.amalto.workbench.webservices.WSDataCluster)5 WSGetDataCluster (com.amalto.workbench.webservices.WSGetDataCluster)5 WSGetView (com.amalto.workbench.webservices.WSGetView)5 WSPing (com.amalto.workbench.webservices.WSPing)5 Matcher (java.util.regex.Matcher)5 WSDigest (com.amalto.workbench.webservices.WSDigest)4 WSRoutingEngineV2Action (com.amalto.workbench.webservices.WSRoutingEngineV2Action)4