use of com.twinsoft.convertigo.beans.rest.FormParameter in project convertigo by convertigo.
the class OperationImportParametersFromVariablesAction 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) {
TreeObject treeObject = explorerView.getFirstSelectedTreeObject();
Object databaseObject = treeObject.getObject();
if ((databaseObject != null) && (databaseObject instanceof UrlMappingOperation)) {
UrlMappingOperation operation = (UrlMappingOperation) databaseObject;
String targetRequestable = operation.getTargetRequestable();
if (!targetRequestable.isEmpty()) {
StringTokenizer st = new StringTokenizer(targetRequestable, ".");
int count = st.countTokens();
String projectName = st.nextToken();
String sequenceName = count == 2 ? st.nextToken() : "";
String connectorName = count == 3 ? st.nextToken() : "";
String transactionName = count == 3 ? st.nextToken() : "";
Project project = Engine.theApp.databaseObjectsManager.getProjectByName(projectName);
RequestableObject requestableObject = null;
if (sequenceName.isEmpty()) {
requestableObject = project.getConnectorByName(connectorName).getTransactionByName(transactionName);
} else {
requestableObject = project.getSequenceByName(sequenceName);
}
if (requestableObject != null && requestableObject instanceof IVariableContainer) {
IVariableContainer variableContainer = (IVariableContainer) requestableObject;
for (Variable variable : variableContainer.getVariables()) {
String variableName = variable.getName();
Object variableValue = variable.getValueOrNull();
UrlMappingParameter parameter = null;
try {
parameter = operation.getParameterByName(variableName);
} catch (Exception e) {
}
if (parameter == null) {
if (operation instanceof PostOperation || operation instanceof PutOperation)
parameter = new FormParameter();
else
parameter = 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;
parameter.hasChanged = true;
operation.add(parameter);
operation.hasChanged = true;
}
}
if (operation.hasChanged) {
explorerView.reloadTreeObject(treeObject);
StructuredSelection structuredSelection = new StructuredSelection(treeObject);
ConvertigoPlugin.getDefault().getPropertiesView().selectionChanged((IWorkbenchPart) explorerView, structuredSelection);
}
}
} else {
throw new ConvertigoException("Operation has no target requestable : please select one first.");
}
}
}
} catch (Throwable e) {
ConvertigoPlugin.logException(e, "Unable to import variables as new parameters in operation!");
} finally {
shell.setCursor(null);
waitCursor.dispose();
}
}
use of com.twinsoft.convertigo.beans.rest.FormParameter in project convertigo by convertigo.
the class ChangeToFormParameterAction 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();
Object databaseObject = treeObject.getObject();
if ((databaseObject != null) && (databaseObject instanceof UrlMappingParameter)) {
UrlMappingParameter parameter = (UrlMappingParameter) databaseObject;
TreeParent treeParent = treeObject.getParent();
DatabaseObjectTreeObject parentTreeObject = null;
if (treeParent instanceof DatabaseObjectTreeObject)
parentTreeObject = (DatabaseObjectTreeObject) treeParent;
else
parentTreeObject = (DatabaseObjectTreeObject) treeParent.getParent();
if (parentTreeObject != null) {
// Create new Form parameter
FormParameter formParameter = new FormParameter();
if (DatabaseObjectsManager.acceptDatabaseObjects(parameter.getParent(), formParameter)) {
formParameter.setComment(parameter.getComment());
formParameter.setInputType(parameter.getInputType());
formParameter.setArray(parameter.isArray());
formParameter.setExposed(parameter.isExposed());
formParameter.setMultiValued(parameter.isMultiValued());
formParameter.setRequired(parameter.isRequired());
formParameter.setValueOrNull(parameter.getValueOrNull());
formParameter.setMappedVariableName(parameter.getMappedVariableName());
formParameter.bNew = true;
formParameter.hasChanged = true;
// Add new parameter to parent operation
UrlMappingOperation operation = (UrlMappingOperation) parameter.getParent();
operation.changeTo(formParameter);
// Add new parameter in Tree
UrlMappingParameterTreeObject parameterTreeObject = new UrlMappingParameterTreeObject(explorerView.viewer, formParameter);
treeParent.addChild(parameterTreeObject);
// Delete old parameter
parameter.delete();
// Rename new parameter
formParameter.setName(parameter.getName());
// Reload in tree
parentTreeObject.hasBeenModified(true);
explorerView.reloadTreeObject(parentTreeObject);
explorerView.setSelectedTreeObject(explorerView.findTreeObjectByUserObject(formParameter));
} else {
throw new EngineException("You cannot paste to a " + parameter.getParent().getClass().getSimpleName() + " a database object of type " + formParameter.getClass().getSimpleName());
}
}
}
}
} catch (Throwable e) {
ConvertigoPlugin.logException(e, "Unable to change parameter to Form parameter!");
} finally {
shell.setCursor(null);
waitCursor.dispose();
}
}
use of com.twinsoft.convertigo.beans.rest.FormParameter 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;
}
Aggregations