Search in sources :

Example 1 with AbstractCouchDbTransaction

use of com.twinsoft.convertigo.beans.transactions.couchdb.AbstractCouchDbTransaction in project convertigo by convertigo.

the class NewObjectWizard method doFinish.

private void doFinish(IProgressMonitor monitor) throws CoreException {
    String dboName, name;
    boolean bContinue = true;
    int index = 0;
    try {
        int total = 0;
        Class<?> c = getCreatedBeanClass();
        if (c != null) {
            total = 4;
            if (c.equals(WebServiceReference.class)) {
                total += ImportWsReference.getTotalTaskNumber();
            }
        }
        monitor.beginTask("Creating new object", total);
        newBean = getCreatedBean();
        if (newBean != null) {
            monitor.setTaskName("Object created");
            monitor.worked(1);
            dboName = newBean.getName();
            if (!StringUtils.isNormalized(dboName))
                throw new EngineException("Bean name is not normalized : \"" + dboName + "\".");
            // Verify if a child object with same name exist and change name
            while (bContinue) {
                if (index == 0)
                    name = dboName;
                else
                    name = dboName + index;
                newBean.setName(name);
                newBean.hasChanged = true;
                newBean.bNew = true;
                try {
                    new WalkHelper() {

                        boolean root = true;

                        boolean find = false;

                        @Override
                        protected boolean before(DatabaseObject dbo, Class<? extends DatabaseObject> dboClass) {
                            boolean isInstance = dboClass.isInstance(newBean);
                            find |= isInstance;
                            return isInstance;
                        }

                        @Override
                        protected void walk(DatabaseObject dbo) throws Exception {
                            if (root) {
                                root = false;
                                super.walk(dbo);
                                if (!find) {
                                    throw new EngineException("You cannot add to a " + newBean.getClass().getSimpleName() + " a database object of type " + parentObject.getClass().getSimpleName());
                                }
                            } else {
                                if (newBean.getName().equalsIgnoreCase(dbo.getName())) {
                                    throw new ObjectWithSameNameException("Unable to add the object because an object with the same name already exists in target.");
                                }
                            }
                        }
                    }.init(parentObject);
                    bContinue = false;
                } catch (ObjectWithSameNameException owsne) {
                    if ((parentObject instanceof HtmlTransaction) && (newBean instanceof Statement)) {
                        throw new EngineException("HtmlTransaction already contains a statement named \"" + name + "\".", owsne);
                    }
                    // Silently ignore
                    index++;
                } catch (EngineException ee) {
                    throw ee;
                } catch (Exception e) {
                    throw new EngineException("Exception in create", e);
                }
            }
            // Now add bean to target
            try {
                boolean hasChanged = parentObject.hasChanged;
                if ((newBean instanceof Statement) && (parentObject instanceof Transaction)) {
                    newBean.priority = 0;
                }
                if (newBean instanceof ScreenClass)
                    newBean.priority = parentObject.priority + 1;
                if (newBean instanceof Criteria) {
                    Connector connector = parentObject.getConnector();
                    if (parentObject.equals(((IScreenClassContainer<?>) connector).getDefaultScreenClass()))
                        throw new EngineException("You cannot add a new criterion on default screenclass.");
                }
                parentObject.add(newBean);
                monitor.setTaskName("Object added");
                monitor.worked(1);
                if (newBean instanceof HTTPStatement) {
                    HTTPStatement httpStatement = (HTTPStatement) newBean;
                    HtmlConnector connector = (HtmlConnector) httpStatement.getParentTransaction().getParent();
                    httpStatement.setMethod("GET");
                    httpStatement.setHost(connector.getServer());
                    httpStatement.setPort(connector.getPort());
                    httpStatement.setHttps(connector.isHttps());
                }
                if (newBean instanceof ContinueWithSiteClipperStatement) {
                    Project project = newBean.getProject();
                    if (project != null) {
                        String[] connectorWithSiteClipperConnector = ContinueWithSiteClipperStatement.getSiteClippersConnectorNames(project);
                        if (connectorWithSiteClipperConnector.length > 0) {
                            ((ContinueWithSiteClipperStatement) newBean).setSiteClipperConnectorName(connectorWithSiteClipperConnector[0]);
                        }
                    }
                }
                if (newBean instanceof Connector) {
                    Project project = (Project) parentObject;
                    if (project.getDefaultConnector() == null)
                        project.setDefaultConnector((Connector) newBean);
                    Connector.setupConnector(newBean);
                }
                if (newBean instanceof PageComponent) {
                    ApplicationComponent application = (ApplicationComponent) parentObject;
                    if (application.getRootPage() == null)
                        application.setRootPage((PageComponent) newBean);
                }
                if (newBean instanceof SequenceStep) {
                    Project project = newBean.getProject();
                    ((SequenceStep) newBean).setSourceSequence(project.getName() + TransactionStep.SOURCE_SEPARATOR + project.getSequencesList().get(0));
                }
                if (newBean instanceof TransactionStep) {
                    Project project = newBean.getProject();
                    Connector connector = project.getDefaultConnector();
                    Transaction transaction = connector.getDefaultTransaction();
                    ((TransactionStep) newBean).setSourceTransaction(project.getName() + TransactionStep.SOURCE_SEPARATOR + connector.getName() + TransactionStep.SOURCE_SEPARATOR + transaction.getName());
                }
                if (newBean instanceof IThenElseContainer) {
                    ThenStep thenStep = new ThenStep();
                    ((IThenElseContainer) newBean).addStep(thenStep);
                    ElseStep elseStep = new ElseStep();
                    ((IThenElseContainer) newBean).addStep(elseStep);
                }
                if (newBean instanceof IThenElseStatementContainer) {
                    ThenStatement thenStatement = new ThenStatement();
                    ((IThenElseStatementContainer) newBean).addStatement(thenStatement);
                    ElseStatement elseStatement = new ElseStatement();
                    ((IThenElseStatementContainer) newBean).addStatement(elseStatement);
                }
                if (newBean instanceof Sheet) {
                    InputStream is = null;
                    try {
                        String sheetName = newBean.getName() + ".xsl";
                        is = new FileInputStream(new File(Engine.XSL_PATH + "/customsheet.xsl"));
                        String projectName = ((DatabaseObject) parentObject).getProject().getName();
                        IProject project = ConvertigoPlugin.getDefault().getProjectPluginResource(projectName);
                        final IFile file = project.getFile(sheetName);
                        if (!file.exists())
                            file.create(is, true, null);
                        ((Sheet) newBean).setUrl(sheetName);
                    } catch (Exception e) {
                    } finally {
                        if (is != null) {
                            try {
                                is.close();
                            } catch (IOException e) {
                            }
                        }
                    }
                }
                if (newBean instanceof TestCase) {
                    TestCase testCase = (TestCase) newBean;
                    testCase.importRequestableVariables((RequestableObject) testCase.getParent());
                }
                if (newBean instanceof RequestableHttpVariable) {
                    RequestableHttpVariable variable = (RequestableHttpVariable) newBean;
                    AbstractHttpTransaction httpTransaction = (AbstractHttpTransaction) variable.getParent();
                    HttpMethodType httpMethodType = httpTransaction.getHttpVerb();
                    boolean isVarPost = httpMethodType.equals(HttpMethodType.PUT) || httpMethodType.equals(HttpMethodType.POST);
                    variable.setHttpMethod(isVarPost ? HttpMethodType.POST.name() : HttpMethodType.GET.name());
                    if (!(httpTransaction instanceof HtmlTransaction)) {
                        variable.setHttpName(variable.getName());
                    }
                }
                if (newBean instanceof WebServiceReference) {
                    try {
                        Project project = (Project) parentObject;
                        WebServiceReference webServiceReference = (WebServiceReference) newBean;
                        ImportWsReference wsr = new ImportWsReference(webServiceReference);
                        wsr.importInto(project);
                    } catch (Exception e) {
                        if (newBean != null) {
                            parentObject.remove(newBean);
                            parentObject.hasChanged = hasChanged;
                        }
                        throw new Exception(e);
                    }
                }
                if (newBean instanceof RestServiceReference) {
                    try {
                        Project project = (Project) parentObject;
                        RestServiceReference restServiceReference = (RestServiceReference) newBean;
                        ImportWsReference wsr = new ImportWsReference(restServiceReference);
                        wsr.importInto(project);
                    } catch (Exception e) {
                        if (newBean != null) {
                            parentObject.remove(newBean);
                            parentObject.hasChanged = hasChanged;
                        }
                        throw new Exception(e);
                    }
                }
                if (newBean instanceof SqlTransaction) {
                    SqlTransaction sqlTransaction = (SqlTransaction) newBean;
                    sqlTransaction.setSqlQuery(sqlQueriesWizardPage.getSQLQueries());
                    sqlTransaction.initializeQueries(true);
                }
                if (newBean instanceof SapJcoLogonTransaction) {
                    SapJcoLogonTransaction sapLogonTransaction = (SapJcoLogonTransaction) newBean;
                    sapLogonTransaction.addCredentialsVariables();
                }
                if (newBean instanceof AbstractCouchDbTransaction) {
                    AbstractCouchDbTransaction abstractCouchDbTransaction = (AbstractCouchDbTransaction) newBean;
                    List<CouchVariable> selectedVariables = objectInfoPage.getSelectedParameters();
                    abstractCouchDbTransaction.createVariables(selectedVariables);
                }
                ConvertigoPlugin.logInfo("New object class '" + this.className + "' named '" + newBean.getName() + "' has been added");
                monitor.setTaskName("Object setted up");
                monitor.worked(1);
                bContinue = false;
            } catch (com.twinsoft.convertigo.engine.ObjectWithSameNameException owsne) {
                if (newBean instanceof HandlerStatement) {
                    throw owsne;
                }
            }
        } else {
            throw new Exception("Could not instantiate bean!");
        }
    } catch (Exception e) {
        String message = "Unable to create a new object from class '" + this.className + "'.";
        ConvertigoPlugin.logException(e, message);
        if (objectExplorerPage != null) {
            objectExplorerPage.doCancel();
        }
    }
}
Also used : RestServiceReference(com.twinsoft.convertigo.beans.references.RestServiceReference) RequestableHttpVariable(com.twinsoft.convertigo.beans.variables.RequestableHttpVariable) ContinueWithSiteClipperStatement(com.twinsoft.convertigo.beans.statements.ContinueWithSiteClipperStatement) IThenElseContainer(com.twinsoft.convertigo.beans.steps.IThenElseContainer) ElseStep(com.twinsoft.convertigo.beans.steps.ElseStep) HttpMethodType(com.twinsoft.convertigo.engine.enums.HttpMethodType) ScreenClass(com.twinsoft.convertigo.beans.core.ScreenClass) EngineException(com.twinsoft.convertigo.engine.EngineException) HTTPStatement(com.twinsoft.convertigo.beans.statements.HTTPStatement) AbstractHttpTransaction(com.twinsoft.convertigo.beans.transactions.AbstractHttpTransaction) DatabaseObject(com.twinsoft.convertigo.beans.core.DatabaseObject) SequenceStep(com.twinsoft.convertigo.beans.steps.SequenceStep) AbstractCouchDbTransaction(com.twinsoft.convertigo.beans.transactions.couchdb.AbstractCouchDbTransaction) ThenStatement(com.twinsoft.convertigo.beans.statements.ThenStatement) FileInputStream(java.io.FileInputStream) IProject(org.eclipse.core.resources.IProject) Project(com.twinsoft.convertigo.beans.core.Project) SqlTransaction(com.twinsoft.convertigo.beans.transactions.SqlTransaction) SapJcoLogonTransaction(com.twinsoft.convertigo.beans.transactions.SapJcoLogonTransaction) Transaction(com.twinsoft.convertigo.beans.core.Transaction) AbstractHttpTransaction(com.twinsoft.convertigo.beans.transactions.AbstractHttpTransaction) AbstractCouchDbTransaction(com.twinsoft.convertigo.beans.transactions.couchdb.AbstractCouchDbTransaction) HtmlTransaction(com.twinsoft.convertigo.beans.transactions.HtmlTransaction) ElseStatement(com.twinsoft.convertigo.beans.statements.ElseStatement) IFile(org.eclipse.core.resources.IFile) File(java.io.File) CouchVariable(com.twinsoft.convertigo.beans.transactions.couchdb.CouchVariable) HtmlConnector(com.twinsoft.convertigo.beans.connectors.HtmlConnector) Connector(com.twinsoft.convertigo.beans.core.Connector) SqlConnector(com.twinsoft.convertigo.beans.connectors.SqlConnector) IFile(org.eclipse.core.resources.IFile) SapJcoLogonTransaction(com.twinsoft.convertigo.beans.transactions.SapJcoLogonTransaction) WalkHelper(com.twinsoft.convertigo.engine.helpers.WalkHelper) Criteria(com.twinsoft.convertigo.beans.core.Criteria) HandlerStatement(com.twinsoft.convertigo.beans.statements.HandlerStatement) PageComponent(com.twinsoft.convertigo.beans.mobile.components.PageComponent) ThenStep(com.twinsoft.convertigo.beans.steps.ThenStep) ImportWsReference(com.twinsoft.convertigo.engine.util.ImportWsReference) IThenElseStatementContainer(com.twinsoft.convertigo.beans.statements.IThenElseStatementContainer) HtmlConnector(com.twinsoft.convertigo.beans.connectors.HtmlConnector) ElseStatement(com.twinsoft.convertigo.beans.statements.ElseStatement) HTTPStatement(com.twinsoft.convertigo.beans.statements.HTTPStatement) Statement(com.twinsoft.convertigo.beans.core.Statement) ContinueWithSiteClipperStatement(com.twinsoft.convertigo.beans.statements.ContinueWithSiteClipperStatement) ThenStatement(com.twinsoft.convertigo.beans.statements.ThenStatement) HandlerStatement(com.twinsoft.convertigo.beans.statements.HandlerStatement) ApplicationComponent(com.twinsoft.convertigo.beans.mobile.components.ApplicationComponent) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) HtmlTransaction(com.twinsoft.convertigo.beans.transactions.HtmlTransaction) SqlTransaction(com.twinsoft.convertigo.beans.transactions.SqlTransaction) IOException(java.io.IOException) CoreException(org.eclipse.core.runtime.CoreException) InvocationTargetException(java.lang.reflect.InvocationTargetException) EngineException(com.twinsoft.convertigo.engine.EngineException) IOException(java.io.IOException) ObjectWithSameNameException(com.twinsoft.convertigo.engine.ObjectWithSameNameException) IProject(org.eclipse.core.resources.IProject) TransactionStep(com.twinsoft.convertigo.beans.steps.TransactionStep) ObjectWithSameNameException(com.twinsoft.convertigo.engine.ObjectWithSameNameException) TestCase(com.twinsoft.convertigo.beans.core.TestCase) WebServiceReference(com.twinsoft.convertigo.beans.references.WebServiceReference) Sheet(com.twinsoft.convertigo.beans.core.Sheet) ObjectWithSameNameException(com.twinsoft.convertigo.engine.ObjectWithSameNameException)

