Search in sources :

Example 26 with TDQIndicatorDefinitionItem

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

the class OpenItemEditorAction method computeEditorInput.

/**
 * get the ItemEditorInput according to the repNode, if there no ItemEditorInput return null.
 *
 * @param repNode
 * @param isOpenItemEditorAction
 * @return IEditorInput
 * @throws PersistenceException
 */
public IEditorInput computeEditorInput(IRepositoryNode repNode, boolean isOpenItemEditorAction) throws BusinessException {
    // TDQ-12499 msjian add : when click the node under recyclebin, no need to find a EditorInput
    if (repNode != null && !isOpenItemEditorAction) {
        IRepositoryNode currentNode = repNode;
        do {
            RepositoryNode parentNode = currentNode.getParent();
            if (parentNode != null && parentNode instanceof RecycleBinRepNode) {
                return null;
            }
            currentNode = parentNode;
        } while (currentNode != null);
    }
    // TDQ-12499~
    IEditorInput result = null;
    IRepositoryViewObject repViewObj = repNode.getObject();
    if (repViewObj != null) {
        // Connection editor
        String key = repViewObj.getRepositoryObjectType().getKey();
        Item item = repViewObj.getProperty().getItem();
        if (item instanceof TDQItem && !(item instanceof TDQFileItem)) {
            ModelElement modelElement = PropertyHelper.getModelElement(repViewObj.getProperty());
            if (modelElement.eIsProxy() && repNode != null) {
                modelElement = (ModelElement) EObjectHelper.resolveObject(modelElement);
                item = repViewObj.getProperty().getItem();
            }
            if (modelElement == null || modelElement.eResource() == null) {
                throw ExceptionFactory.getInstance().createBusinessException(((TDQItem) item).getFilename());
            }
        }
        if (ERepositoryObjectType.METADATA_CONNECTIONS.getKey().equals(key) || ConnectionUtils.isTcompJdbc(key)) {
            result = new ConnectionItemEditorInput(repNode);
            Connection connection = ((ConnectionItem) item).getConnection();
            if (connection == null || connection.getDataPackage().size() == 0) {
                throw ExceptionFactory.getInstance().createBusinessException(repViewObj);
            }
            editorID = ConnectionEditor.class.getName();
        } else if (ERepositoryObjectType.TDQ_ANALYSIS_ELEMENT.getKey().equals(key)) {
            result = new AnalysisItemEditorInput(repNode);
            Analysis analysis = ((TDQAnalysisItem) item).getAnalysis();
            if (analysis == null || analysis.getContext() == null) {
                throw ExceptionFactory.getInstance().createBusinessException(repViewObj);
            }
            EList<ModelElement> analysedElements = analysis.getContext().getAnalysedElements();
            RepositoryNode connectionRepositoryNode = null;
            if (!analysedElements.isEmpty()) {
                Connection connection = null;
                ModelElement modelElement = analysedElements.get(0);
                if (modelElement instanceof Connection) {
                    connection = (Connection) modelElement;
                } else if (modelElement instanceof Catalog) {
                    Catalog catalog = SwitchHelpers.CATALOG_SWITCH.caseCatalog((Catalog) modelElement);
                    connection = ConnectionHelper.getConnection(catalog);
                } else if (modelElement instanceof Schema) {
                    Schema schema = SwitchHelpers.SCHEMA_SWITCH.caseSchema((Schema) modelElement);
                    if (schema != null) {
                        connection = ConnectionHelper.getConnection(schema);
                    }
                } else if (modelElement instanceof TdTable) {
                    TdTable tdTable = SwitchHelpers.TABLE_SWITCH.caseTdTable((TdTable) modelElement);
                    connection = ConnectionHelper.getConnection(tdTable);
                } else if (modelElement instanceof TdView) {
                    TdView tdView = SwitchHelpers.VIEW_SWITCH.caseTdView((TdView) modelElement);
                    connection = ConnectionHelper.getConnection(tdView);
                } else if (modelElement instanceof TdColumn) {
                    TdColumn tdColumn = SwitchHelpers.COLUMN_SWITCH.caseTdColumn((TdColumn) modelElement);
                    connection = ConnectionHelper.getConnection(tdColumn);
                } else if (modelElement instanceof MetadataColumn) {
                    MetadataColumn mColumn = SwitchHelpers.METADATA_COLUMN_SWITCH.doSwitch(modelElement);
                    connection = ConnectionHelper.getTdDataProvider(mColumn);
                }
                connectionRepositoryNode = RepositoryNodeHelper.recursiveFind(connection);
            }
            ((AnalysisItemEditorInput) result).setConnectionNode(connectionRepositoryNode);
            if (analysis.getParameters() != null && analysis.getParameters().getAnalysisType().equals(AnalysisType.MATCH_ANALYSIS)) {
                editorID = MatchAnalysisEditor.class.getName();
            } else {
                editorID = AnalysisEditor.class.getName();
            }
        } else if (ERepositoryObjectType.TDQ_INDICATOR_ELEMENT.getKey().equals(key)) {
            result = new IndicatorDefinitionItemEditorInput(repNode);
            TDQIndicatorDefinitionItem definitionItem = (TDQIndicatorDefinitionItem) item;
            if (definitionItem.getIndicatorDefinition().eResource() == null) {
                throw ExceptionFactory.getInstance().createBusinessException(definitionItem.getFilename());
            }
            if (UDIHelper.getUDICategory(definitionItem.getIndicatorDefinition()) == null) {
                throw ExceptionFactory.getInstance().createBusinessException(definitionItem.getFilename());
            }
            editorID = IndicatorEditor.class.getName();
        } else if (ERepositoryObjectType.TDQ_RULES_SQL.getKey().equals(key) || ERepositoryObjectType.TDQ_RULES_PARSER.getKey().equals(key) || ERepositoryObjectType.TDQ_RULES_MATCHER.getKey().equals(key)) {
            result = new BusinessRuleItemEditorInput(repNode);
            editorID = DQRuleEditor.class.getName();
        } else if (ERepositoryObjectType.TDQ_PATTERN_ELEMENT.getKey().equals(key)) {
            result = new PatternItemEditorInput(repNode);
            TDQPatternItem patternItem = (TDQPatternItem) item;
            if (patternItem.getPattern() == null || patternItem.getPattern().eResource() == null) {
                throw ExceptionFactory.getInstance().createBusinessException(patternItem.getFilename());
            }
            editorID = PatternEditor.class.getName();
        } else if (ERepositoryObjectType.TDQ_REPORT_ELEMENT.getKey().equals(key)) {
            result = new ReportItemEditorInput(repNode);
            TDQReportItem reportItem = (TDQReportItem) item;
            if (!(reportItem.getReport() instanceof TdReport)) {
                throw ExceptionFactory.getInstance().createBusinessException(reportItem.getFilename());
            }
            for (AnalysisMap anaMap : ((TdReport) reportItem.getReport()).getAnalysisMap()) {
                Analysis analysis = anaMap.getAnalysis();
                if (analysis.eResource() == null) {
                    throw ExceptionFactory.getInstance().createBusinessException(reportItem.getFilename());
                }
            }
            // $NON-NLS-1$
            editorID = "org.talend.dataprofiler.core.tdq.ui.editor.report.ReportEditror";
        } else if (ERepositoryObjectType.TDQ_SOURCE_FILE_ELEMENT.getKey().equals(key) || ERepositoryObjectType.TDQ_JRAXML_ELEMENT.getKey().equals(key)) {
            IPath append = WorkbenchUtils.getFilePath(repViewObj.getRepositoryNode());
            DQRepositoryNode node = (DQRepositoryNode) repViewObj.getRepositoryNode();
            file = ResourceManager.getRoot().getProject(node.getProject().getTechnicalLabel()).getFile(append);
            if (!file.exists()) {
                throw ExceptionFactory.getInstance().createBusinessException(repViewObj);
            }
            if (ERepositoryObjectType.TDQ_SOURCE_FILE_ELEMENT.getKey().equals(key)) {
                editorID = SqlExplorerUtils.SQLEDITOR_ID;
            } else {
                editorID = TDQFileEditorInput.DEFAULT_EDITOR_ID;
            }
            result = new TDQFileEditorInput(file);
            // Added TDQ-7143 yyin 20130531
            ((TDQFileEditorInput) result).setFileItem(item);
            CorePlugin.getDefault().refreshDQView(repNode);
        // ~
        }
        // ADD msjian TDQ-4209 2012-2-7 : return the editorInput of *.jrxml and *.sql files
        if (!isOpenItemEditorAction) {
            if (ERepositoryObjectType.TDQ_JRAXML_ELEMENT.getKey().equals(key) || ERepositoryObjectType.TDQ_SOURCE_FILE_ELEMENT.getKey().equals(key)) {
                // if there don't found the correct ItemEditorInput, try to open it as a File
                result = new FileEditorInput(file);
                editorID = FileEditorInput.class.getName();
            }
        }
    // TDQ-4209~
    }
    return result;
}
Also used : TDQFileItem(org.talend.dataquality.properties.TDQFileItem) ConnectionEditor(org.talend.dataprofiler.core.ui.editor.connection.ConnectionEditor) TDQIndicatorDefinitionItem(org.talend.dataquality.properties.TDQIndicatorDefinitionItem) ConnectionItem(org.talend.core.model.properties.ConnectionItem) Schema(orgomg.cwm.resource.relational.Schema) BusinessRuleItemEditorInput(org.talend.dataprofiler.core.ui.editor.dqrules.BusinessRuleItemEditorInput) TDQPatternItem(org.talend.dataquality.properties.TDQPatternItem) 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) TDQFileItem(org.talend.dataquality.properties.TDQFileItem) TDQReportItem(org.talend.dataquality.properties.TDQReportItem) ModelElement(orgomg.cwm.objectmodel.core.ModelElement) MetadataColumn(org.talend.core.model.metadata.builder.connection.MetadataColumn) DQRepositoryNode(org.talend.dq.nodes.DQRepositoryNode) TdView(org.talend.cwm.relational.TdView) AnalysisMap(org.talend.dataquality.reports.AnalysisMap) TDQFileEditorInput(org.talend.dataprofiler.core.ui.editor.TDQFileEditorInput) AnalysisItemEditorInput(org.talend.dataprofiler.core.ui.editor.analysis.AnalysisItemEditorInput) TDQReportItem(org.talend.dataquality.properties.TDQReportItem) ReportItemEditorInput(org.talend.dataprofiler.core.ui.editor.report.ReportItemEditorInput) ConnectionItemEditorInput(org.talend.dataprofiler.core.ui.editor.connection.ConnectionItemEditorInput) TdTable(org.talend.cwm.relational.TdTable) IRepositoryNode(org.talend.repository.model.IRepositoryNode) IPath(org.eclipse.core.runtime.IPath) TdReport(org.talend.dataquality.reports.TdReport) Connection(org.talend.core.model.metadata.builder.connection.Connection) PatternItemEditorInput(org.talend.dataprofiler.core.ui.editor.pattern.PatternItemEditorInput) DQRepositoryNode(org.talend.dq.nodes.DQRepositoryNode) RepositoryNode(org.talend.repository.model.RepositoryNode) IRepositoryNode(org.talend.repository.model.IRepositoryNode) RecycleBinRepNode(org.talend.dq.nodes.RecycleBinRepNode) Catalog(orgomg.cwm.resource.relational.Catalog) EList(org.eclipse.emf.common.util.EList) TdColumn(org.talend.cwm.relational.TdColumn) PatternEditor(org.talend.dataprofiler.core.ui.editor.pattern.PatternEditor) Analysis(org.talend.dataquality.analysis.Analysis) IndicatorEditor(org.talend.dataprofiler.core.ui.editor.indicator.IndicatorEditor) TDQFileEditorInput(org.talend.dataprofiler.core.ui.editor.TDQFileEditorInput) FileEditorInput(org.eclipse.ui.part.FileEditorInput) IRepositoryViewObject(org.talend.core.model.repository.IRepositoryViewObject) TDQItem(org.talend.core.model.properties.TDQItem) IndicatorDefinitionItemEditorInput(org.talend.dataprofiler.core.ui.editor.indicator.IndicatorDefinitionItemEditorInput) IEditorInput(org.eclipse.ui.IEditorInput)

