Search in sources :

Example 1 with TDQBusinessRuleItem

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;
}
Also used : Path(org.eclipse.core.runtime.Path) Item(org.talend.core.model.properties.Item) TDQBusinessRuleItem(org.talend.dataquality.properties.TDQBusinessRuleItem) WhereRule(org.talend.dataquality.rules.WhereRule) EObject(org.eclipse.emf.ecore.EObject) Resource(org.eclipse.emf.ecore.resource.Resource) TDQBusinessRuleItem(org.talend.dataquality.properties.TDQBusinessRuleItem) URI(org.eclipse.emf.common.util.URI) File(java.io.File) IFile(org.eclipse.core.resources.IFile) Property(org.talend.core.model.properties.Property)

Example 2 with TDQBusinessRuleItem

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));
}
Also used : ParserRule(org.talend.dataquality.rules.ParserRule) TDQAnalysisItem(org.talend.dataquality.properties.TDQAnalysisItem) TDQPatternItem(org.talend.dataquality.properties.TDQPatternItem) Item(org.talend.core.model.properties.Item) TDQIndicatorDefinitionItem(org.talend.dataquality.properties.TDQIndicatorDefinitionItem) TDQBusinessRuleItem(org.talend.dataquality.properties.TDQBusinessRuleItem) TDQReportItem(org.talend.dataquality.properties.TDQReportItem) DQRuleWriter(org.talend.dq.writer.impl.DQRuleWriter) TDQBusinessRuleItem(org.talend.dataquality.properties.TDQBusinessRuleItem) Test(org.junit.Test)

Example 3 with TDQBusinessRuleItem

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;
}
Also used : ReturnCode(org.talend.utils.sugars.ReturnCode) TDQBusinessRuleItem(org.talend.dataquality.properties.TDQBusinessRuleItem)

Example 4 with TDQBusinessRuleItem

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;
}
Also used : ReturnCode(org.talend.utils.sugars.ReturnCode) TDQBusinessRuleItem(org.talend.dataquality.properties.TDQBusinessRuleItem)

Example 5 with TDQBusinessRuleItem

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;
}
Also used : TDQIndicatorDefinitionItem(org.talend.dataquality.properties.TDQIndicatorDefinitionItem) TDQMatchRuleItem(org.talend.dataquality.properties.TDQMatchRuleItem) MDMConnectionItem(org.talend.core.model.properties.MDMConnectionItem) TDQPatternItem(org.talend.dataquality.properties.TDQPatternItem) DatabaseConnectionItem(org.talend.core.model.properties.DatabaseConnectionItem) DelimitedFileConnectionItem(org.talend.core.model.properties.DelimitedFileConnectionItem) Item(org.talend.core.model.properties.Item) FolderItem(org.talend.core.model.properties.FolderItem) TDQIndicatorDefinitionItem(org.talend.dataquality.properties.TDQIndicatorDefinitionItem) DatabaseConnectionItem(org.talend.core.model.properties.DatabaseConnectionItem) TDQAnalysisItem(org.talend.dataquality.properties.TDQAnalysisItem) TDQItem(org.talend.core.model.properties.TDQItem) TDQPatternItem(org.talend.dataquality.properties.TDQPatternItem) MDMConnectionItem(org.talend.core.model.properties.MDMConnectionItem) TDQMatchRuleItem(org.talend.dataquality.properties.TDQMatchRuleItem) TDQBusinessRuleItem(org.talend.dataquality.properties.TDQBusinessRuleItem) TDQReportItem(org.talend.dataquality.properties.TDQReportItem) ModelElement(orgomg.cwm.objectmodel.core.ModelElement) TDQBusinessRuleItem(org.talend.dataquality.properties.TDQBusinessRuleItem) DelimitedFileConnectionItem(org.talend.core.model.properties.DelimitedFileConnectionItem) TDQReportItem(org.talend.dataquality.properties.TDQReportItem) TDQAnalysisItem(org.talend.dataquality.properties.TDQAnalysisItem)

Aggregations

TDQBusinessRuleItem (org.talend.dataquality.properties.TDQBusinessRuleItem)11 TDQAnalysisItem (org.talend.dataquality.properties.TDQAnalysisItem)6 TDQIndicatorDefinitionItem (org.talend.dataquality.properties.TDQIndicatorDefinitionItem)6 TDQPatternItem (org.talend.dataquality.properties.TDQPatternItem)6 Item (org.talend.core.model.properties.Item)5 TDQReportItem (org.talend.dataquality.properties.TDQReportItem)5 DQRule (org.talend.dataquality.rules.DQRule)5 ReturnCode (org.talend.utils.sugars.ReturnCode)4 Resource (org.eclipse.emf.ecore.resource.Resource)3 Test (org.junit.Test)3 PersistenceException (org.talend.commons.exception.PersistenceException)3 Property (org.talend.core.model.properties.Property)3 TDQItem (org.talend.core.model.properties.TDQItem)3 Analysis (org.talend.dataquality.analysis.Analysis)3 Pattern (org.talend.dataquality.domain.pattern.Pattern)3 TDQMatchRuleItem (org.talend.dataquality.properties.TDQMatchRuleItem)3 WhereRule (org.talend.dataquality.rules.WhereRule)3 DQRuleWriter (org.talend.dq.writer.impl.DQRuleWriter)3 Path (org.eclipse.core.runtime.Path)2 URI (org.eclipse.emf.common.util.URI)2