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) { ApplicationDTO applicationDTO = applicationsService.getApplicationDtoById(applicationId); StateDTO clickedStateDTO = stateService.getStateDtoByName(clickedState); Assert.notNull(clickedStateDTO); StateHistoryViewRepresentation representation = StateHistoryViewRepresentation.builder() .creationDate(new Date()) .stateId(clickedStateDTO.getId()) .stateName(clickedStateDTO.getName()) .build(); if (clickedStateDTO.getId() == 1) { representation.setChannelName(channelService.getChannelDtoById(applicationDTO.getChannelId()).getName()); representation.setPositionName(positionService.getPositionDtoById(applicationDTO.getPositionId()).getName()); } stateHistoryViewRepresentations.add(0, representation); } 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; }

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); StateHistoryViewRepresentation representation = StateHistoryViewRepresentation.builder() .creationDate(new Date()) .stateId(clickedStateDTO.getId()) .stateName(clickedStateDTO.getName()) .build(); if (clickedState.equals(NEW_STATE)) { ApplicationDTO applicationDTO = applicationsService.getApplicationDtoById(applicationId); representation.setChannelName(channelService.getChannelDtoById(applicationDTO.getChannelId()).getName()); representation.setPositionName(positionService.getPositionDtoById(applicationDTO.getPositionId()).getName()); } stateHistoryViewRepresentations.add(0, representation); } 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; }