Search in sources :

Example 1 with WebServiceReference

use of com.twinsoft.convertigo.beans.references.WebServiceReference in project convertigo by convertigo.

the class WsReferenceImportDialog method run.

public void run() {
    final Display display = getParentShell().getDisplay();
    Thread progressBarThread = new Thread("Progress Bar thread") {

        public void run() {
            int i = 0;
            while (true) {
                try {
                    i += 5;
                    if (i >= 100)
                        i = 0;
                    final int j = i;
                    display.asyncExec(new Runnable() {

                        public void run() {
                            if (progressBar != null) {
                                if (!progressBar.isDisposed()) {
                                    progressBar.setSelection(j);
                                }
                            }
                        }
                    });
                    sleep(500);
                } catch (InterruptedException e) {
                    break;
                }
            }
        }
    };
    Throwable ex = null;
    try {
        progressBarThread.start();
        ImportWsReference wsr = null;
        if (wsReference instanceof WebServiceReference)
            wsr = new ImportWsReference((WebServiceReference) wsReference);
        if (wsReference instanceof RestServiceReference)
            wsr = new ImportWsReference((RestServiceReference) wsReference);
        httpConnector = wsr.importInto(project);
    } catch (Throwable e) {
        ex = e;
    } finally {
        try {
            progressBarThread.interrupt();
            display.asyncExec(new Runnable() {

                public void run() {
                    setReturnCode(OK);
                    close();
                }
            });
        } catch (Throwable e) {
        }
        if (ex != null) {
            ConvertigoPlugin.logException(ex, "Unable to import from WSDL");
        }
    }
}
Also used : RestServiceReference(com.twinsoft.convertigo.beans.references.RestServiceReference) ImportWsReference(com.twinsoft.convertigo.engine.util.ImportWsReference) WebServiceReference(com.twinsoft.convertigo.beans.references.WebServiceReference) Display(org.eclipse.swt.widgets.Display)

Example 2 with WebServiceReference

use of com.twinsoft.convertigo.beans.references.WebServiceReference in project convertigo by convertigo.

the class NewObjectWizard method doFinish.

