Search in sources :

Example 1 with WSGetItemPKsByCriteria

use of com.amalto.workbench.webservices.WSGetItemPKsByCriteria 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 2 with WSGetItemPKsByCriteria

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

the class ExportItemsWizard method exportCluster.

protected TreeObject exportCluster(List<TreeObject> exports, WSDataClusterPK pk, TMDMService service) {
    String encodedID = null;
    try {
        List<String> items1 = new ArrayList<String>();
        List<WSItemPKsByCriteriaResponseResults> results = service.getItemPKsByCriteria(new WSGetItemPKsByCriteria(null, encodedID, (long) -1, encodedID, encodedID, Integer.MAX_VALUE, 0, (long) -1, pk)).getResults();
        if (results == null) {
            return null;
        }
        for (WSItemPKsByCriteriaResponseResults item : results) {
            if (item.getWsItemPK().getIds() == null) {
                continue;
            }
            WSItem wsitem = service.getItem(new WSGetItem(item.getWsItemPK()));
            // Marshal
            StringWriter sw1 = new StringWriter();
            Marshaller.marshal(wsitem, sw1);
            // $NON-NLS-1$
            String uniqueId = pk.getPk() + "." + wsitem.getConceptName();
            for (String id : wsitem.getIds()) {
                // $NON-NLS-1$
                uniqueId = uniqueId + "." + id;
            }
            // $NON-NLS-1$
            encodedID = URLEncoder.encode(uniqueId, "UTF-8");
            // $NON-NLS-1$//$NON-NLS-2$
            writeString(sw1.toString(), TreeObject.DATACONTAINER_COTENTS + "/" + pk.getPk() + "/" + encodedID);
            // $NON-NLS-1$//$NON-NLS-2$
            items1.add(TreeObject.DATACONTAINER_COTENTS + "/" + pk.getPk() + "/" + encodedID);
        }
        TreeObject obj1 = new TreeObject(pk.getPk(), null, TreeObject.DATA_CLUSTER_CONTENTS, null, null);
        obj1.setItems(items1.toArray(new String[items1.size()]));
        exports.add(obj1);
        return obj1;
    } catch (Exception e) {
    }
    return null;
}
Also used : WSGetItem(com.amalto.workbench.webservices.WSGetItem) StringWriter(java.io.StringWriter) WSItem(com.amalto.workbench.webservices.WSItem) ArrayList(java.util.ArrayList) TreeObject(com.amalto.workbench.models.TreeObject) WSGetItemPKsByCriteria(com.amalto.workbench.webservices.WSGetItemPKsByCriteria) WSItemPKsByCriteriaResponseResults(com.amalto.workbench.webservices.WSItemPKsByCriteriaResponseResults)

Aggregations

WSGetItemPKsByCriteria (com.amalto.workbench.webservices.WSGetItemPKsByCriteria)2 WSItemPKsByCriteriaResponseResults (com.amalto.workbench.webservices.WSItemPKsByCriteriaResponseResults)2 ArrayList (java.util.ArrayList)2 TreeObject (com.amalto.workbench.models.TreeObject)1 LineItem (com.amalto.workbench.utils.LineItem)1 XtentisException (com.amalto.workbench.utils.XtentisException)1 TMDMService (com.amalto.workbench.webservices.TMDMService)1 WSDataClusterPK (com.amalto.workbench.webservices.WSDataClusterPK)1 WSGetItem (com.amalto.workbench.webservices.WSGetItem)1 WSGetItemPKsByFullCriteria (com.amalto.workbench.webservices.WSGetItemPKsByFullCriteria)1 WSItem (com.amalto.workbench.webservices.WSItem)1 StringWriter (java.io.StringWriter)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 ServerException (java.rmi.ServerException)1 ParseException (java.text.ParseException)1 Date (java.util.Date)1 Matcher (java.util.regex.Matcher)1 Pattern (java.util.regex.Pattern)1 WebServiceException (javax.xml.ws.WebServiceException)1 Cursor (org.eclipse.swt.graphics.Cursor)1