Search in sources :

Example 11 with DataAccessException

use of com.centurylink.mdw.common.exception.DataAccessException in project mdw-designer by CenturyLinkCloud.

the class DesignerDataAccess method verifyClass.

public String verifyClass(ActivityImplementorVO implementor, String packageName) throws RemoteException, DataAccessException {
    StringBuilder sb = new StringBuilder();
    sb.append("<_mdw_check_implementor>");
    sb.append("<class_name>").append(implementor.getImplementorClassName()).append("</class_name>");
    if (packageName != null)
        sb.append("<package_name>").append(packageName).append("</package_name>");
    sb.append("</_mdw_check_implementor>");
    String result = this.engineCall(sb.toString());
    if (!result.startsWith("<PAGELET"))
        throw new DataAccessException(result);
    return result;
}
Also used : DataAccessException(com.centurylink.mdw.common.exception.DataAccessException)

Example 12 with DataAccessException

use of com.centurylink.mdw.common.exception.DataAccessException in project mdw-designer by CenturyLinkCloud.

the class Importer method importPackage.

public void importPackage(String xml, boolean overwrite) throws DataAccessException, RemoteException, ActionCancelledException, XmlException {
    int preexistingVersion = -1;
    System.out.println("Parsing XML...");
    importedPackageVO = parsePackageXml(xml);
    PackageVO existing = null;
    try {
        existing = dataAccess.getPackage(importedPackageVO.getPackageName());
    } catch (DataAccessException ex) {
        if (!ex.getMessage().startsWith("Package does not exist:"))
            throw ex;
    }
    if (existing != null) {
        if (existing.getVersion() == importedPackageVO.getVersion()) {
            String msg = "Target already contains Package '" + importedPackageVO.getPackageName() + "' v" + importedPackageVO.getVersionString();
            if (!overwrite)
                throw new ActionCancelledException(msg + " and overwrite argument NOT specified.");
            else
                System.out.println(msg + " -- will overwrite existing package.");
            // overwrite existing
            importedPackageVO.setPackageId(existing.getId());
            if (!isLocal())
                importedPackageVO.setVersion(0);
            preexistingVersion = existing.getVersion();
        } else if (existing.getVersion() > importedPackageVO.getVersion()) {
            String msg = "Target already contains Package '" + importedPackageVO.getPackageName() + "' v" + existing.getVersionString() + ", whose version is greater than that of the imported package.  Cannot continue.";
            throw new ActionCancelledException(msg);
        }
    }
    System.out.println("Checking elements...");
    final List<RuleSetVO> conflicts = new ArrayList<>();
    final List<RuleSetVO> conflictsWithDifferences = new ArrayList<>();
    List<ProcessVO> existingProcessVOs = new ArrayList<>();
    List<ProcessVO> processVOsToBeImported = new ArrayList<>();
    ProcessExporter exporter = null;
    System.out.println("Comparing processes...");
    for (ProcessVO importedProcessVO : importedPackageVO.getProcesses()) {
        ProcessVO existingProcess = null;
        try {
            existingProcess = dataAccess.getProcessDefinition(importedProcessVO.getProcessName(), importedProcessVO.getVersion());
        } catch (DataAccessException ex) {
            // trap process does not exist
            if (!ex.getMessage().startsWith("Process does not exist;"))
                throw ex;
        }
        if (existingProcess != null) {
            conflicts.add(existingProcess);
            if (dataAccess.getSupportedSchemaVersion() >= DataAccess.schemaVersion52) {
                // content comparison
                if (exporter == null) {
                    boolean isOldNamespaces = dataAccess.getDatabaseSchemaVersion() < DataAccess.schemaVersion55;
                    exporter = DataAccess.getProcessExporter(dataAccess.getDatabaseSchemaVersion(), isOldNamespaces ? DesignerCompatibility.getInstance() : null);
                }
                String existingProcessXml = dataAccess.getRuleSet(existingProcess.getId()).getRuleSet();
                String importedProcessXml = exporter.exportProcess(importedProcessVO, dataAccess.getDatabaseSchemaVersion(), null);
                if (dataAccess.getSupportedSchemaVersion() < DataAccess.schemaVersion55) {
                    // may need to replace old namespace prefix in existing
                    // to avoid false positives in 5.2
                    String oldNamespaceDecl = "xmlns:xs=\"http://mdw.qwest.com/XMLSchema\"";
                    int oldNsIdx = existingProcessXml.indexOf(oldNamespaceDecl);
                    if (oldNsIdx > 0) {
                        String newNamespaceDecl = "xmlns:bpm=\"http://mdw.qwest.com/XMLSchema\"";
                        existingProcessXml = existingProcessXml.substring(0, oldNsIdx) + newNamespaceDecl + importedProcessXml.substring(oldNsIdx + oldNamespaceDecl.length() + 2);
                        existingProcessXml = existingProcessXml.replaceAll("<xs:", "<bpm:");
                        existingProcessXml = existingProcessXml.replaceAll("</xs:", "</bpm:");
                    }
                }
                // avoid false positives
                existingProcessXml = existingProcessXml.replaceAll("\\s*<bpm:Attribute Name=\"REFERENCED_ACTIVITIES\".*/>", "");
                existingProcessXml = existingProcessXml.replaceAll("\\s*<bpm:Attribute Name=\"REFERENCED_PROCESSES\".*/>", "");
                existingProcessXml = existingProcessXml.replaceFirst(" packageVersion=\"0.0\"", "");
                existingProcessXml = existingProcessXml.replaceAll("\\s*<bpm:Attribute Name=\"processid\".*/>", "");
                if (!existingProcessXml.equals(importedProcessXml))
                    conflictsWithDifferences.add(existingProcess);
            }
            if (isLocal())
                processVOsToBeImported.add(importedProcessVO);
            else
                existingProcessVOs.add(existingProcess);
        } else {
            if (dataAccess.getSupportedSchemaVersion() >= DataAccess.schemaVersion52)
                // not optional
                importedProcessVO.setInRuleSet(true);
            processVOsToBeImported.add(importedProcessVO);
        }
        for (ProcessVO subProcVO : importedProcessVO.getSubProcesses()) {
            ProcessVO existingSubProc = null;
            try {
                existingSubProc = dataAccess.getProcessDefinition(subProcVO.getProcessName(), subProcVO.getVersion());
            } catch (DataAccessException ex) {
                // trap process does not exist
                if (!ex.getMessage().startsWith("Process does not exist;"))
                    throw ex;
            }
            if (existingSubProc != null) {
                conflicts.add(existingSubProc);
                existingProcessVOs.add(existingSubProc);
                if (!isLocal())
                    existingProcessVOs.add(existingSubProc);
            }
        }
    }
    List<RuleSetVO> existingRuleSets = new ArrayList<>();
    List<RuleSetVO> ruleSetsToBeImported = new ArrayList<>();
    List<RuleSetVO> emptyRuleSets = new ArrayList<>();
    if (importedPackageVO.getRuleSets() != null) {
        System.out.println("Comparing assets...");
        for (RuleSetVO importedRuleSet : importedPackageVO.getRuleSets()) {
            RuleSetVO existingAsset = null;
            if (dataAccess.getSupportedSchemaVersion() >= DataAccess.schemaVersion55) {
                // supports same-named assets in different packages
                if (existing != null) {
                    RuleSetVO latestAsset = dataAccess.getRuleSet(existing.getPackageId(), importedRuleSet.getName());
                    if (latestAsset != null && latestAsset.getVersion() >= importedRuleSet.getVersion())
                        existingAsset = latestAsset;
                }
            } else {
                existingAsset = dataAccess.getRuleSet(importedRuleSet.getName(), importedRuleSet.getLanguage(), importedRuleSet.getVersion());
            }
            if (existingAsset != null) {
                conflicts.add(existingAsset);
                if (dataAccess.getSupportedSchemaVersion() >= DataAccess.schemaVersion52) {
                    // content comparison
                    existingAsset = dataAccess.getRuleSet(existingAsset.getId());
                    String existingAssetStr = existingAsset.getRuleSet().trim();
                    String importedAssetStr = importedRuleSet.getRuleSet().trim();
                    if (!existingAsset.isBinary()) {
                        existingAssetStr = existingAssetStr.replaceAll("\r", "");
                        importedAssetStr = importedAssetStr.replaceAll("\r", "");
                    }
                    if (!existingAssetStr.equals(importedAssetStr))
                        conflictsWithDifferences.add(existingAsset);
                }
                if (isLocal())
                    ruleSetsToBeImported.add(importedRuleSet);
                else
                    existingRuleSets.add(existingAsset);
            } else if (importedRuleSet.getRuleSet().trim().isEmpty()) {
                emptyRuleSets.add(importedRuleSet);
            } else {
                ruleSetsToBeImported.add(importedRuleSet);
            }
        }
    }
    if (existing != null && importedPackageVO.getTaskTemplates() != null && existing.getTaskTemplates() != null) {
        for (TaskVO importedTask : importedPackageVO.getTaskTemplates()) {
            for (TaskVO taskTemplate : existing.getTaskTemplates()) {
                if (taskTemplate.getName().equals(importedTask.getName()) && taskTemplate.getVersion() == importedTask.getVersion()) {
                    conflicts.add(taskTemplate);
                    String existingTemplStr = taskTemplate.toTemplate().xmlText();
                    String importedTemplStr = importedTask.toTemplate().xmlText();
                    if (!existingTemplStr.equals(importedTemplStr))
                        conflictsWithDifferences.add(taskTemplate);
                }
            }
        }
    }
    if (!conflicts.isEmpty()) {
        Collections.sort(conflicts, new Comparator<RuleSetVO>() {

            public int compare(RuleSetVO rs1, RuleSetVO rs2) {
                return rs1.getLabel().compareToIgnoreCase(rs2.getLabel());
            }
        });
        String msg;
        if (isLocal())
            msg = "The following versions exist locally in '" + importedPackageVO.getPackageName() + "' and will be overwritten:";
        else
            msg = "The following versions from package '" + importedPackageVO.getPackageName() + "' will not be imported:\n(The same or later versions already exist in the target environment";
        if (dataAccess.getDatabaseSchemaVersion() >= DataAccess.schemaVersion52)
            msg += " -- * indicates content differs";
        msg += ").";
        System.out.println(msg);
        for (RuleSetVO rs : conflicts) {
            String flag = conflictsWithDifferences.contains(rs) ? " *" : "";
            System.out.println("   " + rs.getLabel() + flag);
        }
    }
    if (!emptyRuleSets.isEmpty()) {
        System.out.println("The following assets from package '" + importedPackageVO.getPackageName() + "' will not be imported because they're empty:");
        for (RuleSetVO rs : emptyRuleSets) System.out.println("   " + rs.getLabel());
    }
    importedPackageVO.setProcesses(processVOsToBeImported);
    importedPackageVO.setRuleSets(ruleSetsToBeImported);
    // designer fix for backward compatibility
    ProcessWorker worker = new ProcessWorker();
    if (importedPackageVO.getProcesses() != null) {
        NodeMetaInfo nodeMetaInfo = new NodeMetaInfo();
        nodeMetaInfo.init(dataAccess.getActivityImplementors(), dataAccess.getDatabaseSchemaVersion());
        NodeMetaInfo syncedNodeMetaInfo = syncNodeMetaInfo(nodeMetaInfo, importedPackageVO);
        for (ProcessVO p : importedPackageVO.getProcesses()) {
            worker.convert_to_designer(p);
            worker.convert_from_designer(p, syncedNodeMetaInfo);
        }
    }
    System.out.println("Saving package...");
    if (isLocal())
        dataAccess.savePackageNoAudit(importedPackageVO, ProcessPersister.PersistType.IMPORT);
    else
        dataAccess.savePackage(importedPackageVO, ProcessPersister.PersistType.IMPORT);
    if (preexistingVersion > 0)
        // reset version
        importedPackageVO.setVersion(preexistingVersion);
    if (importedPackageVO.getProcesses() != null) {
        System.out.println("Reloading processes...");
        for (ProcessVO importedProcessVO : importedPackageVO.getProcesses()) {
            ProcessVO reloaded = dataAccess.getProcessDefinition(importedProcessVO.getProcessName(), importedProcessVO.getVersion());
            importedProcessVO.setProcessId(reloaded.getProcessId());
        }
        if (dataAccess.getSupportedSchemaVersion() < DataAccess.schemaVersion52) {
            for (ProcessVO importedProcessVO : importedPackageVO.getProcesses()) updateSubProcessIdAttributes(importedProcessVO);
        }
    }
    if (!existingProcessVOs.isEmpty()) {
        // add back existing processes
        importedPackageVO.getProcesses().addAll(existingProcessVOs);
        dataAccess.savePackage(importedPackageVO);
    }
    if (importedPackageVO.getRuleSets() != null) {
        System.out.println("Reloading workflow assets");
        for (RuleSetVO importedRuleSet : importedPackageVO.getRuleSets()) {
            RuleSetVO reloaded;
            if (dataAccess.getSupportedSchemaVersion() >= DataAccess.schemaVersion55) {
                reloaded = dataAccess.getRuleSet(importedPackageVO.getId(), importedRuleSet.getName());
                if (// need to verify whether the above is
                reloaded == null)
                    // even needed
                    reloaded = dataAccess.getRuleSet(importedRuleSet.getId());
            } else {
                reloaded = dataAccess.getRuleSet(importedRuleSet.getName(), importedRuleSet.getLanguage(), importedRuleSet.getVersion());
            }
            importedRuleSet.setId(reloaded.getId());
        }
    }
    if (!existingRuleSets.isEmpty()) {
        importedPackageVO.getRuleSets().addAll(existingRuleSets);
        System.out.println("Saving Package...");
        if (isLocal())
            dataAccess.savePackageNoAudit(importedPackageVO);
        else
            dataAccess.savePackage(importedPackageVO);
    }
    if (preexistingVersion > 0 && existingProcessVOs.isEmpty() && existingRuleSets.isEmpty()) {
        System.out.println("Saving Package...");
        if (isLocal())
            // force
            dataAccess.savePackageNoAudit(importedPackageVO);
        else
            // associate
            // processes
            // force associate
            dataAccess.savePackage(importedPackageVO);
    // processes
    }
}
Also used : NodeMetaInfo(com.centurylink.mdw.designer.utils.NodeMetaInfo) PackageVO(com.centurylink.mdw.model.value.process.PackageVO) ArrayList(java.util.ArrayList) ProcessExporter(com.centurylink.mdw.dataaccess.ProcessExporter) RuleSetVO(com.centurylink.mdw.model.value.attribute.RuleSetVO) ProcessWorker(com.centurylink.mdw.designer.utils.ProcessWorker) ActionCancelledException(com.centurylink.mdw.common.utilities.timer.ActionCancelledException) ProcessVO(com.centurylink.mdw.model.value.process.ProcessVO) TaskVO(com.centurylink.mdw.model.value.task.TaskVO) DataAccessException(com.centurylink.mdw.common.exception.DataAccessException)

