use of org.talend.dataquality.indicators.RegexpMatchingIndicator in project tdq-studio-se by Talend.
the class FileSystemImportWriter method updatePatternInAnaParams.
/**
* if there is a same name pattern in current workspace,update the pattern in imported analysis IndicatorParameters.
*
* @param systemSupplyModelElement
* @param analysis
*/
private void updatePatternInAnaParams(ModelElement systemSupplyModelElement, Analysis analysis) {
if (analysis.getResults() != null) {
EList<Indicator> indicators = analysis.getResults().getIndicators();
IndicatorParameters parameters = null;
for (Indicator indicator : indicators) {
// AllMatchIndicator is in column set analysis.
if (indicator instanceof AllMatchIndicator) {
EList<RegexpMatchingIndicator> list = ((AllMatchIndicator) indicator).getCompositeRegexMatchingIndicators();
for (RegexpMatchingIndicator regMatchIndicator : list) {
parameters = regMatchIndicator.getParameters();
removOldAddSysPatternInAnaParams(parameters, (Pattern) systemSupplyModelElement, analysis);
}
} else if (indicator instanceof PatternMatchingIndicator) {
parameters = ((PatternMatchingIndicator) indicator).getParameters();
removOldAddSysPatternInAnaParams(parameters, (Pattern) systemSupplyModelElement, analysis);
}
}
}
}
use of org.talend.dataquality.indicators.RegexpMatchingIndicator in project tdq-studio-se by Talend.
the class PatternIndicatorFactory method createRegexpMatchingIndicator.
/**
* Method "createRegexpMatchingIndicator".
*
* @param pattern the pattern from which the RegexpMatchingIndicator is created
* @return the new RegexpMatchingIndicator with the same name as the pattern
*/
public static RegexpMatchingIndicator createRegexpMatchingIndicator(Pattern pattern) {
RegexpMatchingIndicator patternMatchingIndicator = IndicatorsFactory.eINSTANCE.createRegexpMatchingIndicator();
IndicatorParameters indicParams = IndicatorsFactory.eINSTANCE.createIndicatorParameters();
Domain validData = DomainFactory.eINSTANCE.createDomain();
validData.getPatterns().add(pattern);
indicParams.setDataValidDomain(validData);
patternMatchingIndicator.setParameters(indicParams);
patternMatchingIndicator.setName(pattern.getName());
return patternMatchingIndicator;
}
use of org.talend.dataquality.indicators.RegexpMatchingIndicator in project tdq-studio-se by Talend.
the class AllMatchIndicatorImpl method instantiatePatterns.
@SuppressWarnings("unchecked")
private boolean instantiatePatterns() {
boolean noErrors = true;
EList<ModelElement> columns = this.getAnalyzedColumns();
this.patterns = new List[columns.size()];
EList<RegexpMatchingIndicator> indicators = this.getCompositeRegexMatchingIndicators();
for (int i = 0; i < columns.size(); i++) {
for (RegexpMatchingIndicator rmi : indicators) {
if (rmi.getAnalyzedElement() == columns.get(i)) {
if (null == this.patterns[i]) {
this.patterns[i] = new ArrayList<java.util.regex.Pattern>();
}
String regex = rmi.getRegex();
// MOD TDQ-8388 20150530 yyin, should check all patterns, and log the errors
if (null == regex) {
continue;
}
try {
this.patterns[i].add(java.util.regex.Pattern.compile(regex));
} catch (java.util.regex.PatternSyntaxException e) {
log.error(Messages.getString("Using_regular_expression", rmi.getName(), regex), e);
noErrors = false;
continue;
}
}
}
}
return noErrors;
}
use of org.talend.dataquality.indicators.RegexpMatchingIndicator in project tdq-studio-se by Talend.
the class RegexpMatchingIndicatorImplTest method testGetRegexsuccess.
/**
* Test method for {@link org.talend.dataquality.indicators.impl.RegexpMatchingIndicatorImpl#getJavaRegex()}.
*/
@Test
public void testGetRegexsuccess() {
// RegexpMatchingIndicator
RegexpMatchingIndicator createRegexpMatchingIndicator = IndicatorsFactory.eINSTANCE.createRegexpMatchingIndicator();
// ~RegexpMatchingIndicator
// IndicatorParameters
IndicatorParameters createIndicatorParameters = IndicatorsFactory.eINSTANCE.createIndicatorParameters();
// ~IndicatorParameters
// Domain
Domain createDomain = DomainFactory.eINSTANCE.createDomain();
EList<Pattern> patterns = createDomain.getPatterns();
// ~Domain
// Pattern
Pattern createJavaPattern = PatternFactory.eINSTANCE.createPattern();
Pattern createSQLPattern = PatternFactory.eINSTANCE.createPattern();
Pattern createMSSQLPattern = PatternFactory.eINSTANCE.createPattern();
patterns.add(createJavaPattern);
patterns.add(createSQLPattern);
patterns.add(createMSSQLPattern);
// ~Pattern
// init java Pattern data
RegularExpression createJavaRegularExpression = PatternFactory.eINSTANCE.createRegularExpression();
TdExpression createJavaTdExpression = RelationalFactory.eINSTANCE.createTdExpression();
createJavaTdExpression.setBody(JavaRegex);
createJavaTdExpression.setLanguage("Java");
createJavaRegularExpression.setExpression(createJavaTdExpression);
createJavaRegularExpression.setExpressionType(ExpressionType.REGEXP.getLiteral());
EList<PatternComponent> components = createJavaPattern.getComponents();
components.add(createJavaRegularExpression);
// ~init java Pattern data
createIndicatorParameters.setDataValidDomain(createDomain);
createRegexpMatchingIndicator.setParameters(createIndicatorParameters);
// call getRegex()
String regexResult = createRegexpMatchingIndicator.getRegex();
String JavaRegex2 = JavaRegex.substring(1, JavaRegex.length() - 1);
// ~call getRegex()
Assert.assertTrue(JavaRegex2.equalsIgnoreCase(regexResult));
}
use of org.talend.dataquality.indicators.RegexpMatchingIndicator in project tdq-studio-se by Talend.
the class ColumnSetAnalysisDetailsPage method saveAnalysis.
/**
* @param outputFolder
* @throws DataprofilerCoreException
*/
@Override
public void saveAnalysis() throws DataprofilerCoreException {
columnSetAnalysisHandler.changeDefaultRowLoaded(rowLoadedText.getText());
columnSetAnalysisHandler.changeSampleDataShowWay(sampleDataShowWayCombo.getText());
// columnSetAnalysisHandler.setName(columnSetAnalysisHandler.getName().replace(" ", ""));
for (Domain domain : getCurrentModelElement().getParameters().getDataFilter()) {
domain.setName(getCurrentModelElement().getName());
}
// ~
columnSetAnalysisHandler.clearAnalysis();
simpleStatIndicator.getAnalyzedColumns().clear();
allMatchIndicator.getAnalyzedColumns().clear();
// set execute engine
Analysis analysis = columnSetAnalysisHandler.getAnalysis();
analysis.getParameters().setExecutionLanguage(ExecutionLanguage.get(execLang));
// set data filter
columnSetAnalysisHandler.setStringDataFilter(dataFilterComp.getDataFilterString());
// save analysis
List<IRepositoryNode> repositoryNodes = treeViewer.getColumnSetMultiValueList();
Connection tdProvider = null;
IRepositoryViewObject reposObject = null;
if (repositoryNodes != null && repositoryNodes.size() != 0) {
ConnectionItem item = (ConnectionItem) repositoryNodes.get(0).getObject().getProperty().getItem();
tdProvider = item.getConnection();
if (tdProvider.eIsProxy()) {
// Resolve the connection again
tdProvider = (Connection) EObjectHelper.resolveObject(tdProvider);
}
analysis.getContext().setConnection(tdProvider);
List<ModelElement> columnList = new ArrayList<ModelElement>();
for (IRepositoryNode rd : repositoryNodes) {
reposObject = rd.getObject();
columnList.add(((MetadataColumnRepositoryObject) reposObject).getTdColumn());
}
simpleStatIndicator.getAnalyzedColumns().addAll(columnList);
columnSetAnalysisHandler.addIndicator(columnList, simpleStatIndicator);
// ~ MOD mzhao feature 13040. 2010-05-21
allMatchIndicator.getCompositeRegexMatchingIndicators().clear();
ModelElementIndicator[] modelElementIndicator = treeViewer.getModelElementIndicator();
if (modelElementIndicator != null) {
for (ModelElementIndicator modelElementInd : modelElementIndicator) {
Indicator[] inds = modelElementInd.getPatternIndicators();
for (Indicator ind : inds) {
if (ind instanceof RegexpMatchingIndicator) {
// MOD yyi 2011-06-15 22419:column set pattern for MDM
IRepositoryViewObject obj = modelElementInd.getModelElementRepositoryNode().getObject();
ModelElement analyzedElt = ((MetadataColumnRepositoryObject) obj).getTdColumn();
ind.setAnalyzedElement(analyzedElt);
allMatchIndicator.getCompositeRegexMatchingIndicators().add((RegexpMatchingIndicator) ind);
}
}
}
}
if (allMatchIndicator.getCompositeRegexMatchingIndicators().size() > 0) {
allMatchIndicator.getAnalyzedColumns().addAll(columnList);
columnSetAnalysisHandler.addIndicator(columnList, allMatchIndicator);
}
// ~
} else {
analysis.getContext().setConnection(null);
}
TaggedValueHelper.setTaggedValue(getCurrentModelElement(), TaggedValueHelper.IS_USE_SAMPLE_DATA, isRunWithSampleData.toString());
// 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(columnSetAnalysisHandler.getName());
// TDQ-5581,if has removed emlements(patten),should remove dependency each other before saving.
// 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);
treeViewer.setDirty(false);
dataFilterComp.setDirty(false);
}
Aggregations