Search in sources :

Example 1 with MetadataType

use of org.talend.designer.core.model.utils.emf.talendfile.MetadataType 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 MetadataType

use of org.talend.designer.core.model.utils.emf.talendfile.MetadataType 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 MetadataType

use of org.talend.designer.core.model.utils.emf.talendfile.MetadataType 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 MetadataType

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

the class AddSchemaDefaultValue4tFileInputDelimited method execute.

@Override
public ExecutionResult execute(Item item) {
    ProcessType processType = getProcessType(item);
    IComponentFilter filter = new NameComponentFilter("tFileInputDelimited");
    try {
        ModifyComponentsAction.searchAndModify(item, processType, filter, Arrays.<IComponentConversion>asList(new IComponentConversion() {

            public void transform(NodeType node) {
                EList<EObject> list = node.eContents();
                for (EObject object : list) {
                    if (object instanceof MetadataType) {
                        MetadataType flow = (MetadataType) object;
                        if ("FLOW".equalsIgnoreCase(flow.getConnector())) {
                            Iterator<?> columns = flow.getColumn().iterator();
                            while (columns.hasNext()) {
                                Object outColumn = columns.next();
                                if (outColumn instanceof ColumnType) {
                                    ColumnType column = ((ColumnType) outColumn);
                                    JavaType javaType = JavaTypesManager.getJavaTypeFromId(column.getType());
                                    boolean isJavaPrimitiveType = JavaTypesManager.isJavaPrimitiveType(javaType, column.isNullable());
                                    if (isJavaPrimitiveType && (column.getDefaultValue() == null || column.getDefaultValue().isEmpty())) {
                                        String defaultValue = JavaTypesManager.getDefaultValueFromJavaType(javaType.getPrimitiveClass().getSimpleName(), null);
                                        if (defaultValue != null) {
                                            column.setDefaultValue(defaultValue);
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }));
    } catch (PersistenceException e) {
        ExceptionHandler.process(e);
        return ExecutionResult.FAILURE;
    }
    return ExecutionResult.SUCCESS_NO_ALERT;
}
Also used : ColumnType(org.talend.designer.core.model.utils.emf.talendfile.ColumnType) IComponentFilter(org.talend.core.model.components.filters.IComponentFilter) MetadataType(org.talend.designer.core.model.utils.emf.talendfile.MetadataType) NameComponentFilter(org.talend.core.model.components.filters.NameComponentFilter) ProcessType(org.talend.designer.core.model.utils.emf.talendfile.ProcessType) JavaType(org.talend.core.model.metadata.types.JavaType) NodeType(org.talend.designer.core.model.utils.emf.talendfile.NodeType) EObject(org.eclipse.emf.ecore.EObject) PersistenceException(org.talend.commons.exception.PersistenceException) EObject(org.eclipse.emf.ecore.EObject) IComponentConversion(org.talend.core.model.components.conversions.IComponentConversion)

Example 5 with MetadataType

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

the class ReplaceMultiFlowBytReplicateMigrationTask method createNodeType.

/**
     * DOC nrousseau Comment method "createNodeType".
     * 
     * @param processType
     * @param replicatePos
     * @param nodeTypeSource
     * @param sourceName
     * @param nodeConnector
     * @param connections
     * @param fileFact
     * @return
     */
private String createNodeType(ProcessType processType, Point replicatePos, NodeType nodeTypeSource, String sourceName, INodeConnector nodeConnector, List<ConnectionType> connections, TalendFileFactory fileFact) {
    NodeType nodeType = fileFact.createNodeType();
    //$NON-NLS-1$
    String uniqueName = ComponentUtilities.generateUniqueNodeName("tReplicate", processType);
    ElementParameterType elemParam = fileFact.createElementParameterType();
    //$NON-NLS-1$
    elemParam.setField("TEXT");
    //$NON-NLS-1$
    elemParam.setName("UNIQUE_NAME");
    elemParam.setValue(uniqueName);
    nodeType.getElementParameter().add(elemParam);
    ComponentUtilities.setNodeUniqueName(nodeType, uniqueName);
    //$NON-NLS-1$
    nodeType.setComponentName("tReplicate");
    for (ConnectionType connectionType : connections) {
        //$NON-NLS-1$
        connectionType.setConnectorName("FLOW");
        connectionType.setSource(uniqueName);
        connectionType.setMetaname(uniqueName);
    }
    nodeType.setPosX(replicatePos.x);
    nodeType.setPosY(replicatePos.y);
    nodeType.setSizeX(GRID_SIZE);
    nodeType.setSizeY(GRID_SIZE);
    if (nodeTypeSource.getMetadata().size() != 0) {
        MetadataType metadataTypeSource = null;
        for (Object oMetadataType : nodeTypeSource.getMetadata()) {
            MetadataType metadataType = (MetadataType) oMetadataType;
            if ((metadataType.getConnector() != null && metadataType.getConnector().equals(nodeConnector.getName())) || metadataType.getName().equals(sourceName)) {
                metadataTypeSource = metadataType;
            }
        }
        if (metadataTypeSource != null) {
            MetadataType newMetadataType = fileFact.createMetadataType();
            newMetadataType.setComment(metadataTypeSource.getComment());
            //$NON-NLS-1$
            newMetadataType.setConnector("FLOW");
            newMetadataType.setName(uniqueName);
            for (Object oColumn : metadataTypeSource.getColumn()) {
                ColumnType columnType = (ColumnType) oColumn;
                ColumnType newColumnType = fileFact.createColumnType();
                newColumnType.setComment(columnType.getComment());
                newColumnType.setDefaultValue(columnType.getDefaultValue());
                if (columnType.isSetKey()) {
                    newColumnType.setKey(columnType.isKey());
                }
                if (columnType.isSetLength()) {
                    newColumnType.setLength(columnType.getLength());
                }
                newColumnType.setName(columnType.getName());
                if (columnType.isSetNullable()) {
                    newColumnType.setNullable(columnType.isNullable());
                }
                newColumnType.setOriginalDbColumnName(columnType.getOriginalDbColumnName());
                newColumnType.setPattern(columnType.getPattern());
                if (columnType.isSetPrecision()) {
                    newColumnType.setPrecision(columnType.getPrecision());
                }
                newColumnType.setSourceType(columnType.getSourceType());
                newColumnType.setType(columnType.getType());
                newMetadataType.getColumn().add(newColumnType);
            }
            nodeType.getMetadata().add(newMetadataType);
        }
    }
    processType.getNode().add(nodeType);
    return uniqueName;
}
Also used : ElementParameterType(org.talend.designer.core.model.utils.emf.talendfile.ElementParameterType) ColumnType(org.talend.designer.core.model.utils.emf.talendfile.ColumnType) ConnectionType(org.talend.designer.core.model.utils.emf.talendfile.ConnectionType) NodeType(org.talend.designer.core.model.utils.emf.talendfile.NodeType) MetadataType(org.talend.designer.core.model.utils.emf.talendfile.MetadataType)

Aggregations

MetadataType (org.talend.designer.core.model.utils.emf.talendfile.MetadataType)14 NodeType (org.talend.designer.core.model.utils.emf.talendfile.NodeType)13 ColumnType (org.talend.designer.core.model.utils.emf.talendfile.ColumnType)10 ProcessType (org.talend.designer.core.model.utils.emf.talendfile.ProcessType)10 ElementParameterType (org.talend.designer.core.model.utils.emf.talendfile.ElementParameterType)5 PersistenceException (org.talend.commons.exception.PersistenceException)4 IComponentConversion (org.talend.core.model.components.conversions.IComponentConversion)3 IComponentFilter (org.talend.core.model.components.filters.IComponentFilter)3 NameComponentFilter (org.talend.core.model.components.filters.NameComponentFilter)3 ProcessItem (org.talend.core.model.properties.ProcessItem)3 ProxyRepositoryFactory (org.talend.core.repository.model.ProxyRepositoryFactory)3 ConnectionType (org.talend.designer.core.model.utils.emf.talendfile.ConnectionType)3 EList (org.eclipse.emf.common.util.EList)2 IComponent (org.talend.core.model.components.IComponent)2 IMetadataTable (org.talend.core.model.metadata.IMetadataTable)2 IElementParameter (org.talend.core.model.process.IElementParameter)2 TalendFileFactory (org.talend.designer.core.model.utils.emf.talendfile.TalendFileFactory)2 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 Iterator (java.util.Iterator)1