Search in sources :

Example 46 with XmlException

use of org.apache.xmlbeans.XmlException in project mdw-designer by CenturyLinkCloud.

the class DesignerDataAccess method retryActivity.

public void retryActivity(Long activityId, Long activityInstId) throws DataAccessException, XmlException, IOException {
    if (currentServer.isSchemaVersion61()) {
        ((RestfulServer) currentServer).retryActivityInstance(activityInstId, ActivityResultCodeConstant.RESULT_RETRY);
    } else {
        String request = currentServer.buildRetryActivityInstanceRequest(activityId, activityInstId, false);
        String response = this.engineCall(request);
        try {
            String result = currentServer.getErrorMessageFromResponse(response);
            if (result == null || result.length() > 0)
                throw new RemoteException(result);
            auditLog(Action.Retry, Entity.ActivityInstance, activityInstId, null);
        } catch (XmlException e) {
            throw new DataAccessException("Response is not an MDWStatusMessage");
        }
    }
}
Also used : XmlException(org.apache.xmlbeans.XmlException) RestfulServer(com.centurylink.mdw.designer.utils.RestfulServer) RemoteException(java.rmi.RemoteException) DataAccessException(com.centurylink.mdw.common.exception.DataAccessException)

Example 47 with XmlException

use of org.apache.xmlbeans.XmlException in project mdw-designer by CenturyLinkCloud.

the class ActivityInstanceDialog method createButtonsForButtonBar.

protected void createButtonsForButtonBar(Composite parent) {
    if (mode.equals(Mode.VIEW)) {
        createButton(parent, IDialogConstants.OK_ID, IDialogConstants.OK_LABEL, true);
        return;
    }
    if (mode.equals(Mode.RETRY)) {
        retryButton = createButton(parent, -1, "Retry", false);
        retryButton.addSelectionListener(new SelectionAdapter() {

            @Override
            public void widgetSelected(SelectionEvent e) {
                BusyIndicator.showWhile(getShell().getDisplay(), new Runnable() {

                    public void run() {
                        statusMessage = activity.getProject().getDesignerProxy().retryActivityInstance(activity, activityInstanceVO);
                    }
                });
                if (statusMessage == null || statusMessage.trim().length() == 0)
                    MessageDialog.openInformation(getShell(), "Retry Activity", "Activity instance: " + activityInstanceVO.getId() + " retried");
                else if (statusMessage.startsWith("{")) {
                    try {
                        JSONObject json = new JSONObject(statusMessage);
                        StatusMessage status = null;
                        if (json.has("status"))
                            status = new StatusMessage(json);
                        if (status.getCode() == 0)
                            MessageDialog.openInformation(getShell(), "Retry Activity", "Activity instance: " + activityInstanceVO.getId() + " retried");
                        else
                            MessageDialog.openError(getShell(), "Retry Activity", status.getMessage());
                    } catch (JSONException e1) {
                        MessageDialog.openError(getShell(), "Retry Activity", statusMessage);
                    } catch (XmlException e1) {
                        MessageDialog.openError(getShell(), "Retry Activity", statusMessage);
                    }
                } else
                    MessageDialog.openError(getShell(), "Retry Activity", statusMessage);
                close();
            }
        });
        if (!activity.getProcess().isUserAuthorized(UserRoleVO.PROCESS_EXECUTION))
            retryButton.setEnabled(false);
    }
    if (mode.equals(Mode.SKIP)) {
        skipButton = createButton(parent, -1, "Proceed", false);
        skipButton.addSelectionListener(new SelectionAdapter() {

            @Override
            public void widgetSelected(SelectionEvent e) {
                BusyIndicator.showWhile(getShell().getDisplay(), new Runnable() {

                    public void run() {
                        statusMessage = activity.getProject().getDesignerProxy().skipActivityInstance(activity, activityInstanceVO, completionCode);
                    }
                });
                if (statusMessage == null || statusMessage.trim().length() == 0)
                    MessageDialog.openInformation(getShell(), "Skip Activity", "Activity instance: " + activityInstanceVO.getId() + " skipped with completion code: " + completionCode + ".");
                if (statusMessage.startsWith("{")) {
                    try {
                        JSONObject json = new JSONObject(statusMessage);
                        StatusMessage status = null;
                        if (json.has("status"))
                            status = new StatusMessage(json);
                        if (status.getCode() == 0)
                            MessageDialog.openInformation(getShell(), "Skip Activity", "Activity instance: " + activityInstanceVO.getId() + " skipped with completion code: " + completionCode + ".");
                        else
                            MessageDialog.openError(getShell(), "Skip Activity", status.getMessage());
                    } catch (JSONException e1) {
                        MessageDialog.openError(getShell(), "Skip Activity", statusMessage);
                    } catch (XmlException e1) {
                        MessageDialog.openError(getShell(), "Skip Activity", statusMessage);
                    }
                } else
                    MessageDialog.openError(getShell(), "Skip Activity", statusMessage);
                close();
            }
        });
        if (!activity.getProcess().isUserAuthorized(UserRoleVO.PROCESS_EXECUTION))
            skipButton.setEnabled(false);
    }
    createButton(parent, IDialogConstants.CANCEL_ID, IDialogConstants.CANCEL_LABEL, true);
}
Also used : JSONObject(org.json.JSONObject) XmlException(org.apache.xmlbeans.XmlException) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) SelectionEvent(org.eclipse.swt.events.SelectionEvent) JSONException(org.json.JSONException) StatusMessage(com.centurylink.mdw.common.service.types.StatusMessage)

