Search in sources :

Example 1 with TaggedValue

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());
    }
}
Also used : ComponentProperties(org.talend.components.api.properties.ComponentProperties) TaggedValue(orgomg.cwm.objectmodel.core.TaggedValue)

Example 2 with TaggedValue

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;
}
Also used : IMetadataTable(org.talend.core.model.metadata.IMetadataTable) TaggedValue(orgomg.cwm.objectmodel.core.TaggedValue) Schema(org.apache.avro.Schema) IMetadataTable(org.talend.core.model.metadata.IMetadataTable) MetadataTable(org.talend.core.model.metadata.builder.connection.MetadataTable) MetadataTableRepositoryObject(org.talend.core.repository.model.repositoryObject.MetadataTableRepositoryObject) IProxyRepositoryFactory(org.talend.repository.model.IProxyRepositoryFactory)

Example 3 with TaggedValue

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;
}
Also used : ComponentProperties(org.talend.components.api.properties.ComponentProperties) TaggedValue(orgomg.cwm.objectmodel.core.TaggedValue) ComponentWizard(org.talend.components.api.wizard.ComponentWizard) MetadataTable(org.talend.core.model.metadata.builder.connection.MetadataTable) GenericConnection(org.talend.repository.generic.model.genericMetadata.GenericConnection) ComponentService(org.talend.components.api.service.ComponentService) GenericConnectionItem(org.talend.repository.generic.model.genericMetadata.GenericConnectionItem) HashSet(java.util.HashSet)

Example 4 with TaggedValue

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;
}
Also used : MetadataColumn(org.talend.core.model.metadata.builder.connection.MetadataColumn) TaggedValue(orgomg.cwm.objectmodel.core.TaggedValue) Schema(org.apache.avro.Schema) MetadataTable(org.talend.core.model.metadata.builder.connection.MetadataTable)

Example 5 with TaggedValue

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;
}
Also used : MetadataColumn(org.talend.core.model.metadata.builder.connection.MetadataColumn) SalesforceModuleProperties(org.talend.components.salesforce.SalesforceModuleProperties) GenericRepository(org.talend.repository.generic.persistence.GenericRepository) TaggedValue(orgomg.cwm.objectmodel.core.TaggedValue) Schema(org.apache.avro.Schema) MetadataTable(org.talend.core.model.metadata.builder.connection.MetadataTable)

Aggregations

TaggedValue (orgomg.cwm.objectmodel.core.TaggedValue)11 MetadataTable (org.talend.core.model.metadata.builder.connection.MetadataTable)9 Schema (org.apache.avro.Schema)6 ComponentProperties (org.talend.components.api.properties.ComponentProperties)6 IMetadataTable (org.talend.core.model.metadata.IMetadataTable)5 MetadataColumn (org.talend.core.model.metadata.builder.connection.MetadataColumn)4 HashSet (java.util.HashSet)3 ArrayList (java.util.ArrayList)2 Map (java.util.Map)2 Connection (org.talend.core.model.metadata.builder.connection.Connection)2 MetadataTableRepositoryObject (org.talend.core.repository.model.repositoryObject.MetadataTableRepositoryObject)2 GenericConnection (org.talend.repository.generic.model.genericMetadata.GenericConnection)2 IOException (java.io.IOException)1 HashMap (java.util.HashMap)1 List (java.util.List)1 Point (org.eclipse.swt.graphics.Point)1 Test (org.junit.Test)1 ComponentService (org.talend.components.api.service.ComponentService)1 ComponentWizard (org.talend.components.api.wizard.ComponentWizard)1 SalesforceModuleProperties (org.talend.components.salesforce.SalesforceModuleProperties)1