Example 13 with DataAccessException

use of com.centurylink.mdw.common.exception.DataAccessException in project mdw-designer by CenturyLinkCloud.

the class Importer method main.

public static void main(String[] args) {
    if (args.length == 1 && "-h".equals(args[0])) {
        System.out.println("Example Usage: ");
        System.out.println("java com.centurylink.mdw.designer.Importer appcuid apppassword " + "jdbc:oracle:thin:mdwdemo/mdwdemo@mdwdevdb.dev.qintra.com:1594:mdwdev (or /path/to/root/storage) " + "http://lxdenvmtc143.dev.qintra.com:7021/maven/repository/mdw/com/centurylink/mdw/assets/camel/5.5.11/com.centurylink.mdw.camel-5.5.11.xml " + "overwrite=true");
        System.exit(0);
    }
    if (args.length != 4 && args.length != 5) {
        System.err.println("arguments: <user> <password> <jdbcUrl|fileBasedRootDir> <xmlFile|xmlFileUrl> <overwrite=(true|FALSE)>");
        System.err.println("(-h for example usage)");
        System.exit(-1);
    }
    String user = args[0];
    String password = args[1];
    // either jdbcUrl or local file path
    String arg2 = args[2];
    String xmlFile = args[3];
    boolean overwrite = (args.length == 5 && "overwrite=true".equalsIgnoreCase(args[4])) ? true : false;
    try {
        DesignerDataAccess.getAuthenticator().authenticate(user, password);
        boolean local = !arg2.startsWith("jdbc:");
        RestfulServer restfulServer = new RestfulServer(local ? "jdbc://dummy" : arg2, user, "http://dummy");
        DesignerDataAccess dataAccess;
        if (local) {
            VersionControl versionControl = new VersionControlGit();
            versionControl.connect(null, null, null, new File(arg2));
            restfulServer.setVersionControl(versionControl);
            restfulServer.setRootDirectory(new File(arg2));
            dataAccess = new DesignerDataAccess(restfulServer, null, user, false);
        } else {
            dataAccess = new DesignerDataAccess(restfulServer, null, user, true);
            UserVO userVO = dataAccess.getUser(user);
            if (userVO == null)
                throw new DataAccessException("User: '" + user + "' not found.");
            if (!userVO.hasRole(UserGroupVO.COMMON_GROUP, UserRoleVO.PROCESS_DESIGN))
                throw new DataAccessException("User: '" + user + "' not authorized for " + UserRoleVO.PROCESS_DESIGN + ".");
        }
        String xml;
        if ("http://".startsWith(xmlFile) || "https://".startsWith(xmlFile)) {
            xml = new HttpHelper(new URL(xmlFile)).get();
        } else {
            xml = readFile(xmlFile);
        }
        System.out.println("Importing with arguments: " + user + " ******* " + arg2 + " " + xmlFile);
        Importer importer = new Importer(dataAccess);
        long before = System.currentTimeMillis();
        importer.importPackage(xml, overwrite);
        long afterImport = System.currentTimeMillis();
        System.out.println("Time taken for import: " + ((afterImport - before) / 1000) + " s");
        System.out.println("Please restart your server or refresh the MDW asset cache.");
    } catch (Exception ex) {
        ex.printStackTrace();
        System.exit(-1);
    }
}
Also used : VersionControlGit(com.centurylink.mdw.dataaccess.file.VersionControlGit) RestfulServer(com.centurylink.mdw.designer.utils.RestfulServer) VersionControl(com.centurylink.mdw.dataaccess.VersionControl) URL(java.net.URL) DataAccessException(com.centurylink.mdw.common.exception.DataAccessException) IOException(java.io.IOException) RemoteException(java.rmi.RemoteException) XmlException(org.apache.xmlbeans.XmlException) ActionCancelledException(com.centurylink.mdw.common.utilities.timer.ActionCancelledException) UserVO(com.centurylink.mdw.model.value.user.UserVO) File(java.io.File) HttpHelper(com.centurylink.mdw.common.utilities.HttpHelper) DataAccessException(com.centurylink.mdw.common.exception.DataAccessException) ProcessImporter(com.centurylink.mdw.dataaccess.ProcessImporter)

