use of org.talend.utils.sugars.ReturnCode in project tdq-studio-se by Talend.
the class AnalysisExecutorHelper method check.
/**
* Method "check" checks that the analysis can be run.
*
* @param analysis the analysis to prepare
* @return true if ok.
*/
public static ReturnCode check(Analysis analysis) {
ReturnCode rc = new ReturnCode(Boolean.TRUE);
// --- check existence of context
AnalysisContext context = analysis.getContext();
if (context == null) {
// $NON-NLS-1$
rc.setMessage(Messages.getString("AnalysisExecutor.ContextNull", analysis.getName()));
rc.setOk(Boolean.FALSE);
return rc;
}
// --- check that there exists at least on element to analyze
if (context.getAnalysedElements().size() == 0) {
// $NON-NLS-1$
rc.setMessage(Messages.getString("ColumnAnalysisExecutor.AnalysisHaveAtLeastOneColumn"));
rc.setOk(Boolean.FALSE);
return rc;
}
// --- check that the connection has been set
DataManager connection = context.getConnection();
if (connection == null) {
// $NON-NLS-1$
rc.setMessage(Messages.getString("AnalysisExecutor.NoConnectionFound", analysis.getName()));
rc.setOk(Boolean.FALSE);
return rc;
}
if (log.isInfoEnabled()) {
if (SoftwaredeploymentPackage.eINSTANCE.getDataProvider().isInstance(connection)) {
// MOD 20130225 TDQ-6632 the name of the item should be given (not the pathname)
// $NON-NLS-1$
log.info(Messages.getString("AnalysisExecutor.CONNECTIONTO", connection.getName()));
}
}
AnalysisResult results = analysis.getResults();
if (results == null) {
// $NON-NLS-1$
rc.setMessage(Messages.getString("AnalysisExecutor.AnalysisnotNotPrepareCorrect", analysis.getName()));
rc.setOk(Boolean.FALSE);
return rc;
}
// --- check the the dependeny files are exists ADDED mzhao TDQ-10428---
rc = checkDependentFiles(analysis);
return rc;
}
use of org.talend.utils.sugars.ReturnCode in project tdq-studio-se by Talend.
the class AnalysisExecutorHelper method checkDependentFiles.
/**
* Check the dependent file's existance. <br>
* 1. If exist, do "hot" content copy from dependent file to built-in. <br>
* 2. If not exist 1) built-in content is not empty, do nothing, 2) built-in content is empty, ReturnCode = false
* and return. <br>
* 3. Load indicator from built-in content.
*
* @param analysis
* @return
*/
private static ReturnCode checkDependentFiles(Analysis analysis) {
ReturnCode rc = new ReturnCode(Boolean.TRUE);
List<Indicator> indicators = analysis.getResults().getIndicators();
if (indicators.size() == 0) {
rc.setOk(false);
// $NON-NLS-1$
rc.setMessage(Messages.getString("AnalysisExecutor.AnalysisNoIndicators", analysis.getName()));
return rc;
}
// Loop indicators , check the dependeny file's existence.
for (Indicator indicator : indicators) {
if (indicator.getBuiltInIndicatorDefinition() != null) {
// Built-in indicator already exist.
continue;
}
// check pattern matching indicator
rc = checkPatternMatchingIndicator(indicator);
if (!rc.isOk()) {
break;
}
// Check Indicators
rc = checkIndicator(indicator);
if (!rc.isOk()) {
break;
}
}
return rc;
}
use of org.talend.utils.sugars.ReturnCode in project tdq-studio-se by Talend.
the class AnalysisExecutorHelper method checkIndicatorWithChild.
/**
* DOC zhao Comment method "checkIndicatorWithChild".
*
* @param indicator
* @return
*/
private static ReturnCode checkIndicatorWithChild(Indicator indicator) {
ReturnCode rc = new ReturnCode(Boolean.TRUE);
if (indicator.getBuiltInIndicatorDefinition() != null) {
return rc;
}
// Get indicator definition from dependent file
IndicatorDefinition dependentDefinition = indicator.getIndicatorDefinition();
if (isDependentFileExist(dependentDefinition)) {
IndicatorDefinition deepCopiedDefinition;
if (dependentDefinition instanceof WhereRule) {
deepCopiedDefinition = copyWhereRule((WhereRule) dependentDefinition);
} else {
deepCopiedDefinition = EObjectHelper.deepCopy(dependentDefinition);
}
// Hot copy to built-in definition.
deepCopiedDefinition.getSupplierDependency().clear();
// TDQ-10737 Because 'BuiltInIndicatorDefinition' is a containment reference, need to Clear these 3 non-containment
// reference list
deepCopiedDefinition.getCategories().clear();
deepCopiedDefinition.getAggregatedDefinitions().clear();
deepCopiedDefinition.getSubCategories().clear();
indicator.setBuiltInIndicatorDefinition(deepCopiedDefinition);
EMFUtil.saveResource(indicator.eResource());
} else {
IndicatorDefinition builtInDefinition = indicator.getBuiltInIndicatorDefinition();
if (builtInDefinition == null) {
// $NON-NLS-1$
rc.setMessage(Messages.getString("AnalysisExecutor.BuiltInNoIndicators"));
rc.setOk(false);
return rc;
} else {
indicator.setIndicatorDefinition(null);
}
}
return rc;
}
use of org.talend.utils.sugars.ReturnCode in project tdq-studio-se by Talend.
the class ResourceService method initResourcePersistence.
/**
* DOC bzhou Comment method "initResourcePersistence".
*/
public static ReturnCode initResourcePersistence() {
ReturnCode rc = new ReturnCode();
try {
IPath[] allPathes = EResourceConstant.getPathes();
if (allPathes != null) {
for (IPath path : allPathes) {
IFolder folder = ResourceManager.getRootProject().getFolder(path);
if (folder.exists()) {
QualifiedName[] qualifications = EResourceConstant.findQualificationsByPath(path.toString());
for (QualifiedName qualification : qualifications) {
if (qualification == ResourceConstant.READONLY) {
setReadOnlyProperty(folder);
}
if (qualification == ResourceConstant.NO_SUBFOLDER) {
setNoSubFolderProperty(folder);
}
}
}
}
}
rc.setOk(true);
} catch (CoreException e) {
rc.setOk(false);
rc.setMessage(e.getMessage());
}
return rc;
}
use of org.talend.utils.sugars.ReturnCode in project tdq-studio-se by Talend.
the class ReloadDatabaseAction method run.
/*
* (non-Javadoc)
*
* @see org.eclipse.jface.action.Action#run()
*/
@Override
public void run() {
returnCode = new ReturnCode(true);
if (!isSupport()) {
// $NON-NLS-1$
returnCode.setReturnCode(Messages.getString("ReloadDatabaseAction.NotSupportMessage"), false);
return;
}
// MOD TDQ-7528 20130627 yyin: if needCompare=false,no need to popup select compare dialog
if (this.needCompare) {
// popup a dialog to warn the user better do the compare before the reload, and provide two buttons:
// if the user click the compare button, the compare will be executed.
// if the user click the reload button, the reload will continue.
// $NON-NLS-1$
String[] dialogButtonLabels = { Messages.getString("ReloadDatabaseAction.ReloadLabel") };
MessageDialog dialog = new MessageDialog(CorePlugin.getDefault().getWorkbench().getActiveWorkbenchWindow().getShell(), Messages.getString("ReloadDatabaseAction.ReloadLabel"), null, Messages.getString("ReloadDatabaseAction.IsContinue"), 3, dialogButtonLabels, // $NON-NLS-1$ //$NON-NLS-2$
SWT.NONE);
int open = dialog.open();
// when click close, do nothing.
if (open == -1) {
return;
}
// when click compare
// if (open == 0) {
// // go to compare instead of reloading now
// new PopComparisonUIAction(selectedObject, Messages.getString("ReloadDatabaseAction.CompareLabel")).run();//$NON-NLS-1$
// returnCode.setReturnCode(Messages.getString("ReloadDatabaseAction.IsContinue"), false);//$NON-NLS-1$
// return;
// }// ~
}
Connection conn = getConnection();
List<ModelElement> dependencyClients = EObjectHelper.getDependencyClients(conn);
if (!(dependencyClients == null || dependencyClients.isEmpty())) {
int isOk = DeleteModelElementConfirmDialog.showElementImpactConfirmDialog(null, new ModelElement[] { conn }, // $NON-NLS-1$
DefaultMessagesImpl.getString("TOPRepositoryService.dependcyTile"), // $NON-NLS-1$
DefaultMessagesImpl.getString("TOPRepositoryService.dependcyMessage", conn.getLabel()));
if (isOk != Dialog.OK) {
// $NON-NLS-1$
returnCode.setReturnCode("The user canceled the operation!", false);
return;
}
}
IRunnableWithProgress op = new IRunnableWithProgress() {
@Override
public void run(IProgressMonitor monitor) throws InvocationTargetException {
final IComparisonLevel creatComparisonLevel = ComparisonLevelFactory.creatComparisonLevel(selectedObject);
Display.getDefault().asyncExec(new Runnable() {
@Override
public void run() {
try {
Connection oldDataProvider = creatComparisonLevel.reloadCurrentLevelElement();
// MOD mzhao 2009-07-13 bug 7454 Impact existing analysis.
// MOD qiongli 2011-9-8,move method 'impactExistingAnalyses(...)' to class WorkbenchUtils
// update the sql explore.
Property property = PropertyHelper.getProperty(oldDataProvider);
if (property != null) {
Item newItem = property.getItem();
if (newItem != null) {
CWMPlugin.getDefault().updateConnetionAliasByName(oldDataProvider, oldDataProvider.getLabel());
}
}
// update the related analyses.
WorkbenchUtils.impactExistingAnalyses(oldDataProvider);
// Update software system.
updateSoftwareSystem(oldDataProvider);
} catch (ReloadCompareException e) {
// $NON-NLS-1$
MessageUI.openError(Messages.getString("ReloadDatabaseAction.Error", e.getMessage()));
log.error(e, e);
returnCode.setReturnCode(e.getMessage(), false);
} catch (PartInitException e) {
log.error(e, e);
returnCode.setReturnCode(e.getMessage(), false);
}
}
});
}
};
try {
ProgressUI.popProgressDialog(op);
CorePlugin.getDefault().refreshDQView(selectedObject);
} catch (InvocationTargetException e) {
// $NON-NLS-1$
MessageUI.openError(Messages.getString("ReloadDatabaseAction.checkConnectionFailured", e.getCause().getMessage()));
log.error(e, e);
} catch (InterruptedException e) {
log.error(e, e);
}
}
Aggregations