Search in sources :

Example 11 with NamedColumnSet

use of orgomg.cwm.resource.relational.NamedColumnSet in project tdq-studio-se by Talend.

the class PreviewProvider 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 treeSelection = ((TreeSelection) this.getContext().getSelection());
    Object firstElement = treeSelection.getFirstElement();
    NamedColumnSet set = null;
    if (firstElement instanceof DBTableRepNode) {
        set = ((DBTableRepNode) firstElement).getTdTable();
    } else if (firstElement instanceof DBViewRepNode) {
        set = ((DBViewRepNode) firstElement).getTdView();
    }
    if (set != null) {
        PreviewAction action = new PreviewAction(set);
        menu.add(action);
    }
}
Also used : DBTableRepNode(org.talend.dq.nodes.DBTableRepNode) TreeSelection(org.eclipse.jface.viewers.TreeSelection) PreviewAction(org.talend.dataprofiler.core.ui.action.actions.predefined.PreviewAction) DBViewRepNode(org.talend.dq.nodes.DBViewRepNode) NamedColumnSet(orgomg.cwm.resource.relational.NamedColumnSet)

Example 12 with NamedColumnSet

use of orgomg.cwm.resource.relational.NamedColumnSet in project tdq-studio-se by Talend.

the class TableViewerDND method installDND.

/**
 * DOC xqliu Comment method "installDND".
 *
 * @param targetControl
 */
public static void installDND(final Tree targetControl) {
    IWorkbenchPage activePage = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
    DQRespositoryView findView = (DQRespositoryView) activePage.findView(DQRespositoryView.ID);
    final CommonViewer commonViewer = findView.getCommonViewer();
    final LocalSelectionTransfer transfer = LocalSelectionTransfer.getTransfer();
    int operations = DND.DROP_COPY | DND.DROP_MOVE;
    Transfer[] transfers = new Transfer[] { transfer };
    DropTarget dropTarget = new DropTarget(targetControl, operations);
    dropTarget.setTransfer(transfers);
    DropTargetListener dndListener = new TreeDropTargetEffect(targetControl) {

        ISelectionReceiver receiver = null;

        @Override
        public void dragEnter(DropTargetEvent event) {
            super.dragEnter(event);
            IStructuredSelection selection = (IStructuredSelection) LocalSelectionTransfer.getTransfer().getSelection();
            Object object = selection.getFirstElement();
            if (object instanceof RuleRepNode) {
                receiver = new DQRuleReceiver();
            }
            if (object instanceof NamedColumnSet) {
                receiver = new TableReceiver();
            }
            if (object instanceof DBTableRepNode) {
                receiver = new TableReceiver();
            }
            if (object instanceof DBViewRepNode) {
                receiver = new TableReceiver();
            }
            if (receiver == null) {
                event.detail = DND.DROP_NONE;
            } else {
                event.feedback = DND.FEEDBACK_EXPAND;
                receiver.doDropValidation(event, commonViewer);
            }
        }

        @Override
        public void dragOver(DropTargetEvent event) {
            super.dragOver(event);
            if (receiver != null) {
                receiver.doDropValidation(event, commonViewer);
            }
        }

        @Override
        public void drop(DropTargetEvent event) {
            int index = targetControl.getItemCount();
            super.drop(event);
            if (event.item == null) {
            // TreeItem item = new TreeItem(targetControl, SWT.NONE);
            // item.setText(texts);
            // item.setText(text);
            } else {
                TreeItem item = (TreeItem) event.item;
                TreeItem[] items = targetControl.getItems();
                for (int i = 0; i < items.length; i++) {
                    if (items[i] == item) {
                        index = i;
                        break;
                    }
                }
            }
            if (receiver != null) {
                receiver.drop(event, commonViewer, index);
            }
        }
    };
    dropTarget.addDropListener(dndListener);
}
Also used : CommonViewer(org.eclipse.ui.navigator.CommonViewer) TreeItem(org.eclipse.swt.widgets.TreeItem) DropTargetEvent(org.eclipse.swt.dnd.DropTargetEvent) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) RuleRepNode(org.talend.dq.nodes.RuleRepNode) TreeDropTargetEffect(org.eclipse.swt.dnd.TreeDropTargetEffect) DBTableRepNode(org.talend.dq.nodes.DBTableRepNode) DropTargetListener(org.eclipse.swt.dnd.DropTargetListener) LocalSelectionTransfer(org.eclipse.jface.util.LocalSelectionTransfer) Transfer(org.eclipse.swt.dnd.Transfer) IWorkbenchPage(org.eclipse.ui.IWorkbenchPage) MetadataTableRepositoryObject(org.talend.core.repository.model.repositoryObject.MetadataTableRepositoryObject) DropTarget(org.eclipse.swt.dnd.DropTarget) LocalSelectionTransfer(org.eclipse.jface.util.LocalSelectionTransfer) DBViewRepNode(org.talend.dq.nodes.DBViewRepNode) NamedColumnSet(orgomg.cwm.resource.relational.NamedColumnSet)

