Search in sources :

Example 1 with TypedReturnCode

use of org.talend.utils.sugars.TypedReturnCode 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 2 with TypedReturnCode

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

the class SoftwareSystemManagerTest method testUpdateSoftwareSystem.

/**
 * Test method for
 * {@link org.talend.cwm.management.api.SoftwareSystemManager#updateSoftwareSystem(java.sql.Connection, orgomg.cwm.foundation.softwaredeployment.SoftwareSystem)}
 * .
 */
@Test
public void testUpdateSoftwareSystem() {
    SoftwareSystemManager softwareSystemManger = SoftwareSystemManager.getInstance();
    PowerMockito.mockStatic(EMFSharedResources.class);
    EMFSharedResources emfSharedResourceMock = mock(EMFSharedResources.class);
    when(EMFSharedResources.getInstance()).thenReturn(emfSharedResourceMock).thenReturn(emfSharedResourceMock);
    Resource softwareSysResource = mock(Resource.class);
    when(emfSharedResourceMock.getSoftwareDeploymentResource()).thenReturn(softwareSysResource);
    EList<EObject> existedSystems = new BasicEList<EObject>();
    when(softwareSysResource.getContents()).thenReturn(existedSystems);
    when(emfSharedResourceMock.saveResource(softwareSysResource)).thenReturn(Boolean.TRUE);
    try {
        softwareSystemManger.updateSoftwareSystem(null);
        Connection mockConnection = mock(Connection.class);
        DatabaseMetaData mockDBMetaData = mock(DatabaseMetaData.class);
        // Mocking Static Class
        PowerMockito.mockStatic(DriverManager.class);
        // $NON-NLS-1$
        String sql = "jdbc:mysql://localhost:3306/tbi";
        when(DriverManager.getConnection(sql)).thenReturn(mockConnection);
        when(mockConnection.getMetaData()).thenReturn(mockDBMetaData);
        // Mock database product name.
        // $NON-NLS-1$
        String mysqlDB = "MYSQL";
        when(mockDBMetaData.getDatabaseProductName()).thenReturn(mysqlDB);
        // Mock database product version
        // $NON-NLS-1$
        String version = "5.5";
        when(mockDBMetaData.getDatabaseProductVersion()).thenReturn(version);
        when(mockDBMetaData.getDatabaseMinorVersion()).thenReturn(5);
        when(mockDBMetaData.getDatabaseMajorVersion()).thenReturn(5);
        DatabaseConnection dbConn = ConnectionPackage.eINSTANCE.getConnectionFactory().createDatabaseConnection();
        TaggedValueHelper.setTaggedValue(dbConn, TaggedValueHelper.DB_PRODUCT_NAME, mysqlDB);
        TaggedValueHelper.setTaggedValue(dbConn, TaggedValueHelper.DB_PRODUCT_VERSION, version);
        PowerMockito.mockStatic(ConvertionHelper.class);
        // $NON-NLS-1$
        when(ConvertionHelper.convert(dbConn, false, "")).thenReturn(null);
        PowerMockito.mockStatic(MetadataFillFactory.class);
        MetadataFillFactory metadataFillFactory = mock(MetadataFillFactory.class);
        when(MetadataFillFactory.getDBInstance()).thenReturn(metadataFillFactory);
        TypedReturnCode<java.sql.Connection> returnCode = new TypedReturnCode<Connection>(Boolean.TRUE);
        returnCode.setObject(mockConnection);
        when(metadataFillFactory.createConnection(null)).thenReturn(returnCode);
        softwareSystemManger.updateSoftwareSystem(dbConn);
        Assert.assertTrue(existedSystems.size() > 0);
        SoftwareSystem newSoftwareSys = (SoftwareSystem) existedSystems.get(0);
        Assert.assertEquals(mysqlDB, newSoftwareSys.getSubtype());
        Assert.assertEquals(version, newSoftwareSys.getVersion());
    } catch (SQLException e) {
        Assert.fail(e.getMessage());
    }
}
Also used : SQLException(java.sql.SQLException) BasicEList(org.eclipse.emf.common.util.BasicEList) Resource(org.eclipse.emf.ecore.resource.Resource) Connection(java.sql.Connection) DatabaseConnection(org.talend.core.model.metadata.builder.connection.DatabaseConnection) DatabaseMetaData(java.sql.DatabaseMetaData) EMFSharedResources(org.talend.dq.writer.EMFSharedResources) EObject(org.eclipse.emf.ecore.EObject) TypedReturnCode(org.talend.utils.sugars.TypedReturnCode) TdSoftwareSystem(org.talend.cwm.softwaredeployment.TdSoftwareSystem) SoftwareSystem(orgomg.cwm.foundation.softwaredeployment.SoftwareSystem) DatabaseConnection(org.talend.core.model.metadata.builder.connection.DatabaseConnection) MetadataFillFactory(org.talend.metadata.managment.model.MetadataFillFactory) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 3 with TypedReturnCode

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

