@Test public void testExportDataset() throws Exception { String datasetId = "SampleDatasetId"; WebTarget target = target("/" + DatasetOptionListContainer.DATASETS + "/" + datasetId + "/" + DatasetOptionListContainer.EXPORT).queryParam(DatasetOptionListContainer.FORMAT, ""); doThrow(new IOException()).doThrow(new AlreadyExistsException()).doThrow(new ObjectNotFoundException("NOT FOUND!")).doNothing().when(dataManager).startExportDataSource(datasetId, "1000", ""); Response response = target.request(MediaType.APPLICATION_XML).post(null, Response.class); assertEquals(500, response.getStatus()); response = target.request(MediaType.APPLICATION_XML).post(null, Response.class); assertEquals(409, response.getStatus()); response = target.request(MediaType.APPLICATION_XML).post(null, Response.class); assertEquals(404, response.getStatus()); response = target.request(MediaType.APPLICATION_XML).post(null, Response.class); assertEquals(200, response.getStatus()); }
@POST @Path("/" + DatasetOptionListContainer.DATASETID + "/" + DatasetOptionListContainer.EXPORT) @Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML }) @ApiOperation(value = "Initiates an export of data.", httpMethod = "POST", response = String.class) @ApiResponses(value = { @ApiResponse(code = 200, message = "OK (Response containing a String message)"), @ApiResponse(code = 404, message = "DoesNotExistException"), @ApiResponse(code = 409, message = "AlreadyExistsException"), @ApiResponse(code = 500, message = "InternalServerErrorException") }) public Response exportDataset(@ApiParam(value = "Id of dataset", required = true) @PathParam("datasetId") String datasetId, @ApiParam(value = "Format of export") @QueryParam("format") String format) throws DoesNotExistException, AlreadyExistsException, InternalServerErrorException { try { dataManager.startExportDataSource(datasetId, "1000", format); } catch (ClassNotFoundException | NoSuchMethodException | DocumentException | IOException | ParseException e) { throw new InternalServerErrorException("Internal Server Error : " + e.getMessage()); } catch (AlreadyExistsException e) { throw new AlreadyExistsException("Already exists: " + e.getMessage()); } catch (ObjectNotFoundException e) { throw new DoesNotExistException("Does NOT exist: " + e.getMessage()); } return Response.status(200).entity(new Result("Export of dataset with id: " + datasetId + " started!")).build(); }
DatasetsResource { @POST @Path("/" + DatasetOptionListContainer.DATASETID + "/" + DatasetOptionListContainer.EXPORT) @Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML }) @ApiOperation(value = "Initiates an export of data.", httpMethod = "POST", response = String.class) @ApiResponses(value = { @ApiResponse(code = 200, message = "OK (Response containing a String message)"), @ApiResponse(code = 404, message = "DoesNotExistException"), @ApiResponse(code = 409, message = "AlreadyExistsException"), @ApiResponse(code = 500, message = "InternalServerErrorException") }) public Response exportDataset(@ApiParam(value = "Id of dataset", required = true) @PathParam("datasetId") String datasetId, @ApiParam(value = "Format of export") @QueryParam("format") String format) throws DoesNotExistException, AlreadyExistsException, InternalServerErrorException { try { dataManager.startExportDataSource(datasetId, "1000", format); } catch (ClassNotFoundException | NoSuchMethodException | DocumentException | IOException | ParseException e) { throw new InternalServerErrorException("Internal Server Error : " + e.getMessage()); } catch (AlreadyExistsException e) { throw new AlreadyExistsException("Already exists: " + e.getMessage()); } catch (ObjectNotFoundException e) { throw new DoesNotExistException("Does NOT exist: " + e.getMessage()); } return Response.status(200).entity(new Result("Export of dataset with id: " + datasetId + " started!")).build(); } }
DatasetsResource { @POST @Path("/" + DatasetOptionListContainer.DATASETID + "/" + DatasetOptionListContainer.EXPORT) @Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML }) @ApiOperation(value = "Initiates an export of data.", httpMethod = "POST", response = String.class) @ApiResponses(value = { @ApiResponse(code = 200, message = "OK (Response containing a String message)"), @ApiResponse(code = 404, message = "DoesNotExistException"), @ApiResponse(code = 409, message = "AlreadyExistsException"), @ApiResponse(code = 500, message = "InternalServerErrorException") }) public Response exportDataset(@ApiParam(value = "Id of dataset", required = true) @PathParam("datasetId") String datasetId, @ApiParam(value = "Format of export") @QueryParam("format") String format) throws DoesNotExistException, AlreadyExistsException, InternalServerErrorException { try { dataManager.startExportDataSource(datasetId, "1000", format); } catch (ClassNotFoundException | NoSuchMethodException | DocumentException | IOException | ParseException e) { throw new InternalServerErrorException("Internal Server Error : " + e.getMessage()); } catch (AlreadyExistsException e) { throw new AlreadyExistsException("Already exists: " + e.getMessage()); } catch (ObjectNotFoundException e) { throw new DoesNotExistException("Does NOT exist: " + e.getMessage()); } return Response.status(200).entity(new Result("Export of dataset with id: " + datasetId + " started!")).build(); } DatasetsResource();  DatasetsResource(DefaultDataManager dataManager); }
DatasetsResource { @POST @Path("/" + DatasetOptionListContainer.DATASETID + "/" + DatasetOptionListContainer.EXPORT) @Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML }) @ApiOperation(value = "Initiates an export of data.", httpMethod = "POST", response = String.class) @ApiResponses(value = { @ApiResponse(code = 200, message = "OK (Response containing a String message)"), @ApiResponse(code = 404, message = "DoesNotExistException"), @ApiResponse(code = 409, message = "AlreadyExistsException"), @ApiResponse(code = 500, message = "InternalServerErrorException") }) public Response exportDataset(@ApiParam(value = "Id of dataset", required = true) @PathParam("datasetId") String datasetId, @ApiParam(value = "Format of export") @QueryParam("format") String format) throws DoesNotExistException, AlreadyExistsException, InternalServerErrorException { try { dataManager.startExportDataSource(datasetId, "1000", format); } catch (ClassNotFoundException | NoSuchMethodException | DocumentException | IOException | ParseException e) { throw new InternalServerErrorException("Internal Server Error : " + e.getMessage()); } catch (AlreadyExistsException e) { throw new AlreadyExistsException("Already exists: " + e.getMessage()); } catch (ObjectNotFoundException e) { throw new DoesNotExistException("Does NOT exist: " + e.getMessage()); } return Response.status(200).entity(new Result("Export of dataset with id: " + datasetId + " started!")).build(); } DatasetsResource();  DatasetsResource(DefaultDataManager dataManager); @OPTIONS @Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML }) @ApiOperation(value = "Get options over datasets conext.", httpMethod = "OPTIONS", response = DatasetOptionListContainer.class) @ApiResponses(value = { @ApiResponse(code = 200, message = "OK (Response containing a list of all available options)") }) DatasetOptionListContainer getOptions(); @GET @Path("/" + DatasetOptionListContainer.OPTIONS) @Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML }) @ApiOperation(value = "Get options over datasets conext.", httpMethod = "GET", response = DatasetOptionListContainer.class) @ApiResponses(value = { @ApiResponse(code = 200, message = "OK (Response containing a list of all available options)") }) DatasetOptionListContainer getGETOptions(); @GET @Path("/" + DatasetOptionListContainer.DATASETID) @Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML }) @ApiOperation(value = "Get specific dataset.", httpMethod = "GET", response = DataSourceContainer.class) @ApiResponses(value = { @ApiResponse(code = 200, message = "OK (Response containing an Dataset)"), @ApiResponse(code = 404, message = "DoesNotExistException") }) DataSourceContainer getDataset(@ApiParam(value = "Id of dataset", required = true) @PathParam("datasetId") String datasetId); @POST @Consumes({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML }) @Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML }) @ApiOperation(value = "Create a dataset.", httpMethod = "POST", response = String.class) @ApiResponses(value = { @ApiResponse(code = 201, message = "Created (Response containing a String message)"), @ApiResponse(code = 400, message = "InvalidArgumentsException"), @ApiResponse(code = 404, message = "DoesNotExistException"), @ApiResponse(code = 406, message = "MissingArgumentsException"), @ApiResponse(code = 409, message = "AlreadyExistsException"), @ApiResponse(code = 500, message = "InternalServerErrorException") }) Response createDataset(@ApiParam(value = "ProviderId", required = true) @QueryParam("providerId") String providerId,
            @ApiParam(value = "Dataset data", required = true) DataSourceContainer dataSourceContainer); @POST @Path("/" + DatasetOptionListContainer.DATASETID) @Consumes({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML }) @Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML }) @ApiOperation(value = "Copy a dataset.", httpMethod = "POST", response = String.class) @ApiResponses(value = { @ApiResponse(code = 201, message = "Created (Response containing a String message)"), @ApiResponse(code = 400, message = "InvalidArgumentsException"), @ApiResponse(code = 404, message = "DoesNotExistException"), @ApiResponse(code = 406, message = "MissingArgumentsException"), @ApiResponse(code = 409, message = "AlreadyExistsException"), @ApiResponse(code = 500, message = "InternalServerErrorException") }) Response copyDataset(@ApiParam(value = "Id of dataset", required = true) @PathParam("datasetId") String datasetId,
            @ApiParam(value = "newDatasetId", required = true) @QueryParam("newDatasetId") String newDatasetId); @DELETE @Path("/" + DatasetOptionListContainer.DATASETID) @Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML }) @ApiOperation(value = "Delete a dataset.", httpMethod = "DELETE", response = String.class) @ApiResponses(value = { @ApiResponse(code = 200, message = "OK (Response containing a String message)"), @ApiResponse(code = 404, message = "DoesNotExistException"), @ApiResponse(code = 500, message = "InternalServerErrorException") }) Response deleteDataset(@ApiParam(value = "Id of dataset", required = true) @PathParam("datasetId") String datasetId); @PUT @Path("/" + DatasetOptionListContainer.DATASETID) @Consumes({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML }) @Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML }) @ApiOperation(value = "Update a dataset.", httpMethod = "PUT", 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 = 409, message = "AlreadyExistsException"), @ApiResponse(code = 500, message = "InternalServerErrorException") }) Response updateDataset(@ApiParam(value = "Id of dataset", required = true) @PathParam("datasetId") String datasetId,
            @ApiParam(value = "Dataset data", required = true) DataSourceContainer dataSourceContainer); @GET @Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML }) @ApiOperation(value = "Get a list of datasets.", httpMethod = "GET", response = DataSourceContainer.class, responseContainer = "List") @ApiResponses(value = { @ApiResponse(code = 200, message = "OK (Response containing a list of datasets)"), @ApiResponse(code = 400, message = "InvalidArgumentsException"), @ApiResponse(code = 404, message = "DoesNotExistException") }) Response getDatasetList(@ApiParam(value = "ProviderId", required = true) @QueryParam("providerId") String providerId,
            @ApiParam(value = "Index where to start from(negative not allowed)", defaultValue = "0") @DefaultValue("0") @QueryParam("offset") int offset,
            @ApiParam(value = "Number of aggregators requested(-1 to get all)", defaultValue = "-1") @DefaultValue("-1") @QueryParam("number") int number); @GET @Path("/" + DatasetOptionListContainer.DATASETID + "/" + DatasetOptionListContainer.DATE) @Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML }) @ApiOperation(value = "Get last ingestion date.", httpMethod = "GET", response = String.class) @ApiResponses(value = { @ApiResponse(code = 200, message = "OK (Response containing a list of datasets)"), @ApiResponse(code = 404, message = "DoesNotExistException"), @ApiResponse(code = 500, message = "InternalServerErrorException") }) Response getDatasetLastIngestionDate(@ApiParam(value = "Id of dataset", required = true) @PathParam("datasetId") String datasetId); @GET @Path("/" + DatasetOptionListContainer.DATASETID + "/" + DatasetOptionListContainer.COUNT) @Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML }) @ApiOperation(value = "Get record count.", httpMethod = "GET", response = String.class) @ApiResponses(value = { @ApiResponse(code = 200, message = "OK (Response containing a list of datasets)"), @ApiResponse(code = 404, message = "DoesNotExistException"), @ApiResponse(code = 500, message = "InternalServerErrorException") }) Response getDatasetRecordCount(@ApiParam(value = "Id of dataset", required = true) @PathParam("datasetId") String datasetId); @POST @Path("/" + DatasetOptionListContainer.DATASETID + "/" + DatasetOptionListContainer.EXPORT) @Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML }) @ApiOperation(value = "Initiates an export of data.", httpMethod = "POST", response = String.class) @ApiResponses(value = { @ApiResponse(code = 200, message = "OK (Response containing a String message)"), @ApiResponse(code = 404, message = "DoesNotExistException"), @ApiResponse(code = 409, message = "AlreadyExistsException"), @ApiResponse(code = 500, message = "InternalServerErrorException") }) Response exportDataset(@ApiParam(value = "Id of dataset", required = true) @PathParam("datasetId") String datasetId, @ApiParam(value = "Format of export") @QueryParam("format") String format); }
