Search in sources :

Example 1 with ColumnType

use of org.talend.designer.core.model.utils.emf.talendfile.ColumnType in project tdi-studio-se by Talend.

the class AddDdColumnMigrationTask method removeDbColumn.

private void removeDbColumn(Item item) throws PersistenceException {
    ProcessType processType = getProcessType(item);
    if (processType == null) {
        return;
    }
    ProxyRepositoryFactory factory = ProxyRepositoryFactory.getInstance();
    boolean modified = false;
    for (Object o : processType.getNode()) {
        NodeType node = (NodeType) o;
        for (Object o2 : node.getMetadata()) {
            MetadataType metadata = (MetadataType) o2;
            for (Object o3 : metadata.getColumn()) {
                ColumnType column = (ColumnType) o3;
                if (column.getOriginalDbColumnName() != null) {
                    column.setOriginalDbColumnName(null);
                    modified = true;
                }
            }
        }
    }
    if (modified) {
        factory.save(item, true);
    }
}
Also used : ProcessType(org.talend.designer.core.model.utils.emf.talendfile.ProcessType) ProxyRepositoryFactory(org.talend.core.repository.model.ProxyRepositoryFactory) ColumnType(org.talend.designer.core.model.utils.emf.talendfile.ColumnType) NodeType(org.talend.designer.core.model.utils.emf.talendfile.NodeType) MetadataType(org.talend.designer.core.model.utils.emf.talendfile.MetadataType)

Example 2 with ColumnType

use of org.talend.designer.core.model.utils.emf.talendfile.ColumnType in project tdi-studio-se by Talend.

the class RenameCustomerColumnOftGenKey method changeCustomerColumn.

private void changeCustomerColumn(Item item) throws PersistenceException {
    ProcessType processType = getProcessType(item);
    if (processType == null) {
        return;
    }
    ProxyRepositoryFactory factory = ProxyRepositoryFactory.getInstance();
    boolean modified = false;
    for (Object o : processType.getNode()) {
        NodeType node = (NodeType) o;
        for (Object o2 : node.getMetadata()) {
            MetadataType metadata = (MetadataType) o2;
            for (Object o3 : metadata.getColumn()) {
                ColumnType column = (ColumnType) o3;
                if ("T_WINDOW_KEY".equals(column.getName())) {
                    column.setName("T_GEN_KEY");
                    modified = true;
                }
            }
        }
    }
    if (modified) {
        factory.save(item, true);
    }
}
Also used : ProcessType(org.talend.designer.core.model.utils.emf.talendfile.ProcessType) ProxyRepositoryFactory(org.talend.core.repository.model.ProxyRepositoryFactory) ColumnType(org.talend.designer.core.model.utils.emf.talendfile.ColumnType) NodeType(org.talend.designer.core.model.utils.emf.talendfile.NodeType) MetadataType(org.talend.designer.core.model.utils.emf.talendfile.MetadataType)

Example 3 with ColumnType

use of org.talend.designer.core.model.utils.emf.talendfile.ColumnType in project tdi-studio-se by Talend.

the class FixWrongDbTypesMigrationTask 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 (processType == null) {
        return ExecutionResult.NOTHING_TO_DO;
    }
    boolean modified = false;
    for (Object nodeTypeObject : processType.getNode()) {
        NodeType nodeType = (NodeType) nodeTypeObject;
        IComponent component = ComponentsFactoryProvider.getInstance().get(nodeType.getComponentName(), ComponentCategory.CATEGORY_4_DI.getName());
        if (component == null) {
            // in case original component doesn't exist here
            continue;
        }
        FakeNode fNode = new FakeNode(component);
        IElementParameter mappingParameter = fNode.getElementParameterFromField(EParameterFieldType.MAPPING_TYPE);
        if (mappingParameter != null && mappingParameter.getValue() != null) {
            String mappingParameterValue = (String) mappingParameter.getValue();
            MappingTypeRetriever mtr = MetadataTalendType.getMappingTypeRetriever(mappingParameterValue);
            if (mtr == null) {
                continue;
            }
            for (Object metadataObject : nodeType.getMetadata()) {
                MetadataType metadataType = (MetadataType) metadataObject;
                for (Object columnObject : metadataType.getColumn()) {
                    ColumnType columnType = (ColumnType) columnObject;
                    if (columnType.getSourceType() != null && !"".equals(columnType.getSourceType())) {
                        if (mtr.isAdvicedTalendToDbType(columnType.getType(), columnType.getSourceType())) {
                            // correct type already, no need to do anything
                            continue;
                        }
                        List<MappingType> advicedTalendToDbTypes = mtr.getAdvicedTalendToDbTypes(columnType.getType());
                        if (advicedTalendToDbTypes == null) {
                            continue;
                        }
                        String dbType = columnType.getSourceType();
                        for (MappingType type : advicedTalendToDbTypes) {
                            if (type.getDbType().equalsIgnoreCase(dbType)) {
                                columnType.setSourceType(type.getDbType());
                                modified = true;
                                break;
                            }
                        }
                    }
                }
            }
        }
    }
    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;
}
Also used : MappingType(org.talend.core.model.metadata.MappingType) ColumnType(org.talend.designer.core.model.utils.emf.talendfile.ColumnType) MappingTypeRetriever(org.talend.core.model.metadata.MappingTypeRetriever) IComponent(org.talend.core.model.components.IComponent) MetadataType(org.talend.designer.core.model.utils.emf.talendfile.MetadataType) ProcessType(org.talend.designer.core.model.utils.emf.talendfile.ProcessType) NodeType(org.talend.designer.core.model.utils.emf.talendfile.NodeType) PersistenceException(org.talend.commons.exception.PersistenceException) IElementParameter(org.talend.core.model.process.IElementParameter)

