use of org.talend.utils.sugars.ReturnCode in project tdq-studio-se by Talend.
the class ImportObject method extractImportObject.
/**
* build a ImportObject list.
*
* @param componet
* @param information
* @return
*/
public static List<ImportObject> extractImportObject(IEcosComponent componet, List<ReturnCode> information) {
List<ImportObject> importObjects = new ArrayList<ImportObject>();
try {
// $NON-NLS-1$
String targetFolder = System.getProperty("java.io.tmpdir");
File componentFileFolder = ComponentInstaller.unzip(componet.getInstalledLocation(), targetFolder);
// get obj files(csv)
List<File> objFiles = FilesUtils.getAllFilesFromFolder(componentFileFolder, new FilenameFilter() {
public boolean accept(File dir, String name) {
return !FilesUtils.isSVNFolder(dir) && name.endsWith(FileUtils.CSV);
}
});
if (objFiles.isEmpty()) {
// $NON-NLS-1$
information.add(new ReturnCode("No valid exchange extension file(CSV) found in " + componet.getName(), false));
} else {
// get jar files
List<File> jarFiles = FilesUtils.getAllFilesFromFolder(componentFileFolder, new FilenameFilter() {
public boolean accept(File dir, String name) {
// $NON-NLS-1$
return !FilesUtils.isSVNFolder(dir) && name.endsWith("jar");
}
});
for (File file : objFiles) {
importObjects.add(ImportObject.createImportObject(file, jarFiles));
}
}
} catch (Exception e) {
ExceptionHandler.process(e);
}
return importObjects;
}
use of org.talend.utils.sugars.ReturnCode in project tdq-studio-se by Talend.
the class ImportRemotePatternAction method doImportAfterDownload.
private void doImportAfterDownload(IJobChangeEvent event) {
final List<ReturnCode> information = new ArrayList<ReturnCode>();
setEnabled(true);
if (fExtensionDownloaded > 0) {
// $NON-NLS-1$
String csvFormat = System.getProperty("talend.exchange.csv");
if ("true".equals(csvFormat)) {
// $NON-NLS-1$
for (IEcosComponent componet : fInstalledComponents) {
List<ImportObject> validImportObject = ImportObject.extractImportObject(componet, information);
if (!validImportObject.isEmpty()) {
String categoryName = componet.getCategry().getName();
EEcosCategory ecosCategory = EEcosCategory.getEcosCategory(categoryName);
if (ecosCategory != null) {
EResourceConstant resourceType = ecosCategory.getResource();
for (ImportObject importObject : validImportObject) {
information.addAll(ImportFactory.doImport(resourceType, importObject, componet.getName()));
}
}
}
}
// MOD qiongli 2011-11-28 TDQ-4038,give the message when there is nothing to import.
if (information.isEmpty()) {
information.add(new ReturnCode(DefaultMessagesImpl.getString("ImportRemotePatternAction.NothingImport"), // $NON-NLS-1$
false));
}
ImportInfoDialog.openImportInformation(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), DefaultMessagesImpl.getString("ImportRemotePatternAction.ImportFinish"), // $NON-NLS-1$
information.toArray(new ReturnCode[0]));
CorePlugin.getDefault().refreshDQView();
} else {
Display.getDefault().asyncExec(new Runnable() {
public void run() {
for (IEcosComponent componet : fInstalledComponents) {
try {
ImportFactory.importFromExchange(componet);
} catch (Exception e) {
ExceptionHandler.process(e);
}
}
}
});
}
}
}
use of org.talend.utils.sugars.ReturnCode in project tdq-studio-se by Talend.
the class RunAnalysisAction method runAnalysisForItem.
/**
* DOC msjian Comment method "runAnalysisForItem".
*/
protected void runAnalysisForItem(final TDQAnalysisItem anaItem) {
try {
if (anaItem == null) {
// $NON-NLS-1$
log.error("Analysis item is null");
return;
}
if (ifLockByOthers(anaItem)) {
return;
}
// check if the analysis need to be saved or can run before real running by the event
if (!EventManager.getInstance().publish(anaItem.getAnalysis(), EventEnum.DQ_ANALYSIS_CHECK_BEFORERUN, null)) {
// or the analysis can not run, return without continue
return;
}
// to do validate after save.
validateAnalysis(anaItem);
if (!isConnectedAvailable(anaItem)) {
return;
}
if (log.isInfoEnabled()) {
addTaggedVaLueIntoConnection(anaItem);
}
AnalysisType analysisType = anaItem.getAnalysis().getParameters().getAnalysisType();
if (AnalysisType.COLUMNS_COMPARISON.equals(analysisType)) {
// If the analysis type is column comparison, ask user to continue to run or not.
if (!isContinueRun()) {
return;
}
} else if (AnalysisType.CONNECTION.equals(analysisType)) {
// If the analysis type is overview analysis, reload the database.
// TODO check here the needed of reloading database
reloadConnection(anaItem);
}
// when the run comes from context menu, the listener is null
if (this.listener == null && !ProxyRepositoryManager.getInstance().isLocked(anaItem)) {
if (!ProxyRepositoryFactory.getInstance().isEditableAndLockIfPossible(anaItem)) {
// if the analysis is not editable , return without running.
isNeedUnlock = false;
return;
} else {
// it is locked here, means that it need the unlock too.
isNeedUnlock = true;
}
} else {
isNeedUnlock = false;
}
final WorkspaceJob job = new // $NON-NLS-1$
WorkspaceJob(// $NON-NLS-1$
"Run Analysis") {
@Override
public IStatus runInWorkspace(IProgressMonitor monitor) throws CoreException {
final boolean isSupportDynamicChart = isSupportDynamicChart(anaItem);
monitor.beginTask(DefaultMessagesImpl.getString("RunAnalysisAction.running", anaItem.getAnalysis().getName()), // $NON-NLS-1$
100);
Display.getDefault().syncExec(new Runnable() {
public void run() {
if (listener != null) {
listener.fireRuningItemChanged(false, isSupportDynamicChart);
}
// register dynamic event for who supported dynamic chart
if (isSupportDynamicChart) {
EventManager.getInstance().publish(anaItem.getAnalysis(), EventEnum.DQ_DYNAMIC_REGISTER_DYNAMIC_CHART, null);
}
}
});
ReturnCode executed = null;
try {
monitor.worked(10);
executed = AnalysisExecutorSelector.executeAnalysis(anaItem, monitor);
if (monitor.isCanceled()) {
TdqAnalysisConnectionPool.closeConnectionPool(anaItem.getAnalysis());
// $NON-NLS-1$
executed = new ReturnCode(DefaultMessagesImpl.getString("RunAnalysisAction.TaskCancel"), false);
monitor.done();
if (isNeedUnlock) {
unlockAnalysis(anaItem);
}
return Status.CANCEL_STATUS;
}
if (isNeedUnlock) {
unlockAnalysis(anaItem);
}
// $NON-NLS-1$
monitor.subTask(DefaultMessagesImpl.getString("RunAnalysisAction.refresh.page"));
} finally {
// if any exception, still need to unregister dynamic events.
Display.getDefault().syncExec(new Runnable() {
public void run() {
// the analysis
if (isSupportDynamicChart) {
EventManager.getInstance().publish(anaItem.getAnalysis(), EventEnum.DQ_DYNAMIC_UNREGISTER_DYNAMIC_CHART, null);
}
if (listener != null) {
listener.fireRuningItemChanged(true);
} else {
// TODO yyin publish the event from listener.
EventManager.getInstance().publish(anaItem.getAnalysis(), EventEnum.DQ_ANALYSIS_RUN_FROM_MENU, null);
}
}
});
}
displayResultStatus(executed, anaItem);
// TODO move this code to the right place
addAnalysisToRef(anaItem.getAnalysis());
monitor.worked(20);
monitor.done();
return Status.OK_STATUS;
}
};
job.setUser(true);
job.schedule();
// TDQ-11433: fix the job name still show after run analysis for remote project.(maybe this is not the best
// way to fix this issue)
job.addJobChangeListener(new JobChangeAdapter() {
/*
* (non-Javadoc)
*
* @see
* org.eclipse.core.runtime.jobs.JobChangeAdapter#done(org.eclipse.core.runtime.jobs.IJobChangeEvent)
*/
@Override
public void done(IJobChangeEvent event) {
// $NON-NLS-1$
job.setName("");
}
});
// TDQ-11433~
} catch (BusinessException e) {
ExceptionHandler.process(e, Level.FATAL);
}
}
use of org.talend.utils.sugars.ReturnCode in project tdq-studio-se by Talend.
the class ImportPatternsWizard method performFinish.
/*
* (non-Javadoc)
*
* @see org.eclipse.jface.wizard.Wizard#performFinish()
*/
@Override
public boolean performFinish() {
if (IMessageProvider.WARNING == page.getMessageType()) {
if (!// $NON-NLS-1$
MessageDialog.openConfirm(// $NON-NLS-1$
null, // $NON-NLS-1$
DefaultMessagesImpl.getString("ImportPatternsWizard.Warning"), DefaultMessagesImpl.getString("ImportPatternsWizard.ConfirmImport", page.getMessage()))) {
// $NON-NLS-1$
return false;
}
}
File file = new File(page.getSourceFile());
final List<ReturnCode> information = ImportFactory.importToStucture(file, folder, type, page.getSkip(), page.getRename());
if (0 < information.size()) {
Display.getDefault().asyncExec(new Runnable() {
public void run() {
ImportInfoDialog.openImportInformation(getShell(), DefaultMessagesImpl.getString("ImportInfoDialog.INFO_TSK"), // $NON-NLS-1$
information.toArray(new ReturnCode[0]));
}
});
}
return true;
}
use of org.talend.utils.sugars.ReturnCode in project tdq-studio-se by Talend.
the class ChangeConnectionAction method changedDatabaseConnection.
private ReturnCode changedDatabaseConnection() throws ReloadCompareException {
Shell shell = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell();
final EList<ModelElement> analyzedElements = analysisItem.getAnalysis().getContext() == null ? null : analysisItem.getAnalysis().getContext().getAnalysedElements();
if (analyzedElements == null || analyzedElements.size() == 0) {
analysisItem.getAnalysis().getContext().setConnection(newDataProvider);
return new ReturnCode(Boolean.TRUE);
}
// MOD qiongli 2011-1-10,feature 16796.
if (oldDataProvider instanceof DelimitedFileConnection) {
// "Can't change this connection!");
if (!// $NON-NLS-1$
MessageDialog.openConfirm(// $NON-NLS-1$
shell, // $NON-NLS-1$
DefaultMessagesImpl.getString("ChangeConnectionAction.ChangeConnection"), DefaultMessagesImpl.getString("ChangeConnectionAction.ChangeConnectionTips"))) {
// $NON-NLS-1$
return new ReturnCode(Boolean.FALSE);
}
}
// Open synchronized dialog.
boolean retCode = MessageDialog.openQuestion(shell, // $NON-NLS-1$
DefaultMessagesImpl.getString("ChangeConnectionAction.ChangeConnection"), // $NON-NLS-1$
DefaultMessagesImpl.getString("ChangeConnectionAction.MayCauseAsynProblem"));
if (retCode) {
if (analyzedElements.get(0) instanceof TdColumn) {
anaEleSynDialog = new AnalyzedColumnsSynDialog(shell, analysisItem.getAnalysis(), newDataProvider, analyzedElements);
} else if (analyzedElements.get(0) instanceof ColumnSet) {
anaEleSynDialog = new AnalyzedColumnSetsSynDialog(shell, analysisItem.getAnalysis(), newDataProvider, analyzedElements);
} else if (analyzedElements.get(0) instanceof Package) {
anaEleSynDialog = new AnalyzedPackageSynDialog(shell, analysisItem.getAnalysis(), newDataProvider, analyzedElements);
}
final List<SynTreeModel> treeModelLs = anaEleSynDialog == null ? null : anaEleSynDialog.getSynInputModel();
if (treeModelLs != null && treeModelLs.size() > 0) {
// Make attempt to reload from db before showing asyned
// message.
boolean isReload = MessageDialog.openQuestion(shell, // $NON-NLS-1$
DefaultMessagesImpl.getString("ChangeConnectionAction.ReloadFromDatabase"), // $NON-NLS-1$
DefaultMessagesImpl.getString("ChangeConnectionAction.ExistElementAsynchronuos"));
if (isReload) {
ModelElement newDataProviderModel = treeModelLs.get(0).getNewDataProvElement();
if (newDataProviderModel != null && (newDataProviderModel instanceof ColumnSet || newDataProviderModel instanceof Package)) {
if (newDataProviderModel instanceof Package) {
IRunnableWithProgress op = new IRunnableWithProgress() {
public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
try {
reloadByColumnSetFolderLevel(treeModelLs, anaEleSynDialog, newDataProvider);
if (analyzedElements.get(0) instanceof TdColumn) {
// Reload column folder
reloadByColumnFolderLevel(treeModelLs, anaEleSynDialog, newDataProvider);
}
} catch (ReloadCompareException e) {
log.error(e, e);
}
}
};
try {
ProgressUI.popProgressDialog(op);
} catch (InvocationTargetException e) {
log.error(e, e);
} catch (InterruptedException e) {
log.error(e, e);
}
} else if (newDataProviderModel instanceof ColumnSet) {
IRunnableWithProgress op = new IRunnableWithProgress() {
public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
try {
reloadByColumnFolderLevel(treeModelLs, anaEleSynDialog, newDataProvider);
} catch (ReloadCompareException e) {
log.error(e, e);
}
}
};
try {
ProgressUI.popProgressDialog(op);
} catch (InvocationTargetException e) {
log.error(e, e);
} catch (InterruptedException e) {
log.error(e, e);
}
}
}
}
}
// Open asyned dialog.
if (treeModelLs != null && treeModelLs.size() > 0) {
// Open confirmation dialog to see whether user want to
// continue or not.
int returnCode = anaEleSynDialog.open();
if (returnCode != Window.OK) {
return new ReturnCode(Boolean.FALSE);
}
}
// Synchronize analyzed elements.
boolean isExistSynedElement = synAnalyzedElements(anaEleSynDialog, analysisItem.getAnalysis(), oldDataProvider, newDataProvider);
// Add new dependencies.
if (isExistSynedElement) {
DependenciesHandler.getInstance().setDependencyOn(analysisItem.getAnalysis(), newDataProvider);
ElementWriterFactory.getInstance().createDataProviderWriter().save(newDataProvider);
}
// Refresh analysis editor viewer.
ElementWriterFactory.getInstance().createAnalysisWrite().save(analysisItem, false);
// Refresh the repository tree view to adapt for the new analysis
CorePlugin.getDefault().refreshDQView(RepositoryNodeHelper.getDataProfilingFolderNode(EResourceConstant.ANALYSIS));
} else {
return new ReturnCode(Boolean.FALSE);
}
return new ReturnCode(Boolean.TRUE);
}
Aggregations