Example 27 with TDQIndicatorDefinitionItem

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

the class TDQResourceChangeHandler method create.

@Override
public Resource create(IProject project, Item item, int classID, IPath path) {
    String fileExtension = FileConstants.ITEM_EXTENSION;
    Resource itemResource = null;
    try {
        switch(classID) {
            case org.talend.dataquality.properties.PropertiesPackage.TDQ_ANALYSIS_ITEM:
                fileExtension = FileConstants.ANA_EXTENSION;
                itemResource = xmiResourceManager.createItemResourceWithExtension(project, item, path, ERepositoryObjectType.TDQ_ANALYSIS_ELEMENT, false, fileExtension);
                AnalysisWriter createAnalysisWrite = org.talend.dq.writer.impl.ElementWriterFactory.getInstance().createAnalysisWrite();
                Analysis analysis = ((TDQAnalysisItem) item).getAnalysis();
                createAnalysisWrite.addResourceContent(itemResource, analysis);
                createAnalysisWrite.addDependencies(analysis);
                break;
            case org.talend.dataquality.properties.PropertiesPackage.TDQ_REPORT_ITEM:
                fileExtension = FileConstants.REP_EXTENSION;
                itemResource = xmiResourceManager.createItemResourceWithExtension(project, item, path, ERepositoryObjectType.TDQ_REPORT_ELEMENT, false, fileExtension);
                ReportWriter createReportWriter = org.talend.dq.writer.impl.ElementWriterFactory.getInstance().createReportWriter();
                Report report = ((TDQReportItem) item).getReport();
                createReportWriter.addResourceContent(itemResource, report);
                createReportWriter.addDependencies(report);
                break;
            case org.talend.dataquality.properties.PropertiesPackage.TDQ_INDICATOR_DEFINITION_ITEM:
                fileExtension = FileConstants.DEF_EXTENSION;
                itemResource = xmiResourceManager.createItemResourceWithExtension(project, item, path, ERepositoryObjectType.TDQ_INDICATOR_ELEMENT, false, fileExtension);
                IndicatorDefinition indicatorDefinition = ((TDQIndicatorDefinitionItem) item).getIndicatorDefinition();
                IndicatorDefinitionWriter createIndicatorDefinitionWriter = org.talend.dq.writer.impl.ElementWriterFactory.getInstance().createIndicatorDefinitionWriter();
                createIndicatorDefinitionWriter.addResourceContent(itemResource, indicatorDefinition);
                break;
            case org.talend.dataquality.properties.PropertiesPackage.TDQ_PATTERN_ITEM:
                fileExtension = FileConstants.PAT_EXTENSION;
                itemResource = xmiResourceManager.createItemResourceWithExtension(project, item, path, ERepositoryObjectType.TDQ_PATTERN_ELEMENT, false, fileExtension);
                Pattern pattern = ((TDQPatternItem) item).getPattern();
                PatternWriter createPatternWriter = org.talend.dq.writer.impl.ElementWriterFactory.getInstance().createPatternWriter();
                createPatternWriter.addResourceContent(itemResource, pattern);
                break;
            case org.talend.dataquality.properties.PropertiesPackage.TDQ_BUSINESS_RULE_ITEM:
                fileExtension = FileConstants.RULE_EXTENSION;
                // MOD gdbu 2011-6-10 bug : 21823 2011-06-27 revert the error type code by klliu
                DQRule dqrule = ((TDQBusinessRuleItem) item).getDqrule();
                if (dqrule instanceof WhereRule) {
                    itemResource = xmiResourceManager.createItemResourceWithExtension(project, item, path, ERepositoryObjectType.TDQ_RULES_SQL, false, fileExtension);
                } else {
                    itemResource = xmiResourceManager.createItemResourceWithExtension(project, item, path, ERepositoryObjectType.TDQ_RULES_PARSER, false, fileExtension);
                }
                // ~21823
                DQRuleWriter createdRuleWriter = org.talend.dq.writer.impl.ElementWriterFactory.getInstance().createdRuleWriter();
                createdRuleWriter.addResourceContent(itemResource, dqrule);
                break;
            case org.talend.dataquality.properties.PropertiesPackage.TDQ_JRXML_ITEM:
                fileExtension = FileConstants.JRXML_EXTENSION;
                itemResource = xmiResourceManager.createItemResourceWithExtension(project, item, path, ERepositoryObjectType.TDQ_JRAXML_ELEMENT, true, fileExtension);
                itemResource.getContents().add(((TDQFileItem) item).getContent());
                break;
            case org.talend.dataquality.properties.PropertiesPackage.TDQ_SOURCE_FILE_ITEM:
                fileExtension = FileConstants.SQL_EXTENSION;
                itemResource = xmiResourceManager.createItemResourceWithExtension(project, item, path, ERepositoryObjectType.TDQ_SOURCE_FILE_ELEMENT, true, fileExtension);
                itemResource.getContents().add(((TDQFileItem) item).getContent());
                break;
            case org.talend.dataquality.properties.PropertiesPackage.TDQ_MATCH_RULE_ITEM:
                fileExtension = FileConstants.RULE_EXTENSION;
                itemResource = xmiResourceManager.createItemResourceWithExtension(project, item, path, ERepositoryObjectType.TDQ_RULES_MATCHER, false, fileExtension);
                MatchRuleDefinition matchRuleDefinition = ((TDQMatchRuleItem) item).getMatchRule();
                MatchRuleDefinitionWriter matchRuleDefinitionWriter = org.talend.dq.writer.impl.ElementWriterFactory.getInstance().createdMatchRuleWriter();
                matchRuleDefinitionWriter.addResourceContent(itemResource, matchRuleDefinition);
                break;
            default:
        }
    } catch (PersistenceException e) {
        log.error(e, e);
    }
    return itemResource;
}
Also used : Pattern(org.talend.dataquality.domain.pattern.Pattern) TDQIndicatorDefinitionItem(org.talend.dataquality.properties.TDQIndicatorDefinitionItem) Report(orgomg.cwmx.analysis.informationreporting.Report) TDQMatchRuleItem(org.talend.dataquality.properties.TDQMatchRuleItem) DQRuleWriter(org.talend.dq.writer.impl.DQRuleWriter) Resource(org.eclipse.emf.ecore.resource.Resource) IResource(org.eclipse.core.resources.IResource) PatternWriter(org.talend.dq.writer.impl.PatternWriter) MatchRuleDefinition(org.talend.dataquality.rules.MatchRuleDefinition) TDQPatternItem(org.talend.dataquality.properties.TDQPatternItem) IndicatorDefinition(org.talend.dataquality.indicators.definition.IndicatorDefinition) DQRule(org.talend.dataquality.rules.DQRule) ReportWriter(org.talend.dq.writer.impl.ReportWriter) WhereRule(org.talend.dataquality.rules.WhereRule) Analysis(org.talend.dataquality.analysis.Analysis) IndicatorDefinitionWriter(org.talend.dq.writer.impl.IndicatorDefinitionWriter) PersistenceException(org.talend.commons.exception.PersistenceException) TDQBusinessRuleItem(org.talend.dataquality.properties.TDQBusinessRuleItem) MatchRuleDefinitionWriter(org.talend.dq.writer.impl.MatchRuleDefinitionWriter) AnalysisWriter(org.talend.dq.writer.impl.AnalysisWriter) TDQReportItem(org.talend.dataquality.properties.TDQReportItem) TDQAnalysisItem(org.talend.dataquality.properties.TDQAnalysisItem)

