@Test public void shouldSetSyncStatusToFalseIfAlreadySynced() throws Exception { Facility facility = new Facility(3L); Distribution distribution = new Distribution(); distribution.setId(1L); FacilityDistributionDTO facilityDistributionDTO = spy(new FacilityDistributionDTO()); facilityDistributionDTO.setFacilityVisit(new FacilityVisit()); FacilityDistribution facilityDistribution = new FacilityDistribution(); doNothing().when(facilityDistributionDTO).setModifiedBy(USER_ID); doReturn(facilityDistribution).when(facilityDistributionDTO).transform(); doThrow(new DataException("error.facility.already.synced")).when(service).sync(facilityDistribution); ResponseEntity<OpenLmisResponse> response = controller.sync(facilityDistributionDTO, distribution.getId(), facility.getId(), httpServletRequest); assertFalse((Boolean) response.getBody().getData().get("syncStatus")); }
@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; }