Search in sources :

Example 1 with JoinElement

use of org.talend.dataquality.rules.JoinElement in project tdq-studio-se by Talend.

the class DQRuleMasterDetailsPage method creatNewJoinElementLine.

/**
 * DOC xqliu Comment method "creatNewJoinElementLine".
 *
 * @param joinElement
 */
private void creatNewJoinElementLine(JoinElement joinElement) {
    final Composite expressComp = new Composite(joinElementComp, SWT.NONE);
    expressComp.setLayout(new GridLayout(6, false));
    final JoinElement fje = joinElement;
    boolean flag = false;
    if (fje.getColA() != null && fje.getColB() != null && fje.getOperator() != null) {
        flag = true;
    }
    final Label labelL = new Label(expressComp, SWT.NONE);
    labelL.setImage(ImageLib.getImage(ImageLib.TD_COLUMN));
    GridDataFactory.fillDefaults().span(1, 1).grab(false, false).applyTo(labelL);
    final Text textL = new Text(expressComp, SWT.BORDER);
    textL.setEditable(false);
    textL.setText(flag ? fje.getColA().getName() : PluginConstant.EMPTY_STRING);
    GridDataFactory.fillDefaults().span(1, 1).grab(true, false).applyTo(textL);
    ((GridData) textL.getLayoutData()).widthHint = 100;
    DropTarget targetL = new DropTarget(textL, DND.DROP_MOVE | DND.DROP_COPY | DND.DROP_DEFAULT);
    targetL.setTransfer(new Transfer[] { transfer });
    targetL.addDropListener(new ColumnDropTargetListener(fje, ColumnDropTargetListener.LEFT));
    final CCombo combo = new CCombo(expressComp, SWT.BORDER);
    combo.setEditable(false);
    combo.setItems(PluginConstant.OPERATORS);
    combo.setText(flag ? fje.getOperator() : PluginConstant.DEFAULT_OPERATOR);
    GridDataFactory.fillDefaults().span(1, 1).grab(false, false).applyTo(combo);
    combo.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            fje.setOperator(combo.getText());
            setDirty(true);
        }
    });
    final Label labelR = new Label(expressComp, SWT.NONE);
    labelR.setImage(ImageLib.getImage(ImageLib.TD_COLUMN));
    GridDataFactory.fillDefaults().span(1, 1).grab(false, false).applyTo(labelR);
    final Text textR = new Text(expressComp, SWT.BORDER);
    textR.setEditable(false);
    textR.setText(flag ? fje.getColB().getName() : PluginConstant.EMPTY_STRING);
    GridDataFactory.fillDefaults().span(1, 1).grab(true, false).applyTo(textR);
    ((GridData) textR.getLayoutData()).widthHint = 100;
    DropTarget targetR = new DropTarget(textR, DND.DROP_MOVE | DND.DROP_COPY | DND.DROP_DEFAULT);
    targetR.setTransfer(new Transfer[] { transfer });
    targetR.addDropListener(new ColumnDropTargetListener(fje, ColumnDropTargetListener.RIGHT));
    Button delButton = new Button(expressComp, SWT.NONE);
    delButton.setImage(ImageLib.getImage(ImageLib.DELETE_ACTION));
    // $NON-NLS-1$
    delButton.setToolTipText(DefaultMessagesImpl.getString("DQRuleMasterDetailsPage.delete"));
    GridDataFactory.fillDefaults().span(1, 1).grab(false, false).applyTo(delButton);
    delButton.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            tempJoinElements.remove(fje);
            expressComp.dispose();
            joinConditionSection.setExpanded(true);
            setDirty(true);
        }
    });
    GridDataFactory.fillDefaults().align(SWT.FILL, SWT.FILL).grab(true, false).applyTo(expressComp);
}
Also used : Composite(org.eclipse.swt.widgets.Composite) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) Label(org.eclipse.swt.widgets.Label) Text(org.eclipse.swt.widgets.Text) JoinElement(org.talend.dataquality.rules.JoinElement) GridLayout(org.eclipse.swt.layout.GridLayout) CCombo(org.eclipse.swt.custom.CCombo) Button(org.eclipse.swt.widgets.Button) SelectionEvent(org.eclipse.swt.events.SelectionEvent) DropTarget(org.eclipse.swt.dnd.DropTarget)

Example 2 with JoinElement

use of org.talend.dataquality.rules.JoinElement in project tdq-studio-se by Talend.

the class DQRuleMasterDetailsPage method cloneJoin.

