Source:
<code>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()); } <START> ApplicationDTO applicationDTO = applicationsService.getApplication(applicationId); <END> 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; }</code><technical_language>I prefer create a new CandidateService method return a candidate for a application id. save additional trip database back, applicationService.getApplication(applicationId) means now</technical_language>

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