DatasetsResource { @POST @Path("/" + DatasetOptionListContainer.DATASETID + "/" + DatasetOptionListContainer.EXPORT) @Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML }) @ApiOperation(value = "Initiates an export of data.", httpMethod = "POST", response = String.class) @ApiResponses(value = { @ApiResponse(code = 200, message = "OK (Response containing a String message)"), @ApiResponse(code = 404, message = "DoesNotExistException"), @ApiResponse(code = 409, message = "AlreadyExistsException"), @ApiResponse(code = 500, message = "InternalServerErrorException") }) public Response exportDataset(@ApiParam(value = "Id of dataset", required = true) @PathParam("datasetId") String datasetId, @ApiParam(value = "Format of export") @QueryParam("format") String format) throws DoesNotExistException, AlreadyExistsException, InternalServerErrorException { try { dataManager.startExportDataSource(datasetId, "1000", format); } catch (ClassNotFoundException | NoSuchMethodException | DocumentException | IOException | ParseException e) { throw new InternalServerErrorException("Internal Server Error : " + e.getMessage()); } catch (AlreadyExistsException e) { throw new AlreadyExistsException("Already exists: " + e.getMessage()); } catch (ObjectNotFoundException e) { throw new DoesNotExistException("Does NOT exist: " + e.getMessage()); } return Response.status(200).entity(new Result("Export of dataset with id: " + datasetId + " started!")).build(); } DatasetsResource();  DatasetsResource(DefaultDataManager dataManager); @OPTIONS @Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML }) @ApiOperation(value = "Get options over datasets conext.", httpMethod = "OPTIONS", response = DatasetOptionListContainer.class) @ApiResponses(value = { @ApiResponse(code = 200, message = "OK (Response containing a list of all available options)") }) DatasetOptionListContainer getOptions(); @GET @Path("/" + DatasetOptionListContainer.OPTIONS) @Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML }) @ApiOperation(value = "Get options over datasets conext.", httpMethod = "GET", response = DatasetOptionListContainer.class) @ApiResponses(value = { @ApiResponse(code = 200, message = "OK (Response containing a list of all available options)") }) DatasetOptionListContainer getGETOptions(); @GET @Path("/" + DatasetOptionListContainer.DATASETID) @Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML }) @ApiOperation(value = "Get specific dataset.", httpMethod = "GET", response = DataSourceContainer.class) @ApiResponses(value = { @ApiResponse(code = 200, message = "OK (Response containing an Dataset)"), @ApiResponse(code = 404, message = "DoesNotExistException") }) DataSourceContainer getDataset(@ApiParam(value = "Id of dataset", required = true) @PathParam("datasetId") String datasetId); @POST @Consumes({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML }) @Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML }) @ApiOperation(value = "Create a dataset.", httpMethod = "POST", response = String.class) @ApiResponses(value = { @ApiResponse(code = 201, message = "Created (Response containing a String message)"), @ApiResponse(code = 400, message = "InvalidArgumentsException"), @ApiResponse(code = 404, message = "DoesNotExistException"), @ApiResponse(code = 406, message = "MissingArgumentsException"), @ApiResponse(code = 409, message = "AlreadyExistsException"), @ApiResponse(code = 500, message = "InternalServerErrorException") }) Response createDataset(@ApiParam(value = "ProviderId", required = true) @QueryParam("providerId") String providerId,
            @ApiParam(value = "Dataset data", required = true) DataSourceContainer dataSourceContainer); @POST @Path("/" + DatasetOptionListContainer.DATASETID) @Consumes({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML }) @Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML }) @ApiOperation(value = "Copy a dataset.", httpMethod = "POST", response = String.class) @ApiResponses(value = { @ApiResponse(code = 201, message = "Created (Response containing a String message)"), @ApiResponse(code = 400, message = "InvalidArgumentsException"), @ApiResponse(code = 404, message = "DoesNotExistException"), @ApiResponse(code = 406, message = "MissingArgumentsException"), @ApiResponse(code = 409, message = "AlreadyExistsException"), @ApiResponse(code = 500, message = "InternalServerErrorException") }) Response copyDataset(@ApiParam(value = "Id of dataset", required = true) @PathParam("datasetId") String datasetId,
            @ApiParam(value = "newDatasetId", required = true) @QueryParam("newDatasetId") String newDatasetId); @DELETE @Path("/" + DatasetOptionListContainer.DATASETID) @Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML }) @ApiOperation(value = "Delete a dataset.", httpMethod = "DELETE", response = String.class) @ApiResponses(value = { @ApiResponse(code = 200, message = "OK (Response containing a String message)"), @ApiResponse(code = 404, message = "DoesNotExistException"), @ApiResponse(code = 500, message = "InternalServerErrorException") }) Response deleteDataset(@ApiParam(value = "Id of dataset", required = true) @PathParam("datasetId") String datasetId); @PUT @Path("/" + DatasetOptionListContainer.DATASETID) @Consumes({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML }) @Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML }) @ApiOperation(value = "Update a dataset.", httpMethod = "PUT", 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 = 409, message = "AlreadyExistsException"), @ApiResponse(code = 500, message = "InternalServerErrorException") }) Response updateDataset(@ApiParam(value = "Id of dataset", required = true) @PathParam("datasetId") String datasetId,
            @ApiParam(value = "Dataset data", required = true) DataSourceContainer dataSourceContainer); @GET @Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML }) @ApiOperation(value = "Get a list of datasets.", httpMethod = "GET", response = DataSourceContainer.class, responseContainer = "List") @ApiResponses(value = { @ApiResponse(code = 200, message = "OK (Response containing a list of datasets)"), @ApiResponse(code = 400, message = "InvalidArgumentsException"), @ApiResponse(code = 404, message = "DoesNotExistException") }) Response getDatasetList(@ApiParam(value = "ProviderId", required = true) @QueryParam("providerId") String providerId,
            @ApiParam(value = "Index where to start from(negative not allowed)", defaultValue = "0") @DefaultValue("0") @QueryParam("offset") int offset,
            @ApiParam(value = "Number of aggregators requested(-1 to get all)", defaultValue = "-1") @DefaultValue("-1") @QueryParam("number") int number); @GET @Path("/" + DatasetOptionListContainer.DATASETID + "/" + DatasetOptionListContainer.DATE) @Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML }) @ApiOperation(value = "Get last ingestion date.", httpMethod = "GET", response = String.class) @ApiResponses(value = { @ApiResponse(code = 200, message = "OK (Response containing a list of datasets)"), @ApiResponse(code = 404, message = "DoesNotExistException"), @ApiResponse(code = 500, message = "InternalServerErrorException") }) Response getDatasetLastIngestionDate(@ApiParam(value = "Id of dataset", required = true) @PathParam("datasetId") String datasetId); @GET @Path("/" + DatasetOptionListContainer.DATASETID + "/" + DatasetOptionListContainer.COUNT) @Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML }) @ApiOperation(value = "Get record count.", httpMethod = "GET", response = String.class) @ApiResponses(value = { @ApiResponse(code = 200, message = "OK (Response containing a list of datasets)"), @ApiResponse(code = 404, message = "DoesNotExistException"), @ApiResponse(code = 500, message = "InternalServerErrorException") }) Response getDatasetRecordCount(@ApiParam(value = "Id of dataset", required = true) @PathParam("datasetId") String datasetId); @POST @Path("/" + DatasetOptionListContainer.DATASETID + "/" + DatasetOptionListContainer.EXPORT) @Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML }) @ApiOperation(value = "Initiates an export of data.", httpMethod = "POST", response = String.class) @ApiResponses(value = { @ApiResponse(code = 200, message = "OK (Response containing a String message)"), @ApiResponse(code = 404, message = "DoesNotExistException"), @ApiResponse(code = 409, message = "AlreadyExistsException"), @ApiResponse(code = 500, message = "InternalServerErrorException") }) Response exportDataset(@ApiParam(value = "Id of dataset", required = true) @PathParam("datasetId") String datasetId, @ApiParam(value = "Format of export") @QueryParam("format") String format); public DefaultDataManager dataManager; }