Search in sources :

Example 1 with IVariableContainer

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

the class WebServiceTranslator method buildInputDocument.

public void buildInputDocument(Context context, Object inputData) throws Exception {
    Engine.logBeans.debug("[WebServiceTranslator] Making input document");
    HttpServletRequest request = (HttpServletRequest) inputData;
    SOAPMessage requestMessage = (SOAPMessage) request.getAttribute(WebServiceServlet.REQUEST_MESSAGE_ATTRIBUTE);
    SOAPPart sp = requestMessage.getSOAPPart();
    SOAPEnvelope se = sp.getEnvelope();
    SOAPBody sb = se.getBody();
    Iterator<?> iterator = sb.getChildElements();
    SOAPElement method, parameter;
    String methodName;
    InputDocumentBuilder inputDocumentBuilder = new InputDocumentBuilder(context);
    while (iterator.hasNext()) {
        // jmc 12/06/26
        List<RequestableVariable> variableList = null;
        Object element = iterator.next();
        if (element instanceof SOAPElement) {
            method = (SOAPElement) element;
            methodName = method.getElementName().getLocalName();
            Engine.logBeans.debug("[WebServiceTranslator] Requested web service name: " + methodName);
            int i = methodName.indexOf("__");
            // for statefull transaction, don't replace the project
            if (context.project == null || !context.project.getName().equals(context.projectName)) {
                context.project = Engine.theApp.databaseObjectsManager.getProjectByName(context.projectName);
            }
            String connectorName = null;
            if (i == -1) {
                context.connectorName = null;
                context.sequenceName = methodName;
            } else {
                connectorName = methodName.substring(0, i);
                context.transactionName = methodName.substring(i + 2);
            }
            if ((connectorName != null) && (!connectorName.equals(context.connectorName))) {
                Engine.logBeans.debug("Connector name differs from previous one; requiring new session");
                context.isNewSession = true;
                context.connectorName = connectorName;
                Engine.logBeans.debug("[WebServiceTranslator] The connector is overridden to \"" + context.connectorName + "\".");
            }
            Engine.logBeans.debug("[WebServiceTranslator] Connector: " + (context.connectorName == null ? "(default)" : context.connectorName));
            Engine.logBeans.debug("[WebServiceTranslator] Transaction: " + context.transactionName);
            // Connector connector = (context.connectorName == null ? context.project.getDefaultConnector() : context.project.getConnectorByName(context.connectorName));
            // Transaction transaction = (context.transactionName == null ? connector.getDefaultTransaction() : connector.getTransactionByName(context.transactionName));
            RequestableObject requestable = null;
            if (context.sequenceName != null) {
                requestable = context.project.getSequenceByName(context.sequenceName);
                variableList = ((Sequence) requestable).getVariablesList();
            } else if (context.connectorName != null) {
                if (context.transactionName != null) {
                    requestable = context.project.getConnectorByName(context.connectorName).getTransactionByName(context.transactionName);
                    if (requestable instanceof TransactionWithVariables) {
                        variableList = ((TransactionWithVariables) requestable).getVariablesList();
                    }
                }
            }
            Iterator<?> iterator2 = method.getChildElements();
            String parameterName, parameterValue;
            while (iterator2.hasNext()) {
                element = iterator2.next();
                if (element instanceof SOAPElement) {
                    parameter = (SOAPElement) element;
                    parameterName = parameter.getElementName().getLocalName();
                    parameterValue = parameter.getValue();
                    if (parameterValue == null) {
                        parameterValue = "";
                    }
                    if (variableList != null) {
                        // jmc 12/06/26 hide hidden variables in sequences
                        String str = (String) Visibility.Logs.replaceVariables(variableList, "" + parameterName + "=\"" + parameterValue + "\"");
                        Engine.logBeans.debug("   Parameter: " + str);
                    } else
                        Engine.logBeans.debug("   Parameter: " + parameterName + "=\"" + parameterValue + "\"");
                    // Handle convertigo parameters
                    if (parameterName.startsWith("__")) {
                        webServiceServletRequester.handleParameter(parameterName, parameterValue);
                    }
                    // Common parameter handling
                    if (inputDocumentBuilder.handleSpecialParameter(parameterName, parameterValue)) {
                    // handled
                    } else // Compatibility for Convertigo 2.x
                    if (parameterName.equals("context")) {
                    // Just ignore it
                    } else {
                        SOAPElement soapArrayElement = null;
                        Iterator<?> iterator3;
                        String href = parameter.getAttributeValue(se.createName("href"));
                        String arrayType = parameter.getAttributeValue(se.createName("soapenc:arrayType"));
                        if (arrayType == null) {
                            iterator3 = parameter.getAllAttributes();
                            while (iterator3.hasNext()) {
                                element = iterator3.next();
                                if (element instanceof Name) {
                                    String s = ((Name) element).getQualifiedName();
                                    if (s.equals("soapenc:arrayType")) {
                                        arrayType = s;
                                        break;
                                    }
                                }
                            }
                        }
                        // Array (Microsoft .net)
                        if (href != null) {
                            Engine.logBeans.debug("Deserializing Microsoft .net array");
                            iterator3 = sb.getChildElements();
                            while (iterator3.hasNext()) {
                                element = iterator3.next();
                                if (element instanceof SOAPElement) {
                                    soapArrayElement = (SOAPElement) element;
                                    String elementId = soapArrayElement.getAttributeValue(se.createName("id"));
                                    if (elementId != null) {
                                        if (href.equals("#" + elementId)) {
                                            iterator3 = soapArrayElement.getChildElements();
                                            while (iterator3.hasNext()) {
                                                element = iterator3.next();
                                                if (element instanceof SOAPElement) {
                                                    break;
                                                }
                                            }
                                            break;
                                        }
                                    }
                                }
                            }
                            // Find the element with href id
                            iterator3 = sb.getChildElements();
                            while (iterator3.hasNext()) {
                                element = iterator3.next();
                                if (element instanceof SOAPElement) {
                                    soapArrayElement = (SOAPElement) element;
                                    String elementId = soapArrayElement.getAttributeValue(se.createName("id"));
                                    if (elementId != null) {
                                        if (href.equals("#" + elementId)) {
                                            break;
                                        }
                                    }
                                }
                            }
                        } else // Array (Java/Axis)
                        if (arrayType != null) {
                            Engine.logBeans.debug("Deserializing Java/Axis array");
                            soapArrayElement = parameter;
                        } else // If the node has children nodes, we assume it is an array.
                        if (parameter.getChildElements().hasNext()) {
                            if (isSoapArray((IVariableContainer) requestable, parameterName)) {
                                Engine.logBeans.debug("Deserializing array");
                                soapArrayElement = parameter;
                            }
                        }
                        // Deserializing array
                        if (soapArrayElement != null) {
                            iterator3 = soapArrayElement.getChildElements();
                            while (iterator3.hasNext()) {
                                element = iterator3.next();
                                if (element instanceof SOAPElement) {
                                    soapArrayElement = (SOAPElement) element;
                                    parameterValue = soapArrayElement.getValue();
                                    if (parameterValue == null)
                                        parameterValue = "";
                                    handleSimpleVariable(context.inputDocument, soapArrayElement, parameterName, parameterValue, inputDocumentBuilder.transactionVariablesElement);
                                }
                            }
                        } else // Deserializing simple variable
                        {
                            handleSimpleVariable(context.inputDocument, parameter, parameterName, parameterValue, inputDocumentBuilder.transactionVariablesElement);
                        }
                    }
                }
            }
            if (Engine.logBeans.isDebugEnabled()) {
                String soapMessage = SOAPUtils.toString(requestMessage, request.getCharacterEncoding());
                if (requestable instanceof TransactionWithVariables)
                    Engine.logBeans.debug("[WebServiceTranslator] SOAP message received:\n" + Visibility.Logs.replaceVariables(((TransactionWithVariables) (requestable)).getVariablesList(), request));
                else if (requestable instanceof Sequence)
                    Engine.logBeans.debug("[WebServiceTranslator] SOAP message received:\n" + Visibility.Logs.replaceVariables(((Sequence) (requestable)).getVariablesList(), request));
                else
                    Engine.logBeans.debug("[WebServiceTranslator] SOAP message received:\n" + soapMessage);
            }
            break;
        }
    }
    Engine.logBeans.debug("[WebServiceTranslator] SOAP message analyzed");
    Engine.logBeans.debug("[WebServiceTranslator] Input document created");
}
Also used : RequestableObject(com.twinsoft.convertigo.beans.core.RequestableObject) RequestableVariable(com.twinsoft.convertigo.beans.variables.RequestableVariable) SOAPEnvelope(javax.xml.soap.SOAPEnvelope) Sequence(com.twinsoft.convertigo.beans.core.Sequence) SOAPMessage(javax.xml.soap.SOAPMessage) Name(javax.xml.soap.Name) QName(javax.xml.namespace.QName) HttpServletRequest(javax.servlet.http.HttpServletRequest) SOAPBody(javax.xml.soap.SOAPBody) IVariableContainer(com.twinsoft.convertigo.beans.core.IVariableContainer) SOAPPart(javax.xml.soap.SOAPPart) SOAPElement(javax.xml.soap.SOAPElement) Iterator(java.util.Iterator) TransactionWithVariables(com.twinsoft.convertigo.beans.core.TransactionWithVariables) RequestableObject(com.twinsoft.convertigo.beans.core.RequestableObject)

