use of org.talend.dataquality.analysis.AnalysisContext in project tdq-studio-se by Talend.
the class WorkbenchUtilsTest method testUpdateDependAnalysisOfDelimitedFile_3.
// test for no column remained
@Test
public void testUpdateDependAnalysisOfDelimitedFile_3() throws IOException, URISyntaxException, PartInitException, BusinessException {
// create a file connection
DelimitedFileConnection fileConnection = ConnectionPackage.eINSTANCE.getConnectionFactory().createDelimitedFileConnection();
// $NON-NLS-1$
URL fileUrl = this.getClass().getResource("file1");
MetadataTable metadataTable = UnitTestBuildHelper.initFileConnection(fileUrl, fileConnection);
UnitTestBuildHelper.initColumns(metadataTable);
IFile file = WorkspaceUtils.fileToIFile(new File(FileLocator.toFileURL(fileUrl).toURI()));
IPath itemPath = file.getFullPath();
Property connectionProperty = PropertiesFactory.eINSTANCE.createProperty();
connectionProperty.setAuthor(((RepositoryContext) CoreRuntimePlugin.getInstance().getContext().getProperty(Context.REPOSITORY_CONTEXT_KEY)).getUser());
connectionProperty.setVersion(VersionUtils.DEFAULT_VERSION);
// $NON-NLS-1$
connectionProperty.setStatusCode("");
connectionProperty.setLabel("file3");
DelimitedFileConnectionItem connectionItem = PropertiesFactory.eINSTANCE.createDelimitedFileConnectionItem();
connectionItem.setProperty(connectionProperty);
connectionItem.setConnection(fileConnection);
try {
ProxyRepositoryFactory.getInstance().create(connectionItem, itemPath.removeFirstSegments(3).removeLastSegments(1));
} catch (PersistenceException e) {
Assert.fail(e.getMessage());
}
// create an analysis which use the columns in the file connection
Analysis analysis = UnitTestBuildHelper.createRealAnalysis("Ana01", null, false);
AnalysisContext context = AnalysisPackage.eINSTANCE.getAnalysisFactory().createAnalysisContext();
context.setConnection(fileConnection);
analysis.setContext(context);
context.getAnalysedElements().addAll(metadataTable.getColumns());
DependenciesHandler.getInstance().setDependencyOn(analysis, fileConnection);
ElementWriterFactory.getInstance().createAnalysisWrite().save(analysis);
// change the file's schema
List<MetadataColumn> tempNewColumns = new ArrayList<MetadataColumn>();
MetadataColumn name = ConnectionPackage.eINSTANCE.getConnectionFactory().createMetadataColumn();
name.setName("name2");
name.setLabel("name2");
tempNewColumns.add(name);
MetadataColumn country = ConnectionPackage.eINSTANCE.getConnectionFactory().createMetadataColumn();
country.setName("country2");
country.setLabel("country2");
tempNewColumns.add(country);
MetadataColumn country1 = ConnectionPackage.eINSTANCE.getConnectionFactory().createMetadataColumn();
country1.setName("country1");
country1.setLabel("country1");
tempNewColumns.add(country1);
metadataTable.getFeature().clear();
metadataTable.getFeature().addAll(tempNewColumns);
// before compare, the analysis has 5 analyzed elements
Assert.assertEquals(5, analysis.getContext().getAnalysedElements().size());
// call the tested method
WorkbenchUtils.reloadMetadataOfDelimitedFile(metadataTable);
List<MetadataColumn> afterCompareColumns = metadataTable.getColumns();
// check the columns
Assert.assertEquals(3, afterCompareColumns.size());
Assert.assertEquals("name2", afterCompareColumns.get(0).getLabel());
Assert.assertEquals("country2", afterCompareColumns.get(1).getLabel());
Assert.assertEquals("country1", afterCompareColumns.get(2).getLabel());
metadataTable.getColumns().clear();
metadataTable.getColumns().addAll(afterCompareColumns);
WorkbenchUtils.impactExistingAnalyses(fileConnection);
// check the depended analysis
EList<Dependency> clientDependencies = fileConnection.getSupplierDependency();
for (Dependency dep : clientDependencies) {
for (ModelElement mod : dep.getClient()) {
if (!(mod instanceof Analysis)) {
continue;
}
Analysis ana = (Analysis) mod;
// assert the column with same name still in the analysis
Assert.assertNotNull(ana.getContext().getAnalysedElements());
// should be: only 2 with same name remained
Assert.assertEquals(0, ana.getContext().getAnalysedElements().size());
}
}
}
use of org.talend.dataquality.analysis.AnalysisContext in project tdq-studio-se by Talend.
the class RespositoryDetailView method createAnaysisDetail.
private void createAnaysisDetail(Analysis ana) {
if (ana == null) {
return;
}
createName(ana);
createPurpose(ana);
createDescription(ana);
AnalysisParameters parameters = ana.getParameters();
String description = parameters == null ? null : parameters.getAnalysisType().getLiteral();
// $NON-NLS-1$
newLabelAndText(gContainer, DefaultMessagesImpl.getString("RespositoryDetailView.otherType"), description);
AnalysisContext context = ana.getContext();
int numn = context == null ? 0 : context.getAnalysedElements().size();
newLabelAndText(gContainer, DefaultMessagesImpl.getString("RespositoryDetailView.numberOfAnalyzedElements"), // $NON-NLS-1$
String.valueOf(numn));
DataManager connection = context == null ? null : context.getConnection();
if (connection == null) {
description = null;
} else {
description = connection.getName();
}
// $NON-NLS-1$
newLabelAndText(gContainer, DefaultMessagesImpl.getString("RespositoryDetailView.connection"), description);
}
use of org.talend.dataquality.analysis.AnalysisContext in project tdq-studio-se by Talend.
the class AnalysisSubFolderRepNode method getCount.
public String getCount() {
IRepositoryViewObject anaViewObject = this.getParent().getObject();
if (anaViewObject.getProperty() != null) {
TDQAnalysisItem item = (TDQAnalysisItem) anaViewObject.getProperty().getItem();
Analysis analysis = item.getAnalysis();
AnalysisContext context = analysis.getContext();
EList<ModelElement> analysedElements = context.getAnalysedElements();
if (analysedElements.size() == 1) {
ModelElement modelElement = analysedElements.get(0);
if (modelElement instanceof DatabaseConnection) {
EList<Package> dataPackage = ((DatabaseConnection) modelElement).getDataPackage();
// $NON-NLS-1$ //$NON-NLS-2$
return "(" + dataPackage.size() + ")";
}
}
// $NON-NLS-1$ //$NON-NLS-2$
return "(" + analysedElements.size() + ")";
}
// $NON-NLS-1$
return "(0)";
}
use of org.talend.dataquality.analysis.AnalysisContext in project tdq-studio-se by Talend.
the class AnalysisBaseBuilder method setAnalysisConnection.
public boolean setAnalysisConnection(DataManager dataManager) {
if (!initialized) {
log.error(ANALYSIS_NOT_INITIALIZED);
return false;
}
AnalysisContext context = analysis.getContext();
if (context == null) {
// $NON-NLS-1$
log.error(Messages.getString("AnalysisBuilder.CONTEXTISNULL"));
return false;
}
context.setConnection(dataManager);
return true;
}
use of org.talend.dataquality.analysis.AnalysisContext in project tdq-studio-se by Talend.
the class EObjectHelper method getFirstDependency.
/**
* get the first Dependency of node(only used for METADATA_CON_TABLE and METADATA_CON_VIEW).
*
* @param node
* @return
*/
public static List<ModelElement> getFirstDependency(IRepositoryNode node) {
List<ModelElement> result = new ArrayList<ModelElement>();
if (node == null) {
return result;
}
// use the connection supplier to get analyses, and then check them when they use the droped table
// get the connection
ModelElement deleteModel = RepositoryNodeHelper.getMetadataElement(node);
Connection connection = ModelElementHelper.getConnection(deleteModel);
if (connection == null) {
return result;
}
// get the supplier Dependency of the connection
EList<Dependency> supplierDependency = connection.getSupplierDependency();
if (supplierDependency != null && supplierDependency.size() > 0) {
EList<ModelElement> clients = supplierDependency.get(0).getClient();
for (ModelElement client : clients) {
if (!(client instanceof Analysis)) {
continue;
}
Analysis analysis = (Analysis) client;
if (analysis.eIsProxy()) {
analysis = (Analysis) EObjectHelper.resolveObject(analysis);
}
AnalysisContext context = analysis.getContext();
EList<ModelElement> analysedElements = context.getAnalysedElements();
if (analysedElements != null && analysedElements.size() > 0) {
ModelElement analysisModel = null;
ModelElement firstAnalysisElement = analysedElements.get(0);
if (firstAnalysisElement instanceof MetadataColumn) {
analysisModel = ModelElementHelper.getContainer(firstAnalysisElement);
} else if (firstAnalysisElement instanceof MetadataTable) {
analysisModel = firstAnalysisElement;
}
if (compareModelElement(deleteModel, analysisModel)) {
result.add(analysis);
break;
}
}
}
}
return result;
}
Aggregations