Search in sources :

Example 6 with RequestableObject

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

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

the class TestCaseExecuteSelectedAction 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();
            if ((treeObject != null) && (treeObject instanceof TestCaseTreeObject)) {
                TestCase testCase = (TestCase) treeObject.getObject();
                ProjectTreeObject projectTreeObject = treeObject.getProjectTreeObject();
                RequestableObject requestable = (RequestableObject) testCase.getParent();
                if (requestable instanceof Transaction) {
                    TransactionTreeObject transactionTreeObject = (TransactionTreeObject) treeObject.getParent().getParent();
                    transactionTreeObject.getConnectorTreeObject().openConnectorEditor();
                    Transaction transaction = (Transaction) testCase.getParent();
                    Connector connector = (Connector) transaction.getParent();
                    ConnectorEditor connectorEditor = projectTreeObject.getConnectorEditor(connector);
                    if (connectorEditor != null) {
                        getActivePage().activate(connectorEditor);
                        connectorEditor.getDocument(transaction.getName(), testCase.getName(), false);
                    }
                }
                if (requestable instanceof Sequence) {
                    SequenceTreeObject sequenceTreeObject = (SequenceTreeObject) treeObject.getParent().getParent();
                    new SequenceExecuteSelectedAction().openEditors(explorerView, sequenceTreeObject);
                    Sequence sequence = (Sequence) testCase.getParent();
                    SequenceEditor sequenceEditor = projectTreeObject.getSequenceEditor(sequence);
                    if (sequenceEditor != null) {
                        getActivePage().activate(sequenceEditor);
                        sequenceEditor.getDocument(sequence.getName(), testCase.getName(), false);
                    }
                }
            }
        }
    } catch (Throwable e) {
        ConvertigoPlugin.logException(e, "Unable to execute the selected test case!");
    } finally {
        shell.setCursor(null);
        waitCursor.dispose();
    }
}
Also used : TransactionTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.TransactionTreeObject) Connector(com.twinsoft.convertigo.beans.core.Connector) ProjectExplorerView(com.twinsoft.convertigo.eclipse.views.projectexplorer.ProjectExplorerView) RequestableObject(com.twinsoft.convertigo.beans.core.RequestableObject) SequenceTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.SequenceTreeObject) Sequence(com.twinsoft.convertigo.beans.core.Sequence) SequenceEditor(com.twinsoft.convertigo.eclipse.editors.sequence.SequenceEditor) Cursor(org.eclipse.swt.graphics.Cursor) ConnectorEditor(com.twinsoft.convertigo.eclipse.editors.connector.ConnectorEditor) TestCaseTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.TestCaseTreeObject) Shell(org.eclipse.swt.widgets.Shell) Transaction(com.twinsoft.convertigo.beans.core.Transaction) TestCase(com.twinsoft.convertigo.beans.core.TestCase) TestCaseTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.TestCaseTreeObject) SequenceTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.SequenceTreeObject) TreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.TreeObject) ProjectTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.ProjectTreeObject) TransactionTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.TransactionTreeObject) ProjectTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.ProjectTreeObject) Display(org.eclipse.swt.widgets.Display)

Example 8 with RequestableObject

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

the class TestCaseImportRequestableVariablesAction 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 TestCase)) {
                TestCase testCase = (TestCase) databaseObject;
                testCase.importRequestableVariables((RequestableObject) testCase.getParent());
                if (testCase.hasChanged) {
                    explorerView.reloadTreeObject(treeObject);
                    StructuredSelection structuredSelection = new StructuredSelection(treeObject);
                    ConvertigoPlugin.getDefault().getPropertiesView().selectionChanged((IWorkbenchPart) explorerView, structuredSelection);
                }
            }
        }
    } catch (Throwable e) {
        ConvertigoPlugin.logException(e, "Unable to add requestable variables to test case!");
    } finally {
        shell.setCursor(null);
        waitCursor.dispose();
    }
}
Also used : Shell(org.eclipse.swt.widgets.Shell) ProjectExplorerView(com.twinsoft.convertigo.eclipse.views.projectexplorer.ProjectExplorerView) TestCase(com.twinsoft.convertigo.beans.core.TestCase) StructuredSelection(org.eclipse.jface.viewers.StructuredSelection) TreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.TreeObject) RequestableObject(com.twinsoft.convertigo.beans.core.RequestableObject) TreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.TreeObject) Cursor(org.eclipse.swt.graphics.Cursor) Display(org.eclipse.swt.widgets.Display)