Example 2 with IVariableContainer

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

the class Migration7_0_0 method handleSteps.

private static void handleSteps(XmlSchema projectSchema, Map<String, Reference> referenceMap, List<Step> stepList) {
    for (Step step : stepList) {
        if (step instanceof XMLActionStep) {
            XMLVector<XMLVector<Object>> sourcesDefinition = ((XMLActionStep) step).getSourcesDefinition();
            for (XMLVector<Object> row : sourcesDefinition) {
                if (row.size() > 1) {
                    XMLVector<String> definition = GenericUtils.cast(row.get(1));
                    handleSourceDefinition(definition);
                }
            }
        }
        if (step instanceof TransactionStep) {
            XMLVector<String> definition = ((TransactionStep) step).getConnectionStringDefinition();
            handleSourceDefinition(definition);
        }
        if (step instanceof IStepSourceContainer) {
            /**
             * Case step's xpath has not been migrated when project has been deployed
             ** on a 5.0 server from a Studio with an older version *
             */
            IStepSourceContainer stepSourceContainer = (IStepSourceContainer) step;
            XMLVector<String> definition = stepSourceContainer.getSourceDefinition();
            handleSourceDefinition(definition);
        }
        if (step instanceof IVariableContainer) {
            IVariableContainer variableContainer = (IVariableContainer) step;
            for (Variable variable : variableContainer.getVariables()) {
                if (variable instanceof IStepSourceContainer) {
                    IStepSourceContainer stepSourceContainer = (IStepSourceContainer) variable;
                    XMLVector<String> definition = stepSourceContainer.getSourceDefinition();
                    handleSourceDefinition(definition);
                }
            }
        }
        String targetProjectName = null;
        String typeLocalName = null;
        if (step instanceof TransactionStep) {
            targetProjectName = ((TransactionStep) step).getProjectName();
            typeLocalName = ((TransactionStep) step).getConnectorName() + "__" + ((TransactionStep) step).getTransactionName() + "ResponseType";
        } else if (step instanceof SequenceStep) {
            targetProjectName = ((SequenceStep) step).getProjectName();
            typeLocalName = ((SequenceStep) step).getSequenceName() + "ResponseType";
        }
        String namespaceURI = null;
        // Case of Requestable steps
        if (targetProjectName != null) {
            try {
                namespaceURI = Project.CONVERTIGO_PROJECTS_NAMESPACEURI + targetProjectName;
                if (!targetProjectName.equals(step.getProject().getName())) {
                    try {
                        namespaceURI = Engine.theApp.databaseObjectsManager.getOriginalProjectByName(targetProjectName).getTargetNamespace();
                    } catch (Exception e) {
                    }
                    // Add reference
                    String location = "../" + targetProjectName + "/" + targetProjectName + ".xsd";
                    addReferenceToMap(referenceMap, namespaceURI, location);
                }
                // Set step's typeQName
                step.setXmlComplexTypeAffectation(new XmlQName(new QName(namespaceURI, typeLocalName)));
            } catch (Exception e) {
                e.printStackTrace();
            }
        } else // Other steps
        {
            try {
                String targetNamespace = projectSchema.getTargetNamespace();
                String targetPrefix = projectSchema.getNamespaceContext().getPrefix(targetNamespace);
                String s = null;
                try {
                    if (step instanceof XMLCopyStep) {
                        XmlSchemaCollection collection = SchemaMeta.getCollection(projectSchema);
                        XmlSchemaObject ob = step.getXmlSchemaObject(collection, projectSchema);
                        if (ob != null) {
                            if (ob instanceof XmlSchemaSequence) {
                                ob = ((XmlSchemaSequence) ob).getItems().getItem(0);
                            }
                            if (ob instanceof XmlSchemaElement || ob instanceof XmlSchemaAttribute) {
                                QName schemaTypeName = ob instanceof XmlSchemaElement ? ((XmlSchemaElement) ob).getSchemaTypeName() : ((XmlSchemaAttribute) ob).getSchemaTypeName();
                                String schemaTypePrefix = projectSchema.getNamespaceContext().getPrefix(schemaTypeName.getNamespaceURI());
                                String schemaTypeLocalName = schemaTypeName.getLocalPart();
                                s = schemaTypePrefix + ":" + schemaTypeLocalName;
                            }
                        }
                    } else {
                        String schemaType = step.getSchemaDataType();
                        s = schemaType.equals("") ? "xsd:string" : schemaType;
                    }
                } catch (Exception e) {
                    s = "xsd:string";
                }
                if ((s != null) && (!s.equals("")) && (!s.startsWith("xsd:"))) {
                    String prefix = s.split(":")[0];
                    typeLocalName = s.split(":")[1];
                    if (prefix.equals(targetPrefix)) {
                    // ignore
                    } else {
                        // Retrieve namespace uri
                        namespaceURI = projectSchema.getNamespaceContext().getNamespaceURI(prefix);
                        // Set step's typeQName
                        QName qname = new QName(namespaceURI, typeLocalName);
                        XmlSchemaType schemaType = projectSchema.getTypeByName(qname);
                        if (schemaType instanceof XmlSchemaComplexType)
                            step.setXmlComplexTypeAffectation(new XmlQName(qname));
                        if (schemaType instanceof XmlSchemaSimpleType)
                            step.setXmlSimpleTypeAffectation(new XmlQName(qname));
                    }
                }
            } catch (Exception e) {
            }
        }
        if (step instanceof ISimpleTypeAffectation) {
            QName qName = XmlSchemaUtils.getSchemaDataTypeName(step.getSchemaDataType());
            step.setXmlSimpleTypeAffectation(new XmlQName(qName));
        }
        if (step instanceof StepWithExpressions) {
            handleSteps(projectSchema, referenceMap, ((StepWithExpressions) step).getSteps());
        }
    }
}
Also used : XMLVector(com.twinsoft.convertigo.beans.common.XMLVector) RequestableVariable(com.twinsoft.convertigo.beans.variables.RequestableVariable) Variable(com.twinsoft.convertigo.beans.core.Variable) StepWithExpressions(com.twinsoft.convertigo.beans.core.StepWithExpressions) Step(com.twinsoft.convertigo.beans.core.Step) XMLActionStep(com.twinsoft.convertigo.beans.steps.XMLActionStep) SequenceStep(com.twinsoft.convertigo.beans.steps.SequenceStep) XMLCopyStep(com.twinsoft.convertigo.beans.steps.XMLCopyStep) TransactionStep(com.twinsoft.convertigo.beans.steps.TransactionStep) IStepSourceContainer(com.twinsoft.convertigo.beans.core.IStepSourceContainer) XMLCopyStep(com.twinsoft.convertigo.beans.steps.XMLCopyStep) XmlSchemaSequence(org.apache.ws.commons.schema.XmlSchemaSequence) XmlSchemaObject(org.apache.ws.commons.schema.XmlSchemaObject) SequenceStep(com.twinsoft.convertigo.beans.steps.SequenceStep) XmlQName(com.twinsoft.convertigo.beans.common.XmlQName) QName(javax.xml.namespace.QName) XmlSchemaElement(org.apache.ws.commons.schema.XmlSchemaElement) ISimpleTypeAffectation(com.twinsoft.convertigo.beans.core.ISimpleTypeAffectation) XMLActionStep(com.twinsoft.convertigo.beans.steps.XMLActionStep) XmlSchemaType(org.apache.ws.commons.schema.XmlSchemaType) XmlSchemaCollection(org.apache.ws.commons.schema.XmlSchemaCollection) XmlSchemaAttribute(org.apache.ws.commons.schema.XmlSchemaAttribute) EngineException(com.twinsoft.convertigo.engine.EngineException) IOException(java.io.IOException) TransactionStep(com.twinsoft.convertigo.beans.steps.TransactionStep) XmlQName(com.twinsoft.convertigo.beans.common.XmlQName) XmlSchemaSimpleType(org.apache.ws.commons.schema.XmlSchemaSimpleType) IVariableContainer(com.twinsoft.convertigo.beans.core.IVariableContainer) XmlSchemaObject(org.apache.ws.commons.schema.XmlSchemaObject) XmlSchemaComplexType(org.apache.ws.commons.schema.XmlSchemaComplexType)