Example 48 with XmlException

use of org.apache.xmlbeans.XmlException in project mdw-designer by CenturyLinkCloud.

the class WorkflowProjectManager method discoverWorkflowApps.

public List<WorkflowApplication> discoverWorkflowApps() throws DiscoveryException {
    String urlBase = MdwPlugin.getSettings().getProjectDiscoveryUrl();
    if (!urlBase.endsWith("/"))
        urlBase += "/";
    String ctxRoot = urlBase.endsWith("Discovery/") ? "" : "MDWWeb/";
    if (urlBase.indexOf("lxdnd696") >= 0)
        // old discovery server
        ctxRoot = "MDWExampleWeb/";
    String path = urlBase.endsWith("Discovery/") ? "ConfigManagerProjects.xml" : "Services/GetConfigFile?name=ConfigManagerProjects.xml";
    String cfgMgrUrl = urlBase + ctxRoot + path;
    try {
        URL url = new URL(cfgMgrUrl);
        HttpHelper httpHelper = new HttpHelper(url);
        httpHelper.setConnectTimeout(MdwPlugin.getSettings().getHttpConnectTimeout());
        httpHelper.setReadTimeout(MdwPlugin.getSettings().getHttpReadTimeout());
        String xml = httpHelper.get();
        ConfigManagerProjectsDocument doc = ConfigManagerProjectsDocument.Factory.parse(xml, Compatibility.namespaceOptions());
        return doc.getConfigManagerProjects().getWorkflowAppList();
    } catch (XmlException ex) {
        PluginMessages.log(ex);
        throw new DiscoveryException("Unable to obtain/parse Config Manager info from " + cfgMgrUrl);
    } catch (Exception ex) {
        throw new DiscoveryException(ex.getMessage(), ex);
    }
}
Also used : ConfigManagerProjectsDocument(com.centurylink.mdw.workflow.ConfigManagerProjectsDocument) XmlException(org.apache.xmlbeans.XmlException) HttpHelper(com.centurylink.mdw.common.utilities.HttpHelper) DiscoveryException(com.centurylink.mdw.plugin.designer.DiscoveryException) URL(java.net.URL) ResourceException(org.eclipse.core.internal.resources.ResourceException) CoreException(org.eclipse.core.runtime.CoreException) JavaModelException(org.eclipse.jdt.core.JavaModelException) MdwSecurityException(com.centurylink.mdw.auth.MdwSecurityException) DiscoveryException(com.centurylink.mdw.plugin.designer.DiscoveryException) XmlException(org.apache.xmlbeans.XmlException)

Example 49 with XmlException

use of org.apache.xmlbeans.XmlException in project mdw-designer by CenturyLinkCloud.

the class ImportPackagePage method populateTopFolder.

