Search in sources :

Example 1 with IndicatorDefinitionParameter

use of org.talend.dataquality.indicators.definition.IndicatorDefinitionParameter in project tdq-studio-se by Talend.

the class ImportFactoryTest method testImportIndicatorToStucture.

/**
 * Test method for
 * {@link org.talend.dataprofiler.core.pattern.ImportFactory#importIndicatorToStucture(org.talend.dataprofiler.core.ui.action.actions.ImportObject, org.eclipse.core.resources.IFolder, boolean, boolean, java.lang.String)}
 * normal condition: the import file's extension is csv.
 */
@Test
public void testImportIndicatorToStucture() throws Exception {
    // $NON-NLS-1$
    File importFile = createImportFile(UDI_NAME, StringUtilities.getRandomString(8) + ".csv");
    assertTrue(importFile.exists());
    assertTrue(importFile.isFile());
    assertTrue(importFile.length() > 0);
    List<File> pJarfiles = new ArrayList<File>();
    ImportObject importObject = ImportObject.createImportObject(importFile, pJarfiles);
    IFolder udiFolder = ResourceManager.getUDIFolder();
    boolean skip = false;
    boolean rename = true;
    List<ReturnCode> rc = ImportFactory.importIndicatorToStucture(importObject, udiFolder, skip, rename, UDI_NAME);
    assertTrue(rc.size() == 1);
    assertTrue(rc.get(0).isOk());
    IndicatorDefinition indicatorDefinition = null;
    RootContainer<String, IRepositoryViewObject> tdqViewObjects = ProxyRepositoryFactory.getInstance().getTdqRepositoryViewObjects(ERepositoryObjectType.TDQ_USERDEFINE_INDICATORS, ERepositoryObjectType.getFolderName(ERepositoryObjectType.TDQ_USERDEFINE_INDICATORS));
    for (IRepositoryViewObject viewObject : tdqViewObjects.getMembers()) {
        IndicatorDefinition indDefTemp = ((TDQIndicatorDefinitionItem) viewObject.getProperty().getItem()).getIndicatorDefinition();
        if (UDI_NAME.equals(indDefTemp.getName())) {
            indicatorDefinition = indDefTemp;
            break;
        }
    }
    assertNotNull(indicatorDefinition);
    if (indicatorDefinition != null) {
        EList<IndicatorDefinitionParameter> indDefParas = indicatorDefinition.getIndicatorDefinitionParameter();
        assertFalse(indDefParas.isEmpty());
        // String paraString = StringUtils.replace(IND_DEF_PARA_STRING, "\"\"", "\""); //$NON-NLS-1$ //$NON-NLS-2$
        for (IndicatorDefinitionParameter indDefPara : indDefParas) {
            String temp = indDefPara.getKey() + UDIHelper.PARA_SEPARATE_1 + indDefPara.getValue() + UDIHelper.PARA_SEPARATE_2;
            assertTrue(IND_DEF_PARA_STRING.indexOf(temp) > -1);
        }
    }
    importFile.delete();
}
Also used : ReturnCode(org.talend.utils.sugars.ReturnCode) TDQIndicatorDefinitionItem(org.talend.dataquality.properties.TDQIndicatorDefinitionItem) ArrayList(java.util.ArrayList) IndicatorDefinition(org.talend.dataquality.indicators.definition.IndicatorDefinition) ImportObject(org.talend.dataprofiler.core.ui.action.actions.ImportObject) IRepositoryViewObject(org.talend.core.model.repository.IRepositoryViewObject) IndicatorDefinitionParameter(org.talend.dataquality.indicators.definition.IndicatorDefinitionParameter) IFile(org.eclipse.core.resources.IFile) File(java.io.File) IFolder(org.eclipse.core.resources.IFolder) Test(org.junit.Test)

Example 2 with IndicatorDefinitionParameter

