use of org.talend.dq.nodes.AnalysisRepNode in project tdq-studio-se by Talend.
the class CreateDuplicatesAnalysisAction method run.
@Override
public void run() {
ReturnCode success = new ReturnCode(true);
if (this.getColumnsMap() == null || this.getColumnsMap().isEmpty() || this.getConnection() == null) {
return;
}
try {
Set<ColumnSet> keySet = this.getColumnsMap().keySet();
for (ColumnSet cs : keySet) {
List<TdColumn> columns = this.getColumnsMap().get(cs);
// create the analysis
Analysis analysis = null;
AnalysisBuilder analysisBuilder = new AnalysisBuilder();
boolean analysisInitialized = analysisBuilder.initializeAnalysis(getAnalysisName(cs), AnalysisType.MULTIPLE_COLUMN);
if (analysisInitialized) {
analysis = analysisBuilder.getAnalysis();
}
fillMetadataToAnalysis(analysis, createDefaultAnalysisParameter(cs));
// add Connection into the Analysis Context
analysis.getContext().setConnection(this.getConnection());
for (TdColumn theColumn : columns) {
// add TdColumn into the Analysis Context
analysis.getContext().getAnalysedElements().add(theColumn);
// create Row Count Indicator
RowCountIndicator rcIndicator = IndicatorsFactory.eINSTANCE.createRowCountIndicator();
rcIndicator.setAnalyzedElement(theColumn);
DefinitionHandler.getInstance().setDefaultIndicatorDefinition(rcIndicator);
analysis.getResults().getIndicators().add(rcIndicator);
// create Duplicate Count Indicator
DuplicateCountIndicator dcIndicator = IndicatorsFactory.eINSTANCE.createDuplicateCountIndicator();
dcIndicator.setAnalyzedElement(theColumn);
DefinitionHandler.getInstance().setDefaultIndicatorDefinition(dcIndicator);
analysis.getResults().getIndicators().add(dcIndicator);
}
// create dependencies
DependenciesHandler.getInstance().setDependencyOn(analysis, this.getConnection());
// set the domain
for (Domain domain : analysis.getParameters().getDataFilter()) {
domain.setName(analysis.getName());
}
// set execution language
analysis.getParameters().setExecutionLanguage(ExecutionLanguage.SQL);
// save the analysis
RepositoryNode analysisRepNode = (RepositoryNode) RepositoryNodeHelper.getDataProfilingFolderNode(EResourceConstant.ANALYSIS);
IFolder folder = WorkbenchUtils.getFolder(analysisRepNode);
AnalysisWriter analysisWriter = ElementWriterFactory.getInstance().createAnalysisWrite();
TypedReturnCode<Object> create = analysisWriter.create(analysis, folder);
if (create.isOk()) {
// refresh the RepositoryView
CorePlugin.getDefault().refreshDQView(analysisRepNode);
// open the editor
AnalysisRepNode anaRepNode = RepositoryNodeHelper.recursiveFindAnalysis(analysis);
AnalysisItemEditorInput analysisEditorInput = new AnalysisItemEditorInput(anaRepNode);
IRepositoryNode connectionRepNode = RepositoryNodeHelper.recursiveFind(this.getConnection());
analysisEditorInput.setConnectionNode(connectionRepNode);
CorePlugin.getDefault().openEditor(analysisEditorInput, AnalysisEditor.class.getName());
} else {
success.setOk(false);
success.setMessage(create.getMessage());
}
}
// for
} catch (Exception e) {
success.setOk(false);
success.setMessage(e.getMessage());
}
if (!success.isOk()) {
MessageUI.openError(success.getMessage());
}
}
use of org.talend.dq.nodes.AnalysisRepNode in project tdq-studio-se by Talend.
the class DuplicateAction method selectAndReveal.
/**
* DOC bZhou Comment method "selectAndReveal".
*
* Selects and reveals the newly added resource in all parts of the active workbench window's active page.
*
* @param newLabel
*
* @param duplicateObject
* @throws BusinessException
*/
private void selectAndReveal(String newLabel, Item duplicateItem) throws BusinessException {
IWorkbenchWindow workbenchWindow = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
IWorkbenchPage page = workbenchWindow.getActivePage();
IWorkbenchPart activePart = page.getActivePart();
RepositoryNode recursiveFind = null;
recursiveFind = getSelctionNode(newLabel, duplicateItem.getProperty());
if (recursiveFind != null) {
if (recursiveFind instanceof AnalysisRepNode || recursiveFind instanceof AnalysisSubFolderRepNode || recursiveFind instanceof ReportRepNode || recursiveFind instanceof ReportSubFolderRepNode) {
CorePlugin.getDefault().refreshDQView(RepositoryNodeHelper.findNearestSystemFolderNode(recursiveFind));
} else {
CorePlugin.getDefault().refreshDQView(recursiveFind.getParent());
refreshHiveConnectionParent(recursiveFind);
}
// MOD qiongli TDQ-5391 Avoid 'recursiveFind' to casue NPE .
if (activePart instanceof ISetSelectionTarget) {
ISelection selection = new StructuredSelection(recursiveFind);
((ISetSelectionTarget) activePart).selectReveal(selection);
}
}
}
Aggregations