Source:
public ResponseEntity<StudyDetails> getStudyDetails(@PathVariable final String crop, @PathVariable final Integer studyDbId) { final Integer studyId = this.studyDataManager.getProjectIdByStudyDbId(studyDbId); this.studyValidator.checkIfStudyIsUnlocked(studyId); final StudyDetailsDto mwStudyDetails = this.studyService.getStudyDetailsByGeolocation(studyDbId); if (mwStudyDetails != null) { Map<String, String> additionalInfo = mwStudyDetails.getEnvironmentParameters().stream().collect( Collectors.toMap(MeasurementVariable::getDescription, MeasurementVariable::getValue)); mwStudyDetails.getAdditionalInfo().putAll(additionalInfo); final StudyDetails studyDetails = new StudyDetails(); final Metadata metadata = new Metadata(); final Pagination pagination = new Pagination().withPageNumber(1).withPageSize(1).withTotalCount(1L).withTotalPages(1); metadata.setPagination(pagination); studyDetails.setMetadata(metadata); final ModelMapper studyMapper = StudyMapper.getInstance(); final StudyDetailsData result = studyMapper.map(mwStudyDetails, StudyDetailsData.class); if (mwStudyDetails.getMetadata().getLocationId() != null) { final Map<LocationFilters, Object> filters = new EnumMap<>(LocationFilters.class); filters.put(LocationFilters.LOCATION_ID, String.valueOf(mwStudyDetails.getMetadata().getLocationId())); final List<LocationDetailsDto> locations = this.locationDataManager.getLocationsByFilter(0, 1, filters); if (!locations.isEmpty()) { final ModelMapper locationMapper = LocationMapper.getInstance(); final Location location = locationMapper.map(locations.get(0), Location.class); result.setLocation(location); } } studyDetails.setResult(result); return ResponseEntity.ok(studyDetails); } else { return new ResponseEntity(HttpStatus.NOT_FOUND); } }

Target:
public ResponseEntity<StudyDetails> getStudyDetails(@PathVariable final String crop, @PathVariable final Integer studyDbId) { final StudyDetailsDto mwStudyDetails = this.studyService.getStudyDetailsByGeolocation(studyDbId); if (mwStudyDetails != null) { Map<String, String> additionalInfo = mwStudyDetails.getEnvironmentParameters().stream().collect( Collectors.toMap(MeasurementVariable::getDescription, MeasurementVariable::getValue)); mwStudyDetails.getAdditionalInfo().putAll(additionalInfo); final StudyDetails studyDetails = new StudyDetails(); final Metadata metadata = new Metadata(); final Pagination pagination = new Pagination().withPageNumber(1).withPageSize(1).withTotalCount(1L).withTotalPages(1); metadata.setPagination(pagination); studyDetails.setMetadata(metadata); final ModelMapper studyMapper = StudyMapper.getInstance(); final StudyDetailsData result = studyMapper.map(mwStudyDetails, StudyDetailsData.class); if (mwStudyDetails.getMetadata().getLocationId() != null) { final Map<LocationFilters, Object> filters = new EnumMap<>(LocationFilters.class); filters.put(LocationFilters.LOCATION_ID, String.valueOf(mwStudyDetails.getMetadata().getLocationId())); final List<LocationDetailsDto> locations = this.locationDataManager.getLocationsByFilter(0, 1, filters); if (!locations.isEmpty()) { final ModelMapper locationMapper = LocationMapper.getInstance(); final Location location = locationMapper.map(locations.get(0), Location.class); result.setLocation(location); } } studyDetails.setResult(result); return ResponseEntity.ok(studyDetails); } else { return new ResponseEntity(HttpStatus.NOT_FOUND); } }