Search in sources :

Example 1 with VersionControl

use of com.centurylink.mdw.dataaccess.VersionControl 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 2 with VersionControl

use of com.centurylink.mdw.dataaccess.VersionControl 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 3 with VersionControl

use of com.centurylink.mdw.dataaccess.VersionControl 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)

Example 4 with VersionControl

use of com.centurylink.mdw.dataaccess.VersionControl in project mdw-designer by CenturyLinkCloud.

the class ImportPackageWizard method unzipToLocal.

void unzipToLocal(WorkflowProject wfp, java.io.File zipFile, java.io.File tempDir, java.io.File assetDir, List<WorkflowPackage> importedPackages, ProgressMonitor progressMonitor) throws IOException, DataAccessException, CoreException, JSONException {
    VersionControl vcs = new VersionControlGit();
    vcs.connect(null, null, null, wfp.getAssetDir());
    progressMonitor.subTask("Archive existing assets...");
    VcsArchiver archiver = new VcsArchiver(assetDir, tempDir, vcs, progressMonitor);
    archiver.backup();
    PluginMessages.log("Unzipping " + zipFile + " into: " + assetDir);
    ZipHelper.unzip(zipFile, assetDir, null, null, true);
    archiver.archive();
    ZipHelper.unzip(zipFile, tempDir, null, null, true);
    wfp.getSourceProject().refreshLocal(2, null);
    java.io.File explodedDir = new java.io.File(tempDir + "/com");
    if (explodedDir.isDirectory()) {
        List<java.io.File> fileList = FileHelper.getFilesRecursive(explodedDir, "package.json", new ArrayList<java.io.File>());
        for (java.io.File file : fileList) {
            WorkflowPackage workflowPackage = new WorkflowPackage();
            workflowPackage.setProject(wfp);
            workflowPackage.setPackageVO(new PackageVO(new JSONObject(FileHelper.getFileContents(file.getPath()))));
            importedPackages.add(workflowPackage);
        }
        FileHelper.deleteRecursive(explodedDir);
    }
}
Also used : VcsArchiver(com.centurylink.mdw.dataaccess.file.VcsArchiver) VersionControlGit(com.centurylink.mdw.dataaccess.file.VersionControlGit) WorkflowPackage(com.centurylink.mdw.plugin.designer.model.WorkflowPackage) PackageVO(com.centurylink.mdw.model.value.process.PackageVO) JSONObject(org.json.JSONObject) VersionControl(com.centurylink.mdw.dataaccess.VersionControl) File(com.centurylink.mdw.plugin.designer.model.File)

Example 5 with VersionControl

use of com.centurylink.mdw.dataaccess.VersionControl in project mdw-designer by CenturyLinkCloud.

the class DesignerProxy method initialize.

