Search in sources :

Example 31 with StepWithExpressions

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;
}
Also used : HashMap(java.util.HashMap) StepWithExpressions(com.twinsoft.convertigo.beans.core.StepWithExpressions) EngineException(com.twinsoft.convertigo.engine.EngineException) Sequence(com.twinsoft.convertigo.beans.core.Sequence) XMLComplexStep(com.twinsoft.convertigo.beans.steps.XMLComplexStep) XMLAttributeStep(com.twinsoft.convertigo.beans.steps.XMLAttributeStep) Step(com.twinsoft.convertigo.beans.core.Step) IteratorStep(com.twinsoft.convertigo.beans.steps.IteratorStep) XMLElementStep(com.twinsoft.convertigo.beans.steps.XMLElementStep)

Example 32 with StepWithExpressions

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;
}
Also used : StepWithExpressions(com.twinsoft.convertigo.beans.core.StepWithExpressions) XMLComplexStep(com.twinsoft.convertigo.beans.steps.XMLComplexStep) XMLAttributeStep(com.twinsoft.convertigo.beans.steps.XMLAttributeStep) Step(com.twinsoft.convertigo.beans.core.Step) IteratorStep(com.twinsoft.convertigo.beans.steps.IteratorStep) XMLElementStep(com.twinsoft.convertigo.beans.steps.XMLElementStep)

Example 33 with StepWithExpressions

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;
}
Also used : QueryParameter(com.twinsoft.convertigo.beans.rest.QueryParameter) DatabaseObjectTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.DatabaseObjectTreeObject) IThenElseContainer(com.twinsoft.convertigo.beans.steps.IThenElseContainer) RequestableVariable(com.twinsoft.convertigo.beans.variables.RequestableVariable) Variable(com.twinsoft.convertigo.beans.core.Variable) StepMultiValuedVariable(com.twinsoft.convertigo.beans.variables.StepMultiValuedVariable) StepVariable(com.twinsoft.convertigo.beans.variables.StepVariable) UrlMappingParameter(com.twinsoft.convertigo.beans.core.UrlMappingParameter) XMLElementStep(com.twinsoft.convertigo.beans.steps.XMLElementStep) Element(org.w3c.dom.Element) StepWithExpressions(com.twinsoft.convertigo.beans.core.StepWithExpressions) StepVariable(com.twinsoft.convertigo.beans.variables.StepVariable) FormParameter(com.twinsoft.convertigo.beans.rest.FormParameter) StepMultiValuedVariable(com.twinsoft.convertigo.beans.variables.StepMultiValuedVariable) DatabaseObject(com.twinsoft.convertigo.beans.core.DatabaseObject) ArrayList(java.util.ArrayList) List(java.util.List) NodeList(org.w3c.dom.NodeList) SequenceStep(com.twinsoft.convertigo.beans.steps.SequenceStep) UrlMappingOperation(com.twinsoft.convertigo.beans.core.UrlMappingOperation) RequestableObject(com.twinsoft.convertigo.beans.core.RequestableObject) RequestableVariable(com.twinsoft.convertigo.beans.variables.RequestableVariable) Sequence(com.twinsoft.convertigo.beans.core.Sequence) IOException(java.io.IOException) ObjectWithSameNameException(com.twinsoft.convertigo.engine.ObjectWithSameNameException) SAXException(org.xml.sax.SAXException) EngineException(com.twinsoft.convertigo.engine.EngineException) InvalidOperationException(com.twinsoft.convertigo.engine.InvalidOperationException) TransactionStep(com.twinsoft.convertigo.beans.steps.TransactionStep) Project(com.twinsoft.convertigo.beans.core.Project) StringTokenizer(java.util.StringTokenizer) Transaction(com.twinsoft.convertigo.beans.core.Transaction) HtmlTransaction(com.twinsoft.convertigo.beans.transactions.HtmlTransaction) TransactionWithVariables(com.twinsoft.convertigo.beans.core.TransactionWithVariables) PropertyTableRowTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.PropertyTableRowTreeObject) NgxComponentTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.NgxComponentTreeObject) IOrderableTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.IOrderableTreeObject) ProjectTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.ProjectTreeObject) FolderTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.FolderTreeObject) DatabaseObject(com.twinsoft.convertigo.beans.core.DatabaseObject) ObjectsFolderTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.ObjectsFolderTreeObject) NgxUIComponentTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.NgxUIComponentTreeObject) MobileUIComponentTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.MobileUIComponentTreeObject) IPropertyTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.IPropertyTreeObject) RequestableObject(com.twinsoft.convertigo.beans.core.RequestableObject) PropertyTableTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.PropertyTableTreeObject) TreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.TreeObject) DatabaseObjectTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.DatabaseObjectTreeObject) ScreenClassTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.ScreenClassTreeObject) MobileComponentTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.MobileComponentTreeObject)

