Search in sources :

Example 6 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)

Example 7 with TaggedValue

use of orgomg.cwm.objectmodel.core.TaggedValue in project tdi-studio-se by Talend.

the class NewDelimitedFileWizardMigrationTask method updateMetadataTable.

@Override
protected boolean updateMetadataTable(Connection oldConnection, Connection genericConnection, ComponentProperties componentProperties) {
    boolean modified = false;
    if (oldConnection == null || genericConnection == null || componentProperties == null) {
        return modified;
    }
    Set<MetadataTable> tables = ConnectionHelper.getTables(oldConnection);
    Set<MetadataTable> newTables = new HashSet<>(tables);
    for (MetadataTable metaTable : newTables) {
        TaggedValue serializedPropsTV = CoreFactory.eINSTANCE.createTaggedValue();
        serializedPropsTV.setTag(IComponentConstants.COMPONENT_PROPERTIES_TAG);
        serializedPropsTV.setValue(componentProperties.toSerialized());
        metaTable.getTaggedValue().add(serializedPropsTV);
        TaggedValue schemaPropertyTV = CoreFactory.eINSTANCE.createTaggedValue();
        schemaPropertyTV.setTag(IComponentConstants.COMPONENT_SCHEMA_TAG);
        schemaPropertyTV.setValue(SCHEMA);
        metaTable.getTaggedValue().add(schemaPropertyTV);
        ((orgomg.cwm.objectmodel.core.Package) genericConnection).getOwnedElement().add(metaTable);
        Schema schema = SchemaUtils.convertTalendSchemaIntoComponentSchema(metaTable);
        componentProperties.setValue(SCHEMA, schema);
        modified = true;
    }
    return modified;
}
Also used : TaggedValue(orgomg.cwm.objectmodel.core.TaggedValue) Schema(org.apache.avro.Schema) MetadataTable(org.talend.core.model.metadata.builder.connection.MetadataTable) HashSet(java.util.HashSet)

Example 8 with TaggedValue

use of orgomg.cwm.objectmodel.core.TaggedValue in project tdi-studio-se by Talend.

the class NewSalesforceWizardMigrationTask method updateMetadataTable.

@Override
protected boolean updateMetadataTable(Connection oldConnection, Connection genericConnection, ComponentProperties componentProperties) {
    boolean modified = false;
    if (oldConnection == null || genericConnection == null || componentProperties == null) {
        return modified;
    }
    Set<MetadataTable> tables = ConnectionHelper.getTables(oldConnection);
    Set<MetadataTable> newTables = new HashSet<>();
    newTables.addAll(tables);
    for (MetadataTable metaTable : newTables) {
        try {
            Object object = ReflectionUtils.newInstance(REFLECTION_SALESFORCE_MODULE_PROPERTIES, componentProperties.getClass().getClassLoader(), new Object[] { metaTable.getName() });
            if (object != null && object instanceof ComponentProperties) {
                ComponentProperties salesforceModuleProperties = (ComponentProperties) object;
                //$NON-NLS-1$
                salesforceModuleProperties.getProperties("connection").copyValuesFrom(componentProperties, true, false);
                //$NON-NLS-1$
                NamedThing tmp = salesforceModuleProperties.getProperty("moduleName");
                //$NON-NLS-1$
                ((Property) tmp).setTaggedValue(IGenericConstants.REPOSITORY_VALUE, "moduleName");
                ((Property) tmp).setValue(metaTable.getLabel());
                TaggedValue serializedPropsTV = CoreFactory.eINSTANCE.createTaggedValue();
                serializedPropsTV.setTag(IComponentConstants.COMPONENT_PROPERTIES_TAG);
                serializedPropsTV.setValue(salesforceModuleProperties.toSerialized());
                metaTable.getTaggedValue().add(serializedPropsTV);
                TaggedValue schemaPropertyTV = CoreFactory.eINSTANCE.createTaggedValue();
                schemaPropertyTV.setTag(IComponentConstants.COMPONENT_SCHEMA_TAG);
                schemaPropertyTV.setValue(SCHEMA_SCHEMA);
                metaTable.getTaggedValue().add(schemaPropertyTV);
                Schema schema = SchemaUtils.convertTalendSchemaIntoComponentSchema(metaTable);
                salesforceModuleProperties.setValue(SCHEMA_SCHEMA, schema);
                ((orgomg.cwm.objectmodel.core.Package) genericConnection).getOwnedElement().add(metaTable);
                modified = true;
            }
        } catch (Exception e) {
            ExceptionHandler.process(e);
        }
    }
    return modified;
}
Also used : ComponentProperties(org.talend.components.api.properties.ComponentProperties) TaggedValue(orgomg.cwm.objectmodel.core.TaggedValue) Schema(org.apache.avro.Schema) NamedThing(org.talend.daikon.NamedThing) IOException(java.io.IOException) MetadataTable(org.talend.core.model.metadata.builder.connection.MetadataTable) IRepositoryViewObject(org.talend.core.model.repository.IRepositoryViewObject) Property(org.talend.daikon.properties.property.Property) HashSet(java.util.HashSet)

