use of org.talend.core.model.metadata.IMetadataColumn in project tdi-studio-se by Talend.
the class SchemaReferenceController method createButtonCommand.
@Override
protected Command createButtonCommand(Button button) {
if (checkForRepositoryShema(button)) {
return null;
}
Button inputButton = button;
IElementParameter switchParam = elem.getElementParameter(EParameterName.REPOSITORY_ALLOW_AUTO_SWITCH.getName());
if (inputButton.getData(NAME).equals(SCHEMA)) {
// this map wil hold the all input connection for the tUnite component
Map<INode, Map<IMetadataTable, Boolean>> inputInfos = new HashMap<INode, Map<IMetadataTable, Boolean>>();
INode node;
if (elem instanceof Node) {
node = (INode) elem;
} else {
// else instanceof Connection
node = ((IConnection) elem).getSource();
}
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();
}
Object obj = button.getData(FORCE_READ_ONLY);
boolean forceReadOnly = false;
if (obj != null) {
forceReadOnly = (Boolean) obj;
}
boolean inputReadOnly = false, outputReadOnly = false, inputReadOnlyNode = false, inputReadOnlyParam = false;
for (Connection connec : (List<Connection>) node.getIncomingConnections()) {
if (connec.isActivate() && (connec.getLineStyle().equals(EConnectionType.FLOW_MAIN) || connec.getLineStyle().equals(EConnectionType.TABLE) || connec.getLineStyle().equals(EConnectionType.FLOW_MERGE) || connec.getLineStyle() == EConnectionType.FLOW_REF)) {
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_REFERENCE) {
if (curParam.isReadOnly()) {
inputReadOnlyParam = true;
}
}
}
}
// check if the inputMetadata is readonly
if (inputMetadata != null) {
for (IMetadataColumn column : inputMetadata.getListColumns(true)) {
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("SchemaReferenceController.inputNotSet"), //$NON-NLS-1$
Messages.getString("SchemaReferenceController.connectionNotAvaliable"));
return null;
}
IMetadataTable originaleMetadataTable = getMetadataTableFromXml(node);
// check if the outputMetadata is readonly
IMetadataTable originaleOutputTable = node.getMetadataFromConnector(param.getContext());
// when several schema_type button ,need get the right one which is opening
//$NON-NLS-1$
IElementParameter schemaParam = param.getChildParameters().get("SCHEMA_TYPE");
// need setRepository here
if (!param.getContext().equals(schemaParam.getContext())) {
//$NON-NLS-1$
schemaParam = param.getChildParameters().get("SCHEMA_TYPE");
}
if (schemaParam != null && EmfComponent.REPOSITORY.equals(schemaParam.getValue())) {
if (originaleOutputTable != null && originaleOutputTable instanceof MetadataTable) {
((MetadataTable) originaleOutputTable).setRepository(true);
}
} else if (schemaParam != null && EmfComponent.BUILTIN.equals(schemaParam.getValue())) {
if (originaleOutputTable != null && originaleOutputTable instanceof MetadataTable) {
((MetadataTable) originaleOutputTable).setRepository(false);
}
}
IMetadataTable outputMetaCopy = originaleOutputTable.clone(true);
for (IMetadataColumn column : originaleOutputTable.getListColumns(true)) {
IMetadataColumn columnCopied = outputMetaCopy.getColumn(column.getLabel());
columnCopied.setCustom(column.isCustom());
columnCopied.setReadOnly(column.isReadOnly());
}
outputMetaCopy.setReadOnly(originaleOutputTable.isReadOnly() || param.isReadOnly(node.getElementParametersWithChildrens()));
//$NON-NLS-1$
IElementParameter schemaTypeParam = param.getChildParameters().get("SCHEMA_TYPE");
List<IElementParameterDefaultValue> defaultValues = schemaTypeParam.getDefaultValues();
for (IElementParameterDefaultValue elementParameterDefaultValue : defaultValues) {
if (elementParameterDefaultValue.getDefaultValue() instanceof MetadataTable) {
MetadataTable table = (MetadataTable) elementParameterDefaultValue.getDefaultValue();
outputMetaCopy.setReadOnlyColumnPosition(table.getReadOnlyColumnPosition());
break;
}
}
outputMetaCopy.sortCustomColumns();
if (!forceReadOnly) {
outputReadOnly = prepareReadOnlyTable(outputMetaCopy, param.isReadOnly(), node.isReadOnly());
} else {
outputReadOnly = true;
}
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("SchemaReferenceController.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) {
if (switchParam != null) {
switchParam.setValue(Boolean.FALSE);
}
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 {
INode inputNode = (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());
}
if (metaDialog != null) {
//$NON-NLS-1$
metaDialog.setText(Messages.getString("SchemaReferenceController.schema.title", node.getLabel()));
metaDialog.setInputReadOnly(inputReadOnly);
metaDialog.setOutputReadOnly(outputReadOnly);
if (metaDialog.open() == MetadataDialog.OK) {
inputMetaCopy = metaDialog.getInputMetaData();
outputMetaCopy = metaDialog.getOutputMetaData();
boolean modified = false;
if (!outputMetaCopy.sameMetadataAs(originaleOutputTable, IMetadataColumn.OPTIONS_NONE)) {
modified = true;
} else {
if (inputMetadata != null) {
if (!inputMetaCopy.sameMetadataAs(inputMetadata, IMetadataColumn.OPTIONS_NONE)) {
modified = true;
}
}
}
if (modified) {
if (switchParam != null) {
switchParam.setValue(Boolean.FALSE);
}
INode inputNode = null;
if (inputConec != null) {
inputNode = inputConec.getSource();
}
// update the component schema
if (param instanceof GenericElementParameter) {
GenericElementParameter genericElementParameter = (GenericElementParameter) param;
String paramName = genericElementParameter.getName();
ComponentProperties componentProperties = node.getComponentProperties();
if (componentProperties != null) {
org.talend.daikon.properties.property.Property schemaProperty = componentProperties.getValuedProperty(paramName);
if (schemaProperty != null) {
SchemaUtils.updateComponentSchema(node, outputMetaCopy, null);
}
}
}
if (node.getComponent().isSchemaAutoPropagated()) {
ChangeMetadataCommand changeMetadataCommand = new ChangeMetadataCommand(node, param, inputNode, inputMetadata, inputMetaCopy, originaleOutputTable, outputMetaCopy);
return changeMetadataCommand;
} else {
ChangeMetadataCommand changeMetadataCommand = new ChangeMetadataCommand(node, param, inputNode, inputMetadata, inputMetaCopy, originaleOutputTable, outputMetaCopy);
changeMetadataCommand.setPropagate(Boolean.FALSE);
return changeMetadataCommand;
}
}
}
}
} else if (inputButton.getData(NAME).equals(RETRIEVE_SCHEMA)) {
Node node = (Node) elem;
// String propertyName = (String) inputButton.getData(PARAMETER_NAME);
final Command cmd = RetrieveSchemaHelper.retrieveSchemasCommand(node);
if (switchParam != null) {
switchParam.setValue(Boolean.FALSE);
}
return cmd;
} else if (inputButton.getData(NAME).equals(RESET_COLUMNS)) {
Node node = (Node) elem;
String propertyName = (String) inputButton.getData(PARAMETER_NAME);
IElementParameter param = node.getElementParameter(propertyName);
final Command cmd = SynchronizeSchemaHelper.createCommand(node, param);
if (switchParam != null) {
switchParam.setValue(Boolean.FALSE);
}
return cmd;
} else if (button.getData(NAME).equals(REPOSITORY_CHOICE)) {
String paramName = (String) button.getData(PARAMETER_NAME);
IElementParameter schemaParam = elem.getElementParameter(paramName);
ERepositoryObjectType type = ERepositoryObjectType.METADATA_CON_TABLE;
String filter = schemaParam.getFilter();
RepositoryReviewDialog dialog = new RepositoryReviewDialog(button.getShell(), type, filter);
if (dialog.open() == RepositoryReviewDialog.OK) {
RepositoryNode node = dialog.getResult();
while (node.getObject().getProperty().getItem() == null || (!(node.getObject().getProperty().getItem() instanceof ConnectionItem))) {
node = node.getParent();
}
IRepositoryViewObject object = dialog.getResult().getObject();
Property property = object.getProperty();
String id = property.getId();
// The name is Table Name.
String name = object.getLabel();
if (name != null) {
if (elem instanceof Node) {
//$NON-NLS-1$
String value = id + " - " + name;
//$NON-NLS-1$
paramName = paramName + ":" + EParameterName.REPOSITORY_SCHEMA_TYPE.getName();
Command selectorCommand = new PropertyChangeCommand(elem, paramName, TalendTextUtils.addQuotes(value));
executeCommand(selectorCommand);
}
}
//$NON-NLS-1$
String value = id + " - " + name;
//$NON-NLS-1$
String fullParamName = paramName + ":" + getRepositoryChoiceParamName();
org.talend.core.model.metadata.builder.connection.Connection connection = null;
if (elem instanceof Node) {
IMetadataTable repositoryMetadata = MetadataToolHelper.getMetadataFromRepository(value);
connection = MetadataToolHelper.getConnectionFromRepository(value);
// For validation rule.
boolean isValRulesLost = false;
IRepositoryViewObject currentValRuleObj = ValidationRulesUtil.getCurrentValidationRuleObjs(elem);
if (currentValRuleObj != null) {
List<IRepositoryViewObject> valRuleObjs = ValidationRulesUtil.getRelatedValidationRuleObjs(value);
if (!ValidationRulesUtil.isCurrentValRuleObjInList(valRuleObjs, currentValRuleObj)) {
if (!MessageDialog.openConfirm(button.getShell(), //$NON-NLS-1$
Messages.getString("SchemaReferenceController.validationrule.title.confirm"), Messages.getString("SchemaReferenceController.validationrule.selectMetadataMsg"))) {
//$NON-NLS-1$
return null;
} else {
isValRulesLost = true;
}
}
}
if (repositoryMetadata == null) {
repositoryMetadata = new MetadataTable();
}
if (switchParam != null) {
switchParam.setValue(Boolean.FALSE);
}
CompoundCommand cc = new CompoundCommand();
RepositoryChangeMetadataCommand changeMetadataCommand = new RepositoryChangeMetadataCommand((Node) elem, fullParamName, value, repositoryMetadata, null, null);
changeMetadataCommand.setConnection(connection);
cc.add(changeMetadataCommand);
if (isValRulesLost) {
ValidationRulesUtil.appendRemoveValidationRuleCommands(cc, elem);
}
return cc;
}
}
} else if (button.getData(NAME).equals(COPY_CHILD_COLUMNS)) {
String paramName = (String) button.getData(PARAMETER_NAME);
IElementParameter param = elem.getElementParameter(paramName);
IElementParameter processParam = elem.getElementParameterFromField(EParameterFieldType.PROCESS_TYPE);
IElementParameter processIdParam = processParam.getChildParameters().get(EParameterName.PROCESS_TYPE_PROCESS.getName());
String id = (String) processIdParam.getValue();
Item item = ItemCacheManager.getProcessItem(id);
Node node = (Node) elem;
copySchemaFromChildJob(node, item);
// pop up the schema dialog
MetadataDialog metaDialog = new MetadataDialog(composite.getShell(), node.getMetadataList().get(0), node, getCommandStack());
//$NON-NLS-1$
metaDialog.setText(Messages.getString("SchemaReferenceController.schemaOf") + node.getLabel());
if (metaDialog.open() == MetadataDialog.OK) {
IMetadataTable outputMetaData = metaDialog.getOutputMetaData();
return new ChangeMetadataCommand(node, param, null, outputMetaData);
}
}
return null;
}
use of org.talend.core.model.metadata.IMetadataColumn in project tdi-studio-se by Talend.
the class UpdateNodeParameterCommand method updateSchema.
@SuppressWarnings("unchecked")
private void updateSchema() {
Object updateObject = result.getUpdateObject();
if (updateObject == null) {
return;
}
if (updateObject instanceof Node) {
// opened job
Node node = (Node) updateObject;
boolean builtIn = true;
final IExternalNode externalNode = node.getExternalNode();
if (result.getResultType() == EUpdateResult.UPDATE) {
if (result.isChecked()) {
if (result.getParameter() instanceof List) {
// for ebcdic
if (PluginChecker.isEBCDICPluginLoaded()) {
IEBCDICProviderService service = (IEBCDICProviderService) GlobalServiceRegister.getDefault().getService(IEBCDICProviderService.class);
if (service != null) {
if (service.isEbcdicNode(node)) {
List<Object> parameter = (List<Object>) result.getParameter();
if (parameter.size() >= 2) {
IMetadataTable newTable = (IMetadataTable) parameter.get(0);
String schemaName = (String) parameter.get(1);
IMetadataTable metadataTable = MetadataToolHelper.getMetadataTableFromNodeLabel(node, schemaName);
if (metadataTable != null) {
MetadataToolHelper.copyTable(newTable, metadataTable);
}
syncSchemaForEBCDIC(node, metadataTable);
}
return;
}
}
}
// for tMap
if (GlobalServiceRegister.getDefault().isServiceRegistered(IDesignerMapperService.class)) {
IDesignerMapperService service = (IDesignerMapperService) GlobalServiceRegister.getDefault().getService(IDesignerMapperService.class);
if (service != null && externalNode != null && externalNode.getExternalData() != null) {
List<Object> parameter = (List<Object>) result.getParameter();
if (parameter.size() >= 2) {
if (node.getComponent() != null && "tMap".equals(node.getComponent().getName())) {
//$NON-NLS-1$
IMetadataTable newTable = (IMetadataTable) parameter.get(0);
String schemaId = (String) parameter.get(1);
service.updateMapperTableEntries(externalNode, schemaId, newTable);
node.setMetadataList(externalNode.getMetadataList());
syncSchemaForTMap(node);
// update metadataList,or it will cause bug 21080
for (IExternalMapTable latestTable : externalNode.getExternalData().getOutputTables()) {
for (IMetadataTable tableExsit : node.getMetadataList()) {
// find table,and update the table
if (latestTable.getName().equals(tableExsit.getTableName())) {
List<IMetadataColumn> newColumns = newTable.getListColumns();
for (IMetadataColumn column : tableExsit.getListColumns()) {
for (IMetadataColumn newColumn : newColumns) {
if (tableExsit.getTableName().equals(newTable.getTableName()) && newColumn.getLabel().equals(column.getLabel())) {
column.setTalendType(newColumn.getTalendType());
column.setNullable(newColumn.isNullable());
column.setComment(newColumn.getComment());
column.setDefault(newColumn.getDefault());
column.setLength(newColumn.getLength());
column.setType(newColumn.getType());
column.setKey(newColumn.isKey());
column.setPrecision(newColumn.getPrecision());
break;
}
}
}
break;
}
}
}
}
}
}
}
} else if (result.getParameter() instanceof IMetadataTable) {
IMetadataTable newTable = (IMetadataTable) result.getParameter();
// getListColumns());
if (newTable != null) {
INodeConnector nodeConnector = node.getConnectorFromName(newTable.getAttachedConnector());
// if (nodeConnector.getBaseSchema().equals(newTable.getAttachedConnector())) {
if (nodeConnector != null) {
List<IElementParameter> params = node.getElementParametersFromField(EParameterFieldType.SCHEMA_TYPE);
if (params == null || params.isEmpty()) {
params = node.getElementParametersFromField(EParameterFieldType.SCHEMA_REFERENCE);
}
// node.getElementParameterFromField(EParameterFieldType.SCHEMA_TYPE);
if (params != null) {
for (IElementParameter param : params) {
if (!newTable.getAttachedConnector().equals(param.getContext())) {
continue;
}
ChangeMetadataCommand cmd = null;
if (param.getChildParameters() != null && param.getChildParameters().get("REPOSITORY_SCHEMA_TYPE") != null && result.getContextModeConnectionItem() != null) {
final Object value = param.getChildParameters().get("REPOSITORY_SCHEMA_TYPE").getValue();
// for sap
String remark = result.getRemark();
String namePrefix = "";
if (remark != null) {
String[] split = remark.split(UpdatesConstants.SEGMENT_LINE);
if (split.length == 2) {
String tableName = split[1];
String[] tableSplit = tableName.split("/");
if (tableSplit.length == 3) {
namePrefix = tableSplit[0] + "/" + tableSplit[1] + "/";
}
}
}
String idAndName = result.getContextModeConnectionItem().getProperty().getId() + UpdatesConstants.SEGMENT_LINE + namePrefix + newTable.getLabel();
if (idAndName.equals(value)) {
cmd = new ChangeMetadataCommand(node, param, null, newTable);
}
} else {
cmd = new ChangeMetadataCommand(node, param, null, newTable);
}
if (cmd != null) {
// wzhang added to fix 9251. get the current connection.
String propertyValue = (String) node.getPropertyValue(EParameterName.REPOSITORY_PROPERTY_TYPE.getName());
IRepositoryViewObject lastVersion = UpdateRepositoryUtils.getRepositoryObjectById(propertyValue);
Connection repositoryConn = null;
if (lastVersion != null) {
final Item item = lastVersion.getProperty().getItem();
if (item != null && item instanceof ConnectionItem) {
repositoryConn = ((ConnectionItem) item).getConnection();
}
}
cmd.setConnection(repositoryConn);
if (node.getProcess() instanceof IProcess2) {
IUpdateManager updateManager = ((IProcess2) node.getProcess()).getUpdateManager();
if (updateManager instanceof AbstractUpdateManager) {
cmd.setColumnRenameMap(((AbstractUpdateManager) updateManager).getColumnRenamedMap());
}
}
cmd.setRepositoryMode(true);
cmd.execute(true);
}
}
} else {
MetadataToolHelper.copyTable(newTable, node.getMetadataFromConnector(nodeConnector.getName()));
}
// }
}
builtIn = false;
}
}
}
} else if (result.getResultType() == EUpdateResult.RENAME) {
List<Object> parameter = (List<Object>) result.getParameter();
if (parameter.size() >= 3) {
IMetadataTable newTable = (IMetadataTable) parameter.get(0);
String oldSourceId = (String) parameter.get(1);
String newSourceId = (String) parameter.get(2);
// for ebcdic
if (PluginChecker.isEBCDICPluginLoaded()) {
IEBCDICProviderService service = (IEBCDICProviderService) GlobalServiceRegister.getDefault().getService(IEBCDICProviderService.class);
if (service != null) {
if (service.isEbcdicNode(node)) {
String[] sourceIdAndChildName = UpdateManagerUtils.getSourceIdAndChildName(oldSourceId);
final String oldSchemaName = sourceIdAndChildName[1];
sourceIdAndChildName = UpdateManagerUtils.getSourceIdAndChildName(newSourceId);
final String newSchemaName = sourceIdAndChildName[1];
IMetadataTable metadataTable = MetadataToolHelper.getMetadataTableFromNodeLabel(node, oldSchemaName);
if (metadataTable != null && oldSchemaName != null) {
List<Map<String, Object>> paramValues = (List<Map<String, Object>>) node.getPropertyValue(IEbcdicConstant.TABLE_SCHEMAS);
for (Map<String, Object> line : paramValues) {
if (line.get(IEbcdicConstant.FIELD_SCHEMA).equals(oldSchemaName)) {
line.remove(IEbcdicConstant.FIELD_SCHEMA);
line.put(IEbcdicConstant.FIELD_SCHEMA, newSchemaName);
}
}
PropertyChangeCommand cmd = new PropertyChangeCommand(node, IEbcdicConstant.TABLE_SCHEMAS, paramValues);
cmd.execute();
MetadataToolHelper.copyTable(newTable, metadataTable);
metadataTable.setLabel(newSchemaName);
syncSchemaForEBCDIC(node, metadataTable);
}
}
}
}
// for tmap
if (GlobalServiceRegister.getDefault().isServiceRegistered(IDesignerMapperService.class)) {
IDesignerMapperService service = (IDesignerMapperService) GlobalServiceRegister.getDefault().getService(IDesignerMapperService.class);
if (service != null && externalNode != null && externalNode.getExternalData() != null) {
parameter = (List<Object>) result.getParameter();
if (parameter.size() >= 3) {
if (node.getComponent() != null && "tMap".equals(node.getComponent().getName())) {
//$NON-NLS-1$
newTable = (IMetadataTable) parameter.get(0);
String schemaId = (String) parameter.get(1);
String newSchemaId = (String) parameter.get(2);
service.renameMapperTable(externalNode, schemaId, newSchemaId, newTable);
node.setMetadataList(externalNode.getMetadataList());
syncSchemaForTMap(node);
}
}
}
}
String schemaParamName = UpdatesConstants.SCHEMA + UpdatesConstants.COLON + EParameterName.REPOSITORY_SCHEMA_TYPE.getName();
IElementParameter repositoryParam = node.getElementParameter(schemaParamName);
if (repositoryParam == null) {
schemaParamName = UpdatesConstants.SCHEMA_FLOW + UpdatesConstants.COLON + EParameterName.REPOSITORY_SCHEMA_TYPE.getName();
repositoryParam = node.getElementParameter(schemaParamName);
}
if (repositoryParam == null) {
IElementParameter schemaParentParam = node.getElementParameterFromField(EParameterFieldType.SCHEMA_REFERENCE);
if (schemaParentParam != null) {
schemaParamName = schemaParentParam.getName() + UpdatesConstants.COLON + EParameterName.REPOSITORY_SCHEMA_TYPE.getName();
repositoryParam = node.getElementParameter(schemaParamName);
}
}
if (repositoryParam != null && oldSourceId.equals(repositoryParam.getValue())) {
node.setPropertyValue(schemaParamName, newSourceId);
if (newTable != null) {
for (INodeConnector nodeConnector : node.getListConnector()) {
if (nodeConnector.getBaseSchema().equals(newTable.getAttachedConnector())) {
MetadataToolHelper.copyTable(newTable, node.getMetadataFromConnector(nodeConnector.getName()));
}
}
}
builtIn = false;
}
String inputSchemaParamName = UpdatesConstants.INPUT_SCHEMA + UpdatesConstants.COLON + EParameterName.REPOSITORY_SCHEMA_TYPE.getName();
IElementParameter inputRepositoryParam = node.getElementParameter(inputSchemaParamName);
if (inputRepositoryParam != null && oldSourceId.equals(inputRepositoryParam.getValue())) {
node.setPropertyValue(inputSchemaParamName, newSourceId);
if (newTable != null) {
for (INodeConnector nodeConnector : node.getListConnector()) {
if (nodeConnector.getBaseSchema().equals(newTable.getAttachedConnector())) {
MetadataToolHelper.copyTable(newTable, node.getMetadataFromConnector(nodeConnector.getName()));
}
}
}
builtIn = false;
}
// for tELTAggregate
schemaParamName = UpdatesConstants.SCHEMA_TARGET + UpdatesConstants.COLON + EParameterName.REPOSITORY_SCHEMA_TYPE.getName();
repositoryParam = node.getElementParameter(schemaParamName);
if (repositoryParam != null && oldSourceId.equals(repositoryParam.getValue())) {
node.setPropertyValue(schemaParamName, newSourceId);
if (newTable != null) {
for (INodeConnector nodeConnector : node.getListConnector()) {
if (nodeConnector.getBaseSchema().equals(repositoryParam.getContext())) {
MetadataToolHelper.copyTable(newTable, node.getMetadataFromConnector(nodeConnector.getName()));
}
}
}
builtIn = false;
}
}
} else if (result.getResultType() == EUpdateResult.BUIL_IN) {
// for tELTAgrregate
if (UpdatesConstants.SCHEMA_TARGET.equals(result.getParameter())) {
node.setPropertyValue(UpdatesConstants.SCHEMA_TARGET + ":" + EParameterName.SCHEMA_TYPE.getName(), EmfComponent.BUILTIN);
} else {
// for ebcdic
if (PluginChecker.isEBCDICPluginLoaded()) {
IEBCDICProviderService service = (IEBCDICProviderService) GlobalServiceRegister.getDefault().getService(IEBCDICProviderService.class);
if (service != null) {
if (service.isEbcdicNode(node)) {
Object parameter = result.getParameter();
if (parameter instanceof Map) {
Map<String, Object> lineValue = (Map<String, Object>) parameter;
lineValue.remove(IEbcdicConstant.FIELD_SCHEMA + IEbcdicConstant.REF_TYPE);
}
// since it is a build-in ebcdic,should change its property before return
node.setPropertyValue(EParameterName.SCHEMA_TYPE.getName(), EmfComponent.BUILTIN);
return;
}
}
}
if (PluginChecker.isJobLetPluginLoaded()) {
IJobletProviderService service = (IJobletProviderService) GlobalServiceRegister.getDefault().getService(IJobletProviderService.class);
if (service != null && service.isJobletInOutComponent(node)) {
node.setPropertyValue(EParameterName.SCHEMA_TYPE.getName() + ":" + EParameterName.SCHEMA_TYPE.getName(), EmfComponent.BUILTIN);
}
}
node.setPropertyValue(EParameterName.SCHEMA_TYPE.getName(), EmfComponent.BUILTIN);
for (IElementParameter param : node.getElementParameters()) {
SAPParametersUtils.setNoRepositoryParams(param);
}
}
} else if (result.getResultType() == EUpdateResult.DELETE) {
node.setPropertyValue(EParameterName.SCHEMA_TYPE.getName(), EmfComponent.BUILTIN);
} else if (result.getResultType() == EUpdateResult.RELOAD) {
List<Object> parameter = (List<Object>) result.getParameter();
String connectionId = null;
String tableLabel = null;
IRepositoryViewObject toReload = null;
IMetadataTable tableToReload = null;
if (parameter instanceof List) {
List listParameter = parameter;
connectionId = (String) node.getPropertyValue(EParameterName.REPOSITORY_PROPERTY_TYPE.getName());
tableLabel = ((String) listParameter.get(0)).split(UpdatesConstants.SEGMENT_LINE)[0];
}
if (connectionId != null) {
try {
toReload = ProxyRepositoryFactory.getInstance().getLastVersion(connectionId);
} catch (PersistenceException e) {
ExceptionHandler.process(e);
}
}
if (toReload != null) {
Set<MetadataTable> newTables = null;
Item item = toReload.getProperty().getItem();
if (item instanceof DatabaseConnectionItem) {
DatabaseConnectionItem dbItem = (DatabaseConnectionItem) item;
Connection connection = dbItem.getConnection();
if (connection instanceof DatabaseConnection) {
DatabaseConnection dbConn = (DatabaseConnection) connection;
Set<MetadataTable> tables = ProjectNodeHelper.getTablesFromSpecifiedDataPackage(dbConn);
if (tables != null && !tables.isEmpty()) {
Iterator it = tables.iterator();
while (it.hasNext() && tableToReload == null) {
MetadataTable table = (MetadataTable) it.next();
String label = table.getLabel();
if (tableLabel != null) {
if (label != null && label.equals(tableLabel)) {
tableToReload = ConvertionHelper.convert(table);
break;
}
}
}
}
newTables = ConnectionHelper.getTables(connection);
}
} else {
IGenericWizardService wizardService = null;
if (GlobalServiceRegister.getDefault().isServiceRegistered(IGenericWizardService.class)) {
wizardService = (IGenericWizardService) GlobalServiceRegister.getDefault().getService(IGenericWizardService.class);
}
if (wizardService != null && wizardService.isGenericItem(item)) {
Connection connection = ((ConnectionItem) item).getConnection();
List<MetadataTable> metadataTables = wizardService.getMetadataTables(connection);
newTables = new HashSet<>(metadataTables);
}
}
if (newTables != null && !newTables.isEmpty() && tableToReload == null) {
Iterator<MetadataTable> it = newTables.iterator();
while (it.hasNext() && tableToReload == null) {
MetadataTable table = it.next();
String label = table.getLabel();
if (tableLabel != null) {
if (label != null && label.equals(tableLabel)) {
tableToReload = ConvertionHelper.convert(table);
break;
}
}
}
}
if (tableToReload != null) {
int index = -1;
List<IMetadataTable> tablesInNode = node.getMetadataList();
for (IMetadataTable table : tablesInNode) {
if (table.getLabel().equals(tableToReload.getLabel())) {
index = tablesInNode.indexOf(table);
break;
}
}
if (index >= 0) {
IMetadataTable oldTable = tablesInNode.get(index);
/* dbms and Connector should be transfer when reloaded the table,20024 */
tableToReload.setAttachedConnector(oldTable.getAttachedConnector());
tableToReload.setDbms(oldTable.getDbms());
tablesInNode.remove(index);
tablesInNode.add(index, tableToReload);
builtIn = false;
}
}
}
}
// bug 23326
if (builtIn) {
// bult-in
node.setPropertyValue(EParameterName.SCHEMA_TYPE.getName(), EmfComponent.BUILTIN);
}
}
}
use of org.talend.core.model.metadata.IMetadataColumn in project tdi-studio-se by Talend.
the class EntryContentProposal method getDescription.
/*
* (non-Javadoc)
*
* @see org.eclipse.jface.fieldassist.IContentProposal#getDescription()
*/
public String getDescription() {
StringBuilder sb = new StringBuilder();
//$NON-NLS-1$
String separator = " - ";
if (entry instanceof InputColumnTableEntry) {
InputColumnTableEntry inputEntry = (InputColumnTableEntry) entry;
IMetadataColumn metadataColumn = inputEntry.getMetadataColumn();
//$NON-NLS-1$ //$NON-NLS-2$
sb.append(Messages.getString("EntryContentProposal.metadataColumn")).append(" '").append(metadataColumn.getLabel()).append(//$NON-NLS-1$
"' ");
//$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
sb.append(Messages.getString("EntryContentProposal.properties"));
sb.append(DbLanguageConstants.CARRIAGE_RETURN);
//$NON-NLS-1$
sb.append(separator).append(Messages.getString("EntryContentProposal.column")).append(metadataColumn.getLabel());
sb.append(DbLanguageConstants.CARRIAGE_RETURN);
//$NON-NLS-1$
sb.append(separator).append(Messages.getString("EntryContentProposal.key")).append(metadataColumn.isKey());
if (!MapperMain.isStandAloneMode()) {
sb.append(DbLanguageConstants.CARRIAGE_RETURN);
sb.append(separator).append(Messages.getString("EntryContentProposal.type")).append(//$NON-NLS-1$
format(metadataColumn.getTalendType()));
}
sb.append(DbLanguageConstants.CARRIAGE_RETURN);
sb.append(separator).append(Messages.getString("EntryContentProposal.dbType")).append(//$NON-NLS-1$
format(metadataColumn.getType()));
sb.append(DbLanguageConstants.CARRIAGE_RETURN);
//$NON-NLS-1$
sb.append(separator).append(Messages.getString("EntryContentProposal.length"));
if (metadataColumn.getLength() != null && metadataColumn.getLength() > 0) {
sb.append(format(metadataColumn.getLength()));
}
sb.append(DbLanguageConstants.CARRIAGE_RETURN);
//$NON-NLS-1$
sb.append(separator).append(Messages.getString("EntryContentProposal.precision"));
if (metadataColumn.getPrecision() != null && metadataColumn.getPrecision() > 0) {
sb.append(format(metadataColumn.getPrecision()));
}
sb.append(DbLanguageConstants.CARRIAGE_RETURN);
sb.append(separator).append(Messages.getString("EntryContentProposal.default")).append(//$NON-NLS-1$
format(metadataColumn.getDefault()));
sb.append(DbLanguageConstants.CARRIAGE_RETURN);
sb.append(separator).append(Messages.getString("EntryContentProposal.comment")).append(//$NON-NLS-1$
format(metadataColumn.getComment()));
sb.append(DbLanguageConstants.CARRIAGE_RETURN);
//$NON-NLS-1$
sb.append(separator).append(Messages.getString("EntryContentProposal.expressionKey"));
sb.append(DbLanguageConstants.CARRIAGE_RETURN);
sb.append(format(entry.getExpression()));
sb.append(DbLanguageConstants.CARRIAGE_RETURN);
} else if (entry instanceof VarTableEntry) {
//$NON-NLS-1$//$NON-NLS-2$ //$NON-NLS-3$
sb.append(Messages.getString("EntryContentProposal.variable")).append(" '").append(entry.getName()).append("' :");
sb.append(DbLanguageConstants.CARRIAGE_RETURN);
//$NON-NLS-1$
sb.append(separator).append(Messages.getString("EntryContentProposal.expressionKey"));
sb.append(DbLanguageConstants.CARRIAGE_RETURN);
sb.append(format(entry.getExpression()));
}
return sb.toString();
}
use of org.talend.core.model.metadata.IMetadataColumn in project tdi-studio-se by Talend.
the class DesignerMapperService method createAutoMappedNode.
public void createAutoMappedNode(INode node, IConnection inputConnection, IConnection outputConnection) {
MapperData data = (MapperData) node.getExternalNode().getExternalEmfData();
data.setUiProperties(MapperFactory.eINSTANCE.createUiProperties());
data.getUiProperties().setShellMaximized(true);
data.getInputTables().clear();
InputTable inputTable = MapperFactory.eINSTANCE.createInputTable();
data.getInputTables().add(inputTable);
inputTable.setName(inputConnection.getName());
for (IMetadataColumn column : inputConnection.getMetadataTable().getListColumns()) {
MapperTableEntry tableEntry = MapperFactory.eINSTANCE.createMapperTableEntry();
tableEntry.setName(column.getLabel());
tableEntry.setType(column.getTalendType());
tableEntry.setNullable(column.isNullable());
inputTable.getMapperTableEntries().add(tableEntry);
}
data.getOutputTables().clear();
OutputTable outputTable = MapperFactory.eINSTANCE.createOutputTable();
data.getOutputTables().add(outputTable);
outputTable.setName(outputConnection.getName());
for (IMetadataColumn column : outputConnection.getMetadataTable().getListColumns()) {
MapperTableEntry tableEntry = MapperFactory.eINSTANCE.createMapperTableEntry();
tableEntry.setName(column.getLabel());
tableEntry.setType(column.getTalendType());
tableEntry.setNullable(column.isNullable());
tableEntry.setExpression(inputConnection.getName() + "." + column.getLabel());
outputTable.getMapperTableEntries().add(tableEntry);
}
((MapperComponent) node.getExternalNode()).buildExternalData(data);
}
use of org.talend.core.model.metadata.IMetadataColumn in project tdi-studio-se by Talend.
the class DesignerMapperService method updateEntriesByMetaColumns.
private void updateEntriesByMetaColumns(String schemaId, IMetadataTable metadataTable, ExternalMapperTable table, MapperComponent component) {
String id = table.getId();
if (schemaId.equals(id)) {
List<ExternalMapperTableEntry> mapperTableEntries = table.getMetadataTableEntries();
List<ExternalMapperTableEntry> newTableEntries = new ArrayList<ExternalMapperTableEntry>();
/* bug 21080 */
for (ExternalMapperTableEntry oldEntry : mapperTableEntries) {
String expression = oldEntry.getExpression();
String columnname = oldEntry.getName();
if (expression != null) {
oldMappingMap.put(columnname, expression);
}
}
List<IMetadataColumn> columns = metadataTable.getListColumns();
if (columns != null) {
for (IMetadataColumn metadataColumn : columns) {
ExternalMapperTableEntry tableEntry = new ExternalMapperTableEntry();
tableEntry.setName(metadataColumn.getLabel());
tableEntry.setType(metadataColumn.getTalendType());
tableEntry.setNullable(metadataColumn.isNullable());
ExternalMapperTableEntry sameEntry = null;
for (ExternalMapperTableEntry oldEntry : mapperTableEntries) {
if (oldEntry.getName().equals(metadataColumn.getLabel())) {
sameEntry = oldEntry;
}
}
if (sameEntry != null) {
tableEntry.setExpression(sameEntry.getExpression());
tableEntry.setOperator(sameEntry.getOperator());
String oldExpression = oldMappingMap.get(tableEntry.getName());
if (oldExpression != null) {
tableEntry.setExpression(oldExpression);
}
}
newTableEntries.add(tableEntry);
}
}
mapperTableEntries.clear();
table.setMetadataTableEntries(newTableEntries);
final IMetadataTable mapperTabel = getMetadataTable(component, table.getName());
if (mapperTabel != null) {
if (mapperTabel.getListColumns() != null) {
mapperTabel.getListColumns().clear();
mapperTabel.getListColumns().addAll(metadataTable.getListColumns());
} else {
mapperTabel.setListColumns(metadataTable.getListColumns());
}
}
}
oldMappingMap.clear();
}
Aggregations