use of com.twinsoft.convertigo.beans.core.StepWithExpressions in project convertigo by convertigo.
the class StepUtils method createStepFromXmlModel.
private static Step createStepFromXmlModel(Object parent, Node node, boolean deepClone) throws EngineException {
Sequence mainSequence = null;
if (parent instanceof Sequence) {
mainSequence = (Sequence) parent;
} else if (parent instanceof StepWithExpressions) {
mainSequence = ((StepWithExpressions) parent).getSequence();
}
if (mainSequence == null)
throw new EngineException("Unable to create step's structure : sequence is null");
Map<String, Step> stepsMap = new HashMap<String, Step>(50);
Step step = createStep(mainSequence, stepsMap, null, node, deepClone);
stepsMap.clear();
return step;
}
use of com.twinsoft.convertigo.beans.core.StepWithExpressions in project convertigo by convertigo.
the class StepUtils method deepClone.
private static Step deepClone(Sequence mainSequence, Object parent, Step step) throws EngineException {
Step cloned = null;
try {
cloned = (Step) step.clone();
cloned.priority = cloned.getNewOrderValue();
cloned.bNew = true;
addStepToParent(mainSequence, parent, cloned);
if (step instanceof StepWithExpressions) {
StepWithExpressions swe = (StepWithExpressions) step;
for (Step child : swe.getSteps()) {
deepClone(mainSequence, cloned, child);
}
}
} catch (CloneNotSupportedException e) {
}
return cloned;
}
use of com.twinsoft.convertigo.beans.core.StepWithExpressions 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.core.StepWithExpressions in project convertigo by convertigo.
the class SequenceImportFromXmlAction 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) {
DatabaseObjectTreeObject databaseObjectTreeObject = (DatabaseObjectTreeObject) explorerView.getFirstSelectedTreeObject();
DatabaseObject databaseObject = databaseObjectTreeObject.getObject();
SequenceTreeObject sequenceTreeObject = (SequenceTreeObject) ((databaseObject instanceof Sequence) ? databaseObjectTreeObject : databaseObjectTreeObject.getParentDatabaseObjectTreeObject());
Sequence sequence = (databaseObject instanceof Sequence) ? (Sequence) databaseObject : ((StepWithExpressions) databaseObject).getSequence();
// Open a file dialog to search a XML file
FileDialog fileDialog = new FileDialog(shell, SWT.PRIMARY_MODAL | SWT.SAVE);
fileDialog.setText("Import XML file");
fileDialog.setFilterExtensions(new String[] { "*.xml" });
fileDialog.setFilterNames(new String[] { "XML" });
fileDialog.setFilterPath(Engine.PROJECTS_PATH);
String filePath = fileDialog.open();
if (filePath != null) {
// Get XML content from the file
File xmlFile = new File(filePath);
Charset charset = XMLUtils.getEncoding(xmlFile);
String xmlContent = FileUtils.readFileToString(xmlFile, charset.name());
// Open and add XML content to the dialog area
XmlStructureDialog dlg = new XmlStructureDialog(shell, sequence, xmlContent);
if (dlg.open() == Window.OK) {
if (dlg.result instanceof Throwable) {
throw (Throwable) dlg.result;
} else {
Step step = (Step) dlg.result;
if (step != null) {
if (databaseObject instanceof Sequence) {
sequence.addStep(step);
} else {
StepWithExpressions swe = (StepWithExpressions) databaseObject;
swe.addStep(step);
}
sequence.hasChanged = true;
// Reload sequence in tree without updating its schema for faster reload
ConvertigoPlugin.logDebug("Reload sequence: start");
explorerView.reloadTreeObject(sequenceTreeObject);
ConvertigoPlugin.logDebug("Reload sequence: end");
// Select target dbo in tree
explorerView.objectSelected(new CompositeEvent(databaseObject));
}
}
}
}
}
} catch (Throwable e) {
ConvertigoPlugin.logException(e, "Unable to import step from xml!");
} finally {
shell.setCursor(null);
waitCursor.dispose();
}
}
use of com.twinsoft.convertigo.beans.core.StepWithExpressions in project convertigo by convertigo.
the class ReturnStep method stepExecute.
@Override
protected boolean stepExecute(Context javascriptContext, Scriptable scope) throws EngineException {
if (isEnabled()) {
if (super.stepExecute(javascriptContext, scope)) {
DatabaseObject parentStep = this.parent;
while (parentStep != null) {
if (parentStep instanceof FunctionStep) {
FunctionStep functionStep = (FunctionStep) parentStep;
functionStep.setReturnedValue(this.evaluated);
functionStep.bContinue = false;
return true;
} else {
if (parentStep instanceof StepWithExpressions)
((StepWithExpressions) parentStep).bContinue = false;
parentStep = parentStep.getParent();
}
}
sequence.skipNextSteps(true);
return true;
}
}
return false;
}
Aggregations