the class FileSystemImportWriterTest method testMergePattern.

/**
 * Test method for
 * {@link org.talend.dataprofiler.core.ui.imex.model.FileSystemImportWriter#mergePattern(org.talend.dataprofiler.core.ui.imex.model.ItemRecord, org.talend.dataquality.domain.pattern.Pattern)}
 * .
 *
 * @throws MalformedURLException
 */
@Test
public void testMergePattern() throws MalformedURLException {
    // import object
    ItemRecord importItem = mock(ItemRecord.class);
    Pattern importPattern = mock(Pattern.class);
    when(importItem.getElement()).thenReturn(importPattern);
    // old object
    TDQPatternItem oldPatternItem = mock(TDQPatternItem.class);
    Pattern oldPattern = mock(Pattern.class);
    when(oldPatternItem.getPattern()).thenReturn(oldPattern);
    // for imported pattern's expression
    InternalEObject eo = mock(InternalEObject.class);
    EList<PatternComponent> importComponents = new EObjectContainmentEList<PatternComponent>(PatternComponent.class, eo, PatternPackage.PATTERN__COMPONENTS);
    RegularExpression re = PatternFactory.eINSTANCE.createRegularExpression();
    TdExpression td = RelationalFactory.eINSTANCE.createTdExpression();
    // $NON-NLS-1$
    td.setBody("sql body");
    // $NON-NLS-1$
    td.setLanguage("SQL");
    // $NON-NLS-1$
    td.setModificationDate("20130101");
    re.setExpression(td);
    importComponents.add(re);
    RegularExpression re3 = PatternFactory.eINSTANCE.createRegularExpression();
    TdExpression td3 = RelationalFactory.eINSTANCE.createTdExpression();
    // $NON-NLS-1$
    td3.setBody("imported body");
    // $NON-NLS-1$
    td3.setLanguage("MYSQL");
    // $NON-NLS-1$
    td3.setModificationDate("20130101");
    re3.setExpression(td3);
    importComponents.add(re3);
    RegularExpression re4 = PatternFactory.eINSTANCE.createRegularExpression();
    TdExpression td4 = RelationalFactory.eINSTANCE.createTdExpression();
    // $NON-NLS-1$
    td4.setBody("imported 4 body");
    // $NON-NLS-1$
    td4.setLanguage("Default");
    td4.setModificationDate(null);
    re4.setExpression(td4);
    importComponents.add(re4);
    when(importPattern.getComponents()).thenReturn(importComponents);
    // for imported pattern's supplierDependencies
    Analysis analysis = mock(Analysis.class);
    Dependency dependency = mock(Dependency.class);
    when(dependency.getKind()).thenReturn(DependenciesHandler.USAGE);
    EList<ModelElement> analysisList = new BasicEList<ModelElement>();
    analysisList.add(analysis);
    when(dependency.getClient()).thenReturn(analysisList);
    when(analysis.eIsProxy()).thenReturn(false);
    // $NON-NLS-1$
    File file = new File("C://Users//msjian//Desktop//myusetest//AA//TDQ_Data Profiling//Analyses//k_0.1.ana");
    org.eclipse.emf.common.util.URI uri = URI.createFileURI(file.toURL().getPath().substring(1));
    Resource resource = mock(Resource.class);
    when(analysis.eResource()).thenReturn(resource);
    when(resource.getURI()).thenReturn(uri);
    PowerMockito.mockStatic(ResourceManager.class);
    IProject pro = mock(IProject.class);
    when(ResourceManager.getRootProject()).thenReturn(pro);
    // $NON-NLS-1$
    when(pro.getLocation()).thenReturn(new Path("D:\\worspace\\workspace_TDQEE_5.3\\A"));
    EList<ModelElement> patternlist = mock(EObjectContainmentEList.class);
    patternlist.add(importPattern);
    when(dependency.getSupplier()).thenReturn(patternlist);
    EList<Dependency> supplierDependencies_old = new BasicEList<Dependency>();
    when(oldPattern.getSupplierDependency()).thenReturn(supplierDependencies_old);
    Assert.assertEquals(0, oldPattern.getSupplierDependency().size());
    EList<Dependency> supplierDependencies_import = new BasicEList<Dependency>();
    supplierDependencies_import.add(dependency);
    when(importPattern.getSupplierDependency()).thenReturn(supplierDependencies_import);
    Assert.assertEquals(1, importPattern.getSupplierDependency().size());
    PowerMockito.mockStatic(DependenciesHandler.class);
    DependenciesHandler instance = mock(DependenciesHandler.class);
    when(DependenciesHandler.getInstance()).thenReturn(instance);
    TypedReturnCode<Dependency> rc = new TypedReturnCode<Dependency>();
    rc.setObject(dependency);
    when(instance.setUsageDependencyOn(analysis, oldPattern)).thenReturn(rc);
    when(oldPattern.getSupplierDependency()).thenReturn(supplierDependencies_import);
    // for system pattern's expression
    EList<PatternComponent> components = new EObjectContainmentEList<PatternComponent>(PatternComponent.class, eo, PatternPackage.PATTERN__COMPONENTS);
    RegularExpression re2 = PatternFactory.eINSTANCE.createRegularExpression();
    TdExpression td2 = RelationalFactory.eINSTANCE.createTdExpression();
    // $NON-NLS-1$
    td2.setBody("system 2 body");
    // $NON-NLS-1$
    td2.setLanguage("MYSQL");
    // $NON-NLS-1$
    td2.setModificationDate("20120101");
    re2.setExpression(td2);
    components.add(re2);
    // for re5: should be replace by re4
    RegularExpression re5 = PatternFactory.eINSTANCE.createRegularExpression();
    TdExpression td5 = RelationalFactory.eINSTANCE.createTdExpression();
    // $NON-NLS-1$
    td5.setBody("system 5 body");
    // $NON-NLS-1$
    td5.setLanguage("Default");
    td5.setModificationDate(null);
    re5.setExpression(td5);
    components.add(re5);
    when(oldPattern.getComponents()).thenReturn(components);
    ElementWriterFactory ewFactory = mock(ElementWriterFactory.class);
    PatternWriter pw = mock(PatternWriter.class);
    when(pw.save(oldPatternItem, true)).thenReturn(null);
    // $NON-NLS-1$
    stub(method(ElementWriterFactory.class, "getInstance")).toReturn(ewFactory);
    when(ewFactory.createPatternWriter()).thenReturn(pw);
    writer.mergePattern(importItem, oldPatternItem);
    for (PatternComponent component : components) {
        TdExpression ex = ((RegularExpression) component).getExpression();
        if (ex.getLanguage().equals("SQL")) {
            // $NON-NLS-1$
            // $NON-NLS-1$
            Assert.assertEquals("sql body", ex.getBody());
        } else if (ex.getLanguage().equals("MYSQL")) {
            // $NON-NLS-1$
            // $NON-NLS-1$
            Assert.assertEquals("imported body", ex.getBody());
        } else if (ex.getLanguage().equals("Default")) {
            // $NON-NLS-1$
            // $NON-NLS-1$
            Assert.assertEquals("imported 4 body", ex.getBody());
        }
    }
    Assert.assertNotNull(oldPattern.getSupplierDependency());
    Assert.assertEquals(1, oldPattern.getSupplierDependency().size());
}
Also used : URI(org.eclipse.emf.common.util.URI) PatternWriter(org.talend.dq.writer.impl.PatternWriter) TDQPatternItem(org.talend.dataquality.properties.TDQPatternItem) ElementWriterFactory(org.talend.dq.writer.impl.ElementWriterFactory) ModelElement(orgomg.cwm.objectmodel.core.ModelElement) EObjectContainmentEList(org.eclipse.emf.ecore.util.EObjectContainmentEList) DependenciesHandler(org.talend.cwm.dependencies.DependenciesHandler) Path(org.eclipse.core.runtime.Path) Pattern(org.talend.dataquality.domain.pattern.Pattern) RegularExpression(org.talend.dataquality.domain.pattern.RegularExpression) TdExpression(org.talend.cwm.relational.TdExpression) BasicEList(org.eclipse.emf.common.util.BasicEList) Resource(org.eclipse.emf.ecore.resource.Resource) Dependency(orgomg.cwm.objectmodel.core.Dependency) IProject(org.eclipse.core.resources.IProject) Analysis(org.talend.dataquality.analysis.Analysis) TypedReturnCode(org.talend.utils.sugars.TypedReturnCode) PatternComponent(org.talend.dataquality.domain.pattern.PatternComponent) File(java.io.File) InternalEObject(org.eclipse.emf.ecore.InternalEObject) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 4 with TypedReturnCode

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