Example 4 with ColumnType

use of org.talend.designer.core.model.utils.emf.talendfile.ColumnType in project tdi-studio-se by Talend.

the class MetadataEmfFactory method setMetadataTypeCommon.

@SuppressWarnings("unchecked")
private void setMetadataTypeCommon(final MetadataType metadataType) {
    this.metadataType = metadataType;
    IMetadataColumn metaCol;
    ColumnType colType;
    EList listColType;
    List<IMetadataColumn> listMetadataColumn;
    metadataTable.setComment(metadataType.getComment());
    metadataTable.setTableName(metadataType.getName());
    metadataTable.setLabel(metadataType.getLabel());
    metadataTable.setTableType(metadataType.getType());
    EMap<String, String> properties = metadataType.getAdditionalProperties();
    if (properties != null) {
        for (Map.Entry<String, String> entry : properties.entrySet()) {
            metadataTable.getAdditionalProperties().put(entry.getKey(), entry.getValue());
        }
    }
    if (metadataType.getConnector() != null) {
        metadataTable.setAttachedConnector(metadataType.getConnector());
    } else {
        metadataTable.setAttachedConnector(EConnectionType.FLOW_MAIN.getName());
    }
    listColType = metadataType.getColumn();
    listMetadataColumn = new ArrayList<IMetadataColumn>();
    for (int i = 0; i < listColType.size(); i++) {
        colType = (ColumnType) listColType.get(i);
        metaCol = new MetadataColumn();
        metaCol.setComment(colType.getComment());
        metaCol.setKey(colType.isKey());
        metaCol.setNullable(colType.isNullable());
        if (colType.getLength() >= 0) {
            metaCol.setLength(new Integer(colType.getLength()));
        } else {
            metaCol.setLength(null);
        }
        if (colType.getOriginalLength() >= 0) {
            metaCol.setOriginalLength(new Integer(colType.getOriginalLength()));
        } else {
            metaCol.setOriginalLength(null);
        }
        if (colType.getAdditionalField().size() > 0) {
            Iterator it = colType.getAdditionalField().keySet().iterator();
            while (it.hasNext()) {
                String key = (String) it.next();
                metaCol.getAdditionalField().put(key, (String) colType.getAdditionalField().get(key));
            }
        }
        metaCol.setLabel(colType.getName());
        if (colType.getPrecision() >= 0) {
            metaCol.setPrecision(new Integer(colType.getPrecision()));
        } else {
            metaCol.setPrecision(null);
        }
        metaCol.setTalendType(colType.getType());
        metaCol.setType(colType.getSourceType());
        metaCol.setPattern(colType.getPattern());
        metaCol.setDefault(colType.getDefaultValue());
        metaCol.setRelatedEntity(colType.getRelatedEntity());
        metaCol.setRelationshipType(colType.getRelationshipType());
        if (colType.getOriginalDbColumnName() == null) {
            metaCol.setOriginalDbColumnName(colType.getName());
        } else {
            metaCol.setOriginalDbColumnName(colType.getOriginalDbColumnName());
        }
        metaCol.setUsefulColumn(colType.isUsefulColumn());
        listMetadataColumn.add(metaCol);
    }
    metadataTable.setListColumns(listMetadataColumn);
    List<String> columnNames = new ArrayList<String>();
    for (IMetadataColumn column : listMetadataColumn) {
        columnNames.add(column.getLabel());
    }
    metadataTable.setOriginalColumns(columnNames);
}
Also used : ColumnType(org.talend.designer.core.model.utils.emf.talendfile.ColumnType) ArrayList(java.util.ArrayList) IMetadataColumn(org.talend.core.model.metadata.IMetadataColumn) IMetadataColumn(org.talend.core.model.metadata.IMetadataColumn) MetadataColumn(org.talend.core.model.metadata.MetadataColumn) EList(org.eclipse.emf.common.util.EList) Iterator(java.util.Iterator) EMap(org.eclipse.emf.common.util.EMap) Map(java.util.Map)

