Search in sources :

Example 61 with Connector

use of com.twinsoft.convertigo.beans.core.Connector 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)

Example 62 with Connector

use of com.twinsoft.convertigo.beans.core.Connector in project convertigo by convertigo.

the class TransactionStep method getConnectorNames.

public String[] getConnectorNames() {
    try {
        if (!projectName.equals("")) {
            Project p = getTargetProject(projectName);
            List<Connector> v = new ArrayList<Connector>(p.getConnectorsList());
            v = GenericUtils.cast(sort((Vector<?>) v, true));
            String[] connectorNames = new String[v.size() + 1];
            connectorNames[0] = "";
            int i = 0;
            for (Connector connector : v) {
                connectorNames[i + 1] = connector.getName();
                i++;
            }
            return connectorNames;
        }
    } catch (EngineException e) {
    }
    return new String[] {};
}
Also used : Project(com.twinsoft.convertigo.beans.core.Project) Connector(com.twinsoft.convertigo.beans.core.Connector) ArrayList(java.util.ArrayList) EngineException(com.twinsoft.convertigo.engine.EngineException)

Example 63 with Connector

use of com.twinsoft.convertigo.beans.core.Connector in project convertigo by convertigo.

the class TransactionStep method getTargetTransaction.

public Transaction getTargetTransaction() throws EngineException {
    Project p = getTargetProject(projectName);
    Connector connector = (connectorName.equals("") ? p.getDefaultConnector() : p.getConnectorByName(connectorName));
    Transaction targetTransaction = (transactionName.equals("") ? connector.getDefaultTransaction() : connector.getTransactionByName(transactionName));
    return targetTransaction;
}
Also used : Project(com.twinsoft.convertigo.beans.core.Project) Connector(com.twinsoft.convertigo.beans.core.Connector) Transaction(com.twinsoft.convertigo.beans.core.Transaction)

Example 64 with Connector

use of com.twinsoft.convertigo.beans.core.Connector in project convertigo by convertigo.

the class TransactionStep method prepareForRequestable.

