Search in sources :

Example 1 with PostOperation

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();
    }
}
Also used : QueryParameter(com.twinsoft.convertigo.beans.rest.QueryParameter) ProjectExplorerView(com.twinsoft.convertigo.eclipse.views.projectexplorer.ProjectExplorerView) UrlMappingOperation(com.twinsoft.convertigo.beans.core.UrlMappingOperation) Variable(com.twinsoft.convertigo.beans.core.Variable) RequestableVariable(com.twinsoft.convertigo.beans.variables.RequestableVariable) RequestableObject(com.twinsoft.convertigo.beans.core.RequestableObject) UrlMappingParameter(com.twinsoft.convertigo.beans.core.UrlMappingParameter) PutOperation(com.twinsoft.convertigo.beans.rest.PutOperation) StructuredSelection(org.eclipse.jface.viewers.StructuredSelection) Cursor(org.eclipse.swt.graphics.Cursor) FormParameter(com.twinsoft.convertigo.beans.rest.FormParameter) ConvertigoException(com.twinsoft.convertigo.engine.ConvertigoException) PostOperation(com.twinsoft.convertigo.beans.rest.PostOperation) Project(com.twinsoft.convertigo.beans.core.Project) ConvertigoException(com.twinsoft.convertigo.engine.ConvertigoException) Shell(org.eclipse.swt.widgets.Shell) StringTokenizer(java.util.StringTokenizer) IVariableContainer(com.twinsoft.convertigo.beans.core.IVariableContainer) TreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.TreeObject) TreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.TreeObject) RequestableObject(com.twinsoft.convertigo.beans.core.RequestableObject) Display(org.eclipse.swt.widgets.Display)

Aggregations

IVariableContainer (com.twinsoft.convertigo.beans.core.IVariableContainer)1 Project (com.twinsoft.convertigo.beans.core.Project)1 RequestableObject (com.twinsoft.convertigo.beans.core.RequestableObject)1 UrlMappingOperation (com.twinsoft.convertigo.beans.core.UrlMappingOperation)1 UrlMappingParameter (com.twinsoft.convertigo.beans.core.UrlMappingParameter)1 Variable (com.twinsoft.convertigo.beans.core.Variable)1 FormParameter (com.twinsoft.convertigo.beans.rest.FormParameter)1 PostOperation (com.twinsoft.convertigo.beans.rest.PostOperation)1 PutOperation (com.twinsoft.convertigo.beans.rest.PutOperation)1 QueryParameter (com.twinsoft.convertigo.beans.rest.QueryParameter)1 RequestableVariable (com.twinsoft.convertigo.beans.variables.RequestableVariable)1 ProjectExplorerView (com.twinsoft.convertigo.eclipse.views.projectexplorer.ProjectExplorerView)1 TreeObject (com.twinsoft.convertigo.eclipse.views.projectexplorer.model.TreeObject)1 ConvertigoException (com.twinsoft.convertigo.engine.ConvertigoException)1 StringTokenizer (java.util.StringTokenizer)1 StructuredSelection (org.eclipse.jface.viewers.StructuredSelection)1 Cursor (org.eclipse.swt.graphics.Cursor)1 Display (org.eclipse.swt.widgets.Display)1 Shell (org.eclipse.swt.widgets.Shell)1