Search in sources :

Example 1 with StepVariable

use of com.twinsoft.convertigo.beans.variables.StepVariable 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 StepVariable

use of com.twinsoft.convertigo.beans.variables.StepVariable in project convertigo by convertigo.

the class Migration5_0_0 method newVariable.

private static Variable newVariable(String classname, XMLVector<?> xmlv, int index) throws EngineException {
    Class<? extends DatabaseObject> beanClass;
    try {
        beanClass = GenericUtils.cast(Class.forName(classname));
        if (AbstractHttpTransaction.class.isAssignableFrom(beanClass)) {
            Boolean isMulti = (Boolean) xmlv.get(4);
            RequestableHttpVariable variable;
            variable = (isMulti ? new RequestableHttpMultiValuedVariable() : new RequestableHttpVariable());
            variable.setName((String) xmlv.get(0));
            variable.setDescription((String) xmlv.get(1));
            variable.setValueOrNull(xmlv.get(2));
            variable.setWsdl(((Boolean) xmlv.get(3)));
            variable.setPersonalizable(((Boolean) xmlv.get(5)));
            variable.setCachedKey(((Boolean) xmlv.get(6)));
            variable.setHttpMethod((String) xmlv.get(7));
            variable.setHttpName((String) xmlv.get(8));
            variable.bNew = true;
            variable.hasChanged = true;
            return variable;
        } else if (TransactionWithVariables.class.isAssignableFrom(beanClass) || Sequence.class.isAssignableFrom(beanClass)) {
            Boolean isMulti = (Boolean) xmlv.get(4);
            RequestableVariable variable = (isMulti ? new RequestableMultiValuedVariable() : new RequestableVariable());
            variable.setName((String) xmlv.get(0));
            variable.setDescription((String) xmlv.get(1));
            variable.setValueOrNull(xmlv.get(2));
            variable.setWsdl(((Boolean) xmlv.get(3)));
            variable.setPersonalizable(((Boolean) xmlv.get(5)));
            variable.setCachedKey(((Boolean) xmlv.get(6)));
            variable.bNew = true;
            variable.hasChanged = true;
            return variable;
        } else if (RequestableStep.class.isAssignableFrom(beanClass)) {
            StepVariable variable = new StepVariable();
            variable.setName((String) xmlv.get(0));
            variable.setDescription((String) xmlv.get(1));
            variable.setSourceDefinition(GenericUtils.<XMLVector<String>>cast(xmlv.get(2)));
            variable.setValueOrNull(xmlv.get(3));
            variable.bNew = true;
            variable.hasChanged = true;
            return variable;
        } else if (com.twinsoft.convertigo.beans.statements.HTTPStatement.class.isAssignableFrom(beanClass)) {
            Boolean isMulti = (Boolean) xmlv.get(3);
            HttpStatementVariable variable;
            variable = (isMulti ? new HttpStatementMultiValuedVariable() : new HttpStatementVariable());
            try {
                variable.setName((String) xmlv.get(0));
            } catch (Exception e) {
                variable.setName("variable" + index);
                Engine.logDatabaseObjectManager.warn("[Migration 4.6.0] For variable at index " + index + ", empty name has been replaced by 'variable" + index + "'!");
            }
            variable.setDescription((String) xmlv.get(1));
            variable.setValueOrNull(xmlv.get(2));
            variable.setHttpMethod((String) xmlv.get(4));
            variable.setHttpName((String) xmlv.get(5));
            variable.bNew = true;
            variable.hasChanged = true;
            return variable;
        } else {
            throw new EngineException("[Migration 4.6.0] Unsupported classname \"" + classname + "\"");
        }
    } catch (Exception e) {
        throw new EngineException("[Migration 4.6.0] Unable to create variable bean", e);
    }
}
Also used : RequestableHttpVariable(com.twinsoft.convertigo.beans.variables.RequestableHttpVariable) HttpStatementMultiValuedVariable(com.twinsoft.convertigo.beans.variables.HttpStatementMultiValuedVariable) EngineException(com.twinsoft.convertigo.engine.EngineException) RequestableVariable(com.twinsoft.convertigo.beans.variables.RequestableVariable) StepVariable(com.twinsoft.convertigo.beans.variables.StepVariable) HttpStatementVariable(com.twinsoft.convertigo.beans.variables.HttpStatementVariable) EngineException(com.twinsoft.convertigo.engine.EngineException) RequestableHttpMultiValuedVariable(com.twinsoft.convertigo.beans.variables.RequestableHttpMultiValuedVariable) RequestableMultiValuedVariable(com.twinsoft.convertigo.beans.variables.RequestableMultiValuedVariable)

