@Test public void shouldThrowExceptionIfInvalidGeoZoneBeingUpdated() throws Exception { GeographicZone geographicZone = new GeographicZone(); doThrow(new DataException("error")).when(service).save(geographicZone); ResponseEntity<OpenLmisResponse> errorResponse = controller.update(geographicZone, 9L, request); assertThat(errorResponse.getBody().getErrorMsg(), is("error")); assertThat(errorResponse.getStatusCode(), is(BAD_REQUEST)); }
@RequestMapping(value = "/geographicZones/{id}", method = PUT, headers = ACCEPT_JSON) @PreAuthorize("@permissionEvaluator.hasPermission(principal,'MANAGE_GEOGRAPHIC_ZONE')") public ResponseEntity<OpenLmisResponse> update(@RequestBody GeographicZone geographicZone, @PathVariable("id") Long id, HttpServletRequest request) { Long userId = loggedInUserId(request); geographicZone.setId(id); geographicZone.setModifiedBy(userId); try { service.save(geographicZone); } catch (DataException e) { return OpenLmisResponse.error(e, BAD_REQUEST); } ResponseEntity<OpenLmisResponse> success = success( messageService.message("message.geo.zone.updated.success", geographicZone.getName())); success.getBody().addData("geoZone", geographicZone); return success; }
GeographicZoneController extends BaseController { @RequestMapping(value = "/geographicZones/{id}", method = PUT, headers = ACCEPT_JSON) @PreAuthorize("@permissionEvaluator.hasPermission(principal,'MANAGE_GEOGRAPHIC_ZONE')") public ResponseEntity<OpenLmisResponse> update(@RequestBody GeographicZone geographicZone, @PathVariable("id") Long id, HttpServletRequest request) { Long userId = loggedInUserId(request); geographicZone.setId(id); geographicZone.setModifiedBy(userId); try { service.save(geographicZone); } catch (DataException e) { return OpenLmisResponse.error(e, BAD_REQUEST); } ResponseEntity<OpenLmisResponse> success = success( messageService.message("message.geo.zone.updated.success", geographicZone.getName())); success.getBody().addData("geoZone", geographicZone); return success; } }
GeographicZoneController extends BaseController { @RequestMapping(value = "/geographicZones/{id}", method = PUT, headers = ACCEPT_JSON) @PreAuthorize("@permissionEvaluator.hasPermission(principal,'MANAGE_GEOGRAPHIC_ZONE')") public ResponseEntity<OpenLmisResponse> update(@RequestBody GeographicZone geographicZone, @PathVariable("id") Long id, HttpServletRequest request) { Long userId = loggedInUserId(request); geographicZone.setId(id); geographicZone.setModifiedBy(userId); try { service.save(geographicZone); } catch (DataException e) { return OpenLmisResponse.error(e, BAD_REQUEST); } ResponseEntity<OpenLmisResponse> success = success( messageService.message("message.geo.zone.updated.success", geographicZone.getName())); success.getBody().addData("geoZone", geographicZone); return success; }  }
GeographicZoneController extends BaseController { @RequestMapping(value = "/geographicZones/{id}", method = PUT, headers = ACCEPT_JSON) @PreAuthorize("@permissionEvaluator.hasPermission(principal,'MANAGE_GEOGRAPHIC_ZONE')") public ResponseEntity<OpenLmisResponse> update(@RequestBody GeographicZone geographicZone, @PathVariable("id") Long id, HttpServletRequest request) { Long userId = loggedInUserId(request); geographicZone.setId(id); geographicZone.setModifiedBy(userId); try { service.save(geographicZone); } catch (DataException e) { return OpenLmisResponse.error(e, BAD_REQUEST); } ResponseEntity<OpenLmisResponse> success = success( messageService.message("message.geo.zone.updated.success", geographicZone.getName())); success.getBody().addData("geoZone", geographicZone); return success; }  @RequestMapping(value = "/geographicZones/{id}", method = GET, headers = ACCEPT_JSON) @PreAuthorize("@permissionEvaluator.hasPermission(principal,'MANAGE_DISTRIBUTION, MANAGE_GEOGRAPHIC_ZONE')") ResponseEntity<OpenLmisResponse> get(@PathVariable Long id); @RequestMapping(value = "/geographicZones", method = POST, headers = ACCEPT_JSON) @PreAuthorize("@permissionEvaluator.hasPermission(principal,'MANAGE_GEOGRAPHIC_ZONE')") ResponseEntity<OpenLmisResponse> insert(@RequestBody GeographicZone geographicZone,
                                                 HttpServletRequest request); @RequestMapping(value = "/geographicZones/{id}", method = PUT, headers = ACCEPT_JSON) @PreAuthorize("@permissionEvaluator.hasPermission(principal,'MANAGE_GEOGRAPHIC_ZONE')") ResponseEntity<OpenLmisResponse> update(@RequestBody GeographicZone geographicZone,
                                                 @PathVariable("id") Long id,
                                                 HttpServletRequest request); @RequestMapping(value = "/geographicZones", method = GET, headers = ACCEPT_JSON) @PreAuthorize("@permissionEvaluator.hasPermission(principal,'MANAGE_GEOGRAPHIC_ZONE')") ResponseEntity<OpenLmisResponse> search(@RequestParam(value = "searchParam") String searchParam,
                                                 @RequestParam(value = "columnName") String columnName,
                                                 @RequestParam(value = "page", defaultValue = "1") Integer page); @RequestMapping(value = "/geographicLevels", method = GET, headers = ACCEPT_JSON) @PreAuthorize("@permissionEvaluator.hasPermission(principal,'MANAGE_GEOGRAPHIC_ZONE')") List<GeographicLevel> getAllGeographicLevels(); @RequestMapping(value = "/parentGeographicZones/{geoLevelCode}", method = GET, headers = ACCEPT_JSON) @PreAuthorize("@permissionEvaluator.hasPermission(principal,'MANAGE_GEOGRAPHIC_ZONE')") List<GeographicZone> getAllGeographicZonesAbove(@PathVariable("geoLevelCode") String geographicLevelCode); @RequestMapping(value = "/filtered-geographicZones", method = GET, headers = ACCEPT_JSON) @PreAuthorize("@permissionEvaluator.hasPermission(principal,'MANAGE_GEOGRAPHIC_ZONE, MANAGE_SUPERVISORY_NODE, MANAGE_REQUISITION_GROUP, MANAGE_SUPPLY_LINE, MANAGE_USER')") ResponseEntity<OpenLmisResponse> getGeographicZoneByCodeOrName(@RequestParam(value = "searchParam") String searchParam,
                                                                        @Value("${search.results.limit}") String searchLimit); @RequestMapping(value = "/geographic-zone/save-gis", method = POST, headers = ACCEPT_JSON) @PreAuthorize("@permissionEvaluator.hasPermission(principal,'MANAGE_GEOGRAPHIC_ZONE')") ResponseEntity<OpenLmisResponse> saveGeographicZoneGIS(@RequestBody GeoZoneInfo geoZoneGeometries, HttpServletRequest request); }
