Search in sources :

Example 1 with TransactionWithVariables

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

the class ChangeToSingleValuedVariableAction method run.

@Override
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();
            TreeParent treeParent = treeObject.getParent();
            DatabaseObjectTreeObject parentTreeObject = null;
            if (treeParent instanceof DatabaseObjectTreeObject)
                parentTreeObject = (DatabaseObjectTreeObject) treeParent;
            else
                parentTreeObject = (DatabaseObjectTreeObject) treeParent.getParent();
            if (parentTreeObject != null) {
                Object databaseObject = treeObject.getObject();
                if (databaseObject != null) {
                    Variable multi = (Variable) databaseObject;
                    Variable simple = null;
                    if (databaseObject instanceof TestCaseMultiValuedVariable)
                        simple = new TestCaseVariable();
                    if (databaseObject instanceof StepMultiValuedVariable)
                        simple = new StepVariable();
                    if (databaseObject instanceof RequestableMultiValuedVariable)
                        simple = new RequestableVariable();
                    if (databaseObject instanceof RequestableHttpMultiValuedVariable)
                        simple = new RequestableHttpVariable();
                    if (databaseObject instanceof HttpStatementMultiValuedVariable)
                        simple = new HttpStatementVariable();
                    if (simple != null) {
                        if (multi instanceof StepMultiValuedVariable) {
                            ((StepVariable) simple).setSourceDefinition(((StepVariable) multi).getSourceDefinition());
                        }
                        if (multi instanceof RequestableVariable) {
                            ((RequestableVariable) simple).setXmlTypeAffectation(((RequestableVariable) multi).getXmlTypeAffectation());
                        }
                        if (multi instanceof RequestableHttpVariable) {
                            // HttpName
                            ((RequestableHttpVariable) simple).setHttpName(((RequestableHttpVariable) multi).getHttpName());
                            // HttpMethod
                            ((RequestableHttpVariable) simple).setHttpMethod(((RequestableHttpVariable) multi).getHttpMethod());
                        }
                        XMLVector<Object> xmlv = GenericUtils.cast(multi.getValueOrNull());
                        Object value = (xmlv == null) ? null : (xmlv.isEmpty() ? "" : xmlv.get(0).toString());
                        simple.setValueOrNull(value);
                        simple.setVisibility(multi.getVisibility());
                        // Comment
                        simple.setComment(multi.getComment());
                        // Description
                        simple.setDescription(multi.getDescription());
                        // Required
                        simple.setRequired(multi.isRequired());
                        simple.bNew = true;
                        simple.hasChanged = true;
                        // Add new variable to parent
                        DatabaseObject parentDbo = multi.getParent();
                        parentDbo.add(simple);
                        // Set correct order
                        if (parentDbo instanceof TestCase)
                            ((TestCase) parentDbo).insertAtOrder(simple, multi.priority);
                        if (parentDbo instanceof RequestableStep)
                            ((RequestableStep) parentDbo).insertAtOrder(simple, multi.priority);
                        if (parentDbo instanceof Sequence)
                            ((Sequence) parentDbo).insertAtOrder(simple, multi.priority);
                        if (parentDbo instanceof TransactionWithVariables)
                            ((TransactionWithVariables) parentDbo).insertAtOrder(simple, multi.priority);
                        if (parentDbo instanceof HTTPStatement)
                            ((HTTPStatement) parentDbo).insertAtOrder(simple, multi.priority);
                        // Add new variable in Tree
                        VariableTreeObject2 varTreeObject = new VariableTreeObject2(explorerView.viewer, simple);
                        treeParent.addChild(varTreeObject);
                        // Delete simple variable
                        multi.delete();
                        // Set correct name
                        simple.setName(multi.getName());
                        parentTreeObject.hasBeenModified(true);
                        explorerView.reloadTreeObject(parentTreeObject);
                        explorerView.setSelectedTreeObject(explorerView.findTreeObjectByUserObject(simple));
                    }
                }
            }
        }
    } catch (Throwable e) {
        ConvertigoPlugin.logException(e, "Unable to change simple variable to multi valuated variable!");
    } finally {
        shell.setCursor(null);
        waitCursor.dispose();
    }
}
Also used : RequestableHttpVariable(com.twinsoft.convertigo.beans.variables.RequestableHttpVariable) DatabaseObjectTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.DatabaseObjectTreeObject) RequestableMultiValuedVariable(com.twinsoft.convertigo.beans.variables.RequestableMultiValuedVariable) RequestableHttpVariable(com.twinsoft.convertigo.beans.variables.RequestableHttpVariable) HttpStatementVariable(com.twinsoft.convertigo.beans.variables.HttpStatementVariable) TestCaseVariable(com.twinsoft.convertigo.beans.variables.TestCaseVariable) HttpStatementMultiValuedVariable(com.twinsoft.convertigo.beans.variables.HttpStatementMultiValuedVariable) Variable(com.twinsoft.convertigo.beans.core.Variable) StepVariable(com.twinsoft.convertigo.beans.variables.StepVariable) StepMultiValuedVariable(com.twinsoft.convertigo.beans.variables.StepMultiValuedVariable) TestCaseMultiValuedVariable(com.twinsoft.convertigo.beans.variables.TestCaseMultiValuedVariable) RequestableVariable(com.twinsoft.convertigo.beans.variables.RequestableVariable) RequestableHttpMultiValuedVariable(com.twinsoft.convertigo.beans.variables.RequestableHttpMultiValuedVariable) TreeParent(com.twinsoft.convertigo.eclipse.views.projectexplorer.TreeParent) HttpStatementMultiValuedVariable(com.twinsoft.convertigo.beans.variables.HttpStatementMultiValuedVariable) StepVariable(com.twinsoft.convertigo.beans.variables.StepVariable) Cursor(org.eclipse.swt.graphics.Cursor) HTTPStatement(com.twinsoft.convertigo.beans.statements.HTTPStatement) StepMultiValuedVariable(com.twinsoft.convertigo.beans.variables.StepMultiValuedVariable) Shell(org.eclipse.swt.widgets.Shell) DatabaseObject(com.twinsoft.convertigo.beans.core.DatabaseObject) VariableTreeObject2(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.VariableTreeObject2) ProjectExplorerView(com.twinsoft.convertigo.eclipse.views.projectexplorer.ProjectExplorerView) RequestableVariable(com.twinsoft.convertigo.beans.variables.RequestableVariable) Sequence(com.twinsoft.convertigo.beans.core.Sequence) HttpStatementVariable(com.twinsoft.convertigo.beans.variables.HttpStatementVariable) TestCaseVariable(com.twinsoft.convertigo.beans.variables.TestCaseVariable) TestCaseMultiValuedVariable(com.twinsoft.convertigo.beans.variables.TestCaseMultiValuedVariable) RequestableHttpMultiValuedVariable(com.twinsoft.convertigo.beans.variables.RequestableHttpMultiValuedVariable) TestCase(com.twinsoft.convertigo.beans.core.TestCase) RequestableStep(com.twinsoft.convertigo.beans.core.RequestableStep) RequestableMultiValuedVariable(com.twinsoft.convertigo.beans.variables.RequestableMultiValuedVariable) TreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.TreeObject) DatabaseObjectTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.DatabaseObjectTreeObject) TransactionWithVariables(com.twinsoft.convertigo.beans.core.TransactionWithVariables) 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) Display(org.eclipse.swt.widgets.Display)