Example 9 with RequestableObject

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

Example 10 with RequestableObject

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

the class TreeDropAdapter method move.

private boolean move(Node node, TreeObject targetTreeObject) throws EngineException {
    if (targetTreeObject instanceof DatabaseObjectTreeObject) {
        DatabaseObject parent = ((DatabaseObjectTreeObject) targetTreeObject).getObject();
        DatabaseObject databaseObject = paste(node, null, true);
        Element element = (Element) ((Element) node).getElementsByTagName("dnd").item(0);
        // SEQUENCER
        if (parent instanceof Sequence || parent instanceof StepWithExpressions) {
            ;
        } else // URLMAPPER
        if (parent instanceof UrlMappingOperation) {
            // Set associated requestable
            if (databaseObject instanceof RequestableObject) {
                String dboQName = "";
                if (databaseObject instanceof Sequence) {
                    dboQName = ((Element) element.getElementsByTagName("project").item(0)).getAttribute("name") + "." + databaseObject.getName();
                } else if (databaseObject instanceof Transaction) {
                    dboQName = ((Element) element.getElementsByTagName("project").item(0)).getAttribute("name") + "." + ((Element) element.getElementsByTagName("connector").item(0)).getAttribute("name") + "." + databaseObject.getName();
                }
                UrlMappingOperation operation = (UrlMappingOperation) parent;
                operation.setTargetRequestable(dboQName);
                if (operation.getComment().isEmpty()) {
                    operation.setComment(databaseObject.getComment());
                }
                operation.hasChanged = true;
                return true;
            }
        } else if (parent instanceof UrlMappingParameter) {
            // Set associated mapped variable for parameter
            if (databaseObject instanceof RequestableVariable) {
                RequestableVariable variable = (RequestableVariable) databaseObject;
                UrlMappingParameter parameter = (UrlMappingParameter) parent;
                parameter.setMappedVariableName(variable.getName());
                parameter.hasChanged = true;
                return true;
            }
        }
    }
    return false;
}
Also used : DatabaseObjectTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.DatabaseObjectTreeObject) UrlMappingOperation(com.twinsoft.convertigo.beans.core.UrlMappingOperation) RequestableObject(com.twinsoft.convertigo.beans.core.RequestableObject) Transaction(com.twinsoft.convertigo.beans.core.Transaction) HtmlTransaction(com.twinsoft.convertigo.beans.transactions.HtmlTransaction) UrlMappingParameter(com.twinsoft.convertigo.beans.core.UrlMappingParameter) Element(org.w3c.dom.Element) StepWithExpressions(com.twinsoft.convertigo.beans.core.StepWithExpressions) DatabaseObject(com.twinsoft.convertigo.beans.core.DatabaseObject) RequestableVariable(com.twinsoft.convertigo.beans.variables.RequestableVariable) Sequence(com.twinsoft.convertigo.beans.core.Sequence)

Aggregations

RequestableObject (com.twinsoft.convertigo.beans.core.RequestableObject)18 DatabaseObject (com.twinsoft.convertigo.beans.core.DatabaseObject)10 Sequence (com.twinsoft.convertigo.beans.core.Sequence)8 Transaction (com.twinsoft.convertigo.beans.core.Transaction)8 Project (com.twinsoft.convertigo.beans.core.Project)7 Connector (com.twinsoft.convertigo.beans.core.Connector)6 TreeObject (com.twinsoft.convertigo.eclipse.views.projectexplorer.model.TreeObject)6 JSONException (org.codehaus.jettison.json.JSONException)6 Document (org.w3c.dom.Document)6 Element (org.w3c.dom.Element)6 Variable (com.twinsoft.convertigo.beans.core.Variable)4 DesignDocument (com.twinsoft.convertigo.beans.couchdb.DesignDocument)4 RequestableVariable (com.twinsoft.convertigo.beans.variables.RequestableVariable)4 ConnectorEditor (com.twinsoft.convertigo.eclipse.editors.connector.ConnectorEditor)4 ProjectExplorerView (com.twinsoft.convertigo.eclipse.views.projectexplorer.ProjectExplorerView)4 DatabaseObjectTreeObject (com.twinsoft.convertigo.eclipse.views.projectexplorer.model.DatabaseObjectTreeObject)4 IOException (java.io.IOException)4 XmlSchemaObject (org.apache.ws.commons.schema.XmlSchemaObject)4 JSONObject (org.codehaus.jettison.json.JSONObject)4 Cursor (org.eclipse.swt.graphics.Cursor)4