Example 3 with StepVariable

use of com.twinsoft.convertigo.beans.variables.StepVariable in project convertigo by convertigo.

the class ProjectExplorerView method makeActions.

private void makeActions() {
    tracePlayAction = new TracePlayAction();
    doubleClickAction = new Action() {

        @Override
        public void run() {
            IStructuredSelection selection = (IStructuredSelection) viewer.getSelection();
            TreeObject treeObject = (TreeObject) selection.getFirstElement();
            if (treeObject instanceof UnloadedProjectTreeObject) {
                loadProject((UnloadedProjectTreeObject) treeObject);
            } else if (treeObject instanceof ConnectorTreeObject) {
                ((ConnectorTreeObject) treeObject).launchEditor();
            } else if (treeObject instanceof SequenceTreeObject) {
                ((SequenceTreeObject) treeObject).launchEditor();
            } else if (treeObject instanceof StepTreeObject) {
                showStepInPickerAction.run();
                if (treeObject instanceof IEditableTreeObject) {
                    ((IEditableTreeObject) treeObject).launchEditor(null);
                }
            } else if (treeObject instanceof VariableTreeObject2) {
                if (treeObject.getObject() instanceof StepVariable) {
                    showStepInPickerAction.run();
                }
            } else if (treeObject instanceof IEditableTreeObject) {
                ((IEditableTreeObject) treeObject).launchEditor(null);
            } else if (treeObject instanceof TraceTreeObject) {
                tracePlayAction.run();
            }
        }
    };
    undoAction = new UndoAction();
    redoAction = new RedoAction();
    copyAction = new ClipboardCopyAction();
    cutAction = new ClipboardCutAction();
    pasteAction = new ClipboardPasteAction();
    deleteDatabaseObjectAction = new DatabaseObjectDeleteAction();
    deletePropertyTableRowAction = new DeletePropertyTableRowAction();
    deletePropertyTableColumnAction = new DeletePropertyTableColumnAction();
    projectExplorerSaveAllAction = new ProjectExplorerSaveAllAction();
    decreasePriorityAction = new DatabaseObjectDecreasePriorityAction();
    increasePriorityAction = new DatabaseObjectIncreasePriorityAction();
    executeTransaction = new TransactionExecuteSelectedAction();
    executeDefaultTransaction = new TransactionExecuteDefaultAction();
    transactionEditHandlersAction = new TransactionEditHandlersAction();
    executeSequence = new SequenceExecuteSelectedAction();
    executeTestCase = new TestCaseExecuteSelectedAction();
    showStepInPickerAction = new ShowStepInPickerAction();
}
Also used : DatabaseObjectDeleteAction(com.twinsoft.convertigo.eclipse.popup.actions.DatabaseObjectDeleteAction) DeletePropertyTableRowAction(com.twinsoft.convertigo.eclipse.popup.actions.DeletePropertyTableRowAction) DatabaseObjectDecreasePriorityAction(com.twinsoft.convertigo.eclipse.popup.actions.DatabaseObjectDecreasePriorityAction) TestCaseExecuteSelectedAction(com.twinsoft.convertigo.eclipse.popup.actions.TestCaseExecuteSelectedAction) TransactionEditHandlersAction(com.twinsoft.convertigo.eclipse.popup.actions.TransactionEditHandlersAction) Action(org.eclipse.jface.action.Action) TracePlayAction(com.twinsoft.convertigo.eclipse.popup.actions.TracePlayAction) TransactionExecuteSelectedAction(com.twinsoft.convertigo.eclipse.popup.actions.TransactionExecuteSelectedAction) ClipboardCopyAction(com.twinsoft.convertigo.eclipse.popup.actions.ClipboardCopyAction) DeletePropertyTableColumnAction(com.twinsoft.convertigo.eclipse.popup.actions.DeletePropertyTableColumnAction) ClipboardPasteAction(com.twinsoft.convertigo.eclipse.popup.actions.ClipboardPasteAction) SequenceExecuteSelectedAction(com.twinsoft.convertigo.eclipse.popup.actions.SequenceExecuteSelectedAction) DatabaseObjectIncreasePriorityAction(com.twinsoft.convertigo.eclipse.popup.actions.DatabaseObjectIncreasePriorityAction) ShowStepInPickerAction(com.twinsoft.convertigo.eclipse.popup.actions.ShowStepInPickerAction) ClipboardCutAction(com.twinsoft.convertigo.eclipse.popup.actions.ClipboardCutAction) UndoAction(com.twinsoft.convertigo.eclipse.popup.actions.UndoAction) RedoAction(com.twinsoft.convertigo.eclipse.popup.actions.RedoAction) ProjectExplorerSaveAllAction(com.twinsoft.convertigo.eclipse.actions.ProjectExplorerSaveAllAction) TransactionExecuteDefaultAction(com.twinsoft.convertigo.eclipse.popup.actions.TransactionExecuteDefaultAction) TestCaseExecuteSelectedAction(com.twinsoft.convertigo.eclipse.popup.actions.TestCaseExecuteSelectedAction) StepTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.StepTreeObject) DatabaseObjectIncreasePriorityAction(com.twinsoft.convertigo.eclipse.popup.actions.DatabaseObjectIncreasePriorityAction) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) StepVariable(com.twinsoft.convertigo.beans.variables.StepVariable) ClipboardPasteAction(com.twinsoft.convertigo.eclipse.popup.actions.ClipboardPasteAction) DatabaseObjectDeleteAction(com.twinsoft.convertigo.eclipse.popup.actions.DatabaseObjectDeleteAction) DeletePropertyTableRowAction(com.twinsoft.convertigo.eclipse.popup.actions.DeletePropertyTableRowAction) ClipboardCopyAction(com.twinsoft.convertigo.eclipse.popup.actions.ClipboardCopyAction) SequenceExecuteSelectedAction(com.twinsoft.convertigo.eclipse.popup.actions.SequenceExecuteSelectedAction) RedoAction(com.twinsoft.convertigo.eclipse.popup.actions.RedoAction) VariableTreeObject2(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.VariableTreeObject2) TransactionExecuteSelectedAction(com.twinsoft.convertigo.eclipse.popup.actions.TransactionExecuteSelectedAction) DatabaseObjectDecreasePriorityAction(com.twinsoft.convertigo.eclipse.popup.actions.DatabaseObjectDecreasePriorityAction) SequenceTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.SequenceTreeObject) TransactionExecuteDefaultAction(com.twinsoft.convertigo.eclipse.popup.actions.TransactionExecuteDefaultAction) ProjectExplorerSaveAllAction(com.twinsoft.convertigo.eclipse.actions.ProjectExplorerSaveAllAction) TracePlayAction(com.twinsoft.convertigo.eclipse.popup.actions.TracePlayAction) IEditableTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.IEditableTreeObject) ShowStepInPickerAction(com.twinsoft.convertigo.eclipse.popup.actions.ShowStepInPickerAction) ConnectorTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.ConnectorTreeObject) ClipboardCutAction(com.twinsoft.convertigo.eclipse.popup.actions.ClipboardCutAction) UnloadedProjectTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.UnloadedProjectTreeObject) DeletePropertyTableColumnAction(com.twinsoft.convertigo.eclipse.popup.actions.DeletePropertyTableColumnAction) TransactionEditHandlersAction(com.twinsoft.convertigo.eclipse.popup.actions.TransactionEditHandlersAction) UrlMappingParameterTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.UrlMappingParameterTreeObject) MobileApplicationTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.MobileApplicationTreeObject) IClosableTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.IClosableTreeObject) XMLRecordDescriptionTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.XMLRecordDescriptionTreeObject) DesignDocumentValidateTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.DesignDocumentValidateTreeObject) UrlMappingTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.UrlMappingTreeObject) DesignDocumentUpdateTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.DesignDocumentUpdateTreeObject) DesignDocumentTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.DesignDocumentTreeObject) MobileApplicationComponentTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.MobileApplicationComponentTreeObject) UrlMappingOperationTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.UrlMappingOperationTreeObject) ReferenceTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.ReferenceTreeObject) HandlersDeclarationTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.HandlersDeclarationTreeObject) UrlMappingResponseTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.UrlMappingResponseTreeObject) UnloadedProjectTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.UnloadedProjectTreeObject) NgxUIComponentTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.NgxUIComponentTreeObject) MobileUIComponentTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.MobileUIComponentTreeObject) CriteriaTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.CriteriaTreeObject) IPropertyTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.IPropertyTreeObject) UrlAuthenticationTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.UrlAuthenticationTreeObject) SequenceTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.SequenceTreeObject) MobileRouteActionComponentTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.MobileRouteActionComponentTreeObject) ListenerTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.ListenerTreeObject) TransactionTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.TransactionTreeObject) PropertyTableTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.PropertyTableTreeObject) FullSyncListenerTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.FullSyncListenerTreeObject) DatabaseObjectTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.DatabaseObjectTreeObject) ConnectorTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.ConnectorTreeObject) IDesignTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.IDesignTreeObject) ScreenClassTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.ScreenClassTreeObject) StatementTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.StatementTreeObject) NgxApplicationComponentTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.NgxApplicationComponentTreeObject) MobileRouteEventComponentTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.MobileRouteEventComponentTreeObject) PropertyTableRowTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.PropertyTableRowTreeObject) IEditableTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.IEditableTreeObject) XMLTableDescriptionTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.XMLTableDescriptionTreeObject) ProjectTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.ProjectTreeObject) DesignDocumentViewTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.DesignDocumentViewTreeObject) TemplateTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.TemplateTreeObject) TestCaseTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.TestCaseTreeObject) ObjectsFolderTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.ObjectsFolderTreeObject) PropertyTableColumnTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.PropertyTableColumnTreeObject) DesignDocumentFilterTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.DesignDocumentFilterTreeObject) VariableTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.VariableTreeObject) DesignDocumentFunctionTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.DesignDocumentFunctionTreeObject) MobilePlatformTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.MobilePlatformTreeObject) ExtractionRuleTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.ExtractionRuleTreeObject) MobileRouteComponentTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.MobileRouteComponentTreeObject) SheetTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.SheetTreeObject) UrlMapperTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.UrlMapperTreeObject) StepTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.StepTreeObject) NgxPageComponentTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.NgxPageComponentTreeObject) MobilePageComponentTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.MobilePageComponentTreeObject) TreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.TreeObject) TraceTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.TraceTreeObject) DocumentTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.DocumentTreeObject) TraceTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.TraceTreeObject) UndoAction(com.twinsoft.convertigo.eclipse.popup.actions.UndoAction)

