use of orgomg.cwm.objectmodel.core.TaggedValue in project tdi-studio-se by Talend.
the class SchemaUtils method updateComponentSchema.
/**
* DOC ycbai Comment method "updateComponentSchema".
* <p>
* Recreate a component schema by <code>metadataTable<code> and save it back into the <code>metadataTable<code>.
*
* @param metadataTable
* @param connection
*/
public static void updateComponentSchema(MetadataTable metadataTable, Connection connection) {
if (metadataTable == null) {
return;
}
String componentPropertiesStr = null;
String schemaPropertyName = null;
TaggedValue componentPropertiesTaggedValue = null;
EList<TaggedValue> taggedValues = metadataTable.getTaggedValue();
for (TaggedValue taggedValue : taggedValues) {
String tag = taggedValue.getTag();
String tagValue = taggedValue.getValue();
if (IComponentConstants.COMPONENT_PROPERTIES_TAG.equals(tag)) {
componentPropertiesStr = tagValue;
componentPropertiesTaggedValue = taggedValue;
} else if (IComponentConstants.COMPONENT_SCHEMA_TAG.equals(tag)) {
schemaPropertyName = tagValue;
}
}
if (componentPropertiesStr != null && componentPropertiesTaggedValue != null && schemaPropertyName != null) {
ComponentProperties componentProperties = ComponentsUtils.getComponentPropertiesFromSerialized(componentPropertiesStr, connection);
componentProperties.setValue(schemaPropertyName, convertTalendSchemaIntoComponentSchema(metadataTable));
componentPropertiesTaggedValue.setValue(componentProperties.toSerialized());
}
}
use of orgomg.cwm.objectmodel.core.TaggedValue in project tdi-studio-se by Talend.
the class SchemaUtils method createSchema.
public static MetadataTable createSchema(String name, ComponentProperties properties, String schemaPropertyName) {
if (name == null || properties == null || schemaPropertyName == null) {
return null;
}
IProxyRepositoryFactory factory = ProxyRepositoryFactory.getInstance();
MetadataTable metadataTable = ConnectionFactory.eINSTANCE.createMetadataTable();
metadataTable.setId(factory.getNextId());
metadataTable.setName(name);
metadataTable.setLabel(name);
metadataTable.setSourceName(name);
Object schemaObj = ComponentsUtils.getGenericPropertyValue(properties, schemaPropertyName);
if (schemaObj instanceof String) {
Schema avroSchema = new Schema.Parser().parse((String) schemaObj);
convertComponentSchemaIntoTalendSchema(avroSchema, metadataTable);
} else if (schemaObj instanceof Schema) {
convertComponentSchemaIntoTalendSchema((Schema) schemaObj, metadataTable);
}
IMetadataTable iMetadataTable = MetadataToolHelper.convert(metadataTable);
updateComponentSchema(properties, schemaPropertyName, iMetadataTable);
metadataTable = ConvertionHelper.convert(iMetadataTable);
properties.setValue(schemaPropertyName, convertTalendSchemaIntoComponentSchema(metadataTable));
TaggedValue serializedPropsTV = CoreFactory.eINSTANCE.createTaggedValue();
serializedPropsTV.setTag(IComponentConstants.COMPONENT_PROPERTIES_TAG);
serializedPropsTV.setValue(properties.toSerialized());
metadataTable.getTaggedValue().add(serializedPropsTV);
TaggedValue schemaPropertyTV = CoreFactory.eINSTANCE.createTaggedValue();
schemaPropertyTV.setTag(IComponentConstants.COMPONENT_SCHEMA_TAG);
schemaPropertyTV.setValue(schemaPropertyName);
metadataTable.getTaggedValue().add(schemaPropertyTV);
return metadataTable;
}
use of orgomg.cwm.objectmodel.core.TaggedValue in project tdi-studio-se by Talend.
the class Salesforce620WizardMigration method execute.
/*
* (non-Javadoc)
*
* @see org.talend.core.model.migration.AbstractItemMigrationTask#execute(org.talend.core.model.properties.Item)
*/
@Override
public ExecutionResult execute(Item item) {
if (GenericWizardServiceFactory.getGenericWizardService().isGenericItem(item)) {
try {
GenericConnectionItem connectionItem = (GenericConnectionItem) item;
GenericConnection connection = (GenericConnection) connectionItem.getConnection();
String serialized = connection.getCompProperties();
ComponentService service = ComponentsUtils.getComponentService();
ComponentWizard componentWizard = service.getComponentWizard(NewSalesforceWizardMigrationTask.TYPE_NAME, item.getProperty().getId());
ComponentProperties newProperties = (ComponentProperties) componentWizard.getForms().get(0).getProperties();
newProperties.init();
ComponentProperties properties = loadProperties(serialized, newProperties);
updateSubProperties(properties, newProperties);
newProperties.copyValuesFrom(properties, true, false);
connection.setCompProperties(newProperties.toSerialized());
Set<MetadataTable> tables = new HashSet<MetadataTable>();
PackageHelper.getAllTables(connection, tables);
for (MetadataTable table : tables) {
EList<TaggedValue> values = table.getTaggedValue();
for (TaggedValue value : values) {
if (IComponentConstants.COMPONENT_PROPERTIES_TAG.equals(value.getTag())) {
Object object = ReflectionUtils.newInstance(NewSalesforceWizardMigrationTask.REFLECTION_SALESFORCE_MODULE_PROPERTIES, newProperties.getClass().getClassLoader(), new Object[] { table.getName() });
if (object != null && object instanceof ComponentProperties) {
ComponentProperties newSalesforceModuleProperties = (ComponentProperties) object;
ComponentProperties moduleProperties = loadProperties(value.getValue(), newSalesforceModuleProperties);
updateSubProperties(moduleProperties, newSalesforceModuleProperties);
newSalesforceModuleProperties.copyValuesFrom(moduleProperties, true, false);
value.setValue(newSalesforceModuleProperties.toSerialized());
}
}
}
}
ProxyRepositoryFactory.getInstance().save(connectionItem, true);
return ExecutionResult.SUCCESS_NO_ALERT;
} catch (Exception e) {
ExceptionHandler.process(e);
return ExecutionResult.FAILURE;
}
}
return ExecutionResult.NOTHING_TO_DO;
}
use of orgomg.cwm.objectmodel.core.TaggedValue in project tdi-studio-se by Talend.
the class MetadataUtils method createTable.
/**
* Create a MetadataTable instance with ComponentProperties
*
* @param tableName is the table name
* @param columnList is a map which key is column attribute key from {@link IMetadataTableConstants} and value is
* attribute value
* @param schemaProperties is the ComponentProperties which contained component schema
* @return
*/
public static MetadataTable createTable(String tableName, List<Map<String, Object>> columnList, SchemaProperties schemaProperties) {
MetadataTable table = ConnectionFactory.eINSTANCE.createMetadataTable();
table.setName(tableName);
table.setLabel(table.getName());
for (Map<String, Object> columnAttrMap : columnList) {
MetadataColumn column = createColumn(columnAttrMap);
if (column != null) {
table.getColumns().add(column);
}
}
Schema avroSchema = MetadataToolAvroHelper.convertToAvro(table);
schemaProperties.schema.setValue(avroSchema);
// Set the component properties and schema property name into MetadataTable.
TaggedValue serializedPropsTV = CoreFactory.eINSTANCE.createTaggedValue();
serializedPropsTV.setTag(IComponentConstants.COMPONENT_PROPERTIES_TAG);
serializedPropsTV.setValue(schemaProperties.toSerialized());
table.getTaggedValue().add(serializedPropsTV);
TaggedValue schemaPropertyTV = CoreFactory.eINSTANCE.createTaggedValue();
schemaPropertyTV.setTag(IComponentConstants.COMPONENT_SCHEMA_TAG);
schemaPropertyTV.setValue(schemaProperties.schema.getName());
table.getTaggedValue().add(schemaPropertyTV);
return table;
}
use of orgomg.cwm.objectmodel.core.TaggedValue in project tdi-studio-se by Talend.
the class RepositoryUpdateTest method prepareTableForTest.
private MetadataTable prepareTableForTest(String id) {
MetadataTable table = ConnectionFactory.eINSTANCE.createMetadataTable();
table.setLabel("myTableTest");
MetadataColumn col1 = ConnectionFactory.eINSTANCE.createMetadataColumn();
col1.setLabel("myColumn1");
col1.setTalendType(JavaTypesManager.STRING.getId());
col1.setLength(25);
table.getColumns().add(col1);
Schema avroSchema = MetadataToolAvroHelper.convertToAvro(table);
TaggedValue tv = CoreFactory.eINSTANCE.createTaggedValue();
tv.setTag(IComponentConstants.COMPONENT_PROPERTIES_TAG);
SalesforceModuleProperties smp = new SalesforceModuleProperties("test");
smp.connection.init();
// because we should get connection always from the main
smp.connection.userPassword.userId.setValue("old");
// SalesforceConnectionProperties
smp.moduleName.setStoredValue("myModule");
smp.main.schema.setStoredValue(avroSchema);
GenericRepository gr = new GenericRepository();
gr.storeProperties(smp, table.getLabel(), id + "#", "main.schema");
return table;
}
Aggregations