/**
 * DOC xqliu Comment method "cloneJoin".
 *
 * @param joinElement
 * @return
 */
private JoinElement cloneJoin(JoinElement joinElement) {
    if (joinElement != null) {
        JoinElement newJoinElement = RulesFactory.eINSTANCE.createJoinElement();
        newJoinElement.setColA(joinElement.getColA());
        newJoinElement.setColB(joinElement.getColB());
        newJoinElement.setColumnAliasA(joinElement.getColumnAliasA());
        newJoinElement.setColumnAliasB(joinElement.getColumnAliasB());
        newJoinElement.setOperator(joinElement.getOperator());
        newJoinElement.setTableAliasA(joinElement.getTableAliasA());
        newJoinElement.setTableAliasB(joinElement.getTableAliasB());
        return newJoinElement;
    }
    return null;
}
Also used : JoinElement(org.talend.dataquality.rules.JoinElement)

Example 3 with JoinElement

use of org.talend.dataquality.rules.JoinElement in project tdq-studio-se by Talend.

the class JoinConditionTableViewer method showSelectedElements.

/**
 * DOC xqliu Comment method "showSelectedElements".
 *
 * @param table
 * @param ab
 */
protected void showSelectedElements(Table table, String ab) {
    TableItem[] selection = table.getSelection();
    if (selection.length > 0) {
        JoinElement join = (JoinElement) selection[0].getData();
        ModelElement column = join.getColA();
        if (COLUMN_B.equals(ab)) {
            column = join.getColB();
        }
        DQRespositoryView dqview = CorePlugin.getDefault().findAndOpenRepositoryView();
        // if DqRepository view is not openning will don'st should show the element immediately
        if (dqview != null) {
            RepositoryNode recursiveFind = RepositoryNodeHelper.recursiveFind(column);
            if (recursiveFind == null) {
                recursiveFind = RepositoryNodeHelper.createRepositoryNode(column);
            }
            dqview.showSelectedElements(recursiveFind);
        }
    }
}
Also used : JoinElement(org.talend.dataquality.rules.JoinElement) ModelElement(orgomg.cwm.objectmodel.core.ModelElement) TableItem(org.eclipse.swt.widgets.TableItem) RepositoryNode(org.talend.repository.model.RepositoryNode) IRepositoryNode(org.talend.repository.model.IRepositoryNode) DQRespositoryView(org.talend.dataprofiler.core.ui.views.DQRespositoryView)

Example 4 with JoinElement

use of org.talend.dataquality.rules.JoinElement in project tdq-studio-se by Talend.

the class TableAnalysisSqlExecutor method getValidStatement.

/**
 * DOC xqliu Comment method "getValidStatement". 2009-10-29 bug 9702
 *
 * @param dataFilterAsString
 * @param indicator
 * @param valid
 * @return
 */
