use of com.twinsoft.convertigo.beans.variables.RequestableHttpMultiValuedVariable in project convertigo by convertigo.
the class SwaggerUtils method createRestConnector.
@SuppressWarnings("unused")
private static HttpConnector createRestConnector(JSONObject json) throws Exception {
try {
HttpConnector httpConnector = new HttpConnector();
httpConnector.bNew = true;
JSONObject info = json.getJSONObject("info");
httpConnector.setName(StringUtils.normalize(info.getString("title")));
String host = json.getString("host");
int index = host.indexOf(":");
String server = index == -1 ? host : host.substring(0, index);
int port = index == -1 ? 0 : Integer.parseInt(host.substring(index + 1, 10));
httpConnector.setServer(server);
httpConnector.setPort(port <= 0 ? 80 : port);
String basePath = json.getString("basePath");
httpConnector.setBaseDir(basePath);
JSONArray _consumes = new JSONArray();
if (json.has("consumes")) {
_consumes = json.getJSONArray("consumes");
}
JSONArray _produces = new JSONArray();
if (json.has("produces")) {
_produces = json.getJSONArray("produces");
}
Map<String, JSONObject> models = new HashMap<String, JSONObject>();
JSONObject definitions = new JSONObject();
if (json.has("definitions")) {
definitions = json.getJSONObject("definitions");
for (Iterator<String> i = GenericUtils.cast(definitions.keys()); i.hasNext(); ) {
String key = i.next();
JSONObject model = definitions.getJSONObject(key);
models.put(key, model);
}
}
JSONObject paths = json.getJSONObject("paths");
for (Iterator<String> i1 = GenericUtils.cast(paths.keys()); i1.hasNext(); ) {
String subDir = i1.next();
JSONObject path = paths.getJSONObject(subDir);
for (Iterator<String> i2 = GenericUtils.cast(path.keys()); i2.hasNext(); ) {
String httpVerb = i2.next();
JSONObject verb = path.getJSONObject(httpVerb);
XMLVector<XMLVector<String>> httpParameters = new XMLVector<XMLVector<String>>();
AbstractHttpTransaction transaction = new HttpTransaction();
JSONArray consumes = verb.has("consumes") ? verb.getJSONArray("consumes") : _consumes;
List<String> consumeList = new ArrayList<String>();
for (int i = 0; i < consumes.length(); i++) {
consumeList.add(consumes.getString(i));
}
String h_ContentType = null;
if (consumeList.contains(MimeType.Xml.value())) {
h_ContentType = MimeType.Xml.value();
} else if (consumeList.contains(MimeType.Json.value())) {
h_ContentType = MimeType.Json.value();
} else {
h_ContentType = consumeList.size() > 0 ? consumeList.get(0) : MimeType.WwwForm.value();
}
JSONArray produces = verb.has("produces") ? verb.getJSONArray("produces") : _produces;
List<String> produceList = new ArrayList<String>();
for (int i = 0; i < produces.length(); i++) {
produceList.add(produces.getString(i));
}
String h_Accept = null;
if (produceList.contains(h_ContentType)) {
h_Accept = h_ContentType;
} else {
if (produceList.contains(MimeType.Xml.value())) {
h_Accept = MimeType.Xml.value();
} else if (produceList.contains(MimeType.Json.value())) {
h_Accept = MimeType.Json.value();
}
}
if (h_Accept != null) {
XMLVector<String> xmlv = new XMLVector<String>();
xmlv.add("Accept");
xmlv.add(h_Accept);
httpParameters.add(xmlv);
if (h_Accept.equals(MimeType.Xml.value())) {
transaction = new XmlHttpTransaction();
((XmlHttpTransaction) transaction).setXmlEncoding("UTF-8");
} else if (h_Accept.equals(MimeType.Json.value())) {
transaction = new JsonHttpTransaction();
((JsonHttpTransaction) transaction).setIncludeDataType(false);
}
}
if (h_ContentType != null) {
XMLVector<String> xmlv = new XMLVector<String>();
xmlv.add(HeaderName.ContentType.value());
xmlv.add(h_ContentType);
httpParameters.add(xmlv);
}
String operationId = "";
if (verb.has("operationId")) {
operationId = verb.getString("operationId");
}
String summary = "";
if (verb.has("summary")) {
summary = verb.getString("summary");
}
String description = "";
if (verb.has("description")) {
description = verb.getString("description");
}
String name = StringUtils.normalize(operationId);
if (name.isEmpty()) {
name = StringUtils.normalize(summary);
if (name.isEmpty()) {
name = "operation";
}
}
String comment = summary;
if (comment.isEmpty()) {
comment = description;
}
JSONArray parameters = new JSONArray();
if (verb.has("parameters")) {
parameters = verb.getJSONArray("parameters");
for (int i = 0; i < parameters.length(); i++) {
JSONObject parameter = (JSONObject) parameters.get(i);
String type = "string";
if (parameter.has("collectionFormat")) {
type = parameter.getString("type");
}
String collectionFormat = "csv";
if (parameter.has("collectionFormat")) {
collectionFormat = parameter.getString("collectionFormat");
}
boolean isMultiValued = type.equalsIgnoreCase("array") && collectionFormat.equals("multi");
RequestableHttpVariable httpVariable = isMultiValued ? new RequestableHttpMultiValuedVariable() : new RequestableHttpVariable();
httpVariable.bNew = true;
httpVariable.setName(parameter.getString("name"));
httpVariable.setHttpName(parameter.getString("name"));
String in = parameter.getString("in");
if (in.equals("query") || in.equals("path") || in.equals("header")) {
httpVariable.setHttpMethod(HttpMethodType.GET.name());
if (in.equals("header")) {
// overrides variable's name : will be treated as dynamic header
httpVariable.setName(com.twinsoft.convertigo.engine.enums.Parameter.HttpHeader.getName() + parameter.getString("name"));
// do not post on target server
httpVariable.setHttpName("");
}
} else if (in.equals("formData") || in.equals("body")) {
httpVariable.setHttpMethod(HttpMethodType.POST.name());
if (in.equals("body")) {
// overrides variable's name for internal use
httpVariable.setName(com.twinsoft.convertigo.engine.enums.Parameter.HttpBody.getName());
// add internal __contentType variable
RequestableHttpVariable ct = new RequestableHttpVariable();
ct.setName(com.twinsoft.convertigo.engine.enums.Parameter.HttpContentType.getName());
// do not post on target server
ct.setHttpName("");
ct.setHttpMethod(HttpMethodType.POST.name());
ct.setValueOrNull(null);
ct.bNew = true;
transaction.addVariable(ct);
//
if (parameter.has("schema")) {
// String schema = parameter.getString("schema");
}
}
} else {
httpVariable.setHttpMethod("");
}
Object defaultValue = null;
if (parameter.has("default")) {
defaultValue = parameter.get("default");
}
if (defaultValue == null && type.equalsIgnoreCase("array")) {
JSONObject items = parameter.getJSONObject("items");
if (items.has("default")) {
defaultValue = items.get("default");
}
}
httpVariable.setValueOrNull(defaultValue);
if (parameter.has("description")) {
httpVariable.setDescription(parameter.getString("description"));
}
transaction.addVariable(httpVariable);
}
}
transaction.bNew = true;
transaction.setName(name);
transaction.setComment(comment);
transaction.setSubDir(subDir);
transaction.setHttpVerb(HttpMethodType.valueOf(httpVerb.toUpperCase()));
transaction.setHttpParameters(httpParameters);
transaction.setHttpInfo(true);
httpConnector.add(transaction);
}
}
return httpConnector;
} catch (Throwable t) {
System.out.println(t);
throw new Exception("Invalid Swagger format", t);
}
}
use of com.twinsoft.convertigo.beans.variables.RequestableHttpMultiValuedVariable 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.RequestableHttpMultiValuedVariable in project convertigo by convertigo.
the class WsReference method createHttpVariable.
private static RequestableHttpVariable createHttpVariable(boolean multi, String variableName, QName schemaTypeName) throws EngineException {
RequestableHttpVariable httpVariable = (multi ? new RequestableHttpMultiValuedVariable() : new RequestableHttpVariable());
httpVariable.setName(variableName);
httpVariable.setDescription(variableName);
httpVariable.setWsdl(Boolean.TRUE);
httpVariable.setPersonalizable(Boolean.FALSE);
httpVariable.setCachedKey(Boolean.TRUE);
httpVariable.setHttpMethod("POST");
httpVariable.setHttpName(variableName.toUpperCase());
httpVariable.setXmlTypeAffectation(new XmlQName(schemaTypeName));
httpVariable.bNew = true;
return httpVariable;
}
use of com.twinsoft.convertigo.beans.variables.RequestableHttpMultiValuedVariable 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.RequestableHttpMultiValuedVariable 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();
}
}
Aggregations