Search in sources :

Example 81 with PersistenceException

use of org.talend.commons.exception.PersistenceException in project tdi-studio-se by Talend.

the class JSONConnectionContextHelper method convertContextLabel.

/**
     * 
     * change the mode of lebel to Context mode
     * 
     * @param label which you want to convert(it is the name of connection normal)
     * @return Context mode label
     */
public static String convertContextLabel(String label) {
    if (label != null) {
        //$NON-NLS-1$ //$NON-NLS-2$
        String newLabel = label.replaceAll("[\\.\\-\\ \\(\\)\\[\\]=]", "_");
        //$NON-NLS-1$
        Pattern pattern = Pattern.compile("^[0-9]+.*$");
        Matcher m = pattern.matcher(newLabel);
        if (m.matches()) {
            //$NON-NLS-1$
            newLabel = "_" + newLabel;
        }
        //
        try {
            ProxyRepositoryFactory factory = ProxyRepositoryFactory.getInstance();
            List<IRepositoryViewObject> contextObjectList = factory.getAll(ERepositoryObjectType.CONTEXT, true);
            int i = 1;
            String tmpLabel = newLabel;
            while (!isValidContextName(contextObjectList, tmpLabel)) {
                tmpLabel = newLabel + i;
                i++;
            }
            return tmpLabel;
        } catch (PersistenceException e) {
            ExceptionHandler.process(e);
        }
        return newLabel;
    }
    return null;
}
Also used : Pattern(java.util.regex.Pattern) ProxyRepositoryFactory(org.talend.core.repository.model.ProxyRepositoryFactory) Matcher(java.util.regex.Matcher) IRepositoryViewObject(org.talend.core.model.repository.IRepositoryViewObject) PersistenceException(org.talend.commons.exception.PersistenceException)

Example 82 with PersistenceException

use of org.talend.commons.exception.PersistenceException in project tdi-studio-se by Talend.

the class FillParametersForDatabaseConnectionMigrationTask method execute.

@Override
public ExecutionResult execute(Item item) {
    if (item instanceof DatabaseConnectionItem) {
        DatabaseConnectionItem dbItem = (DatabaseConnectionItem) item;
        Connection connection = dbItem.getConnection();
        DatabaseConnection dbconn = (DatabaseConnection) connection;
        EList<orgomg.cwm.objectmodel.core.Package> pkgs = dbconn.getDataPackage();
        // get all tdtables and set sqldatatype
        fillParametersForColumns(pkgs);
        dbconn.setName(dbItem.getProperty().getLabel());
        try {
            factory.save(dbItem, true);
            return ExecutionResult.SUCCESS_WITH_ALERT;
        } catch (PersistenceException e) {
            ExceptionHandler.process(e);
            return ExecutionResult.FAILURE;
        }
    }
    return ExecutionResult.SUCCESS_NO_ALERT;
}
Also used : DatabaseConnection(org.talend.core.model.metadata.builder.connection.DatabaseConnection) Connection(org.talend.core.model.metadata.builder.connection.Connection) PersistenceException(org.talend.commons.exception.PersistenceException) DatabaseConnection(org.talend.core.model.metadata.builder.connection.DatabaseConnection) DatabaseConnectionItem(org.talend.core.model.properties.DatabaseConnectionItem)

Example 83 with PersistenceException

use of org.talend.commons.exception.PersistenceException in project tdi-studio-se by Talend.

the class FixUnevenItemContextParametersMigrationTask method execute.

