Search in sources :

Example 1 with ReturnCode

use of org.talend.utils.sugars.ReturnCode in project tdq-studio-se by Talend.

the class FunctionalDependencyAnalysisDetailsPage method validator.

private ReturnCode validator(List<RepositoryNode> columnASet, List<RepositoryNode> columnBSet) {
    // MOD by gdbu 2011-3-21 bug 19179
    ReturnCode canModRetCode = super.canSave();
    if (!canModRetCode.isOk()) {
        return canModRetCode;
    }
    if (columnASet.isEmpty() || columnBSet.isEmpty()) {
        // $NON-NLS-1$
        return new ReturnCode(DefaultMessagesImpl.getString("ColumnDependencyMasterDetailsPage.columnsBlankMessag"), false);
    }
    if (columnASet.size() != columnBSet.size()) {
        // $NON-NLS-1$
        return new ReturnCode(DefaultMessagesImpl.getString("ColumnsComparisonMasterDetailsPage.columnsSameMessage"), false);
    }
    for (int i = 0; i < columnASet.size(); i++) {
        RepositoryNode columnANode = columnASet.get(i);
        RepositoryNode columnBNode = columnBSet.get(i);
        TdColumn tdColumnA = ((DBColumnRepNode) columnANode).getTdColumn();
        TdColumn tdColumnB = ((DBColumnRepNode) columnBNode).getTdColumn();
        ColumnSet ownerA = ColumnHelper.getColumnOwnerAsColumnSet(tdColumnA);
        ColumnSet ownerB = ColumnHelper.getColumnOwnerAsColumnSet(tdColumnB);
        String uuidA = ResourceHelper.getUUID(ownerA);
        String uuidB = ResourceHelper.getUUID(ownerB);
        if (!uuidA.equals(uuidB)) {
            // $NON-NLS-1$
            return new ReturnCode(DefaultMessagesImpl.getString("ColumnDependencyMasterDetailsPage.tableMessage"), false);
        }
    }
    return new ReturnCode(true);
}
Also used : TypedReturnCode(org.talend.utils.sugars.TypedReturnCode) ReturnCode(org.talend.utils.sugars.ReturnCode) TdColumn(org.talend.cwm.relational.TdColumn) ColumnSet(orgomg.cwm.resource.relational.ColumnSet) DBColumnRepNode(org.talend.dq.nodes.DBColumnRepNode) RepositoryNode(org.talend.repository.model.RepositoryNode) IRepositoryNode(org.talend.repository.model.IRepositoryNode)

Example 2 with ReturnCode

use of org.talend.utils.sugars.ReturnCode in project tdq-studio-se by Talend.

the class FunctionalDependencyAnalysisDetailsPage method saveAnalysis.

/*
     * (non-Javadoc)
     * 
     * @see org.talend.dataprofiler.core.ui.editor.analysis.AbstractAnalysisMetadataPage#saveAnalysis()
     */
