use of com.centurylink.mdw.plugin.project.model.VcsRepository in project mdw-designer by CenturyLinkCloud.
the class ProjectPersist method toXml.
public String toXml() {
StringBuffer sb = new StringBuffer();
sb.append("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n");
sb.append("<mdw-workflow>\n");
sb.append(" <sourceProject name=\"" + workflowProject.getSourceProjectName() + "\" author=\"" + workflowProject.getAuthor() + "\"");
if (workflowProject.isProduction())
sb.append(" production=\"true\"");
sb.append("/>\n");
for (ExtensionModule extension : workflowProject.getExtensionModules()) {
String extensionElementText = extension.writeConfigElement(workflowProject);
if (extensionElementText != null)
sb.append(extensionElementText);
}
if (// remote projects get version
!workflowProject.isRemote())
// dynamically from server
sb.append(" <mdwFramework version=\"" + workflowProject.getMdwVersion() + "\"/>\n");
ServerSettings serverSettings = workflowProject.getServerSettings();
sb.append(" <server host=\"" + serverSettings.getHost() + "\" port=\"" + serverSettings.getPort() + "\"");
if (!StringHelper.isEmpty(workflowProject.getWebContextRoot()))
sb.append(" contextRoot=\"" + workflowProject.getWebContextRoot() + "\"");
else {
sb.append(" contextRoot=\"mdw\"");
}
sb.append("/>\n");
if (workflowProject.getPersistType() == PersistType.Git) {
sb.append(" <repository");
VcsRepository repo = workflowProject.getMdwVcsRepository();
sb.append(" provider=\"" + repo.getProvider() + "\"");
if (repo.getRepositoryUrl() != null && repo.getRepositoryUrl().trim().length() > 0)
sb.append(" url=\"").append(repo.getRepositoryUrlWithEncryptedCredentials() + "\"");
if (repo.getBranch() != null && repo.getBranch().trim().length() > 0)
sb.append(" branch=\"").append(repo.getBranch() + "\"");
if (repo.getLocalPath() != null && repo.getLocalPath().trim().length() > 0)
sb.append(" localPath=\"").append(repo.getLocalPath().replace("\\", "/") + "\"");
if (repo.getPkgPrefixes() != null && !repo.getPkgPrefixes().isEmpty()) {
sb.append(" pkgPrefixes=\"");
for (int i = 0; i < repo.getPkgPrefixes().size(); i++) {
String prefix = repo.getPkgPrefixes().get(i).trim();
sb.append(prefix);
if (i < repo.getPkgPrefixes().size() - 1)
sb.append(",");
}
sb.append("\"");
}
sb.append("/>\n");
}
if (!workflowProject.checkRequiredVersion(6, 0)) {
if (workflowProject.getPersistType() != PersistType.None) {
sb.append(" <database jdbcUrl=\"" + workflowProject.getMdwDataSource().getJdbcUrlWithEncryptedCredentials() + "\"");
if (workflowProject.getMdwDataSource().getSchemaOwner() != null)
sb.append(" schemaOwner=\"" + workflowProject.getMdwDataSource().getSchemaOwner() + "\"");
sb.append("/>\n");
}
if (workflowProject.getFilesToIgnore() != null)
sb.append(" <filesToIgnore duringUpdate=\"" + workflowProject.getFilesToIgnoreDuringUpdate() + "\"/>\n");
}
sb.append("</mdw-workflow>\n");
return sb.toString();
}
use of com.centurylink.mdw.plugin.project.model.VcsRepository in project mdw-designer by CenturyLinkCloud.
the class WorkflowElementActionHandler method remoteImportVcs.
public void remoteImportVcs(final WorkflowProject workflowProject) {
VcsRepository repo = workflowProject.getMdwVcsRepository();
String msg = "Pull latest assets into " + workflowProject.getName() + " from Git branch: " + repo.getBranch() + "?";
boolean proceed = MessageDialog.openConfirm(getShell(), "Import from VCS", msg);
if (proceed) {
ProgressMonitorDialog pmDialog = new MdwProgressMonitorDialog(getShell());
try {
pmDialog.run(true, false, new IRunnableWithProgress() {
public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
monitor.beginTask("Importing remote project from Git...", IProgressMonitor.UNKNOWN);
monitor.worked(20);
try {
workflowProject.getDesignerProxy().remoteImportVcs();
} catch (Exception ex) {
PluginMessages.log(ex);
throw new InvocationTargetException(ex);
}
}
});
} catch (Exception ex) {
PluginMessages.uiError(getShell(), ex, "Import From VCS", workflowProject);
}
}
}
use of com.centurylink.mdw.plugin.project.model.VcsRepository in project mdw-designer by CenturyLinkCloud.
the class ImportProjectWizard method performFinish.
@Override
public boolean performFinish() {
if (errorMessage != null) {
MessageDialog.openError(getShell(), "Import Project", errorMessage);
return false;
}
BusyIndicator.showWhile(getShell().getDisplay(), new Runnable() {
public void run() {
List<IProject> existingProjects = new ArrayList<>();
for (WorkflowProject toImport : projectsToImport) {
IProject existing = MdwPlugin.getWorkspaceRoot().getProject(toImport.getName());
if (existing != null && existing.exists())
existingProjects.add(existing);
}
if (!existingProjects.isEmpty()) {
String text = "Please confirm that the following workspace projects should be overwritten:";
ListSelectionDialog lsd = new ListSelectionDialog(getShell(), existingProjects, new ExistingProjectContentProvider(), new ProjectLabelProvider(), text);
lsd.setTitle("Existing Projects");
lsd.setInitialSelections(existingProjects.toArray(new IProject[0]));
lsd.open();
Object[] results = lsd.getResult();
if (results == null) {
cancel = true;
return;
}
for (IProject existing : existingProjects) {
boolean include = false;
for (Object included : results) {
if (existing.getName().equals(((IProject) included).getName()))
include = true;
}
if (include) {
WorkflowProjectManager.getInstance().deleteProject(existing);
} else {
WorkflowProject toRemove = null;
for (WorkflowProject wfp : projectList) {
if (wfp.getName().equals(existing.getName())) {
toRemove = wfp;
break;
}
}
if (toRemove != null)
projectsToImport.remove(toRemove);
}
}
}
}
});
if (cancel)
return false;
if (projectsToImport.isEmpty()) {
MessageDialog.openInformation(getShell(), "Import Projects", "No projects to import.");
return true;
}
try {
getContainer().run(false, false, new IRunnableWithProgress() {
public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
monitor.beginTask("Importing MDW project(s)", 100);
monitor.worked(20);
try {
for (WorkflowProject workflowProject : projectsToImport) {
if (workflowProject.isFilePersist()) {
File projectDir = new File(ResourcesPlugin.getWorkspace().getRoot().getLocation().toFile() + "/" + workflowProject.getName());
projectDir.mkdir();
String repositoryUrl = projectsToImport.get(0).getMdwVcsRepository().getRepositoryUrl();
if (repositoryUrl != null && repositoryUrl.length() > 0) {
// avoid
Platform.getBundle("org.eclipse.egit.ui").start();
// Eclipse
// default
// Authenticator
workflowProject.setPersistType(PersistType.Git);
workflowProject.getMdwVcsRepository().setProvider(VcsRepository.PROVIDER_GIT);
monitor.subTask("Cloning Git repository for " + workflowProject.getLabel());
monitor.worked(1);
VcsRepository gitRepo = workflowProject.getMdwVcsRepository();
VersionControlGit vcsGit = new VersionControlGit();
String user = null;
String password = null;
if (MdwPlugin.getSettings().isUseDiscoveredVcsCredentials()) {
user = gitRepo.getUser();
password = gitRepo.getPassword();
}
vcsGit.connect(gitRepo.getRepositoryUrl(), user, password, projectDir);
vcsGit.cloneRepo();
} else {
File assetDir = new File(projectDir + "/" + workflowProject.getMdwVcsRepository().getLocalPath());
assetDir.mkdirs();
}
monitor.worked(40 / projectsToImport.size());
}
ProjectInflator inflator = new ProjectInflator(workflowProject, MdwPlugin.getSettings());
inflator.inflateRemoteProject(getContainer());
}
} catch (Exception ex) {
throw new InvocationTargetException(ex);
}
ProjectImporter projectImporter = new ProjectImporter(projectsToImport);
projectImporter.doImport();
monitor.worked(20);
monitor.done();
}
});
} catch (Exception ex) {
PluginMessages.uiError(ex, "Import Project");
return false;
}
DesignerPerspective.openPerspective(activeWindow);
return true;
}
use of com.centurylink.mdw.plugin.project.model.VcsRepository 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();
}
}
use of com.centurylink.mdw.plugin.project.model.VcsRepository in project mdw-designer by CenturyLinkCloud.
the class ProjectVcsSection method elementChanged.
public void elementChanged(ElementChangeEvent ece) {
if (ece.getChangeType().equals(ChangeType.SETTINGS_CHANGE)) {
if (ece.getNewValue() instanceof VcsRepository) {
VcsRepository repository = (VcsRepository) ece.getNewValue();
if (// avoid
!"projectSection".equals(repository.getEntrySource())) // overwriting
{
String newRepositoryUrl = repository.getRepositoryUrlWithMaskedCredentials();
if (!gitRepoUrlEditor.getValue().equals(newRepositoryUrl))
gitRepoUrlEditor.setValue(newRepositoryUrl);
String newGitBranchValue = repository.getBranch();
if (!gitBranchEditor.getValue().equals(newGitBranchValue))
gitBranchEditor.setValue(newGitBranchValue);
String newLocalPath = repository.getLocalPath();
if (!assetLocalPathEditor.getValue().equals(newLocalPath))
assetLocalPathEditor.setValue(newLocalPath);
boolean newSyncAssets = repository.isSyncAssetArchive();
if (includeArchiveEditor != null && !includeArchiveEditor.getValue().equals(String.valueOf(newSyncAssets)))
includeArchiveEditor.setValue(newSyncAssets);
}
}
}
}
Aggregations