Search in sources :

Example 1 with IndicatorDefinition

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

the class AbstractAnalysisMetadataPage method getDqRules.

/**
 * ADD gdbu 2011-6-1 bug : 19833
 *
 * DOC gdbu Comment method "getDqRules". Get all DQRule from analysis.
 *
 * @param analysis
 * @return
 */
public List<DQRule> getDqRules(Analysis analysis) {
    List<DQRule> result = new ArrayList<DQRule>();
    EList<Indicator> indicators = analysis.getResults().getIndicators();
    for (Indicator indicator : indicators) {
        IndicatorDefinition indicatorDefinition = indicator.getIndicatorDefinition();
        if (indicatorDefinition instanceof DQRule) {
            result.add((DQRule) indicatorDefinition);
        }
    }
    return result;
}
Also used : ArrayList(java.util.ArrayList) IndicatorDefinition(org.talend.dataquality.indicators.definition.IndicatorDefinition) Indicator(org.talend.dataquality.indicators.Indicator) ModelElementIndicator(org.talend.dataprofiler.core.model.ModelElementIndicator) DQRule(org.talend.dataquality.rules.DQRule)

Example 2 with IndicatorDefinition

use of org.talend.dataquality.indicators.definition.IndicatorDefinition 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 3 with IndicatorDefinition

use of org.talend.dataquality.indicators.definition.IndicatorDefinition 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 4 with IndicatorDefinition

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

the class SplitSysIndicatorTask method updateIndDefinition.

private void updateIndDefinition(Indicator ind) {
    if (ind == null) {
        return;
    }
    IndicatorDefinition indicatorDefinition = ind.getIndicatorDefinition();
    if (indicatorDefinition == null) {
        return;
    }
    // ADD xqliu 2010-07-28 13676 don't update UserDefIndicator
    if (ind instanceof UserDefIndicator) {
        return;
    }
    // ~ 13676
    CwmResource indDefResource = (CwmResource) indicatorDefinition.eResource();
    if (indDefResource == null) {
        // MOD scorreia 2010-10-05 16030 set the link between indicators and their definition
        if (DefinitionHandler.getInstance().setDefaultIndicatorDefinition(ind)) {
            if (log.isDebugEnabled()) {
                log.debug(// $NON-NLS-1$//$NON-NLS-2$
                "MIGRATING: indicator definition " + indicatorDefinition.getName() + " in indicator " + ind.getName() + " in analysis " + // $NON-NLS-1$
                ind.eResource());
            }
        } else {
            log.error(DefaultMessagesImpl.getString("SplitSysIndicatorTask_LogErr", indicatorDefinition.getName(), ind.getName(), // $NON-NLS-1$
            ind.eResource()));
        }
    // ~ 16030
    } else {
        // Find updated indicator definition
        IndicatorDefinition updatedDefinition = DefinitionHandler.getInstance().getDefinitionById(indDefResource.getID(ind.getIndicatorDefinition()));
        ind.setIndicatorDefinition(updatedDefinition);
    }
}
Also used : CwmResource(org.talend.model.emf.CwmResource) IndicatorDefinition(org.talend.dataquality.indicators.definition.IndicatorDefinition) UserDefIndicator(org.talend.dataquality.indicators.sql.UserDefIndicator)

Example 5 with IndicatorDefinition

use of org.talend.dataquality.indicators.definition.IndicatorDefinition 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)

Aggregations

IndicatorDefinition (org.talend.dataquality.indicators.definition.IndicatorDefinition)141 UDIndicatorDefinition (org.talend.dataquality.indicators.definition.userdefine.UDIndicatorDefinition)37 Test (org.junit.Test)35 ArrayList (java.util.ArrayList)34 TdExpression (org.talend.cwm.relational.TdExpression)31 File (java.io.File)22 Analysis (org.talend.dataquality.analysis.Analysis)16 IFile (org.eclipse.core.resources.IFile)15 Property (org.talend.core.model.properties.Property)14 IRepositoryViewObject (org.talend.core.model.repository.IRepositoryViewObject)14 TDQIndicatorDefinitionItem (org.talend.dataquality.properties.TDQIndicatorDefinitionItem)14 PersistenceException (org.talend.commons.exception.PersistenceException)13 Indicator (org.talend.dataquality.indicators.Indicator)12 ModelElement (orgomg.cwm.objectmodel.core.ModelElement)12 Path (org.eclipse.core.runtime.Path)10 IFolder (org.eclipse.core.resources.IFolder)9 BasicEList (org.eclipse.emf.common.util.BasicEList)9 TdColumn (org.talend.cwm.relational.TdColumn)9 UserDefIndicator (org.talend.dataquality.indicators.sql.UserDefIndicator)7 TDQAnalysisItem (org.talend.dataquality.properties.TDQAnalysisItem)7