Example 2 with AbstractCouchDbTransaction

use of com.twinsoft.convertigo.beans.transactions.couchdb.AbstractCouchDbTransaction in project convertigo by convertigo.

the class NgxPickerComposite method getJsonModel.

private JSONObject getJsonModel(Map<String, Object> data, DatabaseObject databaseObject) throws Exception {
    JSONObject jsonModel = new JSONObject();
    Map<String, String> params;
    DatabaseObject dbo;
    String dataPath;
    if (databaseObject == null) {
        dbo = (DatabaseObject) data.get("databaseObject");
        params = GenericUtils.cast(data.get("params"));
        dataPath = (String) data.get("searchPath");
    } else {
        dbo = databaseObject;
        params = new HashMap<String, String>();
        dataPath = "";
    }
    if (dbo != null) {
        // case of requestable
        if (dbo instanceof RequestableObject) {
            RequestableObject ro = (RequestableObject) dbo;
            Project project = ro.getProject();
            String responseEltName = ro.getXsdTypePrefix() + ro.getName() + "Response";
            boolean isDocumentNode = JsonRoot.docNode.equals(project.getJsonRoot()) && dataPath.isEmpty();
            XmlSchema schema = Engine.theApp.schemaManager.getSchemaForProject(project.getName());
            XmlSchemaObject xso = SchemaMeta.getXmlSchemaObject(schema, ro);
            if (xso != null) {
                Document document = XmlSchemaUtils.getDomInstance(xso);
                // System.out.println(XMLUtils.prettyPrintDOM(document));
                String jsonString = XMLUtils.XmlToJson(document.getDocumentElement(), true, true);
                JSONObject jsonObject = new JSONObject(jsonString);
                String searchPath = "document." + responseEltName + ".response";
                searchPath += isDocumentNode || !dataPath.startsWith(".document") ? dataPath : dataPath.replaceFirst("\\.document", "");
                JSONObject jsonOutput = findJSONObject(jsonObject, searchPath);
                jsonModel = isDocumentNode ? new JSONObject().put("document", jsonOutput) : jsonOutput;
            }
        } else if (dbo instanceof DesignDocument) {
            DesignDocument dd = (DesignDocument) dbo;
            Connector connector = dd.getConnector();
            String ddoc = params.get("ddoc");
            String view = params.get("view");
            String viewName = ddoc + "/" + view;
            String includeDocs = params.get("include_docs");
            Display.getDefault().asyncExec(new Runnable() {

                public void run() {
                    IWorkbenchPage activePage = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
                    ConnectorEditor connectorEditor = ConvertigoPlugin.getDefault().getConnectorEditor(connector);
                    if (connectorEditor == null) {
                        try {
                            connectorEditor = (ConnectorEditor) activePage.openEditor(new ConnectorEditorInput(connector), "com.twinsoft.convertigo.eclipse.editors.connector.ConnectorEditor");
                        } catch (PartInitException e) {
                            ConvertigoPlugin.logException(e, "Error while loading the connector editor '" + connector.getName() + "'");
                        }
                    }
                    if (connectorEditor != null) {
                        // activate connector's editor
                        activePage.activate(connectorEditor);
                        // set transaction's parameters
                        Transaction transaction = connector.getTransactionByName(CouchDbConnector.internalView);
                        ((GetViewTransaction) transaction).setViewname(viewName);
                        ((GetViewTransaction) transaction).setQ_include_docs(includeDocs);
                        Variable view_reduce = ((GetViewTransaction) transaction).getVariable(CouchParam.prefix + "reduce");
                        view_reduce.setValueOrNull(false);
                        // execute view transaction
                        connectorEditor.getDocument(CouchDbConnector.internalView, false);
                    }
                }
            });
        } else // case of UIForm
        if (dbo instanceof UIForm) {
            // JSONObject jsonObject = new JSONObject("{\"controls\":{\"['area']\":{\"value\":\"\"}}}");
            JSONObject jsonObject = new JSONObject(((UIForm) dbo).computeJsonModel());
            String searchPath = dataPath;
            JSONObject jsonOutput = findJSONObject(jsonObject, searchPath);
            jsonModel = jsonOutput;
        } else // case of UIACtionStack
        if (dbo instanceof UIActionStack) {
            JSONObject jsonObject = new JSONObject(((UIActionStack) dbo).computeJsonModel());
            String searchPath = dataPath;
            JSONObject jsonOutput = findJSONObject(jsonObject, searchPath);
            jsonModel = jsonOutput;
        } else // case of UIDynamicAction or UICustomAction
        if (dbo instanceof IAction) {
            JSONObject jsonObject = new JSONObject();
            if (dbo instanceof UIDynamicAction) {
                UIDynamicAction uida = (UIDynamicAction) dbo;
                jsonObject = new JSONObject(uida.computeJsonModel());
                IonBean ionBean = uida.getIonBean();
                if (ionBean != null) {
                    String name = ionBean.getName();
                    if ("CallSequenceAction".equals(name)) {
                        String qname = ionBean.getProperty("requestable").getValue().toString();
                        DatabaseObject sequence = Engine.theApp.databaseObjectsManager.getDatabaseObjectByQName(qname);
                        if (sequence != null) {
                            JSONObject targetJsonModel = getJsonModel(data, sequence);
                            if (jsonObject.has("out")) {
                                jsonObject.put("out", targetJsonModel);
                            }
                        }
                    } else if ("CallFullSyncAction".equals(name)) {
                        String qname = ionBean.getProperty("requestable").getValue().toString();
                        String verb = ionBean.getProperty("verb").getValue().toString();
                        Connector connector = (Connector) Engine.theApp.databaseObjectsManager.getDatabaseObjectByQName(qname);
                        if (connector != null) {
                            XmlSchema schema = Engine.theApp.schemaManager.getSchemaForProject(connector.getProject().getName());
                            AbstractCouchDbTransaction act = null;
                            if ("all".equals(verb))
                                act = new AllDocsTransaction();
                            else if ("create".equals(verb))
                                act = new PutDatabaseTransaction();
                            else if ("destroy".equals(verb))
                                act = new DeleteDatabaseTransaction();
                            else if ("get".equals(verb))
                                act = new GetDocumentTransaction();
                            else if ("delete".equals(verb))
                                act = new DeleteDocumentTransaction();
                            else if ("delete_attachment".equals(verb))
                                act = new DeleteDocumentAttachmentTransaction();
                            else if ("post".equals(verb))
                                act = new PostDocumentTransaction();
                            else if ("put_attachment".equals(verb))
                                act = new PutDocumentAttachmentTransaction();
                            else if ("replicate_push".equals(verb))
                                act = new PostReplicateTransaction();
                            else if ("reset".equals(verb))
                                act = new ResetDatabaseTransaction();
                            else if ("view".equals(verb))
                                act = new GetViewTransaction();
                            if (act != null) {
                                QName typeQName = act.getComplexTypeAffectation();
                                XmlSchemaType xmlSchemaType = schema.getTypeByName(typeQName);
                                Document document = XmlSchemaUtils.getDomInstance(xmlSchemaType);
                                String jsonString = XMLUtils.XmlToJson(document.getDocumentElement(), true, true);
                                JSONObject jsonOutput = new JSONObject(jsonString).getJSONObject("document");
                                cleanJsonModel(jsonOutput);
                                jsonOutput.remove("_c8oMeta");
                                jsonOutput.remove("error");
                                jsonOutput.remove("reason");
                                if (jsonObject.has("out")) {
                                    jsonObject.put("out", jsonOutput);
                                }
                            }
                        }
                    } else if ("FullSyncGetAction".equals(name)) {
                        String qname = ionBean.getProperty("requestable").getValue().toString();
                        String docid = ionBean.getProperty("_id").getValue().toString();
                        Connector connector = (Connector) Engine.theApp.databaseObjectsManager.getDatabaseObjectByQName(qname);
                        if (connector != null) {
                            Display.getDefault().asyncExec(new Runnable() {

                                public void run() {
                                    IWorkbenchPage activePage = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
                                    ConnectorEditor connectorEditor = ConvertigoPlugin.getDefault().getConnectorEditor(connector);
                                    if (connectorEditor == null) {
                                        try {
                                            connectorEditor = (ConnectorEditor) activePage.openEditor(new ConnectorEditorInput(connector), "com.twinsoft.convertigo.eclipse.editors.connector.ConnectorEditor");
                                        } catch (PartInitException e) {
                                            ConvertigoPlugin.logException(e, "Error while loading the connector editor '" + connector.getName() + "'");
                                        }
                                    }
                                    if (connectorEditor != null) {
                                        // activate connector's editor
                                        activePage.activate(connectorEditor);
                                        // set transaction's parameters
                                        Transaction transaction = connector.getTransactionByName(CouchDbConnector.internalDocument);
                                        Variable var_docid = ((GetDocumentTransaction) transaction).getVariable(CouchParam.docid.param());
                                        var_docid.setValueOrNull(docid);
                                        // execute view transaction
                                        connectorEditor.getDocument(CouchDbConnector.internalDocument, false);
                                    }
                                }
                            });
                        }
                    } else if ("FullSyncViewAction".equals(name)) {
                        String fsview = ionBean.getProperty("fsview").getValue().toString();
                        String includeDocs = ionBean.getProperty("include_docs").getValue().toString();
                        String reduce = ionBean.getProperty("reduce").getValue().toString();
                        String qname = fsview.substring(0, fsview.lastIndexOf('.'));
                        DesignDocument dd = (DesignDocument) Engine.theApp.databaseObjectsManager.getDatabaseObjectByQName(qname);
                        Connector connector = dd.getConnector();
                        String viewName = dd.getName() + "/" + fsview.substring(fsview.lastIndexOf('.') + 1);
                        Display.getDefault().asyncExec(new Runnable() {

                            public void run() {
                                IWorkbenchPage activePage = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
                                ConnectorEditor connectorEditor = ConvertigoPlugin.getDefault().getConnectorEditor(connector);
                                if (connectorEditor == null) {
                                    try {
                                        connectorEditor = (ConnectorEditor) activePage.openEditor(new ConnectorEditorInput(connector), "com.twinsoft.convertigo.eclipse.editors.connector.ConnectorEditor");
                                    } catch (PartInitException e) {
                                        ConvertigoPlugin.logException(e, "Error while loading the connector editor '" + connector.getName() + "'");
                                    }
                                }
                                if (connectorEditor != null) {
                                    // activate connector's editor
                                    activePage.activate(connectorEditor);
                                    // set transaction's parameters
                                    Transaction transaction = connector.getTransactionByName(CouchDbConnector.internalView);
                                    ((GetViewTransaction) transaction).setViewname(viewName);
                                    ((GetViewTransaction) transaction).setQ_include_docs(includeDocs);
                                    Variable view_reduce = ((GetViewTransaction) transaction).getVariable(CouchParam.prefix + "reduce");
                                    view_reduce.setValueOrNull(reduce);
                                    // execute view transaction
                                    connectorEditor.getDocument(CouchDbConnector.internalView, false);
                                }
                            }
                        });
                    } else if (name.startsWith("FullSync")) {
                        if (ionBean.getProperty("requestable") != null) {
                            String qname = ionBean.getProperty("requestable").getValue().toString();
                            DatabaseObject connector = Engine.theApp.databaseObjectsManager.getDatabaseObjectByQName(qname);
                            if (connector != null) {
                                XmlSchema schema = Engine.theApp.schemaManager.getSchemaForProject(connector.getProject().getName());
                                AbstractCouchDbTransaction act = null;
                                if ("FullSyncDeleteAction".equals(name))
                                    act = new DeleteDocumentTransaction();
                                else if ("FullSyncDeleteAttachmentAction".equals(name))
                                    act = new DeleteDocumentAttachmentTransaction();
                                else if ("FullSyncPostAction".equals(name))
                                    act = new PostDocumentTransaction();
                                else if ("FullSyncPutAttachmentAction".equals(name))
                                    act = new PutDocumentAttachmentTransaction();
                                if (act != null) {
                                    QName typeQName = act.getComplexTypeAffectation();
                                    XmlSchemaType xmlSchemaType = schema.getTypeByName(typeQName);
                                    Document document = XmlSchemaUtils.getDomInstance(xmlSchemaType);
                                    String jsonString = XMLUtils.XmlToJson(document.getDocumentElement(), true, true);
                                    JSONObject jsonOutput = new JSONObject(jsonString).getJSONObject("document");
                                    cleanJsonModel(jsonOutput);
                                    jsonOutput.remove("_c8oMeta");
                                    jsonOutput.remove("error");
                                    jsonOutput.remove("reason");
                                    if (jsonObject.has("out")) {
                                        jsonObject.put("out", jsonOutput);
                                    }
                                }
                            }
                        }
                    }
                }
            } else if (dbo instanceof UICustomAction) {
                jsonObject = new JSONObject(((UICustomAction) dbo).computeJsonModel());
            }
            String searchPath = dataPath;
            JSONObject jsonOutput = findJSONObject(jsonObject, searchPath);
            jsonModel = jsonOutput;
        } else // case of UISharedComponent
        if (dbo instanceof UISharedComponent) {
            JSONObject jsonObject = new JSONObject(((UISharedComponent) dbo).computeJsonModel());
            String searchPath = dataPath;
            JSONObject jsonOutput = findJSONObject(jsonObject, searchPath);
            jsonModel = jsonOutput;
        } else // case of ApplicationComponent
        if (dbo instanceof ApplicationComponent) {
            String json = params.get("json");
            jsonModel = new JSONObject(json);
        } else // should not happened
        {
            throw new Exception("DatabaseObject " + dbo.getClass().getName() + " not supported!");
        }
    }
    return jsonModel;
}
Also used : CouchDbConnector(com.twinsoft.convertigo.beans.connectors.CouchDbConnector) Connector(com.twinsoft.convertigo.beans.core.Connector) Variable(com.twinsoft.convertigo.beans.core.Variable) IonBean(com.twinsoft.convertigo.beans.ngx.components.dynamic.IonBean) UIForm(com.twinsoft.convertigo.beans.ngx.components.UIForm) GetDocumentTransaction(com.twinsoft.convertigo.beans.transactions.couchdb.GetDocumentTransaction) PostDocumentTransaction(com.twinsoft.convertigo.beans.transactions.couchdb.PostDocumentTransaction) Document(org.w3c.dom.Document) DesignDocument(com.twinsoft.convertigo.beans.couchdb.DesignDocument) ConnectorEditor(com.twinsoft.convertigo.eclipse.editors.connector.ConnectorEditor) ConnectorEditorInput(com.twinsoft.convertigo.eclipse.editors.connector.ConnectorEditorInput) DeleteDatabaseTransaction(com.twinsoft.convertigo.beans.transactions.couchdb.DeleteDatabaseTransaction) UISharedComponent(com.twinsoft.convertigo.beans.ngx.components.UISharedComponent) AllDocsTransaction(com.twinsoft.convertigo.beans.transactions.couchdb.AllDocsTransaction) DeleteDocumentTransaction(com.twinsoft.convertigo.beans.transactions.couchdb.DeleteDocumentTransaction) XmlSchemaObject(org.apache.ws.commons.schema.XmlSchemaObject) DatabaseObject(com.twinsoft.convertigo.beans.core.DatabaseObject) PartInitException(org.eclipse.ui.PartInitException) PutDocumentAttachmentTransaction(com.twinsoft.convertigo.beans.transactions.couchdb.PutDocumentAttachmentTransaction) RequestableObject(com.twinsoft.convertigo.beans.core.RequestableObject) IAction(com.twinsoft.convertigo.beans.ngx.components.IAction) AbstractCouchDbTransaction(com.twinsoft.convertigo.beans.transactions.couchdb.AbstractCouchDbTransaction) PutDatabaseTransaction(com.twinsoft.convertigo.beans.transactions.couchdb.PutDatabaseTransaction) QName(javax.xml.namespace.QName) ApplicationComponent(com.twinsoft.convertigo.beans.ngx.components.ApplicationComponent) DeleteDocumentAttachmentTransaction(com.twinsoft.convertigo.beans.transactions.couchdb.DeleteDocumentAttachmentTransaction) ResetDatabaseTransaction(com.twinsoft.convertigo.beans.transactions.couchdb.ResetDatabaseTransaction) XmlSchemaType(org.apache.ws.commons.schema.XmlSchemaType) PartInitException(org.eclipse.ui.PartInitException) JSONException(org.codehaus.jettison.json.JSONException) Project(com.twinsoft.convertigo.beans.core.Project) UIActionStack(com.twinsoft.convertigo.beans.ngx.components.UIActionStack) GetViewTransaction(com.twinsoft.convertigo.beans.transactions.couchdb.GetViewTransaction) UIDynamicAction(com.twinsoft.convertigo.beans.ngx.components.UIDynamicAction) JSONObject(org.codehaus.jettison.json.JSONObject) DeleteDocumentAttachmentTransaction(com.twinsoft.convertigo.beans.transactions.couchdb.DeleteDocumentAttachmentTransaction) GetViewTransaction(com.twinsoft.convertigo.beans.transactions.couchdb.GetViewTransaction) Transaction(com.twinsoft.convertigo.beans.core.Transaction) PutDatabaseTransaction(com.twinsoft.convertigo.beans.transactions.couchdb.PutDatabaseTransaction) AbstractCouchDbTransaction(com.twinsoft.convertigo.beans.transactions.couchdb.AbstractCouchDbTransaction) GetDocumentTransaction(com.twinsoft.convertigo.beans.transactions.couchdb.GetDocumentTransaction) PostReplicateTransaction(com.twinsoft.convertigo.beans.transactions.couchdb.PostReplicateTransaction) DeleteDocumentTransaction(com.twinsoft.convertigo.beans.transactions.couchdb.DeleteDocumentTransaction) PutDocumentAttachmentTransaction(com.twinsoft.convertigo.beans.transactions.couchdb.PutDocumentAttachmentTransaction) DeleteDatabaseTransaction(com.twinsoft.convertigo.beans.transactions.couchdb.DeleteDatabaseTransaction) ResetDatabaseTransaction(com.twinsoft.convertigo.beans.transactions.couchdb.ResetDatabaseTransaction) PostDocumentTransaction(com.twinsoft.convertigo.beans.transactions.couchdb.PostDocumentTransaction) AllDocsTransaction(com.twinsoft.convertigo.beans.transactions.couchdb.AllDocsTransaction) XmlSchema(org.apache.ws.commons.schema.XmlSchema) PostReplicateTransaction(com.twinsoft.convertigo.beans.transactions.couchdb.PostReplicateTransaction) DesignDocument(com.twinsoft.convertigo.beans.couchdb.DesignDocument) IWorkbenchPage(org.eclipse.ui.IWorkbenchPage) UICustomAction(com.twinsoft.convertigo.beans.ngx.components.UICustomAction)