Example 4 with StepVariable

use of com.twinsoft.convertigo.beans.variables.StepVariable in project convertigo by convertigo.

the class RequestableStep method getPostQuery.

protected String getPostQuery(Scriptable scope) throws EngineException {
    StepVariable stepVariable;
    String postQuery = "";
    int len = numberOfVariables();
    String variableName;
    int variableVisibility;
    for (int i = 0; i < len; i++) {
        stepVariable = (StepVariable) getVariable(i);
        variableName = stepVariable.getName();
        variableVisibility = stepVariable.getVisibility();
        try {
            // Source value
            Object variableValue = stepVariable.getSourceValue();
            if (variableValue instanceof NodeList && ((NodeList) variableValue).getLength() == 0) {
                if (getProject().isStrictMode() && !stepVariable.isMultiValued()) {
                    // override with null (fix #24)
                    variableValue = null;
                }
            }
            if (variableValue != null) {
                Engine.logBeans.trace("(RequestableStep) found value from source: " + Visibility.Logs.printValue(variableVisibility, variableValue));
            }
            // Otherwise Scope parameter
            if (variableValue == null) {
                Scriptable searchScope = scope;
                while ((variableValue == null) && (searchScope != null)) {
                    variableValue = searchScope.get(variableName, searchScope);
                    Engine.logBeans.trace("(RequestableStep) found value from scope: " + Visibility.Logs.printValue(variableVisibility, variableValue));
                    if (variableValue instanceof Undefined) {
                        variableValue = null;
                    } else if (variableValue instanceof UniqueTag && ((UniqueTag) variableValue).equals(UniqueTag.NOT_FOUND)) {
                        variableValue = null;
                    } else if (variableValue instanceof NativeJavaObject) {
                        variableValue = ((NativeJavaObject) variableValue).unwrap();
                    }
                    if (variableValue == null) {
                        // looks up in parent's scope
                        searchScope = searchScope.getParentScope();
                    }
                }
            }
            // Otherwise context parameter
            if (variableValue == null) {
                variableValue = (sequence.context.get(variableName) == null ? null : sequence.context.get(variableName));
                if (variableValue != null)
                    Engine.logBeans.trace("(RequestableStep) found value from context: " + Visibility.Logs.printValue(variableVisibility, variableValue));
            }
            // Otherwise sequence step default value
            if (variableValue == null) {
                variableValue = getVariableValue(variableName);
                if (variableValue != null)
                    Engine.logBeans.trace("(RequestableStep) found default value from step: " + Visibility.Logs.printValue(variableVisibility, variableValue));
            }
            // otherwise value not found
            if (variableValue == null) {
                Engine.logBeans.trace("(RequestableStep) Did not find any value for \"" + variableName + "\", ignore it");
            } else {
                if (bInternalInvoke) {
                    if (stepVariable.isMultiValued() && getProject().isStrictMode() && variableValue instanceof NodeList) {
                        String subXPath = ((StepMultiValuedVariable) stepVariable).getSubXPath();
                        if (subXPath.isEmpty()) {
                            variableValue = XMLUtils.toNodeArray((NodeList) variableValue);
                        } else {
                            TwsCachedXPathAPI xpathAPI = new TwsCachedXPathAPI(this.getProject());
                            NodeList nodeList = (NodeList) variableValue;
                            NodeList[] nodeLists = new NodeList[nodeList.getLength()];
                            for (int j = 0; j < nodeLists.length; j++) {
                                try {
                                    nodeLists[j] = xpathAPI.selectNodeList(nodeList.item(j), subXPath);
                                } catch (TransformerException e) {
                                    Engine.logBeans.debug("(RequestableStep) Failed to select subXpath", e);
                                }
                            }
                            variableValue = nodeLists;
                        }
                    }
                    request.put(variableName, variableValue);
                } else {
                    String parameterValue;
                    if (variableValue instanceof NodeList) {
                        NodeList list = (NodeList) variableValue;
                        if (list != null) {
                            if (list.getLength() == 0) {
                                // Specifies here empty multivalued variable (HTTP invoque only)
                                postQuery = addParamToPostQuery(variableName, "_empty_array_", postQuery);
                            } else {
                                for (int j = 0; j < list.getLength(); j++) {
                                    parameterValue = getNodeValue(list.item(j));
                                    postQuery = addParamToPostQuery(variableName, parameterValue, postQuery);
                                }
                            }
                        }
                    } else if (variableValue instanceof NativeJavaArray) {
                        Object object = ((NativeJavaArray) variableValue).unwrap();
                        List<String> list = GenericUtils.toString(Arrays.asList((Object[]) object));
                        if (list.size() == 0) {
                            // Specifies here empty multivalued variable (HTTP invoque only)
                            postQuery = addParamToPostQuery(variableName, "_empty_array_", postQuery);
                        } else {
                            for (String value : list) {
                                postQuery = addParamToPostQuery(variableName, value, postQuery);
                            }
                        }
                    } else if (variableValue instanceof Collection<?>) {
                        List<String> list = GenericUtils.toString((Collection<?>) variableValue);
                        if (list.size() == 0) {
                            // Specifies here empty multivalued variable (HTTP invoque only)
                            postQuery = addParamToPostQuery(variableName, "_empty_array_", postQuery);
                        } else {
                            for (String value : list) {
                                postQuery = addParamToPostQuery(variableName, value, postQuery);
                            }
                        }
                    } else if (variableValue instanceof String) {
                        parameterValue = variableValue.toString();
                        postQuery = addParamToPostQuery(variableName, parameterValue, postQuery);
                    } else {
                        parameterValue = variableValue.toString();
                        postQuery = addParamToPostQuery(variableName, parameterValue, postQuery);
                    }
                }
            }
        } catch (ClassCastException e) {
            Engine.logBeans.warn("(RequestableStep) Ignoring parameter '" + variableName + "' because its value is not a string");
        }
    }
    if (bInternalInvoke) {
        return null;
    } else {
        if (Engine.logBeans.isTraceEnabled()) {
            Engine.logBeans.trace("(RequestableStep) postQuery :" + Visibility.Logs.replaceVariables(getVariables(), postQuery));
        }
        return postQuery;
    }
}
Also used : Undefined(org.mozilla.javascript.Undefined) NodeList(org.w3c.dom.NodeList) StepVariable(com.twinsoft.convertigo.beans.variables.StepVariable) Scriptable(org.mozilla.javascript.Scriptable) NativeJavaArray(org.mozilla.javascript.NativeJavaArray) StepMultiValuedVariable(com.twinsoft.convertigo.beans.variables.StepMultiValuedVariable) UniqueTag(org.mozilla.javascript.UniqueTag) XmlSchemaCollection(org.apache.ws.commons.schema.XmlSchemaCollection) Collection(java.util.Collection) NativeJavaObject(org.mozilla.javascript.NativeJavaObject) List(java.util.List) ArrayList(java.util.ArrayList) LinkedList(java.util.LinkedList) NodeList(org.w3c.dom.NodeList) NativeJavaObject(org.mozilla.javascript.NativeJavaObject) TransformerException(javax.xml.transform.TransformerException) TwsCachedXPathAPI(com.twinsoft.convertigo.engine.util.TwsCachedXPathAPI)

