/**
  * Lists contributors, based on an optional query string.
  *
  * @param q An optional query string to filter contributors.
  * @return A List of contributors, serialized as the response body.
  */
 @RequestMapping(value = "v1/contributors", method = RequestMethod.GET)
 public @ResponseBody PojoPage<Contributor> listContributors(
     @RequestParam(required = false) String q) {
   if (q == null) {
     return service.readAll(0);
   } else {
     return service.search(q);
   }
 }
 /**
  * Creates a new contributor based on data in the request body
  *
  * @param contributor The request body, marshalled into a Contributor object.
  * @return The newly persisted Contributor, with automated data added.
  */
 @RequestMapping(value = "v1/contributors", method = RequestMethod.POST)
 public @ResponseBody @PreAuthorize("hasRole('ROLE_ADMINS')") @ResponseStatus(HttpStatus.CREATED)
 Contributor newContributor(@RequestBody Contributor contributor) {
   contributor.setId(UUID.randomUUID().toString());
   service.store(contributor);
   return contributor;
 }
 /**
  * Replaces the contributor object with new data from the request body.
  *
  * @param id The id of the contributor to replace. Must match the id in the body.
  * @param contributor The new data for this contributor object.
  * @return The modified contributor.
  */
 @RequestMapping(value = "v1/contributors/{id}", method = RequestMethod.PUT)
 public @ResponseBody @PreAuthorize("hasRole('ROLE_ADMINS')") Contributor replaceContributor(
     @PathVariable("id") String id, @RequestBody Contributor contributor) {
   service.store(contributor);
   return contributor;
 }
 /**
  * Gets a single contributor object from the database.
  *
  * @param id The id of the contributor to fetch
  * @return The JSON serialization of a contributor in the response body.
  */
 @RequestMapping(value = "v1/contributors/{id}", method = RequestMethod.GET)
 public @ResponseBody Contributor get(@PathVariable("id") String id) {
   return service.read(id);
 }
 /**
  * Deletes a contributor by ID.
  *
  * @param id the id of the contributor to delete.
  */
 @RequestMapping(value = "v1/contributors/{id}", method = RequestMethod.DELETE)
 public @ResponseBody @PreAuthorize("hasRole('ROLE_ADMINS')") void removeContributor(
     @PathVariable("id") String id) {
   service.delete(id);
 }
Esempio n. 6
0
 @Before
 public void setupJoe() {
   contributorService.store(Utils.joeUser);
 }