the class AnalysisColumnTreeViewer method sortIndicatorUnits.

/**
 * DOC yyi Sort indicators.
 *
 * @param units
 * @param targetUnit
 * @param step
 * @return
 */
private TypedReturnCode<IndicatorUnit[]> sortIndicatorUnits(IndicatorUnit[] units, IndicatorUnit targetUnit, int step, List<IndicatorUnit> indicatorUnitList) {
    TypedReturnCode<IndicatorUnit[]> code = new TypedReturnCode<IndicatorUnit[]>();
    int index = -1;
    for (int i = 0; i < units.length; i++) {
        if (targetUnit.getIndicator() == units[i].getIndicator()) {
            index = i;
            break;
        } else if (null != units[i].getChildren()) {
            TypedReturnCode<IndicatorUnit[]> code2 = sortIndicatorUnits(units[i].getChildren(), targetUnit, step, indicatorUnitList);
            if (null != code2.getObject()) {
                units[i].setChildren(code2.getObject());
                code.setOk(true);
                break;
            }
        }
    }
    int changeIndex = index + step;
    if (-1 != index && changeIndex > -1 && changeIndex < units.length) {
        IndicatorUnit tmpUnit = units[changeIndex];
        // when the changed one is the selected one too, get next one
        while (indicatorUnitList.contains(tmpUnit)) {
            tmpUnit = units[++changeIndex];
        }
        units[changeIndex] = units[index];
        units[index] = tmpUnit;
        // after the data changed successfully remove it from the selected list
        indicatorUnitList.remove(targetUnit);
        // $NON-NLS-1$
        code.setReturnCode("", true, units);
    }
    return code;
}
Also used : TypedReturnCode(org.talend.utils.sugars.TypedReturnCode) IndicatorUnit(org.talend.dataprofiler.core.ui.editor.preview.IndicatorUnit)

