Search in sources :

Example 1 with IDbMapService

use of org.talend.core.service.IDbMapService in project tdi-studio-se by Talend.

the class UpdateELTComponentMigrationTask method execute.

@Override
public ExecutionResult execute(Item item) {
    boolean isModified = false;
    ProcessType processType = getProcessType(item);
    List nodes = processType.getNode();
    List<ConnectionType> connections = processType.getConnection();
    for (ConnectionType connection : connections) {
        String sourceNodeName = connection.getSource();
        String targetNodeName = connection.getTarget();
        if (sourceNodeName.matches("tELT.+Input.+") && targetNodeName.matches("tELT.+Map.+")) {
            //$NON-NLS-1$ //$NON-NLS-2$
            NodeType eltInputNode = getNodeTypeByUniqueName(nodes, sourceNodeName);
            //$NON-NLS-1$
            String orginalTableName = getPropertyValue(eltInputNode, "ELT_TABLE_NAME");
            //$NON-NLS-1$
            String orginalSchemaName = getPropertyValue(eltInputNode, "ELT_SCHEMA_NAME");
            if (orginalSchemaName == null) {
                continue;
            }
            String tableName = TalendQuoteUtils.removeQuotes(orginalTableName);
            String schemaName = TalendQuoteUtils.removeQuotes(orginalSchemaName);
            String connectionName;
            if (schemaName.trim().equals("")) {
                //$NON-NLS-1$
                connectionName = tableName;
            } else {
                //$NON-NLS-1$
                connectionName = schemaName + "." + tableName;
            }
            if (connection.getLabel().equals(tableName)) {
                connection.setLabel(connectionName);
                isModified = true;
            }
            List<MetadataTypeImpl> tables = eltInputNode.getMetadata();
            for (MetadataTypeImpl table : tables) {
                if (table.getLabel().equals(tableName)) {
                    table.setLabel(connectionName);
                    isModified = true;
                }
            }
            NodeType eltMapNode = getNodeTypeByUniqueName(nodes, targetNodeName);
            if (GlobalServiceRegister.getDefault().isServiceRegistered(IDbMapService.class)) {
                IDbMapService service = (IDbMapService) GlobalServiceRegister.getDefault().getService(IDbMapService.class);
                service.updateEMFDBMapData(eltMapNode, tableName, connectionName);
                isModified = true;
            }
        }
    }
    if (isModified) {
        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 : ProcessType(org.talend.designer.core.model.utils.emf.talendfile.ProcessType) ConnectionType(org.talend.designer.core.model.utils.emf.talendfile.ConnectionType) MetadataTypeImpl(org.talend.designer.core.model.utils.emf.talendfile.impl.MetadataTypeImpl) NodeType(org.talend.designer.core.model.utils.emf.talendfile.NodeType) PersistenceException(org.talend.commons.exception.PersistenceException) List(java.util.List) IDbMapService(org.talend.core.service.IDbMapService)

Aggregations

List (java.util.List)1 PersistenceException (org.talend.commons.exception.PersistenceException)1 IDbMapService (org.talend.core.service.IDbMapService)1 ConnectionType (org.talend.designer.core.model.utils.emf.talendfile.ConnectionType)1 NodeType (org.talend.designer.core.model.utils.emf.talendfile.NodeType)1 ProcessType (org.talend.designer.core.model.utils.emf.talendfile.ProcessType)1 MetadataTypeImpl (org.talend.designer.core.model.utils.emf.talendfile.impl.MetadataTypeImpl)1