target
stringlengths 20
113k
| src_fm
stringlengths 11
86.3k
| src_fm_fc
stringlengths 21
86.4k
| src_fm_fc_co
stringlengths 30
86.4k
| src_fm_fc_ms
stringlengths 42
86.8k
| src_fm_fc_ms_ff
stringlengths 43
86.8k
|
---|---|---|---|---|---|
@Test public void shouldProvideSubmitterForHttpTopology() { TaskSubmitter taskSubmitter = new TaskSubmitterFactory( Mockito.mock(OaiTopologyTaskSubmitter.class), Mockito.mock(HttpTopologyTaskSubmitter.class), Mockito.mock(OtherTopologiesTaskSubmitter.class), Mockito.mock(DepublicationTaskSubmitter.class) ).provideTaskSubmitter( SubmitTaskParameters.builder().topologyName(TopologiesNames.HTTP_TOPOLOGY).build()); assertTrue(taskSubmitter instanceof HttpTopologyTaskSubmitter); } | public TaskSubmitter provideTaskSubmitter(SubmitTaskParameters parameters) { switch (parameters.getTopologyName()) { case TopologiesNames.OAI_TOPOLOGY: return oaiTopologyTaskSubmitter; case TopologiesNames.HTTP_TOPOLOGY: return httpTopologyTaskSubmitter; case TopologiesNames.ENRICHMENT_TOPOLOGY: case TopologiesNames.INDEXING_TOPOLOGY: case TopologiesNames.LINKCHECK_TOPOLOGY: case TopologiesNames.MEDIA_TOPOLOGY: case TopologiesNames.NORMALIZATION_TOPOLOGY: case TopologiesNames.VALIDATION_TOPOLOGY: case TopologiesNames.XSLT_TOPOLOGY: return otherTopologiesTaskSubmitter; case TopologiesNames.DEPUBLICATION_TOPOLOGY: return depublicationTaskSubmitter; default: throw new IllegalArgumentException("Unable to find the TaskSubmitter for the given topology name: " + parameters.getTopologyName()); } } | TaskSubmitterFactory { public TaskSubmitter provideTaskSubmitter(SubmitTaskParameters parameters) { switch (parameters.getTopologyName()) { case TopologiesNames.OAI_TOPOLOGY: return oaiTopologyTaskSubmitter; case TopologiesNames.HTTP_TOPOLOGY: return httpTopologyTaskSubmitter; case TopologiesNames.ENRICHMENT_TOPOLOGY: case TopologiesNames.INDEXING_TOPOLOGY: case TopologiesNames.LINKCHECK_TOPOLOGY: case TopologiesNames.MEDIA_TOPOLOGY: case TopologiesNames.NORMALIZATION_TOPOLOGY: case TopologiesNames.VALIDATION_TOPOLOGY: case TopologiesNames.XSLT_TOPOLOGY: return otherTopologiesTaskSubmitter; case TopologiesNames.DEPUBLICATION_TOPOLOGY: return depublicationTaskSubmitter; default: throw new IllegalArgumentException("Unable to find the TaskSubmitter for the given topology name: " + parameters.getTopologyName()); } } } | TaskSubmitterFactory { public TaskSubmitter provideTaskSubmitter(SubmitTaskParameters parameters) { switch (parameters.getTopologyName()) { case TopologiesNames.OAI_TOPOLOGY: return oaiTopologyTaskSubmitter; case TopologiesNames.HTTP_TOPOLOGY: return httpTopologyTaskSubmitter; case TopologiesNames.ENRICHMENT_TOPOLOGY: case TopologiesNames.INDEXING_TOPOLOGY: case TopologiesNames.LINKCHECK_TOPOLOGY: case TopologiesNames.MEDIA_TOPOLOGY: case TopologiesNames.NORMALIZATION_TOPOLOGY: case TopologiesNames.VALIDATION_TOPOLOGY: case TopologiesNames.XSLT_TOPOLOGY: return otherTopologiesTaskSubmitter; case TopologiesNames.DEPUBLICATION_TOPOLOGY: return depublicationTaskSubmitter; default: throw new IllegalArgumentException("Unable to find the TaskSubmitter for the given topology name: " + parameters.getTopologyName()); } } TaskSubmitterFactory(OaiTopologyTaskSubmitter oaiTopologyTaskSubmitter,
HttpTopologyTaskSubmitter httpTopologyTaskSubmitter,
OtherTopologiesTaskSubmitter otherTopologiesTaskSubmitter,
TaskSubmitter depublicationTaskSubmitter); } | TaskSubmitterFactory { public TaskSubmitter provideTaskSubmitter(SubmitTaskParameters parameters) { switch (parameters.getTopologyName()) { case TopologiesNames.OAI_TOPOLOGY: return oaiTopologyTaskSubmitter; case TopologiesNames.HTTP_TOPOLOGY: return httpTopologyTaskSubmitter; case TopologiesNames.ENRICHMENT_TOPOLOGY: case TopologiesNames.INDEXING_TOPOLOGY: case TopologiesNames.LINKCHECK_TOPOLOGY: case TopologiesNames.MEDIA_TOPOLOGY: case TopologiesNames.NORMALIZATION_TOPOLOGY: case TopologiesNames.VALIDATION_TOPOLOGY: case TopologiesNames.XSLT_TOPOLOGY: return otherTopologiesTaskSubmitter; case TopologiesNames.DEPUBLICATION_TOPOLOGY: return depublicationTaskSubmitter; default: throw new IllegalArgumentException("Unable to find the TaskSubmitter for the given topology name: " + parameters.getTopologyName()); } } TaskSubmitterFactory(OaiTopologyTaskSubmitter oaiTopologyTaskSubmitter,
HttpTopologyTaskSubmitter httpTopologyTaskSubmitter,
OtherTopologiesTaskSubmitter otherTopologiesTaskSubmitter,
TaskSubmitter depublicationTaskSubmitter); TaskSubmitter provideTaskSubmitter(SubmitTaskParameters parameters); } | TaskSubmitterFactory { public TaskSubmitter provideTaskSubmitter(SubmitTaskParameters parameters) { switch (parameters.getTopologyName()) { case TopologiesNames.OAI_TOPOLOGY: return oaiTopologyTaskSubmitter; case TopologiesNames.HTTP_TOPOLOGY: return httpTopologyTaskSubmitter; case TopologiesNames.ENRICHMENT_TOPOLOGY: case TopologiesNames.INDEXING_TOPOLOGY: case TopologiesNames.LINKCHECK_TOPOLOGY: case TopologiesNames.MEDIA_TOPOLOGY: case TopologiesNames.NORMALIZATION_TOPOLOGY: case TopologiesNames.VALIDATION_TOPOLOGY: case TopologiesNames.XSLT_TOPOLOGY: return otherTopologiesTaskSubmitter; case TopologiesNames.DEPUBLICATION_TOPOLOGY: return depublicationTaskSubmitter; default: throw new IllegalArgumentException("Unable to find the TaskSubmitter for the given topology name: " + parameters.getTopologyName()); } } TaskSubmitterFactory(OaiTopologyTaskSubmitter oaiTopologyTaskSubmitter,
HttpTopologyTaskSubmitter httpTopologyTaskSubmitter,
OtherTopologiesTaskSubmitter otherTopologiesTaskSubmitter,
TaskSubmitter depublicationTaskSubmitter); TaskSubmitter provideTaskSubmitter(SubmitTaskParameters parameters); } |
@Test public void shouldProvideSubmitterForOtherTopologies() { TaskSubmitterFactory taskSubmitterFactory = new TaskSubmitterFactory( Mockito.mock(OaiTopologyTaskSubmitter.class), Mockito.mock(HttpTopologyTaskSubmitter.class), Mockito.mock(OtherTopologiesTaskSubmitter.class), Mockito.mock(DepublicationTaskSubmitter.class) ); assertTrue(taskSubmitterFactory.provideTaskSubmitter( SubmitTaskParameters .builder() .topologyName(TopologiesNames.VALIDATION_TOPOLOGY) .build() ) instanceof OtherTopologiesTaskSubmitter); assertTrue(taskSubmitterFactory.provideTaskSubmitter( SubmitTaskParameters .builder() .topologyName(TopologiesNames.INDEXING_TOPOLOGY) .build() ) instanceof OtherTopologiesTaskSubmitter); assertTrue(taskSubmitterFactory.provideTaskSubmitter( SubmitTaskParameters .builder() .topologyName(TopologiesNames.ENRICHMENT_TOPOLOGY) .build() ) instanceof OtherTopologiesTaskSubmitter); assertTrue(taskSubmitterFactory.provideTaskSubmitter( SubmitTaskParameters .builder() .topologyName(TopologiesNames.NORMALIZATION_TOPOLOGY) .build() ) instanceof OtherTopologiesTaskSubmitter); assertTrue(taskSubmitterFactory.provideTaskSubmitter( SubmitTaskParameters .builder() .topologyName(TopologiesNames.LINKCHECK_TOPOLOGY) .build() ) instanceof OtherTopologiesTaskSubmitter); assertTrue(taskSubmitterFactory.provideTaskSubmitter( SubmitTaskParameters .builder() .topologyName(TopologiesNames.MEDIA_TOPOLOGY) .build() ) instanceof OtherTopologiesTaskSubmitter); assertTrue(taskSubmitterFactory.provideTaskSubmitter( SubmitTaskParameters .builder() .topologyName(TopologiesNames.XSLT_TOPOLOGY) .build() ) instanceof OtherTopologiesTaskSubmitter); } | public TaskSubmitter provideTaskSubmitter(SubmitTaskParameters parameters) { switch (parameters.getTopologyName()) { case TopologiesNames.OAI_TOPOLOGY: return oaiTopologyTaskSubmitter; case TopologiesNames.HTTP_TOPOLOGY: return httpTopologyTaskSubmitter; case TopologiesNames.ENRICHMENT_TOPOLOGY: case TopologiesNames.INDEXING_TOPOLOGY: case TopologiesNames.LINKCHECK_TOPOLOGY: case TopologiesNames.MEDIA_TOPOLOGY: case TopologiesNames.NORMALIZATION_TOPOLOGY: case TopologiesNames.VALIDATION_TOPOLOGY: case TopologiesNames.XSLT_TOPOLOGY: return otherTopologiesTaskSubmitter; case TopologiesNames.DEPUBLICATION_TOPOLOGY: return depublicationTaskSubmitter; default: throw new IllegalArgumentException("Unable to find the TaskSubmitter for the given topology name: " + parameters.getTopologyName()); } } | TaskSubmitterFactory { public TaskSubmitter provideTaskSubmitter(SubmitTaskParameters parameters) { switch (parameters.getTopologyName()) { case TopologiesNames.OAI_TOPOLOGY: return oaiTopologyTaskSubmitter; case TopologiesNames.HTTP_TOPOLOGY: return httpTopologyTaskSubmitter; case TopologiesNames.ENRICHMENT_TOPOLOGY: case TopologiesNames.INDEXING_TOPOLOGY: case TopologiesNames.LINKCHECK_TOPOLOGY: case TopologiesNames.MEDIA_TOPOLOGY: case TopologiesNames.NORMALIZATION_TOPOLOGY: case TopologiesNames.VALIDATION_TOPOLOGY: case TopologiesNames.XSLT_TOPOLOGY: return otherTopologiesTaskSubmitter; case TopologiesNames.DEPUBLICATION_TOPOLOGY: return depublicationTaskSubmitter; default: throw new IllegalArgumentException("Unable to find the TaskSubmitter for the given topology name: " + parameters.getTopologyName()); } } } | TaskSubmitterFactory { public TaskSubmitter provideTaskSubmitter(SubmitTaskParameters parameters) { switch (parameters.getTopologyName()) { case TopologiesNames.OAI_TOPOLOGY: return oaiTopologyTaskSubmitter; case TopologiesNames.HTTP_TOPOLOGY: return httpTopologyTaskSubmitter; case TopologiesNames.ENRICHMENT_TOPOLOGY: case TopologiesNames.INDEXING_TOPOLOGY: case TopologiesNames.LINKCHECK_TOPOLOGY: case TopologiesNames.MEDIA_TOPOLOGY: case TopologiesNames.NORMALIZATION_TOPOLOGY: case TopologiesNames.VALIDATION_TOPOLOGY: case TopologiesNames.XSLT_TOPOLOGY: return otherTopologiesTaskSubmitter; case TopologiesNames.DEPUBLICATION_TOPOLOGY: return depublicationTaskSubmitter; default: throw new IllegalArgumentException("Unable to find the TaskSubmitter for the given topology name: " + parameters.getTopologyName()); } } TaskSubmitterFactory(OaiTopologyTaskSubmitter oaiTopologyTaskSubmitter,
HttpTopologyTaskSubmitter httpTopologyTaskSubmitter,
OtherTopologiesTaskSubmitter otherTopologiesTaskSubmitter,
TaskSubmitter depublicationTaskSubmitter); } | TaskSubmitterFactory { public TaskSubmitter provideTaskSubmitter(SubmitTaskParameters parameters) { switch (parameters.getTopologyName()) { case TopologiesNames.OAI_TOPOLOGY: return oaiTopologyTaskSubmitter; case TopologiesNames.HTTP_TOPOLOGY: return httpTopologyTaskSubmitter; case TopologiesNames.ENRICHMENT_TOPOLOGY: case TopologiesNames.INDEXING_TOPOLOGY: case TopologiesNames.LINKCHECK_TOPOLOGY: case TopologiesNames.MEDIA_TOPOLOGY: case TopologiesNames.NORMALIZATION_TOPOLOGY: case TopologiesNames.VALIDATION_TOPOLOGY: case TopologiesNames.XSLT_TOPOLOGY: return otherTopologiesTaskSubmitter; case TopologiesNames.DEPUBLICATION_TOPOLOGY: return depublicationTaskSubmitter; default: throw new IllegalArgumentException("Unable to find the TaskSubmitter for the given topology name: " + parameters.getTopologyName()); } } TaskSubmitterFactory(OaiTopologyTaskSubmitter oaiTopologyTaskSubmitter,
HttpTopologyTaskSubmitter httpTopologyTaskSubmitter,
OtherTopologiesTaskSubmitter otherTopologiesTaskSubmitter,
TaskSubmitter depublicationTaskSubmitter); TaskSubmitter provideTaskSubmitter(SubmitTaskParameters parameters); } | TaskSubmitterFactory { public TaskSubmitter provideTaskSubmitter(SubmitTaskParameters parameters) { switch (parameters.getTopologyName()) { case TopologiesNames.OAI_TOPOLOGY: return oaiTopologyTaskSubmitter; case TopologiesNames.HTTP_TOPOLOGY: return httpTopologyTaskSubmitter; case TopologiesNames.ENRICHMENT_TOPOLOGY: case TopologiesNames.INDEXING_TOPOLOGY: case TopologiesNames.LINKCHECK_TOPOLOGY: case TopologiesNames.MEDIA_TOPOLOGY: case TopologiesNames.NORMALIZATION_TOPOLOGY: case TopologiesNames.VALIDATION_TOPOLOGY: case TopologiesNames.XSLT_TOPOLOGY: return otherTopologiesTaskSubmitter; case TopologiesNames.DEPUBLICATION_TOPOLOGY: return depublicationTaskSubmitter; default: throw new IllegalArgumentException("Unable to find the TaskSubmitter for the given topology name: " + parameters.getTopologyName()); } } TaskSubmitterFactory(OaiTopologyTaskSubmitter oaiTopologyTaskSubmitter,
HttpTopologyTaskSubmitter httpTopologyTaskSubmitter,
OtherTopologiesTaskSubmitter otherTopologiesTaskSubmitter,
TaskSubmitter depublicationTaskSubmitter); TaskSubmitter provideTaskSubmitter(SubmitTaskParameters parameters); } |
@Test(expected = IllegalArgumentException.class) public void shouldThrowExceptionForUnknownTopologyName() { new TaskSubmitterFactory( Mockito.mock(OaiTopologyTaskSubmitter.class), Mockito.mock(HttpTopologyTaskSubmitter.class), Mockito.mock(OtherTopologiesTaskSubmitter.class), Mockito.mock(DepublicationTaskSubmitter.class) ).provideTaskSubmitter( SubmitTaskParameters.builder().topologyName("Unknown topology name").build()); } | public TaskSubmitter provideTaskSubmitter(SubmitTaskParameters parameters) { switch (parameters.getTopologyName()) { case TopologiesNames.OAI_TOPOLOGY: return oaiTopologyTaskSubmitter; case TopologiesNames.HTTP_TOPOLOGY: return httpTopologyTaskSubmitter; case TopologiesNames.ENRICHMENT_TOPOLOGY: case TopologiesNames.INDEXING_TOPOLOGY: case TopologiesNames.LINKCHECK_TOPOLOGY: case TopologiesNames.MEDIA_TOPOLOGY: case TopologiesNames.NORMALIZATION_TOPOLOGY: case TopologiesNames.VALIDATION_TOPOLOGY: case TopologiesNames.XSLT_TOPOLOGY: return otherTopologiesTaskSubmitter; case TopologiesNames.DEPUBLICATION_TOPOLOGY: return depublicationTaskSubmitter; default: throw new IllegalArgumentException("Unable to find the TaskSubmitter for the given topology name: " + parameters.getTopologyName()); } } | TaskSubmitterFactory { public TaskSubmitter provideTaskSubmitter(SubmitTaskParameters parameters) { switch (parameters.getTopologyName()) { case TopologiesNames.OAI_TOPOLOGY: return oaiTopologyTaskSubmitter; case TopologiesNames.HTTP_TOPOLOGY: return httpTopologyTaskSubmitter; case TopologiesNames.ENRICHMENT_TOPOLOGY: case TopologiesNames.INDEXING_TOPOLOGY: case TopologiesNames.LINKCHECK_TOPOLOGY: case TopologiesNames.MEDIA_TOPOLOGY: case TopologiesNames.NORMALIZATION_TOPOLOGY: case TopologiesNames.VALIDATION_TOPOLOGY: case TopologiesNames.XSLT_TOPOLOGY: return otherTopologiesTaskSubmitter; case TopologiesNames.DEPUBLICATION_TOPOLOGY: return depublicationTaskSubmitter; default: throw new IllegalArgumentException("Unable to find the TaskSubmitter for the given topology name: " + parameters.getTopologyName()); } } } | TaskSubmitterFactory { public TaskSubmitter provideTaskSubmitter(SubmitTaskParameters parameters) { switch (parameters.getTopologyName()) { case TopologiesNames.OAI_TOPOLOGY: return oaiTopologyTaskSubmitter; case TopologiesNames.HTTP_TOPOLOGY: return httpTopologyTaskSubmitter; case TopologiesNames.ENRICHMENT_TOPOLOGY: case TopologiesNames.INDEXING_TOPOLOGY: case TopologiesNames.LINKCHECK_TOPOLOGY: case TopologiesNames.MEDIA_TOPOLOGY: case TopologiesNames.NORMALIZATION_TOPOLOGY: case TopologiesNames.VALIDATION_TOPOLOGY: case TopologiesNames.XSLT_TOPOLOGY: return otherTopologiesTaskSubmitter; case TopologiesNames.DEPUBLICATION_TOPOLOGY: return depublicationTaskSubmitter; default: throw new IllegalArgumentException("Unable to find the TaskSubmitter for the given topology name: " + parameters.getTopologyName()); } } TaskSubmitterFactory(OaiTopologyTaskSubmitter oaiTopologyTaskSubmitter,
HttpTopologyTaskSubmitter httpTopologyTaskSubmitter,
OtherTopologiesTaskSubmitter otherTopologiesTaskSubmitter,
TaskSubmitter depublicationTaskSubmitter); } | TaskSubmitterFactory { public TaskSubmitter provideTaskSubmitter(SubmitTaskParameters parameters) { switch (parameters.getTopologyName()) { case TopologiesNames.OAI_TOPOLOGY: return oaiTopologyTaskSubmitter; case TopologiesNames.HTTP_TOPOLOGY: return httpTopologyTaskSubmitter; case TopologiesNames.ENRICHMENT_TOPOLOGY: case TopologiesNames.INDEXING_TOPOLOGY: case TopologiesNames.LINKCHECK_TOPOLOGY: case TopologiesNames.MEDIA_TOPOLOGY: case TopologiesNames.NORMALIZATION_TOPOLOGY: case TopologiesNames.VALIDATION_TOPOLOGY: case TopologiesNames.XSLT_TOPOLOGY: return otherTopologiesTaskSubmitter; case TopologiesNames.DEPUBLICATION_TOPOLOGY: return depublicationTaskSubmitter; default: throw new IllegalArgumentException("Unable to find the TaskSubmitter for the given topology name: " + parameters.getTopologyName()); } } TaskSubmitterFactory(OaiTopologyTaskSubmitter oaiTopologyTaskSubmitter,
HttpTopologyTaskSubmitter httpTopologyTaskSubmitter,
OtherTopologiesTaskSubmitter otherTopologiesTaskSubmitter,
TaskSubmitter depublicationTaskSubmitter); TaskSubmitter provideTaskSubmitter(SubmitTaskParameters parameters); } | TaskSubmitterFactory { public TaskSubmitter provideTaskSubmitter(SubmitTaskParameters parameters) { switch (parameters.getTopologyName()) { case TopologiesNames.OAI_TOPOLOGY: return oaiTopologyTaskSubmitter; case TopologiesNames.HTTP_TOPOLOGY: return httpTopologyTaskSubmitter; case TopologiesNames.ENRICHMENT_TOPOLOGY: case TopologiesNames.INDEXING_TOPOLOGY: case TopologiesNames.LINKCHECK_TOPOLOGY: case TopologiesNames.MEDIA_TOPOLOGY: case TopologiesNames.NORMALIZATION_TOPOLOGY: case TopologiesNames.VALIDATION_TOPOLOGY: case TopologiesNames.XSLT_TOPOLOGY: return otherTopologiesTaskSubmitter; case TopologiesNames.DEPUBLICATION_TOPOLOGY: return depublicationTaskSubmitter; default: throw new IllegalArgumentException("Unable to find the TaskSubmitter for the given topology name: " + parameters.getTopologyName()); } } TaskSubmitterFactory(OaiTopologyTaskSubmitter oaiTopologyTaskSubmitter,
HttpTopologyTaskSubmitter httpTopologyTaskSubmitter,
OtherTopologiesTaskSubmitter otherTopologiesTaskSubmitter,
TaskSubmitter depublicationTaskSubmitter); TaskSubmitter provideTaskSubmitter(SubmitTaskParameters parameters); } |
@Test public void shouldNotStartExecutionForEmptyTasksList() { List<TaskInfo> unfinishedTasks = new ArrayList<>(); Mockito.reset(cassandraTasksDAO); when(cassandraTasksDAO.findTasksInGivenState(Mockito.any(List.class))).thenReturn(unfinishedTasks); unfinishedTasksExecutor.reRunUnfinishedTasks(); Mockito.verify(cassandraTasksDAO, Mockito.times(1)).findTasksInGivenState(UnfinishedTasksExecutor.RESUMABLE_TASK_STATES); } | @PostConstruct public void reRunUnfinishedTasks() { LOGGER.info("Will restart all pending tasks"); List<TaskInfo> results = findProcessingByRestTasks(); List<TaskInfo> tasksForCurrentMachine = findTasksForCurrentMachine(results); resumeExecutionFor(tasksForCurrentMachine); } | UnfinishedTasksExecutor { @PostConstruct public void reRunUnfinishedTasks() { LOGGER.info("Will restart all pending tasks"); List<TaskInfo> results = findProcessingByRestTasks(); List<TaskInfo> tasksForCurrentMachine = findTasksForCurrentMachine(results); resumeExecutionFor(tasksForCurrentMachine); } } | UnfinishedTasksExecutor { @PostConstruct public void reRunUnfinishedTasks() { LOGGER.info("Will restart all pending tasks"); List<TaskInfo> results = findProcessingByRestTasks(); List<TaskInfo> tasksForCurrentMachine = findTasksForCurrentMachine(results); resumeExecutionFor(tasksForCurrentMachine); } UnfinishedTasksExecutor(TasksByStateDAO tasksDAO,
CassandraTaskInfoDAO taskInfoDAO,
TaskSubmitterFactory taskSubmitterFactory,
String applicationIdentifier,
TaskStatusUpdater taskStatusUpdater); } | UnfinishedTasksExecutor { @PostConstruct public void reRunUnfinishedTasks() { LOGGER.info("Will restart all pending tasks"); List<TaskInfo> results = findProcessingByRestTasks(); List<TaskInfo> tasksForCurrentMachine = findTasksForCurrentMachine(results); resumeExecutionFor(tasksForCurrentMachine); } UnfinishedTasksExecutor(TasksByStateDAO tasksDAO,
CassandraTaskInfoDAO taskInfoDAO,
TaskSubmitterFactory taskSubmitterFactory,
String applicationIdentifier,
TaskStatusUpdater taskStatusUpdater); @PostConstruct void reRunUnfinishedTasks(); } | UnfinishedTasksExecutor { @PostConstruct public void reRunUnfinishedTasks() { LOGGER.info("Will restart all pending tasks"); List<TaskInfo> results = findProcessingByRestTasks(); List<TaskInfo> tasksForCurrentMachine = findTasksForCurrentMachine(results); resumeExecutionFor(tasksForCurrentMachine); } UnfinishedTasksExecutor(TasksByStateDAO tasksDAO,
CassandraTaskInfoDAO taskInfoDAO,
TaskSubmitterFactory taskSubmitterFactory,
String applicationIdentifier,
TaskStatusUpdater taskStatusUpdater); @PostConstruct void reRunUnfinishedTasks(); static final List<TaskState> RESUMABLE_TASK_STATES; } |
@Test public void shouldStartExecutionForOneTasks() throws TaskInfoDoesNotExistException { List<TaskInfo> unfinishedTasks = new ArrayList<>(); TaskInfo taskInfo = prepareTestTask(); unfinishedTasks.add(taskInfo); Mockito.reset(cassandraTasksDAO); Mockito.reset(taskSubmitterFactory); when(cassandraTasksDAO.findTasksInGivenState(UnfinishedTasksExecutor.RESUMABLE_TASK_STATES)).thenReturn(unfinishedTasks); when(cassandraTaskInfoDAO.findById(1L)).thenReturn(Optional.of(taskInfo)); when(taskSubmitterFactory.provideTaskSubmitter(Mockito.any(SubmitTaskParameters.class))).thenReturn(Mockito.mock(TaskSubmitter.class)); unfinishedTasksExecutor.reRunUnfinishedTasks(); Mockito.verify(cassandraTasksDAO, Mockito.times(1)).findTasksInGivenState(UnfinishedTasksExecutor.RESUMABLE_TASK_STATES); Mockito.verify(taskSubmitterFactory, Mockito.times(1)).provideTaskSubmitter(Mockito.any(SubmitTaskParameters.class)); } | @PostConstruct public void reRunUnfinishedTasks() { LOGGER.info("Will restart all pending tasks"); List<TaskInfo> results = findProcessingByRestTasks(); List<TaskInfo> tasksForCurrentMachine = findTasksForCurrentMachine(results); resumeExecutionFor(tasksForCurrentMachine); } | UnfinishedTasksExecutor { @PostConstruct public void reRunUnfinishedTasks() { LOGGER.info("Will restart all pending tasks"); List<TaskInfo> results = findProcessingByRestTasks(); List<TaskInfo> tasksForCurrentMachine = findTasksForCurrentMachine(results); resumeExecutionFor(tasksForCurrentMachine); } } | UnfinishedTasksExecutor { @PostConstruct public void reRunUnfinishedTasks() { LOGGER.info("Will restart all pending tasks"); List<TaskInfo> results = findProcessingByRestTasks(); List<TaskInfo> tasksForCurrentMachine = findTasksForCurrentMachine(results); resumeExecutionFor(tasksForCurrentMachine); } UnfinishedTasksExecutor(TasksByStateDAO tasksDAO,
CassandraTaskInfoDAO taskInfoDAO,
TaskSubmitterFactory taskSubmitterFactory,
String applicationIdentifier,
TaskStatusUpdater taskStatusUpdater); } | UnfinishedTasksExecutor { @PostConstruct public void reRunUnfinishedTasks() { LOGGER.info("Will restart all pending tasks"); List<TaskInfo> results = findProcessingByRestTasks(); List<TaskInfo> tasksForCurrentMachine = findTasksForCurrentMachine(results); resumeExecutionFor(tasksForCurrentMachine); } UnfinishedTasksExecutor(TasksByStateDAO tasksDAO,
CassandraTaskInfoDAO taskInfoDAO,
TaskSubmitterFactory taskSubmitterFactory,
String applicationIdentifier,
TaskStatusUpdater taskStatusUpdater); @PostConstruct void reRunUnfinishedTasks(); } | UnfinishedTasksExecutor { @PostConstruct public void reRunUnfinishedTasks() { LOGGER.info("Will restart all pending tasks"); List<TaskInfo> results = findProcessingByRestTasks(); List<TaskInfo> tasksForCurrentMachine = findTasksForCurrentMachine(results); resumeExecutionFor(tasksForCurrentMachine); } UnfinishedTasksExecutor(TasksByStateDAO tasksDAO,
CassandraTaskInfoDAO taskInfoDAO,
TaskSubmitterFactory taskSubmitterFactory,
String applicationIdentifier,
TaskStatusUpdater taskStatusUpdater); @PostConstruct void reRunUnfinishedTasks(); static final List<TaskState> RESUMABLE_TASK_STATES; } |
@Test public void shouldExecuteTheSessionWithoutRetry() throws Exception { ResultSet resultSet = mock(ResultSet.class); when(resultSet.one()).thenReturn(rows.get(0)); when(resultSet.one().getLong("count")).thenReturn(1l); when(session.execute(matchingBoundStatement)).thenReturn(resultSet); PreparedStatement preparedStatement = mock(PreparedStatement.class); when(matchingBoundStatement.preparedStatement()).thenReturn(preparedStatement); when(preparedStatement.getQueryString()).thenReturn("Query String"); final RowsValidatorJob job = new RowsValidatorJob(session, primaryKeys, matchingBoundStatement, rows); job.call(); verify(session, times(1)).execute(any(BoundStatement.class)); } | @Override public Void call() throws Exception { validateRows(); return null; } | RowsValidatorJob implements Callable<Void> { @Override public Void call() throws Exception { validateRows(); return null; } } | RowsValidatorJob implements Callable<Void> { @Override public Void call() throws Exception { validateRows(); return null; } RowsValidatorJob(Session session, List<String> primaryKeys, BoundStatement matchingBoundStatement, List<Row> rows); } | RowsValidatorJob implements Callable<Void> { @Override public Void call() throws Exception { validateRows(); return null; } RowsValidatorJob(Session session, List<String> primaryKeys, BoundStatement matchingBoundStatement, List<Row> rows); @Override Void call(); } | RowsValidatorJob implements Callable<Void> { @Override public Void call() throws Exception { validateRows(); return null; } RowsValidatorJob(Session session, List<String> primaryKeys, BoundStatement matchingBoundStatement, List<Row> rows); @Override Void call(); } |
@Test public void shouldStartExecutionForTasksThatBelongsToGivenMachine() throws TaskInfoDoesNotExistException { List<TaskInfo> unfinishedTasks = new ArrayList<>(); TaskInfo taskInfo = prepareTestTask(); unfinishedTasks.add(taskInfo); unfinishedTasks.add(prepareTestTaskForAnotherMachine()); Mockito.reset(cassandraTasksDAO); Mockito.reset(taskSubmitterFactory); when(cassandraTasksDAO.findTasksInGivenState(UnfinishedTasksExecutor.RESUMABLE_TASK_STATES)).thenReturn(unfinishedTasks); when(cassandraTaskInfoDAO.findById(1L)).thenReturn(Optional.of(taskInfo)); when(taskSubmitterFactory.provideTaskSubmitter(Mockito.any(SubmitTaskParameters.class))).thenReturn(Mockito.mock(TaskSubmitter.class)); unfinishedTasksExecutor.reRunUnfinishedTasks(); Mockito.verify(cassandraTasksDAO, Mockito.times(1)).findTasksInGivenState(UnfinishedTasksExecutor.RESUMABLE_TASK_STATES); Mockito.verify(taskSubmitterFactory, Mockito.times(1)).provideTaskSubmitter(Mockito.any(SubmitTaskParameters.class)); } | @PostConstruct public void reRunUnfinishedTasks() { LOGGER.info("Will restart all pending tasks"); List<TaskInfo> results = findProcessingByRestTasks(); List<TaskInfo> tasksForCurrentMachine = findTasksForCurrentMachine(results); resumeExecutionFor(tasksForCurrentMachine); } | UnfinishedTasksExecutor { @PostConstruct public void reRunUnfinishedTasks() { LOGGER.info("Will restart all pending tasks"); List<TaskInfo> results = findProcessingByRestTasks(); List<TaskInfo> tasksForCurrentMachine = findTasksForCurrentMachine(results); resumeExecutionFor(tasksForCurrentMachine); } } | UnfinishedTasksExecutor { @PostConstruct public void reRunUnfinishedTasks() { LOGGER.info("Will restart all pending tasks"); List<TaskInfo> results = findProcessingByRestTasks(); List<TaskInfo> tasksForCurrentMachine = findTasksForCurrentMachine(results); resumeExecutionFor(tasksForCurrentMachine); } UnfinishedTasksExecutor(TasksByStateDAO tasksDAO,
CassandraTaskInfoDAO taskInfoDAO,
TaskSubmitterFactory taskSubmitterFactory,
String applicationIdentifier,
TaskStatusUpdater taskStatusUpdater); } | UnfinishedTasksExecutor { @PostConstruct public void reRunUnfinishedTasks() { LOGGER.info("Will restart all pending tasks"); List<TaskInfo> results = findProcessingByRestTasks(); List<TaskInfo> tasksForCurrentMachine = findTasksForCurrentMachine(results); resumeExecutionFor(tasksForCurrentMachine); } UnfinishedTasksExecutor(TasksByStateDAO tasksDAO,
CassandraTaskInfoDAO taskInfoDAO,
TaskSubmitterFactory taskSubmitterFactory,
String applicationIdentifier,
TaskStatusUpdater taskStatusUpdater); @PostConstruct void reRunUnfinishedTasks(); } | UnfinishedTasksExecutor { @PostConstruct public void reRunUnfinishedTasks() { LOGGER.info("Will restart all pending tasks"); List<TaskInfo> results = findProcessingByRestTasks(); List<TaskInfo> tasksForCurrentMachine = findTasksForCurrentMachine(results); resumeExecutionFor(tasksForCurrentMachine); } UnfinishedTasksExecutor(TasksByStateDAO tasksDAO,
CassandraTaskInfoDAO taskInfoDAO,
TaskSubmitterFactory taskSubmitterFactory,
String applicationIdentifier,
TaskStatusUpdater taskStatusUpdater); @PostConstruct void reRunUnfinishedTasks(); static final List<TaskState> RESUMABLE_TASK_STATES; } |
@Test public void shouldSuccessfullyParseTopicsList() { TopologiesTopicsParser t = new TopologiesTopicsParser(); Map<String, List<String>> topologiesTopicsList = t.parse(VALID_INPUT); Assert.assertEquals(2, topologiesTopicsList.size()); Assert.assertNotNull(topologiesTopicsList.get("oai_topology")); Assert.assertNotNull(topologiesTopicsList.get("another_topology")); Assert.assertEquals(3, topologiesTopicsList.get("oai_topology").size()); Assert.assertEquals(2, topologiesTopicsList.get("another_topology").size()); } | public Map<String, List<String>> parse(String topicsList) { if (isInputValid(topicsList)) { List<String> topologies = extractTopologies(topicsList); return extractTopics(topologies); } else { throw new RuntimeException("Topics list is not valid"); } } | TopologiesTopicsParser { public Map<String, List<String>> parse(String topicsList) { if (isInputValid(topicsList)) { List<String> topologies = extractTopologies(topicsList); return extractTopics(topologies); } else { throw new RuntimeException("Topics list is not valid"); } } } | TopologiesTopicsParser { public Map<String, List<String>> parse(String topicsList) { if (isInputValid(topicsList)) { List<String> topologies = extractTopologies(topicsList); return extractTopics(topologies); } else { throw new RuntimeException("Topics list is not valid"); } } } | TopologiesTopicsParser { public Map<String, List<String>> parse(String topicsList) { if (isInputValid(topicsList)) { List<String> topologies = extractTopologies(topicsList); return extractTopics(topologies); } else { throw new RuntimeException("Topics list is not valid"); } } Map<String, List<String>> parse(String topicsList); } | TopologiesTopicsParser { public Map<String, List<String>> parse(String topicsList) { if (isInputValid(topicsList)) { List<String> topologies = extractTopologies(topicsList); return extractTopics(topologies); } else { throw new RuntimeException("Topics list is not valid"); } } Map<String, List<String>> parse(String topicsList); } |
@Test public void shouldSuccessfullyParseTopicsList_1() { TopologiesTopicsParser t = new TopologiesTopicsParser(); Map<String, List<String>> topologiesTopicsList = t.parse(VALID_INPUT_1); Assert.assertEquals(2, topologiesTopicsList.size()); Assert.assertNotNull(topologiesTopicsList.get("oai_topology")); Assert.assertNotNull(topologiesTopicsList.get("another_topology")); Assert.assertEquals(3, topologiesTopicsList.get("oai_topology").size()); Assert.assertEquals(0, topologiesTopicsList.get("another_topology").size()); } | public Map<String, List<String>> parse(String topicsList) { if (isInputValid(topicsList)) { List<String> topologies = extractTopologies(topicsList); return extractTopics(topologies); } else { throw new RuntimeException("Topics list is not valid"); } } | TopologiesTopicsParser { public Map<String, List<String>> parse(String topicsList) { if (isInputValid(topicsList)) { List<String> topologies = extractTopologies(topicsList); return extractTopics(topologies); } else { throw new RuntimeException("Topics list is not valid"); } } } | TopologiesTopicsParser { public Map<String, List<String>> parse(String topicsList) { if (isInputValid(topicsList)) { List<String> topologies = extractTopologies(topicsList); return extractTopics(topologies); } else { throw new RuntimeException("Topics list is not valid"); } } } | TopologiesTopicsParser { public Map<String, List<String>> parse(String topicsList) { if (isInputValid(topicsList)) { List<String> topologies = extractTopologies(topicsList); return extractTopics(topologies); } else { throw new RuntimeException("Topics list is not valid"); } } Map<String, List<String>> parse(String topicsList); } | TopologiesTopicsParser { public Map<String, List<String>> parse(String topicsList) { if (isInputValid(topicsList)) { List<String> topologies = extractTopologies(topicsList); return extractTopics(topologies); } else { throw new RuntimeException("Topics list is not valid"); } } Map<String, List<String>> parse(String topicsList); } |
@Test(expected = RuntimeException.class) public void shouldThrowExceptionForInvalidTopicsList_1() { TopologiesTopicsParser t = new TopologiesTopicsParser(); t.parse(INVALID_INPUT_1); } | public Map<String, List<String>> parse(String topicsList) { if (isInputValid(topicsList)) { List<String> topologies = extractTopologies(topicsList); return extractTopics(topologies); } else { throw new RuntimeException("Topics list is not valid"); } } | TopologiesTopicsParser { public Map<String, List<String>> parse(String topicsList) { if (isInputValid(topicsList)) { List<String> topologies = extractTopologies(topicsList); return extractTopics(topologies); } else { throw new RuntimeException("Topics list is not valid"); } } } | TopologiesTopicsParser { public Map<String, List<String>> parse(String topicsList) { if (isInputValid(topicsList)) { List<String> topologies = extractTopologies(topicsList); return extractTopics(topologies); } else { throw new RuntimeException("Topics list is not valid"); } } } | TopologiesTopicsParser { public Map<String, List<String>> parse(String topicsList) { if (isInputValid(topicsList)) { List<String> topologies = extractTopologies(topicsList); return extractTopics(topologies); } else { throw new RuntimeException("Topics list is not valid"); } } Map<String, List<String>> parse(String topicsList); } | TopologiesTopicsParser { public Map<String, List<String>> parse(String topicsList) { if (isInputValid(topicsList)) { List<String> topologies = extractTopologies(topicsList); return extractTopics(topologies); } else { throw new RuntimeException("Topics list is not valid"); } } Map<String, List<String>> parse(String topicsList); } |
@Test public void findGhostTasksReturnsEmptyListIfNotTaskActive() { assertThat(service.findGhostTasks(), empty()); } | public List<TaskInfo> findGhostTasks() { return findTasksInGivenStates(TaskState.PROCESSING_BY_REST_APPLICATION, TaskState.QUEUED). filter(this::isGhost).collect(Collectors.toList()); } | GhostTaskService { public List<TaskInfo> findGhostTasks() { return findTasksInGivenStates(TaskState.PROCESSING_BY_REST_APPLICATION, TaskState.QUEUED). filter(this::isGhost).collect(Collectors.toList()); } } | GhostTaskService { public List<TaskInfo> findGhostTasks() { return findTasksInGivenStates(TaskState.PROCESSING_BY_REST_APPLICATION, TaskState.QUEUED). filter(this::isGhost).collect(Collectors.toList()); } GhostTaskService(Environment environment); } | GhostTaskService { public List<TaskInfo> findGhostTasks() { return findTasksInGivenStates(TaskState.PROCESSING_BY_REST_APPLICATION, TaskState.QUEUED). filter(this::isGhost).collect(Collectors.toList()); } GhostTaskService(Environment environment); @Scheduled(cron = "0 0 * * * *") void serviceTask(); List<TaskInfo> findGhostTasks(); } | GhostTaskService { public List<TaskInfo> findGhostTasks() { return findTasksInGivenStates(TaskState.PROCESSING_BY_REST_APPLICATION, TaskState.QUEUED). filter(this::isGhost).collect(Collectors.toList()); } GhostTaskService(Environment environment); @Scheduled(cron = "0 0 * * * *") void serviceTask(); List<TaskInfo> findGhostTasks(); } |
@Test public void findGhostTasksReturnsTaskIfItIsOldSentAndNoStarted() { when(tasksByStateDAO.findTasksInGivenState(eq(ACTIVE_TASK_STATES))) .thenReturn(Collections.singletonList(TOPIC_INFO_1)); when(taskInfoDAO.findById(anyLong())).thenReturn(Optional.of(OLD_SENT_NO_STARTED_TASK_INFO_1)); assertThat(service.findGhostTasks(), contains(OLD_SENT_NO_STARTED_TASK_INFO_1)); } | public List<TaskInfo> findGhostTasks() { return findTasksInGivenStates(TaskState.PROCESSING_BY_REST_APPLICATION, TaskState.QUEUED). filter(this::isGhost).collect(Collectors.toList()); } | GhostTaskService { public List<TaskInfo> findGhostTasks() { return findTasksInGivenStates(TaskState.PROCESSING_BY_REST_APPLICATION, TaskState.QUEUED). filter(this::isGhost).collect(Collectors.toList()); } } | GhostTaskService { public List<TaskInfo> findGhostTasks() { return findTasksInGivenStates(TaskState.PROCESSING_BY_REST_APPLICATION, TaskState.QUEUED). filter(this::isGhost).collect(Collectors.toList()); } GhostTaskService(Environment environment); } | GhostTaskService { public List<TaskInfo> findGhostTasks() { return findTasksInGivenStates(TaskState.PROCESSING_BY_REST_APPLICATION, TaskState.QUEUED). filter(this::isGhost).collect(Collectors.toList()); } GhostTaskService(Environment environment); @Scheduled(cron = "0 0 * * * *") void serviceTask(); List<TaskInfo> findGhostTasks(); } | GhostTaskService { public List<TaskInfo> findGhostTasks() { return findTasksInGivenStates(TaskState.PROCESSING_BY_REST_APPLICATION, TaskState.QUEUED). filter(this::isGhost).collect(Collectors.toList()); } GhostTaskService(Environment environment); @Scheduled(cron = "0 0 * * * *") void serviceTask(); List<TaskInfo> findGhostTasks(); } |
@Test public void findGhostTasksReturnsTaskIfItIsOldSentAndOldStarted() { when(tasksByStateDAO.findTasksInGivenState(eq(ACTIVE_TASK_STATES))) .thenReturn(Collections.singletonList(TOPIC_INFO_1)); when(taskInfoDAO.findById(anyLong())).thenReturn(Optional.of(OLD_SENT_OLD_STARTED_TASK_INFO_1)); assertThat(service.findGhostTasks(), contains(OLD_SENT_OLD_STARTED_TASK_INFO_1)); } | public List<TaskInfo> findGhostTasks() { return findTasksInGivenStates(TaskState.PROCESSING_BY_REST_APPLICATION, TaskState.QUEUED). filter(this::isGhost).collect(Collectors.toList()); } | GhostTaskService { public List<TaskInfo> findGhostTasks() { return findTasksInGivenStates(TaskState.PROCESSING_BY_REST_APPLICATION, TaskState.QUEUED). filter(this::isGhost).collect(Collectors.toList()); } } | GhostTaskService { public List<TaskInfo> findGhostTasks() { return findTasksInGivenStates(TaskState.PROCESSING_BY_REST_APPLICATION, TaskState.QUEUED). filter(this::isGhost).collect(Collectors.toList()); } GhostTaskService(Environment environment); } | GhostTaskService { public List<TaskInfo> findGhostTasks() { return findTasksInGivenStates(TaskState.PROCESSING_BY_REST_APPLICATION, TaskState.QUEUED). filter(this::isGhost).collect(Collectors.toList()); } GhostTaskService(Environment environment); @Scheduled(cron = "0 0 * * * *") void serviceTask(); List<TaskInfo> findGhostTasks(); } | GhostTaskService { public List<TaskInfo> findGhostTasks() { return findTasksInGivenStates(TaskState.PROCESSING_BY_REST_APPLICATION, TaskState.QUEUED). filter(this::isGhost).collect(Collectors.toList()); } GhostTaskService(Environment environment); @Scheduled(cron = "0 0 * * * *") void serviceTask(); List<TaskInfo> findGhostTasks(); } |
@Test public void findGhostTasksShouldIgnoreTasksThatNewlySentAndNewStarted() { when(tasksByStateDAO.findTasksInGivenState(eq(ACTIVE_TASK_STATES))) .thenReturn(Collections.singletonList(TOPIC_INFO_1)); when(taskInfoDAO.findById(anyLong())).thenReturn(Optional.of(OLD_SENT_NEWLY_STARTED_TASK_INFO_1)); assertThat(service.findGhostTasks(), empty()); } | public List<TaskInfo> findGhostTasks() { return findTasksInGivenStates(TaskState.PROCESSING_BY_REST_APPLICATION, TaskState.QUEUED). filter(this::isGhost).collect(Collectors.toList()); } | GhostTaskService { public List<TaskInfo> findGhostTasks() { return findTasksInGivenStates(TaskState.PROCESSING_BY_REST_APPLICATION, TaskState.QUEUED). filter(this::isGhost).collect(Collectors.toList()); } } | GhostTaskService { public List<TaskInfo> findGhostTasks() { return findTasksInGivenStates(TaskState.PROCESSING_BY_REST_APPLICATION, TaskState.QUEUED). filter(this::isGhost).collect(Collectors.toList()); } GhostTaskService(Environment environment); } | GhostTaskService { public List<TaskInfo> findGhostTasks() { return findTasksInGivenStates(TaskState.PROCESSING_BY_REST_APPLICATION, TaskState.QUEUED). filter(this::isGhost).collect(Collectors.toList()); } GhostTaskService(Environment environment); @Scheduled(cron = "0 0 * * * *") void serviceTask(); List<TaskInfo> findGhostTasks(); } | GhostTaskService { public List<TaskInfo> findGhostTasks() { return findTasksInGivenStates(TaskState.PROCESSING_BY_REST_APPLICATION, TaskState.QUEUED). filter(this::isGhost).collect(Collectors.toList()); } GhostTaskService(Environment environment); @Scheduled(cron = "0 0 * * * *") void serviceTask(); List<TaskInfo> findGhostTasks(); } |
@Test public void findGhostTasksShouldIgnoreTasksThatOldSentButNewStarted() { when(tasksByStateDAO.findTasksInGivenState(eq(ACTIVE_TASK_STATES))) .thenReturn(Collections.singletonList(TOPIC_INFO_1)); when(taskInfoDAO.findById(anyLong())).thenReturn(Optional.of(NEWLY_SENT_NEWLY_STARTED_TASK_INFO_1)); assertThat(service.findGhostTasks(), empty()); } | public List<TaskInfo> findGhostTasks() { return findTasksInGivenStates(TaskState.PROCESSING_BY_REST_APPLICATION, TaskState.QUEUED). filter(this::isGhost).collect(Collectors.toList()); } | GhostTaskService { public List<TaskInfo> findGhostTasks() { return findTasksInGivenStates(TaskState.PROCESSING_BY_REST_APPLICATION, TaskState.QUEUED). filter(this::isGhost).collect(Collectors.toList()); } } | GhostTaskService { public List<TaskInfo> findGhostTasks() { return findTasksInGivenStates(TaskState.PROCESSING_BY_REST_APPLICATION, TaskState.QUEUED). filter(this::isGhost).collect(Collectors.toList()); } GhostTaskService(Environment environment); } | GhostTaskService { public List<TaskInfo> findGhostTasks() { return findTasksInGivenStates(TaskState.PROCESSING_BY_REST_APPLICATION, TaskState.QUEUED). filter(this::isGhost).collect(Collectors.toList()); } GhostTaskService(Environment environment); @Scheduled(cron = "0 0 * * * *") void serviceTask(); List<TaskInfo> findGhostTasks(); } | GhostTaskService { public List<TaskInfo> findGhostTasks() { return findTasksInGivenStates(TaskState.PROCESSING_BY_REST_APPLICATION, TaskState.QUEUED). filter(this::isGhost).collect(Collectors.toList()); } GhostTaskService(Environment environment); @Scheduled(cron = "0 0 * * * *") void serviceTask(); List<TaskInfo> findGhostTasks(); } |
@Test public void findGhostTasksShouldIgnoreTasksThatNewlySentAndNotStarted() { when(tasksByStateDAO.findTasksInGivenState(eq(ACTIVE_TASK_STATES))) .thenReturn(Collections.singletonList(TOPIC_INFO_1)); when(taskInfoDAO.findById(anyLong())).thenReturn(Optional.of(NEWLY_SENT_NO_STARTED_TASK_INFO_1)); assertThat(service.findGhostTasks(), empty()); } | public List<TaskInfo> findGhostTasks() { return findTasksInGivenStates(TaskState.PROCESSING_BY_REST_APPLICATION, TaskState.QUEUED). filter(this::isGhost).collect(Collectors.toList()); } | GhostTaskService { public List<TaskInfo> findGhostTasks() { return findTasksInGivenStates(TaskState.PROCESSING_BY_REST_APPLICATION, TaskState.QUEUED). filter(this::isGhost).collect(Collectors.toList()); } } | GhostTaskService { public List<TaskInfo> findGhostTasks() { return findTasksInGivenStates(TaskState.PROCESSING_BY_REST_APPLICATION, TaskState.QUEUED). filter(this::isGhost).collect(Collectors.toList()); } GhostTaskService(Environment environment); } | GhostTaskService { public List<TaskInfo> findGhostTasks() { return findTasksInGivenStates(TaskState.PROCESSING_BY_REST_APPLICATION, TaskState.QUEUED). filter(this::isGhost).collect(Collectors.toList()); } GhostTaskService(Environment environment); @Scheduled(cron = "0 0 * * * *") void serviceTask(); List<TaskInfo> findGhostTasks(); } | GhostTaskService { public List<TaskInfo> findGhostTasks() { return findTasksInGivenStates(TaskState.PROCESSING_BY_REST_APPLICATION, TaskState.QUEUED). filter(this::isGhost).collect(Collectors.toList()); } GhostTaskService(Environment environment); @Scheduled(cron = "0 0 * * * *") void serviceTask(); List<TaskInfo> findGhostTasks(); } |
@Test public void shouldExecuteTheSessionWithMaximumRetry() throws Exception { ResultSet resultSet = mock(ResultSet.class); when(resultSet.one()).thenReturn(rows.get(0)); when(resultSet.one().getLong("count")).thenReturn(0l); final Session session = mock(Session.class); when(session.execute(matchingBoundStatement)).thenReturn(resultSet); final RowsValidatorJob job = new RowsValidatorJob(session, primaryKeys, matchingBoundStatement, rows); try { job.call(); assertTrue(false); } catch (Exception e) { } verify(session, times(5)).execute(any(BoundStatement.class)); } | @Override public Void call() throws Exception { validateRows(); return null; } | RowsValidatorJob implements Callable<Void> { @Override public Void call() throws Exception { validateRows(); return null; } } | RowsValidatorJob implements Callable<Void> { @Override public Void call() throws Exception { validateRows(); return null; } RowsValidatorJob(Session session, List<String> primaryKeys, BoundStatement matchingBoundStatement, List<Row> rows); } | RowsValidatorJob implements Callable<Void> { @Override public Void call() throws Exception { validateRows(); return null; } RowsValidatorJob(Session session, List<String> primaryKeys, BoundStatement matchingBoundStatement, List<Row> rows); @Override Void call(); } | RowsValidatorJob implements Callable<Void> { @Override public Void call() throws Exception { validateRows(); return null; } RowsValidatorJob(Session session, List<String> primaryKeys, BoundStatement matchingBoundStatement, List<Row> rows); @Override Void call(); } |
@Test public void shouldRemoveEntireRepresentation() throws Exception { final int NUMBER_OF_REVISIONS = 1; final int NUMBER_OF_RESPONSES = 2; RevisionInformation revisionInformation = new RevisionInformation("DATASET", DATA_PROVIDER, SOURCE + REPRESENTATION_NAME, REVISION_NAME, REVISION_PROVIDER, getUTCDateString(date)); revisionRemoverJob.setRevisionInformation(revisionInformation); Representation representation = testHelper.prepareRepresentation(SOURCE + CLOUD_ID, SOURCE + REPRESENTATION_NAME, SOURCE + VERSION, SOURCE_VERSION_URL, DATA_PROVIDER, false, date); List<Representation> representations = new ArrayList<>(1); representations.add(representation); List<Revision> revisions = getRevisions(NUMBER_OF_REVISIONS); representation.setRevisions(revisions); ResultSlice<CloudTagsResponse> resultSlice = getCloudTagsResponseResultSlice(NUMBER_OF_RESPONSES); when(dataSetServiceClient.getDataSetRevisionsChunk(anyString(), anyString(), anyString(), anyString(), anyString(), anyString(), anyString(), anyInt())).thenReturn(resultSlice); when(recordServiceClient.getRepresentationsByRevision(SOURCE + CLOUD_ID, SOURCE + REPRESENTATION_NAME, REVISION_NAME, REVISION_PROVIDER, getUTCDateString(date))).thenReturn(Arrays.asList(representation)); when(recordServiceClient.getRepresentationsByRevision(SOURCE + CLOUD_ID2, SOURCE + REPRESENTATION_NAME, REVISION_NAME, REVISION_PROVIDER, getUTCDateString(date))).thenReturn(Arrays.asList(representation)); Thread thread = new Thread(revisionRemoverJob); thread.start(); thread.join(); verify(revisionServiceClient, times(0)).deleteRevision(anyString(), anyString(), anyString(), anyString(), anyString(), anyString()); verify(recordServiceClient, times(NUMBER_OF_RESPONSES)).deleteRepresentation(anyString(), anyString(), anyString()); } | void setRevisionInformation(RevisionInformation revisionInformation) { this.revisionInformation = revisionInformation; } | RevisionRemoverJob implements Runnable { void setRevisionInformation(RevisionInformation revisionInformation) { this.revisionInformation = revisionInformation; } } | RevisionRemoverJob implements Runnable { void setRevisionInformation(RevisionInformation revisionInformation) { this.revisionInformation = revisionInformation; } RevisionRemoverJob(DataSetServiceClient dataSetServiceClient, RecordServiceClient recordServiceClient, RevisionInformation revisionInformation, RevisionServiceClient revisionServiceClient); } | RevisionRemoverJob implements Runnable { void setRevisionInformation(RevisionInformation revisionInformation) { this.revisionInformation = revisionInformation; } RevisionRemoverJob(DataSetServiceClient dataSetServiceClient, RecordServiceClient recordServiceClient, RevisionInformation revisionInformation, RevisionServiceClient revisionServiceClient); @Override void run(); } | RevisionRemoverJob implements Runnable { void setRevisionInformation(RevisionInformation revisionInformation) { this.revisionInformation = revisionInformation; } RevisionRemoverJob(DataSetServiceClient dataSetServiceClient, RecordServiceClient recordServiceClient, RevisionInformation revisionInformation, RevisionServiceClient revisionServiceClient); @Override void run(); } |
@Test public void findGhostTasksShouldIgnoreTasksThatNotReserveTopicBelongingToTopology() { when(tasksByStateDAO.findTasksInGivenState(eq(ACTIVE_TASK_STATES))) .thenReturn(Collections.singletonList(TOPIC_INFO_1_UNKNONW_TOPIC)); when(taskInfoDAO.findById(anyLong())).thenReturn(Optional.of(OLD_SENT_NO_STARTED_TASK_INFO_1)); assertThat(service.findGhostTasks(), empty()); } | public List<TaskInfo> findGhostTasks() { return findTasksInGivenStates(TaskState.PROCESSING_BY_REST_APPLICATION, TaskState.QUEUED). filter(this::isGhost).collect(Collectors.toList()); } | GhostTaskService { public List<TaskInfo> findGhostTasks() { return findTasksInGivenStates(TaskState.PROCESSING_BY_REST_APPLICATION, TaskState.QUEUED). filter(this::isGhost).collect(Collectors.toList()); } } | GhostTaskService { public List<TaskInfo> findGhostTasks() { return findTasksInGivenStates(TaskState.PROCESSING_BY_REST_APPLICATION, TaskState.QUEUED). filter(this::isGhost).collect(Collectors.toList()); } GhostTaskService(Environment environment); } | GhostTaskService { public List<TaskInfo> findGhostTasks() { return findTasksInGivenStates(TaskState.PROCESSING_BY_REST_APPLICATION, TaskState.QUEUED). filter(this::isGhost).collect(Collectors.toList()); } GhostTaskService(Environment environment); @Scheduled(cron = "0 0 * * * *") void serviceTask(); List<TaskInfo> findGhostTasks(); } | GhostTaskService { public List<TaskInfo> findGhostTasks() { return findTasksInGivenStates(TaskState.PROCESSING_BY_REST_APPLICATION, TaskState.QUEUED). filter(this::isGhost).collect(Collectors.toList()); } GhostTaskService(Environment environment); @Scheduled(cron = "0 0 * * * *") void serviceTask(); List<TaskInfo> findGhostTasks(); } |
@Test public void shouldReturnProcessedFiles() throws Exception { TaskInfo taskInfo = new TaskInfo(TASK_ID, TOPOLOGY_NAME, TaskState.PROCESSED, "", EXPECTED_SIZE, EXPECTED_SIZE, 0, 0, new Date(), new Date(), new Date()); when(taskInfoDAO.findById(TASK_ID)).thenReturn(Optional.of(taskInfo)); dpsTask.addParameter(PluginParameterKeys.PREVIOUS_TASK_ID, String.valueOf(TASK_ID)); int expectedFilesCount = datasetFilesCounter.getFilesCount(dpsTask); assertEquals(EXPECTED_SIZE, expectedFilesCount); } | public int getFilesCount(DpsTask task) throws TaskSubmissionException { String providedTaskId = task.getParameter(PluginParameterKeys.PREVIOUS_TASK_ID); if (providedTaskId==null) return UNKNOWN_EXPECTED_SIZE; try { long taskId = Long.parseLong(providedTaskId); TaskInfo taskInfo = taskInfoDAO.findById(taskId).orElseThrow(TaskInfoDoesNotExistException::new); return taskInfo.getProcessedElementCount(); } catch (NumberFormatException e) { LOGGER.error("The provided previous task id {} is not long ", providedTaskId); return UNKNOWN_EXPECTED_SIZE; } catch (TaskInfoDoesNotExistException e) { LOGGER.error("Task with taskId {} doesn't exist ", providedTaskId); return UNKNOWN_EXPECTED_SIZE; } catch (Exception e) { LOGGER.error("he task was dropped because of {} ", e.getMessage()); throw new TaskSubmissionException("The task was dropped while counting the files number because of " + e.getMessage()); } } | DatasetFilesCounter extends FilesCounter { public int getFilesCount(DpsTask task) throws TaskSubmissionException { String providedTaskId = task.getParameter(PluginParameterKeys.PREVIOUS_TASK_ID); if (providedTaskId==null) return UNKNOWN_EXPECTED_SIZE; try { long taskId = Long.parseLong(providedTaskId); TaskInfo taskInfo = taskInfoDAO.findById(taskId).orElseThrow(TaskInfoDoesNotExistException::new); return taskInfo.getProcessedElementCount(); } catch (NumberFormatException e) { LOGGER.error("The provided previous task id {} is not long ", providedTaskId); return UNKNOWN_EXPECTED_SIZE; } catch (TaskInfoDoesNotExistException e) { LOGGER.error("Task with taskId {} doesn't exist ", providedTaskId); return UNKNOWN_EXPECTED_SIZE; } catch (Exception e) { LOGGER.error("he task was dropped because of {} ", e.getMessage()); throw new TaskSubmissionException("The task was dropped while counting the files number because of " + e.getMessage()); } } } | DatasetFilesCounter extends FilesCounter { public int getFilesCount(DpsTask task) throws TaskSubmissionException { String providedTaskId = task.getParameter(PluginParameterKeys.PREVIOUS_TASK_ID); if (providedTaskId==null) return UNKNOWN_EXPECTED_SIZE; try { long taskId = Long.parseLong(providedTaskId); TaskInfo taskInfo = taskInfoDAO.findById(taskId).orElseThrow(TaskInfoDoesNotExistException::new); return taskInfo.getProcessedElementCount(); } catch (NumberFormatException e) { LOGGER.error("The provided previous task id {} is not long ", providedTaskId); return UNKNOWN_EXPECTED_SIZE; } catch (TaskInfoDoesNotExistException e) { LOGGER.error("Task with taskId {} doesn't exist ", providedTaskId); return UNKNOWN_EXPECTED_SIZE; } catch (Exception e) { LOGGER.error("he task was dropped because of {} ", e.getMessage()); throw new TaskSubmissionException("The task was dropped while counting the files number because of " + e.getMessage()); } } DatasetFilesCounter(CassandraTaskInfoDAO taskInfoDAO); } | DatasetFilesCounter extends FilesCounter { public int getFilesCount(DpsTask task) throws TaskSubmissionException { String providedTaskId = task.getParameter(PluginParameterKeys.PREVIOUS_TASK_ID); if (providedTaskId==null) return UNKNOWN_EXPECTED_SIZE; try { long taskId = Long.parseLong(providedTaskId); TaskInfo taskInfo = taskInfoDAO.findById(taskId).orElseThrow(TaskInfoDoesNotExistException::new); return taskInfo.getProcessedElementCount(); } catch (NumberFormatException e) { LOGGER.error("The provided previous task id {} is not long ", providedTaskId); return UNKNOWN_EXPECTED_SIZE; } catch (TaskInfoDoesNotExistException e) { LOGGER.error("Task with taskId {} doesn't exist ", providedTaskId); return UNKNOWN_EXPECTED_SIZE; } catch (Exception e) { LOGGER.error("he task was dropped because of {} ", e.getMessage()); throw new TaskSubmissionException("The task was dropped while counting the files number because of " + e.getMessage()); } } DatasetFilesCounter(CassandraTaskInfoDAO taskInfoDAO); int getFilesCount(DpsTask task); } | DatasetFilesCounter extends FilesCounter { public int getFilesCount(DpsTask task) throws TaskSubmissionException { String providedTaskId = task.getParameter(PluginParameterKeys.PREVIOUS_TASK_ID); if (providedTaskId==null) return UNKNOWN_EXPECTED_SIZE; try { long taskId = Long.parseLong(providedTaskId); TaskInfo taskInfo = taskInfoDAO.findById(taskId).orElseThrow(TaskInfoDoesNotExistException::new); return taskInfo.getProcessedElementCount(); } catch (NumberFormatException e) { LOGGER.error("The provided previous task id {} is not long ", providedTaskId); return UNKNOWN_EXPECTED_SIZE; } catch (TaskInfoDoesNotExistException e) { LOGGER.error("Task with taskId {} doesn't exist ", providedTaskId); return UNKNOWN_EXPECTED_SIZE; } catch (Exception e) { LOGGER.error("he task was dropped because of {} ", e.getMessage()); throw new TaskSubmissionException("The task was dropped while counting the files number because of " + e.getMessage()); } } DatasetFilesCounter(CassandraTaskInfoDAO taskInfoDAO); int getFilesCount(DpsTask task); static final int UNKNOWN_EXPECTED_SIZE; } |
@Test public void shouldReturnedDefaultFilesCountWhenNoPreviousTaskIdIsProvided() throws Exception { int expectedFilesCount = datasetFilesCounter.getFilesCount(dpsTask); assertEquals(DEFAULT_FILES_COUNT, expectedFilesCount); } | public int getFilesCount(DpsTask task) throws TaskSubmissionException { String providedTaskId = task.getParameter(PluginParameterKeys.PREVIOUS_TASK_ID); if (providedTaskId==null) return UNKNOWN_EXPECTED_SIZE; try { long taskId = Long.parseLong(providedTaskId); TaskInfo taskInfo = taskInfoDAO.findById(taskId).orElseThrow(TaskInfoDoesNotExistException::new); return taskInfo.getProcessedElementCount(); } catch (NumberFormatException e) { LOGGER.error("The provided previous task id {} is not long ", providedTaskId); return UNKNOWN_EXPECTED_SIZE; } catch (TaskInfoDoesNotExistException e) { LOGGER.error("Task with taskId {} doesn't exist ", providedTaskId); return UNKNOWN_EXPECTED_SIZE; } catch (Exception e) { LOGGER.error("he task was dropped because of {} ", e.getMessage()); throw new TaskSubmissionException("The task was dropped while counting the files number because of " + e.getMessage()); } } | DatasetFilesCounter extends FilesCounter { public int getFilesCount(DpsTask task) throws TaskSubmissionException { String providedTaskId = task.getParameter(PluginParameterKeys.PREVIOUS_TASK_ID); if (providedTaskId==null) return UNKNOWN_EXPECTED_SIZE; try { long taskId = Long.parseLong(providedTaskId); TaskInfo taskInfo = taskInfoDAO.findById(taskId).orElseThrow(TaskInfoDoesNotExistException::new); return taskInfo.getProcessedElementCount(); } catch (NumberFormatException e) { LOGGER.error("The provided previous task id {} is not long ", providedTaskId); return UNKNOWN_EXPECTED_SIZE; } catch (TaskInfoDoesNotExistException e) { LOGGER.error("Task with taskId {} doesn't exist ", providedTaskId); return UNKNOWN_EXPECTED_SIZE; } catch (Exception e) { LOGGER.error("he task was dropped because of {} ", e.getMessage()); throw new TaskSubmissionException("The task was dropped while counting the files number because of " + e.getMessage()); } } } | DatasetFilesCounter extends FilesCounter { public int getFilesCount(DpsTask task) throws TaskSubmissionException { String providedTaskId = task.getParameter(PluginParameterKeys.PREVIOUS_TASK_ID); if (providedTaskId==null) return UNKNOWN_EXPECTED_SIZE; try { long taskId = Long.parseLong(providedTaskId); TaskInfo taskInfo = taskInfoDAO.findById(taskId).orElseThrow(TaskInfoDoesNotExistException::new); return taskInfo.getProcessedElementCount(); } catch (NumberFormatException e) { LOGGER.error("The provided previous task id {} is not long ", providedTaskId); return UNKNOWN_EXPECTED_SIZE; } catch (TaskInfoDoesNotExistException e) { LOGGER.error("Task with taskId {} doesn't exist ", providedTaskId); return UNKNOWN_EXPECTED_SIZE; } catch (Exception e) { LOGGER.error("he task was dropped because of {} ", e.getMessage()); throw new TaskSubmissionException("The task was dropped while counting the files number because of " + e.getMessage()); } } DatasetFilesCounter(CassandraTaskInfoDAO taskInfoDAO); } | DatasetFilesCounter extends FilesCounter { public int getFilesCount(DpsTask task) throws TaskSubmissionException { String providedTaskId = task.getParameter(PluginParameterKeys.PREVIOUS_TASK_ID); if (providedTaskId==null) return UNKNOWN_EXPECTED_SIZE; try { long taskId = Long.parseLong(providedTaskId); TaskInfo taskInfo = taskInfoDAO.findById(taskId).orElseThrow(TaskInfoDoesNotExistException::new); return taskInfo.getProcessedElementCount(); } catch (NumberFormatException e) { LOGGER.error("The provided previous task id {} is not long ", providedTaskId); return UNKNOWN_EXPECTED_SIZE; } catch (TaskInfoDoesNotExistException e) { LOGGER.error("Task with taskId {} doesn't exist ", providedTaskId); return UNKNOWN_EXPECTED_SIZE; } catch (Exception e) { LOGGER.error("he task was dropped because of {} ", e.getMessage()); throw new TaskSubmissionException("The task was dropped while counting the files number because of " + e.getMessage()); } } DatasetFilesCounter(CassandraTaskInfoDAO taskInfoDAO); int getFilesCount(DpsTask task); } | DatasetFilesCounter extends FilesCounter { public int getFilesCount(DpsTask task) throws TaskSubmissionException { String providedTaskId = task.getParameter(PluginParameterKeys.PREVIOUS_TASK_ID); if (providedTaskId==null) return UNKNOWN_EXPECTED_SIZE; try { long taskId = Long.parseLong(providedTaskId); TaskInfo taskInfo = taskInfoDAO.findById(taskId).orElseThrow(TaskInfoDoesNotExistException::new); return taskInfo.getProcessedElementCount(); } catch (NumberFormatException e) { LOGGER.error("The provided previous task id {} is not long ", providedTaskId); return UNKNOWN_EXPECTED_SIZE; } catch (TaskInfoDoesNotExistException e) { LOGGER.error("Task with taskId {} doesn't exist ", providedTaskId); return UNKNOWN_EXPECTED_SIZE; } catch (Exception e) { LOGGER.error("he task was dropped because of {} ", e.getMessage()); throw new TaskSubmissionException("The task was dropped while counting the files number because of " + e.getMessage()); } } DatasetFilesCounter(CassandraTaskInfoDAO taskInfoDAO); int getFilesCount(DpsTask task); static final int UNKNOWN_EXPECTED_SIZE; } |
@Test public void shouldReturnedDefaultFilesCountWhenPreviousTaskIdIsNotLongValue() throws Exception { int expectedFilesCount = datasetFilesCounter.getFilesCount(dpsTask); dpsTask.addParameter(PluginParameterKeys.PREVIOUS_TASK_ID, "Not long value"); assertEquals(DEFAULT_FILES_COUNT, expectedFilesCount); } | public int getFilesCount(DpsTask task) throws TaskSubmissionException { String providedTaskId = task.getParameter(PluginParameterKeys.PREVIOUS_TASK_ID); if (providedTaskId==null) return UNKNOWN_EXPECTED_SIZE; try { long taskId = Long.parseLong(providedTaskId); TaskInfo taskInfo = taskInfoDAO.findById(taskId).orElseThrow(TaskInfoDoesNotExistException::new); return taskInfo.getProcessedElementCount(); } catch (NumberFormatException e) { LOGGER.error("The provided previous task id {} is not long ", providedTaskId); return UNKNOWN_EXPECTED_SIZE; } catch (TaskInfoDoesNotExistException e) { LOGGER.error("Task with taskId {} doesn't exist ", providedTaskId); return UNKNOWN_EXPECTED_SIZE; } catch (Exception e) { LOGGER.error("he task was dropped because of {} ", e.getMessage()); throw new TaskSubmissionException("The task was dropped while counting the files number because of " + e.getMessage()); } } | DatasetFilesCounter extends FilesCounter { public int getFilesCount(DpsTask task) throws TaskSubmissionException { String providedTaskId = task.getParameter(PluginParameterKeys.PREVIOUS_TASK_ID); if (providedTaskId==null) return UNKNOWN_EXPECTED_SIZE; try { long taskId = Long.parseLong(providedTaskId); TaskInfo taskInfo = taskInfoDAO.findById(taskId).orElseThrow(TaskInfoDoesNotExistException::new); return taskInfo.getProcessedElementCount(); } catch (NumberFormatException e) { LOGGER.error("The provided previous task id {} is not long ", providedTaskId); return UNKNOWN_EXPECTED_SIZE; } catch (TaskInfoDoesNotExistException e) { LOGGER.error("Task with taskId {} doesn't exist ", providedTaskId); return UNKNOWN_EXPECTED_SIZE; } catch (Exception e) { LOGGER.error("he task was dropped because of {} ", e.getMessage()); throw new TaskSubmissionException("The task was dropped while counting the files number because of " + e.getMessage()); } } } | DatasetFilesCounter extends FilesCounter { public int getFilesCount(DpsTask task) throws TaskSubmissionException { String providedTaskId = task.getParameter(PluginParameterKeys.PREVIOUS_TASK_ID); if (providedTaskId==null) return UNKNOWN_EXPECTED_SIZE; try { long taskId = Long.parseLong(providedTaskId); TaskInfo taskInfo = taskInfoDAO.findById(taskId).orElseThrow(TaskInfoDoesNotExistException::new); return taskInfo.getProcessedElementCount(); } catch (NumberFormatException e) { LOGGER.error("The provided previous task id {} is not long ", providedTaskId); return UNKNOWN_EXPECTED_SIZE; } catch (TaskInfoDoesNotExistException e) { LOGGER.error("Task with taskId {} doesn't exist ", providedTaskId); return UNKNOWN_EXPECTED_SIZE; } catch (Exception e) { LOGGER.error("he task was dropped because of {} ", e.getMessage()); throw new TaskSubmissionException("The task was dropped while counting the files number because of " + e.getMessage()); } } DatasetFilesCounter(CassandraTaskInfoDAO taskInfoDAO); } | DatasetFilesCounter extends FilesCounter { public int getFilesCount(DpsTask task) throws TaskSubmissionException { String providedTaskId = task.getParameter(PluginParameterKeys.PREVIOUS_TASK_ID); if (providedTaskId==null) return UNKNOWN_EXPECTED_SIZE; try { long taskId = Long.parseLong(providedTaskId); TaskInfo taskInfo = taskInfoDAO.findById(taskId).orElseThrow(TaskInfoDoesNotExistException::new); return taskInfo.getProcessedElementCount(); } catch (NumberFormatException e) { LOGGER.error("The provided previous task id {} is not long ", providedTaskId); return UNKNOWN_EXPECTED_SIZE; } catch (TaskInfoDoesNotExistException e) { LOGGER.error("Task with taskId {} doesn't exist ", providedTaskId); return UNKNOWN_EXPECTED_SIZE; } catch (Exception e) { LOGGER.error("he task was dropped because of {} ", e.getMessage()); throw new TaskSubmissionException("The task was dropped while counting the files number because of " + e.getMessage()); } } DatasetFilesCounter(CassandraTaskInfoDAO taskInfoDAO); int getFilesCount(DpsTask task); } | DatasetFilesCounter extends FilesCounter { public int getFilesCount(DpsTask task) throws TaskSubmissionException { String providedTaskId = task.getParameter(PluginParameterKeys.PREVIOUS_TASK_ID); if (providedTaskId==null) return UNKNOWN_EXPECTED_SIZE; try { long taskId = Long.parseLong(providedTaskId); TaskInfo taskInfo = taskInfoDAO.findById(taskId).orElseThrow(TaskInfoDoesNotExistException::new); return taskInfo.getProcessedElementCount(); } catch (NumberFormatException e) { LOGGER.error("The provided previous task id {} is not long ", providedTaskId); return UNKNOWN_EXPECTED_SIZE; } catch (TaskInfoDoesNotExistException e) { LOGGER.error("Task with taskId {} doesn't exist ", providedTaskId); return UNKNOWN_EXPECTED_SIZE; } catch (Exception e) { LOGGER.error("he task was dropped because of {} ", e.getMessage()); throw new TaskSubmissionException("The task was dropped while counting the files number because of " + e.getMessage()); } } DatasetFilesCounter(CassandraTaskInfoDAO taskInfoDAO); int getFilesCount(DpsTask task); static final int UNKNOWN_EXPECTED_SIZE; } |
@Test public void shouldReturnedDefaultFilesCountWhenPreviousTaskIdDoesNotExist() throws Exception { dpsTask.addParameter(PluginParameterKeys.PREVIOUS_TASK_ID, String.valueOf(TASK_ID)); doReturn(Optional.empty()).when(taskInfoDAO).findById(TASK_ID); int expectedFilesCount = datasetFilesCounter.getFilesCount(dpsTask); assertEquals(DEFAULT_FILES_COUNT, expectedFilesCount); } | public int getFilesCount(DpsTask task) throws TaskSubmissionException { String providedTaskId = task.getParameter(PluginParameterKeys.PREVIOUS_TASK_ID); if (providedTaskId==null) return UNKNOWN_EXPECTED_SIZE; try { long taskId = Long.parseLong(providedTaskId); TaskInfo taskInfo = taskInfoDAO.findById(taskId).orElseThrow(TaskInfoDoesNotExistException::new); return taskInfo.getProcessedElementCount(); } catch (NumberFormatException e) { LOGGER.error("The provided previous task id {} is not long ", providedTaskId); return UNKNOWN_EXPECTED_SIZE; } catch (TaskInfoDoesNotExistException e) { LOGGER.error("Task with taskId {} doesn't exist ", providedTaskId); return UNKNOWN_EXPECTED_SIZE; } catch (Exception e) { LOGGER.error("he task was dropped because of {} ", e.getMessage()); throw new TaskSubmissionException("The task was dropped while counting the files number because of " + e.getMessage()); } } | DatasetFilesCounter extends FilesCounter { public int getFilesCount(DpsTask task) throws TaskSubmissionException { String providedTaskId = task.getParameter(PluginParameterKeys.PREVIOUS_TASK_ID); if (providedTaskId==null) return UNKNOWN_EXPECTED_SIZE; try { long taskId = Long.parseLong(providedTaskId); TaskInfo taskInfo = taskInfoDAO.findById(taskId).orElseThrow(TaskInfoDoesNotExistException::new); return taskInfo.getProcessedElementCount(); } catch (NumberFormatException e) { LOGGER.error("The provided previous task id {} is not long ", providedTaskId); return UNKNOWN_EXPECTED_SIZE; } catch (TaskInfoDoesNotExistException e) { LOGGER.error("Task with taskId {} doesn't exist ", providedTaskId); return UNKNOWN_EXPECTED_SIZE; } catch (Exception e) { LOGGER.error("he task was dropped because of {} ", e.getMessage()); throw new TaskSubmissionException("The task was dropped while counting the files number because of " + e.getMessage()); } } } | DatasetFilesCounter extends FilesCounter { public int getFilesCount(DpsTask task) throws TaskSubmissionException { String providedTaskId = task.getParameter(PluginParameterKeys.PREVIOUS_TASK_ID); if (providedTaskId==null) return UNKNOWN_EXPECTED_SIZE; try { long taskId = Long.parseLong(providedTaskId); TaskInfo taskInfo = taskInfoDAO.findById(taskId).orElseThrow(TaskInfoDoesNotExistException::new); return taskInfo.getProcessedElementCount(); } catch (NumberFormatException e) { LOGGER.error("The provided previous task id {} is not long ", providedTaskId); return UNKNOWN_EXPECTED_SIZE; } catch (TaskInfoDoesNotExistException e) { LOGGER.error("Task with taskId {} doesn't exist ", providedTaskId); return UNKNOWN_EXPECTED_SIZE; } catch (Exception e) { LOGGER.error("he task was dropped because of {} ", e.getMessage()); throw new TaskSubmissionException("The task was dropped while counting the files number because of " + e.getMessage()); } } DatasetFilesCounter(CassandraTaskInfoDAO taskInfoDAO); } | DatasetFilesCounter extends FilesCounter { public int getFilesCount(DpsTask task) throws TaskSubmissionException { String providedTaskId = task.getParameter(PluginParameterKeys.PREVIOUS_TASK_ID); if (providedTaskId==null) return UNKNOWN_EXPECTED_SIZE; try { long taskId = Long.parseLong(providedTaskId); TaskInfo taskInfo = taskInfoDAO.findById(taskId).orElseThrow(TaskInfoDoesNotExistException::new); return taskInfo.getProcessedElementCount(); } catch (NumberFormatException e) { LOGGER.error("The provided previous task id {} is not long ", providedTaskId); return UNKNOWN_EXPECTED_SIZE; } catch (TaskInfoDoesNotExistException e) { LOGGER.error("Task with taskId {} doesn't exist ", providedTaskId); return UNKNOWN_EXPECTED_SIZE; } catch (Exception e) { LOGGER.error("he task was dropped because of {} ", e.getMessage()); throw new TaskSubmissionException("The task was dropped while counting the files number because of " + e.getMessage()); } } DatasetFilesCounter(CassandraTaskInfoDAO taskInfoDAO); int getFilesCount(DpsTask task); } | DatasetFilesCounter extends FilesCounter { public int getFilesCount(DpsTask task) throws TaskSubmissionException { String providedTaskId = task.getParameter(PluginParameterKeys.PREVIOUS_TASK_ID); if (providedTaskId==null) return UNKNOWN_EXPECTED_SIZE; try { long taskId = Long.parseLong(providedTaskId); TaskInfo taskInfo = taskInfoDAO.findById(taskId).orElseThrow(TaskInfoDoesNotExistException::new); return taskInfo.getProcessedElementCount(); } catch (NumberFormatException e) { LOGGER.error("The provided previous task id {} is not long ", providedTaskId); return UNKNOWN_EXPECTED_SIZE; } catch (TaskInfoDoesNotExistException e) { LOGGER.error("Task with taskId {} doesn't exist ", providedTaskId); return UNKNOWN_EXPECTED_SIZE; } catch (Exception e) { LOGGER.error("he task was dropped because of {} ", e.getMessage()); throw new TaskSubmissionException("The task was dropped while counting the files number because of " + e.getMessage()); } } DatasetFilesCounter(CassandraTaskInfoDAO taskInfoDAO); int getFilesCount(DpsTask task); static final int UNKNOWN_EXPECTED_SIZE; } |
@Test(expected = TaskSubmissionException.class) public void shouldThrowExceptionWhenQueryingDatabaseUsingPreviousTaskIdThrowAnExceptionOtherThanTaskInfoDoesNotExistException() throws Exception { dpsTask.addParameter(PluginParameterKeys.PREVIOUS_TASK_ID, String.valueOf(TASK_ID)); doThrow(Exception.class).when(taskInfoDAO).findById(TASK_ID); datasetFilesCounter.getFilesCount(dpsTask); } | public int getFilesCount(DpsTask task) throws TaskSubmissionException { String providedTaskId = task.getParameter(PluginParameterKeys.PREVIOUS_TASK_ID); if (providedTaskId==null) return UNKNOWN_EXPECTED_SIZE; try { long taskId = Long.parseLong(providedTaskId); TaskInfo taskInfo = taskInfoDAO.findById(taskId).orElseThrow(TaskInfoDoesNotExistException::new); return taskInfo.getProcessedElementCount(); } catch (NumberFormatException e) { LOGGER.error("The provided previous task id {} is not long ", providedTaskId); return UNKNOWN_EXPECTED_SIZE; } catch (TaskInfoDoesNotExistException e) { LOGGER.error("Task with taskId {} doesn't exist ", providedTaskId); return UNKNOWN_EXPECTED_SIZE; } catch (Exception e) { LOGGER.error("he task was dropped because of {} ", e.getMessage()); throw new TaskSubmissionException("The task was dropped while counting the files number because of " + e.getMessage()); } } | DatasetFilesCounter extends FilesCounter { public int getFilesCount(DpsTask task) throws TaskSubmissionException { String providedTaskId = task.getParameter(PluginParameterKeys.PREVIOUS_TASK_ID); if (providedTaskId==null) return UNKNOWN_EXPECTED_SIZE; try { long taskId = Long.parseLong(providedTaskId); TaskInfo taskInfo = taskInfoDAO.findById(taskId).orElseThrow(TaskInfoDoesNotExistException::new); return taskInfo.getProcessedElementCount(); } catch (NumberFormatException e) { LOGGER.error("The provided previous task id {} is not long ", providedTaskId); return UNKNOWN_EXPECTED_SIZE; } catch (TaskInfoDoesNotExistException e) { LOGGER.error("Task with taskId {} doesn't exist ", providedTaskId); return UNKNOWN_EXPECTED_SIZE; } catch (Exception e) { LOGGER.error("he task was dropped because of {} ", e.getMessage()); throw new TaskSubmissionException("The task was dropped while counting the files number because of " + e.getMessage()); } } } | DatasetFilesCounter extends FilesCounter { public int getFilesCount(DpsTask task) throws TaskSubmissionException { String providedTaskId = task.getParameter(PluginParameterKeys.PREVIOUS_TASK_ID); if (providedTaskId==null) return UNKNOWN_EXPECTED_SIZE; try { long taskId = Long.parseLong(providedTaskId); TaskInfo taskInfo = taskInfoDAO.findById(taskId).orElseThrow(TaskInfoDoesNotExistException::new); return taskInfo.getProcessedElementCount(); } catch (NumberFormatException e) { LOGGER.error("The provided previous task id {} is not long ", providedTaskId); return UNKNOWN_EXPECTED_SIZE; } catch (TaskInfoDoesNotExistException e) { LOGGER.error("Task with taskId {} doesn't exist ", providedTaskId); return UNKNOWN_EXPECTED_SIZE; } catch (Exception e) { LOGGER.error("he task was dropped because of {} ", e.getMessage()); throw new TaskSubmissionException("The task was dropped while counting the files number because of " + e.getMessage()); } } DatasetFilesCounter(CassandraTaskInfoDAO taskInfoDAO); } | DatasetFilesCounter extends FilesCounter { public int getFilesCount(DpsTask task) throws TaskSubmissionException { String providedTaskId = task.getParameter(PluginParameterKeys.PREVIOUS_TASK_ID); if (providedTaskId==null) return UNKNOWN_EXPECTED_SIZE; try { long taskId = Long.parseLong(providedTaskId); TaskInfo taskInfo = taskInfoDAO.findById(taskId).orElseThrow(TaskInfoDoesNotExistException::new); return taskInfo.getProcessedElementCount(); } catch (NumberFormatException e) { LOGGER.error("The provided previous task id {} is not long ", providedTaskId); return UNKNOWN_EXPECTED_SIZE; } catch (TaskInfoDoesNotExistException e) { LOGGER.error("Task with taskId {} doesn't exist ", providedTaskId); return UNKNOWN_EXPECTED_SIZE; } catch (Exception e) { LOGGER.error("he task was dropped because of {} ", e.getMessage()); throw new TaskSubmissionException("The task was dropped while counting the files number because of " + e.getMessage()); } } DatasetFilesCounter(CassandraTaskInfoDAO taskInfoDAO); int getFilesCount(DpsTask task); } | DatasetFilesCounter extends FilesCounter { public int getFilesCount(DpsTask task) throws TaskSubmissionException { String providedTaskId = task.getParameter(PluginParameterKeys.PREVIOUS_TASK_ID); if (providedTaskId==null) return UNKNOWN_EXPECTED_SIZE; try { long taskId = Long.parseLong(providedTaskId); TaskInfo taskInfo = taskInfoDAO.findById(taskId).orElseThrow(TaskInfoDoesNotExistException::new); return taskInfo.getProcessedElementCount(); } catch (NumberFormatException e) { LOGGER.error("The provided previous task id {} is not long ", providedTaskId); return UNKNOWN_EXPECTED_SIZE; } catch (TaskInfoDoesNotExistException e) { LOGGER.error("Task with taskId {} doesn't exist ", providedTaskId); return UNKNOWN_EXPECTED_SIZE; } catch (Exception e) { LOGGER.error("he task was dropped because of {} ", e.getMessage()); throw new TaskSubmissionException("The task was dropped while counting the files number because of " + e.getMessage()); } } DatasetFilesCounter(CassandraTaskInfoDAO taskInfoDAO); int getFilesCount(DpsTask task); static final int UNKNOWN_EXPECTED_SIZE; } |
@Test public void shouldGetCorrectCompleteListSize() throws Exception { stubFor(get(urlEqualTo("/oai-phm/?verb=ListIdentifiers")) .willReturn(response200XmlContent(getFileContent("/oaiListIdentifiers.xml")))); OaiPmhFilesCounter counter = new OaiPmhFilesCounter(); OAIPMHHarvestingDetails details = new OAIPMHHarvestingDetails(null, null, null, null, null); DpsTask task = getDpsTask(details); assertEquals(2932, counter.getFilesCount(task)); } | @Override public int getFilesCount(DpsTask task) throws TaskSubmissionException { OAIPMHHarvestingDetails harvestingDetails = task.getHarvestingDetails(); if (harvestingDetails != null) { if (specified(harvestingDetails.getExcludedSets()) || specified(harvestingDetails.getExcludedSchemas())) { LOGGER.info("Cannot count completeListSize for taskId= {} . Excluded sets or schemas are not supported", task.getTaskId()); return DEFAULT_LIST_SIZE; } String repositoryUrl = getRepositoryUrl(task.getInputData()); if (repositoryUrl != null) { ListIdentifiersParameters params = new ListIdentifiersParameters() .withFrom(harvestingDetails.getDateFrom()) .withUntil(harvestingDetails.getDateUntil()); Set<String> schemas = harvestingDetails.getSchemas(); Set<String> sets = harvestingDetails.getSets(); if (specified(sets)) { if (sets.size() == 1) { params.withSetSpec(sets.iterator().next()); } else { LOGGER.info("Cannot count completeListSize for taskId= {} . Specifying multiple sets is not supported ", task.getTaskId()); return DEFAULT_LIST_SIZE; } } try { return getListSizeForSchemasAndSet(repositoryUrl, params, schemas); } catch (OAIResponseParseException e) { LOGGER.info("Cannot count completeListSize for taskId= {}", task.getTaskId(), e); return DEFAULT_LIST_SIZE; } catch (OAIRequestException e) { String logMessage = "Cannot complete the request for the following repository URL " + repositoryUrl; LOGGER.info(logMessage, e); throw new TaskSubmissionException(logMessage + " Because: " + e.getMessage(), e); } } else { throw new TaskSubmissionException("The task was dropped because the repositoryUrl can not be null"); } } else return DEFAULT_LIST_SIZE; } | OaiPmhFilesCounter extends FilesCounter { @Override public int getFilesCount(DpsTask task) throws TaskSubmissionException { OAIPMHHarvestingDetails harvestingDetails = task.getHarvestingDetails(); if (harvestingDetails != null) { if (specified(harvestingDetails.getExcludedSets()) || specified(harvestingDetails.getExcludedSchemas())) { LOGGER.info("Cannot count completeListSize for taskId= {} . Excluded sets or schemas are not supported", task.getTaskId()); return DEFAULT_LIST_SIZE; } String repositoryUrl = getRepositoryUrl(task.getInputData()); if (repositoryUrl != null) { ListIdentifiersParameters params = new ListIdentifiersParameters() .withFrom(harvestingDetails.getDateFrom()) .withUntil(harvestingDetails.getDateUntil()); Set<String> schemas = harvestingDetails.getSchemas(); Set<String> sets = harvestingDetails.getSets(); if (specified(sets)) { if (sets.size() == 1) { params.withSetSpec(sets.iterator().next()); } else { LOGGER.info("Cannot count completeListSize for taskId= {} . Specifying multiple sets is not supported ", task.getTaskId()); return DEFAULT_LIST_SIZE; } } try { return getListSizeForSchemasAndSet(repositoryUrl, params, schemas); } catch (OAIResponseParseException e) { LOGGER.info("Cannot count completeListSize for taskId= {}", task.getTaskId(), e); return DEFAULT_LIST_SIZE; } catch (OAIRequestException e) { String logMessage = "Cannot complete the request for the following repository URL " + repositoryUrl; LOGGER.info(logMessage, e); throw new TaskSubmissionException(logMessage + " Because: " + e.getMessage(), e); } } else { throw new TaskSubmissionException("The task was dropped because the repositoryUrl can not be null"); } } else return DEFAULT_LIST_SIZE; } } | OaiPmhFilesCounter extends FilesCounter { @Override public int getFilesCount(DpsTask task) throws TaskSubmissionException { OAIPMHHarvestingDetails harvestingDetails = task.getHarvestingDetails(); if (harvestingDetails != null) { if (specified(harvestingDetails.getExcludedSets()) || specified(harvestingDetails.getExcludedSchemas())) { LOGGER.info("Cannot count completeListSize for taskId= {} . Excluded sets or schemas are not supported", task.getTaskId()); return DEFAULT_LIST_SIZE; } String repositoryUrl = getRepositoryUrl(task.getInputData()); if (repositoryUrl != null) { ListIdentifiersParameters params = new ListIdentifiersParameters() .withFrom(harvestingDetails.getDateFrom()) .withUntil(harvestingDetails.getDateUntil()); Set<String> schemas = harvestingDetails.getSchemas(); Set<String> sets = harvestingDetails.getSets(); if (specified(sets)) { if (sets.size() == 1) { params.withSetSpec(sets.iterator().next()); } else { LOGGER.info("Cannot count completeListSize for taskId= {} . Specifying multiple sets is not supported ", task.getTaskId()); return DEFAULT_LIST_SIZE; } } try { return getListSizeForSchemasAndSet(repositoryUrl, params, schemas); } catch (OAIResponseParseException e) { LOGGER.info("Cannot count completeListSize for taskId= {}", task.getTaskId(), e); return DEFAULT_LIST_SIZE; } catch (OAIRequestException e) { String logMessage = "Cannot complete the request for the following repository URL " + repositoryUrl; LOGGER.info(logMessage, e); throw new TaskSubmissionException(logMessage + " Because: " + e.getMessage(), e); } } else { throw new TaskSubmissionException("The task was dropped because the repositoryUrl can not be null"); } } else return DEFAULT_LIST_SIZE; } } | OaiPmhFilesCounter extends FilesCounter { @Override public int getFilesCount(DpsTask task) throws TaskSubmissionException { OAIPMHHarvestingDetails harvestingDetails = task.getHarvestingDetails(); if (harvestingDetails != null) { if (specified(harvestingDetails.getExcludedSets()) || specified(harvestingDetails.getExcludedSchemas())) { LOGGER.info("Cannot count completeListSize for taskId= {} . Excluded sets or schemas are not supported", task.getTaskId()); return DEFAULT_LIST_SIZE; } String repositoryUrl = getRepositoryUrl(task.getInputData()); if (repositoryUrl != null) { ListIdentifiersParameters params = new ListIdentifiersParameters() .withFrom(harvestingDetails.getDateFrom()) .withUntil(harvestingDetails.getDateUntil()); Set<String> schemas = harvestingDetails.getSchemas(); Set<String> sets = harvestingDetails.getSets(); if (specified(sets)) { if (sets.size() == 1) { params.withSetSpec(sets.iterator().next()); } else { LOGGER.info("Cannot count completeListSize for taskId= {} . Specifying multiple sets is not supported ", task.getTaskId()); return DEFAULT_LIST_SIZE; } } try { return getListSizeForSchemasAndSet(repositoryUrl, params, schemas); } catch (OAIResponseParseException e) { LOGGER.info("Cannot count completeListSize for taskId= {}", task.getTaskId(), e); return DEFAULT_LIST_SIZE; } catch (OAIRequestException e) { String logMessage = "Cannot complete the request for the following repository URL " + repositoryUrl; LOGGER.info(logMessage, e); throw new TaskSubmissionException(logMessage + " Because: " + e.getMessage(), e); } } else { throw new TaskSubmissionException("The task was dropped because the repositoryUrl can not be null"); } } else return DEFAULT_LIST_SIZE; } @Override int getFilesCount(DpsTask task); } | OaiPmhFilesCounter extends FilesCounter { @Override public int getFilesCount(DpsTask task) throws TaskSubmissionException { OAIPMHHarvestingDetails harvestingDetails = task.getHarvestingDetails(); if (harvestingDetails != null) { if (specified(harvestingDetails.getExcludedSets()) || specified(harvestingDetails.getExcludedSchemas())) { LOGGER.info("Cannot count completeListSize for taskId= {} . Excluded sets or schemas are not supported", task.getTaskId()); return DEFAULT_LIST_SIZE; } String repositoryUrl = getRepositoryUrl(task.getInputData()); if (repositoryUrl != null) { ListIdentifiersParameters params = new ListIdentifiersParameters() .withFrom(harvestingDetails.getDateFrom()) .withUntil(harvestingDetails.getDateUntil()); Set<String> schemas = harvestingDetails.getSchemas(); Set<String> sets = harvestingDetails.getSets(); if (specified(sets)) { if (sets.size() == 1) { params.withSetSpec(sets.iterator().next()); } else { LOGGER.info("Cannot count completeListSize for taskId= {} . Specifying multiple sets is not supported ", task.getTaskId()); return DEFAULT_LIST_SIZE; } } try { return getListSizeForSchemasAndSet(repositoryUrl, params, schemas); } catch (OAIResponseParseException e) { LOGGER.info("Cannot count completeListSize for taskId= {}", task.getTaskId(), e); return DEFAULT_LIST_SIZE; } catch (OAIRequestException e) { String logMessage = "Cannot complete the request for the following repository URL " + repositoryUrl; LOGGER.info(logMessage, e); throw new TaskSubmissionException(logMessage + " Because: " + e.getMessage(), e); } } else { throw new TaskSubmissionException("The task was dropped because the repositoryUrl can not be null"); } } else return DEFAULT_LIST_SIZE; } @Override int getFilesCount(DpsTask task); static final String COMPLETE_LIST_SIZE; } |
@Test public void shouldReturnMinusOneWhenEmptyCompleteListSize() throws Exception { stubFor(get(urlEqualTo("/oai-phm/?verb=ListIdentifiers")) .willReturn(response200XmlContent(getFileContent("/oaiListIdentifiersNoCompleteListSize.xml")))); OaiPmhFilesCounter counter = new OaiPmhFilesCounter(); OAIPMHHarvestingDetails details = new OAIPMHHarvestingDetails(null, null, null, null,null ); DpsTask task = getDpsTask(details); assertEquals(-1, counter.getFilesCount(task)); } | @Override public int getFilesCount(DpsTask task) throws TaskSubmissionException { OAIPMHHarvestingDetails harvestingDetails = task.getHarvestingDetails(); if (harvestingDetails != null) { if (specified(harvestingDetails.getExcludedSets()) || specified(harvestingDetails.getExcludedSchemas())) { LOGGER.info("Cannot count completeListSize for taskId= {} . Excluded sets or schemas are not supported", task.getTaskId()); return DEFAULT_LIST_SIZE; } String repositoryUrl = getRepositoryUrl(task.getInputData()); if (repositoryUrl != null) { ListIdentifiersParameters params = new ListIdentifiersParameters() .withFrom(harvestingDetails.getDateFrom()) .withUntil(harvestingDetails.getDateUntil()); Set<String> schemas = harvestingDetails.getSchemas(); Set<String> sets = harvestingDetails.getSets(); if (specified(sets)) { if (sets.size() == 1) { params.withSetSpec(sets.iterator().next()); } else { LOGGER.info("Cannot count completeListSize for taskId= {} . Specifying multiple sets is not supported ", task.getTaskId()); return DEFAULT_LIST_SIZE; } } try { return getListSizeForSchemasAndSet(repositoryUrl, params, schemas); } catch (OAIResponseParseException e) { LOGGER.info("Cannot count completeListSize for taskId= {}", task.getTaskId(), e); return DEFAULT_LIST_SIZE; } catch (OAIRequestException e) { String logMessage = "Cannot complete the request for the following repository URL " + repositoryUrl; LOGGER.info(logMessage, e); throw new TaskSubmissionException(logMessage + " Because: " + e.getMessage(), e); } } else { throw new TaskSubmissionException("The task was dropped because the repositoryUrl can not be null"); } } else return DEFAULT_LIST_SIZE; } | OaiPmhFilesCounter extends FilesCounter { @Override public int getFilesCount(DpsTask task) throws TaskSubmissionException { OAIPMHHarvestingDetails harvestingDetails = task.getHarvestingDetails(); if (harvestingDetails != null) { if (specified(harvestingDetails.getExcludedSets()) || specified(harvestingDetails.getExcludedSchemas())) { LOGGER.info("Cannot count completeListSize for taskId= {} . Excluded sets or schemas are not supported", task.getTaskId()); return DEFAULT_LIST_SIZE; } String repositoryUrl = getRepositoryUrl(task.getInputData()); if (repositoryUrl != null) { ListIdentifiersParameters params = new ListIdentifiersParameters() .withFrom(harvestingDetails.getDateFrom()) .withUntil(harvestingDetails.getDateUntil()); Set<String> schemas = harvestingDetails.getSchemas(); Set<String> sets = harvestingDetails.getSets(); if (specified(sets)) { if (sets.size() == 1) { params.withSetSpec(sets.iterator().next()); } else { LOGGER.info("Cannot count completeListSize for taskId= {} . Specifying multiple sets is not supported ", task.getTaskId()); return DEFAULT_LIST_SIZE; } } try { return getListSizeForSchemasAndSet(repositoryUrl, params, schemas); } catch (OAIResponseParseException e) { LOGGER.info("Cannot count completeListSize for taskId= {}", task.getTaskId(), e); return DEFAULT_LIST_SIZE; } catch (OAIRequestException e) { String logMessage = "Cannot complete the request for the following repository URL " + repositoryUrl; LOGGER.info(logMessage, e); throw new TaskSubmissionException(logMessage + " Because: " + e.getMessage(), e); } } else { throw new TaskSubmissionException("The task was dropped because the repositoryUrl can not be null"); } } else return DEFAULT_LIST_SIZE; } } | OaiPmhFilesCounter extends FilesCounter { @Override public int getFilesCount(DpsTask task) throws TaskSubmissionException { OAIPMHHarvestingDetails harvestingDetails = task.getHarvestingDetails(); if (harvestingDetails != null) { if (specified(harvestingDetails.getExcludedSets()) || specified(harvestingDetails.getExcludedSchemas())) { LOGGER.info("Cannot count completeListSize for taskId= {} . Excluded sets or schemas are not supported", task.getTaskId()); return DEFAULT_LIST_SIZE; } String repositoryUrl = getRepositoryUrl(task.getInputData()); if (repositoryUrl != null) { ListIdentifiersParameters params = new ListIdentifiersParameters() .withFrom(harvestingDetails.getDateFrom()) .withUntil(harvestingDetails.getDateUntil()); Set<String> schemas = harvestingDetails.getSchemas(); Set<String> sets = harvestingDetails.getSets(); if (specified(sets)) { if (sets.size() == 1) { params.withSetSpec(sets.iterator().next()); } else { LOGGER.info("Cannot count completeListSize for taskId= {} . Specifying multiple sets is not supported ", task.getTaskId()); return DEFAULT_LIST_SIZE; } } try { return getListSizeForSchemasAndSet(repositoryUrl, params, schemas); } catch (OAIResponseParseException e) { LOGGER.info("Cannot count completeListSize for taskId= {}", task.getTaskId(), e); return DEFAULT_LIST_SIZE; } catch (OAIRequestException e) { String logMessage = "Cannot complete the request for the following repository URL " + repositoryUrl; LOGGER.info(logMessage, e); throw new TaskSubmissionException(logMessage + " Because: " + e.getMessage(), e); } } else { throw new TaskSubmissionException("The task was dropped because the repositoryUrl can not be null"); } } else return DEFAULT_LIST_SIZE; } } | OaiPmhFilesCounter extends FilesCounter { @Override public int getFilesCount(DpsTask task) throws TaskSubmissionException { OAIPMHHarvestingDetails harvestingDetails = task.getHarvestingDetails(); if (harvestingDetails != null) { if (specified(harvestingDetails.getExcludedSets()) || specified(harvestingDetails.getExcludedSchemas())) { LOGGER.info("Cannot count completeListSize for taskId= {} . Excluded sets or schemas are not supported", task.getTaskId()); return DEFAULT_LIST_SIZE; } String repositoryUrl = getRepositoryUrl(task.getInputData()); if (repositoryUrl != null) { ListIdentifiersParameters params = new ListIdentifiersParameters() .withFrom(harvestingDetails.getDateFrom()) .withUntil(harvestingDetails.getDateUntil()); Set<String> schemas = harvestingDetails.getSchemas(); Set<String> sets = harvestingDetails.getSets(); if (specified(sets)) { if (sets.size() == 1) { params.withSetSpec(sets.iterator().next()); } else { LOGGER.info("Cannot count completeListSize for taskId= {} . Specifying multiple sets is not supported ", task.getTaskId()); return DEFAULT_LIST_SIZE; } } try { return getListSizeForSchemasAndSet(repositoryUrl, params, schemas); } catch (OAIResponseParseException e) { LOGGER.info("Cannot count completeListSize for taskId= {}", task.getTaskId(), e); return DEFAULT_LIST_SIZE; } catch (OAIRequestException e) { String logMessage = "Cannot complete the request for the following repository URL " + repositoryUrl; LOGGER.info(logMessage, e); throw new TaskSubmissionException(logMessage + " Because: " + e.getMessage(), e); } } else { throw new TaskSubmissionException("The task was dropped because the repositoryUrl can not be null"); } } else return DEFAULT_LIST_SIZE; } @Override int getFilesCount(DpsTask task); } | OaiPmhFilesCounter extends FilesCounter { @Override public int getFilesCount(DpsTask task) throws TaskSubmissionException { OAIPMHHarvestingDetails harvestingDetails = task.getHarvestingDetails(); if (harvestingDetails != null) { if (specified(harvestingDetails.getExcludedSets()) || specified(harvestingDetails.getExcludedSchemas())) { LOGGER.info("Cannot count completeListSize for taskId= {} . Excluded sets or schemas are not supported", task.getTaskId()); return DEFAULT_LIST_SIZE; } String repositoryUrl = getRepositoryUrl(task.getInputData()); if (repositoryUrl != null) { ListIdentifiersParameters params = new ListIdentifiersParameters() .withFrom(harvestingDetails.getDateFrom()) .withUntil(harvestingDetails.getDateUntil()); Set<String> schemas = harvestingDetails.getSchemas(); Set<String> sets = harvestingDetails.getSets(); if (specified(sets)) { if (sets.size() == 1) { params.withSetSpec(sets.iterator().next()); } else { LOGGER.info("Cannot count completeListSize for taskId= {} . Specifying multiple sets is not supported ", task.getTaskId()); return DEFAULT_LIST_SIZE; } } try { return getListSizeForSchemasAndSet(repositoryUrl, params, schemas); } catch (OAIResponseParseException e) { LOGGER.info("Cannot count completeListSize for taskId= {}", task.getTaskId(), e); return DEFAULT_LIST_SIZE; } catch (OAIRequestException e) { String logMessage = "Cannot complete the request for the following repository URL " + repositoryUrl; LOGGER.info(logMessage, e); throw new TaskSubmissionException(logMessage + " Because: " + e.getMessage(), e); } } else { throw new TaskSubmissionException("The task was dropped because the repositoryUrl can not be null"); } } else return DEFAULT_LIST_SIZE; } @Override int getFilesCount(DpsTask task); static final String COMPLETE_LIST_SIZE; } |
@Test public void shouldReturnMinusOneWhenIncorrectCompleteListSize() throws Exception { stubFor(get(urlEqualTo("/oai-phm/?verb=ListIdentifiers")) .willReturn(response200XmlContent(getFileContent("/oaiListIdentifiersIncorrectCompleteListSize.xml")))); OaiPmhFilesCounter counter = new OaiPmhFilesCounter(); OAIPMHHarvestingDetails details = new OAIPMHHarvestingDetails(null, null, null, null, null); DpsTask task = getDpsTask(details); assertEquals(-1, counter.getFilesCount(task)); } | @Override public int getFilesCount(DpsTask task) throws TaskSubmissionException { OAIPMHHarvestingDetails harvestingDetails = task.getHarvestingDetails(); if (harvestingDetails != null) { if (specified(harvestingDetails.getExcludedSets()) || specified(harvestingDetails.getExcludedSchemas())) { LOGGER.info("Cannot count completeListSize for taskId= {} . Excluded sets or schemas are not supported", task.getTaskId()); return DEFAULT_LIST_SIZE; } String repositoryUrl = getRepositoryUrl(task.getInputData()); if (repositoryUrl != null) { ListIdentifiersParameters params = new ListIdentifiersParameters() .withFrom(harvestingDetails.getDateFrom()) .withUntil(harvestingDetails.getDateUntil()); Set<String> schemas = harvestingDetails.getSchemas(); Set<String> sets = harvestingDetails.getSets(); if (specified(sets)) { if (sets.size() == 1) { params.withSetSpec(sets.iterator().next()); } else { LOGGER.info("Cannot count completeListSize for taskId= {} . Specifying multiple sets is not supported ", task.getTaskId()); return DEFAULT_LIST_SIZE; } } try { return getListSizeForSchemasAndSet(repositoryUrl, params, schemas); } catch (OAIResponseParseException e) { LOGGER.info("Cannot count completeListSize for taskId= {}", task.getTaskId(), e); return DEFAULT_LIST_SIZE; } catch (OAIRequestException e) { String logMessage = "Cannot complete the request for the following repository URL " + repositoryUrl; LOGGER.info(logMessage, e); throw new TaskSubmissionException(logMessage + " Because: " + e.getMessage(), e); } } else { throw new TaskSubmissionException("The task was dropped because the repositoryUrl can not be null"); } } else return DEFAULT_LIST_SIZE; } | OaiPmhFilesCounter extends FilesCounter { @Override public int getFilesCount(DpsTask task) throws TaskSubmissionException { OAIPMHHarvestingDetails harvestingDetails = task.getHarvestingDetails(); if (harvestingDetails != null) { if (specified(harvestingDetails.getExcludedSets()) || specified(harvestingDetails.getExcludedSchemas())) { LOGGER.info("Cannot count completeListSize for taskId= {} . Excluded sets or schemas are not supported", task.getTaskId()); return DEFAULT_LIST_SIZE; } String repositoryUrl = getRepositoryUrl(task.getInputData()); if (repositoryUrl != null) { ListIdentifiersParameters params = new ListIdentifiersParameters() .withFrom(harvestingDetails.getDateFrom()) .withUntil(harvestingDetails.getDateUntil()); Set<String> schemas = harvestingDetails.getSchemas(); Set<String> sets = harvestingDetails.getSets(); if (specified(sets)) { if (sets.size() == 1) { params.withSetSpec(sets.iterator().next()); } else { LOGGER.info("Cannot count completeListSize for taskId= {} . Specifying multiple sets is not supported ", task.getTaskId()); return DEFAULT_LIST_SIZE; } } try { return getListSizeForSchemasAndSet(repositoryUrl, params, schemas); } catch (OAIResponseParseException e) { LOGGER.info("Cannot count completeListSize for taskId= {}", task.getTaskId(), e); return DEFAULT_LIST_SIZE; } catch (OAIRequestException e) { String logMessage = "Cannot complete the request for the following repository URL " + repositoryUrl; LOGGER.info(logMessage, e); throw new TaskSubmissionException(logMessage + " Because: " + e.getMessage(), e); } } else { throw new TaskSubmissionException("The task was dropped because the repositoryUrl can not be null"); } } else return DEFAULT_LIST_SIZE; } } | OaiPmhFilesCounter extends FilesCounter { @Override public int getFilesCount(DpsTask task) throws TaskSubmissionException { OAIPMHHarvestingDetails harvestingDetails = task.getHarvestingDetails(); if (harvestingDetails != null) { if (specified(harvestingDetails.getExcludedSets()) || specified(harvestingDetails.getExcludedSchemas())) { LOGGER.info("Cannot count completeListSize for taskId= {} . Excluded sets or schemas are not supported", task.getTaskId()); return DEFAULT_LIST_SIZE; } String repositoryUrl = getRepositoryUrl(task.getInputData()); if (repositoryUrl != null) { ListIdentifiersParameters params = new ListIdentifiersParameters() .withFrom(harvestingDetails.getDateFrom()) .withUntil(harvestingDetails.getDateUntil()); Set<String> schemas = harvestingDetails.getSchemas(); Set<String> sets = harvestingDetails.getSets(); if (specified(sets)) { if (sets.size() == 1) { params.withSetSpec(sets.iterator().next()); } else { LOGGER.info("Cannot count completeListSize for taskId= {} . Specifying multiple sets is not supported ", task.getTaskId()); return DEFAULT_LIST_SIZE; } } try { return getListSizeForSchemasAndSet(repositoryUrl, params, schemas); } catch (OAIResponseParseException e) { LOGGER.info("Cannot count completeListSize for taskId= {}", task.getTaskId(), e); return DEFAULT_LIST_SIZE; } catch (OAIRequestException e) { String logMessage = "Cannot complete the request for the following repository URL " + repositoryUrl; LOGGER.info(logMessage, e); throw new TaskSubmissionException(logMessage + " Because: " + e.getMessage(), e); } } else { throw new TaskSubmissionException("The task was dropped because the repositoryUrl can not be null"); } } else return DEFAULT_LIST_SIZE; } } | OaiPmhFilesCounter extends FilesCounter { @Override public int getFilesCount(DpsTask task) throws TaskSubmissionException { OAIPMHHarvestingDetails harvestingDetails = task.getHarvestingDetails(); if (harvestingDetails != null) { if (specified(harvestingDetails.getExcludedSets()) || specified(harvestingDetails.getExcludedSchemas())) { LOGGER.info("Cannot count completeListSize for taskId= {} . Excluded sets or schemas are not supported", task.getTaskId()); return DEFAULT_LIST_SIZE; } String repositoryUrl = getRepositoryUrl(task.getInputData()); if (repositoryUrl != null) { ListIdentifiersParameters params = new ListIdentifiersParameters() .withFrom(harvestingDetails.getDateFrom()) .withUntil(harvestingDetails.getDateUntil()); Set<String> schemas = harvestingDetails.getSchemas(); Set<String> sets = harvestingDetails.getSets(); if (specified(sets)) { if (sets.size() == 1) { params.withSetSpec(sets.iterator().next()); } else { LOGGER.info("Cannot count completeListSize for taskId= {} . Specifying multiple sets is not supported ", task.getTaskId()); return DEFAULT_LIST_SIZE; } } try { return getListSizeForSchemasAndSet(repositoryUrl, params, schemas); } catch (OAIResponseParseException e) { LOGGER.info("Cannot count completeListSize for taskId= {}", task.getTaskId(), e); return DEFAULT_LIST_SIZE; } catch (OAIRequestException e) { String logMessage = "Cannot complete the request for the following repository URL " + repositoryUrl; LOGGER.info(logMessage, e); throw new TaskSubmissionException(logMessage + " Because: " + e.getMessage(), e); } } else { throw new TaskSubmissionException("The task was dropped because the repositoryUrl can not be null"); } } else return DEFAULT_LIST_SIZE; } @Override int getFilesCount(DpsTask task); } | OaiPmhFilesCounter extends FilesCounter { @Override public int getFilesCount(DpsTask task) throws TaskSubmissionException { OAIPMHHarvestingDetails harvestingDetails = task.getHarvestingDetails(); if (harvestingDetails != null) { if (specified(harvestingDetails.getExcludedSets()) || specified(harvestingDetails.getExcludedSchemas())) { LOGGER.info("Cannot count completeListSize for taskId= {} . Excluded sets or schemas are not supported", task.getTaskId()); return DEFAULT_LIST_SIZE; } String repositoryUrl = getRepositoryUrl(task.getInputData()); if (repositoryUrl != null) { ListIdentifiersParameters params = new ListIdentifiersParameters() .withFrom(harvestingDetails.getDateFrom()) .withUntil(harvestingDetails.getDateUntil()); Set<String> schemas = harvestingDetails.getSchemas(); Set<String> sets = harvestingDetails.getSets(); if (specified(sets)) { if (sets.size() == 1) { params.withSetSpec(sets.iterator().next()); } else { LOGGER.info("Cannot count completeListSize for taskId= {} . Specifying multiple sets is not supported ", task.getTaskId()); return DEFAULT_LIST_SIZE; } } try { return getListSizeForSchemasAndSet(repositoryUrl, params, schemas); } catch (OAIResponseParseException e) { LOGGER.info("Cannot count completeListSize for taskId= {}", task.getTaskId(), e); return DEFAULT_LIST_SIZE; } catch (OAIRequestException e) { String logMessage = "Cannot complete the request for the following repository URL " + repositoryUrl; LOGGER.info(logMessage, e); throw new TaskSubmissionException(logMessage + " Because: " + e.getMessage(), e); } } else { throw new TaskSubmissionException("The task was dropped because the repositoryUrl can not be null"); } } else return DEFAULT_LIST_SIZE; } @Override int getFilesCount(DpsTask task); static final String COMPLETE_LIST_SIZE; } |
@Test public void shouldReturnMinusOneWhen200ReturnedButErrorInResponse() throws Exception { stubFor(get(urlEqualTo("/oai-phm/?verb=ListIdentifiers")) .willReturn(response200XmlContent(getFileContent("/oaiListIdentifiersIncorrectMetadataPrefix.xml")))); OaiPmhFilesCounter counter = new OaiPmhFilesCounter(); OAIPMHHarvestingDetails details = new OAIPMHHarvestingDetails(null, null, null, null, null); DpsTask task = getDpsTask(details); assertEquals(-1, counter.getFilesCount(task)); } | @Override public int getFilesCount(DpsTask task) throws TaskSubmissionException { OAIPMHHarvestingDetails harvestingDetails = task.getHarvestingDetails(); if (harvestingDetails != null) { if (specified(harvestingDetails.getExcludedSets()) || specified(harvestingDetails.getExcludedSchemas())) { LOGGER.info("Cannot count completeListSize for taskId= {} . Excluded sets or schemas are not supported", task.getTaskId()); return DEFAULT_LIST_SIZE; } String repositoryUrl = getRepositoryUrl(task.getInputData()); if (repositoryUrl != null) { ListIdentifiersParameters params = new ListIdentifiersParameters() .withFrom(harvestingDetails.getDateFrom()) .withUntil(harvestingDetails.getDateUntil()); Set<String> schemas = harvestingDetails.getSchemas(); Set<String> sets = harvestingDetails.getSets(); if (specified(sets)) { if (sets.size() == 1) { params.withSetSpec(sets.iterator().next()); } else { LOGGER.info("Cannot count completeListSize for taskId= {} . Specifying multiple sets is not supported ", task.getTaskId()); return DEFAULT_LIST_SIZE; } } try { return getListSizeForSchemasAndSet(repositoryUrl, params, schemas); } catch (OAIResponseParseException e) { LOGGER.info("Cannot count completeListSize for taskId= {}", task.getTaskId(), e); return DEFAULT_LIST_SIZE; } catch (OAIRequestException e) { String logMessage = "Cannot complete the request for the following repository URL " + repositoryUrl; LOGGER.info(logMessage, e); throw new TaskSubmissionException(logMessage + " Because: " + e.getMessage(), e); } } else { throw new TaskSubmissionException("The task was dropped because the repositoryUrl can not be null"); } } else return DEFAULT_LIST_SIZE; } | OaiPmhFilesCounter extends FilesCounter { @Override public int getFilesCount(DpsTask task) throws TaskSubmissionException { OAIPMHHarvestingDetails harvestingDetails = task.getHarvestingDetails(); if (harvestingDetails != null) { if (specified(harvestingDetails.getExcludedSets()) || specified(harvestingDetails.getExcludedSchemas())) { LOGGER.info("Cannot count completeListSize for taskId= {} . Excluded sets or schemas are not supported", task.getTaskId()); return DEFAULT_LIST_SIZE; } String repositoryUrl = getRepositoryUrl(task.getInputData()); if (repositoryUrl != null) { ListIdentifiersParameters params = new ListIdentifiersParameters() .withFrom(harvestingDetails.getDateFrom()) .withUntil(harvestingDetails.getDateUntil()); Set<String> schemas = harvestingDetails.getSchemas(); Set<String> sets = harvestingDetails.getSets(); if (specified(sets)) { if (sets.size() == 1) { params.withSetSpec(sets.iterator().next()); } else { LOGGER.info("Cannot count completeListSize for taskId= {} . Specifying multiple sets is not supported ", task.getTaskId()); return DEFAULT_LIST_SIZE; } } try { return getListSizeForSchemasAndSet(repositoryUrl, params, schemas); } catch (OAIResponseParseException e) { LOGGER.info("Cannot count completeListSize for taskId= {}", task.getTaskId(), e); return DEFAULT_LIST_SIZE; } catch (OAIRequestException e) { String logMessage = "Cannot complete the request for the following repository URL " + repositoryUrl; LOGGER.info(logMessage, e); throw new TaskSubmissionException(logMessage + " Because: " + e.getMessage(), e); } } else { throw new TaskSubmissionException("The task was dropped because the repositoryUrl can not be null"); } } else return DEFAULT_LIST_SIZE; } } | OaiPmhFilesCounter extends FilesCounter { @Override public int getFilesCount(DpsTask task) throws TaskSubmissionException { OAIPMHHarvestingDetails harvestingDetails = task.getHarvestingDetails(); if (harvestingDetails != null) { if (specified(harvestingDetails.getExcludedSets()) || specified(harvestingDetails.getExcludedSchemas())) { LOGGER.info("Cannot count completeListSize for taskId= {} . Excluded sets or schemas are not supported", task.getTaskId()); return DEFAULT_LIST_SIZE; } String repositoryUrl = getRepositoryUrl(task.getInputData()); if (repositoryUrl != null) { ListIdentifiersParameters params = new ListIdentifiersParameters() .withFrom(harvestingDetails.getDateFrom()) .withUntil(harvestingDetails.getDateUntil()); Set<String> schemas = harvestingDetails.getSchemas(); Set<String> sets = harvestingDetails.getSets(); if (specified(sets)) { if (sets.size() == 1) { params.withSetSpec(sets.iterator().next()); } else { LOGGER.info("Cannot count completeListSize for taskId= {} . Specifying multiple sets is not supported ", task.getTaskId()); return DEFAULT_LIST_SIZE; } } try { return getListSizeForSchemasAndSet(repositoryUrl, params, schemas); } catch (OAIResponseParseException e) { LOGGER.info("Cannot count completeListSize for taskId= {}", task.getTaskId(), e); return DEFAULT_LIST_SIZE; } catch (OAIRequestException e) { String logMessage = "Cannot complete the request for the following repository URL " + repositoryUrl; LOGGER.info(logMessage, e); throw new TaskSubmissionException(logMessage + " Because: " + e.getMessage(), e); } } else { throw new TaskSubmissionException("The task was dropped because the repositoryUrl can not be null"); } } else return DEFAULT_LIST_SIZE; } } | OaiPmhFilesCounter extends FilesCounter { @Override public int getFilesCount(DpsTask task) throws TaskSubmissionException { OAIPMHHarvestingDetails harvestingDetails = task.getHarvestingDetails(); if (harvestingDetails != null) { if (specified(harvestingDetails.getExcludedSets()) || specified(harvestingDetails.getExcludedSchemas())) { LOGGER.info("Cannot count completeListSize for taskId= {} . Excluded sets or schemas are not supported", task.getTaskId()); return DEFAULT_LIST_SIZE; } String repositoryUrl = getRepositoryUrl(task.getInputData()); if (repositoryUrl != null) { ListIdentifiersParameters params = new ListIdentifiersParameters() .withFrom(harvestingDetails.getDateFrom()) .withUntil(harvestingDetails.getDateUntil()); Set<String> schemas = harvestingDetails.getSchemas(); Set<String> sets = harvestingDetails.getSets(); if (specified(sets)) { if (sets.size() == 1) { params.withSetSpec(sets.iterator().next()); } else { LOGGER.info("Cannot count completeListSize for taskId= {} . Specifying multiple sets is not supported ", task.getTaskId()); return DEFAULT_LIST_SIZE; } } try { return getListSizeForSchemasAndSet(repositoryUrl, params, schemas); } catch (OAIResponseParseException e) { LOGGER.info("Cannot count completeListSize for taskId= {}", task.getTaskId(), e); return DEFAULT_LIST_SIZE; } catch (OAIRequestException e) { String logMessage = "Cannot complete the request for the following repository URL " + repositoryUrl; LOGGER.info(logMessage, e); throw new TaskSubmissionException(logMessage + " Because: " + e.getMessage(), e); } } else { throw new TaskSubmissionException("The task was dropped because the repositoryUrl can not be null"); } } else return DEFAULT_LIST_SIZE; } @Override int getFilesCount(DpsTask task); } | OaiPmhFilesCounter extends FilesCounter { @Override public int getFilesCount(DpsTask task) throws TaskSubmissionException { OAIPMHHarvestingDetails harvestingDetails = task.getHarvestingDetails(); if (harvestingDetails != null) { if (specified(harvestingDetails.getExcludedSets()) || specified(harvestingDetails.getExcludedSchemas())) { LOGGER.info("Cannot count completeListSize for taskId= {} . Excluded sets or schemas are not supported", task.getTaskId()); return DEFAULT_LIST_SIZE; } String repositoryUrl = getRepositoryUrl(task.getInputData()); if (repositoryUrl != null) { ListIdentifiersParameters params = new ListIdentifiersParameters() .withFrom(harvestingDetails.getDateFrom()) .withUntil(harvestingDetails.getDateUntil()); Set<String> schemas = harvestingDetails.getSchemas(); Set<String> sets = harvestingDetails.getSets(); if (specified(sets)) { if (sets.size() == 1) { params.withSetSpec(sets.iterator().next()); } else { LOGGER.info("Cannot count completeListSize for taskId= {} . Specifying multiple sets is not supported ", task.getTaskId()); return DEFAULT_LIST_SIZE; } } try { return getListSizeForSchemasAndSet(repositoryUrl, params, schemas); } catch (OAIResponseParseException e) { LOGGER.info("Cannot count completeListSize for taskId= {}", task.getTaskId(), e); return DEFAULT_LIST_SIZE; } catch (OAIRequestException e) { String logMessage = "Cannot complete the request for the following repository URL " + repositoryUrl; LOGGER.info(logMessage, e); throw new TaskSubmissionException(logMessage + " Because: " + e.getMessage(), e); } } else { throw new TaskSubmissionException("The task was dropped because the repositoryUrl can not be null"); } } else return DEFAULT_LIST_SIZE; } @Override int getFilesCount(DpsTask task); static final String COMPLETE_LIST_SIZE; } |
@Test public void shouldThrowAnExceptionWithCorrectMessage() throws Exception { ResultSet resultSet = mock(ResultSet.class); when(resultSet.one()).thenReturn(rows.get(0)); when(resultSet.one().getLong("count")).thenReturn(0l); final Session session = mock(Session.class); when(session.execute(matchingBoundStatement)).thenReturn(resultSet); PreparedStatement preparedStatement = mock(PreparedStatement.class); when(matchingBoundStatement.preparedStatement()).thenReturn(preparedStatement); when(preparedStatement.getQueryString()).thenReturn("Select count(*) From TableName"); final RowsValidatorJob job = new RowsValidatorJob(session, primaryKeys, matchingBoundStatement, rows); try { job.call(); } catch (Exception e) { assertEquals("The data doesn't fully match!. The exception was thrown for this query: Select count(*) From TableName Using these values(Item1)", e.getMessage()); } verify(session, times(5)).execute(any(BoundStatement.class)); } | @Override public Void call() throws Exception { validateRows(); return null; } | RowsValidatorJob implements Callable<Void> { @Override public Void call() throws Exception { validateRows(); return null; } } | RowsValidatorJob implements Callable<Void> { @Override public Void call() throws Exception { validateRows(); return null; } RowsValidatorJob(Session session, List<String> primaryKeys, BoundStatement matchingBoundStatement, List<Row> rows); } | RowsValidatorJob implements Callable<Void> { @Override public Void call() throws Exception { validateRows(); return null; } RowsValidatorJob(Session session, List<String> primaryKeys, BoundStatement matchingBoundStatement, List<Row> rows); @Override Void call(); } | RowsValidatorJob implements Callable<Void> { @Override public Void call() throws Exception { validateRows(); return null; } RowsValidatorJob(Session session, List<String> primaryKeys, BoundStatement matchingBoundStatement, List<Row> rows); @Override Void call(); } |
@Test public void shouldReturnMinusOneWhenNoResumptionToken() throws Exception { stubFor(get(urlEqualTo("/oai-phm/?verb=ListIdentifiers")) .willReturn(response200XmlContent(getFileContent("/oaiListIdentifiersNoResumptionToken.xml")))); OaiPmhFilesCounter counter = new OaiPmhFilesCounter(); OAIPMHHarvestingDetails details = new OAIPMHHarvestingDetails(null, null, null, null, null); DpsTask task = getDpsTask(details); assertEquals(-1, counter.getFilesCount(task)); } | @Override public int getFilesCount(DpsTask task) throws TaskSubmissionException { OAIPMHHarvestingDetails harvestingDetails = task.getHarvestingDetails(); if (harvestingDetails != null) { if (specified(harvestingDetails.getExcludedSets()) || specified(harvestingDetails.getExcludedSchemas())) { LOGGER.info("Cannot count completeListSize for taskId= {} . Excluded sets or schemas are not supported", task.getTaskId()); return DEFAULT_LIST_SIZE; } String repositoryUrl = getRepositoryUrl(task.getInputData()); if (repositoryUrl != null) { ListIdentifiersParameters params = new ListIdentifiersParameters() .withFrom(harvestingDetails.getDateFrom()) .withUntil(harvestingDetails.getDateUntil()); Set<String> schemas = harvestingDetails.getSchemas(); Set<String> sets = harvestingDetails.getSets(); if (specified(sets)) { if (sets.size() == 1) { params.withSetSpec(sets.iterator().next()); } else { LOGGER.info("Cannot count completeListSize for taskId= {} . Specifying multiple sets is not supported ", task.getTaskId()); return DEFAULT_LIST_SIZE; } } try { return getListSizeForSchemasAndSet(repositoryUrl, params, schemas); } catch (OAIResponseParseException e) { LOGGER.info("Cannot count completeListSize for taskId= {}", task.getTaskId(), e); return DEFAULT_LIST_SIZE; } catch (OAIRequestException e) { String logMessage = "Cannot complete the request for the following repository URL " + repositoryUrl; LOGGER.info(logMessage, e); throw new TaskSubmissionException(logMessage + " Because: " + e.getMessage(), e); } } else { throw new TaskSubmissionException("The task was dropped because the repositoryUrl can not be null"); } } else return DEFAULT_LIST_SIZE; } | OaiPmhFilesCounter extends FilesCounter { @Override public int getFilesCount(DpsTask task) throws TaskSubmissionException { OAIPMHHarvestingDetails harvestingDetails = task.getHarvestingDetails(); if (harvestingDetails != null) { if (specified(harvestingDetails.getExcludedSets()) || specified(harvestingDetails.getExcludedSchemas())) { LOGGER.info("Cannot count completeListSize for taskId= {} . Excluded sets or schemas are not supported", task.getTaskId()); return DEFAULT_LIST_SIZE; } String repositoryUrl = getRepositoryUrl(task.getInputData()); if (repositoryUrl != null) { ListIdentifiersParameters params = new ListIdentifiersParameters() .withFrom(harvestingDetails.getDateFrom()) .withUntil(harvestingDetails.getDateUntil()); Set<String> schemas = harvestingDetails.getSchemas(); Set<String> sets = harvestingDetails.getSets(); if (specified(sets)) { if (sets.size() == 1) { params.withSetSpec(sets.iterator().next()); } else { LOGGER.info("Cannot count completeListSize for taskId= {} . Specifying multiple sets is not supported ", task.getTaskId()); return DEFAULT_LIST_SIZE; } } try { return getListSizeForSchemasAndSet(repositoryUrl, params, schemas); } catch (OAIResponseParseException e) { LOGGER.info("Cannot count completeListSize for taskId= {}", task.getTaskId(), e); return DEFAULT_LIST_SIZE; } catch (OAIRequestException e) { String logMessage = "Cannot complete the request for the following repository URL " + repositoryUrl; LOGGER.info(logMessage, e); throw new TaskSubmissionException(logMessage + " Because: " + e.getMessage(), e); } } else { throw new TaskSubmissionException("The task was dropped because the repositoryUrl can not be null"); } } else return DEFAULT_LIST_SIZE; } } | OaiPmhFilesCounter extends FilesCounter { @Override public int getFilesCount(DpsTask task) throws TaskSubmissionException { OAIPMHHarvestingDetails harvestingDetails = task.getHarvestingDetails(); if (harvestingDetails != null) { if (specified(harvestingDetails.getExcludedSets()) || specified(harvestingDetails.getExcludedSchemas())) { LOGGER.info("Cannot count completeListSize for taskId= {} . Excluded sets or schemas are not supported", task.getTaskId()); return DEFAULT_LIST_SIZE; } String repositoryUrl = getRepositoryUrl(task.getInputData()); if (repositoryUrl != null) { ListIdentifiersParameters params = new ListIdentifiersParameters() .withFrom(harvestingDetails.getDateFrom()) .withUntil(harvestingDetails.getDateUntil()); Set<String> schemas = harvestingDetails.getSchemas(); Set<String> sets = harvestingDetails.getSets(); if (specified(sets)) { if (sets.size() == 1) { params.withSetSpec(sets.iterator().next()); } else { LOGGER.info("Cannot count completeListSize for taskId= {} . Specifying multiple sets is not supported ", task.getTaskId()); return DEFAULT_LIST_SIZE; } } try { return getListSizeForSchemasAndSet(repositoryUrl, params, schemas); } catch (OAIResponseParseException e) { LOGGER.info("Cannot count completeListSize for taskId= {}", task.getTaskId(), e); return DEFAULT_LIST_SIZE; } catch (OAIRequestException e) { String logMessage = "Cannot complete the request for the following repository URL " + repositoryUrl; LOGGER.info(logMessage, e); throw new TaskSubmissionException(logMessage + " Because: " + e.getMessage(), e); } } else { throw new TaskSubmissionException("The task was dropped because the repositoryUrl can not be null"); } } else return DEFAULT_LIST_SIZE; } } | OaiPmhFilesCounter extends FilesCounter { @Override public int getFilesCount(DpsTask task) throws TaskSubmissionException { OAIPMHHarvestingDetails harvestingDetails = task.getHarvestingDetails(); if (harvestingDetails != null) { if (specified(harvestingDetails.getExcludedSets()) || specified(harvestingDetails.getExcludedSchemas())) { LOGGER.info("Cannot count completeListSize for taskId= {} . Excluded sets or schemas are not supported", task.getTaskId()); return DEFAULT_LIST_SIZE; } String repositoryUrl = getRepositoryUrl(task.getInputData()); if (repositoryUrl != null) { ListIdentifiersParameters params = new ListIdentifiersParameters() .withFrom(harvestingDetails.getDateFrom()) .withUntil(harvestingDetails.getDateUntil()); Set<String> schemas = harvestingDetails.getSchemas(); Set<String> sets = harvestingDetails.getSets(); if (specified(sets)) { if (sets.size() == 1) { params.withSetSpec(sets.iterator().next()); } else { LOGGER.info("Cannot count completeListSize for taskId= {} . Specifying multiple sets is not supported ", task.getTaskId()); return DEFAULT_LIST_SIZE; } } try { return getListSizeForSchemasAndSet(repositoryUrl, params, schemas); } catch (OAIResponseParseException e) { LOGGER.info("Cannot count completeListSize for taskId= {}", task.getTaskId(), e); return DEFAULT_LIST_SIZE; } catch (OAIRequestException e) { String logMessage = "Cannot complete the request for the following repository URL " + repositoryUrl; LOGGER.info(logMessage, e); throw new TaskSubmissionException(logMessage + " Because: " + e.getMessage(), e); } } else { throw new TaskSubmissionException("The task was dropped because the repositoryUrl can not be null"); } } else return DEFAULT_LIST_SIZE; } @Override int getFilesCount(DpsTask task); } | OaiPmhFilesCounter extends FilesCounter { @Override public int getFilesCount(DpsTask task) throws TaskSubmissionException { OAIPMHHarvestingDetails harvestingDetails = task.getHarvestingDetails(); if (harvestingDetails != null) { if (specified(harvestingDetails.getExcludedSets()) || specified(harvestingDetails.getExcludedSchemas())) { LOGGER.info("Cannot count completeListSize for taskId= {} . Excluded sets or schemas are not supported", task.getTaskId()); return DEFAULT_LIST_SIZE; } String repositoryUrl = getRepositoryUrl(task.getInputData()); if (repositoryUrl != null) { ListIdentifiersParameters params = new ListIdentifiersParameters() .withFrom(harvestingDetails.getDateFrom()) .withUntil(harvestingDetails.getDateUntil()); Set<String> schemas = harvestingDetails.getSchemas(); Set<String> sets = harvestingDetails.getSets(); if (specified(sets)) { if (sets.size() == 1) { params.withSetSpec(sets.iterator().next()); } else { LOGGER.info("Cannot count completeListSize for taskId= {} . Specifying multiple sets is not supported ", task.getTaskId()); return DEFAULT_LIST_SIZE; } } try { return getListSizeForSchemasAndSet(repositoryUrl, params, schemas); } catch (OAIResponseParseException e) { LOGGER.info("Cannot count completeListSize for taskId= {}", task.getTaskId(), e); return DEFAULT_LIST_SIZE; } catch (OAIRequestException e) { String logMessage = "Cannot complete the request for the following repository URL " + repositoryUrl; LOGGER.info(logMessage, e); throw new TaskSubmissionException(logMessage + " Because: " + e.getMessage(), e); } } else { throw new TaskSubmissionException("The task was dropped because the repositoryUrl can not be null"); } } else return DEFAULT_LIST_SIZE; } @Override int getFilesCount(DpsTask task); static final String COMPLETE_LIST_SIZE; } |
@Test(expected = TaskSubmissionException.class) public void shouldRetry10TimesAndFail() throws Exception { stubFor(get(urlEqualTo("/oai-phm/?verb=ListIdentifiers")).inScenario("Retry and fail scenario") .willReturn(response404())); OaiPmhFilesCounter counter = new OaiPmhFilesCounter(); OAIPMHHarvestingDetails details = new OAIPMHHarvestingDetails(null, null, null, null, null); DpsTask task = getDpsTask(details); counter.getFilesCount(task); } | @Override public int getFilesCount(DpsTask task) throws TaskSubmissionException { OAIPMHHarvestingDetails harvestingDetails = task.getHarvestingDetails(); if (harvestingDetails != null) { if (specified(harvestingDetails.getExcludedSets()) || specified(harvestingDetails.getExcludedSchemas())) { LOGGER.info("Cannot count completeListSize for taskId= {} . Excluded sets or schemas are not supported", task.getTaskId()); return DEFAULT_LIST_SIZE; } String repositoryUrl = getRepositoryUrl(task.getInputData()); if (repositoryUrl != null) { ListIdentifiersParameters params = new ListIdentifiersParameters() .withFrom(harvestingDetails.getDateFrom()) .withUntil(harvestingDetails.getDateUntil()); Set<String> schemas = harvestingDetails.getSchemas(); Set<String> sets = harvestingDetails.getSets(); if (specified(sets)) { if (sets.size() == 1) { params.withSetSpec(sets.iterator().next()); } else { LOGGER.info("Cannot count completeListSize for taskId= {} . Specifying multiple sets is not supported ", task.getTaskId()); return DEFAULT_LIST_SIZE; } } try { return getListSizeForSchemasAndSet(repositoryUrl, params, schemas); } catch (OAIResponseParseException e) { LOGGER.info("Cannot count completeListSize for taskId= {}", task.getTaskId(), e); return DEFAULT_LIST_SIZE; } catch (OAIRequestException e) { String logMessage = "Cannot complete the request for the following repository URL " + repositoryUrl; LOGGER.info(logMessage, e); throw new TaskSubmissionException(logMessage + " Because: " + e.getMessage(), e); } } else { throw new TaskSubmissionException("The task was dropped because the repositoryUrl can not be null"); } } else return DEFAULT_LIST_SIZE; } | OaiPmhFilesCounter extends FilesCounter { @Override public int getFilesCount(DpsTask task) throws TaskSubmissionException { OAIPMHHarvestingDetails harvestingDetails = task.getHarvestingDetails(); if (harvestingDetails != null) { if (specified(harvestingDetails.getExcludedSets()) || specified(harvestingDetails.getExcludedSchemas())) { LOGGER.info("Cannot count completeListSize for taskId= {} . Excluded sets or schemas are not supported", task.getTaskId()); return DEFAULT_LIST_SIZE; } String repositoryUrl = getRepositoryUrl(task.getInputData()); if (repositoryUrl != null) { ListIdentifiersParameters params = new ListIdentifiersParameters() .withFrom(harvestingDetails.getDateFrom()) .withUntil(harvestingDetails.getDateUntil()); Set<String> schemas = harvestingDetails.getSchemas(); Set<String> sets = harvestingDetails.getSets(); if (specified(sets)) { if (sets.size() == 1) { params.withSetSpec(sets.iterator().next()); } else { LOGGER.info("Cannot count completeListSize for taskId= {} . Specifying multiple sets is not supported ", task.getTaskId()); return DEFAULT_LIST_SIZE; } } try { return getListSizeForSchemasAndSet(repositoryUrl, params, schemas); } catch (OAIResponseParseException e) { LOGGER.info("Cannot count completeListSize for taskId= {}", task.getTaskId(), e); return DEFAULT_LIST_SIZE; } catch (OAIRequestException e) { String logMessage = "Cannot complete the request for the following repository URL " + repositoryUrl; LOGGER.info(logMessage, e); throw new TaskSubmissionException(logMessage + " Because: " + e.getMessage(), e); } } else { throw new TaskSubmissionException("The task was dropped because the repositoryUrl can not be null"); } } else return DEFAULT_LIST_SIZE; } } | OaiPmhFilesCounter extends FilesCounter { @Override public int getFilesCount(DpsTask task) throws TaskSubmissionException { OAIPMHHarvestingDetails harvestingDetails = task.getHarvestingDetails(); if (harvestingDetails != null) { if (specified(harvestingDetails.getExcludedSets()) || specified(harvestingDetails.getExcludedSchemas())) { LOGGER.info("Cannot count completeListSize for taskId= {} . Excluded sets or schemas are not supported", task.getTaskId()); return DEFAULT_LIST_SIZE; } String repositoryUrl = getRepositoryUrl(task.getInputData()); if (repositoryUrl != null) { ListIdentifiersParameters params = new ListIdentifiersParameters() .withFrom(harvestingDetails.getDateFrom()) .withUntil(harvestingDetails.getDateUntil()); Set<String> schemas = harvestingDetails.getSchemas(); Set<String> sets = harvestingDetails.getSets(); if (specified(sets)) { if (sets.size() == 1) { params.withSetSpec(sets.iterator().next()); } else { LOGGER.info("Cannot count completeListSize for taskId= {} . Specifying multiple sets is not supported ", task.getTaskId()); return DEFAULT_LIST_SIZE; } } try { return getListSizeForSchemasAndSet(repositoryUrl, params, schemas); } catch (OAIResponseParseException e) { LOGGER.info("Cannot count completeListSize for taskId= {}", task.getTaskId(), e); return DEFAULT_LIST_SIZE; } catch (OAIRequestException e) { String logMessage = "Cannot complete the request for the following repository URL " + repositoryUrl; LOGGER.info(logMessage, e); throw new TaskSubmissionException(logMessage + " Because: " + e.getMessage(), e); } } else { throw new TaskSubmissionException("The task was dropped because the repositoryUrl can not be null"); } } else return DEFAULT_LIST_SIZE; } } | OaiPmhFilesCounter extends FilesCounter { @Override public int getFilesCount(DpsTask task) throws TaskSubmissionException { OAIPMHHarvestingDetails harvestingDetails = task.getHarvestingDetails(); if (harvestingDetails != null) { if (specified(harvestingDetails.getExcludedSets()) || specified(harvestingDetails.getExcludedSchemas())) { LOGGER.info("Cannot count completeListSize for taskId= {} . Excluded sets or schemas are not supported", task.getTaskId()); return DEFAULT_LIST_SIZE; } String repositoryUrl = getRepositoryUrl(task.getInputData()); if (repositoryUrl != null) { ListIdentifiersParameters params = new ListIdentifiersParameters() .withFrom(harvestingDetails.getDateFrom()) .withUntil(harvestingDetails.getDateUntil()); Set<String> schemas = harvestingDetails.getSchemas(); Set<String> sets = harvestingDetails.getSets(); if (specified(sets)) { if (sets.size() == 1) { params.withSetSpec(sets.iterator().next()); } else { LOGGER.info("Cannot count completeListSize for taskId= {} . Specifying multiple sets is not supported ", task.getTaskId()); return DEFAULT_LIST_SIZE; } } try { return getListSizeForSchemasAndSet(repositoryUrl, params, schemas); } catch (OAIResponseParseException e) { LOGGER.info("Cannot count completeListSize for taskId= {}", task.getTaskId(), e); return DEFAULT_LIST_SIZE; } catch (OAIRequestException e) { String logMessage = "Cannot complete the request for the following repository URL " + repositoryUrl; LOGGER.info(logMessage, e); throw new TaskSubmissionException(logMessage + " Because: " + e.getMessage(), e); } } else { throw new TaskSubmissionException("The task was dropped because the repositoryUrl can not be null"); } } else return DEFAULT_LIST_SIZE; } @Override int getFilesCount(DpsTask task); } | OaiPmhFilesCounter extends FilesCounter { @Override public int getFilesCount(DpsTask task) throws TaskSubmissionException { OAIPMHHarvestingDetails harvestingDetails = task.getHarvestingDetails(); if (harvestingDetails != null) { if (specified(harvestingDetails.getExcludedSets()) || specified(harvestingDetails.getExcludedSchemas())) { LOGGER.info("Cannot count completeListSize for taskId= {} . Excluded sets or schemas are not supported", task.getTaskId()); return DEFAULT_LIST_SIZE; } String repositoryUrl = getRepositoryUrl(task.getInputData()); if (repositoryUrl != null) { ListIdentifiersParameters params = new ListIdentifiersParameters() .withFrom(harvestingDetails.getDateFrom()) .withUntil(harvestingDetails.getDateUntil()); Set<String> schemas = harvestingDetails.getSchemas(); Set<String> sets = harvestingDetails.getSets(); if (specified(sets)) { if (sets.size() == 1) { params.withSetSpec(sets.iterator().next()); } else { LOGGER.info("Cannot count completeListSize for taskId= {} . Specifying multiple sets is not supported ", task.getTaskId()); return DEFAULT_LIST_SIZE; } } try { return getListSizeForSchemasAndSet(repositoryUrl, params, schemas); } catch (OAIResponseParseException e) { LOGGER.info("Cannot count completeListSize for taskId= {}", task.getTaskId(), e); return DEFAULT_LIST_SIZE; } catch (OAIRequestException e) { String logMessage = "Cannot complete the request for the following repository URL " + repositoryUrl; LOGGER.info(logMessage, e); throw new TaskSubmissionException(logMessage + " Because: " + e.getMessage(), e); } } else { throw new TaskSubmissionException("The task was dropped because the repositoryUrl can not be null"); } } else return DEFAULT_LIST_SIZE; } @Override int getFilesCount(DpsTask task); static final String COMPLETE_LIST_SIZE; } |
@Test public void shouldRetryAndReturnACorrectValue() throws Exception { stubFor(get(urlEqualTo("/oai-phm/?verb=ListIdentifiers")).inScenario("Retry and success scenario").whenScenarioStateIs(STARTED).willSetStateTo("one time requested") .willReturn(response404())); stubFor(get(urlEqualTo("/oai-phm/?verb=ListIdentifiers")).inScenario("Retry and success scenario").whenScenarioStateIs("one time requested") .willReturn(response200XmlContent(getFileContent("/oaiListIdentifiers.xml")))); OaiPmhFilesCounter counter = new OaiPmhFilesCounter(); OAIPMHHarvestingDetails details = new OAIPMHHarvestingDetails(null, null, null, null, null); DpsTask task = getDpsTask(details); assertEquals(2932, counter.getFilesCount(task)); } | @Override public int getFilesCount(DpsTask task) throws TaskSubmissionException { OAIPMHHarvestingDetails harvestingDetails = task.getHarvestingDetails(); if (harvestingDetails != null) { if (specified(harvestingDetails.getExcludedSets()) || specified(harvestingDetails.getExcludedSchemas())) { LOGGER.info("Cannot count completeListSize for taskId= {} . Excluded sets or schemas are not supported", task.getTaskId()); return DEFAULT_LIST_SIZE; } String repositoryUrl = getRepositoryUrl(task.getInputData()); if (repositoryUrl != null) { ListIdentifiersParameters params = new ListIdentifiersParameters() .withFrom(harvestingDetails.getDateFrom()) .withUntil(harvestingDetails.getDateUntil()); Set<String> schemas = harvestingDetails.getSchemas(); Set<String> sets = harvestingDetails.getSets(); if (specified(sets)) { if (sets.size() == 1) { params.withSetSpec(sets.iterator().next()); } else { LOGGER.info("Cannot count completeListSize for taskId= {} . Specifying multiple sets is not supported ", task.getTaskId()); return DEFAULT_LIST_SIZE; } } try { return getListSizeForSchemasAndSet(repositoryUrl, params, schemas); } catch (OAIResponseParseException e) { LOGGER.info("Cannot count completeListSize for taskId= {}", task.getTaskId(), e); return DEFAULT_LIST_SIZE; } catch (OAIRequestException e) { String logMessage = "Cannot complete the request for the following repository URL " + repositoryUrl; LOGGER.info(logMessage, e); throw new TaskSubmissionException(logMessage + " Because: " + e.getMessage(), e); } } else { throw new TaskSubmissionException("The task was dropped because the repositoryUrl can not be null"); } } else return DEFAULT_LIST_SIZE; } | OaiPmhFilesCounter extends FilesCounter { @Override public int getFilesCount(DpsTask task) throws TaskSubmissionException { OAIPMHHarvestingDetails harvestingDetails = task.getHarvestingDetails(); if (harvestingDetails != null) { if (specified(harvestingDetails.getExcludedSets()) || specified(harvestingDetails.getExcludedSchemas())) { LOGGER.info("Cannot count completeListSize for taskId= {} . Excluded sets or schemas are not supported", task.getTaskId()); return DEFAULT_LIST_SIZE; } String repositoryUrl = getRepositoryUrl(task.getInputData()); if (repositoryUrl != null) { ListIdentifiersParameters params = new ListIdentifiersParameters() .withFrom(harvestingDetails.getDateFrom()) .withUntil(harvestingDetails.getDateUntil()); Set<String> schemas = harvestingDetails.getSchemas(); Set<String> sets = harvestingDetails.getSets(); if (specified(sets)) { if (sets.size() == 1) { params.withSetSpec(sets.iterator().next()); } else { LOGGER.info("Cannot count completeListSize for taskId= {} . Specifying multiple sets is not supported ", task.getTaskId()); return DEFAULT_LIST_SIZE; } } try { return getListSizeForSchemasAndSet(repositoryUrl, params, schemas); } catch (OAIResponseParseException e) { LOGGER.info("Cannot count completeListSize for taskId= {}", task.getTaskId(), e); return DEFAULT_LIST_SIZE; } catch (OAIRequestException e) { String logMessage = "Cannot complete the request for the following repository URL " + repositoryUrl; LOGGER.info(logMessage, e); throw new TaskSubmissionException(logMessage + " Because: " + e.getMessage(), e); } } else { throw new TaskSubmissionException("The task was dropped because the repositoryUrl can not be null"); } } else return DEFAULT_LIST_SIZE; } } | OaiPmhFilesCounter extends FilesCounter { @Override public int getFilesCount(DpsTask task) throws TaskSubmissionException { OAIPMHHarvestingDetails harvestingDetails = task.getHarvestingDetails(); if (harvestingDetails != null) { if (specified(harvestingDetails.getExcludedSets()) || specified(harvestingDetails.getExcludedSchemas())) { LOGGER.info("Cannot count completeListSize for taskId= {} . Excluded sets or schemas are not supported", task.getTaskId()); return DEFAULT_LIST_SIZE; } String repositoryUrl = getRepositoryUrl(task.getInputData()); if (repositoryUrl != null) { ListIdentifiersParameters params = new ListIdentifiersParameters() .withFrom(harvestingDetails.getDateFrom()) .withUntil(harvestingDetails.getDateUntil()); Set<String> schemas = harvestingDetails.getSchemas(); Set<String> sets = harvestingDetails.getSets(); if (specified(sets)) { if (sets.size() == 1) { params.withSetSpec(sets.iterator().next()); } else { LOGGER.info("Cannot count completeListSize for taskId= {} . Specifying multiple sets is not supported ", task.getTaskId()); return DEFAULT_LIST_SIZE; } } try { return getListSizeForSchemasAndSet(repositoryUrl, params, schemas); } catch (OAIResponseParseException e) { LOGGER.info("Cannot count completeListSize for taskId= {}", task.getTaskId(), e); return DEFAULT_LIST_SIZE; } catch (OAIRequestException e) { String logMessage = "Cannot complete the request for the following repository URL " + repositoryUrl; LOGGER.info(logMessage, e); throw new TaskSubmissionException(logMessage + " Because: " + e.getMessage(), e); } } else { throw new TaskSubmissionException("The task was dropped because the repositoryUrl can not be null"); } } else return DEFAULT_LIST_SIZE; } } | OaiPmhFilesCounter extends FilesCounter { @Override public int getFilesCount(DpsTask task) throws TaskSubmissionException { OAIPMHHarvestingDetails harvestingDetails = task.getHarvestingDetails(); if (harvestingDetails != null) { if (specified(harvestingDetails.getExcludedSets()) || specified(harvestingDetails.getExcludedSchemas())) { LOGGER.info("Cannot count completeListSize for taskId= {} . Excluded sets or schemas are not supported", task.getTaskId()); return DEFAULT_LIST_SIZE; } String repositoryUrl = getRepositoryUrl(task.getInputData()); if (repositoryUrl != null) { ListIdentifiersParameters params = new ListIdentifiersParameters() .withFrom(harvestingDetails.getDateFrom()) .withUntil(harvestingDetails.getDateUntil()); Set<String> schemas = harvestingDetails.getSchemas(); Set<String> sets = harvestingDetails.getSets(); if (specified(sets)) { if (sets.size() == 1) { params.withSetSpec(sets.iterator().next()); } else { LOGGER.info("Cannot count completeListSize for taskId= {} . Specifying multiple sets is not supported ", task.getTaskId()); return DEFAULT_LIST_SIZE; } } try { return getListSizeForSchemasAndSet(repositoryUrl, params, schemas); } catch (OAIResponseParseException e) { LOGGER.info("Cannot count completeListSize for taskId= {}", task.getTaskId(), e); return DEFAULT_LIST_SIZE; } catch (OAIRequestException e) { String logMessage = "Cannot complete the request for the following repository URL " + repositoryUrl; LOGGER.info(logMessage, e); throw new TaskSubmissionException(logMessage + " Because: " + e.getMessage(), e); } } else { throw new TaskSubmissionException("The task was dropped because the repositoryUrl can not be null"); } } else return DEFAULT_LIST_SIZE; } @Override int getFilesCount(DpsTask task); } | OaiPmhFilesCounter extends FilesCounter { @Override public int getFilesCount(DpsTask task) throws TaskSubmissionException { OAIPMHHarvestingDetails harvestingDetails = task.getHarvestingDetails(); if (harvestingDetails != null) { if (specified(harvestingDetails.getExcludedSets()) || specified(harvestingDetails.getExcludedSchemas())) { LOGGER.info("Cannot count completeListSize for taskId= {} . Excluded sets or schemas are not supported", task.getTaskId()); return DEFAULT_LIST_SIZE; } String repositoryUrl = getRepositoryUrl(task.getInputData()); if (repositoryUrl != null) { ListIdentifiersParameters params = new ListIdentifiersParameters() .withFrom(harvestingDetails.getDateFrom()) .withUntil(harvestingDetails.getDateUntil()); Set<String> schemas = harvestingDetails.getSchemas(); Set<String> sets = harvestingDetails.getSets(); if (specified(sets)) { if (sets.size() == 1) { params.withSetSpec(sets.iterator().next()); } else { LOGGER.info("Cannot count completeListSize for taskId= {} . Specifying multiple sets is not supported ", task.getTaskId()); return DEFAULT_LIST_SIZE; } } try { return getListSizeForSchemasAndSet(repositoryUrl, params, schemas); } catch (OAIResponseParseException e) { LOGGER.info("Cannot count completeListSize for taskId= {}", task.getTaskId(), e); return DEFAULT_LIST_SIZE; } catch (OAIRequestException e) { String logMessage = "Cannot complete the request for the following repository URL " + repositoryUrl; LOGGER.info(logMessage, e); throw new TaskSubmissionException(logMessage + " Because: " + e.getMessage(), e); } } else { throw new TaskSubmissionException("The task was dropped because the repositoryUrl can not be null"); } } else return DEFAULT_LIST_SIZE; } @Override int getFilesCount(DpsTask task); static final String COMPLETE_LIST_SIZE; } |
@Test public void shouldReturnCorrectSumWhenSchemasAndSetListed() throws Exception { String schema1 = "schema1"; String schema2 = "schema2"; String set1 = "set1"; stubFor(get(urlEqualTo("/oai-phm/?verb=ListIdentifiers&set=" + set1 + "&metadataPrefix=" + schema1)) .willReturn(response200XmlContent(getFileContent("/oaiListIdentifiers.xml")))); stubFor(get(urlEqualTo("/oai-phm/?verb=ListIdentifiers&set=" + set1 + "&metadataPrefix=" + schema2)) .willReturn(response200XmlContent(getFileContent("/oaiListIdentifiers2.xml")))); OaiPmhFilesCounter counter = new OaiPmhFilesCounter(); OAIPMHHarvestingDetails details = new OAIPMHHarvestingDetails(Sets.newHashSet(schema1, schema2), Sets.newHashSet(set1), null, null, null); DpsTask task = getDpsTask(details); assertEquals(2934, counter.getFilesCount(task)); } | @Override public int getFilesCount(DpsTask task) throws TaskSubmissionException { OAIPMHHarvestingDetails harvestingDetails = task.getHarvestingDetails(); if (harvestingDetails != null) { if (specified(harvestingDetails.getExcludedSets()) || specified(harvestingDetails.getExcludedSchemas())) { LOGGER.info("Cannot count completeListSize for taskId= {} . Excluded sets or schemas are not supported", task.getTaskId()); return DEFAULT_LIST_SIZE; } String repositoryUrl = getRepositoryUrl(task.getInputData()); if (repositoryUrl != null) { ListIdentifiersParameters params = new ListIdentifiersParameters() .withFrom(harvestingDetails.getDateFrom()) .withUntil(harvestingDetails.getDateUntil()); Set<String> schemas = harvestingDetails.getSchemas(); Set<String> sets = harvestingDetails.getSets(); if (specified(sets)) { if (sets.size() == 1) { params.withSetSpec(sets.iterator().next()); } else { LOGGER.info("Cannot count completeListSize for taskId= {} . Specifying multiple sets is not supported ", task.getTaskId()); return DEFAULT_LIST_SIZE; } } try { return getListSizeForSchemasAndSet(repositoryUrl, params, schemas); } catch (OAIResponseParseException e) { LOGGER.info("Cannot count completeListSize for taskId= {}", task.getTaskId(), e); return DEFAULT_LIST_SIZE; } catch (OAIRequestException e) { String logMessage = "Cannot complete the request for the following repository URL " + repositoryUrl; LOGGER.info(logMessage, e); throw new TaskSubmissionException(logMessage + " Because: " + e.getMessage(), e); } } else { throw new TaskSubmissionException("The task was dropped because the repositoryUrl can not be null"); } } else return DEFAULT_LIST_SIZE; } | OaiPmhFilesCounter extends FilesCounter { @Override public int getFilesCount(DpsTask task) throws TaskSubmissionException { OAIPMHHarvestingDetails harvestingDetails = task.getHarvestingDetails(); if (harvestingDetails != null) { if (specified(harvestingDetails.getExcludedSets()) || specified(harvestingDetails.getExcludedSchemas())) { LOGGER.info("Cannot count completeListSize for taskId= {} . Excluded sets or schemas are not supported", task.getTaskId()); return DEFAULT_LIST_SIZE; } String repositoryUrl = getRepositoryUrl(task.getInputData()); if (repositoryUrl != null) { ListIdentifiersParameters params = new ListIdentifiersParameters() .withFrom(harvestingDetails.getDateFrom()) .withUntil(harvestingDetails.getDateUntil()); Set<String> schemas = harvestingDetails.getSchemas(); Set<String> sets = harvestingDetails.getSets(); if (specified(sets)) { if (sets.size() == 1) { params.withSetSpec(sets.iterator().next()); } else { LOGGER.info("Cannot count completeListSize for taskId= {} . Specifying multiple sets is not supported ", task.getTaskId()); return DEFAULT_LIST_SIZE; } } try { return getListSizeForSchemasAndSet(repositoryUrl, params, schemas); } catch (OAIResponseParseException e) { LOGGER.info("Cannot count completeListSize for taskId= {}", task.getTaskId(), e); return DEFAULT_LIST_SIZE; } catch (OAIRequestException e) { String logMessage = "Cannot complete the request for the following repository URL " + repositoryUrl; LOGGER.info(logMessage, e); throw new TaskSubmissionException(logMessage + " Because: " + e.getMessage(), e); } } else { throw new TaskSubmissionException("The task was dropped because the repositoryUrl can not be null"); } } else return DEFAULT_LIST_SIZE; } } | OaiPmhFilesCounter extends FilesCounter { @Override public int getFilesCount(DpsTask task) throws TaskSubmissionException { OAIPMHHarvestingDetails harvestingDetails = task.getHarvestingDetails(); if (harvestingDetails != null) { if (specified(harvestingDetails.getExcludedSets()) || specified(harvestingDetails.getExcludedSchemas())) { LOGGER.info("Cannot count completeListSize for taskId= {} . Excluded sets or schemas are not supported", task.getTaskId()); return DEFAULT_LIST_SIZE; } String repositoryUrl = getRepositoryUrl(task.getInputData()); if (repositoryUrl != null) { ListIdentifiersParameters params = new ListIdentifiersParameters() .withFrom(harvestingDetails.getDateFrom()) .withUntil(harvestingDetails.getDateUntil()); Set<String> schemas = harvestingDetails.getSchemas(); Set<String> sets = harvestingDetails.getSets(); if (specified(sets)) { if (sets.size() == 1) { params.withSetSpec(sets.iterator().next()); } else { LOGGER.info("Cannot count completeListSize for taskId= {} . Specifying multiple sets is not supported ", task.getTaskId()); return DEFAULT_LIST_SIZE; } } try { return getListSizeForSchemasAndSet(repositoryUrl, params, schemas); } catch (OAIResponseParseException e) { LOGGER.info("Cannot count completeListSize for taskId= {}", task.getTaskId(), e); return DEFAULT_LIST_SIZE; } catch (OAIRequestException e) { String logMessage = "Cannot complete the request for the following repository URL " + repositoryUrl; LOGGER.info(logMessage, e); throw new TaskSubmissionException(logMessage + " Because: " + e.getMessage(), e); } } else { throw new TaskSubmissionException("The task was dropped because the repositoryUrl can not be null"); } } else return DEFAULT_LIST_SIZE; } } | OaiPmhFilesCounter extends FilesCounter { @Override public int getFilesCount(DpsTask task) throws TaskSubmissionException { OAIPMHHarvestingDetails harvestingDetails = task.getHarvestingDetails(); if (harvestingDetails != null) { if (specified(harvestingDetails.getExcludedSets()) || specified(harvestingDetails.getExcludedSchemas())) { LOGGER.info("Cannot count completeListSize for taskId= {} . Excluded sets or schemas are not supported", task.getTaskId()); return DEFAULT_LIST_SIZE; } String repositoryUrl = getRepositoryUrl(task.getInputData()); if (repositoryUrl != null) { ListIdentifiersParameters params = new ListIdentifiersParameters() .withFrom(harvestingDetails.getDateFrom()) .withUntil(harvestingDetails.getDateUntil()); Set<String> schemas = harvestingDetails.getSchemas(); Set<String> sets = harvestingDetails.getSets(); if (specified(sets)) { if (sets.size() == 1) { params.withSetSpec(sets.iterator().next()); } else { LOGGER.info("Cannot count completeListSize for taskId= {} . Specifying multiple sets is not supported ", task.getTaskId()); return DEFAULT_LIST_SIZE; } } try { return getListSizeForSchemasAndSet(repositoryUrl, params, schemas); } catch (OAIResponseParseException e) { LOGGER.info("Cannot count completeListSize for taskId= {}", task.getTaskId(), e); return DEFAULT_LIST_SIZE; } catch (OAIRequestException e) { String logMessage = "Cannot complete the request for the following repository URL " + repositoryUrl; LOGGER.info(logMessage, e); throw new TaskSubmissionException(logMessage + " Because: " + e.getMessage(), e); } } else { throw new TaskSubmissionException("The task was dropped because the repositoryUrl can not be null"); } } else return DEFAULT_LIST_SIZE; } @Override int getFilesCount(DpsTask task); } | OaiPmhFilesCounter extends FilesCounter { @Override public int getFilesCount(DpsTask task) throws TaskSubmissionException { OAIPMHHarvestingDetails harvestingDetails = task.getHarvestingDetails(); if (harvestingDetails != null) { if (specified(harvestingDetails.getExcludedSets()) || specified(harvestingDetails.getExcludedSchemas())) { LOGGER.info("Cannot count completeListSize for taskId= {} . Excluded sets or schemas are not supported", task.getTaskId()); return DEFAULT_LIST_SIZE; } String repositoryUrl = getRepositoryUrl(task.getInputData()); if (repositoryUrl != null) { ListIdentifiersParameters params = new ListIdentifiersParameters() .withFrom(harvestingDetails.getDateFrom()) .withUntil(harvestingDetails.getDateUntil()); Set<String> schemas = harvestingDetails.getSchemas(); Set<String> sets = harvestingDetails.getSets(); if (specified(sets)) { if (sets.size() == 1) { params.withSetSpec(sets.iterator().next()); } else { LOGGER.info("Cannot count completeListSize for taskId= {} . Specifying multiple sets is not supported ", task.getTaskId()); return DEFAULT_LIST_SIZE; } } try { return getListSizeForSchemasAndSet(repositoryUrl, params, schemas); } catch (OAIResponseParseException e) { LOGGER.info("Cannot count completeListSize for taskId= {}", task.getTaskId(), e); return DEFAULT_LIST_SIZE; } catch (OAIRequestException e) { String logMessage = "Cannot complete the request for the following repository URL " + repositoryUrl; LOGGER.info(logMessage, e); throw new TaskSubmissionException(logMessage + " Because: " + e.getMessage(), e); } } else { throw new TaskSubmissionException("The task was dropped because the repositoryUrl can not be null"); } } else return DEFAULT_LIST_SIZE; } @Override int getFilesCount(DpsTask task); static final String COMPLETE_LIST_SIZE; } |
@Test public void shouldReturnCorrectSumWhenSchemasAndNoSetsListed() throws Exception { String schema1 = "schema1"; String schema2 = "schema2"; stubFor(get(urlEqualTo("/oai-phm/?verb=ListIdentifiers&metadataPrefix=" + schema1)) .willReturn(response200XmlContent(getFileContent("/oaiListIdentifiers.xml")))); stubFor(get(urlEqualTo("/oai-phm/?verb=ListIdentifiers&metadataPrefix=" + schema2)) .willReturn(response200XmlContent(getFileContent("/oaiListIdentifiers2.xml")))); OaiPmhFilesCounter counter = new OaiPmhFilesCounter(); OAIPMHHarvestingDetails details = new OAIPMHHarvestingDetails(Sets.newHashSet(schema1, schema2), null, null, null, null); DpsTask task = getDpsTask(details); assertEquals(2934, counter.getFilesCount(task)); } | @Override public int getFilesCount(DpsTask task) throws TaskSubmissionException { OAIPMHHarvestingDetails harvestingDetails = task.getHarvestingDetails(); if (harvestingDetails != null) { if (specified(harvestingDetails.getExcludedSets()) || specified(harvestingDetails.getExcludedSchemas())) { LOGGER.info("Cannot count completeListSize for taskId= {} . Excluded sets or schemas are not supported", task.getTaskId()); return DEFAULT_LIST_SIZE; } String repositoryUrl = getRepositoryUrl(task.getInputData()); if (repositoryUrl != null) { ListIdentifiersParameters params = new ListIdentifiersParameters() .withFrom(harvestingDetails.getDateFrom()) .withUntil(harvestingDetails.getDateUntil()); Set<String> schemas = harvestingDetails.getSchemas(); Set<String> sets = harvestingDetails.getSets(); if (specified(sets)) { if (sets.size() == 1) { params.withSetSpec(sets.iterator().next()); } else { LOGGER.info("Cannot count completeListSize for taskId= {} . Specifying multiple sets is not supported ", task.getTaskId()); return DEFAULT_LIST_SIZE; } } try { return getListSizeForSchemasAndSet(repositoryUrl, params, schemas); } catch (OAIResponseParseException e) { LOGGER.info("Cannot count completeListSize for taskId= {}", task.getTaskId(), e); return DEFAULT_LIST_SIZE; } catch (OAIRequestException e) { String logMessage = "Cannot complete the request for the following repository URL " + repositoryUrl; LOGGER.info(logMessage, e); throw new TaskSubmissionException(logMessage + " Because: " + e.getMessage(), e); } } else { throw new TaskSubmissionException("The task was dropped because the repositoryUrl can not be null"); } } else return DEFAULT_LIST_SIZE; } | OaiPmhFilesCounter extends FilesCounter { @Override public int getFilesCount(DpsTask task) throws TaskSubmissionException { OAIPMHHarvestingDetails harvestingDetails = task.getHarvestingDetails(); if (harvestingDetails != null) { if (specified(harvestingDetails.getExcludedSets()) || specified(harvestingDetails.getExcludedSchemas())) { LOGGER.info("Cannot count completeListSize for taskId= {} . Excluded sets or schemas are not supported", task.getTaskId()); return DEFAULT_LIST_SIZE; } String repositoryUrl = getRepositoryUrl(task.getInputData()); if (repositoryUrl != null) { ListIdentifiersParameters params = new ListIdentifiersParameters() .withFrom(harvestingDetails.getDateFrom()) .withUntil(harvestingDetails.getDateUntil()); Set<String> schemas = harvestingDetails.getSchemas(); Set<String> sets = harvestingDetails.getSets(); if (specified(sets)) { if (sets.size() == 1) { params.withSetSpec(sets.iterator().next()); } else { LOGGER.info("Cannot count completeListSize for taskId= {} . Specifying multiple sets is not supported ", task.getTaskId()); return DEFAULT_LIST_SIZE; } } try { return getListSizeForSchemasAndSet(repositoryUrl, params, schemas); } catch (OAIResponseParseException e) { LOGGER.info("Cannot count completeListSize for taskId= {}", task.getTaskId(), e); return DEFAULT_LIST_SIZE; } catch (OAIRequestException e) { String logMessage = "Cannot complete the request for the following repository URL " + repositoryUrl; LOGGER.info(logMessage, e); throw new TaskSubmissionException(logMessage + " Because: " + e.getMessage(), e); } } else { throw new TaskSubmissionException("The task was dropped because the repositoryUrl can not be null"); } } else return DEFAULT_LIST_SIZE; } } | OaiPmhFilesCounter extends FilesCounter { @Override public int getFilesCount(DpsTask task) throws TaskSubmissionException { OAIPMHHarvestingDetails harvestingDetails = task.getHarvestingDetails(); if (harvestingDetails != null) { if (specified(harvestingDetails.getExcludedSets()) || specified(harvestingDetails.getExcludedSchemas())) { LOGGER.info("Cannot count completeListSize for taskId= {} . Excluded sets or schemas are not supported", task.getTaskId()); return DEFAULT_LIST_SIZE; } String repositoryUrl = getRepositoryUrl(task.getInputData()); if (repositoryUrl != null) { ListIdentifiersParameters params = new ListIdentifiersParameters() .withFrom(harvestingDetails.getDateFrom()) .withUntil(harvestingDetails.getDateUntil()); Set<String> schemas = harvestingDetails.getSchemas(); Set<String> sets = harvestingDetails.getSets(); if (specified(sets)) { if (sets.size() == 1) { params.withSetSpec(sets.iterator().next()); } else { LOGGER.info("Cannot count completeListSize for taskId= {} . Specifying multiple sets is not supported ", task.getTaskId()); return DEFAULT_LIST_SIZE; } } try { return getListSizeForSchemasAndSet(repositoryUrl, params, schemas); } catch (OAIResponseParseException e) { LOGGER.info("Cannot count completeListSize for taskId= {}", task.getTaskId(), e); return DEFAULT_LIST_SIZE; } catch (OAIRequestException e) { String logMessage = "Cannot complete the request for the following repository URL " + repositoryUrl; LOGGER.info(logMessage, e); throw new TaskSubmissionException(logMessage + " Because: " + e.getMessage(), e); } } else { throw new TaskSubmissionException("The task was dropped because the repositoryUrl can not be null"); } } else return DEFAULT_LIST_SIZE; } } | OaiPmhFilesCounter extends FilesCounter { @Override public int getFilesCount(DpsTask task) throws TaskSubmissionException { OAIPMHHarvestingDetails harvestingDetails = task.getHarvestingDetails(); if (harvestingDetails != null) { if (specified(harvestingDetails.getExcludedSets()) || specified(harvestingDetails.getExcludedSchemas())) { LOGGER.info("Cannot count completeListSize for taskId= {} . Excluded sets or schemas are not supported", task.getTaskId()); return DEFAULT_LIST_SIZE; } String repositoryUrl = getRepositoryUrl(task.getInputData()); if (repositoryUrl != null) { ListIdentifiersParameters params = new ListIdentifiersParameters() .withFrom(harvestingDetails.getDateFrom()) .withUntil(harvestingDetails.getDateUntil()); Set<String> schemas = harvestingDetails.getSchemas(); Set<String> sets = harvestingDetails.getSets(); if (specified(sets)) { if (sets.size() == 1) { params.withSetSpec(sets.iterator().next()); } else { LOGGER.info("Cannot count completeListSize for taskId= {} . Specifying multiple sets is not supported ", task.getTaskId()); return DEFAULT_LIST_SIZE; } } try { return getListSizeForSchemasAndSet(repositoryUrl, params, schemas); } catch (OAIResponseParseException e) { LOGGER.info("Cannot count completeListSize for taskId= {}", task.getTaskId(), e); return DEFAULT_LIST_SIZE; } catch (OAIRequestException e) { String logMessage = "Cannot complete the request for the following repository URL " + repositoryUrl; LOGGER.info(logMessage, e); throw new TaskSubmissionException(logMessage + " Because: " + e.getMessage(), e); } } else { throw new TaskSubmissionException("The task was dropped because the repositoryUrl can not be null"); } } else return DEFAULT_LIST_SIZE; } @Override int getFilesCount(DpsTask task); } | OaiPmhFilesCounter extends FilesCounter { @Override public int getFilesCount(DpsTask task) throws TaskSubmissionException { OAIPMHHarvestingDetails harvestingDetails = task.getHarvestingDetails(); if (harvestingDetails != null) { if (specified(harvestingDetails.getExcludedSets()) || specified(harvestingDetails.getExcludedSchemas())) { LOGGER.info("Cannot count completeListSize for taskId= {} . Excluded sets or schemas are not supported", task.getTaskId()); return DEFAULT_LIST_SIZE; } String repositoryUrl = getRepositoryUrl(task.getInputData()); if (repositoryUrl != null) { ListIdentifiersParameters params = new ListIdentifiersParameters() .withFrom(harvestingDetails.getDateFrom()) .withUntil(harvestingDetails.getDateUntil()); Set<String> schemas = harvestingDetails.getSchemas(); Set<String> sets = harvestingDetails.getSets(); if (specified(sets)) { if (sets.size() == 1) { params.withSetSpec(sets.iterator().next()); } else { LOGGER.info("Cannot count completeListSize for taskId= {} . Specifying multiple sets is not supported ", task.getTaskId()); return DEFAULT_LIST_SIZE; } } try { return getListSizeForSchemasAndSet(repositoryUrl, params, schemas); } catch (OAIResponseParseException e) { LOGGER.info("Cannot count completeListSize for taskId= {}", task.getTaskId(), e); return DEFAULT_LIST_SIZE; } catch (OAIRequestException e) { String logMessage = "Cannot complete the request for the following repository URL " + repositoryUrl; LOGGER.info(logMessage, e); throw new TaskSubmissionException(logMessage + " Because: " + e.getMessage(), e); } } else { throw new TaskSubmissionException("The task was dropped because the repositoryUrl can not be null"); } } else return DEFAULT_LIST_SIZE; } @Override int getFilesCount(DpsTask task); static final String COMPLETE_LIST_SIZE; } |
@Test public void shouldReturnMinusOneWhenMultipleSetsSpecified() throws Exception { OaiPmhFilesCounter counter = new OaiPmhFilesCounter(); OAIPMHHarvestingDetails details = new OAIPMHHarvestingDetails(null, null, Sets.newHashSet("a", "b", "c"), null, null, null, null); DpsTask task = getDpsTask(details); assertEquals(-1, counter.getFilesCount(task)); } | @Override public int getFilesCount(DpsTask task) throws TaskSubmissionException { OAIPMHHarvestingDetails harvestingDetails = task.getHarvestingDetails(); if (harvestingDetails != null) { if (specified(harvestingDetails.getExcludedSets()) || specified(harvestingDetails.getExcludedSchemas())) { LOGGER.info("Cannot count completeListSize for taskId= {} . Excluded sets or schemas are not supported", task.getTaskId()); return DEFAULT_LIST_SIZE; } String repositoryUrl = getRepositoryUrl(task.getInputData()); if (repositoryUrl != null) { ListIdentifiersParameters params = new ListIdentifiersParameters() .withFrom(harvestingDetails.getDateFrom()) .withUntil(harvestingDetails.getDateUntil()); Set<String> schemas = harvestingDetails.getSchemas(); Set<String> sets = harvestingDetails.getSets(); if (specified(sets)) { if (sets.size() == 1) { params.withSetSpec(sets.iterator().next()); } else { LOGGER.info("Cannot count completeListSize for taskId= {} . Specifying multiple sets is not supported ", task.getTaskId()); return DEFAULT_LIST_SIZE; } } try { return getListSizeForSchemasAndSet(repositoryUrl, params, schemas); } catch (OAIResponseParseException e) { LOGGER.info("Cannot count completeListSize for taskId= {}", task.getTaskId(), e); return DEFAULT_LIST_SIZE; } catch (OAIRequestException e) { String logMessage = "Cannot complete the request for the following repository URL " + repositoryUrl; LOGGER.info(logMessage, e); throw new TaskSubmissionException(logMessage + " Because: " + e.getMessage(), e); } } else { throw new TaskSubmissionException("The task was dropped because the repositoryUrl can not be null"); } } else return DEFAULT_LIST_SIZE; } | OaiPmhFilesCounter extends FilesCounter { @Override public int getFilesCount(DpsTask task) throws TaskSubmissionException { OAIPMHHarvestingDetails harvestingDetails = task.getHarvestingDetails(); if (harvestingDetails != null) { if (specified(harvestingDetails.getExcludedSets()) || specified(harvestingDetails.getExcludedSchemas())) { LOGGER.info("Cannot count completeListSize for taskId= {} . Excluded sets or schemas are not supported", task.getTaskId()); return DEFAULT_LIST_SIZE; } String repositoryUrl = getRepositoryUrl(task.getInputData()); if (repositoryUrl != null) { ListIdentifiersParameters params = new ListIdentifiersParameters() .withFrom(harvestingDetails.getDateFrom()) .withUntil(harvestingDetails.getDateUntil()); Set<String> schemas = harvestingDetails.getSchemas(); Set<String> sets = harvestingDetails.getSets(); if (specified(sets)) { if (sets.size() == 1) { params.withSetSpec(sets.iterator().next()); } else { LOGGER.info("Cannot count completeListSize for taskId= {} . Specifying multiple sets is not supported ", task.getTaskId()); return DEFAULT_LIST_SIZE; } } try { return getListSizeForSchemasAndSet(repositoryUrl, params, schemas); } catch (OAIResponseParseException e) { LOGGER.info("Cannot count completeListSize for taskId= {}", task.getTaskId(), e); return DEFAULT_LIST_SIZE; } catch (OAIRequestException e) { String logMessage = "Cannot complete the request for the following repository URL " + repositoryUrl; LOGGER.info(logMessage, e); throw new TaskSubmissionException(logMessage + " Because: " + e.getMessage(), e); } } else { throw new TaskSubmissionException("The task was dropped because the repositoryUrl can not be null"); } } else return DEFAULT_LIST_SIZE; } } | OaiPmhFilesCounter extends FilesCounter { @Override public int getFilesCount(DpsTask task) throws TaskSubmissionException { OAIPMHHarvestingDetails harvestingDetails = task.getHarvestingDetails(); if (harvestingDetails != null) { if (specified(harvestingDetails.getExcludedSets()) || specified(harvestingDetails.getExcludedSchemas())) { LOGGER.info("Cannot count completeListSize for taskId= {} . Excluded sets or schemas are not supported", task.getTaskId()); return DEFAULT_LIST_SIZE; } String repositoryUrl = getRepositoryUrl(task.getInputData()); if (repositoryUrl != null) { ListIdentifiersParameters params = new ListIdentifiersParameters() .withFrom(harvestingDetails.getDateFrom()) .withUntil(harvestingDetails.getDateUntil()); Set<String> schemas = harvestingDetails.getSchemas(); Set<String> sets = harvestingDetails.getSets(); if (specified(sets)) { if (sets.size() == 1) { params.withSetSpec(sets.iterator().next()); } else { LOGGER.info("Cannot count completeListSize for taskId= {} . Specifying multiple sets is not supported ", task.getTaskId()); return DEFAULT_LIST_SIZE; } } try { return getListSizeForSchemasAndSet(repositoryUrl, params, schemas); } catch (OAIResponseParseException e) { LOGGER.info("Cannot count completeListSize for taskId= {}", task.getTaskId(), e); return DEFAULT_LIST_SIZE; } catch (OAIRequestException e) { String logMessage = "Cannot complete the request for the following repository URL " + repositoryUrl; LOGGER.info(logMessage, e); throw new TaskSubmissionException(logMessage + " Because: " + e.getMessage(), e); } } else { throw new TaskSubmissionException("The task was dropped because the repositoryUrl can not be null"); } } else return DEFAULT_LIST_SIZE; } } | OaiPmhFilesCounter extends FilesCounter { @Override public int getFilesCount(DpsTask task) throws TaskSubmissionException { OAIPMHHarvestingDetails harvestingDetails = task.getHarvestingDetails(); if (harvestingDetails != null) { if (specified(harvestingDetails.getExcludedSets()) || specified(harvestingDetails.getExcludedSchemas())) { LOGGER.info("Cannot count completeListSize for taskId= {} . Excluded sets or schemas are not supported", task.getTaskId()); return DEFAULT_LIST_SIZE; } String repositoryUrl = getRepositoryUrl(task.getInputData()); if (repositoryUrl != null) { ListIdentifiersParameters params = new ListIdentifiersParameters() .withFrom(harvestingDetails.getDateFrom()) .withUntil(harvestingDetails.getDateUntil()); Set<String> schemas = harvestingDetails.getSchemas(); Set<String> sets = harvestingDetails.getSets(); if (specified(sets)) { if (sets.size() == 1) { params.withSetSpec(sets.iterator().next()); } else { LOGGER.info("Cannot count completeListSize for taskId= {} . Specifying multiple sets is not supported ", task.getTaskId()); return DEFAULT_LIST_SIZE; } } try { return getListSizeForSchemasAndSet(repositoryUrl, params, schemas); } catch (OAIResponseParseException e) { LOGGER.info("Cannot count completeListSize for taskId= {}", task.getTaskId(), e); return DEFAULT_LIST_SIZE; } catch (OAIRequestException e) { String logMessage = "Cannot complete the request for the following repository URL " + repositoryUrl; LOGGER.info(logMessage, e); throw new TaskSubmissionException(logMessage + " Because: " + e.getMessage(), e); } } else { throw new TaskSubmissionException("The task was dropped because the repositoryUrl can not be null"); } } else return DEFAULT_LIST_SIZE; } @Override int getFilesCount(DpsTask task); } | OaiPmhFilesCounter extends FilesCounter { @Override public int getFilesCount(DpsTask task) throws TaskSubmissionException { OAIPMHHarvestingDetails harvestingDetails = task.getHarvestingDetails(); if (harvestingDetails != null) { if (specified(harvestingDetails.getExcludedSets()) || specified(harvestingDetails.getExcludedSchemas())) { LOGGER.info("Cannot count completeListSize for taskId= {} . Excluded sets or schemas are not supported", task.getTaskId()); return DEFAULT_LIST_SIZE; } String repositoryUrl = getRepositoryUrl(task.getInputData()); if (repositoryUrl != null) { ListIdentifiersParameters params = new ListIdentifiersParameters() .withFrom(harvestingDetails.getDateFrom()) .withUntil(harvestingDetails.getDateUntil()); Set<String> schemas = harvestingDetails.getSchemas(); Set<String> sets = harvestingDetails.getSets(); if (specified(sets)) { if (sets.size() == 1) { params.withSetSpec(sets.iterator().next()); } else { LOGGER.info("Cannot count completeListSize for taskId= {} . Specifying multiple sets is not supported ", task.getTaskId()); return DEFAULT_LIST_SIZE; } } try { return getListSizeForSchemasAndSet(repositoryUrl, params, schemas); } catch (OAIResponseParseException e) { LOGGER.info("Cannot count completeListSize for taskId= {}", task.getTaskId(), e); return DEFAULT_LIST_SIZE; } catch (OAIRequestException e) { String logMessage = "Cannot complete the request for the following repository URL " + repositoryUrl; LOGGER.info(logMessage, e); throw new TaskSubmissionException(logMessage + " Because: " + e.getMessage(), e); } } else { throw new TaskSubmissionException("The task was dropped because the repositoryUrl can not be null"); } } else return DEFAULT_LIST_SIZE; } @Override int getFilesCount(DpsTask task); static final String COMPLETE_LIST_SIZE; } |
@Test public void shouldReturnCountForSchemaWhenEmptySetsProvided() throws Exception { stubFor(get(urlEqualTo("/oai-phm/?verb=ListIdentifiers")) .willReturn(response200XmlContent(getFileContent("/oaiListIdentifiers.xml")))); OaiPmhFilesCounter counter = new OaiPmhFilesCounter(); OAIPMHHarvestingDetails details = new OAIPMHHarvestingDetails(null, null, new HashSet<String>(), null, null, null, null); DpsTask task = getDpsTask(details); assertEquals(2932, counter.getFilesCount(task)); } | @Override public int getFilesCount(DpsTask task) throws TaskSubmissionException { OAIPMHHarvestingDetails harvestingDetails = task.getHarvestingDetails(); if (harvestingDetails != null) { if (specified(harvestingDetails.getExcludedSets()) || specified(harvestingDetails.getExcludedSchemas())) { LOGGER.info("Cannot count completeListSize for taskId= {} . Excluded sets or schemas are not supported", task.getTaskId()); return DEFAULT_LIST_SIZE; } String repositoryUrl = getRepositoryUrl(task.getInputData()); if (repositoryUrl != null) { ListIdentifiersParameters params = new ListIdentifiersParameters() .withFrom(harvestingDetails.getDateFrom()) .withUntil(harvestingDetails.getDateUntil()); Set<String> schemas = harvestingDetails.getSchemas(); Set<String> sets = harvestingDetails.getSets(); if (specified(sets)) { if (sets.size() == 1) { params.withSetSpec(sets.iterator().next()); } else { LOGGER.info("Cannot count completeListSize for taskId= {} . Specifying multiple sets is not supported ", task.getTaskId()); return DEFAULT_LIST_SIZE; } } try { return getListSizeForSchemasAndSet(repositoryUrl, params, schemas); } catch (OAIResponseParseException e) { LOGGER.info("Cannot count completeListSize for taskId= {}", task.getTaskId(), e); return DEFAULT_LIST_SIZE; } catch (OAIRequestException e) { String logMessage = "Cannot complete the request for the following repository URL " + repositoryUrl; LOGGER.info(logMessage, e); throw new TaskSubmissionException(logMessage + " Because: " + e.getMessage(), e); } } else { throw new TaskSubmissionException("The task was dropped because the repositoryUrl can not be null"); } } else return DEFAULT_LIST_SIZE; } | OaiPmhFilesCounter extends FilesCounter { @Override public int getFilesCount(DpsTask task) throws TaskSubmissionException { OAIPMHHarvestingDetails harvestingDetails = task.getHarvestingDetails(); if (harvestingDetails != null) { if (specified(harvestingDetails.getExcludedSets()) || specified(harvestingDetails.getExcludedSchemas())) { LOGGER.info("Cannot count completeListSize for taskId= {} . Excluded sets or schemas are not supported", task.getTaskId()); return DEFAULT_LIST_SIZE; } String repositoryUrl = getRepositoryUrl(task.getInputData()); if (repositoryUrl != null) { ListIdentifiersParameters params = new ListIdentifiersParameters() .withFrom(harvestingDetails.getDateFrom()) .withUntil(harvestingDetails.getDateUntil()); Set<String> schemas = harvestingDetails.getSchemas(); Set<String> sets = harvestingDetails.getSets(); if (specified(sets)) { if (sets.size() == 1) { params.withSetSpec(sets.iterator().next()); } else { LOGGER.info("Cannot count completeListSize for taskId= {} . Specifying multiple sets is not supported ", task.getTaskId()); return DEFAULT_LIST_SIZE; } } try { return getListSizeForSchemasAndSet(repositoryUrl, params, schemas); } catch (OAIResponseParseException e) { LOGGER.info("Cannot count completeListSize for taskId= {}", task.getTaskId(), e); return DEFAULT_LIST_SIZE; } catch (OAIRequestException e) { String logMessage = "Cannot complete the request for the following repository URL " + repositoryUrl; LOGGER.info(logMessage, e); throw new TaskSubmissionException(logMessage + " Because: " + e.getMessage(), e); } } else { throw new TaskSubmissionException("The task was dropped because the repositoryUrl can not be null"); } } else return DEFAULT_LIST_SIZE; } } | OaiPmhFilesCounter extends FilesCounter { @Override public int getFilesCount(DpsTask task) throws TaskSubmissionException { OAIPMHHarvestingDetails harvestingDetails = task.getHarvestingDetails(); if (harvestingDetails != null) { if (specified(harvestingDetails.getExcludedSets()) || specified(harvestingDetails.getExcludedSchemas())) { LOGGER.info("Cannot count completeListSize for taskId= {} . Excluded sets or schemas are not supported", task.getTaskId()); return DEFAULT_LIST_SIZE; } String repositoryUrl = getRepositoryUrl(task.getInputData()); if (repositoryUrl != null) { ListIdentifiersParameters params = new ListIdentifiersParameters() .withFrom(harvestingDetails.getDateFrom()) .withUntil(harvestingDetails.getDateUntil()); Set<String> schemas = harvestingDetails.getSchemas(); Set<String> sets = harvestingDetails.getSets(); if (specified(sets)) { if (sets.size() == 1) { params.withSetSpec(sets.iterator().next()); } else { LOGGER.info("Cannot count completeListSize for taskId= {} . Specifying multiple sets is not supported ", task.getTaskId()); return DEFAULT_LIST_SIZE; } } try { return getListSizeForSchemasAndSet(repositoryUrl, params, schemas); } catch (OAIResponseParseException e) { LOGGER.info("Cannot count completeListSize for taskId= {}", task.getTaskId(), e); return DEFAULT_LIST_SIZE; } catch (OAIRequestException e) { String logMessage = "Cannot complete the request for the following repository URL " + repositoryUrl; LOGGER.info(logMessage, e); throw new TaskSubmissionException(logMessage + " Because: " + e.getMessage(), e); } } else { throw new TaskSubmissionException("The task was dropped because the repositoryUrl can not be null"); } } else return DEFAULT_LIST_SIZE; } } | OaiPmhFilesCounter extends FilesCounter { @Override public int getFilesCount(DpsTask task) throws TaskSubmissionException { OAIPMHHarvestingDetails harvestingDetails = task.getHarvestingDetails(); if (harvestingDetails != null) { if (specified(harvestingDetails.getExcludedSets()) || specified(harvestingDetails.getExcludedSchemas())) { LOGGER.info("Cannot count completeListSize for taskId= {} . Excluded sets or schemas are not supported", task.getTaskId()); return DEFAULT_LIST_SIZE; } String repositoryUrl = getRepositoryUrl(task.getInputData()); if (repositoryUrl != null) { ListIdentifiersParameters params = new ListIdentifiersParameters() .withFrom(harvestingDetails.getDateFrom()) .withUntil(harvestingDetails.getDateUntil()); Set<String> schemas = harvestingDetails.getSchemas(); Set<String> sets = harvestingDetails.getSets(); if (specified(sets)) { if (sets.size() == 1) { params.withSetSpec(sets.iterator().next()); } else { LOGGER.info("Cannot count completeListSize for taskId= {} . Specifying multiple sets is not supported ", task.getTaskId()); return DEFAULT_LIST_SIZE; } } try { return getListSizeForSchemasAndSet(repositoryUrl, params, schemas); } catch (OAIResponseParseException e) { LOGGER.info("Cannot count completeListSize for taskId= {}", task.getTaskId(), e); return DEFAULT_LIST_SIZE; } catch (OAIRequestException e) { String logMessage = "Cannot complete the request for the following repository URL " + repositoryUrl; LOGGER.info(logMessage, e); throw new TaskSubmissionException(logMessage + " Because: " + e.getMessage(), e); } } else { throw new TaskSubmissionException("The task was dropped because the repositoryUrl can not be null"); } } else return DEFAULT_LIST_SIZE; } @Override int getFilesCount(DpsTask task); } | OaiPmhFilesCounter extends FilesCounter { @Override public int getFilesCount(DpsTask task) throws TaskSubmissionException { OAIPMHHarvestingDetails harvestingDetails = task.getHarvestingDetails(); if (harvestingDetails != null) { if (specified(harvestingDetails.getExcludedSets()) || specified(harvestingDetails.getExcludedSchemas())) { LOGGER.info("Cannot count completeListSize for taskId= {} . Excluded sets or schemas are not supported", task.getTaskId()); return DEFAULT_LIST_SIZE; } String repositoryUrl = getRepositoryUrl(task.getInputData()); if (repositoryUrl != null) { ListIdentifiersParameters params = new ListIdentifiersParameters() .withFrom(harvestingDetails.getDateFrom()) .withUntil(harvestingDetails.getDateUntil()); Set<String> schemas = harvestingDetails.getSchemas(); Set<String> sets = harvestingDetails.getSets(); if (specified(sets)) { if (sets.size() == 1) { params.withSetSpec(sets.iterator().next()); } else { LOGGER.info("Cannot count completeListSize for taskId= {} . Specifying multiple sets is not supported ", task.getTaskId()); return DEFAULT_LIST_SIZE; } } try { return getListSizeForSchemasAndSet(repositoryUrl, params, schemas); } catch (OAIResponseParseException e) { LOGGER.info("Cannot count completeListSize for taskId= {}", task.getTaskId(), e); return DEFAULT_LIST_SIZE; } catch (OAIRequestException e) { String logMessage = "Cannot complete the request for the following repository URL " + repositoryUrl; LOGGER.info(logMessage, e); throw new TaskSubmissionException(logMessage + " Because: " + e.getMessage(), e); } } else { throw new TaskSubmissionException("The task was dropped because the repositoryUrl can not be null"); } } else return DEFAULT_LIST_SIZE; } @Override int getFilesCount(DpsTask task); static final String COMPLETE_LIST_SIZE; } |
@Test public void shouldReturnMinusOneWhenSetsExcluded() throws Exception { OaiPmhFilesCounter counter = new OaiPmhFilesCounter(); OAIPMHHarvestingDetails details = new OAIPMHHarvestingDetails(null, null, null, Sets.newHashSet("a", "b", "c"), null, null, null); DpsTask task = getDpsTask(details); assertEquals(-1, counter.getFilesCount(task)); } | @Override public int getFilesCount(DpsTask task) throws TaskSubmissionException { OAIPMHHarvestingDetails harvestingDetails = task.getHarvestingDetails(); if (harvestingDetails != null) { if (specified(harvestingDetails.getExcludedSets()) || specified(harvestingDetails.getExcludedSchemas())) { LOGGER.info("Cannot count completeListSize for taskId= {} . Excluded sets or schemas are not supported", task.getTaskId()); return DEFAULT_LIST_SIZE; } String repositoryUrl = getRepositoryUrl(task.getInputData()); if (repositoryUrl != null) { ListIdentifiersParameters params = new ListIdentifiersParameters() .withFrom(harvestingDetails.getDateFrom()) .withUntil(harvestingDetails.getDateUntil()); Set<String> schemas = harvestingDetails.getSchemas(); Set<String> sets = harvestingDetails.getSets(); if (specified(sets)) { if (sets.size() == 1) { params.withSetSpec(sets.iterator().next()); } else { LOGGER.info("Cannot count completeListSize for taskId= {} . Specifying multiple sets is not supported ", task.getTaskId()); return DEFAULT_LIST_SIZE; } } try { return getListSizeForSchemasAndSet(repositoryUrl, params, schemas); } catch (OAIResponseParseException e) { LOGGER.info("Cannot count completeListSize for taskId= {}", task.getTaskId(), e); return DEFAULT_LIST_SIZE; } catch (OAIRequestException e) { String logMessage = "Cannot complete the request for the following repository URL " + repositoryUrl; LOGGER.info(logMessage, e); throw new TaskSubmissionException(logMessage + " Because: " + e.getMessage(), e); } } else { throw new TaskSubmissionException("The task was dropped because the repositoryUrl can not be null"); } } else return DEFAULT_LIST_SIZE; } | OaiPmhFilesCounter extends FilesCounter { @Override public int getFilesCount(DpsTask task) throws TaskSubmissionException { OAIPMHHarvestingDetails harvestingDetails = task.getHarvestingDetails(); if (harvestingDetails != null) { if (specified(harvestingDetails.getExcludedSets()) || specified(harvestingDetails.getExcludedSchemas())) { LOGGER.info("Cannot count completeListSize for taskId= {} . Excluded sets or schemas are not supported", task.getTaskId()); return DEFAULT_LIST_SIZE; } String repositoryUrl = getRepositoryUrl(task.getInputData()); if (repositoryUrl != null) { ListIdentifiersParameters params = new ListIdentifiersParameters() .withFrom(harvestingDetails.getDateFrom()) .withUntil(harvestingDetails.getDateUntil()); Set<String> schemas = harvestingDetails.getSchemas(); Set<String> sets = harvestingDetails.getSets(); if (specified(sets)) { if (sets.size() == 1) { params.withSetSpec(sets.iterator().next()); } else { LOGGER.info("Cannot count completeListSize for taskId= {} . Specifying multiple sets is not supported ", task.getTaskId()); return DEFAULT_LIST_SIZE; } } try { return getListSizeForSchemasAndSet(repositoryUrl, params, schemas); } catch (OAIResponseParseException e) { LOGGER.info("Cannot count completeListSize for taskId= {}", task.getTaskId(), e); return DEFAULT_LIST_SIZE; } catch (OAIRequestException e) { String logMessage = "Cannot complete the request for the following repository URL " + repositoryUrl; LOGGER.info(logMessage, e); throw new TaskSubmissionException(logMessage + " Because: " + e.getMessage(), e); } } else { throw new TaskSubmissionException("The task was dropped because the repositoryUrl can not be null"); } } else return DEFAULT_LIST_SIZE; } } | OaiPmhFilesCounter extends FilesCounter { @Override public int getFilesCount(DpsTask task) throws TaskSubmissionException { OAIPMHHarvestingDetails harvestingDetails = task.getHarvestingDetails(); if (harvestingDetails != null) { if (specified(harvestingDetails.getExcludedSets()) || specified(harvestingDetails.getExcludedSchemas())) { LOGGER.info("Cannot count completeListSize for taskId= {} . Excluded sets or schemas are not supported", task.getTaskId()); return DEFAULT_LIST_SIZE; } String repositoryUrl = getRepositoryUrl(task.getInputData()); if (repositoryUrl != null) { ListIdentifiersParameters params = new ListIdentifiersParameters() .withFrom(harvestingDetails.getDateFrom()) .withUntil(harvestingDetails.getDateUntil()); Set<String> schemas = harvestingDetails.getSchemas(); Set<String> sets = harvestingDetails.getSets(); if (specified(sets)) { if (sets.size() == 1) { params.withSetSpec(sets.iterator().next()); } else { LOGGER.info("Cannot count completeListSize for taskId= {} . Specifying multiple sets is not supported ", task.getTaskId()); return DEFAULT_LIST_SIZE; } } try { return getListSizeForSchemasAndSet(repositoryUrl, params, schemas); } catch (OAIResponseParseException e) { LOGGER.info("Cannot count completeListSize for taskId= {}", task.getTaskId(), e); return DEFAULT_LIST_SIZE; } catch (OAIRequestException e) { String logMessage = "Cannot complete the request for the following repository URL " + repositoryUrl; LOGGER.info(logMessage, e); throw new TaskSubmissionException(logMessage + " Because: " + e.getMessage(), e); } } else { throw new TaskSubmissionException("The task was dropped because the repositoryUrl can not be null"); } } else return DEFAULT_LIST_SIZE; } } | OaiPmhFilesCounter extends FilesCounter { @Override public int getFilesCount(DpsTask task) throws TaskSubmissionException { OAIPMHHarvestingDetails harvestingDetails = task.getHarvestingDetails(); if (harvestingDetails != null) { if (specified(harvestingDetails.getExcludedSets()) || specified(harvestingDetails.getExcludedSchemas())) { LOGGER.info("Cannot count completeListSize for taskId= {} . Excluded sets or schemas are not supported", task.getTaskId()); return DEFAULT_LIST_SIZE; } String repositoryUrl = getRepositoryUrl(task.getInputData()); if (repositoryUrl != null) { ListIdentifiersParameters params = new ListIdentifiersParameters() .withFrom(harvestingDetails.getDateFrom()) .withUntil(harvestingDetails.getDateUntil()); Set<String> schemas = harvestingDetails.getSchemas(); Set<String> sets = harvestingDetails.getSets(); if (specified(sets)) { if (sets.size() == 1) { params.withSetSpec(sets.iterator().next()); } else { LOGGER.info("Cannot count completeListSize for taskId= {} . Specifying multiple sets is not supported ", task.getTaskId()); return DEFAULT_LIST_SIZE; } } try { return getListSizeForSchemasAndSet(repositoryUrl, params, schemas); } catch (OAIResponseParseException e) { LOGGER.info("Cannot count completeListSize for taskId= {}", task.getTaskId(), e); return DEFAULT_LIST_SIZE; } catch (OAIRequestException e) { String logMessage = "Cannot complete the request for the following repository URL " + repositoryUrl; LOGGER.info(logMessage, e); throw new TaskSubmissionException(logMessage + " Because: " + e.getMessage(), e); } } else { throw new TaskSubmissionException("The task was dropped because the repositoryUrl can not be null"); } } else return DEFAULT_LIST_SIZE; } @Override int getFilesCount(DpsTask task); } | OaiPmhFilesCounter extends FilesCounter { @Override public int getFilesCount(DpsTask task) throws TaskSubmissionException { OAIPMHHarvestingDetails harvestingDetails = task.getHarvestingDetails(); if (harvestingDetails != null) { if (specified(harvestingDetails.getExcludedSets()) || specified(harvestingDetails.getExcludedSchemas())) { LOGGER.info("Cannot count completeListSize for taskId= {} . Excluded sets or schemas are not supported", task.getTaskId()); return DEFAULT_LIST_SIZE; } String repositoryUrl = getRepositoryUrl(task.getInputData()); if (repositoryUrl != null) { ListIdentifiersParameters params = new ListIdentifiersParameters() .withFrom(harvestingDetails.getDateFrom()) .withUntil(harvestingDetails.getDateUntil()); Set<String> schemas = harvestingDetails.getSchemas(); Set<String> sets = harvestingDetails.getSets(); if (specified(sets)) { if (sets.size() == 1) { params.withSetSpec(sets.iterator().next()); } else { LOGGER.info("Cannot count completeListSize for taskId= {} . Specifying multiple sets is not supported ", task.getTaskId()); return DEFAULT_LIST_SIZE; } } try { return getListSizeForSchemasAndSet(repositoryUrl, params, schemas); } catch (OAIResponseParseException e) { LOGGER.info("Cannot count completeListSize for taskId= {}", task.getTaskId(), e); return DEFAULT_LIST_SIZE; } catch (OAIRequestException e) { String logMessage = "Cannot complete the request for the following repository URL " + repositoryUrl; LOGGER.info(logMessage, e); throw new TaskSubmissionException(logMessage + " Because: " + e.getMessage(), e); } } else { throw new TaskSubmissionException("The task was dropped because the repositoryUrl can not be null"); } } else return DEFAULT_LIST_SIZE; } @Override int getFilesCount(DpsTask task); static final String COMPLETE_LIST_SIZE; } |
@Test public void shouldReturnMinusOneWheHarvestingDetailsIsNotProvided() throws Exception { OaiPmhFilesCounter counter = new OaiPmhFilesCounter(); DpsTask task = getDpsTask(null); assertEquals(-1, counter.getFilesCount(task)); } | @Override public int getFilesCount(DpsTask task) throws TaskSubmissionException { OAIPMHHarvestingDetails harvestingDetails = task.getHarvestingDetails(); if (harvestingDetails != null) { if (specified(harvestingDetails.getExcludedSets()) || specified(harvestingDetails.getExcludedSchemas())) { LOGGER.info("Cannot count completeListSize for taskId= {} . Excluded sets or schemas are not supported", task.getTaskId()); return DEFAULT_LIST_SIZE; } String repositoryUrl = getRepositoryUrl(task.getInputData()); if (repositoryUrl != null) { ListIdentifiersParameters params = new ListIdentifiersParameters() .withFrom(harvestingDetails.getDateFrom()) .withUntil(harvestingDetails.getDateUntil()); Set<String> schemas = harvestingDetails.getSchemas(); Set<String> sets = harvestingDetails.getSets(); if (specified(sets)) { if (sets.size() == 1) { params.withSetSpec(sets.iterator().next()); } else { LOGGER.info("Cannot count completeListSize for taskId= {} . Specifying multiple sets is not supported ", task.getTaskId()); return DEFAULT_LIST_SIZE; } } try { return getListSizeForSchemasAndSet(repositoryUrl, params, schemas); } catch (OAIResponseParseException e) { LOGGER.info("Cannot count completeListSize for taskId= {}", task.getTaskId(), e); return DEFAULT_LIST_SIZE; } catch (OAIRequestException e) { String logMessage = "Cannot complete the request for the following repository URL " + repositoryUrl; LOGGER.info(logMessage, e); throw new TaskSubmissionException(logMessage + " Because: " + e.getMessage(), e); } } else { throw new TaskSubmissionException("The task was dropped because the repositoryUrl can not be null"); } } else return DEFAULT_LIST_SIZE; } | OaiPmhFilesCounter extends FilesCounter { @Override public int getFilesCount(DpsTask task) throws TaskSubmissionException { OAIPMHHarvestingDetails harvestingDetails = task.getHarvestingDetails(); if (harvestingDetails != null) { if (specified(harvestingDetails.getExcludedSets()) || specified(harvestingDetails.getExcludedSchemas())) { LOGGER.info("Cannot count completeListSize for taskId= {} . Excluded sets or schemas are not supported", task.getTaskId()); return DEFAULT_LIST_SIZE; } String repositoryUrl = getRepositoryUrl(task.getInputData()); if (repositoryUrl != null) { ListIdentifiersParameters params = new ListIdentifiersParameters() .withFrom(harvestingDetails.getDateFrom()) .withUntil(harvestingDetails.getDateUntil()); Set<String> schemas = harvestingDetails.getSchemas(); Set<String> sets = harvestingDetails.getSets(); if (specified(sets)) { if (sets.size() == 1) { params.withSetSpec(sets.iterator().next()); } else { LOGGER.info("Cannot count completeListSize for taskId= {} . Specifying multiple sets is not supported ", task.getTaskId()); return DEFAULT_LIST_SIZE; } } try { return getListSizeForSchemasAndSet(repositoryUrl, params, schemas); } catch (OAIResponseParseException e) { LOGGER.info("Cannot count completeListSize for taskId= {}", task.getTaskId(), e); return DEFAULT_LIST_SIZE; } catch (OAIRequestException e) { String logMessage = "Cannot complete the request for the following repository URL " + repositoryUrl; LOGGER.info(logMessage, e); throw new TaskSubmissionException(logMessage + " Because: " + e.getMessage(), e); } } else { throw new TaskSubmissionException("The task was dropped because the repositoryUrl can not be null"); } } else return DEFAULT_LIST_SIZE; } } | OaiPmhFilesCounter extends FilesCounter { @Override public int getFilesCount(DpsTask task) throws TaskSubmissionException { OAIPMHHarvestingDetails harvestingDetails = task.getHarvestingDetails(); if (harvestingDetails != null) { if (specified(harvestingDetails.getExcludedSets()) || specified(harvestingDetails.getExcludedSchemas())) { LOGGER.info("Cannot count completeListSize for taskId= {} . Excluded sets or schemas are not supported", task.getTaskId()); return DEFAULT_LIST_SIZE; } String repositoryUrl = getRepositoryUrl(task.getInputData()); if (repositoryUrl != null) { ListIdentifiersParameters params = new ListIdentifiersParameters() .withFrom(harvestingDetails.getDateFrom()) .withUntil(harvestingDetails.getDateUntil()); Set<String> schemas = harvestingDetails.getSchemas(); Set<String> sets = harvestingDetails.getSets(); if (specified(sets)) { if (sets.size() == 1) { params.withSetSpec(sets.iterator().next()); } else { LOGGER.info("Cannot count completeListSize for taskId= {} . Specifying multiple sets is not supported ", task.getTaskId()); return DEFAULT_LIST_SIZE; } } try { return getListSizeForSchemasAndSet(repositoryUrl, params, schemas); } catch (OAIResponseParseException e) { LOGGER.info("Cannot count completeListSize for taskId= {}", task.getTaskId(), e); return DEFAULT_LIST_SIZE; } catch (OAIRequestException e) { String logMessage = "Cannot complete the request for the following repository URL " + repositoryUrl; LOGGER.info(logMessage, e); throw new TaskSubmissionException(logMessage + " Because: " + e.getMessage(), e); } } else { throw new TaskSubmissionException("The task was dropped because the repositoryUrl can not be null"); } } else return DEFAULT_LIST_SIZE; } } | OaiPmhFilesCounter extends FilesCounter { @Override public int getFilesCount(DpsTask task) throws TaskSubmissionException { OAIPMHHarvestingDetails harvestingDetails = task.getHarvestingDetails(); if (harvestingDetails != null) { if (specified(harvestingDetails.getExcludedSets()) || specified(harvestingDetails.getExcludedSchemas())) { LOGGER.info("Cannot count completeListSize for taskId= {} . Excluded sets or schemas are not supported", task.getTaskId()); return DEFAULT_LIST_SIZE; } String repositoryUrl = getRepositoryUrl(task.getInputData()); if (repositoryUrl != null) { ListIdentifiersParameters params = new ListIdentifiersParameters() .withFrom(harvestingDetails.getDateFrom()) .withUntil(harvestingDetails.getDateUntil()); Set<String> schemas = harvestingDetails.getSchemas(); Set<String> sets = harvestingDetails.getSets(); if (specified(sets)) { if (sets.size() == 1) { params.withSetSpec(sets.iterator().next()); } else { LOGGER.info("Cannot count completeListSize for taskId= {} . Specifying multiple sets is not supported ", task.getTaskId()); return DEFAULT_LIST_SIZE; } } try { return getListSizeForSchemasAndSet(repositoryUrl, params, schemas); } catch (OAIResponseParseException e) { LOGGER.info("Cannot count completeListSize for taskId= {}", task.getTaskId(), e); return DEFAULT_LIST_SIZE; } catch (OAIRequestException e) { String logMessage = "Cannot complete the request for the following repository URL " + repositoryUrl; LOGGER.info(logMessage, e); throw new TaskSubmissionException(logMessage + " Because: " + e.getMessage(), e); } } else { throw new TaskSubmissionException("The task was dropped because the repositoryUrl can not be null"); } } else return DEFAULT_LIST_SIZE; } @Override int getFilesCount(DpsTask task); } | OaiPmhFilesCounter extends FilesCounter { @Override public int getFilesCount(DpsTask task) throws TaskSubmissionException { OAIPMHHarvestingDetails harvestingDetails = task.getHarvestingDetails(); if (harvestingDetails != null) { if (specified(harvestingDetails.getExcludedSets()) || specified(harvestingDetails.getExcludedSchemas())) { LOGGER.info("Cannot count completeListSize for taskId= {} . Excluded sets or schemas are not supported", task.getTaskId()); return DEFAULT_LIST_SIZE; } String repositoryUrl = getRepositoryUrl(task.getInputData()); if (repositoryUrl != null) { ListIdentifiersParameters params = new ListIdentifiersParameters() .withFrom(harvestingDetails.getDateFrom()) .withUntil(harvestingDetails.getDateUntil()); Set<String> schemas = harvestingDetails.getSchemas(); Set<String> sets = harvestingDetails.getSets(); if (specified(sets)) { if (sets.size() == 1) { params.withSetSpec(sets.iterator().next()); } else { LOGGER.info("Cannot count completeListSize for taskId= {} . Specifying multiple sets is not supported ", task.getTaskId()); return DEFAULT_LIST_SIZE; } } try { return getListSizeForSchemasAndSet(repositoryUrl, params, schemas); } catch (OAIResponseParseException e) { LOGGER.info("Cannot count completeListSize for taskId= {}", task.getTaskId(), e); return DEFAULT_LIST_SIZE; } catch (OAIRequestException e) { String logMessage = "Cannot complete the request for the following repository URL " + repositoryUrl; LOGGER.info(logMessage, e); throw new TaskSubmissionException(logMessage + " Because: " + e.getMessage(), e); } } else { throw new TaskSubmissionException("The task was dropped because the repositoryUrl can not be null"); } } else return DEFAULT_LIST_SIZE; } @Override int getFilesCount(DpsTask task); static final String COMPLETE_LIST_SIZE; } |
@Test public void shouldReturnMinusOneWhenSchemasExcluded() throws Exception { OaiPmhFilesCounter counter = new OaiPmhFilesCounter(); OAIPMHHarvestingDetails details = new OAIPMHHarvestingDetails(null, Sets.newHashSet("a", "b", "c"), null, null, null, null, null); DpsTask task = getDpsTask(details); assertEquals(-1, counter.getFilesCount(task)); } | @Override public int getFilesCount(DpsTask task) throws TaskSubmissionException { OAIPMHHarvestingDetails harvestingDetails = task.getHarvestingDetails(); if (harvestingDetails != null) { if (specified(harvestingDetails.getExcludedSets()) || specified(harvestingDetails.getExcludedSchemas())) { LOGGER.info("Cannot count completeListSize for taskId= {} . Excluded sets or schemas are not supported", task.getTaskId()); return DEFAULT_LIST_SIZE; } String repositoryUrl = getRepositoryUrl(task.getInputData()); if (repositoryUrl != null) { ListIdentifiersParameters params = new ListIdentifiersParameters() .withFrom(harvestingDetails.getDateFrom()) .withUntil(harvestingDetails.getDateUntil()); Set<String> schemas = harvestingDetails.getSchemas(); Set<String> sets = harvestingDetails.getSets(); if (specified(sets)) { if (sets.size() == 1) { params.withSetSpec(sets.iterator().next()); } else { LOGGER.info("Cannot count completeListSize for taskId= {} . Specifying multiple sets is not supported ", task.getTaskId()); return DEFAULT_LIST_SIZE; } } try { return getListSizeForSchemasAndSet(repositoryUrl, params, schemas); } catch (OAIResponseParseException e) { LOGGER.info("Cannot count completeListSize for taskId= {}", task.getTaskId(), e); return DEFAULT_LIST_SIZE; } catch (OAIRequestException e) { String logMessage = "Cannot complete the request for the following repository URL " + repositoryUrl; LOGGER.info(logMessage, e); throw new TaskSubmissionException(logMessage + " Because: " + e.getMessage(), e); } } else { throw new TaskSubmissionException("The task was dropped because the repositoryUrl can not be null"); } } else return DEFAULT_LIST_SIZE; } | OaiPmhFilesCounter extends FilesCounter { @Override public int getFilesCount(DpsTask task) throws TaskSubmissionException { OAIPMHHarvestingDetails harvestingDetails = task.getHarvestingDetails(); if (harvestingDetails != null) { if (specified(harvestingDetails.getExcludedSets()) || specified(harvestingDetails.getExcludedSchemas())) { LOGGER.info("Cannot count completeListSize for taskId= {} . Excluded sets or schemas are not supported", task.getTaskId()); return DEFAULT_LIST_SIZE; } String repositoryUrl = getRepositoryUrl(task.getInputData()); if (repositoryUrl != null) { ListIdentifiersParameters params = new ListIdentifiersParameters() .withFrom(harvestingDetails.getDateFrom()) .withUntil(harvestingDetails.getDateUntil()); Set<String> schemas = harvestingDetails.getSchemas(); Set<String> sets = harvestingDetails.getSets(); if (specified(sets)) { if (sets.size() == 1) { params.withSetSpec(sets.iterator().next()); } else { LOGGER.info("Cannot count completeListSize for taskId= {} . Specifying multiple sets is not supported ", task.getTaskId()); return DEFAULT_LIST_SIZE; } } try { return getListSizeForSchemasAndSet(repositoryUrl, params, schemas); } catch (OAIResponseParseException e) { LOGGER.info("Cannot count completeListSize for taskId= {}", task.getTaskId(), e); return DEFAULT_LIST_SIZE; } catch (OAIRequestException e) { String logMessage = "Cannot complete the request for the following repository URL " + repositoryUrl; LOGGER.info(logMessage, e); throw new TaskSubmissionException(logMessage + " Because: " + e.getMessage(), e); } } else { throw new TaskSubmissionException("The task was dropped because the repositoryUrl can not be null"); } } else return DEFAULT_LIST_SIZE; } } | OaiPmhFilesCounter extends FilesCounter { @Override public int getFilesCount(DpsTask task) throws TaskSubmissionException { OAIPMHHarvestingDetails harvestingDetails = task.getHarvestingDetails(); if (harvestingDetails != null) { if (specified(harvestingDetails.getExcludedSets()) || specified(harvestingDetails.getExcludedSchemas())) { LOGGER.info("Cannot count completeListSize for taskId= {} . Excluded sets or schemas are not supported", task.getTaskId()); return DEFAULT_LIST_SIZE; } String repositoryUrl = getRepositoryUrl(task.getInputData()); if (repositoryUrl != null) { ListIdentifiersParameters params = new ListIdentifiersParameters() .withFrom(harvestingDetails.getDateFrom()) .withUntil(harvestingDetails.getDateUntil()); Set<String> schemas = harvestingDetails.getSchemas(); Set<String> sets = harvestingDetails.getSets(); if (specified(sets)) { if (sets.size() == 1) { params.withSetSpec(sets.iterator().next()); } else { LOGGER.info("Cannot count completeListSize for taskId= {} . Specifying multiple sets is not supported ", task.getTaskId()); return DEFAULT_LIST_SIZE; } } try { return getListSizeForSchemasAndSet(repositoryUrl, params, schemas); } catch (OAIResponseParseException e) { LOGGER.info("Cannot count completeListSize for taskId= {}", task.getTaskId(), e); return DEFAULT_LIST_SIZE; } catch (OAIRequestException e) { String logMessage = "Cannot complete the request for the following repository URL " + repositoryUrl; LOGGER.info(logMessage, e); throw new TaskSubmissionException(logMessage + " Because: " + e.getMessage(), e); } } else { throw new TaskSubmissionException("The task was dropped because the repositoryUrl can not be null"); } } else return DEFAULT_LIST_SIZE; } } | OaiPmhFilesCounter extends FilesCounter { @Override public int getFilesCount(DpsTask task) throws TaskSubmissionException { OAIPMHHarvestingDetails harvestingDetails = task.getHarvestingDetails(); if (harvestingDetails != null) { if (specified(harvestingDetails.getExcludedSets()) || specified(harvestingDetails.getExcludedSchemas())) { LOGGER.info("Cannot count completeListSize for taskId= {} . Excluded sets or schemas are not supported", task.getTaskId()); return DEFAULT_LIST_SIZE; } String repositoryUrl = getRepositoryUrl(task.getInputData()); if (repositoryUrl != null) { ListIdentifiersParameters params = new ListIdentifiersParameters() .withFrom(harvestingDetails.getDateFrom()) .withUntil(harvestingDetails.getDateUntil()); Set<String> schemas = harvestingDetails.getSchemas(); Set<String> sets = harvestingDetails.getSets(); if (specified(sets)) { if (sets.size() == 1) { params.withSetSpec(sets.iterator().next()); } else { LOGGER.info("Cannot count completeListSize for taskId= {} . Specifying multiple sets is not supported ", task.getTaskId()); return DEFAULT_LIST_SIZE; } } try { return getListSizeForSchemasAndSet(repositoryUrl, params, schemas); } catch (OAIResponseParseException e) { LOGGER.info("Cannot count completeListSize for taskId= {}", task.getTaskId(), e); return DEFAULT_LIST_SIZE; } catch (OAIRequestException e) { String logMessage = "Cannot complete the request for the following repository URL " + repositoryUrl; LOGGER.info(logMessage, e); throw new TaskSubmissionException(logMessage + " Because: " + e.getMessage(), e); } } else { throw new TaskSubmissionException("The task was dropped because the repositoryUrl can not be null"); } } else return DEFAULT_LIST_SIZE; } @Override int getFilesCount(DpsTask task); } | OaiPmhFilesCounter extends FilesCounter { @Override public int getFilesCount(DpsTask task) throws TaskSubmissionException { OAIPMHHarvestingDetails harvestingDetails = task.getHarvestingDetails(); if (harvestingDetails != null) { if (specified(harvestingDetails.getExcludedSets()) || specified(harvestingDetails.getExcludedSchemas())) { LOGGER.info("Cannot count completeListSize for taskId= {} . Excluded sets or schemas are not supported", task.getTaskId()); return DEFAULT_LIST_SIZE; } String repositoryUrl = getRepositoryUrl(task.getInputData()); if (repositoryUrl != null) { ListIdentifiersParameters params = new ListIdentifiersParameters() .withFrom(harvestingDetails.getDateFrom()) .withUntil(harvestingDetails.getDateUntil()); Set<String> schemas = harvestingDetails.getSchemas(); Set<String> sets = harvestingDetails.getSets(); if (specified(sets)) { if (sets.size() == 1) { params.withSetSpec(sets.iterator().next()); } else { LOGGER.info("Cannot count completeListSize for taskId= {} . Specifying multiple sets is not supported ", task.getTaskId()); return DEFAULT_LIST_SIZE; } } try { return getListSizeForSchemasAndSet(repositoryUrl, params, schemas); } catch (OAIResponseParseException e) { LOGGER.info("Cannot count completeListSize for taskId= {}", task.getTaskId(), e); return DEFAULT_LIST_SIZE; } catch (OAIRequestException e) { String logMessage = "Cannot complete the request for the following repository URL " + repositoryUrl; LOGGER.info(logMessage, e); throw new TaskSubmissionException(logMessage + " Because: " + e.getMessage(), e); } } else { throw new TaskSubmissionException("The task was dropped because the repositoryUrl can not be null"); } } else return DEFAULT_LIST_SIZE; } @Override int getFilesCount(DpsTask task); static final String COMPLETE_LIST_SIZE; } |
@Test public void TestValidator() { Validator validator = ValidatorFactory.getValidator(ValidatorType.KEYSPACE); assertTrue(validator instanceof KeyspaceValidator); validator = ValidatorFactory.getValidator(ValidatorType.TABLE); assertTrue(validator instanceof TableValidator); } | public static Validator getValidator(ValidatorType type) { if (type == ValidatorType.KEYSPACE) return new KeyspaceValidator(); if (type == ValidatorType.TABLE) return new TableValidator(); return null; } | ValidatorFactory { public static Validator getValidator(ValidatorType type) { if (type == ValidatorType.KEYSPACE) return new KeyspaceValidator(); if (type == ValidatorType.TABLE) return new TableValidator(); return null; } } | ValidatorFactory { public static Validator getValidator(ValidatorType type) { if (type == ValidatorType.KEYSPACE) return new KeyspaceValidator(); if (type == ValidatorType.TABLE) return new TableValidator(); return null; } } | ValidatorFactory { public static Validator getValidator(ValidatorType type) { if (type == ValidatorType.KEYSPACE) return new KeyspaceValidator(); if (type == ValidatorType.TABLE) return new TableValidator(); return null; } static Validator getValidator(ValidatorType type); } | ValidatorFactory { public static Validator getValidator(ValidatorType type) { if (type == ValidatorType.KEYSPACE) return new KeyspaceValidator(); if (type == ValidatorType.TABLE) return new TableValidator(); return null; } static Validator getValidator(ValidatorType type); } |
@Test(expected = TaskSubmissionException.class) public void shouldThrowTaskSubmissionExceptionWhenURLsIsNull() throws Exception { OaiPmhFilesCounter counter = new OaiPmhFilesCounter(); OAIPMHHarvestingDetails details = new OAIPMHHarvestingDetails(null, null, null, null, null, null, null); DpsTask task = getDpsTaskNoEndpoint(details); counter.getFilesCount(task); } | @Override public int getFilesCount(DpsTask task) throws TaskSubmissionException { OAIPMHHarvestingDetails harvestingDetails = task.getHarvestingDetails(); if (harvestingDetails != null) { if (specified(harvestingDetails.getExcludedSets()) || specified(harvestingDetails.getExcludedSchemas())) { LOGGER.info("Cannot count completeListSize for taskId= {} . Excluded sets or schemas are not supported", task.getTaskId()); return DEFAULT_LIST_SIZE; } String repositoryUrl = getRepositoryUrl(task.getInputData()); if (repositoryUrl != null) { ListIdentifiersParameters params = new ListIdentifiersParameters() .withFrom(harvestingDetails.getDateFrom()) .withUntil(harvestingDetails.getDateUntil()); Set<String> schemas = harvestingDetails.getSchemas(); Set<String> sets = harvestingDetails.getSets(); if (specified(sets)) { if (sets.size() == 1) { params.withSetSpec(sets.iterator().next()); } else { LOGGER.info("Cannot count completeListSize for taskId= {} . Specifying multiple sets is not supported ", task.getTaskId()); return DEFAULT_LIST_SIZE; } } try { return getListSizeForSchemasAndSet(repositoryUrl, params, schemas); } catch (OAIResponseParseException e) { LOGGER.info("Cannot count completeListSize for taskId= {}", task.getTaskId(), e); return DEFAULT_LIST_SIZE; } catch (OAIRequestException e) { String logMessage = "Cannot complete the request for the following repository URL " + repositoryUrl; LOGGER.info(logMessage, e); throw new TaskSubmissionException(logMessage + " Because: " + e.getMessage(), e); } } else { throw new TaskSubmissionException("The task was dropped because the repositoryUrl can not be null"); } } else return DEFAULT_LIST_SIZE; } | OaiPmhFilesCounter extends FilesCounter { @Override public int getFilesCount(DpsTask task) throws TaskSubmissionException { OAIPMHHarvestingDetails harvestingDetails = task.getHarvestingDetails(); if (harvestingDetails != null) { if (specified(harvestingDetails.getExcludedSets()) || specified(harvestingDetails.getExcludedSchemas())) { LOGGER.info("Cannot count completeListSize for taskId= {} . Excluded sets or schemas are not supported", task.getTaskId()); return DEFAULT_LIST_SIZE; } String repositoryUrl = getRepositoryUrl(task.getInputData()); if (repositoryUrl != null) { ListIdentifiersParameters params = new ListIdentifiersParameters() .withFrom(harvestingDetails.getDateFrom()) .withUntil(harvestingDetails.getDateUntil()); Set<String> schemas = harvestingDetails.getSchemas(); Set<String> sets = harvestingDetails.getSets(); if (specified(sets)) { if (sets.size() == 1) { params.withSetSpec(sets.iterator().next()); } else { LOGGER.info("Cannot count completeListSize for taskId= {} . Specifying multiple sets is not supported ", task.getTaskId()); return DEFAULT_LIST_SIZE; } } try { return getListSizeForSchemasAndSet(repositoryUrl, params, schemas); } catch (OAIResponseParseException e) { LOGGER.info("Cannot count completeListSize for taskId= {}", task.getTaskId(), e); return DEFAULT_LIST_SIZE; } catch (OAIRequestException e) { String logMessage = "Cannot complete the request for the following repository URL " + repositoryUrl; LOGGER.info(logMessage, e); throw new TaskSubmissionException(logMessage + " Because: " + e.getMessage(), e); } } else { throw new TaskSubmissionException("The task was dropped because the repositoryUrl can not be null"); } } else return DEFAULT_LIST_SIZE; } } | OaiPmhFilesCounter extends FilesCounter { @Override public int getFilesCount(DpsTask task) throws TaskSubmissionException { OAIPMHHarvestingDetails harvestingDetails = task.getHarvestingDetails(); if (harvestingDetails != null) { if (specified(harvestingDetails.getExcludedSets()) || specified(harvestingDetails.getExcludedSchemas())) { LOGGER.info("Cannot count completeListSize for taskId= {} . Excluded sets or schemas are not supported", task.getTaskId()); return DEFAULT_LIST_SIZE; } String repositoryUrl = getRepositoryUrl(task.getInputData()); if (repositoryUrl != null) { ListIdentifiersParameters params = new ListIdentifiersParameters() .withFrom(harvestingDetails.getDateFrom()) .withUntil(harvestingDetails.getDateUntil()); Set<String> schemas = harvestingDetails.getSchemas(); Set<String> sets = harvestingDetails.getSets(); if (specified(sets)) { if (sets.size() == 1) { params.withSetSpec(sets.iterator().next()); } else { LOGGER.info("Cannot count completeListSize for taskId= {} . Specifying multiple sets is not supported ", task.getTaskId()); return DEFAULT_LIST_SIZE; } } try { return getListSizeForSchemasAndSet(repositoryUrl, params, schemas); } catch (OAIResponseParseException e) { LOGGER.info("Cannot count completeListSize for taskId= {}", task.getTaskId(), e); return DEFAULT_LIST_SIZE; } catch (OAIRequestException e) { String logMessage = "Cannot complete the request for the following repository URL " + repositoryUrl; LOGGER.info(logMessage, e); throw new TaskSubmissionException(logMessage + " Because: " + e.getMessage(), e); } } else { throw new TaskSubmissionException("The task was dropped because the repositoryUrl can not be null"); } } else return DEFAULT_LIST_SIZE; } } | OaiPmhFilesCounter extends FilesCounter { @Override public int getFilesCount(DpsTask task) throws TaskSubmissionException { OAIPMHHarvestingDetails harvestingDetails = task.getHarvestingDetails(); if (harvestingDetails != null) { if (specified(harvestingDetails.getExcludedSets()) || specified(harvestingDetails.getExcludedSchemas())) { LOGGER.info("Cannot count completeListSize for taskId= {} . Excluded sets or schemas are not supported", task.getTaskId()); return DEFAULT_LIST_SIZE; } String repositoryUrl = getRepositoryUrl(task.getInputData()); if (repositoryUrl != null) { ListIdentifiersParameters params = new ListIdentifiersParameters() .withFrom(harvestingDetails.getDateFrom()) .withUntil(harvestingDetails.getDateUntil()); Set<String> schemas = harvestingDetails.getSchemas(); Set<String> sets = harvestingDetails.getSets(); if (specified(sets)) { if (sets.size() == 1) { params.withSetSpec(sets.iterator().next()); } else { LOGGER.info("Cannot count completeListSize for taskId= {} . Specifying multiple sets is not supported ", task.getTaskId()); return DEFAULT_LIST_SIZE; } } try { return getListSizeForSchemasAndSet(repositoryUrl, params, schemas); } catch (OAIResponseParseException e) { LOGGER.info("Cannot count completeListSize for taskId= {}", task.getTaskId(), e); return DEFAULT_LIST_SIZE; } catch (OAIRequestException e) { String logMessage = "Cannot complete the request for the following repository URL " + repositoryUrl; LOGGER.info(logMessage, e); throw new TaskSubmissionException(logMessage + " Because: " + e.getMessage(), e); } } else { throw new TaskSubmissionException("The task was dropped because the repositoryUrl can not be null"); } } else return DEFAULT_LIST_SIZE; } @Override int getFilesCount(DpsTask task); } | OaiPmhFilesCounter extends FilesCounter { @Override public int getFilesCount(DpsTask task) throws TaskSubmissionException { OAIPMHHarvestingDetails harvestingDetails = task.getHarvestingDetails(); if (harvestingDetails != null) { if (specified(harvestingDetails.getExcludedSets()) || specified(harvestingDetails.getExcludedSchemas())) { LOGGER.info("Cannot count completeListSize for taskId= {} . Excluded sets or schemas are not supported", task.getTaskId()); return DEFAULT_LIST_SIZE; } String repositoryUrl = getRepositoryUrl(task.getInputData()); if (repositoryUrl != null) { ListIdentifiersParameters params = new ListIdentifiersParameters() .withFrom(harvestingDetails.getDateFrom()) .withUntil(harvestingDetails.getDateUntil()); Set<String> schemas = harvestingDetails.getSchemas(); Set<String> sets = harvestingDetails.getSets(); if (specified(sets)) { if (sets.size() == 1) { params.withSetSpec(sets.iterator().next()); } else { LOGGER.info("Cannot count completeListSize for taskId= {} . Specifying multiple sets is not supported ", task.getTaskId()); return DEFAULT_LIST_SIZE; } } try { return getListSizeForSchemasAndSet(repositoryUrl, params, schemas); } catch (OAIResponseParseException e) { LOGGER.info("Cannot count completeListSize for taskId= {}", task.getTaskId(), e); return DEFAULT_LIST_SIZE; } catch (OAIRequestException e) { String logMessage = "Cannot complete the request for the following repository URL " + repositoryUrl; LOGGER.info(logMessage, e); throw new TaskSubmissionException(logMessage + " Because: " + e.getMessage(), e); } } else { throw new TaskSubmissionException("The task was dropped because the repositoryUrl can not be null"); } } else return DEFAULT_LIST_SIZE; } @Override int getFilesCount(DpsTask task); static final String COMPLETE_LIST_SIZE; } |
@Test public void shouldCountRecords() throws Exception { int randomNum = ThreadLocalRandom.current().nextInt(1, DATASET_EXPECTED_SIZE); StringBuilder records = new StringBuilder("r1"); for(int index = 2; index <= randomNum; index++) { records.append(", r"); records.append(index); } DpsTask dpsTask = new DpsTask(); dpsTask.addParameter(METIS_DATASET_ID, ""); dpsTask.addParameter(RECORD_IDS_TO_DEPUBLISH, records.toString()); DepublicationFilesCounter depublicationFilesCounter = new DepublicationFilesCounter(datasetDepublisher); int count = depublicationFilesCounter.getFilesCount(dpsTask); assertEquals(randomNum, count); } | @Override public int getFilesCount(DpsTask task) throws TaskSubmissionException { if (task.getParameter(PluginParameterKeys.RECORD_IDS_TO_DEPUBLISH) != null) { return calculateRecordsNumber(task); } if (task.getParameter(PluginParameterKeys.METIS_DATASET_ID) != null) { return calculateDatasetSize(task); } throw new TaskSubmissionException("Can't evaluate task expected size! Needed parameters not found in the task"); } | DepublicationFilesCounter extends FilesCounter { @Override public int getFilesCount(DpsTask task) throws TaskSubmissionException { if (task.getParameter(PluginParameterKeys.RECORD_IDS_TO_DEPUBLISH) != null) { return calculateRecordsNumber(task); } if (task.getParameter(PluginParameterKeys.METIS_DATASET_ID) != null) { return calculateDatasetSize(task); } throw new TaskSubmissionException("Can't evaluate task expected size! Needed parameters not found in the task"); } } | DepublicationFilesCounter extends FilesCounter { @Override public int getFilesCount(DpsTask task) throws TaskSubmissionException { if (task.getParameter(PluginParameterKeys.RECORD_IDS_TO_DEPUBLISH) != null) { return calculateRecordsNumber(task); } if (task.getParameter(PluginParameterKeys.METIS_DATASET_ID) != null) { return calculateDatasetSize(task); } throw new TaskSubmissionException("Can't evaluate task expected size! Needed parameters not found in the task"); } DepublicationFilesCounter(DatasetDepublisher depublisher); } | DepublicationFilesCounter extends FilesCounter { @Override public int getFilesCount(DpsTask task) throws TaskSubmissionException { if (task.getParameter(PluginParameterKeys.RECORD_IDS_TO_DEPUBLISH) != null) { return calculateRecordsNumber(task); } if (task.getParameter(PluginParameterKeys.METIS_DATASET_ID) != null) { return calculateDatasetSize(task); } throw new TaskSubmissionException("Can't evaluate task expected size! Needed parameters not found in the task"); } DepublicationFilesCounter(DatasetDepublisher depublisher); @Override int getFilesCount(DpsTask task); } | DepublicationFilesCounter extends FilesCounter { @Override public int getFilesCount(DpsTask task) throws TaskSubmissionException { if (task.getParameter(PluginParameterKeys.RECORD_IDS_TO_DEPUBLISH) != null) { return calculateRecordsNumber(task); } if (task.getParameter(PluginParameterKeys.METIS_DATASET_ID) != null) { return calculateDatasetSize(task); } throw new TaskSubmissionException("Can't evaluate task expected size! Needed parameters not found in the task"); } DepublicationFilesCounter(DatasetDepublisher depublisher); @Override int getFilesCount(DpsTask task); } |
@Test public void shouldCountEntireDataset() throws Exception { DpsTask dpsTask = new DpsTask(); dpsTask.addParameter(METIS_DATASET_ID, ""); DepublicationFilesCounter depublicationFilesCounter = new DepublicationFilesCounter(datasetDepublisher); int count = depublicationFilesCounter.getFilesCount(dpsTask); assertEquals(DATASET_EXPECTED_SIZE, count); } | @Override public int getFilesCount(DpsTask task) throws TaskSubmissionException { if (task.getParameter(PluginParameterKeys.RECORD_IDS_TO_DEPUBLISH) != null) { return calculateRecordsNumber(task); } if (task.getParameter(PluginParameterKeys.METIS_DATASET_ID) != null) { return calculateDatasetSize(task); } throw new TaskSubmissionException("Can't evaluate task expected size! Needed parameters not found in the task"); } | DepublicationFilesCounter extends FilesCounter { @Override public int getFilesCount(DpsTask task) throws TaskSubmissionException { if (task.getParameter(PluginParameterKeys.RECORD_IDS_TO_DEPUBLISH) != null) { return calculateRecordsNumber(task); } if (task.getParameter(PluginParameterKeys.METIS_DATASET_ID) != null) { return calculateDatasetSize(task); } throw new TaskSubmissionException("Can't evaluate task expected size! Needed parameters not found in the task"); } } | DepublicationFilesCounter extends FilesCounter { @Override public int getFilesCount(DpsTask task) throws TaskSubmissionException { if (task.getParameter(PluginParameterKeys.RECORD_IDS_TO_DEPUBLISH) != null) { return calculateRecordsNumber(task); } if (task.getParameter(PluginParameterKeys.METIS_DATASET_ID) != null) { return calculateDatasetSize(task); } throw new TaskSubmissionException("Can't evaluate task expected size! Needed parameters not found in the task"); } DepublicationFilesCounter(DatasetDepublisher depublisher); } | DepublicationFilesCounter extends FilesCounter { @Override public int getFilesCount(DpsTask task) throws TaskSubmissionException { if (task.getParameter(PluginParameterKeys.RECORD_IDS_TO_DEPUBLISH) != null) { return calculateRecordsNumber(task); } if (task.getParameter(PluginParameterKeys.METIS_DATASET_ID) != null) { return calculateDatasetSize(task); } throw new TaskSubmissionException("Can't evaluate task expected size! Needed parameters not found in the task"); } DepublicationFilesCounter(DatasetDepublisher depublisher); @Override int getFilesCount(DpsTask task); } | DepublicationFilesCounter extends FilesCounter { @Override public int getFilesCount(DpsTask task) throws TaskSubmissionException { if (task.getParameter(PluginParameterKeys.RECORD_IDS_TO_DEPUBLISH) != null) { return calculateRecordsNumber(task); } if (task.getParameter(PluginParameterKeys.METIS_DATASET_ID) != null) { return calculateDatasetSize(task); } throw new TaskSubmissionException("Can't evaluate task expected size! Needed parameters not found in the task"); } DepublicationFilesCounter(DatasetDepublisher depublisher); @Override int getFilesCount(DpsTask task); } |
@Test public void verifyUseValidEnvironmentIfNoAlternativeEnvironmentParameterSet() throws IndexingException, URISyntaxException { service.depublishDataset(parameters); verify(metisIndexerFactory, atLeast(1)).openIndexer(eq(false)); verify(metisIndexerFactory, never()).openIndexer(eq(true)); } | public void depublishDataset(SubmitTaskParameters parameters) { try { long taskId = parameters.getTask().getTaskId(); checkTaskKilled(taskId); Future<Integer> future = depublisher.executeDatasetDepublicationAsync(parameters); waitForFinish(future, parameters); } catch (SubmitingTaskWasKilled e) { LOGGER.warn(e.getMessage(), e); } catch (Exception e) { saveErrorResult(parameters, e); } } | DepublicationService { public void depublishDataset(SubmitTaskParameters parameters) { try { long taskId = parameters.getTask().getTaskId(); checkTaskKilled(taskId); Future<Integer> future = depublisher.executeDatasetDepublicationAsync(parameters); waitForFinish(future, parameters); } catch (SubmitingTaskWasKilled e) { LOGGER.warn(e.getMessage(), e); } catch (Exception e) { saveErrorResult(parameters, e); } } } | DepublicationService { public void depublishDataset(SubmitTaskParameters parameters) { try { long taskId = parameters.getTask().getTaskId(); checkTaskKilled(taskId); Future<Integer> future = depublisher.executeDatasetDepublicationAsync(parameters); waitForFinish(future, parameters); } catch (SubmitingTaskWasKilled e) { LOGGER.warn(e.getMessage(), e); } catch (Exception e) { saveErrorResult(parameters, e); } } DepublicationService(TaskStatusChecker taskStatusChecker, DatasetDepublisher depublisher, TaskStatusUpdater taskStatusUpdater, RecordStatusUpdater recordStatusUpdater); } | DepublicationService { public void depublishDataset(SubmitTaskParameters parameters) { try { long taskId = parameters.getTask().getTaskId(); checkTaskKilled(taskId); Future<Integer> future = depublisher.executeDatasetDepublicationAsync(parameters); waitForFinish(future, parameters); } catch (SubmitingTaskWasKilled e) { LOGGER.warn(e.getMessage(), e); } catch (Exception e) { saveErrorResult(parameters, e); } } DepublicationService(TaskStatusChecker taskStatusChecker, DatasetDepublisher depublisher, TaskStatusUpdater taskStatusUpdater, RecordStatusUpdater recordStatusUpdater); void depublishDataset(SubmitTaskParameters parameters); void depublishIndividualRecords(SubmitTaskParameters parameters); } | DepublicationService { public void depublishDataset(SubmitTaskParameters parameters) { try { long taskId = parameters.getTask().getTaskId(); checkTaskKilled(taskId); Future<Integer> future = depublisher.executeDatasetDepublicationAsync(parameters); waitForFinish(future, parameters); } catch (SubmitingTaskWasKilled e) { LOGGER.warn(e.getMessage(), e); } catch (Exception e) { saveErrorResult(parameters, e); } } DepublicationService(TaskStatusChecker taskStatusChecker, DatasetDepublisher depublisher, TaskStatusUpdater taskStatusUpdater, RecordStatusUpdater recordStatusUpdater); void depublishDataset(SubmitTaskParameters parameters); void depublishIndividualRecords(SubmitTaskParameters parameters); } |
@Test public void verifyUseAlternativeEnvironmentIfAlternativeEnvironmentParameterSet() throws IndexingException, URISyntaxException { task.addParameter(PluginParameterKeys.METIS_USE_ALT_INDEXING_ENV, "true"); service.depublishDataset(parameters); verify(metisIndexerFactory, atLeast(1)).openIndexer(eq(true)); verify(metisIndexerFactory, never()).openIndexer(eq(false)); } | public void depublishDataset(SubmitTaskParameters parameters) { try { long taskId = parameters.getTask().getTaskId(); checkTaskKilled(taskId); Future<Integer> future = depublisher.executeDatasetDepublicationAsync(parameters); waitForFinish(future, parameters); } catch (SubmitingTaskWasKilled e) { LOGGER.warn(e.getMessage(), e); } catch (Exception e) { saveErrorResult(parameters, e); } } | DepublicationService { public void depublishDataset(SubmitTaskParameters parameters) { try { long taskId = parameters.getTask().getTaskId(); checkTaskKilled(taskId); Future<Integer> future = depublisher.executeDatasetDepublicationAsync(parameters); waitForFinish(future, parameters); } catch (SubmitingTaskWasKilled e) { LOGGER.warn(e.getMessage(), e); } catch (Exception e) { saveErrorResult(parameters, e); } } } | DepublicationService { public void depublishDataset(SubmitTaskParameters parameters) { try { long taskId = parameters.getTask().getTaskId(); checkTaskKilled(taskId); Future<Integer> future = depublisher.executeDatasetDepublicationAsync(parameters); waitForFinish(future, parameters); } catch (SubmitingTaskWasKilled e) { LOGGER.warn(e.getMessage(), e); } catch (Exception e) { saveErrorResult(parameters, e); } } DepublicationService(TaskStatusChecker taskStatusChecker, DatasetDepublisher depublisher, TaskStatusUpdater taskStatusUpdater, RecordStatusUpdater recordStatusUpdater); } | DepublicationService { public void depublishDataset(SubmitTaskParameters parameters) { try { long taskId = parameters.getTask().getTaskId(); checkTaskKilled(taskId); Future<Integer> future = depublisher.executeDatasetDepublicationAsync(parameters); waitForFinish(future, parameters); } catch (SubmitingTaskWasKilled e) { LOGGER.warn(e.getMessage(), e); } catch (Exception e) { saveErrorResult(parameters, e); } } DepublicationService(TaskStatusChecker taskStatusChecker, DatasetDepublisher depublisher, TaskStatusUpdater taskStatusUpdater, RecordStatusUpdater recordStatusUpdater); void depublishDataset(SubmitTaskParameters parameters); void depublishIndividualRecords(SubmitTaskParameters parameters); } | DepublicationService { public void depublishDataset(SubmitTaskParameters parameters) { try { long taskId = parameters.getTask().getTaskId(); checkTaskKilled(taskId); Future<Integer> future = depublisher.executeDatasetDepublicationAsync(parameters); waitForFinish(future, parameters); } catch (SubmitingTaskWasKilled e) { LOGGER.warn(e.getMessage(), e); } catch (Exception e) { saveErrorResult(parameters, e); } } DepublicationService(TaskStatusChecker taskStatusChecker, DatasetDepublisher depublisher, TaskStatusUpdater taskStatusUpdater, RecordStatusUpdater recordStatusUpdater); void depublishDataset(SubmitTaskParameters parameters); void depublishIndividualRecords(SubmitTaskParameters parameters); } |
@Test public void verifyTaskRemoveInvokedOnIndexer() throws IndexingException { service.depublishDataset(parameters); verify(indexer).removeAll(eq(DATASET_METIS_ID), isNull(Date.class)); assertTaskSucceed(); } | public void depublishDataset(SubmitTaskParameters parameters) { try { long taskId = parameters.getTask().getTaskId(); checkTaskKilled(taskId); Future<Integer> future = depublisher.executeDatasetDepublicationAsync(parameters); waitForFinish(future, parameters); } catch (SubmitingTaskWasKilled e) { LOGGER.warn(e.getMessage(), e); } catch (Exception e) { saveErrorResult(parameters, e); } } | DepublicationService { public void depublishDataset(SubmitTaskParameters parameters) { try { long taskId = parameters.getTask().getTaskId(); checkTaskKilled(taskId); Future<Integer> future = depublisher.executeDatasetDepublicationAsync(parameters); waitForFinish(future, parameters); } catch (SubmitingTaskWasKilled e) { LOGGER.warn(e.getMessage(), e); } catch (Exception e) { saveErrorResult(parameters, e); } } } | DepublicationService { public void depublishDataset(SubmitTaskParameters parameters) { try { long taskId = parameters.getTask().getTaskId(); checkTaskKilled(taskId); Future<Integer> future = depublisher.executeDatasetDepublicationAsync(parameters); waitForFinish(future, parameters); } catch (SubmitingTaskWasKilled e) { LOGGER.warn(e.getMessage(), e); } catch (Exception e) { saveErrorResult(parameters, e); } } DepublicationService(TaskStatusChecker taskStatusChecker, DatasetDepublisher depublisher, TaskStatusUpdater taskStatusUpdater, RecordStatusUpdater recordStatusUpdater); } | DepublicationService { public void depublishDataset(SubmitTaskParameters parameters) { try { long taskId = parameters.getTask().getTaskId(); checkTaskKilled(taskId); Future<Integer> future = depublisher.executeDatasetDepublicationAsync(parameters); waitForFinish(future, parameters); } catch (SubmitingTaskWasKilled e) { LOGGER.warn(e.getMessage(), e); } catch (Exception e) { saveErrorResult(parameters, e); } } DepublicationService(TaskStatusChecker taskStatusChecker, DatasetDepublisher depublisher, TaskStatusUpdater taskStatusUpdater, RecordStatusUpdater recordStatusUpdater); void depublishDataset(SubmitTaskParameters parameters); void depublishIndividualRecords(SubmitTaskParameters parameters); } | DepublicationService { public void depublishDataset(SubmitTaskParameters parameters) { try { long taskId = parameters.getTask().getTaskId(); checkTaskKilled(taskId); Future<Integer> future = depublisher.executeDatasetDepublicationAsync(parameters); waitForFinish(future, parameters); } catch (SubmitingTaskWasKilled e) { LOGGER.warn(e.getMessage(), e); } catch (Exception e) { saveErrorResult(parameters, e); } } DepublicationService(TaskStatusChecker taskStatusChecker, DatasetDepublisher depublisher, TaskStatusUpdater taskStatusUpdater, RecordStatusUpdater recordStatusUpdater); void depublishDataset(SubmitTaskParameters parameters); void depublishIndividualRecords(SubmitTaskParameters parameters); } |
@Test public void verifyWaitForAllRowsRemoved() throws IndexingException { AtomicBoolean allRowsRemoved = new AtomicBoolean(false); StopWatch watch = StopWatch.createStarted(); when(indexer.countRecords(anyString())).then(r -> { allRowsRemoved.set(watch.getTime() > WAITING_FOR_COMPLETE_TIME); if (allRowsRemoved.get()) { return 0; } else { return EXPECTED_SIZE; } }); service.depublishDataset(parameters); assertTaskSucceed(); assertTrue(allRowsRemoved.get()); } | public void depublishDataset(SubmitTaskParameters parameters) { try { long taskId = parameters.getTask().getTaskId(); checkTaskKilled(taskId); Future<Integer> future = depublisher.executeDatasetDepublicationAsync(parameters); waitForFinish(future, parameters); } catch (SubmitingTaskWasKilled e) { LOGGER.warn(e.getMessage(), e); } catch (Exception e) { saveErrorResult(parameters, e); } } | DepublicationService { public void depublishDataset(SubmitTaskParameters parameters) { try { long taskId = parameters.getTask().getTaskId(); checkTaskKilled(taskId); Future<Integer> future = depublisher.executeDatasetDepublicationAsync(parameters); waitForFinish(future, parameters); } catch (SubmitingTaskWasKilled e) { LOGGER.warn(e.getMessage(), e); } catch (Exception e) { saveErrorResult(parameters, e); } } } | DepublicationService { public void depublishDataset(SubmitTaskParameters parameters) { try { long taskId = parameters.getTask().getTaskId(); checkTaskKilled(taskId); Future<Integer> future = depublisher.executeDatasetDepublicationAsync(parameters); waitForFinish(future, parameters); } catch (SubmitingTaskWasKilled e) { LOGGER.warn(e.getMessage(), e); } catch (Exception e) { saveErrorResult(parameters, e); } } DepublicationService(TaskStatusChecker taskStatusChecker, DatasetDepublisher depublisher, TaskStatusUpdater taskStatusUpdater, RecordStatusUpdater recordStatusUpdater); } | DepublicationService { public void depublishDataset(SubmitTaskParameters parameters) { try { long taskId = parameters.getTask().getTaskId(); checkTaskKilled(taskId); Future<Integer> future = depublisher.executeDatasetDepublicationAsync(parameters); waitForFinish(future, parameters); } catch (SubmitingTaskWasKilled e) { LOGGER.warn(e.getMessage(), e); } catch (Exception e) { saveErrorResult(parameters, e); } } DepublicationService(TaskStatusChecker taskStatusChecker, DatasetDepublisher depublisher, TaskStatusUpdater taskStatusUpdater, RecordStatusUpdater recordStatusUpdater); void depublishDataset(SubmitTaskParameters parameters); void depublishIndividualRecords(SubmitTaskParameters parameters); } | DepublicationService { public void depublishDataset(SubmitTaskParameters parameters) { try { long taskId = parameters.getTask().getTaskId(); checkTaskKilled(taskId); Future<Integer> future = depublisher.executeDatasetDepublicationAsync(parameters); waitForFinish(future, parameters); } catch (SubmitingTaskWasKilled e) { LOGGER.warn(e.getMessage(), e); } catch (Exception e) { saveErrorResult(parameters, e); } } DepublicationService(TaskStatusChecker taskStatusChecker, DatasetDepublisher depublisher, TaskStatusUpdater taskStatusUpdater, RecordStatusUpdater recordStatusUpdater); void depublishDataset(SubmitTaskParameters parameters); void depublishIndividualRecords(SubmitTaskParameters parameters); } |
@Test public void verifyTaskRemoveNotInvokedIfTaskWereKilledBefore() throws IndexingException { when(taskStatusChecker.hasKillFlag(anyLong())).thenReturn(true); service.depublishDataset(parameters); verify(indexer, never()).removeAll(eq(DATASET_METIS_ID), isNull(Date.class)); verify(updater, never()).setTaskCompletelyProcessed(eq(TASK_ID), anyString()); } | public void depublishDataset(SubmitTaskParameters parameters) { try { long taskId = parameters.getTask().getTaskId(); checkTaskKilled(taskId); Future<Integer> future = depublisher.executeDatasetDepublicationAsync(parameters); waitForFinish(future, parameters); } catch (SubmitingTaskWasKilled e) { LOGGER.warn(e.getMessage(), e); } catch (Exception e) { saveErrorResult(parameters, e); } } | DepublicationService { public void depublishDataset(SubmitTaskParameters parameters) { try { long taskId = parameters.getTask().getTaskId(); checkTaskKilled(taskId); Future<Integer> future = depublisher.executeDatasetDepublicationAsync(parameters); waitForFinish(future, parameters); } catch (SubmitingTaskWasKilled e) { LOGGER.warn(e.getMessage(), e); } catch (Exception e) { saveErrorResult(parameters, e); } } } | DepublicationService { public void depublishDataset(SubmitTaskParameters parameters) { try { long taskId = parameters.getTask().getTaskId(); checkTaskKilled(taskId); Future<Integer> future = depublisher.executeDatasetDepublicationAsync(parameters); waitForFinish(future, parameters); } catch (SubmitingTaskWasKilled e) { LOGGER.warn(e.getMessage(), e); } catch (Exception e) { saveErrorResult(parameters, e); } } DepublicationService(TaskStatusChecker taskStatusChecker, DatasetDepublisher depublisher, TaskStatusUpdater taskStatusUpdater, RecordStatusUpdater recordStatusUpdater); } | DepublicationService { public void depublishDataset(SubmitTaskParameters parameters) { try { long taskId = parameters.getTask().getTaskId(); checkTaskKilled(taskId); Future<Integer> future = depublisher.executeDatasetDepublicationAsync(parameters); waitForFinish(future, parameters); } catch (SubmitingTaskWasKilled e) { LOGGER.warn(e.getMessage(), e); } catch (Exception e) { saveErrorResult(parameters, e); } } DepublicationService(TaskStatusChecker taskStatusChecker, DatasetDepublisher depublisher, TaskStatusUpdater taskStatusUpdater, RecordStatusUpdater recordStatusUpdater); void depublishDataset(SubmitTaskParameters parameters); void depublishIndividualRecords(SubmitTaskParameters parameters); } | DepublicationService { public void depublishDataset(SubmitTaskParameters parameters) { try { long taskId = parameters.getTask().getTaskId(); checkTaskKilled(taskId); Future<Integer> future = depublisher.executeDatasetDepublicationAsync(parameters); waitForFinish(future, parameters); } catch (SubmitingTaskWasKilled e) { LOGGER.warn(e.getMessage(), e); } catch (Exception e) { saveErrorResult(parameters, e); } } DepublicationService(TaskStatusChecker taskStatusChecker, DatasetDepublisher depublisher, TaskStatusUpdater taskStatusUpdater, RecordStatusUpdater recordStatusUpdater); void depublishDataset(SubmitTaskParameters parameters); void depublishIndividualRecords(SubmitTaskParameters parameters); } |
@Test public void verifyTaskFailedWhenRemoveMethodThrowsException() throws IndexingException { when(indexer.removeAll(anyString(), any(Date.class))).thenThrow(new IndexerRelatedIndexingException("Indexer exception!")); service.depublishDataset(parameters); assertTaskFailed(); } | public void depublishDataset(SubmitTaskParameters parameters) { try { long taskId = parameters.getTask().getTaskId(); checkTaskKilled(taskId); Future<Integer> future = depublisher.executeDatasetDepublicationAsync(parameters); waitForFinish(future, parameters); } catch (SubmitingTaskWasKilled e) { LOGGER.warn(e.getMessage(), e); } catch (Exception e) { saveErrorResult(parameters, e); } } | DepublicationService { public void depublishDataset(SubmitTaskParameters parameters) { try { long taskId = parameters.getTask().getTaskId(); checkTaskKilled(taskId); Future<Integer> future = depublisher.executeDatasetDepublicationAsync(parameters); waitForFinish(future, parameters); } catch (SubmitingTaskWasKilled e) { LOGGER.warn(e.getMessage(), e); } catch (Exception e) { saveErrorResult(parameters, e); } } } | DepublicationService { public void depublishDataset(SubmitTaskParameters parameters) { try { long taskId = parameters.getTask().getTaskId(); checkTaskKilled(taskId); Future<Integer> future = depublisher.executeDatasetDepublicationAsync(parameters); waitForFinish(future, parameters); } catch (SubmitingTaskWasKilled e) { LOGGER.warn(e.getMessage(), e); } catch (Exception e) { saveErrorResult(parameters, e); } } DepublicationService(TaskStatusChecker taskStatusChecker, DatasetDepublisher depublisher, TaskStatusUpdater taskStatusUpdater, RecordStatusUpdater recordStatusUpdater); } | DepublicationService { public void depublishDataset(SubmitTaskParameters parameters) { try { long taskId = parameters.getTask().getTaskId(); checkTaskKilled(taskId); Future<Integer> future = depublisher.executeDatasetDepublicationAsync(parameters); waitForFinish(future, parameters); } catch (SubmitingTaskWasKilled e) { LOGGER.warn(e.getMessage(), e); } catch (Exception e) { saveErrorResult(parameters, e); } } DepublicationService(TaskStatusChecker taskStatusChecker, DatasetDepublisher depublisher, TaskStatusUpdater taskStatusUpdater, RecordStatusUpdater recordStatusUpdater); void depublishDataset(SubmitTaskParameters parameters); void depublishIndividualRecords(SubmitTaskParameters parameters); } | DepublicationService { public void depublishDataset(SubmitTaskParameters parameters) { try { long taskId = parameters.getTask().getTaskId(); checkTaskKilled(taskId); Future<Integer> future = depublisher.executeDatasetDepublicationAsync(parameters); waitForFinish(future, parameters); } catch (SubmitingTaskWasKilled e) { LOGGER.warn(e.getMessage(), e); } catch (Exception e) { saveErrorResult(parameters, e); } } DepublicationService(TaskStatusChecker taskStatusChecker, DatasetDepublisher depublisher, TaskStatusUpdater taskStatusUpdater, RecordStatusUpdater recordStatusUpdater); void depublishDataset(SubmitTaskParameters parameters); void depublishIndividualRecords(SubmitTaskParameters parameters); } |
@Test public void verifyTaskFailedWhenRemovedRowCountNotMatchExpected() throws IndexingException { when(indexer.removeAll(anyString(), any(Date.class))).thenReturn(EXPECTED_SIZE + 2); service.depublishDataset(parameters); assertTaskFailed(); } | public void depublishDataset(SubmitTaskParameters parameters) { try { long taskId = parameters.getTask().getTaskId(); checkTaskKilled(taskId); Future<Integer> future = depublisher.executeDatasetDepublicationAsync(parameters); waitForFinish(future, parameters); } catch (SubmitingTaskWasKilled e) { LOGGER.warn(e.getMessage(), e); } catch (Exception e) { saveErrorResult(parameters, e); } } | DepublicationService { public void depublishDataset(SubmitTaskParameters parameters) { try { long taskId = parameters.getTask().getTaskId(); checkTaskKilled(taskId); Future<Integer> future = depublisher.executeDatasetDepublicationAsync(parameters); waitForFinish(future, parameters); } catch (SubmitingTaskWasKilled e) { LOGGER.warn(e.getMessage(), e); } catch (Exception e) { saveErrorResult(parameters, e); } } } | DepublicationService { public void depublishDataset(SubmitTaskParameters parameters) { try { long taskId = parameters.getTask().getTaskId(); checkTaskKilled(taskId); Future<Integer> future = depublisher.executeDatasetDepublicationAsync(parameters); waitForFinish(future, parameters); } catch (SubmitingTaskWasKilled e) { LOGGER.warn(e.getMessage(), e); } catch (Exception e) { saveErrorResult(parameters, e); } } DepublicationService(TaskStatusChecker taskStatusChecker, DatasetDepublisher depublisher, TaskStatusUpdater taskStatusUpdater, RecordStatusUpdater recordStatusUpdater); } | DepublicationService { public void depublishDataset(SubmitTaskParameters parameters) { try { long taskId = parameters.getTask().getTaskId(); checkTaskKilled(taskId); Future<Integer> future = depublisher.executeDatasetDepublicationAsync(parameters); waitForFinish(future, parameters); } catch (SubmitingTaskWasKilled e) { LOGGER.warn(e.getMessage(), e); } catch (Exception e) { saveErrorResult(parameters, e); } } DepublicationService(TaskStatusChecker taskStatusChecker, DatasetDepublisher depublisher, TaskStatusUpdater taskStatusUpdater, RecordStatusUpdater recordStatusUpdater); void depublishDataset(SubmitTaskParameters parameters); void depublishIndividualRecords(SubmitTaskParameters parameters); } | DepublicationService { public void depublishDataset(SubmitTaskParameters parameters) { try { long taskId = parameters.getTask().getTaskId(); checkTaskKilled(taskId); Future<Integer> future = depublisher.executeDatasetDepublicationAsync(parameters); waitForFinish(future, parameters); } catch (SubmitingTaskWasKilled e) { LOGGER.warn(e.getMessage(), e); } catch (Exception e) { saveErrorResult(parameters, e); } } DepublicationService(TaskStatusChecker taskStatusChecker, DatasetDepublisher depublisher, TaskStatusUpdater taskStatusUpdater, RecordStatusUpdater recordStatusUpdater); void depublishDataset(SubmitTaskParameters parameters); void depublishIndividualRecords(SubmitTaskParameters parameters); } |
@Test public void verifyJobExecution() throws Exception { CassandraConnectionProvider cassandraConnectionProvider = mock(CassandraConnectionProvider.class); int threadCount = 1; String tableName = "tableName"; KeyspaceValidator keyspaceValidator = new KeyspaceValidator(); Metadata metadata = mock(Metadata.class); KeyspaceMetadata keyspaceMetadata = mock(KeyspaceMetadata.class); when(cassandraConnectionProvider.getMetadata()).thenReturn(metadata); when(cassandraConnectionProvider.getKeyspaceName()).thenReturn("keyspace"); when(metadata.getKeyspace(anyString())).thenReturn(keyspaceMetadata); TableMetadata tableMetadata = mock(TableMetadata.class); when(tableMetadata.getName()).thenReturn(tableName); Collection<TableMetadata> tableMetadataList = Arrays.asList(tableMetadata); when(keyspaceMetadata.getTables()).thenReturn(tableMetadataList); PowerMockito.whenNew(CassandraConnectionProvider.class).withAnyArguments().thenReturn(cassandraConnectionProvider); ExecutorService executorService = mock(ExecutorService.class); PowerMockito.mockStatic(Executors.class); when(Executors.newFixedThreadPool(threadCount)).thenReturn(executorService); keyspaceValidator.validate(cassandraConnectionProvider, cassandraConnectionProvider, tableName, tableName, threadCount); verify(executorService, times(1)).invokeAll(any(Collection.class)); } | @Override public void validate(CassandraConnectionProvider sourceCassandraConnectionProvider, CassandraConnectionProvider targetCassandraConnectionProvider, String sourceTableName, String targetTableName, int threadsCount) throws InterruptedException, ExecutionException { ExecutorService executorService = null; try { Iterator<TableMetadata> tmIterator = sourceCassandraConnectionProvider.getMetadata().getKeyspace(sourceCassandraConnectionProvider.getKeyspaceName()).getTables().iterator(); final Set<Callable<Void>> tableValidatorJobs = new HashSet<>(); executorService = Executors.newFixedThreadPool(threadsCount); while (tmIterator.hasNext()) { CassandraConnectionProvider newSourceCassandraConnectionProvider = new CassandraConnectionProvider(sourceCassandraConnectionProvider); CassandraConnectionProvider newTargetCassandraConnectionProvider = new CassandraConnectionProvider(targetCassandraConnectionProvider); DataValidator dataValidator = new DataValidator(newSourceCassandraConnectionProvider, newTargetCassandraConnectionProvider); TableMetadata t = tmIterator.next(); LOGGER.info("Checking data integrity between source table " + t.getName() + " and target table " + t.getName()); tableValidatorJobs.add(new TableValidatorJob(dataValidator, t.getName(), t.getName(), threadsCount)); } executorService.invokeAll(tableValidatorJobs); } finally { if (executorService != null) executorService.shutdown(); if (sourceCassandraConnectionProvider != null) sourceCassandraConnectionProvider.closeConnections(); if (targetCassandraConnectionProvider != null) targetCassandraConnectionProvider.closeConnections(); } } | KeyspaceValidator implements Validator { @Override public void validate(CassandraConnectionProvider sourceCassandraConnectionProvider, CassandraConnectionProvider targetCassandraConnectionProvider, String sourceTableName, String targetTableName, int threadsCount) throws InterruptedException, ExecutionException { ExecutorService executorService = null; try { Iterator<TableMetadata> tmIterator = sourceCassandraConnectionProvider.getMetadata().getKeyspace(sourceCassandraConnectionProvider.getKeyspaceName()).getTables().iterator(); final Set<Callable<Void>> tableValidatorJobs = new HashSet<>(); executorService = Executors.newFixedThreadPool(threadsCount); while (tmIterator.hasNext()) { CassandraConnectionProvider newSourceCassandraConnectionProvider = new CassandraConnectionProvider(sourceCassandraConnectionProvider); CassandraConnectionProvider newTargetCassandraConnectionProvider = new CassandraConnectionProvider(targetCassandraConnectionProvider); DataValidator dataValidator = new DataValidator(newSourceCassandraConnectionProvider, newTargetCassandraConnectionProvider); TableMetadata t = tmIterator.next(); LOGGER.info("Checking data integrity between source table " + t.getName() + " and target table " + t.getName()); tableValidatorJobs.add(new TableValidatorJob(dataValidator, t.getName(), t.getName(), threadsCount)); } executorService.invokeAll(tableValidatorJobs); } finally { if (executorService != null) executorService.shutdown(); if (sourceCassandraConnectionProvider != null) sourceCassandraConnectionProvider.closeConnections(); if (targetCassandraConnectionProvider != null) targetCassandraConnectionProvider.closeConnections(); } } } | KeyspaceValidator implements Validator { @Override public void validate(CassandraConnectionProvider sourceCassandraConnectionProvider, CassandraConnectionProvider targetCassandraConnectionProvider, String sourceTableName, String targetTableName, int threadsCount) throws InterruptedException, ExecutionException { ExecutorService executorService = null; try { Iterator<TableMetadata> tmIterator = sourceCassandraConnectionProvider.getMetadata().getKeyspace(sourceCassandraConnectionProvider.getKeyspaceName()).getTables().iterator(); final Set<Callable<Void>> tableValidatorJobs = new HashSet<>(); executorService = Executors.newFixedThreadPool(threadsCount); while (tmIterator.hasNext()) { CassandraConnectionProvider newSourceCassandraConnectionProvider = new CassandraConnectionProvider(sourceCassandraConnectionProvider); CassandraConnectionProvider newTargetCassandraConnectionProvider = new CassandraConnectionProvider(targetCassandraConnectionProvider); DataValidator dataValidator = new DataValidator(newSourceCassandraConnectionProvider, newTargetCassandraConnectionProvider); TableMetadata t = tmIterator.next(); LOGGER.info("Checking data integrity between source table " + t.getName() + " and target table " + t.getName()); tableValidatorJobs.add(new TableValidatorJob(dataValidator, t.getName(), t.getName(), threadsCount)); } executorService.invokeAll(tableValidatorJobs); } finally { if (executorService != null) executorService.shutdown(); if (sourceCassandraConnectionProvider != null) sourceCassandraConnectionProvider.closeConnections(); if (targetCassandraConnectionProvider != null) targetCassandraConnectionProvider.closeConnections(); } } } | KeyspaceValidator implements Validator { @Override public void validate(CassandraConnectionProvider sourceCassandraConnectionProvider, CassandraConnectionProvider targetCassandraConnectionProvider, String sourceTableName, String targetTableName, int threadsCount) throws InterruptedException, ExecutionException { ExecutorService executorService = null; try { Iterator<TableMetadata> tmIterator = sourceCassandraConnectionProvider.getMetadata().getKeyspace(sourceCassandraConnectionProvider.getKeyspaceName()).getTables().iterator(); final Set<Callable<Void>> tableValidatorJobs = new HashSet<>(); executorService = Executors.newFixedThreadPool(threadsCount); while (tmIterator.hasNext()) { CassandraConnectionProvider newSourceCassandraConnectionProvider = new CassandraConnectionProvider(sourceCassandraConnectionProvider); CassandraConnectionProvider newTargetCassandraConnectionProvider = new CassandraConnectionProvider(targetCassandraConnectionProvider); DataValidator dataValidator = new DataValidator(newSourceCassandraConnectionProvider, newTargetCassandraConnectionProvider); TableMetadata t = tmIterator.next(); LOGGER.info("Checking data integrity between source table " + t.getName() + " and target table " + t.getName()); tableValidatorJobs.add(new TableValidatorJob(dataValidator, t.getName(), t.getName(), threadsCount)); } executorService.invokeAll(tableValidatorJobs); } finally { if (executorService != null) executorService.shutdown(); if (sourceCassandraConnectionProvider != null) sourceCassandraConnectionProvider.closeConnections(); if (targetCassandraConnectionProvider != null) targetCassandraConnectionProvider.closeConnections(); } } @Override void validate(CassandraConnectionProvider sourceCassandraConnectionProvider, CassandraConnectionProvider targetCassandraConnectionProvider, String sourceTableName, String targetTableName, int threadsCount); } | KeyspaceValidator implements Validator { @Override public void validate(CassandraConnectionProvider sourceCassandraConnectionProvider, CassandraConnectionProvider targetCassandraConnectionProvider, String sourceTableName, String targetTableName, int threadsCount) throws InterruptedException, ExecutionException { ExecutorService executorService = null; try { Iterator<TableMetadata> tmIterator = sourceCassandraConnectionProvider.getMetadata().getKeyspace(sourceCassandraConnectionProvider.getKeyspaceName()).getTables().iterator(); final Set<Callable<Void>> tableValidatorJobs = new HashSet<>(); executorService = Executors.newFixedThreadPool(threadsCount); while (tmIterator.hasNext()) { CassandraConnectionProvider newSourceCassandraConnectionProvider = new CassandraConnectionProvider(sourceCassandraConnectionProvider); CassandraConnectionProvider newTargetCassandraConnectionProvider = new CassandraConnectionProvider(targetCassandraConnectionProvider); DataValidator dataValidator = new DataValidator(newSourceCassandraConnectionProvider, newTargetCassandraConnectionProvider); TableMetadata t = tmIterator.next(); LOGGER.info("Checking data integrity between source table " + t.getName() + " and target table " + t.getName()); tableValidatorJobs.add(new TableValidatorJob(dataValidator, t.getName(), t.getName(), threadsCount)); } executorService.invokeAll(tableValidatorJobs); } finally { if (executorService != null) executorService.shutdown(); if (sourceCassandraConnectionProvider != null) sourceCassandraConnectionProvider.closeConnections(); if (targetCassandraConnectionProvider != null) targetCassandraConnectionProvider.closeConnections(); } } @Override void validate(CassandraConnectionProvider sourceCassandraConnectionProvider, CassandraConnectionProvider targetCassandraConnectionProvider, String sourceTableName, String targetTableName, int threadsCount); } |
@Betamax(tape = "DPSClient/submitTaskAndFail") @Test(expected = AccessDeniedOrObjectDoesNotExistException.class) public final void shouldThrowAnExceptionWhenCannotSubmitATask() throws Exception { dpsClient = new DpsClient(BASE_URL, REGULAR_USER_NAME, REGULAR_USER_PASSWORD); DpsTask task = prepareDpsTask(); dpsClient.submitTask(task, TOPOLOGY_NAME); } | public long submitTask(DpsTask task, String topologyName) throws DpsException { Response resp = null; try { resp = client.target(dpsUrl) .path(TASKS_URL) .resolveTemplate(TOPOLOGY_NAME, topologyName) .request() .post(Entity.json(task)); if (resp.getStatus() == Response.Status.CREATED.getStatusCode()) { return getTaskId(resp.getLocation()); } else { LOGGER.error("Submit Task Was not successful"); throw handleException(resp); } } finally { closeResponse(resp); } } | DpsClient { public long submitTask(DpsTask task, String topologyName) throws DpsException { Response resp = null; try { resp = client.target(dpsUrl) .path(TASKS_URL) .resolveTemplate(TOPOLOGY_NAME, topologyName) .request() .post(Entity.json(task)); if (resp.getStatus() == Response.Status.CREATED.getStatusCode()) { return getTaskId(resp.getLocation()); } else { LOGGER.error("Submit Task Was not successful"); throw handleException(resp); } } finally { closeResponse(resp); } } } | DpsClient { public long submitTask(DpsTask task, String topologyName) throws DpsException { Response resp = null; try { resp = client.target(dpsUrl) .path(TASKS_URL) .resolveTemplate(TOPOLOGY_NAME, topologyName) .request() .post(Entity.json(task)); if (resp.getStatus() == Response.Status.CREATED.getStatusCode()) { return getTaskId(resp.getLocation()); } else { LOGGER.error("Submit Task Was not successful"); throw handleException(resp); } } finally { closeResponse(resp); } } DpsClient(final String dpsUrl, final String username, final String password,
final int connectTimeoutInMillis, final int readTimeoutInMillis); DpsClient(final String dpsUrl, final String username, final String password); DpsClient(final String dpsUrl, final int connectTimeoutInMillis,
final int readTimeoutInMillis); DpsClient(final String dpsUrl); } | DpsClient { public long submitTask(DpsTask task, String topologyName) throws DpsException { Response resp = null; try { resp = client.target(dpsUrl) .path(TASKS_URL) .resolveTemplate(TOPOLOGY_NAME, topologyName) .request() .post(Entity.json(task)); if (resp.getStatus() == Response.Status.CREATED.getStatusCode()) { return getTaskId(resp.getLocation()); } else { LOGGER.error("Submit Task Was not successful"); throw handleException(resp); } } finally { closeResponse(resp); } } DpsClient(final String dpsUrl, final String username, final String password,
final int connectTimeoutInMillis, final int readTimeoutInMillis); DpsClient(final String dpsUrl, final String username, final String password); DpsClient(final String dpsUrl, final int connectTimeoutInMillis,
final int readTimeoutInMillis); DpsClient(final String dpsUrl); long submitTask(DpsTask task, String topologyName); void cleanMetisIndexingDataset(String topologyName, long taskId,
DataSetCleanerParameters dataSetCleanerParameters); void cleanMetisIndexingDataset(String topologyName, long taskId,
DataSetCleanerParameters dataSetCleanerParameters, String key, String value); Response.StatusType topologyPermit(String topologyName, String username); TaskInfo getTaskProgress(String topologyName, final long taskId); List<SubTaskInfo> getDetailedTaskReport(final String topologyName, final long taskId); List<SubTaskInfo> getDetailedTaskReportBetweenChunks(final String topologyName,
final long taskId, int from, int to); List<NodeReport> getElementReport(final String topologyName, final long taskId,
String elementPath); TaskErrorsInfo getTaskErrorsReport(final String topologyName, final long taskId,
final String error, final int idsCount); boolean checkIfErrorReportExists(final String topologyName, final long taskId); StatisticsReport getTaskStatisticsReport(final String topologyName, final long taskId); String killTask(final String topologyName, final long taskId, String info); void close(); } | DpsClient { public long submitTask(DpsTask task, String topologyName) throws DpsException { Response resp = null; try { resp = client.target(dpsUrl) .path(TASKS_URL) .resolveTemplate(TOPOLOGY_NAME, topologyName) .request() .post(Entity.json(task)); if (resp.getStatus() == Response.Status.CREATED.getStatusCode()) { return getTaskId(resp.getLocation()); } else { LOGGER.error("Submit Task Was not successful"); throw handleException(resp); } } finally { closeResponse(resp); } } DpsClient(final String dpsUrl, final String username, final String password,
final int connectTimeoutInMillis, final int readTimeoutInMillis); DpsClient(final String dpsUrl, final String username, final String password); DpsClient(final String dpsUrl, final int connectTimeoutInMillis,
final int readTimeoutInMillis); DpsClient(final String dpsUrl); long submitTask(DpsTask task, String topologyName); void cleanMetisIndexingDataset(String topologyName, long taskId,
DataSetCleanerParameters dataSetCleanerParameters); void cleanMetisIndexingDataset(String topologyName, long taskId,
DataSetCleanerParameters dataSetCleanerParameters, String key, String value); Response.StatusType topologyPermit(String topologyName, String username); TaskInfo getTaskProgress(String topologyName, final long taskId); List<SubTaskInfo> getDetailedTaskReport(final String topologyName, final long taskId); List<SubTaskInfo> getDetailedTaskReportBetweenChunks(final String topologyName,
final long taskId, int from, int to); List<NodeReport> getElementReport(final String topologyName, final long taskId,
String elementPath); TaskErrorsInfo getTaskErrorsReport(final String topologyName, final long taskId,
final String error, final int idsCount); boolean checkIfErrorReportExists(final String topologyName, final long taskId); StatisticsReport getTaskStatisticsReport(final String topologyName, final long taskId); String killTask(final String topologyName, final long taskId, String info); void close(); } |
@Betamax(tape = "DPSClient/permitAndSubmitTaskReturnBadURI") @Test(expected = RuntimeException.class) public final void shouldThrowAnExceptionWhenReturnedTaskIdIsNotParsable() throws Exception { dpsClient = new DpsClient(BASE_URL, REGULAR_USER_NAME, REGULAR_USER_PASSWORD); DpsTask task = prepareDpsTask(); dpsClient.submitTask(task, TOPOLOGY_NAME); } | public long submitTask(DpsTask task, String topologyName) throws DpsException { Response resp = null; try { resp = client.target(dpsUrl) .path(TASKS_URL) .resolveTemplate(TOPOLOGY_NAME, topologyName) .request() .post(Entity.json(task)); if (resp.getStatus() == Response.Status.CREATED.getStatusCode()) { return getTaskId(resp.getLocation()); } else { LOGGER.error("Submit Task Was not successful"); throw handleException(resp); } } finally { closeResponse(resp); } } | DpsClient { public long submitTask(DpsTask task, String topologyName) throws DpsException { Response resp = null; try { resp = client.target(dpsUrl) .path(TASKS_URL) .resolveTemplate(TOPOLOGY_NAME, topologyName) .request() .post(Entity.json(task)); if (resp.getStatus() == Response.Status.CREATED.getStatusCode()) { return getTaskId(resp.getLocation()); } else { LOGGER.error("Submit Task Was not successful"); throw handleException(resp); } } finally { closeResponse(resp); } } } | DpsClient { public long submitTask(DpsTask task, String topologyName) throws DpsException { Response resp = null; try { resp = client.target(dpsUrl) .path(TASKS_URL) .resolveTemplate(TOPOLOGY_NAME, topologyName) .request() .post(Entity.json(task)); if (resp.getStatus() == Response.Status.CREATED.getStatusCode()) { return getTaskId(resp.getLocation()); } else { LOGGER.error("Submit Task Was not successful"); throw handleException(resp); } } finally { closeResponse(resp); } } DpsClient(final String dpsUrl, final String username, final String password,
final int connectTimeoutInMillis, final int readTimeoutInMillis); DpsClient(final String dpsUrl, final String username, final String password); DpsClient(final String dpsUrl, final int connectTimeoutInMillis,
final int readTimeoutInMillis); DpsClient(final String dpsUrl); } | DpsClient { public long submitTask(DpsTask task, String topologyName) throws DpsException { Response resp = null; try { resp = client.target(dpsUrl) .path(TASKS_URL) .resolveTemplate(TOPOLOGY_NAME, topologyName) .request() .post(Entity.json(task)); if (resp.getStatus() == Response.Status.CREATED.getStatusCode()) { return getTaskId(resp.getLocation()); } else { LOGGER.error("Submit Task Was not successful"); throw handleException(resp); } } finally { closeResponse(resp); } } DpsClient(final String dpsUrl, final String username, final String password,
final int connectTimeoutInMillis, final int readTimeoutInMillis); DpsClient(final String dpsUrl, final String username, final String password); DpsClient(final String dpsUrl, final int connectTimeoutInMillis,
final int readTimeoutInMillis); DpsClient(final String dpsUrl); long submitTask(DpsTask task, String topologyName); void cleanMetisIndexingDataset(String topologyName, long taskId,
DataSetCleanerParameters dataSetCleanerParameters); void cleanMetisIndexingDataset(String topologyName, long taskId,
DataSetCleanerParameters dataSetCleanerParameters, String key, String value); Response.StatusType topologyPermit(String topologyName, String username); TaskInfo getTaskProgress(String topologyName, final long taskId); List<SubTaskInfo> getDetailedTaskReport(final String topologyName, final long taskId); List<SubTaskInfo> getDetailedTaskReportBetweenChunks(final String topologyName,
final long taskId, int from, int to); List<NodeReport> getElementReport(final String topologyName, final long taskId,
String elementPath); TaskErrorsInfo getTaskErrorsReport(final String topologyName, final long taskId,
final String error, final int idsCount); boolean checkIfErrorReportExists(final String topologyName, final long taskId); StatisticsReport getTaskStatisticsReport(final String topologyName, final long taskId); String killTask(final String topologyName, final long taskId, String info); void close(); } | DpsClient { public long submitTask(DpsTask task, String topologyName) throws DpsException { Response resp = null; try { resp = client.target(dpsUrl) .path(TASKS_URL) .resolveTemplate(TOPOLOGY_NAME, topologyName) .request() .post(Entity.json(task)); if (resp.getStatus() == Response.Status.CREATED.getStatusCode()) { return getTaskId(resp.getLocation()); } else { LOGGER.error("Submit Task Was not successful"); throw handleException(resp); } } finally { closeResponse(resp); } } DpsClient(final String dpsUrl, final String username, final String password,
final int connectTimeoutInMillis, final int readTimeoutInMillis); DpsClient(final String dpsUrl, final String username, final String password); DpsClient(final String dpsUrl, final int connectTimeoutInMillis,
final int readTimeoutInMillis); DpsClient(final String dpsUrl); long submitTask(DpsTask task, String topologyName); void cleanMetisIndexingDataset(String topologyName, long taskId,
DataSetCleanerParameters dataSetCleanerParameters); void cleanMetisIndexingDataset(String topologyName, long taskId,
DataSetCleanerParameters dataSetCleanerParameters, String key, String value); Response.StatusType topologyPermit(String topologyName, String username); TaskInfo getTaskProgress(String topologyName, final long taskId); List<SubTaskInfo> getDetailedTaskReport(final String topologyName, final long taskId); List<SubTaskInfo> getDetailedTaskReportBetweenChunks(final String topologyName,
final long taskId, int from, int to); List<NodeReport> getElementReport(final String topologyName, final long taskId,
String elementPath); TaskErrorsInfo getTaskErrorsReport(final String topologyName, final long taskId,
final String error, final int idsCount); boolean checkIfErrorReportExists(final String topologyName, final long taskId); StatisticsReport getTaskStatisticsReport(final String topologyName, final long taskId); String killTask(final String topologyName, final long taskId, String info); void close(); } |
@Test @Betamax(tape = "DPSClient/permitForNotDefinedTopologyTest") public final void shouldNotBeAbleToPermitUserForNotDefinedTopology() throws Exception { dpsClient = new DpsClient(BASE_URL, REGULAR_USER_NAME, REGULAR_USER_PASSWORD); try { dpsClient.topologyPermit(NOT_DEFINED_TOPOLOGY_NAME, "user"); fail(); } catch (AccessDeniedOrTopologyDoesNotExistException e) { assertThat(e.getLocalizedMessage(), equalTo("The topology doesn't exist")); } } | public Response.StatusType topologyPermit(String topologyName, String username) throws DpsException { Form form = new Form(); form.param("username", username); Response resp = null; try { resp = client.target(dpsUrl) .path(PERMIT_TOPOLOGY_URL) .resolveTemplate(TOPOLOGY_NAME, topologyName) .request() .post(Entity.entity(form, MediaType.APPLICATION_FORM_URLENCODED_TYPE)); if (resp.getStatus() == Response.Status.OK.getStatusCode()) { return resp.getStatusInfo(); } else { LOGGER.error("Granting permission was not successful"); throw handleException(resp); } } finally { closeResponse(resp); } } | DpsClient { public Response.StatusType topologyPermit(String topologyName, String username) throws DpsException { Form form = new Form(); form.param("username", username); Response resp = null; try { resp = client.target(dpsUrl) .path(PERMIT_TOPOLOGY_URL) .resolveTemplate(TOPOLOGY_NAME, topologyName) .request() .post(Entity.entity(form, MediaType.APPLICATION_FORM_URLENCODED_TYPE)); if (resp.getStatus() == Response.Status.OK.getStatusCode()) { return resp.getStatusInfo(); } else { LOGGER.error("Granting permission was not successful"); throw handleException(resp); } } finally { closeResponse(resp); } } } | DpsClient { public Response.StatusType topologyPermit(String topologyName, String username) throws DpsException { Form form = new Form(); form.param("username", username); Response resp = null; try { resp = client.target(dpsUrl) .path(PERMIT_TOPOLOGY_URL) .resolveTemplate(TOPOLOGY_NAME, topologyName) .request() .post(Entity.entity(form, MediaType.APPLICATION_FORM_URLENCODED_TYPE)); if (resp.getStatus() == Response.Status.OK.getStatusCode()) { return resp.getStatusInfo(); } else { LOGGER.error("Granting permission was not successful"); throw handleException(resp); } } finally { closeResponse(resp); } } DpsClient(final String dpsUrl, final String username, final String password,
final int connectTimeoutInMillis, final int readTimeoutInMillis); DpsClient(final String dpsUrl, final String username, final String password); DpsClient(final String dpsUrl, final int connectTimeoutInMillis,
final int readTimeoutInMillis); DpsClient(final String dpsUrl); } | DpsClient { public Response.StatusType topologyPermit(String topologyName, String username) throws DpsException { Form form = new Form(); form.param("username", username); Response resp = null; try { resp = client.target(dpsUrl) .path(PERMIT_TOPOLOGY_URL) .resolveTemplate(TOPOLOGY_NAME, topologyName) .request() .post(Entity.entity(form, MediaType.APPLICATION_FORM_URLENCODED_TYPE)); if (resp.getStatus() == Response.Status.OK.getStatusCode()) { return resp.getStatusInfo(); } else { LOGGER.error("Granting permission was not successful"); throw handleException(resp); } } finally { closeResponse(resp); } } DpsClient(final String dpsUrl, final String username, final String password,
final int connectTimeoutInMillis, final int readTimeoutInMillis); DpsClient(final String dpsUrl, final String username, final String password); DpsClient(final String dpsUrl, final int connectTimeoutInMillis,
final int readTimeoutInMillis); DpsClient(final String dpsUrl); long submitTask(DpsTask task, String topologyName); void cleanMetisIndexingDataset(String topologyName, long taskId,
DataSetCleanerParameters dataSetCleanerParameters); void cleanMetisIndexingDataset(String topologyName, long taskId,
DataSetCleanerParameters dataSetCleanerParameters, String key, String value); Response.StatusType topologyPermit(String topologyName, String username); TaskInfo getTaskProgress(String topologyName, final long taskId); List<SubTaskInfo> getDetailedTaskReport(final String topologyName, final long taskId); List<SubTaskInfo> getDetailedTaskReportBetweenChunks(final String topologyName,
final long taskId, int from, int to); List<NodeReport> getElementReport(final String topologyName, final long taskId,
String elementPath); TaskErrorsInfo getTaskErrorsReport(final String topologyName, final long taskId,
final String error, final int idsCount); boolean checkIfErrorReportExists(final String topologyName, final long taskId); StatisticsReport getTaskStatisticsReport(final String topologyName, final long taskId); String killTask(final String topologyName, final long taskId, String info); void close(); } | DpsClient { public Response.StatusType topologyPermit(String topologyName, String username) throws DpsException { Form form = new Form(); form.param("username", username); Response resp = null; try { resp = client.target(dpsUrl) .path(PERMIT_TOPOLOGY_URL) .resolveTemplate(TOPOLOGY_NAME, topologyName) .request() .post(Entity.entity(form, MediaType.APPLICATION_FORM_URLENCODED_TYPE)); if (resp.getStatus() == Response.Status.OK.getStatusCode()) { return resp.getStatusInfo(); } else { LOGGER.error("Granting permission was not successful"); throw handleException(resp); } } finally { closeResponse(resp); } } DpsClient(final String dpsUrl, final String username, final String password,
final int connectTimeoutInMillis, final int readTimeoutInMillis); DpsClient(final String dpsUrl, final String username, final String password); DpsClient(final String dpsUrl, final int connectTimeoutInMillis,
final int readTimeoutInMillis); DpsClient(final String dpsUrl); long submitTask(DpsTask task, String topologyName); void cleanMetisIndexingDataset(String topologyName, long taskId,
DataSetCleanerParameters dataSetCleanerParameters); void cleanMetisIndexingDataset(String topologyName, long taskId,
DataSetCleanerParameters dataSetCleanerParameters, String key, String value); Response.StatusType topologyPermit(String topologyName, String username); TaskInfo getTaskProgress(String topologyName, final long taskId); List<SubTaskInfo> getDetailedTaskReport(final String topologyName, final long taskId); List<SubTaskInfo> getDetailedTaskReportBetweenChunks(final String topologyName,
final long taskId, int from, int to); List<NodeReport> getElementReport(final String topologyName, final long taskId,
String elementPath); TaskErrorsInfo getTaskErrorsReport(final String topologyName, final long taskId,
final String error, final int idsCount); boolean checkIfErrorReportExists(final String topologyName, final long taskId); StatisticsReport getTaskStatisticsReport(final String topologyName, final long taskId); String killTask(final String topologyName, final long taskId, String info); void close(); } |
@Test @Betamax(tape = "DPSClient/getTaskProgressTest") public final void shouldReturnedProgressReport() throws DpsException { dpsClient = new DpsClient(BASE_URL, REGULAR_USER_NAME, REGULAR_USER_NAME); TaskInfo taskInfo = new TaskInfo(TASK_ID, TOPOLOGY_NAME, TaskState.PROCESSED, "", 1, 0, 0, 0, null, null, null); assertThat(dpsClient.getTaskProgress(TOPOLOGY_NAME, TASK_ID), is(taskInfo)); } | public TaskInfo getTaskProgress(String topologyName, final long taskId) throws DpsException { Response response = null; try { response = client .target(dpsUrl) .path(TASK_PROGRESS_URL) .resolveTemplate(TOPOLOGY_NAME, topologyName) .resolveTemplate(TASK_ID, taskId) .request().get(); if (response.getStatus() == Response.Status.OK.getStatusCode()) { return response.readEntity(TaskInfo.class); } else { LOGGER.error("Task progress cannot be read"); throw handleException(response); } } finally { closeResponse(response); } } | DpsClient { public TaskInfo getTaskProgress(String topologyName, final long taskId) throws DpsException { Response response = null; try { response = client .target(dpsUrl) .path(TASK_PROGRESS_URL) .resolveTemplate(TOPOLOGY_NAME, topologyName) .resolveTemplate(TASK_ID, taskId) .request().get(); if (response.getStatus() == Response.Status.OK.getStatusCode()) { return response.readEntity(TaskInfo.class); } else { LOGGER.error("Task progress cannot be read"); throw handleException(response); } } finally { closeResponse(response); } } } | DpsClient { public TaskInfo getTaskProgress(String topologyName, final long taskId) throws DpsException { Response response = null; try { response = client .target(dpsUrl) .path(TASK_PROGRESS_URL) .resolveTemplate(TOPOLOGY_NAME, topologyName) .resolveTemplate(TASK_ID, taskId) .request().get(); if (response.getStatus() == Response.Status.OK.getStatusCode()) { return response.readEntity(TaskInfo.class); } else { LOGGER.error("Task progress cannot be read"); throw handleException(response); } } finally { closeResponse(response); } } DpsClient(final String dpsUrl, final String username, final String password,
final int connectTimeoutInMillis, final int readTimeoutInMillis); DpsClient(final String dpsUrl, final String username, final String password); DpsClient(final String dpsUrl, final int connectTimeoutInMillis,
final int readTimeoutInMillis); DpsClient(final String dpsUrl); } | DpsClient { public TaskInfo getTaskProgress(String topologyName, final long taskId) throws DpsException { Response response = null; try { response = client .target(dpsUrl) .path(TASK_PROGRESS_URL) .resolveTemplate(TOPOLOGY_NAME, topologyName) .resolveTemplate(TASK_ID, taskId) .request().get(); if (response.getStatus() == Response.Status.OK.getStatusCode()) { return response.readEntity(TaskInfo.class); } else { LOGGER.error("Task progress cannot be read"); throw handleException(response); } } finally { closeResponse(response); } } DpsClient(final String dpsUrl, final String username, final String password,
final int connectTimeoutInMillis, final int readTimeoutInMillis); DpsClient(final String dpsUrl, final String username, final String password); DpsClient(final String dpsUrl, final int connectTimeoutInMillis,
final int readTimeoutInMillis); DpsClient(final String dpsUrl); long submitTask(DpsTask task, String topologyName); void cleanMetisIndexingDataset(String topologyName, long taskId,
DataSetCleanerParameters dataSetCleanerParameters); void cleanMetisIndexingDataset(String topologyName, long taskId,
DataSetCleanerParameters dataSetCleanerParameters, String key, String value); Response.StatusType topologyPermit(String topologyName, String username); TaskInfo getTaskProgress(String topologyName, final long taskId); List<SubTaskInfo> getDetailedTaskReport(final String topologyName, final long taskId); List<SubTaskInfo> getDetailedTaskReportBetweenChunks(final String topologyName,
final long taskId, int from, int to); List<NodeReport> getElementReport(final String topologyName, final long taskId,
String elementPath); TaskErrorsInfo getTaskErrorsReport(final String topologyName, final long taskId,
final String error, final int idsCount); boolean checkIfErrorReportExists(final String topologyName, final long taskId); StatisticsReport getTaskStatisticsReport(final String topologyName, final long taskId); String killTask(final String topologyName, final long taskId, String info); void close(); } | DpsClient { public TaskInfo getTaskProgress(String topologyName, final long taskId) throws DpsException { Response response = null; try { response = client .target(dpsUrl) .path(TASK_PROGRESS_URL) .resolveTemplate(TOPOLOGY_NAME, topologyName) .resolveTemplate(TASK_ID, taskId) .request().get(); if (response.getStatus() == Response.Status.OK.getStatusCode()) { return response.readEntity(TaskInfo.class); } else { LOGGER.error("Task progress cannot be read"); throw handleException(response); } } finally { closeResponse(response); } } DpsClient(final String dpsUrl, final String username, final String password,
final int connectTimeoutInMillis, final int readTimeoutInMillis); DpsClient(final String dpsUrl, final String username, final String password); DpsClient(final String dpsUrl, final int connectTimeoutInMillis,
final int readTimeoutInMillis); DpsClient(final String dpsUrl); long submitTask(DpsTask task, String topologyName); void cleanMetisIndexingDataset(String topologyName, long taskId,
DataSetCleanerParameters dataSetCleanerParameters); void cleanMetisIndexingDataset(String topologyName, long taskId,
DataSetCleanerParameters dataSetCleanerParameters, String key, String value); Response.StatusType topologyPermit(String topologyName, String username); TaskInfo getTaskProgress(String topologyName, final long taskId); List<SubTaskInfo> getDetailedTaskReport(final String topologyName, final long taskId); List<SubTaskInfo> getDetailedTaskReportBetweenChunks(final String topologyName,
final long taskId, int from, int to); List<NodeReport> getElementReport(final String topologyName, final long taskId,
String elementPath); TaskErrorsInfo getTaskErrorsReport(final String topologyName, final long taskId,
final String error, final int idsCount); boolean checkIfErrorReportExists(final String topologyName, final long taskId); StatisticsReport getTaskStatisticsReport(final String topologyName, final long taskId); String killTask(final String topologyName, final long taskId, String info); void close(); } |
@Test @Betamax(tape = "DPSClient/killTaskTest") public final void shouldKillTask() throws DpsException { dpsClient = new DpsClient(BASE_URL, REGULAR_USER_NAME, REGULAR_USER_NAME); String responseMessage = dpsClient.killTask(TOPOLOGY_NAME, TASK_ID, null); assertEquals(responseMessage, "The task was killed because of Dropped by the user"); } | public String killTask(final String topologyName, final long taskId, String info) throws DpsException { Response response = null; try { WebTarget webTarget = client.target(dpsUrl).path(KILL_TASK_URL) .resolveTemplate(TOPOLOGY_NAME, topologyName).resolveTemplate(TASK_ID, taskId); if (info != null) { webTarget = webTarget.queryParam("info", info); } response = webTarget.request().post(null); if (response.getStatus() == Response.Status.OK.getStatusCode()) { return response.readEntity(String.class); } else { LOGGER.error("Task Can't be killed"); throw handleException(response); } } finally { closeResponse(response); } } | DpsClient { public String killTask(final String topologyName, final long taskId, String info) throws DpsException { Response response = null; try { WebTarget webTarget = client.target(dpsUrl).path(KILL_TASK_URL) .resolveTemplate(TOPOLOGY_NAME, topologyName).resolveTemplate(TASK_ID, taskId); if (info != null) { webTarget = webTarget.queryParam("info", info); } response = webTarget.request().post(null); if (response.getStatus() == Response.Status.OK.getStatusCode()) { return response.readEntity(String.class); } else { LOGGER.error("Task Can't be killed"); throw handleException(response); } } finally { closeResponse(response); } } } | DpsClient { public String killTask(final String topologyName, final long taskId, String info) throws DpsException { Response response = null; try { WebTarget webTarget = client.target(dpsUrl).path(KILL_TASK_URL) .resolveTemplate(TOPOLOGY_NAME, topologyName).resolveTemplate(TASK_ID, taskId); if (info != null) { webTarget = webTarget.queryParam("info", info); } response = webTarget.request().post(null); if (response.getStatus() == Response.Status.OK.getStatusCode()) { return response.readEntity(String.class); } else { LOGGER.error("Task Can't be killed"); throw handleException(response); } } finally { closeResponse(response); } } DpsClient(final String dpsUrl, final String username, final String password,
final int connectTimeoutInMillis, final int readTimeoutInMillis); DpsClient(final String dpsUrl, final String username, final String password); DpsClient(final String dpsUrl, final int connectTimeoutInMillis,
final int readTimeoutInMillis); DpsClient(final String dpsUrl); } | DpsClient { public String killTask(final String topologyName, final long taskId, String info) throws DpsException { Response response = null; try { WebTarget webTarget = client.target(dpsUrl).path(KILL_TASK_URL) .resolveTemplate(TOPOLOGY_NAME, topologyName).resolveTemplate(TASK_ID, taskId); if (info != null) { webTarget = webTarget.queryParam("info", info); } response = webTarget.request().post(null); if (response.getStatus() == Response.Status.OK.getStatusCode()) { return response.readEntity(String.class); } else { LOGGER.error("Task Can't be killed"); throw handleException(response); } } finally { closeResponse(response); } } DpsClient(final String dpsUrl, final String username, final String password,
final int connectTimeoutInMillis, final int readTimeoutInMillis); DpsClient(final String dpsUrl, final String username, final String password); DpsClient(final String dpsUrl, final int connectTimeoutInMillis,
final int readTimeoutInMillis); DpsClient(final String dpsUrl); long submitTask(DpsTask task, String topologyName); void cleanMetisIndexingDataset(String topologyName, long taskId,
DataSetCleanerParameters dataSetCleanerParameters); void cleanMetisIndexingDataset(String topologyName, long taskId,
DataSetCleanerParameters dataSetCleanerParameters, String key, String value); Response.StatusType topologyPermit(String topologyName, String username); TaskInfo getTaskProgress(String topologyName, final long taskId); List<SubTaskInfo> getDetailedTaskReport(final String topologyName, final long taskId); List<SubTaskInfo> getDetailedTaskReportBetweenChunks(final String topologyName,
final long taskId, int from, int to); List<NodeReport> getElementReport(final String topologyName, final long taskId,
String elementPath); TaskErrorsInfo getTaskErrorsReport(final String topologyName, final long taskId,
final String error, final int idsCount); boolean checkIfErrorReportExists(final String topologyName, final long taskId); StatisticsReport getTaskStatisticsReport(final String topologyName, final long taskId); String killTask(final String topologyName, final long taskId, String info); void close(); } | DpsClient { public String killTask(final String topologyName, final long taskId, String info) throws DpsException { Response response = null; try { WebTarget webTarget = client.target(dpsUrl).path(KILL_TASK_URL) .resolveTemplate(TOPOLOGY_NAME, topologyName).resolveTemplate(TASK_ID, taskId); if (info != null) { webTarget = webTarget.queryParam("info", info); } response = webTarget.request().post(null); if (response.getStatus() == Response.Status.OK.getStatusCode()) { return response.readEntity(String.class); } else { LOGGER.error("Task Can't be killed"); throw handleException(response); } } finally { closeResponse(response); } } DpsClient(final String dpsUrl, final String username, final String password,
final int connectTimeoutInMillis, final int readTimeoutInMillis); DpsClient(final String dpsUrl, final String username, final String password); DpsClient(final String dpsUrl, final int connectTimeoutInMillis,
final int readTimeoutInMillis); DpsClient(final String dpsUrl); long submitTask(DpsTask task, String topologyName); void cleanMetisIndexingDataset(String topologyName, long taskId,
DataSetCleanerParameters dataSetCleanerParameters); void cleanMetisIndexingDataset(String topologyName, long taskId,
DataSetCleanerParameters dataSetCleanerParameters, String key, String value); Response.StatusType topologyPermit(String topologyName, String username); TaskInfo getTaskProgress(String topologyName, final long taskId); List<SubTaskInfo> getDetailedTaskReport(final String topologyName, final long taskId); List<SubTaskInfo> getDetailedTaskReportBetweenChunks(final String topologyName,
final long taskId, int from, int to); List<NodeReport> getElementReport(final String topologyName, final long taskId,
String elementPath); TaskErrorsInfo getTaskErrorsReport(final String topologyName, final long taskId,
final String error, final int idsCount); boolean checkIfErrorReportExists(final String topologyName, final long taskId); StatisticsReport getTaskStatisticsReport(final String topologyName, final long taskId); String killTask(final String topologyName, final long taskId, String info); void close(); } |
@Test @Betamax(tape = "DPSClient/killTaskTestWithSpecificInfo") public final void shouldKillTaskWithSpecificInfo() throws DpsException { dpsClient = new DpsClient(BASE_URL, REGULAR_USER_NAME, REGULAR_USER_NAME); String responseMessage = dpsClient.killTask(TOPOLOGY_NAME, TASK_ID, "Aggregator-choice"); assertEquals(responseMessage, "The task was killed because of Aggregator-choice"); } | public String killTask(final String topologyName, final long taskId, String info) throws DpsException { Response response = null; try { WebTarget webTarget = client.target(dpsUrl).path(KILL_TASK_URL) .resolveTemplate(TOPOLOGY_NAME, topologyName).resolveTemplate(TASK_ID, taskId); if (info != null) { webTarget = webTarget.queryParam("info", info); } response = webTarget.request().post(null); if (response.getStatus() == Response.Status.OK.getStatusCode()) { return response.readEntity(String.class); } else { LOGGER.error("Task Can't be killed"); throw handleException(response); } } finally { closeResponse(response); } } | DpsClient { public String killTask(final String topologyName, final long taskId, String info) throws DpsException { Response response = null; try { WebTarget webTarget = client.target(dpsUrl).path(KILL_TASK_URL) .resolveTemplate(TOPOLOGY_NAME, topologyName).resolveTemplate(TASK_ID, taskId); if (info != null) { webTarget = webTarget.queryParam("info", info); } response = webTarget.request().post(null); if (response.getStatus() == Response.Status.OK.getStatusCode()) { return response.readEntity(String.class); } else { LOGGER.error("Task Can't be killed"); throw handleException(response); } } finally { closeResponse(response); } } } | DpsClient { public String killTask(final String topologyName, final long taskId, String info) throws DpsException { Response response = null; try { WebTarget webTarget = client.target(dpsUrl).path(KILL_TASK_URL) .resolveTemplate(TOPOLOGY_NAME, topologyName).resolveTemplate(TASK_ID, taskId); if (info != null) { webTarget = webTarget.queryParam("info", info); } response = webTarget.request().post(null); if (response.getStatus() == Response.Status.OK.getStatusCode()) { return response.readEntity(String.class); } else { LOGGER.error("Task Can't be killed"); throw handleException(response); } } finally { closeResponse(response); } } DpsClient(final String dpsUrl, final String username, final String password,
final int connectTimeoutInMillis, final int readTimeoutInMillis); DpsClient(final String dpsUrl, final String username, final String password); DpsClient(final String dpsUrl, final int connectTimeoutInMillis,
final int readTimeoutInMillis); DpsClient(final String dpsUrl); } | DpsClient { public String killTask(final String topologyName, final long taskId, String info) throws DpsException { Response response = null; try { WebTarget webTarget = client.target(dpsUrl).path(KILL_TASK_URL) .resolveTemplate(TOPOLOGY_NAME, topologyName).resolveTemplate(TASK_ID, taskId); if (info != null) { webTarget = webTarget.queryParam("info", info); } response = webTarget.request().post(null); if (response.getStatus() == Response.Status.OK.getStatusCode()) { return response.readEntity(String.class); } else { LOGGER.error("Task Can't be killed"); throw handleException(response); } } finally { closeResponse(response); } } DpsClient(final String dpsUrl, final String username, final String password,
final int connectTimeoutInMillis, final int readTimeoutInMillis); DpsClient(final String dpsUrl, final String username, final String password); DpsClient(final String dpsUrl, final int connectTimeoutInMillis,
final int readTimeoutInMillis); DpsClient(final String dpsUrl); long submitTask(DpsTask task, String topologyName); void cleanMetisIndexingDataset(String topologyName, long taskId,
DataSetCleanerParameters dataSetCleanerParameters); void cleanMetisIndexingDataset(String topologyName, long taskId,
DataSetCleanerParameters dataSetCleanerParameters, String key, String value); Response.StatusType topologyPermit(String topologyName, String username); TaskInfo getTaskProgress(String topologyName, final long taskId); List<SubTaskInfo> getDetailedTaskReport(final String topologyName, final long taskId); List<SubTaskInfo> getDetailedTaskReportBetweenChunks(final String topologyName,
final long taskId, int from, int to); List<NodeReport> getElementReport(final String topologyName, final long taskId,
String elementPath); TaskErrorsInfo getTaskErrorsReport(final String topologyName, final long taskId,
final String error, final int idsCount); boolean checkIfErrorReportExists(final String topologyName, final long taskId); StatisticsReport getTaskStatisticsReport(final String topologyName, final long taskId); String killTask(final String topologyName, final long taskId, String info); void close(); } | DpsClient { public String killTask(final String topologyName, final long taskId, String info) throws DpsException { Response response = null; try { WebTarget webTarget = client.target(dpsUrl).path(KILL_TASK_URL) .resolveTemplate(TOPOLOGY_NAME, topologyName).resolveTemplate(TASK_ID, taskId); if (info != null) { webTarget = webTarget.queryParam("info", info); } response = webTarget.request().post(null); if (response.getStatus() == Response.Status.OK.getStatusCode()) { return response.readEntity(String.class); } else { LOGGER.error("Task Can't be killed"); throw handleException(response); } } finally { closeResponse(response); } } DpsClient(final String dpsUrl, final String username, final String password,
final int connectTimeoutInMillis, final int readTimeoutInMillis); DpsClient(final String dpsUrl, final String username, final String password); DpsClient(final String dpsUrl, final int connectTimeoutInMillis,
final int readTimeoutInMillis); DpsClient(final String dpsUrl); long submitTask(DpsTask task, String topologyName); void cleanMetisIndexingDataset(String topologyName, long taskId,
DataSetCleanerParameters dataSetCleanerParameters); void cleanMetisIndexingDataset(String topologyName, long taskId,
DataSetCleanerParameters dataSetCleanerParameters, String key, String value); Response.StatusType topologyPermit(String topologyName, String username); TaskInfo getTaskProgress(String topologyName, final long taskId); List<SubTaskInfo> getDetailedTaskReport(final String topologyName, final long taskId); List<SubTaskInfo> getDetailedTaskReportBetweenChunks(final String topologyName,
final long taskId, int from, int to); List<NodeReport> getElementReport(final String topologyName, final long taskId,
String elementPath); TaskErrorsInfo getTaskErrorsReport(final String topologyName, final long taskId,
final String error, final int idsCount); boolean checkIfErrorReportExists(final String topologyName, final long taskId); StatisticsReport getTaskStatisticsReport(final String topologyName, final long taskId); String killTask(final String topologyName, final long taskId, String info); void close(); } |
@Test(expected = AccessDeniedOrObjectDoesNotExistException.class) @Betamax(tape = "DPSClient/shouldThrowExceptionWhenKillingNonExistingTaskTest") public final void shouldThrowExceptionWhenKillingNonExistingTaskTest() throws DpsException { dpsClient = new DpsClient(BASE_URL, REGULAR_USER_NAME, REGULAR_USER_NAME); long nonExistedTaskId = 1111l; dpsClient.killTask(TOPOLOGY_NAME, nonExistedTaskId, null); } | public String killTask(final String topologyName, final long taskId, String info) throws DpsException { Response response = null; try { WebTarget webTarget = client.target(dpsUrl).path(KILL_TASK_URL) .resolveTemplate(TOPOLOGY_NAME, topologyName).resolveTemplate(TASK_ID, taskId); if (info != null) { webTarget = webTarget.queryParam("info", info); } response = webTarget.request().post(null); if (response.getStatus() == Response.Status.OK.getStatusCode()) { return response.readEntity(String.class); } else { LOGGER.error("Task Can't be killed"); throw handleException(response); } } finally { closeResponse(response); } } | DpsClient { public String killTask(final String topologyName, final long taskId, String info) throws DpsException { Response response = null; try { WebTarget webTarget = client.target(dpsUrl).path(KILL_TASK_URL) .resolveTemplate(TOPOLOGY_NAME, topologyName).resolveTemplate(TASK_ID, taskId); if (info != null) { webTarget = webTarget.queryParam("info", info); } response = webTarget.request().post(null); if (response.getStatus() == Response.Status.OK.getStatusCode()) { return response.readEntity(String.class); } else { LOGGER.error("Task Can't be killed"); throw handleException(response); } } finally { closeResponse(response); } } } | DpsClient { public String killTask(final String topologyName, final long taskId, String info) throws DpsException { Response response = null; try { WebTarget webTarget = client.target(dpsUrl).path(KILL_TASK_URL) .resolveTemplate(TOPOLOGY_NAME, topologyName).resolveTemplate(TASK_ID, taskId); if (info != null) { webTarget = webTarget.queryParam("info", info); } response = webTarget.request().post(null); if (response.getStatus() == Response.Status.OK.getStatusCode()) { return response.readEntity(String.class); } else { LOGGER.error("Task Can't be killed"); throw handleException(response); } } finally { closeResponse(response); } } DpsClient(final String dpsUrl, final String username, final String password,
final int connectTimeoutInMillis, final int readTimeoutInMillis); DpsClient(final String dpsUrl, final String username, final String password); DpsClient(final String dpsUrl, final int connectTimeoutInMillis,
final int readTimeoutInMillis); DpsClient(final String dpsUrl); } | DpsClient { public String killTask(final String topologyName, final long taskId, String info) throws DpsException { Response response = null; try { WebTarget webTarget = client.target(dpsUrl).path(KILL_TASK_URL) .resolveTemplate(TOPOLOGY_NAME, topologyName).resolveTemplate(TASK_ID, taskId); if (info != null) { webTarget = webTarget.queryParam("info", info); } response = webTarget.request().post(null); if (response.getStatus() == Response.Status.OK.getStatusCode()) { return response.readEntity(String.class); } else { LOGGER.error("Task Can't be killed"); throw handleException(response); } } finally { closeResponse(response); } } DpsClient(final String dpsUrl, final String username, final String password,
final int connectTimeoutInMillis, final int readTimeoutInMillis); DpsClient(final String dpsUrl, final String username, final String password); DpsClient(final String dpsUrl, final int connectTimeoutInMillis,
final int readTimeoutInMillis); DpsClient(final String dpsUrl); long submitTask(DpsTask task, String topologyName); void cleanMetisIndexingDataset(String topologyName, long taskId,
DataSetCleanerParameters dataSetCleanerParameters); void cleanMetisIndexingDataset(String topologyName, long taskId,
DataSetCleanerParameters dataSetCleanerParameters, String key, String value); Response.StatusType topologyPermit(String topologyName, String username); TaskInfo getTaskProgress(String topologyName, final long taskId); List<SubTaskInfo> getDetailedTaskReport(final String topologyName, final long taskId); List<SubTaskInfo> getDetailedTaskReportBetweenChunks(final String topologyName,
final long taskId, int from, int to); List<NodeReport> getElementReport(final String topologyName, final long taskId,
String elementPath); TaskErrorsInfo getTaskErrorsReport(final String topologyName, final long taskId,
final String error, final int idsCount); boolean checkIfErrorReportExists(final String topologyName, final long taskId); StatisticsReport getTaskStatisticsReport(final String topologyName, final long taskId); String killTask(final String topologyName, final long taskId, String info); void close(); } | DpsClient { public String killTask(final String topologyName, final long taskId, String info) throws DpsException { Response response = null; try { WebTarget webTarget = client.target(dpsUrl).path(KILL_TASK_URL) .resolveTemplate(TOPOLOGY_NAME, topologyName).resolveTemplate(TASK_ID, taskId); if (info != null) { webTarget = webTarget.queryParam("info", info); } response = webTarget.request().post(null); if (response.getStatus() == Response.Status.OK.getStatusCode()) { return response.readEntity(String.class); } else { LOGGER.error("Task Can't be killed"); throw handleException(response); } } finally { closeResponse(response); } } DpsClient(final String dpsUrl, final String username, final String password,
final int connectTimeoutInMillis, final int readTimeoutInMillis); DpsClient(final String dpsUrl, final String username, final String password); DpsClient(final String dpsUrl, final int connectTimeoutInMillis,
final int readTimeoutInMillis); DpsClient(final String dpsUrl); long submitTask(DpsTask task, String topologyName); void cleanMetisIndexingDataset(String topologyName, long taskId,
DataSetCleanerParameters dataSetCleanerParameters); void cleanMetisIndexingDataset(String topologyName, long taskId,
DataSetCleanerParameters dataSetCleanerParameters, String key, String value); Response.StatusType topologyPermit(String topologyName, String username); TaskInfo getTaskProgress(String topologyName, final long taskId); List<SubTaskInfo> getDetailedTaskReport(final String topologyName, final long taskId); List<SubTaskInfo> getDetailedTaskReportBetweenChunks(final String topologyName,
final long taskId, int from, int to); List<NodeReport> getElementReport(final String topologyName, final long taskId,
String elementPath); TaskErrorsInfo getTaskErrorsReport(final String topologyName, final long taskId,
final String error, final int idsCount); boolean checkIfErrorReportExists(final String topologyName, final long taskId); StatisticsReport getTaskStatisticsReport(final String topologyName, final long taskId); String killTask(final String topologyName, final long taskId, String info); void close(); } |
@Test(expected = AccessDeniedOrTopologyDoesNotExistException.class) @Betamax(tape = "DPSClient/shouldThrowExceptionWhenKillingTaskForNonExistedTopologyTest") public final void shouldThrowExceptionWhenKillingTaskForNonExistedTopologyTest() throws DpsException { dpsClient = new DpsClient(BASE_URL, REGULAR_USER_NAME, REGULAR_USER_NAME); dpsClient.killTask(NOT_DEFINED_TOPOLOGY_NAME, TASK_ID, null); } | public String killTask(final String topologyName, final long taskId, String info) throws DpsException { Response response = null; try { WebTarget webTarget = client.target(dpsUrl).path(KILL_TASK_URL) .resolveTemplate(TOPOLOGY_NAME, topologyName).resolveTemplate(TASK_ID, taskId); if (info != null) { webTarget = webTarget.queryParam("info", info); } response = webTarget.request().post(null); if (response.getStatus() == Response.Status.OK.getStatusCode()) { return response.readEntity(String.class); } else { LOGGER.error("Task Can't be killed"); throw handleException(response); } } finally { closeResponse(response); } } | DpsClient { public String killTask(final String topologyName, final long taskId, String info) throws DpsException { Response response = null; try { WebTarget webTarget = client.target(dpsUrl).path(KILL_TASK_URL) .resolveTemplate(TOPOLOGY_NAME, topologyName).resolveTemplate(TASK_ID, taskId); if (info != null) { webTarget = webTarget.queryParam("info", info); } response = webTarget.request().post(null); if (response.getStatus() == Response.Status.OK.getStatusCode()) { return response.readEntity(String.class); } else { LOGGER.error("Task Can't be killed"); throw handleException(response); } } finally { closeResponse(response); } } } | DpsClient { public String killTask(final String topologyName, final long taskId, String info) throws DpsException { Response response = null; try { WebTarget webTarget = client.target(dpsUrl).path(KILL_TASK_URL) .resolveTemplate(TOPOLOGY_NAME, topologyName).resolveTemplate(TASK_ID, taskId); if (info != null) { webTarget = webTarget.queryParam("info", info); } response = webTarget.request().post(null); if (response.getStatus() == Response.Status.OK.getStatusCode()) { return response.readEntity(String.class); } else { LOGGER.error("Task Can't be killed"); throw handleException(response); } } finally { closeResponse(response); } } DpsClient(final String dpsUrl, final String username, final String password,
final int connectTimeoutInMillis, final int readTimeoutInMillis); DpsClient(final String dpsUrl, final String username, final String password); DpsClient(final String dpsUrl, final int connectTimeoutInMillis,
final int readTimeoutInMillis); DpsClient(final String dpsUrl); } | DpsClient { public String killTask(final String topologyName, final long taskId, String info) throws DpsException { Response response = null; try { WebTarget webTarget = client.target(dpsUrl).path(KILL_TASK_URL) .resolveTemplate(TOPOLOGY_NAME, topologyName).resolveTemplate(TASK_ID, taskId); if (info != null) { webTarget = webTarget.queryParam("info", info); } response = webTarget.request().post(null); if (response.getStatus() == Response.Status.OK.getStatusCode()) { return response.readEntity(String.class); } else { LOGGER.error("Task Can't be killed"); throw handleException(response); } } finally { closeResponse(response); } } DpsClient(final String dpsUrl, final String username, final String password,
final int connectTimeoutInMillis, final int readTimeoutInMillis); DpsClient(final String dpsUrl, final String username, final String password); DpsClient(final String dpsUrl, final int connectTimeoutInMillis,
final int readTimeoutInMillis); DpsClient(final String dpsUrl); long submitTask(DpsTask task, String topologyName); void cleanMetisIndexingDataset(String topologyName, long taskId,
DataSetCleanerParameters dataSetCleanerParameters); void cleanMetisIndexingDataset(String topologyName, long taskId,
DataSetCleanerParameters dataSetCleanerParameters, String key, String value); Response.StatusType topologyPermit(String topologyName, String username); TaskInfo getTaskProgress(String topologyName, final long taskId); List<SubTaskInfo> getDetailedTaskReport(final String topologyName, final long taskId); List<SubTaskInfo> getDetailedTaskReportBetweenChunks(final String topologyName,
final long taskId, int from, int to); List<NodeReport> getElementReport(final String topologyName, final long taskId,
String elementPath); TaskErrorsInfo getTaskErrorsReport(final String topologyName, final long taskId,
final String error, final int idsCount); boolean checkIfErrorReportExists(final String topologyName, final long taskId); StatisticsReport getTaskStatisticsReport(final String topologyName, final long taskId); String killTask(final String topologyName, final long taskId, String info); void close(); } | DpsClient { public String killTask(final String topologyName, final long taskId, String info) throws DpsException { Response response = null; try { WebTarget webTarget = client.target(dpsUrl).path(KILL_TASK_URL) .resolveTemplate(TOPOLOGY_NAME, topologyName).resolveTemplate(TASK_ID, taskId); if (info != null) { webTarget = webTarget.queryParam("info", info); } response = webTarget.request().post(null); if (response.getStatus() == Response.Status.OK.getStatusCode()) { return response.readEntity(String.class); } else { LOGGER.error("Task Can't be killed"); throw handleException(response); } } finally { closeResponse(response); } } DpsClient(final String dpsUrl, final String username, final String password,
final int connectTimeoutInMillis, final int readTimeoutInMillis); DpsClient(final String dpsUrl, final String username, final String password); DpsClient(final String dpsUrl, final int connectTimeoutInMillis,
final int readTimeoutInMillis); DpsClient(final String dpsUrl); long submitTask(DpsTask task, String topologyName); void cleanMetisIndexingDataset(String topologyName, long taskId,
DataSetCleanerParameters dataSetCleanerParameters); void cleanMetisIndexingDataset(String topologyName, long taskId,
DataSetCleanerParameters dataSetCleanerParameters, String key, String value); Response.StatusType topologyPermit(String topologyName, String username); TaskInfo getTaskProgress(String topologyName, final long taskId); List<SubTaskInfo> getDetailedTaskReport(final String topologyName, final long taskId); List<SubTaskInfo> getDetailedTaskReportBetweenChunks(final String topologyName,
final long taskId, int from, int to); List<NodeReport> getElementReport(final String topologyName, final long taskId,
String elementPath); TaskErrorsInfo getTaskErrorsReport(final String topologyName, final long taskId,
final String error, final int idsCount); boolean checkIfErrorReportExists(final String topologyName, final long taskId); StatisticsReport getTaskStatisticsReport(final String topologyName, final long taskId); String killTask(final String topologyName, final long taskId, String info); void close(); } |
@Test @Betamax(tape = "DPSClient_getTaskDetailsReportTest") public final void shouldReturnedDetailsReport() throws DpsException { dpsClient = new DpsClient(BASE_URL, REGULAR_USER_NAME, REGULAR_USER_PASSWORD); SubTaskInfo subTaskInfo = new SubTaskInfo(1, "resource", RecordState.SUCCESS, "", "", "result"); List<SubTaskInfo> taskInfoList = new ArrayList<>(1); taskInfoList.add(subTaskInfo); assertThat(dpsClient.getDetailedTaskReport(TOPOLOGY_NAME, TASK_ID), is(taskInfoList)); } | public List<SubTaskInfo> getDetailedTaskReport(final String topologyName, final long taskId) throws DpsException { Response response = null; try { response = client .target(dpsUrl) .path(DETAILED_TASK_REPORT_URL) .resolveTemplate(TOPOLOGY_NAME, topologyName) .resolveTemplate(TASK_ID, taskId) .request().get(); return handleResponse(response); } finally { closeResponse(response); } } | DpsClient { public List<SubTaskInfo> getDetailedTaskReport(final String topologyName, final long taskId) throws DpsException { Response response = null; try { response = client .target(dpsUrl) .path(DETAILED_TASK_REPORT_URL) .resolveTemplate(TOPOLOGY_NAME, topologyName) .resolveTemplate(TASK_ID, taskId) .request().get(); return handleResponse(response); } finally { closeResponse(response); } } } | DpsClient { public List<SubTaskInfo> getDetailedTaskReport(final String topologyName, final long taskId) throws DpsException { Response response = null; try { response = client .target(dpsUrl) .path(DETAILED_TASK_REPORT_URL) .resolveTemplate(TOPOLOGY_NAME, topologyName) .resolveTemplate(TASK_ID, taskId) .request().get(); return handleResponse(response); } finally { closeResponse(response); } } DpsClient(final String dpsUrl, final String username, final String password,
final int connectTimeoutInMillis, final int readTimeoutInMillis); DpsClient(final String dpsUrl, final String username, final String password); DpsClient(final String dpsUrl, final int connectTimeoutInMillis,
final int readTimeoutInMillis); DpsClient(final String dpsUrl); } | DpsClient { public List<SubTaskInfo> getDetailedTaskReport(final String topologyName, final long taskId) throws DpsException { Response response = null; try { response = client .target(dpsUrl) .path(DETAILED_TASK_REPORT_URL) .resolveTemplate(TOPOLOGY_NAME, topologyName) .resolveTemplate(TASK_ID, taskId) .request().get(); return handleResponse(response); } finally { closeResponse(response); } } DpsClient(final String dpsUrl, final String username, final String password,
final int connectTimeoutInMillis, final int readTimeoutInMillis); DpsClient(final String dpsUrl, final String username, final String password); DpsClient(final String dpsUrl, final int connectTimeoutInMillis,
final int readTimeoutInMillis); DpsClient(final String dpsUrl); long submitTask(DpsTask task, String topologyName); void cleanMetisIndexingDataset(String topologyName, long taskId,
DataSetCleanerParameters dataSetCleanerParameters); void cleanMetisIndexingDataset(String topologyName, long taskId,
DataSetCleanerParameters dataSetCleanerParameters, String key, String value); Response.StatusType topologyPermit(String topologyName, String username); TaskInfo getTaskProgress(String topologyName, final long taskId); List<SubTaskInfo> getDetailedTaskReport(final String topologyName, final long taskId); List<SubTaskInfo> getDetailedTaskReportBetweenChunks(final String topologyName,
final long taskId, int from, int to); List<NodeReport> getElementReport(final String topologyName, final long taskId,
String elementPath); TaskErrorsInfo getTaskErrorsReport(final String topologyName, final long taskId,
final String error, final int idsCount); boolean checkIfErrorReportExists(final String topologyName, final long taskId); StatisticsReport getTaskStatisticsReport(final String topologyName, final long taskId); String killTask(final String topologyName, final long taskId, String info); void close(); } | DpsClient { public List<SubTaskInfo> getDetailedTaskReport(final String topologyName, final long taskId) throws DpsException { Response response = null; try { response = client .target(dpsUrl) .path(DETAILED_TASK_REPORT_URL) .resolveTemplate(TOPOLOGY_NAME, topologyName) .resolveTemplate(TASK_ID, taskId) .request().get(); return handleResponse(response); } finally { closeResponse(response); } } DpsClient(final String dpsUrl, final String username, final String password,
final int connectTimeoutInMillis, final int readTimeoutInMillis); DpsClient(final String dpsUrl, final String username, final String password); DpsClient(final String dpsUrl, final int connectTimeoutInMillis,
final int readTimeoutInMillis); DpsClient(final String dpsUrl); long submitTask(DpsTask task, String topologyName); void cleanMetisIndexingDataset(String topologyName, long taskId,
DataSetCleanerParameters dataSetCleanerParameters); void cleanMetisIndexingDataset(String topologyName, long taskId,
DataSetCleanerParameters dataSetCleanerParameters, String key, String value); Response.StatusType topologyPermit(String topologyName, String username); TaskInfo getTaskProgress(String topologyName, final long taskId); List<SubTaskInfo> getDetailedTaskReport(final String topologyName, final long taskId); List<SubTaskInfo> getDetailedTaskReportBetweenChunks(final String topologyName,
final long taskId, int from, int to); List<NodeReport> getElementReport(final String topologyName, final long taskId,
String elementPath); TaskErrorsInfo getTaskErrorsReport(final String topologyName, final long taskId,
final String error, final int idsCount); boolean checkIfErrorReportExists(final String topologyName, final long taskId); StatisticsReport getTaskStatisticsReport(final String topologyName, final long taskId); String killTask(final String topologyName, final long taskId, String info); void close(); } |
@Test @Betamax(tape = "DPSClient_shouldReturnedGeneralErrorReport") public final void shouldReturnedGeneralErrorReport() throws DpsException { dpsClient = new DpsClient(BASE_URL, REGULAR_USER_NAME, REGULAR_USER_PASSWORD); TaskErrorsInfo report = createErrorInfo(TASK_ID, false); assertThat(dpsClient.getTaskErrorsReport(TOPOLOGY_NAME, TASK_ID, null, 0), is(report)); } | public TaskErrorsInfo getTaskErrorsReport(final String topologyName, final long taskId, final String error, final int idsCount) throws DpsException { Response response = null; try { response = client .target(dpsUrl) .path(ERRORS_TASK_REPORT_URL) .resolveTemplate(TOPOLOGY_NAME, topologyName) .resolveTemplate(TASK_ID, taskId) .queryParam(ERROR, error) .queryParam(IDS_COUNT, idsCount) .request().get(); return handleErrorResponse(response); } finally { closeResponse(response); } } | DpsClient { public TaskErrorsInfo getTaskErrorsReport(final String topologyName, final long taskId, final String error, final int idsCount) throws DpsException { Response response = null; try { response = client .target(dpsUrl) .path(ERRORS_TASK_REPORT_URL) .resolveTemplate(TOPOLOGY_NAME, topologyName) .resolveTemplate(TASK_ID, taskId) .queryParam(ERROR, error) .queryParam(IDS_COUNT, idsCount) .request().get(); return handleErrorResponse(response); } finally { closeResponse(response); } } } | DpsClient { public TaskErrorsInfo getTaskErrorsReport(final String topologyName, final long taskId, final String error, final int idsCount) throws DpsException { Response response = null; try { response = client .target(dpsUrl) .path(ERRORS_TASK_REPORT_URL) .resolveTemplate(TOPOLOGY_NAME, topologyName) .resolveTemplate(TASK_ID, taskId) .queryParam(ERROR, error) .queryParam(IDS_COUNT, idsCount) .request().get(); return handleErrorResponse(response); } finally { closeResponse(response); } } DpsClient(final String dpsUrl, final String username, final String password,
final int connectTimeoutInMillis, final int readTimeoutInMillis); DpsClient(final String dpsUrl, final String username, final String password); DpsClient(final String dpsUrl, final int connectTimeoutInMillis,
final int readTimeoutInMillis); DpsClient(final String dpsUrl); } | DpsClient { public TaskErrorsInfo getTaskErrorsReport(final String topologyName, final long taskId, final String error, final int idsCount) throws DpsException { Response response = null; try { response = client .target(dpsUrl) .path(ERRORS_TASK_REPORT_URL) .resolveTemplate(TOPOLOGY_NAME, topologyName) .resolveTemplate(TASK_ID, taskId) .queryParam(ERROR, error) .queryParam(IDS_COUNT, idsCount) .request().get(); return handleErrorResponse(response); } finally { closeResponse(response); } } DpsClient(final String dpsUrl, final String username, final String password,
final int connectTimeoutInMillis, final int readTimeoutInMillis); DpsClient(final String dpsUrl, final String username, final String password); DpsClient(final String dpsUrl, final int connectTimeoutInMillis,
final int readTimeoutInMillis); DpsClient(final String dpsUrl); long submitTask(DpsTask task, String topologyName); void cleanMetisIndexingDataset(String topologyName, long taskId,
DataSetCleanerParameters dataSetCleanerParameters); void cleanMetisIndexingDataset(String topologyName, long taskId,
DataSetCleanerParameters dataSetCleanerParameters, String key, String value); Response.StatusType topologyPermit(String topologyName, String username); TaskInfo getTaskProgress(String topologyName, final long taskId); List<SubTaskInfo> getDetailedTaskReport(final String topologyName, final long taskId); List<SubTaskInfo> getDetailedTaskReportBetweenChunks(final String topologyName,
final long taskId, int from, int to); List<NodeReport> getElementReport(final String topologyName, final long taskId,
String elementPath); TaskErrorsInfo getTaskErrorsReport(final String topologyName, final long taskId,
final String error, final int idsCount); boolean checkIfErrorReportExists(final String topologyName, final long taskId); StatisticsReport getTaskStatisticsReport(final String topologyName, final long taskId); String killTask(final String topologyName, final long taskId, String info); void close(); } | DpsClient { public TaskErrorsInfo getTaskErrorsReport(final String topologyName, final long taskId, final String error, final int idsCount) throws DpsException { Response response = null; try { response = client .target(dpsUrl) .path(ERRORS_TASK_REPORT_URL) .resolveTemplate(TOPOLOGY_NAME, topologyName) .resolveTemplate(TASK_ID, taskId) .queryParam(ERROR, error) .queryParam(IDS_COUNT, idsCount) .request().get(); return handleErrorResponse(response); } finally { closeResponse(response); } } DpsClient(final String dpsUrl, final String username, final String password,
final int connectTimeoutInMillis, final int readTimeoutInMillis); DpsClient(final String dpsUrl, final String username, final String password); DpsClient(final String dpsUrl, final int connectTimeoutInMillis,
final int readTimeoutInMillis); DpsClient(final String dpsUrl); long submitTask(DpsTask task, String topologyName); void cleanMetisIndexingDataset(String topologyName, long taskId,
DataSetCleanerParameters dataSetCleanerParameters); void cleanMetisIndexingDataset(String topologyName, long taskId,
DataSetCleanerParameters dataSetCleanerParameters, String key, String value); Response.StatusType topologyPermit(String topologyName, String username); TaskInfo getTaskProgress(String topologyName, final long taskId); List<SubTaskInfo> getDetailedTaskReport(final String topologyName, final long taskId); List<SubTaskInfo> getDetailedTaskReportBetweenChunks(final String topologyName,
final long taskId, int from, int to); List<NodeReport> getElementReport(final String topologyName, final long taskId,
String elementPath); TaskErrorsInfo getTaskErrorsReport(final String topologyName, final long taskId,
final String error, final int idsCount); boolean checkIfErrorReportExists(final String topologyName, final long taskId); StatisticsReport getTaskStatisticsReport(final String topologyName, final long taskId); String killTask(final String topologyName, final long taskId, String info); void close(); } |
@Test public void prepareBoundStatementForMatchingTargetTableTest() { assertThat(CassandraHelper.prepareBoundStatementForMatchingTargetTable(cassandraConnectionProvider, "table", primaryKeys), is(boundStatement)); } | public static BoundStatement prepareBoundStatementForMatchingTargetTable(CassandraConnectionProvider cassandraConnectionProvider, String targetTableName, List<String> primaryKeys) { String matchCountStatementCQL = CQLBuilder.getMatchCountStatementFromTargetTable(targetTableName, primaryKeys); PreparedStatement matchCountStatementCQLStatement = cassandraConnectionProvider.getSession().prepare(matchCountStatementCQL); matchCountStatementCQLStatement.setConsistencyLevel(cassandraConnectionProvider.getConsistencyLevel()); return matchCountStatementCQLStatement.bind(); } | CassandraHelper { public static BoundStatement prepareBoundStatementForMatchingTargetTable(CassandraConnectionProvider cassandraConnectionProvider, String targetTableName, List<String> primaryKeys) { String matchCountStatementCQL = CQLBuilder.getMatchCountStatementFromTargetTable(targetTableName, primaryKeys); PreparedStatement matchCountStatementCQLStatement = cassandraConnectionProvider.getSession().prepare(matchCountStatementCQL); matchCountStatementCQLStatement.setConsistencyLevel(cassandraConnectionProvider.getConsistencyLevel()); return matchCountStatementCQLStatement.bind(); } } | CassandraHelper { public static BoundStatement prepareBoundStatementForMatchingTargetTable(CassandraConnectionProvider cassandraConnectionProvider, String targetTableName, List<String> primaryKeys) { String matchCountStatementCQL = CQLBuilder.getMatchCountStatementFromTargetTable(targetTableName, primaryKeys); PreparedStatement matchCountStatementCQLStatement = cassandraConnectionProvider.getSession().prepare(matchCountStatementCQL); matchCountStatementCQLStatement.setConsistencyLevel(cassandraConnectionProvider.getConsistencyLevel()); return matchCountStatementCQLStatement.bind(); } } | CassandraHelper { public static BoundStatement prepareBoundStatementForMatchingTargetTable(CassandraConnectionProvider cassandraConnectionProvider, String targetTableName, List<String> primaryKeys) { String matchCountStatementCQL = CQLBuilder.getMatchCountStatementFromTargetTable(targetTableName, primaryKeys); PreparedStatement matchCountStatementCQLStatement = cassandraConnectionProvider.getSession().prepare(matchCountStatementCQL); matchCountStatementCQLStatement.setConsistencyLevel(cassandraConnectionProvider.getConsistencyLevel()); return matchCountStatementCQLStatement.bind(); } static BoundStatement prepareBoundStatementForMatchingTargetTable(CassandraConnectionProvider cassandraConnectionProvider, String targetTableName, List<String> primaryKeys); static ResultSet getPrimaryKeysFromSourceTable(CassandraConnectionProvider cassandraConnectionProvider, String sourceTableName, List<String> primaryKeys); static List<String> getPrimaryKeysNames(CassandraConnectionProvider cassandraConnectionProvider, String tableName, String selectColumnNames); } | CassandraHelper { public static BoundStatement prepareBoundStatementForMatchingTargetTable(CassandraConnectionProvider cassandraConnectionProvider, String targetTableName, List<String> primaryKeys) { String matchCountStatementCQL = CQLBuilder.getMatchCountStatementFromTargetTable(targetTableName, primaryKeys); PreparedStatement matchCountStatementCQLStatement = cassandraConnectionProvider.getSession().prepare(matchCountStatementCQL); matchCountStatementCQLStatement.setConsistencyLevel(cassandraConnectionProvider.getConsistencyLevel()); return matchCountStatementCQLStatement.bind(); } static BoundStatement prepareBoundStatementForMatchingTargetTable(CassandraConnectionProvider cassandraConnectionProvider, String targetTableName, List<String> primaryKeys); static ResultSet getPrimaryKeysFromSourceTable(CassandraConnectionProvider cassandraConnectionProvider, String sourceTableName, List<String> primaryKeys); static List<String> getPrimaryKeysNames(CassandraConnectionProvider cassandraConnectionProvider, String tableName, String selectColumnNames); } |
@Test @Betamax(tape = "DPSClient_shouldReturnTrueWhenErrorsReportExists") public final void shouldReturnTrueWhenErrorsReportExists() throws DpsException { dpsClient = new DpsClient(BASE_URL, REGULAR_USER_NAME, REGULAR_USER_PASSWORD); assertTrue(dpsClient.checkIfErrorReportExists(TOPOLOGY_NAME, TASK_ID)); } | public boolean checkIfErrorReportExists(final String topologyName, final long taskId) { Response response = null; try { response = client .target(dpsUrl) .path(ERRORS_TASK_REPORT_URL) .resolveTemplate(TOPOLOGY_NAME, topologyName) .resolveTemplate(TASK_ID, taskId) .request().head(); return response.getStatus() == Response.Status.OK.getStatusCode(); } finally { closeResponse(response); } } | DpsClient { public boolean checkIfErrorReportExists(final String topologyName, final long taskId) { Response response = null; try { response = client .target(dpsUrl) .path(ERRORS_TASK_REPORT_URL) .resolveTemplate(TOPOLOGY_NAME, topologyName) .resolveTemplate(TASK_ID, taskId) .request().head(); return response.getStatus() == Response.Status.OK.getStatusCode(); } finally { closeResponse(response); } } } | DpsClient { public boolean checkIfErrorReportExists(final String topologyName, final long taskId) { Response response = null; try { response = client .target(dpsUrl) .path(ERRORS_TASK_REPORT_URL) .resolveTemplate(TOPOLOGY_NAME, topologyName) .resolveTemplate(TASK_ID, taskId) .request().head(); return response.getStatus() == Response.Status.OK.getStatusCode(); } finally { closeResponse(response); } } DpsClient(final String dpsUrl, final String username, final String password,
final int connectTimeoutInMillis, final int readTimeoutInMillis); DpsClient(final String dpsUrl, final String username, final String password); DpsClient(final String dpsUrl, final int connectTimeoutInMillis,
final int readTimeoutInMillis); DpsClient(final String dpsUrl); } | DpsClient { public boolean checkIfErrorReportExists(final String topologyName, final long taskId) { Response response = null; try { response = client .target(dpsUrl) .path(ERRORS_TASK_REPORT_URL) .resolveTemplate(TOPOLOGY_NAME, topologyName) .resolveTemplate(TASK_ID, taskId) .request().head(); return response.getStatus() == Response.Status.OK.getStatusCode(); } finally { closeResponse(response); } } DpsClient(final String dpsUrl, final String username, final String password,
final int connectTimeoutInMillis, final int readTimeoutInMillis); DpsClient(final String dpsUrl, final String username, final String password); DpsClient(final String dpsUrl, final int connectTimeoutInMillis,
final int readTimeoutInMillis); DpsClient(final String dpsUrl); long submitTask(DpsTask task, String topologyName); void cleanMetisIndexingDataset(String topologyName, long taskId,
DataSetCleanerParameters dataSetCleanerParameters); void cleanMetisIndexingDataset(String topologyName, long taskId,
DataSetCleanerParameters dataSetCleanerParameters, String key, String value); Response.StatusType topologyPermit(String topologyName, String username); TaskInfo getTaskProgress(String topologyName, final long taskId); List<SubTaskInfo> getDetailedTaskReport(final String topologyName, final long taskId); List<SubTaskInfo> getDetailedTaskReportBetweenChunks(final String topologyName,
final long taskId, int from, int to); List<NodeReport> getElementReport(final String topologyName, final long taskId,
String elementPath); TaskErrorsInfo getTaskErrorsReport(final String topologyName, final long taskId,
final String error, final int idsCount); boolean checkIfErrorReportExists(final String topologyName, final long taskId); StatisticsReport getTaskStatisticsReport(final String topologyName, final long taskId); String killTask(final String topologyName, final long taskId, String info); void close(); } | DpsClient { public boolean checkIfErrorReportExists(final String topologyName, final long taskId) { Response response = null; try { response = client .target(dpsUrl) .path(ERRORS_TASK_REPORT_URL) .resolveTemplate(TOPOLOGY_NAME, topologyName) .resolveTemplate(TASK_ID, taskId) .request().head(); return response.getStatus() == Response.Status.OK.getStatusCode(); } finally { closeResponse(response); } } DpsClient(final String dpsUrl, final String username, final String password,
final int connectTimeoutInMillis, final int readTimeoutInMillis); DpsClient(final String dpsUrl, final String username, final String password); DpsClient(final String dpsUrl, final int connectTimeoutInMillis,
final int readTimeoutInMillis); DpsClient(final String dpsUrl); long submitTask(DpsTask task, String topologyName); void cleanMetisIndexingDataset(String topologyName, long taskId,
DataSetCleanerParameters dataSetCleanerParameters); void cleanMetisIndexingDataset(String topologyName, long taskId,
DataSetCleanerParameters dataSetCleanerParameters, String key, String value); Response.StatusType topologyPermit(String topologyName, String username); TaskInfo getTaskProgress(String topologyName, final long taskId); List<SubTaskInfo> getDetailedTaskReport(final String topologyName, final long taskId); List<SubTaskInfo> getDetailedTaskReportBetweenChunks(final String topologyName,
final long taskId, int from, int to); List<NodeReport> getElementReport(final String topologyName, final long taskId,
String elementPath); TaskErrorsInfo getTaskErrorsReport(final String topologyName, final long taskId,
final String error, final int idsCount); boolean checkIfErrorReportExists(final String topologyName, final long taskId); StatisticsReport getTaskStatisticsReport(final String topologyName, final long taskId); String killTask(final String topologyName, final long taskId, String info); void close(); } |
@Test @Betamax(tape = "DPSClient_shouldReturnFalseWhenErrorsReportDoesNotExists") public final void shouldReturnFalseWhenErrorsReportDoesNotExists() throws DpsException { dpsClient = new DpsClient(BASE_URL, REGULAR_USER_NAME, REGULAR_USER_PASSWORD); assertFalse(dpsClient.checkIfErrorReportExists(TOPOLOGY_NAME, TASK_ID)); } | public boolean checkIfErrorReportExists(final String topologyName, final long taskId) { Response response = null; try { response = client .target(dpsUrl) .path(ERRORS_TASK_REPORT_URL) .resolveTemplate(TOPOLOGY_NAME, topologyName) .resolveTemplate(TASK_ID, taskId) .request().head(); return response.getStatus() == Response.Status.OK.getStatusCode(); } finally { closeResponse(response); } } | DpsClient { public boolean checkIfErrorReportExists(final String topologyName, final long taskId) { Response response = null; try { response = client .target(dpsUrl) .path(ERRORS_TASK_REPORT_URL) .resolveTemplate(TOPOLOGY_NAME, topologyName) .resolveTemplate(TASK_ID, taskId) .request().head(); return response.getStatus() == Response.Status.OK.getStatusCode(); } finally { closeResponse(response); } } } | DpsClient { public boolean checkIfErrorReportExists(final String topologyName, final long taskId) { Response response = null; try { response = client .target(dpsUrl) .path(ERRORS_TASK_REPORT_URL) .resolveTemplate(TOPOLOGY_NAME, topologyName) .resolveTemplate(TASK_ID, taskId) .request().head(); return response.getStatus() == Response.Status.OK.getStatusCode(); } finally { closeResponse(response); } } DpsClient(final String dpsUrl, final String username, final String password,
final int connectTimeoutInMillis, final int readTimeoutInMillis); DpsClient(final String dpsUrl, final String username, final String password); DpsClient(final String dpsUrl, final int connectTimeoutInMillis,
final int readTimeoutInMillis); DpsClient(final String dpsUrl); } | DpsClient { public boolean checkIfErrorReportExists(final String topologyName, final long taskId) { Response response = null; try { response = client .target(dpsUrl) .path(ERRORS_TASK_REPORT_URL) .resolveTemplate(TOPOLOGY_NAME, topologyName) .resolveTemplate(TASK_ID, taskId) .request().head(); return response.getStatus() == Response.Status.OK.getStatusCode(); } finally { closeResponse(response); } } DpsClient(final String dpsUrl, final String username, final String password,
final int connectTimeoutInMillis, final int readTimeoutInMillis); DpsClient(final String dpsUrl, final String username, final String password); DpsClient(final String dpsUrl, final int connectTimeoutInMillis,
final int readTimeoutInMillis); DpsClient(final String dpsUrl); long submitTask(DpsTask task, String topologyName); void cleanMetisIndexingDataset(String topologyName, long taskId,
DataSetCleanerParameters dataSetCleanerParameters); void cleanMetisIndexingDataset(String topologyName, long taskId,
DataSetCleanerParameters dataSetCleanerParameters, String key, String value); Response.StatusType topologyPermit(String topologyName, String username); TaskInfo getTaskProgress(String topologyName, final long taskId); List<SubTaskInfo> getDetailedTaskReport(final String topologyName, final long taskId); List<SubTaskInfo> getDetailedTaskReportBetweenChunks(final String topologyName,
final long taskId, int from, int to); List<NodeReport> getElementReport(final String topologyName, final long taskId,
String elementPath); TaskErrorsInfo getTaskErrorsReport(final String topologyName, final long taskId,
final String error, final int idsCount); boolean checkIfErrorReportExists(final String topologyName, final long taskId); StatisticsReport getTaskStatisticsReport(final String topologyName, final long taskId); String killTask(final String topologyName, final long taskId, String info); void close(); } | DpsClient { public boolean checkIfErrorReportExists(final String topologyName, final long taskId) { Response response = null; try { response = client .target(dpsUrl) .path(ERRORS_TASK_REPORT_URL) .resolveTemplate(TOPOLOGY_NAME, topologyName) .resolveTemplate(TASK_ID, taskId) .request().head(); return response.getStatus() == Response.Status.OK.getStatusCode(); } finally { closeResponse(response); } } DpsClient(final String dpsUrl, final String username, final String password,
final int connectTimeoutInMillis, final int readTimeoutInMillis); DpsClient(final String dpsUrl, final String username, final String password); DpsClient(final String dpsUrl, final int connectTimeoutInMillis,
final int readTimeoutInMillis); DpsClient(final String dpsUrl); long submitTask(DpsTask task, String topologyName); void cleanMetisIndexingDataset(String topologyName, long taskId,
DataSetCleanerParameters dataSetCleanerParameters); void cleanMetisIndexingDataset(String topologyName, long taskId,
DataSetCleanerParameters dataSetCleanerParameters, String key, String value); Response.StatusType topologyPermit(String topologyName, String username); TaskInfo getTaskProgress(String topologyName, final long taskId); List<SubTaskInfo> getDetailedTaskReport(final String topologyName, final long taskId); List<SubTaskInfo> getDetailedTaskReportBetweenChunks(final String topologyName,
final long taskId, int from, int to); List<NodeReport> getElementReport(final String topologyName, final long taskId,
String elementPath); TaskErrorsInfo getTaskErrorsReport(final String topologyName, final long taskId,
final String error, final int idsCount); boolean checkIfErrorReportExists(final String topologyName, final long taskId); StatisticsReport getTaskStatisticsReport(final String topologyName, final long taskId); String killTask(final String topologyName, final long taskId, String info); void close(); } |
@Test @Betamax(tape = "DPSClient_shouldReturnedSpecificErrorReport") public final void shouldReturnedSpecificErrorReport() throws DpsException { dpsClient = new DpsClient(BASE_URL, REGULAR_USER_NAME, REGULAR_USER_PASSWORD); TaskErrorsInfo report = createErrorInfo(TASK_ID, true); assertThat(dpsClient.getTaskErrorsReport(TOPOLOGY_NAME, TASK_ID, ERROR_TYPE, 100), is(report)); } | public TaskErrorsInfo getTaskErrorsReport(final String topologyName, final long taskId, final String error, final int idsCount) throws DpsException { Response response = null; try { response = client .target(dpsUrl) .path(ERRORS_TASK_REPORT_URL) .resolveTemplate(TOPOLOGY_NAME, topologyName) .resolveTemplate(TASK_ID, taskId) .queryParam(ERROR, error) .queryParam(IDS_COUNT, idsCount) .request().get(); return handleErrorResponse(response); } finally { closeResponse(response); } } | DpsClient { public TaskErrorsInfo getTaskErrorsReport(final String topologyName, final long taskId, final String error, final int idsCount) throws DpsException { Response response = null; try { response = client .target(dpsUrl) .path(ERRORS_TASK_REPORT_URL) .resolveTemplate(TOPOLOGY_NAME, topologyName) .resolveTemplate(TASK_ID, taskId) .queryParam(ERROR, error) .queryParam(IDS_COUNT, idsCount) .request().get(); return handleErrorResponse(response); } finally { closeResponse(response); } } } | DpsClient { public TaskErrorsInfo getTaskErrorsReport(final String topologyName, final long taskId, final String error, final int idsCount) throws DpsException { Response response = null; try { response = client .target(dpsUrl) .path(ERRORS_TASK_REPORT_URL) .resolveTemplate(TOPOLOGY_NAME, topologyName) .resolveTemplate(TASK_ID, taskId) .queryParam(ERROR, error) .queryParam(IDS_COUNT, idsCount) .request().get(); return handleErrorResponse(response); } finally { closeResponse(response); } } DpsClient(final String dpsUrl, final String username, final String password,
final int connectTimeoutInMillis, final int readTimeoutInMillis); DpsClient(final String dpsUrl, final String username, final String password); DpsClient(final String dpsUrl, final int connectTimeoutInMillis,
final int readTimeoutInMillis); DpsClient(final String dpsUrl); } | DpsClient { public TaskErrorsInfo getTaskErrorsReport(final String topologyName, final long taskId, final String error, final int idsCount) throws DpsException { Response response = null; try { response = client .target(dpsUrl) .path(ERRORS_TASK_REPORT_URL) .resolveTemplate(TOPOLOGY_NAME, topologyName) .resolveTemplate(TASK_ID, taskId) .queryParam(ERROR, error) .queryParam(IDS_COUNT, idsCount) .request().get(); return handleErrorResponse(response); } finally { closeResponse(response); } } DpsClient(final String dpsUrl, final String username, final String password,
final int connectTimeoutInMillis, final int readTimeoutInMillis); DpsClient(final String dpsUrl, final String username, final String password); DpsClient(final String dpsUrl, final int connectTimeoutInMillis,
final int readTimeoutInMillis); DpsClient(final String dpsUrl); long submitTask(DpsTask task, String topologyName); void cleanMetisIndexingDataset(String topologyName, long taskId,
DataSetCleanerParameters dataSetCleanerParameters); void cleanMetisIndexingDataset(String topologyName, long taskId,
DataSetCleanerParameters dataSetCleanerParameters, String key, String value); Response.StatusType topologyPermit(String topologyName, String username); TaskInfo getTaskProgress(String topologyName, final long taskId); List<SubTaskInfo> getDetailedTaskReport(final String topologyName, final long taskId); List<SubTaskInfo> getDetailedTaskReportBetweenChunks(final String topologyName,
final long taskId, int from, int to); List<NodeReport> getElementReport(final String topologyName, final long taskId,
String elementPath); TaskErrorsInfo getTaskErrorsReport(final String topologyName, final long taskId,
final String error, final int idsCount); boolean checkIfErrorReportExists(final String topologyName, final long taskId); StatisticsReport getTaskStatisticsReport(final String topologyName, final long taskId); String killTask(final String topologyName, final long taskId, String info); void close(); } | DpsClient { public TaskErrorsInfo getTaskErrorsReport(final String topologyName, final long taskId, final String error, final int idsCount) throws DpsException { Response response = null; try { response = client .target(dpsUrl) .path(ERRORS_TASK_REPORT_URL) .resolveTemplate(TOPOLOGY_NAME, topologyName) .resolveTemplate(TASK_ID, taskId) .queryParam(ERROR, error) .queryParam(IDS_COUNT, idsCount) .request().get(); return handleErrorResponse(response); } finally { closeResponse(response); } } DpsClient(final String dpsUrl, final String username, final String password,
final int connectTimeoutInMillis, final int readTimeoutInMillis); DpsClient(final String dpsUrl, final String username, final String password); DpsClient(final String dpsUrl, final int connectTimeoutInMillis,
final int readTimeoutInMillis); DpsClient(final String dpsUrl); long submitTask(DpsTask task, String topologyName); void cleanMetisIndexingDataset(String topologyName, long taskId,
DataSetCleanerParameters dataSetCleanerParameters); void cleanMetisIndexingDataset(String topologyName, long taskId,
DataSetCleanerParameters dataSetCleanerParameters, String key, String value); Response.StatusType topologyPermit(String topologyName, String username); TaskInfo getTaskProgress(String topologyName, final long taskId); List<SubTaskInfo> getDetailedTaskReport(final String topologyName, final long taskId); List<SubTaskInfo> getDetailedTaskReportBetweenChunks(final String topologyName,
final long taskId, int from, int to); List<NodeReport> getElementReport(final String topologyName, final long taskId,
String elementPath); TaskErrorsInfo getTaskErrorsReport(final String topologyName, final long taskId,
final String error, final int idsCount); boolean checkIfErrorReportExists(final String topologyName, final long taskId); StatisticsReport getTaskStatisticsReport(final String topologyName, final long taskId); String killTask(final String topologyName, final long taskId, String info); void close(); } |
@Test @Betamax(tape = "DPSClient_shouldReturnElementReport") public void shouldGetTheElementReport() throws DpsException { dpsClient = new DpsClient(BASE_URL, REGULAR_USER_NAME, REGULAR_USER_PASSWORD); List<NodeReport> nodeReports = dpsClient.getElementReport(TOPOLOGY_NAME, TASK_ID, " assertNotNull(nodeReports); assertEquals(1, nodeReports.size()); assertEquals("Lattakia", nodeReports.get(0).getNodeValue()); assertEquals(10, nodeReports.get(0).getOccurrence()); List<AttributeStatistics> attributes = nodeReports.get(0).getAttributeStatistics(); assertNotNull(attributes); assertEquals(1, attributes.size()); assertEquals(" assertEquals(10, attributes.get(0).getOccurrence()); assertEquals("en", attributes.get(0).getValue()); } | public List<NodeReport> getElementReport(final String topologyName, final long taskId, String elementPath) throws DpsException { Response getResponse = null; try { getResponse = client .target(dpsUrl) .path(ELEMENT_REPORT) .resolveTemplate(TOPOLOGY_NAME, topologyName) .resolveTemplate(TASK_ID, taskId).queryParam("path", elementPath) .request().get(); return handleElementReportResponse(getResponse); } finally { closeResponse(getResponse); } } | DpsClient { public List<NodeReport> getElementReport(final String topologyName, final long taskId, String elementPath) throws DpsException { Response getResponse = null; try { getResponse = client .target(dpsUrl) .path(ELEMENT_REPORT) .resolveTemplate(TOPOLOGY_NAME, topologyName) .resolveTemplate(TASK_ID, taskId).queryParam("path", elementPath) .request().get(); return handleElementReportResponse(getResponse); } finally { closeResponse(getResponse); } } } | DpsClient { public List<NodeReport> getElementReport(final String topologyName, final long taskId, String elementPath) throws DpsException { Response getResponse = null; try { getResponse = client .target(dpsUrl) .path(ELEMENT_REPORT) .resolveTemplate(TOPOLOGY_NAME, topologyName) .resolveTemplate(TASK_ID, taskId).queryParam("path", elementPath) .request().get(); return handleElementReportResponse(getResponse); } finally { closeResponse(getResponse); } } DpsClient(final String dpsUrl, final String username, final String password,
final int connectTimeoutInMillis, final int readTimeoutInMillis); DpsClient(final String dpsUrl, final String username, final String password); DpsClient(final String dpsUrl, final int connectTimeoutInMillis,
final int readTimeoutInMillis); DpsClient(final String dpsUrl); } | DpsClient { public List<NodeReport> getElementReport(final String topologyName, final long taskId, String elementPath) throws DpsException { Response getResponse = null; try { getResponse = client .target(dpsUrl) .path(ELEMENT_REPORT) .resolveTemplate(TOPOLOGY_NAME, topologyName) .resolveTemplate(TASK_ID, taskId).queryParam("path", elementPath) .request().get(); return handleElementReportResponse(getResponse); } finally { closeResponse(getResponse); } } DpsClient(final String dpsUrl, final String username, final String password,
final int connectTimeoutInMillis, final int readTimeoutInMillis); DpsClient(final String dpsUrl, final String username, final String password); DpsClient(final String dpsUrl, final int connectTimeoutInMillis,
final int readTimeoutInMillis); DpsClient(final String dpsUrl); long submitTask(DpsTask task, String topologyName); void cleanMetisIndexingDataset(String topologyName, long taskId,
DataSetCleanerParameters dataSetCleanerParameters); void cleanMetisIndexingDataset(String topologyName, long taskId,
DataSetCleanerParameters dataSetCleanerParameters, String key, String value); Response.StatusType topologyPermit(String topologyName, String username); TaskInfo getTaskProgress(String topologyName, final long taskId); List<SubTaskInfo> getDetailedTaskReport(final String topologyName, final long taskId); List<SubTaskInfo> getDetailedTaskReportBetweenChunks(final String topologyName,
final long taskId, int from, int to); List<NodeReport> getElementReport(final String topologyName, final long taskId,
String elementPath); TaskErrorsInfo getTaskErrorsReport(final String topologyName, final long taskId,
final String error, final int idsCount); boolean checkIfErrorReportExists(final String topologyName, final long taskId); StatisticsReport getTaskStatisticsReport(final String topologyName, final long taskId); String killTask(final String topologyName, final long taskId, String info); void close(); } | DpsClient { public List<NodeReport> getElementReport(final String topologyName, final long taskId, String elementPath) throws DpsException { Response getResponse = null; try { getResponse = client .target(dpsUrl) .path(ELEMENT_REPORT) .resolveTemplate(TOPOLOGY_NAME, topologyName) .resolveTemplate(TASK_ID, taskId).queryParam("path", elementPath) .request().get(); return handleElementReportResponse(getResponse); } finally { closeResponse(getResponse); } } DpsClient(final String dpsUrl, final String username, final String password,
final int connectTimeoutInMillis, final int readTimeoutInMillis); DpsClient(final String dpsUrl, final String username, final String password); DpsClient(final String dpsUrl, final int connectTimeoutInMillis,
final int readTimeoutInMillis); DpsClient(final String dpsUrl); long submitTask(DpsTask task, String topologyName); void cleanMetisIndexingDataset(String topologyName, long taskId,
DataSetCleanerParameters dataSetCleanerParameters); void cleanMetisIndexingDataset(String topologyName, long taskId,
DataSetCleanerParameters dataSetCleanerParameters, String key, String value); Response.StatusType topologyPermit(String topologyName, String username); TaskInfo getTaskProgress(String topologyName, final long taskId); List<SubTaskInfo> getDetailedTaskReport(final String topologyName, final long taskId); List<SubTaskInfo> getDetailedTaskReportBetweenChunks(final String topologyName,
final long taskId, int from, int to); List<NodeReport> getElementReport(final String topologyName, final long taskId,
String elementPath); TaskErrorsInfo getTaskErrorsReport(final String topologyName, final long taskId,
final String error, final int idsCount); boolean checkIfErrorReportExists(final String topologyName, final long taskId); StatisticsReport getTaskStatisticsReport(final String topologyName, final long taskId); String killTask(final String topologyName, final long taskId, String info); void close(); } |
@Test(expected = AccessDeniedOrTopologyDoesNotExistException.class) @Betamax(tape = "DPSClient_shouldThrowExceptionForStatisticsWhenTopologyDoesNotExist") public void shouldThrowExceptionForStatistics() throws DpsException { dpsClient = new DpsClient(BASE_URL, REGULAR_USER_NAME, REGULAR_USER_PASSWORD); dpsClient.getTaskStatisticsReport(NOT_DEFINED_TOPOLOGY_NAME, TASK_ID); } | public StatisticsReport getTaskStatisticsReport(final String topologyName, final long taskId) throws DpsException { Response response = null; try { response = client.target(dpsUrl).path(STATISTICS_REPORT_URL) .resolveTemplate(TOPOLOGY_NAME, topologyName).resolveTemplate(TASK_ID, taskId).request() .get(); if (response.getStatus() == Response.Status.OK.getStatusCode()) { return response.readEntity(StatisticsReport.class); } else { LOGGER.error("Task statistics report cannot be read"); throw handleException(response); } } finally { closeResponse(response); } } | DpsClient { public StatisticsReport getTaskStatisticsReport(final String topologyName, final long taskId) throws DpsException { Response response = null; try { response = client.target(dpsUrl).path(STATISTICS_REPORT_URL) .resolveTemplate(TOPOLOGY_NAME, topologyName).resolveTemplate(TASK_ID, taskId).request() .get(); if (response.getStatus() == Response.Status.OK.getStatusCode()) { return response.readEntity(StatisticsReport.class); } else { LOGGER.error("Task statistics report cannot be read"); throw handleException(response); } } finally { closeResponse(response); } } } | DpsClient { public StatisticsReport getTaskStatisticsReport(final String topologyName, final long taskId) throws DpsException { Response response = null; try { response = client.target(dpsUrl).path(STATISTICS_REPORT_URL) .resolveTemplate(TOPOLOGY_NAME, topologyName).resolveTemplate(TASK_ID, taskId).request() .get(); if (response.getStatus() == Response.Status.OK.getStatusCode()) { return response.readEntity(StatisticsReport.class); } else { LOGGER.error("Task statistics report cannot be read"); throw handleException(response); } } finally { closeResponse(response); } } DpsClient(final String dpsUrl, final String username, final String password,
final int connectTimeoutInMillis, final int readTimeoutInMillis); DpsClient(final String dpsUrl, final String username, final String password); DpsClient(final String dpsUrl, final int connectTimeoutInMillis,
final int readTimeoutInMillis); DpsClient(final String dpsUrl); } | DpsClient { public StatisticsReport getTaskStatisticsReport(final String topologyName, final long taskId) throws DpsException { Response response = null; try { response = client.target(dpsUrl).path(STATISTICS_REPORT_URL) .resolveTemplate(TOPOLOGY_NAME, topologyName).resolveTemplate(TASK_ID, taskId).request() .get(); if (response.getStatus() == Response.Status.OK.getStatusCode()) { return response.readEntity(StatisticsReport.class); } else { LOGGER.error("Task statistics report cannot be read"); throw handleException(response); } } finally { closeResponse(response); } } DpsClient(final String dpsUrl, final String username, final String password,
final int connectTimeoutInMillis, final int readTimeoutInMillis); DpsClient(final String dpsUrl, final String username, final String password); DpsClient(final String dpsUrl, final int connectTimeoutInMillis,
final int readTimeoutInMillis); DpsClient(final String dpsUrl); long submitTask(DpsTask task, String topologyName); void cleanMetisIndexingDataset(String topologyName, long taskId,
DataSetCleanerParameters dataSetCleanerParameters); void cleanMetisIndexingDataset(String topologyName, long taskId,
DataSetCleanerParameters dataSetCleanerParameters, String key, String value); Response.StatusType topologyPermit(String topologyName, String username); TaskInfo getTaskProgress(String topologyName, final long taskId); List<SubTaskInfo> getDetailedTaskReport(final String topologyName, final long taskId); List<SubTaskInfo> getDetailedTaskReportBetweenChunks(final String topologyName,
final long taskId, int from, int to); List<NodeReport> getElementReport(final String topologyName, final long taskId,
String elementPath); TaskErrorsInfo getTaskErrorsReport(final String topologyName, final long taskId,
final String error, final int idsCount); boolean checkIfErrorReportExists(final String topologyName, final long taskId); StatisticsReport getTaskStatisticsReport(final String topologyName, final long taskId); String killTask(final String topologyName, final long taskId, String info); void close(); } | DpsClient { public StatisticsReport getTaskStatisticsReport(final String topologyName, final long taskId) throws DpsException { Response response = null; try { response = client.target(dpsUrl).path(STATISTICS_REPORT_URL) .resolveTemplate(TOPOLOGY_NAME, topologyName).resolveTemplate(TASK_ID, taskId).request() .get(); if (response.getStatus() == Response.Status.OK.getStatusCode()) { return response.readEntity(StatisticsReport.class); } else { LOGGER.error("Task statistics report cannot be read"); throw handleException(response); } } finally { closeResponse(response); } } DpsClient(final String dpsUrl, final String username, final String password,
final int connectTimeoutInMillis, final int readTimeoutInMillis); DpsClient(final String dpsUrl, final String username, final String password); DpsClient(final String dpsUrl, final int connectTimeoutInMillis,
final int readTimeoutInMillis); DpsClient(final String dpsUrl); long submitTask(DpsTask task, String topologyName); void cleanMetisIndexingDataset(String topologyName, long taskId,
DataSetCleanerParameters dataSetCleanerParameters); void cleanMetisIndexingDataset(String topologyName, long taskId,
DataSetCleanerParameters dataSetCleanerParameters, String key, String value); Response.StatusType topologyPermit(String topologyName, String username); TaskInfo getTaskProgress(String topologyName, final long taskId); List<SubTaskInfo> getDetailedTaskReport(final String topologyName, final long taskId); List<SubTaskInfo> getDetailedTaskReportBetweenChunks(final String topologyName,
final long taskId, int from, int to); List<NodeReport> getElementReport(final String topologyName, final long taskId,
String elementPath); TaskErrorsInfo getTaskErrorsReport(final String topologyName, final long taskId,
final String error, final int idsCount); boolean checkIfErrorReportExists(final String topologyName, final long taskId); StatisticsReport getTaskStatisticsReport(final String topologyName, final long taskId); String killTask(final String topologyName, final long taskId, String info); void close(); } |
@Test(expected = AccessDeniedOrObjectDoesNotExistException.class) @Betamax(tape = "DPSClient_shouldThrowExceptionForStatisticsWhenTaskIdDoesNotExistOrUnAccessible") public void shouldThrowExceptionForStatisticsWhenTaskIdIsUnAccessible() throws DpsException { dpsClient = new DpsClient(BASE_URL, REGULAR_USER_NAME, REGULAR_USER_PASSWORD); dpsClient.getTaskStatisticsReport(TOPOLOGY_NAME, TASK_ID); } | public StatisticsReport getTaskStatisticsReport(final String topologyName, final long taskId) throws DpsException { Response response = null; try { response = client.target(dpsUrl).path(STATISTICS_REPORT_URL) .resolveTemplate(TOPOLOGY_NAME, topologyName).resolveTemplate(TASK_ID, taskId).request() .get(); if (response.getStatus() == Response.Status.OK.getStatusCode()) { return response.readEntity(StatisticsReport.class); } else { LOGGER.error("Task statistics report cannot be read"); throw handleException(response); } } finally { closeResponse(response); } } | DpsClient { public StatisticsReport getTaskStatisticsReport(final String topologyName, final long taskId) throws DpsException { Response response = null; try { response = client.target(dpsUrl).path(STATISTICS_REPORT_URL) .resolveTemplate(TOPOLOGY_NAME, topologyName).resolveTemplate(TASK_ID, taskId).request() .get(); if (response.getStatus() == Response.Status.OK.getStatusCode()) { return response.readEntity(StatisticsReport.class); } else { LOGGER.error("Task statistics report cannot be read"); throw handleException(response); } } finally { closeResponse(response); } } } | DpsClient { public StatisticsReport getTaskStatisticsReport(final String topologyName, final long taskId) throws DpsException { Response response = null; try { response = client.target(dpsUrl).path(STATISTICS_REPORT_URL) .resolveTemplate(TOPOLOGY_NAME, topologyName).resolveTemplate(TASK_ID, taskId).request() .get(); if (response.getStatus() == Response.Status.OK.getStatusCode()) { return response.readEntity(StatisticsReport.class); } else { LOGGER.error("Task statistics report cannot be read"); throw handleException(response); } } finally { closeResponse(response); } } DpsClient(final String dpsUrl, final String username, final String password,
final int connectTimeoutInMillis, final int readTimeoutInMillis); DpsClient(final String dpsUrl, final String username, final String password); DpsClient(final String dpsUrl, final int connectTimeoutInMillis,
final int readTimeoutInMillis); DpsClient(final String dpsUrl); } | DpsClient { public StatisticsReport getTaskStatisticsReport(final String topologyName, final long taskId) throws DpsException { Response response = null; try { response = client.target(dpsUrl).path(STATISTICS_REPORT_URL) .resolveTemplate(TOPOLOGY_NAME, topologyName).resolveTemplate(TASK_ID, taskId).request() .get(); if (response.getStatus() == Response.Status.OK.getStatusCode()) { return response.readEntity(StatisticsReport.class); } else { LOGGER.error("Task statistics report cannot be read"); throw handleException(response); } } finally { closeResponse(response); } } DpsClient(final String dpsUrl, final String username, final String password,
final int connectTimeoutInMillis, final int readTimeoutInMillis); DpsClient(final String dpsUrl, final String username, final String password); DpsClient(final String dpsUrl, final int connectTimeoutInMillis,
final int readTimeoutInMillis); DpsClient(final String dpsUrl); long submitTask(DpsTask task, String topologyName); void cleanMetisIndexingDataset(String topologyName, long taskId,
DataSetCleanerParameters dataSetCleanerParameters); void cleanMetisIndexingDataset(String topologyName, long taskId,
DataSetCleanerParameters dataSetCleanerParameters, String key, String value); Response.StatusType topologyPermit(String topologyName, String username); TaskInfo getTaskProgress(String topologyName, final long taskId); List<SubTaskInfo> getDetailedTaskReport(final String topologyName, final long taskId); List<SubTaskInfo> getDetailedTaskReportBetweenChunks(final String topologyName,
final long taskId, int from, int to); List<NodeReport> getElementReport(final String topologyName, final long taskId,
String elementPath); TaskErrorsInfo getTaskErrorsReport(final String topologyName, final long taskId,
final String error, final int idsCount); boolean checkIfErrorReportExists(final String topologyName, final long taskId); StatisticsReport getTaskStatisticsReport(final String topologyName, final long taskId); String killTask(final String topologyName, final long taskId, String info); void close(); } | DpsClient { public StatisticsReport getTaskStatisticsReport(final String topologyName, final long taskId) throws DpsException { Response response = null; try { response = client.target(dpsUrl).path(STATISTICS_REPORT_URL) .resolveTemplate(TOPOLOGY_NAME, topologyName).resolveTemplate(TASK_ID, taskId).request() .get(); if (response.getStatus() == Response.Status.OK.getStatusCode()) { return response.readEntity(StatisticsReport.class); } else { LOGGER.error("Task statistics report cannot be read"); throw handleException(response); } } finally { closeResponse(response); } } DpsClient(final String dpsUrl, final String username, final String password,
final int connectTimeoutInMillis, final int readTimeoutInMillis); DpsClient(final String dpsUrl, final String username, final String password); DpsClient(final String dpsUrl, final int connectTimeoutInMillis,
final int readTimeoutInMillis); DpsClient(final String dpsUrl); long submitTask(DpsTask task, String topologyName); void cleanMetisIndexingDataset(String topologyName, long taskId,
DataSetCleanerParameters dataSetCleanerParameters); void cleanMetisIndexingDataset(String topologyName, long taskId,
DataSetCleanerParameters dataSetCleanerParameters, String key, String value); Response.StatusType topologyPermit(String topologyName, String username); TaskInfo getTaskProgress(String topologyName, final long taskId); List<SubTaskInfo> getDetailedTaskReport(final String topologyName, final long taskId); List<SubTaskInfo> getDetailedTaskReportBetweenChunks(final String topologyName,
final long taskId, int from, int to); List<NodeReport> getElementReport(final String topologyName, final long taskId,
String elementPath); TaskErrorsInfo getTaskErrorsReport(final String topologyName, final long taskId,
final String error, final int idsCount); boolean checkIfErrorReportExists(final String topologyName, final long taskId); StatisticsReport getTaskStatisticsReport(final String topologyName, final long taskId); String killTask(final String topologyName, final long taskId, String info); void close(); } |
@Test @Betamax(tape = "DPSClient_shouldCleanIndexingDataSet") public void shouldCleanIndexingDataSet() throws DpsException { DpsClient dpsClient = new DpsClient(BASE_URL, REGULAR_USER_NAME, REGULAR_USER_PASSWORD); dpsClient.cleanMetisIndexingDataset(TOPOLOGY_NAME, TASK_ID, new DataSetCleanerParameters()); } | public void cleanMetisIndexingDataset(String topologyName, long taskId, DataSetCleanerParameters dataSetCleanerParameters) throws DpsException { Response resp = null; try { resp = client.target(dpsUrl) .path(TASK_CLEAN_DATASET_URL) .resolveTemplate(TOPOLOGY_NAME, topologyName) .resolveTemplate(TASK_ID, taskId) .request() .post(Entity.json(dataSetCleanerParameters)); if (resp.getStatus() != Response.Status.OK.getStatusCode()) { LOGGER.error("Cleaning a dataset was not successful"); throw handleException(resp); } } finally { closeResponse(resp); } } | DpsClient { public void cleanMetisIndexingDataset(String topologyName, long taskId, DataSetCleanerParameters dataSetCleanerParameters) throws DpsException { Response resp = null; try { resp = client.target(dpsUrl) .path(TASK_CLEAN_DATASET_URL) .resolveTemplate(TOPOLOGY_NAME, topologyName) .resolveTemplate(TASK_ID, taskId) .request() .post(Entity.json(dataSetCleanerParameters)); if (resp.getStatus() != Response.Status.OK.getStatusCode()) { LOGGER.error("Cleaning a dataset was not successful"); throw handleException(resp); } } finally { closeResponse(resp); } } } | DpsClient { public void cleanMetisIndexingDataset(String topologyName, long taskId, DataSetCleanerParameters dataSetCleanerParameters) throws DpsException { Response resp = null; try { resp = client.target(dpsUrl) .path(TASK_CLEAN_DATASET_URL) .resolveTemplate(TOPOLOGY_NAME, topologyName) .resolveTemplate(TASK_ID, taskId) .request() .post(Entity.json(dataSetCleanerParameters)); if (resp.getStatus() != Response.Status.OK.getStatusCode()) { LOGGER.error("Cleaning a dataset was not successful"); throw handleException(resp); } } finally { closeResponse(resp); } } DpsClient(final String dpsUrl, final String username, final String password,
final int connectTimeoutInMillis, final int readTimeoutInMillis); DpsClient(final String dpsUrl, final String username, final String password); DpsClient(final String dpsUrl, final int connectTimeoutInMillis,
final int readTimeoutInMillis); DpsClient(final String dpsUrl); } | DpsClient { public void cleanMetisIndexingDataset(String topologyName, long taskId, DataSetCleanerParameters dataSetCleanerParameters) throws DpsException { Response resp = null; try { resp = client.target(dpsUrl) .path(TASK_CLEAN_DATASET_URL) .resolveTemplate(TOPOLOGY_NAME, topologyName) .resolveTemplate(TASK_ID, taskId) .request() .post(Entity.json(dataSetCleanerParameters)); if (resp.getStatus() != Response.Status.OK.getStatusCode()) { LOGGER.error("Cleaning a dataset was not successful"); throw handleException(resp); } } finally { closeResponse(resp); } } DpsClient(final String dpsUrl, final String username, final String password,
final int connectTimeoutInMillis, final int readTimeoutInMillis); DpsClient(final String dpsUrl, final String username, final String password); DpsClient(final String dpsUrl, final int connectTimeoutInMillis,
final int readTimeoutInMillis); DpsClient(final String dpsUrl); long submitTask(DpsTask task, String topologyName); void cleanMetisIndexingDataset(String topologyName, long taskId,
DataSetCleanerParameters dataSetCleanerParameters); void cleanMetisIndexingDataset(String topologyName, long taskId,
DataSetCleanerParameters dataSetCleanerParameters, String key, String value); Response.StatusType topologyPermit(String topologyName, String username); TaskInfo getTaskProgress(String topologyName, final long taskId); List<SubTaskInfo> getDetailedTaskReport(final String topologyName, final long taskId); List<SubTaskInfo> getDetailedTaskReportBetweenChunks(final String topologyName,
final long taskId, int from, int to); List<NodeReport> getElementReport(final String topologyName, final long taskId,
String elementPath); TaskErrorsInfo getTaskErrorsReport(final String topologyName, final long taskId,
final String error, final int idsCount); boolean checkIfErrorReportExists(final String topologyName, final long taskId); StatisticsReport getTaskStatisticsReport(final String topologyName, final long taskId); String killTask(final String topologyName, final long taskId, String info); void close(); } | DpsClient { public void cleanMetisIndexingDataset(String topologyName, long taskId, DataSetCleanerParameters dataSetCleanerParameters) throws DpsException { Response resp = null; try { resp = client.target(dpsUrl) .path(TASK_CLEAN_DATASET_URL) .resolveTemplate(TOPOLOGY_NAME, topologyName) .resolveTemplate(TASK_ID, taskId) .request() .post(Entity.json(dataSetCleanerParameters)); if (resp.getStatus() != Response.Status.OK.getStatusCode()) { LOGGER.error("Cleaning a dataset was not successful"); throw handleException(resp); } } finally { closeResponse(resp); } } DpsClient(final String dpsUrl, final String username, final String password,
final int connectTimeoutInMillis, final int readTimeoutInMillis); DpsClient(final String dpsUrl, final String username, final String password); DpsClient(final String dpsUrl, final int connectTimeoutInMillis,
final int readTimeoutInMillis); DpsClient(final String dpsUrl); long submitTask(DpsTask task, String topologyName); void cleanMetisIndexingDataset(String topologyName, long taskId,
DataSetCleanerParameters dataSetCleanerParameters); void cleanMetisIndexingDataset(String topologyName, long taskId,
DataSetCleanerParameters dataSetCleanerParameters, String key, String value); Response.StatusType topologyPermit(String topologyName, String username); TaskInfo getTaskProgress(String topologyName, final long taskId); List<SubTaskInfo> getDetailedTaskReport(final String topologyName, final long taskId); List<SubTaskInfo> getDetailedTaskReportBetweenChunks(final String topologyName,
final long taskId, int from, int to); List<NodeReport> getElementReport(final String topologyName, final long taskId,
String elementPath); TaskErrorsInfo getTaskErrorsReport(final String topologyName, final long taskId,
final String error, final int idsCount); boolean checkIfErrorReportExists(final String topologyName, final long taskId); StatisticsReport getTaskStatisticsReport(final String topologyName, final long taskId); String killTask(final String topologyName, final long taskId, String info); void close(); } |
@Test(expected = AccessDeniedOrObjectDoesNotExistException.class) @Betamax(tape = "DPSClient_shouldThrowAccessDeniedWhenTaskIdDoesNotExistOrUnAccessible") public void shouldThrowAccessDeniedWhenTaskIdDoesNotExistOrUnAccessible() throws DpsException { DpsClient dpsClient = new DpsClient(BASE_URL, REGULAR_USER_NAME, REGULAR_USER_PASSWORD); long missingTaskId = 111; dpsClient.cleanMetisIndexingDataset(TOPOLOGY_NAME, missingTaskId, new DataSetCleanerParameters()); } | public void cleanMetisIndexingDataset(String topologyName, long taskId, DataSetCleanerParameters dataSetCleanerParameters) throws DpsException { Response resp = null; try { resp = client.target(dpsUrl) .path(TASK_CLEAN_DATASET_URL) .resolveTemplate(TOPOLOGY_NAME, topologyName) .resolveTemplate(TASK_ID, taskId) .request() .post(Entity.json(dataSetCleanerParameters)); if (resp.getStatus() != Response.Status.OK.getStatusCode()) { LOGGER.error("Cleaning a dataset was not successful"); throw handleException(resp); } } finally { closeResponse(resp); } } | DpsClient { public void cleanMetisIndexingDataset(String topologyName, long taskId, DataSetCleanerParameters dataSetCleanerParameters) throws DpsException { Response resp = null; try { resp = client.target(dpsUrl) .path(TASK_CLEAN_DATASET_URL) .resolveTemplate(TOPOLOGY_NAME, topologyName) .resolveTemplate(TASK_ID, taskId) .request() .post(Entity.json(dataSetCleanerParameters)); if (resp.getStatus() != Response.Status.OK.getStatusCode()) { LOGGER.error("Cleaning a dataset was not successful"); throw handleException(resp); } } finally { closeResponse(resp); } } } | DpsClient { public void cleanMetisIndexingDataset(String topologyName, long taskId, DataSetCleanerParameters dataSetCleanerParameters) throws DpsException { Response resp = null; try { resp = client.target(dpsUrl) .path(TASK_CLEAN_DATASET_URL) .resolveTemplate(TOPOLOGY_NAME, topologyName) .resolveTemplate(TASK_ID, taskId) .request() .post(Entity.json(dataSetCleanerParameters)); if (resp.getStatus() != Response.Status.OK.getStatusCode()) { LOGGER.error("Cleaning a dataset was not successful"); throw handleException(resp); } } finally { closeResponse(resp); } } DpsClient(final String dpsUrl, final String username, final String password,
final int connectTimeoutInMillis, final int readTimeoutInMillis); DpsClient(final String dpsUrl, final String username, final String password); DpsClient(final String dpsUrl, final int connectTimeoutInMillis,
final int readTimeoutInMillis); DpsClient(final String dpsUrl); } | DpsClient { public void cleanMetisIndexingDataset(String topologyName, long taskId, DataSetCleanerParameters dataSetCleanerParameters) throws DpsException { Response resp = null; try { resp = client.target(dpsUrl) .path(TASK_CLEAN_DATASET_URL) .resolveTemplate(TOPOLOGY_NAME, topologyName) .resolveTemplate(TASK_ID, taskId) .request() .post(Entity.json(dataSetCleanerParameters)); if (resp.getStatus() != Response.Status.OK.getStatusCode()) { LOGGER.error("Cleaning a dataset was not successful"); throw handleException(resp); } } finally { closeResponse(resp); } } DpsClient(final String dpsUrl, final String username, final String password,
final int connectTimeoutInMillis, final int readTimeoutInMillis); DpsClient(final String dpsUrl, final String username, final String password); DpsClient(final String dpsUrl, final int connectTimeoutInMillis,
final int readTimeoutInMillis); DpsClient(final String dpsUrl); long submitTask(DpsTask task, String topologyName); void cleanMetisIndexingDataset(String topologyName, long taskId,
DataSetCleanerParameters dataSetCleanerParameters); void cleanMetisIndexingDataset(String topologyName, long taskId,
DataSetCleanerParameters dataSetCleanerParameters, String key, String value); Response.StatusType topologyPermit(String topologyName, String username); TaskInfo getTaskProgress(String topologyName, final long taskId); List<SubTaskInfo> getDetailedTaskReport(final String topologyName, final long taskId); List<SubTaskInfo> getDetailedTaskReportBetweenChunks(final String topologyName,
final long taskId, int from, int to); List<NodeReport> getElementReport(final String topologyName, final long taskId,
String elementPath); TaskErrorsInfo getTaskErrorsReport(final String topologyName, final long taskId,
final String error, final int idsCount); boolean checkIfErrorReportExists(final String topologyName, final long taskId); StatisticsReport getTaskStatisticsReport(final String topologyName, final long taskId); String killTask(final String topologyName, final long taskId, String info); void close(); } | DpsClient { public void cleanMetisIndexingDataset(String topologyName, long taskId, DataSetCleanerParameters dataSetCleanerParameters) throws DpsException { Response resp = null; try { resp = client.target(dpsUrl) .path(TASK_CLEAN_DATASET_URL) .resolveTemplate(TOPOLOGY_NAME, topologyName) .resolveTemplate(TASK_ID, taskId) .request() .post(Entity.json(dataSetCleanerParameters)); if (resp.getStatus() != Response.Status.OK.getStatusCode()) { LOGGER.error("Cleaning a dataset was not successful"); throw handleException(resp); } } finally { closeResponse(resp); } } DpsClient(final String dpsUrl, final String username, final String password,
final int connectTimeoutInMillis, final int readTimeoutInMillis); DpsClient(final String dpsUrl, final String username, final String password); DpsClient(final String dpsUrl, final int connectTimeoutInMillis,
final int readTimeoutInMillis); DpsClient(final String dpsUrl); long submitTask(DpsTask task, String topologyName); void cleanMetisIndexingDataset(String topologyName, long taskId,
DataSetCleanerParameters dataSetCleanerParameters); void cleanMetisIndexingDataset(String topologyName, long taskId,
DataSetCleanerParameters dataSetCleanerParameters, String key, String value); Response.StatusType topologyPermit(String topologyName, String username); TaskInfo getTaskProgress(String topologyName, final long taskId); List<SubTaskInfo> getDetailedTaskReport(final String topologyName, final long taskId); List<SubTaskInfo> getDetailedTaskReportBetweenChunks(final String topologyName,
final long taskId, int from, int to); List<NodeReport> getElementReport(final String topologyName, final long taskId,
String elementPath); TaskErrorsInfo getTaskErrorsReport(final String topologyName, final long taskId,
final String error, final int idsCount); boolean checkIfErrorReportExists(final String topologyName, final long taskId); StatisticsReport getTaskStatisticsReport(final String topologyName, final long taskId); String killTask(final String topologyName, final long taskId, String info); void close(); } |
@Test(expected = AccessDeniedOrObjectDoesNotExistException.class) @Betamax(tape = "DPSClient_shouldThrowAccessDeniedWhenTopologyDoesNotExist") public void shouldThrowAccessDeniedWhenTopologyDoesNotExist() throws DpsException { DpsClient dpsClient = new DpsClient(BASE_URL, REGULAR_USER_NAME, REGULAR_USER_PASSWORD); String wrongTopologyName = "wrongTopology"; dpsClient.cleanMetisIndexingDataset(wrongTopologyName, TASK_ID, new DataSetCleanerParameters()); } | public void cleanMetisIndexingDataset(String topologyName, long taskId, DataSetCleanerParameters dataSetCleanerParameters) throws DpsException { Response resp = null; try { resp = client.target(dpsUrl) .path(TASK_CLEAN_DATASET_URL) .resolveTemplate(TOPOLOGY_NAME, topologyName) .resolveTemplate(TASK_ID, taskId) .request() .post(Entity.json(dataSetCleanerParameters)); if (resp.getStatus() != Response.Status.OK.getStatusCode()) { LOGGER.error("Cleaning a dataset was not successful"); throw handleException(resp); } } finally { closeResponse(resp); } } | DpsClient { public void cleanMetisIndexingDataset(String topologyName, long taskId, DataSetCleanerParameters dataSetCleanerParameters) throws DpsException { Response resp = null; try { resp = client.target(dpsUrl) .path(TASK_CLEAN_DATASET_URL) .resolveTemplate(TOPOLOGY_NAME, topologyName) .resolveTemplate(TASK_ID, taskId) .request() .post(Entity.json(dataSetCleanerParameters)); if (resp.getStatus() != Response.Status.OK.getStatusCode()) { LOGGER.error("Cleaning a dataset was not successful"); throw handleException(resp); } } finally { closeResponse(resp); } } } | DpsClient { public void cleanMetisIndexingDataset(String topologyName, long taskId, DataSetCleanerParameters dataSetCleanerParameters) throws DpsException { Response resp = null; try { resp = client.target(dpsUrl) .path(TASK_CLEAN_DATASET_URL) .resolveTemplate(TOPOLOGY_NAME, topologyName) .resolveTemplate(TASK_ID, taskId) .request() .post(Entity.json(dataSetCleanerParameters)); if (resp.getStatus() != Response.Status.OK.getStatusCode()) { LOGGER.error("Cleaning a dataset was not successful"); throw handleException(resp); } } finally { closeResponse(resp); } } DpsClient(final String dpsUrl, final String username, final String password,
final int connectTimeoutInMillis, final int readTimeoutInMillis); DpsClient(final String dpsUrl, final String username, final String password); DpsClient(final String dpsUrl, final int connectTimeoutInMillis,
final int readTimeoutInMillis); DpsClient(final String dpsUrl); } | DpsClient { public void cleanMetisIndexingDataset(String topologyName, long taskId, DataSetCleanerParameters dataSetCleanerParameters) throws DpsException { Response resp = null; try { resp = client.target(dpsUrl) .path(TASK_CLEAN_DATASET_URL) .resolveTemplate(TOPOLOGY_NAME, topologyName) .resolveTemplate(TASK_ID, taskId) .request() .post(Entity.json(dataSetCleanerParameters)); if (resp.getStatus() != Response.Status.OK.getStatusCode()) { LOGGER.error("Cleaning a dataset was not successful"); throw handleException(resp); } } finally { closeResponse(resp); } } DpsClient(final String dpsUrl, final String username, final String password,
final int connectTimeoutInMillis, final int readTimeoutInMillis); DpsClient(final String dpsUrl, final String username, final String password); DpsClient(final String dpsUrl, final int connectTimeoutInMillis,
final int readTimeoutInMillis); DpsClient(final String dpsUrl); long submitTask(DpsTask task, String topologyName); void cleanMetisIndexingDataset(String topologyName, long taskId,
DataSetCleanerParameters dataSetCleanerParameters); void cleanMetisIndexingDataset(String topologyName, long taskId,
DataSetCleanerParameters dataSetCleanerParameters, String key, String value); Response.StatusType topologyPermit(String topologyName, String username); TaskInfo getTaskProgress(String topologyName, final long taskId); List<SubTaskInfo> getDetailedTaskReport(final String topologyName, final long taskId); List<SubTaskInfo> getDetailedTaskReportBetweenChunks(final String topologyName,
final long taskId, int from, int to); List<NodeReport> getElementReport(final String topologyName, final long taskId,
String elementPath); TaskErrorsInfo getTaskErrorsReport(final String topologyName, final long taskId,
final String error, final int idsCount); boolean checkIfErrorReportExists(final String topologyName, final long taskId); StatisticsReport getTaskStatisticsReport(final String topologyName, final long taskId); String killTask(final String topologyName, final long taskId, String info); void close(); } | DpsClient { public void cleanMetisIndexingDataset(String topologyName, long taskId, DataSetCleanerParameters dataSetCleanerParameters) throws DpsException { Response resp = null; try { resp = client.target(dpsUrl) .path(TASK_CLEAN_DATASET_URL) .resolveTemplate(TOPOLOGY_NAME, topologyName) .resolveTemplate(TASK_ID, taskId) .request() .post(Entity.json(dataSetCleanerParameters)); if (resp.getStatus() != Response.Status.OK.getStatusCode()) { LOGGER.error("Cleaning a dataset was not successful"); throw handleException(resp); } } finally { closeResponse(resp); } } DpsClient(final String dpsUrl, final String username, final String password,
final int connectTimeoutInMillis, final int readTimeoutInMillis); DpsClient(final String dpsUrl, final String username, final String password); DpsClient(final String dpsUrl, final int connectTimeoutInMillis,
final int readTimeoutInMillis); DpsClient(final String dpsUrl); long submitTask(DpsTask task, String topologyName); void cleanMetisIndexingDataset(String topologyName, long taskId,
DataSetCleanerParameters dataSetCleanerParameters); void cleanMetisIndexingDataset(String topologyName, long taskId,
DataSetCleanerParameters dataSetCleanerParameters, String key, String value); Response.StatusType topologyPermit(String topologyName, String username); TaskInfo getTaskProgress(String topologyName, final long taskId); List<SubTaskInfo> getDetailedTaskReport(final String topologyName, final long taskId); List<SubTaskInfo> getDetailedTaskReportBetweenChunks(final String topologyName,
final long taskId, int from, int to); List<NodeReport> getElementReport(final String topologyName, final long taskId,
String elementPath); TaskErrorsInfo getTaskErrorsReport(final String topologyName, final long taskId,
final String error, final int idsCount); boolean checkIfErrorReportExists(final String topologyName, final long taskId); StatisticsReport getTaskStatisticsReport(final String topologyName, final long taskId); String killTask(final String topologyName, final long taskId, String info); void close(); } |
@Test public void shouldFilterOaiDcResponse() throws IOException, HarvesterException { final String fileContent = WiremockHelper.getFileContent("/sampleOaiRecord.xml"); final InputStream inputStream = IOUtils.toInputStream(fileContent, ENCODING); String content = IOUtils.toString(inputStream, ENCODING); final InputStream result = new XmlXPath(content).xpathToStream(expr); final String actual = TestHelper.convertToString(result); assertThat(actual, TestHelper.isSimilarXml(WiremockHelper.getFileContent("/expectedOaiRecord.xml"))); } | InputStream xpathToStream(XPathExpression expr) throws HarvesterException { try { final InputSource inputSource = getInputSource(); final ArrayList<NodeInfo> result = (ArrayList<NodeInfo>) expr.evaluate(inputSource, XPathConstants.NODESET); return convertToStream(result); } catch (XPathExpressionException | TransformerException e) { throw new HarvesterException("Cannot xpath XML!", e); } } | XmlXPath { InputStream xpathToStream(XPathExpression expr) throws HarvesterException { try { final InputSource inputSource = getInputSource(); final ArrayList<NodeInfo> result = (ArrayList<NodeInfo>) expr.evaluate(inputSource, XPathConstants.NODESET); return convertToStream(result); } catch (XPathExpressionException | TransformerException e) { throw new HarvesterException("Cannot xpath XML!", e); } } } | XmlXPath { InputStream xpathToStream(XPathExpression expr) throws HarvesterException { try { final InputSource inputSource = getInputSource(); final ArrayList<NodeInfo> result = (ArrayList<NodeInfo>) expr.evaluate(inputSource, XPathConstants.NODESET); return convertToStream(result); } catch (XPathExpressionException | TransformerException e) { throw new HarvesterException("Cannot xpath XML!", e); } } XmlXPath(String input); } | XmlXPath { InputStream xpathToStream(XPathExpression expr) throws HarvesterException { try { final InputSource inputSource = getInputSource(); final ArrayList<NodeInfo> result = (ArrayList<NodeInfo>) expr.evaluate(inputSource, XPathConstants.NODESET); return convertToStream(result); } catch (XPathExpressionException | TransformerException e) { throw new HarvesterException("Cannot xpath XML!", e); } } XmlXPath(String input); } | XmlXPath { InputStream xpathToStream(XPathExpression expr) throws HarvesterException { try { final InputSource inputSource = getInputSource(); final ArrayList<NodeInfo> result = (ArrayList<NodeInfo>) expr.evaluate(inputSource, XPathConstants.NODESET); return convertToStream(result); } catch (XPathExpressionException | TransformerException e) { throw new HarvesterException("Cannot xpath XML!", e); } } XmlXPath(String input); } |
@Test public void getPrimaryKeysFromSourceTableTest() { ResultSet resultSet = mock(ResultSet.class); when(session.execute(boundStatement)).thenReturn(resultSet); assertThat(CassandraHelper.getPrimaryKeysFromSourceTable(cassandraConnectionProvider, "table", primaryKeys), is(resultSet)); } | public static ResultSet getPrimaryKeysFromSourceTable(CassandraConnectionProvider cassandraConnectionProvider, String sourceTableName, List<String> primaryKeys) { String selectPrimaryKeysFromSourceTable = CQLBuilder.constructSelectPrimaryKeysFromSourceTable(sourceTableName, primaryKeys); PreparedStatement sourceSelectStatement = cassandraConnectionProvider.getSession().prepare(selectPrimaryKeysFromSourceTable); sourceSelectStatement.setConsistencyLevel(cassandraConnectionProvider.getConsistencyLevel()); BoundStatement boundStatement = sourceSelectStatement.bind(); return cassandraConnectionProvider.getSession().execute(boundStatement); } | CassandraHelper { public static ResultSet getPrimaryKeysFromSourceTable(CassandraConnectionProvider cassandraConnectionProvider, String sourceTableName, List<String> primaryKeys) { String selectPrimaryKeysFromSourceTable = CQLBuilder.constructSelectPrimaryKeysFromSourceTable(sourceTableName, primaryKeys); PreparedStatement sourceSelectStatement = cassandraConnectionProvider.getSession().prepare(selectPrimaryKeysFromSourceTable); sourceSelectStatement.setConsistencyLevel(cassandraConnectionProvider.getConsistencyLevel()); BoundStatement boundStatement = sourceSelectStatement.bind(); return cassandraConnectionProvider.getSession().execute(boundStatement); } } | CassandraHelper { public static ResultSet getPrimaryKeysFromSourceTable(CassandraConnectionProvider cassandraConnectionProvider, String sourceTableName, List<String> primaryKeys) { String selectPrimaryKeysFromSourceTable = CQLBuilder.constructSelectPrimaryKeysFromSourceTable(sourceTableName, primaryKeys); PreparedStatement sourceSelectStatement = cassandraConnectionProvider.getSession().prepare(selectPrimaryKeysFromSourceTable); sourceSelectStatement.setConsistencyLevel(cassandraConnectionProvider.getConsistencyLevel()); BoundStatement boundStatement = sourceSelectStatement.bind(); return cassandraConnectionProvider.getSession().execute(boundStatement); } } | CassandraHelper { public static ResultSet getPrimaryKeysFromSourceTable(CassandraConnectionProvider cassandraConnectionProvider, String sourceTableName, List<String> primaryKeys) { String selectPrimaryKeysFromSourceTable = CQLBuilder.constructSelectPrimaryKeysFromSourceTable(sourceTableName, primaryKeys); PreparedStatement sourceSelectStatement = cassandraConnectionProvider.getSession().prepare(selectPrimaryKeysFromSourceTable); sourceSelectStatement.setConsistencyLevel(cassandraConnectionProvider.getConsistencyLevel()); BoundStatement boundStatement = sourceSelectStatement.bind(); return cassandraConnectionProvider.getSession().execute(boundStatement); } static BoundStatement prepareBoundStatementForMatchingTargetTable(CassandraConnectionProvider cassandraConnectionProvider, String targetTableName, List<String> primaryKeys); static ResultSet getPrimaryKeysFromSourceTable(CassandraConnectionProvider cassandraConnectionProvider, String sourceTableName, List<String> primaryKeys); static List<String> getPrimaryKeysNames(CassandraConnectionProvider cassandraConnectionProvider, String tableName, String selectColumnNames); } | CassandraHelper { public static ResultSet getPrimaryKeysFromSourceTable(CassandraConnectionProvider cassandraConnectionProvider, String sourceTableName, List<String> primaryKeys) { String selectPrimaryKeysFromSourceTable = CQLBuilder.constructSelectPrimaryKeysFromSourceTable(sourceTableName, primaryKeys); PreparedStatement sourceSelectStatement = cassandraConnectionProvider.getSession().prepare(selectPrimaryKeysFromSourceTable); sourceSelectStatement.setConsistencyLevel(cassandraConnectionProvider.getConsistencyLevel()); BoundStatement boundStatement = sourceSelectStatement.bind(); return cassandraConnectionProvider.getSession().execute(boundStatement); } static BoundStatement prepareBoundStatementForMatchingTargetTable(CassandraConnectionProvider cassandraConnectionProvider, String targetTableName, List<String> primaryKeys); static ResultSet getPrimaryKeysFromSourceTable(CassandraConnectionProvider cassandraConnectionProvider, String sourceTableName, List<String> primaryKeys); static List<String> getPrimaryKeysNames(CassandraConnectionProvider cassandraConnectionProvider, String tableName, String selectColumnNames); } |
@Test public void shouldReturnRecordIsDeleted() throws IOException, HarvesterException { final String fileContent = WiremockHelper.getFileContent("/deletedOaiRecord.xml"); final InputStream inputStream = IOUtils.toInputStream(fileContent, ENCODING); String content = IOUtils.toString(inputStream, ENCODING); assertEquals("deleted", new XmlXPath(content).xpathToString(isDeletedExpression)); } | String xpathToString(XPathExpression expr) throws HarvesterException { try { return evaluateExpression(expr); } catch (XPathExpressionException e) { throw new HarvesterException("Cannot xpath XML!", e); } } | XmlXPath { String xpathToString(XPathExpression expr) throws HarvesterException { try { return evaluateExpression(expr); } catch (XPathExpressionException e) { throw new HarvesterException("Cannot xpath XML!", e); } } } | XmlXPath { String xpathToString(XPathExpression expr) throws HarvesterException { try { return evaluateExpression(expr); } catch (XPathExpressionException e) { throw new HarvesterException("Cannot xpath XML!", e); } } XmlXPath(String input); } | XmlXPath { String xpathToString(XPathExpression expr) throws HarvesterException { try { return evaluateExpression(expr); } catch (XPathExpressionException e) { throw new HarvesterException("Cannot xpath XML!", e); } } XmlXPath(String input); } | XmlXPath { String xpathToString(XPathExpression expr) throws HarvesterException { try { return evaluateExpression(expr); } catch (XPathExpressionException e) { throw new HarvesterException("Cannot xpath XML!", e); } } XmlXPath(String input); } |
@Test public void shouldReturnRecordIsNotDeleted() throws IOException, HarvesterException { final String fileContent = WiremockHelper.getFileContent("/sampleOaiRecord.xml"); final InputStream inputStream = IOUtils.toInputStream(fileContent, ENCODING); String content = IOUtils.toString(inputStream, ENCODING); assertFalse("deleted".equalsIgnoreCase(new XmlXPath(content).xpathToString(isDeletedExpression))); } | String xpathToString(XPathExpression expr) throws HarvesterException { try { return evaluateExpression(expr); } catch (XPathExpressionException e) { throw new HarvesterException("Cannot xpath XML!", e); } } | XmlXPath { String xpathToString(XPathExpression expr) throws HarvesterException { try { return evaluateExpression(expr); } catch (XPathExpressionException e) { throw new HarvesterException("Cannot xpath XML!", e); } } } | XmlXPath { String xpathToString(XPathExpression expr) throws HarvesterException { try { return evaluateExpression(expr); } catch (XPathExpressionException e) { throw new HarvesterException("Cannot xpath XML!", e); } } XmlXPath(String input); } | XmlXPath { String xpathToString(XPathExpression expr) throws HarvesterException { try { return evaluateExpression(expr); } catch (XPathExpressionException e) { throw new HarvesterException("Cannot xpath XML!", e); } } XmlXPath(String input); } | XmlXPath { String xpathToString(XPathExpression expr) throws HarvesterException { try { return evaluateExpression(expr); } catch (XPathExpressionException e) { throw new HarvesterException("Cannot xpath XML!", e); } } XmlXPath(String input); } |
@Test public void shouldThrowExceptionNonSingleOutputCandidate() throws IOException, XPathExpressionException { final String fileContent = WiremockHelper.getFileContent("/sampleOaiRecord.xml"); final InputStream inputStream = IOUtils.toInputStream(fileContent, ENCODING); String content = IOUtils.toString(inputStream, ENCODING); try { XPath xpath = new net.sf.saxon.xpath.XPathFactoryImpl().newXPath(); expr = xpath.compile("/some/bad/xpath"); new XmlXPath(content).xpathToStream(expr); fail(); } catch (HarvesterException e) { assertThat(e.getMessage(), is("Empty XML!")); } } | InputStream xpathToStream(XPathExpression expr) throws HarvesterException { try { final InputSource inputSource = getInputSource(); final ArrayList<NodeInfo> result = (ArrayList<NodeInfo>) expr.evaluate(inputSource, XPathConstants.NODESET); return convertToStream(result); } catch (XPathExpressionException | TransformerException e) { throw new HarvesterException("Cannot xpath XML!", e); } } | XmlXPath { InputStream xpathToStream(XPathExpression expr) throws HarvesterException { try { final InputSource inputSource = getInputSource(); final ArrayList<NodeInfo> result = (ArrayList<NodeInfo>) expr.evaluate(inputSource, XPathConstants.NODESET); return convertToStream(result); } catch (XPathExpressionException | TransformerException e) { throw new HarvesterException("Cannot xpath XML!", e); } } } | XmlXPath { InputStream xpathToStream(XPathExpression expr) throws HarvesterException { try { final InputSource inputSource = getInputSource(); final ArrayList<NodeInfo> result = (ArrayList<NodeInfo>) expr.evaluate(inputSource, XPathConstants.NODESET); return convertToStream(result); } catch (XPathExpressionException | TransformerException e) { throw new HarvesterException("Cannot xpath XML!", e); } } XmlXPath(String input); } | XmlXPath { InputStream xpathToStream(XPathExpression expr) throws HarvesterException { try { final InputSource inputSource = getInputSource(); final ArrayList<NodeInfo> result = (ArrayList<NodeInfo>) expr.evaluate(inputSource, XPathConstants.NODESET); return convertToStream(result); } catch (XPathExpressionException | TransformerException e) { throw new HarvesterException("Cannot xpath XML!", e); } } XmlXPath(String input); } | XmlXPath { InputStream xpathToStream(XPathExpression expr) throws HarvesterException { try { final InputSource inputSource = getInputSource(); final ArrayList<NodeInfo> result = (ArrayList<NodeInfo>) expr.evaluate(inputSource, XPathConstants.NODESET); return convertToStream(result); } catch (XPathExpressionException | TransformerException e) { throw new HarvesterException("Cannot xpath XML!", e); } } XmlXPath(String input); } |
@Test public void shouldThrowExceptionOnEmpty() throws IOException { final String fileContent = ""; final InputStream inputStream = IOUtils.toInputStream(fileContent, ENCODING); String content = IOUtils.toString(inputStream, ENCODING); try { new XmlXPath(content).xpathToStream(expr); fail(); } catch (HarvesterException e) { assertThat(e.getMessage(), is("Cannot xpath XML!")); } } | InputStream xpathToStream(XPathExpression expr) throws HarvesterException { try { final InputSource inputSource = getInputSource(); final ArrayList<NodeInfo> result = (ArrayList<NodeInfo>) expr.evaluate(inputSource, XPathConstants.NODESET); return convertToStream(result); } catch (XPathExpressionException | TransformerException e) { throw new HarvesterException("Cannot xpath XML!", e); } } | XmlXPath { InputStream xpathToStream(XPathExpression expr) throws HarvesterException { try { final InputSource inputSource = getInputSource(); final ArrayList<NodeInfo> result = (ArrayList<NodeInfo>) expr.evaluate(inputSource, XPathConstants.NODESET); return convertToStream(result); } catch (XPathExpressionException | TransformerException e) { throw new HarvesterException("Cannot xpath XML!", e); } } } | XmlXPath { InputStream xpathToStream(XPathExpression expr) throws HarvesterException { try { final InputSource inputSource = getInputSource(); final ArrayList<NodeInfo> result = (ArrayList<NodeInfo>) expr.evaluate(inputSource, XPathConstants.NODESET); return convertToStream(result); } catch (XPathExpressionException | TransformerException e) { throw new HarvesterException("Cannot xpath XML!", e); } } XmlXPath(String input); } | XmlXPath { InputStream xpathToStream(XPathExpression expr) throws HarvesterException { try { final InputSource inputSource = getInputSource(); final ArrayList<NodeInfo> result = (ArrayList<NodeInfo>) expr.evaluate(inputSource, XPathConstants.NODESET); return convertToStream(result); } catch (XPathExpressionException | TransformerException e) { throw new HarvesterException("Cannot xpath XML!", e); } } XmlXPath(String input); } | XmlXPath { InputStream xpathToStream(XPathExpression expr) throws HarvesterException { try { final InputSource inputSource = getInputSource(); final ArrayList<NodeInfo> result = (ArrayList<NodeInfo>) expr.evaluate(inputSource, XPathConstants.NODESET); return convertToStream(result); } catch (XPathExpressionException | TransformerException e) { throw new HarvesterException("Cannot xpath XML!", e); } } XmlXPath(String input); } |
@Test public void shouldHarvestRecord() throws IOException, HarvesterException { stubFor(get(urlEqualTo("/oai-phm/?verb=GetRecord&identifier=mediateka" + "&metadataPrefix=oai_dc")) .willReturn(response200XmlContent(getFileContent("/sampleOaiRecord.xml")) )); final HarvesterImpl harvester = new HarvesterImpl(DEFAULT_RETRIES, SLEEP_TIME); final InputStream result = harvester.harvestRecord(OAI_PMH_ENDPOINT, "mediateka", "oai_dc", expr, isDeletedExpression); final String actual = TestHelper.convertToString(result); assertThat(actual, TestHelper.isSimilarXml(getFileContent("/expectedOaiRecord.xml"))); } | @Override public InputStream harvestRecord(String oaiPmhEndpoint, String recordId, String metadataPrefix, XPathExpression expression, XPathExpression statusCheckerExpression) throws HarvesterException { return harvestRecord(DEFAULT_CONNECTION_FACTORY, oaiPmhEndpoint, recordId, metadataPrefix, expression, statusCheckerExpression); } | HarvesterImpl implements Harvester { @Override public InputStream harvestRecord(String oaiPmhEndpoint, String recordId, String metadataPrefix, XPathExpression expression, XPathExpression statusCheckerExpression) throws HarvesterException { return harvestRecord(DEFAULT_CONNECTION_FACTORY, oaiPmhEndpoint, recordId, metadataPrefix, expression, statusCheckerExpression); } } | HarvesterImpl implements Harvester { @Override public InputStream harvestRecord(String oaiPmhEndpoint, String recordId, String metadataPrefix, XPathExpression expression, XPathExpression statusCheckerExpression) throws HarvesterException { return harvestRecord(DEFAULT_CONNECTION_FACTORY, oaiPmhEndpoint, recordId, metadataPrefix, expression, statusCheckerExpression); } HarvesterImpl(int numberOfRetries, int timeBetweenRetries); } | HarvesterImpl implements Harvester { @Override public InputStream harvestRecord(String oaiPmhEndpoint, String recordId, String metadataPrefix, XPathExpression expression, XPathExpression statusCheckerExpression) throws HarvesterException { return harvestRecord(DEFAULT_CONNECTION_FACTORY, oaiPmhEndpoint, recordId, metadataPrefix, expression, statusCheckerExpression); } HarvesterImpl(int numberOfRetries, int timeBetweenRetries); @Override InputStream harvestRecord(String oaiPmhEndpoint, String recordId, String metadataPrefix,
XPathExpression expression, XPathExpression statusCheckerExpression); @Override Iterator<OAIHeader> harvestIdentifiers(Harvest harvest); } | HarvesterImpl implements Harvester { @Override public InputStream harvestRecord(String oaiPmhEndpoint, String recordId, String metadataPrefix, XPathExpression expression, XPathExpression statusCheckerExpression) throws HarvesterException { return harvestRecord(DEFAULT_CONNECTION_FACTORY, oaiPmhEndpoint, recordId, metadataPrefix, expression, statusCheckerExpression); } HarvesterImpl(int numberOfRetries, int timeBetweenRetries); @Override InputStream harvestRecord(String oaiPmhEndpoint, String recordId, String metadataPrefix,
XPathExpression expression, XPathExpression statusCheckerExpression); @Override Iterator<OAIHeader> harvestIdentifiers(Harvest harvest); } |
@Test(expected = HarvesterException.class) public void shouldHandleDeletedRecords() throws IOException, HarvesterException { stubFor(get(urlEqualTo("/oai-phm/?verb=GetRecord&identifier=mediateka" + "&metadataPrefix=oai_dc")) .willReturn(response200XmlContent(getFileContent("/deletedOaiRecord.xml")) )); final HarvesterImpl harvester = new HarvesterImpl(DEFAULT_RETRIES, SLEEP_TIME); harvester.harvestRecord(OAI_PMH_ENDPOINT, "mediateka", "oai_dc", expr, isDeletedExpression); } | @Override public InputStream harvestRecord(String oaiPmhEndpoint, String recordId, String metadataPrefix, XPathExpression expression, XPathExpression statusCheckerExpression) throws HarvesterException { return harvestRecord(DEFAULT_CONNECTION_FACTORY, oaiPmhEndpoint, recordId, metadataPrefix, expression, statusCheckerExpression); } | HarvesterImpl implements Harvester { @Override public InputStream harvestRecord(String oaiPmhEndpoint, String recordId, String metadataPrefix, XPathExpression expression, XPathExpression statusCheckerExpression) throws HarvesterException { return harvestRecord(DEFAULT_CONNECTION_FACTORY, oaiPmhEndpoint, recordId, metadataPrefix, expression, statusCheckerExpression); } } | HarvesterImpl implements Harvester { @Override public InputStream harvestRecord(String oaiPmhEndpoint, String recordId, String metadataPrefix, XPathExpression expression, XPathExpression statusCheckerExpression) throws HarvesterException { return harvestRecord(DEFAULT_CONNECTION_FACTORY, oaiPmhEndpoint, recordId, metadataPrefix, expression, statusCheckerExpression); } HarvesterImpl(int numberOfRetries, int timeBetweenRetries); } | HarvesterImpl implements Harvester { @Override public InputStream harvestRecord(String oaiPmhEndpoint, String recordId, String metadataPrefix, XPathExpression expression, XPathExpression statusCheckerExpression) throws HarvesterException { return harvestRecord(DEFAULT_CONNECTION_FACTORY, oaiPmhEndpoint, recordId, metadataPrefix, expression, statusCheckerExpression); } HarvesterImpl(int numberOfRetries, int timeBetweenRetries); @Override InputStream harvestRecord(String oaiPmhEndpoint, String recordId, String metadataPrefix,
XPathExpression expression, XPathExpression statusCheckerExpression); @Override Iterator<OAIHeader> harvestIdentifiers(Harvest harvest); } | HarvesterImpl implements Harvester { @Override public InputStream harvestRecord(String oaiPmhEndpoint, String recordId, String metadataPrefix, XPathExpression expression, XPathExpression statusCheckerExpression) throws HarvesterException { return harvestRecord(DEFAULT_CONNECTION_FACTORY, oaiPmhEndpoint, recordId, metadataPrefix, expression, statusCheckerExpression); } HarvesterImpl(int numberOfRetries, int timeBetweenRetries); @Override InputStream harvestRecord(String oaiPmhEndpoint, String recordId, String metadataPrefix,
XPathExpression expression, XPathExpression statusCheckerExpression); @Override Iterator<OAIHeader> harvestIdentifiers(Harvest harvest); } |
@Test public void shouldThrowExceptionHarvestedRecordNotFound() { stubFor(get(urlEqualTo("/oai-phm/?verb=GetRecord&identifier=oai%3Amediateka.centrumzamenhofa" + ".pl%3A19&metadataPrefix=oai_dc")) .willReturn(response404())); final HarvesterImpl harvester = new HarvesterImpl(DEFAULT_RETRIES, SLEEP_TIME); try { harvester.harvestRecord(OAI_PMH_ENDPOINT, "oai:mediateka.centrumzamenhofa.pl:19", "oai_dc", expr, isDeletedExpression); fail(); } catch (HarvesterException e) { assertThat(e.getMessage(), is("Problem with harvesting record oai:mediateka.centrumzamenhofa.pl:19 for endpoint http: } } | @Override public InputStream harvestRecord(String oaiPmhEndpoint, String recordId, String metadataPrefix, XPathExpression expression, XPathExpression statusCheckerExpression) throws HarvesterException { return harvestRecord(DEFAULT_CONNECTION_FACTORY, oaiPmhEndpoint, recordId, metadataPrefix, expression, statusCheckerExpression); } | HarvesterImpl implements Harvester { @Override public InputStream harvestRecord(String oaiPmhEndpoint, String recordId, String metadataPrefix, XPathExpression expression, XPathExpression statusCheckerExpression) throws HarvesterException { return harvestRecord(DEFAULT_CONNECTION_FACTORY, oaiPmhEndpoint, recordId, metadataPrefix, expression, statusCheckerExpression); } } | HarvesterImpl implements Harvester { @Override public InputStream harvestRecord(String oaiPmhEndpoint, String recordId, String metadataPrefix, XPathExpression expression, XPathExpression statusCheckerExpression) throws HarvesterException { return harvestRecord(DEFAULT_CONNECTION_FACTORY, oaiPmhEndpoint, recordId, metadataPrefix, expression, statusCheckerExpression); } HarvesterImpl(int numberOfRetries, int timeBetweenRetries); } | HarvesterImpl implements Harvester { @Override public InputStream harvestRecord(String oaiPmhEndpoint, String recordId, String metadataPrefix, XPathExpression expression, XPathExpression statusCheckerExpression) throws HarvesterException { return harvestRecord(DEFAULT_CONNECTION_FACTORY, oaiPmhEndpoint, recordId, metadataPrefix, expression, statusCheckerExpression); } HarvesterImpl(int numberOfRetries, int timeBetweenRetries); @Override InputStream harvestRecord(String oaiPmhEndpoint, String recordId, String metadataPrefix,
XPathExpression expression, XPathExpression statusCheckerExpression); @Override Iterator<OAIHeader> harvestIdentifiers(Harvest harvest); } | HarvesterImpl implements Harvester { @Override public InputStream harvestRecord(String oaiPmhEndpoint, String recordId, String metadataPrefix, XPathExpression expression, XPathExpression statusCheckerExpression) throws HarvesterException { return harvestRecord(DEFAULT_CONNECTION_FACTORY, oaiPmhEndpoint, recordId, metadataPrefix, expression, statusCheckerExpression); } HarvesterImpl(int numberOfRetries, int timeBetweenRetries); @Override InputStream harvestRecord(String oaiPmhEndpoint, String recordId, String metadataPrefix,
XPathExpression expression, XPathExpression statusCheckerExpression); @Override Iterator<OAIHeader> harvestIdentifiers(Harvest harvest); } |
@Test(expected = HarvesterException.class) public void shouldHandleTimeout() throws IOException, HarvesterException { stubFor(get(urlEqualTo("/oai-phm/?verb=GetRecord&identifier=mediateka" + "&metadataPrefix=oai_dc")) .willReturn(responsTimeoutGreaterThanSocketTimeout(getFileContent("/sampleOaiRecord.xml"), TEST_SOCKET_TIMEOUT) )); final HarvesterImpl.ConnectionFactory connectionFactory = new HarvesterImpl.ConnectionFactory() { @Override public OaiPmhConnection createConnection(String oaiPmhEndpoint, Parameters parameters) { return new OaiPmhConnection(oaiPmhEndpoint, parameters, TEST_SOCKET_TIMEOUT, TEST_SOCKET_TIMEOUT, TEST_SOCKET_TIMEOUT); } }; final HarvesterImpl harvester = new HarvesterImpl(1, SLEEP_TIME); harvester.harvestRecord(connectionFactory, OAI_PMH_ENDPOINT, "mediateka", "oai_dc", expr, isDeletedExpression); } | @Override public InputStream harvestRecord(String oaiPmhEndpoint, String recordId, String metadataPrefix, XPathExpression expression, XPathExpression statusCheckerExpression) throws HarvesterException { return harvestRecord(DEFAULT_CONNECTION_FACTORY, oaiPmhEndpoint, recordId, metadataPrefix, expression, statusCheckerExpression); } | HarvesterImpl implements Harvester { @Override public InputStream harvestRecord(String oaiPmhEndpoint, String recordId, String metadataPrefix, XPathExpression expression, XPathExpression statusCheckerExpression) throws HarvesterException { return harvestRecord(DEFAULT_CONNECTION_FACTORY, oaiPmhEndpoint, recordId, metadataPrefix, expression, statusCheckerExpression); } } | HarvesterImpl implements Harvester { @Override public InputStream harvestRecord(String oaiPmhEndpoint, String recordId, String metadataPrefix, XPathExpression expression, XPathExpression statusCheckerExpression) throws HarvesterException { return harvestRecord(DEFAULT_CONNECTION_FACTORY, oaiPmhEndpoint, recordId, metadataPrefix, expression, statusCheckerExpression); } HarvesterImpl(int numberOfRetries, int timeBetweenRetries); } | HarvesterImpl implements Harvester { @Override public InputStream harvestRecord(String oaiPmhEndpoint, String recordId, String metadataPrefix, XPathExpression expression, XPathExpression statusCheckerExpression) throws HarvesterException { return harvestRecord(DEFAULT_CONNECTION_FACTORY, oaiPmhEndpoint, recordId, metadataPrefix, expression, statusCheckerExpression); } HarvesterImpl(int numberOfRetries, int timeBetweenRetries); @Override InputStream harvestRecord(String oaiPmhEndpoint, String recordId, String metadataPrefix,
XPathExpression expression, XPathExpression statusCheckerExpression); @Override Iterator<OAIHeader> harvestIdentifiers(Harvest harvest); } | HarvesterImpl implements Harvester { @Override public InputStream harvestRecord(String oaiPmhEndpoint, String recordId, String metadataPrefix, XPathExpression expression, XPathExpression statusCheckerExpression) throws HarvesterException { return harvestRecord(DEFAULT_CONNECTION_FACTORY, oaiPmhEndpoint, recordId, metadataPrefix, expression, statusCheckerExpression); } HarvesterImpl(int numberOfRetries, int timeBetweenRetries); @Override InputStream harvestRecord(String oaiPmhEndpoint, String recordId, String metadataPrefix,
XPathExpression expression, XPathExpression statusCheckerExpression); @Override Iterator<OAIHeader> harvestIdentifiers(Harvest harvest); } |
@Test public void should_successfully_getTopologyNames() { List<String> resultNameList = instance.getNames(); List<String> expectedNameList = convertStringToList(nameList); assertThat(resultNameList, is(equalTo(expectedNameList))); } | public List<String> getNames() { return topologies; } | TopologyManager { public List<String> getNames() { return topologies; } } | TopologyManager { public List<String> getNames() { return topologies; } TopologyManager(final String nameList); } | TopologyManager { public List<String> getNames() { return topologies; } TopologyManager(final String nameList); List<String> getNames(); boolean containsTopology(String topologyName); } | TopologyManager { public List<String> getNames() { return topologies; } TopologyManager(final String nameList); List<String> getNames(); boolean containsTopology(String topologyName); static final String separatorChar; static final Logger logger; } |
@Test public void should_successfully_containsTopology1() { final String topologyName = "topologyA"; boolean result = instance.containsTopology(topologyName); assertThat(result, is(equalTo(true))); } | public boolean containsTopology(String topologyName) { return topologies.contains(topologyName); } | TopologyManager { public boolean containsTopology(String topologyName) { return topologies.contains(topologyName); } } | TopologyManager { public boolean containsTopology(String topologyName) { return topologies.contains(topologyName); } TopologyManager(final String nameList); } | TopologyManager { public boolean containsTopology(String topologyName) { return topologies.contains(topologyName); } TopologyManager(final String nameList); List<String> getNames(); boolean containsTopology(String topologyName); } | TopologyManager { public boolean containsTopology(String topologyName) { return topologies.contains(topologyName); } TopologyManager(final String nameList); List<String> getNames(); boolean containsTopology(String topologyName); static final String separatorChar; static final Logger logger; } |
@Test public void getPrimaryKeysNamesTest() { ResultSet resultSet = mock(ResultSet.class); when(preparedStatement.bind(anyString(), anyString())).thenReturn(boundStatement); when(session.execute(boundStatement)).thenReturn(resultSet); Iterator iterator = mock(Iterator.class); when(resultSet.iterator()).thenReturn(iterator); when(iterator.hasNext()).thenReturn(true).thenReturn(true).thenReturn(false); Row row1 = mock(Row.class); Row row2 = mock(Row.class); when(iterator.next()).thenReturn(row1).thenReturn(row2); when(row1.getString(COLUMN_INDEX_TYPE)).thenReturn(CLUSTERING_KEY_TYPE); when(row2.getString(COLUMN_INDEX_TYPE)).thenReturn(CLUSTERING_KEY_TYPE); when(row1.getString(COLUMN_INDEX_TYPE)).thenReturn(PARTITION_KEY_TYPE); when(row2.getString(COLUMN_INDEX_TYPE)).thenReturn(PARTITION_KEY_TYPE); when(row1.getString(COLUMN_NAME_SELECTOR)).thenReturn(primaryKeys.get(0)); when(row2.getString(COLUMN_NAME_SELECTOR)).thenReturn(primaryKeys.get(1)); assertThat(CassandraHelper.getPrimaryKeysNames(cassandraConnectionProvider, "table", "Query String"), is(primaryKeys)); } | public static List<String> getPrimaryKeysNames(CassandraConnectionProvider cassandraConnectionProvider, String tableName, String selectColumnNames) { List<String> names = new LinkedList<>(); PreparedStatement selectStatement = cassandraConnectionProvider.getSession().prepare(selectColumnNames); selectStatement.setConsistencyLevel(cassandraConnectionProvider.getConsistencyLevel()); BoundStatement boundStatement = selectStatement.bind(cassandraConnectionProvider.getKeyspaceName(), tableName); ResultSet rs = cassandraConnectionProvider.getSession().execute(boundStatement); Iterator<Row> iterator = rs.iterator(); while (iterator.hasNext()) { Row row = iterator.next(); if (row.getString(COLUMN_INDEX_TYPE).equals(CLUSTERING_KEY_TYPE) || row.getString(COLUMN_INDEX_TYPE).equals(PARTITION_KEY_TYPE)) names.add(row.getString(COLUMN_NAME_SELECTOR)); } return names; } | CassandraHelper { public static List<String> getPrimaryKeysNames(CassandraConnectionProvider cassandraConnectionProvider, String tableName, String selectColumnNames) { List<String> names = new LinkedList<>(); PreparedStatement selectStatement = cassandraConnectionProvider.getSession().prepare(selectColumnNames); selectStatement.setConsistencyLevel(cassandraConnectionProvider.getConsistencyLevel()); BoundStatement boundStatement = selectStatement.bind(cassandraConnectionProvider.getKeyspaceName(), tableName); ResultSet rs = cassandraConnectionProvider.getSession().execute(boundStatement); Iterator<Row> iterator = rs.iterator(); while (iterator.hasNext()) { Row row = iterator.next(); if (row.getString(COLUMN_INDEX_TYPE).equals(CLUSTERING_KEY_TYPE) || row.getString(COLUMN_INDEX_TYPE).equals(PARTITION_KEY_TYPE)) names.add(row.getString(COLUMN_NAME_SELECTOR)); } return names; } } | CassandraHelper { public static List<String> getPrimaryKeysNames(CassandraConnectionProvider cassandraConnectionProvider, String tableName, String selectColumnNames) { List<String> names = new LinkedList<>(); PreparedStatement selectStatement = cassandraConnectionProvider.getSession().prepare(selectColumnNames); selectStatement.setConsistencyLevel(cassandraConnectionProvider.getConsistencyLevel()); BoundStatement boundStatement = selectStatement.bind(cassandraConnectionProvider.getKeyspaceName(), tableName); ResultSet rs = cassandraConnectionProvider.getSession().execute(boundStatement); Iterator<Row> iterator = rs.iterator(); while (iterator.hasNext()) { Row row = iterator.next(); if (row.getString(COLUMN_INDEX_TYPE).equals(CLUSTERING_KEY_TYPE) || row.getString(COLUMN_INDEX_TYPE).equals(PARTITION_KEY_TYPE)) names.add(row.getString(COLUMN_NAME_SELECTOR)); } return names; } } | CassandraHelper { public static List<String> getPrimaryKeysNames(CassandraConnectionProvider cassandraConnectionProvider, String tableName, String selectColumnNames) { List<String> names = new LinkedList<>(); PreparedStatement selectStatement = cassandraConnectionProvider.getSession().prepare(selectColumnNames); selectStatement.setConsistencyLevel(cassandraConnectionProvider.getConsistencyLevel()); BoundStatement boundStatement = selectStatement.bind(cassandraConnectionProvider.getKeyspaceName(), tableName); ResultSet rs = cassandraConnectionProvider.getSession().execute(boundStatement); Iterator<Row> iterator = rs.iterator(); while (iterator.hasNext()) { Row row = iterator.next(); if (row.getString(COLUMN_INDEX_TYPE).equals(CLUSTERING_KEY_TYPE) || row.getString(COLUMN_INDEX_TYPE).equals(PARTITION_KEY_TYPE)) names.add(row.getString(COLUMN_NAME_SELECTOR)); } return names; } static BoundStatement prepareBoundStatementForMatchingTargetTable(CassandraConnectionProvider cassandraConnectionProvider, String targetTableName, List<String> primaryKeys); static ResultSet getPrimaryKeysFromSourceTable(CassandraConnectionProvider cassandraConnectionProvider, String sourceTableName, List<String> primaryKeys); static List<String> getPrimaryKeysNames(CassandraConnectionProvider cassandraConnectionProvider, String tableName, String selectColumnNames); } | CassandraHelper { public static List<String> getPrimaryKeysNames(CassandraConnectionProvider cassandraConnectionProvider, String tableName, String selectColumnNames) { List<String> names = new LinkedList<>(); PreparedStatement selectStatement = cassandraConnectionProvider.getSession().prepare(selectColumnNames); selectStatement.setConsistencyLevel(cassandraConnectionProvider.getConsistencyLevel()); BoundStatement boundStatement = selectStatement.bind(cassandraConnectionProvider.getKeyspaceName(), tableName); ResultSet rs = cassandraConnectionProvider.getSession().execute(boundStatement); Iterator<Row> iterator = rs.iterator(); while (iterator.hasNext()) { Row row = iterator.next(); if (row.getString(COLUMN_INDEX_TYPE).equals(CLUSTERING_KEY_TYPE) || row.getString(COLUMN_INDEX_TYPE).equals(PARTITION_KEY_TYPE)) names.add(row.getString(COLUMN_NAME_SELECTOR)); } return names; } static BoundStatement prepareBoundStatementForMatchingTargetTable(CassandraConnectionProvider cassandraConnectionProvider, String targetTableName, List<String> primaryKeys); static ResultSet getPrimaryKeysFromSourceTable(CassandraConnectionProvider cassandraConnectionProvider, String sourceTableName, List<String> primaryKeys); static List<String> getPrimaryKeysNames(CassandraConnectionProvider cassandraConnectionProvider, String tableName, String selectColumnNames); } |
@Test public void should_successfully_containsTopology2() { final String topologyName = "topologyB"; boolean result = instance.containsTopology(topologyName); assertThat(result, is(equalTo(true))); } | public boolean containsTopology(String topologyName) { return topologies.contains(topologyName); } | TopologyManager { public boolean containsTopology(String topologyName) { return topologies.contains(topologyName); } } | TopologyManager { public boolean containsTopology(String topologyName) { return topologies.contains(topologyName); } TopologyManager(final String nameList); } | TopologyManager { public boolean containsTopology(String topologyName) { return topologies.contains(topologyName); } TopologyManager(final String nameList); List<String> getNames(); boolean containsTopology(String topologyName); } | TopologyManager { public boolean containsTopology(String topologyName) { return topologies.contains(topologyName); } TopologyManager(final String nameList); List<String> getNames(); boolean containsTopology(String topologyName); static final String separatorChar; static final Logger logger; } |
@Test public void should_unsuccessfully_containsTopology() { final String topologyName = "topologyC"; boolean result = instance.containsTopology(topologyName); assertThat(result, is(equalTo(false))); } | public boolean containsTopology(String topologyName) { return topologies.contains(topologyName); } | TopologyManager { public boolean containsTopology(String topologyName) { return topologies.contains(topologyName); } } | TopologyManager { public boolean containsTopology(String topologyName) { return topologies.contains(topologyName); } TopologyManager(final String nameList); } | TopologyManager { public boolean containsTopology(String topologyName) { return topologies.contains(topologyName); } TopologyManager(final String nameList); List<String> getNames(); boolean containsTopology(String topologyName); } | TopologyManager { public boolean containsTopology(String topologyName) { return topologies.contains(topologyName); } TopologyManager(final String nameList); List<String> getNames(); boolean containsTopology(String topologyName); static final String separatorChar; static final Logger logger; } |
@Test(expected = ProviderNotExistsException.class) public void exceptionShouldBeThrowForNotExistingProviderId() throws RepresentationNotExistsException, ProviderNotExistsException, RecordNotExistsException { representationResource.getRepresentation(null, NOT_EXISTING_PROVIDER_ID, "localID", "repName"); } | @GetMapping @PostAuthorize("hasPermission" + "( " + " (returnObject.cloudId).concat('/').concat(#representationName).concat('/').concat(returnObject.version) ," + " 'eu.europeana.cloud.common.model.Representation', read" + ")") public @ResponseBody Representation getRepresentation( HttpServletRequest httpServletRequest, @PathVariable String providerId, @PathVariable String localId, @PathVariable String representationName) throws RepresentationNotExistsException, ProviderNotExistsException, RecordNotExistsException { LOGGER.info("Reading representation '{}' using 'friendly' approach for providerId: {} and localId: {}", representationName, providerId, localId); final String cloudId = findCloudIdFor(providerId, localId); Representation representation = recordService.getRepresentation(cloudId, representationName); EnrichUriUtil.enrich(httpServletRequest, representation); return representation; } | SimplifiedRepresentationResource { @GetMapping @PostAuthorize("hasPermission" + "( " + " (returnObject.cloudId).concat('/').concat(#representationName).concat('/').concat(returnObject.version) ," + " 'eu.europeana.cloud.common.model.Representation', read" + ")") public @ResponseBody Representation getRepresentation( HttpServletRequest httpServletRequest, @PathVariable String providerId, @PathVariable String localId, @PathVariable String representationName) throws RepresentationNotExistsException, ProviderNotExistsException, RecordNotExistsException { LOGGER.info("Reading representation '{}' using 'friendly' approach for providerId: {} and localId: {}", representationName, providerId, localId); final String cloudId = findCloudIdFor(providerId, localId); Representation representation = recordService.getRepresentation(cloudId, representationName); EnrichUriUtil.enrich(httpServletRequest, representation); return representation; } } | SimplifiedRepresentationResource { @GetMapping @PostAuthorize("hasPermission" + "( " + " (returnObject.cloudId).concat('/').concat(#representationName).concat('/').concat(returnObject.version) ," + " 'eu.europeana.cloud.common.model.Representation', read" + ")") public @ResponseBody Representation getRepresentation( HttpServletRequest httpServletRequest, @PathVariable String providerId, @PathVariable String localId, @PathVariable String representationName) throws RepresentationNotExistsException, ProviderNotExistsException, RecordNotExistsException { LOGGER.info("Reading representation '{}' using 'friendly' approach for providerId: {} and localId: {}", representationName, providerId, localId); final String cloudId = findCloudIdFor(providerId, localId); Representation representation = recordService.getRepresentation(cloudId, representationName); EnrichUriUtil.enrich(httpServletRequest, representation); return representation; } SimplifiedRepresentationResource(UISClientHandler uisClientHandler, RecordService recordService); } | SimplifiedRepresentationResource { @GetMapping @PostAuthorize("hasPermission" + "( " + " (returnObject.cloudId).concat('/').concat(#representationName).concat('/').concat(returnObject.version) ," + " 'eu.europeana.cloud.common.model.Representation', read" + ")") public @ResponseBody Representation getRepresentation( HttpServletRequest httpServletRequest, @PathVariable String providerId, @PathVariable String localId, @PathVariable String representationName) throws RepresentationNotExistsException, ProviderNotExistsException, RecordNotExistsException { LOGGER.info("Reading representation '{}' using 'friendly' approach for providerId: {} and localId: {}", representationName, providerId, localId); final String cloudId = findCloudIdFor(providerId, localId); Representation representation = recordService.getRepresentation(cloudId, representationName); EnrichUriUtil.enrich(httpServletRequest, representation); return representation; } SimplifiedRepresentationResource(UISClientHandler uisClientHandler, RecordService recordService); @GetMapping @PostAuthorize("hasPermission" + "( " + " (returnObject.cloudId).concat('/').concat(#representationName).concat('/').concat(returnObject.version) ," + " 'eu.europeana.cloud.common.model.Representation', read" + ")") @ResponseBody Representation getRepresentation(
HttpServletRequest httpServletRequest,
@PathVariable String providerId,
@PathVariable String localId,
@PathVariable String representationName); } | SimplifiedRepresentationResource { @GetMapping @PostAuthorize("hasPermission" + "( " + " (returnObject.cloudId).concat('/').concat(#representationName).concat('/').concat(returnObject.version) ," + " 'eu.europeana.cloud.common.model.Representation', read" + ")") public @ResponseBody Representation getRepresentation( HttpServletRequest httpServletRequest, @PathVariable String providerId, @PathVariable String localId, @PathVariable String representationName) throws RepresentationNotExistsException, ProviderNotExistsException, RecordNotExistsException { LOGGER.info("Reading representation '{}' using 'friendly' approach for providerId: {} and localId: {}", representationName, providerId, localId); final String cloudId = findCloudIdFor(providerId, localId); Representation representation = recordService.getRepresentation(cloudId, representationName); EnrichUriUtil.enrich(httpServletRequest, representation); return representation; } SimplifiedRepresentationResource(UISClientHandler uisClientHandler, RecordService recordService); @GetMapping @PostAuthorize("hasPermission" + "( " + " (returnObject.cloudId).concat('/').concat(#representationName).concat('/').concat(returnObject.version) ," + " 'eu.europeana.cloud.common.model.Representation', read" + ")") @ResponseBody Representation getRepresentation(
HttpServletRequest httpServletRequest,
@PathVariable String providerId,
@PathVariable String localId,
@PathVariable String representationName); } |
@Test(expected = RecordNotExistsException.class) public void exceptionShouldBeThrowForNotExistingCloudId() throws RepresentationNotExistsException, ProviderNotExistsException, RecordNotExistsException { representationResource.getRepresentation(null, PROVIDER_ID, LOCAL_ID_FOR_NOT_EXISTING_RECORD, "repName"); } | @GetMapping @PostAuthorize("hasPermission" + "( " + " (returnObject.cloudId).concat('/').concat(#representationName).concat('/').concat(returnObject.version) ," + " 'eu.europeana.cloud.common.model.Representation', read" + ")") public @ResponseBody Representation getRepresentation( HttpServletRequest httpServletRequest, @PathVariable String providerId, @PathVariable String localId, @PathVariable String representationName) throws RepresentationNotExistsException, ProviderNotExistsException, RecordNotExistsException { LOGGER.info("Reading representation '{}' using 'friendly' approach for providerId: {} and localId: {}", representationName, providerId, localId); final String cloudId = findCloudIdFor(providerId, localId); Representation representation = recordService.getRepresentation(cloudId, representationName); EnrichUriUtil.enrich(httpServletRequest, representation); return representation; } | SimplifiedRepresentationResource { @GetMapping @PostAuthorize("hasPermission" + "( " + " (returnObject.cloudId).concat('/').concat(#representationName).concat('/').concat(returnObject.version) ," + " 'eu.europeana.cloud.common.model.Representation', read" + ")") public @ResponseBody Representation getRepresentation( HttpServletRequest httpServletRequest, @PathVariable String providerId, @PathVariable String localId, @PathVariable String representationName) throws RepresentationNotExistsException, ProviderNotExistsException, RecordNotExistsException { LOGGER.info("Reading representation '{}' using 'friendly' approach for providerId: {} and localId: {}", representationName, providerId, localId); final String cloudId = findCloudIdFor(providerId, localId); Representation representation = recordService.getRepresentation(cloudId, representationName); EnrichUriUtil.enrich(httpServletRequest, representation); return representation; } } | SimplifiedRepresentationResource { @GetMapping @PostAuthorize("hasPermission" + "( " + " (returnObject.cloudId).concat('/').concat(#representationName).concat('/').concat(returnObject.version) ," + " 'eu.europeana.cloud.common.model.Representation', read" + ")") public @ResponseBody Representation getRepresentation( HttpServletRequest httpServletRequest, @PathVariable String providerId, @PathVariable String localId, @PathVariable String representationName) throws RepresentationNotExistsException, ProviderNotExistsException, RecordNotExistsException { LOGGER.info("Reading representation '{}' using 'friendly' approach for providerId: {} and localId: {}", representationName, providerId, localId); final String cloudId = findCloudIdFor(providerId, localId); Representation representation = recordService.getRepresentation(cloudId, representationName); EnrichUriUtil.enrich(httpServletRequest, representation); return representation; } SimplifiedRepresentationResource(UISClientHandler uisClientHandler, RecordService recordService); } | SimplifiedRepresentationResource { @GetMapping @PostAuthorize("hasPermission" + "( " + " (returnObject.cloudId).concat('/').concat(#representationName).concat('/').concat(returnObject.version) ," + " 'eu.europeana.cloud.common.model.Representation', read" + ")") public @ResponseBody Representation getRepresentation( HttpServletRequest httpServletRequest, @PathVariable String providerId, @PathVariable String localId, @PathVariable String representationName) throws RepresentationNotExistsException, ProviderNotExistsException, RecordNotExistsException { LOGGER.info("Reading representation '{}' using 'friendly' approach for providerId: {} and localId: {}", representationName, providerId, localId); final String cloudId = findCloudIdFor(providerId, localId); Representation representation = recordService.getRepresentation(cloudId, representationName); EnrichUriUtil.enrich(httpServletRequest, representation); return representation; } SimplifiedRepresentationResource(UISClientHandler uisClientHandler, RecordService recordService); @GetMapping @PostAuthorize("hasPermission" + "( " + " (returnObject.cloudId).concat('/').concat(#representationName).concat('/').concat(returnObject.version) ," + " 'eu.europeana.cloud.common.model.Representation', read" + ")") @ResponseBody Representation getRepresentation(
HttpServletRequest httpServletRequest,
@PathVariable String providerId,
@PathVariable String localId,
@PathVariable String representationName); } | SimplifiedRepresentationResource { @GetMapping @PostAuthorize("hasPermission" + "( " + " (returnObject.cloudId).concat('/').concat(#representationName).concat('/').concat(returnObject.version) ," + " 'eu.europeana.cloud.common.model.Representation', read" + ")") public @ResponseBody Representation getRepresentation( HttpServletRequest httpServletRequest, @PathVariable String providerId, @PathVariable String localId, @PathVariable String representationName) throws RepresentationNotExistsException, ProviderNotExistsException, RecordNotExistsException { LOGGER.info("Reading representation '{}' using 'friendly' approach for providerId: {} and localId: {}", representationName, providerId, localId); final String cloudId = findCloudIdFor(providerId, localId); Representation representation = recordService.getRepresentation(cloudId, representationName); EnrichUriUtil.enrich(httpServletRequest, representation); return representation; } SimplifiedRepresentationResource(UISClientHandler uisClientHandler, RecordService recordService); @GetMapping @PostAuthorize("hasPermission" + "( " + " (returnObject.cloudId).concat('/').concat(#representationName).concat('/').concat(returnObject.version) ," + " 'eu.europeana.cloud.common.model.Representation', read" + ")") @ResponseBody Representation getRepresentation(
HttpServletRequest httpServletRequest,
@PathVariable String providerId,
@PathVariable String localId,
@PathVariable String representationName); } |
@Test(expected = RepresentationNotExistsException.class) public void exceptionShouldBeThrowForRecordWithoutNamedRepresentation() throws RepresentationNotExistsException, ProviderNotExistsException, RecordNotExistsException { representationResource.getRepresentation(null, PROVIDER_ID, LOCAL_ID, RANDOM_REPRESENTATION_NAME); } | @GetMapping @PostAuthorize("hasPermission" + "( " + " (returnObject.cloudId).concat('/').concat(#representationName).concat('/').concat(returnObject.version) ," + " 'eu.europeana.cloud.common.model.Representation', read" + ")") public @ResponseBody Representation getRepresentation( HttpServletRequest httpServletRequest, @PathVariable String providerId, @PathVariable String localId, @PathVariable String representationName) throws RepresentationNotExistsException, ProviderNotExistsException, RecordNotExistsException { LOGGER.info("Reading representation '{}' using 'friendly' approach for providerId: {} and localId: {}", representationName, providerId, localId); final String cloudId = findCloudIdFor(providerId, localId); Representation representation = recordService.getRepresentation(cloudId, representationName); EnrichUriUtil.enrich(httpServletRequest, representation); return representation; } | SimplifiedRepresentationResource { @GetMapping @PostAuthorize("hasPermission" + "( " + " (returnObject.cloudId).concat('/').concat(#representationName).concat('/').concat(returnObject.version) ," + " 'eu.europeana.cloud.common.model.Representation', read" + ")") public @ResponseBody Representation getRepresentation( HttpServletRequest httpServletRequest, @PathVariable String providerId, @PathVariable String localId, @PathVariable String representationName) throws RepresentationNotExistsException, ProviderNotExistsException, RecordNotExistsException { LOGGER.info("Reading representation '{}' using 'friendly' approach for providerId: {} and localId: {}", representationName, providerId, localId); final String cloudId = findCloudIdFor(providerId, localId); Representation representation = recordService.getRepresentation(cloudId, representationName); EnrichUriUtil.enrich(httpServletRequest, representation); return representation; } } | SimplifiedRepresentationResource { @GetMapping @PostAuthorize("hasPermission" + "( " + " (returnObject.cloudId).concat('/').concat(#representationName).concat('/').concat(returnObject.version) ," + " 'eu.europeana.cloud.common.model.Representation', read" + ")") public @ResponseBody Representation getRepresentation( HttpServletRequest httpServletRequest, @PathVariable String providerId, @PathVariable String localId, @PathVariable String representationName) throws RepresentationNotExistsException, ProviderNotExistsException, RecordNotExistsException { LOGGER.info("Reading representation '{}' using 'friendly' approach for providerId: {} and localId: {}", representationName, providerId, localId); final String cloudId = findCloudIdFor(providerId, localId); Representation representation = recordService.getRepresentation(cloudId, representationName); EnrichUriUtil.enrich(httpServletRequest, representation); return representation; } SimplifiedRepresentationResource(UISClientHandler uisClientHandler, RecordService recordService); } | SimplifiedRepresentationResource { @GetMapping @PostAuthorize("hasPermission" + "( " + " (returnObject.cloudId).concat('/').concat(#representationName).concat('/').concat(returnObject.version) ," + " 'eu.europeana.cloud.common.model.Representation', read" + ")") public @ResponseBody Representation getRepresentation( HttpServletRequest httpServletRequest, @PathVariable String providerId, @PathVariable String localId, @PathVariable String representationName) throws RepresentationNotExistsException, ProviderNotExistsException, RecordNotExistsException { LOGGER.info("Reading representation '{}' using 'friendly' approach for providerId: {} and localId: {}", representationName, providerId, localId); final String cloudId = findCloudIdFor(providerId, localId); Representation representation = recordService.getRepresentation(cloudId, representationName); EnrichUriUtil.enrich(httpServletRequest, representation); return representation; } SimplifiedRepresentationResource(UISClientHandler uisClientHandler, RecordService recordService); @GetMapping @PostAuthorize("hasPermission" + "( " + " (returnObject.cloudId).concat('/').concat(#representationName).concat('/').concat(returnObject.version) ," + " 'eu.europeana.cloud.common.model.Representation', read" + ")") @ResponseBody Representation getRepresentation(
HttpServletRequest httpServletRequest,
@PathVariable String providerId,
@PathVariable String localId,
@PathVariable String representationName); } | SimplifiedRepresentationResource { @GetMapping @PostAuthorize("hasPermission" + "( " + " (returnObject.cloudId).concat('/').concat(#representationName).concat('/').concat(returnObject.version) ," + " 'eu.europeana.cloud.common.model.Representation', read" + ")") public @ResponseBody Representation getRepresentation( HttpServletRequest httpServletRequest, @PathVariable String providerId, @PathVariable String localId, @PathVariable String representationName) throws RepresentationNotExistsException, ProviderNotExistsException, RecordNotExistsException { LOGGER.info("Reading representation '{}' using 'friendly' approach for providerId: {} and localId: {}", representationName, providerId, localId); final String cloudId = findCloudIdFor(providerId, localId); Representation representation = recordService.getRepresentation(cloudId, representationName); EnrichUriUtil.enrich(httpServletRequest, representation); return representation; } SimplifiedRepresentationResource(UISClientHandler uisClientHandler, RecordService recordService); @GetMapping @PostAuthorize("hasPermission" + "( " + " (returnObject.cloudId).concat('/').concat(#representationName).concat('/').concat(returnObject.version) ," + " 'eu.europeana.cloud.common.model.Representation', read" + ")") @ResponseBody Representation getRepresentation(
HttpServletRequest httpServletRequest,
@PathVariable String providerId,
@PathVariable String localId,
@PathVariable String representationName); } |
@Test public void properRepresentationShouldBeReturned() throws RepresentationNotExistsException, ProviderNotExistsException, RecordNotExistsException { HttpServletRequest info = mockHttpServletRequest(); Representation rep = representationResource.getRepresentation(info, PROVIDER_ID, LOCAL_ID, EXISTING_REPRESENTATION_NAME); Assert.assertNotNull(rep); assertThat(rep.getCloudId(), is(CLOUD_ID)); assertThat(rep.getRepresentationName(), is(EXISTING_REPRESENTATION_NAME)); } | @GetMapping @PostAuthorize("hasPermission" + "( " + " (returnObject.cloudId).concat('/').concat(#representationName).concat('/').concat(returnObject.version) ," + " 'eu.europeana.cloud.common.model.Representation', read" + ")") public @ResponseBody Representation getRepresentation( HttpServletRequest httpServletRequest, @PathVariable String providerId, @PathVariable String localId, @PathVariable String representationName) throws RepresentationNotExistsException, ProviderNotExistsException, RecordNotExistsException { LOGGER.info("Reading representation '{}' using 'friendly' approach for providerId: {} and localId: {}", representationName, providerId, localId); final String cloudId = findCloudIdFor(providerId, localId); Representation representation = recordService.getRepresentation(cloudId, representationName); EnrichUriUtil.enrich(httpServletRequest, representation); return representation; } | SimplifiedRepresentationResource { @GetMapping @PostAuthorize("hasPermission" + "( " + " (returnObject.cloudId).concat('/').concat(#representationName).concat('/').concat(returnObject.version) ," + " 'eu.europeana.cloud.common.model.Representation', read" + ")") public @ResponseBody Representation getRepresentation( HttpServletRequest httpServletRequest, @PathVariable String providerId, @PathVariable String localId, @PathVariable String representationName) throws RepresentationNotExistsException, ProviderNotExistsException, RecordNotExistsException { LOGGER.info("Reading representation '{}' using 'friendly' approach for providerId: {} and localId: {}", representationName, providerId, localId); final String cloudId = findCloudIdFor(providerId, localId); Representation representation = recordService.getRepresentation(cloudId, representationName); EnrichUriUtil.enrich(httpServletRequest, representation); return representation; } } | SimplifiedRepresentationResource { @GetMapping @PostAuthorize("hasPermission" + "( " + " (returnObject.cloudId).concat('/').concat(#representationName).concat('/').concat(returnObject.version) ," + " 'eu.europeana.cloud.common.model.Representation', read" + ")") public @ResponseBody Representation getRepresentation( HttpServletRequest httpServletRequest, @PathVariable String providerId, @PathVariable String localId, @PathVariable String representationName) throws RepresentationNotExistsException, ProviderNotExistsException, RecordNotExistsException { LOGGER.info("Reading representation '{}' using 'friendly' approach for providerId: {} and localId: {}", representationName, providerId, localId); final String cloudId = findCloudIdFor(providerId, localId); Representation representation = recordService.getRepresentation(cloudId, representationName); EnrichUriUtil.enrich(httpServletRequest, representation); return representation; } SimplifiedRepresentationResource(UISClientHandler uisClientHandler, RecordService recordService); } | SimplifiedRepresentationResource { @GetMapping @PostAuthorize("hasPermission" + "( " + " (returnObject.cloudId).concat('/').concat(#representationName).concat('/').concat(returnObject.version) ," + " 'eu.europeana.cloud.common.model.Representation', read" + ")") public @ResponseBody Representation getRepresentation( HttpServletRequest httpServletRequest, @PathVariable String providerId, @PathVariable String localId, @PathVariable String representationName) throws RepresentationNotExistsException, ProviderNotExistsException, RecordNotExistsException { LOGGER.info("Reading representation '{}' using 'friendly' approach for providerId: {} and localId: {}", representationName, providerId, localId); final String cloudId = findCloudIdFor(providerId, localId); Representation representation = recordService.getRepresentation(cloudId, representationName); EnrichUriUtil.enrich(httpServletRequest, representation); return representation; } SimplifiedRepresentationResource(UISClientHandler uisClientHandler, RecordService recordService); @GetMapping @PostAuthorize("hasPermission" + "( " + " (returnObject.cloudId).concat('/').concat(#representationName).concat('/').concat(returnObject.version) ," + " 'eu.europeana.cloud.common.model.Representation', read" + ")") @ResponseBody Representation getRepresentation(
HttpServletRequest httpServletRequest,
@PathVariable String providerId,
@PathVariable String localId,
@PathVariable String representationName); } | SimplifiedRepresentationResource { @GetMapping @PostAuthorize("hasPermission" + "( " + " (returnObject.cloudId).concat('/').concat(#representationName).concat('/').concat(returnObject.version) ," + " 'eu.europeana.cloud.common.model.Representation', read" + ")") public @ResponseBody Representation getRepresentation( HttpServletRequest httpServletRequest, @PathVariable String providerId, @PathVariable String localId, @PathVariable String representationName) throws RepresentationNotExistsException, ProviderNotExistsException, RecordNotExistsException { LOGGER.info("Reading representation '{}' using 'friendly' approach for providerId: {} and localId: {}", representationName, providerId, localId); final String cloudId = findCloudIdFor(providerId, localId); Representation representation = recordService.getRepresentation(cloudId, representationName); EnrichUriUtil.enrich(httpServletRequest, representation); return representation; } SimplifiedRepresentationResource(UISClientHandler uisClientHandler, RecordService recordService); @GetMapping @PostAuthorize("hasPermission" + "( " + " (returnObject.cloudId).concat('/').concat(#representationName).concat('/').concat(returnObject.version) ," + " 'eu.europeana.cloud.common.model.Representation', read" + ")") @ResponseBody Representation getRepresentation(
HttpServletRequest httpServletRequest,
@PathVariable String providerId,
@PathVariable String localId,
@PathVariable String representationName); } |
@Test(expected = RecordNotExistsException.class) public void exceptionShouldBeThrownWhenProviderIdDoesNotExist() throws RecordNotExistsException, FileNotExistsException, WrongContentRangeException, RepresentationNotExistsException, ProviderNotExistsException { fileAccessResource.getFile(null, NOT_EXISTING_PROVIDER_ID, NOT_EXISTING_LOCAL_ID, "repName", "fileName"); } | @GetMapping public ResponseEntity<StreamingResponseBody> getFile( HttpServletRequest httpServletRequest, @PathVariable final String providerId, @PathVariable final String localId, @PathVariable final String representationName, @PathVariable final String fileName) throws RepresentationNotExistsException, FileNotExistsException, RecordNotExistsException, ProviderNotExistsException, WrongContentRangeException { LOGGER.info("Reading file in friendly way for: provider: {}, localId: {}, represenatation: {}, fileName: {}", providerId, localId, representationName, fileName); final String cloudId = findCloudIdFor(providerId, localId); final Representation representation = selectRepresentationVersion(cloudId, representationName); if (representation == null) { throw new RepresentationNotExistsException(); } if (userHasRightsToReadFile(cloudId, representation.getRepresentationName(), representation.getVersion())) { final File requestedFile = readFile(cloudId, representationName, representation.getVersion(), fileName); String md5 = requestedFile.getMd5(); MediaType fileMimeType = null; if (StringUtils.isNotBlank(requestedFile.getMimeType())) { fileMimeType = MediaType.parseMediaType(requestedFile.getMimeType()); } EnrichUriUtil.enrich(httpServletRequest, representation, requestedFile); final FileResource.ContentRange contentRange = new FileResource.ContentRange(-1L, -1L); Consumer<OutputStream> downloadingMethod = recordService.getContent(cloudId, representationName, representation.getVersion(), fileName, contentRange.getStart(), contentRange.getEnd()); ResponseEntity.BodyBuilder response = ResponseEntity .status(HttpStatus.OK) .location(requestedFile.getContentUri()); if (md5 != null) { response.eTag(md5); } if (fileMimeType != null) { response.contentType(fileMimeType); } return response.body(output -> downloadingMethod.accept(output)); } else { throw new AccessDeniedException("Access is denied"); } } | SimplifiedFileAccessResource { @GetMapping public ResponseEntity<StreamingResponseBody> getFile( HttpServletRequest httpServletRequest, @PathVariable final String providerId, @PathVariable final String localId, @PathVariable final String representationName, @PathVariable final String fileName) throws RepresentationNotExistsException, FileNotExistsException, RecordNotExistsException, ProviderNotExistsException, WrongContentRangeException { LOGGER.info("Reading file in friendly way for: provider: {}, localId: {}, represenatation: {}, fileName: {}", providerId, localId, representationName, fileName); final String cloudId = findCloudIdFor(providerId, localId); final Representation representation = selectRepresentationVersion(cloudId, representationName); if (representation == null) { throw new RepresentationNotExistsException(); } if (userHasRightsToReadFile(cloudId, representation.getRepresentationName(), representation.getVersion())) { final File requestedFile = readFile(cloudId, representationName, representation.getVersion(), fileName); String md5 = requestedFile.getMd5(); MediaType fileMimeType = null; if (StringUtils.isNotBlank(requestedFile.getMimeType())) { fileMimeType = MediaType.parseMediaType(requestedFile.getMimeType()); } EnrichUriUtil.enrich(httpServletRequest, representation, requestedFile); final FileResource.ContentRange contentRange = new FileResource.ContentRange(-1L, -1L); Consumer<OutputStream> downloadingMethod = recordService.getContent(cloudId, representationName, representation.getVersion(), fileName, contentRange.getStart(), contentRange.getEnd()); ResponseEntity.BodyBuilder response = ResponseEntity .status(HttpStatus.OK) .location(requestedFile.getContentUri()); if (md5 != null) { response.eTag(md5); } if (fileMimeType != null) { response.contentType(fileMimeType); } return response.body(output -> downloadingMethod.accept(output)); } else { throw new AccessDeniedException("Access is denied"); } } } | SimplifiedFileAccessResource { @GetMapping public ResponseEntity<StreamingResponseBody> getFile( HttpServletRequest httpServletRequest, @PathVariable final String providerId, @PathVariable final String localId, @PathVariable final String representationName, @PathVariable final String fileName) throws RepresentationNotExistsException, FileNotExistsException, RecordNotExistsException, ProviderNotExistsException, WrongContentRangeException { LOGGER.info("Reading file in friendly way for: provider: {}, localId: {}, represenatation: {}, fileName: {}", providerId, localId, representationName, fileName); final String cloudId = findCloudIdFor(providerId, localId); final Representation representation = selectRepresentationVersion(cloudId, representationName); if (representation == null) { throw new RepresentationNotExistsException(); } if (userHasRightsToReadFile(cloudId, representation.getRepresentationName(), representation.getVersion())) { final File requestedFile = readFile(cloudId, representationName, representation.getVersion(), fileName); String md5 = requestedFile.getMd5(); MediaType fileMimeType = null; if (StringUtils.isNotBlank(requestedFile.getMimeType())) { fileMimeType = MediaType.parseMediaType(requestedFile.getMimeType()); } EnrichUriUtil.enrich(httpServletRequest, representation, requestedFile); final FileResource.ContentRange contentRange = new FileResource.ContentRange(-1L, -1L); Consumer<OutputStream> downloadingMethod = recordService.getContent(cloudId, representationName, representation.getVersion(), fileName, contentRange.getStart(), contentRange.getEnd()); ResponseEntity.BodyBuilder response = ResponseEntity .status(HttpStatus.OK) .location(requestedFile.getContentUri()); if (md5 != null) { response.eTag(md5); } if (fileMimeType != null) { response.contentType(fileMimeType); } return response.body(output -> downloadingMethod.accept(output)); } else { throw new AccessDeniedException("Access is denied"); } } SimplifiedFileAccessResource(RecordService recordService, UISClientHandler uisClientHandler, PermissionEvaluator permissionEvaluator); } | SimplifiedFileAccessResource { @GetMapping public ResponseEntity<StreamingResponseBody> getFile( HttpServletRequest httpServletRequest, @PathVariable final String providerId, @PathVariable final String localId, @PathVariable final String representationName, @PathVariable final String fileName) throws RepresentationNotExistsException, FileNotExistsException, RecordNotExistsException, ProviderNotExistsException, WrongContentRangeException { LOGGER.info("Reading file in friendly way for: provider: {}, localId: {}, represenatation: {}, fileName: {}", providerId, localId, representationName, fileName); final String cloudId = findCloudIdFor(providerId, localId); final Representation representation = selectRepresentationVersion(cloudId, representationName); if (representation == null) { throw new RepresentationNotExistsException(); } if (userHasRightsToReadFile(cloudId, representation.getRepresentationName(), representation.getVersion())) { final File requestedFile = readFile(cloudId, representationName, representation.getVersion(), fileName); String md5 = requestedFile.getMd5(); MediaType fileMimeType = null; if (StringUtils.isNotBlank(requestedFile.getMimeType())) { fileMimeType = MediaType.parseMediaType(requestedFile.getMimeType()); } EnrichUriUtil.enrich(httpServletRequest, representation, requestedFile); final FileResource.ContentRange contentRange = new FileResource.ContentRange(-1L, -1L); Consumer<OutputStream> downloadingMethod = recordService.getContent(cloudId, representationName, representation.getVersion(), fileName, contentRange.getStart(), contentRange.getEnd()); ResponseEntity.BodyBuilder response = ResponseEntity .status(HttpStatus.OK) .location(requestedFile.getContentUri()); if (md5 != null) { response.eTag(md5); } if (fileMimeType != null) { response.contentType(fileMimeType); } return response.body(output -> downloadingMethod.accept(output)); } else { throw new AccessDeniedException("Access is denied"); } } SimplifiedFileAccessResource(RecordService recordService, UISClientHandler uisClientHandler, PermissionEvaluator permissionEvaluator); @GetMapping ResponseEntity<StreamingResponseBody> getFile(
HttpServletRequest httpServletRequest,
@PathVariable final String providerId,
@PathVariable final String localId,
@PathVariable final String representationName,
@PathVariable final String fileName); @RequestMapping(method = RequestMethod.HEAD) ResponseEntity<?> getFileHeaders(
HttpServletRequest httpServletRequest,
@PathVariable final String providerId,
@PathVariable final String localId,
@PathVariable final String representationName,
@PathVariable final String fileName); } | SimplifiedFileAccessResource { @GetMapping public ResponseEntity<StreamingResponseBody> getFile( HttpServletRequest httpServletRequest, @PathVariable final String providerId, @PathVariable final String localId, @PathVariable final String representationName, @PathVariable final String fileName) throws RepresentationNotExistsException, FileNotExistsException, RecordNotExistsException, ProviderNotExistsException, WrongContentRangeException { LOGGER.info("Reading file in friendly way for: provider: {}, localId: {}, represenatation: {}, fileName: {}", providerId, localId, representationName, fileName); final String cloudId = findCloudIdFor(providerId, localId); final Representation representation = selectRepresentationVersion(cloudId, representationName); if (representation == null) { throw new RepresentationNotExistsException(); } if (userHasRightsToReadFile(cloudId, representation.getRepresentationName(), representation.getVersion())) { final File requestedFile = readFile(cloudId, representationName, representation.getVersion(), fileName); String md5 = requestedFile.getMd5(); MediaType fileMimeType = null; if (StringUtils.isNotBlank(requestedFile.getMimeType())) { fileMimeType = MediaType.parseMediaType(requestedFile.getMimeType()); } EnrichUriUtil.enrich(httpServletRequest, representation, requestedFile); final FileResource.ContentRange contentRange = new FileResource.ContentRange(-1L, -1L); Consumer<OutputStream> downloadingMethod = recordService.getContent(cloudId, representationName, representation.getVersion(), fileName, contentRange.getStart(), contentRange.getEnd()); ResponseEntity.BodyBuilder response = ResponseEntity .status(HttpStatus.OK) .location(requestedFile.getContentUri()); if (md5 != null) { response.eTag(md5); } if (fileMimeType != null) { response.contentType(fileMimeType); } return response.body(output -> downloadingMethod.accept(output)); } else { throw new AccessDeniedException("Access is denied"); } } SimplifiedFileAccessResource(RecordService recordService, UISClientHandler uisClientHandler, PermissionEvaluator permissionEvaluator); @GetMapping ResponseEntity<StreamingResponseBody> getFile(
HttpServletRequest httpServletRequest,
@PathVariable final String providerId,
@PathVariable final String localId,
@PathVariable final String representationName,
@PathVariable final String fileName); @RequestMapping(method = RequestMethod.HEAD) ResponseEntity<?> getFileHeaders(
HttpServletRequest httpServletRequest,
@PathVariable final String providerId,
@PathVariable final String localId,
@PathVariable final String representationName,
@PathVariable final String fileName); } |
@Test(expected = RecordNotExistsException.class) public void exceptionShouldBeThrownWhenLocalIdDoesNotExist() throws RecordNotExistsException, FileNotExistsException, WrongContentRangeException, RepresentationNotExistsException, ProviderNotExistsException { fileAccessResource.getFile(null, EXISTING_PROVIDER_ID, NOT_EXISTING_LOCAL_ID, "repName", "fileName"); } | @GetMapping public ResponseEntity<StreamingResponseBody> getFile( HttpServletRequest httpServletRequest, @PathVariable final String providerId, @PathVariable final String localId, @PathVariable final String representationName, @PathVariable final String fileName) throws RepresentationNotExistsException, FileNotExistsException, RecordNotExistsException, ProviderNotExistsException, WrongContentRangeException { LOGGER.info("Reading file in friendly way for: provider: {}, localId: {}, represenatation: {}, fileName: {}", providerId, localId, representationName, fileName); final String cloudId = findCloudIdFor(providerId, localId); final Representation representation = selectRepresentationVersion(cloudId, representationName); if (representation == null) { throw new RepresentationNotExistsException(); } if (userHasRightsToReadFile(cloudId, representation.getRepresentationName(), representation.getVersion())) { final File requestedFile = readFile(cloudId, representationName, representation.getVersion(), fileName); String md5 = requestedFile.getMd5(); MediaType fileMimeType = null; if (StringUtils.isNotBlank(requestedFile.getMimeType())) { fileMimeType = MediaType.parseMediaType(requestedFile.getMimeType()); } EnrichUriUtil.enrich(httpServletRequest, representation, requestedFile); final FileResource.ContentRange contentRange = new FileResource.ContentRange(-1L, -1L); Consumer<OutputStream> downloadingMethod = recordService.getContent(cloudId, representationName, representation.getVersion(), fileName, contentRange.getStart(), contentRange.getEnd()); ResponseEntity.BodyBuilder response = ResponseEntity .status(HttpStatus.OK) .location(requestedFile.getContentUri()); if (md5 != null) { response.eTag(md5); } if (fileMimeType != null) { response.contentType(fileMimeType); } return response.body(output -> downloadingMethod.accept(output)); } else { throw new AccessDeniedException("Access is denied"); } } | SimplifiedFileAccessResource { @GetMapping public ResponseEntity<StreamingResponseBody> getFile( HttpServletRequest httpServletRequest, @PathVariable final String providerId, @PathVariable final String localId, @PathVariable final String representationName, @PathVariable final String fileName) throws RepresentationNotExistsException, FileNotExistsException, RecordNotExistsException, ProviderNotExistsException, WrongContentRangeException { LOGGER.info("Reading file in friendly way for: provider: {}, localId: {}, represenatation: {}, fileName: {}", providerId, localId, representationName, fileName); final String cloudId = findCloudIdFor(providerId, localId); final Representation representation = selectRepresentationVersion(cloudId, representationName); if (representation == null) { throw new RepresentationNotExistsException(); } if (userHasRightsToReadFile(cloudId, representation.getRepresentationName(), representation.getVersion())) { final File requestedFile = readFile(cloudId, representationName, representation.getVersion(), fileName); String md5 = requestedFile.getMd5(); MediaType fileMimeType = null; if (StringUtils.isNotBlank(requestedFile.getMimeType())) { fileMimeType = MediaType.parseMediaType(requestedFile.getMimeType()); } EnrichUriUtil.enrich(httpServletRequest, representation, requestedFile); final FileResource.ContentRange contentRange = new FileResource.ContentRange(-1L, -1L); Consumer<OutputStream> downloadingMethod = recordService.getContent(cloudId, representationName, representation.getVersion(), fileName, contentRange.getStart(), contentRange.getEnd()); ResponseEntity.BodyBuilder response = ResponseEntity .status(HttpStatus.OK) .location(requestedFile.getContentUri()); if (md5 != null) { response.eTag(md5); } if (fileMimeType != null) { response.contentType(fileMimeType); } return response.body(output -> downloadingMethod.accept(output)); } else { throw new AccessDeniedException("Access is denied"); } } } | SimplifiedFileAccessResource { @GetMapping public ResponseEntity<StreamingResponseBody> getFile( HttpServletRequest httpServletRequest, @PathVariable final String providerId, @PathVariable final String localId, @PathVariable final String representationName, @PathVariable final String fileName) throws RepresentationNotExistsException, FileNotExistsException, RecordNotExistsException, ProviderNotExistsException, WrongContentRangeException { LOGGER.info("Reading file in friendly way for: provider: {}, localId: {}, represenatation: {}, fileName: {}", providerId, localId, representationName, fileName); final String cloudId = findCloudIdFor(providerId, localId); final Representation representation = selectRepresentationVersion(cloudId, representationName); if (representation == null) { throw new RepresentationNotExistsException(); } if (userHasRightsToReadFile(cloudId, representation.getRepresentationName(), representation.getVersion())) { final File requestedFile = readFile(cloudId, representationName, representation.getVersion(), fileName); String md5 = requestedFile.getMd5(); MediaType fileMimeType = null; if (StringUtils.isNotBlank(requestedFile.getMimeType())) { fileMimeType = MediaType.parseMediaType(requestedFile.getMimeType()); } EnrichUriUtil.enrich(httpServletRequest, representation, requestedFile); final FileResource.ContentRange contentRange = new FileResource.ContentRange(-1L, -1L); Consumer<OutputStream> downloadingMethod = recordService.getContent(cloudId, representationName, representation.getVersion(), fileName, contentRange.getStart(), contentRange.getEnd()); ResponseEntity.BodyBuilder response = ResponseEntity .status(HttpStatus.OK) .location(requestedFile.getContentUri()); if (md5 != null) { response.eTag(md5); } if (fileMimeType != null) { response.contentType(fileMimeType); } return response.body(output -> downloadingMethod.accept(output)); } else { throw new AccessDeniedException("Access is denied"); } } SimplifiedFileAccessResource(RecordService recordService, UISClientHandler uisClientHandler, PermissionEvaluator permissionEvaluator); } | SimplifiedFileAccessResource { @GetMapping public ResponseEntity<StreamingResponseBody> getFile( HttpServletRequest httpServletRequest, @PathVariable final String providerId, @PathVariable final String localId, @PathVariable final String representationName, @PathVariable final String fileName) throws RepresentationNotExistsException, FileNotExistsException, RecordNotExistsException, ProviderNotExistsException, WrongContentRangeException { LOGGER.info("Reading file in friendly way for: provider: {}, localId: {}, represenatation: {}, fileName: {}", providerId, localId, representationName, fileName); final String cloudId = findCloudIdFor(providerId, localId); final Representation representation = selectRepresentationVersion(cloudId, representationName); if (representation == null) { throw new RepresentationNotExistsException(); } if (userHasRightsToReadFile(cloudId, representation.getRepresentationName(), representation.getVersion())) { final File requestedFile = readFile(cloudId, representationName, representation.getVersion(), fileName); String md5 = requestedFile.getMd5(); MediaType fileMimeType = null; if (StringUtils.isNotBlank(requestedFile.getMimeType())) { fileMimeType = MediaType.parseMediaType(requestedFile.getMimeType()); } EnrichUriUtil.enrich(httpServletRequest, representation, requestedFile); final FileResource.ContentRange contentRange = new FileResource.ContentRange(-1L, -1L); Consumer<OutputStream> downloadingMethod = recordService.getContent(cloudId, representationName, representation.getVersion(), fileName, contentRange.getStart(), contentRange.getEnd()); ResponseEntity.BodyBuilder response = ResponseEntity .status(HttpStatus.OK) .location(requestedFile.getContentUri()); if (md5 != null) { response.eTag(md5); } if (fileMimeType != null) { response.contentType(fileMimeType); } return response.body(output -> downloadingMethod.accept(output)); } else { throw new AccessDeniedException("Access is denied"); } } SimplifiedFileAccessResource(RecordService recordService, UISClientHandler uisClientHandler, PermissionEvaluator permissionEvaluator); @GetMapping ResponseEntity<StreamingResponseBody> getFile(
HttpServletRequest httpServletRequest,
@PathVariable final String providerId,
@PathVariable final String localId,
@PathVariable final String representationName,
@PathVariable final String fileName); @RequestMapping(method = RequestMethod.HEAD) ResponseEntity<?> getFileHeaders(
HttpServletRequest httpServletRequest,
@PathVariable final String providerId,
@PathVariable final String localId,
@PathVariable final String representationName,
@PathVariable final String fileName); } | SimplifiedFileAccessResource { @GetMapping public ResponseEntity<StreamingResponseBody> getFile( HttpServletRequest httpServletRequest, @PathVariable final String providerId, @PathVariable final String localId, @PathVariable final String representationName, @PathVariable final String fileName) throws RepresentationNotExistsException, FileNotExistsException, RecordNotExistsException, ProviderNotExistsException, WrongContentRangeException { LOGGER.info("Reading file in friendly way for: provider: {}, localId: {}, represenatation: {}, fileName: {}", providerId, localId, representationName, fileName); final String cloudId = findCloudIdFor(providerId, localId); final Representation representation = selectRepresentationVersion(cloudId, representationName); if (representation == null) { throw new RepresentationNotExistsException(); } if (userHasRightsToReadFile(cloudId, representation.getRepresentationName(), representation.getVersion())) { final File requestedFile = readFile(cloudId, representationName, representation.getVersion(), fileName); String md5 = requestedFile.getMd5(); MediaType fileMimeType = null; if (StringUtils.isNotBlank(requestedFile.getMimeType())) { fileMimeType = MediaType.parseMediaType(requestedFile.getMimeType()); } EnrichUriUtil.enrich(httpServletRequest, representation, requestedFile); final FileResource.ContentRange contentRange = new FileResource.ContentRange(-1L, -1L); Consumer<OutputStream> downloadingMethod = recordService.getContent(cloudId, representationName, representation.getVersion(), fileName, contentRange.getStart(), contentRange.getEnd()); ResponseEntity.BodyBuilder response = ResponseEntity .status(HttpStatus.OK) .location(requestedFile.getContentUri()); if (md5 != null) { response.eTag(md5); } if (fileMimeType != null) { response.contentType(fileMimeType); } return response.body(output -> downloadingMethod.accept(output)); } else { throw new AccessDeniedException("Access is denied"); } } SimplifiedFileAccessResource(RecordService recordService, UISClientHandler uisClientHandler, PermissionEvaluator permissionEvaluator); @GetMapping ResponseEntity<StreamingResponseBody> getFile(
HttpServletRequest httpServletRequest,
@PathVariable final String providerId,
@PathVariable final String localId,
@PathVariable final String representationName,
@PathVariable final String fileName); @RequestMapping(method = RequestMethod.HEAD) ResponseEntity<?> getFileHeaders(
HttpServletRequest httpServletRequest,
@PathVariable final String providerId,
@PathVariable final String localId,
@PathVariable final String representationName,
@PathVariable final String fileName); } |
@Test(expected = RepresentationNotExistsException.class) public void exceptionShouldBeThrownWhenRepresentationIsMissing() throws RecordNotExistsException, FileNotExistsException, WrongContentRangeException, RepresentationNotExistsException, ProviderNotExistsException { fileAccessResource.getFile(null, EXISTING_PROVIDER_ID, EXISTING_LOCAL_ID, NOT_EXISTING_REPRESENTATION_NAME, "fileName"); } | @GetMapping public ResponseEntity<StreamingResponseBody> getFile( HttpServletRequest httpServletRequest, @PathVariable final String providerId, @PathVariable final String localId, @PathVariable final String representationName, @PathVariable final String fileName) throws RepresentationNotExistsException, FileNotExistsException, RecordNotExistsException, ProviderNotExistsException, WrongContentRangeException { LOGGER.info("Reading file in friendly way for: provider: {}, localId: {}, represenatation: {}, fileName: {}", providerId, localId, representationName, fileName); final String cloudId = findCloudIdFor(providerId, localId); final Representation representation = selectRepresentationVersion(cloudId, representationName); if (representation == null) { throw new RepresentationNotExistsException(); } if (userHasRightsToReadFile(cloudId, representation.getRepresentationName(), representation.getVersion())) { final File requestedFile = readFile(cloudId, representationName, representation.getVersion(), fileName); String md5 = requestedFile.getMd5(); MediaType fileMimeType = null; if (StringUtils.isNotBlank(requestedFile.getMimeType())) { fileMimeType = MediaType.parseMediaType(requestedFile.getMimeType()); } EnrichUriUtil.enrich(httpServletRequest, representation, requestedFile); final FileResource.ContentRange contentRange = new FileResource.ContentRange(-1L, -1L); Consumer<OutputStream> downloadingMethod = recordService.getContent(cloudId, representationName, representation.getVersion(), fileName, contentRange.getStart(), contentRange.getEnd()); ResponseEntity.BodyBuilder response = ResponseEntity .status(HttpStatus.OK) .location(requestedFile.getContentUri()); if (md5 != null) { response.eTag(md5); } if (fileMimeType != null) { response.contentType(fileMimeType); } return response.body(output -> downloadingMethod.accept(output)); } else { throw new AccessDeniedException("Access is denied"); } } | SimplifiedFileAccessResource { @GetMapping public ResponseEntity<StreamingResponseBody> getFile( HttpServletRequest httpServletRequest, @PathVariable final String providerId, @PathVariable final String localId, @PathVariable final String representationName, @PathVariable final String fileName) throws RepresentationNotExistsException, FileNotExistsException, RecordNotExistsException, ProviderNotExistsException, WrongContentRangeException { LOGGER.info("Reading file in friendly way for: provider: {}, localId: {}, represenatation: {}, fileName: {}", providerId, localId, representationName, fileName); final String cloudId = findCloudIdFor(providerId, localId); final Representation representation = selectRepresentationVersion(cloudId, representationName); if (representation == null) { throw new RepresentationNotExistsException(); } if (userHasRightsToReadFile(cloudId, representation.getRepresentationName(), representation.getVersion())) { final File requestedFile = readFile(cloudId, representationName, representation.getVersion(), fileName); String md5 = requestedFile.getMd5(); MediaType fileMimeType = null; if (StringUtils.isNotBlank(requestedFile.getMimeType())) { fileMimeType = MediaType.parseMediaType(requestedFile.getMimeType()); } EnrichUriUtil.enrich(httpServletRequest, representation, requestedFile); final FileResource.ContentRange contentRange = new FileResource.ContentRange(-1L, -1L); Consumer<OutputStream> downloadingMethod = recordService.getContent(cloudId, representationName, representation.getVersion(), fileName, contentRange.getStart(), contentRange.getEnd()); ResponseEntity.BodyBuilder response = ResponseEntity .status(HttpStatus.OK) .location(requestedFile.getContentUri()); if (md5 != null) { response.eTag(md5); } if (fileMimeType != null) { response.contentType(fileMimeType); } return response.body(output -> downloadingMethod.accept(output)); } else { throw new AccessDeniedException("Access is denied"); } } } | SimplifiedFileAccessResource { @GetMapping public ResponseEntity<StreamingResponseBody> getFile( HttpServletRequest httpServletRequest, @PathVariable final String providerId, @PathVariable final String localId, @PathVariable final String representationName, @PathVariable final String fileName) throws RepresentationNotExistsException, FileNotExistsException, RecordNotExistsException, ProviderNotExistsException, WrongContentRangeException { LOGGER.info("Reading file in friendly way for: provider: {}, localId: {}, represenatation: {}, fileName: {}", providerId, localId, representationName, fileName); final String cloudId = findCloudIdFor(providerId, localId); final Representation representation = selectRepresentationVersion(cloudId, representationName); if (representation == null) { throw new RepresentationNotExistsException(); } if (userHasRightsToReadFile(cloudId, representation.getRepresentationName(), representation.getVersion())) { final File requestedFile = readFile(cloudId, representationName, representation.getVersion(), fileName); String md5 = requestedFile.getMd5(); MediaType fileMimeType = null; if (StringUtils.isNotBlank(requestedFile.getMimeType())) { fileMimeType = MediaType.parseMediaType(requestedFile.getMimeType()); } EnrichUriUtil.enrich(httpServletRequest, representation, requestedFile); final FileResource.ContentRange contentRange = new FileResource.ContentRange(-1L, -1L); Consumer<OutputStream> downloadingMethod = recordService.getContent(cloudId, representationName, representation.getVersion(), fileName, contentRange.getStart(), contentRange.getEnd()); ResponseEntity.BodyBuilder response = ResponseEntity .status(HttpStatus.OK) .location(requestedFile.getContentUri()); if (md5 != null) { response.eTag(md5); } if (fileMimeType != null) { response.contentType(fileMimeType); } return response.body(output -> downloadingMethod.accept(output)); } else { throw new AccessDeniedException("Access is denied"); } } SimplifiedFileAccessResource(RecordService recordService, UISClientHandler uisClientHandler, PermissionEvaluator permissionEvaluator); } | SimplifiedFileAccessResource { @GetMapping public ResponseEntity<StreamingResponseBody> getFile( HttpServletRequest httpServletRequest, @PathVariable final String providerId, @PathVariable final String localId, @PathVariable final String representationName, @PathVariable final String fileName) throws RepresentationNotExistsException, FileNotExistsException, RecordNotExistsException, ProviderNotExistsException, WrongContentRangeException { LOGGER.info("Reading file in friendly way for: provider: {}, localId: {}, represenatation: {}, fileName: {}", providerId, localId, representationName, fileName); final String cloudId = findCloudIdFor(providerId, localId); final Representation representation = selectRepresentationVersion(cloudId, representationName); if (representation == null) { throw new RepresentationNotExistsException(); } if (userHasRightsToReadFile(cloudId, representation.getRepresentationName(), representation.getVersion())) { final File requestedFile = readFile(cloudId, representationName, representation.getVersion(), fileName); String md5 = requestedFile.getMd5(); MediaType fileMimeType = null; if (StringUtils.isNotBlank(requestedFile.getMimeType())) { fileMimeType = MediaType.parseMediaType(requestedFile.getMimeType()); } EnrichUriUtil.enrich(httpServletRequest, representation, requestedFile); final FileResource.ContentRange contentRange = new FileResource.ContentRange(-1L, -1L); Consumer<OutputStream> downloadingMethod = recordService.getContent(cloudId, representationName, representation.getVersion(), fileName, contentRange.getStart(), contentRange.getEnd()); ResponseEntity.BodyBuilder response = ResponseEntity .status(HttpStatus.OK) .location(requestedFile.getContentUri()); if (md5 != null) { response.eTag(md5); } if (fileMimeType != null) { response.contentType(fileMimeType); } return response.body(output -> downloadingMethod.accept(output)); } else { throw new AccessDeniedException("Access is denied"); } } SimplifiedFileAccessResource(RecordService recordService, UISClientHandler uisClientHandler, PermissionEvaluator permissionEvaluator); @GetMapping ResponseEntity<StreamingResponseBody> getFile(
HttpServletRequest httpServletRequest,
@PathVariable final String providerId,
@PathVariable final String localId,
@PathVariable final String representationName,
@PathVariable final String fileName); @RequestMapping(method = RequestMethod.HEAD) ResponseEntity<?> getFileHeaders(
HttpServletRequest httpServletRequest,
@PathVariable final String providerId,
@PathVariable final String localId,
@PathVariable final String representationName,
@PathVariable final String fileName); } | SimplifiedFileAccessResource { @GetMapping public ResponseEntity<StreamingResponseBody> getFile( HttpServletRequest httpServletRequest, @PathVariable final String providerId, @PathVariable final String localId, @PathVariable final String representationName, @PathVariable final String fileName) throws RepresentationNotExistsException, FileNotExistsException, RecordNotExistsException, ProviderNotExistsException, WrongContentRangeException { LOGGER.info("Reading file in friendly way for: provider: {}, localId: {}, represenatation: {}, fileName: {}", providerId, localId, representationName, fileName); final String cloudId = findCloudIdFor(providerId, localId); final Representation representation = selectRepresentationVersion(cloudId, representationName); if (representation == null) { throw new RepresentationNotExistsException(); } if (userHasRightsToReadFile(cloudId, representation.getRepresentationName(), representation.getVersion())) { final File requestedFile = readFile(cloudId, representationName, representation.getVersion(), fileName); String md5 = requestedFile.getMd5(); MediaType fileMimeType = null; if (StringUtils.isNotBlank(requestedFile.getMimeType())) { fileMimeType = MediaType.parseMediaType(requestedFile.getMimeType()); } EnrichUriUtil.enrich(httpServletRequest, representation, requestedFile); final FileResource.ContentRange contentRange = new FileResource.ContentRange(-1L, -1L); Consumer<OutputStream> downloadingMethod = recordService.getContent(cloudId, representationName, representation.getVersion(), fileName, contentRange.getStart(), contentRange.getEnd()); ResponseEntity.BodyBuilder response = ResponseEntity .status(HttpStatus.OK) .location(requestedFile.getContentUri()); if (md5 != null) { response.eTag(md5); } if (fileMimeType != null) { response.contentType(fileMimeType); } return response.body(output -> downloadingMethod.accept(output)); } else { throw new AccessDeniedException("Access is denied"); } } SimplifiedFileAccessResource(RecordService recordService, UISClientHandler uisClientHandler, PermissionEvaluator permissionEvaluator); @GetMapping ResponseEntity<StreamingResponseBody> getFile(
HttpServletRequest httpServletRequest,
@PathVariable final String providerId,
@PathVariable final String localId,
@PathVariable final String representationName,
@PathVariable final String fileName); @RequestMapping(method = RequestMethod.HEAD) ResponseEntity<?> getFileHeaders(
HttpServletRequest httpServletRequest,
@PathVariable final String providerId,
@PathVariable final String localId,
@PathVariable final String representationName,
@PathVariable final String fileName); } |
@Test(expected = RepresentationNotExistsException.class) public void exceptionShouldBeThrownWhenThereIsNoPersistentRepresentationInGivenRecord() throws RecordNotExistsException, FileNotExistsException, WrongContentRangeException, RepresentationNotExistsException, ProviderNotExistsException { fileAccessResource.getFile(null, EXISTING_PROVIDER_ID, EXISTING_LOCAL_ID_FOR_RECORD_WITHOUT_PERSISTENT_REPRESENTATION, existingRepresentationName, "fileName"); } | @GetMapping public ResponseEntity<StreamingResponseBody> getFile( HttpServletRequest httpServletRequest, @PathVariable final String providerId, @PathVariable final String localId, @PathVariable final String representationName, @PathVariable final String fileName) throws RepresentationNotExistsException, FileNotExistsException, RecordNotExistsException, ProviderNotExistsException, WrongContentRangeException { LOGGER.info("Reading file in friendly way for: provider: {}, localId: {}, represenatation: {}, fileName: {}", providerId, localId, representationName, fileName); final String cloudId = findCloudIdFor(providerId, localId); final Representation representation = selectRepresentationVersion(cloudId, representationName); if (representation == null) { throw new RepresentationNotExistsException(); } if (userHasRightsToReadFile(cloudId, representation.getRepresentationName(), representation.getVersion())) { final File requestedFile = readFile(cloudId, representationName, representation.getVersion(), fileName); String md5 = requestedFile.getMd5(); MediaType fileMimeType = null; if (StringUtils.isNotBlank(requestedFile.getMimeType())) { fileMimeType = MediaType.parseMediaType(requestedFile.getMimeType()); } EnrichUriUtil.enrich(httpServletRequest, representation, requestedFile); final FileResource.ContentRange contentRange = new FileResource.ContentRange(-1L, -1L); Consumer<OutputStream> downloadingMethod = recordService.getContent(cloudId, representationName, representation.getVersion(), fileName, contentRange.getStart(), contentRange.getEnd()); ResponseEntity.BodyBuilder response = ResponseEntity .status(HttpStatus.OK) .location(requestedFile.getContentUri()); if (md5 != null) { response.eTag(md5); } if (fileMimeType != null) { response.contentType(fileMimeType); } return response.body(output -> downloadingMethod.accept(output)); } else { throw new AccessDeniedException("Access is denied"); } } | SimplifiedFileAccessResource { @GetMapping public ResponseEntity<StreamingResponseBody> getFile( HttpServletRequest httpServletRequest, @PathVariable final String providerId, @PathVariable final String localId, @PathVariable final String representationName, @PathVariable final String fileName) throws RepresentationNotExistsException, FileNotExistsException, RecordNotExistsException, ProviderNotExistsException, WrongContentRangeException { LOGGER.info("Reading file in friendly way for: provider: {}, localId: {}, represenatation: {}, fileName: {}", providerId, localId, representationName, fileName); final String cloudId = findCloudIdFor(providerId, localId); final Representation representation = selectRepresentationVersion(cloudId, representationName); if (representation == null) { throw new RepresentationNotExistsException(); } if (userHasRightsToReadFile(cloudId, representation.getRepresentationName(), representation.getVersion())) { final File requestedFile = readFile(cloudId, representationName, representation.getVersion(), fileName); String md5 = requestedFile.getMd5(); MediaType fileMimeType = null; if (StringUtils.isNotBlank(requestedFile.getMimeType())) { fileMimeType = MediaType.parseMediaType(requestedFile.getMimeType()); } EnrichUriUtil.enrich(httpServletRequest, representation, requestedFile); final FileResource.ContentRange contentRange = new FileResource.ContentRange(-1L, -1L); Consumer<OutputStream> downloadingMethod = recordService.getContent(cloudId, representationName, representation.getVersion(), fileName, contentRange.getStart(), contentRange.getEnd()); ResponseEntity.BodyBuilder response = ResponseEntity .status(HttpStatus.OK) .location(requestedFile.getContentUri()); if (md5 != null) { response.eTag(md5); } if (fileMimeType != null) { response.contentType(fileMimeType); } return response.body(output -> downloadingMethod.accept(output)); } else { throw new AccessDeniedException("Access is denied"); } } } | SimplifiedFileAccessResource { @GetMapping public ResponseEntity<StreamingResponseBody> getFile( HttpServletRequest httpServletRequest, @PathVariable final String providerId, @PathVariable final String localId, @PathVariable final String representationName, @PathVariable final String fileName) throws RepresentationNotExistsException, FileNotExistsException, RecordNotExistsException, ProviderNotExistsException, WrongContentRangeException { LOGGER.info("Reading file in friendly way for: provider: {}, localId: {}, represenatation: {}, fileName: {}", providerId, localId, representationName, fileName); final String cloudId = findCloudIdFor(providerId, localId); final Representation representation = selectRepresentationVersion(cloudId, representationName); if (representation == null) { throw new RepresentationNotExistsException(); } if (userHasRightsToReadFile(cloudId, representation.getRepresentationName(), representation.getVersion())) { final File requestedFile = readFile(cloudId, representationName, representation.getVersion(), fileName); String md5 = requestedFile.getMd5(); MediaType fileMimeType = null; if (StringUtils.isNotBlank(requestedFile.getMimeType())) { fileMimeType = MediaType.parseMediaType(requestedFile.getMimeType()); } EnrichUriUtil.enrich(httpServletRequest, representation, requestedFile); final FileResource.ContentRange contentRange = new FileResource.ContentRange(-1L, -1L); Consumer<OutputStream> downloadingMethod = recordService.getContent(cloudId, representationName, representation.getVersion(), fileName, contentRange.getStart(), contentRange.getEnd()); ResponseEntity.BodyBuilder response = ResponseEntity .status(HttpStatus.OK) .location(requestedFile.getContentUri()); if (md5 != null) { response.eTag(md5); } if (fileMimeType != null) { response.contentType(fileMimeType); } return response.body(output -> downloadingMethod.accept(output)); } else { throw new AccessDeniedException("Access is denied"); } } SimplifiedFileAccessResource(RecordService recordService, UISClientHandler uisClientHandler, PermissionEvaluator permissionEvaluator); } | SimplifiedFileAccessResource { @GetMapping public ResponseEntity<StreamingResponseBody> getFile( HttpServletRequest httpServletRequest, @PathVariable final String providerId, @PathVariable final String localId, @PathVariable final String representationName, @PathVariable final String fileName) throws RepresentationNotExistsException, FileNotExistsException, RecordNotExistsException, ProviderNotExistsException, WrongContentRangeException { LOGGER.info("Reading file in friendly way for: provider: {}, localId: {}, represenatation: {}, fileName: {}", providerId, localId, representationName, fileName); final String cloudId = findCloudIdFor(providerId, localId); final Representation representation = selectRepresentationVersion(cloudId, representationName); if (representation == null) { throw new RepresentationNotExistsException(); } if (userHasRightsToReadFile(cloudId, representation.getRepresentationName(), representation.getVersion())) { final File requestedFile = readFile(cloudId, representationName, representation.getVersion(), fileName); String md5 = requestedFile.getMd5(); MediaType fileMimeType = null; if (StringUtils.isNotBlank(requestedFile.getMimeType())) { fileMimeType = MediaType.parseMediaType(requestedFile.getMimeType()); } EnrichUriUtil.enrich(httpServletRequest, representation, requestedFile); final FileResource.ContentRange contentRange = new FileResource.ContentRange(-1L, -1L); Consumer<OutputStream> downloadingMethod = recordService.getContent(cloudId, representationName, representation.getVersion(), fileName, contentRange.getStart(), contentRange.getEnd()); ResponseEntity.BodyBuilder response = ResponseEntity .status(HttpStatus.OK) .location(requestedFile.getContentUri()); if (md5 != null) { response.eTag(md5); } if (fileMimeType != null) { response.contentType(fileMimeType); } return response.body(output -> downloadingMethod.accept(output)); } else { throw new AccessDeniedException("Access is denied"); } } SimplifiedFileAccessResource(RecordService recordService, UISClientHandler uisClientHandler, PermissionEvaluator permissionEvaluator); @GetMapping ResponseEntity<StreamingResponseBody> getFile(
HttpServletRequest httpServletRequest,
@PathVariable final String providerId,
@PathVariable final String localId,
@PathVariable final String representationName,
@PathVariable final String fileName); @RequestMapping(method = RequestMethod.HEAD) ResponseEntity<?> getFileHeaders(
HttpServletRequest httpServletRequest,
@PathVariable final String providerId,
@PathVariable final String localId,
@PathVariable final String representationName,
@PathVariable final String fileName); } | SimplifiedFileAccessResource { @GetMapping public ResponseEntity<StreamingResponseBody> getFile( HttpServletRequest httpServletRequest, @PathVariable final String providerId, @PathVariable final String localId, @PathVariable final String representationName, @PathVariable final String fileName) throws RepresentationNotExistsException, FileNotExistsException, RecordNotExistsException, ProviderNotExistsException, WrongContentRangeException { LOGGER.info("Reading file in friendly way for: provider: {}, localId: {}, represenatation: {}, fileName: {}", providerId, localId, representationName, fileName); final String cloudId = findCloudIdFor(providerId, localId); final Representation representation = selectRepresentationVersion(cloudId, representationName); if (representation == null) { throw new RepresentationNotExistsException(); } if (userHasRightsToReadFile(cloudId, representation.getRepresentationName(), representation.getVersion())) { final File requestedFile = readFile(cloudId, representationName, representation.getVersion(), fileName); String md5 = requestedFile.getMd5(); MediaType fileMimeType = null; if (StringUtils.isNotBlank(requestedFile.getMimeType())) { fileMimeType = MediaType.parseMediaType(requestedFile.getMimeType()); } EnrichUriUtil.enrich(httpServletRequest, representation, requestedFile); final FileResource.ContentRange contentRange = new FileResource.ContentRange(-1L, -1L); Consumer<OutputStream> downloadingMethod = recordService.getContent(cloudId, representationName, representation.getVersion(), fileName, contentRange.getStart(), contentRange.getEnd()); ResponseEntity.BodyBuilder response = ResponseEntity .status(HttpStatus.OK) .location(requestedFile.getContentUri()); if (md5 != null) { response.eTag(md5); } if (fileMimeType != null) { response.contentType(fileMimeType); } return response.body(output -> downloadingMethod.accept(output)); } else { throw new AccessDeniedException("Access is denied"); } } SimplifiedFileAccessResource(RecordService recordService, UISClientHandler uisClientHandler, PermissionEvaluator permissionEvaluator); @GetMapping ResponseEntity<StreamingResponseBody> getFile(
HttpServletRequest httpServletRequest,
@PathVariable final String providerId,
@PathVariable final String localId,
@PathVariable final String representationName,
@PathVariable final String fileName); @RequestMapping(method = RequestMethod.HEAD) ResponseEntity<?> getFileHeaders(
HttpServletRequest httpServletRequest,
@PathVariable final String providerId,
@PathVariable final String localId,
@PathVariable final String representationName,
@PathVariable final String fileName); } |
@Test public void shouldReturnTheExpectedPrimaryKeysSelectionCQL() { assertEquals(EXPECTED_PRIMARY_KEYS_SELECTION_STATEMENT, CQLBuilder.constructSelectPrimaryKeysFromSourceTable(SOURCE_TABLE, primaryKeys)); } | public static String constructSelectPrimaryKeysFromSourceTable(String sourceTableName, List<String> primaryKeyNames) { StringBuilder stringBuilder = new StringBuilder(); stringBuilder.append("SELECT "); for (int i = 0; i < primaryKeyNames.size() - 1; i++) stringBuilder.append(primaryKeyNames.get(i)).append(" , "); stringBuilder.append(primaryKeyNames.get(primaryKeyNames.size() - 1)); stringBuilder.append(" from ").append(sourceTableName).append(";"); return stringBuilder.toString(); } | CQLBuilder { public static String constructSelectPrimaryKeysFromSourceTable(String sourceTableName, List<String> primaryKeyNames) { StringBuilder stringBuilder = new StringBuilder(); stringBuilder.append("SELECT "); for (int i = 0; i < primaryKeyNames.size() - 1; i++) stringBuilder.append(primaryKeyNames.get(i)).append(" , "); stringBuilder.append(primaryKeyNames.get(primaryKeyNames.size() - 1)); stringBuilder.append(" from ").append(sourceTableName).append(";"); return stringBuilder.toString(); } } | CQLBuilder { public static String constructSelectPrimaryKeysFromSourceTable(String sourceTableName, List<String> primaryKeyNames) { StringBuilder stringBuilder = new StringBuilder(); stringBuilder.append("SELECT "); for (int i = 0; i < primaryKeyNames.size() - 1; i++) stringBuilder.append(primaryKeyNames.get(i)).append(" , "); stringBuilder.append(primaryKeyNames.get(primaryKeyNames.size() - 1)); stringBuilder.append(" from ").append(sourceTableName).append(";"); return stringBuilder.toString(); } } | CQLBuilder { public static String constructSelectPrimaryKeysFromSourceTable(String sourceTableName, List<String> primaryKeyNames) { StringBuilder stringBuilder = new StringBuilder(); stringBuilder.append("SELECT "); for (int i = 0; i < primaryKeyNames.size() - 1; i++) stringBuilder.append(primaryKeyNames.get(i)).append(" , "); stringBuilder.append(primaryKeyNames.get(primaryKeyNames.size() - 1)); stringBuilder.append(" from ").append(sourceTableName).append(";"); return stringBuilder.toString(); } static String getMatchCountStatementFromTargetTable(String targetTableName, List<String> names); static String constructSelectPrimaryKeysFromSourceTable(String sourceTableName, List<String> primaryKeyNames); } | CQLBuilder { public static String constructSelectPrimaryKeysFromSourceTable(String sourceTableName, List<String> primaryKeyNames) { StringBuilder stringBuilder = new StringBuilder(); stringBuilder.append("SELECT "); for (int i = 0; i < primaryKeyNames.size() - 1; i++) stringBuilder.append(primaryKeyNames.get(i)).append(" , "); stringBuilder.append(primaryKeyNames.get(primaryKeyNames.size() - 1)); stringBuilder.append(" from ").append(sourceTableName).append(";"); return stringBuilder.toString(); } static String getMatchCountStatementFromTargetTable(String targetTableName, List<String> names); static String constructSelectPrimaryKeysFromSourceTable(String sourceTableName, List<String> primaryKeyNames); } |
@Test public void fileShouldBeReadSuccessfully() throws RecordNotExistsException, FileNotExistsException, WrongContentRangeException, RepresentationNotExistsException, ProviderNotExistsException, URISyntaxException { setupUriInfo(); ResponseEntity<?> response = fileAccessResource.getFile(URI_INFO, EXISTING_PROVIDER_ID, EXISTING_LOCAL_ID, existingRepresentationName, "fileWithoutReadRights"); Assert.assertEquals(200, response.getStatusCodeValue()); response.toString(); } | @GetMapping public ResponseEntity<StreamingResponseBody> getFile( HttpServletRequest httpServletRequest, @PathVariable final String providerId, @PathVariable final String localId, @PathVariable final String representationName, @PathVariable final String fileName) throws RepresentationNotExistsException, FileNotExistsException, RecordNotExistsException, ProviderNotExistsException, WrongContentRangeException { LOGGER.info("Reading file in friendly way for: provider: {}, localId: {}, represenatation: {}, fileName: {}", providerId, localId, representationName, fileName); final String cloudId = findCloudIdFor(providerId, localId); final Representation representation = selectRepresentationVersion(cloudId, representationName); if (representation == null) { throw new RepresentationNotExistsException(); } if (userHasRightsToReadFile(cloudId, representation.getRepresentationName(), representation.getVersion())) { final File requestedFile = readFile(cloudId, representationName, representation.getVersion(), fileName); String md5 = requestedFile.getMd5(); MediaType fileMimeType = null; if (StringUtils.isNotBlank(requestedFile.getMimeType())) { fileMimeType = MediaType.parseMediaType(requestedFile.getMimeType()); } EnrichUriUtil.enrich(httpServletRequest, representation, requestedFile); final FileResource.ContentRange contentRange = new FileResource.ContentRange(-1L, -1L); Consumer<OutputStream> downloadingMethod = recordService.getContent(cloudId, representationName, representation.getVersion(), fileName, contentRange.getStart(), contentRange.getEnd()); ResponseEntity.BodyBuilder response = ResponseEntity .status(HttpStatus.OK) .location(requestedFile.getContentUri()); if (md5 != null) { response.eTag(md5); } if (fileMimeType != null) { response.contentType(fileMimeType); } return response.body(output -> downloadingMethod.accept(output)); } else { throw new AccessDeniedException("Access is denied"); } } | SimplifiedFileAccessResource { @GetMapping public ResponseEntity<StreamingResponseBody> getFile( HttpServletRequest httpServletRequest, @PathVariable final String providerId, @PathVariable final String localId, @PathVariable final String representationName, @PathVariable final String fileName) throws RepresentationNotExistsException, FileNotExistsException, RecordNotExistsException, ProviderNotExistsException, WrongContentRangeException { LOGGER.info("Reading file in friendly way for: provider: {}, localId: {}, represenatation: {}, fileName: {}", providerId, localId, representationName, fileName); final String cloudId = findCloudIdFor(providerId, localId); final Representation representation = selectRepresentationVersion(cloudId, representationName); if (representation == null) { throw new RepresentationNotExistsException(); } if (userHasRightsToReadFile(cloudId, representation.getRepresentationName(), representation.getVersion())) { final File requestedFile = readFile(cloudId, representationName, representation.getVersion(), fileName); String md5 = requestedFile.getMd5(); MediaType fileMimeType = null; if (StringUtils.isNotBlank(requestedFile.getMimeType())) { fileMimeType = MediaType.parseMediaType(requestedFile.getMimeType()); } EnrichUriUtil.enrich(httpServletRequest, representation, requestedFile); final FileResource.ContentRange contentRange = new FileResource.ContentRange(-1L, -1L); Consumer<OutputStream> downloadingMethod = recordService.getContent(cloudId, representationName, representation.getVersion(), fileName, contentRange.getStart(), contentRange.getEnd()); ResponseEntity.BodyBuilder response = ResponseEntity .status(HttpStatus.OK) .location(requestedFile.getContentUri()); if (md5 != null) { response.eTag(md5); } if (fileMimeType != null) { response.contentType(fileMimeType); } return response.body(output -> downloadingMethod.accept(output)); } else { throw new AccessDeniedException("Access is denied"); } } } | SimplifiedFileAccessResource { @GetMapping public ResponseEntity<StreamingResponseBody> getFile( HttpServletRequest httpServletRequest, @PathVariable final String providerId, @PathVariable final String localId, @PathVariable final String representationName, @PathVariable final String fileName) throws RepresentationNotExistsException, FileNotExistsException, RecordNotExistsException, ProviderNotExistsException, WrongContentRangeException { LOGGER.info("Reading file in friendly way for: provider: {}, localId: {}, represenatation: {}, fileName: {}", providerId, localId, representationName, fileName); final String cloudId = findCloudIdFor(providerId, localId); final Representation representation = selectRepresentationVersion(cloudId, representationName); if (representation == null) { throw new RepresentationNotExistsException(); } if (userHasRightsToReadFile(cloudId, representation.getRepresentationName(), representation.getVersion())) { final File requestedFile = readFile(cloudId, representationName, representation.getVersion(), fileName); String md5 = requestedFile.getMd5(); MediaType fileMimeType = null; if (StringUtils.isNotBlank(requestedFile.getMimeType())) { fileMimeType = MediaType.parseMediaType(requestedFile.getMimeType()); } EnrichUriUtil.enrich(httpServletRequest, representation, requestedFile); final FileResource.ContentRange contentRange = new FileResource.ContentRange(-1L, -1L); Consumer<OutputStream> downloadingMethod = recordService.getContent(cloudId, representationName, representation.getVersion(), fileName, contentRange.getStart(), contentRange.getEnd()); ResponseEntity.BodyBuilder response = ResponseEntity .status(HttpStatus.OK) .location(requestedFile.getContentUri()); if (md5 != null) { response.eTag(md5); } if (fileMimeType != null) { response.contentType(fileMimeType); } return response.body(output -> downloadingMethod.accept(output)); } else { throw new AccessDeniedException("Access is denied"); } } SimplifiedFileAccessResource(RecordService recordService, UISClientHandler uisClientHandler, PermissionEvaluator permissionEvaluator); } | SimplifiedFileAccessResource { @GetMapping public ResponseEntity<StreamingResponseBody> getFile( HttpServletRequest httpServletRequest, @PathVariable final String providerId, @PathVariable final String localId, @PathVariable final String representationName, @PathVariable final String fileName) throws RepresentationNotExistsException, FileNotExistsException, RecordNotExistsException, ProviderNotExistsException, WrongContentRangeException { LOGGER.info("Reading file in friendly way for: provider: {}, localId: {}, represenatation: {}, fileName: {}", providerId, localId, representationName, fileName); final String cloudId = findCloudIdFor(providerId, localId); final Representation representation = selectRepresentationVersion(cloudId, representationName); if (representation == null) { throw new RepresentationNotExistsException(); } if (userHasRightsToReadFile(cloudId, representation.getRepresentationName(), representation.getVersion())) { final File requestedFile = readFile(cloudId, representationName, representation.getVersion(), fileName); String md5 = requestedFile.getMd5(); MediaType fileMimeType = null; if (StringUtils.isNotBlank(requestedFile.getMimeType())) { fileMimeType = MediaType.parseMediaType(requestedFile.getMimeType()); } EnrichUriUtil.enrich(httpServletRequest, representation, requestedFile); final FileResource.ContentRange contentRange = new FileResource.ContentRange(-1L, -1L); Consumer<OutputStream> downloadingMethod = recordService.getContent(cloudId, representationName, representation.getVersion(), fileName, contentRange.getStart(), contentRange.getEnd()); ResponseEntity.BodyBuilder response = ResponseEntity .status(HttpStatus.OK) .location(requestedFile.getContentUri()); if (md5 != null) { response.eTag(md5); } if (fileMimeType != null) { response.contentType(fileMimeType); } return response.body(output -> downloadingMethod.accept(output)); } else { throw new AccessDeniedException("Access is denied"); } } SimplifiedFileAccessResource(RecordService recordService, UISClientHandler uisClientHandler, PermissionEvaluator permissionEvaluator); @GetMapping ResponseEntity<StreamingResponseBody> getFile(
HttpServletRequest httpServletRequest,
@PathVariable final String providerId,
@PathVariable final String localId,
@PathVariable final String representationName,
@PathVariable final String fileName); @RequestMapping(method = RequestMethod.HEAD) ResponseEntity<?> getFileHeaders(
HttpServletRequest httpServletRequest,
@PathVariable final String providerId,
@PathVariable final String localId,
@PathVariable final String representationName,
@PathVariable final String fileName); } | SimplifiedFileAccessResource { @GetMapping public ResponseEntity<StreamingResponseBody> getFile( HttpServletRequest httpServletRequest, @PathVariable final String providerId, @PathVariable final String localId, @PathVariable final String representationName, @PathVariable final String fileName) throws RepresentationNotExistsException, FileNotExistsException, RecordNotExistsException, ProviderNotExistsException, WrongContentRangeException { LOGGER.info("Reading file in friendly way for: provider: {}, localId: {}, represenatation: {}, fileName: {}", providerId, localId, representationName, fileName); final String cloudId = findCloudIdFor(providerId, localId); final Representation representation = selectRepresentationVersion(cloudId, representationName); if (representation == null) { throw new RepresentationNotExistsException(); } if (userHasRightsToReadFile(cloudId, representation.getRepresentationName(), representation.getVersion())) { final File requestedFile = readFile(cloudId, representationName, representation.getVersion(), fileName); String md5 = requestedFile.getMd5(); MediaType fileMimeType = null; if (StringUtils.isNotBlank(requestedFile.getMimeType())) { fileMimeType = MediaType.parseMediaType(requestedFile.getMimeType()); } EnrichUriUtil.enrich(httpServletRequest, representation, requestedFile); final FileResource.ContentRange contentRange = new FileResource.ContentRange(-1L, -1L); Consumer<OutputStream> downloadingMethod = recordService.getContent(cloudId, representationName, representation.getVersion(), fileName, contentRange.getStart(), contentRange.getEnd()); ResponseEntity.BodyBuilder response = ResponseEntity .status(HttpStatus.OK) .location(requestedFile.getContentUri()); if (md5 != null) { response.eTag(md5); } if (fileMimeType != null) { response.contentType(fileMimeType); } return response.body(output -> downloadingMethod.accept(output)); } else { throw new AccessDeniedException("Access is denied"); } } SimplifiedFileAccessResource(RecordService recordService, UISClientHandler uisClientHandler, PermissionEvaluator permissionEvaluator); @GetMapping ResponseEntity<StreamingResponseBody> getFile(
HttpServletRequest httpServletRequest,
@PathVariable final String providerId,
@PathVariable final String localId,
@PathVariable final String representationName,
@PathVariable final String fileName); @RequestMapping(method = RequestMethod.HEAD) ResponseEntity<?> getFileHeaders(
HttpServletRequest httpServletRequest,
@PathVariable final String providerId,
@PathVariable final String localId,
@PathVariable final String representationName,
@PathVariable final String fileName); } |
@Test public void fileHeadersShouldBeReadSuccessfully() throws FileNotExistsException, RecordNotExistsException, ProviderNotExistsException, RepresentationNotExistsException, URISyntaxException { setupUriInfo(); ResponseEntity<?> response = fileAccessResource.getFileHeaders(URI_INFO, EXISTING_PROVIDER_ID, EXISTING_LOCAL_ID, existingRepresentationName, "fileWithoutReadRights"); Assert.assertEquals(200, response.getStatusCodeValue()); Assert.assertNotNull(response.getHeaders().get("Location")); response.toString(); } | @RequestMapping(method = RequestMethod.HEAD) public ResponseEntity<?> getFileHeaders( HttpServletRequest httpServletRequest, @PathVariable final String providerId, @PathVariable final String localId, @PathVariable final String representationName, @PathVariable final String fileName) throws RepresentationNotExistsException, FileNotExistsException, RecordNotExistsException, ProviderNotExistsException { LOGGER.info("Reading file headers in friendly way for: provider: {}, localId: {}, represenatation: {}, fileName: {}", providerId, localId, representationName, fileName); final String cloudId = findCloudIdFor(providerId, localId); final Representation representation = selectRepresentationVersion(cloudId, representationName); if (representation == null) { throw new RepresentationNotExistsException(); } if (userHasRightsToReadFile(cloudId, representation.getRepresentationName(), representation.getVersion())) { final File requestedFile = readFile(cloudId, representationName, representation.getVersion(), fileName); String md5 = requestedFile.getMd5(); MediaType fileMimeType = null; if (StringUtils.isNotBlank(requestedFile.getMimeType())) { fileMimeType = MediaType.parseMediaType(requestedFile.getMimeType()); } EnrichUriUtil.enrich(httpServletRequest, representation, requestedFile); ResponseEntity.BodyBuilder response = ResponseEntity .status(HttpStatus.OK) .location(requestedFile.getContentUri()); if (md5 != null) { response.eTag(md5); } if (fileMimeType != null) { response.contentType(fileMimeType); } return response.build(); } else { throw new AccessDeniedException("Access is denied"); } } | SimplifiedFileAccessResource { @RequestMapping(method = RequestMethod.HEAD) public ResponseEntity<?> getFileHeaders( HttpServletRequest httpServletRequest, @PathVariable final String providerId, @PathVariable final String localId, @PathVariable final String representationName, @PathVariable final String fileName) throws RepresentationNotExistsException, FileNotExistsException, RecordNotExistsException, ProviderNotExistsException { LOGGER.info("Reading file headers in friendly way for: provider: {}, localId: {}, represenatation: {}, fileName: {}", providerId, localId, representationName, fileName); final String cloudId = findCloudIdFor(providerId, localId); final Representation representation = selectRepresentationVersion(cloudId, representationName); if (representation == null) { throw new RepresentationNotExistsException(); } if (userHasRightsToReadFile(cloudId, representation.getRepresentationName(), representation.getVersion())) { final File requestedFile = readFile(cloudId, representationName, representation.getVersion(), fileName); String md5 = requestedFile.getMd5(); MediaType fileMimeType = null; if (StringUtils.isNotBlank(requestedFile.getMimeType())) { fileMimeType = MediaType.parseMediaType(requestedFile.getMimeType()); } EnrichUriUtil.enrich(httpServletRequest, representation, requestedFile); ResponseEntity.BodyBuilder response = ResponseEntity .status(HttpStatus.OK) .location(requestedFile.getContentUri()); if (md5 != null) { response.eTag(md5); } if (fileMimeType != null) { response.contentType(fileMimeType); } return response.build(); } else { throw new AccessDeniedException("Access is denied"); } } } | SimplifiedFileAccessResource { @RequestMapping(method = RequestMethod.HEAD) public ResponseEntity<?> getFileHeaders( HttpServletRequest httpServletRequest, @PathVariable final String providerId, @PathVariable final String localId, @PathVariable final String representationName, @PathVariable final String fileName) throws RepresentationNotExistsException, FileNotExistsException, RecordNotExistsException, ProviderNotExistsException { LOGGER.info("Reading file headers in friendly way for: provider: {}, localId: {}, represenatation: {}, fileName: {}", providerId, localId, representationName, fileName); final String cloudId = findCloudIdFor(providerId, localId); final Representation representation = selectRepresentationVersion(cloudId, representationName); if (representation == null) { throw new RepresentationNotExistsException(); } if (userHasRightsToReadFile(cloudId, representation.getRepresentationName(), representation.getVersion())) { final File requestedFile = readFile(cloudId, representationName, representation.getVersion(), fileName); String md5 = requestedFile.getMd5(); MediaType fileMimeType = null; if (StringUtils.isNotBlank(requestedFile.getMimeType())) { fileMimeType = MediaType.parseMediaType(requestedFile.getMimeType()); } EnrichUriUtil.enrich(httpServletRequest, representation, requestedFile); ResponseEntity.BodyBuilder response = ResponseEntity .status(HttpStatus.OK) .location(requestedFile.getContentUri()); if (md5 != null) { response.eTag(md5); } if (fileMimeType != null) { response.contentType(fileMimeType); } return response.build(); } else { throw new AccessDeniedException("Access is denied"); } } SimplifiedFileAccessResource(RecordService recordService, UISClientHandler uisClientHandler, PermissionEvaluator permissionEvaluator); } | SimplifiedFileAccessResource { @RequestMapping(method = RequestMethod.HEAD) public ResponseEntity<?> getFileHeaders( HttpServletRequest httpServletRequest, @PathVariable final String providerId, @PathVariable final String localId, @PathVariable final String representationName, @PathVariable final String fileName) throws RepresentationNotExistsException, FileNotExistsException, RecordNotExistsException, ProviderNotExistsException { LOGGER.info("Reading file headers in friendly way for: provider: {}, localId: {}, represenatation: {}, fileName: {}", providerId, localId, representationName, fileName); final String cloudId = findCloudIdFor(providerId, localId); final Representation representation = selectRepresentationVersion(cloudId, representationName); if (representation == null) { throw new RepresentationNotExistsException(); } if (userHasRightsToReadFile(cloudId, representation.getRepresentationName(), representation.getVersion())) { final File requestedFile = readFile(cloudId, representationName, representation.getVersion(), fileName); String md5 = requestedFile.getMd5(); MediaType fileMimeType = null; if (StringUtils.isNotBlank(requestedFile.getMimeType())) { fileMimeType = MediaType.parseMediaType(requestedFile.getMimeType()); } EnrichUriUtil.enrich(httpServletRequest, representation, requestedFile); ResponseEntity.BodyBuilder response = ResponseEntity .status(HttpStatus.OK) .location(requestedFile.getContentUri()); if (md5 != null) { response.eTag(md5); } if (fileMimeType != null) { response.contentType(fileMimeType); } return response.build(); } else { throw new AccessDeniedException("Access is denied"); } } SimplifiedFileAccessResource(RecordService recordService, UISClientHandler uisClientHandler, PermissionEvaluator permissionEvaluator); @GetMapping ResponseEntity<StreamingResponseBody> getFile(
HttpServletRequest httpServletRequest,
@PathVariable final String providerId,
@PathVariable final String localId,
@PathVariable final String representationName,
@PathVariable final String fileName); @RequestMapping(method = RequestMethod.HEAD) ResponseEntity<?> getFileHeaders(
HttpServletRequest httpServletRequest,
@PathVariable final String providerId,
@PathVariable final String localId,
@PathVariable final String representationName,
@PathVariable final String fileName); } | SimplifiedFileAccessResource { @RequestMapping(method = RequestMethod.HEAD) public ResponseEntity<?> getFileHeaders( HttpServletRequest httpServletRequest, @PathVariable final String providerId, @PathVariable final String localId, @PathVariable final String representationName, @PathVariable final String fileName) throws RepresentationNotExistsException, FileNotExistsException, RecordNotExistsException, ProviderNotExistsException { LOGGER.info("Reading file headers in friendly way for: provider: {}, localId: {}, represenatation: {}, fileName: {}", providerId, localId, representationName, fileName); final String cloudId = findCloudIdFor(providerId, localId); final Representation representation = selectRepresentationVersion(cloudId, representationName); if (representation == null) { throw new RepresentationNotExistsException(); } if (userHasRightsToReadFile(cloudId, representation.getRepresentationName(), representation.getVersion())) { final File requestedFile = readFile(cloudId, representationName, representation.getVersion(), fileName); String md5 = requestedFile.getMd5(); MediaType fileMimeType = null; if (StringUtils.isNotBlank(requestedFile.getMimeType())) { fileMimeType = MediaType.parseMediaType(requestedFile.getMimeType()); } EnrichUriUtil.enrich(httpServletRequest, representation, requestedFile); ResponseEntity.BodyBuilder response = ResponseEntity .status(HttpStatus.OK) .location(requestedFile.getContentUri()); if (md5 != null) { response.eTag(md5); } if (fileMimeType != null) { response.contentType(fileMimeType); } return response.build(); } else { throw new AccessDeniedException("Access is denied"); } } SimplifiedFileAccessResource(RecordService recordService, UISClientHandler uisClientHandler, PermissionEvaluator permissionEvaluator); @GetMapping ResponseEntity<StreamingResponseBody> getFile(
HttpServletRequest httpServletRequest,
@PathVariable final String providerId,
@PathVariable final String localId,
@PathVariable final String representationName,
@PathVariable final String fileName); @RequestMapping(method = RequestMethod.HEAD) ResponseEntity<?> getFileHeaders(
HttpServletRequest httpServletRequest,
@PathVariable final String providerId,
@PathVariable final String localId,
@PathVariable final String representationName,
@PathVariable final String fileName); } |
@Test @Parameters(method = "mimeTypes") public void testListVersions(MediaType mediaType) throws Exception { List<Representation> expected = copy(REPRESENTATIONS); Representation expectedRepresentation = expected.get(0); URITools.enrich(expectedRepresentation, getBaseUri()); when(recordService.listRepresentationVersions(GLOBAL_ID, SCHEMA)).thenReturn(copy(REPRESENTATIONS)); ResultActions response = mockMvc.perform(get(LIST_VERSIONS_PATH).accept(mediaType)) .andExpect(status().isOk()) .andExpect(content().contentType(mediaType)); List<Representation> entity = responseContentAsRepresentationList(response, mediaType); assertThat(entity, is(expected)); verify(recordService, times(1)).listRepresentationVersions(GLOBAL_ID, SCHEMA); verifyNoMoreInteractions(recordService); } | @GetMapping(produces = {MediaType.APPLICATION_XML_VALUE, MediaType.APPLICATION_JSON_VALUE}) @ResponseBody public RepresentationsListWrapper listVersions( final HttpServletRequest request, @PathVariable String cloudId, @PathVariable String representationName) throws RepresentationNotExistsException { List<Representation> representationVersions = recordService.listRepresentationVersions(cloudId, representationName); for (Representation representationVersion : representationVersions) { EnrichUriUtil.enrich(request, representationVersion); } return new RepresentationsListWrapper(representationVersions); } | RepresentationVersionsResource { @GetMapping(produces = {MediaType.APPLICATION_XML_VALUE, MediaType.APPLICATION_JSON_VALUE}) @ResponseBody public RepresentationsListWrapper listVersions( final HttpServletRequest request, @PathVariable String cloudId, @PathVariable String representationName) throws RepresentationNotExistsException { List<Representation> representationVersions = recordService.listRepresentationVersions(cloudId, representationName); for (Representation representationVersion : representationVersions) { EnrichUriUtil.enrich(request, representationVersion); } return new RepresentationsListWrapper(representationVersions); } } | RepresentationVersionsResource { @GetMapping(produces = {MediaType.APPLICATION_XML_VALUE, MediaType.APPLICATION_JSON_VALUE}) @ResponseBody public RepresentationsListWrapper listVersions( final HttpServletRequest request, @PathVariable String cloudId, @PathVariable String representationName) throws RepresentationNotExistsException { List<Representation> representationVersions = recordService.listRepresentationVersions(cloudId, representationName); for (Representation representationVersion : representationVersions) { EnrichUriUtil.enrich(request, representationVersion); } return new RepresentationsListWrapper(representationVersions); } RepresentationVersionsResource(RecordService recordService); } | RepresentationVersionsResource { @GetMapping(produces = {MediaType.APPLICATION_XML_VALUE, MediaType.APPLICATION_JSON_VALUE}) @ResponseBody public RepresentationsListWrapper listVersions( final HttpServletRequest request, @PathVariable String cloudId, @PathVariable String representationName) throws RepresentationNotExistsException { List<Representation> representationVersions = recordService.listRepresentationVersions(cloudId, representationName); for (Representation representationVersion : representationVersions) { EnrichUriUtil.enrich(request, representationVersion); } return new RepresentationsListWrapper(representationVersions); } RepresentationVersionsResource(RecordService recordService); @GetMapping(produces = {MediaType.APPLICATION_XML_VALUE, MediaType.APPLICATION_JSON_VALUE}) @ResponseBody RepresentationsListWrapper listVersions(
final HttpServletRequest request,
@PathVariable String cloudId,
@PathVariable String representationName); } | RepresentationVersionsResource { @GetMapping(produces = {MediaType.APPLICATION_XML_VALUE, MediaType.APPLICATION_JSON_VALUE}) @ResponseBody public RepresentationsListWrapper listVersions( final HttpServletRequest request, @PathVariable String cloudId, @PathVariable String representationName) throws RepresentationNotExistsException { List<Representation> representationVersions = recordService.listRepresentationVersions(cloudId, representationName); for (Representation representationVersion : representationVersions) { EnrichUriUtil.enrich(request, representationVersion); } return new RepresentationsListWrapper(representationVersions); } RepresentationVersionsResource(RecordService recordService); @GetMapping(produces = {MediaType.APPLICATION_XML_VALUE, MediaType.APPLICATION_JSON_VALUE}) @ResponseBody RepresentationsListWrapper listVersions(
final HttpServletRequest request,
@PathVariable String cloudId,
@PathVariable String representationName); static final Logger LOGGER; } |
@Test(expected = ProviderNotExistsException.class) public void exceptionShouldBeThrowForNotExistingProviderId() throws RecordNotExistsException, ProviderNotExistsException { recordsResource.getRecord(null, NOT_EXISTING_PROVIDER_ID, "anyLocalId"); } | @GetMapping(produces = {MediaType.APPLICATION_XML_VALUE, MediaType.APPLICATION_JSON_VALUE}) public @ResponseBody Record getRecord( HttpServletRequest httpServletRequest, @PathVariable String providerId, @PathVariable String localId) throws RecordNotExistsException, ProviderNotExistsException { final String cloudId = findCloudIdFor(providerId, localId); Record record = recordService.getRecord(cloudId); prepare(httpServletRequest, record); return record; } | SimplifiedRecordsResource { @GetMapping(produces = {MediaType.APPLICATION_XML_VALUE, MediaType.APPLICATION_JSON_VALUE}) public @ResponseBody Record getRecord( HttpServletRequest httpServletRequest, @PathVariable String providerId, @PathVariable String localId) throws RecordNotExistsException, ProviderNotExistsException { final String cloudId = findCloudIdFor(providerId, localId); Record record = recordService.getRecord(cloudId); prepare(httpServletRequest, record); return record; } } | SimplifiedRecordsResource { @GetMapping(produces = {MediaType.APPLICATION_XML_VALUE, MediaType.APPLICATION_JSON_VALUE}) public @ResponseBody Record getRecord( HttpServletRequest httpServletRequest, @PathVariable String providerId, @PathVariable String localId) throws RecordNotExistsException, ProviderNotExistsException { final String cloudId = findCloudIdFor(providerId, localId); Record record = recordService.getRecord(cloudId); prepare(httpServletRequest, record); return record; } SimplifiedRecordsResource(RecordService recordService, UISClientHandler uisHandler); } | SimplifiedRecordsResource { @GetMapping(produces = {MediaType.APPLICATION_XML_VALUE, MediaType.APPLICATION_JSON_VALUE}) public @ResponseBody Record getRecord( HttpServletRequest httpServletRequest, @PathVariable String providerId, @PathVariable String localId) throws RecordNotExistsException, ProviderNotExistsException { final String cloudId = findCloudIdFor(providerId, localId); Record record = recordService.getRecord(cloudId); prepare(httpServletRequest, record); return record; } SimplifiedRecordsResource(RecordService recordService, UISClientHandler uisHandler); @GetMapping(produces = {MediaType.APPLICATION_XML_VALUE, MediaType.APPLICATION_JSON_VALUE}) @ResponseBody Record getRecord(
HttpServletRequest httpServletRequest,
@PathVariable String providerId,
@PathVariable String localId); } | SimplifiedRecordsResource { @GetMapping(produces = {MediaType.APPLICATION_XML_VALUE, MediaType.APPLICATION_JSON_VALUE}) public @ResponseBody Record getRecord( HttpServletRequest httpServletRequest, @PathVariable String providerId, @PathVariable String localId) throws RecordNotExistsException, ProviderNotExistsException { final String cloudId = findCloudIdFor(providerId, localId); Record record = recordService.getRecord(cloudId); prepare(httpServletRequest, record); return record; } SimplifiedRecordsResource(RecordService recordService, UISClientHandler uisHandler); @GetMapping(produces = {MediaType.APPLICATION_XML_VALUE, MediaType.APPLICATION_JSON_VALUE}) @ResponseBody Record getRecord(
HttpServletRequest httpServletRequest,
@PathVariable String providerId,
@PathVariable String localId); } |
@Test(expected = RecordNotExistsException.class) public void exceptionShouldBeThrowForNotExistingCloudId() throws RecordNotExistsException, ProviderNotExistsException { recordsResource.getRecord(null, PROVIDER_ID, LOCAL_ID_FOR_NOT_EXISTING_RECORD); } | @GetMapping(produces = {MediaType.APPLICATION_XML_VALUE, MediaType.APPLICATION_JSON_VALUE}) public @ResponseBody Record getRecord( HttpServletRequest httpServletRequest, @PathVariable String providerId, @PathVariable String localId) throws RecordNotExistsException, ProviderNotExistsException { final String cloudId = findCloudIdFor(providerId, localId); Record record = recordService.getRecord(cloudId); prepare(httpServletRequest, record); return record; } | SimplifiedRecordsResource { @GetMapping(produces = {MediaType.APPLICATION_XML_VALUE, MediaType.APPLICATION_JSON_VALUE}) public @ResponseBody Record getRecord( HttpServletRequest httpServletRequest, @PathVariable String providerId, @PathVariable String localId) throws RecordNotExistsException, ProviderNotExistsException { final String cloudId = findCloudIdFor(providerId, localId); Record record = recordService.getRecord(cloudId); prepare(httpServletRequest, record); return record; } } | SimplifiedRecordsResource { @GetMapping(produces = {MediaType.APPLICATION_XML_VALUE, MediaType.APPLICATION_JSON_VALUE}) public @ResponseBody Record getRecord( HttpServletRequest httpServletRequest, @PathVariable String providerId, @PathVariable String localId) throws RecordNotExistsException, ProviderNotExistsException { final String cloudId = findCloudIdFor(providerId, localId); Record record = recordService.getRecord(cloudId); prepare(httpServletRequest, record); return record; } SimplifiedRecordsResource(RecordService recordService, UISClientHandler uisHandler); } | SimplifiedRecordsResource { @GetMapping(produces = {MediaType.APPLICATION_XML_VALUE, MediaType.APPLICATION_JSON_VALUE}) public @ResponseBody Record getRecord( HttpServletRequest httpServletRequest, @PathVariable String providerId, @PathVariable String localId) throws RecordNotExistsException, ProviderNotExistsException { final String cloudId = findCloudIdFor(providerId, localId); Record record = recordService.getRecord(cloudId); prepare(httpServletRequest, record); return record; } SimplifiedRecordsResource(RecordService recordService, UISClientHandler uisHandler); @GetMapping(produces = {MediaType.APPLICATION_XML_VALUE, MediaType.APPLICATION_JSON_VALUE}) @ResponseBody Record getRecord(
HttpServletRequest httpServletRequest,
@PathVariable String providerId,
@PathVariable String localId); } | SimplifiedRecordsResource { @GetMapping(produces = {MediaType.APPLICATION_XML_VALUE, MediaType.APPLICATION_JSON_VALUE}) public @ResponseBody Record getRecord( HttpServletRequest httpServletRequest, @PathVariable String providerId, @PathVariable String localId) throws RecordNotExistsException, ProviderNotExistsException { final String cloudId = findCloudIdFor(providerId, localId); Record record = recordService.getRecord(cloudId); prepare(httpServletRequest, record); return record; } SimplifiedRecordsResource(RecordService recordService, UISClientHandler uisHandler); @GetMapping(produces = {MediaType.APPLICATION_XML_VALUE, MediaType.APPLICATION_JSON_VALUE}) @ResponseBody Record getRecord(
HttpServletRequest httpServletRequest,
@PathVariable String providerId,
@PathVariable String localId); } |
Subsets and Splits
No saved queries yet
Save your SQL queries to embed, download, and access them later. Queries will appear here once saved.