Example 2 with TransactionWithVariables

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

the class VariableTreeObject2 method handlesBeanNameChanged.

protected void handlesBeanNameChanged(TreeObjectEvent treeObjectEvent) {
    DatabaseObjectTreeObject treeObject = (DatabaseObjectTreeObject) treeObjectEvent.getSource();
    DatabaseObject databaseObject = (DatabaseObject) treeObject.getObject();
    Object oldValue = treeObjectEvent.oldValue;
    Object newValue = treeObjectEvent.newValue;
    int update = treeObjectEvent.update;
    // Updates variables references
    if (update != TreeObjectEvent.UPDATE_NONE) {
        boolean isLocalProject = false;
        boolean isSameValue = false;
        boolean shouldUpdate = false;
        try {
            if (getObject() instanceof Variable) {
                Variable variable = (Variable) getObject();
                if (databaseObject instanceof RequestableVariable) {
                    isLocalProject = variable.getProject().equals(databaseObject.getProject());
                    isSameValue = variable.getName().equals(oldValue);
                    shouldUpdate = (update == TreeObjectEvent.UPDATE_ALL) || ((update == TreeObjectEvent.UPDATE_LOCAL) && (isLocalProject));
                    // Verify if parent of databaseObject is a transaction
                    if (databaseObject.getParent() instanceof Transaction) {
                        Transaction transaction = (Transaction) databaseObject.getParent();
                        // Case of rename for Call Transaction
                        if (variable.getParent() instanceof TransactionStep) {
                            TransactionStep transactionStep = (TransactionStep) variable.getParent();
                            if (transactionStep.getSourceTransaction().equals(transaction.getProject() + "." + transaction.getConnector() + "." + transaction.getName())) {
                                updateNameReference(isSameValue, shouldUpdate, variable, newValue);
                            }
                        }
                        /*
							 * propagation to testCases of variable renaming in a transaction
							 */
                        if (variable.getParent() instanceof TransactionWithVariables) {
                            propagateVariableRename(true, true, treeObjectEvent, ((TransactionWithVariables) transaction).getTestCasesList(), transaction.getName());
                        }
                    }
                    // Verify if parent of databaseObject is a sequence
                    if (databaseObject.getParent() instanceof Sequence) {
                        Sequence sequence = (Sequence) databaseObject.getParent();
                        // Case of rename for Call Sequence
                        if (variable.getParent() instanceof SequenceStep) {
                            SequenceStep sequenceStep = (SequenceStep) variable.getParent();
                            if (sequenceStep.getSourceSequence().equals(sequence.getProject() + "." + sequence.getName())) {
                                updateNameReference(isSameValue, shouldUpdate, variable, newValue);
                            }
                        }
                        /*
							 * propagation to testCases of variable renaming in a sequence
							 */
                        if (variable.getParent() instanceof Sequence) {
                            propagateVariableRename(true, true, treeObjectEvent, sequence.getTestCasesList(), sequence.getName());
                        }
                    }
                }
            }
        } catch (EngineException e) {
            ConvertigoPlugin.logException(e, "Unable to rename the variable references of '" + databaseObject.getName() + "'!");
        }
    }
}
Also used : SequenceStep(com.twinsoft.convertigo.beans.steps.SequenceStep) TestCaseVariable(com.twinsoft.convertigo.beans.variables.TestCaseVariable) Variable(com.twinsoft.convertigo.beans.core.Variable) RequestableVariable(com.twinsoft.convertigo.beans.variables.RequestableVariable) EngineException(com.twinsoft.convertigo.engine.EngineException) RequestableVariable(com.twinsoft.convertigo.beans.variables.RequestableVariable) Sequence(com.twinsoft.convertigo.beans.core.Sequence) TransactionStep(com.twinsoft.convertigo.beans.steps.TransactionStep) Transaction(com.twinsoft.convertigo.beans.core.Transaction) DatabaseObject(com.twinsoft.convertigo.beans.core.DatabaseObject) TransactionWithVariables(com.twinsoft.convertigo.beans.core.TransactionWithVariables) DatabaseObject(com.twinsoft.convertigo.beans.core.DatabaseObject)

Example 3 with TransactionWithVariables

use of com.twinsoft.convertigo.beans.core.TransactionWithVariables 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 4 with TransactionWithVariables

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

the class Migration7_0_0 method migrate.

