@Test public void testRemoveRecord() throws Exception { String recordId = "recordIdSample"; WebTarget target = target("/" + RecordOptionListContainer.RECORDS).queryParam("recordId", recordId).queryParam("type", RecordOptionListContainer.DELETE); when(dataManager.deleteRecord(recordId)).thenThrow(new IOException()).thenThrow(new ObjectNotFoundException("Record with id: " + recordId + " does NOT exist!")).thenThrow(new InvalidInputException("Invalid")).thenReturn(MessageType.OK); Response response = target.request(MediaType.APPLICATION_XML).delete(); assertEquals(500, response.getStatus()); response = target.request(MediaType.APPLICATION_XML).delete(); assertEquals(404, response.getStatus()); response = target.request(MediaType.APPLICATION_XML).delete(); assertEquals(400, response.getStatus()); response = target.request(MediaType.APPLICATION_XML).delete(); assertEquals(200, response.getStatus()); target = target("/" + RecordOptionListContainer.RECORDS).queryParam("recordId", recordId).queryParam("type", RecordOptionListContainer.ERASE); when(dataManager.eraseRecord(recordId)).thenThrow(new IOException()).thenThrow(new ObjectNotFoundException("Record with id: " + recordId + " does NOT exist!")).thenThrow(new InvalidInputException("Invalid")).thenReturn(MessageType.OK); response = target.request(MediaType.APPLICATION_XML).delete(); assertEquals(500, response.getStatus()); response = target.request(MediaType.APPLICATION_XML).delete(); assertEquals(404, response.getStatus()); response = target.request(MediaType.APPLICATION_XML).delete(); assertEquals(400, response.getStatus()); response = target.request(MediaType.APPLICATION_XML).delete(); assertEquals(200, response.getStatus()); }
@DELETE @Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML }) @ApiOperation(value = "Deletes (mark) or permanently erase a record.", httpMethod = "DELETE", response = String.class) @ApiResponses(value = { @ApiResponse(code = 200, message = "OK (Response containing a String message)"), @ApiResponse(code = 400, message = "InvalidArgumentsException"), @ApiResponse(code = 404, message = "DoesNotExistException"), @ApiResponse(code = 406, message = "MissingArgumentsException"), @ApiResponse(code = 500, message = "InternalServerErrorException") }) public Response removeRecord( @ApiParam(value = "Id of record", required = true) @QueryParam("recordId") String recordId, @ApiParam(value = "Delete(mark) or erase(permanent)", defaultValue = RecordOptionListContainer.DELETE, allowableValues = RecordOptionListContainer.DELETE + " , " + RecordOptionListContainer.ERASE) @DefaultValue(RecordOptionListContainer.DELETE) @QueryParam("type") String type) throws DoesNotExistException, MissingArgumentsException, InvalidArgumentsException { if (recordId == null || recordId.equals("")) throw new MissingArgumentsException("Missing value: " + "recordId type missing!"); if (type == null || type.equals("") || (!type.equals(RecordOptionListContainer.DELETE) && !type.equals(RecordOptionListContainer.ERASE))) throw new MissingArgumentsException("Missing value: " + "Query parameter type not valid!"); if (type.equals(RecordOptionListContainer.DELETE)) { try { dataManager.deleteRecord(recordId); } catch (DocumentException | SQLException | IOException e) { throw new InternalServerErrorException("Internal Server Error : " + e.getMessage()); } catch (ObjectNotFoundException e) { throw new DoesNotExistException("Does NOT exist: " + e.getMessage()); } catch (InvalidInputException e) { throw new InvalidArgumentsException("Invalid argument: " + e.getMessage()); } return Response.status(200).entity(new Result("Record with id: " + recordId + " deleted!")).build(); } else { try { dataManager.eraseRecord(recordId); } catch (DocumentException | SQLException | IOException e) { throw new InternalServerErrorException("Internal Server Error : " + e.getMessage()); } catch (ObjectNotFoundException e) { throw new DoesNotExistException("Does NOT exist: " + e.getMessage()); } catch (InvalidInputException e) { throw new InvalidArgumentsException("Invalid argument: " + e.getMessage()); } return Response.status(200).entity(new Result("Record with id: " + recordId + " erased!")).build(); } }
RecordsResource { @DELETE @Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML }) @ApiOperation(value = "Deletes (mark) or permanently erase a record.", httpMethod = "DELETE", response = String.class) @ApiResponses(value = { @ApiResponse(code = 200, message = "OK (Response containing a String message)"), @ApiResponse(code = 400, message = "InvalidArgumentsException"), @ApiResponse(code = 404, message = "DoesNotExistException"), @ApiResponse(code = 406, message = "MissingArgumentsException"), @ApiResponse(code = 500, message = "InternalServerErrorException") }) public Response removeRecord( @ApiParam(value = "Id of record", required = true) @QueryParam("recordId") String recordId, @ApiParam(value = "Delete(mark) or erase(permanent)", defaultValue = RecordOptionListContainer.DELETE, allowableValues = RecordOptionListContainer.DELETE + " , " + RecordOptionListContainer.ERASE) @DefaultValue(RecordOptionListContainer.DELETE) @QueryParam("type") String type) throws DoesNotExistException, MissingArgumentsException, InvalidArgumentsException { if (recordId == null || recordId.equals("")) throw new MissingArgumentsException("Missing value: " + "recordId type missing!"); if (type == null || type.equals("") || (!type.equals(RecordOptionListContainer.DELETE) && !type.equals(RecordOptionListContainer.ERASE))) throw new MissingArgumentsException("Missing value: " + "Query parameter type not valid!"); if (type.equals(RecordOptionListContainer.DELETE)) { try { dataManager.deleteRecord(recordId); } catch (DocumentException | SQLException | IOException e) { throw new InternalServerErrorException("Internal Server Error : " + e.getMessage()); } catch (ObjectNotFoundException e) { throw new DoesNotExistException("Does NOT exist: " + e.getMessage()); } catch (InvalidInputException e) { throw new InvalidArgumentsException("Invalid argument: " + e.getMessage()); } return Response.status(200).entity(new Result("Record with id: " + recordId + " deleted!")).build(); } else { try { dataManager.eraseRecord(recordId); } catch (DocumentException | SQLException | IOException e) { throw new InternalServerErrorException("Internal Server Error : " + e.getMessage()); } catch (ObjectNotFoundException e) { throw new DoesNotExistException("Does NOT exist: " + e.getMessage()); } catch (InvalidInputException e) { throw new InvalidArgumentsException("Invalid argument: " + e.getMessage()); } return Response.status(200).entity(new Result("Record with id: " + recordId + " erased!")).build(); } } }
RecordsResource { @DELETE @Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML }) @ApiOperation(value = "Deletes (mark) or permanently erase a record.", httpMethod = "DELETE", response = String.class) @ApiResponses(value = { @ApiResponse(code = 200, message = "OK (Response containing a String message)"), @ApiResponse(code = 400, message = "InvalidArgumentsException"), @ApiResponse(code = 404, message = "DoesNotExistException"), @ApiResponse(code = 406, message = "MissingArgumentsException"), @ApiResponse(code = 500, message = "InternalServerErrorException") }) public Response removeRecord( @ApiParam(value = "Id of record", required = true) @QueryParam("recordId") String recordId, @ApiParam(value = "Delete(mark) or erase(permanent)", defaultValue = RecordOptionListContainer.DELETE, allowableValues = RecordOptionListContainer.DELETE + " , " + RecordOptionListContainer.ERASE) @DefaultValue(RecordOptionListContainer.DELETE) @QueryParam("type") String type) throws DoesNotExistException, MissingArgumentsException, InvalidArgumentsException { if (recordId == null || recordId.equals("")) throw new MissingArgumentsException("Missing value: " + "recordId type missing!"); if (type == null || type.equals("") || (!type.equals(RecordOptionListContainer.DELETE) && !type.equals(RecordOptionListContainer.ERASE))) throw new MissingArgumentsException("Missing value: " + "Query parameter type not valid!"); if (type.equals(RecordOptionListContainer.DELETE)) { try { dataManager.deleteRecord(recordId); } catch (DocumentException | SQLException | IOException e) { throw new InternalServerErrorException("Internal Server Error : " + e.getMessage()); } catch (ObjectNotFoundException e) { throw new DoesNotExistException("Does NOT exist: " + e.getMessage()); } catch (InvalidInputException e) { throw new InvalidArgumentsException("Invalid argument: " + e.getMessage()); } return Response.status(200).entity(new Result("Record with id: " + recordId + " deleted!")).build(); } else { try { dataManager.eraseRecord(recordId); } catch (DocumentException | SQLException | IOException e) { throw new InternalServerErrorException("Internal Server Error : " + e.getMessage()); } catch (ObjectNotFoundException e) { throw new DoesNotExistException("Does NOT exist: " + e.getMessage()); } catch (InvalidInputException e) { throw new InvalidArgumentsException("Invalid argument: " + e.getMessage()); } return Response.status(200).entity(new Result("Record with id: " + recordId + " erased!")).build(); } } RecordsResource();  RecordsResource(DefaultDataManager dataManager, Urn urn); }
RecordsResource { @DELETE @Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML }) @ApiOperation(value = "Deletes (mark) or permanently erase a record.", httpMethod = "DELETE", response = String.class) @ApiResponses(value = { @ApiResponse(code = 200, message = "OK (Response containing a String message)"), @ApiResponse(code = 400, message = "InvalidArgumentsException"), @ApiResponse(code = 404, message = "DoesNotExistException"), @ApiResponse(code = 406, message = "MissingArgumentsException"), @ApiResponse(code = 500, message = "InternalServerErrorException") }) public Response removeRecord( @ApiParam(value = "Id of record", required = true) @QueryParam("recordId") String recordId, @ApiParam(value = "Delete(mark) or erase(permanent)", defaultValue = RecordOptionListContainer.DELETE, allowableValues = RecordOptionListContainer.DELETE + " , " + RecordOptionListContainer.ERASE) @DefaultValue(RecordOptionListContainer.DELETE) @QueryParam("type") String type) throws DoesNotExistException, MissingArgumentsException, InvalidArgumentsException { if (recordId == null || recordId.equals("")) throw new MissingArgumentsException("Missing value: " + "recordId type missing!"); if (type == null || type.equals("") || (!type.equals(RecordOptionListContainer.DELETE) && !type.equals(RecordOptionListContainer.ERASE))) throw new MissingArgumentsException("Missing value: " + "Query parameter type not valid!"); if (type.equals(RecordOptionListContainer.DELETE)) { try { dataManager.deleteRecord(recordId); } catch (DocumentException | SQLException | IOException e) { throw new InternalServerErrorException("Internal Server Error : " + e.getMessage()); } catch (ObjectNotFoundException e) { throw new DoesNotExistException("Does NOT exist: " + e.getMessage()); } catch (InvalidInputException e) { throw new InvalidArgumentsException("Invalid argument: " + e.getMessage()); } return Response.status(200).entity(new Result("Record with id: " + recordId + " deleted!")).build(); } else { try { dataManager.eraseRecord(recordId); } catch (DocumentException | SQLException | IOException e) { throw new InternalServerErrorException("Internal Server Error : " + e.getMessage()); } catch (ObjectNotFoundException e) { throw new DoesNotExistException("Does NOT exist: " + e.getMessage()); } catch (InvalidInputException e) { throw new InvalidArgumentsException("Invalid argument: " + e.getMessage()); } return Response.status(200).entity(new Result("Record with id: " + recordId + " erased!")).build(); } } RecordsResource();  RecordsResource(DefaultDataManager dataManager, Urn urn); @OPTIONS @Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML }) @ApiOperation(value = "Get options over record conext.", httpMethod = "OPTIONS", response = RecordOptionListContainer.class) @ApiResponses(value = { @ApiResponse(code = 200, message = "OK (Response containing a list of all available options)") }) RecordOptionListContainer getOptions(); @GET @Path("/" + RecordOptionListContainer.OPTIONS) @Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML }) @ApiOperation(value = "Get options over record conext.", httpMethod = "GET", response = RecordOptionListContainer.class) @ApiResponses(value = { @ApiResponse(code = 200, message = "OK (Response containing a list of all available options)") }) RecordOptionListContainer getGETOptions(); @GET @Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML }) @ApiOperation(value = "Get specific record.", httpMethod = "GET", response = String.class) @ApiResponses(value = { @ApiResponse(code = 200, message = "OK (Response containing a Record)"), @ApiResponse(code = 400, message = "InvalidArgumentsException"), @ApiResponse(code = 404, message = "DoesNotExistException"), @ApiResponse(code = 500, message = "InternalServerErrorException") }) Response getRecord(@ApiParam(value = "Id of record", required = true) @QueryParam("recordId") String recordId); @DELETE @Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML }) @ApiOperation(value = "Deletes (mark) or permanently erase a record.", httpMethod = "DELETE", response = String.class) @ApiResponses(value = { @ApiResponse(code = 200, message = "OK (Response containing a String message)"), @ApiResponse(code = 400, message = "InvalidArgumentsException"), @ApiResponse(code = 404, message = "DoesNotExistException"), @ApiResponse(code = 406, message = "MissingArgumentsException"), @ApiResponse(code = 500, message = "InternalServerErrorException") }) Response removeRecord(
            @ApiParam(value = "Id of record", required = true) @QueryParam("recordId") String recordId,
            @ApiParam(value = "Delete(mark) or erase(permanent)", defaultValue = RecordOptionListContainer.DELETE, allowableValues = RecordOptionListContainer.DELETE + " , " + RecordOptionListContainer.ERASE) @DefaultValue(RecordOptionListContainer.DELETE) @QueryParam("type") String type); @POST @Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML }) @Consumes(MediaType.APPLICATION_XML) @ApiOperation(value = "Create a new record.", httpMethod = "POST", response = String.class) @ApiResponses(value = { @ApiResponse(code = 201, message = "OK (Response containing a String message)"), @ApiResponse(code = 404, message = "DoesNotExistException"), @ApiResponse(code = 406, message = "MissingArgumentsException"), // @ApiResponse(code = 409, message = "AlreadyExistsException"), @ApiResponse(code = 500, message = "InternalServerErrorException") }) Response createRecord(@ApiParam(value = "Id of dataset", required = true) @QueryParam("datasetId") String datasetId,
            @ApiParam(value = "Id of record", required = true) @QueryParam("recordId") String recordId, @ApiParam(value = "Record data", required = true) String recordString); }
