Search in sources :

Example 1 with TDQIndicatorDefinitionItem

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

the class IndicatorDefinitionActionProvider method fillContextMenu.

/*
     * (non-Javadoc)
     * 
     * @see org.eclipse.ui.actions.ActionGroup#fillContextMenu(org.eclipse.jface.action.IMenuManager)
     */
@Override
public void fillContextMenu(IMenuManager menu) {
    // MOD mzhao user readonly role on svn repository mode.
    if (!isShowMenu()) {
        return;
    }
    TreeSelection currentSelection = ((TreeSelection) this.getContext().getSelection());
    List<IndicatorDefinition> list = new ArrayList<IndicatorDefinition>();
    Object[] objs = currentSelection.toArray();
    for (Object obj : objs) {
        if (obj instanceof RepositoryNode) {
            RepositoryNode node = (RepositoryNode) obj;
            if (ERepositoryObjectType.TDQ_INDICATOR_ELEMENT.equals(node.getContentType())) {
                TDQIndicatorDefinitionItem item = (TDQIndicatorDefinitionItem) node.getObject().getProperty().getItem();
                list.add(item.getIndicatorDefinition());
            }
        }
    }
    if (!list.isEmpty()) {
        menu.add(new OpenIndicatorDefinitionAction(list.toArray(new IndicatorDefinition[list.size()])));
    }
}
Also used : TDQIndicatorDefinitionItem(org.talend.dataquality.properties.TDQIndicatorDefinitionItem) TreeSelection(org.eclipse.jface.viewers.TreeSelection) ArrayList(java.util.ArrayList) RepositoryNode(org.talend.repository.model.RepositoryNode) IndicatorDefinition(org.talend.dataquality.indicators.definition.IndicatorDefinition) OpenIndicatorDefinitionAction(org.talend.dataprofiler.core.ui.action.actions.OpenIndicatorDefinitionAction)

Example 2 with TDQIndicatorDefinitionItem

use of org.talend.dataquality.properties.TDQIndicatorDefinitionItem 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 3 with TDQIndicatorDefinitionItem

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

the class UpdateModeIndicatorDefinitionForAS400Task method doExecute.

@Override
protected boolean doExecute() throws Exception {
    boolean result = true;
    try {
        IndicatorDefinition indicatorDefinition = DefinitionHandler.getInstance().getIndicatorDefinition(MODE_INDICATOR_LABEL);
        URI uriItem = indicatorDefinition.eResource().getURI();
        File fileItem = null;
        if (uriItem.isPlatform()) {
            fileItem = WorkspaceUtils.ifileToFile(getIFile(indicatorDefinition));
        } else {
            fileItem = new File(uriItem.toFileString());
        }
        File fileProp = WorkspaceUtils.ifileToFile(PropertyHelper.getPropertyFile(indicatorDefinition));
        Property property = PropertyHelper.getProperty(indicatorDefinition);
        Item item = property.getItem();
        if (indicatorDefinition != null) {
            EList<TdExpression> sqlGenericExpression = indicatorDefinition.getSqlGenericExpression();
            boolean addAS400Expression = true;
            for (TdExpression expression : sqlGenericExpression) {
                if (SupportDBUrlType.AS400DEFAULTURL.getLanguage().equals(expression.getLanguage())) {
                    addAS400Expression = false;
                    break;
                }
            }
            if (addAS400Expression) {
                TDQIndicatorDefinitionItem indDefItem = (TDQIndicatorDefinitionItem) item;
                Resource itemResource = getResource(fileItem);
                IndicatorDefinition indDef = null;
                for (EObject object : itemResource.getContents()) {
                    if (object instanceof IndicatorDefinition) {
                        indDef = (IndicatorDefinition) object;
                        IndicatorDefinitionFileHelper.addSqlExpression(indDef, SupportDBUrlType.AS400DEFAULTURL.getLanguage(), BODY_MODE_AS400);
                        String relationPropPath = ReponsitoryContextBridge.getRootProject().getFullPath().append(new Path(fileProp.getPath()).makeRelativeTo(this.getWorkspacePath())).toOSString();
                        MetadataHelper.setPropertyPath(relationPropPath, indDef);
                        indDefItem.setIndicatorDefinition(indDef);
                    }
                }
                EMFUtil.saveResource(itemResource);
                Resource propResource = getResource(fileProp);
                Property newProperty = (Property) EcoreUtil.getObjectByType(propResource.getContents(), PropertiesPackage.eINSTANCE.getProperty());
                newProperty.setAuthor(property.getAuthor());
                newProperty.setLabel(indDefItem.getIndicatorDefinition().getName());
                newProperty.setItem(item);
                item.setProperty(newProperty);
                propResource.getContents().clear();
                propResource.getContents().add(newProperty);
                propResource.getContents().add(item);
                propResource.getContents().add(item.getState());
                EMFUtil.saveResource(propResource);
            }
        }
    } catch (Exception e) {
        result = false;
        e.printStackTrace();
    }
    return result;
}
Also used : Path(org.eclipse.core.runtime.Path) TDQIndicatorDefinitionItem(org.talend.dataquality.properties.TDQIndicatorDefinitionItem) TdExpression(org.talend.cwm.relational.TdExpression) Resource(org.eclipse.emf.ecore.resource.Resource) IndicatorDefinition(org.talend.dataquality.indicators.definition.IndicatorDefinition) URI(org.eclipse.emf.common.util.URI) Item(org.talend.core.model.properties.Item) TDQIndicatorDefinitionItem(org.talend.dataquality.properties.TDQIndicatorDefinitionItem) EObject(org.eclipse.emf.ecore.EObject) IFile(org.eclipse.core.resources.IFile) File(java.io.File) Property(org.talend.core.model.properties.Property)