use of org.talend.dataquality.indicators.definition.IndicatorDefinitionParameter in project tdq-studio-se by Talend.

the class ImportFactory method createAndStoreUDI.

/**
 * DOC xqliu Comment method "createAndStoreUDI".
 *
 * @param parameters
 * @param selectionFolder
 */
private static TypedReturnCode<Object> createAndStoreUDI(UDIParameters parameters, IFolder selectionFolder) {
    UDIndicatorDefinition indDef = UDIHelper.createUDI(parameters.name, parameters.auther, parameters.description, parameters.purpose, parameters.status, parameters.category, parameters.javaClassName, parameters.javaJarPath);
    for (String key : parameters.regex.keySet()) {
        TdExpression expression = BooleanExpressionHelper.createTdExpression(key, parameters.regex.get(key));
        indDef.getSqlGenericExpression().add(expression);
    }
    boolean validStatus = UDIHelper.isUDIValid(indDef);
    TaggedValueHelper.setValidStatus(validStatus, indDef);
    Map<String, String> paraMap = parameters.getParaMap();
    if (!paraMap.isEmpty()) {
        for (String key : paraMap.keySet()) {
            String value = paraMap.get(key);
            IndicatorDefinitionParameter idPara = DefinitionFactory.eINSTANCE.createIndicatorDefinitionParameter();
            idPara.setKey(key);
            idPara.setValue(value);
            indDef.getIndicatorDefinitionParameter().add(idPara);
        }
    }
    try {
        // $NON-NLS-1$
        String[] folderNames = parameters.relativePath.split("/");
        for (String folderName : folderNames) {
            IFolder folder = selectionFolder.getFolder(folderName);
            if (!folder.exists()) {
                folder.create(false, true, null);
            }
            selectionFolder = folder;
        }
    } catch (CoreException e) {
        log.error(e, e);
    }
    indDef = UDIUtils.createDefaultDrillDownList(indDef);
    return ElementWriterFactory.getInstance().createIndicatorDefinitionWriter().create(indDef, selectionFolder);
}
Also used : CoreException(org.eclipse.core.runtime.CoreException) UDIndicatorDefinition(org.talend.dataquality.indicators.definition.userdefine.UDIndicatorDefinition) TdExpression(org.talend.cwm.relational.TdExpression) IndicatorDefinitionParameter(org.talend.dataquality.indicators.definition.IndicatorDefinitionParameter) IFolder(org.eclipse.core.resources.IFolder)

Example 3 with IndicatorDefinitionParameter

use of org.talend.dataquality.indicators.definition.IndicatorDefinitionParameter in project tdq-studio-se by Talend.

the class ExportFactoryTest method createExportIndicaorDefinition.

/**
 * create the IndicaorDefinition for test.
 *
 * @return
 */
private IndicatorDefinition createExportIndicaorDefinition(IFolder folder, String udiName) {
    IndicatorDefinition indDef = DefinitionFactory.eINSTANCE.createIndicatorDefinition();
    indDef.setName(udiName);
    Map<String, String> indDefParaMap = getIndDefParaMap();
    for (String key : indDefParaMap.keySet()) {
        IndicatorDefinitionParameter indDefPara = DefinitionFactory.eINSTANCE.createIndicatorDefinitionParameter();
        indDefPara.setKey(key);
        indDefPara.setValue(indDefParaMap.get(key));
        indDef.getIndicatorDefinitionParameter().add(indDefPara);
    }
    UDIHelper.setUDICategory(indDef, DefinitionHandler.getInstance().getUserDefinedCountIndicatorCategory());
    ElementWriterFactory.getInstance().createIndicatorDefinitionWriter().create(indDef, folder);
    DefinitionHandler.getInstance().reloadIndicatorsDefinitions();
    return indDef;
}
Also used : IndicatorDefinitionParameter(org.talend.dataquality.indicators.definition.IndicatorDefinitionParameter) IndicatorDefinition(org.talend.dataquality.indicators.definition.IndicatorDefinition)