Example 14 with DataAccessException

use of com.centurylink.mdw.common.exception.DataAccessException in project mdw-designer by CenturyLinkCloud.

the class ServerAccessRest method isOnline.

public boolean isOnline() throws DataAccessException {
    if (serverOnline == null) {
        try {
            server.getAppSummary();
            serverOnline = true;
        } catch (IOException ex) {
            serverOnline = false;
            serverOfflineException = new DataAccessOfflineException("Server unavailable: " + getServiceBaseUrl(), ex);
        } catch (Exception ex) {
            throw new DataAccessException("Error communicating with server: " + ex.getMessage(), ex);
        }
    }
    return serverOnline;
}
Also used : DataAccessOfflineException(com.centurylink.mdw.dataaccess.DataAccessOfflineException) IOException(java.io.IOException) DataAccessException(com.centurylink.mdw.common.exception.DataAccessException) IOException(java.io.IOException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) DataAccessOfflineException(com.centurylink.mdw.dataaccess.DataAccessOfflineException) RemoteException(java.rmi.RemoteException) DataAccessException(com.centurylink.mdw.common.exception.DataAccessException)

Example 15 with DataAccessException

use of com.centurylink.mdw.common.exception.DataAccessException in project mdw-designer by CenturyLinkCloud.

the class UserDataAccessRest method getAllGroups.

