Search in sources :

Example 6 with RequestableHttpVariable

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

Example 7 with RequestableHttpVariable

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

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

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

the class EventStatementGenerator method addVariable.

/*protected String addVariable(String name, String value, boolean wsdl){
		while(transaction.getVariableDefinitionIndex(name)!= -1){
			String base = name;
			int count = 1;
			int i_ = name.lastIndexOf("_");
			if(i_ != -1 && i_+1 < name.length()){
				String end = name.substring(i_+1);
				try{
					count = Integer.parseInt(end) + 1;
					base = name.substring(0, i_);
				}catch(NumberFormatException e){}
			}
			name = base + "_" + count;
		}
		
		transaction.addVariableDefinition(name, name, value, Boolean.valueOf(wsdl), Boolean.FALSE, Boolean.FALSE, Boolean.TRUE, "GET", "");
		transaction.hasChanged = true;
		return name;
	}*/
protected String addVariable(String name, String value, boolean wsdl) {
    while (transaction.getVariable(name) != null) {
        String base = name;
        int count = 1;
        int i_ = name.lastIndexOf("_");
        if (i_ != -1 && i_ + 1 < name.length()) {
            String end = name.substring(i_ + 1);
            try {
                count = Integer.parseInt(end) + 1;
                base = name.substring(0, i_);
            } catch (NumberFormatException e) {
            }
        }
        name = base + "_" + count;
    }
    RequestableHttpVariable httpVariable = new RequestableHttpVariable();
    try {
        if (!StringUtils.isNormalized(name))
            throw new EngineException("Http variable name is not normalized : \"" + name + "\"");
        httpVariable.setName(name);
        httpVariable.setDescription(name);
        httpVariable.setValueOrNull(value);
        httpVariable.setWsdl(Boolean.valueOf(wsdl));
        httpVariable.setCachedKey(Boolean.TRUE);
        httpVariable.setHttpMethod("GET");
        transaction.addVariable(httpVariable);
        transaction.hasChanged = true;
    } catch (EngineException e) {
    }
    return name;
}
Also used : RequestableHttpVariable(com.twinsoft.convertigo.beans.variables.RequestableHttpVariable) EngineException(com.twinsoft.convertigo.engine.EngineException)

Example 10 with RequestableHttpVariable

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

the class WsReference method getVariableName.

private static String getVariableName(List<RequestableHttpVariable> variables, String name) {
    String variableName = StringUtils.normalize(name);
    int index = 1;
    for (RequestableHttpVariable variable : variables) {
        if (variable.getName().equals(variableName)) {
            variableName += "_" + index;
            index++;
            continue;
        }
    }
    return variableName;
}
Also used : RequestableHttpVariable(com.twinsoft.convertigo.beans.variables.RequestableHttpVariable)

Aggregations

RequestableHttpVariable (com.twinsoft.convertigo.beans.variables.RequestableHttpVariable)21 RequestableHttpMultiValuedVariable (com.twinsoft.convertigo.beans.variables.RequestableHttpMultiValuedVariable)9 RequestableVariable (com.twinsoft.convertigo.beans.variables.RequestableVariable)9 EngineException (com.twinsoft.convertigo.engine.EngineException)9 AbstractHttpTransaction (com.twinsoft.convertigo.beans.transactions.AbstractHttpTransaction)7 XMLVector (com.twinsoft.convertigo.beans.common.XMLVector)6 DatabaseObject (com.twinsoft.convertigo.beans.core.DatabaseObject)6 IOException (java.io.IOException)6 Element (org.w3c.dom.Element)5 HTTPStatement (com.twinsoft.convertigo.beans.statements.HTTPStatement)4 XmlHttpTransaction (com.twinsoft.convertigo.beans.transactions.XmlHttpTransaction)4 HttpStatementVariable (com.twinsoft.convertigo.beans.variables.HttpStatementVariable)4 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)3 XmlQName (com.twinsoft.convertigo.beans.common.XmlQName)3 HttpConnector (com.twinsoft.convertigo.beans.connectors.HttpConnector)3 TestCase (com.twinsoft.convertigo.beans.core.TestCase)3 Variable (com.twinsoft.convertigo.beans.core.Variable)3 HttpStatementMultiValuedVariable (com.twinsoft.convertigo.beans.variables.HttpStatementMultiValuedVariable)3 RequestableMultiValuedVariable (com.twinsoft.convertigo.beans.variables.RequestableMultiValuedVariable)3 HttpMethodType (com.twinsoft.convertigo.engine.enums.HttpMethodType)3