Example 3 with AbstractCouchDbTransaction

use of com.twinsoft.convertigo.beans.transactions.couchdb.AbstractCouchDbTransaction in project convertigo by convertigo.

the class CouchAddVariables method run.

public void run() {
    Display display = Display.getDefault();
    Cursor waitCursor = new Cursor(display, SWT.CURSOR_WAIT);
    Shell shell = getParentShell();
    shell.setCursor(waitCursor);
    try {
        TreeObject parentTreeObject = null;
        AbstractCouchDbTransaction databaseObject = null;
        ProjectExplorerView explorerView = getProjectExplorerView();
        if (explorerView != null) {
            parentTreeObject = explorerView.getFirstSelectedTreeObject();
            if (parentTreeObject.getObject() instanceof AbstractCouchDbTransaction) {
                databaseObject = (AbstractCouchDbTransaction) parentTreeObject.getObject();
                PropertyDescriptor[] props = CachedIntrospector.getBeanInfo(databaseObject).getPropertyDescriptors();
                props = cleanProps(databaseObject, props);
                if (props.length > 0) {
                    CouchVariablesDialog couchVariablesDialog = new CouchVariablesDialog(shell, databaseObject, props);
                    couchVariablesDialog.open();
                    explorerView.reloadTreeObject(parentTreeObject);
                } else {
                    MessageBox messageBox = new MessageBox(shell, SWT.ICON_QUESTION | SWT.OK);
                    messageBox.setMessage("No parameters are available for this transaction.");
                    messageBox.setText("No availables parameters");
                    messageBox.open();
                }
            }
        }
    } catch (Throwable e) {
        ConvertigoPlugin.logException(e, "Unable to create a new database object '" + databaseObjectClassName + "'!");
    } finally {
        shell.setCursor(null);
        waitCursor.dispose();
    }
}
Also used : Shell(org.eclipse.swt.widgets.Shell) ProjectExplorerView(com.twinsoft.convertigo.eclipse.views.projectexplorer.ProjectExplorerView) PropertyDescriptor(java.beans.PropertyDescriptor) CouchVariablesDialog(com.twinsoft.convertigo.eclipse.dialogs.CouchVariablesDialog) AbstractCouchDbTransaction(com.twinsoft.convertigo.beans.transactions.couchdb.AbstractCouchDbTransaction) TreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.TreeObject) Cursor(org.eclipse.swt.graphics.Cursor) Display(org.eclipse.swt.widgets.Display) MessageBox(org.eclipse.swt.widgets.MessageBox)