Example 34 with StepWithExpressions

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();
    }
}
Also used : ProjectExplorerView(com.twinsoft.convertigo.eclipse.views.projectexplorer.ProjectExplorerView) DatabaseObjectTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.DatabaseObjectTreeObject) SequenceTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.SequenceTreeObject) StepWithExpressions(com.twinsoft.convertigo.beans.core.StepWithExpressions) Charset(java.nio.charset.Charset) Sequence(com.twinsoft.convertigo.beans.core.Sequence) Step(com.twinsoft.convertigo.beans.core.Step) Cursor(org.eclipse.swt.graphics.Cursor) XmlStructureDialog(com.twinsoft.convertigo.eclipse.dialogs.XmlStructureDialog) Shell(org.eclipse.swt.widgets.Shell) DatabaseObject(com.twinsoft.convertigo.beans.core.DatabaseObject) FileDialog(org.eclipse.swt.widgets.FileDialog) File(java.io.File) CompositeEvent(com.twinsoft.convertigo.eclipse.editors.CompositeEvent) Display(org.eclipse.swt.widgets.Display)

Example 35 with StepWithExpressions

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;
}
Also used : StepWithExpressions(com.twinsoft.convertigo.beans.core.StepWithExpressions) DatabaseObject(com.twinsoft.convertigo.beans.core.DatabaseObject)

Aggregations

StepWithExpressions (com.twinsoft.convertigo.beans.core.StepWithExpressions)35 Sequence (com.twinsoft.convertigo.beans.core.Sequence)27 Step (com.twinsoft.convertigo.beans.core.Step)26 DatabaseObject (com.twinsoft.convertigo.beans.core.DatabaseObject)24 DatabaseObjectTreeObject (com.twinsoft.convertigo.eclipse.views.projectexplorer.model.DatabaseObjectTreeObject)22 TreeObject (com.twinsoft.convertigo.eclipse.views.projectexplorer.model.TreeObject)19 Cursor (org.eclipse.swt.graphics.Cursor)19 Display (org.eclipse.swt.widgets.Display)19 Shell (org.eclipse.swt.widgets.Shell)19 ProjectExplorerView (com.twinsoft.convertigo.eclipse.views.projectexplorer.ProjectExplorerView)18 EngineException (com.twinsoft.convertigo.engine.EngineException)16 StepEvent (com.twinsoft.convertigo.beans.core.StepEvent)15 TreeParent (com.twinsoft.convertigo.eclipse.views.projectexplorer.TreeParent)15 StepTreeObject (com.twinsoft.convertigo.eclipse.views.projectexplorer.model.StepTreeObject)15 ThenStep (com.twinsoft.convertigo.beans.steps.ThenStep)10 TreePath (com.twinsoft.convertigo.eclipse.views.projectexplorer.TreePath)8 SequenceStep (com.twinsoft.convertigo.beans.steps.SequenceStep)7 ElseStep (com.twinsoft.convertigo.beans.steps.ElseStep)6 TransactionStep (com.twinsoft.convertigo.beans.steps.TransactionStep)6 XMLElementStep (com.twinsoft.convertigo.beans.steps.XMLElementStep)6