@Override
protected void saveAnalysis() throws DataprofilerCoreException {
    analysisHandler.changeDefaultRowLoaded(rowLoadedText.getText());
    analysisHandler.changeSampleDataShowWay(sampleDataShowWayCombo.getText());
    for (Domain domain : getCurrentModelElement().getParameters().getDataFilter()) {
        domain.setName(getCurrentModelElement().getName());
    }
    IRepositoryViewObject reposObject = null;
    getAnalysisHandler().clearAnalysis();
    List<RepositoryNode> columnListAANode = anaColumnCompareViewer.getColumnListA();
    List<RepositoryNode> columnListBBNode = anaColumnCompareViewer.getColumnListB();
    AnalysisBuilder anaBuilder = new AnalysisBuilder();
    anaBuilder.setAnalysis(getCurrentModelElement());
    Connection tdDataProvider = null;
    for (int i = 0; i < columnListAANode.size(); i++) {
        if (columnListBBNode.size() > i) {
            ColumnDependencyIndicator indicator = ColumnsetFactory.eINSTANCE.createColumnDependencyIndicator();
            TdColumn columnA = (TdColumn) ((MetadataColumnRepositoryObject) columnListAANode.get(i).getObject()).getTdColumn();
            TdColumn columnB = (TdColumn) ((MetadataColumnRepositoryObject) columnListBBNode.get(i).getObject()).getTdColumn();
            indicator.setColumnA(columnA);
            indicator.setColumnB(columnB);
            indicator.setIndicatorDefinition(DefinitionHandler.getInstance().getFDRuleDefaultIndicatorDefinition());
            getCurrentModelElement().getResults().getIndicators().add(indicator);
            anaBuilder.addElementToAnalyze(columnA, indicator);
            // ADD this line qiongli 2010-6-8
            anaBuilder.addElementToAnalyze(columnB, indicator);
        }
    }
    if (columnListAANode.size() > 0) {
        reposObject = columnListAANode.get(0).getObject();
        tdDataProvider = ((ConnectionItem) reposObject.getProperty().getItem()).getConnection();
        // MOD qiongli bug 14437:Add dependency
        getCurrentModelElement().getContext().setConnection(tdDataProvider);
        TypedReturnCode<Dependency> rc = DependenciesHandler.getInstance().setDependencyOn(getCurrentModelElement(), tdDataProvider);
        if (!rc.isOk()) {
            // $NON-NLS-1$
            log.info("fail to save dependency analysis:" + getCurrentModelElement().getFileName());
        }
    } else {
        getCurrentModelElement().getContext().setConnection(null);
    }
    // save the number of connections per analysis
    this.saveNumberOfConnectionsPerAnalysis();
    // 2011.1.12 MOD by zhsne to unify anlysis and connection id when saving.
    this.nameText.setText(getCurrentModelElement().getName());
    // MOD yyi 2012-02-08 TDQ-4621:Explicitly set true for updating dependencies.
    ReturnCode saved = ElementWriterFactory.getInstance().createAnalysisWrite().save(getCurrentRepNode().getObject().getProperty().getItem(), true);
    // MOD yyi 2012-02-03 TDQ-3602:Avoid to rewriting all analyzes after saving, no reason to update all analyzes
    // which is depended in the referred connection.
    // Extract saving log function.
    // @see org.talend.dataprofiler.core.ui.editor.analysis.AbstractAnalysisMetadataPage#logSaved(ReturnCode)
    logSaved(saved);
    anaColumnCompareViewer.setDirty(false);
    dataFilterComp.setDirty(false);
}
Also used : ColumnDependencyIndicator(org.talend.dataquality.indicators.columnset.ColumnDependencyIndicator) TdColumn(org.talend.cwm.relational.TdColumn) TypedReturnCode(org.talend.utils.sugars.TypedReturnCode) ReturnCode(org.talend.utils.sugars.ReturnCode) IRepositoryViewObject(org.talend.core.model.repository.IRepositoryViewObject) Connection(org.talend.core.model.metadata.builder.connection.Connection) AnalysisBuilder(org.talend.dq.analysis.AnalysisBuilder) Dependency(orgomg.cwm.objectmodel.core.Dependency) Domain(org.talend.dataquality.domain.Domain) RepositoryNode(org.talend.repository.model.RepositoryNode) IRepositoryNode(org.talend.repository.model.IRepositoryNode)

Example 3 with ReturnCode

use of org.talend.utils.sugars.ReturnCode in project tdq-studio-se by Talend.

the class MatchAnalysisDetailsPage method canSave.

/*
     * (non-Javadoc)
     * 
     * @see org.talend.dataprofiler.core.ui.editor.analysis.AbstractAnalysisMetadataPage#canSave()
     */