Example 3 with IVariableContainer

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

the class JScriptEditorInput method makeFile.

private static IFile makeFile(IJScriptContainer jsContainer, IProject project) {
    String fullname = jsContainer.getFullName();
    if (jsContainer instanceof DesignDocumentFunctionTreeObject) {
        IFile jsconfig = project.getFile("_private/editor/" + fullname + "/jsconfig.json");
        String conf = "{\"compilerOptions\": {\"module\": \"es5\", \"target\": \"es5\"}, \"include\": [\"*\"]}";
        SwtUtils.fillFile(jsconfig, conf);
        SwtUtils.fillFile(project.getFile("_private/editor/" + fullname + "/couchdb.d.ts"), "declare function emit(key, value)\n" + "declare function sum(values)" + "declare function log(txt)\n");
    } else {
        DatabaseObject dbo = jsContainer.getDatabaseObject();
        if (dbo instanceof Step) {
            dbo = ((Step) dbo).getSequence();
        }
        if (dbo instanceof IVariableContainer) {
            IVariableContainer vc = (IVariableContainer) dbo;
            StringBuilder sb = new StringBuilder();
            for (Variable v : vc.getVariables()) {
                sb.append("declare var ").append(v.getName()).append(v.isMultiValued() ? ": Array<string>" : ": string\n");
            }
            SwtUtils.fillFile(project.getFile("_private/editor/" + fullname + "/variables.d.ts"), sb.toString());
        }
        IFile jsconfig = project.getFile("_private/editor/" + fullname + "/jsconfig.json");
        String conf = "{\"compilerOptions\": {\"module\": \"es6\", \"target\": \"es6\"},\n" + "  \"include\": [\"" + ConvertigoTypeScriptDefinition.getDeclarationFile().getAbsolutePath().replace('\\', '/') + "\", \"*\"]}";
        SwtUtils.fillFile(jsconfig, conf);
    }
    IFile file = project.getFile("_private/editor/" + fullname + "/code.js");
    SwtUtils.fillFile(file, jsContainer.getExpression());
    return file;
}
Also used : DesignDocumentFunctionTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.DesignDocumentFunctionTreeObject) IFile(org.eclipse.core.resources.IFile) Variable(com.twinsoft.convertigo.beans.core.Variable) IVariableContainer(com.twinsoft.convertigo.beans.core.IVariableContainer) DatabaseObject(com.twinsoft.convertigo.beans.core.DatabaseObject) Step(com.twinsoft.convertigo.beans.core.Step)