public static void migrate(final String projectName) {
    try {
        Map<String, Reference> referenceMap = new HashMap<String, Reference>();
        XmlSchema projectSchema = null;
        Project project = Engine.theApp.databaseObjectsManager.getOriginalProjectByName(projectName, false);
        // Copy all xsd files to project's xsd directory
        File destDir = new File(project.getXsdDirPath());
        copyXsdOfProject(projectName, destDir);
        String projectWsdlFilePath = Engine.PROJECTS_PATH + "/" + projectName + "/" + projectName + ".wsdl";
        File wsdlFile = new File(projectWsdlFilePath);
        String projectXsdFilePath = Engine.PROJECTS_PATH + "/" + projectName + "/" + projectName + ".xsd";
        File xsdFile = new File(projectXsdFilePath);
        if (xsdFile.exists()) {
            // Load project schema from old XSD file
            XmlSchemaCollection collection = new XmlSchemaCollection();
            collection.setSchemaResolver(new DefaultURIResolver() {

                public InputSource resolveEntity(String targetNamespace, String schemaLocation, String baseUri) {
                    // Case of a c8o project location
                    if (schemaLocation.startsWith("../") && schemaLocation.endsWith(".xsd")) {
                        try {
                            String targetProjectName = schemaLocation.substring(3, schemaLocation.indexOf("/", 3));
                            File pDir = new File(Engine.projectDir(targetProjectName));
                            if (pDir.exists()) {
                                File pFile = new File(Engine.PROJECTS_PATH + schemaLocation.substring(2));
                                // Case c8o project is already migrated
                                if (!pFile.exists()) {
                                    Document doc = Engine.theApp.schemaManager.getSchemaForProject(targetProjectName).getSchemaDocument();
                                    DOMSource source = new DOMSource(doc);
                                    StringWriter writer = new StringWriter();
                                    StreamResult result = new StreamResult(writer);
                                    TransformerFactory.newInstance().newTransformer().transform(source, result);
                                    StringReader reader = new StringReader(writer.toString());
                                    return new InputSource(reader);
                                }
                            }
                            return null;
                        } catch (Exception e) {
                            Engine.logDatabaseObjectManager.warn("[Migration 7.0.0] Unable to find schema location \"" + schemaLocation + "\"", e);
                            return null;
                        }
                    } else if (schemaLocation.indexOf("://") == -1 && schemaLocation.endsWith(".xsd")) {
                        return super.resolveEntity(targetNamespace, schemaLocation, Engine.PROJECTS_PATH + "/" + projectName);
                    }
                    return super.resolveEntity(targetNamespace, schemaLocation, baseUri);
                }
            });
            projectSchema = SchemaUtils.loadSchema(new File(projectXsdFilePath), collection);
            ConvertigoError.updateXmlSchemaObjects(projectSchema);
            SchemaMeta.setCollection(projectSchema, collection);
            for (Connector connector : project.getConnectorsList()) {
                for (Transaction transaction : connector.getTransactionsList()) {
                    try {
                        // Migrate transaction in case of a Web Service consumption project
                        if (transaction instanceof XmlHttpTransaction) {
                            XmlHttpTransaction xmlHttpTransaction = (XmlHttpTransaction) transaction;
                            String reqn = xmlHttpTransaction.getResponseElementQName();
                            if (!reqn.equals("")) {
                                boolean useRef = reqn.indexOf(";") == -1;
                                // Doc/Literal case
                                if (useRef) {
                                    try {
                                        String[] qn = reqn.split(":");
                                        QName refName = new QName(projectSchema.getNamespaceContext().getNamespaceURI(qn[0]), qn[1]);
                                        xmlHttpTransaction.setXmlElementRefAffectation(new XmlQName(refName));
                                    } catch (Exception e) {
                                    }
                                } else // RPC case
                                {
                                    int index, index2;
                                    try {
                                        index = reqn.indexOf(";");
                                        String opName = reqn.substring(0, index);
                                        if ((index2 = reqn.indexOf(";", index + 1)) != -1) {
                                            String eltName = reqn.substring(index + 1, index2);
                                            String eltType = reqn.substring(index2 + 1);
                                            String[] qn = eltType.split(":");
                                            QName typeName = new QName(projectSchema.getNamespaceContext().getNamespaceURI(qn[0]), qn[1]);
                                            String responseElementQName = opName + ";" + eltName + ";" + "{" + typeName.getNamespaceURI() + "}" + typeName.getLocalPart();
                                            xmlHttpTransaction.setResponseElementQName(responseElementQName);
                                        }
                                    } catch (Exception e) {
                                    }
                                }
                            }
                        }
                        // Retrieve required XmlSchemaObjects for transaction
                        QName requestQName = new QName(project.getTargetNamespace(), transaction.getXsdRequestElementName());
                        QName responseQName = new QName(project.getTargetNamespace(), transaction.getXsdResponseElementName());
                        LinkedHashMap<QName, XmlSchemaObject> map = new LinkedHashMap<QName, XmlSchemaObject>();
                        XmlSchemaWalker dw = XmlSchemaWalker.newDependencyWalker(map, true, false);
                        dw.walkByElementRef(projectSchema, requestQName);
                        dw.walkByElementRef(projectSchema, responseQName);
                        // Create transaction schema
                        String targetNamespace = projectSchema.getTargetNamespace();
                        String prefix = projectSchema.getNamespaceContext().getPrefix(targetNamespace);
                        XmlSchema transactionSchema = SchemaUtils.createSchema(prefix, targetNamespace, XsdForm.unqualified.name(), XsdForm.unqualified.name());
                        // Add required prefix declarations
                        List<String> nsList = new LinkedList<String>();
                        for (QName qname : map.keySet()) {
                            String nsURI = qname.getNamespaceURI();
                            if (!nsURI.equals(Constants.URI_2001_SCHEMA_XSD)) {
                                if (!nsList.contains(nsURI)) {
                                    nsList.add(nsURI);
                                }
                            }
                            String nsPrefix = qname.getPrefix();
                            if (!nsURI.equals(targetNamespace)) {
                                NamespaceMap nsMap = SchemaUtils.getNamespaceMap(transactionSchema);
                                if (nsMap.getNamespaceURI(nsPrefix) == null) {
                                    nsMap.add(nsPrefix, nsURI);
                                    transactionSchema.setNamespaceContext(nsMap);
                                }
                            }
                        }
                        // Add required imports
                        for (String namespaceURI : nsList) {
                            XmlSchemaObjectCollection includes = projectSchema.getIncludes();
                            for (int i = 0; i < includes.getCount(); i++) {
                                XmlSchemaObject xmlSchemaObject = includes.getItem(i);
                                if (xmlSchemaObject instanceof XmlSchemaImport) {
                                    if (((XmlSchemaImport) xmlSchemaObject).getNamespace().equals(namespaceURI)) {
                                        // do not allow import with same ns !
                                        if (namespaceURI.equals(project.getTargetNamespace()))
                                            continue;
                                        String location = ((XmlSchemaImport) xmlSchemaObject).getSchemaLocation();
                                        // This is a convertigo project reference
                                        if (location.startsWith("../")) {
                                            // Copy all xsd files to xsd directory
                                            String targetProjectName = location.substring(3, location.indexOf("/", 3));
                                            copyXsdOfProject(targetProjectName, destDir);
                                        }
                                        // Add reference
                                        addReferenceToMap(referenceMap, namespaceURI, location);
                                        // Add import
                                        addImport(transactionSchema, namespaceURI, location);
                                    }
                                }
                            }
                        }
                        QName responseTypeQName = new QName(project.getTargetNamespace(), transaction.getXsdResponseTypeName());
                        // Add required schema objects
                        for (QName qname : map.keySet()) {
                            if (qname.getNamespaceURI().equals(targetNamespace)) {
                                XmlSchemaObject ob = map.get(qname);
                                if (qname.getLocalPart().startsWith("ConvertigoError"))
                                    continue;
                                transactionSchema.getItems().add(ob);
                                // Add missing response error element and attributes
                                if (qname.equals(responseTypeQName)) {
                                    Transaction.addSchemaResponseObjects(transactionSchema, (XmlSchemaComplexType) ob);
                                }
                            }
                        }
                        // Add missing ResponseType (with document)
                        if (map.containsKey(responseTypeQName)) {
                            Transaction.addSchemaResponseType(transactionSchema, transaction);
                        }
                        // Add everything
                        if (map.isEmpty()) {
                            Transaction.addSchemaObjects(transactionSchema, transaction);
                        }
                        // Add c8o error objects (for internal xsd edition only)
                        ConvertigoError.updateXmlSchemaObjects(transactionSchema);
                        // Save schema to file
                        String transactionXsdFilePath = transaction.getSchemaFilePath();
                        new File(transaction.getSchemaFileDirPath()).mkdirs();
                        SchemaUtils.saveSchema(transactionXsdFilePath, transactionSchema);
                    } catch (Exception e) {
                        Engine.logDatabaseObjectManager.error("[Migration 7.0.0] An error occured while migrating transaction \"" + transaction.getName() + "\"", e);
                    }
                    if (transaction instanceof TransactionWithVariables) {
                        TransactionWithVariables transactionVars = (TransactionWithVariables) transaction;
                        handleRequestableVariable(transactionVars.getVariablesList());
                        // Change SQLQuery variables : i.e. {id} --> {{id}}
                        if (transaction instanceof SqlTransaction) {
                            String sqlQuery = ((SqlTransaction) transaction).getSqlQuery();
                            sqlQuery = sqlQuery.replaceAll("\\{([a-zA-Z0-9_]+)\\}", "{{$1}}");
                            ((SqlTransaction) transaction).setSqlQuery(sqlQuery);
                        }
                    }
                }
            }
        } else {
            // Should only happen for projects which version <= 4.6.0
            XmlSchemaCollection collection = new XmlSchemaCollection();
            String prefix = project.getName() + "_ns";
            projectSchema = SchemaUtils.createSchema(prefix, project.getNamespaceUri(), XsdForm.unqualified.name(), XsdForm.unqualified.name());
            ConvertigoError.addXmlSchemaObjects(projectSchema);
            SchemaMeta.setCollection(projectSchema, collection);
            for (Connector connector : project.getConnectorsList()) {
                for (Transaction transaction : connector.getTransactionsList()) {
                    if (transaction instanceof TransactionWithVariables) {
                        TransactionWithVariables transactionVars = (TransactionWithVariables) transaction;
                        handleRequestableVariable(transactionVars.getVariablesList());
                    }
                }
            }
        }
        // Handle sequence objects
        for (Sequence sequence : project.getSequencesList()) {
            handleSteps(projectSchema, referenceMap, sequence.getSteps());
            handleRequestableVariable(sequence.getVariablesList());
        }
        // Add all references to project
        if (!referenceMap.isEmpty()) {
            for (Reference reference : referenceMap.values()) project.add(reference);
        }
        // Delete XSD file
        if (xsdFile.exists())
            xsdFile.delete();
        // Delete WSDL file
        if (wsdlFile.exists())
            wsdlFile.delete();
    } catch (Exception e) {
        Engine.logDatabaseObjectManager.error("[Migration 7.0.0] An error occured while migrating project \"" + projectName + "\"", e);
    }
}
Also used : Connector(com.twinsoft.convertigo.beans.core.Connector) InputSource(org.xml.sax.InputSource) DOMSource(javax.xml.transform.dom.DOMSource) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) Document(org.w3c.dom.Document) LinkedHashMap(java.util.LinkedHashMap) XmlSchemaWalker(com.twinsoft.convertigo.engine.util.XmlSchemaWalker) StringWriter(java.io.StringWriter) XmlSchemaObject(org.apache.ws.commons.schema.XmlSchemaObject) DefaultURIResolver(org.apache.ws.commons.schema.resolver.DefaultURIResolver) StringReader(java.io.StringReader) XmlSchemaImport(org.apache.ws.commons.schema.XmlSchemaImport) XmlSchemaObjectCollection(org.apache.ws.commons.schema.XmlSchemaObjectCollection) StreamResult(javax.xml.transform.stream.StreamResult) Reference(com.twinsoft.convertigo.beans.core.Reference) ProjectSchemaReference(com.twinsoft.convertigo.beans.references.ProjectSchemaReference) ImportXsdSchemaReference(com.twinsoft.convertigo.beans.references.ImportXsdSchemaReference) XmlHttpTransaction(com.twinsoft.convertigo.beans.transactions.XmlHttpTransaction) XmlQName(com.twinsoft.convertigo.beans.common.XmlQName) QName(javax.xml.namespace.QName) SqlTransaction(com.twinsoft.convertigo.beans.transactions.SqlTransaction) XmlSchemaSequence(org.apache.ws.commons.schema.XmlSchemaSequence) Sequence(com.twinsoft.convertigo.beans.core.Sequence) XmlSchemaCollection(org.apache.ws.commons.schema.XmlSchemaCollection) EngineException(com.twinsoft.convertigo.engine.EngineException) IOException(java.io.IOException) LinkedList(java.util.LinkedList) Project(com.twinsoft.convertigo.beans.core.Project) XmlQName(com.twinsoft.convertigo.beans.common.XmlQName) SqlTransaction(com.twinsoft.convertigo.beans.transactions.SqlTransaction) XmlHttpTransaction(com.twinsoft.convertigo.beans.transactions.XmlHttpTransaction) Transaction(com.twinsoft.convertigo.beans.core.Transaction) XmlSchema(org.apache.ws.commons.schema.XmlSchema) NamespaceMap(org.apache.ws.commons.schema.utils.NamespaceMap) TransactionWithVariables(com.twinsoft.convertigo.beans.core.TransactionWithVariables) File(java.io.File)