Example 9 with TaggedValue

use of orgomg.cwm.objectmodel.core.TaggedValue in project tdi-studio-se by Talend.

the class SchemaUtils method getCurrentComponentProperties.

public static ComponentProperties getCurrentComponentProperties(IMetadataTable table) {
    if (table != null) {
        String serializedProperties = null;
        SerializerDeserializer.Deserialized<ComponentProperties> fromSerializedProperties = null;
        if (table instanceof MetadataTableRepositoryObject) {
            MetadataTableRepositoryObject metaTableRepObj = (MetadataTableRepositoryObject) table;
            MetadataTable metadataTable = metaTableRepObj.getTable();
            if (metadataTable != null && metadataTable.getTaggedValue() != null) {
                for (TaggedValue serializedProps : metadataTable.getTaggedValue()) {
                    if (IComponentConstants.COMPONENT_PROPERTIES_TAG.equals(serializedProps.getTag())) {
                        serializedProperties = serializedProps.getValue();
                        break;
                    }
                }
            }
            if (serializedProperties != null) {
                Connection connection = ((ConnectionItem) metaTableRepObj.getViewObject().getProperty().getItem()).getConnection();
                return ComponentsUtils.getComponentPropertiesFromSerialized(serializedProperties, connection);
            }
        } else if (table instanceof org.talend.core.model.metadata.MetadataTable) {
            org.talend.core.model.metadata.MetadataTable metaTable = (org.talend.core.model.metadata.MetadataTable) table;
            Map<String, String> additionalProperties = metaTable.getAdditionalProperties();
            serializedProperties = additionalProperties.get(IComponentConstants.COMPONENT_PROPERTIES_TAG);
            if (serializedProperties != null) {
                fromSerializedProperties = Properties.Helper.fromSerializedPersistent(serializedProperties, ComponentProperties.class, null);
            }
        }
        if (fromSerializedProperties != null) {
            return fromSerializedProperties.object;
        }
    }
    return null;
}
Also used : ComponentProperties(org.talend.components.api.properties.ComponentProperties) TaggedValue(orgomg.cwm.objectmodel.core.TaggedValue) ConnectionItem(org.talend.core.model.properties.ConnectionItem) Connection(org.talend.core.model.metadata.builder.connection.Connection) MetadataTableRepositoryObject(org.talend.core.repository.model.repositoryObject.MetadataTableRepositoryObject) IMetadataTable(org.talend.core.model.metadata.IMetadataTable) MetadataTable(org.talend.core.model.metadata.builder.connection.MetadataTable) SerializerDeserializer(org.talend.daikon.serialize.SerializerDeserializer) Map(java.util.Map)

Example 10 with TaggedValue

use of orgomg.cwm.objectmodel.core.TaggedValue in project tdi-studio-se by Talend.

the class GenericWizardService method getAllComponentProperties.

@Override
public List<ComponentProperties> getAllComponentProperties(Connection connection, String tableLabel) {
    List<ComponentProperties> componentProperties = new ArrayList<>();
    if (isGenericConnection(connection)) {
        GenericConnection genericConnection = (GenericConnection) connection;
        String compProperties = genericConnection.getCompProperties();
        ComponentProperties cp = ComponentsUtils.getComponentPropertiesFromSerialized(compProperties, connection, false);
        if (cp != null) {
            componentProperties.add(cp);
        }
        List<MetadataTable> metadataTables;
        if (tableLabel == null) {
            metadataTables = SchemaUtils.getMetadataTables(genericConnection, SubContainer.class);
        } else {
            metadataTables = Arrays.asList(SchemaUtils.getMetadataTable(genericConnection, tableLabel, SubContainer.class));
        }
        for (MetadataTable metadataTable : metadataTables) {
            if (metadataTable == null) {
                continue;
            }
            for (TaggedValue taggedValue : metadataTable.getTaggedValue()) {
                if (IComponentConstants.COMPONENT_PROPERTIES_TAG.equals(taggedValue.getTag())) {
                    ComponentProperties compPros = ComponentsUtils.getComponentPropertiesFromSerialized(taggedValue.getValue(), connection, false);
                    if (compPros != null && !componentProperties.contains(compPros)) {
                        compPros.updateNestedProperties(cp);
                        componentProperties.add(compPros);
                    }
                }
            }
        }
    }
    return componentProperties;
}
Also used : ComponentProperties(org.talend.components.api.properties.ComponentProperties) TaggedValue(orgomg.cwm.objectmodel.core.TaggedValue) ArrayList(java.util.ArrayList) IMetadataTable(org.talend.core.model.metadata.IMetadataTable) MetadataTable(org.talend.core.model.metadata.builder.connection.MetadataTable) GenericConnection(org.talend.repository.generic.model.genericMetadata.GenericConnection) SubContainer(org.talend.repository.generic.model.genericMetadata.SubContainer)

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