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();
}
}
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);
}
}
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();
}
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;
}
}
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;
}
Aggregations