Search in sources :

Example 11 with StepVariable

use of com.twinsoft.convertigo.beans.variables.StepVariable 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 12 with StepVariable

use of com.twinsoft.convertigo.beans.variables.StepVariable in project convertigo by convertigo.

the class RequestableStep method getVariableValue.

@Override
public Object getVariableValue(String requestedVariableName) throws EngineException {
    Object value = null, valueToPrint = null;
    StepVariable stepVariable = (StepVariable) getVariable(requestedVariableName);
    if (stepVariable != null) {
        value = stepVariable.getValueOrNull();
        valueToPrint = Visibility.Logs.printValue(stepVariable.getVisibility(), value);
        if (Engine.logBeans.isDebugEnabled()) {
            if ((value != null) && (value instanceof String))
                Engine.logBeans.debug("Default value: " + requestedVariableName + " = \"" + valueToPrint + "\"");
            else
                Engine.logBeans.debug("Default value: " + requestedVariableName + " = " + valueToPrint);
        }
        if (value == null && stepVariable.isRequired()) {
            throw new EngineException("Variable named \"" + requestedVariableName + "\" is required for step \"" + getName() + "\"");
        }
    }
    return value;
}
Also used : EngineException(com.twinsoft.convertigo.engine.EngineException) NativeJavaObject(org.mozilla.javascript.NativeJavaObject) StepVariable(com.twinsoft.convertigo.beans.variables.StepVariable)

Example 13 with StepVariable

use of com.twinsoft.convertigo.beans.variables.StepVariable in project convertigo by convertigo.

the class RequestableStep method getAllChildren.

@Override
public List<DatabaseObject> getAllChildren() {
    List<DatabaseObject> rep = super.getAllChildren();
    List<StepVariable> stepVariables = getAllVariables();
    for (StepVariable stepVariable : stepVariables) {
        rep.add(stepVariable);
    }
    return rep;
}
Also used : StepVariable(com.twinsoft.convertigo.beans.variables.StepVariable)

Example 14 with StepVariable

use of com.twinsoft.convertigo.beans.variables.StepVariable in project convertigo by convertigo.

the class RequestableStep method exportVariableDefinition.

public void exportVariableDefinition() throws EngineException {
    for (StepVariable stepVariable : getVariables()) {
        String variableName = stepVariable.getName();
        if (sequence.getVariable(variableName) == null) {
            if (!StringUtils.isNormalized(variableName))
                throw new EngineException("Variable name is not normalized : \"" + variableName + "\".");
            RequestableVariable requestableVariable = stepVariable.isMultiValued() ? new RequestableMultiValuedVariable() : new RequestableVariable();
            requestableVariable.setName(variableName);
            requestableVariable.setComment(stepVariable.getComment());
            requestableVariable.setDescription(stepVariable.getDescription());
            requestableVariable.setComment(stepVariable.getComment());
            requestableVariable.setRequired(stepVariable.isRequired());
            requestableVariable.setValueOrNull(stepVariable.getValueOrNull());
            requestableVariable.setVisibility(stepVariable.getVisibility());
            sequence.addVariable(requestableVariable);
            requestableVariable.bNew = true;
            requestableVariable.hasChanged = true;
            sequence.hasChanged = true;
        }
    }
}
Also used : EngineException(com.twinsoft.convertigo.engine.EngineException) RequestableMultiValuedVariable(com.twinsoft.convertigo.beans.variables.RequestableMultiValuedVariable) RequestableVariable(com.twinsoft.convertigo.beans.variables.RequestableVariable) StepVariable(com.twinsoft.convertigo.beans.variables.StepVariable)

Example 15 with StepVariable

use of com.twinsoft.convertigo.beans.variables.StepVariable 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;
            }
        }
    }
}
Also used : EngineException(com.twinsoft.convertigo.engine.EngineException) RequestableVariable(com.twinsoft.convertigo.beans.variables.RequestableVariable) StepVariable(com.twinsoft.convertigo.beans.variables.StepVariable) StepMultiValuedVariable(com.twinsoft.convertigo.beans.variables.StepMultiValuedVariable)

Aggregations

StepVariable (com.twinsoft.convertigo.beans.variables.StepVariable)15 RequestableVariable (com.twinsoft.convertigo.beans.variables.RequestableVariable)8 DatabaseObject (com.twinsoft.convertigo.beans.core.DatabaseObject)6 StepMultiValuedVariable (com.twinsoft.convertigo.beans.variables.StepMultiValuedVariable)6 DatabaseObjectTreeObject (com.twinsoft.convertigo.eclipse.views.projectexplorer.model.DatabaseObjectTreeObject)6 TreeObject (com.twinsoft.convertigo.eclipse.views.projectexplorer.model.TreeObject)6 RequestableMultiValuedVariable (com.twinsoft.convertigo.beans.variables.RequestableMultiValuedVariable)5 EngineException (com.twinsoft.convertigo.engine.EngineException)5 ArrayList (java.util.ArrayList)5 Sequence (com.twinsoft.convertigo.beans.core.Sequence)4 RequestableObject (com.twinsoft.convertigo.beans.core.RequestableObject)3 RequestableStep (com.twinsoft.convertigo.beans.core.RequestableStep)3 Step (com.twinsoft.convertigo.beans.core.Step)3 TransactionWithVariables (com.twinsoft.convertigo.beans.core.TransactionWithVariables)3 Variable (com.twinsoft.convertigo.beans.core.Variable)3 SequenceStep (com.twinsoft.convertigo.beans.steps.SequenceStep)3 TransactionStep (com.twinsoft.convertigo.beans.steps.TransactionStep)3 IStepSourceContainer (com.twinsoft.convertigo.beans.core.IStepSourceContainer)2 StepWithExpressions (com.twinsoft.convertigo.beans.core.StepWithExpressions)2 TestCase (com.twinsoft.convertigo.beans.core.TestCase)2