Search in sources :

Example 6 with TDQBusinessRuleItem

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;
}
Also used : IPath(org.eclipse.core.runtime.IPath) Path(org.eclipse.core.runtime.Path) Pattern(org.talend.dataquality.domain.pattern.Pattern) TDQIndicatorDefinitionItem(org.talend.dataquality.properties.TDQIndicatorDefinitionItem) IPath(org.eclipse.core.runtime.IPath) ConnectionItem(org.talend.core.model.properties.ConnectionItem) Resource(org.eclipse.emf.ecore.resource.Resource) MatchRuleDefinition(org.talend.dataquality.rules.MatchRuleDefinition) URI(org.eclipse.emf.common.util.URI) DQRule(org.talend.dataquality.rules.DQRule) Item(org.talend.core.model.properties.Item) TDQIndicatorDefinitionItem(org.talend.dataquality.properties.TDQIndicatorDefinitionItem) TDQAnalysisItem(org.talend.dataquality.properties.TDQAnalysisItem) ConnectionItem(org.talend.core.model.properties.ConnectionItem) TDQItem(org.talend.core.model.properties.TDQItem) TDQPatternItem(org.talend.dataquality.properties.TDQPatternItem) TDQMatchRuleItem(org.talend.dataquality.properties.TDQMatchRuleItem) TDQBusinessRuleItem(org.talend.dataquality.properties.TDQBusinessRuleItem) TDQReportItem(org.talend.dataquality.properties.TDQReportItem) ItemState(org.talend.core.model.properties.ItemState) TDQItem(org.talend.core.model.properties.TDQItem) DatabaseConnection(org.talend.core.model.metadata.builder.connection.DatabaseConnection) TDQReportItem(org.talend.dataquality.properties.TDQReportItem) TDQAnalysisItem(org.talend.dataquality.properties.TDQAnalysisItem)

Example 7 with TDQBusinessRuleItem

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;
}
Also used : ReturnCode(org.talend.utils.sugars.ReturnCode) PersistenceException(org.talend.commons.exception.PersistenceException) RepositoryWorkUnit(org.talend.repository.RepositoryWorkUnit) TDQBusinessRuleItem(org.talend.dataquality.properties.TDQBusinessRuleItem) DQRule(org.talend.dataquality.rules.DQRule)

Example 8 with TDQBusinessRuleItem

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);
    }
}
Also used : Pattern(org.talend.dataquality.domain.pattern.Pattern) TDQIndicatorDefinitionItem(org.talend.dataquality.properties.TDQIndicatorDefinitionItem) Dependency(orgomg.cwm.objectmodel.core.Dependency) TDQPatternItem(org.talend.dataquality.properties.TDQPatternItem) IndicatorDefinition(org.talend.dataquality.indicators.definition.IndicatorDefinition) DQRule(org.talend.dataquality.rules.DQRule) DQRepositoryNode(org.talend.dq.nodes.DQRepositoryNode) Analysis(org.talend.dataquality.analysis.Analysis) PersistenceException(org.talend.commons.exception.PersistenceException) TDQItem(org.talend.core.model.properties.TDQItem) TDQBusinessRuleItem(org.talend.dataquality.properties.TDQBusinessRuleItem) Property(org.talend.core.model.properties.Property) InternalEObject(org.eclipse.emf.ecore.InternalEObject)

Example 9 with TDQBusinessRuleItem

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());
}
Also used : ReturnCode(org.talend.utils.sugars.ReturnCode) WhereRuleIndicator(org.talend.dataquality.indicators.sql.WhereRuleIndicator) Analysis(org.talend.dataquality.analysis.Analysis) AnalysisContext(org.talend.dataquality.analysis.AnalysisContext) TDQBusinessRuleItem(org.talend.dataquality.properties.TDQBusinessRuleItem) Property(org.talend.core.model.properties.Property) AnalysisWriter(org.talend.dq.writer.impl.AnalysisWriter) AnalysisResult(org.talend.dataquality.analysis.AnalysisResult) TDQAnalysisItem(org.talend.dataquality.properties.TDQAnalysisItem) DQRule(org.talend.dataquality.rules.DQRule) Test(org.junit.Test)

Example 10 with TDQBusinessRuleItem

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));
}
Also used : 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) WhereRule(org.talend.dataquality.rules.WhereRule) DQRuleWriter(org.talend.dq.writer.impl.DQRuleWriter) TDQBusinessRuleItem(org.talend.dataquality.properties.TDQBusinessRuleItem) Test(org.junit.Test)

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