private void doFinish(IProgressMonitor monitor) throws CoreException {
    String dboName, name;
    boolean bContinue = true;
    int index = 0;
    try {
        int total = 0;
        Class<?> c = getCreatedBeanClass();
        if (c != null) {
            total = 4;
            if (c.equals(WebServiceReference.class)) {
                total += ImportWsReference.getTotalTaskNumber();
            }
        }
        monitor.beginTask("Creating new object", total);
        newBean = getCreatedBean();
        if (newBean != null) {
            monitor.setTaskName("Object created");
            monitor.worked(1);
            dboName = newBean.getName();
            if (!StringUtils.isNormalized(dboName))
                throw new EngineException("Bean name is not normalized : \"" + dboName + "\".");
            // Verify if a child object with same name exist and change name
            while (bContinue) {
                if (index == 0)
                    name = dboName;
                else
                    name = dboName + index;
                newBean.setName(name);
                newBean.hasChanged = true;
                newBean.bNew = true;
                try {
                    new WalkHelper() {

                        boolean root = true;

                        boolean find = false;

                        @Override
                        protected boolean before(DatabaseObject dbo, Class<? extends DatabaseObject> dboClass) {
                            boolean isInstance = dboClass.isInstance(newBean);
                            find |= isInstance;
                            return isInstance;
                        }

                        @Override
                        protected void walk(DatabaseObject dbo) throws Exception {
                            if (root) {
                                root = false;
                                super.walk(dbo);
                                if (!find) {
                                    throw new EngineException("You cannot add to a " + newBean.getClass().getSimpleName() + " a database object of type " + parentObject.getClass().getSimpleName());
                                }
                            } else {
                                if (newBean.getName().equalsIgnoreCase(dbo.getName())) {
                                    throw new ObjectWithSameNameException("Unable to add the object because an object with the same name already exists in target.");
                                }
                            }
                        }
                    }.init(parentObject);
                    bContinue = false;
                } catch (ObjectWithSameNameException owsne) {
                    if ((parentObject instanceof HtmlTransaction) && (newBean instanceof Statement)) {
                        throw new EngineException("HtmlTransaction already contains a statement named \"" + name + "\".", owsne);
                    }
                    // Silently ignore
                    index++;
                } catch (EngineException ee) {
                    throw ee;
                } catch (Exception e) {
                    throw new EngineException("Exception in create", e);
                }
            }
            // Now add bean to target
            try {
                boolean hasChanged = parentObject.hasChanged;
                if ((newBean instanceof Statement) && (parentObject instanceof Transaction)) {
                    newBean.priority = 0;
                }
                if (newBean instanceof ScreenClass)
                    newBean.priority = parentObject.priority + 1;
                if (newBean instanceof Criteria) {
                    Connector connector = parentObject.getConnector();
                    if (parentObject.equals(((IScreenClassContainer<?>) connector).getDefaultScreenClass()))
                        throw new EngineException("You cannot add a new criterion on default screenclass.");
                }
                parentObject.add(newBean);
                monitor.setTaskName("Object added");
                monitor.worked(1);
                if (newBean instanceof HTTPStatement) {
                    HTTPStatement httpStatement = (HTTPStatement) newBean;
                    HtmlConnector connector = (HtmlConnector) httpStatement.getParentTransaction().getParent();
                    httpStatement.setMethod("GET");
                    httpStatement.setHost(connector.getServer());
                    httpStatement.setPort(connector.getPort());
                    httpStatement.setHttps(connector.isHttps());
                }
                if (newBean instanceof ContinueWithSiteClipperStatement) {
                    Project project = newBean.getProject();
                    if (project != null) {
                        String[] connectorWithSiteClipperConnector = ContinueWithSiteClipperStatement.getSiteClippersConnectorNames(project);
                        if (connectorWithSiteClipperConnector.length > 0) {
                            ((ContinueWithSiteClipperStatement) newBean).setSiteClipperConnectorName(connectorWithSiteClipperConnector[0]);
                        }
                    }
                }
                if (newBean instanceof Connector) {
                    Project project = (Project) parentObject;
                    if (project.getDefaultConnector() == null)
                        project.setDefaultConnector((Connector) newBean);
                    Connector.setupConnector(newBean);
                }
                if (newBean instanceof PageComponent) {
                    ApplicationComponent application = (ApplicationComponent) parentObject;
                    if (application.getRootPage() == null)
                        application.setRootPage((PageComponent) newBean);
                }
                if (newBean instanceof SequenceStep) {
                    Project project = newBean.getProject();
                    ((SequenceStep) newBean).setSourceSequence(project.getName() + TransactionStep.SOURCE_SEPARATOR + project.getSequencesList().get(0));
                }
                if (newBean instanceof TransactionStep) {
                    Project project = newBean.getProject();
                    Connector connector = project.getDefaultConnector();
                    Transaction transaction = connector.getDefaultTransaction();
                    ((TransactionStep) newBean).setSourceTransaction(project.getName() + TransactionStep.SOURCE_SEPARATOR + connector.getName() + TransactionStep.SOURCE_SEPARATOR + transaction.getName());
                }
                if (newBean instanceof IThenElseContainer) {
                    ThenStep thenStep = new ThenStep();
                    ((IThenElseContainer) newBean).addStep(thenStep);
                    ElseStep elseStep = new ElseStep();
                    ((IThenElseContainer) newBean).addStep(elseStep);
                }
                if (newBean instanceof IThenElseStatementContainer) {
                    ThenStatement thenStatement = new ThenStatement();
                    ((IThenElseStatementContainer) newBean).addStatement(thenStatement);
                    ElseStatement elseStatement = new ElseStatement();
                    ((IThenElseStatementContainer) newBean).addStatement(elseStatement);
                }
                if (newBean instanceof Sheet) {
                    InputStream is = null;
                    try {
                        String sheetName = newBean.getName() + ".xsl";
                        is = new FileInputStream(new File(Engine.XSL_PATH + "/customsheet.xsl"));
                        String projectName = ((DatabaseObject) parentObject).getProject().getName();
                        IProject project = ConvertigoPlugin.getDefault().getProjectPluginResource(projectName);
                        final IFile file = project.getFile(sheetName);
                        if (!file.exists())
                            file.create(is, true, null);
                        ((Sheet) newBean).setUrl(sheetName);
                    } catch (Exception e) {
                    } finally {
                        if (is != null) {
                            try {
                                is.close();
                            } catch (IOException e) {
                            }
                        }
                    }
                }
                if (newBean instanceof TestCase) {
                    TestCase testCase = (TestCase) newBean;
                    testCase.importRequestableVariables((RequestableObject) testCase.getParent());
                }
                if (newBean instanceof RequestableHttpVariable) {
                    RequestableHttpVariable variable = (RequestableHttpVariable) newBean;
                    AbstractHttpTransaction httpTransaction = (AbstractHttpTransaction) variable.getParent();
                    HttpMethodType httpMethodType = httpTransaction.getHttpVerb();
                    boolean isVarPost = httpMethodType.equals(HttpMethodType.PUT) || httpMethodType.equals(HttpMethodType.POST);
                    variable.setHttpMethod(isVarPost ? HttpMethodType.POST.name() : HttpMethodType.GET.name());
                    if (!(httpTransaction instanceof HtmlTransaction)) {
                        variable.setHttpName(variable.getName());
                    }
                }
                if (newBean instanceof WebServiceReference) {
                    try {
                        Project project = (Project) parentObject;
                        WebServiceReference webServiceReference = (WebServiceReference) newBean;
                        ImportWsReference wsr = new ImportWsReference(webServiceReference);
                        wsr.importInto(project);
                    } catch (Exception e) {
                        if (newBean != null) {
                            parentObject.remove(newBean);
                            parentObject.hasChanged = hasChanged;
                        }
                        throw new Exception(e);
                    }
                }
                if (newBean instanceof RestServiceReference) {
                    try {
                        Project project = (Project) parentObject;
                        RestServiceReference restServiceReference = (RestServiceReference) newBean;
                        ImportWsReference wsr = new ImportWsReference(restServiceReference);
                        wsr.importInto(project);
                    } catch (Exception e) {
                        if (newBean != null) {
                            parentObject.remove(newBean);
                            parentObject.hasChanged = hasChanged;
                        }
                        throw new Exception(e);
                    }
                }
                if (newBean instanceof SqlTransaction) {
                    SqlTransaction sqlTransaction = (SqlTransaction) newBean;
                    sqlTransaction.setSqlQuery(sqlQueriesWizardPage.getSQLQueries());
                    sqlTransaction.initializeQueries(true);
                }
                if (newBean instanceof SapJcoLogonTransaction) {
                    SapJcoLogonTransaction sapLogonTransaction = (SapJcoLogonTransaction) newBean;
                    sapLogonTransaction.addCredentialsVariables();
                }
                if (newBean instanceof AbstractCouchDbTransaction) {
                    AbstractCouchDbTransaction abstractCouchDbTransaction = (AbstractCouchDbTransaction) newBean;
                    List<CouchVariable> selectedVariables = objectInfoPage.getSelectedParameters();
                    abstractCouchDbTransaction.createVariables(selectedVariables);
                }
                ConvertigoPlugin.logInfo("New object class '" + this.className + "' named '" + newBean.getName() + "' has been added");
                monitor.setTaskName("Object setted up");
                monitor.worked(1);
                bContinue = false;
            } catch (com.twinsoft.convertigo.engine.ObjectWithSameNameException owsne) {
                if (newBean instanceof HandlerStatement) {
                    throw owsne;
                }
            }
        } else {
            throw new Exception("Could not instantiate bean!");
        }
    } catch (Exception e) {
        String message = "Unable to create a new object from class '" + this.className + "'.";
        ConvertigoPlugin.logException(e, message);
        if (objectExplorerPage != null) {
            objectExplorerPage.doCancel();
        }
    }
}
Also used : RestServiceReference(com.twinsoft.convertigo.beans.references.RestServiceReference) RequestableHttpVariable(com.twinsoft.convertigo.beans.variables.RequestableHttpVariable) ContinueWithSiteClipperStatement(com.twinsoft.convertigo.beans.statements.ContinueWithSiteClipperStatement) IThenElseContainer(com.twinsoft.convertigo.beans.steps.IThenElseContainer) ElseStep(com.twinsoft.convertigo.beans.steps.ElseStep) HttpMethodType(com.twinsoft.convertigo.engine.enums.HttpMethodType) ScreenClass(com.twinsoft.convertigo.beans.core.ScreenClass) EngineException(com.twinsoft.convertigo.engine.EngineException) HTTPStatement(com.twinsoft.convertigo.beans.statements.HTTPStatement) AbstractHttpTransaction(com.twinsoft.convertigo.beans.transactions.AbstractHttpTransaction) DatabaseObject(com.twinsoft.convertigo.beans.core.DatabaseObject) SequenceStep(com.twinsoft.convertigo.beans.steps.SequenceStep) AbstractCouchDbTransaction(com.twinsoft.convertigo.beans.transactions.couchdb.AbstractCouchDbTransaction) ThenStatement(com.twinsoft.convertigo.beans.statements.ThenStatement) FileInputStream(java.io.FileInputStream) IProject(org.eclipse.core.resources.IProject) Project(com.twinsoft.convertigo.beans.core.Project) SqlTransaction(com.twinsoft.convertigo.beans.transactions.SqlTransaction) SapJcoLogonTransaction(com.twinsoft.convertigo.beans.transactions.SapJcoLogonTransaction) Transaction(com.twinsoft.convertigo.beans.core.Transaction) AbstractHttpTransaction(com.twinsoft.convertigo.beans.transactions.AbstractHttpTransaction) AbstractCouchDbTransaction(com.twinsoft.convertigo.beans.transactions.couchdb.AbstractCouchDbTransaction) HtmlTransaction(com.twinsoft.convertigo.beans.transactions.HtmlTransaction) ElseStatement(com.twinsoft.convertigo.beans.statements.ElseStatement) IFile(org.eclipse.core.resources.IFile) File(java.io.File) CouchVariable(com.twinsoft.convertigo.beans.transactions.couchdb.CouchVariable) HtmlConnector(com.twinsoft.convertigo.beans.connectors.HtmlConnector) Connector(com.twinsoft.convertigo.beans.core.Connector) SqlConnector(com.twinsoft.convertigo.beans.connectors.SqlConnector) IFile(org.eclipse.core.resources.IFile) SapJcoLogonTransaction(com.twinsoft.convertigo.beans.transactions.SapJcoLogonTransaction) WalkHelper(com.twinsoft.convertigo.engine.helpers.WalkHelper) Criteria(com.twinsoft.convertigo.beans.core.Criteria) HandlerStatement(com.twinsoft.convertigo.beans.statements.HandlerStatement) PageComponent(com.twinsoft.convertigo.beans.mobile.components.PageComponent) ThenStep(com.twinsoft.convertigo.beans.steps.ThenStep) ImportWsReference(com.twinsoft.convertigo.engine.util.ImportWsReference) IThenElseStatementContainer(com.twinsoft.convertigo.beans.statements.IThenElseStatementContainer) HtmlConnector(com.twinsoft.convertigo.beans.connectors.HtmlConnector) ElseStatement(com.twinsoft.convertigo.beans.statements.ElseStatement) HTTPStatement(com.twinsoft.convertigo.beans.statements.HTTPStatement) Statement(com.twinsoft.convertigo.beans.core.Statement) ContinueWithSiteClipperStatement(com.twinsoft.convertigo.beans.statements.ContinueWithSiteClipperStatement) ThenStatement(com.twinsoft.convertigo.beans.statements.ThenStatement) HandlerStatement(com.twinsoft.convertigo.beans.statements.HandlerStatement) ApplicationComponent(com.twinsoft.convertigo.beans.mobile.components.ApplicationComponent) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) HtmlTransaction(com.twinsoft.convertigo.beans.transactions.HtmlTransaction) SqlTransaction(com.twinsoft.convertigo.beans.transactions.SqlTransaction) IOException(java.io.IOException) CoreException(org.eclipse.core.runtime.CoreException) InvocationTargetException(java.lang.reflect.InvocationTargetException) EngineException(com.twinsoft.convertigo.engine.EngineException) IOException(java.io.IOException) ObjectWithSameNameException(com.twinsoft.convertigo.engine.ObjectWithSameNameException) IProject(org.eclipse.core.resources.IProject) TransactionStep(com.twinsoft.convertigo.beans.steps.TransactionStep) ObjectWithSameNameException(com.twinsoft.convertigo.engine.ObjectWithSameNameException) TestCase(com.twinsoft.convertigo.beans.core.TestCase) WebServiceReference(com.twinsoft.convertigo.beans.references.WebServiceReference) Sheet(com.twinsoft.convertigo.beans.core.Sheet) ObjectWithSameNameException(com.twinsoft.convertigo.engine.ObjectWithSameNameException)