Example 4 with IVariableContainer

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

the class OperationImportParametersFromVariablesAction method run.

public void run() {
    Display display = Display.getDefault();
    Cursor waitCursor = new Cursor(display, SWT.CURSOR_WAIT);
    Shell shell = getParentShell();
    shell.setCursor(waitCursor);
    try {
        ProjectExplorerView explorerView = getProjectExplorerView();
        if (explorerView != null) {
            TreeObject treeObject = explorerView.getFirstSelectedTreeObject();
            Object databaseObject = treeObject.getObject();
            if ((databaseObject != null) && (databaseObject instanceof UrlMappingOperation)) {
                UrlMappingOperation operation = (UrlMappingOperation) databaseObject;
                String targetRequestable = operation.getTargetRequestable();
                if (!targetRequestable.isEmpty()) {
                    StringTokenizer st = new StringTokenizer(targetRequestable, ".");
                    int count = st.countTokens();
                    String projectName = st.nextToken();
                    String sequenceName = count == 2 ? st.nextToken() : "";
                    String connectorName = count == 3 ? st.nextToken() : "";
                    String transactionName = count == 3 ? st.nextToken() : "";
                    Project project = Engine.theApp.databaseObjectsManager.getProjectByName(projectName);
                    RequestableObject requestableObject = null;
                    if (sequenceName.isEmpty()) {
                        requestableObject = project.getConnectorByName(connectorName).getTransactionByName(transactionName);
                    } else {
                        requestableObject = project.getSequenceByName(sequenceName);
                    }
                    if (requestableObject != null && requestableObject instanceof IVariableContainer) {
                        IVariableContainer variableContainer = (IVariableContainer) requestableObject;
                        for (Variable variable : variableContainer.getVariables()) {
                            String variableName = variable.getName();
                            Object variableValue = variable.getValueOrNull();
                            UrlMappingParameter parameter = null;
                            try {
                                parameter = operation.getParameterByName(variableName);
                            } catch (Exception e) {
                            }
                            if (parameter == null) {
                                if (operation instanceof PostOperation || operation instanceof PutOperation)
                                    parameter = new FormParameter();
                                else
                                    parameter = new QueryParameter();
                                parameter.setName(variableName);
                                parameter.setComment(variable.getComment());
                                parameter.setArray(false);
                                parameter.setExposed(((RequestableVariable) variable).isWsdl());
                                parameter.setMultiValued(variable.isMultiValued());
                                parameter.setRequired(variable.isRequired());
                                parameter.setValueOrNull(!variable.isMultiValued() ? variableValue : null);
                                parameter.setMappedVariableName(variableName);
                                parameter.bNew = true;
                                parameter.hasChanged = true;
                                operation.add(parameter);
                                operation.hasChanged = true;
                            }
                        }
                        if (operation.hasChanged) {
                            explorerView.reloadTreeObject(treeObject);
                            StructuredSelection structuredSelection = new StructuredSelection(treeObject);
                            ConvertigoPlugin.getDefault().getPropertiesView().selectionChanged((IWorkbenchPart) explorerView, structuredSelection);
                        }
                    }
                } else {
                    throw new ConvertigoException("Operation has no target requestable : please select one first.");
                }
            }
        }
    } catch (Throwable e) {
        ConvertigoPlugin.logException(e, "Unable to import variables as new parameters in operation!");
    } finally {
        shell.setCursor(null);
        waitCursor.dispose();
    }
}
Also used : QueryParameter(com.twinsoft.convertigo.beans.rest.QueryParameter) ProjectExplorerView(com.twinsoft.convertigo.eclipse.views.projectexplorer.ProjectExplorerView) UrlMappingOperation(com.twinsoft.convertigo.beans.core.UrlMappingOperation) Variable(com.twinsoft.convertigo.beans.core.Variable) RequestableVariable(com.twinsoft.convertigo.beans.variables.RequestableVariable) RequestableObject(com.twinsoft.convertigo.beans.core.RequestableObject) UrlMappingParameter(com.twinsoft.convertigo.beans.core.UrlMappingParameter) PutOperation(com.twinsoft.convertigo.beans.rest.PutOperation) StructuredSelection(org.eclipse.jface.viewers.StructuredSelection) Cursor(org.eclipse.swt.graphics.Cursor) FormParameter(com.twinsoft.convertigo.beans.rest.FormParameter) ConvertigoException(com.twinsoft.convertigo.engine.ConvertigoException) PostOperation(com.twinsoft.convertigo.beans.rest.PostOperation) Project(com.twinsoft.convertigo.beans.core.Project) ConvertigoException(com.twinsoft.convertigo.engine.ConvertigoException) Shell(org.eclipse.swt.widgets.Shell) StringTokenizer(java.util.StringTokenizer) IVariableContainer(com.twinsoft.convertigo.beans.core.IVariableContainer) TreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.TreeObject) TreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.TreeObject) RequestableObject(com.twinsoft.convertigo.beans.core.RequestableObject) Display(org.eclipse.swt.widgets.Display)

