Source:
public ModelAndView loadPage(@RequestParam Long applicationId, @RequestParam(required = false, name = "state") String clickedState) { ModelAndView modelAndView = new ModelAndView(VIEW_NAME); modelAndView.addObject("applicationId", applicationId); List<StateHistoryViewRepresentation> stateHistoryViewRepresentations = converterService .convert(statesHistoryService.getStateHistoriesByApplicationId(applicationId), StateHistoryViewRepresentation.class); if (clickedState != null) { StateDTO clickedStateDTO = stateService.getStateDtoByName(clickedState); Assert.notNull(clickedStateDTO); stateHistoryViewRepresentations.add(0, StateHistoryViewRepresentation.builder() .creationDate(new Date()) .stateId(clickedStateDTO.getId()) .stateName(clickedStateDTO.getName()) .build()); } ApplicationDTO applicationDTO = applicationsService.getApplication(applicationId); CandidateDTO candidateDTO = candidateService.getCandidate(applicationDTO.getCandidateId()); for (StateHistoryViewRepresentation stateHistoryViewRepresentation : stateHistoryViewRepresentations) { stateHistoryViewRepresentation.setLanguageSkill(candidateDTO.getLanguageSkill()); String stateType = stateHistoryViewRepresentation.getStateName(); stateType = messageKeyResolver .resolveMessageOrDefault( APPLICATION_STATE + stateHistoryViewRepresentation.getStateName(), stateType); stateHistoryViewRepresentation.setStateFullName(stateType); } modelAndView.addObject(STATE_FLOW_OBJECT_KEY, stateFlowService.getStateFlowDTOByFromStateDTO( new StateDTO(stateHistoryViewRepresentations.get(0).getStateId(), stateHistoryViewRepresentations.get(0).getStateName()))); modelAndView.addObject(STATES_OBJECT_KEY, stateHistoryViewRepresentations); return modelAndView; }

Target:
public ModelAndView loadPage(@RequestParam Long applicationId, @RequestParam(required = false, name = "state") String clickedState) { ModelAndView modelAndView = new ModelAndView(VIEW_NAME); modelAndView.addObject("applicationId", applicationId); List<StateHistoryViewRepresentation> stateHistoryViewRepresentations = converterService .convert(statesHistoryService.getStateHistoriesByApplicationId(applicationId), StateHistoryViewRepresentation.class); if (clickedState != null) { StateDTO clickedStateDTO = stateService.getStateDtoByName(clickedState); Assert.notNull(clickedStateDTO); stateHistoryViewRepresentations.add(0, StateHistoryViewRepresentation.builder() .creationDate(new Date()) .stateId(clickedStateDTO.getId()) .stateName(clickedStateDTO.getName()) .build()); } CandidateDTO candidateDTO = candidateService.getCandidateByApplicationID(applicationId); for (StateHistoryViewRepresentation stateHistoryViewRepresentation : stateHistoryViewRepresentations) { stateHistoryViewRepresentation.setLanguageSkill(candidateDTO.getLanguageSkill()); String stateType = stateHistoryViewRepresentation.getStateName(); stateType = messageKeyResolver .resolveMessageOrDefault( APPLICATION_STATE + stateHistoryViewRepresentation.getStateName(), stateType); stateHistoryViewRepresentation.setStateFullName(stateType); } modelAndView.addObject(STATE_FLOW_OBJECT_KEY, stateFlowService.getStateFlowDTOByFromStateDTO( new StateDTO(stateHistoryViewRepresentations.get(0).getStateId(), stateHistoryViewRepresentations.get(0).getStateName()))); modelAndView.addObject(STATES_OBJECT_KEY, stateHistoryViewRepresentations); return modelAndView; }