Search in sources :

Example 11 with WSDataModel

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

the class XSDEditorUtil method isEditorOpened.

private static boolean isEditorOpened(TreeObject xobject) throws Exception {
    WSDataModel wsDataModel = (WSDataModel) xobject.getWsObject();
    // $NON-NLS-1$//$NON-NLS-2$//$NON-NLS-3$
    String filename = xobject.getDisplayName().replace(" ", "") + ".xsd";
    String content = wsDataModel.getXsdSchema();
    IProject project = createProject(xobject);
    String path = getXObjectPath(xobject);
    int pos = path.indexOf('/');
    String folder = path.substring(0, pos);
    IFolder fold = project.getFolder(folder);
    if (!fold.exists()) {
        fold.create(true, true, null);
    }
    IFile file = fold.getFile(filename);
    if (!file.exists()) {
        return true;
    }
    return false;
}
Also used : WSDataModel(com.amalto.workbench.webservices.WSDataModel) IFile(org.eclipse.core.resources.IFile) IProject(org.eclipse.core.resources.IProject) IFolder(org.eclipse.core.resources.IFolder)

Example 12 with WSDataModel

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

the class XMLEditor method refresh.

public void refresh(TreeObject xobject) {
    state = -1;
    this.xobject = xobject;
    WSDataModel wsObject = (WSDataModel) (xobject.getWsObject());
    Document doc = new Document(Util.formatXsdSource(wsObject.getXsdSchema()));
    setInput(new XMLEditorInput(doc));
}
Also used : WSDataModel(com.amalto.workbench.webservices.WSDataModel) Document(org.eclipse.jface.text.Document) IDocument(org.eclipse.jface.text.IDocument)

Example 13 with WSDataModel

use of com.amalto.workbench.webservices.WSDataModel 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)

Example 14 with WSDataModel

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

the class ExportItemsWizard method doexport.