Example 4 with IndicatorDefinitionParameter

use of org.talend.dataquality.indicators.definition.IndicatorDefinitionParameter in project tdq-studio-se by Talend.

the class ExportFactoryTest method testExportFolderIFolderIndicatorDefinitionArray.

/**
 * Test method for
 * {@link org.talend.dataprofiler.core.pattern.ExportFactory#export(java.io.File, org.eclipse.core.resources.IFolder, org.talend.dataquality.indicators.definition.IndicatorDefinition[])}
 * normal condition: exportFile is a folder(not a file).
 */
@Test
public void testExportFolderIFolderIndicatorDefinitionArray() throws Exception {
    String udiName = getRandomUdiName();
    // $NON-NLS-1$
    File exportFolder = new File(System.getProperty("java.io.tmpdir") + File.separator + StringUtilities.getRandomString(8));
    if (!exportFolder.exists()) {
        exportFolder.mkdirs();
    }
    IFolder udiFolder = ResourceManager.getUDIFolder();
    IndicatorDefinition indDef = createExportIndicaorDefinition(udiFolder, udiName);
    ExportFactory.export(exportFolder, udiFolder, indDef);
    // $NON-NLS-1$
    File exportFile = new File(exportFolder.getAbsolutePath() + File.separator + udiName + ".csv");
    assertTrue(exportFile.exists());
    assertTrue(exportFile.isFile());
    assertTrue(exportFile.length() > 0);
    CSVReader reader = FileUtils.createCSVReader(exportFile, FileUtils.TEXT_QUAL, FileUtils.TEXT_QUAL);
    reader.setSkipEmptyRecords(true);
    reader.readHeaders();
    boolean haveRecord = false;
    while (reader.readNext()) {
        haveRecord = true;
        String name = reader.get(PatternToExcelEnum.Label.getLiteral());
        assertEquals(name, indDef.getName());
        String paraString = reader.get(PatternToExcelEnum.IndicatorDefinitionParameter.getLiteral());
        EList<IndicatorDefinitionParameter> indDefParas = indDef.getIndicatorDefinitionParameter();
        for (IndicatorDefinitionParameter indDefPara : indDefParas) {
            String temp = indDefPara.getKey() + UDIHelper.PARA_SEPARATE_1 + indDefPara.getValue() + UDIHelper.PARA_SEPARATE_2;
            assertTrue(paraString.indexOf(temp) > -1);
        }
    }
    reader.close();
    assertTrue(haveRecord);
}
Also used : CSVReader(com.talend.csv.CSVReader) IndicatorDefinitionParameter(org.talend.dataquality.indicators.definition.IndicatorDefinitionParameter) File(java.io.File) IndicatorDefinition(org.talend.dataquality.indicators.definition.IndicatorDefinition) IFolder(org.eclipse.core.resources.IFolder) Test(org.junit.Test)

Example 5 with IndicatorDefinitionParameter

use of org.talend.dataquality.indicators.definition.IndicatorDefinitionParameter in project tdq-studio-se by Talend.

the class UDIMasterPage method checkBeforeSave.

/*
     * (non-Javadoc)
     * 
     * @see org.talend.dataprofiler.core.ui.editor.indicator.IndicatorDefinitionMaterPage#checkBeforeSave()
     */