Example 5 with TransactionWithVariables

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

the class ClipboardManager method paste.

public Object paste(Node node, DatabaseObject parentDatabaseObject, boolean bChangeName) throws EngineException {
    Object object = read(node);
    if (object instanceof DatabaseObject) {
        DatabaseObject databaseObject = (DatabaseObject) object;
        String dboName = databaseObject.getName();
        String name = null;
        if (objectsType != ProjectExplorerView.TREE_OBJECT_TYPE_DBO_PROJECT) {
            // Verify if object is accepted for paste
            if (!DatabaseObjectsManager.acceptDatabaseObjects(parentDatabaseObject, databaseObject)) {
                throw new EngineException("You cannot paste to a " + parentDatabaseObject.getClass().getSimpleName() + " a database object of type " + databaseObject.getClass().getSimpleName());
            }
            if (parentDatabaseObject instanceof com.twinsoft.convertigo.beans.mobile.components.MobileComponent) {
                if (!com.twinsoft.convertigo.beans.mobile.components.dynamic.ComponentManager.acceptDatabaseObjects(parentDatabaseObject, databaseObject)) {
                    throw new EngineException("You cannot paste to a " + parentDatabaseObject.getClass().getSimpleName() + " a database object of type " + databaseObject.getClass().getSimpleName());
                }
                if (!com.twinsoft.convertigo.beans.mobile.components.dynamic.ComponentManager.isTplCompatible(parentDatabaseObject, databaseObject)) {
                    String tplVersion = com.twinsoft.convertigo.beans.mobile.components.dynamic.ComponentManager.getTplRequired(databaseObject);
                    throw new EngineException("Template project " + tplVersion + " compatibility required");
                }
            } else if (parentDatabaseObject instanceof com.twinsoft.convertigo.beans.ngx.components.MobileComponent) {
                if (!com.twinsoft.convertigo.beans.ngx.components.dynamic.ComponentManager.acceptDatabaseObjects(parentDatabaseObject, databaseObject)) {
                    throw new EngineException("You cannot paste to a " + parentDatabaseObject.getClass().getSimpleName() + " a database object of type " + databaseObject.getClass().getSimpleName());
                }
                if (!com.twinsoft.convertigo.beans.ngx.components.dynamic.ComponentManager.isTplCompatible(parentDatabaseObject, databaseObject)) {
                    String tplVersion = com.twinsoft.convertigo.beans.ngx.components.dynamic.ComponentManager.getTplRequired(databaseObject);
                    throw new EngineException("Template project " + tplVersion + " compatibility required");
                }
            }
            // Disable the isDefault boolean flag when the connector is pasted
            if (databaseObject instanceof Connector) {
                Connector connector = (Connector) databaseObject;
                if (connector.isDefault) {
                    connector.isDefault = false;
                }
            }
            // Disable the isRoot boolean flag when the page is pasted
            if (databaseObject instanceof com.twinsoft.convertigo.beans.mobile.components.PageComponent) {
                com.twinsoft.convertigo.beans.mobile.components.PageComponent page = GenericUtils.cast(databaseObject);
                if (page.isRoot) {
                    page.isRoot = false;
                }
            } else if (databaseObject instanceof com.twinsoft.convertigo.beans.ngx.components.PageComponent) {
                com.twinsoft.convertigo.beans.ngx.components.PageComponent page = GenericUtils.cast(databaseObject);
                if (page.isRoot) {
                    page.isRoot = false;
                }
            }
            if (objectsType != ProjectExplorerView.TREE_OBJECT_TYPE_DBO_CONNECTOR) {
                // Disable the isDefault boolean flag when the transaction is pasted
                if (databaseObject instanceof Transaction) {
                    Transaction transaction = (Transaction) databaseObject;
                    if (transaction.isDefault) {
                        transaction.isDefault = false;
                    }
                }
            }
        }
        // Special case of project
        if (databaseObject instanceof Project) {
            return databaseObject;
        }
        boolean bContinue = true;
        int index = 0;
        long oldPriority = databaseObject.priority;
        // Verify if a child object with same name exist and change name
        while (bContinue) {
            if (bChangeName) {
                if (index == 0)
                    name = dboName;
                else
                    name = dboName + index;
                databaseObject.setName(name);
            }
            databaseObject.hasChanged = true;
            databaseObject.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(databaseObject);
                        find |= isInstance;
                        return isInstance;
                    }

                    @Override
                    protected void walk(DatabaseObject dbo) throws Exception {
                        if (root) {
                            root = false;
                            super.walk(dbo);
                            if (!find) {
                            // ignore: we must accept special paste: e.g. transaction over sequence
                            }
                        } else {
                            if (databaseObject.getName().equalsIgnoreCase(dbo.getName())) {
                                throw new ObjectWithSameNameException("Unable to paste the object because an object with the same name already exists in target.");
                            }
                        }
                    }
                }.init(parentDatabaseObject);
                bContinue = false;
            } catch (ObjectWithSameNameException owsne) {
                if ((parentDatabaseObject instanceof HtmlTransaction) && (databaseObject 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 paste", e);
            }
        }
        // reset ordered properties
        if (databaseObject instanceof IContainerOrdered) {
            // Mobile beans
            if (databaseObject instanceof com.twinsoft.convertigo.beans.mobile.components.MobileComponent) {
                if (databaseObject instanceof com.twinsoft.convertigo.beans.mobile.components.ApplicationComponent) {
                    com.twinsoft.convertigo.beans.mobile.components.ApplicationComponent ac = GenericUtils.cast(databaseObject);
                    ac.setOrderedRoutes(getNewOrdered());
                    ac.setOrderedMenus(getNewOrdered());
                    ac.setOrderedPages(getNewOrdered());
                    ac.setOrderedComponents(getNewOrdered());
                    ac.setOrderedSharedActions(getNewOrdered());
                    ac.setOrderedSharedComponents(getNewOrdered());
                }
                if (databaseObject instanceof com.twinsoft.convertigo.beans.mobile.components.RouteComponent) {
                    com.twinsoft.convertigo.beans.mobile.components.RouteComponent rc = GenericUtils.cast(databaseObject);
                    rc.setOrderedActions(getNewOrdered());
                    rc.setOrderedEvents(getNewOrdered());
                }
                if (databaseObject instanceof com.twinsoft.convertigo.beans.mobile.components.PageComponent) {
                    com.twinsoft.convertigo.beans.mobile.components.PageComponent pc = GenericUtils.cast(databaseObject);
                    pc.setOrderedComponents(getNewOrdered());
                }
                if (databaseObject instanceof com.twinsoft.convertigo.beans.mobile.components.UIComponent) {
                    com.twinsoft.convertigo.beans.mobile.components.UIComponent uic = GenericUtils.cast(databaseObject);
                    uic.setOrderedComponents(getNewOrdered());
                }
            } else if (databaseObject instanceof com.twinsoft.convertigo.beans.ngx.components.MobileComponent) {
                if (databaseObject instanceof com.twinsoft.convertigo.beans.ngx.components.ApplicationComponent) {
                    com.twinsoft.convertigo.beans.ngx.components.ApplicationComponent ac = GenericUtils.cast(databaseObject);
                    ac.setOrderedMenus(getNewOrdered());
                    ac.setOrderedPages(getNewOrdered());
                    ac.setOrderedComponents(getNewOrdered());
                    ac.setOrderedSharedActions(getNewOrdered());
                    ac.setOrderedSharedComponents(getNewOrdered());
                }
                if (databaseObject instanceof com.twinsoft.convertigo.beans.ngx.components.PageComponent) {
                    com.twinsoft.convertigo.beans.ngx.components.PageComponent pc = GenericUtils.cast(databaseObject);
                    pc.setOrderedComponents(getNewOrdered());
                }
                if (databaseObject instanceof com.twinsoft.convertigo.beans.ngx.components.UIComponent) {
                    com.twinsoft.convertigo.beans.ngx.components.UIComponent uic = GenericUtils.cast(databaseObject);
                    uic.setOrderedComponents(getNewOrdered());
                }
            }
            // Sequence beans
            if (databaseObject instanceof Sequence) {
                ((Sequence) databaseObject).setOrderedSteps(getNewOrdered());
                ((Sequence) databaseObject).setOrderedVariables(getNewOrdered());
            }
            if (databaseObject instanceof StepWithExpressions) {
                ((StepWithExpressions) databaseObject).setOrderedSteps(getNewOrdered());
            }
            if (databaseObject instanceof RequestableStep) {
                ((RequestableStep) databaseObject).setOrderedVariables(getNewOrdered());
            }
            // Transaction beans
            if (databaseObject instanceof TransactionWithVariables) {
                ((TransactionWithVariables) databaseObject).setOrderedVariables(getNewOrdered());
            }
            if (databaseObject instanceof StatementWithExpressions) {
                ((StatementWithExpressions) databaseObject).setOrderedStatements(getNewOrdered());
            }
            if (databaseObject instanceof HTTPStatement) {
                ((HTTPStatement) databaseObject).setOrderedVariables(getNewOrdered());
            }
            if (databaseObject instanceof ScreenClass) {
                ((ScreenClass) databaseObject).setOrderedCriterias(getNewOrdered());
                ((ScreenClass) databaseObject).setOrderedExtractionRules(getNewOrdered());
            }
            // TestCase bean
            if (databaseObject instanceof TestCase) {
                ((TestCase) databaseObject).setOrderedVariables(getNewOrdered());
            }
        }
        // Now add dbo to target
        try {
            if (parentDatabaseObject instanceof ScreenClass) {
                if (parentDatabaseObject instanceof JavelinScreenClass) {
                    JavelinScreenClass screenClass = (JavelinScreenClass) parentDatabaseObject;
                    if (databaseObject instanceof BlockFactory) {
                        screenClass.add(databaseObject);
                        screenClass.setBlockFactory((BlockFactory) databaseObject);
                    }
                }
                ScreenClass screenClass = (ScreenClass) parentDatabaseObject;
                if (databaseObject instanceof Criteria) {
                    if ((!screenClass.bNew) && (screenClass.equals(((IScreenClassContainer<?>) screenClass.getConnector()).getDefaultScreenClass()))) {
                        throw new EngineException("You cannot paste a new criterion to the default screen class");
                    }
                    databaseObject.priority = databaseObject.getNewOrderValue();
                    screenClass.add(databaseObject);
                } else if (databaseObject instanceof ExtractionRule) {
                    databaseObject.priority = databaseObject.getNewOrderValue();
                    screenClass.add(databaseObject);
                } else if (databaseObject instanceof Sheet) {
                    screenClass.add(databaseObject);
                } else if (databaseObject instanceof ScreenClass) {
                    databaseObject.priority = screenClass.priority + 1;
                    screenClass.add(databaseObject);
                }
            } else if (parentDatabaseObject instanceof HtmlTransaction) {
                HtmlTransaction transaction = (HtmlTransaction) parentDatabaseObject;
                if (databaseObject instanceof Sheet) {
                    transaction.add(databaseObject);
                } else if (databaseObject instanceof TestCase) {
                    transaction.add(databaseObject);
                } else if (databaseObject instanceof Variable) {
                    databaseObject.priority = databaseObject.getNewOrderValue();
                    transaction.add(databaseObject);
                } else if (databaseObject instanceof FunctionStatement) {
                    if (databaseObject instanceof StatementWithExpressions) {
                        databaseObject.priority = 0;
                    }
                    transaction.add(databaseObject);
                } else {
                    throw new EngineException("You cannot paste to an HtmlTransaction a database object of type " + databaseObject.getClass().getName());
                }
            } else if (parentDatabaseObject instanceof TransactionWithVariables) {
                TransactionWithVariables transaction = (TransactionWithVariables) parentDatabaseObject;
                if (databaseObject instanceof Sheet) {
                    transaction.add(databaseObject);
                } else if (databaseObject instanceof TestCase) {
                    transaction.add(databaseObject);
                } else if (databaseObject instanceof Variable) {
                    databaseObject.priority = databaseObject.getNewOrderValue();
                    transaction.add(databaseObject);
                }
            } else if (parentDatabaseObject instanceof Sequence) {
                Sequence sequence = (Sequence) parentDatabaseObject;
                if (databaseObject instanceof Sheet) {
                    sequence.add(databaseObject);
                } else if (databaseObject instanceof TestCase) {
                    sequence.add(databaseObject);
                } else if (databaseObject instanceof Step) {
                    databaseObject.priority = databaseObject.getNewOrderValue();
                    sequence.add(databaseObject);
                } else if (databaseObject instanceof Variable) {
                    databaseObject.priority = databaseObject.getNewOrderValue();
                    sequence.add(databaseObject);
                } else {
                    throw new EngineException("You cannot paste to a Sequence a database object of type " + databaseObject.getClass().getName());
                }
            } else if (parentDatabaseObject instanceof StatementWithExpressions) {
                StatementWithExpressions statement = (StatementWithExpressions) parentDatabaseObject;
                databaseObject.priority = databaseObject.getNewOrderValue();
                statement.add(databaseObject);
            } else if (parentDatabaseObject instanceof HTTPStatement) {
                HTTPStatement statement = (HTTPStatement) parentDatabaseObject;
                if (databaseObject instanceof Variable) {
                    databaseObject.priority = databaseObject.getNewOrderValue();
                    statement.add(databaseObject);
                }
            } else if (parentDatabaseObject instanceof StepWithExpressions) {
                StepWithExpressions step = (StepWithExpressions) parentDatabaseObject;
                databaseObject.priority = databaseObject.getNewOrderValue();
                step.add(databaseObject);
            } else if (parentDatabaseObject instanceof RequestableStep) {
                RequestableStep step = (RequestableStep) parentDatabaseObject;
                if (databaseObject instanceof Variable) {
                    databaseObject.priority = databaseObject.getNewOrderValue();
                    step.add(databaseObject);
                }
            } else if (parentDatabaseObject instanceof TestCase) {
                TestCase testCase = (TestCase) parentDatabaseObject;
                if (databaseObject instanceof Variable) {
                    databaseObject.priority = databaseObject.getNewOrderValue();
                    testCase.add(databaseObject);
                }
            } else // MOBILE COMPONENTS
            if (parentDatabaseObject instanceof com.twinsoft.convertigo.beans.mobile.components.MobileComponent) {
                if (parentDatabaseObject instanceof com.twinsoft.convertigo.beans.mobile.components.ApplicationComponent) {
                    com.twinsoft.convertigo.beans.mobile.components.ApplicationComponent app = GenericUtils.cast(parentDatabaseObject);
                    if (databaseObject instanceof com.twinsoft.convertigo.beans.mobile.components.PageComponent) {
                        databaseObject.priority = databaseObject.getNewOrderValue();
                        app.add(databaseObject);
                    } else if (databaseObject instanceof com.twinsoft.convertigo.beans.mobile.components.RouteComponent) {
                        databaseObject.priority = databaseObject.getNewOrderValue();
                        app.add(databaseObject);
                    } else if (databaseObject instanceof com.twinsoft.convertigo.beans.mobile.components.UIDynamicMenu) {
                        databaseObject.priority = databaseObject.getNewOrderValue();
                        app.add(databaseObject);
                    } else if (databaseObject instanceof com.twinsoft.convertigo.beans.mobile.components.UIComponent) {
                        databaseObject.priority = databaseObject.getNewOrderValue();
                        app.add(databaseObject);
                    }
                } else if (parentDatabaseObject instanceof com.twinsoft.convertigo.beans.mobile.components.RouteComponent) {
                    com.twinsoft.convertigo.beans.mobile.components.RouteComponent route = GenericUtils.cast(parentDatabaseObject);
                    if (databaseObject instanceof com.twinsoft.convertigo.beans.mobile.components.RouteActionComponent) {
                        databaseObject.priority = databaseObject.getNewOrderValue();
                        com.twinsoft.convertigo.beans.mobile.components.RouteActionComponent rac = GenericUtils.cast(databaseObject);
                        int i = rac.getPage().lastIndexOf(".");
                        if (i != -1) {
                            String pageName = rac.getPage().substring(i);
                            String pageQName = route.getParent().getQName() + pageName;
                            rac.setPage(pageQName);
                        }
                        route.add(rac);
                    } else if (databaseObject instanceof com.twinsoft.convertigo.beans.mobile.components.RouteEventComponent) {
                        databaseObject.priority = databaseObject.getNewOrderValue();
                        route.add(databaseObject);
                    }
                } else if (parentDatabaseObject instanceof com.twinsoft.convertigo.beans.mobile.components.PageComponent) {
                    com.twinsoft.convertigo.beans.mobile.components.PageComponent page = GenericUtils.cast(parentDatabaseObject);
                    if (databaseObject instanceof com.twinsoft.convertigo.beans.mobile.components.UIComponent) {
                        databaseObject.priority = databaseObject.getNewOrderValue();
                        page.add(databaseObject);
                    }
                } else if (parentDatabaseObject instanceof com.twinsoft.convertigo.beans.mobile.components.UIDynamicMenu) {
                    com.twinsoft.convertigo.beans.mobile.components.UIDynamicMenu menu = GenericUtils.cast(parentDatabaseObject);
                    if (databaseObject instanceof com.twinsoft.convertigo.beans.mobile.components.UIComponent) {
                        databaseObject.priority = databaseObject.getNewOrderValue();
                        menu.add(databaseObject);
                    }
                } else if (parentDatabaseObject instanceof com.twinsoft.convertigo.beans.mobile.components.UIComponent) {
                    com.twinsoft.convertigo.beans.mobile.components.UIComponent component = GenericUtils.cast(parentDatabaseObject);
                    databaseObject.priority = databaseObject.getNewOrderValue();
                    component.add(databaseObject);
                }
            } else // NGX COMPONENTS
            if (parentDatabaseObject instanceof com.twinsoft.convertigo.beans.ngx.components.MobileComponent) {
                if (parentDatabaseObject instanceof com.twinsoft.convertigo.beans.ngx.components.ApplicationComponent) {
                    com.twinsoft.convertigo.beans.ngx.components.ApplicationComponent app = GenericUtils.cast(parentDatabaseObject);
                    if (databaseObject instanceof com.twinsoft.convertigo.beans.ngx.components.PageComponent) {
                        databaseObject.priority = databaseObject.getNewOrderValue();
                        app.add(databaseObject);
                    } else if (databaseObject instanceof com.twinsoft.convertigo.beans.ngx.components.UIDynamicMenu) {
                        databaseObject.priority = databaseObject.getNewOrderValue();
                        app.add(databaseObject);
                    } else if (databaseObject instanceof com.twinsoft.convertigo.beans.ngx.components.UIComponent) {
                        databaseObject.priority = databaseObject.getNewOrderValue();
                        app.add(databaseObject);
                    }
                } else if (parentDatabaseObject instanceof com.twinsoft.convertigo.beans.ngx.components.PageComponent) {
                    com.twinsoft.convertigo.beans.ngx.components.PageComponent page = GenericUtils.cast(parentDatabaseObject);
                    if (databaseObject instanceof com.twinsoft.convertigo.beans.ngx.components.UIComponent) {
                        databaseObject.priority = databaseObject.getNewOrderValue();
                        page.add(databaseObject);
                    }
                } else if (parentDatabaseObject instanceof com.twinsoft.convertigo.beans.ngx.components.UIDynamicMenu) {
                    com.twinsoft.convertigo.beans.ngx.components.UIDynamicMenu menu = GenericUtils.cast(parentDatabaseObject);
                    if (databaseObject instanceof com.twinsoft.convertigo.beans.ngx.components.UIComponent) {
                        databaseObject.priority = databaseObject.getNewOrderValue();
                        menu.add(databaseObject);
                    }
                } else if (parentDatabaseObject instanceof com.twinsoft.convertigo.beans.ngx.components.UIComponent) {
                    com.twinsoft.convertigo.beans.ngx.components.UIComponent component = GenericUtils.cast(parentDatabaseObject);
                    databaseObject.priority = databaseObject.getNewOrderValue();
                    component.add(databaseObject);
                }
            } else if (parentDatabaseObject == null) {
                if (databaseObject instanceof Project) {
                    if (Engine.theApp.databaseObjectsManager.existsProject(databaseObject.getName())) {
                        throw new ObjectWithSameNameException("Project already exist!");
                    }
                }
            } else {
                parentDatabaseObject.add(databaseObject);
            }
        } catch (ObjectWithSameNameException owsne) {
            if ((parentDatabaseObject instanceof HtmlTransaction) && (databaseObject instanceof Statement)) {
                throw new EngineException("HtmlTransaction already contains a statement named \"" + name + "\".", owsne);
            }
            if ((parentDatabaseObject instanceof Sequence) && (databaseObject instanceof Step)) {
                throw new EngineException("Sequence already contains a step named \"" + name + "\".", owsne);
            }
        }
        NodeList childNodes = node.getChildNodes();
        int len = childNodes.getLength();
        Node childNode;
        String childNodeName;
        for (int i = 0; i < len; i++) {
            childNode = childNodes.item(i);
            if (childNode.getNodeType() != Node.ELEMENT_NODE) {
                continue;
            }
            childNodeName = childNode.getNodeName();
            if (!(childNodeName.equalsIgnoreCase("property")) && !(childNodeName.equalsIgnoreCase("handlers")) && !(childNodeName.equalsIgnoreCase("wsdltype")) && !(childNodeName.equalsIgnoreCase("docdata")) && !(childNodeName.equalsIgnoreCase("dnd"))) {
                paste(childNode, databaseObject, bChangeName);
            }
        }
        // For update of sources which reference this step
        if (databaseObject instanceof Step) {
            pastedSteps.put(String.valueOf(oldPriority), (Step) databaseObject);
        }
        // For update of sources which reference this mobile component
        if (databaseObject instanceof com.twinsoft.convertigo.beans.mobile.components.MobileComponent) {
            if (databaseObject instanceof com.twinsoft.convertigo.beans.mobile.components.IAction || databaseObject instanceof com.twinsoft.convertigo.beans.mobile.components.UIActionStack || databaseObject instanceof com.twinsoft.convertigo.beans.mobile.components.UIControlDirective || databaseObject instanceof com.twinsoft.convertigo.beans.mobile.components.UIForm || databaseObject instanceof com.twinsoft.convertigo.beans.mobile.components.UISharedComponent) {
                pastedComponents.put(String.valueOf(oldPriority), GenericUtils.cast(databaseObject));
            }
        } else if (databaseObject instanceof com.twinsoft.convertigo.beans.ngx.components.MobileComponent) {
            if (databaseObject instanceof com.twinsoft.convertigo.beans.ngx.components.IAction || databaseObject instanceof com.twinsoft.convertigo.beans.ngx.components.UIActionStack || databaseObject instanceof com.twinsoft.convertigo.beans.ngx.components.UIControlDirective || databaseObject instanceof com.twinsoft.convertigo.beans.ngx.components.UIForm || databaseObject instanceof com.twinsoft.convertigo.beans.ngx.components.UISharedComponent) {
                pastedComponents.put(String.valueOf(oldPriority), GenericUtils.cast(databaseObject));
            }
        }
        // needed
        databaseObject.isImporting = false;
        databaseObject.isSubLoaded = true;
        return databaseObject;
    } else if (object instanceof JsonData) {
        if (parentDatabaseObject instanceof com.twinsoft.convertigo.beans.mobile.components.MobileComponent) {
            if (parentDatabaseObject instanceof com.twinsoft.convertigo.beans.mobile.components.UIPageEvent || parentDatabaseObject instanceof com.twinsoft.convertigo.beans.mobile.components.UIAppEvent || parentDatabaseObject instanceof com.twinsoft.convertigo.beans.mobile.components.UIDynamicAction || parentDatabaseObject instanceof com.twinsoft.convertigo.beans.mobile.components.UIActionStack) {
                JsonData jsonData = (JsonData) object;
                JSONObject json = jsonData.getData();
                if (json.has("qname")) {
                    try {
                        com.twinsoft.convertigo.beans.mobile.components.UIComponent uiComponent = GenericUtils.cast(parentDatabaseObject);
                        DatabaseObject call = com.twinsoft.convertigo.beans.mobile.components.dynamic.ComponentManager.createBean(com.twinsoft.convertigo.beans.mobile.components.dynamic.ComponentManager.getComponentByName("FullSyncViewAction"));
                        if (call != null && call instanceof com.twinsoft.convertigo.beans.mobile.components.UIDynamicAction) {
                            com.twinsoft.convertigo.beans.mobile.components.UIDynamicAction dynAction = GenericUtils.cast(call);
                            com.twinsoft.convertigo.beans.mobile.components.dynamic.IonBean ionBean = dynAction.getIonBean();
                            if (ionBean != null && ionBean.hasProperty("fsview")) {
                                call.bNew = true;
                                call.hasChanged = true;
                                ionBean.setPropertyValue("fsview", new com.twinsoft.convertigo.beans.mobile.components.MobileSmartSourceType(json.getString("qname")));
                                uiComponent.add(call);
                                uiComponent.hasChanged = true;
                            }
                            return call;
                        }
                    } catch (JSONException e) {
                        Engine.logStudio.warn("Failed to create a FullSyncViewAction", e);
                    }
                }
            }
        } else if (parentDatabaseObject instanceof com.twinsoft.convertigo.beans.ngx.components.MobileComponent) {
            if (parentDatabaseObject instanceof com.twinsoft.convertigo.beans.ngx.components.UIPageEvent || parentDatabaseObject instanceof com.twinsoft.convertigo.beans.ngx.components.UIAppEvent || parentDatabaseObject instanceof com.twinsoft.convertigo.beans.ngx.components.UIDynamicAction || parentDatabaseObject instanceof com.twinsoft.convertigo.beans.ngx.components.UIActionStack) {
                JsonData jsonData = (JsonData) object;
                JSONObject json = jsonData.getData();
                if (json.has("qname")) {
                    try {
                        com.twinsoft.convertigo.beans.ngx.components.UIComponent uiComponent = GenericUtils.cast(parentDatabaseObject);
                        DatabaseObject call = com.twinsoft.convertigo.beans.ngx.components.dynamic.ComponentManager.createBean(com.twinsoft.convertigo.beans.ngx.components.dynamic.ComponentManager.getComponentByName("FullSyncViewAction"));
                        if (call != null && call instanceof com.twinsoft.convertigo.beans.ngx.components.UIDynamicAction) {
                            com.twinsoft.convertigo.beans.ngx.components.UIDynamicAction dynAction = GenericUtils.cast(call);
                            com.twinsoft.convertigo.beans.ngx.components.dynamic.IonBean ionBean = dynAction.getIonBean();
                            if (ionBean != null && ionBean.hasProperty("fsview")) {
                                call.bNew = true;
                                call.hasChanged = true;
                                ionBean.setPropertyValue("fsview", new com.twinsoft.convertigo.beans.ngx.components.MobileSmartSourceType(json.getString("qname")));
                                uiComponent.add(call);
                                uiComponent.hasChanged = true;
                            }
                            return call;
                        }
                    } catch (JSONException e) {
                        Engine.logStudio.warn("Failed to create a FullSyncViewAction", e);
                    }
                }
            }
        }
    }
    return null;
}
Also used : BlockFactory(com.twinsoft.convertigo.beans.core.BlockFactory) JavelinScreenClass(com.twinsoft.convertigo.beans.screenclasses.JavelinScreenClass) ScreenClass(com.twinsoft.convertigo.beans.core.ScreenClass) Node(org.w3c.dom.Node) EngineException(com.twinsoft.convertigo.engine.EngineException) StepWithExpressions(com.twinsoft.convertigo.beans.core.StepWithExpressions) HTTPStatement(com.twinsoft.convertigo.beans.statements.HTTPStatement) FunctionStatement(com.twinsoft.convertigo.beans.statements.FunctionStatement) StatementWithExpressions(com.twinsoft.convertigo.beans.core.StatementWithExpressions) DatabaseObject(com.twinsoft.convertigo.beans.core.DatabaseObject) JavelinScreenClass(com.twinsoft.convertigo.beans.screenclasses.JavelinScreenClass) NodeList(org.w3c.dom.NodeList) Sequence(com.twinsoft.convertigo.beans.core.Sequence) Project(com.twinsoft.convertigo.beans.core.Project) Transaction(com.twinsoft.convertigo.beans.core.Transaction) HtmlTransaction(com.twinsoft.convertigo.beans.transactions.HtmlTransaction) JSONObject(org.codehaus.jettison.json.JSONObject) RequestableStep(com.twinsoft.convertigo.beans.core.RequestableStep) IContainerOrdered(com.twinsoft.convertigo.beans.core.IContainerOrdered) IPropertyTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.IPropertyTreeObject) RequestableObject(com.twinsoft.convertigo.beans.core.RequestableObject) DatabaseObject(com.twinsoft.convertigo.beans.core.DatabaseObject) JSONObject(org.codehaus.jettison.json.JSONObject) TreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.TreeObject) DatabaseObjectTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.DatabaseObjectTreeObject) IDesignTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.IDesignTreeObject) MobileObject(com.twinsoft.convertigo.beans.core.MobileObject) Connector(com.twinsoft.convertigo.beans.core.Connector) Variable(com.twinsoft.convertigo.beans.core.Variable) ExtractionRule(com.twinsoft.convertigo.beans.core.ExtractionRule) WalkHelper(com.twinsoft.convertigo.engine.helpers.WalkHelper) Criteria(com.twinsoft.convertigo.beans.core.Criteria) Step(com.twinsoft.convertigo.beans.core.Step) ElseStep(com.twinsoft.convertigo.beans.steps.ElseStep) RequestableStep(com.twinsoft.convertigo.beans.core.RequestableStep) ThenStep(com.twinsoft.convertigo.beans.steps.ThenStep) ElseStatement(com.twinsoft.convertigo.beans.statements.ElseStatement) FunctionStatement(com.twinsoft.convertigo.beans.statements.FunctionStatement) HTTPStatement(com.twinsoft.convertigo.beans.statements.HTTPStatement) Statement(com.twinsoft.convertigo.beans.core.Statement) ThenStatement(com.twinsoft.convertigo.beans.statements.ThenStatement) HtmlTransaction(com.twinsoft.convertigo.beans.transactions.HtmlTransaction) JSONException(org.codehaus.jettison.json.JSONException) SAXException(org.xml.sax.SAXException) EngineException(com.twinsoft.convertigo.engine.EngineException) ConvertigoException(com.twinsoft.convertigo.engine.ConvertigoException) IOException(java.io.IOException) JSONException(org.codehaus.jettison.json.JSONException) InvalidOperationException(com.twinsoft.convertigo.engine.InvalidOperationException) ObjectWithSameNameException(com.twinsoft.convertigo.engine.ObjectWithSameNameException) ObjectWithSameNameException(com.twinsoft.convertigo.engine.ObjectWithSameNameException) TestCase(com.twinsoft.convertigo.beans.core.TestCase) TransactionWithVariables(com.twinsoft.convertigo.beans.core.TransactionWithVariables) Sheet(com.twinsoft.convertigo.beans.core.Sheet)