public void doexport(Object[] selectedObjs, IProgressMonitor monitor) {
    TreeObject[] objs = null;
    if (selectedObjs.length > 0 && selectedObjs[0] instanceof TreeObject) {
        objs = Arrays.asList(selectedObjs).toArray(new TreeObject[0]);
    }
    if (objs == null || objs.length == 0) {
        return;
    }
    monitor.beginTask(Messages.ExportItemsWizard_Export, IProgressMonitor.UNKNOWN);
    Exports eps = new Exports();
    List<TreeObject> exports = new ArrayList<TreeObject>();
    TMDMService service;
    try {
        service = Util.getMDMService(objs[0]);
        try {
            LocalTreeObjectRepository.getInstance().parseElementForOutput(objs);
        } catch (Exception e) {
        }
        for (TreeObject obj : objs) {
            StringWriter sw;
            ArrayList<String> items;
            String encodedID = null;
            switch(obj.getType()) {
                case TreeObject.DATA_CLUSTER:
                    monitor.subTask(Messages.ExportItemsWizard_2);
                    items = new ArrayList<String>();
                    // dataclusters
                    WSDataClusterPK pk = (WSDataClusterPK) obj.getWsKey();
                    try {
                        WSDataCluster cluster = service.getDataCluster(new WSGetDataCluster(pk));
                        // Marshal
                        sw = new StringWriter();
                        Marshaller.marshal(cluster, sw);
                        // $NON-NLS-1$
                        encodedID = URLEncoder.encode(cluster.getName(), "UTF-8");
                        // $NON-NLS-1$
                        writeString(sw.toString(), TreeObject.DATACONTAINER + "/" + encodedID);
                        // $NON-NLS-1$
                        items.add(TreeObject.DATACONTAINER + "/" + encodedID);
                        obj.setItems(items.toArray(new String[items.size()]));
                        exports.add(obj);
                    } catch (Exception e) {
                    }
                    monitor.worked(1);
                    // datacluster contents
                    monitor.subTask(Messages.bind(Messages.ExportItemsWizard_3, pk.getPk()));
                    exportCluster(exports, pk, service);
                    monitor.worked(1);
                    break;
                case TreeObject.DATA_MODEL:
                    monitor.subTask(Messages.ExportItemsWizard_5);
                    items = new ArrayList<String>();
                    // datamodels
                    try {
                        WSDataModel model = service.getDataModel(new WSGetDataModel((WSDataModelPK) obj.getWsKey()));
                        sw = new StringWriter();
                        Marshaller.marshal(model, sw);
                        // $NON-NLS-1$
                        encodedID = URLEncoder.encode(model.getName(), "UTF-8");
                        // $NON-NLS-1$
                        writeString(sw.toString(), TreeObject.DATAMODEL_ + "/" + encodedID);
                        // $NON-NLS-1$
                        items.add(TreeObject.DATAMODEL_ + "/" + encodedID);
                        obj.setItems(items.toArray(new String[items.size()]));
                        exports.add(obj);
                    } catch (Exception e) {
                    }
                    monitor.worked(1);
                    break;
                case TreeObject.MENU:
                    monitor.subTask(Messages.ExportItemsWizard_6);
                    // ExportItem exportItem=new ExportItem();
                    items = new ArrayList<String>();
                    // menu
                    try {
                        WSMenu menu = service.getMenu(new WSGetMenu((WSMenuPK) obj.getWsKey()));
                        // Marshal
                        sw = new StringWriter();
                        Marshaller.marshal(menu, sw);
                        // $NON-NLS-1$
                        encodedID = URLEncoder.encode(menu.getName(), "UTF-8");
                        // $NON-NLS-1$
                        writeString(sw.toString(), TreeObject.MENU_ + "/" + encodedID);
                        // $NON-NLS-1$
                        items.add(TreeObject.MENU_ + "/" + encodedID);
                        obj.setItems(items.toArray(new String[items.size()]));
                        exports.add(obj);
                    } catch (Exception e) {
                    }
                    monitor.worked(1);
                    break;
                case TreeObject.PICTURES_RESOURCE:
                    monitor.subTask(Messages.ExportItemsWizard_7);
                    // ExportItem exportItem=new ExportItem();
                    items = new ArrayList<String>();
                    // picture
                    try {
                        String endpointIpAddress = obj.getEndpointIpAddress();
                        // $NON-NLS-1$
                        int index = endpointIpAddress.indexOf("/services/soap");
                        if (index != -1) {
                            endpointIpAddress = endpointIpAddress.substring(0, index);
                        }
                        String picUrl = endpointIpAddress + ResourcesUtil.getResourcesMapFromURI(endpointIpAddress + TreeObject.PICTURES_URI, objs[0]).get(obj.getDisplayName());
                        // Marshal
                        sw = new StringWriter();
                        byte[] content = HttpClientUtil.getByteArrayContentByHttpget(picUrl);
                        Marshaller.marshal(content, sw);
                        // $NON-NLS-1$
                        encodedID = URLEncoder.encode(obj.getDisplayName(), "UTF-8");
                        // $NON-NLS-1$
                        writeInputStream(new ByteArrayInputStream(content), TreeObject.PICTURES_ + "/" + encodedID);
                        // $NON-NLS-1$
                        items.add(TreeObject.PICTURES_ + "/" + encodedID);
                        obj.setItems(items.toArray(new String[items.size()]));
                        exports.add(obj);
                    } catch (Exception e) {
                        log.error(e.getMessage(), e);
                    }
                    monitor.worked(1);
                    break;
                case TreeObject.ROUTING_RULE:
                    monitor.subTask(Messages.ExportItemsWizard_10);
                    // ExportItem exportItem=new ExportItem();
                    items = new ArrayList<String>();
                    // routing rule
                    try {
                        WSRoutingRule RoutingRule = service.getRoutingRule(new WSGetRoutingRule((WSRoutingRulePK) obj.getWsKey()));
                        // Marshal
                        sw = new StringWriter();
                        Marshaller.marshal(RoutingRule, sw);
                        // $NON-NLS-1$
                        encodedID = URLEncoder.encode(RoutingRule.getName(), "UTF-8");
                        // $NON-NLS-1$
                        writeString(sw.toString(), TreeObject.ROUTINGRULE_ + "/" + encodedID);
                        // $NON-NLS-1$
                        items.add(TreeObject.ROUTINGRULE_ + "/" + encodedID);
                        obj.setItems(items.toArray(new String[items.size()]));
                        exports.add(obj);
                    } catch (Exception e) {
                    }
                    monitor.worked(1);
                    break;
                case TreeObject.STORED_PROCEDURE:
                    monitor.subTask(Messages.ExportItemsWizard_11);
                    items = new ArrayList<String>();
                    // stored procedure
                    try {
                        WSStoredProcedure StoredProcedure = service.getStoredProcedure(new WSGetStoredProcedure((WSStoredProcedurePK) obj.getWsKey()));
                        // Marshal
                        sw = new StringWriter();
                        Marshaller.marshal(StoredProcedure, sw);
                        // $NON-NLS-1$
                        encodedID = URLEncoder.encode(StoredProcedure.getName(), "UTF-8");
                        // $NON-NLS-1$
                        writeString(sw.toString(), TreeObject.STOREDPROCEDURE_ + "/" + encodedID);
                        // $NON-NLS-1$
                        items.add(TreeObject.STOREDPROCEDURE_ + "/" + encodedID);
                        obj.setItems(items.toArray(new String[items.size()]));
                        exports.add(obj);
                    } catch (Exception e) {
                    }
                    monitor.worked(1);
                    break;
                case TreeObject.TRANSFORMER:
                    monitor.subTask(Messages.ExportItemsWizard_13);
                    items = new ArrayList<String>();
                    // TODO:check the pk
                    try {
                        WSTransformerV2 transformer = service.getTransformerV2(new WSGetTransformerV2(new WSTransformerV2PK(((WSTransformerV2PK) obj.getWsKey()).getPk())));
                        // Marshal
                        sw = new StringWriter();
                        Marshaller.marshal(transformer, sw);
                        // $NON-NLS-1$
                        encodedID = URLEncoder.encode(transformer.getName(), "UTF-8");
                        // $NON-NLS-1$
                        writeString(sw.toString(), TreeObject.TRANSFORMER_ + "/" + encodedID);
                        // $NON-NLS-1$
                        items.add(TreeObject.TRANSFORMER_ + "/" + encodedID);
                        obj.setItems(items.toArray(new String[items.size()]));
                        exports.add(obj);
                    } catch (Exception e) {
                    }
                    monitor.worked(1);
                    break;
                case TreeObject.VIEW:
                    monitor.subTask(Messages.ExportItemsWizard_15);
                    items = new ArrayList<String>();
                    // view
                    try {
                        WSView View = service.getView(new WSGetView((WSViewPK) obj.getWsKey()));
                        // Marshal
                        sw = new StringWriter();
                        Marshaller.marshal(View, sw);
                        // $NON-NLS-1$
                        encodedID = URLEncoder.encode(View.getName(), "UTF-8");
                        // $NON-NLS-1$
                        writeString(sw.toString(), TreeObject.VIEW_ + "/" + encodedID);
                        // $NON-NLS-1$
                        items.add(TreeObject.VIEW_ + "/" + encodedID);
                        obj.setItems(items.toArray(new String[items.size()]));
                        exports.add(obj);
                    } catch (Exception e) {
                    }
                    monitor.worked(1);
                    break;
                default:
                    IExportItemsWizardAdapter exAdapter = ExAdapterManager.getAdapter(this, IExportItemsWizardAdapter.class);
                    if (exAdapter != null) {
                        exAdapter.doexport(service, obj.getType(), exports, obj, monitor);
                    }
                    break;
            }
        }
        // store the content xml
        eps.setItems(exports.toArray(new TreeObject[exports.size()]));
        eps.setSchemas(LocalTreeObjectRepository.getInstance().outPutSchemas());
        // export autoincrement
        try {
            WSAutoIncrement auto = service.getAutoIncrement(null);
            if (auto != null && auto.getAutoincrement() != null) {
                eps.setAutoIncrement(auto.getAutoincrement());
            }
        } catch (Exception e) {
        }
        StringWriter sw = new StringWriter();
        try {
            Marshaller.marshal(eps, sw);
            // $NON-NLS-1$
            writeString(sw.toString(), "exportitems.xml");
        } catch (Exception e) {
        }
        monitor.done();
    } catch (Exception e) {
    }
}
Also used : WSGetStoredProcedure(com.amalto.workbench.webservices.WSGetStoredProcedure) WSAutoIncrement(com.amalto.workbench.webservices.WSAutoIncrement) WSMenuPK(com.amalto.workbench.webservices.WSMenuPK) WSGetTransformerV2(com.amalto.workbench.webservices.WSGetTransformerV2) WSStoredProcedurePK(com.amalto.workbench.webservices.WSStoredProcedurePK) ArrayList(java.util.ArrayList) WSView(com.amalto.workbench.webservices.WSView) WSDataCluster(com.amalto.workbench.webservices.WSDataCluster) WSGetDataModel(com.amalto.workbench.webservices.WSGetDataModel) WSDataClusterPK(com.amalto.workbench.webservices.WSDataClusterPK) StringWriter(java.io.StringWriter) TMDMService(com.amalto.workbench.webservices.TMDMService) WSRoutingRule(com.amalto.workbench.webservices.WSRoutingRule) WSStoredProcedure(com.amalto.workbench.webservices.WSStoredProcedure) WSGetView(com.amalto.workbench.webservices.WSGetView) WSGetMenu(com.amalto.workbench.webservices.WSGetMenu) WSRoutingRulePK(com.amalto.workbench.webservices.WSRoutingRulePK) WSGetRoutingRule(com.amalto.workbench.webservices.WSGetRoutingRule) WSMenu(com.amalto.workbench.webservices.WSMenu) WSGetDataCluster(com.amalto.workbench.webservices.WSGetDataCluster) WSDataModel(com.amalto.workbench.webservices.WSDataModel) WSTransformerV2(com.amalto.workbench.webservices.WSTransformerV2) ByteArrayInputStream(java.io.ByteArrayInputStream) WSTransformerV2PK(com.amalto.workbench.webservices.WSTransformerV2PK) TreeObject(com.amalto.workbench.models.TreeObject) WSDataModelPK(com.amalto.workbench.webservices.WSDataModelPK) WSViewPK(com.amalto.workbench.webservices.WSViewPK)

