Search in sources :

Example 1 with RestfulServer

use of com.centurylink.mdw.designer.utils.RestfulServer in project mdw-designer by CenturyLinkCloud.

the class DesignerDataAccess method remoteRetrieveProcess.

public ProcessVO remoteRetrieveProcess(String name, int version) throws DataAccessException {
    try {
        String path = "Processes?name=" + name;
        if (version != 0)
            path += "&version=" + RuleSetVO.formatVersion(version);
        String pkgXml = ((RestfulServer) currentServer).invokeResourceService(path);
        ProcessImporter importer = DataAccess.getProcessImporter(getDatabaseSchemaVersion());
        PackageVO pkg = importer.importPackage(pkgXml);
        ProcessVO process = pkg.getProcesses().get(0);
        process.setPackageName(pkg.getName());
        process.setPackageVersion(pkg.getVersionString());
        if (isVcsPersist())
            process.setId(currentServer.getVersionControl().getId(getLogicalFile(process)));
        return process;
    } catch (IOException ex) {
        throw new DataAccessException("Error retrieving process: " + name + " v" + RuleSetVO.formatVersion(version), ex);
    }
}
Also used : PackageVO(com.centurylink.mdw.model.value.process.PackageVO) ProcessVO(com.centurylink.mdw.model.value.process.ProcessVO) ProcessImporter(com.centurylink.mdw.dataaccess.ProcessImporter) RestfulServer(com.centurylink.mdw.designer.utils.RestfulServer) IOException(java.io.IOException) DataAccessException(com.centurylink.mdw.common.exception.DataAccessException)

Example 2 with RestfulServer

use of com.centurylink.mdw.designer.utils.RestfulServer 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 3 with RestfulServer

use of com.centurylink.mdw.designer.utils.RestfulServer in project mdw-designer by CenturyLinkCloud.

the class Exporter 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.Exporter " + "jdbc:oracle:thin:mdwdemo/mdwdemo@mdwdevdb.dev.qintra.com:1594:mdwdev (or /path/to/root/storage) " + "com.centurylink.mdw.tests " + "/path/to/packageDef(.xml|.json)");
        System.exit(0);
    }
    if (args.length != 2 && args.length != 3) {
        System.err.println("arguments: <jdbcUrl|fileBasedRootDir> <packageName> <xmlFile>");
        System.err.println("(-h for example usage)");
        System.exit(-1);
    }
    // either jdbcUrl or local file path
    String arg0 = args[0];
    String packageName = args[1];
    String outFile = args[2];
    try {
        boolean local = !arg0.startsWith("jdbc:");
        RestfulServer restfulServer = new RestfulServer(local ? "jdbc://dummy" : arg0, null, "http://dummy");
        DesignerDataAccess dataAccess;
        if (local) {
            VersionControl versionControl = new VersionControlGit();
            versionControl.connect(null, null, null, new File(arg0));
            restfulServer.setVersionControl(versionControl);
            restfulServer.setRootDirectory(new File(arg0));
            dataAccess = new DesignerDataAccess(restfulServer, null, EXPORT, false);
        } else {
            dataAccess = new DesignerDataAccess(restfulServer, null, EXPORT, true);
        }
        System.out.println("Exporting with arguments: " + arg0 + " " + packageName + " " + outFile);
        Exporter exporter = new Exporter(dataAccess);
        long before = System.currentTimeMillis();
        String xml = exporter.exportPackage(packageName, true, outFile.endsWith(".json"));
        File outputFile = new File(outFile);
        if (outputFile.exists()) {
            System.out.println("Overwriting existing file: " + outputFile);
        } else if (!outputFile.getParentFile().exists() && !outputFile.getParentFile().mkdirs()) {
            throw new IOException("Cannot create directory: " + outputFile.getParentFile());
        }
        exporter.writeFile(outputFile, xml.getBytes());
        long afterExport = System.currentTimeMillis();
        System.out.println("Time taken for export: " + ((afterExport - before) / 1000) + " s");
    } catch (Exception ex) {
        ex.printStackTrace();
        System.exit(-1);
    }
}
Also used : VersionControlGit(com.centurylink.mdw.dataaccess.file.VersionControlGit) RestfulServer(com.centurylink.mdw.designer.utils.RestfulServer) IOException(java.io.IOException) VersionControl(com.centurylink.mdw.dataaccess.VersionControl) File(java.io.File) DataAccessException(com.centurylink.mdw.common.exception.DataAccessException) IOException(java.io.IOException) RemoteException(java.rmi.RemoteException) JSONException(org.json.JSONException) XmlException(org.apache.xmlbeans.XmlException) ActionCancelledException(com.centurylink.mdw.common.utilities.timer.ActionCancelledException)

Example 4 with RestfulServer

use of com.centurylink.mdw.designer.utils.RestfulServer 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 5 with RestfulServer

use of com.centurylink.mdw.designer.utils.RestfulServer in project mdw-designer by CenturyLinkCloud.

the class WorkflowImageHelper method getProcessImage.

/**
 * Generate a process instance image.
 */
public BufferedImage getProcessImage() throws Exception {
    VersionControl vc = DataAccess.getAssetVersionControl(ApplicationContext.getAssetRoot());
    String serviceUrl = ApplicationContext.getServicesUrl();
    RestfulServer restfulServer = new RestfulServer("jdbc://dummy", "mdwapp", serviceUrl);
    restfulServer.setVersionControl(vc);
    restfulServer.setRootDirectory(ApplicationContext.getAssetRoot());
    DesignerDataAccess dao = new DesignerDataAccess(restfulServer, null, "mdwapp");
    // clone the process since it'll be converted to Designer
    Long processId = process.getId();
    process = new ProcessVO(process);
    process.setId(processId);
    return generateImage(dao);
}
Also used : ProcessVO(com.centurylink.mdw.model.value.process.ProcessVO) RestfulServer(com.centurylink.mdw.designer.utils.RestfulServer) DesignerDataAccess(com.centurylink.mdw.designer.DesignerDataAccess) VersionControl(com.centurylink.mdw.dataaccess.VersionControl)

Aggregations

RestfulServer (com.centurylink.mdw.designer.utils.RestfulServer)13 DataAccessException (com.centurylink.mdw.common.exception.DataAccessException)10 IOException (java.io.IOException)8 RemoteException (java.rmi.RemoteException)7 XmlException (org.apache.xmlbeans.XmlException)7 JSONException (org.json.JSONException)6 VersionControl (com.centurylink.mdw.dataaccess.VersionControl)5 VersionControlGit (com.centurylink.mdw.dataaccess.file.VersionControlGit)4 ProcessVO (com.centurylink.mdw.model.value.process.ProcessVO)4 File (java.io.File)4 DesignerDataAccess (com.centurylink.mdw.designer.DesignerDataAccess)3 Server (com.centurylink.mdw.designer.utils.Server)3 HashMap (java.util.HashMap)3 ActionCancelledException (com.centurylink.mdw.common.utilities.timer.ActionCancelledException)2 ProcessImporter (com.centurylink.mdw.dataaccess.ProcessImporter)2 AppSummary (com.centurylink.mdw.designer.model.AppSummary)2 ValidationException (com.centurylink.mdw.designer.utils.ValidationException)2 VariableVO (com.centurylink.mdw.model.value.variable.VariableVO)2 WebLaunchAction (com.centurylink.mdw.plugin.actions.WebLaunchActions.WebLaunchAction)2 WorkflowElement (com.centurylink.mdw.plugin.designer.model.WorkflowElement)2