use of org.talend.dataquality.properties.TDQBusinessRuleItem in project tdq-studio-se by Talend.
the class AElementPersistance method createItem.
/**
* DOC bZhou Comment method "createItem".
*
* @param element
* @return
*/
public Item createItem(ModelElement element) {
Item item = null;
// MOD mzhao feature 13114, 2010-05-19 distinguish tdq items.
if (ModelElementIdentifier.isAnalysis(element)) {
item = PropertiesFactory.eINSTANCE.createTDQAnalysisItem();
((TDQAnalysisItem) item).setAnalysis((Analysis) element);
} else if (ModelElementIdentifier.isDQRule(element)) {
item = PropertiesFactory.eINSTANCE.createTDQBusinessRuleItem();
((TDQBusinessRuleItem) item).setDqrule((DQRule) element);
} else if (ModelElementIdentifier.isDataProvider(element)) {
if (element instanceof DatabaseConnection) {
item = org.talend.core.model.properties.PropertiesFactory.eINSTANCE.createDatabaseConnectionItem();
((ConnectionItem) item).setConnection((DatabaseConnection) element);
}
((ConnectionItem) item).setConnection((Connection) element);
} else if (ModelElementIdentifier.isMatchRule(element)) {
// this Condition must before the IndicatorDefinition one because MatchRule instance of it.
item = PropertiesFactory.eINSTANCE.createTDQMatchRuleItem();
((TDQMatchRuleItem) item).setMatchRule((MatchRuleDefinition) element);
} else if (ModelElementIdentifier.isID(element)) {
item = PropertiesFactory.eINSTANCE.createTDQIndicatorDefinitionItem();
((TDQIndicatorDefinitionItem) item).setIndicatorDefinition((IndicatorDefinition) element);
} else if (ModelElementIdentifier.isPattern(element)) {
item = PropertiesFactory.eINSTANCE.createTDQPatternItem();
((TDQPatternItem) item).setPattern((Pattern) element);
} else if (ModelElementIdentifier.isReport(element)) {
item = PropertiesFactory.eINSTANCE.createTDQReportItem();
((TDQReportItem) item).setReport((Report) element);
} else {
item = org.talend.core.model.properties.PropertiesFactory.eINSTANCE.createTDQItem();
}
ItemState itemState = org.talend.core.model.properties.PropertiesFactory.eINSTANCE.createItemState();
itemState.setDeleted(false);
item.setState(itemState);
if (item instanceof TDQItem) {
setTDQItemFileName(element, item);
}
Resource eResource = element.eResource();
if (eResource != null) {
URI uri = eResource.getURI();
if (uri.isPlatform()) {
IPath elementPath = new Path(uri.toPlatformString(true)).removeLastSegments(1);
IPath typedPath = ResourceManager.getRootProject().getFullPath().append(PropertyHelper.getItemTypedPath(item));
IPath statePath = elementPath.makeRelativeTo(typedPath);
itemState.setPath(statePath.toString());
}
}
return item;
}
use of org.talend.dataquality.properties.TDQBusinessRuleItem in project tdq-studio-se by Talend.
the class DQRuleWriter method save.
@Override
public ReturnCode save(final Item item, final boolean careDependency) {
ReturnCode rc = new ReturnCode();
RepositoryWorkUnit<Object> repositoryWorkUnit = new // $NON-NLS-1$
RepositoryWorkUnit<Object>(// $NON-NLS-1$
"save DQRule item") {
@Override
protected void run() throws LoginException, PersistenceException {
TDQBusinessRuleItem ruleItem = (TDQBusinessRuleItem) item;
DQRule rule = ruleItem.getDqrule();
// MOD yyi 2012-02-07 TDQ-4621:Update dependencies(connection) when careDependency is true.
if (careDependency) {
saveWithDependencies(ruleItem, rule);
} else {
saveWithoutDependencies(ruleItem, rule);
}
}
};
repositoryWorkUnit.setAvoidUnloadResources(true);
ProxyRepositoryFactory.getInstance().executeRepositoryWorkUnit(repositoryWorkUnit);
try {
repositoryWorkUnit.throwPersistenceExceptionIfAny();
} catch (PersistenceException e) {
log.error(e, e);
rc.setOk(Boolean.FALSE);
rc.setMessage(e.getMessage());
}
return rc;
}
use of org.talend.dataquality.properties.TDQBusinessRuleItem 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.properties.TDQBusinessRuleItem 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.properties.TDQBusinessRuleItem in project tdq-studio-se by Talend.
the class AElementPersistanceRealTest method testCreateItemWhereRule.
/**
* Test method for
* {@link org.talend.dq.writer.AElementPersistance#createItem(orgomg.cwm.objectmodel.core.ModelElement)}.
*/
@Test
public void testCreateItemWhereRule() {
DQRuleWriter createdRuleWriter = ElementWriterFactory.getInstance().createdRuleWriter();
// test normal name
// $NON-NLS-1$
String whereRuleName = "whereRule1";
// $NON-NLS-1$
String exceptedFileName = whereRuleName + "_0.1.rules";
WhereRule createWhereRule = RulesFactory.eINSTANCE.createWhereRule();
createWhereRule.setName(whereRuleName);
Item createItem = createdRuleWriter.createItem(createWhereRule);
assertTrue(createItem instanceof TDQBusinessRuleItem);
TDQBusinessRuleItem ruleItem = (TDQBusinessRuleItem) createItem;
assertTrue(ruleItem.getFilename().equals(exceptedFileName));
// test special name
// $NON-NLS-1$
String whereRuleName2 = "whereRule1*\\/?";
// $NON-NLS-1$
String exceptedFileName2 = "whereRule1_____0.1.rules";
WhereRule createWhereRule2 = RulesFactory.eINSTANCE.createWhereRule();
createWhereRule2.setName(whereRuleName2);
Item createItem2 = createdRuleWriter.createItem(createWhereRule2);
assertTrue(createItem2 instanceof TDQBusinessRuleItem);
TDQBusinessRuleItem ruleItem2 = (TDQBusinessRuleItem) createItem2;
assertTrue(ruleItem2.getFilename().equals(exceptedFileName2));
}
Aggregations