Search in sources :

Example 26 with ReturnCode

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

the class FileSystemImportWriterTest method testMergeSystemIndicator.

/**
 * Test method for
 * {@link org.talend.dataprofiler.core.ui.imex.model.FileSystemImportWriter#mergeSystemIndicator(org.talend.dataprofiler.core.ui.imex.model.ItemRecord, org.talend.dataquality.indicators.definition.IndicatorDefinition)}
 * .
 */
@Test
public void testMergeSystemIndicator() {
    ItemRecord mockItem = mock(ItemRecord.class);
    TDQIndicatorDefinitionItem siItem = PropertiesFactory.eINSTANCE.createTDQIndicatorDefinitionItem();
    Property siProp = org.talend.core.model.properties.PropertiesFactory.eINSTANCE.createProperty();
    IndicatorDefinition SIdef = DefinitionFactory.eINSTANCE.createIndicatorDefinition();
    siItem.setIndicatorDefinition(SIdef);
    siItem.setProperty(siProp);
    IndicatorDefinition importedDef = DefinitionFactory.eINSTANCE.createIndicatorDefinition();
    // make mockItem has: one new template, one modified newer template, one modified older template.
    // $NON-NLS-1$ //$NON-NLS-2$
    TdExpression e0 = BooleanExpressionHelper.createTdExpression("new", "new body");
    // $NON-NLS-1$
    e0.setModificationDate("20130101");
    // $NON-NLS-1$ //$NON-NLS-2$
    TdExpression e1 = BooleanExpressionHelper.createTdExpression("tem_1", "modified newer body");
    // $NON-NLS-1$
    e1.setModificationDate("20130101");
    // $NON-NLS-1$ //$NON-NLS-2$
    TdExpression e2 = BooleanExpressionHelper.createTdExpression("tem_2", "modified older body");
    // $NON-NLS-1$
    e2.setModificationDate("20110101");
    importedDef.getSqlGenericExpression().add(e0);
    importedDef.getSqlGenericExpression().add(e1);
    importedDef.getSqlGenericExpression().add(e2);
    when(mockItem.getElement()).thenReturn(importedDef);
    // $NON-NLS-1$ //$NON-NLS-2$
    TdExpression e3 = BooleanExpressionHelper.createTdExpression("tem_1", "should be replaced");
    // $NON-NLS-1$
    e3.setModificationDate("20120101");
    // $NON-NLS-1$ //$NON-NLS-2$
    TdExpression e4 = BooleanExpressionHelper.createTdExpression("tem_2", "should keep this");
    // $NON-NLS-1$
    e4.setModificationDate("20120101");
    SIdef.getSqlGenericExpression().add(e3);
    SIdef.getSqlGenericExpression().add(e4);
    ReturnCode rc = mock(ReturnCode.class);
    when(rc.isOk()).thenReturn(true);
    ElementWriterFactory ewFactory = mock(ElementWriterFactory.class);
    IndicatorDefinitionWriter indWriter = mock(IndicatorDefinitionWriter.class);
    when(indWriter.save(siItem, false)).thenReturn(rc);
    // $NON-NLS-1$
    stub(method(ElementWriterFactory.class, "getInstance")).toReturn(ewFactory);
    when(ewFactory.createIndicatorDefinitionWriter()).thenReturn(indWriter);
    // before merge
    Assert.assertEquals(SIdef.getSqlGenericExpression().size(), 2);
    writer.mergeSystemIndicator(mockItem, siItem);
    // after merge
    Assert.assertEquals(SIdef.getSqlGenericExpression().size(), 3);
    for (TdExpression ex : SIdef.getSqlGenericExpression()) {
        if (ex.getLanguage().equals("new")) {
            // $NON-NLS-1$
            // $NON-NLS-1$
            Assert.assertEquals("new body", ex.getBody());
        } else if (ex.getLanguage().equals("tem_1")) {
            // $NON-NLS-1$
            // $NON-NLS-1$
            Assert.assertEquals("modified newer body", ex.getBody());
        } else if (ex.getLanguage().equals("tem_2")) {
            // $NON-NLS-1$
            // $NON-NLS-1$
            Assert.assertEquals("should keep this", ex.getBody());
        }
    }
// other type?not SI
}
Also used : TDQIndicatorDefinitionItem(org.talend.dataquality.properties.TDQIndicatorDefinitionItem) TypedReturnCode(org.talend.utils.sugars.TypedReturnCode) ReturnCode(org.talend.utils.sugars.ReturnCode) TdExpression(org.talend.cwm.relational.TdExpression) IndicatorDefinitionWriter(org.talend.dq.writer.impl.IndicatorDefinitionWriter) Property(org.talend.core.model.properties.Property) IndicatorDefinition(org.talend.dataquality.indicators.definition.IndicatorDefinition) ElementWriterFactory(org.talend.dq.writer.impl.ElementWriterFactory) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 27 with ReturnCode

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

the class DQRuleMasterDetailsPage method saveDQRule.

/**
 * DOC xqliu Comment method "saveDQRule".
 *
 * @return
 */
