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);
}
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;
}
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);
}
}
}
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;
}
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;
}
Aggregations