Search in sources :

Example 1 with WSConceptKey

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

the class RepositoryResourceUtil method getBusinessConceptKey.

public static WSConceptKey getBusinessConceptKey(WSGetBusinessConceptKey businessConcepKey) throws XtentisException {
    String pk = businessConcepKey.getWsDataModelPK().getPk();
    String concept = businessConcepKey.getConcept();
    WSDataModelE dataModel = RepositoryQueryService.findDataModelByName(pk);
    if (dataModel != null) {
        try {
            XSDSchema xsdSchema = Util.getXSDSchema(dataModel.getXsdSchema());
            for (XSDIdentityConstraintDefinition idDef : xsdSchema.getIdentityConstraintDefinitions()) {
                if (idDef.getName().equals(concept)) {
                    WSConceptKey key = new WSConceptKey();
                    // 
                    XSDXPathDefinition selector = idDef.getSelector();
                    key.setSelector(selector.getValue());
                    // 
                    EList<XSDXPathDefinition> fields = idDef.getFields();
                    List<String> keyFields = new ArrayList<String>();
                    for (XSDXPathDefinition pathDef : fields) {
                        keyFields.add(pathDef.getValue());
                    }
                    key.getFields().clear();
                    key.getFields().addAll(keyFields);
                    return key;
                }
            }
        } catch (Exception e) {
            log.error(e.getMessage(), e);
        }
    }
    return null;
}
Also used : WSDataModelE(org.talend.mdm.repository.model.mdmserverobject.WSDataModelE) ArrayList(java.util.ArrayList) XSDIdentityConstraintDefinition(org.eclipse.xsd.XSDIdentityConstraintDefinition) XSDXPathDefinition(org.eclipse.xsd.XSDXPathDefinition) WSConceptKey(com.amalto.workbench.webservices.WSConceptKey) CoreException(org.eclipse.core.runtime.CoreException) PartInitException(org.eclipse.ui.PartInitException) LoginException(org.talend.commons.exception.LoginException) InvocationTargetException(java.lang.reflect.InvocationTargetException) IOException(java.io.IOException) XtentisException(com.amalto.workbench.utils.XtentisException) FileNotFoundException(java.io.FileNotFoundException) PersistenceException(org.talend.commons.exception.PersistenceException) XSDSchema(org.eclipse.xsd.XSDSchema)

Example 2 with WSConceptKey

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

the class ViewMainPage method doSave.

@Override
public void doSave(IProgressMonitor monitor) {
    super.doSave(monitor);
    if (this.viewName != null && this.viewName.length() > 0) {
        if (viewName.matches("Browse_items.*")) {
            // $NON-NLS-1$
            // lastDataModelName=XpathSelectDialog.getDataModelName();
            // $NON-NLS-1$//$NON-NLS-2$//$NON-NLS-3$//$NON-NLS-4$
            String concept = viewName.replaceAll("Browse_items_", "").replaceAll("#.*", "");
            java.util.List<String> avaiList = getAvailableDataModel();
            if (avaiList.size() > 0) {
                lastDataModelName = avaiList.get(0);
            }
            if (concept != null && concept.length() > 0 && lastDataModelName != null && lastDataModelName.length() > 0) {
                // if(concept!=null&&concept.length()>0&&lastDataModelName!=null&&lastDataModelName.length()>0){
                // keys validate
                java.util.List<String> toAddViewableList = new ArrayList<String>();
                WSGetBusinessConceptKey wsGetBusinessConceptKey = new WSGetBusinessConceptKey(concept, new WSDataModelPK(lastDataModelName));
                WSConceptKey wsConceptKey = null;
                try {
                    wsConceptKey = getBusinessConceptKey(wsGetBusinessConceptKey);
                } catch (XtentisException e) {
                    log.error(e.getMessage(), e);
                }
                if (wsConceptKey != null) {
                    java.util.List<String> viewableList = new ArrayList<String>();
                    java.util.List<Line> vlines = (java.util.List<Line>) viewableViewer.getViewer().getInput();
                    for (int j = 0; j < vlines.size(); j++) {
                        Line item = vlines.get(j);
                        viewableList.add(item.keyValues.get(0).value);
                    }
                    java.util.List<String> keys = wsConceptKey.getFields();
                    for (int i = 0; i < keys.size(); i++) {
                        if (".".equals(wsConceptKey.getSelector())) {
                            // $NON-NLS-1$//$NON-NLS-2$
                            keys.set(i, "/" + concept + "/" + keys.get(i));
                        } else {
                            keys.set(i, wsConceptKey.getSelector() + keys.get(i));
                        }
                    }
                    java.util.List<String> ids = wsConceptKey.getFields();
                    for (String id : ids) {
                        // need to care about more case
                        if (id.startsWith("/")) {
                            // $NON-NLS-1$
                            id = id.substring(1);
                        } else if (id.startsWith("//")) {
                            // $NON-NLS-1$
                            id = id.substring(2);
                        }
                        if (!viewableList.contains(id)) {
                            toAddViewableList.add(0, id);
                        }
                    }
                }
                // show verify report
                if (toAddViewableList.size() > 0) {
                    String msg = Messages.ViewMainPage_Msg;
                    for (Object element : toAddViewableList) {
                        String toAddItem = (String) element;
                        // $NON-NLS-1$
                        msg += (toAddItem + "\n");
                    }
                    msg += Messages.ViewMainPage_Addtions;
                    MessageDialog.openInformation(this.getSite().getShell(), Messages.ViewMainPage_VerifyReport, msg);
                }
                // auto fix
                IRunnableWithProgress autoFixProcess = new AutoFixProgress(toAddViewableList, viewableViewer, this.getSite().getShell());
                try {
                    new ProgressMonitorDialog(this.getSite().getShell()).run(false, true, autoFixProcess);
                } catch (InvocationTargetException e) {
                    log.error(e.getMessage(), e);
                } catch (InterruptedException e) {
                    log.error(e.getMessage(), e);
                }
            }
        }
    }
}
Also used : ProgressMonitorDialog(org.eclipse.jface.dialogs.ProgressMonitorDialog) ArrayList(java.util.ArrayList) InvocationTargetException(java.lang.reflect.InvocationTargetException) IRunnableWithProgress(org.eclipse.jface.operation.IRunnableWithProgress) Line(com.amalto.workbench.models.Line) WSGetBusinessConceptKey(com.amalto.workbench.webservices.WSGetBusinessConceptKey) List(org.eclipse.swt.widgets.List) ArrayList(java.util.ArrayList) TreeObject(com.amalto.workbench.models.TreeObject) WSConceptKey(com.amalto.workbench.webservices.WSConceptKey) WSDataModelPK(com.amalto.workbench.webservices.WSDataModelPK) XtentisException(com.amalto.workbench.utils.XtentisException)