Example 5 with ColumnType

use of org.talend.designer.core.model.utils.emf.talendfile.ColumnType in project tdi-studio-se by Talend.

the class MetadataEmfFactory method setMetadataTable.

@SuppressWarnings("unchecked")
public void setMetadataTable(final IMetadataTable metadataTable) {
    this.metadataTable = metadataTable;
    TalendFileFactory fileFact = TalendFileFactory.eINSTANCE;
    metadataType = fileFact.createMetadataType();
    IMetadataColumn metaCol;
    ColumnType colType;
    EList listColType;
    metadataType.setComment(metadataTable.getComment());
    metadataType.setName(metadataTable.getTableName());
    metadataType.setLabel(metadataTable.getLabel());
    metadataType.setConnector(metadataTable.getAttachedConnector());
    metadataType.setType(metadataTable.getTableType());
    metadataType.getAdditionalProperties().putAll(metadataTable.getAdditionalProperties());
    listColType = metadataType.getColumn();
    if (metadataTable.getListColumns(true) != null) {
        for (int i = 0; i < metadataTable.getListColumns(true).size(); i++) {
            metaCol = metadataTable.getListColumns(true).get(i);
            colType = fileFact.createColumnType();
            colType.setComment(metaCol.getComment());
            colType.setKey(metaCol.isKey());
            colType.setNullable(metaCol.isNullable());
            if (metaCol.getLength() == null || metaCol.getLength().intValue() < 0) {
                colType.setLength(-1);
            // colType.unsetLength();
            } else {
                colType.setLength(metaCol.getLength());
            }
            if (metaCol.getOriginalLength() != null) {
                colType.setOriginalLength(metaCol.getOriginalLength());
            } else {
                colType.setOriginalLength(-1);
            }
            if (metaCol.getAdditionalField().size() > 0) {
                for (String key : metaCol.getAdditionalField().keySet()) {
                    colType.getAdditionalField().put(key, metaCol.getAdditionalField().get(key));
                }
            }
            colType.setName(metaCol.getLabel());
            if (metaCol.getPrecision() == null || metaCol.getPrecision().intValue() < 0) {
                colType.setPrecision(-1);
            // colType.unsetPrecision();
            } else {
                colType.setPrecision(metaCol.getPrecision());
            }
            if (!metaCol.getLabel().equals(metaCol.getOriginalDbColumnName())) {
                colType.setOriginalDbColumnName(metaCol.getOriginalDbColumnName());
            }
            colType.setType(metaCol.getTalendType());
            colType.setSourceType(metaCol.getType());
            colType.setPattern(metaCol.getPattern());
            colType.setDefaultValue(metaCol.getDefault());
            if (PluginChecker.isDatacertPluginLoaded()) {
                colType.setRelatedEntity(metaCol.getRelatedEntity());
                colType.setRelationshipType(metaCol.getRelationshipType());
            }
            colType.setUsefulColumn(metaCol.isUsefulColumn());
            listColType.add(colType);
        }
    }
}
Also used : ColumnType(org.talend.designer.core.model.utils.emf.talendfile.ColumnType) EList(org.eclipse.emf.common.util.EList) TalendFileFactory(org.talend.designer.core.model.utils.emf.talendfile.TalendFileFactory) IMetadataColumn(org.talend.core.model.metadata.IMetadataColumn)

Aggregations

ColumnType (org.talend.designer.core.model.utils.emf.talendfile.ColumnType)15 MetadataType (org.talend.designer.core.model.utils.emf.talendfile.MetadataType)10 NodeType (org.talend.designer.core.model.utils.emf.talendfile.NodeType)9 ProcessType (org.talend.designer.core.model.utils.emf.talendfile.ProcessType)8 EList (org.eclipse.emf.common.util.EList)4 ElementParameterType (org.talend.designer.core.model.utils.emf.talendfile.ElementParameterType)4 PersistenceException (org.talend.commons.exception.PersistenceException)3 ProxyRepositoryFactory (org.talend.core.repository.model.ProxyRepositoryFactory)3 TalendFileFactory (org.talend.designer.core.model.utils.emf.talendfile.TalendFileFactory)3 ArrayList (java.util.ArrayList)2 Iterator (java.util.Iterator)2 IComponentConversion (org.talend.core.model.components.conversions.IComponentConversion)2 IComponentFilter (org.talend.core.model.components.filters.IComponentFilter)2 NameComponentFilter (org.talend.core.model.components.filters.NameComponentFilter)2 IMetadataColumn (org.talend.core.model.metadata.IMetadataColumn)2 ConnectionType (org.talend.designer.core.model.utils.emf.talendfile.ConnectionType)2 Map (java.util.Map)1 EMap (org.eclipse.emf.common.util.EMap)1 EObject (org.eclipse.emf.ecore.EObject)1 Test (org.junit.Test)1