Search in sources :

Example 6 with TDQPatternItem

use of org.talend.dataquality.properties.TDQPatternItem 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 TDQPatternItem

use of org.talend.dataquality.properties.TDQPatternItem in project tdq-studio-se by Talend.

the class PatternWriter 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 Analysis item") {

        @Override
        protected void run() throws LoginException, PersistenceException {
            TDQPatternItem patternItem = (TDQPatternItem) item;
            Pattern pattern = patternItem.getPattern();
            updateDisplayName(patternItem);
            // MOD yyi 2012-02-07 TDQ-4621:Update dependencies(connection) when careDependency is true.
            if (careDependency) {
                saveWithDependencies(patternItem, pattern);
            } else {
                saveWithoutDependencies(patternItem, pattern);
            }
        }
    };
    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 : Pattern(org.talend.dataquality.domain.pattern.Pattern) ReturnCode(org.talend.utils.sugars.ReturnCode) PersistenceException(org.talend.commons.exception.PersistenceException) RepositoryWorkUnit(org.talend.repository.RepositoryWorkUnit) TDQPatternItem(org.talend.dataquality.properties.TDQPatternItem)

Example 8 with TDQPatternItem

use of org.talend.dataquality.properties.TDQPatternItem 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 TDQPatternItem

use of org.talend.dataquality.properties.TDQPatternItem in project tdq-studio-se by Talend.

the class RespositoryDetailView method createFileDetail.

private boolean createFileDetail(boolean is, IRepositoryViewObject reposViewObj) {
    // MOD klliu 2001-02-28 bug 19154
    if (reposViewObj.getProperty() != null) {
        Item item = reposViewObj.getProperty().getItem();
        if (item instanceof ConnectionItem) {
            Connection conn = ((ConnectionItem) item).getConnection();
            createDataProviderDetail(conn);
            is = false;
        }
        if (item instanceof TDQAnalysisItem) {
            Analysis analysis = ((TDQAnalysisItem) item).getAnalysis();
            createAnaysisDetail(analysis);
            is = false;
        }
        if (item instanceof TDQPatternItem) {
            Pattern pattern = ((TDQPatternItem) item).getPattern();
            createPatternDetail(pattern);
            is = false;
        }
        if (item instanceof TDQReportItem) {
            Report report = ((TDQReportItem) item).getReport();
            createReportDetail(report);
            is = false;
        }
    }
    return is;
}
Also used : ContextItem(org.talend.core.model.properties.ContextItem) Item(org.talend.core.model.properties.Item) TDQAnalysisItem(org.talend.dataquality.properties.TDQAnalysisItem) ConnectionItem(org.talend.core.model.properties.ConnectionItem) TDQPatternItem(org.talend.dataquality.properties.TDQPatternItem) TDQReportItem(org.talend.dataquality.properties.TDQReportItem) Pattern(org.talend.dataquality.domain.pattern.Pattern) Report(orgomg.cwmx.analysis.informationreporting.Report) TdReport(org.talend.dataquality.reports.TdReport) ConnectionItem(org.talend.core.model.properties.ConnectionItem) Analysis(org.talend.dataquality.analysis.Analysis) DatabaseConnection(org.talend.core.model.metadata.builder.connection.DatabaseConnection) DelimitedFileConnection(org.talend.core.model.metadata.builder.connection.DelimitedFileConnection) FileConnection(org.talend.core.model.metadata.builder.connection.FileConnection) Connection(org.talend.core.model.metadata.builder.connection.Connection) TDQPatternItem(org.talend.dataquality.properties.TDQPatternItem) TDQReportItem(org.talend.dataquality.properties.TDQReportItem) TDQAnalysisItem(org.talend.dataquality.properties.TDQAnalysisItem)

Example 10 with TDQPatternItem

use of org.talend.dataquality.properties.TDQPatternItem in project tdq-studio-se by Talend.

the class FileSystemImportWriter method write.