Example 3 with WebServiceReference

use of com.twinsoft.convertigo.beans.references.WebServiceReference in project convertigo by convertigo.

the class ProjectImportWsReference 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();
            if (treeObject != null) {
                ProjectTreeObject projectTreeObject = null;
                RemoteFileReference reference = null;
                HttpConnector httpConnector = null;
                // Create a new  WS reference
                if (treeObject instanceof ProjectTreeObject) {
                    projectTreeObject = (ProjectTreeObject) treeObject;
                    if (wsType == TYPE_SOAP) {
                        reference = new WebServiceReference();
                        reference.bNew = true;
                    }
                    if (wsType == TYPE_REST) {
                        reference = new RestServiceReference();
                        reference.bNew = true;
                    }
                } else // Update an existing WS reference
                if (treeObject instanceof ReferenceTreeObject) {
                /* For further use
						ReferenceTreeObject referenceTreeObject = (ReferenceTreeObject)treeObject;
						webServiceReference = (WebServiceReference) referenceTreeObject.getObject();
						projectTreeObject = referenceTreeObject.getProjectTreeObject();*/
                }
                if (reference != null) {
                    WsReferenceImportDialog wsReferenceImportDialog = null;
                    if (wsType == TYPE_SOAP) {
                        wsReferenceImportDialog = new WsReferenceImportDialog(shell, WsSoapReferenceImportDialogComposite.class, "SOAP Web Service reference");
                    }
                    if (wsType == TYPE_REST) {
                        wsReferenceImportDialog = new WsReferenceImportDialog(shell, WsRestReferenceImportDialogComposite.class, "REST Web Service reference");
                    }
                    wsReferenceImportDialog.setProject(projectTreeObject.getObject());
                    wsReferenceImportDialog.setReference(reference);
                    wsReferenceImportDialog.open();
                    if (wsReferenceImportDialog.getReturnCode() != Window.CANCEL) {
                        httpConnector = wsReferenceImportDialog.getHttpConnector();
                    }
                    Project project = projectTreeObject.getObject();
                    Engine.theApp.schemaManager.clearCache(project.getName());
                    // Reload project in tree
                    explorerView.reloadTreeObject(projectTreeObject);
                    if (httpConnector != null && httpConnector.getParent() != null) {
                        explorerView.objectSelected(new CompositeEvent(httpConnector));
                    } else if (reference != null && reference.getParent() != null) {
                        if (reference.hasChanged)
                            projectTreeObject.hasBeenModified(true);
                        explorerView.objectSelected(new CompositeEvent(reference));
                    }
                }
            }
        }
    } catch (Throwable e) {
        ConvertigoPlugin.logException(e, "Unable to " + (updateMode ? "update" : "import") + " from remote WS definition!");
    } finally {
        shell.setCursor(null);
        waitCursor.dispose();
    }
}
Also used : RestServiceReference(com.twinsoft.convertigo.beans.references.RestServiceReference) HttpConnector(com.twinsoft.convertigo.beans.connectors.HttpConnector) ProjectExplorerView(com.twinsoft.convertigo.eclipse.views.projectexplorer.ProjectExplorerView) WsReferenceImportDialog(com.twinsoft.convertigo.eclipse.dialogs.WsReferenceImportDialog) WsRestReferenceImportDialogComposite(com.twinsoft.convertigo.eclipse.dialogs.WsRestReferenceImportDialogComposite) Cursor(org.eclipse.swt.graphics.Cursor) WsSoapReferenceImportDialogComposite(com.twinsoft.convertigo.eclipse.dialogs.WsSoapReferenceImportDialogComposite) Project(com.twinsoft.convertigo.beans.core.Project) Shell(org.eclipse.swt.widgets.Shell) ReferenceTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.ReferenceTreeObject) TreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.TreeObject) ReferenceTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.ReferenceTreeObject) ProjectTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.ProjectTreeObject) ProjectTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.ProjectTreeObject) RemoteFileReference(com.twinsoft.convertigo.beans.references.RemoteFileReference) WebServiceReference(com.twinsoft.convertigo.beans.references.WebServiceReference) CompositeEvent(com.twinsoft.convertigo.eclipse.editors.CompositeEvent) Display(org.eclipse.swt.widgets.Display)