private boolean saveDQRule() {
    boolean ret = false;
    this.tempJoinElements = cleanJoins(tempJoinElements);
    if (checkValus()) {
        TaggedValueHelper.setValidStatus(true, getCurrentModelElement());
        getCurrentModelElement().setCriticalityLevel(Integer.valueOf(getCriticalityLevelText().getText()));
        getCurrentModelElement().setWhereExpression(whereText.getText());
        getCurrentModelElement().getJoins().clear();
        getCurrentModelElement().getJoins().addAll(this.tempJoinElements);
        TDQBusinessRuleItem whereRuleItem = (TDQBusinessRuleItem) getCurrentRepNode().getObject().getProperty().getItem();
        // MOD yyi 2012-02-08 TDQ-4621:Explicitly set true for updating dependencies.
        ReturnCode rc = ElementWriterFactory.getInstance().createdRuleWriter().save(whereRuleItem, true);
        ret = rc.isOk();
        this.joinConditionTableViewer.updateModelViewer();
    }
    return ret;
}
Also used : ReturnCode(org.talend.utils.sugars.ReturnCode) TDQBusinessRuleItem(org.talend.dataquality.properties.TDQBusinessRuleItem)

Example 28 with ReturnCode

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

the class ParserRuleMasterDetailsPage method saveParserRule.

private boolean saveParserRule() {
    TaggedValueHelper.setValidStatus(true, getCurrentModelElement());
    getCurrentModelElement().getExpression().addAll(parserRuleTableViewer.getParserRuleTdExpressions());
    TDQBusinessRuleItem parserRuleItem = (TDQBusinessRuleItem) getCurrentRepNode().getObject().getProperty().getItem();
    ReturnCode rc = ElementWriterFactory.getInstance().createdRuleWriter().save(parserRuleItem, Boolean.FALSE);
    if (!rc.isOk()) {
        return false;
    }
    return true;
}
Also used : ReturnCode(org.talend.utils.sugars.ReturnCode) TDQBusinessRuleItem(org.talend.dataquality.properties.TDQBusinessRuleItem)

Example 29 with ReturnCode

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

the class IndicatorDefinitionMaterPage method checkCorrectForCharacterMapping.

/**
 * DOC talend Comment method "checkDuplicateLanguage".
 *
 * @param rc
 * @return
 */
private ReturnCode checkCorrectForCharacterMapping() {
    ReturnCode rc = new ReturnCode();
    Map<String, Integer> languageCountMap = new HashMap<String, Integer>();
    Iterator<CharactersMapping> charMappIterator = charactersMappingMapTemp.values().iterator();
    while (charMappIterator.hasNext()) {
        CharactersMapping cm = charMappIterator.next();
        String language = cm.getLanguage();
        Integer languageCount = languageCountMap.get(language);
        if (languageCount == null) {
            languageCount = 1;
        } else {
            languageCount++;
        }
        languageCountMap.put(language, languageCount);
    }
    Iterator<String> iterator = languageCountMap.keySet().iterator();
    while (iterator.hasNext()) {
        String key = iterator.next();
        Integer integer = languageCountMap.get(key);
        if (integer > 1) {
            rc.setOk(false);
            // $NON-NLS-1$
            rc.setMessage(DefaultMessagesImpl.getString("IndicatorDefinitionMaterPage.isRepeatedCharMapp", key));
            return rc;
        }
    }
    return rc;
}
Also used : CharactersMapping(org.talend.dataquality.indicators.definition.CharactersMapping) ReturnCode(org.talend.utils.sugars.ReturnCode) HashMap(java.util.HashMap)

Example 30 with ReturnCode

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

the class IndicatorDefinitionMaterPage method checkCorrectForExpression.

/**
 * DOC talend Comment method "checkDuplicateLanguage".
 *
 * @param rc
 * @return
 */
private ReturnCode checkCorrectForExpression() {
    ReturnCode rc = new ReturnCode();
    Map<String, Integer> languageVersionCountMap = new HashMap<String, Integer>();
    Iterator<CCombo> it = tempExpressionMap.keySet().iterator();
    while (it.hasNext()) {
        CCombo cb = it.next();
        TdExpression expression = tempExpressionMap.get(cb);
        String language = expression.getLanguage();
        String version = expression.getVersion();
        if (!language.equals(PatternLanguageType.JAVA.getLiteral())) {
            String body = expression.getBody();
            if (null == body || body.length() + 1 < UDIHelper.MIN_EXPRESSION_LENGTH) {
                rc.setOk(false);
                // $NON-NLS-1$
                rc.setMessage(DefaultMessagesImpl.getString("IndicatorDefinition.validateTooShort"));
                return rc;
            }
        }
        if (version != null && !PluginConstant.EMPTY_STRING.equals(version)) {
            // $NON-NLS-1$
            language = language + " V" + expression.getVersion();
        }
        Integer integer = languageVersionCountMap.get(language);
        if (integer == null) {
            languageVersionCountMap.put(language, 1);
        } else {
            languageVersionCountMap.put(language, integer + 1);
        }
    }
    Iterator<String> iterator = languageVersionCountMap.keySet().iterator();
    while (iterator.hasNext()) {
        String key = iterator.next();
        Integer integer = languageVersionCountMap.get(key);
        if (integer > 1) {
            rc.setOk(false);
            // $NON-NLS-1$
            rc.setMessage(DefaultMessagesImpl.getString("IndicatorDefinitionMaterPage.isRepeatedExp", key));
            return rc;
        }
    }
    return rc;
}
Also used : ReturnCode(org.talend.utils.sugars.ReturnCode) CCombo(org.eclipse.swt.custom.CCombo) HashMap(java.util.HashMap) TdExpression(org.talend.cwm.relational.TdExpression)

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