use of org.talend.core.ITDQRuleService in project tdi-studio-se by Talend.
the class ComboController method refresh.
@Override
public void refresh(IElementParameter param, boolean check) {
String paramName = param.getName();
boolean isPatternList = StringUtils.equals(paramName, "PATTERN_LIST");
boolean isRule = StringUtils.equals(paramName, "DQRULES_LIST");
CCombo combo = (CCombo) hashCurControls.get(paramName);
if (combo == null || combo.isDisposed()) {
return;
}
// if it is pattern,then it can get ITDQPatternService's instance
if (isPatternList) {
ITDQPatternService service = null;
try {
service = (ITDQPatternService) GlobalServiceRegister.getDefault().getService(ITDQPatternService.class);
} catch (RuntimeException e) {
// nothing to do
}
if (service != null && elem instanceof Node) {
Node node = (Node) elem;
IElementParameter typeParam = node.getElementParameter("TYPE");
service.overridePatternList(typeParam, param);
}
}
if (isRule) {
ITDQRuleService service = null;
try {
service = (ITDQRuleService) GlobalServiceRegister.getDefault().getService(ITDQRuleService.class);
} catch (RuntimeException e) {
// nothing to do
}
if (service != null) {
service.fillTDQRuleList(param);
}
}
Object value = param.getValue();
if (value instanceof String) {
//$NON-NLS-1$
String strValue = "";
int nbInList = 0, nbMax = param.getListItemsValue().length;
String name = (String) value;
while (strValue.equals(new String("")) && nbInList < nbMax) {
//$NON-NLS-1$
if (name.equals(param.getListItemsValue()[nbInList])) {
strValue = param.getListItemsDisplayName()[nbInList];
}
nbInList++;
}
String[] paramItems = getListToDisplay(param);
String[] comboItems = combo.getItems();
if (!Arrays.equals(paramItems, comboItems)) {
combo.setItems(paramItems);
}
// bug 19837
if (isPatternList || isRule) {
combo.setText("".equals(strValue) ? (String) value : strValue);
} else {
if (!StringUtils.isEmpty(strValue)) {
combo.setText(strValue);
} else {
combo.setText((String) value);
}
}
combo.setVisible(true);
}
if (param.isContextMode()) {
combo.setBackground(Display.getDefault().getSystemColor(SWT.COLOR_YELLOW));
combo.setEnabled(false);
}
}
use of org.talend.core.ITDQRuleService in project tdi-studio-se by Talend.
the class QueryGuessCommand method generateNewQueryFromDQRuler.
private String generateNewQueryFromDQRuler(IElementParameter dqRulerParam) {
ITDQRuleService rulerService = null;
try {
rulerService = (ITDQRuleService) GlobalServiceRegister.getDefault().getService(ITDQRuleService.class);
} catch (RuntimeException e) {
// nothing to do
}
if (rulerService != null) {
//$NON-NLS-1$
IElementParameter existConnection = node.getElementParameter("USE_EXISTING_CONNECTION");
boolean useExistConnection = (existConnection == null ? false : (Boolean) existConnection.getValue());
INode connectionNode = null;
if (node != null && node instanceof INode) {
process = ((INode) node).getProcess();
}
if (useExistConnection && process != null) {
IElementParameter connector = node.getElementParameter("CONNECTION");
if (connector != null) {
String connectorValue = connector.getValue().toString();
List<? extends INode> graphicalNodes = process.getGeneratingNodes();
for (INode node : graphicalNodes) {
if (node.getUniqueName().equals(connectorValue)) {
connectionNode = node;
break;
}
}
}
}
//$NON-NLS-1$
IElementParameter typeParam = node.getElementParameter("TYPE");
IElementParameter dbParam = node.getElementParameter(EParameterName.DBNAME.getName());
IContext lastRunContext = ((IProcess2) process).getLastRunContext();
String dbName = JavaProcessUtil.getRealParamValue(process, dbParam.getValue().toString(), lastRunContext);
IElementParameter schemaParam = node.getElementParameter(EParameterName.SCHEMA_DB.getName());
String schemaName = JavaProcessUtil.getRealParamValue(process, schemaParam == null ? org.apache.commons.lang.StringUtils.EMPTY : schemaParam.getValue().toString(), lastRunContext);
IElementParameter tableParam = node.getElementParameterFromField(EParameterFieldType.DBTABLE);
String tableName = JavaProcessUtil.getRealParamValue(process, tableParam.getValue().toString(), lastRunContext);
//$NON-NLS-1$
IElementParameter whereClause = node.getElementParameter("WHERE_CLAUSE");
String whereStr = org.apache.commons.lang.StringUtils.EMPTY;
if (whereClause.getValue() != null) {
whereStr = JavaProcessUtil.getRealParamValue(process, whereClause.getValue().toString(), lastRunContext);
}
if (connectionNode != null) {
//$NON-NLS-1$
typeParam = connectionNode.getElementParameter("TYPE");
dbParam = connectionNode.getElementParameter(EParameterName.DBNAME.getName());
dbName = JavaProcessUtil.getRealParamValue(process, dbParam.getValue().toString(), lastRunContext);
schemaParam = connectionNode.getElementParameter(EParameterName.SCHEMA_DB.getName());
schemaName = JavaProcessUtil.getRealParamValue(process, schemaParam == null ? org.apache.commons.lang.StringUtils.EMPTY : schemaParam.getValue().toString(), lastRunContext);
}
List<IMetadataTable> metadataList = null;
IMetadataTable metadataTable = null;
if (node instanceof Node) {
metadataList = ((Node) node).getMetadataList();
if (metadataList != null && !metadataList.isEmpty()) {
metadataTable = metadataList.get(0);
}
}
return rulerService.getQueryByRule(dqRulerParam, typeParam, dbName, schemaName, tableName, metadataTable, node.getElementName().contains("Invalid"), //$NON-NLS-1$
whereStr);
}
return org.apache.commons.lang.StringUtils.EMPTY;
}
use of org.talend.core.ITDQRuleService in project tdi-studio-se by Talend.
the class GuessSchemaController method runShadowProcess.
private void runShadowProcess(final Property property, final Node inputNode, final IContext selectContext, final IElementParameter switchParam) {
DatabaseConnection connt = TracesConnectionUtils.createConnection(connParameters);
String dbmsId = connt.getDbmsId();
if (dbmsId == null) {
Shell shell = Display.getCurrent().getActiveShell();
MessageDialog.openError(shell, "No info about DB found !", "Please choose the correct mapping file.\n Note: This is normal when using JDBC component");
MappingFileSelectDialog dialog = new MappingFileSelectDialog(shell);
dialog.open();
dbmsId = dialog.getSelectId();
}
GuessSchemaProcess gsp = new GuessSchemaProcess(property, inputNode, selectContext, memoSQL, info, part.getProcess());
try {
List<Integer> indexsForSameNamedColumn = new ArrayList<Integer>();
CsvArray array = gsp.run();
List<String[]> schemaContent = array.getRows();
List<String> columnLabels = new ArrayList<String>();
if (columns != null) {
columns.clear();
}
if (!schemaContent.isEmpty()) {
int numbOfColumn = schemaContent.get(0).length;
for (int i = 1; i <= numbOfColumn; i++) {
indexsForSameNamedColumn.clear();
Boolean b = false;
IMetadataColumn oneColum = new MetadataColumn();
// get the column name from the temp file genenrated by GuessSchemaProcess.java
String labelName = (schemaContent.get(0))[i - 1];
if (info != null && info.isHive()) {
if (labelName != null && labelName.indexOf(TalendTextUtils.JAVA_END_STRING) != -1) {
labelName = labelName.substring(labelName.lastIndexOf(TalendTextUtils.JAVA_END_STRING) + 1, labelName.length());
}
}
String name = labelName;
String sub = "";
String sub2 = "";
if (labelName != null && labelName.length() > 0 && labelName.startsWith("_")) {
//$NON-NLS-1$
sub = labelName.substring(1);
if (sub != null && sub.length() > 0) {
sub2 = sub.substring(1);
}
}
if (KeywordsValidator.isKeyword(labelName) || KeywordsValidator.isKeyword(sub) || KeywordsValidator.isKeyword(sub2)) {
labelName = "_" + labelName;
b = true;
}
// String label = labelName;
// findSameNamedColumnAndReplaceTheIndex(indexsForSameNamedColumn, i, oneColum, labelName);
oneColum.setLabel(MetadataToolHelper.validateColumnName(labelName, i, columnLabels));
// if (b && label != null && label.length() > 0 && label.startsWith("_")) { //$NON-NLS-1$
// String substring = label.substring(1);
// if (label.startsWith("_")
// && (KeywordsValidator.isKeyword(substring) || KeywordsValidator.isKeyword(sub) ||
// KeywordsValidator
// .isKeyword(sub2))) {
// label = substring;
// }
// }
oneColum.setOriginalDbColumnName(name);
if (schemaContent.size() > 5) {
oneColum.setPrecision(Integer.parseInt(schemaContent.get(2)[i - 1]));
oneColum.setLength(Integer.parseInt(schemaContent.get(3)[i - 1]));
}
try {
String talendType = null;
// to see if the language is java or perl
if (LanguageManager.getCurrentLanguage() == ECodeLanguage.JAVA) {
if (schemaContent.size() >= 5) {
talendType = MetadataTalendType.getMappingTypeRetriever(dbmsId).getDefaultSelectedTalendType(schemaContent.get(4)[i - 1]);
} else {
talendType = JavaTypesManager.STRING.getId();
}
} else {
if (schemaContent.size() >= 5) {
talendType = PerlDataTypeHelper.getNewTalendTypeOfValue(schemaContent.get(4)[i - 1]);
} else {
talendType = PerlTypesManager.STRING;
}
}
oneColum.setTalendType(talendType);
if (dbmsId != null) {
if (!TypesManager.checkDBType(dbmsId, oneColum.getTalendType(), oneColum.getType())) {
oneColum.setType(TypesManager.getDBTypeFromTalendType(dbmsId, oneColum.getTalendType()));
}
}
// oneColum.setTalendType(JavaTypesManager.STRING.getId());
} catch (Exception e) {
/*
* the table have no data at all ,to do nothing
*/
ExceptionHandler.process(e);
}
// get if a column is nullable from the temp file genenrated by GuessSchemaProcess.java
oneColum.setNullable((schemaContent.get(1))[i - 1].equals(Boolean.TRUE.toString()) ? true : false);
columns.add(oneColum);
columnLabels.add(oneColum.getLabel());
}
if (columns.size() > 0) {
IElementParameter dqRule = elem.getElementParameter("DQRULES_LIST");
if (dqRule != null) {
ITDQRuleService ruleService = null;
try {
ruleService = (ITDQRuleService) GlobalServiceRegister.getDefault().getService(ITDQRuleService.class);
} catch (RuntimeException e) {
// nothing to do
}
IElementParameter queryParam = elem.getElementParameter("QUERY");
if (ruleService != null && queryParam != null) {
ruleService.updateOriginalColumnNames(columns, queryParam);
}
}
}
IMetadataTable tempMetatable = new MetadataTable();
/* for bug 20973 */
if (tempMetatable.getTableName() == null) {
tempMetatable.setTableName(inputNode.getUniqueName());
}
IMetadataTable outputMetaCopy, originaleOutputTable;
String propertyName = "";
if (!btn.isDisposed()) {
propertyName = (String) btn.getData(PARAMETER_NAME);
}
IElementParameter param = inputNode.getElementParameter(propertyName);
for (IElementParameter eParam : elem.getElementParameters()) {
if (eParam.getContext() != null) {
param = eParam;
}
}
originaleOutputTable = inputNode.getMetadataFromConnector(param.getContext());
if (originaleOutputTable != null) {
outputMetaCopy = originaleOutputTable.clone();
}
tempMetatable.setListColumns(columns);
tempMetatable.setDbms(dbmsId);
MetadataDialog metaDialog = new MetadataDialog(composite.getShell(), tempMetatable, inputNode, getCommandStack());
if (metaDialog != null) {
//$NON-NLS-1$
metaDialog.setText(Messages.getString("AbstractSchemaController.schema.title", inputNode.getLabel()));
}
// ok pressed
if (metaDialog.open() == MetadataDialog.OK) {
outputMetaCopy = metaDialog.getOutputMetaData();
boolean modified = false;
if (!outputMetaCopy.sameMetadataAs(originaleOutputTable, IMetadataColumn.OPTIONS_NONE)) {
modified = true;
}
if (modified) {
if (switchParam != null) {
switchParam.setValue(Boolean.FALSE);
}
changeMetadataCommand = new ChangeMetadataCommand(inputNode, param, originaleOutputTable, outputMetaCopy);
changeMetadataCommand.execute();
}
}
}
} catch (ProcessorException e) {
ExtractMetaDataUtils.getInstance().closeConnection();
final String strExcepton = e.getMessage();
Display.getDefault().asyncExec(new Runnable() {
@Override
public void run() {
MessageDialog.openWarning(composite.getShell(), Messages.getString("GuessSchemaController.connectionError"), //$NON-NLS-1$
strExcepton);
}
});
ExceptionHandler.process(e);
}
}
Aggregations