use of org.talend.dataquality.rules.DQRule in project tdq-studio-se by Talend.
the class TreeMessageInfoDialog method getLabelProvider.
protected ILabelProvider getLabelProvider() {
if (labelProvider == null) {
labelProvider = new LabelProvider() {
@Override
public String getText(Object obj) {
if (obj == null) {
// $NON-NLS-1$
return "";
}
if (obj instanceof ImpactNode) {
return ((ImpactNode) obj).toString();
} else if (obj instanceof IFile) {
IFile file = (IFile) obj;
ModelElement modelElement = ModelElementFileFactory.getModelElement(file);
// MOD msjian TDQ-5909: modify to displayName
return modelElement != null ? PropertyHelper.getProperty(modelElement).getDisplayName() : file.getName();
} else if (obj instanceof RepositoryViewObject) {
// Added 20130226 TDQ-6899 show the name for Jrxml object (which has no related ModelElement)
return ((IRepositoryViewObject) obj).getLabel();
} else if (obj instanceof MetadataTable) {
// ADD TDQ-7146: for all type's connection table/view node
return ((ModelElement) obj).getName();
}
Property property = PropertyHelper.getProperty((ModelElement) obj);
return property == null ? ((ModelElement) obj).getName() : property.getDisplayName();
}
@Override
public Image getImage(Object obj) {
ModelElement modelElement = null;
if (obj instanceof ModelElement) {
modelElement = (ModelElement) obj;
} else if (obj instanceof ImpactNode) {
modelElement = ((ImpactNode) obj).getNodeElement();
} else if (obj instanceof IFile) {
modelElement = ModelElementFileFactory.getModelElement((IFile) obj);
} else if (obj instanceof RepositoryViewObject) {
// Added 20130226 TDQ-6899 show the name for Jrxml object (which has no related ModelElement)
return ImageLib.getImage(ImageLib.JRXML_ICON);
}
// ~
if (modelElement == null) {
if (((ImpactNode) obj).getNode() != null) {
return ImageLib.getImage(ImageLib.JRXML_ICON);
}
return super.getImage(obj);
}
Image modelElementImage = null;
String imgName = null;
if (modelElement instanceof Analysis) {
imgName = ImageLib.ANALYSIS_OBJECT;
} else if (modelElement instanceof TdReport) {
imgName = ImageLib.REPORT_OBJECT;
} else if (modelElement instanceof DatabaseConnection) {
imgName = ImageLib.CONNECTION;
} else if (modelElement instanceof DelimitedFileConnection) {
imgName = ImageLib.FILE_DELIMITED;
} else if (modelElement instanceof Pattern) {
imgName = ImageLib.PATTERN_REG;
} else if (modelElement instanceof IndicatorDefinition) {
// IndicatorDefinition
if (modelElement instanceof DQRule) {
imgName = ImageLib.DQ_RULE;
} else if (modelElement instanceof MatchRuleDefinition) {
imgName = ImageLib.MATCH_RULE_ICON;
} else {
imgName = ImageLib.IND_DEFINITION;
}
// TDQ-8550~
} else if (modelElement instanceof MetadataTable) {
imgName = ImageLib.TABLE;
}
if (imgName != null) {
modelElementImage = ImageLib.getImage(imgName);
}
// add lock icon on the image
if (modelElementImage != null) {
if (modelElement != null) {
Property property = PropertyHelper.getProperty(modelElement);
if (property != null) {
Item item = property.getItem();
if (item != null) {
if (ProxyRepositoryManager.getInstance().isLockByUserOwn(item)) {
modelElementImage = ImageLib.createLockedByOwnIcon(imgName);
} else if (ProxyRepositoryManager.getInstance().isLockByOthers(item)) {
modelElementImage = ImageLib.createLockedByOtherIcon(imgName);
}
}
}
}
return modelElementImage;
}
return super.getImage(obj);
}
};
}
return labelProvider;
}
use of org.talend.dataquality.rules.DQRule in project tdq-studio-se by Talend.
the class AnalysisWriter method addDependencies.
/*
* (non-Javadoc)
*
* @see org.talend.dq.writer.AElementPersistance#addDependencies(orgomg.cwm.objectmodel.core.ModelElement)
*/
@Override
public void addDependencies(ModelElement element) {
Analysis analysis = (Analysis) element;
List<IndicatorDefinition> udis = AnalysisHelper.getUserDefinedIndicators(analysis);
try {
for (IndicatorDefinition udi : udis) {
if (udi == null) {
continue;
}
InternalEObject iudi = (InternalEObject) udi;
if (!iudi.eIsProxy()) {
DQRepositoryNode recursiveFind = RepositoryNodeHelper.recursiveFind(udi);
// only do save when the dependency is not reference project node
if (recursiveFind != null && recursiveFind.getProject().isMainProject()) {
TypedReturnCode<Dependency> dependencyReturn = DependenciesHandler.getInstance().setDependencyOn(analysis, udi);
if (dependencyReturn.isOk()) {
Property property = PropertyHelper.getProperty(udi);
if (property != null) {
TDQItem udiItem = (TDQItem) property.getItem();
if (udiItem instanceof TDQIndicatorDefinitionItem) {
((TDQIndicatorDefinitionItem) udiItem).setIndicatorDefinition(udi);
} else if (udiItem instanceof TDQBusinessRuleItem) {
((TDQBusinessRuleItem) udiItem).setDqrule((DQRule) udi);
}
}
ProxyRepositoryFactory.getInstance().getRepositoryFactoryFromProvider().getResourceManager().saveResource(udi.eResource());
}
}
}
}
List<Pattern> patterns = AnalysisHelper.getPatterns(analysis);
for (Pattern pattern : patterns) {
InternalEObject iptn = (InternalEObject) pattern;
if (!iptn.eIsProxy()) {
DQRepositoryNode recursiveFind = RepositoryNodeHelper.recursiveFind(pattern);
// only do save when the dependency is not reference project node
if (recursiveFind != null && recursiveFind.getProject().isMainProject()) {
TypedReturnCode<Dependency> dependencyReturn = DependenciesHandler.getInstance().setDependencyOn(analysis, pattern);
if (dependencyReturn.isOk()) {
Property property = PropertyHelper.getProperty(pattern);
if (property != null && property.getItem() instanceof TDQPatternItem) {
TDQPatternItem patternItem = (TDQPatternItem) property.getItem();
patternItem.setPattern(pattern);
}
ProxyRepositoryFactory.getInstance().getRepositoryFactoryFromProvider().getResourceManager().saveResource(pattern.eResource());
// EMFUtil.saveSingleResource(pattern.eResource());
}
}
}
}
} catch (PersistenceException e) {
log.error(e, e);
}
}
use of org.talend.dataquality.rules.DQRule in project tdq-studio-se by Talend.
the class FileSystemImportWriter method mergeParserRule.
/**
* for ParserRule: 1) replace the same name old rule with new rule; 2) will keep the old rule if new one don't
* include the same name rule
*
* @param record imported modified parser rule
* @param parserRuleItem the parser rule in the current studio
*/
protected void mergeParserRule(ItemRecord record, TDQBusinessRuleItem parserRuleItem) {
// only when the parser rule is modified, do the save
boolean isModified = false;
// old object
DQRule parserRule = parserRuleItem.getDqrule();
Property parserRuleProp = parserRuleItem.getProperty();
// new object
DQRule recordRule = (DQRule) record.getElement();
Property recordRuleProp = record.getProperty();
// get expression list from record
EList<TdExpression> importedExs = recordRule.getSqlGenericExpression();
// for each expression:
for (TdExpression importedEx : importedExs) {
TdExpression systemExpression = null;
for (TdExpression ex : parserRule.getSqlGenericExpression()) {
if (ex.getName().equals(importedEx.getName())) {
systemExpression = ex;
break;
}
}
if (systemExpression != null) {
IndicatorDefinitionFileHelper.removeSqlExpressionByName(parserRule, importedEx.getName());
IndicatorDefinitionFileHelper.addSqlExpression(parserRule, importedEx.getName(), importedEx.getLanguage(), importedEx.getBody(), importedEx.getModificationDate());
} else {
IndicatorDefinitionFileHelper.addSqlExpression(parserRule, importedEx.getName(), importedEx.getLanguage(), importedEx.getBody(), importedEx.getModificationDate());
}
isModified = true;
}
// for ParserRule Metadata
if (parserRuleProp != null && recordRuleProp != null) {
if (!StringUtils.isBlank(recordRuleProp.getPurpose())) {
parserRuleProp.setPurpose(recordRuleProp.getPurpose());
}
if (!StringUtils.isBlank(recordRuleProp.getDescription())) {
parserRuleProp.setDescription(recordRuleProp.getDescription());
}
parserRuleProp.setAuthor(recordRuleProp.getAuthor());
parserRuleProp.setStatusCode(recordRuleProp.getStatusCode());
isModified = true;
}
if (isModified) {
ElementWriterFactory.getInstance().createdRuleWriter().save(parserRuleItem, false);
}
}
use of org.talend.dataquality.rules.DQRule in project tdq-studio-se by Talend.
the class AElementPersistanceRealTest method testSaveWithDependenciesAnalysis.
/**
* Test method for
* {@link org.talend.dq.writer.AElementPersistance#saveWithDependencies(org.talend.core.model.properties.Item, orgomg.cwm.objectmodel.core.ModelElement)}
* .
*
* @throws PersistenceException
*/
@Test
public void testSaveWithDependenciesAnalysis() throws PersistenceException {
AnalysisWriter createAnalysisWriter = ElementWriterFactory.getInstance().createAnalysisWrite();
String anaName = "AElementPersistanceRealTestanalysis5";
// create analysis
Analysis createAnalysis = AnalysisFactory.eINSTANCE.createAnalysis();
AnalysisResult createAnalysisResult = AnalysisFactory.eINSTANCE.createAnalysisResult();
AnalysisContext createAnalysisContext = AnalysisFactory.eINSTANCE.createAnalysisContext();
createAnalysis.setResults(createAnalysisResult);
createAnalysis.setContext(createAnalysisContext);
createAnalysis.setName(anaName);
// create analysis item
TDQAnalysisItem createTDQAnalysisItem = PropertiesFactory.eINSTANCE.createTDQAnalysisItem();
createTDQAnalysisItem.setAnalysis(createAnalysis);
Property createAnalysisProperty = org.talend.core.model.properties.PropertiesFactory.eINSTANCE.createProperty();
// $NON-NLS-1$
createAnalysisProperty.setLabel("AElementPersistanceRealTestanalysis5");
createTDQAnalysisItem.setProperty(createAnalysisProperty);
createAnalysisProperty.setId(EcoreUtil.generateUUID());
ProxyRepositoryFactory.getInstance().create(createTDQAnalysisItem, Path.EMPTY, false);
// create pattern match indicator
WhereRuleIndicator whereRuleIndicator = IndicatorSqlFactory.eINSTANCE.createWhereRuleIndicator();
// create definition
createAnalysisResult.getIndicators().add(whereRuleIndicator);
DQRule dqRule = RulesFactory.eINSTANCE.createWhereRule();
whereRuleIndicator.setIndicatorDefinition(dqRule);
TDQBusinessRuleItem createTDQBusinessRuleItem = PropertiesFactory.eINSTANCE.createTDQBusinessRuleItem();
createTDQBusinessRuleItem.setDqrule(dqRule);
Property createPatternProperty = org.talend.core.model.properties.PropertiesFactory.eINSTANCE.createProperty();
// $NON-NLS-1$
createPatternProperty.setLabel("AElementPersistanceRealTestDQRule5");
createTDQBusinessRuleItem.setProperty(createPatternProperty);
createPatternProperty.setId(EcoreUtil.generateUUID());
ProxyRepositoryFactory.getInstance().create(createTDQBusinessRuleItem, Path.EMPTY, false);
// $NON-NLS-1$
String exceptedFileName = anaName + "_0.1.ana";
ReturnCode create = createAnalysisWriter.saveWithDependencies(createTDQAnalysisItem, createAnalysis);
assertTrue(create.isOk());
Assert.assertEquals(exceptedFileName, createTDQAnalysisItem.getFilename());
// $NON-NLS-1$
String anaName2 = "ana52";
// $NON-NLS-1$
String exceptedFileName2 = anaName2 + "_0.1.ana";
createAnalysis.setName(anaName2);
create = createAnalysisWriter.saveWithDependencies(createTDQAnalysisItem, createAnalysis);
assertTrue(create.isOk());
Assert.assertEquals(exceptedFileName2, createTDQAnalysisItem.getFilename());
}
use of org.talend.dataquality.rules.DQRule in project tdq-studio-se by Talend.
the class TDQResourceChangeHandler method create.
@Override
public Resource create(IProject project, Item item, int classID, IPath path) {
String fileExtension = FileConstants.ITEM_EXTENSION;
Resource itemResource = null;
try {
switch(classID) {
case org.talend.dataquality.properties.PropertiesPackage.TDQ_ANALYSIS_ITEM:
fileExtension = FileConstants.ANA_EXTENSION;
itemResource = xmiResourceManager.createItemResourceWithExtension(project, item, path, ERepositoryObjectType.TDQ_ANALYSIS_ELEMENT, false, fileExtension);
AnalysisWriter createAnalysisWrite = org.talend.dq.writer.impl.ElementWriterFactory.getInstance().createAnalysisWrite();
Analysis analysis = ((TDQAnalysisItem) item).getAnalysis();
createAnalysisWrite.addResourceContent(itemResource, analysis);
createAnalysisWrite.addDependencies(analysis);
break;
case org.talend.dataquality.properties.PropertiesPackage.TDQ_REPORT_ITEM:
fileExtension = FileConstants.REP_EXTENSION;
itemResource = xmiResourceManager.createItemResourceWithExtension(project, item, path, ERepositoryObjectType.TDQ_REPORT_ELEMENT, false, fileExtension);
ReportWriter createReportWriter = org.talend.dq.writer.impl.ElementWriterFactory.getInstance().createReportWriter();
Report report = ((TDQReportItem) item).getReport();
createReportWriter.addResourceContent(itemResource, report);
createReportWriter.addDependencies(report);
break;
case org.talend.dataquality.properties.PropertiesPackage.TDQ_INDICATOR_DEFINITION_ITEM:
fileExtension = FileConstants.DEF_EXTENSION;
itemResource = xmiResourceManager.createItemResourceWithExtension(project, item, path, ERepositoryObjectType.TDQ_INDICATOR_ELEMENT, false, fileExtension);
IndicatorDefinition indicatorDefinition = ((TDQIndicatorDefinitionItem) item).getIndicatorDefinition();
IndicatorDefinitionWriter createIndicatorDefinitionWriter = org.talend.dq.writer.impl.ElementWriterFactory.getInstance().createIndicatorDefinitionWriter();
createIndicatorDefinitionWriter.addResourceContent(itemResource, indicatorDefinition);
break;
case org.talend.dataquality.properties.PropertiesPackage.TDQ_PATTERN_ITEM:
fileExtension = FileConstants.PAT_EXTENSION;
itemResource = xmiResourceManager.createItemResourceWithExtension(project, item, path, ERepositoryObjectType.TDQ_PATTERN_ELEMENT, false, fileExtension);
Pattern pattern = ((TDQPatternItem) item).getPattern();
PatternWriter createPatternWriter = org.talend.dq.writer.impl.ElementWriterFactory.getInstance().createPatternWriter();
createPatternWriter.addResourceContent(itemResource, pattern);
break;
case org.talend.dataquality.properties.PropertiesPackage.TDQ_BUSINESS_RULE_ITEM:
fileExtension = FileConstants.RULE_EXTENSION;
// MOD gdbu 2011-6-10 bug : 21823 2011-06-27 revert the error type code by klliu
DQRule dqrule = ((TDQBusinessRuleItem) item).getDqrule();
if (dqrule instanceof WhereRule) {
itemResource = xmiResourceManager.createItemResourceWithExtension(project, item, path, ERepositoryObjectType.TDQ_RULES_SQL, false, fileExtension);
} else {
itemResource = xmiResourceManager.createItemResourceWithExtension(project, item, path, ERepositoryObjectType.TDQ_RULES_PARSER, false, fileExtension);
}
// ~21823
DQRuleWriter createdRuleWriter = org.talend.dq.writer.impl.ElementWriterFactory.getInstance().createdRuleWriter();
createdRuleWriter.addResourceContent(itemResource, dqrule);
break;
case org.talend.dataquality.properties.PropertiesPackage.TDQ_JRXML_ITEM:
fileExtension = FileConstants.JRXML_EXTENSION;
itemResource = xmiResourceManager.createItemResourceWithExtension(project, item, path, ERepositoryObjectType.TDQ_JRAXML_ELEMENT, true, fileExtension);
itemResource.getContents().add(((TDQFileItem) item).getContent());
break;
case org.talend.dataquality.properties.PropertiesPackage.TDQ_SOURCE_FILE_ITEM:
fileExtension = FileConstants.SQL_EXTENSION;
itemResource = xmiResourceManager.createItemResourceWithExtension(project, item, path, ERepositoryObjectType.TDQ_SOURCE_FILE_ELEMENT, true, fileExtension);
itemResource.getContents().add(((TDQFileItem) item).getContent());
break;
case org.talend.dataquality.properties.PropertiesPackage.TDQ_MATCH_RULE_ITEM:
fileExtension = FileConstants.RULE_EXTENSION;
itemResource = xmiResourceManager.createItemResourceWithExtension(project, item, path, ERepositoryObjectType.TDQ_RULES_MATCHER, false, fileExtension);
MatchRuleDefinition matchRuleDefinition = ((TDQMatchRuleItem) item).getMatchRule();
MatchRuleDefinitionWriter matchRuleDefinitionWriter = org.talend.dq.writer.impl.ElementWriterFactory.getInstance().createdMatchRuleWriter();
matchRuleDefinitionWriter.addResourceContent(itemResource, matchRuleDefinition);
break;
default:
}
} catch (PersistenceException e) {
log.error(e, e);
}
return itemResource;
}
Aggregations