Example 5 with StepVariable

use of com.twinsoft.convertigo.beans.variables.StepVariable in project convertigo by convertigo.

the class RequestableStep method clone.

@Override
public RequestableStep clone() throws CloneNotSupportedException {
    RequestableStep clonedObject = (RequestableStep) super.clone();
    clonedObject.vVariables = new LinkedList<StepVariable>();
    clonedObject.vAllVariables = null;
    clonedObject.xmlHttpDocument = null;
    clonedObject.hostConfiguration = new HostConfiguration();
    clonedObject.targetUrl = null;
    clonedObject.method = null;
    return clonedObject;
}
Also used : HostConfiguration(org.apache.commons.httpclient.HostConfiguration) StepVariable(com.twinsoft.convertigo.beans.variables.StepVariable)

Aggregations

StepVariable (com.twinsoft.convertigo.beans.variables.StepVariable)15 RequestableVariable (com.twinsoft.convertigo.beans.variables.RequestableVariable)8 DatabaseObject (com.twinsoft.convertigo.beans.core.DatabaseObject)6 StepMultiValuedVariable (com.twinsoft.convertigo.beans.variables.StepMultiValuedVariable)6 DatabaseObjectTreeObject (com.twinsoft.convertigo.eclipse.views.projectexplorer.model.DatabaseObjectTreeObject)6 TreeObject (com.twinsoft.convertigo.eclipse.views.projectexplorer.model.TreeObject)6 RequestableMultiValuedVariable (com.twinsoft.convertigo.beans.variables.RequestableMultiValuedVariable)5 EngineException (com.twinsoft.convertigo.engine.EngineException)5 ArrayList (java.util.ArrayList)5 Sequence (com.twinsoft.convertigo.beans.core.Sequence)4 RequestableObject (com.twinsoft.convertigo.beans.core.RequestableObject)3 RequestableStep (com.twinsoft.convertigo.beans.core.RequestableStep)3 Step (com.twinsoft.convertigo.beans.core.Step)3 TransactionWithVariables (com.twinsoft.convertigo.beans.core.TransactionWithVariables)3 Variable (com.twinsoft.convertigo.beans.core.Variable)3 SequenceStep (com.twinsoft.convertigo.beans.steps.SequenceStep)3 TransactionStep (com.twinsoft.convertigo.beans.steps.TransactionStep)3 IStepSourceContainer (com.twinsoft.convertigo.beans.core.IStepSourceContainer)2 StepWithExpressions (com.twinsoft.convertigo.beans.core.StepWithExpressions)2 TestCase (com.twinsoft.convertigo.beans.core.TestCase)2