Source:
<code>private Map<String, Serializable> createBindingsForSelectionScripts(InternalJob job, EligibleTaskDescriptor etd, InternalTask task) throws IOException, ClassNotFoundException { Map<String, Serializable> bindings = new HashMap<>(); Map<String, Serializable> variables = new HashMap<>(); int resultSize = etd.getParents().size(); if (job.getType() == JobType.TASKSFLOW) { if ((resultSize > 0) && task.handleResultsArguments()) { List<TaskId> parentIds = new ArrayList<>(resultSize); for (int i = 0; i < resultSize; i++) { parentIds.add(etd.getParents().get(i).getTaskId()); } Map<TaskId, TaskResult> taskResults = schedulingService.getInfrastructure().getDBManager() .loadTasksResults( job.getId(), parentIds); for (TaskResult taskResult : taskResults.values()) { <START> if (taskResult.getPropagatedVariables() != null) { <END> variables.putAll(SerializationUtil.deserializeVariableMap(taskResult.getPropagatedVariables())); } } } else { variables.putAll(job.getVariables()); } } variables.put(SchedulerVars.PA_JOB_ID.toString(), job.getId().value()); variables.put(SchedulerVars.PA_JOB_NAME.toString(), job.getName()); variables.put(SchedulerVars.PA_TASK_ID.toString(), task.getId().value()); variables.put(SchedulerVars.PA_TASK_NAME.toString(), task.getName()); variables.put(SchedulerVars.PA_USER.toString(), job.getOwner()); if (job.getType() == JobType.TASKSFLOW) { variables.put(SchedulerVars.PA_TASK_ITERATION.toString(), task.getIterationIndex()); variables.put(SchedulerVars.PA_TASK_REPLICATION.toString(), task.getReplicationIndex()); } bindings.put(SchedulerConstants.VARIABLES_BINDING_NAME, (Serializable) variables); bindings.put(SchedulerConstants.GENERIC_INFO_BINDING_NAME, (Serializable) task.getGenericInformation()); return bindings; }</code><technical_language>![MAJOR](<LINK_1> Refactor this code nest more 3 if/for/while/switch/try statements. [![rule](<LINK_2>](<LINK_0></technical_language>

Target:
private Map<String, Serializable> createBindingsForSelectionScripts(InternalJob job, EligibleTaskDescriptor etd, InternalTask task) throws IOException, ClassNotFoundException { Map<String, Serializable> bindings = new HashMap<>(); Map<String, Serializable> variables = new HashMap<>(); Map<String, Serializable> genericInfo = new HashMap<>(); int resultSize = etd.getParents().size(); if (job.getType() == JobType.TASKSFLOW) { if ((resultSize > 0) && task.handleResultsArguments()) { List<TaskId> parentIds = new ArrayList<>(resultSize); for (int i = 0; i < resultSize; i++) { parentIds.add(etd.getParents().get(i).getTaskId()); } Map<TaskId, TaskResult> taskResults = schedulingService.getInfrastructure().getDBManager() .loadTasksResults( job.getId(), parentIds); for (TaskResult taskResult : taskResults.values()) { if (taskResult.getPropagatedVariables() != null) { variables.putAll(SerializationUtil.deserializeVariableMap(taskResult.getPropagatedVariables())); } } } else { variables.putAll(job.getVariables()); } } variables.put(SchedulerVars.PA_JOB_ID.toString(), job.getId().value()); variables.put(SchedulerVars.PA_JOB_NAME.toString(), job.getName()); variables.put(SchedulerVars.PA_TASK_ID.toString(), task.getId().value()); variables.put(SchedulerVars.PA_TASK_NAME.toString(), task.getName()); variables.put(SchedulerVars.PA_USER.toString(), job.getOwner()); genericInfo.putAll(job.getGenericInformation()); if (job.getType() == JobType.TASKSFLOW) { variables.put(SchedulerVars.PA_TASK_ITERATION.toString(), task.getIterationIndex()); variables.put(SchedulerVars.PA_TASK_REPLICATION.toString(), task.getReplicationIndex()); genericInfo.putAll(task.getGenericInformation()); } bindings.put(SchedulerConstants.VARIABLES_BINDING_NAME, (Serializable) variables); bindings.put(SchedulerConstants.GENERIC_INFO_BINDING_NAME, (Serializable) genericInfo); return bindings; }