Example 5 with IVariableContainer

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

the class VariableGenerateFromXmlAndLinkAction method run.

public void run() {
    Display display = Display.getDefault();
    Cursor waitCursor = new Cursor(display, SWT.CURSOR_WAIT);
    Shell shell = getParentShell();
    shell.setCursor(waitCursor);
    try {
        ProjectExplorerView explorerView = getProjectExplorerView();
        if (explorerView != null) {
            TreeObject treeObject = explorerView.getFirstSelectedTreeObject();
            Object databaseObject = treeObject.getObject();
            if ((databaseObject != null) && ((databaseObject instanceof StepVariable))) {
                StepVariable stepVariable = (StepVariable) databaseObject;
                RequestableStep requestableStep = (RequestableStep) stepVariable.getParent();
                if (requestableStep != null) {
                    DatabaseObjectTreeObject parentDboTreeObject = ((DatabaseObjectTreeObject) treeObject).getParentDatabaseObjectTreeObject().getParentDatabaseObjectTreeObject();
                    RequestableObject requestableObject = null;
                    if (requestableStep instanceof SequenceStep) {
                        requestableObject = ((SequenceStep) requestableStep).getTargetSequence();
                    } else if (requestableStep instanceof TransactionStep) {
                        requestableObject = ((TransactionStep) requestableStep).getTargetTransaction();
                    }
                    if ((requestableObject != null) && (requestableObject instanceof IVariableContainer)) {
                        String variableName = stepVariable.getName();
                        IVariableContainer container = (IVariableContainer) requestableObject;
                        RequestableVariable variable = (RequestableVariable) container.getVariable(variableName);
                        // generate dom model
                        Document document = null;
                        try {
                            String description = variable.getDescription();
                            document = XMLUtils.parseDOMFromString(description);
                        } catch (Exception e) {
                        }
                        if (document != null) {
                            Element root = document.getDocumentElement();
                            if (root != null) {
                                // create step's structure from dom
                                DatabaseObject parentObject = requestableStep.getParent();
                                Step step = StepUtils.createStepFromXmlDomModel(parentObject, root);
                                // add step's structure to parent of requestableStep
                                if (parentObject instanceof Sequence) {
                                    Sequence parentSequence = (Sequence) parentObject;
                                    parentSequence.addStep(step);
                                    parentSequence.insertAtOrder(step, requestableStep.priority);
                                } else {
                                    StepWithExpressions parentSwe = (StepWithExpressions) parentObject;
                                    parentSwe.addStep(step);
                                    parentSwe.insertAtOrder(step, requestableStep.priority);
                                }
                                // set source definition of variable
                                XMLVector<String> sourceDefinition = new XMLVector<String>();
                                sourceDefinition.add(String.valueOf(step.priority));
                                sourceDefinition.add(".");
                                stepVariable.setSourceDefinition(sourceDefinition);
                                stepVariable.hasChanged = true;
                                // Reload parent dbo in tree
                                explorerView.reloadTreeObject(parentDboTreeObject);
                                // Select variable dbo in tree
                                explorerView.objectSelected(new CompositeEvent(databaseObject));
                            }
                        }
                    }
                }
            }
        }
    } catch (Throwable e) {
        ConvertigoPlugin.logException(e, "Unable to generate and link variable!");
    } finally {
        shell.setCursor(null);
        waitCursor.dispose();
    }
}
Also used : DatabaseObjectTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.DatabaseObjectTreeObject) XMLVector(com.twinsoft.convertigo.beans.common.XMLVector) Element(org.w3c.dom.Element) StepWithExpressions(com.twinsoft.convertigo.beans.core.StepWithExpressions) StepVariable(com.twinsoft.convertigo.beans.variables.StepVariable) Step(com.twinsoft.convertigo.beans.core.Step) SequenceStep(com.twinsoft.convertigo.beans.steps.SequenceStep) RequestableStep(com.twinsoft.convertigo.beans.core.RequestableStep) TransactionStep(com.twinsoft.convertigo.beans.steps.TransactionStep) Cursor(org.eclipse.swt.graphics.Cursor) Document(org.w3c.dom.Document) Shell(org.eclipse.swt.widgets.Shell) DatabaseObject(com.twinsoft.convertigo.beans.core.DatabaseObject) CompositeEvent(com.twinsoft.convertigo.eclipse.editors.CompositeEvent) SequenceStep(com.twinsoft.convertigo.beans.steps.SequenceStep) ProjectExplorerView(com.twinsoft.convertigo.eclipse.views.projectexplorer.ProjectExplorerView) RequestableObject(com.twinsoft.convertigo.beans.core.RequestableObject) RequestableVariable(com.twinsoft.convertigo.beans.variables.RequestableVariable) Sequence(com.twinsoft.convertigo.beans.core.Sequence) TransactionStep(com.twinsoft.convertigo.beans.steps.TransactionStep) RequestableStep(com.twinsoft.convertigo.beans.core.RequestableStep) IVariableContainer(com.twinsoft.convertigo.beans.core.IVariableContainer) TreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.TreeObject) DatabaseObjectTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.DatabaseObjectTreeObject) DatabaseObject(com.twinsoft.convertigo.beans.core.DatabaseObject) TreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.TreeObject) DatabaseObjectTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.DatabaseObjectTreeObject) RequestableObject(com.twinsoft.convertigo.beans.core.RequestableObject) Display(org.eclipse.swt.widgets.Display)