public String getValidStatement(String dataFilterAsString, Indicator indicator, boolean valid) {
    if (!isAnalyzedElementValid(indicator)) {
        return PluginConstant.EMPTY_STRING;
    }
    IndicatorDefinition indicatorDefinition = indicator.getIndicatorDefinition();
    if (!isIndicatorDefinitionValid(indicatorDefinition, AnalysisExecutorHelper.getIndicatorName(indicator))) {
        return PluginConstant.EMPTY_STRING;
    }
    Expression sqlGenericExpression = dbms().getSqlExpression(indicatorDefinition);
    if (!isExpressionValid(sqlGenericExpression, indicator)) {
        return PluginConstant.EMPTY_STRING;
    }
    // --- get indicator parameters and convert them into sql expression
    List<String> whereExpressionAnalysis = new ArrayList<String>();
    if (StringUtils.isNotBlank(dataFilterAsString)) {
        whereExpressionAnalysis.add(dataFilterAsString);
    }
    List<String> whereExpressionDQRule = new ArrayList<String>();
    String setAliasA = PluginConstant.EMPTY_STRING;
    final EList<JoinElement> joinConditions = indicator.getJoinConditions();
    if (RulesPackage.eINSTANCE.getWhereRule().equals(indicatorDefinition.eClass())) {
        WhereRule wr = (WhereRule) indicatorDefinition;
        whereExpressionDQRule.add(wr.getWhereExpression());
        // MOD scorreia 2009-03-13 copy joins conditions into the indicator
        joinConditions.clear();
        if (!isJoinConditionEmpty(indicator)) {
            for (JoinElement joinelt : wr.getJoins()) {
                JoinElement joinCopy = EcoreUtil.copy(joinelt);
                joinConditions.add(joinCopy);
                setAliasA = PluginConstant.EMPTY_STRING.equals(setAliasA) ? joinCopy.getTableAliasA() : setAliasA;
            }
        }
    }
    NamedColumnSet set = SwitchHelpers.NAMED_COLUMN_SET_SWITCH.doSwitch(indicator.getAnalyzedElement());
    String schemaName = getQuotedSchemaName(set);
    // --- normalize table name
    String catalogName = getQuotedCatalogName(set);
    if (catalogName == null && schemaName != null) {
        // try to get catalog above schema
        final Schema parentSchema = SchemaHelper.getParentSchema(set);
        final Catalog parentCatalog = CatalogHelper.getParentCatalog(parentSchema);
        catalogName = parentCatalog != null ? parentCatalog.getName() : null;
    }
    String setName = dbms().toQualifiedName(catalogName, schemaName, quote(set.getName()));
    // ### evaluate SQL Statement depending on indicators ###
    String completedSqlString = null;
    // --- default case
    // allow join
    String joinclause = (!joinConditions.isEmpty()) ? dbms().createJoinConditionAsString(set, joinConditions, catalogName, schemaName) : PluginConstant.EMPTY_STRING;
    String genericSql = sqlGenericExpression.getBody();
    // $NON-NLS-1$//$NON-NLS-2$
    setAliasA = PluginConstant.EMPTY_STRING.equals(setAliasA) ? "*" : setAliasA + ".*";
    // $NON-NLS-1$
    genericSql = genericSql.replace("COUNT(*)", setAliasA);
    completedSqlString = dbms().fillGenericQueryWithJoin(genericSql, setName, joinclause);
    // ~
    completedSqlString = addWhereToSqlStringStatement(whereExpressionAnalysis, whereExpressionDQRule, completedSqlString, valid);
    return completedSqlString;
}
Also used : JoinElement(org.talend.dataquality.rules.JoinElement) WhereRule(org.talend.dataquality.rules.WhereRule) TdExpression(org.talend.cwm.relational.TdExpression) Expression(orgomg.cwm.objectmodel.core.Expression) Schema(orgomg.cwm.resource.relational.Schema) ArrayList(java.util.ArrayList) IndicatorDefinition(org.talend.dataquality.indicators.definition.IndicatorDefinition) NamedColumnSet(orgomg.cwm.resource.relational.NamedColumnSet) Catalog(orgomg.cwm.resource.relational.Catalog)

Example 5 with JoinElement

use of org.talend.dataquality.rules.JoinElement in project tdq-studio-se by Talend.

the class RepositoryNodeHelper method getAllColumnNodes.

/**
 * get All the Column level Nodes.
 *
 * @param selectedNodes
 * @return
 */