Example 4 with WebServiceReference

use of com.twinsoft.convertigo.beans.references.WebServiceReference in project convertigo by convertigo.

the class NewProjectWizard method doFinish.

/**
 * The worker method. We create the project here according to the templateId
 * variable
 */
private void doFinish(IProgressMonitor monitor) throws CoreException {
    try {
        if (page10 != null) {
            projectName = page1.getProjectName();
            monitor.beginTask("Creating project " + projectName, 7);
            Project project = createFromBlankProject(monitor);
            boolean needAuth = page10.useAuthentication();
            String wsURL = page10.getWsdlURL().toString();
            String login = page10.getLogin();
            String password = page10.getPassword();
            WebServiceReference webWsReference = null;
            RestServiceReference restWsReference = null;
            RemoteFileReference reference = null;
            if (wizardId.equals("com.twinsoft.convertigo.eclipse.wizards.NewWebServiceSoapReferenceWizard")) {
                reference = webWsReference = new WebServiceReference();
            } else if (wizardId.equals("com.twinsoft.convertigo.eclipse.wizards.NewWebServiceSwaggerReferenceWizard")) {
                reference = restWsReference = new RestServiceReference();
            }
            reference.setUrlpath(wsURL);
            reference.setNeedAuthentication(needAuth);
            reference.setAuthUser(login == null ? "" : login);
            reference.setAuthUser(password == null ? "" : password);
            reference.bNew = true;
            ImportWsReference wsr = webWsReference != null ? new ImportWsReference(webWsReference) : new ImportWsReference(restWsReference);
            HttpConnector httpConnector = wsr.importInto(project);
            if (httpConnector != null) {
                Connector defaultConnector = project.getDefaultConnector();
                project.setDefaultConnector(httpConnector);
                defaultConnector.delete();
            }
        } else if (page1 != null) {
            projectName = page1.getProjectName();
            monitor.beginTask("Creating project " + projectName, 7);
            createFromBlankProject(monitor);
            return;
        } else if (pageSummarySampleProject != null) {
            monitor.beginTask("Creating project", 7);
            createFromArchiveProject(monitor);
            return;
        }
    } catch (Exception e) {
        ConvertigoPlugin.logException(e, "An error occured while creating the project", false);
        String message = "An error occured while creating the project (see Error log):\n" + e.getMessage();
        IStatus status = new Status(Status.ERROR, ConvertigoPlugin.PLUGIN_UNIQUE_ID, message, e);
        throw new CoreException(status);
    }
}
Also used : RestServiceReference(com.twinsoft.convertigo.beans.references.RestServiceReference) IStatus(org.eclipse.core.runtime.IStatus) Status(org.eclipse.core.runtime.Status) Connector(com.twinsoft.convertigo.beans.core.Connector) SapJcoConnector(com.twinsoft.convertigo.beans.connectors.SapJcoConnector) CicsConnector(com.twinsoft.convertigo.beans.connectors.CicsConnector) JavelinConnector(com.twinsoft.convertigo.beans.connectors.JavelinConnector) SiteClipperConnector(com.twinsoft.convertigo.beans.connectors.SiteClipperConnector) SqlConnector(com.twinsoft.convertigo.beans.connectors.SqlConnector) HttpConnector(com.twinsoft.convertigo.beans.connectors.HttpConnector) HttpConnector(com.twinsoft.convertigo.beans.connectors.HttpConnector) IStatus(org.eclipse.core.runtime.IStatus) CoreException(org.eclipse.core.runtime.CoreException) InvocationTargetException(java.lang.reflect.InvocationTargetException) JSONException(org.codehaus.jettison.json.JSONException) EngineException(com.twinsoft.convertigo.engine.EngineException) Project(com.twinsoft.convertigo.beans.core.Project) CoreException(org.eclipse.core.runtime.CoreException) RemoteFileReference(com.twinsoft.convertigo.beans.references.RemoteFileReference) ImportWsReference(com.twinsoft.convertigo.engine.util.ImportWsReference) WebServiceReference(com.twinsoft.convertigo.beans.references.WebServiceReference)

