use of org.talend.dataquality.properties.TDQBusinessRuleItem in project tdq-studio-se by Talend.
the class UpdateDemoDqruleTask method doExecute.
@Override
protected boolean doExecute() throws Exception {
boolean result = true;
try {
WhereRule whereRule = WhereRuleHandler.getInstance().getWhereRule(DEMO_DQRULE_NAME);
URI uriItem = whereRule.eResource().getURI();
File fileItem = null;
if (uriItem.isPlatform()) {
fileItem = WorkspaceUtils.ifileToFile(getIFile(whereRule));
} else {
fileItem = new File(uriItem.toFileString());
}
File fileProp = WorkspaceUtils.ifileToFile(PropertyHelper.getPropertyFile(whereRule));
Property property = PropertyHelper.getProperty(whereRule);
Item item = property.getItem();
if (whereRule != null) {
TDQBusinessRuleItem dqruleItem = (TDQBusinessRuleItem) item;
Resource itemResource = getResource(fileItem);
for (EObject object : itemResource.getContents()) {
if (object instanceof WhereRule) {
whereRule = (WhereRule) object;
whereRule.getSqlGenericExpression().clear();
IndicatorDefinitionFileHelper.addSqlExpression(whereRule, SQL, BODY_DEMO_DQRULE);
String relationPropPath = ReponsitoryContextBridge.getRootProject().getFullPath().append(new Path(fileProp.getPath()).makeRelativeTo(this.getWorkspacePath())).toOSString();
MetadataHelper.setPropertyPath(relationPropPath, whereRule);
dqruleItem.setDqrule(whereRule);
}
EMFUtil.saveResource(itemResource);
Resource propResource = getResource(fileProp);
Property newProperty = (Property) EcoreUtil.getObjectByType(propResource.getContents(), PropertiesPackage.eINSTANCE.getProperty());
newProperty.setAuthor(property.getAuthor());
newProperty.setLabel(dqruleItem.getDqrule().getName());
newProperty.setItem(item);
item.setProperty(newProperty);
propResource.getContents().clear();
propResource.getContents().add(newProperty);
propResource.getContents().add(item);
propResource.getContents().add(item.getState());
EMFUtil.saveResource(propResource);
}
}
} catch (Exception e) {
result = false;
e.printStackTrace();
}
return result;
}
use of org.talend.dataquality.properties.TDQBusinessRuleItem in project tdq-studio-se by Talend.
the class AElementPersistanceRealTest method testCreateItemParserRule.
/**
* Test method for
* {@link org.talend.dq.writer.AElementPersistance#createItem(orgomg.cwm.objectmodel.core.ModelElement)}.
*/
@Test
public void testCreateItemParserRule() {
DQRuleWriter createdRuleWriter = ElementWriterFactory.getInstance().createdRuleWriter();
// test normal name
// $NON-NLS-1$
String parserRuleName = "parserRule1";
// $NON-NLS-1$
String exceptedFileName = parserRuleName + "_0.1.rules";
ParserRule createParserRule = RulesFactory.eINSTANCE.createParserRule();
createParserRule.setName(parserRuleName);
Item createItem = createdRuleWriter.createItem(createParserRule);
assertTrue(createItem instanceof TDQBusinessRuleItem);
TDQBusinessRuleItem ruleItem = (TDQBusinessRuleItem) createItem;
assertTrue(ruleItem.getFilename().equals(exceptedFileName));
// test special name
// $NON-NLS-1$
String parserRuleName2 = "parserRule1:;\".";
// $NON-NLS-1$
String exceptedFileName2 = "parserRule1_____0.1.rules";
ParserRule createParserRule2 = RulesFactory.eINSTANCE.createParserRule();
createParserRule2.setName(parserRuleName2);
Item createItem2 = createdRuleWriter.createItem(createParserRule2);
assertTrue(createItem2 instanceof TDQBusinessRuleItem);
TDQBusinessRuleItem ruleItem2 = (TDQBusinessRuleItem) createItem2;
assertTrue(ruleItem2.getFilename().equals(exceptedFileName2));
}
use of org.talend.dataquality.properties.TDQBusinessRuleItem in project tdq-studio-se by Talend.
the class DQRuleMasterDetailsPage method saveDQRule.
/**
* DOC xqliu Comment method "saveDQRule".
*
* @return
*/
private boolean saveDQRule() {
boolean ret = false;
this.tempJoinElements = cleanJoins(tempJoinElements);
if (checkValus()) {
TaggedValueHelper.setValidStatus(true, getCurrentModelElement());
getCurrentModelElement().setCriticalityLevel(Integer.valueOf(getCriticalityLevelText().getText()));
getCurrentModelElement().setWhereExpression(whereText.getText());
getCurrentModelElement().getJoins().clear();
getCurrentModelElement().getJoins().addAll(this.tempJoinElements);
TDQBusinessRuleItem whereRuleItem = (TDQBusinessRuleItem) getCurrentRepNode().getObject().getProperty().getItem();
// MOD yyi 2012-02-08 TDQ-4621:Explicitly set true for updating dependencies.
ReturnCode rc = ElementWriterFactory.getInstance().createdRuleWriter().save(whereRuleItem, true);
ret = rc.isOk();
this.joinConditionTableViewer.updateModelViewer();
}
return ret;
}
use of org.talend.dataquality.properties.TDQBusinessRuleItem in project tdq-studio-se by Talend.
the class ParserRuleMasterDetailsPage method saveParserRule.
private boolean saveParserRule() {
TaggedValueHelper.setValidStatus(true, getCurrentModelElement());
getCurrentModelElement().getExpression().addAll(parserRuleTableViewer.getParserRuleTdExpressions());
TDQBusinessRuleItem parserRuleItem = (TDQBusinessRuleItem) getCurrentRepNode().getObject().getProperty().getItem();
ReturnCode rc = ElementWriterFactory.getInstance().createdRuleWriter().save(parserRuleItem, Boolean.FALSE);
if (!rc.isOk()) {
return false;
}
return true;
}
use of org.talend.dataquality.properties.TDQBusinessRuleItem in project tdq-studio-se by Talend.
the class PropertyHelper method getModelElement.
/**
* DOC bZhou Comment method "getModelElement".
*
* Get model element from property recognized by current system.
*
* @param property
* @return
*/
public static ModelElement getModelElement(Property property) {
Item item = property.getItem();
assert item != null;
ModelElement element = (ModelElement) new org.talend.core.model.properties.util.PropertiesSwitch() {
@Override
public Object caseDatabaseConnectionItem(DatabaseConnectionItem object) {
return object.getConnection();
}
@Override
public Object caseMDMConnectionItem(MDMConnectionItem object) {
return object.getConnection();
}
@Override
public Object caseDelimitedFileConnectionItem(DelimitedFileConnectionItem object) {
return object.getConnection();
}
}.doSwitch(item);
if (element == null) {
element = new org.talend.dataquality.properties.util.PropertiesSwitch<ModelElement>() {
@Override
public ModelElement caseTDQReportItem(TDQReportItem object) {
return object.getReport();
}
@Override
public ModelElement caseTDQAnalysisItem(TDQAnalysisItem object) {
return object.getAnalysis();
}
@Override
public ModelElement caseTDQBusinessRuleItem(TDQBusinessRuleItem object) {
return object.getDqrule();
}
/*
* (non-Javadoc)
*
* @see
* org.talend.dataquality.properties.util.PropertiesSwitch#caseTDQMatchRuleItem(org.talend.dataquality
* .properties.TDQMatchRuleItem)
*/
@Override
public ModelElement caseTDQMatchRuleItem(TDQMatchRuleItem object) {
return object.getMatchRule();
}
@Override
public ModelElement caseTDQIndicatorDefinitionItem(TDQIndicatorDefinitionItem object) {
return object.getIndicatorDefinition();
}
@Override
public ModelElement caseTDQPatternItem(TDQPatternItem object) {
return object.getPattern();
}
}.doSwitch(item);
}
return element;
}
Aggregations