Search in sources :

Example 1 with RequestableVariable

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

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

the class NgxUIComponentTreeObject 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;
    if (update != TreeObjectEvent.UPDATE_NONE) {
        // Case a UIStackVariable has been renamed
        if (databaseObject instanceof UIStackVariable) {
            UIStackVariable variable = (UIStackVariable) databaseObject;
            UIActionStack stack = variable.getSharedAction();
            if (stack != null) {
                // rename variable for InvokeAction
                if (getObject() instanceof UIDynamicInvoke) {
                    UIDynamicInvoke udi = (UIDynamicInvoke) getObject();
                    if (udi.getSharedActionQName().equals(stack.getQName())) {
                        boolean isLocalProject = variable.getProject().equals(udi.getProject());
                        boolean isSameValue = variable.getName().equals(oldValue);
                        boolean shouldUpdate = (update == TreeObjectEvent.UPDATE_ALL) || ((update == TreeObjectEvent.UPDATE_LOCAL) && (isLocalProject));
                        if (!isSameValue && shouldUpdate) {
                            Iterator<UIComponent> it = udi.getUIComponentList().iterator();
                            while (it.hasNext()) {
                                UIComponent component = (UIComponent) it.next();
                                if (component instanceof UIControlVariable) {
                                    UIControlVariable uicv = (UIControlVariable) component;
                                    if (uicv.getName().equals(oldValue)) {
                                        try {
                                            uicv.setName((String) newValue);
                                            uicv.hasChanged = true;
                                            viewer.refresh();
                                            markMainAsDirty(udi);
                                            notifyDataseObjectPropertyChanged(uicv, "name", oldValue, newValue, new HashSet<Object>());
                                            break;
                                        } catch (EngineException e) {
                                            ConvertigoPlugin.logException(e, "Unable to refactor the references of '" + newValue + "' variable for InvokeAction !");
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
        // Case a UICompVariable has been renamed
        if (databaseObject instanceof UICompVariable) {
            UICompVariable variable = (UICompVariable) databaseObject;
            UISharedComponent comp = variable.getSharedComponent();
            if (comp != null) {
                // rename variable for UseShared
                if (getObject() instanceof UIUseShared) {
                    UIUseShared uus = (UIUseShared) getObject();
                    if (uus.getSharedComponentQName().equals(comp.getQName())) {
                        boolean isLocalProject = variable.getProject().equals(uus.getProject());
                        boolean isSameValue = variable.getName().equals(oldValue);
                        boolean shouldUpdate = (update == TreeObjectEvent.UPDATE_ALL) || ((update == TreeObjectEvent.UPDATE_LOCAL) && (isLocalProject));
                        if (!isSameValue && shouldUpdate) {
                            Iterator<UIComponent> it = uus.getUIComponentList().iterator();
                            while (it.hasNext()) {
                                UIComponent component = (UIComponent) it.next();
                                if (component instanceof UIControlVariable) {
                                    UIControlVariable uicv = (UIControlVariable) component;
                                    if (uicv.getName().equals(oldValue)) {
                                        try {
                                            uicv.setName((String) newValue);
                                            uicv.hasChanged = true;
                                            viewer.refresh();
                                            markMainAsDirty(uus);
                                            notifyDataseObjectPropertyChanged(uicv, "name", oldValue, newValue, new HashSet<Object>());
                                            break;
                                        } catch (EngineException e) {
                                            ConvertigoPlugin.logException(e, "Unable to refactor the references of '" + newValue + "' variable for UseShared !");
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
        } else // Case a RequestableVariable has been renamed
        if (databaseObject instanceof RequestableVariable) {
            RequestableVariable variable = (RequestableVariable) databaseObject;
            DatabaseObject parent = variable.getParent();
            if (getObject() instanceof UIDynamicAction) {
                UIDynamicAction uia = (UIDynamicAction) getObject();
                IonBean ionBean = uia.getIonBean();
                if (ionBean != null) {
                    // rename variable for CallSequenceAction
                    if (ionBean.getName().equals("CallSequenceAction")) {
                        Object p_val = ionBean.getProperty("requestable").getValue();
                        if (!p_val.equals(false)) {
                            if (parent.getQName().equals(p_val.toString())) {
                                boolean isLocalProject = variable.getProject().equals(uia.getProject());
                                boolean isSameValue = variable.getName().equals(oldValue);
                                boolean shouldUpdate = (update == TreeObjectEvent.UPDATE_ALL) || ((update == TreeObjectEvent.UPDATE_LOCAL) && (isLocalProject));
                                if (!isSameValue && shouldUpdate) {
                                    Iterator<UIComponent> it = uia.getUIComponentList().iterator();
                                    while (it.hasNext()) {
                                        UIComponent component = (UIComponent) it.next();
                                        if (component instanceof UIControlVariable) {
                                            UIControlVariable uicv = (UIControlVariable) component;
                                            if (uicv.getName().equals(oldValue)) {
                                                try {
                                                    uicv.setName((String) newValue);
                                                    uicv.hasChanged = true;
                                                    viewer.refresh();
                                                    markMainAsDirty(uia);
                                                    notifyDataseObjectPropertyChanged(uicv, "name", oldValue, newValue, new HashSet<Object>());
                                                    break;
                                                } catch (EngineException e) {
                                                    ConvertigoPlugin.logException(e, "Unable to refactor the references of '" + newValue + "' variable for CallSequenceAction !");
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
    }
}
Also used : UICompVariable(com.twinsoft.convertigo.beans.ngx.components.UICompVariable) IonBean(com.twinsoft.convertigo.beans.ngx.components.dynamic.IonBean) UIUseShared(com.twinsoft.convertigo.beans.ngx.components.UIUseShared) UIComponent(com.twinsoft.convertigo.beans.ngx.components.UIComponent) EngineException(com.twinsoft.convertigo.engine.EngineException) UIStackVariable(com.twinsoft.convertigo.beans.ngx.components.UIStackVariable) UIControlVariable(com.twinsoft.convertigo.beans.ngx.components.UIControlVariable) RequestableVariable(com.twinsoft.convertigo.beans.variables.RequestableVariable) UISharedComponent(com.twinsoft.convertigo.beans.ngx.components.UISharedComponent) UIActionStack(com.twinsoft.convertigo.beans.ngx.components.UIActionStack) UIDynamicAction(com.twinsoft.convertigo.beans.ngx.components.UIDynamicAction) UIDynamicInvoke(com.twinsoft.convertigo.beans.ngx.components.UIDynamicInvoke) Iterator(java.util.Iterator) DatabaseObject(com.twinsoft.convertigo.beans.core.DatabaseObject) DatabaseObject(com.twinsoft.convertigo.beans.core.DatabaseObject) HashSet(java.util.HashSet)

Example 3 with RequestableVariable

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

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

the class SqlTransaction method updateVariable.

private void updateVariable(boolean updateDefinitions, String parameterName) {
    if (updateDefinitions && (getVariable(parameterName) == null)) {
        try {
            if (!StringUtils.isNormalized(parameterName))
                throw new EngineException("Parameter name is not normalized : \"" + parameterName + "\".");
            RequestableVariable variable = new RequestableVariable();
            variable.setName(parameterName);
            variable.setDescription(parameterName);
            variable.setWsdl(Boolean.TRUE);
            variable.setCachedKey(Boolean.TRUE);
            addVariable(variable);
            variable.bNew = true;
            variable.hasChanged = true;
            hasChanged = true;
        } catch (EngineException e) {
            Engine.logBeans.error("Could not add variable '" + parameterName + "' for SqlTransaction '" + getName() + "'", null);
        }
    }
}
Also used : EngineException(com.twinsoft.convertigo.engine.EngineException) RequestableVariable(com.twinsoft.convertigo.beans.variables.RequestableVariable)

Example 5 with RequestableVariable

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

the class AbstractCouchDbTransaction method createVariables.

public void createVariables(List<CouchVariable> selectedParameters) {
    try {
        if (selectedParameters != null) {
            for (CouchVariable variable : selectedParameters) {
                String varName = variable.getName();
                String varNameNew = (varName.startsWith("p_") || varName.startsWith("q_") ? CouchParam.prefix + varName.substring(2) : varName);
                String varDesc = variable.getDescription();
                if (getVariable(varNameNew) == null) {
                    RequestableVariable requestableVariable = null;
                    if (variable.isMultiValued()) {
                        requestableVariable = new RequestableMultiValuedVariable();
                    } else {
                        requestableVariable = new RequestableVariable();
                    }
                    requestableVariable.setName(varNameNew);
                    requestableVariable.setDescription(varDesc);
                    addVariable(requestableVariable);
                    hasChanged = true;
                }
            }
        }
    } catch (Exception e) {
        Engine.logBeans.error("Unable to add needed variable(s) for CouchDbTransaction", e);
    }
}
Also used : RequestableMultiValuedVariable(com.twinsoft.convertigo.beans.variables.RequestableMultiValuedVariable) RequestableVariable(com.twinsoft.convertigo.beans.variables.RequestableVariable) JSONException(org.codehaus.jettison.json.JSONException) EngineException(com.twinsoft.convertigo.engine.EngineException)

Aggregations

RequestableVariable (com.twinsoft.convertigo.beans.variables.RequestableVariable)54 EngineException (com.twinsoft.convertigo.engine.EngineException)23 DatabaseObject (com.twinsoft.convertigo.beans.core.DatabaseObject)13 Sequence (com.twinsoft.convertigo.beans.core.Sequence)11 Element (org.w3c.dom.Element)9 DatabaseObjectTreeObject (com.twinsoft.convertigo.eclipse.views.projectexplorer.model.DatabaseObjectTreeObject)8 TreeObject (com.twinsoft.convertigo.eclipse.views.projectexplorer.model.TreeObject)8 RequestableMultiValuedVariable (com.twinsoft.convertigo.beans.variables.RequestableMultiValuedVariable)7 StepVariable (com.twinsoft.convertigo.beans.variables.StepVariable)7 TestCaseVariable (com.twinsoft.convertigo.beans.variables.TestCaseVariable)7 Shell (org.eclipse.swt.widgets.Shell)6 TransactionWithVariables (com.twinsoft.convertigo.beans.core.TransactionWithVariables)5 Variable (com.twinsoft.convertigo.beans.core.Variable)5 RequestableHttpVariable (com.twinsoft.convertigo.beans.variables.RequestableHttpVariable)5 ProjectExplorerView (com.twinsoft.convertigo.eclipse.views.projectexplorer.ProjectExplorerView)5 Cursor (org.eclipse.swt.graphics.Cursor)5 Display (org.eclipse.swt.widgets.Display)5 RequestableObject (com.twinsoft.convertigo.beans.core.RequestableObject)4 StructuredSelection (org.eclipse.jface.viewers.StructuredSelection)4 XMLVector (com.twinsoft.convertigo.beans.common.XMLVector)3