Example 13 with NamedColumnSet

use of orgomg.cwm.resource.relational.NamedColumnSet in project tdq-studio-se by Talend.

the class TableAnalysisSqlExecutor method createSqlQuery.

private boolean createSqlQuery(String dataFilterAsString, Indicator indicator, boolean withWhereOfRule) throws AnalysisExecutionException {
    if (!isAnalyzedElementValid(indicator)) {
        return Boolean.FALSE;
    }
    IndicatorDefinition indicatorDefinition = indicator.getIndicatorDefinition();
    if (!isIndicatorDefinitionValid(indicatorDefinition, AnalysisExecutorHelper.getIndicatorName(indicator))) {
        return Boolean.FALSE;
    }
    Expression sqlGenericExpression = dbms().getSqlExpression(indicatorDefinition);
    if (!isExpressionValid(sqlGenericExpression, indicator)) {
        return Boolean.FALSE;
    }
    // --- get indicator parameters and convert them into sql expression
    List<String> whereExpressionDQRule = new ArrayList<String>();
    final EList<JoinElement> joinConditions = indicator.getJoinConditions();
    if (RulesPackage.eINSTANCE.getWhereRule().equals(indicatorDefinition.eClass())) {
        WhereRule wr = (WhereRule) indicatorDefinition;
        if (withWhereOfRule) {
            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);
            }
        }
    }
    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;
    }
    // --- default case
    // allow join
    String joinclause = (!joinConditions.isEmpty()) ? dbms().createJoinConditionAsString(set, joinConditions, catalogName, schemaName) : PluginConstant.EMPTY_STRING;
    String setName = dbms().toQualifiedName(catalogName, schemaName, quote(set.getName()));
    String completedSqlString = dbms().fillGenericQueryWithJoin(sqlGenericExpression.getBody(), setName, joinclause);
    // ~
    List<String> whereExpressionAnalysis = new ArrayList<String>();
    if (StringUtils.isNotBlank(dataFilterAsString)) {
        whereExpressionAnalysis.add(dataFilterAsString);
    }
    completedSqlString = addWhereToSqlStringStatement(whereExpressionAnalysis, whereExpressionDQRule, completedSqlString, true);
    // completedSqlString is the final query
    String finalQuery = completedSqlString;
    TdExpression instantiateSqlExpression = BooleanExpressionHelper.createTdExpression(dbms().getDbmsName(), finalQuery);
    indicator.setInstantiatedExpression(instantiateSqlExpression);
    return true;
}
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) TdExpression(org.talend.cwm.relational.TdExpression) 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 14 with NamedColumnSet

use of orgomg.cwm.resource.relational.NamedColumnSet in project tdq-studio-se by Talend.

the class TableAnalysisSqlExecutor method evaluate.