Aggregations

TransactionWithVariables (com.twinsoft.convertigo.beans.core.TransactionWithVariables)10 Sequence (com.twinsoft.convertigo.beans.core.Sequence)8 DatabaseObject (com.twinsoft.convertigo.beans.core.DatabaseObject)6 Transaction (com.twinsoft.convertigo.beans.core.Transaction)6 Variable (com.twinsoft.convertigo.beans.core.Variable)6 RequestableVariable (com.twinsoft.convertigo.beans.variables.RequestableVariable)5 TreeObject (com.twinsoft.convertigo.eclipse.views.projectexplorer.model.TreeObject)5 EngineException (com.twinsoft.convertigo.engine.EngineException)5 Connector (com.twinsoft.convertigo.beans.core.Connector)4 TestCase (com.twinsoft.convertigo.beans.core.TestCase)4 DatabaseObjectTreeObject (com.twinsoft.convertigo.eclipse.views.projectexplorer.model.DatabaseObjectTreeObject)4 IOException (java.io.IOException)4 Project (com.twinsoft.convertigo.beans.core.Project)3 RequestableObject (com.twinsoft.convertigo.beans.core.RequestableObject)3 RequestableStep (com.twinsoft.convertigo.beans.core.RequestableStep)3 Sheet (com.twinsoft.convertigo.beans.core.Sheet)3 HttpConnector (com.twinsoft.convertigo.beans.connectors.HttpConnector)2 Criteria (com.twinsoft.convertigo.beans.core.Criteria)2 ExtractionRule (com.twinsoft.convertigo.beans.core.ExtractionRule)2 ScreenClass (com.twinsoft.convertigo.beans.core.ScreenClass)2