use of com.centurylink.mdw.dataaccess.DataAccessOfflineException in project mdw-designer by CenturyLinkCloud.
the class ProcessExplorerContentProvider method getChildren.
public Object[] getChildren(Object parentElement) {
if (parentElement instanceof WorkflowProject) {
final WorkflowProject workflowProject = (WorkflowProject) parentElement;
if (!workflowProject.isLoaded()) {
try {
IRunnableWithProgress loader = new IRunnableWithProgress() {
public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
ProgressMonitor progressMonitor = new SwtProgressMonitor(monitor);
progressMonitor.start("Loading " + workflowProject.getLabel());
progressMonitor.progress(5);
try {
workflowProject.initialize(progressMonitor);
if (workflowProject.getDataAccess() != null) {
workflowProject.getTopLevelUserVisiblePackages(progressMonitor);
workflowProject.getArchivedUserVisiblePackagesFolder(progressMonitor);
progressMonitor.done();
}
} catch (Exception ex) {
throw new InvocationTargetException(ex);
}
}
};
ProgressMonitorDialog progMonDlg = new MdwProgressMonitorDialog(MdwPlugin.getShell());
progMonDlg.run(true, false, loader);
} catch (InvocationTargetException itx) {
if (itx.getCause() instanceof DataUnavailableException) {
PluginMessages.log(itx);
MessageDialog.openWarning(MdwPlugin.getShell(), LOAD_WF_PROJECT, itx.getCause().getMessage());
} else if (itx.getCause() instanceof DataAccessOfflineException) {
PluginMessages.log(itx);
MessageDialog.openError(MdwPlugin.getShell(), LOAD_WF_PROJECT, itx.getCause().getMessage());
return new WorkflowPackage[0];
} else {
PluginMessages.uiError(itx, LOAD_WF_PROJECT, workflowProject);
return new WorkflowPackage[0];
}
} catch (Exception ex) {
PluginMessages.uiError(ex, LOAD_WF_PROJECT, workflowProject);
return new WorkflowPackage[0];
}
}
if (workflowProject.getDataAccess() == null)
return new WorkflowPackage[0];
List<WorkflowPackage> topLevelPackages = workflowProject.getTopLevelUserVisiblePackages();
Folder archivedPackageFolder = workflowProject.getArchivedUserVisiblePackagesFolder();
int size = topLevelPackages.size();
boolean showArchived = isShowArchivedItems(workflowProject);
if (showArchived)
size++;
AutomatedTestSuite testSuite = workflowProject.getLegacyTestSuite();
if (testSuite != null && !testSuite.isEmpty())
size++;
Object[] objects = new Object[size];
for (int i = 0; i < topLevelPackages.size(); i++) objects[i] = topLevelPackages.get(i);
int cur = topLevelPackages.size();
if (showArchived) {
objects[cur] = archivedPackageFolder;
cur++;
}
if (testSuite != null && !testSuite.isEmpty())
objects[cur] = testSuite;
return objects;
} else if (parentElement instanceof WorkflowPackage) {
WorkflowPackage packageVersion = (WorkflowPackage) parentElement;
if (packageVersion.isArchived() && packageVersion.hasDescendantPackageVersions()) {
return packageVersion.getDescendantPackageVersions().toArray(new WorkflowPackage[0]);
} else {
List<WorkflowElement> elements = new ArrayList<>();
IPreferenceStore prefsStore = MdwPlugin.getDefault().getPreferenceStore();
if (!prefsStore.getBoolean(PreferenceConstants.PREFS_FILTER_PROCESSES_IN_PEX))
elements.addAll(packageVersion.getProcesses());
if (!prefsStore.getBoolean(PreferenceConstants.PREFS_FILTER_WORKFLOW_ASSETS_IN_PEX))
elements.addAll(packageVersion.getAssets());
if (!prefsStore.getBoolean(PreferenceConstants.PREFS_FILTER_EVENT_HANDLERS_IN_PEX))
elements.addAll(packageVersion.getExternalEvents());
if (prefsStore.getBoolean(PreferenceConstants.PREFS_SHOW_ACTIVITY_IMPLEMENTORS_IN_PEX))
elements.addAll(packageVersion.getActivityImpls());
if (!prefsStore.getBoolean(PreferenceConstants.PREFS_FILTER_TASK_TEMPLATES_IN_PEX))
elements.addAll(packageVersion.getTaskTemplates());
elements.addAll(packageVersion.getChildFolders());
if (isSortPackageContentsAtoZ()) {
Collections.sort(elements, new Comparator<WorkflowElement>() {
public int compare(WorkflowElement e1, WorkflowElement e2) {
return e1.getLabel().compareToIgnoreCase(e2.getLabel());
}
});
}
return elements.toArray(new Object[0]);
}
} else if (parentElement instanceof WorkflowProcess) {
WorkflowProcess processVersion = (WorkflowProcess) parentElement;
if (processVersion.hasDescendantProcessVersions()) {
return processVersion.getDescendantProcessVersions().toArray(new WorkflowProcess[0]);
} else {
return emptyARRAY;
}
} else if (parentElement instanceof Folder) {
Folder folder = (Folder) parentElement;
return folder.getChildren().toArray(new WorkflowElement[0]);
} else if (parentElement instanceof AutomatedTestSuite) {
AutomatedTestSuite testSuite = (AutomatedTestSuite) parentElement;
return testSuite.getTestCases().toArray(new AutomatedTestCase[0]);
} else if (parentElement instanceof AutomatedTestCase) {
AutomatedTestCase testCase = (AutomatedTestCase) parentElement;
if (!testCase.isLegacy())
return emptyARRAY;
List<LegacyExpectedResults> expectedResults = testCase.getLegacyExpectedResults();
List<File> files = testCase.getFiles();
Object[] objects = new Object[expectedResults.size() + files.size()];
for (int i = 0; i < expectedResults.size(); i++) objects[i] = expectedResults.get(i);
for (int i = expectedResults.size(); i < objects.length; i++) objects[i] = files.get(i - expectedResults.size());
return objects;
} else {
return emptyARRAY;
}
}
use of com.centurylink.mdw.dataaccess.DataAccessOfflineException 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.dataaccess.DataAccessOfflineException in project mdw-designer by CenturyLinkCloud.
the class DesignerProxy method renameProcess.
public void renameProcess(final WorkflowProcess processVersion, final String newName) {
if (dataAccess.processNameExists(processVersion.getPackage().getPackageVO(), newName)) {
Shell shell = MdwPlugin.getActiveWorkbenchWindow().getShell();
MessageDialog.openError(shell, RENAME_ERROR, "Process name already exists: '" + newName + "'");
return;
}
String version = "v" + processVersion.getVersionString();
String progressMsg = "Renaming to '" + newName + "' " + version;
String errorMsg = "Rename Process";
designerRunner = new DesignerRunner(progressMsg, errorMsg, project) {
public void perform() throws ValidationException, DataAccessException, RemoteException, XmlException {
try {
if (dataAccess.getDesignerDataAccess().hasProcessInstances(processVersion.getId()))
throw new DataAccessException("Process " + processVersion.getLabel() + " has instances and cannot be renamed.\nPlease save as a new version.");
} catch (DataAccessOfflineException ex) {
final StringBuilder confirm = new StringBuilder();
MdwPlugin.getDisplay().syncExec(new Runnable() {
public void run() {
String msg = "Cannot connect to server to check for instances. Are you sure you want to rename?";
confirm.append(MessageDialog.openConfirm(MdwPlugin.getShell(), "Rename Process", msg));
}
});
if (!Boolean.valueOf(confirm.toString()))
return;
}
dataAccess.removeProcess(processVersion.getProcessVO());
if (processVersion.isInRuleSet() && !project.isFilePersist()) {
ProcessVO procVO = dataAccess.getDesignerDataAccess().getProcessDefinition(processVersion.getName(), processVersion.getVersion());
procVO = dataAccess.getDesignerDataAccess().getProcess(procVO.getProcessId(), procVO);
procVO.setName(newName);
procVO.setVersion(1);
new ProcessWorker().convert_to_designer(procVO);
dataAccess.getDesignerDataAccess().updateProcess(procVO, 0, false);
processVersion.setProcessVO(procVO);
} else {
processVersion.setName(newName);
processVersion.getProcessVO().setVersion(1);
processVersion.getProcessVO().setId(dataAccess.getDesignerDataAccess().renameProcess(processVersion.getId(), newName, 1));
}
dataAccess.getDesignerDataModel().addProcess(processVersion.getProcessVO());
}
};
designerRunner.run();
}
use of com.centurylink.mdw.dataaccess.DataAccessOfflineException in project mdw-designer by CenturyLinkCloud.
the class RestfulServer method invokeService.
public MDWStatusMessageDocument invokeService(String request) throws DataAccessException, RemoteException {
String response = null;
try {
// append to Services context root since sometimes only Services/* are excluded from CT auth
HttpHelper httpHelper = getHttpHelper(getMdwWebUrl() + "/Services/REST");
httpHelper.setConnectTimeout(getConnectTimeout());
httpHelper.setReadTimeout(getReadTimeout());
response = httpHelper.post(request);
MDWStatusMessageDocument statusMessageDoc;
if (response.startsWith("{")) {
StatusMessage statusMessage = new StatusMessage(new JSONObject(response));
statusMessageDoc = statusMessage.getStatusDocument();
} else {
statusMessageDoc = MDWStatusMessageDocument.Factory.parse(response, Compatibility.namespaceOptions());
}
MDWStatusMessage statusMessage = statusMessageDoc.getMDWStatusMessage();
if (statusMessage.getStatusCode() == -3) {
// event handler not registered
throw new RemoteException("No event handler is registered for instance-level actions on: " + getMdwWebUrl());
} else if (statusMessage.getStatusCode() != 0) {
throw new RemoteException("Error response from server: " + statusMessage.getStatusMessage());
}
return statusMessageDoc;
} catch (RemoteException ex) {
// don't fall through to IOException catch block
throw ex;
} catch (SocketTimeoutException ex) {
throw new DataAccessOfflineException("Timeout after " + getReadTimeout() + " ms", ex);
} catch (IOException ex) {
throw new DataAccessOfflineException("Unable to connect to " + getMdwWebUrl(), ex);
} catch (JSONException ex) {
throw new DataAccessException("Unparsable JSON response:\n" + response);
} catch (XmlException ex) {
throw new DataAccessException("Unparsable XML response:\n" + response);
}
}
use of com.centurylink.mdw.dataaccess.DataAccessOfflineException in project mdw-designer by CenturyLinkCloud.
the class DesignerDataAccess method exportAttributes.
public String exportAttributes(String prefix, Long artifactId, int schemaVersion, ProgressMonitor monitor, String exportArtifactType) throws DataAccessException, ActionCancelledException, XmlException {
monitor.subTask("Loading attributes...");
PackageVO packageVO = null;
ProcessVO processVO = null;
if (exportArtifactType.equals(OwnerType.PACKAGE)) {
packageVO = loadPackage(artifactId, true);
if (isVcsPersist()) {
try {
for (ProcessVO process : packageVO.getProcesses()) {
Map<String, String> overrideAttrs = workflowAccessRest.getAttributes(OwnerType.PROCESS, process.getId());
process.applyOverrideAttributes(overrideAttrs);
}
} catch (IOException ex) {
throw new DataAccessOfflineException("Server does not appear to be running.", ex);
}
} else {
for (ProcessVO process : packageVO.getProcesses()) {
if (process.isInRuleSet()) {
Map<String, String> overrideAttrs = getAttributes(OwnerType.PROCESS, process.getId());
process.applyOverrideAttributes(overrideAttrs);
}
}
}
} else {
processVO = getProcess(artifactId, null);
if (isVcsPersist()) {
try {
// need to make sure attributes are retrieved
Map<String, String> overrideAttrs = workflowAccessRest.getAttributes(OwnerType.PROCESS, processVO.getId());
processVO.applyOverrideAttributes(overrideAttrs);
} catch (IOException ex) {
throw new DataAccessOfflineException("Server does not appear to be running.", ex);
}
}
}
monitor.progress(30);
if (monitor.isCanceled())
throw new ActionCancelledException();
if (packageVO != null) {
// -- subprocesses must come after their containing parent processes
Collections.sort(packageVO.getProcesses(), new Comparator<ProcessVO>() {
public int compare(ProcessVO pVO1, ProcessVO pVO2) {
boolean pVO1HasSubProcs = pVO1.getSubProcesses() != null && !pVO1.getSubProcesses().isEmpty();
boolean pVO2HasSubProcs = pVO2.getSubProcesses() != null && !pVO2.getSubProcesses().isEmpty();
if (pVO1HasSubProcs == pVO2HasSubProcs) {
// sort by label
return pVO1.getLabel().compareToIgnoreCase(pVO2.getLabel());
} else if (pVO1HasSubProcs)
return -1;
else
return 1;
}
});
}
if (monitor.isCanceled())
throw new ActionCancelledException();
monitor.progress(5);
monitor.subTask(EXPORTXML);
ProcessExporter exporter = DataAccess.getProcessExporter(schemaVersion, oldNamespaces ? DesignerCompatibility.getInstance() : null);
String xml;
if (packageVO != null)
xml = exporter.exportOverrideAttributes(prefix, packageVO);
else
xml = exporter.exportOverrideAttributes(prefix, processVO, schemaVersion);
monitor.progress(40);
return xml;
}
Aggregations