Example 4 with AbstractCouchDbTransaction

use of com.twinsoft.convertigo.beans.transactions.couchdb.AbstractCouchDbTransaction in project convertigo by convertigo.

the class MobilePickerComposite method getJsonModel.

private JSONObject getJsonModel(Map<String, Object> data, DatabaseObject databaseObject) throws Exception {
    JSONObject jsonModel = new JSONObject();
    Map<String, String> params;
    DatabaseObject dbo;
    String dataPath;
    if (databaseObject == null) {
        dbo = (DatabaseObject) data.get("databaseObject");
        params = GenericUtils.cast(data.get("params"));
        dataPath = (String) data.get("searchPath");
    } else {
        dbo = databaseObject;
        params = new HashMap<String, String>();
        dataPath = "";
    }
    if (dbo != null) {
        // case of requestable
        if (dbo instanceof RequestableObject) {
            RequestableObject ro = (RequestableObject) dbo;
            Project project = ro.getProject();
            String responseEltName = ro.getXsdTypePrefix() + ro.getName() + "Response";
            boolean isDocumentNode = JsonRoot.docNode.equals(project.getJsonRoot()) && dataPath.isEmpty();
            XmlSchema schema = Engine.theApp.schemaManager.getSchemaForProject(project.getName());
            XmlSchemaObject xso = SchemaMeta.getXmlSchemaObject(schema, ro);
            if (xso != null) {
                Document document = XmlSchemaUtils.getDomInstance(xso);
                // System.out.println(XMLUtils.prettyPrintDOM(document));
                String jsonString = XMLUtils.XmlToJson(document.getDocumentElement(), true, true);
                JSONObject jsonObject = new JSONObject(jsonString);
                String searchPath = "document." + responseEltName + ".response";
                searchPath += isDocumentNode || !dataPath.startsWith(".document") ? dataPath : dataPath.replaceFirst("\\.document", "");
                JSONObject jsonOutput = findJSONObject(jsonObject, searchPath);
                jsonModel = isDocumentNode ? new JSONObject().put("document", jsonOutput) : jsonOutput;
            }
        } else if (dbo instanceof DesignDocument) {
            DesignDocument dd = (DesignDocument) dbo;
            Connector connector = dd.getConnector();
            String ddoc = params.get("ddoc");
            String view = params.get("view");
            String viewName = ddoc + "/" + view;
            String includeDocs = params.get("include_docs");
            Display.getDefault().asyncExec(new Runnable() {

                public void run() {
                    IWorkbenchPage activePage = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
                    ConnectorEditor connectorEditor = ConvertigoPlugin.getDefault().getConnectorEditor(connector);
                    if (connectorEditor == null) {
                        try {
                            connectorEditor = (ConnectorEditor) activePage.openEditor(new ConnectorEditorInput(connector), "com.twinsoft.convertigo.eclipse.editors.connector.ConnectorEditor");
                        } catch (PartInitException e) {
                            ConvertigoPlugin.logException(e, "Error while loading the connector editor '" + connector.getName() + "'");
                        }
                    }
                    if (connectorEditor != null) {
                        // activate connector's editor
                        activePage.activate(connectorEditor);
                        // set transaction's parameters
                        Transaction transaction = connector.getTransactionByName(CouchDbConnector.internalView);
                        ((GetViewTransaction) transaction).setViewname(viewName);
                        ((GetViewTransaction) transaction).setQ_include_docs(includeDocs);
                        Variable view_reduce = ((GetViewTransaction) transaction).getVariable(CouchParam.prefix + "reduce");
                        view_reduce.setValueOrNull(false);
                        // execute view transaction
                        connectorEditor.getDocument(CouchDbConnector.internalView, false);
                    }
                }
            });
        } else // case of UIForm
        if (dbo instanceof UIForm) {
            // JSONObject jsonObject = new JSONObject("{\"controls\":{\"['area']\":{\"value\":\"\"}}}");
            JSONObject jsonObject = new JSONObject(((UIForm) dbo).computeJsonModel());
            String searchPath = dataPath;
            JSONObject jsonOutput = findJSONObject(jsonObject, searchPath);
            jsonModel = jsonOutput;
        } else // case of UIACtionStack
        if (dbo instanceof UIActionStack) {
            JSONObject jsonObject = new JSONObject(((UIActionStack) dbo).computeJsonModel());
            String searchPath = dataPath;
            JSONObject jsonOutput = findJSONObject(jsonObject, searchPath);
            jsonModel = jsonOutput;
        } else // case of UIDynamicAction or UICustomAction
        if (dbo instanceof IAction) {
            JSONObject jsonObject = new JSONObject();
            if (dbo instanceof UIDynamicAction) {
                UIDynamicAction uida = (UIDynamicAction) dbo;
                jsonObject = new JSONObject(uida.computeJsonModel());
                IonBean ionBean = uida.getIonBean();
                if (ionBean != null) {
                    String name = ionBean.getName();
                    if ("CallSequenceAction".equals(name)) {
                        String qname = ionBean.getProperty("requestable").getValue().toString();
                        DatabaseObject sequence = Engine.theApp.databaseObjectsManager.getDatabaseObjectByQName(qname);
                        if (sequence != null) {
                            JSONObject targetJsonModel = getJsonModel(data, sequence);
                            if (jsonObject.has("out")) {
                                jsonObject.put("out", targetJsonModel);
                            }
                        }
                    } else if ("CallFullSyncAction".equals(name)) {
                        String qname = ionBean.getProperty("requestable").getValue().toString();
                        String verb = ionBean.getProperty("verb").getValue().toString();
                        Connector connector = (Connector) Engine.theApp.databaseObjectsManager.getDatabaseObjectByQName(qname);
                        if (connector != null) {
                            XmlSchema schema = Engine.theApp.schemaManager.getSchemaForProject(connector.getProject().getName());
                            AbstractCouchDbTransaction act = null;
                            if ("all".equals(verb))
                                act = new AllDocsTransaction();
                            else if ("create".equals(verb))
                                act = new PutDatabaseTransaction();
                            else if ("destroy".equals(verb))
                                act = new DeleteDatabaseTransaction();
                            else if ("get".equals(verb))
                                act = new GetDocumentTransaction();
                            else if ("delete".equals(verb))
                                act = new DeleteDocumentTransaction();
                            else if ("delete_attachment".equals(verb))
                                act = new DeleteDocumentAttachmentTransaction();
                            else if ("post".equals(verb))
                                act = new PostDocumentTransaction();
                            else if ("put_attachment".equals(verb))
                                act = new PutDocumentAttachmentTransaction();
                            else if ("replicate_push".equals(verb))
                                act = new PostReplicateTransaction();
                            else if ("reset".equals(verb))
                                act = new ResetDatabaseTransaction();
                            else if ("view".equals(verb))
                                act = new GetViewTransaction();
                            if (act != null) {
                                QName typeQName = act.getComplexTypeAffectation();
                                XmlSchemaType xmlSchemaType = schema.getTypeByName(typeQName);
                                Document document = XmlSchemaUtils.getDomInstance(xmlSchemaType);
                                String jsonString = XMLUtils.XmlToJson(document.getDocumentElement(), true, true);
                                JSONObject jsonOutput = new JSONObject(jsonString).getJSONObject("document");
                                cleanJsonModel(jsonOutput);
                                jsonOutput.remove("_c8oMeta");
                                jsonOutput.remove("error");
                                jsonOutput.remove("reason");
                                if (jsonObject.has("out")) {
                                    jsonObject.put("out", jsonOutput);
                                }
                            }
                        }
                    } else if ("FullSyncGetAction".equals(name)) {
                        String qname = ionBean.getProperty("requestable").getValue().toString();
                        String docid = ionBean.getProperty("_id").getValue().toString();
                        Connector connector = (Connector) Engine.theApp.databaseObjectsManager.getDatabaseObjectByQName(qname);
                        if (connector != null) {
                            Display.getDefault().asyncExec(new Runnable() {

                                public void run() {
                                    IWorkbenchPage activePage = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
                                    ConnectorEditor connectorEditor = ConvertigoPlugin.getDefault().getConnectorEditor(connector);
                                    if (connectorEditor == null) {
                                        try {
                                            connectorEditor = (ConnectorEditor) activePage.openEditor(new ConnectorEditorInput(connector), "com.twinsoft.convertigo.eclipse.editors.connector.ConnectorEditor");
                                        } catch (PartInitException e) {
                                            ConvertigoPlugin.logException(e, "Error while loading the connector editor '" + connector.getName() + "'");
                                        }
                                    }
                                    if (connectorEditor != null) {
                                        // activate connector's editor
                                        activePage.activate(connectorEditor);
                                        // set transaction's parameters
                                        Transaction transaction = connector.getTransactionByName(CouchDbConnector.internalDocument);
                                        Variable var_docid = ((GetDocumentTransaction) transaction).getVariable(CouchParam.docid.param());
                                        var_docid.setValueOrNull(docid);
                                        // execute view transaction
                                        connectorEditor.getDocument(CouchDbConnector.internalDocument, false);
                                    }
                                }
                            });
                        }
                    } else if ("FullSyncViewAction".equals(name)) {
                        String fsview = ionBean.getProperty("fsview").getValue().toString();
                        String includeDocs = ionBean.getProperty("include_docs").getValue().toString();
                        String reduce = ionBean.getProperty("reduce").getValue().toString();
                        String qname = fsview.substring(0, fsview.lastIndexOf('.'));
                        DesignDocument dd = (DesignDocument) Engine.theApp.databaseObjectsManager.getDatabaseObjectByQName(qname);
                        Connector connector = dd.getConnector();
                        String viewName = dd.getName() + "/" + fsview.substring(fsview.lastIndexOf('.') + 1);
                        Display.getDefault().asyncExec(new Runnable() {

                            public void run() {
                                IWorkbenchPage activePage = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
                                ConnectorEditor connectorEditor = ConvertigoPlugin.getDefault().getConnectorEditor(connector);
                                if (connectorEditor == null) {
                                    try {
                                        connectorEditor = (ConnectorEditor) activePage.openEditor(new ConnectorEditorInput(connector), "com.twinsoft.convertigo.eclipse.editors.connector.ConnectorEditor");
                                    } catch (PartInitException e) {
                                        ConvertigoPlugin.logException(e, "Error while loading the connector editor '" + connector.getName() + "'");
                                    }
                                }
                                if (connectorEditor != null) {
                                    // activate connector's editor
                                    activePage.activate(connectorEditor);
                                    // set transaction's parameters
                                    Transaction transaction = connector.getTransactionByName(CouchDbConnector.internalView);
                                    ((GetViewTransaction) transaction).setViewname(viewName);
                                    ((GetViewTransaction) transaction).setQ_include_docs(includeDocs);
                                    Variable view_reduce = ((GetViewTransaction) transaction).getVariable(CouchParam.prefix + "reduce");
                                    view_reduce.setValueOrNull(reduce);
                                    // execute view transaction
                                    connectorEditor.getDocument(CouchDbConnector.internalView, false);
                                }
                            }
                        });
                    } else if (name.startsWith("FullSync")) {
                        if (ionBean.getProperty("requestable") != null) {
                            String qname = ionBean.getProperty("requestable").getValue().toString();
                            DatabaseObject connector = Engine.theApp.databaseObjectsManager.getDatabaseObjectByQName(qname);
                            if (connector != null) {
                                XmlSchema schema = Engine.theApp.schemaManager.getSchemaForProject(connector.getProject().getName());
                                AbstractCouchDbTransaction act = null;
                                if ("FullSyncDeleteAction".equals(name))
                                    act = new DeleteDocumentTransaction();
                                else if ("FullSyncDeleteAttachmentAction".equals(name))
                                    act = new DeleteDocumentAttachmentTransaction();
                                else if ("FullSyncPostAction".equals(name))
                                    act = new PostDocumentTransaction();
                                else if ("FullSyncPutAttachmentAction".equals(name))
                                    act = new PutDocumentAttachmentTransaction();
                                if (act != null) {
                                    QName typeQName = act.getComplexTypeAffectation();
                                    XmlSchemaType xmlSchemaType = schema.getTypeByName(typeQName);
                                    Document document = XmlSchemaUtils.getDomInstance(xmlSchemaType);
                                    String jsonString = XMLUtils.XmlToJson(document.getDocumentElement(), true, true);
                                    JSONObject jsonOutput = new JSONObject(jsonString).getJSONObject("document");
                                    cleanJsonModel(jsonOutput);
                                    jsonOutput.remove("_c8oMeta");
                                    jsonOutput.remove("error");
                                    jsonOutput.remove("reason");
                                    if (jsonObject.has("out")) {
                                        jsonObject.put("out", jsonOutput);
                                    }
                                }
                            }
                        }
                    }
                }
            } else if (dbo instanceof UICustomAction) {
                jsonObject = new JSONObject(((UICustomAction) dbo).computeJsonModel());
            }
            String searchPath = dataPath;
            JSONObject jsonOutput = findJSONObject(jsonObject, searchPath);
            jsonModel = jsonOutput;
        } else // case of UISharedComponent
        if (dbo instanceof UISharedComponent) {
            JSONObject jsonObject = new JSONObject(((UISharedComponent) dbo).computeJsonModel());
            String searchPath = dataPath;
            JSONObject jsonOutput = findJSONObject(jsonObject, searchPath);
            jsonModel = jsonOutput;
        } else // case of ApplicationComponent
        if (dbo instanceof ApplicationComponent) {
            String json = params.get("json");
            jsonModel = new JSONObject(json);
        } else // should not happened
        {
            throw new Exception("DatabaseObject " + dbo.getClass().getName() + " not supported!");
        }
    }
    return jsonModel;
}
Also used : CouchDbConnector(com.twinsoft.convertigo.beans.connectors.CouchDbConnector) Connector(com.twinsoft.convertigo.beans.core.Connector) Variable(com.twinsoft.convertigo.beans.core.Variable) IonBean(com.twinsoft.convertigo.beans.mobile.components.dynamic.IonBean) UIForm(com.twinsoft.convertigo.beans.mobile.components.UIForm) GetDocumentTransaction(com.twinsoft.convertigo.beans.transactions.couchdb.GetDocumentTransaction) PostDocumentTransaction(com.twinsoft.convertigo.beans.transactions.couchdb.PostDocumentTransaction) Document(org.w3c.dom.Document) DesignDocument(com.twinsoft.convertigo.beans.couchdb.DesignDocument) ConnectorEditor(com.twinsoft.convertigo.eclipse.editors.connector.ConnectorEditor) ConnectorEditorInput(com.twinsoft.convertigo.eclipse.editors.connector.ConnectorEditorInput) DeleteDatabaseTransaction(com.twinsoft.convertigo.beans.transactions.couchdb.DeleteDatabaseTransaction) UISharedComponent(com.twinsoft.convertigo.beans.mobile.components.UISharedComponent) AllDocsTransaction(com.twinsoft.convertigo.beans.transactions.couchdb.AllDocsTransaction) DeleteDocumentTransaction(com.twinsoft.convertigo.beans.transactions.couchdb.DeleteDocumentTransaction) XmlSchemaObject(org.apache.ws.commons.schema.XmlSchemaObject) DatabaseObject(com.twinsoft.convertigo.beans.core.DatabaseObject) PartInitException(org.eclipse.ui.PartInitException) PutDocumentAttachmentTransaction(com.twinsoft.convertigo.beans.transactions.couchdb.PutDocumentAttachmentTransaction) RequestableObject(com.twinsoft.convertigo.beans.core.RequestableObject) IAction(com.twinsoft.convertigo.beans.mobile.components.IAction) AbstractCouchDbTransaction(com.twinsoft.convertigo.beans.transactions.couchdb.AbstractCouchDbTransaction) PutDatabaseTransaction(com.twinsoft.convertigo.beans.transactions.couchdb.PutDatabaseTransaction) QName(javax.xml.namespace.QName) ApplicationComponent(com.twinsoft.convertigo.beans.mobile.components.ApplicationComponent) DeleteDocumentAttachmentTransaction(com.twinsoft.convertigo.beans.transactions.couchdb.DeleteDocumentAttachmentTransaction) ResetDatabaseTransaction(com.twinsoft.convertigo.beans.transactions.couchdb.ResetDatabaseTransaction) XmlSchemaType(org.apache.ws.commons.schema.XmlSchemaType) PartInitException(org.eclipse.ui.PartInitException) JSONException(org.codehaus.jettison.json.JSONException) Project(com.twinsoft.convertigo.beans.core.Project) UIActionStack(com.twinsoft.convertigo.beans.mobile.components.UIActionStack) GetViewTransaction(com.twinsoft.convertigo.beans.transactions.couchdb.GetViewTransaction) UIDynamicAction(com.twinsoft.convertigo.beans.mobile.components.UIDynamicAction) JSONObject(org.codehaus.jettison.json.JSONObject) DeleteDocumentAttachmentTransaction(com.twinsoft.convertigo.beans.transactions.couchdb.DeleteDocumentAttachmentTransaction) GetViewTransaction(com.twinsoft.convertigo.beans.transactions.couchdb.GetViewTransaction) Transaction(com.twinsoft.convertigo.beans.core.Transaction) PutDatabaseTransaction(com.twinsoft.convertigo.beans.transactions.couchdb.PutDatabaseTransaction) AbstractCouchDbTransaction(com.twinsoft.convertigo.beans.transactions.couchdb.AbstractCouchDbTransaction) GetDocumentTransaction(com.twinsoft.convertigo.beans.transactions.couchdb.GetDocumentTransaction) PostReplicateTransaction(com.twinsoft.convertigo.beans.transactions.couchdb.PostReplicateTransaction) DeleteDocumentTransaction(com.twinsoft.convertigo.beans.transactions.couchdb.DeleteDocumentTransaction) PutDocumentAttachmentTransaction(com.twinsoft.convertigo.beans.transactions.couchdb.PutDocumentAttachmentTransaction) DeleteDatabaseTransaction(com.twinsoft.convertigo.beans.transactions.couchdb.DeleteDatabaseTransaction) ResetDatabaseTransaction(com.twinsoft.convertigo.beans.transactions.couchdb.ResetDatabaseTransaction) PostDocumentTransaction(com.twinsoft.convertigo.beans.transactions.couchdb.PostDocumentTransaction) AllDocsTransaction(com.twinsoft.convertigo.beans.transactions.couchdb.AllDocsTransaction) XmlSchema(org.apache.ws.commons.schema.XmlSchema) PostReplicateTransaction(com.twinsoft.convertigo.beans.transactions.couchdb.PostReplicateTransaction) DesignDocument(com.twinsoft.convertigo.beans.couchdb.DesignDocument) IWorkbenchPage(org.eclipse.ui.IWorkbenchPage) UICustomAction(com.twinsoft.convertigo.beans.mobile.components.UICustomAction)