Example 4 with TDQIndicatorDefinitionItem

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

the class UpdateSybaseLanguageNameForMedianIndicatorTask method saveMedianIndicator.

/**
 * save the System Indicator Definition: Median.
 *
 * @param medianInd
 * @return
 */
private boolean saveMedianIndicator(IndicatorDefinition medianInd) {
    URI uriItem = medianInd.eResource().getURI();
    File fileItem = null;
    if (uriItem.isPlatform()) {
        fileItem = WorkspaceUtils.ifileToFile(ModelElementHelper.getIFile(medianInd));
    } else {
        fileItem = new File(uriItem.toFileString());
    }
    File fileProp = WorkspaceUtils.ifileToFile(PropertyHelper.getPropertyFile(medianInd));
    Property property = PropertyHelper.getProperty(medianInd);
    Item item = property.getItem();
    // save TDQIndicatorDefinitionItem
    TDQIndicatorDefinitionItem indDefItem = (TDQIndicatorDefinitionItem) item;
    indDefItem.setIndicatorDefinition(medianInd);
    Resource itemResource = getResource(fileItem);
    EMFUtil.saveResource(itemResource);
    // save the property
    Resource propResource = getResource(fileProp);
    Property newProperty = (Property) EcoreUtil.getObjectByType(propResource.getContents(), PropertiesPackage.eINSTANCE.getProperty());
    newProperty.setAuthor(property.getAuthor());
    newProperty.setLabel(indDefItem.getIndicatorDefinition().getName());
    newProperty.setItem(item);
    item.setProperty(newProperty);
    propResource.getContents().clear();
    propResource.getContents().add(newProperty);
    propResource.getContents().add(item);
    propResource.getContents().add(item.getState());
    EMFUtil.saveResource(propResource);
    return true;
}
Also used : Item(org.talend.core.model.properties.Item) TDQIndicatorDefinitionItem(org.talend.dataquality.properties.TDQIndicatorDefinitionItem) TDQIndicatorDefinitionItem(org.talend.dataquality.properties.TDQIndicatorDefinitionItem) Resource(org.eclipse.emf.ecore.resource.Resource) URI(org.eclipse.emf.common.util.URI) File(java.io.File) Property(org.talend.core.model.properties.Property)

Example 5 with TDQIndicatorDefinitionItem

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

the class InidcatorUnitTest method testGetIndicatorNameCase3.

/**
 * Test method for {@link org.talend.dataprofiler.core.ui.editor.preview.IndicatorUnit#getIndicatorName()}.
 *
 * test case 3: Get Indicator Name from TableIndicatorUnit
 */
@Test
public void testGetIndicatorNameCase3() {
    RowCountIndicator rowCountIndicator = IndicatorsFactory.eINSTANCE.createRowCountIndicator();
    IRepositoryViewObject rowCountRepositoryViewObject = null;
    try {
        List<IRepositoryViewObject> all = ProxyRepositoryFactory.getInstance().getAll(ERepositoryObjectType.SYSTEM_INDICATORS_SIMPLE_STATISTICS);
        Assert.assertEquals(10, all.size());
        rowCountRepositoryViewObject = all.get(7);
    } catch (PersistenceException e) {
        Assert.fail(e.getMessage());
    }
    Assert.assertNotNull(rowCountRepositoryViewObject);
    TDQIndicatorDefinitionItem rowCountItem = (TDQIndicatorDefinitionItem) rowCountRepositoryViewObject.getProperty().getItem();
    rowCountIndicator.setIndicatorDefinition(rowCountItem.getIndicatorDefinition());
    TableIndicatorUnit TableIndicatorUnit = new TableIndicatorUnit(IndicatorEnum.RowCountIndicatorEnum, rowCountIndicator, null);
    Assert.assertEquals(org.talend.cwm.management.i18n.Messages.getString(rowCountItem.getProperty().getLabel()), TableIndicatorUnit.getIndicatorName());
}
Also used : TDQIndicatorDefinitionItem(org.talend.dataquality.properties.TDQIndicatorDefinitionItem) IRepositoryViewObject(org.talend.core.model.repository.IRepositoryViewObject) PersistenceException(org.talend.commons.exception.PersistenceException) RowCountIndicator(org.talend.dataquality.indicators.RowCountIndicator) Test(org.junit.Test)

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