Example 5 with WebServiceReference

use of com.twinsoft.convertigo.beans.references.WebServiceReference in project convertigo by convertigo.

the class RemoteFileWizardPage method dialogChanged.

public void dialogChanged() {
    String message = null;
    if (!urlPath.isEmpty()) {
        try {
            URL url = new URL(urlPath);
            if (urlPath.startsWith("file:/")) {
                if (FileUtils.toFile(url).exists()) {
                    // wsRefAuthenticated.getFilterExtension()[0].split(";");
                    String[] filterExtensions = wsRefAuthenticated.getFilterExtension();
                    for (String fileFilter : filterExtensions) {
                        String fileExtension = fileFilter.substring(fileFilter.lastIndexOf("."));
                        if (!urlPath.endsWith(fileExtension)) {
                            message = "Please select a compatible file";
                        } else {
                            message = null;
                            break;
                        }
                    }
                } else {
                    message = "Please select an existing file";
                }
            }
        } catch (Exception e) {
            message = "Please enter a valid URL";
        }
    } else if (!filePath.equals("")) {
        File file = new File(filePath);
        if (!file.exists()) {
            message = "Please select an existing file";
        } else {
            // filterExtension[0].split(";");
            String[] filterExtensions = getFilterExtension();
            for (String fileFilter : filterExtensions) {
                String fileExtension = fileFilter.substring(fileFilter.lastIndexOf("."));
                if (!filePath.endsWith(fileExtension)) {
                    message = "Please select a compatible file";
                } else {
                    message = null;
                    break;
                }
            }
        }
    } else {
        message = "Please enter an URL!";
    }
    if (message == null) {
        if (useAuthentication.getSelection() && (loginText.getText().equals("") || passwordText.getText().equals(""))) {
            message = "Please enter login and password";
        }
    }
    if (message == null) {
        try {
            RemoteFileReference reference = (RemoteFileReference) getDbo();
            String localPath = "";
            if (urlPath.startsWith("file:/")) {
                localPath = getLocalFilePath(urlPath.substring("file:/".length()));
            }
            if (reference instanceof WebServiceReference || reference instanceof RestServiceReference) {
                reference.setUrlpath(urlPath);
                reference.setFilepath("");
            } else {
                reference.setUrlpath(localPath.isEmpty() ? urlPath : "");
                reference.setFilepath(localPath.isEmpty() ? "" : localPath);
            }
            if (useAuthentication.getSelection()) {
                reference.setNeedAuthentication(true);
                reference.setAuthUser(loginText.getText());
                reference.setAuthPassword(passwordText.getText());
            }
        } catch (Exception e) {
            message = e.getMessage();
        }
    }
    setTextStatus(message);
}
Also used : RestServiceReference(com.twinsoft.convertigo.beans.references.RestServiceReference) RemoteFileReference(com.twinsoft.convertigo.beans.references.RemoteFileReference) WebServiceReference(com.twinsoft.convertigo.beans.references.WebServiceReference) File(java.io.File) URL(java.net.URL) MalformedURLException(java.net.MalformedURLException)