Aggregations

AbstractCouchDbTransaction (com.twinsoft.convertigo.beans.transactions.couchdb.AbstractCouchDbTransaction)4 Connector (com.twinsoft.convertigo.beans.core.Connector)3 DatabaseObject (com.twinsoft.convertigo.beans.core.DatabaseObject)3 Project (com.twinsoft.convertigo.beans.core.Project)3 Transaction (com.twinsoft.convertigo.beans.core.Transaction)3 CouchDbConnector (com.twinsoft.convertigo.beans.connectors.CouchDbConnector)2 RequestableObject (com.twinsoft.convertigo.beans.core.RequestableObject)2 Variable (com.twinsoft.convertigo.beans.core.Variable)2 DesignDocument (com.twinsoft.convertigo.beans.couchdb.DesignDocument)2 ApplicationComponent (com.twinsoft.convertigo.beans.mobile.components.ApplicationComponent)2 HtmlConnector (com.twinsoft.convertigo.beans.connectors.HtmlConnector)1 SqlConnector (com.twinsoft.convertigo.beans.connectors.SqlConnector)1 Criteria (com.twinsoft.convertigo.beans.core.Criteria)1 ScreenClass (com.twinsoft.convertigo.beans.core.ScreenClass)1 Sheet (com.twinsoft.convertigo.beans.core.Sheet)1 Statement (com.twinsoft.convertigo.beans.core.Statement)1 TestCase (com.twinsoft.convertigo.beans.core.TestCase)1 IAction (com.twinsoft.convertigo.beans.mobile.components.IAction)1 PageComponent (com.twinsoft.convertigo.beans.mobile.components.PageComponent)1 UIActionStack (com.twinsoft.convertigo.beans.mobile.components.UIActionStack)1