use of org.talend.dataquality.indicators.RowCountIndicator in project tdq-studio-se by Talend.
the class ItemRecordTest method testLoadProperty.
/**
* Test method for {@link org.talend.dataprofiler.core.ui.imex.model.ItemRecord#loadProperty()}.
*
* @throws PersistenceException
*/
@Test
public void testLoadProperty() throws PersistenceException {
chooseRightProject();
// $NON-NLS-1$
Property analysisProperty = createAnalysis("ItemRecordTestanalysis1");
TDQAnalysisItem item = (TDQAnalysisItem) analysisProperty.getItem();
Analysis analysis = item.getAnalysis();
AnalysisResult createAnalysisResult = analysis.getResults();
Assert.assertEquals(0, createAnalysisResult.getIndicators().size());
// create Indicator
RowCountIndicator rowCountIndicator = IndicatorsFactory.eINSTANCE.createRowCountIndicator();
String rowCountPropertyID = EcoreUtil.generateUUID();
// $NON-NLS-1$
saveIndicatorDefintion(rowCountPropertyID, "ItemRecordWithRefreshedTestIndicatorDefinition1");
rowCountIndicator.setIndicatorDefinition(((TDQIndicatorDefinitionItem) ProxyRepositoryFactory.getInstance().getLastVersion(rowCountPropertyID).getProperty().getItem()).getIndicatorDefinition());
// $NON-NLS-1$
Assert.assertNotNull("Row count indicator definition should not be null", rowCountIndicator.getIndicatorDefinition());
Assert.assertEquals("ItemRecordWithRefreshedTestIndicatorDefinition1", // $NON-NLS-1$
rowCountIndicator.getIndicatorDefinition().getLabel());
createAnalysisResult.getIndicators().add(rowCountIndicator);
Assert.assertEquals(1, createAnalysisResult.getIndicators().size());
ReturnCode saveAnalysis = saveAnalysis(analysis);
Assert.assertEquals(1, ((TDQAnalysisItem) analysisProperty.getItem()).getAnalysis().getResults().getIndicators().size());
// $NON-NLS-1$
Assert.assertTrue("The analysis first time saving is not work", saveAnalysis.isOk());
File analysisFile = WorkspaceUtils.ifileToFile(PropertyHelper.getItemFile(analysisProperty));
ItemRecord itemRecord = new ItemRecord(analysisFile);
Assert.assertEquals(1, itemRecord.getDependencySet().size());
// create Indicator
NullCountIndicator nullCountIndicator = IndicatorsFactory.eINSTANCE.createNullCountIndicator();
String nullCountPropertyID = EcoreUtil.generateUUID();
// $NON-NLS-1$
saveIndicatorDefintion(nullCountPropertyID, "ItemRecordWithRefreshedTestIndicatorDefinition2");
nullCountIndicator.setIndicatorDefinition(((TDQIndicatorDefinitionItem) ProxyRepositoryFactory.getInstance().getLastVersion(nullCountPropertyID).getProperty().getItem()).getIndicatorDefinition());
analysis = item.getAnalysis();
analysis.getResults().getIndicators().add(nullCountIndicator);
ReturnCode saveAnalysis2 = saveAnalysis(analysis);
// $NON-NLS-1$
Assert.assertTrue("The analysis second time saving is not work", saveAnalysis2.isOk());
// get last resource so that the dependecy will not changed
itemRecord = new ItemRecord(analysisFile);
Assert.assertEquals(1, itemRecord.getDependencySet().size());
// after clear the resource will be lastest so that the dependency is added
ItemRecord.clear();
itemRecord = new ItemRecord(analysisFile);
Assert.assertEquals(2, itemRecord.getDependencySet().size());
}
use of org.talend.dataquality.indicators.RowCountIndicator in project tdq-studio-se by Talend.
the class IndicatorHelperTest method testGetRowCountIndicator2.
/**
* Test method for
* {@link org.talend.dataquality.helpers.IndicatorHelper#getRowCountIndicator(orgomg.cwm.objectmodel.core.ModelElement, java.util.Map)}
* . get RowCountIndicator
*/
@Test
public void testGetRowCountIndicator2() {
// TdColumn
TdColumn column1 = RelationalFactory.eINSTANCE.createTdColumn();
// ~
// List
List<Indicator> list = null;
// ~
// Map
Map<ModelElement, List<Indicator>> elementToIndicator = new HashMap<ModelElement, List<Indicator>>();
elementToIndicator.put(column1, list);
// ~
RowCountIndicator rowCountIndicator2 = IndicatorHelper.getRowCountIndicator(column1, elementToIndicator);
assert (rowCountIndicator2 == null);
}
use of org.talend.dataquality.indicators.RowCountIndicator in project tdq-studio-se by Talend.
the class ColumnAnalysisSqlExecutor method addElements2IndicatorsMapping.
/**
* add mapping of analyzed elements to their indicators.
*
* @param elementToIndicator
* @param indicator
*/
protected void addElements2IndicatorsMapping(Map<ModelElement, List<Indicator>> elementToIndicator, Indicator indicator) {
// to set rowcount for each element
if (indicator instanceof RowCountIndicatorsAdapter) {
RowCountIndicatorsAdapter indicator1 = (RowCountIndicatorsAdapter) indicator;
Set<RowCountIndicator> rowCountIndiSet = indicator1.getRowCountIndiSet();
for (RowCountIndicator rowCountInd : rowCountIndiSet) {
MultiMapHelper.addUniqueObjectToListMap(rowCountInd.getAnalyzedElement(), indicator, elementToIndicator);
}
} else {
MultiMapHelper.addUniqueObjectToListMap(indicator.getAnalyzedElement(), indicator, elementToIndicator);
}
}
use of org.talend.dataquality.indicators.RowCountIndicator in project tdq-studio-se by Talend.
the class ColumnAnalysisSqlExecutor method setRowCountAndNullCount.
/**
* DOC scorreia Comment method "setRowCountAndNullCount".
*
* @param elementToIndicator
*/
protected void setRowCountAndNullCount(Map<ModelElement, List<Indicator>> elementToIndicator) {
Set<ModelElement> analyzedElements = elementToIndicator.keySet();
for (ModelElement modelElement : analyzedElements) {
// get row count indicator
RowCountIndicator rowCount = IndicatorHelper.getRowCountIndicator(modelElement, elementToIndicator);
// get null count indicator
NullCountIndicator nullCount = IndicatorHelper.getNullCountIndicator(modelElement, elementToIndicator);
List<Indicator> list = elementToIndicator.get(modelElement);
for (Indicator ind : list) {
// set row count value to each indicator
if (rowCount != null && needPercentage(ind)) {
ind.setCount(rowCount.getCount());
}
// set null count value to each indicator
if (nullCount != null) {
ind.setNullCount(nullCount.getNullCount());
}
}
}
}
use of org.talend.dataquality.indicators.RowCountIndicator 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());
}
}
Aggregations