@Override
protected ReturnCode evaluate(Analysis analysis, java.sql.Connection connection, String sqlStatement) {
    IndicatorEvaluator eval = new IndicatorEvaluator(analysis);
    eval.setMonitor(getMonitor());
    // --- add indicators
    EList<Indicator> indicators = analysis.getResults().getIndicators();
    for (Indicator indicator : indicators) {
        assert indicator != null;
        NamedColumnSet set = SwitchHelpers.NAMED_COLUMN_SET_SWITCH.doSwitch(indicator.getAnalyzedElement());
        if (set == null) {
            continue;
        }
        // --- get the schema owner
        if (!belongToSameSchemata(set)) {
            // $NON-NLS-1$
            setError(Messages.getString("TableAnalysisExecutor.GivenTable", set.getName()));
            return new ReturnCode(getErrorMessage(), Boolean.FALSE);
        }
        String setName = dbms().getQueryColumnSetWithPrefix(set);
        eval.storeIndicator(setName, indicator);
    }
    // set it into the evaluator
    eval.setConnection(connection);
    // use pooled connection
    eval.setPooledConnection(POOLED_CONNECTION);
    // when to close connection
    boolean closeAtTheEnd = true;
    Package catalog = schemata.values().iterator().next();
    if (!eval.selectCatalog(catalog.getName())) {
        // $NON-NLS-1$//$NON-NLS-2$
        log.warn("Failed to select catalog " + catalog.getName() + " for connection.");
    }
    ReturnCode retCode = eval.evaluateIndicators(sqlStatement, closeAtTheEnd);
    if (getMonitor() != null) {
        getMonitor().worked(compIndicatorsWorked);
    }
    return retCode;
}
Also used : TypedReturnCode(org.talend.utils.sugars.TypedReturnCode) ReturnCode(org.talend.utils.sugars.ReturnCode) IndicatorEvaluator(org.talend.dq.indicators.IndicatorEvaluator) RulesPackage(org.talend.dataquality.rules.RulesPackage) RelationalPackage(orgomg.cwm.resource.relational.RelationalPackage) Package(orgomg.cwm.objectmodel.core.Package) Indicator(org.talend.dataquality.indicators.Indicator) WhereRuleIndicator(org.talend.dataquality.indicators.sql.WhereRuleIndicator) NamedColumnSet(orgomg.cwm.resource.relational.NamedColumnSet)

Example 15 with NamedColumnSet

use of orgomg.cwm.resource.relational.NamedColumnSet in project tdq-studio-se by Talend.

the class AnalysisTableTreeViewer method setInput.

/**
 * DOC xqliu Comment method "setInput".
 *
 * @param objs
 */