Example 3 with WSConceptKey

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

the class AddBrowseItemsWizardR method getKeyElements.

private static List<String> getKeyElements(String datamodel, String concept) {
    java.util.List<String> idList = new ArrayList<String>();
    WSGetBusinessConceptKey wsGetBusinessConceptKey = new WSGetBusinessConceptKey(concept, new WSDataModelPK(datamodel));
    WSConceptKey wsConceptKey;
    try {
        wsConceptKey = RepositoryResourceUtil.getBusinessConceptKey(wsGetBusinessConceptKey);
    } catch (Exception e) {
        log.error(e.getMessage(), e);
        return idList;
    }
    List<String> ids = wsConceptKey.getFields();
    for (String id : ids) {
        // need to care about more case
        if (id.startsWith("/")) {
            // $NON-NLS-1$
            id = id.substring(1);
        } else if (id.startsWith("//")) {
            // $NON-NLS-1$
            id = id.substring(2);
        }
        idList.add(concept + '/' + id);
    }
    return idList;
}
Also used : WSGetBusinessConceptKey(com.amalto.workbench.webservices.WSGetBusinessConceptKey) ArrayList(java.util.ArrayList) WSConceptKey(com.amalto.workbench.webservices.WSConceptKey) LoginException(org.talend.commons.exception.LoginException) PersistenceException(org.talend.commons.exception.PersistenceException) WSDataModelPK(com.amalto.workbench.webservices.WSDataModelPK)

Aggregations

WSConceptKey (com.amalto.workbench.webservices.WSConceptKey)3 ArrayList (java.util.ArrayList)3 XtentisException (com.amalto.workbench.utils.XtentisException)2 WSDataModelPK (com.amalto.workbench.webservices.WSDataModelPK)2 WSGetBusinessConceptKey (com.amalto.workbench.webservices.WSGetBusinessConceptKey)2 InvocationTargetException (java.lang.reflect.InvocationTargetException)2 LoginException (org.talend.commons.exception.LoginException)2 PersistenceException (org.talend.commons.exception.PersistenceException)2 Line (com.amalto.workbench.models.Line)1 TreeObject (com.amalto.workbench.models.TreeObject)1 FileNotFoundException (java.io.FileNotFoundException)1 IOException (java.io.IOException)1 CoreException (org.eclipse.core.runtime.CoreException)1 ProgressMonitorDialog (org.eclipse.jface.dialogs.ProgressMonitorDialog)1 IRunnableWithProgress (org.eclipse.jface.operation.IRunnableWithProgress)1 List (org.eclipse.swt.widgets.List)1 PartInitException (org.eclipse.ui.PartInitException)1 XSDIdentityConstraintDefinition (org.eclipse.xsd.XSDIdentityConstraintDefinition)1 XSDSchema (org.eclipse.xsd.XSDSchema)1 XSDXPathDefinition (org.eclipse.xsd.XSDXPathDefinition)1