@Test public void testScheduleHarvest() throws Exception { String providerId = "SampleProviderId"; String datasetId = "SampleId"; WebTarget target = target("/" + DatasetOptionListContainer.DATASETS + "/" + datasetId + "/" + HarvestOptionListContainer.HARVEST + "/" + HarvestOptionListContainer.SCHEDULE); 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 defaultDataSourceContainer = new DefaultDataSourceContainer(oaiDataSource, "SampleNameCode", "SampleName", "/Sample/Export/Path"); ScheduledTask scheduledTask = new ScheduledTask(); String newTaskId = "SampleId"; scheduledTask.setId(newTaskId); Calendar calendar = Calendar.getInstance(); scheduledTask.setFrequency(null); when(dataManager.getDataSourceContainer(datasetId)).thenThrow(new IOException()).thenReturn(null).thenReturn(defaultDataSourceContainer); Response response = target.request(MediaType.APPLICATION_XML).post(Entity.entity(scheduledTask, MediaType.APPLICATION_XML), Response.class); assertEquals(500, response.getStatus()); response = target.request(MediaType.APPLICATION_JSON).post(Entity.entity(scheduledTask, MediaType.APPLICATION_JSON), Response.class); assertEquals(404, response.getStatus()); response = target.request(MediaType.APPLICATION_JSON).post(Entity.entity(scheduledTask, MediaType.APPLICATION_JSON), Response.class); assertEquals(406, response.getStatus()); calendar.add(Calendar.MONTH, 1); scheduledTask.setFirstRun(calendar); response = target.request(MediaType.APPLICATION_JSON).post(Entity.entity(scheduledTask, MediaType.APPLICATION_JSON), Response.class); assertEquals(406, response.getStatus()); scheduledTask.setFrequency(Frequency.XMONTHLY); scheduledTask.setXmonths(null); response = target.request(MediaType.APPLICATION_JSON).post(Entity.entity(scheduledTask, MediaType.APPLICATION_JSON), Response.class); assertEquals(406, response.getStatus()); scheduledTask.setFrequency(Frequency.ONCE); DataSource dataSource = mock(DataSource.class); defaultDataSourceContainer.setDataSource(dataSource); when(dataSource.getNewTaskId()).thenThrow(new IOException()).thenReturn("TaskId"); response = target.request(MediaType.APPLICATION_XML).post(Entity.entity(scheduledTask, MediaType.APPLICATION_XML), Response.class); assertEquals(500, response.getStatus()); when(dataSource.getId()).thenReturn(datasetId); when(taskManager.taskAlreadyExists(datasetId, DateUtil.date2String(scheduledTask.getFirstRun().getTime(), TimeUtil.LONG_DATE_FORMAT_NO_SECS), scheduledTask.getFrequency())) .thenReturn(true).thenReturn(false); response = target.request(MediaType.APPLICATION_JSON).post(Entity.entity(scheduledTask, MediaType.APPLICATION_JSON), Response.class); assertEquals(409, response.getStatus()); response = target.request(MediaType.APPLICATION_XML).post(Entity.entity(scheduledTask, MediaType.APPLICATION_XML), Response.class); assertEquals(201, response.getStatus()); }
@POST @Path("/" + DatasetOptionListContainer.DATASETID + "/" + HarvestOptionListContainer.HARVEST + "/" + HarvestOptionListContainer.SCHEDULE) @Consumes({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML }) @Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML }) @ApiOperation(value = "Schedules an automatic harvesting.", httpMethod = "POST", response = String.class) @ApiResponses(value = { @ApiResponse(code = 201, message = "Created (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") }) public Response scheduleHarvest(@ApiParam(value = "Id of dataset", required = true) @PathParam("datasetId") String datasetId, @ApiParam(value = "Task", required = true) Task task, @ApiParam(value = "true|false") @DefaultValue("false") @QueryParam("incremental") boolean incremental) throws MissingArgumentsException, DoesNotExistException, AlreadyExistsException { DataSourceContainer dataSourceContainer; try { dataSourceContainer = dataManager.getDataSourceContainer(datasetId); } catch (DocumentException | IOException e) { throw new InternalServerErrorException("Error in server : " + e.getMessage()); } if (dataSourceContainer != null) { DataSource dataSource = dataSourceContainer.getDataSource(); if (task instanceof ScheduledTask) { ScheduledTask scheduledTask = (ScheduledTask)task; Calendar firstRun = scheduledTask.getFirstRun(); Frequency frequency = scheduledTask.getFrequency(); String xmonths = ""; if (scheduledTask.getXmonths() != null) xmonths = Integer.toString(scheduledTask.getXmonths()); if (firstRun == null) throw new MissingArgumentsException("Missing value: " + "Date or are time must not be empty"); else if (frequency == null) throw new MissingArgumentsException("Missing value: " + "frequency must not be empty"); else if ((frequency == Frequency.XMONTHLY) && (xmonths == null || xmonths.isEmpty())) throw new MissingArgumentsException("Missing value: " + "xmonths must not be empty"); String newTaskId; try { newTaskId = dataSource.getNewTaskId(); scheduledTask.setId(newTaskId); } catch (IOException e) { throw new InternalServerErrorException("Error in server : " + e.getMessage()); } scheduledTask.setTaskClass(IngestDataSource.class); String[] parameters = new String[] { newTaskId, dataSource.getId(), (Boolean.valueOf(!incremental)).toString() }; scheduledTask.setParameters(parameters); try { if (taskManager.taskAlreadyExists(dataSource.getId(), DateUtil.date2String(scheduledTask.getFirstRun().getTime(), TimeUtil.LONG_DATE_FORMAT_NO_SECS), scheduledTask.getFrequency())) { throw new AlreadyExistsException("Already exists: " + "Task already exists!"); } else { dataSource.setMaxRecord4Sample(-1); dataManager.setDataSetSampleState(false, dataSource); taskManager.saveTask(scheduledTask); } } catch (IOException e) { throw new InternalServerErrorException("Error in server : " + e.getMessage()); } return Response.status(201).entity(new Result("Task for dataset with id '" + datasetId + "' created!")).build(); } else return Response.status(500).entity(new Result("Invalid task instance in body!")).build(); } else throw new DoesNotExistException("Dataset with id " + datasetId + " does NOT exist!"); }
HarvestResource { @POST @Path("/" + DatasetOptionListContainer.DATASETID + "/" + HarvestOptionListContainer.HARVEST + "/" + HarvestOptionListContainer.SCHEDULE) @Consumes({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML }) @Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML }) @ApiOperation(value = "Schedules an automatic harvesting.", httpMethod = "POST", response = String.class) @ApiResponses(value = { @ApiResponse(code = 201, message = "Created (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") }) public Response scheduleHarvest(@ApiParam(value = "Id of dataset", required = true) @PathParam("datasetId") String datasetId, @ApiParam(value = "Task", required = true) Task task, @ApiParam(value = "true|false") @DefaultValue("false") @QueryParam("incremental") boolean incremental) throws MissingArgumentsException, DoesNotExistException, AlreadyExistsException { DataSourceContainer dataSourceContainer; try { dataSourceContainer = dataManager.getDataSourceContainer(datasetId); } catch (DocumentException | IOException e) { throw new InternalServerErrorException("Error in server : " + e.getMessage()); } if (dataSourceContainer != null) { DataSource dataSource = dataSourceContainer.getDataSource(); if (task instanceof ScheduledTask) { ScheduledTask scheduledTask = (ScheduledTask)task; Calendar firstRun = scheduledTask.getFirstRun(); Frequency frequency = scheduledTask.getFrequency(); String xmonths = ""; if (scheduledTask.getXmonths() != null) xmonths = Integer.toString(scheduledTask.getXmonths()); if (firstRun == null) throw new MissingArgumentsException("Missing value: " + "Date or are time must not be empty"); else if (frequency == null) throw new MissingArgumentsException("Missing value: " + "frequency must not be empty"); else if ((frequency == Frequency.XMONTHLY) && (xmonths == null || xmonths.isEmpty())) throw new MissingArgumentsException("Missing value: " + "xmonths must not be empty"); String newTaskId; try { newTaskId = dataSource.getNewTaskId(); scheduledTask.setId(newTaskId); } catch (IOException e) { throw new InternalServerErrorException("Error in server : " + e.getMessage()); } scheduledTask.setTaskClass(IngestDataSource.class); String[] parameters = new String[] { newTaskId, dataSource.getId(), (Boolean.valueOf(!incremental)).toString() }; scheduledTask.setParameters(parameters); try { if (taskManager.taskAlreadyExists(dataSource.getId(), DateUtil.date2String(scheduledTask.getFirstRun().getTime(), TimeUtil.LONG_DATE_FORMAT_NO_SECS), scheduledTask.getFrequency())) { throw new AlreadyExistsException("Already exists: " + "Task already exists!"); } else { dataSource.setMaxRecord4Sample(-1); dataManager.setDataSetSampleState(false, dataSource); taskManager.saveTask(scheduledTask); } } catch (IOException e) { throw new InternalServerErrorException("Error in server : " + e.getMessage()); } return Response.status(201).entity(new Result("Task for dataset with id '" + datasetId + "' created!")).build(); } else return Response.status(500).entity(new Result("Invalid task instance in body!")).build(); } else throw new DoesNotExistException("Dataset with id " + datasetId + " does NOT exist!"); } }
HarvestResource { @POST @Path("/" + DatasetOptionListContainer.DATASETID + "/" + HarvestOptionListContainer.HARVEST + "/" + HarvestOptionListContainer.SCHEDULE) @Consumes({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML }) @Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML }) @ApiOperation(value = "Schedules an automatic harvesting.", httpMethod = "POST", response = String.class) @ApiResponses(value = { @ApiResponse(code = 201, message = "Created (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") }) public Response scheduleHarvest(@ApiParam(value = "Id of dataset", required = true) @PathParam("datasetId") String datasetId, @ApiParam(value = "Task", required = true) Task task, @ApiParam(value = "true|false") @DefaultValue("false") @QueryParam("incremental") boolean incremental) throws MissingArgumentsException, DoesNotExistException, AlreadyExistsException { DataSourceContainer dataSourceContainer; try { dataSourceContainer = dataManager.getDataSourceContainer(datasetId); } catch (DocumentException | IOException e) { throw new InternalServerErrorException("Error in server : " + e.getMessage()); } if (dataSourceContainer != null) { DataSource dataSource = dataSourceContainer.getDataSource(); if (task instanceof ScheduledTask) { ScheduledTask scheduledTask = (ScheduledTask)task; Calendar firstRun = scheduledTask.getFirstRun(); Frequency frequency = scheduledTask.getFrequency(); String xmonths = ""; if (scheduledTask.getXmonths() != null) xmonths = Integer.toString(scheduledTask.getXmonths()); if (firstRun == null) throw new MissingArgumentsException("Missing value: " + "Date or are time must not be empty"); else if (frequency == null) throw new MissingArgumentsException("Missing value: " + "frequency must not be empty"); else if ((frequency == Frequency.XMONTHLY) && (xmonths == null || xmonths.isEmpty())) throw new MissingArgumentsException("Missing value: " + "xmonths must not be empty"); String newTaskId; try { newTaskId = dataSource.getNewTaskId(); scheduledTask.setId(newTaskId); } catch (IOException e) { throw new InternalServerErrorException("Error in server : " + e.getMessage()); } scheduledTask.setTaskClass(IngestDataSource.class); String[] parameters = new String[] { newTaskId, dataSource.getId(), (Boolean.valueOf(!incremental)).toString() }; scheduledTask.setParameters(parameters); try { if (taskManager.taskAlreadyExists(dataSource.getId(), DateUtil.date2String(scheduledTask.getFirstRun().getTime(), TimeUtil.LONG_DATE_FORMAT_NO_SECS), scheduledTask.getFrequency())) { throw new AlreadyExistsException("Already exists: " + "Task already exists!"); } else { dataSource.setMaxRecord4Sample(-1); dataManager.setDataSetSampleState(false, dataSource); taskManager.saveTask(scheduledTask); } } catch (IOException e) { throw new InternalServerErrorException("Error in server : " + e.getMessage()); } return Response.status(201).entity(new Result("Task for dataset with id '" + datasetId + "' created!")).build(); } else return Response.status(500).entity(new Result("Invalid task instance in body!")).build(); } else throw new DoesNotExistException("Dataset with id " + datasetId + " does NOT exist!"); } HarvestResource();  HarvestResource(DefaultDataManager dataManager, TaskManager taskManager); }
HarvestResource { @POST @Path("/" + DatasetOptionListContainer.DATASETID + "/" + HarvestOptionListContainer.HARVEST + "/" + HarvestOptionListContainer.SCHEDULE) @Consumes({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML }) @Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML }) @ApiOperation(value = "Schedules an automatic harvesting.", httpMethod = "POST", response = String.class) @ApiResponses(value = { @ApiResponse(code = 201, message = "Created (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") }) public Response scheduleHarvest(@ApiParam(value = "Id of dataset", required = true) @PathParam("datasetId") String datasetId, @ApiParam(value = "Task", required = true) Task task, @ApiParam(value = "true|false") @DefaultValue("false") @QueryParam("incremental") boolean incremental) throws MissingArgumentsException, DoesNotExistException, AlreadyExistsException { DataSourceContainer dataSourceContainer; try { dataSourceContainer = dataManager.getDataSourceContainer(datasetId); } catch (DocumentException | IOException e) { throw new InternalServerErrorException("Error in server : " + e.getMessage()); } if (dataSourceContainer != null) { DataSource dataSource = dataSourceContainer.getDataSource(); if (task instanceof ScheduledTask) { ScheduledTask scheduledTask = (ScheduledTask)task; Calendar firstRun = scheduledTask.getFirstRun(); Frequency frequency = scheduledTask.getFrequency(); String xmonths = ""; if (scheduledTask.getXmonths() != null) xmonths = Integer.toString(scheduledTask.getXmonths()); if (firstRun == null) throw new MissingArgumentsException("Missing value: " + "Date or are time must not be empty"); else if (frequency == null) throw new MissingArgumentsException("Missing value: " + "frequency must not be empty"); else if ((frequency == Frequency.XMONTHLY) && (xmonths == null || xmonths.isEmpty())) throw new MissingArgumentsException("Missing value: " + "xmonths must not be empty"); String newTaskId; try { newTaskId = dataSource.getNewTaskId(); scheduledTask.setId(newTaskId); } catch (IOException e) { throw new InternalServerErrorException("Error in server : " + e.getMessage()); } scheduledTask.setTaskClass(IngestDataSource.class); String[] parameters = new String[] { newTaskId, dataSource.getId(), (Boolean.valueOf(!incremental)).toString() }; scheduledTask.setParameters(parameters); try { if (taskManager.taskAlreadyExists(dataSource.getId(), DateUtil.date2String(scheduledTask.getFirstRun().getTime(), TimeUtil.LONG_DATE_FORMAT_NO_SECS), scheduledTask.getFrequency())) { throw new AlreadyExistsException("Already exists: " + "Task already exists!"); } else { dataSource.setMaxRecord4Sample(-1); dataManager.setDataSetSampleState(false, dataSource); taskManager.saveTask(scheduledTask); } } catch (IOException e) { throw new InternalServerErrorException("Error in server : " + e.getMessage()); } return Response.status(201).entity(new Result("Task for dataset with id '" + datasetId + "' created!")).build(); } else return Response.status(500).entity(new Result("Invalid task instance in body!")).build(); } else throw new DoesNotExistException("Dataset with id " + datasetId + " does NOT exist!"); } HarvestResource();  HarvestResource(DefaultDataManager dataManager, TaskManager taskManager); @OPTIONS @Path("/" + HarvestOptionListContainer.HARVEST) @Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML }) @ApiOperation(value = "Get options over harvest conext.", httpMethod = "OPTIONS", response = HarvestOptionListContainer.class) @ApiResponses(value = { @ApiResponse(code = 200, message = "OK (Response containing a list of all available options)") }) HarvestOptionListContainer getOptions(); @GET @Path("/" + HarvestOptionListContainer.HARVEST + "/" + HarvestOptionListContainer.OPTIONS) @Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML }) @ApiOperation(value = "Get options over harvest conext.", httpMethod = "GET", response = HarvestOptionListContainer.class) @ApiResponses(value = { @ApiResponse(code = 200, message = "OK (Response containing a list of all available options)") }) HarvestOptionListContainer getGETOptions(); @POST @Path("/" + DatasetOptionListContainer.DATASETID + "/" + HarvestOptionListContainer.HARVEST + "/" + HarvestOptionListContainer.START) @Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML }) @ApiOperation(value = "Initiate a new harvest.", 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 startHarvest(
            @ApiParam(value = "Id of dataset", required = true) @PathParam("datasetId") String datasetId,
            @ApiParam(value = "full|sample", defaultValue = HarvestOptionListContainer.SAMPLE, allowableValues = HarvestOptionListContainer.SAMPLE + " , " + HarvestOptionListContainer.FULL) @DefaultValue(HarvestOptionListContainer.SAMPLE) @QueryParam("type") String type); @DELETE @Path("/" + DatasetOptionListContainer.DATASETID + "/" + HarvestOptionListContainer.HARVEST + "/" + HarvestOptionListContainer.CANCEL) @Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML }) @ApiOperation(value = "Cancels a harvesting ingest.", 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 cancelHarvest(@ApiParam(value = "Id of dataset", required = true) @PathParam("datasetId") String datasetId); @POST @Path("/" + DatasetOptionListContainer.DATASETID + "/" + HarvestOptionListContainer.HARVEST + "/" + HarvestOptionListContainer.SCHEDULE) @Consumes({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML }) @Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML }) @ApiOperation(value = "Schedules an automatic harvesting.", httpMethod = "POST", response = String.class) @ApiResponses(value = { @ApiResponse(code = 201, message = "Created (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 scheduleHarvest(@ApiParam(value = "Id of dataset", required = true) @PathParam("datasetId") String datasetId, @ApiParam(value = "Task", required = true) Task task,
            @ApiParam(value = "true|false") @DefaultValue("false") @QueryParam("incremental") boolean incremental); @GET @Path("/" + DatasetOptionListContainer.DATASETID + "/" + HarvestOptionListContainer.HARVEST + "/" + HarvestOptionListContainer.SCHEDULES) @Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML }) @ApiOperation(value = "Retrieves the list of schedules.", httpMethod = "GET", response = ScheduledTask.class, responseContainer = "List") @ApiResponses(value = { @ApiResponse(code = 200, message = "OK (Response containing an Dataset)"), @ApiResponse(code = 404, message = "DoesNotExistException"), @ApiResponse(code = 500, message = "InternalServerErrorException") }) Response getDatasetScheduledTasks(@ApiParam(value = "Id of dataset", required = true) @PathParam("datasetId") String datasetId); @DELETE @Path("/" + DatasetOptionListContainer.DATASETID + "/" + HarvestOptionListContainer.HARVEST + "/" + HarvestOptionListContainer.SCHEDULES + "/" + HarvestOptionListContainer.TASKID) @Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML }) @ApiOperation(value = "Deletes an automatic harvesting.", 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 deleteScheduledTask(@ApiParam(value = "Id of dataset", required = true) @PathParam("datasetId") String datasetId,
            @ApiParam(value = "Id of task", required = true) @PathParam("taskId") String taskId); @GET @Path("/" + DatasetOptionListContainer.DATASETID + "/" + HarvestOptionListContainer.HARVEST + "/" + HarvestOptionListContainer.STATUS) @Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML }) @ApiOperation(value = "Gets the status of a specific dataset harvesting.", httpMethod = "GET", response = String.class) @ApiResponses(value = { @ApiResponse(code = 200, message = "OK (Response containing an Dataset)"), @ApiResponse(code = 404, message = "DoesNotExistException"), @ApiResponse(code = 500, message = "InternalServerErrorException") }) Response getDatasetHarvestingStatus(@ApiParam(value = "Id of dataset", required = true) @PathParam("datasetId") String datasetId); @GET @Path("/" + DatasetOptionListContainer.DATASETID + "/" + HarvestOptionListContainer.HARVEST + "/" + HarvestOptionListContainer.LOG) @Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML }) @ApiOperation(value = "Gets the logs of the last ingest.", httpMethod = "GET", response = String.class) @ApiResponses(value = { @ApiResponse(code = 200, message = "OK (Response containing an Dataset)"), @ApiResponse(code = 404, message = "DoesNotExistException"), @ApiResponse(code = 500, message = "InternalServerErrorException") }) Response getDatasetLastIngestLog(@ApiParam(value = "Id of dataset", required = true) @PathParam("datasetId") String datasetId); @GET @Path("/" + HarvestOptionListContainer.HARVESTS) @Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML }) @ApiOperation(value = "Gets a list of currently executing dataset harvests", httpMethod = "GET", response = Task.class, responseContainer = "List") @ApiResponses(value = { @ApiResponse(code = 200, message = "OK (Response containing an Dataset)"), // @ApiResponse(code = 404, message = "DoesNotExistException") }) Response getCurrentHarvestsList(); }
HarvestResource { @POST @Path("/" + DatasetOptionListContainer.DATASETID + "/" + HarvestOptionListContainer.HARVEST + "/" + HarvestOptionListContainer.SCHEDULE) @Consumes({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML }) @Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML }) @ApiOperation(value = "Schedules an automatic harvesting.", httpMethod = "POST", response = String.class) @ApiResponses(value = { @ApiResponse(code = 201, message = "Created (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") }) public Response scheduleHarvest(@ApiParam(value = "Id of dataset", required = true) @PathParam("datasetId") String datasetId, @ApiParam(value = "Task", required = true) Task task, @ApiParam(value = "true|false") @DefaultValue("false") @QueryParam("incremental") boolean incremental) throws MissingArgumentsException, DoesNotExistException, AlreadyExistsException { DataSourceContainer dataSourceContainer; try { dataSourceContainer = dataManager.getDataSourceContainer(datasetId); } catch (DocumentException | IOException e) { throw new InternalServerErrorException("Error in server : " + e.getMessage()); } if (dataSourceContainer != null) { DataSource dataSource = dataSourceContainer.getDataSource(); if (task instanceof ScheduledTask) { ScheduledTask scheduledTask = (ScheduledTask)task; Calendar firstRun = scheduledTask.getFirstRun(); Frequency frequency = scheduledTask.getFrequency(); String xmonths = ""; if (scheduledTask.getXmonths() != null) xmonths = Integer.toString(scheduledTask.getXmonths()); if (firstRun == null) throw new MissingArgumentsException("Missing value: " + "Date or are time must not be empty"); else if (frequency == null) throw new MissingArgumentsException("Missing value: " + "frequency must not be empty"); else if ((frequency == Frequency.XMONTHLY) && (xmonths == null || xmonths.isEmpty())) throw new MissingArgumentsException("Missing value: " + "xmonths must not be empty"); String newTaskId; try { newTaskId = dataSource.getNewTaskId(); scheduledTask.setId(newTaskId); } catch (IOException e) { throw new InternalServerErrorException("Error in server : " + e.getMessage()); } scheduledTask.setTaskClass(IngestDataSource.class); String[] parameters = new String[] { newTaskId, dataSource.getId(), (Boolean.valueOf(!incremental)).toString() }; scheduledTask.setParameters(parameters); try { if (taskManager.taskAlreadyExists(dataSource.getId(), DateUtil.date2String(scheduledTask.getFirstRun().getTime(), TimeUtil.LONG_DATE_FORMAT_NO_SECS), scheduledTask.getFrequency())) { throw new AlreadyExistsException("Already exists: " + "Task already exists!"); } else { dataSource.setMaxRecord4Sample(-1); dataManager.setDataSetSampleState(false, dataSource); taskManager.saveTask(scheduledTask); } } catch (IOException e) { throw new InternalServerErrorException("Error in server : " + e.getMessage()); } return Response.status(201).entity(new Result("Task for dataset with id '" + datasetId + "' created!")).build(); } else return Response.status(500).entity(new Result("Invalid task instance in body!")).build(); } else throw new DoesNotExistException("Dataset with id " + datasetId + " does NOT exist!"); } HarvestResource();  HarvestResource(DefaultDataManager dataManager, TaskManager taskManager); @OPTIONS @Path("/" + HarvestOptionListContainer.HARVEST) @Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML }) @ApiOperation(value = "Get options over harvest conext.", httpMethod = "OPTIONS", response = HarvestOptionListContainer.class) @ApiResponses(value = { @ApiResponse(code = 200, message = "OK (Response containing a list of all available options)") }) HarvestOptionListContainer getOptions(); @GET @Path("/" + HarvestOptionListContainer.HARVEST + "/" + HarvestOptionListContainer.OPTIONS) @Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML }) @ApiOperation(value = "Get options over harvest conext.", httpMethod = "GET", response = HarvestOptionListContainer.class) @ApiResponses(value = { @ApiResponse(code = 200, message = "OK (Response containing a list of all available options)") }) HarvestOptionListContainer getGETOptions(); @POST @Path("/" + DatasetOptionListContainer.DATASETID + "/" + HarvestOptionListContainer.HARVEST + "/" + HarvestOptionListContainer.START) @Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML }) @ApiOperation(value = "Initiate a new harvest.", 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 startHarvest(
            @ApiParam(value = "Id of dataset", required = true) @PathParam("datasetId") String datasetId,
            @ApiParam(value = "full|sample", defaultValue = HarvestOptionListContainer.SAMPLE, allowableValues = HarvestOptionListContainer.SAMPLE + " , " + HarvestOptionListContainer.FULL) @DefaultValue(HarvestOptionListContainer.SAMPLE) @QueryParam("type") String type); @DELETE @Path("/" + DatasetOptionListContainer.DATASETID + "/" + HarvestOptionListContainer.HARVEST + "/" + HarvestOptionListContainer.CANCEL) @Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML }) @ApiOperation(value = "Cancels a harvesting ingest.", 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 cancelHarvest(@ApiParam(value = "Id of dataset", required = true) @PathParam("datasetId") String datasetId); @POST @Path("/" + DatasetOptionListContainer.DATASETID + "/" + HarvestOptionListContainer.HARVEST + "/" + HarvestOptionListContainer.SCHEDULE) @Consumes({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML }) @Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML }) @ApiOperation(value = "Schedules an automatic harvesting.", httpMethod = "POST", response = String.class) @ApiResponses(value = { @ApiResponse(code = 201, message = "Created (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 scheduleHarvest(@ApiParam(value = "Id of dataset", required = true) @PathParam("datasetId") String datasetId, @ApiParam(value = "Task", required = true) Task task,
            @ApiParam(value = "true|false") @DefaultValue("false") @QueryParam("incremental") boolean incremental); @GET @Path("/" + DatasetOptionListContainer.DATASETID + "/" + HarvestOptionListContainer.HARVEST + "/" + HarvestOptionListContainer.SCHEDULES) @Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML }) @ApiOperation(value = "Retrieves the list of schedules.", httpMethod = "GET", response = ScheduledTask.class, responseContainer = "List") @ApiResponses(value = { @ApiResponse(code = 200, message = "OK (Response containing an Dataset)"), @ApiResponse(code = 404, message = "DoesNotExistException"), @ApiResponse(code = 500, message = "InternalServerErrorException") }) Response getDatasetScheduledTasks(@ApiParam(value = "Id of dataset", required = true) @PathParam("datasetId") String datasetId); @DELETE @Path("/" + DatasetOptionListContainer.DATASETID + "/" + HarvestOptionListContainer.HARVEST + "/" + HarvestOptionListContainer.SCHEDULES + "/" + HarvestOptionListContainer.TASKID) @Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML }) @ApiOperation(value = "Deletes an automatic harvesting.", 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 deleteScheduledTask(@ApiParam(value = "Id of dataset", required = true) @PathParam("datasetId") String datasetId,
            @ApiParam(value = "Id of task", required = true) @PathParam("taskId") String taskId); @GET @Path("/" + DatasetOptionListContainer.DATASETID + "/" + HarvestOptionListContainer.HARVEST + "/" + HarvestOptionListContainer.STATUS) @Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML }) @ApiOperation(value = "Gets the status of a specific dataset harvesting.", httpMethod = "GET", response = String.class) @ApiResponses(value = { @ApiResponse(code = 200, message = "OK (Response containing an Dataset)"), @ApiResponse(code = 404, message = "DoesNotExistException"), @ApiResponse(code = 500, message = "InternalServerErrorException") }) Response getDatasetHarvestingStatus(@ApiParam(value = "Id of dataset", required = true) @PathParam("datasetId") String datasetId); @GET @Path("/" + DatasetOptionListContainer.DATASETID + "/" + HarvestOptionListContainer.HARVEST + "/" + HarvestOptionListContainer.LOG) @Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML }) @ApiOperation(value = "Gets the logs of the last ingest.", httpMethod = "GET", response = String.class) @ApiResponses(value = { @ApiResponse(code = 200, message = "OK (Response containing an Dataset)"), @ApiResponse(code = 404, message = "DoesNotExistException"), @ApiResponse(code = 500, message = "InternalServerErrorException") }) Response getDatasetLastIngestLog(@ApiParam(value = "Id of dataset", required = true) @PathParam("datasetId") String datasetId); @GET @Path("/" + HarvestOptionListContainer.HARVESTS) @Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML }) @ApiOperation(value = "Gets a list of currently executing dataset harvests", httpMethod = "GET", response = Task.class, responseContainer = "List") @ApiResponses(value = { @ApiResponse(code = 200, message = "OK (Response containing an Dataset)"), // @ApiResponse(code = 404, message = "DoesNotExistException") }) Response getCurrentHarvestsList(); public DefaultDataManager dataManager; public TaskManager taskManager; }