public static IRepositoryNode[] getAllColumnNodes(Object[] selectedNodes) {
    List<IRepositoryNode> list = new ArrayList<IRepositoryNode>();
    if (selectedNodes == null || selectedNodes.length == 0) {
        return list.toArray(new IRepositoryNode[list.size()]);
    }
    Object firstElement = selectedNodes[0];
    if (firstElement instanceof IRepositoryNode) {
        IRepositoryNode repNode = (IRepositoryNode) firstElement;
        IRepositoryViewObject repViewObject = repNode.getObject();
        if (repViewObject instanceof MetadataColumnRepositoryObject || repViewObject instanceof MetadataXmlElementType) {
            IRepositoryNode[] column = new IRepositoryNode[selectedNodes.length];
            for (int i = 0; i < selectedNodes.length; i++) {
                column[i] = (IRepositoryNode) selectedNodes[i];
            }
            return column;
        } else if (repViewObject instanceof MetadataTableRepositoryObject) {
            for (Object currentObj : selectedNodes) {
                IRepositoryNode columnSetNode = (IRepositoryNode) currentObj;
                List<IRepositoryNode> children = columnSetNode.getChildren();
                if (children.size() > 0) {
                    list.addAll(children.get(0).getChildren());
                }
            }
            return list.toArray(new IRepositoryNode[list.size()]);
        }
    } else if (firstElement instanceof TdTable) {
        TdTable table = (TdTable) firstElement;
        EList<MetadataColumn> columns = table.getColumns();
        for (MetadataColumn column : columns) {
            RepositoryNode recursiveFind = RepositoryNodeHelper.recursiveFind(column);
            list.add(recursiveFind);
        }
        return list.toArray(new IRepositoryNode[list.size()]);
    } else if (firstElement instanceof WhereRuleChartDataEntity) {
        // ADD msjian 2012-2-9 TDQ-4470: get columns from the join conditions
        EList<JoinElement> joinConditions = ((WhereRuleChartDataEntity) firstElement).getIndicator().getJoinConditions();
        if (joinConditions != null && joinConditions.size() > 0) {
            JoinElement joinElement = joinConditions.get(0);
            list.add(RepositoryNodeHelper.recursiveFind(joinElement.getColA()));
            list.add(RepositoryNodeHelper.recursiveFind(joinElement.getColB()));
            return list.toArray(new IRepositoryNode[list.size()]);
        }
    // TDQ-4470 ~
    } else if (firstElement instanceof TdView) {
        // Added yyin 20120522 TDQ-4945, support tdView
        TdView view = (TdView) firstElement;
        EList<MetadataColumn> columns = view.getColumns();
        for (MetadataColumn column : columns) {
            RepositoryNode recursiveFind = RepositoryNodeHelper.recursiveFind(column);
            list.add(recursiveFind);
        }
        return list.toArray(new IRepositoryNode[list.size()]);
    }
    // ~
    return null;
}
Also used : TdTable(org.talend.cwm.relational.TdTable) IRepositoryNode(org.talend.repository.model.IRepositoryNode) ArrayList(java.util.ArrayList) RepositoryNode(org.talend.repository.model.RepositoryNode) IRepositoryNode(org.talend.repository.model.IRepositoryNode) DQRepositoryNode(org.talend.dq.nodes.DQRepositoryNode) MetadataTableRepositoryObject(org.talend.core.repository.model.repositoryObject.MetadataTableRepositoryObject) JoinElement(org.talend.dataquality.rules.JoinElement) MetadataColumn(org.talend.core.model.metadata.builder.connection.MetadataColumn) EList(org.eclipse.emf.common.util.EList) WhereRuleChartDataEntity(org.talend.dq.indicators.preview.table.WhereRuleChartDataEntity) TdView(org.talend.cwm.relational.TdView) MetadataXmlElementType(org.talend.core.model.metadata.MetadataXmlElementType) IRepositoryViewObject(org.talend.core.model.repository.IRepositoryViewObject) TdViewRepositoryObject(org.talend.core.repository.model.repositoryObject.TdViewRepositoryObject) IRepositoryViewObject(org.talend.core.model.repository.IRepositoryViewObject) ISubRepositoryObject(org.talend.core.model.repository.ISubRepositoryObject) RepositoryViewObject(org.talend.core.model.repository.RepositoryViewObject) MetadataTableRepositoryObject(org.talend.core.repository.model.repositoryObject.MetadataTableRepositoryObject) TdTableRepositoryObject(org.talend.core.repository.model.repositoryObject.TdTableRepositoryObject) MetadataColumnRepositoryObject(org.talend.core.repository.model.repositoryObject.MetadataColumnRepositoryObject) EObject(org.eclipse.emf.ecore.EObject) MetadataColumnRepositoryObject(org.talend.core.repository.model.repositoryObject.MetadataColumnRepositoryObject) ArrayList(java.util.ArrayList) List(java.util.List) EList(org.eclipse.emf.common.util.EList)

Aggregations

JoinElement (org.talend.dataquality.rules.JoinElement)15 ArrayList (java.util.ArrayList)6 SelectionAdapter (org.eclipse.swt.events.SelectionAdapter)4 SelectionEvent (org.eclipse.swt.events.SelectionEvent)4 Button (org.eclipse.swt.widgets.Button)3 TdColumn (org.talend.cwm.relational.TdColumn)3 TdExpression (org.talend.cwm.relational.TdExpression)3 TdTable (org.talend.cwm.relational.TdTable)3 IndicatorDefinition (org.talend.dataquality.indicators.definition.IndicatorDefinition)3 IRepositoryNode (org.talend.repository.model.IRepositoryNode)3 RepositoryNode (org.talend.repository.model.RepositoryNode)3 Expression (orgomg.cwm.objectmodel.core.Expression)3 List (java.util.List)2 EList (org.eclipse.emf.common.util.EList)2 GridData (org.eclipse.swt.layout.GridData)2 GridLayout (org.eclipse.swt.layout.GridLayout)2 Composite (org.eclipse.swt.widgets.Composite)2 MetadataColumnRepositoryObject (org.talend.core.repository.model.repositoryObject.MetadataColumnRepositoryObject)2 WhereRuleChartDataEntity (org.talend.dq.indicators.preview.table.WhereRuleChartDataEntity)2 HashMap (java.util.HashMap)1