public Folder populateTopFolder(String discoveryUrl, String groupId, boolean latestVersionsOnly, IProgressMonitor progressMonitor) throws Exception {
    Folder folder = null;
    getImportPackageWizard().getImportPackageSelectPage().clear();
    if (discoveryUrl != null || groupId != null) {
        if (discoveryUrl != null) {
            if (getProject().checkRequiredVersion(6, 0, 13))
                folder = new Discoverer(new URL(discoveryUrl), getProject().getHttpHelper(discoveryUrl)).getAssetTopFolder(latestVersionsOnly, progressMonitor);
            else
                folder = new Discoverer(new URL(discoveryUrl)).getAssetTopFolder(latestVersionsOnly, progressMonitor);
        }
        if (groupId != null)
            folder = new Discoverer(groupId).getAssetTopFolder(latestVersionsOnly, progressMonitor);
        if (getProject().isRemote() && getProject().isGitVcs()) {
            List<Folder> emptyFolders = removeGitVersionedPackages(folder);
            List<Folder> emptyParents = new ArrayList<>();
            for (Folder emptyFolder : emptyFolders) {
                if (emptyFolder.getParent() instanceof Folder) {
                    Folder parent = emptyFolder.getParent();
                    parent.getChildren().remove(emptyFolder);
                    // go one more level up
                    if (parent.getChildren().isEmpty() && !emptyParents.contains(parent))
                        emptyParents.add(parent);
                }
            }
            for (Folder emptyParent : emptyParents) {
                if (emptyParent.getParent() instanceof Folder)
                    (emptyParent.getParent()).getChildren().remove(emptyParent);
            }
        }
    } else {
        String filepath = filePathText.getText().trim();
        String contents = FileHelper.getFileContents(filepath);
        folder = new Folder(filepath);
        boolean hasOldImpls = false;
        if (contents.trim().startsWith("{")) {
            ImporterExporterJson importer = new ImporterExporterJson();
            List<PackageVO> packages = importer.importPackages(contents);
            for (PackageVO pkg : packages) {
                if (getProject().isRemote() && getProject().isGitVcs()) {
                    for (WorkflowPackage existingVcs : getProject().getTopLevelPackages()) {
                        if (existingVcs.getName().equals(pkg.getName()))
                            getImportPackageWizard().getImportPackageSelectPage().setError(PKG_EXISTS + pkg.getName());
                    }
                }
                File aFile = new File(folder, pkg.getName() + " v" + pkg.getVersionString());
                ImporterExporterJson jsonExporter = new ImporterExporterJson();
                List<PackageVO> pkgs = new ArrayList<>();
                pkgs.add(pkg);
                JSONObject pkgJson = new JSONObject(jsonExporter.exportPackages(pkgs));
                pkgJson.put("name", pkg.getName());
                aFile.setContent(pkgJson.toString(2));
                folder.addChild(aFile);
            }
            preselected = folder;
        } else {
            try {
                // try and parse as multiple packages
                PackageDocument pkgDoc = PackageDocument.Factory.parse(contents);
                QName docElement = new QName("http://mdw.centurylink.com/bpm", "processDefinition");
                for (MDWProcessDefinition pkgDef : pkgDoc.getPackage().getProcessDefinitionList()) {
                    if (getProject().isRemote() && getProject().isGitVcs()) {
                        for (WorkflowPackage existingVcs : getProject().getTopLevelPackages()) {
                            if (existingVcs.getName().equals(pkgDef.getPackageName()))
                                getImportPackageWizard().getImportPackageSelectPage().setError(PKG_EXISTS + pkgDef.getPackageName());
                        }
                    }
                    if (!hasOldImpls && getProject().isFilePersist() && !getProject().isRemote())
                        hasOldImpls = checkForOldImplementors(pkgDef);
                    File aFile = new File(folder, pkgDef.getPackageName() + " v" + pkgDef.getPackageVersion());
                    aFile.setContent(pkgDef.xmlText(new XmlOptions().setSaveOuter().setSaveSyntheticDocumentElement(docElement)));
                    folder.addChild(aFile);
                }
                preselected = folder;
            } catch (XmlException ex) {
                // unparseable -- assume single package
                if (getProject().isRemote() && getProject().isGitVcs()) {
                    MDWProcessDefinition procDef = ProcessDefinitionDocument.Factory.parse(contents, Compatibility.namespaceOptions()).getProcessDefinition();
                    for (WorkflowPackage existingVcs : getProject().getTopLevelPackages()) {
                        if (existingVcs.getName().equals(procDef.getPackageName()))
                            getImportPackageWizard().getImportPackageSelectPage().setError(PKG_EXISTS + procDef.getPackageName());
                    }
                }
                if (getProject().isFilePersist() && !getProject().isRemote())
                    hasOldImpls = checkForOldImplementors(ProcessDefinitionDocument.Factory.parse(contents, Compatibility.namespaceOptions()).getProcessDefinition());
                File file = new File(folder, filepath);
                file.setContent(contents);
                folder.addChild(file);
                preselected = file;
            }
        }
        getImportPackageWizard().setHasOldImplementors(hasOldImpls);
    }
    return folder;
}
Also used : WorkflowPackage(com.centurylink.mdw.plugin.designer.model.WorkflowPackage) PackageVO(com.centurylink.mdw.model.value.process.PackageVO) QName(javax.xml.namespace.QName) XmlOptions(org.apache.xmlbeans.XmlOptions) ArrayList(java.util.ArrayList) MDWProcessDefinition(com.centurylink.mdw.bpm.MDWProcessDefinition) Discoverer(com.centurylink.mdw.plugin.designer.Discoverer) Folder(com.centurylink.mdw.plugin.designer.model.Folder) URL(java.net.URL) PackageDocument(com.centurylink.mdw.bpm.PackageDocument) JSONObject(org.json.JSONObject) XmlException(org.apache.xmlbeans.XmlException) File(com.centurylink.mdw.plugin.designer.model.File) ImporterExporterJson(com.centurylink.mdw.dataaccess.file.ImporterExporterJson)