Example 15 with WSDataModel

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

the class DataModelMainPage method save.

public int save(String xsd) {
    try {
        WSDataModel wsObject = (WSDataModel) (xobject.getWsObject());
        wsObject.setDescription(desAntionComposite.getText());
        String schema = xsd;
        if (xsd == null) {
            schema = ((SchemaTreeContentProvider) viewer.getContentProvider()).getXSDSchemaAsString();
            xsdSchema = ((SchemaTreeContentProvider) viewer.getContentProvider()).getXsdSchema();
        }
        XSDImport xsdImport = XSDFactory.eINSTANCE.createXSDImport();
        // $NON-NLS-1$
        xsdImport.setNamespace("http://www.w3.org/2001/XMLSchema");
        if (xsdSchema == null) {
            xsdSchema = ((SchemaTreeContentProvider) viewer.getContentProvider()).getXsdSchema();
        }
        if (xsdSchema == null || (xsd != null && !xsd.equals(wsObject.getXsdSchema())) || (xsd != null && !xsd.equals(getXSDSchemaString()))) {
            // 
            xsdSchema = Util.createXsdSchema(schema, xobject);
            // 
            getSchemaContentProvider().setXsdSchema(xsdSchema);
        }
        wsObject.setXsdSchema(schema);
        EList<XSDSchemaContent> elist = xsdSchema.getContents();
        for (XSDSchemaContent cnt : elist) {
            if (cnt instanceof XSDImport) {
                XSDImport imp = (XSDImport) cnt;
                if (imp.getNamespace().equals("http://www.w3.org/2001/XMLSchema")) {
                    // $NON-NLS-1$
                    xsdImport = null;
                    break;
                }
            }
        }
        if (xsdImport != null) {
            xsdSchema.getContents().add(0, xsdImport);
            wsObject.setXsdSchema(schema);
        }
        validateSchema();
        // save to db
        doSave(wsObject);
        dirty = false;
    } catch (Exception e) {
        dirty = true;
        log.error(e.getMessage(), e);
    }
    firePropertyChange(PROP_DIRTY);
    return dirty ? 1 : 0;
}
Also used : WSDataModel(com.amalto.workbench.webservices.WSDataModel) XSDSchemaContent(org.eclipse.xsd.XSDSchemaContent) XSDImport(org.eclipse.xsd.XSDImport) CoreException(org.eclipse.core.runtime.CoreException) PartInitException(org.eclipse.ui.PartInitException) SAXParseException(org.xml.sax.SAXParseException)

