コード例 #1
0
 /**
  * Handles GET requests of the URL "/datarecords"<br>
  * This method is used to retrieve data records. The GET parameter name is used for filtering the
  * result. If this parameter is not provided all results are returned.
  *
  * @param name Filter for field name
  * @return List including retrieved data records + status 200 OK
  */
 @RequestMapping(value = "/datarecords", method = RequestMethod.GET, produces = "application/json")
 public ResponseEntity<List<DataRecord>> findDataRecordsByName(
     @RequestParam(value = "name", defaultValue = "") String name) {
   if (name.length() == 0) return new ResponseEntity<>(service.findTop100(), HttpStatus.OK);
   else
     return new ResponseEntity<>(
         service.findTop100ByNameContainingIgnoreCase(name), HttpStatus.OK);
 }
コード例 #2
0
  /**
   * Handles PUT requests of the URL "/datarecords/{id}"<br>
   * This method is used to update an existing data record specified by the id. The id is part of
   * the URL. The new data record is part of the body. <br>
   * If the id does not exist an error is returned.
   *
   * @param id The id of the data record that will be updated.
   * @param newDataRecord The data record containing the new information
   * @return the updated object + status 200 OK or an error + status 404 NOT FOUND
   */
  @RequestMapping(
      value = "/datarecords/{id}",
      method = RequestMethod.PUT,
      produces = "application/json")
  public ResponseEntity<DataRecord> updateDataRecord(
      @PathVariable String id, @RequestBody DataRecord newDataRecord) {
    DataRecord dataRecord = service.findById(id);
    dataRecord.setName(newDataRecord.getName());
    dataRecord.setDescription(newDataRecord.getDescription());

    return new ResponseEntity<>(service.update(dataRecord), HttpStatus.OK);
  }
コード例 #3
0
 /**
  * Handles GET requests of the URL "/datarecords/{id}"<br>
  * This method is used to retrieve a data record specified by the id. The id is part of the URL.
  * <br>
  * If the id does not exist an error is returned.
  *
  * @param id The id of the data record that will be retrieved
  * @return the retrieved object + status 200 OK or an error + status 404 NOT FOUND
  */
 @RequestMapping(
     value = "/datarecords/{id}",
     method = RequestMethod.GET,
     produces = "application/json")
 public ResponseEntity<DataRecord> findDataRecord(@PathVariable String id) {
   return new ResponseEntity<>(service.findById(id), HttpStatus.OK);
 }
コード例 #4
0
 /**
  * Handles DELETE requests of the URL "/datarecords/{id}"<br>
  * This method is used to remove an existing data record specified by the id. The id is part of
  * the URL. If the id does not exist an error is returned.
  *
  * @param id The id of the data record that will be removed.
  * @return status 200 OK if the data record has been deleted successfully
  */
 @RequestMapping(
     value = "/datarecords/{id}",
     method = RequestMethod.DELETE,
     produces = "application/json")
 public ResponseEntity<DataRecord> updateDataRecord(@PathVariable String id) {
   service.delete(id);
   return new ResponseEntity<>(HttpStatus.OK);
 }
コード例 #5
0
  /**
   * Handles POST requests of the URL "/datarecords"<br>
   * This method is used to create a new data record. Therefore the datarecord object needs to be
   * specified in the request body.
   *
   * @param dataRecord The data record object that will be created
   * @return The created data record + status 201 CREATED
   */
  @RequestMapping(
      value = "/datarecords",
      method = RequestMethod.POST,
      produces = "application/json")
  public ResponseEntity<DataRecord> createDataRecord(@RequestBody DataRecord dataRecord) {

    // the id will be set when inserting into the database, so we set it to null now
    dataRecord.setId(null);

    service.create(dataRecord);
    return new ResponseEntity<>(dataRecord, HttpStatus.CREATED);
  }