use of org.talend.dataquality.indicators.columnset.AllMatchIndicator in project tdq-studio-se by Talend.
the class ModelElementDuplicateHandle method dupAnaWithoutBuiltInPattern.
/**
* when duplicate an analysis,remove the built-in pattern. or else, the reference pattern will be copied as a built-in
* pattern.
*
* @param oldModelElement
* @return
*/
private ModelElement dupAnaWithoutBuiltInPattern(ModelElement oldModelElement) {
ModelElement newModEle = null;
if (!(oldModelElement instanceof Analysis)) {
newModEle = (ModelElement) EMFSharedResources.getInstance().copyEObject(oldModelElement);
return newModEle;
}
try {
Analysis analysis = (Analysis) oldModelElement;
EList<Indicator> indicators = analysis.getResults().getIndicators();
List<Indicator> orignalIndicators = new ArrayList<Indicator>();
orignalIndicators.addAll(indicators);
Map<Indicator, List<Pattern>> map = new HashMap<Indicator, List<Pattern>>();
// 2.after copy the analysis without built-in pattern, reset the built for the old analysis.
for (Indicator indicator : indicators) {
if (!(indicator instanceof PatternMatchingIndicator)) {
continue;
}
List<Pattern> builtInLs = new ArrayList<Pattern>();
if (indicator instanceof AllMatchIndicator) {
EList<RegexpMatchingIndicator> list = ((AllMatchIndicator) indicator).getCompositeRegexMatchingIndicators();
for (RegexpMatchingIndicator regxIndicator : list) {
builtInLs.addAll(regxIndicator.getParameters().getDataValidDomain().getBuiltInPatterns());
map.put(regxIndicator, builtInLs);
regxIndicator.getParameters().getDataValidDomain().getBuiltInPatterns().clear();
}
} else {
builtInLs.addAll(indicator.getParameters().getDataValidDomain().getBuiltInPatterns());
map.put(indicator, builtInLs);
indicator.getParameters().getDataValidDomain().getBuiltInPatterns().clear();
}
}
newModEle = (ModelElement) EMFSharedResources.getInstance().copyEObject(analysis);
for (Indicator patternInd : map.keySet()) {
patternInd.getParameters().getDataValidDomain().getBuiltInPatterns().addAll(map.get(patternInd));
}
ProxyRepositoryFactory.getInstance().getRepositoryFactoryFromProvider().getResourceManager().saveResource(analysis.eResource());
} catch (Exception e) {
LOG.error(e);
}
return newModEle;
}
Aggregations