/*
     * After check the conflicts of the imported object, calling this method (from ImportWizard) replace the conflicts
     * object in the records if the record is valid; then call the finish to do migrate. OR: merge the conflict system
     * indicators if valid.(overwrite)
     * 
     * @see
     * org.talend.dataprofiler.core.ui.imex.model.IImexWriter#write(org.talend.dataprofiler.core.ui.imex.model.ItemRecord
     * [], org.eclipse.core.runtime.IProgressMonitor)
     */
public void write(ItemRecord[] records, IProgressMonitor monitor) {
    if (monitor == null) {
        monitor = new NullProgressMonitor();
    }
    final ItemRecord[] fRecords = records;
    final IProgressMonitor fMonitor = monitor;
    need2MergeModelElementMap.clear();
    allImportItems.clear();
    RepositoryWorkUnit<Object> workUnit = new // $NON-NLS-1$
    RepositoryWorkUnit<Object>(// $NON-NLS-1$
    "Import TDQ Element") {

        @Override
        protected void run() {
            try {
                for (ItemRecord record : fRecords) {
                    if (fMonitor.isCanceled()) {
                        break;
                    }
                    Map<IPath, IPath> toImportMap = mapping(record);
                    // $NON-NLS-1$
                    fMonitor.subTask("Importing " + record.getName());
                    if (record.isValid()) {
                        boolean isDeleted = false;
                        // $NON-NLS-1$
                        log.info("Importing " + record.getFile().getAbsolutePath());
                        // Delete the conflict node before import.
                        IRepositoryViewObject object = record.getConflictObject();
                        boolean isDelete = true;
                        ModelElement modEle = record.getElement();
                        if (object != null) {
                            // is a system indicator definition, (using its UUid to find this SI not label)
                            if (isIndicatorDefinition(modEle)) {
                                if (isDQRule(modEle)) {
                                    if (isParserRule(modEle)) {
                                        mergeParserRule(record, (TDQBusinessRuleItem) object.getProperty().getItem());
                                        isDelete = false;
                                    } else if (isWhereRule(modEle)) {
                                    // do nothing here now
                                    }
                                } else if (isMatchRuleDefinition(modEle)) {
                                // do nothing here now
                                } else {
                                    // System Indicator and UDI need merge
                                    TDQIndicatorDefinitionItem indItem = (TDQIndicatorDefinitionItem) object.getProperty().getItem();
                                    mergeSystemIndicator(record, indItem);
                                    // only add it when it is UDIndicatorDefinition
                                    if (record.getElement() instanceof UDIndicatorDefinition) {
                                        need2MergeModelElementMap.put(indItem, record.getElement());
                                    }
                                    isDelete = false;
                                }
                            } else if (isPattern(modEle)) {
                                TDQPatternItem patternItem = (TDQPatternItem) object.getProperty().getItem();
                                mergePattern(record, patternItem);
                                need2MergeModelElementMap.put(patternItem, record.getElement());
                                isDelete = false;
                            } else {
                                // remove the dependency of the object
                                EObjectHelper.removeDependencys(PropertyHelper.getModelElement(object.getProperty()));
                                isDeleted = true;
                                // delete the object
                                ProxyRepositoryFactory.getInstance().deleteObjectPhysical(object);
                            }
                        }
                        if (isDelete) {
                            updateFiles.clear();
                            updateFilesCoverd.clear();
                            for (IPath resPath : toImportMap.keySet()) {
                                IPath desPath = toImportMap.get(resPath);
                                ResourceSet resourceSet = ProxyRepositoryFactory.getInstance().getRepositoryFactoryFromProvider().getResourceManager().resourceSet;
                                synchronized (resourceSet) {
                                    write(resPath, desPath);
                                    allCopiedFiles.add(desPath.toFile());
                                }
                                allImportItems.add(desPath);
                                // TDQ-12180
                                if (isDeleted) {
                                    AbstractSvnRepositoryService svnReposService = GlobalServiceRegister.getDefault().getSvnRepositoryService(AbstractSvnRepositoryService.class);
                                    if (svnReposService != null) {
                                        svnReposService.addIfImportOverride(desPath);
                                    }
                                }
                            }
                            for (File file : updateFiles) {
                                update(file, false);
                            }
                            for (File file : updateFilesCoverd) {
                                update(file, true);
                            }
                        }
                    } else {
                        for (String error : record.getErrors()) {
                            log.error(error);
                        }
                    }
                    fMonitor.worked(1);
                }
                finish(fRecords, fMonitor);
            } catch (Exception e) {
                log.error(e, e);
            }
        }
    };
    workUnit.setAvoidUnloadResources(Boolean.TRUE);
    ProxyRepositoryFactory.getInstance().executeRepositoryWorkUnit(workUnit);
    // after above workUnit executed, the imported items will worked, than can do merge/update about UDI and Pattern
    RepositoryWorkUnit<Object> workUnitFinish = new // $NON-NLS-1$
    RepositoryWorkUnit<Object>(// $NON-NLS-1$
    "Finish Import TDQ Element") {

        @Override
        protected void run() throws LoginException, PersistenceException {
            try {
                postFinish();
            } catch (IOException e) {
                log.error(e, e);
            }
        }
    };
    workUnitFinish.setAvoidUnloadResources(Boolean.TRUE);
    ProxyRepositoryFactory.getInstance().executeRepositoryWorkUnit(workUnitFinish);
}
Also used : NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) TDQIndicatorDefinitionItem(org.talend.dataquality.properties.TDQIndicatorDefinitionItem) IPath(org.eclipse.core.runtime.IPath) AbstractSvnRepositoryService(org.talend.dataprofiler.core.service.AbstractSvnRepositoryService) UDIndicatorDefinition(org.talend.dataquality.indicators.definition.userdefine.UDIndicatorDefinition) RepositoryWorkUnit(org.talend.repository.RepositoryWorkUnit) ResourceSet(org.eclipse.emf.ecore.resource.ResourceSet) IOException(java.io.IOException) TDQPatternItem(org.talend.dataquality.properties.TDQPatternItem) CoreException(org.eclipse.core.runtime.CoreException) LoginException(org.talend.commons.exception.LoginException) IOException(java.io.IOException) PersistenceException(org.talend.commons.exception.PersistenceException) ModelElement(orgomg.cwm.objectmodel.core.ModelElement) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) IRepositoryViewObject(org.talend.core.model.repository.IRepositoryViewObject) IRepositoryViewObject(org.talend.core.model.repository.IRepositoryViewObject) InternalEObject(org.eclipse.emf.ecore.InternalEObject) EObject(org.eclipse.emf.ecore.EObject) IFile(org.eclipse.core.resources.IFile) File(java.io.File)

