Search in sources :

Example 6 with Variable

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

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

the class GetTestPlatform method handleIVariableContainer.

private void handleIVariableContainer(Document document, Element e_vars, IVariableContainer vars) {
    for (Variable variable : vars.getVariables()) {
        Element e_variable = createDatabaseObjectElement(document, variable);
        Object val = variable.getValueOrNull();
        String strval = val == null ? null : variable.isMultiValued() ? new JSONArray(GenericUtils.<XMLVector<String>>cast(val)).toString() : val.toString();
        e_variable.setAttribute("value", strval);
        e_variable.setAttribute("isMasked", Visibility.Platform.isMasked(variable.getVisibility()) ? "true" : "false");
        e_variable.setAttribute("isMultivalued", "" + variable.isMultiValued());
        e_variable.setAttribute("isFileUpload", "" + variable.getIsFileUpload());
        e_variable.setAttribute("description", variable.getDescription());
        e_variable.setAttribute("required", "" + variable.isRequired());
        e_vars.appendChild(e_variable);
    }
}
Also used : Variable(com.twinsoft.convertigo.beans.core.Variable) XMLVector(com.twinsoft.convertigo.beans.common.XMLVector) Element(org.w3c.dom.Element) JSONArray(org.codehaus.jettison.json.JSONArray) DatabaseObject(com.twinsoft.convertigo.beans.core.DatabaseObject) RequestableObject(com.twinsoft.convertigo.beans.core.RequestableObject)

Example 8 with Variable

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

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

the class AbstractCouchDbTransaction method getParameterStringValue.

public String getParameterStringValue(CouchParam param) throws EngineException {
    String value = null;
    Variable variable = getVariable(param.param());
    if (variable != null) {
        value = getParameterStringValue(param.param());
    }
    if (value == null) {
        try {
            value = (String) getClass().getMethod("getP_" + param.name()).invoke(this);
        } catch (Exception e) {
            // TODO: handle error
            e.printStackTrace();
        }
    }
    return value;
}
Also used : RequestableMultiValuedVariable(com.twinsoft.convertigo.beans.variables.RequestableMultiValuedVariable) Variable(com.twinsoft.convertigo.beans.core.Variable) RequestableVariable(com.twinsoft.convertigo.beans.variables.RequestableVariable) JSONException(org.codehaus.jettison.json.JSONException) EngineException(com.twinsoft.convertigo.engine.EngineException)

Example 10 with Variable

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

the class HttpTransactionVariablesComposite method applyProceed.

public void applyProceed() {
    for (Button check : checkboxes) {
        DynamicHttpVariable v = (DynamicHttpVariable) check.getData(DynamicHttpVariable.class.getName());
        Variable dboVar = httpTransaction.getVariable(v.name());
        if (check.getSelection() && dboVar == null) {
            try {
                RequestableHttpVariable newDboVar = new RequestableHttpVariable();
                newDboVar.setName(v.name());
                httpTransaction.addVariable(newDboVar);
            } catch (EngineException e) {
            }
        } else if (!check.getSelection() && dboVar != null) {
            httpTransaction.removeVariable((RequestableVariable) dboVar);
        }
    }
    for (Iterator<Text> i = customs.iterator(); i.hasNext(); ) {
        Text txtName = i.next();
        Text txtValue = i.next();
        if (txtName.getText().isBlank()) {
            continue;
        }
        DynamicHttpVariable v = (DynamicHttpVariable) txtName.getData(DynamicHttpVariable.class.getName());
        try {
            RequestableHttpVariable newDboVar = new RequestableHttpVariable();
            String name = v.prefix() + txtName.getText();
            String normalized = StringUtils.normalize(name);
            newDboVar.setName(normalized);
            if (!name.equals(normalized)) {
                newDboVar.setHttpName(txtName.getText());
            }
            if (v == DynamicHttpVariable.__POST_) {
                newDboVar.setHttpMethod("POST");
            }
            if (!txtValue.getText().isEmpty()) {
                newDboVar.setValueOrNull(txtValue.getText());
            }
            httpTransaction.addVariable(newDboVar);
        } catch (EngineException e) {
        }
    }
}
Also used : RequestableHttpVariable(com.twinsoft.convertigo.beans.variables.RequestableHttpVariable) DynamicHttpVariable(com.twinsoft.convertigo.engine.enums.DynamicHttpVariable) RequestableHttpVariable(com.twinsoft.convertigo.beans.variables.RequestableHttpVariable) Variable(com.twinsoft.convertigo.beans.core.Variable) RequestableVariable(com.twinsoft.convertigo.beans.variables.RequestableVariable) Button(org.eclipse.swt.widgets.Button) DynamicHttpVariable(com.twinsoft.convertigo.engine.enums.DynamicHttpVariable) EngineException(com.twinsoft.convertigo.engine.EngineException) RequestableVariable(com.twinsoft.convertigo.beans.variables.RequestableVariable) Text(org.eclipse.swt.widgets.Text)

Aggregations

Variable (com.twinsoft.convertigo.beans.core.Variable)21 DatabaseObject (com.twinsoft.convertigo.beans.core.DatabaseObject)14 EngineException (com.twinsoft.convertigo.engine.EngineException)13 RequestableVariable (com.twinsoft.convertigo.beans.variables.RequestableVariable)12 Transaction (com.twinsoft.convertigo.beans.core.Transaction)9 Sequence (com.twinsoft.convertigo.beans.core.Sequence)7 TreeObject (com.twinsoft.convertigo.eclipse.views.projectexplorer.model.TreeObject)7 Project (com.twinsoft.convertigo.beans.core.Project)6 RequestableObject (com.twinsoft.convertigo.beans.core.RequestableObject)6 TransactionWithVariables (com.twinsoft.convertigo.beans.core.TransactionWithVariables)6 Connector (com.twinsoft.convertigo.beans.core.Connector)5 Step (com.twinsoft.convertigo.beans.core.Step)5 TestCase (com.twinsoft.convertigo.beans.core.TestCase)5 RequestableHttpVariable (com.twinsoft.convertigo.beans.variables.RequestableHttpVariable)5 StepVariable (com.twinsoft.convertigo.beans.variables.StepVariable)5 DatabaseObjectTreeObject (com.twinsoft.convertigo.eclipse.views.projectexplorer.model.DatabaseObjectTreeObject)5 XMLVector (com.twinsoft.convertigo.beans.common.XMLVector)4 ScreenClass (com.twinsoft.convertigo.beans.core.ScreenClass)4 HtmlTransaction (com.twinsoft.convertigo.beans.transactions.HtmlTransaction)4 PartInitException (org.eclipse.ui.PartInitException)4