@Test public void shouldSyncFacilityDistributionData() { Facility facility = new Facility(3L); Distribution distribution = new Distribution(); distribution.setId(1L); FacilityDistributionDTO facilityDistributionDTO = spy(new FacilityDistributionDTO()); facilityDistributionDTO.setFacilityVisit(new FacilityVisit()); FacilityDistribution facilityDistributionData = new FacilityDistribution(null, null, new DistributionRefrigerators(EMPTY_LIST), null, null, null, null); FacilityDistribution syncedFacilityDistribution = new FacilityDistribution(); FacilityVisit syncedFacilityVisit = new FacilityVisit(); syncedFacilityVisit.setSynced(true); syncedFacilityDistribution.setFacilityVisit(syncedFacilityVisit); when(service.sync(facilityDistributionData)).thenReturn(syncedFacilityDistribution); when(service.updateDistributionStatus(distribution.getId(), USER_ID)).thenReturn(SYNCED); doReturn(facilityDistributionData).when(facilityDistributionDTO).transform(); doNothing().when(facilityDistributionDTO).setModifiedBy(USER_ID); doNothing().when(facilityDistributionDTO).setDistributionId(distribution.getId()); ResponseEntity<OpenLmisResponse> response = controller.sync(facilityDistributionDTO, distribution.getId(), facility.getId(), httpServletRequest); assertThat(response.getStatusCode(), is(HttpStatus.OK)); assertTrue((boolean) response.getBody().getData().get("syncStatus")); assertThat((DistributionStatus) response.getBody().getData().get("distributionStatus"), is(SYNCED)); verify(service).sync(facilityDistributionData); verify(service).updateDistributionStatus(distribution.getId(), USER_ID); verify(facilityDistributionDTO).setModifiedBy(USER_ID); verify(facilityDistributionDTO).setDistributionId(distribution.getId()); }
@RequestMapping(value = "/distributions/{id}/facilities/{facilityId}", method = PUT, headers = ACCEPT_JSON) @PreAuthorize("@distributionPermissionService.hasPermission(principal, 'MANAGE_DISTRIBUTION', #id)") public ResponseEntity<OpenLmisResponse> sync(@RequestBody FacilityDistributionDTO facilityDistributionDTO, @PathVariable Long id, @PathVariable Long facilityId, HttpServletRequest httpServletRequest) { ResponseEntity<OpenLmisResponse> response; try { facilityDistributionDTO.getFacilityVisit().setFacilityId(facilityId); facilityDistributionDTO.setDistributionId(id); facilityDistributionDTO.setModifiedBy(loggedInUserId(httpServletRequest)); distributionService.sync(facilityDistributionDTO.transform()); response = response("syncStatus", true); } catch (DataException e) { response = response("syncStatus", false); } response.getBody().addData("distributionStatus", distributionService.updateDistributionStatus(id, loggedInUserId(httpServletRequest))); return response; }
DistributionController extends BaseController { @RequestMapping(value = "/distributions/{id}/facilities/{facilityId}", method = PUT, headers = ACCEPT_JSON) @PreAuthorize("@distributionPermissionService.hasPermission(principal, 'MANAGE_DISTRIBUTION', #id)") public ResponseEntity<OpenLmisResponse> sync(@RequestBody FacilityDistributionDTO facilityDistributionDTO, @PathVariable Long id, @PathVariable Long facilityId, HttpServletRequest httpServletRequest) { ResponseEntity<OpenLmisResponse> response; try { facilityDistributionDTO.getFacilityVisit().setFacilityId(facilityId); facilityDistributionDTO.setDistributionId(id); facilityDistributionDTO.setModifiedBy(loggedInUserId(httpServletRequest)); distributionService.sync(facilityDistributionDTO.transform()); response = response("syncStatus", true); } catch (DataException e) { response = response("syncStatus", false); } response.getBody().addData("distributionStatus", distributionService.updateDistributionStatus(id, loggedInUserId(httpServletRequest))); return response; } }
DistributionController extends BaseController { @RequestMapping(value = "/distributions/{id}/facilities/{facilityId}", method = PUT, headers = ACCEPT_JSON) @PreAuthorize("@distributionPermissionService.hasPermission(principal, 'MANAGE_DISTRIBUTION', #id)") public ResponseEntity<OpenLmisResponse> sync(@RequestBody FacilityDistributionDTO facilityDistributionDTO, @PathVariable Long id, @PathVariable Long facilityId, HttpServletRequest httpServletRequest) { ResponseEntity<OpenLmisResponse> response; try { facilityDistributionDTO.getFacilityVisit().setFacilityId(facilityId); facilityDistributionDTO.setDistributionId(id); facilityDistributionDTO.setModifiedBy(loggedInUserId(httpServletRequest)); distributionService.sync(facilityDistributionDTO.transform()); response = response("syncStatus", true); } catch (DataException e) { response = response("syncStatus", false); } response.getBody().addData("distributionStatus", distributionService.updateDistributionStatus(id, loggedInUserId(httpServletRequest))); return response; }  }
DistributionController extends BaseController { @RequestMapping(value = "/distributions/{id}/facilities/{facilityId}", method = PUT, headers = ACCEPT_JSON) @PreAuthorize("@distributionPermissionService.hasPermission(principal, 'MANAGE_DISTRIBUTION', #id)") public ResponseEntity<OpenLmisResponse> sync(@RequestBody FacilityDistributionDTO facilityDistributionDTO, @PathVariable Long id, @PathVariable Long facilityId, HttpServletRequest httpServletRequest) { ResponseEntity<OpenLmisResponse> response; try { facilityDistributionDTO.getFacilityVisit().setFacilityId(facilityId); facilityDistributionDTO.setDistributionId(id); facilityDistributionDTO.setModifiedBy(loggedInUserId(httpServletRequest)); distributionService.sync(facilityDistributionDTO.transform()); response = response("syncStatus", true); } catch (DataException e) { response = response("syncStatus", false); } response.getBody().addData("distributionStatus", distributionService.updateDistributionStatus(id, loggedInUserId(httpServletRequest))); return response; }  @RequestMapping(value = "/distributions", method = POST, headers = ACCEPT_JSON) @PreAuthorize("@distributionPermissionService.hasPermission(principal, 'MANAGE_DISTRIBUTION', #distribution)") ResponseEntity<OpenLmisResponse> create(@RequestBody Distribution distribution, HttpServletRequest request); @RequestMapping(value = "/distributions/{id}/facilities/{facilityId}", method = PUT, headers = ACCEPT_JSON) @PreAuthorize("@distributionPermissionService.hasPermission(principal, 'MANAGE_DISTRIBUTION', #id)") ResponseEntity<OpenLmisResponse> sync(@RequestBody FacilityDistributionDTO facilityDistributionDTO, @PathVariable Long id,
                                               @PathVariable Long facilityId, HttpServletRequest httpServletRequest); }