Example 28 with TDQIndicatorDefinitionItem

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

the class IndicatorDuplicateHandle method duplicateItem.

@Override
public Item duplicateItem(Item oldItem, String newName) throws BusinessException {
    Item duplicateItem = super.duplicateItem(oldItem, newName);
    // reload is needed after duplicate an indicator.
    DefinitionHandler.getInstance().reloadIndicatorsDefinitions();
    // update the udi model to new model, after have created the indicator definition item
    if (!isUserDefCategory) {
        updateUDIModel(newName, ((TDQIndicatorDefinitionItem) duplicateItem).getIndicatorDefinition());
    }
    return duplicateItem;
}
Also used : Item(org.talend.core.model.properties.Item) TDQIndicatorDefinitionItem(org.talend.dataquality.properties.TDQIndicatorDefinitionItem)

Aggregations

TDQIndicatorDefinitionItem (org.talend.dataquality.properties.TDQIndicatorDefinitionItem)28 PersistenceException (org.talend.commons.exception.PersistenceException)13 IRepositoryViewObject (org.talend.core.model.repository.IRepositoryViewObject)13 IndicatorDefinition (org.talend.dataquality.indicators.definition.IndicatorDefinition)13 Test (org.junit.Test)12 Item (org.talend.core.model.properties.Item)9 Property (org.talend.core.model.properties.Property)8 TDQAnalysisItem (org.talend.dataquality.properties.TDQAnalysisItem)8 Path (org.eclipse.core.runtime.Path)7 TDQPatternItem (org.talend.dataquality.properties.TDQPatternItem)7 Analysis (org.talend.dataquality.analysis.Analysis)6 RowCountIndicator (org.talend.dataquality.indicators.RowCountIndicator)6 TDQBusinessRuleItem (org.talend.dataquality.properties.TDQBusinessRuleItem)5 TDQReportItem (org.talend.dataquality.properties.TDQReportItem)5 File (java.io.File)4 IPath (org.eclipse.core.runtime.IPath)4 Resource (org.eclipse.emf.ecore.resource.Resource)4 ItemState (org.talend.core.model.properties.ItemState)4 TDQItem (org.talend.core.model.properties.TDQItem)4 ReturnCode (org.talend.utils.sugars.ReturnCode)4