use of org.talend.core.model.metadata.IMetadataColumn in project tdi-studio-se by Talend.
the class DCSchemaController method createButtonCommand.
/*
* (non-Javadoc)
*
* @see
* org.talend.designer.core.ui.editor.properties.controllers.AbstractRepositoryController#createButtonCommand(org
* .eclipse.swt.widgets.Button)
*/
@SuppressWarnings("unchecked")
protected Command createButtonCommand(Button button) {
Button inputButton = button;
Map<INode, Map<IMetadataTable, Boolean>> inputInfos = new HashMap<INode, Map<IMetadataTable, Boolean>>();
Node node;
if (elem instanceof Node) {
node = (Node) elem;
} else {
// else instanceof Connection
node = (Node) ((Connection) elem).getSource();
}
String componentName = node.getComponent().getName();
initConnectionParameters();
IContextManager manager;
if (part == null) {
manager = new EmptyContextManager();
} else {
manager = part.getProcess().getContextManager();
}
IElement oldElement = elem;
if (isUseExistingConnection()) {
this.elem = connectionNode;
initConnectionParametersWithContext(connectionNode, manager.getDefaultContext());
} else {
initConnectionParametersWithContext(elem, manager.getDefaultContext());
}
this.elem = oldElement;
if (!GlobalServiceRegister.getDefault().isServiceRegistered(IDCService.class)) {
return null;
}
IDCService restService = (IDCService) GlobalServiceRegister.getDefault().getService(IDCService.class);
restService.setupRestHelperInstance(connParameters.getHost(), connParameters.getPort(), connParameters.getUserName(), connParameters.getPassword(), connParameters.getDirectory(), connParameters.isHttps());
String entityName = elem.getPropertyValue("ENTITY").toString().replaceAll("\"", "");
IMetadataTable inputMetadata = null, inputMetaCopy = null;
Connection inputConec = null;
String propertyName = (String) inputButton.getData(PARAMETER_NAME);
IElementParameter param = node.getElementParameter(propertyName);
IElementParameter connectionParam = param.getChildParameters().get(EParameterName.CONNECTION.getName());
String connectionName = null;
if (connectionParam != null) {
connectionName = (String) connectionParam.getValue();
}
boolean inputReadOnly = false, outputReadOnly = false, inputReadOnlyNode = false, inputReadOnlyParam = false;
for (Connection connec : (List<Connection>) node.getIncomingConnections()) {
if (connec.isActivate() && (EConnectionType.FLOW_MAIN.equals(connec.getLineStyle()) || EConnectionType.TABLE.equals(connec.getLineStyle()) || EConnectionType.FLOW_MERGE.equals(connec.getLineStyle()) || EConnectionType.FLOW_REF.equals(connec.getLineStyle()))) {
if (connectionName != null && !connec.getName().equals(connectionName)) {
continue;
}
inputMetadata = connec.getMetadataTable();
inputMetaCopy = inputMetadata.clone();
inputConec = connec;
if (connec.getSource().isReadOnly()) {
inputReadOnlyNode = true;
} else {
for (IElementParameter curParam : connec.getSource().getElementParameters()) {
if (curParam.getFieldType() == EParameterFieldType.SCHEMA_TYPE || curParam.getFieldType() == EParameterFieldType.DCSCHEMA) {
if (curParam.isReadOnly()) {
inputReadOnlyParam = true;
}
}
}
}
// check if the inputMetadata is readonly
if (inputMetadata != null) {
for (IMetadataColumn column : inputMetadata.getListColumns()) {
IMetadataColumn columnCopied = inputMetaCopy.getColumn(column.getLabel());
columnCopied.setCustom(column.isCustom());
columnCopied.setReadOnly(column.isReadOnly());
}
inputMetaCopy.setReadOnly(inputMetadata.isReadOnly());
inputReadOnly = prepareReadOnlyTable(inputMetaCopy, inputReadOnlyParam, inputReadOnlyNode);
}
// store the value for Dialog
Map<IMetadataTable, Boolean> oneInput = new HashMap<IMetadataTable, Boolean>();
oneInput.put(inputMetaCopy, inputReadOnly);
inputInfos.put(connec.getSource(), oneInput);
}
}
if (connectionParam != null && inputMetadata == null) {
//$NON-NLS-1$
MessageDialog.openError(//$NON-NLS-1$
button.getShell(), //$NON-NLS-1$
Messages.getString("SchemaTypeController.inputNotSet"), //$NON-NLS-1$
Messages.getString("SchemaTypeController.connectionNotAvaliable"));
return null;
}
IMetadataTable originaleMetadataTable = getMetadataTableFromXml(node);
// check if the outputMetadata is readonly
IMetadataTable originaleOutputTable = node.getMetadataFromConnector(param.getContext());
IMetadataTable outputMetaCopy = originaleOutputTable.clone();
for (IMetadataColumn column : originaleOutputTable.getListColumns()) {
IMetadataColumn columnCopied = outputMetaCopy.getColumn(column.getLabel());
columnCopied.setCustom(column.isCustom());
columnCopied.setReadOnly(column.isReadOnly());
}
outputMetaCopy.setReadOnly(originaleOutputTable.isReadOnly() || param.isReadOnly(node.getElementParametersWithChildrens()));
outputMetaCopy.sortCustomColumns();
// create the MetadataDialog
MetadataDialog metaDialog = null;
if (inputMetadata != null) {
if (inputInfos != null && inputInfos.size() > 1 && connectionName == null) {
MetadataDialogForMerge metaDialogForMerge = new MetadataDialogForMerge(composite.getShell(), inputInfos, outputMetaCopy, node, getCommandStack());
//$NON-NLS-1$
metaDialogForMerge.setText(Messages.getString("SchemaController.schemaOf") + node.getLabel());
metaDialogForMerge.setInputReadOnly(inputReadOnly);
metaDialogForMerge.setOutputReadOnly(outputReadOnly);
if (metaDialogForMerge.open() == MetadataDialogForMerge.OK) {
outputMetaCopy = metaDialogForMerge.getOutputMetaData();
// check if the metadata is modified
boolean modified = false;
if (!outputMetaCopy.sameMetadataAs(originaleOutputTable, IMetadataColumn.OPTIONS_NONE)) {
modified = true;
} else {
if (inputMetadata != null) {
// Notice: the Map inputInfos maybe is modified by the dialog.
Set<INode> inputNodes = inputInfos.keySet();
for (INode inputNode : inputNodes) {
Map<IMetadataTable, Boolean> oneInput = inputInfos.get(inputNode);
inputMetaCopy = (IMetadataTable) oneInput.keySet().toArray()[0];
if (!inputMetaCopy.sameMetadataAs(inputNode.getMetadataList().get(0), IMetadataColumn.OPTIONS_NONE)) {
modified = true;
}
}
}
}
// create the changeMetadataCommand
if (modified) {
Command changeMetadataCommand = null;
// only output, no input
if (inputInfos.isEmpty()) {
changeMetadataCommand = new ChangeMetadataCommand(node, param, null, null, null, originaleOutputTable, outputMetaCopy);
} else {
Set<INode> inputNodes = inputInfos.keySet();
int count = 0;
for (INode inputNode : inputNodes) {
Map<IMetadataTable, Boolean> oneInput = inputInfos.get(inputNode);
inputMetaCopy = (IMetadataTable) oneInput.keySet().toArray()[0];
if (count == 0) {
changeMetadataCommand = new ChangeMetadataCommand(node, param, inputNode, inputNode.getMetadataList().get(0), inputMetaCopy, originaleOutputTable, outputMetaCopy);
} else {
changeMetadataCommand = changeMetadataCommand.chain(new ChangeMetadataCommand(node, param, inputNode, inputNode.getMetadataList().get(0), inputMetaCopy, originaleOutputTable, outputMetaCopy));
}
count++;
}
}
return changeMetadataCommand;
}
}
} else {
Node inputNode = (Node) (inputConec.getSource());
if (inputMetaCopy.getAttachedConnector() == null) {
INodeConnector mainConnector;
if (inputNode.isELTComponent()) {
mainConnector = inputNode.getConnectorFromType(EConnectionType.TABLE);
} else {
mainConnector = inputNode.getConnectorFromType(EConnectionType.FLOW_MAIN);
}
inputMetaCopy.setAttachedConnector(mainConnector.getName());
}
metaDialog = new MetadataDialog(composite.getShell(), inputMetaCopy, inputNode, outputMetaCopy, node, getCommandStack());
}
} else {
metaDialog = new MetadataDialog(composite.getShell(), outputMetaCopy, node, getCommandStack());
}
/*
* Datacert: Populating data in the edit schema dialog
*
* @author : virtusa
*/
List<IMetadataColumn> columnList = new ArrayList<IMetadataColumn>();
String prefix = "";
if (componentName.equalsIgnoreCase(Messages.getString("DataCertController.tDataCertDenormalize.componentName"))) {
String denorCol = elem.getPropertyValue("DC_COLUMN_DENORMALIZE").toString().replaceAll("\"", "");
;
prefix = denorCol;
IMetadataTable inputTable = null;
if (node.getIncomingConnections() != null && node.getIncomingConnections().size() > 0) {
IConnection inputConn = node.getIncomingConnections().get(0);
if (inputConn != null) {
inputTable = inputConn.getMetadataTable();
}
}
if (inputTable != null) {
for (IMetadataColumn inCol : inputTable.getListColumns()) {
if (!inCol.getLabel().equals(denorCol)) {
columnList.add(inCol);
}
}
}
}
restService.addColumnsToSchema(entityName, componentName, prefix, columnList);
outputMetaCopy.setListColumns(columnList);
outputMetaCopy.setComment("Attribute Metadata");
outputMetaCopy.setLabel("Attribute Metadata");
outputMetaCopy.setTableName(entityName);
if (metaDialog != null) {
//$NON-NLS-1$
metaDialog.setText(Messages.getString("AbstractSchemaController.schema.title", node.getLabel()));
metaDialog.setInputReadOnly(false);
metaDialog.setOutputReadOnly(false);
if (metaDialog.open() == MetadataDialog.OK) {
outputMetaCopy = metaDialog.getOutputMetaData();
boolean modified = false;
if (!outputMetaCopy.sameMetadataAs(originaleOutputTable, IMetadataColumn.OPTIONS_NONE)) {
modified = true;
}
if (modified) {
Node inputNode = null;
if (inputConec != null) {
inputNode = (Node) inputConec.getSource();
}
ChangeMetadataCommand changeMetadataCommand = new ChangeMetadataCommand(node, param, inputNode, inputMetadata, inputMetaCopy, originaleOutputTable, outputMetaCopy);
return changeMetadataCommand;
}
}
}
return null;
}
use of org.talend.core.model.metadata.IMetadataColumn in project tdi-studio-se by Talend.
the class GuessSchemaController method findSameNamedColumnAndReplaceTheIndex.
private void findSameNamedColumnAndReplaceTheIndex(List<Integer> indexsForSameNamedColumn, int i, IMetadataColumn oneColum, String labelName) {
boolean findSameNameColumn = false;
boolean hasMax = false;
for (IMetadataColumn exsitingOneColumn : columns) {
boolean hasIndex = false;
String[] allseg = exsitingOneColumn.getLabel().split("_");
String name = "";
String priorIndex = allseg[allseg.length - 1];
if (isNumeric(priorIndex)) {
hasIndex = true;
for (int j = 0; j < allseg.length - 1; j++) {
if (j != allseg.length - 2) {
name = name + allseg[j] + "_";
} else {
name = name + allseg[j];
}
}
}
if (exsitingOneColumn.getLabel() != null && exsitingOneColumn.getLabel().split("_").length > 1 && hasIndex) {
if (name.equals(MetadataToolHelper.validateColumnName(labelName, i))) {
findSameNameColumn = true;
indexsForSameNamedColumn.add(Integer.parseInt(priorIndex));
}
} else if (exsitingOneColumn.getLabel().equals(MetadataToolHelper.validateColumnName(labelName, i))) {
findSameNameColumn = true;
}
}
Integer[] indexsarray = indexsForSameNamedColumn.toArray(new Integer[0]);
if (indexsarray.length > 0) {
Arrays.sort(indexsarray);
hasMax = true;
}
if (findSameNameColumn && hasMax) {
int nextIndex = ++indexsarray[indexsarray.length - 1];
oneColum.setLabel(MetadataToolHelper.validateColumnName(labelName + "_" + Integer.toString(nextIndex), i));
} else if (findSameNameColumn) {
oneColum.setLabel(MetadataToolHelper.validateColumnName(labelName + "_" + Integer.toString(1), i));
} else {
oneColum.setLabel(MetadataToolHelper.validateColumnName(labelName, i));
}
}
use of org.talend.core.model.metadata.IMetadataColumn in project tdi-studio-se by Talend.
the class DbGenerationManager method initExpression.
protected String initExpression(DbMapComponent component, ExternalDbMapEntry dbMapEntry) {
String expression = dbMapEntry.getExpression();
if (expression != null) {
List<Map<String, String>> itemNameList = null;
// MapExpressionParser mapParser = new MapExpressionParser("((\\s*(\\w+)\\s*\\.)*)(\\w+)");
// List<String> parseInTableEntryLocations = mapParser.parseInTableEntryLocations2(expression);
// for (String entryLocation : parseInTableEntryLocations) {
//
// }
// context.schema.context.table.column
// context.schema.table.column
// schema.context.table.column
// schema.table.column
// table.column
// add \\w*#* for oracle 12 , schema name start with C##
//$NON-NLS-1$
MapExpressionParser mapParser1 = new MapExpressionParser("((\\s*(\\w*#*\\w+)\\s*\\.)*)(\\w+)");
itemNameList = mapParser1.parseInTableEntryLocations2(expression);
if (itemNameList == null || itemNameList.isEmpty()) {
//$NON-NLS-1$
MapExpressionParser mapParser2 = new MapExpressionParser("\\s*(\\w+)\\s*\\.\\s*(\\w+)\\s*");
itemNameList = mapParser2.parseInTableEntryLocations(expression);
}
for (Map<String, String> itemNamemap : itemNameList) {
Set<Entry<String, String>> set = itemNamemap.entrySet();
Iterator<Entry<String, String>> ite = set.iterator();
while (ite.hasNext()) {
Entry<String, String> entry = ite.next();
String columnValue = entry.getKey();
String tableValue = entry.getValue();
String tableNameValue = tableValue;
// find original table name if tableValue is alias
String originaltableName = tableValue;
ExternalDbMapData externalData = (ExternalDbMapData) component.getExternalData();
final List<ExternalDbMapTable> inputTables = externalData.getInputTables();
for (ExternalDbMapTable inputTable : inputTables) {
if (inputTable.getAlias() != null && inputTable.getAlias().equals(tableValue)) {
originaltableName = inputTable.getTableName();
tableNameValue = inputTable.getAlias();
}
}
List<IConnection> inputConnections = (List<IConnection>) component.getIncomingConnections();
if (inputConnections == null) {
return expression;
}
for (IConnection iconn : inputConnections) {
IMetadataTable metadataTable = iconn.getMetadataTable();
String tName = iconn.getName();
if ((originaltableName.equals(tName) || tableValue.equals(tName)) && metadataTable != null) {
List<IMetadataColumn> lColumn = metadataTable.getListColumns();
String tableName = metadataTable.getTableName();
String tableColneName = tableName;
tableColneName = MetadataToolHelper.validateTableName(tableColneName);
if (tableValue.contains(".") && tableName != null) {
//$NON-NLS-1$
//$NON-NLS-1$
MapExpressionParser mapParser2 = new MapExpressionParser("\\s*(\\w+)\\s*\\.\\s*(\\w+)\\s*");
List<Map<String, String>> tableNameList = mapParser2.parseInTableEntryLocations(tableValue);
for (Map<String, String> tableNameMap : tableNameList) {
Set<Entry<String, String>> setTable = tableNameMap.entrySet();
Iterator<Entry<String, String>> iteTable = setTable.iterator();
while (iteTable.hasNext()) {
Entry<String, String> tableEntry = iteTable.next();
String tableLabel = tableEntry.getKey();
String schemaValue = tableEntry.getValue();
if (tableLabel.equals(metadataTable.getLabel()) && tableColneName.equals(tableLabel)) {
//$NON-NLS-1$//$NON-NLS-2$
tableName = tableName.replaceAll("\\$", "\\\\\\$");
//$NON-NLS-1$
expression = expression.replaceFirst(tableValue, schemaValue + "." + tableName);
}
}
}
} else if (tableName != null) {
if (tableValue.equals(metadataTable.getLabel()) && tableColneName.equals(tableValue)) {
//$NON-NLS-1$ //$NON-NLS-2$
tableName = tableName.replaceAll("\\$", "\\\\\\$");
expression = expression.replaceFirst(tableValue, tableName);
}
}
for (IMetadataColumn co : lColumn) {
if (columnValue.equals(co.getLabel())) {
String oriName = co.getOriginalDbColumnName();
// if OriginalDbColumn is empty , still use label to generate sql
if (oriName == null || "".equals(oriName)) {
//$NON-NLS-1$
continue;
}
if (expression.trim().equals(tableValue + "." + oriName)) {
continue;
}
if (expression.trim().equals(originaltableName + "." + oriName)) {
continue;
}
// if it is temp delived table, use label to generate sql
if (iconn.getLineStyle() == EConnectionType.TABLE_REF) {
continue;
}
//$NON-NLS-1$ //$NON-NLS-2$
oriName = oriName.replaceAll("\\$", "\\\\\\$");
expression = //$NON-NLS-1$
expression.replaceFirst(//$NON-NLS-1$
"\\." + co.getLabel(), //$NON-NLS-1$
"\\." + oriName);
expression = expression.replace("\"", "\\\"");
}
}
}
}
}
}
}
return expression;
}
use of org.talend.core.model.metadata.IMetadataColumn in project tdi-studio-se by Talend.
the class DbGenerationManager method getOriginalColumnName.
private String getOriginalColumnName(String entryName, DbMapComponent component, ExternalDbMapTable table) {
List<IConnection> inputConnections = (List<IConnection>) component.getIncomingConnections();
if (inputConnections != null) {
for (IConnection iconn : inputConnections) {
IMetadataTable metadataTable = iconn.getMetadataTable();
String tName = iconn.getName();
String tableValue = table.getTableName();
if (tableValue != null && tableValue.equals(tName) && metadataTable != null) {
List<IMetadataColumn> lColumn = metadataTable.getListColumns();
for (IMetadataColumn colu : lColumn) {
if (colu.getLabel().equals(entryName)) {
String tempName = colu.getOriginalDbColumnName();
if (tempName != null && tempName.length() > 0) {
entryName = tempName;
return entryName;
}
}
}
}
}
}
return entryName;
}
use of org.talend.core.model.metadata.IMetadataColumn in project tdi-studio-se by Talend.
the class DbGenerationManager method removeUnmatchingEntriesWithColumnsOfMetadataTable.
/**
* DOC amaumont Comment method "removeUnmatchingEntriesWithColumnsOfMetadataTable".
*
* @param outputTable
* @param metadataTable
*/
protected ExternalDbMapTable removeUnmatchingEntriesWithColumnsOfMetadataTable(ExternalDbMapTable externalDbMapTable, IMetadataTable metadataTable) {
ExternalDbMapTable clonedTable = null;
try {
clonedTable = (ExternalDbMapTable) externalDbMapTable.clone();
} catch (CloneNotSupportedException e) {
ExceptionHandler.process(e);
}
List<ExternalDbMapEntry> metadataTableEntries = clonedTable.getMetadataTableEntries();
if (metadataTableEntries != null) {
HashMap<String, IMetadataColumn> hNameToColumn = new HashMap<String, IMetadataColumn>();
List<IMetadataColumn> listColumns = metadataTable.getListColumns();
for (IMetadataColumn column : listColumns) {
hNameToColumn.put(column.getLabel(), column);
}
List<ExternalDbMapEntry> dbMapEntriesToRemove = new ArrayList<ExternalDbMapEntry>();
for (ExternalDbMapEntry externalTableEntry : metadataTableEntries) {
String entryName = externalTableEntry.getName();
IMetadataColumn column = hNameToColumn.get(entryName);
if (column == null) {
dbMapEntriesToRemove.add(externalTableEntry);
}
}
metadataTableEntries.removeAll(dbMapEntriesToRemove);
}
return clonedTable;
}
Aggregations