public void initialize(ProgressMonitor progressMonitor) throws Exception {
    mainFrame = new MainFrame("Not Displayed");
    mainFrame.setOptionPane(new SwtDialogProvider(MdwPlugin.getDisplay()));
    CodeTimer timer = new CodeTimer("initialize()");
    Map<String, String> connProps = new HashMap<>();
    try {
        User user = project.getUser();
        if (user != null && user.getJwtToken() != null)
            user.setJwtToken(((MdwAuthenticator) project.getAuthenticator()).doAuthentication(user.getUsername(), user.getPassword()));
        if (user == null)
            handleLazyUserAuth();
        if (project.getPersistType() == WorkflowProject.PersistType.Git) {
            restfulServer = createRestfulServer(project.getMdwDataSource().getJdbcUrlWithCredentials(), project.getMdwMajorVersion() * 1000 + project.getMdwMinorVersion() * 100);
            VcsRepository gitRepo = project.getMdwVcsRepository();
            VersionControlGit versionControl = new VersionControlGit();
            String gitUser = null;
            String gitPassword = null;
            if (MdwPlugin.getSettings().isUseDiscoveredVcsCredentials()) {
                gitUser = gitRepo.getUser();
                gitPassword = gitRepo.getPassword();
            }
            versionControl.connect(gitRepo.getRepositoryUrl(), gitUser, gitPassword, project.getProjectDir());
            versionControl.setValidateVersions(!project.checkRequiredVersion(6) && MdwPlugin.getSettings().isValidateProcessVersions());
            restfulServer.setVersionControl(versionControl);
            restfulServer.setRootDirectory(project.getAssetDir());
            if (project.isRemote()) {
                File assetDir = project.getAssetDir();
                boolean isGit = gitRepo.getRepositoryUrl() != null;
                String pkgDownloadServicePath = null;
                try {
                    if (isGit) {
                        // update branch from Git
                        if (progressMonitor != null)
                            progressMonitor.subTask("Retrieving Git status");
                        // avoid
                        Platform.getBundle("org.eclipse.egit.ui").start();
                        // Eclipse
                        // default
                        // Authenticator
                        // --
                        // otherwise
                        // login
                        // fails
                        AppSummary appSummary = restfulServer.getAppSummary();
                        if (appSummary.getRepository() == null)
                            throw new DataAccessOfflineException("Unable to confirm Git status on server (missing repository)");
                        String branch = appSummary.getRepository().getBranch();
                        if (branch == null || branch.isEmpty())
                            throw new DataAccessOfflineException("Unable to confirm Git status on server (missing branch)");
                        String oldBranch = gitRepo.getBranch();
                        if (!branch.equals(oldBranch))
                            gitRepo.setBranch(branch);
                        if (progressMonitor != null)
                            progressMonitor.subTask("Updating from branch: " + branch);
                        versionControl.hardReset();
                        // in case changed
                        versionControl.checkout(branch);
                        versionControl.pull(branch);
                        String serverCommit = appSummary.getRepository().getCommit();
                        String localCommit = versionControl.getCommit();
                        if (localCommit == null || !localCommit.equals(serverCommit)) {
                            project.setWarn(true);
                            PluginMessages.log("Server commit: " + serverCommit + " does not match Git repository for branch " + branch + ": " + versionControl.getCommit() + ".", IStatus.WARNING);
                        }
                        // save
                        WorkflowProjectManager.getInstance().save(project);
                        // branch
                        if (progressMonitor != null)
                            progressMonitor.progress(10);
                        if (project.checkRequiredVersion(5, 5, 34))
                            pkgDownloadServicePath = "Packages?format=json&nonVersioned=true";
                    } else {
                        // non-git -- delete existing asset dir
                        if (assetDir.exists())
                            PluginUtil.deleteDirectory(assetDir);
                        if (!assetDir.mkdirs())
                            throw new DiscoveryException("Unable to create asset directory: " + assetDir);
                        pkgDownloadServicePath = "Packages?format=json&topLevel=true";
                    }
                    if (pkgDownloadServicePath != null && progressMonitor != null) {
                        if (gitRepo.isSyncAssetArchive())
                            pkgDownloadServicePath += "&archive=true";
                        String json = restfulServer.invokeResourceService(pkgDownloadServicePath);
                        Download download = new Download(new JSONObject(json));
                        if (!StringHelper.isEmpty(download.getUrl())) {
                            URL url = new URL(download.getUrl() + "&recursive=true");
                            IFolder tempFolder = project.getTempFolder();
                            IFile tempFile = tempFolder.getFile("/pkgs" + StringHelper.filenameDateToString(new Date()) + ".zip");
                            IProgressMonitor subMonitor = new SubProgressMonitor(((SwtProgressMonitor) progressMonitor).getWrappedMonitor(), 5);
                            try {
                                PluginUtil.downloadIntoProject(project.getSourceProject(), url, tempFolder, tempFile, "Download Packages", subMonitor);
                                PluginUtil.unzipProjectResource(project.getSourceProject(), tempFile, null, project.getAssetFolder(), subMonitor);
                            } catch (FileNotFoundException ex) {
                                if (isGit)
                                    PluginMessages.uiMessage("Extra/Archived packages not retrieved.  Showing only assets from Git.", "Load Workflow Project", PluginMessages.INFO_MESSAGE);
                                else
                                    throw ex;
                            }
                        }
                    }
                } catch (ZipException ze) {
                    throw ze;
                } catch (IOException ex) {
                    PluginMessages.uiMessage("Extra/Archived packages not retrieved.  Showing only assets from Git.", "Load Workflow Project", PluginMessages.INFO_MESSAGE);
                }
            }
        } else if (project.getPersistType() == WorkflowProject.PersistType.None) {
            restfulServer = new RestfulServer(null, project.getUser().getUsername(), project.getServiceUrl());
            VersionControl dummyVersionControl = new VersionControlDummy();
            dummyVersionControl.connect(null, null, null, project.getProjectDir());
            restfulServer.setVersionControl(dummyVersionControl);
            restfulServer.setRootDirectory(project.getAssetDir());
        } else {
            String jdbcUrl = project.getMdwDataSource().getJdbcUrlWithCredentials();
            if (jdbcUrl == null)
                throw new DataAccessException("Please specify a valid JDBC URL in your MDW Project Settings");
            if (project.getMdwDataSource().getSchemaOwner() == null)
                // don't qualify queries
                DBMappingUtil.setSchemaOwner("");
            else
                DBMappingUtil.setSchemaOwner(project.getMdwDataSource().getSchemaOwner());
            restfulServer = new RestfulServer(jdbcUrl, project.getUser().getUsername(), project.getServiceUrl());
            connProps.put("defaultRowPrefetch", String.valueOf(MdwPlugin.getSettings().getJdbcFetchSize()));
        }
        cacheRefresh = new CacheRefresh(project, restfulServer);
        boolean oldNamespaces = project.isOldNamespaces();
        boolean remoteRetrieve = project.isFilePersist() && project.checkRequiredVersion(5, 5, 19);
        restfulServer.setConnectTimeout(MdwPlugin.getSettings().getHttpConnectTimeout());
        restfulServer.setReadTimeout(MdwPlugin.getSettings().getHttpReadTimeout());
        mainFrame.startSession(project.getUser().getUsername(), restfulServer, progressMonitor, connProps, oldNamespaces, remoteRetrieve);
        restfulServer.setDataModel(mainFrame.getDataModel());
        mainFrame.dao.setCurrentServer(restfulServer);
        dataAccess = new PluginDataAccess(project, mainFrame.getDataModel(), mainFrame.dao);
        // they've already been retrieved
        dataAccess.organizeRuleSets();
        // static supportedSchemaVersion has just been set, so save it at
        // instance level
        dataAccess.setSupportedSchemaVersion(DataAccess.supportedSchemaVersion);
        if (project.getPersistType() == WorkflowProject.PersistType.Git && !project.isRemote()) {
            try {
                mainFrame.dao.checkServerOnline();
            } catch (DataAccessOfflineException offlineEx) {
                if (MdwPlugin.getSettings().isLogConnectErrors())
                    PluginMessages.log(offlineEx);
            }
        }
        dataAccess.getVariableTypes(true);
        try {
            // override mainframe's settings for look-and-feel
            UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
        } catch (Exception ex) {
            PluginMessages.log(ex);
        }
        System.setProperty("awt.useSystemAAFontSettings", "on");
        System.setProperty("swing.aatext", "true");
    } finally {
        timer.stopAndLog();
    }
}
Also used : VersionControlGit(com.centurylink.mdw.dataaccess.file.VersionControlGit) User(com.centurylink.mdw.plugin.User) IFile(org.eclipse.core.resources.IFile) HashMap(java.util.HashMap) MdwAuthenticator(com.centurylink.mdw.designer.auth.MdwAuthenticator) FileNotFoundException(java.io.FileNotFoundException) VersionControl(com.centurylink.mdw.dataaccess.VersionControl) MainFrame(com.centurylink.mdw.designer.MainFrame) URL(java.net.URL) VersionControlDummy(com.centurylink.mdw.dataaccess.VersionControlDummy) CodeTimer(com.centurylink.mdw.plugin.CodeTimer) Download(com.centurylink.mdw.model.Download) DataAccessException(com.centurylink.mdw.common.exception.DataAccessException) DataAccessOfflineException(com.centurylink.mdw.dataaccess.DataAccessOfflineException) ZipException(java.util.zip.ZipException) IOException(java.io.IOException) RestfulServer(com.centurylink.mdw.designer.utils.RestfulServer) Date(java.util.Date) SubProgressMonitor(org.eclipse.core.runtime.SubProgressMonitor) JSONException(org.json.JSONException) TranslationException(com.centurylink.mdw.common.exception.TranslationException) AuthenticationException(com.centurylink.mdw.auth.AuthenticationException) IOException(java.io.IOException) XmlException(org.apache.xmlbeans.XmlException) ValidationException(com.centurylink.mdw.designer.utils.ValidationException) DataAccessOfflineException(com.centurylink.mdw.dataaccess.DataAccessOfflineException) ZipException(java.util.zip.ZipException) DataAccessException(com.centurylink.mdw.common.exception.DataAccessException) FileNotFoundException(java.io.FileNotFoundException) RemoteException(java.rmi.RemoteException) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) JSONObject(org.json.JSONObject) SwtDialogProvider(com.centurylink.mdw.plugin.designer.dialogs.SwtDialogProvider) VcsRepository(com.centurylink.mdw.plugin.project.model.VcsRepository) AppSummary(com.centurylink.mdw.designer.model.AppSummary) IFile(org.eclipse.core.resources.IFile) File(java.io.File) IFolder(org.eclipse.core.resources.IFolder)