@Override
public void setInput(Object[] objs) {
    List<DBTableRepNode> tableNodeList = RepositoryNodeHelper.getTableNodeList(objs);
    List<TableIndicator> tableIndicatorList = new ArrayList<TableIndicator>();
    // MOD by zshen for 2011.06.13 add the support for the view.
    List<DBViewRepNode> viewNodeList = RepositoryNodeHelper.getViewNodeList(objs);
    if (tableNodeList.size() == 0 && viewNodeList.size() == 0) {
        // feature 22206 : fixed another bug, when deselect all, the view is not changed
        this.tableIndicators = tableIndicatorList.toArray(new TableIndicator[tableIndicatorList.size()]);
        this.setElements(tableIndicators);
        return;
    }
    List<RepositoryNode> setList = new ArrayList<RepositoryNode>();
    Connection tdProvider = null;
    for (DBTableRepNode tableNode : tableNodeList) {
        if (tdProvider == null) {
            tdProvider = ConnectionHelper.getTdDataProvider(TableHelper.getParentCatalogOrSchema(tableNode.getTdTable()));
        }
        if (tdProvider == null) {
            MessageUI.openError(DefaultMessagesImpl.getString("AnalysisTableTreeViewer.TableProviderIsNull", // $NON-NLS-1$
            tableNode.getLabel()));
        } else if (this.getAnalysis().getContext().getConnection() != null && !tdProvider.equals(this.getAnalysis().getContext().getConnection())) {
            MessageUI.openError(DefaultMessagesImpl.getString("AnalysisTableTreeViewer.TableDataProviderIsInvalid", // $NON-NLS-1$
            tableNode.getLabel()));
        } else {
            setList.add(tableNode);
        }
    }
    for (DBViewRepNode tableNode : viewNodeList) {
        if (tdProvider == null) {
            tdProvider = ConnectionHelper.getTdDataProvider(TableHelper.getParentCatalogOrSchema(tableNode.getTdView()));
        }
        if (tdProvider == null) {
            MessageUI.openError(DefaultMessagesImpl.getString("AnalysisTableTreeViewer.TableProviderIsNull", // $NON-NLS-1$
            tableNode.getLabel()));
        } else if (this.getAnalysis().getContext().getConnection() != null && !tdProvider.equals(this.getAnalysis().getContext().getConnection())) {
            MessageUI.openError(DefaultMessagesImpl.getString("AnalysisTableTreeViewer.TableDataProviderIsInvalid", // $NON-NLS-1$
            tableNode.getLabel()));
        } else {
            setList.add(tableNode);
        }
    }
    for (TableIndicator tableIndicator : tableIndicators) {
        // ADDED yyin 20120606 TDQ-5343
        NamedColumnSet selectedTable = tableIndicator.getColumnSet();
        DQRepositoryNode tableNode = null;
        if (selectedTable instanceof TdTable) {
            tableNode = RepositoryNodeHelper.recursiveFindTdTable(((TdTable) selectedTable));
        } else if (selectedTable instanceof TdView) {
            tableNode = RepositoryNodeHelper.recursiveFindTdView(((TdView) selectedTable));
        }
        // ~
        if (setList.contains(tableNode)) {
            tableIndicatorList.add(tableIndicator);
            setList.remove(tableNode);
        }
    }
    for (RepositoryNode set : setList) {
        TableIndicator tableIndicator = null;
        if (set instanceof DBViewRepNode) {
            tableIndicator = TableIndicator.createTableIndicatorWithRowCountIndicator(((DBViewRepNode) set).getTdView());
        } else if (set instanceof DBTableRepNode) {
            tableIndicator = TableIndicator.createTableIndicatorWithRowCountIndicator(((DBTableRepNode) set).getTdTable());
        } else {
            continue;
        }
        tableIndicatorList.add(tableIndicator);
    }
    this.tableIndicators = tableIndicatorList.toArray(new TableIndicator[tableIndicatorList.size()]);
    this.setElements(tableIndicators);
}
Also used : TableIndicator(org.talend.dataprofiler.core.model.TableIndicator) TdTable(org.talend.cwm.relational.TdTable) ArrayList(java.util.ArrayList) Connection(org.talend.core.model.metadata.builder.connection.Connection) DQRepositoryNode(org.talend.dq.nodes.DQRepositoryNode) RepositoryNode(org.talend.repository.model.RepositoryNode) DBTableRepNode(org.talend.dq.nodes.DBTableRepNode) DQRepositoryNode(org.talend.dq.nodes.DQRepositoryNode) TdView(org.talend.cwm.relational.TdView) DBViewRepNode(org.talend.dq.nodes.DBViewRepNode) NamedColumnSet(orgomg.cwm.resource.relational.NamedColumnSet)

Aggregations

NamedColumnSet (orgomg.cwm.resource.relational.NamedColumnSet)20 ArrayList (java.util.ArrayList)12 TableIndicator (org.talend.dataprofiler.core.model.TableIndicator)8 Connection (org.talend.core.model.metadata.builder.connection.Connection)5 Indicator (org.talend.dataquality.indicators.Indicator)5 DBTableRepNode (org.talend.dq.nodes.DBTableRepNode)4 List (java.util.List)3 TdTable (org.talend.cwm.relational.TdTable)3 CompositeIndicator (org.talend.dataprofiler.core.ui.editor.preview.CompositeIndicator)3 TableIndicatorUnit (org.talend.dataprofiler.core.ui.editor.preview.TableIndicatorUnit)3 WhereRule (org.talend.dataquality.rules.WhereRule)3 DBViewRepNode (org.talend.dq.nodes.DBViewRepNode)3 Expression (orgomg.cwm.objectmodel.core.Expression)3 InvocationTargetException (java.lang.reflect.InvocationTargetException)2 Map (java.util.Map)2 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)2 ProgressMonitorDialog (org.eclipse.jface.dialogs.ProgressMonitorDialog)2 IRunnableWithProgress (org.eclipse.jface.operation.IRunnableWithProgress)2 GridData (org.eclipse.swt.layout.GridData)2 GridLayout (org.eclipse.swt.layout.GridLayout)2