@SuppressWarnings("unchecked")
@Override
public ExecutionResult execute(Item item) {
    EList<ContextType> contexts = null;
    String defualtGroupName = null;
    if (item instanceof ProcessItem) {
        // process, process_mr, process_storm, route, routelet.
        ProcessItem processItem = (ProcessItem) item;
        contexts = processItem.getProcess().getContext();
        defualtGroupName = processItem.getProcess().getDefaultContext();
    } else if (item instanceof JobletProcessItem) {
        JobletProcessItem jobletItem = (JobletProcessItem) item;
        contexts = jobletItem.getJobletProcess().getContext();
        defualtGroupName = jobletItem.getJobletProcess().getDefaultContext();
    } else if (item instanceof ContextItem) {
        ContextItem contextItem = (ContextItem) item;
        contexts = contextItem.getContext();
        defualtGroupName = contextItem.getDefaultContext();
    }
    try {
        ContextType defaultGroup = null;
        for (ContextType context : contexts) {
            if (context.getName().equals(defualtGroupName)) {
                defaultGroup = context;
                break;
            }
        }
        if (defaultGroup == null && contexts.size() > 0) {
            defaultGroup = contexts.get(0);
        }
        boolean contextChanged = false;
        if (defaultGroup != null) {
            Map<String, ContextParameterType> paramMap = new HashMap<String, ContextParameterType>();
            List<String> paramNameList = new ArrayList<String>();
            paramMap.putAll(collectDefaultGroupParams(defaultGroup, paramNameList));
            for (ContextType context : contexts) {
                if (context == defaultGroup) {
                    continue;
                }
                Map<String, ContextParameterType> otherGroupParam = collectDefaultGroupParams(context, paramNameList);
                for (String paramName : otherGroupParam.keySet()) {
                    if (!paramMap.containsKey(paramName)) {
                        paramMap.put(paramName, otherGroupParam.get(paramName));
                    }
                }
            }
            // make sure all groups have the same param list
            for (ContextType context : contexts) {
                EList<ContextParameterType> params = context.getContextParameter();
                List<String> paramNames = new ArrayList<String>(paramNameList);
                for (ContextParameterType param : params) {
                    if (paramNames.contains(param.getName())) {
                        paramNames.remove(param.getName());
                    }
                }
                if (!paramNames.isEmpty()) {
                    contextChanged = true;
                    for (String paramToAdd : paramNames) {
                        ContextParameterType toAdd = paramMap.get(paramToAdd);
                        context.getContextParameter().add(EcoreUtil.copy(toAdd));
                    }
                }
            }
            // change param order if needed
            for (ContextType context : contexts) {
                EList<ContextParameterType> params = context.getContextParameter();
                List<ContextParameterType> copyOfParam = new ArrayList<ContextParameterType>(params);
                for (int i = 0; i < copyOfParam.size(); i++) {
                    ContextParameterType param = copyOfParam.get(i);
                    int indexOf = paramNameList.indexOf(param.getName());
                    if (i != indexOf) {
                        contextChanged = true;
                        params.remove(param);
                        params.add(indexOf, param);
                    }
                }
            }
            // make sure params in different groups have the same repository id and type as default group
            for (ContextType context : contexts) {
                EList<ContextParameterType> params = context.getContextParameter();
                for (ContextParameterType param : params) {
                    ContextParameterType paramDefault = paramMap.get(param.getName());
                    if (!paramDefault.getType().equals(param.getType())) {
                        contextChanged = true;
                        param.setType(paramDefault.getType());
                    }
                    if (paramDefault.getRepositoryContextId() == null && param.getRepositoryContextId() != null || (paramDefault.getRepositoryContextId() != null && !paramDefault.getRepositoryContextId().equals(param.getRepositoryContextId()))) {
                        contextChanged = true;
                        param.setRepositoryContextId(paramDefault.getRepositoryContextId());
                    }
                }
            }
        }
        if (contextChanged) {
            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 : ContextType(org.talend.designer.core.model.utils.emf.talendfile.ContextType) ContextItem(org.talend.core.model.properties.ContextItem) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) ProcessItem(org.talend.core.model.properties.ProcessItem) JobletProcessItem(org.talend.core.model.properties.JobletProcessItem) JobletProcessItem(org.talend.core.model.properties.JobletProcessItem) PersistenceException(org.talend.commons.exception.PersistenceException) ContextParameterType(org.talend.designer.core.model.utils.emf.talendfile.ContextParameterType)

Example 84 with PersistenceException

use of org.talend.commons.exception.PersistenceException 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 85 with PersistenceException

use of org.talend.commons.exception.PersistenceException in project tdi-studio-se by Talend.

the class CorrectBatchSizeForDBComponents 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 (getProject().getLanguage() != ECodeLanguage.JAVA || processType == null) {
        return ExecutionResult.NOTHING_TO_DO;
    }
    List<String> filterList = Arrays.asList("tAmazonOracleOutput", "tInformixOutput");
    IComponentConversion correctBatchModeForDBComponents = new IComponentConversion() {

        public void transform(NodeType node) {
            ElementParameterType useExistingConnPara = ComponentUtilities.getNodeProperty(node, "USE_EXISTING_CONNECTION");
            if (useExistingConnPara == null) {
                ComponentUtilities.addNodeProperty(node, "USE_EXISTING_CONNECTION", "CHECK");
                ComponentUtilities.getNodeProperty(node, "USE_EXISTING_CONNECTION").setValue("false");
            }
            ElementParameterType useBatchAndUseConnPara = ComponentUtilities.getNodeProperty(node, "USE_BATCH_AND_USE_CONN");
            if (useBatchAndUseConnPara == null) {
                ComponentUtilities.addNodeProperty(node, "USE_BATCH_AND_USE_CONN", "CHECK");
                ComponentUtilities.getNodeProperty(node, "USE_BATCH_AND_USE_CONN").setValue("false");
            }
            boolean useExistConn = ComponentUtilities.getNodeProperty(node, "USE_EXISTING_CONNECTION").getValue().equalsIgnoreCase("true");
            ElementParameterType elementParaType = ComponentUtilities.getNodeProperty(node, "USE_BATCH_SIZE");
            if (elementParaType == null) {
                ComponentUtilities.addNodeProperty(node, "USE_BATCH_SIZE", "CHECK");
                ComponentUtilities.getNodeProperty(node, "USE_BATCH_SIZE").setValue("false");
            }
            if (!useExistConn) {
                if (elementParaType != null && elementParaType.getValue().equalsIgnoreCase("true")) {
                    String batchSizeInStr = ComponentUtilities.getNodeProperty(node, "BATCH_SIZE").getValue();
                    if (batchSizeInStr != null && !"".equals(batchSizeInStr)) {
                        int batchSize = Integer.valueOf(batchSizeInStr);
                        if (batchSize <= 0) {
                            ComponentUtilities.getNodeProperty(node, "BATCH_SIZE").setValue("1");
                        }
                    }
                }
            }
        }
    };
    for (String componentName : filterList) {
        IComponentFilter filter = new NameComponentFilter(componentName);
        try {
            ModifyComponentsAction.searchAndModify(item, processType, filter, Arrays.<IComponentConversion>asList(correctBatchModeForDBComponents));
        } catch (PersistenceException e) {
            ExceptionHandler.process(e);
            return ExecutionResult.FAILURE;
        }
    }
    return ExecutionResult.SUCCESS_NO_ALERT;
}
Also used : ElementParameterType(org.talend.designer.core.model.utils.emf.talendfile.ElementParameterType) ProcessType(org.talend.designer.core.model.utils.emf.talendfile.ProcessType) NodeType(org.talend.designer.core.model.utils.emf.talendfile.NodeType) IComponentFilter(org.talend.core.model.components.filters.IComponentFilter) PersistenceException(org.talend.commons.exception.PersistenceException) NameComponentFilter(org.talend.core.model.components.filters.NameComponentFilter) IComponentConversion(org.talend.core.model.components.conversions.IComponentConversion)

Aggregations

PersistenceException (org.talend.commons.exception.PersistenceException)367 IProxyRepositoryFactory (org.talend.repository.model.IProxyRepositoryFactory)113 IRepositoryViewObject (org.talend.core.model.repository.IRepositoryViewObject)112 ProcessType (org.talend.designer.core.model.utils.emf.talendfile.ProcessType)104 NodeType (org.talend.designer.core.model.utils.emf.talendfile.NodeType)89 ElementParameterType (org.talend.designer.core.model.utils.emf.talendfile.ElementParameterType)84 IComponentConversion (org.talend.core.model.components.conversions.IComponentConversion)77 IComponentFilter (org.talend.core.model.components.filters.IComponentFilter)76 NameComponentFilter (org.talend.core.model.components.filters.NameComponentFilter)75 Item (org.talend.core.model.properties.Item)59 ArrayList (java.util.ArrayList)58 ProcessItem (org.talend.core.model.properties.ProcessItem)54 Property (org.talend.core.model.properties.Property)51 ConnectionItem (org.talend.core.model.properties.ConnectionItem)47 Project (org.talend.core.model.general.Project)40 CoreException (org.eclipse.core.runtime.CoreException)37 List (java.util.List)36 IElementParameter (org.talend.core.model.process.IElementParameter)35 IProject (org.eclipse.core.resources.IProject)32 ProxyRepositoryFactory (org.talend.core.repository.model.ProxyRepositoryFactory)32