use of org.talend.dataquality.analysis.AnalysisContext in project tdq-studio-se by Talend.
the class RowMatchExplorerTest method setUpBeforeClass.
@BeforeClass
public static void setUpBeforeClass() throws Exception {
// analysis
analysis = AnalysisFactory.eINSTANCE.createAnalysis();
AnalysisContext context = AnalysisFactory.eINSTANCE.createAnalysisContext();
analysis.setContext(context);
AnalysisResult mockResults = AnalysisFactory.eINSTANCE.createAnalysisResult();
analysis.setResults(mockResults);
// connection
connection = ConnectionFactory.eINSTANCE.createDatabaseConnection();
analysis.getContext().setConnection(connection);
TaggedValueHelper.setTaggedValue(connection, TaggedValueHelper.DB_PRODUCT_NAME, TaggedValueHelper.DB_PRODUCT_NAME);
// ------------------------- table A ------------------------------
Catalog catalogA = orgomg.cwm.resource.relational.RelationalFactory.eINSTANCE.createCatalog();
// $NON-NLS-1$
catalogA.setName("catalogA");
Schema schemaA = orgomg.cwm.resource.relational.RelationalFactory.eINSTANCE.createSchema();
// $NON-NLS-1$
schemaA.setName("schemaA");
catalogA.getOwnedElement().add(schemaA);
TdTable tableA = RelationalFactory.eINSTANCE.createTdTable();
// $NON-NLS-1$
tableA.setName("tableA");
schemaA.getOwnedElement().add(tableA);
TdColumn tdColumnA = RelationalFactory.eINSTANCE.createTdColumn();
// $NON-NLS-1$
tdColumnA.setName("columnA");
tableA.getFeature().add(tdColumnA);
// ------------------------- table B ------------------------------
Catalog catalogB = orgomg.cwm.resource.relational.RelationalFactory.eINSTANCE.createCatalog();
// $NON-NLS-1$
catalogB.setName("catalogB");
Schema schemaB = orgomg.cwm.resource.relational.RelationalFactory.eINSTANCE.createSchema();
// $NON-NLS-1$
schemaB.setName("schemaB");
catalogB.getOwnedElement().add(schemaB);
TdTable tableB = org.talend.cwm.relational.RelationalFactory.eINSTANCE.createTdTable();
// $NON-NLS-1$
tableB.setName("tableB");
schemaB.getOwnedElement().add(tableB);
TdColumn tdColumnB = org.talend.cwm.relational.RelationalFactory.eINSTANCE.createTdColumn();
// $NON-NLS-1$
tdColumnB.setName("columnB");
tableB.getFeature().add(tdColumnB);
// indicator
RowMatchingIndicator rowMatchingIndicator = ColumnsetFactory.eINSTANCE.createRowMatchingIndicator();
// create indicatorDefinition
IndicatorDefinition testIndicatorDefinition = DefinitionFactory.eINSTANCE.createIndicatorDefinition();
// $NON-NLS-1$
testIndicatorDefinition.setName("RowMatchingIndicator");
rowMatchingIndicator.setIndicatorDefinition(testIndicatorDefinition);
analysis.getResults().getIndicators().add(rowMatchingIndicator);
TaggedValueHelper.setTaggedValue(analysis, TaggedValueHelper.PURPOSE, TaggedValueHelper.PURPOSE);
TaggedValueHelper.setTaggedValue(analysis, TaggedValueHelper.DESCRIPTION, TaggedValueHelper.DESCRIPTION);
rowMatchingIndicator.setAnalyzedElement(tableA);
rowMatchingIndicator.getColumnSetA().add(tdColumnA);
rowMatchingIndicator.getColumnSetB().add(tdColumnB);
explorer = new RowMatchExplorer();
entity = new ChartDataEntity();
entity.setIndicator(rowMatchingIndicator);
}
use of org.talend.dataquality.analysis.AnalysisContext in project tdq-studio-se by Talend.
the class WorkbenchUtils method impactExistingAnalyses.
/**
* DOC qiongli TDQ-3317:move this method from ReloadDatabaseAction. to this class .
*
* @param oldDataProvider
* @throws PartInitException
*/
public static void impactExistingAnalyses(DataProvider oldDataProvider) throws PartInitException {
EList<Dependency> clientDependencies = oldDataProvider.getSupplierDependency();
List<Analysis> unsynedAnalyses = new ArrayList<Analysis>();
for (Dependency dep : clientDependencies) {
for (ModelElement mod : dep.getClient()) {
// MOD mzhao 2009-08-24 The dependencies include "Property" and "Analysis"
if (!(mod instanceof Analysis)) {
continue;
}
Analysis ana = (Analysis) mod;
unsynedAnalyses.add(ana);
}
for (Analysis analysis : unsynedAnalyses) {
// Reload.
IFile file = getTempAnalysisFile(analysis);
Analysis tempAnalysis = (Analysis) AnaResourceFileHelper.getInstance().getModelElement(file);
// MOD qiongli 2010-8-17,bug 14977
if (tempAnalysis != null) {
Resource eResource = tempAnalysis.eResource();
Map<EObject, Collection<Setting>> referenceMaps = EcoreUtil.UnresolvedProxyCrossReferencer.find(eResource);
Iterator<EObject> it = referenceMaps.keySet().iterator();
ModelElement eobj = null;
boolean isModified = false;
while (it.hasNext()) {
eobj = (ModelElement) it.next();
Collection<Setting> settings = referenceMaps.get(eobj);
for (Setting setting : settings) {
if (setting.getEObject() instanceof AnalysisContext) {
tempAnalysis.getContext().getAnalysedElements().remove(eobj);
isModified = true;
} else if (setting.getEObject() instanceof Indicator) {
// the only indicator in the column set analysis. (Added TDQ-8842 20140512 yyin)
if (AnalysisType.COLUMN_SET.equals(tempAnalysis.getParameters().getAnalysisType())) {
// ~
((SimpleStatIndicator) setting.getEObject()).getAnalyzedColumns().remove(eobj);
} else {
tempAnalysis.getResults().getIndicators().remove(setting.getEObject());
}
isModified = true;
}
}
}
if (isModified) {
saveTempAnalysis(file, tempAnalysis);
}
// Should reopen this analyis's editor if it is opened now. what ever it is modified or not.
EventManager.getInstance().publish(tempAnalysis.getName(), EventEnum.DQ_ANALYSIS_REOPEN_EDITOR, null);
}
}
}
}
use of org.talend.dataquality.analysis.AnalysisContext in project tdq-studio-se by Talend.
the class DQRepositoryViewLabelProvider method addWarnIconIfNeeded.
/**
* if it is needed,add a over warning icon..eg., it is empty analysis or report; imported a MDM analysis or report.
*
* @param image
* @param node
* @param originalImageName
* @return
*/
private Image addWarnIconIfNeeded(IRepositoryNode node, String originalImageName) {
ModelElement modEle = RepositoryNodeHelper.getResourceModelElement(node);
ERepositoryObjectType objectType = node.getObjectType();
if (modEle != null) {
if (ERepositoryObjectType.TDQ_ANALYSIS_ELEMENT == objectType) {
Analysis analysis = (Analysis) modEle;
AnalysisContext context = analysis.getContext();
if (context == null) {
return ImageLib.createInvalidIcon(originalImageName);
}
EList<ModelElement> analysedElements = context.getAnalysedElements();
DataManager connection = context.getConnection();
if (analysedElements.isEmpty() || connection instanceof MDMConnection) {
return ImageLib.createInvalidIcon(originalImageName);
}
} else if (ERepositoryObjectType.TDQ_REPORT_ELEMENT == objectType) {
TdReport report = (TdReport) modEle;
EList<AnalysisMap> analysisMap = report.getAnalysisMap();
if (analysisMap.isEmpty()) {
return ImageLib.createInvalidIcon(originalImageName);
}
for (AnalysisMap anaMap : report.getAnalysisMap()) {
Analysis analysis = anaMap.getAnalysis();
if (analysis == null || analysis.getContext() == null) {
continue;
}
DataManager connection = analysis.getContext().getConnection();
if (connection instanceof MDMConnection) {
return ImageLib.createInvalidIcon(originalImageName);
}
}
}
}
return ImageLib.getImage(originalImageName);
}
use of org.talend.dataquality.analysis.AnalysisContext in project tdq-studio-se by Talend.
the class UnitTestBuildHelper method createAndInitAnalysis.
public static Analysis createAndInitAnalysis() {
Analysis ana = UnitTestBuildHelper.createRealAnalysis("anaA", null, false);
AnalysisParameters parameters = AnalysisFactory.eINSTANCE.createAnalysisParameters();
parameters.setExecutionLanguage(ExecutionLanguage.SQL);
ana.setParameters(parameters);
AnalysisContext context = AnalysisFactory.eINSTANCE.createAnalysisContext();
ana.setContext(context);
Connection createConnection = ConnectionFactory.eINSTANCE.createConnection();
createConnection.setName("MySQL");
context.setConnection(createConnection);
return ana;
}
use of org.talend.dataquality.analysis.AnalysisContext in project tdq-studio-se by Talend.
the class ColumnSetIndicatorEvaluatorTest method testExecuteSqlQuery_file.
/**
* Test method for {@link org.talend.dq.indicators.ColumnSetIndicatorEvaluator#executeSqlQuery(String)} .
*/
@Test
public void testExecuteSqlQuery_file() throws Exception {
Analysis analysis = mock(Analysis.class);
// $NON-NLS-1$
stub(method(DelimitedFileIndicatorEvaluator.class, "handleByARow"));
// $NON-NLS-1$
stub(method(DelimitedFileIndicatorEvaluator.class, "addResultToIndicatorToRowMap", Indicator.class, EMap.class));
AnalysisContext context = mock(AnalysisContext.class);
when(analysis.getContext()).thenReturn(context);
DelimitedFileConnection deliFileConn = mock(DelimitedFileConnection.class);
when(context.getConnection()).thenReturn(deliFileConn);
when(deliFileConn.isContextMode()).thenReturn(true);
when(deliFileConn.getFilePath()).thenReturn(context_fd1_File);
when(deliFileConn.getFieldSeparatorValue()).thenReturn(context_fd1_FieldSeparator);
when(deliFileConn.getEncoding()).thenReturn(context_fd1_Encoding);
IPath iPath = mock(IPath.class);
File file = new File(realFile);
BufferedWriter output = new BufferedWriter(new FileWriter(file));
String str = "id;Cocust(Tests);owner_id\n" + "1;yellow;3301\n" + "2;blue;3302\n" + "4;red;3307\n" + "5;white;4563\n" + "6;pink2;457883\n" + "7;blank;231233\n";
output.write(str);
output.close();
when(iPath.toFile()).thenReturn(file);
assertTrue(file.exists());
PowerMockito.mockStatic(JavaSqlFactory.class);
when(JavaSqlFactory.getURL(deliFileConn)).thenReturn(realFile);
when(JavaSqlFactory.getFieldSeparatorValue(deliFileConn)).thenReturn(realFieldSeparator);
when(JavaSqlFactory.getEncoding(deliFileConn)).thenReturn(realEncoding);
PowerMockito.mockStatic(ResourceBundle.class);
ResourceBundle bundle = mock(ResourceBundle.class);
// $NON-NLS-1$
when(ResourceBundle.getBundle("Messages")).thenReturn(bundle);
PowerMockito.mockStatic(Messages.class);
// $NON-NLS-1$
when(Messages.getString(anyString())).thenReturn("testString");
AnalysisResult results = mock(AnalysisResult.class);
when(analysis.getResults()).thenReturn(results);
EMap<Indicator, AnalyzedDataSet> indicToRowMap = mock(EMap.class);
when(results.getIndicToRowMap()).thenReturn(indicToRowMap);
when(deliFileConn.getHeaderValue()).thenReturn(context_fd1_Header);
when(deliFileConn.getFooterValue()).thenReturn(zero);
when(deliFileConn.getLimitValue()).thenReturn(zero);
when(deliFileConn.getEscapeType()).thenReturn(Escape.DELIMITED);
when(deliFileConn.getRowSeparatorValue()).thenReturn(context_fd1_RowSeparator);
when(deliFileConn.isSplitRecord()).thenReturn(false);
when(deliFileConn.isRemoveEmptyRow()).thenReturn(false);
when(JavaSqlFactory.getHeadValue(deliFileConn)).thenReturn(realHeading);
when(JavaSqlFactory.getRowSeparatorValue(deliFileConn)).thenReturn(realRowSeparator);
PowerMockito.mockStatic(LanguageManager.class);
when(LanguageManager.getCurrentLanguage()).thenReturn(ECodeLanguage.JAVA);
PowerMockito.mockStatic(ParameterUtil.class);
when(ParameterUtil.trimParameter(realFile)).thenReturn(realFile);
when(ParameterUtil.trimParameter(realEncoding)).thenReturn(realEncoding);
PowerMockito.mockStatic(StringUtils.class);
when(StringUtils.loadConvert(realFieldSeparator, ECodeLanguage.JAVA.getName())).thenReturn(realFieldSeparator);
when(ParameterUtil.trimParameter(realFieldSeparator)).thenReturn(realFieldSeparator);
when(StringUtils.loadConvert(realRowSeparator, ECodeLanguage.JAVA.getName())).thenReturn(realRowSeparator);
when(ParameterUtil.trimParameter(realRowSeparator)).thenReturn(realRowSeparator);
List<ModelElement> columnElementList = new BasicEList<ModelElement>();
List<MetadataColumn> columnElementList2 = new BasicEList<MetadataColumn>();
MetadataColumn mc0 = mock(MetadataColumn.class);
MetadataColumn mc1 = mock(MetadataColumn.class);
MetadataColumn mc2 = mock(MetadataColumn.class);
columnElementList.add(mc0);
columnElementList.add(mc1);
columnElementList.add(mc2);
columnElementList2.add(mc0);
columnElementList2.add(mc1);
columnElementList2.add(mc2);
EList<ModelElement> eLs = (EList<ModelElement>) columnElementList;
when(context.getAnalysedElements()).thenReturn(eLs);
PowerMockito.mockStatic(ColumnHelper.class);
MetadataTable mTable = mock(MetadataTable.class);
when(mTable.getColumns()).thenReturn((EList<MetadataColumn>) columnElementList2);
when(ColumnHelper.getColumnOwnerAsMetadataTable(mc0)).thenReturn(mTable);
when(ColumnHelper.getColumnOwnerAsMetadataTable(mc1)).thenReturn(mTable);
when(ColumnHelper.getColumnOwnerAsMetadataTable(mc2)).thenReturn(mTable);
ColumnSetIndicatorEvaluator evaluator = new ColumnSetIndicatorEvaluator(analysis);
ColumnSetIndicatorEvaluator spyEvaluator = Mockito.spy(evaluator);
Mockito.doReturn(true).when(spyEvaluator).continueRun();
ReturnCode rc = spyEvaluator.executeSqlQuery(empty);
assertTrue(rc.isOk());
}
Aggregations