protected void prepareForRequestable(Context javascriptContext, Scriptable scope) throws MalformedURLException, EngineException {
    Transaction targetTransaction = getTargetTransaction();
    Connector targetConnector = targetTransaction.getConnector();
    String ctxName = getContextName(javascriptContext, scope);
    boolean useSequenceJSession = sequence.useSameJSessionForSteps();
    String connectionStringValue = (String) getConnectionStringValue();
    if (isInternalInvoke()) {
        request.put(Parameter.Project.getName(), new String[] { projectName });
        // request.put(Parameter.Pool.getName(), new String[] { "" });
        request.put(Parameter.MotherSequenceContext.getName(), new String[] { sequence.context.contextID });
        request.put(Parameter.Transaction.getName(), new String[] { targetTransaction.getName() });
        request.put(Parameter.Connector.getName(), new String[] { targetConnector.getName() });
        request.put(Parameter.Context.getName(), new String[] { sequence.addStepContextName(ctxName) });
        request.put(Parameter.SessionId.getName(), new String[] { getTransactionSessionId() });
        if (!connectionStringValue.equals(""))
            request.put(Parameter.ConnectorConnectionString.getName(), new String[] { connectionStringValue });
        getPostQuery(scope);
    } else {
        targetUrl = EnginePropertiesManager.getProperty(PropertyName.APPLICATION_SERVER_CONVERTIGO_URL);
        targetUrl += "/projects/" + projectName + "/.xml?";
        URL url = new URL(targetUrl);
        String host = url.getHost();
        int port = url.getPort();
        Engine.logBeans.trace("(TransactionStep) Host: " + host + ":" + port);
        hostConfiguration.setHost(host, port);
        method = new PostMethod(targetUrl);
        HeaderName.ContentType.setRequestHeader(method, MimeType.WwwForm.value());
        // Set transaction sessionId from context maintainer
        String sessionId = getTransactionSessionId();
        if (useSequenceJSession) {
            Engine.logBeans.trace("(TransactionStep) JSESSIONID required : " + sessionId);
            if (sessionId != null) {
                method.setRequestHeader("Cookie", "JSESSIONID=" + sessionId + ";");
                Engine.logBeans.trace("(TransactionStep) JSESSIONID used : " + sessionId);
            } else {
                Engine.logBeans.trace("(TransactionStep) JSESSIONID is null");
            }
        } else {
            if (sessionId != null) {
                method.setRequestHeader("Cookie", "JSESSIONID=" + sessionId + ";");
                Engine.logBeans.trace("(TransactionStep) Transaction JSESSIONID used : " + sessionId);
            } else {
                Engine.logBeans.trace("(TransactionStep) Transaction JSESSIONID is null");
            }
        }
        String postQuery = getPostQuery(scope);
        if (postQuery.indexOf(Parameter.Connector.getName()) == -1)
            postQuery = addParamToPostQuery(Parameter.Connector.getName(), targetConnector.getName(), postQuery);
        if (postQuery.indexOf(Parameter.Transaction.getName()) == -1)
            postQuery = addParamToPostQuery(Parameter.Transaction.getName(), targetTransaction.getName(), postQuery);
        if (postQuery.indexOf(Parameter.MotherSequenceContext.getName()) == -1)
            postQuery = addParamToPostQuery(Parameter.MotherSequenceContext.getName(), sequence.context.contextID, postQuery);
        if (postQuery.indexOf(Parameter.Context.getName()) == -1)
            postQuery = addParamToPostQuery(Parameter.Context.getName(), sequence.addStepContextName(ctxName), postQuery);
        if (!connectionStringValue.equals(""))
            postQuery = addParamToPostQuery(Parameter.ConnectorConnectionString.getName(), connectionStringValue, postQuery);
        if (Engine.logBeans.isTraceEnabled())
            Engine.logBeans.trace("(TransactionStep) postQuery :" + Visibility.Logs.replaceVariables(getVariables(), postQuery));
        try {
            method.setRequestEntity(new StringRequestEntity(postQuery, null, "UTF-8"));
        } catch (UnsupportedEncodingException e) {
            throw new EngineException("Encoding error", e);
        }
    }
}
Also used : Connector(com.twinsoft.convertigo.beans.core.Connector) StringRequestEntity(org.apache.commons.httpclient.methods.StringRequestEntity) Transaction(com.twinsoft.convertigo.beans.core.Transaction) PostMethod(org.apache.commons.httpclient.methods.PostMethod) EngineException(com.twinsoft.convertigo.engine.EngineException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) URL(java.net.URL)

Example 65 with Connector

use of com.twinsoft.convertigo.beans.core.Connector in project convertigo by convertigo.

the class DatabaseObjectsManager method deleteProject.

