use of org.talend.core.model.components.filters.IComponentFilter in project tesb-studio-se by Talend.
the class NormalizeDataServiceJobBuildTypeMigrationTask method execute.
/*
* (non-Javadoc)
*
* @see
* org.talend.core.model.migration.AbstractDataserviceMigrationTask#execute(org
* .talend.core.model.properties.Item)
*/
@SuppressWarnings("unchecked")
@Override
public ExecutionResult execute(Item item) {
final ProcessType processType = getProcessType(item);
boolean modified = false;
for (String name : ESB_COMPONENTS) {
IComponentFilter filter = new NameComponentFilter(name);
List<NodeType> c = searchComponent(processType, filter);
if (!c.isEmpty()) {
Object buildType = item.getProperty().getAdditionalProperties().get(BUILD_TYPE_PROPERTY);
if (BUILD_TYPE_ROUTE.equals(buildType)) {
item.getProperty().getAdditionalProperties().put(BUILD_TYPE_PROPERTY, BUILD_TYPE_OSGI);
try {
save(item);
modified |= true;
generateReportRecord(new MigrationReportRecorder(this, MigrationReportRecorder.MigrationOperationType.MODIFY, item, null, "Build Type", BUILD_TYPE_ROUTE, BUILD_TYPE_OSGI));
} catch (PersistenceException e) {
ExceptionHandler.process(e);
return ExecutionResult.FAILURE;
}
return ExecutionResult.SUCCESS_NO_ALERT;
}
}
}
if (modified) {
return ExecutionResult.SUCCESS_NO_ALERT;
} else {
return ExecutionResult.NOTHING_TO_DO;
}
}
use of org.talend.core.model.components.filters.IComponentFilter in project tdi-studio-se by Talend.
the class Salesforce620Migration method execute.
/*
* (non-Javadoc)
*
* @see org.talend.core.model.migration.AbstractItemMigrationTask#execute(org.talend.core.model.properties.Item)
*/
@Override
public ExecutionResult execute(Item item) {
ProcessType processType = getProcessType(item);
if (getProject().getLanguage() != ECodeLanguage.JAVA || processType == null) {
return ExecutionResult.NOTHING_TO_DO;
}
String[] componentsName = new String[] { //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
"tSalesforceConnection", //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
"tSalesforceBulkExec", //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
"tSalesforceGetDeleted", //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
"tSalesforceGetUpdated", "tSalesforceInput", "tSalesforceOutput", "tSalesforceOutputBulk", //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
"tSalesforceOutputBulkExec" };
IComponentConversion changeJDBCDriverJarType = new IComponentConversion() {
@Override
public void transform(NodeType node) {
ElementParameterType elemParamType = ComponentUtilities.getNodeProperty(node, "PROPERTIES");
String propertiesString = elemParamType.getValue();
SerializerDeserializer.Deserialized<ComponentProperties> fromSerialized = Properties.Helper.fromSerializedPersistent(propertiesString, ComponentProperties.class, new PostDeserializeSetup() {
@Override
public void setup(Object properties) {
((Properties) properties).setValueEvaluator(new PropertyValueEvaluator() {
@Override
public Object evaluate(Property property, Object storedValue) {
if (storedValue instanceof String) {
if (GenericTypeUtils.isEnumType(property)) {
ComponentProperties newProperties = ComponentsUtils.getComponentProperties(node.getComponentName());
Property newProperty = (Property) newProperties.getProperty(property.getName());
if (newProperty == null) {
newProperty = (Property) newProperties.getProperty("connection.loginType");
}
if (newProperty != null) {
List<?> propertyPossibleValues = ((Property<?>) newProperty).getPossibleValues();
if (propertyPossibleValues != null) {
for (Object possibleValue : propertyPossibleValues) {
if (possibleValue.toString().equals(storedValue)) {
property.setStoredValue(possibleValue);
return possibleValue;
}
}
}
}
}
}
return storedValue;
}
});
}
});
ComponentProperties newProperties = ComponentsUtils.getComponentProperties(node.getComponentName());
updateSubProperties(fromSerialized.object, newProperties);
newProperties.copyValuesFrom(fromSerialized.object, true, false);
NamedThing nt = newProperties.getProperty("module.moduleName");
if (nt != null && nt instanceof Property) {
Property moduleNameProperty = (Property) nt;
String moduleName = (String) moduleNameProperty.getValue();
if (ContextParameterUtils.isContainContextParam(moduleName)) {
moduleName = TalendQuoteUtils.removeQuotes(moduleName);
} else {
moduleName = TalendQuoteUtils.addPairQuotesIfNotExist(moduleName);
}
moduleNameProperty.setStoredValue(moduleName);
}
nt = newProperties.getProperty("upsertRelationTable.columnName");
if (nt != null && nt instanceof Property) {
Property moduleNameProperty = (Property) nt;
if (moduleNameProperty.getPossibleValues() == null || moduleNameProperty.getPossibleValues().isEmpty()) {
List<String> columns = new ArrayList<String>();
if (moduleNameProperty.getValue() instanceof String) {
String column = (String) moduleNameProperty.getValue();
columns.add(column);
} else if (moduleNameProperty.getValue() instanceof List) {
columns.addAll((Collection<? extends String>) moduleNameProperty.getValue());
}
moduleNameProperty.setPossibleValues(columns);
}
}
elemParamType.setValue(newProperties.toSerialized());
}
};
boolean modified = false;
for (Object obj : processType.getNode()) {
if (obj != null && obj instanceof NodeType) {
String componentName = ((NodeType) obj).getComponentName();
if (ArrayUtils.contains(componentsName, componentName)) {
IComponentFilter filter = new NameComponentFilter(componentName);
modified = ModifyComponentsAction.searchAndModify((NodeType) obj, filter, Arrays.<IComponentConversion>asList(changeJDBCDriverJarType)) || 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.SUCCESS_WITH_ALERT;
}
use of org.talend.core.model.components.filters.IComponentFilter 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.components.filters.IComponentFilter in project tdi-studio-se by Talend.
the class ChangeSalesForceComponetsCustomerModuleName method execute.
@Override
public ExecutionResult execute(Item item) {
ProcessType processType = getProcessType(item);
if (getProject().getLanguage() != ECodeLanguage.JAVA || processType == null) {
return ExecutionResult.NOTHING_TO_DO;
}
String[] componentsName = new String[] { "tSalesforceBulkExec", "tSalesforceGetDeleted", "tSalesforceGetUpdated", "tSalesforceInput", "tSalesforceOutput", //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
"tSalesforceOutputBulkExec" };
IComponentConversion changeJDBCDriverJarType = new IComponentConversion() {
public void transform(NodeType node) {
ElementParameterType module = ComponentUtilities.getNodeProperty(node, "MODULENAME");
if (module != null && "CustomModule".equals(module.getValue())) {
ElementParameterType customModule = ComponentUtilities.getNodeProperty(node, "CUSTOM_MODULE");
if (customModule == null) {
customModule = ComponentUtilities.getNodeProperty(node, "CUSTOM_MODULE_NAME");
}
if (customModule != null) {
String customModuleName = customModule.getValue();
if (customModuleName != null) {
if (!customModuleName.startsWith("\"")) {
customModuleName = "\"" + customModuleName;
}
if (!customModuleName.endsWith("\"")) {
customModuleName = customModuleName + "\"";
}
customModule.setValue(customModuleName);
}
}
}
}
};
for (String name : componentsName) {
//$NON-NLS-1$
IComponentFilter filter = new NameComponentFilter(name);
try {
ModifyComponentsAction.searchAndModify(item, processType, filter, Arrays.<IComponentConversion>asList(changeJDBCDriverJarType));
} catch (PersistenceException e) {
ExceptionHandler.process(e);
return ExecutionResult.FAILURE;
}
}
return ExecutionResult.SUCCESS_WITH_ALERT;
}
use of org.talend.core.model.components.filters.IComponentFilter in project tdi-studio-se by Talend.
the class ChangeShareIdentityDefaultValueMigrationTaskIssue9519 method execute.
public ExecutionResult execute(Item item) {
ProcessType processType = getProcessType(item);
if (getProject().getLanguage() != ECodeLanguage.JAVA || processType == null) {
return ExecutionResult.NOTHING_TO_DO;
}
//$NON-NLS-1$
String[] componentsName = new String[] { "tMSSqlConnection" };
for (String name : componentsName) {
//$NON-NLS-1$
IComponentFilter filter = new NameComponentFilter(name);
try {
ModifyComponentsAction.searchAndModify(item, processType, filter, Arrays.<IComponentConversion>asList(new IComponentConversion() {
public void transform(NodeType node) {
// TODO Auto-generated method stub
//$NON-NLS-1$
ElementParameterType propertyShareIdentitySetting = ComponentUtilities.getNodeProperty(node, "SHARE_IDENTITY_SETTING");
if (propertyShareIdentitySetting == null) {
//$NON-NLS-1$
//$NON-NLS-1$ //$NON-NLS-2$
ComponentUtilities.addNodeProperty(node, "SHARE_IDENTITY_SETTING", "CHECK");
//$NON-NLS-1$ //$NON-NLS-2$
ComponentUtilities.setNodeValue(node, "SHARE_IDENTITY_SETTING", "true");
}
}
}));
} catch (PersistenceException e) {
// TODO Auto-generated catch block
ExceptionHandler.process(e);
return ExecutionResult.FAILURE;
}
}
return ExecutionResult.SUCCESS_NO_ALERT;
}
Aggregations