Example 50 with XmlException

use of org.apache.xmlbeans.XmlException in project knime-core by knime.

the class PMMLPortObject method loadFrom.

/**
 * Initializes the pmml port object based on the xml input stream.
 * @param spec the referring spec of this object
 * @param is the pmml input stream
 * @throws IOException if the file cannot be found
 * @throws XmlException if something goes wrong during reading
 */
public void loadFrom(final PMMLPortObjectSpec spec, final InputStream is) throws IOException, XmlException {
    // disallow close in the factory -- we had indeterministic behavior
    // where close was called more than once (which should be OK) but as
    // the argument input stream is a NonClosableZipInput, which delegates
    // close to closeEntry(), we have to make sure that close is only
    // called once.
    // TODO: The document is read twice here. Could we "probe" into the file to check the version?
    XmlObject xmlDoc = null;
    Thread current = Thread.currentThread();
    ClassLoader oldLoader = current.getContextClassLoader();
    current.setContextClassLoader(PMMLDocument.class.getClassLoader());
    try (NonClosableInputStream nonClosableIn = new NonClosableInputStream(is)) {
        xmlDoc = XmlObject.Factory.parse(nonClosableIn);
    } finally {
        current.setContextClassLoader(oldLoader);
        // call only once (see above)
        is.close();
    }
    if (xmlDoc instanceof PMMLDocument) {
        m_pmmlDoc = (PMMLDocument) xmlDoc;
    } else {
        /* Try to recover when reading a PMML 3.x/4.0 document that
             * was produced by KNIME by just replacing the PMML version and
             * namespace. */
        if (PMMLUtils.isOldKNIMEPMML(xmlDoc) || PMMLUtils.is4_1PMML(xmlDoc)) {
            try {
                String updatedPMML = PMMLUtils.getUpdatedVersionAndNamespace(xmlDoc);
                /* Parse the modified document and assign it to a
                     * PMMLDocument.*/
                m_pmmlDoc = PMMLDocument.Factory.parse(updatedPMML);
            } catch (Exception e) {
                throw new RuntimeException("Parsing of PMML v 3.x/4.0 document failed.", e);
            }
            LOGGER.info("KNIME produced PMML 3.x/4.0  converted to PMML 4.1.");
        } else {
            throw new RuntimeException("Parsing of PMML v 3.x/4.0 document failed.");
        }
    }
    m_spec = spec;
}
Also used : NonClosableInputStream(org.knime.core.data.util.NonClosableInputStream) XmlObject(org.apache.xmlbeans.XmlObject) PMMLDocument(org.dmg.pmml.PMMLDocument) SAXException(org.xml.sax.SAXException) IOException(java.io.IOException) XmlException(org.apache.xmlbeans.XmlException) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException)

Aggregations

XmlException (org.apache.xmlbeans.XmlException)112 XmlObject (org.apache.xmlbeans.XmlObject)45 IOException (java.io.IOException)35 DecodingException (org.n52.svalbard.decode.exception.DecodingException)19 EncodingException (org.n52.svalbard.encode.exception.EncodingException)17 POIXMLException (org.apache.poi.POIXMLException)15 InputStream (java.io.InputStream)11 ArrayList (java.util.ArrayList)10 XmlCursor (org.apache.xmlbeans.XmlCursor)10 XmlOptions (org.apache.xmlbeans.XmlOptions)10 OpenXML4JException (org.apache.poi.openxml4j.exceptions.OpenXML4JException)8 POIXMLDocumentPart (org.apache.poi.POIXMLDocumentPart)7 AbstractFeature (org.n52.shetland.ogc.gml.AbstractFeature)7 Geometry (org.locationtech.jts.geom.Geometry)6 Document (org.w3c.dom.Document)6 Node (org.w3c.dom.Node)6 DataAccessException (com.centurylink.mdw.common.exception.DataAccessException)5 ByteArrayInputStream (java.io.ByteArrayInputStream)5 ByteArrayOutputStream (java.io.ByteArrayOutputStream)5 File (java.io.File)5