use of com.twinsoft.convertigo.beans.rest.PostOperation 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();
}
}
Aggregations