use of org.talend.dq.analysis.AnalysisBuilder in project tdq-studio-se by Talend.
the class FunctionalDependencyAnalysisDetailsPage method saveAnalysis.
/*
* (non-Javadoc)
*
* @see org.talend.dataprofiler.core.ui.editor.analysis.AbstractAnalysisMetadataPage#saveAnalysis()
*/
@Override
protected void saveAnalysis() throws DataprofilerCoreException {
analysisHandler.changeDefaultRowLoaded(rowLoadedText.getText());
analysisHandler.changeSampleDataShowWay(sampleDataShowWayCombo.getText());
for (Domain domain : getCurrentModelElement().getParameters().getDataFilter()) {
domain.setName(getCurrentModelElement().getName());
}
IRepositoryViewObject reposObject = null;
getAnalysisHandler().clearAnalysis();
List<RepositoryNode> columnListAANode = anaColumnCompareViewer.getColumnListA();
List<RepositoryNode> columnListBBNode = anaColumnCompareViewer.getColumnListB();
AnalysisBuilder anaBuilder = new AnalysisBuilder();
anaBuilder.setAnalysis(getCurrentModelElement());
Connection tdDataProvider = null;
for (int i = 0; i < columnListAANode.size(); i++) {
if (columnListBBNode.size() > i) {
ColumnDependencyIndicator indicator = ColumnsetFactory.eINSTANCE.createColumnDependencyIndicator();
TdColumn columnA = (TdColumn) ((MetadataColumnRepositoryObject) columnListAANode.get(i).getObject()).getTdColumn();
TdColumn columnB = (TdColumn) ((MetadataColumnRepositoryObject) columnListBBNode.get(i).getObject()).getTdColumn();
indicator.setColumnA(columnA);
indicator.setColumnB(columnB);
indicator.setIndicatorDefinition(DefinitionHandler.getInstance().getFDRuleDefaultIndicatorDefinition());
getCurrentModelElement().getResults().getIndicators().add(indicator);
anaBuilder.addElementToAnalyze(columnA, indicator);
// ADD this line qiongli 2010-6-8
anaBuilder.addElementToAnalyze(columnB, indicator);
}
}
if (columnListAANode.size() > 0) {
reposObject = columnListAANode.get(0).getObject();
tdDataProvider = ((ConnectionItem) reposObject.getProperty().getItem()).getConnection();
// MOD qiongli bug 14437:Add dependency
getCurrentModelElement().getContext().setConnection(tdDataProvider);
TypedReturnCode<Dependency> rc = DependenciesHandler.getInstance().setDependencyOn(getCurrentModelElement(), tdDataProvider);
if (!rc.isOk()) {
// $NON-NLS-1$
log.info("fail to save dependency analysis:" + getCurrentModelElement().getFileName());
}
} else {
getCurrentModelElement().getContext().setConnection(null);
}
// save the number of connections per analysis
this.saveNumberOfConnectionsPerAnalysis();
// 2011.1.12 MOD by zhsne to unify anlysis and connection id when saving.
this.nameText.setText(getCurrentModelElement().getName());
// MOD yyi 2012-02-08 TDQ-4621:Explicitly set true for updating dependencies.
ReturnCode saved = ElementWriterFactory.getInstance().createAnalysisWrite().save(getCurrentRepNode().getObject().getProperty().getItem(), true);
// MOD yyi 2012-02-03 TDQ-3602:Avoid to rewriting all analyzes after saving, no reason to update all analyzes
// which is depended in the referred connection.
// Extract saving log function.
// @see org.talend.dataprofiler.core.ui.editor.analysis.AbstractAnalysisMetadataPage#logSaved(ReturnCode)
logSaved(saved);
anaColumnCompareViewer.setDirty(false);
dataFilterComp.setDirty(false);
}
use of org.talend.dq.analysis.AnalysisBuilder in project tdq-studio-se by Talend.
the class RedundancyAnalysisDetailsPage method saveAnalysis.
@Override
protected void saveAnalysis() throws DataprofilerCoreException {
for (Domain domain : getCurrentModelElement().getParameters().getDataFilter()) {
domain.setName(getCurrentModelElement().getName());
}
IRepositoryViewObject reposObject = null;
getAnalysisHandler().clearAnalysis();
List<ModelElement> analysedElements = new ArrayList<ModelElement>();
anaColumnCompareViewer.setColumnABForMatchingIndicator(rowMatchingIndicatorA, anaColumnCompareViewer.getColumnListA(), anaColumnCompareViewer.getColumnListB());
anaColumnCompareViewer.setColumnABForMatchingIndicator(rowMatchingIndicatorB, anaColumnCompareViewer.getColumnListB(), anaColumnCompareViewer.getColumnListA());
Connection tdDataProvider = null;
for (int i = 0; i < anaColumnCompareViewer.getColumnListA().size(); i++) {
reposObject = anaColumnCompareViewer.getColumnListA().get(i).getObject();
analysedElements.add(((MetadataColumnRepositoryObject) reposObject).getTdColumn());
}
for (int i = 0; i < anaColumnCompareViewer.getColumnListB().size(); i++) {
reposObject = anaColumnCompareViewer.getColumnListB().get(i).getObject();
analysedElements.add(((MetadataColumnRepositoryObject) reposObject).getTdColumn());
}
if (analysedElements.size() > 0) {
tdDataProvider = ConnectionHelper.getTdDataProvider((TdColumn) analysedElements.get(0));
// MOD qiongli bug 14437:Add dependency
getCurrentModelElement().getContext().setConnection(tdDataProvider);
TypedReturnCode<Dependency> rc = DependenciesHandler.getInstance().setDependencyOn(getCurrentModelElement(), tdDataProvider);
if (!rc.isOk()) {
// $NON-NLS-1$
log.info("fail to save dependency analysis:" + getCurrentModelElement().getFileName());
}
} else {
getCurrentModelElement().getContext().setConnection(null);
}
AnalysisBuilder anaBuilder = new AnalysisBuilder();
anaBuilder.setAnalysis(getCurrentModelElement());
if (anaColumnCompareViewer.getCheckComputeButton().getSelection()) {
getCurrentModelElement().getParameters().getDeactivatedIndicators().add(rowMatchingIndicatorB);
} else {
getCurrentModelElement().getParameters().getDeactivatedIndicators().clear();
}
anaBuilder.addElementsToAnalyze(analysedElements.toArray(new ModelElement[analysedElements.size()]), new Indicator[] { rowMatchingIndicatorA, rowMatchingIndicatorB });
// save the number of connections per analysis
this.saveNumberOfConnectionsPerAnalysis();
// 2011.1.12 MOD by zhsne to unify anlysis and connection id when saving.
this.nameText.setText(getCurrentModelElement().getName());
// MOD yyi 2012-02-08 TDQ-4621:Explicitly set true for updating dependencies.
ReturnCode saved = ElementWriterFactory.getInstance().createAnalysisWrite().save(getCurrentRepNode().getObject().getProperty().getItem(), true);
// MOD yyi 2012-02-03 TDQ-3602:Avoid to rewriting all analyzes after saving, no reason to update all analyzes
// which is depended in the referred connection.
// Extract saving log function.
// @see org.talend.dataprofiler.core.ui.editor.analysis.AbstractAnalysisMetadataPage#logSaved(ReturnCode)
logSaved(saved);
// ADD xqliu 2012-04-19 TDQ-5005
anaColumnCompareViewer.setDirty(false);
dataFilterCompA.setDirty(false);
dataFilterCompB.setDirty(false);
}
use of org.talend.dq.analysis.AnalysisBuilder in project tdq-studio-se by Talend.
the class AbstractAnalysisWizard method initCWMResourceBuilder.
public ModelElement initCWMResourceBuilder() {
analysisBuilder = new AnalysisBuilder();
boolean analysisInitialized = analysisBuilder.initializeAnalysis(parameter.getName(), parameter.getAnalysisType());
if (analysisInitialized) {
return analysisBuilder.getAnalysis();
}
return null;
}
use of org.talend.dq.analysis.AnalysisBuilder 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.analysis.AnalysisBuilder in project tdq-studio-se by Talend.
the class ChangeConnectionAction method synAnalyzedElements.
private boolean synAnalyzedElements(AnalyzedElementSynDialog anaEleSynDialog, Analysis synAnalysis, Connection oldDataProvider, Connection newDataProv) {
// Change connection uuid.
Map<ModelElement, ModelElement> synEleMap = anaEleSynDialog == null ? null : anaEleSynDialog.getSynedEleMap();
AnalysisBuilder anaBuilder = new AnalysisBuilder();
anaBuilder.setAnalysis(synAnalysis);
// Remove old dependencies.
boolean isRemovedDependency = DependenciesHandler.getInstance().removeConnDependencyAndSave(analysisItem);
if (!isRemovedDependency) {
return false;
}
synAnalysis.getContext().setConnection(newDataProv);
// Synchronize analysis result.
EList<Indicator> indcList = synAnalysis.getResults().getIndicators();
Indicator[] copiedIndArray = new Indicator[indcList.size()];
System.arraycopy(indcList.toArray(), 0, copiedIndArray, 0, indcList.size());
// MOD qiongli 2010-6-13,bug 12766:To column analysis, which has same
// construct connection with before and maybe have not indicator
boolean isExistSynedElement = false;
AnalysisType analysisType = synAnalysis.getParameters().getAnalysisType();
if (analysisType == AnalysisType.MULTIPLE_COLUMN) {
EList<ModelElement> meLs = synAnalysis.getContext().getAnalysedElements();
ModelElement[] mes = new ModelElement[meLs.size()];
System.arraycopy(meLs.toArray(), 0, mes, 0, meLs.size());
synAnalysis.getContext().getAnalysedElements().clear();
for (ModelElement me : mes) {
if (synEleMap != null && synEleMap.get(me) != null) {
TdColumn newColumn = (TdColumn) synEleMap.get(me);
synAnalysis.getContext().getAnalysedElements().add(newColumn);
isExistSynedElement = true;
}
}
}
if (!isExistSynedElement) {
synAnalysis.getContext().getAnalysedElements().clear();
}
// ~
synAnalysis.getResults().getIndicators().clear();
for (Indicator indicator : copiedIndArray) {
// connection.
if (indicator instanceof ColumnSetMultiValueIndicator) {
ColumnSetMultiValueIndicator compositeInd = (ColumnSetMultiValueIndicator) indicator;
ModelElement[] mes = new ModelElement[compositeInd.getAnalyzedColumns().size()];
((ColumnSetMultiValueIndicator) indicator).getAnalyzedColumns().toArray(mes);
compositeInd.getAnalyzedColumns().clear();
for (ModelElement me : mes) {
if (synEleMap != null && synEleMap.get(me) != null) {
TdColumn newColumn = (TdColumn) synEleMap.get(me);
DataminingType dataminingType = MetadataHelper.getDataminingType((TdColumn) me);
if (dataminingType == null) {
dataminingType = MetadataHelper.getDefaultDataminingType(((TdColumn) me).getSqlDataType().getJavaDataType());
}
MetadataHelper.setDataminingType(dataminingType, newColumn);
compositeInd.getAnalyzedColumns().add(newColumn);
anaBuilder.addElementToAnalyze(newColumn, indicator);
isExistSynedElement = true;
}
}
} else if (indicator instanceof ColumnsCompareIndicator) {
// Correlation compare
ColumnsCompareIndicator compInd = (ColumnsCompareIndicator) indicator;
if ((compInd.getColumnSetA() == null || compInd.getColumnSetA().size() == 0) || (compInd.getColumnSetB() == null || compInd.getColumnSetB().size() == 0)) {
return false;
}
// Column set(Columns)
ModelElement[] mesA = new ModelElement[compInd.getColumnSetA().size()];
compInd.getColumnSetA().toArray(mesA);
compInd.getColumnSetA().clear();
for (ModelElement me : mesA) {
if (synEleMap != null && synEleMap.get(me) != null) {
TdColumn newColumn = (TdColumn) synEleMap.get(me);
compInd.getColumnSetA().add(newColumn);
anaBuilder.addElementToAnalyze(newColumn, indicator);
isExistSynedElement = true;
}
}
ModelElement[] mesB = new ModelElement[compInd.getColumnSetB().size()];
compInd.getColumnSetB().toArray(mesB);
compInd.getColumnSetB().clear();
for (ModelElement me : mesB) {
if (synEleMap != null && synEleMap.get(me) != null) {
TdColumn newColumn = (TdColumn) synEleMap.get(me);
compInd.getColumnSetB().add(newColumn);
anaBuilder.addElementToAnalyze(newColumn, indicator);
isExistSynedElement = true;
}
}
// Analyzed element(Table)
ModelElement oldAnaEle = compInd.getAnalyzedElement();
compInd.setAnalyzedElement(null);
ColumnSet oldColSetA = ColumnHelper.getColumnOwnerAsColumnSet(mesA[0]);
ColumnSet oldColSetB = ColumnHelper.getColumnOwnerAsColumnSet(mesB[0]);
if (oldColSetA == oldAnaEle) {
if (synEleMap != null && synEleMap.get(mesA[0]) != null) {
compInd.setAnalyzedElement(ColumnHelper.getColumnOwnerAsColumnSet(synEleMap.get(mesA[0])));
}
}
if (oldColSetB == oldAnaEle) {
if (synEleMap != null && synEleMap.get(mesB[0]) != null) {
compInd.setAnalyzedElement(ColumnHelper.getColumnOwnerAsColumnSet(synEleMap.get(mesB[0])));
}
}
} else if (indicator instanceof ColumnDependencyIndicator) {
// ADD qiongli bug 0012766
// Functional Dependency indicator
ColumnDependencyIndicator funDepInd = (ColumnDependencyIndicator) indicator;
if (funDepInd.getColumnA() == null || funDepInd.getColumnB() == null) {
return false;
}
// Column A
if (synEleMap != null && synEleMap.get(funDepInd.getColumnA()) != null) {
TdColumn newColumn = (TdColumn) synEleMap.get(funDepInd.getColumnA());
funDepInd.setColumnA(newColumn);
anaBuilder.addElementToAnalyze(newColumn, indicator);
isExistSynedElement = true;
}
// Column B
if (synEleMap != null && synEleMap.get(funDepInd.getColumnB()) != null) {
TdColumn newColumn = (TdColumn) synEleMap.get(funDepInd.getColumnB());
funDepInd.setColumnB(newColumn);
anaBuilder.addElementToAnalyze(newColumn, indicator);
isExistSynedElement = true;
}
// Analyzed element(Table)
ModelElement oldAnaEle = funDepInd.getAnalyzedElement();
funDepInd.setAnalyzedElement(null);
ColumnSet oldColSetA = ColumnHelper.getColumnOwnerAsColumnSet(funDepInd.getColumnA());
ColumnSet oldColSetB = ColumnHelper.getColumnOwnerAsColumnSet(funDepInd.getColumnB());
if (oldColSetA == oldAnaEle) {
if (synEleMap != null && synEleMap.get(funDepInd.getColumnA()) != null) {
funDepInd.setAnalyzedElement(ColumnHelper.getColumnOwnerAsColumnSet(synEleMap.get(funDepInd.getColumnA())));
}
}
if (oldColSetB == oldAnaEle) {
if (synEleMap != null && synEleMap.get(funDepInd.getColumnB()) != null) {
funDepInd.setAnalyzedElement(ColumnHelper.getColumnOwnerAsColumnSet(synEleMap.get(funDepInd.getColumnB())));
}
}
} else {
ModelElement me = indicator.getAnalyzedElement();
if (synEleMap != null && synEleMap.get(me) != null) {
indicator.setAnalyzedElement(synEleMap.get(me));
if (analysisType == AnalysisType.MULTIPLE_COLUMN) {
synAnalysis.getResults().getIndicators().add(indicator);
} else {
anaBuilder.addElementToAnalyze(synEleMap.get(me), indicator);
}
isExistSynedElement = true;
}
}
}
return isExistSynedElement;
}
Aggregations