use of com.twinsoft.convertigo.beans.variables.HttpStatementVariable 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();
}
}
use of com.twinsoft.convertigo.beans.variables.HttpStatementVariable 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);
}
}
use of com.twinsoft.convertigo.beans.variables.HttpStatementVariable in project convertigo by convertigo.
the class HTTPStatement method addData.
public void addData(String variable, Object value, boolean bmulti, String method) {
if ((variable != null) && !(variable.equals(""))) {
String variableName = parse(variable);
HttpStatementVariable httpStatementVariable = (bmulti ? new HttpStatementMultiValuedVariable() : new HttpStatementVariable());
try {
httpStatementVariable.setName(StringUtils.normalize(variableName));
httpStatementVariable.setDescription("");
httpStatementVariable.setValueOrNull(value);
httpStatementVariable.setHttpMethod(method);
httpStatementVariable.setHttpName(variableName);
httpStatementVariable.bNew = true;
httpStatementVariable.hasChanged = true;
hasChanged = true;
} catch (EngineException e) {
Engine.logBeans.info("Could not update variable");
}
}
}
use of com.twinsoft.convertigo.beans.variables.HttpStatementVariable in project convertigo by convertigo.
the class ChangeToMultiValuedVariableAction 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 simple = (Variable) databaseObject;
Variable multi = null;
if (databaseObject instanceof TestCaseVariable)
multi = new TestCaseMultiValuedVariable();
if (databaseObject instanceof StepVariable)
multi = new StepMultiValuedVariable();
if (databaseObject instanceof RequestableVariable)
multi = new RequestableMultiValuedVariable();
if (databaseObject instanceof RequestableHttpVariable)
multi = new RequestableHttpMultiValuedVariable();
if (databaseObject instanceof HttpStatementVariable)
multi = new HttpStatementMultiValuedVariable();
if (multi != null) {
if (multi instanceof StepVariable) {
((StepVariable) multi).setSourceDefinition(((StepVariable) simple).getSourceDefinition());
}
if (multi instanceof RequestableVariable) {
((RequestableVariable) multi).setXmlTypeAffectation(((RequestableVariable) simple).getXmlTypeAffectation());
}
if (multi instanceof RequestableHttpVariable) {
// HttpName
((RequestableHttpVariable) multi).setHttpName(((RequestableHttpVariable) simple).getHttpName());
// HttpMethod
((RequestableHttpVariable) multi).setHttpMethod(((RequestableHttpVariable) simple).getHttpMethod());
}
Object value = simple.getValueOrNull();
multi.setValueOrNull(value);
multi.setVisibility(simple.getVisibility());
// Comment
multi.setComment(simple.getComment());
// Description
multi.setDescription(simple.getDescription());
// Required
multi.setRequired(simple.isRequired());
multi.bNew = true;
multi.hasChanged = true;
// Add new variable to parent
DatabaseObject parentDbo = simple.getParent();
parentDbo.add(multi);
// Set correct order
if (parentDbo instanceof TestCase)
((TestCase) parentDbo).insertAtOrder(multi, simple.priority);
if (parentDbo instanceof RequestableStep)
((RequestableStep) parentDbo).insertAtOrder(multi, simple.priority);
if (parentDbo instanceof Sequence)
((Sequence) parentDbo).insertAtOrder(multi, simple.priority);
if (parentDbo instanceof TransactionWithVariables)
((TransactionWithVariables) parentDbo).insertAtOrder(multi, simple.priority);
if (parentDbo instanceof HTTPStatement)
((HTTPStatement) parentDbo).insertAtOrder(multi, simple.priority);
// Add new variable in Tree
VariableTreeObject2 varTreeObject = new VariableTreeObject2(explorerView.viewer, multi);
treeParent.addChild(varTreeObject);
// Delete simple variable
simple.delete();
// Set correct name
multi.setName(simple.getName());
parentTreeObject.hasBeenModified(true);
explorerView.reloadTreeObject(parentTreeObject);
explorerView.setSelectedTreeObject(explorerView.findTreeObjectByUserObject(multi));
}
}
}
}
} catch (Throwable e) {
ConvertigoPlugin.logException(e, "Unable to change simple variable to multi valuated variable!");
} finally {
shell.setCursor(null);
waitCursor.dispose();
}
}
use of com.twinsoft.convertigo.beans.variables.HttpStatementVariable in project convertigo by convertigo.
the class StatementAddVariableToTransactionAction 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 HTTPStatement)) {
HTTPStatement httpStatement = (HTTPStatement) databaseObject;
HtmlTransaction htmlTransaction = (HtmlTransaction) httpStatement.getParentTransaction();
List<String> variables = new ArrayList<String>();
int i, size;
/*size = htmlTransaction.getVariablesDefinitionSize();
for (i = 0 ; i < size ; i++) {
variables.add(htmlTransaction.getVariableDefinitionHttpName(i));
}*/
size = htmlTransaction.numberOfVariables();
for (i = 0; i < size; i++) {
RequestableHttpVariable httpVariable = (RequestableHttpVariable) htmlTransaction.getVariable(i);
variables.add(httpVariable.getHttpName());
}
String variableName, variableDescription, variableMethod;
Boolean variableType, variableRequired;
Object variableValue;
int variableVisibility;
size = httpStatement.numberOfVariables();
for (i = 0; i < size; i++) {
HttpStatementVariable httpStatementVariable = (HttpStatementVariable) httpStatement.getVariable(i);
if (httpStatementVariable != null) {
variableName = httpStatementVariable.getName();
variableDescription = httpStatementVariable.getDescription();
variableRequired = httpStatementVariable.isRequired();
variableValue = httpStatementVariable.getValueOrNull();
variableType = httpStatementVariable.isMultiValued();
variableMethod = httpStatementVariable.getHttpMethod();
variableVisibility = httpStatementVariable.getVisibility();
if (!variables.contains(variableName)) {
RequestableHttpVariable requestableVariable = (variableType ? new RequestableHttpMultiValuedVariable() : new RequestableHttpVariable());
requestableVariable.setName(variableName);
requestableVariable.setDescription(variableDescription);
requestableVariable.setRequired(variableRequired);
requestableVariable.setValueOrNull(variableValue);
requestableVariable.setWsdl(Boolean.TRUE);
requestableVariable.setPersonalizable(Boolean.FALSE);
requestableVariable.setCachedKey(Boolean.TRUE);
requestableVariable.setHttpMethod(variableMethod);
requestableVariable.setHttpName("");
requestableVariable.setVisibility(variableVisibility);
requestableVariable.bNew = true;
requestableVariable.hasChanged = true;
htmlTransaction.add(requestableVariable);
}
}
}
htmlTransaction.hasChanged = true;
explorerView.reloadDatabaseObject(htmlTransaction);
}
}
} catch (Throwable e) {
ConvertigoPlugin.logException(e, "Unable to add HTTP variables to transaction!");
} finally {
shell.setCursor(null);
waitCursor.dispose();
}
}
Aggregations