use of org.talend.core.model.metadata.IMetadataTable in project tdi-studio-se by Talend.
the class SapSchemaTypeController method createComboCommand.
/*
* (non-Javadoc)
*
* @see
* org.talend.designer.core.ui.editor.properties.controllers.AbstractRepositoryController#createComboCommand(org
* .eclipse.swt.custom.CCombo)
*/
@Override
protected Command createComboCommand(CCombo combo) {
IMetadataTable repositoryMetadata = null;
String fullParamName = (String) combo.getData(PARAMETER_NAME);
IElementParameter switchParam = elem.getElementParameter(EParameterName.REPOSITORY_ALLOW_AUTO_SWITCH.getName());
//$NON-NLS-1$
String value = new String("");
IElementParameter param = elem.getElementParameter(fullParamName);
for (int j = 0; j < param.getListItemsValue().length; j++) {
if (combo.getText().equals(param.getListItemsDisplayName()[j])) {
value = (String) param.getListItemsValue()[j];
}
}
// if change to build-in, unuse the validation rule if the component has.
boolean isValRulesLost = false;
IRepositoryViewObject currentValRuleObj = ValidationRulesUtil.getCurrentValidationRuleObjs(elem);
if (value.equals(EmfComponent.BUILTIN) && currentValRuleObj != null) {
if (!MessageDialog.openConfirm(combo.getShell(), //$NON-NLS-1$
Messages.getString("SchemaTypeController.validationrule.title.confirm"), Messages.getString("SchemaTypeController.validationrule.selectBuildInMsg"))) {
//$NON-NLS-1$
return null;
} else {
isValRulesLost = true;
}
}
org.talend.core.model.metadata.builder.connection.Connection connection = null;
if (elem instanceof Node) {
Node node = (Node) elem;
Command baseCommand = null;
boolean isReadOnly = false;
String newRepositoryIdValue = null;
if (node.getMetadataFromConnector(param.getContext()) != null) {
isReadOnly = node.getMetadataFromConnector(param.getContext()).isReadOnly();
}
if (//$NON-NLS-1$
value.equals(EmfComponent.BUILTIN) && isReadOnly && !"tLogCatcher".equals(node.getComponent().getName()) && !"tStatCatcher".equals(node.getComponent().getName())) {
//$NON-NLS-1$
boolean hasMetadataInput = false;
if (node.getCurrentActiveLinksNbInput(EConnectionType.FLOW_MAIN) > 0 || node.getCurrentActiveLinksNbInput(EConnectionType.TABLE) > 0) {
hasMetadataInput = true;
}
repositoryMetadata = new MetadataTable();
if (hasMetadataInput) {
for (Connection connec : (List<Connection>) node.getIncomingConnections()) {
if (connec.isActivate() && (connec.getLineStyle().equals(EConnectionType.FLOW_MAIN) || connec.getLineStyle().equals(EConnectionType.TABLE))) {
repositoryMetadata = connec.getMetadataTable().clone();
}
}
}
} else if (value.equals(EmfComponent.REPOSITORY)) {
// Map<String, IMetadataTable> repositoryTableMap = dynamicProperty.getRepositoryTableMap();
IElementParameter property = ((Node) elem).getElementParameter(EParameterName.PROPERTY_TYPE.getName());
if ((property != null) && EmfComponent.REPOSITORY.equals(property.getValue())) {
String propertySelected = (String) ((Node) elem).getElementParameter(EParameterName.REPOSITORY_PROPERTY_TYPE.getName()).getValue();
IProxyRepositoryFactory factory = ProxyRepositoryFactory.getInstance();
/* 16969 */
Item item = null;
try {
IRepositoryViewObject repobj = factory.getLastVersion(propertySelected);
if (repobj != null) {
Property tmpproperty = repobj.getProperty();
if (tmpproperty != null) {
item = tmpproperty.getItem();
}
}
// item = factory.getLastVersion(propertySelected).getProperty().getItem();
} catch (PersistenceException e) {
ExceptionHandler.process(e);
}
if (item != null && item instanceof ConnectionItem) {
final ConnectionItem connectionItem = (ConnectionItem) item;
if (connectionItem != null) {
connection = connectionItem.getConnection();
}
}
}
IElementParameter repositorySchemaType = param.getParentParameter().getChildParameters().get(EParameterName.REPOSITORY_SCHEMA_TYPE.getName());
String schemaSelected = (String) repositorySchemaType.getValue();
/* value can be devided means the value like "connectionid - label" */
//$NON-NLS-1$
String[] keySplitValues = schemaSelected.toString().split(" - ");
if (keySplitValues.length > 1) {
String connectionId = keySplitValues[0];
String tableLabel = keySplitValues[1];
IProxyRepositoryFactory factory = ProxyRepositoryFactory.getInstance();
Item item = null;
try {
IRepositoryViewObject repobj = factory.getLastVersion(connectionId);
if (repobj != null) {
Property tmpproperty = repobj.getProperty();
if (tmpproperty != null) {
item = tmpproperty.getItem();
}
}
} catch (PersistenceException e) {
ExceptionHandler.process(e);
}
if (item != null && item instanceof ConnectionItem) {
final ConnectionItem connectionItem = (ConnectionItem) item;
if (connectionItem != null) {
connection = connectionItem.getConnection();
}
}
if (item != null && item instanceof ConnectionItem) {
boolean findTable = false;
for (org.talend.core.model.metadata.builder.connection.MetadataTable table : ConnectionHelper.getTables(connection)) {
if (table.getLabel().equals(tableLabel)) {
repositoryMetadata = ConvertionHelper.convert(table);
newRepositoryIdValue = schemaSelected;
findTable = true;
break;
}
}
if (!findTable) {
repositoryMetadata = new MetadataTable();
}
} else {
repositoryMetadata = new MetadataTable();
}
} else {
// value only got a empty string
repositoryMetadata = new MetadataTable();
}
/* see bug 16969 */
// if (repositoryTableMap.containsKey(schemaSelected)) {
// repositoryMetadata = repositoryTableMap.get(schemaSelected);
// // bug 6028, Display the parameter of REPOSITORY_SCHEMA_TYPE
// newRepositoryIdValue = schemaSelected;// + " - " + repositoryMetadata.getLabel();
// } else {
// if (repositoryTableMap.keySet().size() == 0) {
// repositoryMetadata = new MetadataTable();
// } else {
// newRepositoryIdValue = repositoryTableMap.keySet().iterator().next();
// // Gets the schema of the first item in repository schema type combo.
// repositoryMetadata = repositoryTableMap.get(newRepositoryIdValue);
// // bug 6028, Display the parameter of REPOSITORY_SCHEMA_TYPE
// // newRepositoryIdValue = newRepositoryIdValue + " - " + repositoryMetadata.getLabel();
// }
// }
} else {
baseCommand = new PropertyChangeCommand(elem, fullParamName, value);
}
if (switchParam != null) {
switchParam.setValue(Boolean.FALSE);
}
CompoundCommand cc = new CompoundCommand();
if (baseCommand != null) {
cc.add(baseCommand);
} else {
RepositoryChangeMetadataCommand changeMetadataCommand = new RepositoryChangeMetadataCommand((Node) elem, fullParamName, value, repositoryMetadata, newRepositoryIdValue, null);
changeMetadataCommand.setConnection(connection);
cc.add(changeMetadataCommand);
}
// unuse the validation rules of the component.
if (isValRulesLost) {
ValidationRulesUtil.appendRemoveValidationRuleCommands(cc, elem);
}
return cc;
}
return null;
}
use of org.talend.core.model.metadata.IMetadataTable in project tdi-studio-se by Talend.
the class MultipleThreadDynamicComposite method updateRepositoryList.
public void updateRepositoryList() {
ProgressDialog progressDialog = new ProgressDialog(this.getShell(), 1000) {
private IProgressMonitor monitorWrap;
@Override
public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
monitorWrap = new EventLoopProgressMonitor(monitor);
IProxyRepositoryFactory factory = DesignerPlugin.getDefault().getProxyRepositoryFactory();
List<IRepositoryViewObject> repositoryObjects = getAllRepositoryMetadata();
// + elem.getElementParameters().size();
int total = repositoryObjects.size();
//$NON-NLS-1$
monitorWrap.beginTask(Messages.getString("MultipleThreadDynamicComposite.gatherInformation"), total);
IElementParameter propertyParam = elem.getElementParameterFromField(EParameterFieldType.PROPERTY_TYPE, section);
String repositoryValue = null;
if (propertyParam != null) {
repositoryValue = propertyParam.getRepositoryValue();
}
if (repositoryObjects != null && (repositoryObjects.size() != 0)) {
tableIdAndDbTypeMap.clear();
tableIdAndDbSchemaMap.clear();
for (IRepositoryViewObject curObject : repositoryObjects) {
Item item = curObject.getProperty().getItem();
if (item instanceof ConnectionItem) {
ConnectionItem connectionItem = (ConnectionItem) item;
Connection connection = connectionItem.getConnection();
if (connection == null || connection.isReadOnly()) {
continue;
}
for (Object tableObj : ConnectionHelper.getTables(connection)) {
org.talend.core.model.metadata.builder.connection.MetadataTable table;
table = (org.talend.core.model.metadata.builder.connection.MetadataTable) tableObj;
if (factory.getStatus(connectionItem) != ERepositoryStatus.DELETED) {
if (!factory.isDeleted(table)) {
IMetadataTable newTable = ConvertionHelper.convert(table);
// newTable);
if (connection instanceof DatabaseConnection) {
String dbType = ((DatabaseConnection) connection).getDatabaseType();
String schema = ((DatabaseConnection) connection).getUiSchema();
tableIdAndDbTypeMap.put(newTable.getId(), dbType);
if (schema != null && !schema.equals("")) {
//$NON-NLS-1$
tableIdAndDbSchemaMap.put(newTable.getId(), schema);
}
}
}
}
}
monitorWrap.worked(1);
}
// hywang add for feature 6484
if (item instanceof FileItem) {
FileItem FileItem = (FileItem) item;
if (repositoryValue != null) {
if (repositoryValue.equals("RULE")) {
//$NON-NLS-1$
repositoryFileItemMap.put(FileItem.getProperty().getId(), FileItem);
}
}
monitorWrap.worked(1);
}
if (item instanceof LinkRulesItem) {
LinkRulesItem linkItem = (LinkRulesItem) item;
if (repositoryValue != null) {
if (repositoryValue.equals("RULE")) {
//$NON-NLS-1$
repositoryLinkRulesItemMap.put(linkItem.getProperty().getId(), linkItem);
}
}
monitorWrap.worked(1);
}
}
}
monitorWrap.done();
}
};
try {
progressDialog.executeProcess();
} catch (InvocationTargetException e) {
ExceptionHandler.process(e);
return;
} catch (Exception e) {
ExceptionHandler.process(e);
return;
}
}
use of org.talend.core.model.metadata.IMetadataTable in project tdi-studio-se by Talend.
the class GenericElementParameter method updateSchema.
private void updateSchema() {
IElement element = this.getElement();
if (element instanceof Node) {
Node node = (Node) element;
List<INodeConnector> connectors = node.getConnectorsFromType(EConnectionType.FLOW_MAIN);
for (INodeConnector connector : connectors) {
if (connector instanceof GenericNodeConnector) {
Connector componentConnector = ((GenericNodeConnector) connector).getComponentConnector();
Schema schema = null;
schema = getRootProperties().getSchema(componentConnector, ((GenericNodeConnector) connector).isOutput());
IMetadataTable mainTable = node.getMetadataFromConnector(connector.getName());
if (schema != null && mainTable != null) {
MetadataTable metadataTable = MetadataToolAvroHelper.convertFromAvro(schema);
IMetadataTable newTable = MetadataToolHelper.convert(metadataTable);
if (!mainTable.sameMetadataAs(newTable) || !newTable.sameMetadataAs(mainTable)) {
mainTable.setListColumns(newTable.getListColumns());
List<IElementParameter> schemaParameters = node.getElementParametersFromField(EParameterFieldType.SCHEMA_REFERENCE);
updateSchemaParameters(schemaParameters, connector.getName(), schema);
if (this.askPropagate == null && node.getOutgoingConnections().size() != 0) {
boolean hasPropagation = false;
for (IConnection connection : node.getOutgoingConnections()) {
if (connector.getName().equals(connection.getConnectorName())) {
if (isSchemaPropagated(connection.getTarget())) {
hasPropagation = true;
break;
}
}
}
if (hasPropagation) {
Display.getDefault().syncExec(new Runnable() {
@Override
public void run() {
askPropagate = ChangeMetadataCommand.askPropagate();
}
});
}
}
if (this.askPropagate != null && this.askPropagate) {
for (IConnection connection : node.getOutgoingConnections()) {
if (connector.getName().equals(connection.getConnectorName())) {
INode target = connection.getTarget();
if (!isSchemaPropagated(target)) {
continue;
}
ChangeMetadataCommand cmd = new ChangeMetadataCommand(target, null, null, newTable, null);
cmd.setPropagate(true);
IProcess process = node.getProcess();
if (process instanceof org.talend.designer.core.ui.editor.process.Process) {
CommandStack commandStack = ((org.talend.designer.core.ui.editor.process.Process) process).getCommandStack();
commandStack.execute(cmd);
}
}
}
}
}
}
}
}
this.askPropagate = null;
}
}
use of org.talend.core.model.metadata.IMetadataTable in project tdi-studio-se by Talend.
the class NewComponentFrameworkMigrationTask method execute.
@Override
public ExecutionResult execute(final Item item) {
final ProcessType processType = getProcessType(item);
ComponentCategory category = ComponentCategory.getComponentCategoryFromItem(item);
Properties props = getPropertiesFromFile();
IComponentConversion conversion = new IComponentConversion() {
@Override
public void transform(NodeType nodeType) {
if (nodeType == null || props == null) {
return;
}
boolean modified = false;
Map<String, String> schemaParamMap = new HashMap<>();
String currComponentName = nodeType.getComponentName();
String newComponentName = props.getProperty(currComponentName);
nodeType.setComponentName(newComponentName);
IComponent component = ComponentsFactoryProvider.getInstance().get(newComponentName, category.getName());
ComponentProperties compProperties = ComponentsUtils.getComponentProperties(newComponentName);
FakeNode fNode = new FakeNode(component);
for (IElementParameter param : fNode.getElementParameters()) {
if (param instanceof GenericElementParameter) {
String paramName = param.getName();
NamedThing currNamedThing = ComponentsUtils.getGenericSchemaElement(compProperties, paramName);
String oldParamName = props.getProperty(currComponentName + IGenericConstants.EXP_SEPARATOR + paramName);
if (oldParamName != null && !(oldParamName = oldParamName.trim()).isEmpty()) {
if (currNamedThing instanceof Property && (GenericTypeUtils.isSchemaType((Property<?>) currNamedThing))) {
schemaParamMap.put(paramName, props.getProperty(currComponentName + IGenericConstants.EXP_SEPARATOR + paramName + IGenericConstants.EXP_SEPARATOR + "connector"));
}
ElementParameterType paramType = getParameterType(nodeType, oldParamName);
if (paramType != null) {
if (currNamedThing instanceof ComponentReferenceProperties) {
ComponentReferenceProperties refProps = (ComponentReferenceProperties) currNamedThing;
refProps.referenceType.setValue(ComponentReferenceProperties.ReferenceType.COMPONENT_INSTANCE);
refProps.componentInstanceId.setStoredValue(ParameterUtilTool.convertParameterValue(paramType));
refProps.componentInstanceId.setTaggedValue(IGenericConstants.ADD_QUOTES, true);
} else {
processMappedElementParameter(props, nodeType, (GenericElementParameter) param, paramType, currNamedThing);
}
ParameterUtilTool.removeParameterType(nodeType, paramType);
modified = true;
}
if (EParameterFieldType.SCHEMA_REFERENCE.equals(param.getFieldType())) {
//$NON-NLS-1$
String schemaTypeName = ":" + EParameterName.SCHEMA_TYPE.getName();
//$NON-NLS-1$
String repSchemaTypeName = ":" + EParameterName.REPOSITORY_SCHEMA_TYPE.getName();
paramType = getParameterType(nodeType, oldParamName + schemaTypeName);
if (paramType != null) {
paramType.setName(param.getName() + schemaTypeName);
}
paramType = getParameterType(nodeType, oldParamName + repSchemaTypeName);
if (paramType != null) {
paramType.setName(param.getName() + repSchemaTypeName);
}
}
} else {
processUnmappedElementParameter(props, nodeType, (GenericElementParameter) param, currNamedThing);
}
} else {
if (EParameterFieldType.SCHEMA_REFERENCE.equals(param.getFieldType())) {
String paramName = param.getName();
schemaParamMap.put(paramName, props.getProperty(currComponentName + IGenericConstants.EXP_SEPARATOR + paramName + IGenericConstants.EXP_SEPARATOR + "connector"));
String oldParamName = props.getProperty(currComponentName + IGenericConstants.EXP_SEPARATOR + paramName);
//$NON-NLS-1$
String schemaTypeName = ":" + EParameterName.SCHEMA_TYPE.getName();
//$NON-NLS-1$
String repSchemaTypeName = ":" + EParameterName.REPOSITORY_SCHEMA_TYPE.getName();
ElementParameterType paramType = getParameterType(nodeType, oldParamName + schemaTypeName);
if (paramType != null) {
paramType.setName(param.getName() + schemaTypeName);
}
paramType = getParameterType(nodeType, oldParamName + repSchemaTypeName);
if (paramType != null) {
paramType.setName(param.getName() + repSchemaTypeName);
}
}
}
}
// Migrate schemas
Map<String, MetadataType> metadatasMap = new HashMap<>();
EList<MetadataType> metadatas = nodeType.getMetadata();
for (MetadataType metadataType : metadatas) {
metadatasMap.put(metadataType.getConnector(), metadataType);
}
Iterator<Entry<String, String>> schemaParamIter = schemaParamMap.entrySet().iterator();
//$NON-NLS-1$
String uniqueName = ParameterUtilTool.getParameterValue(nodeType, "UNIQUE_NAME");
while (schemaParamIter.hasNext()) {
Entry<String, String> schemaParamEntry = schemaParamIter.next();
String newParamName = schemaParamEntry.getKey();
String connectorMapping = schemaParamEntry.getValue();
//$NON-NLS-1$
String oldConnector = connectorMapping.split("->")[0];
//$NON-NLS-1$
String newConnector = connectorMapping.split("->")[1];
MetadataType metadataType = metadatasMap.get(oldConnector);
if (metadataType != null) {
metadataType.setConnector(newConnector);
MetadataEmfFactory factory = new MetadataEmfFactory();
factory.setMetadataType(metadataType);
IMetadataTable metadataTable = factory.getMetadataTable();
Schema schema = SchemaUtils.convertTalendSchemaIntoComponentSchema(ConvertionHelper.convert(metadataTable));
compProperties.setValue(newParamName, schema);
}
if (!oldConnector.equals(newConnector)) {
// if connector was changed, we should update the connections
for (Object connectionObj : processType.getConnection()) {
if (connectionObj instanceof ConnectionType) {
ConnectionType connectionType = (ConnectionType) connectionObj;
if (connectionType.getSource().equals(uniqueName) && connectionType.getConnectorName().equals(oldConnector)) {
connectionType.setConnectorName(newConnector);
}
}
}
}
}
for (Object connectionObj : processType.getConnection()) {
ConnectionType connection = (ConnectionType) connectionObj;
if (connection.getSource() != null && connection.getSource().equals(uniqueName)) {
if (EConnectionType.FLOW_MAIN.getName().equals(connection.getConnectorName())) {
connection.setConnectorName(Connector.MAIN_NAME);
}
}
}
if (modified) {
String serializedProperties = compProperties.toSerialized();
if (serializedProperties != null) {
ElementParameterType pType = //$NON-NLS-1$
ParameterUtilTool.createParameterType(//$NON-NLS-1$
null, //$NON-NLS-1$
"PROPERTIES", serializedProperties);
nodeType.getElementParameter().add(pType);
}
}
}
};
if (processType != null) {
boolean modified = false;
for (Object obj : processType.getNode()) {
if (obj != null && obj instanceof NodeType) {
String componentName = ((NodeType) obj).getComponentName();
String newComponentName = props.getProperty(componentName);
if (newComponentName == null) {
continue;
}
IComponentFilter filter = new NameComponentFilter(componentName);
modified = ModifyComponentsAction.searchAndModify((NodeType) obj, filter, Arrays.<IComponentConversion>asList(conversion)) || modified;
}
}
if (modified) {
try {
ProxyRepositoryFactory.getInstance().save(item, true);
return ExecutionResult.SUCCESS_NO_ALERT;
} catch (PersistenceException e) {
ExceptionHandler.process(e);
return ExecutionResult.FAILURE;
}
}
}
return ExecutionResult.NOTHING_TO_DO;
}
use of org.talend.core.model.metadata.IMetadataTable in project tdi-studio-se by Talend.
the class ComponentChooseDialog method createRefreshingPropertiesCommand.
/**
* DOC bqian Comment method "createRefreshingPropertiesCommand".
*
* @param selectedNode
* @param node
*/
private List<Command> createRefreshingPropertiesCommand(CompoundCommand cc, RepositoryNode selectedNode, Node node) {
// List<Command> list = new ArrayList<Command>();
if (selectedNode.getObject().getProperty().getItem() instanceof ConnectionItem) {
String propertyId = selectedNode.getObject().getProperty().getId();
ConnectionItem originalConnectionItem = (ConnectionItem) selectedNode.getObject().getProperty().getItem();
ConnectionItem connectionItem = originalConnectionItem;
Connection originalConnection = connectionItem.getConnection();
Connection connection = connectionItem.getConnection();
// if component is CDC, replace by the CDC connection.
if (node.getComponent().getName().contains("CDC")) {
// to replace by a flag CDC in component? //$NON-NLS-1$
if (selectedNode.getObject().getProperty().getItem() instanceof DatabaseConnectionItem) {
final DatabaseConnection databaseConnection = (DatabaseConnection) connection;
CDCConnection cdcConn = databaseConnection.getCdcConns();
if (cdcConn != null) {
EList cdcTypes = cdcConn.getCdcTypes();
if (cdcTypes != null && !cdcTypes.isEmpty()) {
CDCType cdcType = (CDCType) cdcTypes.get(0);
// replace property by CDC property.
propertyId = cdcType.getLinkDB();
try {
IRepositoryViewObject object = ProxyRepositoryFactory.getInstance().getLastVersion(propertyId);
if (object != null) {
if (object.getProperty().getItem() instanceof DatabaseConnectionItem) {
DatabaseConnectionItem dbConnItem = (DatabaseConnectionItem) object.getProperty().getItem();
// replace connection by CDC connection
connectionItem = dbConnItem;
connection = dbConnItem.getConnection();
}
}
} catch (PersistenceException e) {
ExceptionHandler.process(e);
}
// set cdc type mode.
IElementParameter logModeParam = node.getElementParameter(EParameterName.CDC_TYPE_MODE.getName());
if (logModeParam != null) {
String cdcTypeMode = ((DatabaseConnection) originalConnection).getCdcTypeMode();
Command logModeCmd = new PropertyChangeCommand(node, EParameterName.CDC_TYPE_MODE.getName(), CDCTypeMode.LOG_MODE.getName().equals(cdcTypeMode));
cc.add(logModeCmd);
}
// set lib for as400 so far.
//$NON-NLS-1$
final String name = "SOURCE_LIB";
IElementParameter libParam = node.getElementParameter(name);
if (libParam != null) {
Object propValue;
if (connection.isContextMode() && ContextParameterUtils.isContainContextParam(databaseConnection.getSID())) {
propValue = databaseConnection.getSID();
} else {
propValue = TalendTextUtils.addQuotes(databaseConnection.getSID());
}
Command libSettingCmd = new PropertyChangeCommand(node, name, propValue);
cc.add(libSettingCmd);
}
}
}
}
}
// fore EBCDIC, by cli
if ((connectionItem instanceof EbcdicConnectionItem) && PluginChecker.isEBCDICPluginLoaded()) {
// TDI-20505:integration the drag/drop for EBCDIC connection and EBCDIC metadataTable
IRepositoryViewObject object = selectedNode.getObject();
if (selectedNode.getObjectType() == ERepositoryObjectType.METADATA_FILE_EBCDIC) {
for (MetadataTable table : ConnectionHelper.getTables(originalConnection)) {
Command ebcdicCmd = new RepositoryChangeMetadataForEBCDICCommand(node, IEbcdicConstant.TABLE_SCHEMAS, table.getLabel(), ConvertionHelper.convert(table));
cc.add(ebcdicCmd);
}
}
if (selectedNode.getProperties(EProperties.CONTENT_TYPE) == ERepositoryObjectType.METADATA_CON_TABLE) {
MetadataTable table = null;
if (object instanceof MetadataTableRepositoryObject) {
table = ((MetadataTableRepositoryObject) object).getTable();
}
Command ebcdicCmd = new RepositoryChangeMetadataForEBCDICCommand(node, IEbcdicConstant.TABLE_SCHEMAS, table.getLabel(), ConvertionHelper.convert(table));
cc.add(ebcdicCmd);
}
}
// fore HL7, by gcui
if ((selectedNode.getObjectType() == ERepositoryObjectType.METADATA_FILE_HL7 && PluginChecker.isHL7PluginLoaded()) || (selectedNode.getParent() != null && selectedNode.getParent().getObjectType() == ERepositoryObjectType.METADATA_FILE_HL7 && PluginChecker.isHL7PluginLoaded())) {
if (originalConnection instanceof HL7ConnectionImpl) {
if (((HL7ConnectionImpl) originalConnection).getRoot() != null) {
List<Map<String, String>> mapList = new ArrayList<Map<String, String>>();
for (Object obj : ((HL7ConnectionImpl) originalConnection).getRoot()) {
if (obj instanceof HL7FileNode) {
Map<String, String> newMap = new HashMap<String, String>();
newMap.put(IHL7Constant.ATTRIBUTE, ((HL7FileNode) obj).getAttribute());
newMap.put(IHL7Constant.PATH, ((HL7FileNode) obj).getFilePath());
newMap.put(IHL7Constant.COLUMN, ((HL7FileNode) obj).getRelatedColumn());
newMap.put(IHL7Constant.ORDER, String.valueOf(((HL7FileNode) obj).getOrder()));
newMap.put(IHL7Constant.VALUE, ((HL7FileNode) obj).getDefaultValue());
newMap.put(IHL7Constant.REPEATABLE, String.valueOf(((HL7FileNode) obj).isRepeatable()));
mapList.add(newMap);
}
}
IExternalNode externalNode = ExternalUtilities.getExternalNodeReadyToOpen(node);
if (externalNode != null && externalNode.getElementParameter("ROOT") != null) {
//$NON-NLS-1$
//$NON-NLS-1$
externalNode.getElementParameter("ROOT").setValue(mapList);
}
String fileName = ((HL7ConnectionImpl) originalConnection).getOutputFilePath();
if (externalNode != null && externalNode.getElementParameter("FILENAME") != null && fileName != null) {
//$NON-NLS-1$
//$NON-NLS-1$
externalNode.getElementParameter("FILENAME").setValue(TalendTextUtils.addQuotes(fileName));
}
}
}
// fore HL7, by gcui
if (selectedNode.getObjectType() == ERepositoryObjectType.METADATA_FILE_HL7 && PluginChecker.isHL7PluginLoaded()) {
for (MetadataTable table : ConnectionHelper.getTablesWithOrders(originalConnection)) {
Command hl7Cmd = new RepositoryChangeMetadataForHL7Command(node, IHL7Constant.TABLE_SCHEMAS, table.getLabel(), ConvertionHelper.convert(table));
cc.add(hl7Cmd);
}
}
}
// for brms
if ((selectedNode.getObjectType() == ERepositoryObjectType.METADATA_FILE_BRMS && PluginChecker.isBRMSPluginLoaded()) || (selectedNode.getParent() != null && selectedNode.getParent().getObjectType() == ERepositoryObjectType.METADATA_FILE_BRMS && PluginChecker.isBRMSPluginLoaded())) {
if (originalConnection instanceof BRMSConnectionImpl) {
if (((BRMSConnectionImpl) originalConnection).getRoot() != null) {
List<Map<String, String>> rootList = new ArrayList<Map<String, String>>();
List<Map<String, String>> loopList = new ArrayList<Map<String, String>>();
List<Map<String, String>> groupList = new ArrayList<Map<String, String>>();
for (Object obj : ((BRMSConnectionImpl) originalConnection).getRoot()) {
if (obj instanceof XMLFileNode) {
Map<String, String> rootMap = new HashMap<String, String>();
//$NON-NLS-1$
rootMap.put("ATTRIBUTE", ((XMLFileNode) obj).getAttribute());
//$NON-NLS-1$
rootMap.put("PATH", ((XMLFileNode) obj).getXMLPath());
//$NON-NLS-1$
rootMap.put("COLUMN", ((XMLFileNode) obj).getRelatedColumn());
//$NON-NLS-1$
rootMap.put("ORDER", String.valueOf(((XMLFileNode) obj).getOrder()));
//$NON-NLS-1$
rootMap.put("VALUE", ((XMLFileNode) obj).getDefaultValue());
rootList.add(rootMap);
}
}
for (Object obj : ((BRMSConnectionImpl) originalConnection).getLoop()) {
if (obj instanceof XMLFileNode) {
Map<String, String> loopMap = new HashMap<String, String>();
//$NON-NLS-1$
loopMap.put("ATTRIBUTE", ((XMLFileNode) obj).getAttribute());
//$NON-NLS-1$
loopMap.put("PATH", ((XMLFileNode) obj).getXMLPath());
//$NON-NLS-1$
loopMap.put("COLUMN", ((XMLFileNode) obj).getRelatedColumn());
//$NON-NLS-1$
loopMap.put("ORDER", String.valueOf(((XMLFileNode) obj).getOrder()));
//$NON-NLS-1$
loopMap.put("VALUE", ((XMLFileNode) obj).getDefaultValue());
loopList.add(loopMap);
}
}
for (Object obj : ((BRMSConnectionImpl) originalConnection).getGroup()) {
if (obj instanceof XMLFileNode) {
Map<String, String> groupMap = new HashMap<String, String>();
//$NON-NLS-1$
groupMap.put("ATTRIBUTE", ((XMLFileNode) obj).getAttribute());
//$NON-NLS-1$
groupMap.put("PATH", ((XMLFileNode) obj).getXMLPath());
//$NON-NLS-1$
groupMap.put("COLUMN", ((XMLFileNode) obj).getRelatedColumn());
//$NON-NLS-1$
groupMap.put("ORDER", String.valueOf(((XMLFileNode) obj).getOrder()));
//$NON-NLS-1$
groupMap.put("VALUE", ((XMLFileNode) obj).getDefaultValue());
groupList.add(groupMap);
}
}
IExternalNode externalNode = ExternalUtilities.getExternalNodeReadyToOpen(node);
if (externalNode != null && externalNode.getElementParameter("ROOT") != null) {
//$NON-NLS-1$
//$NON-NLS-1$
externalNode.getElementParameter("ROOT").setValue(rootList);
}
if (externalNode != null && externalNode.getElementParameter("LOOP") != null) {
//$NON-NLS-1$
//$NON-NLS-1$
externalNode.getElementParameter("LOOP").setValue(loopList);
}
if (externalNode != null && externalNode.getElementParameter("GROUP") != null) {
//$NON-NLS-1$
//$NON-NLS-1$
externalNode.getElementParameter("GROUP").setValue(groupList);
}
}
}
}
IElementParameter propertyParam = node.getElementParameterFromField(EParameterFieldType.PROPERTY_TYPE);
if (propertyParam != null) {
propertyParam.getChildParameters().get(EParameterName.PROPERTY_TYPE.getName()).setValue(EmfComponent.REPOSITORY);
propertyParam.getChildParameters().get(EParameterName.REPOSITORY_PROPERTY_TYPE.getName()).setValue(propertyId);
}
IProxyRepositoryFactory factory = DesignerPlugin.getDefault().getProxyRepositoryFactory();
Map<String, IMetadataTable> repositoryTableMap = new HashMap<String, IMetadataTable>();
if (!originalConnection.isReadOnly()) {
for (Object tableObj : ConnectionHelper.getTables(originalConnection)) {
org.talend.core.model.metadata.builder.connection.MetadataTable table;
table = (org.talend.core.model.metadata.builder.connection.MetadataTable) tableObj;
if (factory.getStatus(originalConnectionItem) != ERepositoryStatus.DELETED) {
if (!factory.isDeleted(table)) {
String value = table.getId();
IMetadataTable newTable = ConvertionHelper.convert(table);
repositoryTableMap.put(value, newTable);
}
}
}
}
// DesignerPlugin.getDefault().getProxyRepositoryFactory().getLastVersion("")
if (propertyParam != null) {
// command used to set property type
IMetadataTable metadataTable = null;
// && selectedNode.getObjectType() == ERepositoryObjectType.METADATA_CON_TABLE) {
if (selectedNode.getObject() instanceof IMetadataTable) {
metadataTable = (IMetadataTable) selectedNode.getObject();
if (metadataTable != null && repositoryTableMap.get(metadataTable.getId()) != null) {
metadataTable = repositoryTableMap.get(metadataTable.getId());
}
}
// }
ChangeValuesFromRepository command1 = new ChangeValuesFromRepository(node, connection, metadataTable, propertyParam.getName() + ":" + EParameterName.REPOSITORY_PROPERTY_TYPE.getName(), propertyId, //$NON-NLS-1$
true);
command1.setMaps(repositoryTableMap);
if (selectedNode.getProperties(EProperties.CONTENT_TYPE) != ERepositoryObjectType.METADATA_CON_QUERY) {
command1.setGuessQuery(true);
}
setSAPSpecailValueForCommand(selectedNode, command1);
// for salesForce module
SalesforceModuleRepositoryObject sfObject = null;
if (selectedNode.getProperties(EProperties.CONTENT_TYPE) == ERepositoryObjectType.METADATA_SALESFORCE_MODULE) {
sfObject = (SalesforceModuleRepositoryObject) selectedNode.getObject();
} else if (selectedNode.getProperties(EProperties.CONTENT_TYPE) == ERepositoryObjectType.METADATA_CON_TABLE) {
IRepositoryViewObject object = selectedNode.getParent().getObject();
if (object instanceof SalesforceModuleRepositoryObject) {
sfObject = (SalesforceModuleRepositoryObject) object;
}
}
if (sfObject != null) {
ModelElement modelElement = sfObject.getModelElement();
if (modelElement instanceof SalesforceModuleUnit) {
command1.setSalesForceModuleUnit((SalesforceModuleUnit) modelElement);
}
}
cc.add(command1);
}
// command used to set metadata
getChangeMetadataCommand(cc, selectedNode, node, originalConnectionItem);
// command used to set query
if (selectedNode.getProperties(EProperties.CONTENT_TYPE) == ERepositoryObjectType.METADATA_CON_QUERY) {
IElementParameter queryParam = node.getElementParameterFromField(EParameterFieldType.QUERYSTORE_TYPE);
QueryRepositoryObject object = (QueryRepositoryObject) selectedNode.getObject();
Query query = object.getQuery();
//$NON-NLS-1$
String value = originalConnectionItem.getProperty().getId() + " - " + query.getLabel();
if (queryParam != null) {
RepositoryChangeQueryCommand command3 = new RepositoryChangeQueryCommand(node, query, queryParam.getName() + ":" + EParameterName.REPOSITORY_QUERYSTORE_TYPE.getName(), //$NON-NLS-1$
value);
cc.add(command3);
}
} else {
if (connection instanceof DatabaseConnection && hasQuery(node)) {
DatabaseConnection connection2 = (DatabaseConnection) connection;
String schema = connection2.getUiSchema();
String dbType = connection2.getDatabaseType();
QueryGuessCommand queryGuessCommand = null;
if (node.getMetadataList().size() == 0) {
queryGuessCommand = new QueryGuessCommand(node, null, schema, dbType);
} else {
// modified by hyWang for bug 7190
queryGuessCommand = new QueryGuessCommand(node, node.getMetadataList().get(0), schema, dbType, connection);
}
if (queryGuessCommand != null) {
cc.add(queryGuessCommand);
}
}
}
// context, moved to ChangeValuesFromRepository(bug 5198)
// ConnectionContextHelper.addContextForNodeParameter(node, connectionItem);
} else if (selectedNode.getObject().getProperty().getItem() instanceof ProcessItem) {
ProcessItem processItem = (ProcessItem) selectedNode.getObject().getProperty().getItem();
// command used to set job
String value = processItem.getProperty().getId();
PropertyChangeCommand command4 = new PropertyChangeCommand(node, EParameterName.PROCESS_TYPE_PROCESS.getName(), value);
cc.add(command4);
PropertyChangeCommand command5 = new PropertyChangeCommand(node, EParameterName.PROCESS_TYPE_CONTEXT.getName(), processItem.getProcess().getDefaultContext());
cc.add(command5);
} else if (selectedNode.getObject().getProperty().getItem() instanceof FileItem) {
// hywang add for 6484
if (selectedNode.getObject().getProperty().getItem() instanceof RulesItem) {
RulesItem rulesItem = (RulesItem) selectedNode.getObject().getProperty().getItem();
// String displayName = "Rules:" + rulesItem.getProperty().getLabel(); //$NON-NLS-N$
IElementParameter propertyParam = node.getElementParameterFromField(EParameterFieldType.PROPERTY_TYPE);
if (propertyParam != null) {
propertyParam.getChildParameters().get(EParameterName.PROPERTY_TYPE.getName()).setValue(EmfComponent.REPOSITORY);
// propertyParam.getChildParameters().get(EParameterName.REPOSITORY_PROPERTY_TYPE.getName())
// .setListItemsDisplayName(new String[] { displayName });
final String showId = rulesItem.getProperty().getId();
PropertyChangeCommand command6 = new PropertyChangeCommand(node, EParameterName.REPOSITORY_PROPERTY_TYPE.getName(), showId);
cc.add(command6);
}
}
} else if (selectedNode.getObject().getProperty().getItem() instanceof LinkRulesItem) {
LinkRulesItem linkItem = (LinkRulesItem) selectedNode.getObject().getProperty().getItem();
IElementParameter propertyParam = node.getElementParameterFromField(EParameterFieldType.PROPERTY_TYPE);
if (propertyParam != null) {
propertyParam.getChildParameters().get(EParameterName.PROPERTY_TYPE.getName()).setValue(EmfComponent.REPOSITORY);
// propertyParam.getChildParameters().get(EParameterName.REPOSITORY_PROPERTY_TYPE.getName())
// .setListItemsDisplayName(new String[] { displayName });
final String showId = linkItem.getProperty().getId();
PropertyChangeCommand command7 = new PropertyChangeCommand(node, EParameterName.REPOSITORY_PROPERTY_TYPE.getName(), showId);
cc.add(command7);
}
}
return null;
}
Aggregations