public List<UserGroupVO> getAllGroups(boolean includeDeleted) throws DataAccessException {
    try {
        String pathWithArgs = "Workgroups?format=json";
        if (includeDeleted)
            pathWithArgs += "&includeDeleted=true";
        String response = invokeResourceService(pathWithArgs);
        return new WorkgroupList(response).getItems();
    } catch (IOException ex) {
        throw new DataAccessOfflineException(ex.getMessage(), ex);
    } catch (Exception ex) {
        throw new DataAccessException(ex.getMessage(), ex);
    }
}
Also used : DataAccessOfflineException(com.centurylink.mdw.dataaccess.DataAccessOfflineException) WorkgroupList(com.centurylink.mdw.model.value.user.WorkgroupList) IOException(java.io.IOException) DataAccessException(com.centurylink.mdw.common.exception.DataAccessException) IOException(java.io.IOException) FileNotFoundException(java.io.FileNotFoundException) DataAccessOfflineException(com.centurylink.mdw.dataaccess.DataAccessOfflineException) DataAccessException(com.centurylink.mdw.common.exception.DataAccessException)

Aggregations

DataAccessException (com.centurylink.mdw.common.exception.DataAccessException)61 IOException (java.io.IOException)32 DataAccessOfflineException (com.centurylink.mdw.dataaccess.DataAccessOfflineException)25 JSONException (org.json.JSONException)21 XmlException (org.apache.xmlbeans.XmlException)19 RemoteException (java.rmi.RemoteException)18 JSONObject (org.json.JSONObject)12 ValidationException (com.centurylink.mdw.designer.utils.ValidationException)10 ProcessVO (com.centurylink.mdw.model.value.process.ProcessVO)10 HttpHelper (com.centurylink.mdw.common.utilities.HttpHelper)8 FileNotFoundException (java.io.FileNotFoundException)8 ArrayList (java.util.ArrayList)8 HashMap (java.util.HashMap)7 RestfulServer (com.centurylink.mdw.designer.utils.RestfulServer)6 PackageVO (com.centurylink.mdw.model.value.process.PackageVO)5 Graph (com.centurylink.mdw.designer.display.Graph)4 SubGraph (com.centurylink.mdw.designer.display.SubGraph)4 WorkflowProcess (com.centurylink.mdw.plugin.designer.model.WorkflowProcess)4 File (java.io.File)4 MDWStatusMessageDocument (com.centurylink.mdw.bpm.MDWStatusMessageDocument)3