Aggregations

VersionControl (com.centurylink.mdw.dataaccess.VersionControl)6 VersionControlGit (com.centurylink.mdw.dataaccess.file.VersionControlGit)5 RestfulServer (com.centurylink.mdw.designer.utils.RestfulServer)5 IOException (java.io.IOException)4 DataAccessException (com.centurylink.mdw.common.exception.DataAccessException)3 File (java.io.File)3 RemoteException (java.rmi.RemoteException)3 XmlException (org.apache.xmlbeans.XmlException)3 JSONException (org.json.JSONException)3 JSONObject (org.json.JSONObject)3 ActionCancelledException (com.centurylink.mdw.common.utilities.timer.ActionCancelledException)2 DesignerDataAccess (com.centurylink.mdw.designer.DesignerDataAccess)2 URL (java.net.URL)2 AuthenticationException (com.centurylink.mdw.auth.AuthenticationException)1 TranslationException (com.centurylink.mdw.common.exception.TranslationException)1 HttpHelper (com.centurylink.mdw.common.utilities.HttpHelper)1 DataAccessOfflineException (com.centurylink.mdw.dataaccess.DataAccessOfflineException)1 ProcessImporter (com.centurylink.mdw.dataaccess.ProcessImporter)1 VersionControlDummy (com.centurylink.mdw.dataaccess.VersionControlDummy)1 VcsArchiver (com.centurylink.mdw.dataaccess.file.VcsArchiver)1