Aggregations

RestServiceReference (com.twinsoft.convertigo.beans.references.RestServiceReference)6 WebServiceReference (com.twinsoft.convertigo.beans.references.WebServiceReference)6 RemoteFileReference (com.twinsoft.convertigo.beans.references.RemoteFileReference)4 Project (com.twinsoft.convertigo.beans.core.Project)3 EngineException (com.twinsoft.convertigo.engine.EngineException)3 ImportWsReference (com.twinsoft.convertigo.engine.util.ImportWsReference)3 HttpConnector (com.twinsoft.convertigo.beans.connectors.HttpConnector)2 SqlConnector (com.twinsoft.convertigo.beans.connectors.SqlConnector)2 Connector (com.twinsoft.convertigo.beans.core.Connector)2 File (java.io.File)2 URL (java.net.URL)2 CicsConnector (com.twinsoft.convertigo.beans.connectors.CicsConnector)1 HtmlConnector (com.twinsoft.convertigo.beans.connectors.HtmlConnector)1 JavelinConnector (com.twinsoft.convertigo.beans.connectors.JavelinConnector)1 SapJcoConnector (com.twinsoft.convertigo.beans.connectors.SapJcoConnector)1 SiteClipperConnector (com.twinsoft.convertigo.beans.connectors.SiteClipperConnector)1 Criteria (com.twinsoft.convertigo.beans.core.Criteria)1 DatabaseObject (com.twinsoft.convertigo.beans.core.DatabaseObject)1 ScreenClass (com.twinsoft.convertigo.beans.core.ScreenClass)1 Sheet (com.twinsoft.convertigo.beans.core.Sheet)1