Search in sources :

Example 1 with ItemInforType

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

the class ChangeModelForRoutineParameterMigrationTask method execute.

@SuppressWarnings("unchecked")
@Override
public ExecutionResult execute(Item item) {
    if (!(item instanceof ProcessItem)) {
        return ExecutionResult.NOTHING_TO_DO;
    }
    try {
        ProcessItem item2 = (ProcessItem) item;
        List<ItemInforType> oldRoutinesDependencies = (List<ItemInforType>) item2.getProcess().getRoutinesDependencies();
        if (item2.getProcess().getParameters() == null || item2.getProcess().getParameters().getRoutinesParameter() == null) {
            ParametersType parameterType = TalendFileFactory.eINSTANCE.createParametersType();
            item2.getProcess().setParameters(parameterType);
        }
        List<RoutinesParameterType> routinesDependencies = (List<RoutinesParameterType>) item2.getProcess().getParameters().getRoutinesParameter();
        List<IRepositoryViewObject> viewObjects = RoutinesUtil.getCurrentSystemRoutines();
        boolean modified = false;
        for (ItemInforType added : oldRoutinesDependencies) {
            if (added.isSystem()) {
                for (int i = 0; i < viewObjects.size(); i++) {
                    IRepositoryViewObject viewObject = viewObjects.get(i);
                    if (viewObject.getLabel().equals(added.getIdOrName())) {
                        RoutinesParameterType routinesParameterType = TalendFileFactory.eINSTANCE.createRoutinesParameterType();
                        routinesParameterType.setId(viewObject.getId());
                        routinesParameterType.setName(added.getIdOrName());
                        routinesDependencies.add(routinesParameterType);
                        modified = true;
                    }
                }
            } else {
                IRepositoryViewObject userRoutines = RoutinesUtil.getUserRoutines(added.getIdOrName());
                if (userRoutines != null) {
                    RoutinesParameterType routinesParameterType = TalendFileFactory.eINSTANCE.createRoutinesParameterType();
                    routinesParameterType.setId(added.getIdOrName());
                    routinesParameterType.setName(userRoutines.getLabel());
                    routinesDependencies.add(routinesParameterType);
                    modified = true;
                }
            }
        }
        if (modified) {
            oldRoutinesDependencies.clear();
            CorePlugin.getDefault().getRepositoryService().getProxyRepositoryFactory().save(item, true);
            RelationshipItemBuilder.getInstance().addOrUpdateItem(item, true);
            return ExecutionResult.SUCCESS_WITH_ALERT;
        }
    } catch (Exception e) {
        ExceptionHandler.process(e);
        return ExecutionResult.FAILURE;
    }
    return ExecutionResult.NOTHING_TO_DO;
}
Also used : ProcessItem(org.talend.core.model.properties.ProcessItem) RoutinesParameterType(org.talend.designer.core.model.utils.emf.talendfile.RoutinesParameterType) IRepositoryViewObject(org.talend.core.model.repository.IRepositoryViewObject) ArrayList(java.util.ArrayList) List(java.util.List) ParametersType(org.talend.designer.core.model.utils.emf.talendfile.ParametersType) ItemInforType(org.talend.designer.core.model.utils.emf.talendfile.ItemInforType)

Aggregations

ArrayList (java.util.ArrayList)1 List (java.util.List)1 ProcessItem (org.talend.core.model.properties.ProcessItem)1 IRepositoryViewObject (org.talend.core.model.repository.IRepositoryViewObject)1 ItemInforType (org.talend.designer.core.model.utils.emf.talendfile.ItemInforType)1 ParametersType (org.talend.designer.core.model.utils.emf.talendfile.ParametersType)1 RoutinesParameterType (org.talend.designer.core.model.utils.emf.talendfile.RoutinesParameterType)1