GeographicZoneController extends BaseController { @RequestMapping(value = "/geographicZones/{id}", method = PUT, headers = ACCEPT_JSON) @PreAuthorize("@permissionEvaluator.hasPermission(principal,'MANAGE_GEOGRAPHIC_ZONE')") public ResponseEntity<OpenLmisResponse> update(@RequestBody GeographicZone geographicZone, @PathVariable("id") Long id, HttpServletRequest request) { Long userId = loggedInUserId(request); geographicZone.setId(id); geographicZone.setModifiedBy(userId); try { service.save(geographicZone); } catch (DataException e) { return OpenLmisResponse.error(e, BAD_REQUEST); } ResponseEntity<OpenLmisResponse> success = success( messageService.message("message.geo.zone.updated.success", geographicZone.getName())); success.getBody().addData("geoZone", geographicZone); return success; }  @RequestMapping(value = "/geographicZones/{id}", method = GET, headers = ACCEPT_JSON) @PreAuthorize("@permissionEvaluator.hasPermission(principal,'MANAGE_DISTRIBUTION, MANAGE_GEOGRAPHIC_ZONE')") ResponseEntity<OpenLmisResponse> get(@PathVariable Long id); @RequestMapping(value = "/geographicZones", method = POST, headers = ACCEPT_JSON) @PreAuthorize("@permissionEvaluator.hasPermission(principal,'MANAGE_GEOGRAPHIC_ZONE')") ResponseEntity<OpenLmisResponse> insert(@RequestBody GeographicZone geographicZone,
                                                 HttpServletRequest request); @RequestMapping(value = "/geographicZones/{id}", method = PUT, headers = ACCEPT_JSON) @PreAuthorize("@permissionEvaluator.hasPermission(principal,'MANAGE_GEOGRAPHIC_ZONE')") ResponseEntity<OpenLmisResponse> update(@RequestBody GeographicZone geographicZone,
                                                 @PathVariable("id") Long id,
                                                 HttpServletRequest request); @RequestMapping(value = "/geographicZones", method = GET, headers = ACCEPT_JSON) @PreAuthorize("@permissionEvaluator.hasPermission(principal,'MANAGE_GEOGRAPHIC_ZONE')") ResponseEntity<OpenLmisResponse> search(@RequestParam(value = "searchParam") String searchParam,
                                                 @RequestParam(value = "columnName") String columnName,
                                                 @RequestParam(value = "page", defaultValue = "1") Integer page); @RequestMapping(value = "/geographicLevels", method = GET, headers = ACCEPT_JSON) @PreAuthorize("@permissionEvaluator.hasPermission(principal,'MANAGE_GEOGRAPHIC_ZONE')") List<GeographicLevel> getAllGeographicLevels(); @RequestMapping(value = "/parentGeographicZones/{geoLevelCode}", method = GET, headers = ACCEPT_JSON) @PreAuthorize("@permissionEvaluator.hasPermission(principal,'MANAGE_GEOGRAPHIC_ZONE')") List<GeographicZone> getAllGeographicZonesAbove(@PathVariable("geoLevelCode") String geographicLevelCode); @RequestMapping(value = "/filtered-geographicZones", method = GET, headers = ACCEPT_JSON) @PreAuthorize("@permissionEvaluator.hasPermission(principal,'MANAGE_GEOGRAPHIC_ZONE, MANAGE_SUPERVISORY_NODE, MANAGE_REQUISITION_GROUP, MANAGE_SUPPLY_LINE, MANAGE_USER')") ResponseEntity<OpenLmisResponse> getGeographicZoneByCodeOrName(@RequestParam(value = "searchParam") String searchParam,
                                                                        @Value("${search.results.limit}") String searchLimit); @RequestMapping(value = "/geographic-zone/save-gis", method = POST, headers = ACCEPT_JSON) @PreAuthorize("@permissionEvaluator.hasPermission(principal,'MANAGE_GEOGRAPHIC_ZONE')") ResponseEntity<OpenLmisResponse> saveGeographicZoneGIS(@RequestBody GeoZoneInfo geoZoneGeometries, HttpServletRequest request); static final String GEO_ZONES; }