@Override
public ReturnCode canSave() {
    if (this.isDirty) {
        ReturnCode checkResultStatus = blockingKeySection.checkResultStatus();
        if (checkResultStatus.isOk()) {
            if (selectAlgorithmSection.isVSRMode()) {
                checkResultStatus = matchingKeySection.checkResultStatus();
            } else {
                checkResultStatus = matchAndSurvivorKeySection.checkResultStatus();
                if (checkResultStatus.isOk()) {
                    checkResultStatus = this.defaultSurvivorshipDefinitionSection.checkResultStatus();
                }
            }
        }
        if (checkResultStatus.isOk() && !selectAlgorithmSection.isVSRMode()) {
            checkResultStatus = this.particularDefaultSurvivorshipSection.checkResultStatus();
        }
        if (checkResultStatus.isOk()) {
            if (TaggedValueHelper.getValueBoolean(SQLExecutor.STORE_ON_DISK_KEY, getCurrentModelElement())) {
                if (StringUtils.isBlank(TaggedValueHelper.getValueString(SQLExecutor.TEMP_DATA_DIR, getCurrentModelElement()))) {
                    checkResultStatus.setOk(false);
                    // $NON-NLS-1$
                    checkResultStatus.setMessage(DefaultMessagesImpl.getString("MatchMasterDetailsPage.invalidTempFolder"));
                }
            }
        }
        if (!checkResultStatus.isOk()) {
            return checkResultStatus;
        }
    }
    return super.canSave();
}
Also used : ReturnCode(org.talend.utils.sugars.ReturnCode)

Example 4 with ReturnCode

use of org.talend.utils.sugars.ReturnCode in project tdq-studio-se by Talend.

the class MatchAnalysisDetailsPage method saveAnalysis.

/*
     * (non-Javadoc)
     * 
     * @see org.talend.dataprofiler.core.ui.editor.analysis.AbstractAnalysisMetadataPage#saveAnalysis()
     */
@Override
protected void saveAnalysis() throws DataprofilerCoreException {
    // save the default loaded row count
    if (this.isValidateRowCount()) {
        analysisHandler.changeDefaultRowLoaded(rowLoadedText.getText());
    } else {
        // $NON-NLS-1$
        MessageDialog.openWarning(// $NON-NLS-1$
        null, // $NON-NLS-1$
        DefaultMessagesImpl.getString("MatchMasterDetailsPage.NotValidate"), // $NON-NLS-1$
        DefaultMessagesImpl.getString("MatchMasterDetailsPage.LoadedRowCountError"));
        return;
    }
    analysisHandler.changeSampleDataShowWay(sampleDataShowWayCombo.getText());
    analysisHandler.saveSelectedAnalyzedElements();
    TDQAnalysisItem analysisItem = (TDQAnalysisItem) getCurrentRepNode().getObject().getProperty().getItem();
    analysisHandler.updateAnaConnRelationship(analysisItem);
    this.nameText.setText(analysisHandler.getName());
    ReturnCode saved = ElementWriterFactory.getInstance().createAnalysisWrite().save(analysisItem, true);
    logSaved(saved);
}
Also used : ReturnCode(org.talend.utils.sugars.ReturnCode) TDQAnalysisItem(org.talend.dataquality.properties.TDQAnalysisItem)

Example 5 with ReturnCode

use of org.talend.utils.sugars.ReturnCode in project tdq-studio-se by Talend.

the class RedundancyAnalysisDetailsPage method canSave.