RecordsResource { @DELETE @Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML }) @ApiOperation(value = "Deletes (mark) or permanently erase a record.", httpMethod = "DELETE", response = String.class) @ApiResponses(value = { @ApiResponse(code = 200, message = "OK (Response containing a String message)"), @ApiResponse(code = 400, message = "InvalidArgumentsException"), @ApiResponse(code = 404, message = "DoesNotExistException"), @ApiResponse(code = 406, message = "MissingArgumentsException"), @ApiResponse(code = 500, message = "InternalServerErrorException") }) public Response removeRecord( @ApiParam(value = "Id of record", required = true) @QueryParam("recordId") String recordId, @ApiParam(value = "Delete(mark) or erase(permanent)", defaultValue = RecordOptionListContainer.DELETE, allowableValues = RecordOptionListContainer.DELETE + " , " + RecordOptionListContainer.ERASE) @DefaultValue(RecordOptionListContainer.DELETE) @QueryParam("type") String type) throws DoesNotExistException, MissingArgumentsException, InvalidArgumentsException { if (recordId == null || recordId.equals("")) throw new MissingArgumentsException("Missing value: " + "recordId type missing!"); if (type == null || type.equals("") || (!type.equals(RecordOptionListContainer.DELETE) && !type.equals(RecordOptionListContainer.ERASE))) throw new MissingArgumentsException("Missing value: " + "Query parameter type not valid!"); if (type.equals(RecordOptionListContainer.DELETE)) { try { dataManager.deleteRecord(recordId); } catch (DocumentException | SQLException | IOException e) { throw new InternalServerErrorException("Internal Server Error : " + e.getMessage()); } catch (ObjectNotFoundException e) { throw new DoesNotExistException("Does NOT exist: " + e.getMessage()); } catch (InvalidInputException e) { throw new InvalidArgumentsException("Invalid argument: " + e.getMessage()); } return Response.status(200).entity(new Result("Record with id: " + recordId + " deleted!")).build(); } else { try { dataManager.eraseRecord(recordId); } catch (DocumentException | SQLException | IOException e) { throw new InternalServerErrorException("Internal Server Error : " + e.getMessage()); } catch (ObjectNotFoundException e) { throw new DoesNotExistException("Does NOT exist: " + e.getMessage()); } catch (InvalidInputException e) { throw new InvalidArgumentsException("Invalid argument: " + e.getMessage()); } return Response.status(200).entity(new Result("Record with id: " + recordId + " erased!")).build(); } } RecordsResource();  RecordsResource(DefaultDataManager dataManager, Urn urn); @OPTIONS @Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML }) @ApiOperation(value = "Get options over record conext.", httpMethod = "OPTIONS", response = RecordOptionListContainer.class) @ApiResponses(value = { @ApiResponse(code = 200, message = "OK (Response containing a list of all available options)") }) RecordOptionListContainer getOptions(); @GET @Path("/" + RecordOptionListContainer.OPTIONS) @Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML }) @ApiOperation(value = "Get options over record conext.", httpMethod = "GET", response = RecordOptionListContainer.class) @ApiResponses(value = { @ApiResponse(code = 200, message = "OK (Response containing a list of all available options)") }) RecordOptionListContainer getGETOptions(); @GET @Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML }) @ApiOperation(value = "Get specific record.", httpMethod = "GET", response = String.class) @ApiResponses(value = { @ApiResponse(code = 200, message = "OK (Response containing a Record)"), @ApiResponse(code = 400, message = "InvalidArgumentsException"), @ApiResponse(code = 404, message = "DoesNotExistException"), @ApiResponse(code = 500, message = "InternalServerErrorException") }) Response getRecord(@ApiParam(value = "Id of record", required = true) @QueryParam("recordId") String recordId); @DELETE @Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML }) @ApiOperation(value = "Deletes (mark) or permanently erase a record.", httpMethod = "DELETE", response = String.class) @ApiResponses(value = { @ApiResponse(code = 200, message = "OK (Response containing a String message)"), @ApiResponse(code = 400, message = "InvalidArgumentsException"), @ApiResponse(code = 404, message = "DoesNotExistException"), @ApiResponse(code = 406, message = "MissingArgumentsException"), @ApiResponse(code = 500, message = "InternalServerErrorException") }) Response removeRecord(
            @ApiParam(value = "Id of record", required = true) @QueryParam("recordId") String recordId,
            @ApiParam(value = "Delete(mark) or erase(permanent)", defaultValue = RecordOptionListContainer.DELETE, allowableValues = RecordOptionListContainer.DELETE + " , " + RecordOptionListContainer.ERASE) @DefaultValue(RecordOptionListContainer.DELETE) @QueryParam("type") String type); @POST @Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML }) @Consumes(MediaType.APPLICATION_XML) @ApiOperation(value = "Create a new record.", httpMethod = "POST", response = String.class) @ApiResponses(value = { @ApiResponse(code = 201, message = "OK (Response containing a String message)"), @ApiResponse(code = 404, message = "DoesNotExistException"), @ApiResponse(code = 406, message = "MissingArgumentsException"), // @ApiResponse(code = 409, message = "AlreadyExistsException"), @ApiResponse(code = 500, message = "InternalServerErrorException") }) Response createRecord(@ApiParam(value = "Id of dataset", required = true) @QueryParam("datasetId") String datasetId,
            @ApiParam(value = "Id of record", required = true) @QueryParam("recordId") String recordId, @ApiParam(value = "Record data", required = true) String recordString); public DefaultDataManager dataManager; public Urn urn; }