DistributionController extends BaseController { @RequestMapping(value = "/distributions/{id}/facilities/{facilityId}", method = PUT, headers = ACCEPT_JSON) @PreAuthorize("@distributionPermissionService.hasPermission(principal, 'MANAGE_DISTRIBUTION', #id)") public ResponseEntity<OpenLmisResponse> sync(@RequestBody FacilityDistributionDTO facilityDistributionDTO, @PathVariable Long id, @PathVariable Long facilityId, HttpServletRequest httpServletRequest) { ResponseEntity<OpenLmisResponse> response; try { facilityDistributionDTO.getFacilityVisit().setFacilityId(facilityId); facilityDistributionDTO.setDistributionId(id); facilityDistributionDTO.setModifiedBy(loggedInUserId(httpServletRequest)); distributionService.sync(facilityDistributionDTO.transform()); response = response("syncStatus", true); } catch (DataException e) { response = response("syncStatus", false); } response.getBody().addData("distributionStatus", distributionService.updateDistributionStatus(id, loggedInUserId(httpServletRequest))); return response; }  @RequestMapping(value = "/distributions", method = POST, headers = ACCEPT_JSON) @PreAuthorize("@distributionPermissionService.hasPermission(principal, 'MANAGE_DISTRIBUTION', #distribution)") ResponseEntity<OpenLmisResponse> create(@RequestBody Distribution distribution, HttpServletRequest request); @RequestMapping(value = "/distributions/{id}/facilities/{facilityId}", method = PUT, headers = ACCEPT_JSON) @PreAuthorize("@distributionPermissionService.hasPermission(principal, 'MANAGE_DISTRIBUTION', #id)") ResponseEntity<OpenLmisResponse> sync(@RequestBody FacilityDistributionDTO facilityDistributionDTO, @PathVariable Long id,
                                               @PathVariable Long facilityId, HttpServletRequest httpServletRequest); static final SimpleDateFormat DATE_FORMAT; }