use of com.centurylink.mdw.plugin.CodeTimer in project mdw-designer by CenturyLinkCloud.
the class WorkflowProject method findArchivedPackages.
/**
* Returns all top-level archived (non-latest) packages, populated with
* their descendants which include the appropriate process versions. Uses
* 10% of progressMonitor.
*/
private Folder findArchivedPackages(ProgressMonitor progressMonitor, boolean visiblePkgsOnly) {
CodeTimer timer = new CodeTimer("findAuthorizedArchivedPackages()");
if (progressMonitor != null)
progressMonitor.subTask("Organizing packages");
Folder archivedPkgFolder = new Folder("Archive", this);
archivedPkgFolder.setIcon("archive.gif");
List<WorkflowPackage> topLevelArchivedPackageList = new ArrayList<>();
List<WorkflowPackage> allArchivedPackages = new ArrayList<>();
for (PackageVO packageVO : getDataAccess().getPackages(false)) {
if (isShowDefaultPackage() || !packageVO.isDefaultPackage()) {
WorkflowPackage potentialArchived = new WorkflowPackage(this, packageVO);
if (!getTopLevelPackages().contains(potentialArchived)) {
potentialArchived.setArchived(true);
potentialArchived.setProcesses(findProcesses(potentialArchived));
potentialArchived.setAssets(findWorkflowAssets(potentialArchived));
potentialArchived.setActivityImpls(findActivityImplementors(potentialArchived));
potentialArchived.setExternalEvents(findExternalEvents(potentialArchived));
potentialArchived.setTaskTemplates(findTaskTemplates(potentialArchived));
allArchivedPackages.add(potentialArchived);
}
}
}
// organize the package version hierarchy
Map<String, WorkflowPackage> topLevelArchivedPackages = new HashMap<>();
for (WorkflowPackage archivedPackage : allArchivedPackages) {
WorkflowPackage topLevel = topLevelArchivedPackages.get(archivedPackage.getName());
if ((!visiblePkgsOnly || (visiblePkgsOnly && archivedPackage.isVisible())) && (topLevel == null || archivedPackage.getPackageVO().getVersion() > topLevel.getPackageVO().getVersion()))
topLevelArchivedPackages.put(archivedPackage.getName(), archivedPackage);
}
for (WorkflowPackage topLevelArchivedPackage : topLevelArchivedPackages.values()) {
for (WorkflowPackage archivedPackage : allArchivedPackages) {
if (topLevelArchivedPackage.getName().equals(archivedPackage.getName()) && (!visiblePkgsOnly || (visiblePkgsOnly && archivedPackage.isVisible()))) {
if (topLevelArchivedPackage.equals(archivedPackage)) {
// clone top-level process for first child
WorkflowPackage firstChild = new WorkflowPackage(topLevelArchivedPackage);
firstChild.setArchived(true);
firstChild.setTopLevelVersion(topLevelArchivedPackage);
firstChild.setProcesses(topLevelArchivedPackage.getProcesses());
firstChild.setAssets(topLevelArchivedPackage.getAssets());
firstChild.setActivityImpls(topLevelArchivedPackage.getActivityImpls());
firstChild.setExternalEvents(topLevelArchivedPackage.getExternalEvents());
firstChild.setTaskTemplates(topLevelArchivedPackage.getTaskTemplates());
topLevelArchivedPackage.addDescendantPackageVersion(firstChild);
} else {
archivedPackage.setTopLevelVersion(topLevelArchivedPackage);
topLevelArchivedPackage.addDescendantPackageVersion(archivedPackage);
}
}
}
topLevelArchivedPackageList.add(topLevelArchivedPackage);
topLevelArchivedPackage.setArchivedFolder(archivedPkgFolder);
}
Collections.sort(topLevelArchivedPackageList);
if (isShowDefaultPackage()) {
// add unpackaged (default package)
PackageVO defaultPackageVO = new PackageVO();
defaultPackageVO.setPackageId(Long.valueOf(0));
defaultPackageVO.setPackageName(PackageVO.DEFAULT_PACKAGE_NAME);
archivedDefaultPackage = new WorkflowPackage(this, defaultPackageVO);
archivedDefaultPackage.setProcesses(findUnpackagedProcesses());
archivedDefaultPackage.setChildFolders(findUnpackagedAssetFolders());
archivedDefaultPackage.setArchived(true);
topLevelArchivedPackageList.add(0, archivedDefaultPackage);
}
List<WorkflowElement> children = new ArrayList<>();
children.addAll(topLevelArchivedPackageList);
archivedPkgFolder.setChildren(children);
if (progressMonitor != null)
progressMonitor.progress(10);
timer.stopAndLog();
return archivedPkgFolder;
}
use of com.centurylink.mdw.plugin.CodeTimer in project mdw-designer by CenturyLinkCloud.
the class Discoverer method getAssetTopFolder.
public Folder getAssetTopFolder(boolean latestVersionsOnly, IProgressMonitor progressMonitor) throws DiscoveryException, IOException, InterruptedException {
this.latestVersionsOnly = latestVersionsOnly;
this.progressMonitor = progressMonitor;
progressMonitor.worked(10);
CodeTimer timer = new CodeTimer("crawl for assets");
Folder topFolder = new Folder(MdwPlugin.getSettings().getMdwReleasesUrl());
if (groupId != null) {
Discover discover = new Discover(groupId, latestVersionsOnly);
parseJsonPacakges(topFolder, discover.run(new SwtProgressMonitor(progressMonitor)).getPackages().toString());
} else if (url != null) {
topFolder = new Folder(url.toString());
crawlForPackageFiles(topFolder);
removeEmptyFolders(topFolder);
}
timer.stopAndLog();
return topFolder;
}
use of com.centurylink.mdw.plugin.CodeTimer in project mdw-designer by CenturyLinkCloud.
the class WorkflowProject method findUnpackagedAssetFolders.
/**
* Returns the folders for unpackaged archived workflow assets. Side-effect:
* If an unpackaged version is later than any package, add to default
* package.
*/
private List<Folder> findUnpackagedAssetFolders() {
CodeTimer timer = new CodeTimer("findUnpackagedAssetFolders()");
Map<String, Folder> upAssetFolders = new HashMap<>();
Map<String, List<RuleSetVO>> nonLatestUnpackaged = new HashMap<>();
for (RuleSetVO ruleSetVO : getDataAccess().getRuleSets(false)) {
if (!isPackaged(ruleSetVO)) {
// if version is later than that in any non-archived package,
// it belongs in the top-level default package
boolean laterThanPackaged = true;
for (WorkflowPackage pkg : getTopLevelPackages()) {
WorkflowAsset packaged = pkg.getAsset(ruleSetVO.getName());
if (packaged != null && packaged.getVersion() >= ruleSetVO.getVersion()) {
laterThanPackaged = false;
break;
}
}
boolean latestUnpackaged = true;
if (laterThanPackaged) {
WorkflowAsset defPkgAsset = getDefaultPackage().getAsset(ruleSetVO.getName());
if (defPkgAsset != null) {
if (defPkgAsset.getVersion() > ruleSetVO.getVersion()) {
latestUnpackaged = false;
} else if (defPkgAsset.getVersion() < ruleSetVO.getVersion()) {
defPkgAsset.removeElementChangeListener(this);
getDefaultPackage().removeAsset(defPkgAsset);
WorkflowAssetFactory.deRegisterAsset(defPkgAsset);
List<RuleSetVO> list = nonLatestUnpackaged.get(ruleSetVO.getName());
if (list == null) {
list = new ArrayList<>();
nonLatestUnpackaged.put(ruleSetVO.getName(), list);
}
list.add(defPkgAsset.getRuleSetVO());
}
}
}
if (laterThanPackaged && latestUnpackaged) {
WorkflowAsset asset = WorkflowAssetFactory.createAsset(ruleSetVO, getDefaultPackage());
if (asset != null) {
asset.addElementChangeListener(this);
getDefaultPackage().addAsset(asset);
WorkflowAssetFactory.registerAsset(asset);
}
} else {
List<RuleSetVO> list = nonLatestUnpackaged.get(ruleSetVO.getName());
if (list == null) {
list = new ArrayList<>();
nonLatestUnpackaged.put(ruleSetVO.getName(), list);
}
list.add(ruleSetVO);
}
}
}
for (String rsName : nonLatestUnpackaged.keySet()) {
List<RuleSetVO> list = nonLatestUnpackaged.get(rsName);
Collections.sort(list, new Comparator<RuleSetVO>() {
public int compare(RuleSetVO rs1, RuleSetVO rs2) {
return rs2.getVersion() - rs1.getVersion();
}
});
for (RuleSetVO rs : list) {
WorkflowAsset asset = WorkflowAssetFactory.createAsset(rs, archivedDefaultPackage);
if (asset != null) {
Folder folder = upAssetFolders.get(asset.getName());
if (folder == null) {
folder = WorkflowAssetFactory.createAssetFolder(asset);
upAssetFolders.put(asset.getName(), folder);
} else {
folder.getChildren().add(asset);
}
}
}
}
List<Folder> folders = new ArrayList<>();
folders.addAll(upAssetFolders.values());
Collections.sort(folders);
timer.stopAndLog();
return folders;
}
use of com.centurylink.mdw.plugin.CodeTimer in project mdw-designer by CenturyLinkCloud.
the class WorkflowProject method findTopLevelPackages.
/**
* Finds the list of top level packages (including the default if
* supported), populated with the appropriate processes, etc.
*/
private void findTopLevelPackages(ProgressMonitor progressMonitor) {
CodeTimer timer = new CodeTimer("findTopLevelPackages()");
topLevelPackages = new ArrayList<>();
topLevelUserVisiblePackages = new ArrayList<>();
activityImpls.clear();
for (PackageVO packageVO : getTopLevelPackageVOs(progressMonitor)) {
WorkflowPackage topLevelPackage = new WorkflowPackage(this, packageVO);
topLevelPackage.setProcesses(findProcesses(topLevelPackage));
topLevelPackage.setExternalEvents(findExternalEvents(topLevelPackage));
topLevelPackage.setActivityImpls(findActivityImplementors(topLevelPackage));
topLevelPackage.setAssets(findWorkflowAssets(topLevelPackage));
topLevelPackage.setTaskTemplates(findTaskTemplates(topLevelPackage));
topLevelPackages.add(topLevelPackage);
if (topLevelPackage.isVisible())
topLevelUserVisiblePackages.add(topLevelPackage);
// register as a listener so that i can pass on element change
// events
topLevelPackage.addElementChangeListener(this);
for (WorkflowProcess process : topLevelPackage.getProcesses()) process.addElementChangeListener(this);
}
Collections.sort(topLevelPackages);
Collections.sort(topLevelUserVisiblePackages);
File resultsFile = getFunctionTestResultsFile();
if (resultsFile.exists()) {
// update test case statuses
List<TestCase> testCases = new ArrayList<>();
for (WorkflowPackage pkg : topLevelPackages) {
for (WorkflowAsset asset : pkg.getAssets()) {
if (asset instanceof AutomatedTestCase)
testCases.add(((AutomatedTestCase) asset).getTestCase());
}
}
if (!testCases.isEmpty()) {
try {
TestResultsParser parser = new TestResultsParser(resultsFile, testCases);
if (resultsFile.getName().endsWith(".xml"))
parser.parseXml();
else
parser.parseJson(getAssetDir());
} catch (Exception ex) {
PluginMessages.uiError(ex, "Parse Test Results", this);
}
}
}
timer.stopAndLog();
}
use of com.centurylink.mdw.plugin.CodeTimer 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();
}
}
Aggregations