@Test public void testCopyDataset() throws DocumentException, IOException { String providerId = "SampleProviderId"; String datasetId = "SampleDatasetId"; String newDatasetId = "SampleNewDatasetId"; WebTarget target = target("/" + DatasetOptionListContainer.DATASETS + "/" + datasetId).queryParam("newDatasetId", newDatasetId); DataProvider dataProvider = new DataProvider(providerId, "testName", "testCountry", "testDescription", null, "testNameCode", "testHomePage", ProviderType.LIBRARY, "SampleEmail"); OaiDataSource oaiDataSource = new OaiDataSource(dataProvider, "SampleId", "SampleDescription", "SampleSchema", "SampleNamespace", "SampleMetadataFormat", "SampleOaiSourceURL", "SampleOaiSet", new IdProvidedRecordIdPolicy(), new TreeMap<String, MetadataTransformation>()); oaiDataSource.setExportDir("/Sample/Export/Path"); oaiDataSource.setMarcFormat("SampleMarcFormat"); DefaultDataSourceContainer defaultDataSourceContainerWithNull = new DefaultDataSourceContainer(null, "SampleNameCode", "SampleName", "/Sample/Export/Path"); DefaultDataSourceContainer defaultDataSourceContainer = new DefaultDataSourceContainer(oaiDataSource, "SampleNameCode", "SampleName", "/Sample/Export/Path"); DataSource dataSource = new DataSource() { @Override public boolean isWorking() { throw new UnsupportedOperationException("Sorry, not implemented."); } @Override public Status ingestRecords(File logFile, boolean fullIngest) throws Exception { throw new UnsupportedOperationException("Sorry, not implemented."); } @Override public List<Long> getStatisticsHarvester() { throw new UnsupportedOperationException("Sorry, not implemented."); } @Override public int getNumberOfRecordsPerResponse() { throw new UnsupportedOperationException("Sorry, not implemented."); } @Override public String getNumberOfRecords2HarvestStr() { throw new UnsupportedOperationException("Sorry, not implemented."); } @Override public int getNumberOfRecords2Harvest() { throw new UnsupportedOperationException("Sorry, not implemented."); } @Override public Element addSpecificInfo(Element sourceElement) { throw new UnsupportedOperationException("Sorry, not implemented."); } }; DefaultDataSourceContainer defaultDataSourceContainerWithInvalidInstance = new DefaultDataSourceContainer(dataSource, "SampleNameCode", "SampleName", "/Sample/Export/Path"); when(dataManager.getDataSourceContainer(datasetId)).thenReturn(null).thenReturn(defaultDataSourceContainerWithNull).thenReturn(defaultDataSourceContainer) .thenReturn(defaultDataSourceContainerWithInvalidInstance); Response response = target.request(MediaType.APPLICATION_XML).post(Entity.entity(null, MediaType.APPLICATION_XML), Response.class); assertEquals(404, response.getStatus()); response = target.request(MediaType.APPLICATION_JSON).post(Entity.entity(null, MediaType.APPLICATION_XML), Response.class); assertEquals(404, response.getStatus()); when(dataManager.getDataSourceContainer(newDatasetId)).thenReturn(defaultDataSourceContainer).thenThrow(new DocumentException()); response = target.request(MediaType.APPLICATION_JSON).post(Entity.entity(null, MediaType.APPLICATION_XML), Response.class); assertEquals(409, response.getStatus()); response = target.request(MediaType.APPLICATION_JSON).post(Entity.entity(null, MediaType.APPLICATION_XML), Response.class); assertEquals(500, response.getStatus()); response = target.request(MediaType.APPLICATION_JSON).post(Entity.entity(null, MediaType.APPLICATION_XML), Response.class); assertEquals(500, response.getStatus()); }
@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") }) public Response copyDataset(@ApiParam(value = "Id of dataset", required = true) @PathParam("datasetId") String datasetId, @ApiParam(value = "newDatasetId", required = true) @QueryParam("newDatasetId") String newDatasetId) throws DoesNotExistException, InternalServerErrorException, AlreadyExistsException, MissingArgumentsException, InvalidArgumentsException { DefaultDataSourceContainer oldDataSourceContainer = null; try { oldDataSourceContainer = (DefaultDataSourceContainer)dataManager.getDataSourceContainer(datasetId); if (oldDataSourceContainer == null) throw new DoesNotExistException("Dataset with id " + datasetId + " does NOT exist!"); DataSource oldDataSource = oldDataSourceContainer.getDataSource(); if (oldDataSource == null) throw new DoesNotExistException("Dataset with id " + datasetId + " does NOT exist!"); } catch (DocumentException | IOException e) { throw new InternalServerErrorException("Error in server : " + e.getMessage()); } try { DefaultDataSourceContainer newDataSourceContainer = null; newDataSourceContainer = (DefaultDataSourceContainer)dataManager.getDataSourceContainer(newDatasetId); if (newDataSourceContainer != null) throw new AlreadyExistsException("Dataset with newId " + newDatasetId + " already exist!"); } catch (DocumentException | IOException e) { throw new InternalServerErrorException("Error in server : " + e.getMessage()); } DataProvider dataProviderParent = dataManager.getDataProviderParent(datasetId); DataSource oldDataSource = oldDataSourceContainer.getDataSource(); DefaultDataSourceContainer dataSourceContainer = new DefaultDataSourceContainer(oldDataSourceContainer); if(oldDataSource instanceof OaiDataSource) { OaiDataSource oldOaiDataSource = (OaiDataSource)oldDataSource; OaiDataSource oaiDataSource = new OaiDataSource(oldOaiDataSource); oaiDataSource.setId(newDatasetId); dataSourceContainer.setDataSource(oaiDataSource); } else if (oldDataSource instanceof DirectoryImporterDataSource) { DirectoryImporterDataSource oldDirectoryImporterDataSource = (DirectoryImporterDataSource)oldDataSource; DirectoryImporterDataSource directoryImporterDataSource = new DirectoryImporterDataSource(oldDirectoryImporterDataSource); directoryImporterDataSource.setId(newDatasetId); dataSourceContainer.setDataSource(directoryImporterDataSource); } else return Response.status(500).entity(new Result("Invalid dataSourceContainer instance in body!")).build(); return createDataset(dataProviderParent.getId(), dataSourceContainer); }
DatasetsResource { @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") }) public Response copyDataset(@ApiParam(value = "Id of dataset", required = true) @PathParam("datasetId") String datasetId, @ApiParam(value = "newDatasetId", required = true) @QueryParam("newDatasetId") String newDatasetId) throws DoesNotExistException, InternalServerErrorException, AlreadyExistsException, MissingArgumentsException, InvalidArgumentsException { DefaultDataSourceContainer oldDataSourceContainer = null; try { oldDataSourceContainer = (DefaultDataSourceContainer)dataManager.getDataSourceContainer(datasetId); if (oldDataSourceContainer == null) throw new DoesNotExistException("Dataset with id " + datasetId + " does NOT exist!"); DataSource oldDataSource = oldDataSourceContainer.getDataSource(); if (oldDataSource == null) throw new DoesNotExistException("Dataset with id " + datasetId + " does NOT exist!"); } catch (DocumentException | IOException e) { throw new InternalServerErrorException("Error in server : " + e.getMessage()); } try { DefaultDataSourceContainer newDataSourceContainer = null; newDataSourceContainer = (DefaultDataSourceContainer)dataManager.getDataSourceContainer(newDatasetId); if (newDataSourceContainer != null) throw new AlreadyExistsException("Dataset with newId " + newDatasetId + " already exist!"); } catch (DocumentException | IOException e) { throw new InternalServerErrorException("Error in server : " + e.getMessage()); } DataProvider dataProviderParent = dataManager.getDataProviderParent(datasetId); DataSource oldDataSource = oldDataSourceContainer.getDataSource(); DefaultDataSourceContainer dataSourceContainer = new DefaultDataSourceContainer(oldDataSourceContainer); if(oldDataSource instanceof OaiDataSource) { OaiDataSource oldOaiDataSource = (OaiDataSource)oldDataSource; OaiDataSource oaiDataSource = new OaiDataSource(oldOaiDataSource); oaiDataSource.setId(newDatasetId); dataSourceContainer.setDataSource(oaiDataSource); } else if (oldDataSource instanceof DirectoryImporterDataSource) { DirectoryImporterDataSource oldDirectoryImporterDataSource = (DirectoryImporterDataSource)oldDataSource; DirectoryImporterDataSource directoryImporterDataSource = new DirectoryImporterDataSource(oldDirectoryImporterDataSource); directoryImporterDataSource.setId(newDatasetId); dataSourceContainer.setDataSource(directoryImporterDataSource); } else return Response.status(500).entity(new Result("Invalid dataSourceContainer instance in body!")).build(); return createDataset(dataProviderParent.getId(), dataSourceContainer); } }
DatasetsResource { @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") }) public Response copyDataset(@ApiParam(value = "Id of dataset", required = true) @PathParam("datasetId") String datasetId, @ApiParam(value = "newDatasetId", required = true) @QueryParam("newDatasetId") String newDatasetId) throws DoesNotExistException, InternalServerErrorException, AlreadyExistsException, MissingArgumentsException, InvalidArgumentsException { DefaultDataSourceContainer oldDataSourceContainer = null; try { oldDataSourceContainer = (DefaultDataSourceContainer)dataManager.getDataSourceContainer(datasetId); if (oldDataSourceContainer == null) throw new DoesNotExistException("Dataset with id " + datasetId + " does NOT exist!"); DataSource oldDataSource = oldDataSourceContainer.getDataSource(); if (oldDataSource == null) throw new DoesNotExistException("Dataset with id " + datasetId + " does NOT exist!"); } catch (DocumentException | IOException e) { throw new InternalServerErrorException("Error in server : " + e.getMessage()); } try { DefaultDataSourceContainer newDataSourceContainer = null; newDataSourceContainer = (DefaultDataSourceContainer)dataManager.getDataSourceContainer(newDatasetId); if (newDataSourceContainer != null) throw new AlreadyExistsException("Dataset with newId " + newDatasetId + " already exist!"); } catch (DocumentException | IOException e) { throw new InternalServerErrorException("Error in server : " + e.getMessage()); } DataProvider dataProviderParent = dataManager.getDataProviderParent(datasetId); DataSource oldDataSource = oldDataSourceContainer.getDataSource(); DefaultDataSourceContainer dataSourceContainer = new DefaultDataSourceContainer(oldDataSourceContainer); if(oldDataSource instanceof OaiDataSource) { OaiDataSource oldOaiDataSource = (OaiDataSource)oldDataSource; OaiDataSource oaiDataSource = new OaiDataSource(oldOaiDataSource); oaiDataSource.setId(newDatasetId); dataSourceContainer.setDataSource(oaiDataSource); } else if (oldDataSource instanceof DirectoryImporterDataSource) { DirectoryImporterDataSource oldDirectoryImporterDataSource = (DirectoryImporterDataSource)oldDataSource; DirectoryImporterDataSource directoryImporterDataSource = new DirectoryImporterDataSource(oldDirectoryImporterDataSource); directoryImporterDataSource.setId(newDatasetId); dataSourceContainer.setDataSource(directoryImporterDataSource); } else return Response.status(500).entity(new Result("Invalid dataSourceContainer instance in body!")).build(); return createDataset(dataProviderParent.getId(), dataSourceContainer); } DatasetsResource();  DatasetsResource(DefaultDataManager dataManager); }
DatasetsResource { @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") }) public Response copyDataset(@ApiParam(value = "Id of dataset", required = true) @PathParam("datasetId") String datasetId, @ApiParam(value = "newDatasetId", required = true) @QueryParam("newDatasetId") String newDatasetId) throws DoesNotExistException, InternalServerErrorException, AlreadyExistsException, MissingArgumentsException, InvalidArgumentsException { DefaultDataSourceContainer oldDataSourceContainer = null; try { oldDataSourceContainer = (DefaultDataSourceContainer)dataManager.getDataSourceContainer(datasetId); if (oldDataSourceContainer == null) throw new DoesNotExistException("Dataset with id " + datasetId + " does NOT exist!"); DataSource oldDataSource = oldDataSourceContainer.getDataSource(); if (oldDataSource == null) throw new DoesNotExistException("Dataset with id " + datasetId + " does NOT exist!"); } catch (DocumentException | IOException e) { throw new InternalServerErrorException("Error in server : " + e.getMessage()); } try { DefaultDataSourceContainer newDataSourceContainer = null; newDataSourceContainer = (DefaultDataSourceContainer)dataManager.getDataSourceContainer(newDatasetId); if (newDataSourceContainer != null) throw new AlreadyExistsException("Dataset with newId " + newDatasetId + " already exist!"); } catch (DocumentException | IOException e) { throw new InternalServerErrorException("Error in server : " + e.getMessage()); } DataProvider dataProviderParent = dataManager.getDataProviderParent(datasetId); DataSource oldDataSource = oldDataSourceContainer.getDataSource(); DefaultDataSourceContainer dataSourceContainer = new DefaultDataSourceContainer(oldDataSourceContainer); if(oldDataSource instanceof OaiDataSource) { OaiDataSource oldOaiDataSource = (OaiDataSource)oldDataSource; OaiDataSource oaiDataSource = new OaiDataSource(oldOaiDataSource); oaiDataSource.setId(newDatasetId); dataSourceContainer.setDataSource(oaiDataSource); } else if (oldDataSource instanceof DirectoryImporterDataSource) { DirectoryImporterDataSource oldDirectoryImporterDataSource = (DirectoryImporterDataSource)oldDataSource; DirectoryImporterDataSource directoryImporterDataSource = new DirectoryImporterDataSource(oldDirectoryImporterDataSource); directoryImporterDataSource.setId(newDatasetId); dataSourceContainer.setDataSource(directoryImporterDataSource); } else return Response.status(500).entity(new Result("Invalid dataSourceContainer instance in body!")).build(); return createDataset(dataProviderParent.getId(), dataSourceContainer); } 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) @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") }) public Response copyDataset(@ApiParam(value = "Id of dataset", required = true) @PathParam("datasetId") String datasetId, @ApiParam(value = "newDatasetId", required = true) @QueryParam("newDatasetId") String newDatasetId) throws DoesNotExistException, InternalServerErrorException, AlreadyExistsException, MissingArgumentsException, InvalidArgumentsException { DefaultDataSourceContainer oldDataSourceContainer = null; try { oldDataSourceContainer = (DefaultDataSourceContainer)dataManager.getDataSourceContainer(datasetId); if (oldDataSourceContainer == null) throw new DoesNotExistException("Dataset with id " + datasetId + " does NOT exist!"); DataSource oldDataSource = oldDataSourceContainer.getDataSource(); if (oldDataSource == null) throw new DoesNotExistException("Dataset with id " + datasetId + " does NOT exist!"); } catch (DocumentException | IOException e) { throw new InternalServerErrorException("Error in server : " + e.getMessage()); } try { DefaultDataSourceContainer newDataSourceContainer = null; newDataSourceContainer = (DefaultDataSourceContainer)dataManager.getDataSourceContainer(newDatasetId); if (newDataSourceContainer != null) throw new AlreadyExistsException("Dataset with newId " + newDatasetId + " already exist!"); } catch (DocumentException | IOException e) { throw new InternalServerErrorException("Error in server : " + e.getMessage()); } DataProvider dataProviderParent = dataManager.getDataProviderParent(datasetId); DataSource oldDataSource = oldDataSourceContainer.getDataSource(); DefaultDataSourceContainer dataSourceContainer = new DefaultDataSourceContainer(oldDataSourceContainer); if(oldDataSource instanceof OaiDataSource) { OaiDataSource oldOaiDataSource = (OaiDataSource)oldDataSource; OaiDataSource oaiDataSource = new OaiDataSource(oldOaiDataSource); oaiDataSource.setId(newDatasetId); dataSourceContainer.setDataSource(oaiDataSource); } else if (oldDataSource instanceof DirectoryImporterDataSource) { DirectoryImporterDataSource oldDirectoryImporterDataSource = (DirectoryImporterDataSource)oldDataSource; DirectoryImporterDataSource directoryImporterDataSource = new DirectoryImporterDataSource(oldDirectoryImporterDataSource); directoryImporterDataSource.setId(newDatasetId); dataSourceContainer.setDataSource(directoryImporterDataSource); } else return Response.status(500).entity(new Result("Invalid dataSourceContainer instance in body!")).build(); return createDataset(dataProviderParent.getId(), dataSourceContainer); } 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; }