@Override
protected ReturnCode checkBeforeSave() {
    ReturnCode rc = super.checkBeforeSave();
    if (tempParameters != null) {
        // detecting the IndicatorDefinitionParameter whether include duplicate keywords
        Map<String, Integer> paraMap = new HashMap<String, Integer>();
        for (IndicatorDefinitionParameter para : tempParameters) {
            String key = para.getKey();
            Integer keyCount = paraMap.get(key);
            if (keyCount == null) {
                paraMap.put(key, Integer.valueOf(1));
            } else {
                paraMap.put(key, Integer.valueOf(keyCount.intValue() + 1));
            }
        }
        if (paraMap.size() != tempParameters.size()) {
            StringBuffer duplicateKeywords = new StringBuffer();
            for (String key : paraMap.keySet()) {
                Integer value = paraMap.get(key);
                if (value.intValue() > 1) {
                    // $NON-NLS-1$
                    duplicateKeywords.append("\n" + key);
                }
            }
            rc.setOk(false);
            rc.setMessage(DefaultMessagesImpl.getString("IndicatorDefinitionMaterPage.includeDuplicateKeywords", // $NON-NLS-1$
            duplicateKeywords.toString()));
            return rc;
        }
        // detecting the IndicatorDefinitionParameter whether include special characters
        for (IndicatorDefinitionParameter para : tempParameters) {
            String key = para.getKey();
            String value = para.getValue();
            if (!StringUtils.isBlank(key) && (key.indexOf(UDIHelper.PARA_SEPARATE_1) > -1 || key.indexOf(UDIHelper.PARA_SEPARATE_2) > -1)) {
                rc.setOk(false);
                rc.setMessage(DefaultMessagesImpl.getString("IndicatorDefinitionMaterPage.includeSpecialCharacter", // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
                "\n" + UDIHelper.PARA_SEPARATE_1 + "\n" + UDIHelper.PARA_SEPARATE_2));
                return rc;
            }
            if (!StringUtils.isBlank(value) && (value.indexOf(UDIHelper.PARA_SEPARATE_1) > -1 || value.indexOf(UDIHelper.PARA_SEPARATE_2) > -1)) {
                rc.setOk(false);
                rc.setMessage(DefaultMessagesImpl.getString("IndicatorDefinitionMaterPage.includeSpecialCharacter", // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
                "\n" + UDIHelper.PARA_SEPARATE_1 + "\n" + UDIHelper.PARA_SEPARATE_2));
                return rc;
            }
        }
    }
    // ADD klliu 2010-06-01 bug 13451: Class name of Java User Define Indicator must be validated
    if (!checkJavaDefinitionBeforeSave()) {
        ((IndicatorEditor) this.getEditor()).setSaveActionButtonState(false);
        rc.setOk(false);
        // $NON-NLS-1$
        rc.setMessage(DefaultMessagesImpl.getString("IndicatorDefinitionMaterPage.classPathError"));
        return rc;
    }
    return rc;
}
Also used : ReturnCode(org.talend.utils.sugars.ReturnCode) HashMap(java.util.HashMap) IndicatorDefinitionParameter(org.talend.dataquality.indicators.definition.IndicatorDefinitionParameter)

Aggregations

IndicatorDefinitionParameter (org.talend.dataquality.indicators.definition.IndicatorDefinitionParameter)12 IndicatorDefinition (org.talend.dataquality.indicators.definition.IndicatorDefinition)5 IFolder (org.eclipse.core.resources.IFolder)4 TdExpression (org.talend.cwm.relational.TdExpression)4 File (java.io.File)3 ArrayList (java.util.ArrayList)3 Test (org.junit.Test)3 CSVReader (com.talend.csv.CSVReader)2 HashMap (java.util.HashMap)2 IFile (org.eclipse.core.resources.IFile)2 CoreException (org.eclipse.core.runtime.CoreException)2 UDIndicatorDefinition (org.talend.dataquality.indicators.definition.userdefine.UDIndicatorDefinition)2 ReturnCode (org.talend.utils.sugars.ReturnCode)2 Expression (orgomg.cwm.objectmodel.core.Expression)2 IOException (java.io.IOException)1 URI (java.net.URI)1 ICellModifier (org.eclipse.jface.viewers.ICellModifier)1 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)1 TextCellEditor (org.eclipse.jface.viewers.TextCellEditor)1 ModifyEvent (org.eclipse.swt.events.ModifyEvent)1