use of com.twinsoft.convertigo.beans.variables.StepMultiValuedVariable 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.StepMultiValuedVariable 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.StepMultiValuedVariable 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.StepMultiValuedVariable in project convertigo by convertigo.
the class TreeDropAdapter method paste.
private boolean paste(Node node, TreeObject targetTreeObject) throws EngineException {
if (targetTreeObject instanceof DatabaseObjectTreeObject) {
DatabaseObject parent = ((DatabaseObjectTreeObject) targetTreeObject).getObject();
DatabaseObject databaseObject = paste(node, null, true);
Element element = (Element) ((Element) node).getElementsByTagName("dnd").item(0);
// SEQUENCER
if (parent instanceof Sequence || parent instanceof StepWithExpressions) {
if (parent instanceof XMLElementStep)
return false;
if (parent instanceof IThenElseContainer)
return false;
// Add a TransactionStep
if (databaseObject instanceof Transaction) {
String projectName = ((Element) element.getElementsByTagName("project").item(0)).getAttribute("name");
String connectorName = ((Element) element.getElementsByTagName("connector").item(0)).getAttribute("name");
Transaction transaction = (Transaction) databaseObject;
TransactionStep transactionStep = new TransactionStep();
transactionStep.setSourceTransaction(projectName + TransactionStep.SOURCE_SEPARATOR + connectorName + TransactionStep.SOURCE_SEPARATOR + transaction.getName());
transactionStep.bNew = true;
parent.add(transactionStep);
parent.hasChanged = true;
if (transaction instanceof TransactionWithVariables) {
for (Variable variable : ((TransactionWithVariables) transaction).getVariablesList()) {
StepVariable stepVariable = variable.isMultiValued() ? new StepMultiValuedVariable() : new StepVariable();
stepVariable.setName(variable.getName());
stepVariable.setComment(variable.getComment());
stepVariable.setDescription(variable.getDescription());
stepVariable.setRequired(variable.isRequired());
stepVariable.setValueOrNull(variable.getValueOrNull());
stepVariable.setVisibility(variable.getVisibility());
transactionStep.addVariable(stepVariable);
}
}
return true;
} else // Add a SequenceStep
if (databaseObject instanceof Sequence) {
String projectName = ((Element) element.getElementsByTagName("project").item(0)).getAttribute("name");
Sequence seq = (Sequence) databaseObject;
SequenceStep sequenceStep = new SequenceStep();
sequenceStep.setSourceSequence(projectName + SequenceStep.SOURCE_SEPARATOR + seq.getName());
sequenceStep.bNew = true;
parent.add(sequenceStep);
parent.hasChanged = true;
for (Variable variable : seq.getVariablesList()) {
StepVariable stepVariable = variable.isMultiValued() ? new StepMultiValuedVariable() : new StepVariable();
stepVariable.setName(variable.getName());
stepVariable.setComment(variable.getComment());
stepVariable.setDescription(variable.getDescription());
stepVariable.setRequired(variable.isRequired());
stepVariable.setValueOrNull(variable.getValueOrNull());
stepVariable.setVisibility(variable.getVisibility());
sequenceStep.addVariable(stepVariable);
}
return true;
}
} else // URLMAPPER
if (parent instanceof UrlMappingOperation) {
// Set associated requestable, add all parameters for operation
if (databaseObject instanceof RequestableObject) {
String dboQName = "";
if (databaseObject instanceof Sequence) {
dboQName = ((Element) element.getElementsByTagName("project").item(0)).getAttribute("name") + "." + databaseObject.getName();
} else if (databaseObject instanceof Transaction) {
dboQName = ((Element) element.getElementsByTagName("project").item(0)).getAttribute("name") + "." + ((Element) element.getElementsByTagName("connector").item(0)).getAttribute("name") + "." + databaseObject.getName();
}
UrlMappingOperation operation = (UrlMappingOperation) parent;
operation.setTargetRequestable(dboQName);
if (operation.getComment().isEmpty()) {
operation.setComment(databaseObject.getComment());
}
operation.hasChanged = true;
try {
StringTokenizer st = new StringTokenizer(dboQName, ".");
int count = st.countTokens();
Project p = Engine.theApp.databaseObjectsManager.getProjectByName(st.nextToken());
List<RequestableVariable> variables = new ArrayList<RequestableVariable>();
if (count == 2) {
variables = p.getSequenceByName(st.nextToken()).getVariablesList();
} else if (count == 3) {
variables = ((TransactionWithVariables) p.getConnectorByName(st.nextToken()).getTransactionByName(st.nextToken())).getVariablesList();
}
for (RequestableVariable variable : variables) {
String variableName = variable.getName();
Object variableValue = variable.getValueOrNull();
UrlMappingParameter parameter = null;
try {
parameter = operation.getParameterByName(variableName);
} catch (Exception e) {
}
if (parameter == null) {
boolean acceptForm = operation.getMethod().equalsIgnoreCase(HttpMethodType.POST.name()) || operation.getMethod().equalsIgnoreCase(HttpMethodType.PUT.name());
parameter = acceptForm ? new FormParameter() : 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;
operation.add(parameter);
operation.hasChanged = true;
}
}
} catch (Exception e) {
}
return true;
} else // Add a parameter to mapping operation
if (databaseObject instanceof RequestableVariable) {
RequestableVariable variable = (RequestableVariable) databaseObject;
UrlMappingOperation operation = (UrlMappingOperation) parent;
UrlMappingParameter parameter = null;
String variableName = variable.getName();
Object variableValue = variable.getValueOrNull();
try {
parameter = operation.getParameterByName(variableName);
} catch (Exception e) {
}
if (parameter == null) {
boolean acceptForm = operation.getMethod().equalsIgnoreCase(HttpMethodType.POST.name()) || operation.getMethod().equalsIgnoreCase(HttpMethodType.PUT.name());
parameter = acceptForm ? new FormParameter() : 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;
operation.add(parameter);
operation.hasChanged = true;
}
return true;
}
} else // MOBILE COMPONENTS
if (parent instanceof com.twinsoft.convertigo.beans.mobile.components.MobileComponent) {
return pasteMobileComponent(parent, databaseObject, element);
} else // NGX COMPONENTS
if (parent instanceof com.twinsoft.convertigo.beans.ngx.components.MobileComponent) {
return pasteNgxComponent(parent, databaseObject, element);
}
}
return false;
}
use of com.twinsoft.convertigo.beans.variables.StepMultiValuedVariable in project convertigo by convertigo.
the class RequestableStep method importVariableDefinition.
public void importVariableDefinition(RequestableObject requestable) throws EngineException {
if (!(requestable instanceof IVariableContainer))
return;
IVariableContainer container = (IVariableContainer) requestable;
int size = container.numberOfVariables();
for (int i = 0; i < size; i++) {
RequestableVariable variable = (RequestableVariable) container.getVariable(i);
if (variable != null) {
String variableName = variable.getName();
if (getVariable(variableName) == null) {
if (!StringUtils.isNormalized(variableName))
throw new EngineException("Variable name is not normalized : \"" + variableName + "\".");
StepVariable stepVariable = variable.isMultiValued() ? new StepMultiValuedVariable() : new StepVariable();
stepVariable.setName(variableName);
stepVariable.setComment(variable.getComment());
stepVariable.setDescription(variable.getDescription());
stepVariable.setSourceDefinition(new XMLVector<String>());
stepVariable.setRequired(variable.isRequired());
stepVariable.setValueOrNull(variable.getValueOrNull());
stepVariable.setVisibility(variable.getVisibility());
addVariable(stepVariable);
stepVariable.bNew = true;
stepVariable.hasChanged = true;
hasChanged = true;
}
}
}
}
Aggregations