Aggregations

WSDataModel (com.amalto.workbench.webservices.WSDataModel)23 WSDataModelPK (com.amalto.workbench.webservices.WSDataModelPK)10 WSGetDataModel (com.amalto.workbench.webservices.WSGetDataModel)10 SAXParseException (org.xml.sax.SAXParseException)8 TMDMService (com.amalto.workbench.webservices.TMDMService)6 PartInitException (org.eclipse.ui.PartInitException)6 TreeObject (com.amalto.workbench.models.TreeObject)5 XSDSchema (org.eclipse.xsd.XSDSchema)5 ByteArrayInputStream (java.io.ByteArrayInputStream)4 IFile (org.eclipse.core.resources.IFile)4 CoreException (org.eclipse.core.runtime.CoreException)4 TreeParent (com.amalto.workbench.models.TreeParent)3 WSDataCluster (com.amalto.workbench.webservices.WSDataCluster)3 WSDataClusterPK (com.amalto.workbench.webservices.WSDataClusterPK)3 WSGetDataCluster (com.amalto.workbench.webservices.WSGetDataCluster)3 WSGetMenu (com.amalto.workbench.webservices.WSGetMenu)3 WSGetRoutingRule (com.amalto.workbench.webservices.WSGetRoutingRule)3 WSGetStoredProcedure (com.amalto.workbench.webservices.WSGetStoredProcedure)3 WSGetTransformerV2 (com.amalto.workbench.webservices.WSGetTransformerV2)3 WSGetView (com.amalto.workbench.webservices.WSGetView)3