@Override
public ReturnCode canSave() {
    // MOD by gdbu 2011-3-21 bug 19179
    ReturnCode canModRetCode = super.canSave();
    if (!canModRetCode.isOk()) {
        return canModRetCode;
    }
    if (anaColumnCompareViewer.getColumnListA().size() != anaColumnCompareViewer.getColumnListB().size()) {
        // $NON-NLS-1$
        return new ReturnCode(DefaultMessagesImpl.getString("ColumnsComparisonMasterDetailsPage.columnsSameMessage"), false);
    }
    List<TdColumn> columnAList = new ArrayList<TdColumn>();
    List<TdColumn> columnBList = new ArrayList<TdColumn>();
    for (RepositoryNode rd : anaColumnCompareViewer.getColumnListA()) {
        columnAList.add((TdColumn) ((MetadataColumnRepositoryObject) rd.getObject()).getTdColumn());
    }
    for (RepositoryNode rd : anaColumnCompareViewer.getColumnListB()) {
        columnBList.add((TdColumn) ((MetadataColumnRepositoryObject) rd.getObject()).getTdColumn());
    }
    if (anaColumnCompareViewer.getColumnListA().size() > 0) {
        if (!ColumnHelper.isFromSameTable(columnAList) || !ColumnHelper.isFromSameTable(columnBList)) {
            return new ReturnCode(DefaultMessagesImpl.getString("ColumnsComparisonMasterDetailsPage.notSameElementMessage"), // $NON-NLS-1$
            false);
        }
        for (int i = 0; i < anaColumnCompareViewer.getColumnListA().size(); i++) {
            TdColumn columnA = columnAList.get(i);
            TdColumn columnB = columnBList.get(i);
            ColumnSet ownerA = ColumnHelper.getColumnOwnerAsColumnSet(columnA);
            ColumnSet ownerB = ColumnHelper.getColumnOwnerAsColumnSet(columnB);
            int typeA = columnA.getSqlDataType().getJavaDataType();
            int typeB = columnB.getSqlDataType().getJavaDataType();
            if (!Java2SqlType.isGenericSameType(typeA, typeB)) {
                return new ReturnCode(DefaultMessagesImpl.getString("ColumnsComparisonMasterDetailsPage.notSameColumnType"), // $NON-NLS-1$
                false);
            }
            if (!ColumnSetHelper.isFromSamePackage(ownerA, ownerB)) {
                return new ReturnCode(DefaultMessagesImpl.getString("ColumnsComparisonMasterDetailsPage.schemaSameMessage"), // $NON-NLS-1$
                false);
            }
        }
        List<TdColumn> allColumns = new ArrayList<TdColumn>();
        allColumns.addAll(columnAList);
        allColumns.addAll(columnBList);
    // MOD scorreia 2009-05-25 allow to compare elements from the same
    // table
    // if (ColumnHelper.isFromSameTable(allColumns)) {
    // return new ReturnCode(DefaultMessagesImpl.getString("ColumnsComparisonMasterDetailsPage.TwoSideColumns"), false); //$NON-NLS-1$
    // }
    }
    return new ReturnCode(true);
}
Also used : TypedReturnCode(org.talend.utils.sugars.TypedReturnCode) ReturnCode(org.talend.utils.sugars.ReturnCode) TdColumn(org.talend.cwm.relational.TdColumn) ArrayList(java.util.ArrayList) MetadataColumnRepositoryObject(org.talend.core.repository.model.repositoryObject.MetadataColumnRepositoryObject) ColumnSet(orgomg.cwm.resource.relational.ColumnSet) RepositoryNode(org.talend.repository.model.RepositoryNode) IRepositoryNode(org.talend.repository.model.IRepositoryNode)

Aggregations

ReturnCode (org.talend.utils.sugars.ReturnCode)175 ArrayList (java.util.ArrayList)42 TypedReturnCode (org.talend.utils.sugars.TypedReturnCode)42 Test (org.junit.Test)29 File (java.io.File)26 Connection (org.talend.core.model.metadata.builder.connection.Connection)26 Indicator (org.talend.dataquality.indicators.Indicator)25 ModelElement (orgomg.cwm.objectmodel.core.ModelElement)20 DatabaseConnection (org.talend.core.model.metadata.builder.connection.DatabaseConnection)18 Analysis (org.talend.dataquality.analysis.Analysis)18 Property (org.talend.core.model.properties.Property)17 IFile (org.eclipse.core.resources.IFile)16 IRepositoryNode (org.talend.repository.model.IRepositoryNode)16 IFolder (org.eclipse.core.resources.IFolder)15 SQLException (java.sql.SQLException)14 PersistenceException (org.talend.commons.exception.PersistenceException)11 TdColumn (org.talend.cwm.relational.TdColumn)11 IOException (java.io.IOException)10 EObject (org.eclipse.emf.ecore.EObject)10 IMetadataConnection (org.talend.core.model.metadata.IMetadataConnection)10