Example 5 with TypedReturnCode

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

the class ExecuteMatchRuleHandler method execute.

public TypedReturnCode<MatchGroupResultConsumer> execute(Map<MetadataColumn, String> columnMap, RecordMatchingIndicator recordMatchingIndicator, List<Object[]> matchRows, BlockKeyIndicator blockKeyIndicator, MatchGroupResultConsumer matchResultConsumer) {
    TypedReturnCode<MatchGroupResultConsumer> returnCode = new TypedReturnCode<MatchGroupResultConsumer>(false);
    returnCode.setObject(matchResultConsumer);
    // By default for analysis, the applied blocking key will be the key
    // from key generation definition. This
    // will be refined when there is a need to define the applied blocking
    // key manually by user later.
    AnalysisRecordGroupingUtils.createAppliedBlockKeyByGenKey(recordMatchingIndicator);
    ReturnCode computeMatchGroupReturnCode = null;
    // Blocking key specified.
    computeMatchGroupReturnCode = computeMatchGroupWithBlockKey(recordMatchingIndicator, blockKeyIndicator, columnMap, matchResultConsumer, matchRows);
    returnCode.setOk(computeMatchGroupReturnCode.isOk());
    returnCode.setMessage(computeMatchGroupReturnCode.getMessage());
    return returnCode;
}
Also used : ReturnCode(org.talend.utils.sugars.ReturnCode) TypedReturnCode(org.talend.utils.sugars.TypedReturnCode) MatchGroupResultConsumer(org.talend.dataquality.record.linkage.grouping.MatchGroupResultConsumer) TypedReturnCode(org.talend.utils.sugars.TypedReturnCode)

Aggregations

TypedReturnCode (org.talend.utils.sugars.TypedReturnCode)34 ReturnCode (org.talend.utils.sugars.ReturnCode)19 Connection (org.talend.core.model.metadata.builder.connection.Connection)10 SQLException (java.sql.SQLException)7 Indicator (org.talend.dataquality.indicators.Indicator)7 ModelElement (orgomg.cwm.objectmodel.core.ModelElement)7 Connection (java.sql.Connection)6 ArrayList (java.util.ArrayList)5 IMetadataConnection (org.talend.core.model.metadata.IMetadataConnection)5 Dependency (orgomg.cwm.objectmodel.core.Dependency)5 File (java.io.File)4 DatabaseMetaData (java.sql.DatabaseMetaData)4 EObject (org.eclipse.emf.ecore.EObject)4 MetadataFillFactory (org.talend.metadata.managment.model.MetadataFillFactory)4 DatabaseConnection (org.talend.core.model.metadata.builder.connection.DatabaseConnection)3 TdColumn (org.talend.cwm.relational.TdColumn)3 Expression (orgomg.cwm.objectmodel.core.Expression)3 CSVReader (com.talend.csv.CSVReader)2 IOException (java.io.IOException)2 Date (java.util.Date)2