public void deleteProject(String projectName, DeleteProjectOption... options) throws EngineException {
    boolean bCreateBackup = DeleteProjectOption.createBackup.as(options);
    boolean bDataOnly = DeleteProjectOption.dataOnly.as(options);
    boolean bPreserveEclipe = DeleteProjectOption.preserveEclipse.as(options);
    boolean bPreserveVCS = DeleteProjectOption.preserveVCS.as(options);
    boolean bUnloadOnly = DeleteProjectOption.unloadOnly.as(options);
    try {
        // Remove all pooled related contexts in server mode
        if (Engine.isEngineMode() && !Engine.isCliMode()) {
            // process is ongoing!
            if (!(Thread.currentThread() instanceof MigrationJob)) {
                Project projectToDelete = Engine.theApp.databaseObjectsManager.getCachedProject(projectName);
                if (projectToDelete != null) {
                    for (Connector connector : projectToDelete.getConnectorsList()) {
                        Engine.theApp.contextManager.removeDevicePool(connector.getQName());
                    }
                }
                Engine.theApp.contextManager.removeAll("/" + projectName);
            }
        }
        if (bUnloadOnly) {
            clearCache(projectName);
            return;
        }
        File projectDir = new File(Engine.projectDir(projectName));
        File removeDir = projectDir;
        if (!bDataOnly && !bPreserveEclipe && !bPreserveVCS) {
            StringBuilder sb = new StringBuilder("_remove_" + projectName);
            while ((removeDir = new File(projectDir.getParentFile(), sb.toString())).exists()) {
                sb.append('_');
            }
            if (!projectDir.renameTo(removeDir)) {
                throw new EngineException("Unable to rename project's directory. It may be locked.");
            }
        }
        if (bCreateBackup && EnginePropertiesManager.getPropertyAsBoolean(PropertyName.ZIP_BACKUP_OLD_PROJECT) && !Engine.isCliMode()) {
            Engine.logDatabaseObjectManager.info("Making backup of project \"" + projectName + "\"");
            makeProjectBackup(projectName, removeDir);
        }
        if (bDataOnly) {
            Engine.logDatabaseObjectManager.info("Deleting _data for project \"" + projectName + "\"");
            File dataDir = new File(removeDir, "_data");
            deleteDir(dataDir);
            Engine.logDatabaseObjectManager.info("Deleting _private for project \"" + projectName + "\"");
            File privateDir = new File(removeDir, "/_private");
            deleteDir(privateDir);
        } else {
            Engine.logDatabaseObjectManager.info("Deleting  project \"" + projectName + "\"");
            if (!bPreserveEclipe && !bPreserveVCS) {
                deleteDir(removeDir);
                File f = new File(Engine.PROJECTS_PATH, projectName);
                if (f.exists() && f.isFile()) {
                    f.delete();
                }
            } else {
                for (File f : removeDir.listFiles((dir, name) -> {
                    if (bPreserveEclipe && (name.equals(".project") || name.equals(".settings"))) {
                        return false;
                    }
                    if (bPreserveVCS && (name.equals(".git") || name.equals(".svn"))) {
                        return false;
                    }
                    return true;
                })) {
                    deleteDir(f);
                }
                ;
            }
        }
        clearCache(projectName);
    } catch (Exception e) {
        throw new EngineException("Unable to delete" + (bDataOnly ? " datas for" : "") + " project \"" + projectName + "\".", e);
    }
}
Also used : Project(com.twinsoft.convertigo.beans.core.Project) Connector(com.twinsoft.convertigo.beans.core.Connector) File(java.io.File) FileNotFoundException(java.io.FileNotFoundException) SAXException(org.xml.sax.SAXException) IOException(java.io.IOException) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException)

Aggregations

Connector (com.twinsoft.convertigo.beans.core.Connector)72 Transaction (com.twinsoft.convertigo.beans.core.Transaction)43 Project (com.twinsoft.convertigo.beans.core.Project)32 EngineException (com.twinsoft.convertigo.engine.EngineException)28 JavelinConnector (com.twinsoft.convertigo.beans.connectors.JavelinConnector)22 Sequence (com.twinsoft.convertigo.beans.core.Sequence)21 HtmlConnector (com.twinsoft.convertigo.beans.connectors.HtmlConnector)17 Step (com.twinsoft.convertigo.beans.core.Step)17 DatabaseObject (com.twinsoft.convertigo.beans.core.DatabaseObject)16 HttpConnector (com.twinsoft.convertigo.beans.connectors.HttpConnector)15 SiteClipperConnector (com.twinsoft.convertigo.beans.connectors.SiteClipperConnector)14 ScreenClass (com.twinsoft.convertigo.beans.core.ScreenClass)14 HtmlTransaction (com.twinsoft.convertigo.beans.transactions.HtmlTransaction)14 TreeObject (com.twinsoft.convertigo.eclipse.views.projectexplorer.model.TreeObject)12 CouchDbConnector (com.twinsoft.convertigo.beans.connectors.CouchDbConnector)11 SqlConnector (com.twinsoft.convertigo.beans.connectors.SqlConnector)11 Statement (com.twinsoft.convertigo.beans.core.Statement)11 ElseStep (com.twinsoft.convertigo.beans.steps.ElseStep)11 ThenStep (com.twinsoft.convertigo.beans.steps.ThenStep)11 ProjectExplorerView (com.twinsoft.convertigo.eclipse.views.projectexplorer.ProjectExplorerView)11