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;
}
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;
}
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;
}
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;
}
}
}
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;
}
}
}
}
Aggregations