Aggregations

IVariableContainer (com.twinsoft.convertigo.beans.core.IVariableContainer)6 RequestableVariable (com.twinsoft.convertigo.beans.variables.RequestableVariable)4 RequestableObject (com.twinsoft.convertigo.beans.core.RequestableObject)3 Step (com.twinsoft.convertigo.beans.core.Step)3 Variable (com.twinsoft.convertigo.beans.core.Variable)3 XMLVector (com.twinsoft.convertigo.beans.common.XMLVector)2 DatabaseObject (com.twinsoft.convertigo.beans.core.DatabaseObject)2 Sequence (com.twinsoft.convertigo.beans.core.Sequence)2 StepWithExpressions (com.twinsoft.convertigo.beans.core.StepWithExpressions)2 SequenceStep (com.twinsoft.convertigo.beans.steps.SequenceStep)2 TransactionStep (com.twinsoft.convertigo.beans.steps.TransactionStep)2 ProjectExplorerView (com.twinsoft.convertigo.eclipse.views.projectexplorer.ProjectExplorerView)2 TreeObject (com.twinsoft.convertigo.eclipse.views.projectexplorer.model.TreeObject)2 QName (javax.xml.namespace.QName)2 Cursor (org.eclipse.swt.graphics.Cursor)2 Display (org.eclipse.swt.widgets.Display)2 Shell (org.eclipse.swt.widgets.Shell)2 XmlQName (com.twinsoft.convertigo.beans.common.XmlQName)1 ISimpleTypeAffectation (com.twinsoft.convertigo.beans.core.ISimpleTypeAffectation)1 IStepSourceContainer (com.twinsoft.convertigo.beans.core.IStepSourceContainer)1