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;
}
Aggregations