use of com.twinsoft.convertigo.beans.core.Variable in project convertigo by convertigo.
the class JScriptEditorInput method makeFile.
private static IFile makeFile(IJScriptContainer jsContainer, IProject project) {
String fullname = jsContainer.getFullName();
if (jsContainer instanceof DesignDocumentFunctionTreeObject) {
IFile jsconfig = project.getFile("_private/editor/" + fullname + "/jsconfig.json");
String conf = "{\"compilerOptions\": {\"module\": \"es5\", \"target\": \"es5\"}, \"include\": [\"*\"]}";
SwtUtils.fillFile(jsconfig, conf);
SwtUtils.fillFile(project.getFile("_private/editor/" + fullname + "/couchdb.d.ts"), "declare function emit(key, value)\n" + "declare function sum(values)" + "declare function log(txt)\n");
} else {
DatabaseObject dbo = jsContainer.getDatabaseObject();
if (dbo instanceof Step) {
dbo = ((Step) dbo).getSequence();
}
if (dbo instanceof IVariableContainer) {
IVariableContainer vc = (IVariableContainer) dbo;
StringBuilder sb = new StringBuilder();
for (Variable v : vc.getVariables()) {
sb.append("declare var ").append(v.getName()).append(v.isMultiValued() ? ": Array<string>" : ": string\n");
}
SwtUtils.fillFile(project.getFile("_private/editor/" + fullname + "/variables.d.ts"), sb.toString());
}
IFile jsconfig = project.getFile("_private/editor/" + fullname + "/jsconfig.json");
String conf = "{\"compilerOptions\": {\"module\": \"es6\", \"target\": \"es6\"},\n" + " \"include\": [\"" + ConvertigoTypeScriptDefinition.getDeclarationFile().getAbsolutePath().replace('\\', '/') + "\", \"*\"]}";
SwtUtils.fillFile(jsconfig, conf);
}
IFile file = project.getFile("_private/editor/" + fullname + "/code.js");
SwtUtils.fillFile(file, jsContainer.getExpression());
return file;
}
use of com.twinsoft.convertigo.beans.core.Variable 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.core.Variable in project convertigo by convertigo.
the class Migration5_0_0 method createVariables.
private static void createVariables(Document document, Element element) throws Exception {
Element pName, pVariablesDef;
// NodeList properties;
XMLVector<XMLVector<?>> xmlv;
XMLVector<?> row;
XMLVector<Long> ordered;
Node node, newChild, newNode;
Variable variable;
String elementName, elementClassName;
// first update element (see preconfigure() and configure())
updateElement(element);
NodeList children = element.getChildNodes();
elementClassName = element.getAttribute("classname");
pName = MigrationUtils.findChildElementByAttributeValue(children, "property", "name");
elementName = (String) XMLUtils.readObjectFromXml((Element) XMLUtils.findChildNode(pName, Node.ELEMENT_NODE));
pVariablesDef = MigrationUtils.findChildElementByAttributeValue(children, "property", "variablesDefinition");
if (pVariablesDef != null) {
node = XMLUtils.findChildNode(pVariablesDef, Node.ELEMENT_NODE);
xmlv = GenericUtils.cast(XMLUtils.readObjectFromXml((Element) node));
ordered = new XMLVector<Long>();
for (int j = 0; j < xmlv.size(); j++) {
row = (XMLVector<?>) xmlv.get(j);
if (!row.isEmpty()) {
try {
variable = newVariable(elementClassName, row, j);
newChild = variable.toXml(document);
ordered.add(Long.valueOf(variable.priority));
element.appendChild(newChild);
Engine.logDatabaseObjectManager.info("[Migration 4.6.0] Added variable \"" + variable.getName() + "\" for object \"" + elementName + "\" (" + elementClassName + ")");
} catch (EngineException e) {
Engine.logDatabaseObjectManager.error("[Migration 4.6.0] Unable to migrate variable defined at row" + j + " for object \"" + elementName + "\" (" + elementClassName + ")", e);
}
} else {
Engine.logDatabaseObjectManager.info("[Migration 4.6.0] No variable defined for object \"" + elementName + "\" (" + elementClassName + ")");
}
}
xmlv = new XMLVector<XMLVector<?>>();
xmlv.add(ordered);
newNode = XMLUtils.writeObjectToXml(document, xmlv);
pVariablesDef.replaceChild(newNode, node);
}
}
use of com.twinsoft.convertigo.beans.core.Variable in project convertigo by convertigo.
the class Migration7_0_0 method handleSteps.
private static void handleSteps(XmlSchema projectSchema, Map<String, Reference> referenceMap, List<Step> stepList) {
for (Step step : stepList) {
if (step instanceof XMLActionStep) {
XMLVector<XMLVector<Object>> sourcesDefinition = ((XMLActionStep) step).getSourcesDefinition();
for (XMLVector<Object> row : sourcesDefinition) {
if (row.size() > 1) {
XMLVector<String> definition = GenericUtils.cast(row.get(1));
handleSourceDefinition(definition);
}
}
}
if (step instanceof TransactionStep) {
XMLVector<String> definition = ((TransactionStep) step).getConnectionStringDefinition();
handleSourceDefinition(definition);
}
if (step instanceof IStepSourceContainer) {
/**
* Case step's xpath has not been migrated when project has been deployed
** on a 5.0 server from a Studio with an older version *
*/
IStepSourceContainer stepSourceContainer = (IStepSourceContainer) step;
XMLVector<String> definition = stepSourceContainer.getSourceDefinition();
handleSourceDefinition(definition);
}
if (step instanceof IVariableContainer) {
IVariableContainer variableContainer = (IVariableContainer) step;
for (Variable variable : variableContainer.getVariables()) {
if (variable instanceof IStepSourceContainer) {
IStepSourceContainer stepSourceContainer = (IStepSourceContainer) variable;
XMLVector<String> definition = stepSourceContainer.getSourceDefinition();
handleSourceDefinition(definition);
}
}
}
String targetProjectName = null;
String typeLocalName = null;
if (step instanceof TransactionStep) {
targetProjectName = ((TransactionStep) step).getProjectName();
typeLocalName = ((TransactionStep) step).getConnectorName() + "__" + ((TransactionStep) step).getTransactionName() + "ResponseType";
} else if (step instanceof SequenceStep) {
targetProjectName = ((SequenceStep) step).getProjectName();
typeLocalName = ((SequenceStep) step).getSequenceName() + "ResponseType";
}
String namespaceURI = null;
// Case of Requestable steps
if (targetProjectName != null) {
try {
namespaceURI = Project.CONVERTIGO_PROJECTS_NAMESPACEURI + targetProjectName;
if (!targetProjectName.equals(step.getProject().getName())) {
try {
namespaceURI = Engine.theApp.databaseObjectsManager.getOriginalProjectByName(targetProjectName).getTargetNamespace();
} catch (Exception e) {
}
// Add reference
String location = "../" + targetProjectName + "/" + targetProjectName + ".xsd";
addReferenceToMap(referenceMap, namespaceURI, location);
}
// Set step's typeQName
step.setXmlComplexTypeAffectation(new XmlQName(new QName(namespaceURI, typeLocalName)));
} catch (Exception e) {
e.printStackTrace();
}
} else // Other steps
{
try {
String targetNamespace = projectSchema.getTargetNamespace();
String targetPrefix = projectSchema.getNamespaceContext().getPrefix(targetNamespace);
String s = null;
try {
if (step instanceof XMLCopyStep) {
XmlSchemaCollection collection = SchemaMeta.getCollection(projectSchema);
XmlSchemaObject ob = step.getXmlSchemaObject(collection, projectSchema);
if (ob != null) {
if (ob instanceof XmlSchemaSequence) {
ob = ((XmlSchemaSequence) ob).getItems().getItem(0);
}
if (ob instanceof XmlSchemaElement || ob instanceof XmlSchemaAttribute) {
QName schemaTypeName = ob instanceof XmlSchemaElement ? ((XmlSchemaElement) ob).getSchemaTypeName() : ((XmlSchemaAttribute) ob).getSchemaTypeName();
String schemaTypePrefix = projectSchema.getNamespaceContext().getPrefix(schemaTypeName.getNamespaceURI());
String schemaTypeLocalName = schemaTypeName.getLocalPart();
s = schemaTypePrefix + ":" + schemaTypeLocalName;
}
}
} else {
String schemaType = step.getSchemaDataType();
s = schemaType.equals("") ? "xsd:string" : schemaType;
}
} catch (Exception e) {
s = "xsd:string";
}
if ((s != null) && (!s.equals("")) && (!s.startsWith("xsd:"))) {
String prefix = s.split(":")[0];
typeLocalName = s.split(":")[1];
if (prefix.equals(targetPrefix)) {
// ignore
} else {
// Retrieve namespace uri
namespaceURI = projectSchema.getNamespaceContext().getNamespaceURI(prefix);
// Set step's typeQName
QName qname = new QName(namespaceURI, typeLocalName);
XmlSchemaType schemaType = projectSchema.getTypeByName(qname);
if (schemaType instanceof XmlSchemaComplexType)
step.setXmlComplexTypeAffectation(new XmlQName(qname));
if (schemaType instanceof XmlSchemaSimpleType)
step.setXmlSimpleTypeAffectation(new XmlQName(qname));
}
}
} catch (Exception e) {
}
}
if (step instanceof ISimpleTypeAffectation) {
QName qName = XmlSchemaUtils.getSchemaDataTypeName(step.getSchemaDataType());
step.setXmlSimpleTypeAffectation(new XmlQName(qName));
}
if (step instanceof StepWithExpressions) {
handleSteps(projectSchema, referenceMap, ((StepWithExpressions) step).getSteps());
}
}
}
use of com.twinsoft.convertigo.beans.core.Variable 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