Aggregations

TDQPatternItem (org.talend.dataquality.properties.TDQPatternItem)14 Pattern (org.talend.dataquality.domain.pattern.Pattern)10 Item (org.talend.core.model.properties.Item)7 TDQAnalysisItem (org.talend.dataquality.properties.TDQAnalysisItem)7 TDQIndicatorDefinitionItem (org.talend.dataquality.properties.TDQIndicatorDefinitionItem)7 TDQReportItem (org.talend.dataquality.properties.TDQReportItem)7 Analysis (org.talend.dataquality.analysis.Analysis)6 TDQBusinessRuleItem (org.talend.dataquality.properties.TDQBusinessRuleItem)5 IPath (org.eclipse.core.runtime.IPath)4 PersistenceException (org.talend.commons.exception.PersistenceException)4 ConnectionItem (org.talend.core.model.properties.ConnectionItem)4 TDQItem (org.talend.core.model.properties.TDQItem)4 IRepositoryViewObject (org.talend.core.model.repository.IRepositoryViewObject)4 PatternComponent (org.talend.dataquality.domain.pattern.PatternComponent)4 ModelElement (orgomg.cwm.objectmodel.core.ModelElement)4 InternalEObject (org.eclipse.emf.ecore.InternalEObject)3 Resource (org.eclipse.emf.ecore.resource.Resource)3 Connection (org.talend.core.model.metadata.builder.connection.Connection)3 DatabaseConnection (org.talend.core.model.metadata.builder.connection.DatabaseConnection)3 File (java.io.File)2