Skip to content
Snippets Groups Projects
Commit bc75a9c1 authored by Sonia Zorba's avatar Sonia Zorba
Browse files

Added non-standard parameter on job list endpoint to filter on transfer view...

Added non-standard parameter on job list endpoint to filter on transfer view type (useful for retrieving the list of generated tar/zip archives from UI)
parent b376a7c2
No related branches found
No related tags found
No related merge requests found
...@@ -173,6 +173,7 @@ public class TransferController { ...@@ -173,6 +173,7 @@ public class TransferController {
@RequestParam(value = "PHASE", required = false) Optional<List<ExecutionPhase>> phase, @RequestParam(value = "PHASE", required = false) Optional<List<ExecutionPhase>> phase,
@RequestParam(value = "AFTER", required = false) @DateTimeFormat(iso = DateTimeFormat.ISO.DATE_TIME) Optional<LocalDateTime> after, @RequestParam(value = "AFTER", required = false) @DateTimeFormat(iso = DateTimeFormat.ISO.DATE_TIME) Optional<LocalDateTime> after,
@RequestParam(value = "LAST", required = false) Optional<Integer> last, @RequestParam(value = "LAST", required = false) Optional<Integer> last,
@RequestParam(value = "VIEW", required = false) Optional<List<String>> views,
@RequestParam(value = "direction", required = false) Optional<List<JobService.JobDirection>> direction, @RequestParam(value = "direction", required = false) Optional<List<JobService.JobDirection>> direction,
User principal) { User principal) {
...@@ -184,21 +185,11 @@ public class TransferController { ...@@ -184,21 +185,11 @@ public class TransferController {
String userId = principal.getName(); String userId = principal.getName();
List<ExecutionPhase> phaseList; List<ExecutionPhase> phaseList = phase.orElse(List.of());
if (phase.isPresent()) { List<JobService.JobDirection> directionList = direction.orElse(List.of());
phaseList = phase.get(); List<String> viewsList = views.orElse(List.of());
} else {
phaseList = List.of();
}
List<JobService.JobDirection> directionList;
if (direction.isPresent()) {
directionList = direction.get();
} else {
directionList = List.of();
}
Jobs jobs = jobDAO.getJobs(userId, phaseList, directionList, after, last); Jobs jobs = jobDAO.getJobs(userId, phaseList, directionList, viewsList, after, last);
return ResponseEntity.ok(jobs); return ResponseEntity.ok(jobs);
} }
......
...@@ -31,6 +31,7 @@ import org.springframework.stereotype.Repository; ...@@ -31,6 +31,7 @@ import org.springframework.stereotype.Repository;
import java.util.ArrayList; import java.util.ArrayList;
import java.time.LocalDateTime; import java.time.LocalDateTime;
import java.math.BigDecimal; import java.math.BigDecimal;
import java.util.Collections;
import net.ivoa.xml.uws.v1.ErrorType; import net.ivoa.xml.uws.v1.ErrorType;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
...@@ -149,6 +150,7 @@ public class JobDAO { ...@@ -149,6 +150,7 @@ public class JobDAO {
public Jobs getJobs(String userId, public Jobs getJobs(String userId,
List<ExecutionPhase> phaseList, List<ExecutionPhase> phaseList,
List<JobService.JobDirection> directionList, List<JobService.JobDirection> directionList,
List<String> viewList,
Optional<LocalDateTime> after, Optional<LocalDateTime> after,
Optional<Integer> last Optional<Integer> last
) { ) {
...@@ -199,6 +201,18 @@ public class JobDAO { ...@@ -199,6 +201,18 @@ public class JobDAO {
sb.append(")"); sb.append(")");
} }
// Fill conditions on views list
if (!viewList.isEmpty()) {
sb.append(" AND (")
.append(String.join(" OR ",
Collections.nCopies(viewList.size(), "job_info->'transfer'->'view'->>'uri' = ?")))
.append(")");
for (String view : viewList) {
queryParams.add(view);
queryParamTypes.add(Types.VARCHAR);
}
}
// Fill conditions on creation date // Fill conditions on creation date
if (after.isPresent()) { if (after.isPresent()) {
sb.append(" AND creation_time > ?"); sb.append(" AND creation_time > ?");
......
...@@ -8,6 +8,7 @@ package it.inaf.oats.vospace; ...@@ -8,6 +8,7 @@ package it.inaf.oats.vospace;
import it.inaf.ia2.aa.data.User; import it.inaf.ia2.aa.data.User;
import static it.inaf.oats.vospace.VOSpaceXmlTestUtil.loadDocument; import static it.inaf.oats.vospace.VOSpaceXmlTestUtil.loadDocument;
import it.inaf.oats.vospace.datamodel.NodeProperties; import it.inaf.oats.vospace.datamodel.NodeProperties;
import it.inaf.oats.vospace.datamodel.Views;
import it.inaf.oats.vospace.exception.ErrorSummaryFactory; import it.inaf.oats.vospace.exception.ErrorSummaryFactory;
import it.inaf.oats.vospace.exception.PermissionDeniedException; import it.inaf.oats.vospace.exception.PermissionDeniedException;
import it.inaf.oats.vospace.persistence.JobDAO; import it.inaf.oats.vospace.persistence.JobDAO;
...@@ -357,7 +358,7 @@ public class TransferControllerTest { ...@@ -357,7 +358,7 @@ public class TransferControllerTest {
@Test @Test
public void testGetJobs() throws Exception { public void testGetJobs() throws Exception {
when(jobDao.getJobs(eq("user1"), any(), any(), any(), any())) when(jobDao.getJobs(eq("user1"), any(), any(), any(), any(), any()))
.thenReturn(this.getFakeJobs()); .thenReturn(this.getFakeJobs());
mockMvc.perform(get("/transfers") mockMvc.perform(get("/transfers")
...@@ -367,12 +368,48 @@ public class TransferControllerTest { ...@@ -367,12 +368,48 @@ public class TransferControllerTest {
.andDo(print()) .andDo(print())
.andExpect(status().is4xxClientError()); .andExpect(status().is4xxClientError());
String xml2 = mockMvc.perform(get("/transfers") mockMvc.perform(get("/transfers")
.header("Authorization", "Bearer user1_token") .header("Authorization", "Bearer user1_token")
.accept(MediaType.APPLICATION_XML)) .accept(MediaType.APPLICATION_XML))
.andDo(print()) .andDo(print())
.andExpect(status().isOk()) .andExpect(status().isOk());
.andReturn().getResponse().getContentAsString();
// direction query parameter
mockMvc.perform(get("/transfers")
.param("direction", "pullFromVoSpace")
.header("Authorization", "Bearer user1_token")
.accept(MediaType.APPLICATION_XML))
.andDo(print())
.andExpect(status().isOk());
verify(jobDao, times(1)).getJobs(eq("user1"), any(), argThat(v -> {
return v.size() == 1 && v.contains(JobService.JobDirection.pullFromVoSpace);
}), any(), any(), any());
// PHASE query parameter
mockMvc.perform(get("/transfers")
.param("PHASE", ExecutionPhase.EXECUTING.value())
.header("Authorization", "Bearer user1_token")
.accept(MediaType.APPLICATION_XML))
.andDo(print())
.andExpect(status().isOk());
verify(jobDao, times(1)).getJobs(eq("user1"), argThat(v -> {
return v.size() == 1 && v.contains(ExecutionPhase.EXECUTING);
}), any(), any(), any(), any());
// VIEW query parameters
mockMvc.perform(get("/transfers")
.param("VIEW", Views.TAR_VIEW_URI)
.param("VIEW", Views.ZIP_VIEW_URI)
.header("Authorization", "Bearer user1_token")
.accept(MediaType.APPLICATION_XML))
.andDo(print())
.andExpect(status().isOk());
verify(jobDao, times(1)).getJobs(eq("user1"), any(), any(), argThat(v -> {
return v.size() == 2 && v.contains(Views.TAR_VIEW_URI) && v.contains(Views.ZIP_VIEW_URI);
}), any(), any());
} }
@Test @Test
......
...@@ -6,6 +6,7 @@ ...@@ -6,6 +6,7 @@
package it.inaf.oats.vospace.persistence; package it.inaf.oats.vospace.persistence;
import it.inaf.oats.vospace.JobService; import it.inaf.oats.vospace.JobService;
import it.inaf.oats.vospace.datamodel.Views;
import java.util.List; import java.util.List;
import javax.sql.DataSource; import javax.sql.DataSource;
import net.ivoa.xml.uws.v1.ExecutionPhase; import net.ivoa.xml.uws.v1.ExecutionPhase;
...@@ -202,10 +203,11 @@ public class JobDAOTest { ...@@ -202,10 +203,11 @@ public class JobDAOTest {
String user = "user1"; String user = "user1";
List<ExecutionPhase> phaseList = List.of(); List<ExecutionPhase> phaseList = List.of();
List<JobService.JobDirection> directionList = List.of(); List<JobService.JobDirection> directionList = List.of();
List<String> viewList = List.of();
Optional<LocalDateTime> after = Optional.ofNullable(null); Optional<LocalDateTime> after = Optional.ofNullable(null);
Optional<Integer> last = Optional.ofNullable(null); Optional<Integer> last = Optional.ofNullable(null);
Jobs jobs = dao.getJobs(user, phaseList, directionList, after, last); Jobs jobs = dao.getJobs(user, phaseList, directionList, viewList, after, last);
assertTrue(jobs != null); assertTrue(jobs != null);
List<ShortJobDescription> sjdList = jobs.getJobref(); List<ShortJobDescription> sjdList = jobs.getJobref();
...@@ -227,10 +229,11 @@ public class JobDAOTest { ...@@ -227,10 +229,11 @@ public class JobDAOTest {
String user = "user1"; String user = "user1";
List<ExecutionPhase> phaseList = List.of(); List<ExecutionPhase> phaseList = List.of();
List<JobService.JobDirection> directionList = List.of(); List<JobService.JobDirection> directionList = List.of();
List<String> viewList = List.of();
Optional<LocalDateTime> after = Optional.ofNullable(null); Optional<LocalDateTime> after = Optional.ofNullable(null);
Optional<Integer> last = Optional.of(2); Optional<Integer> last = Optional.of(2);
Jobs jobs = dao.getJobs(user, phaseList, directionList, after, last); Jobs jobs = dao.getJobs(user, phaseList, directionList, viewList, after, last);
List<ShortJobDescription> sjdList = jobs.getJobref(); List<ShortJobDescription> sjdList = jobs.getJobref();
assertEquals(2, sjdList.size()); assertEquals(2, sjdList.size());
...@@ -243,10 +246,11 @@ public class JobDAOTest { ...@@ -243,10 +246,11 @@ public class JobDAOTest {
List<ExecutionPhase> phaseList List<ExecutionPhase> phaseList
= List.of(ExecutionPhase.PENDING, ExecutionPhase.EXECUTING); = List.of(ExecutionPhase.PENDING, ExecutionPhase.EXECUTING);
List<JobService.JobDirection> directionList = List.of(); List<JobService.JobDirection> directionList = List.of();
List<String> viewList = List.of();
Optional<LocalDateTime> after = Optional.ofNullable(null); Optional<LocalDateTime> after = Optional.ofNullable(null);
Optional<Integer> last = Optional.ofNullable(null); Optional<Integer> last = Optional.ofNullable(null);
Jobs jobs = dao.getJobs(user, phaseList, directionList, after, last); Jobs jobs = dao.getJobs(user, phaseList, directionList, viewList, after, last);
List<ShortJobDescription> sjdList = jobs.getJobref(); List<ShortJobDescription> sjdList = jobs.getJobref();
assertEquals(sjdList.size(), 2); assertEquals(sjdList.size(), 2);
assertEquals("pippo5", sjdList.get(0).getId()); assertEquals("pippo5", sjdList.get(0).getId());
...@@ -261,10 +265,11 @@ public class JobDAOTest { ...@@ -261,10 +265,11 @@ public class JobDAOTest {
List<JobService.JobDirection> directionList List<JobService.JobDirection> directionList
= List.of(JobService.JobDirection.pullFromVoSpace, = List.of(JobService.JobDirection.pullFromVoSpace,
JobService.JobDirection.pullToVoSpace); JobService.JobDirection.pullToVoSpace);
List<String> viewList = List.of();
Optional<LocalDateTime> after = Optional.ofNullable(null); Optional<LocalDateTime> after = Optional.ofNullable(null);
Optional<Integer> last = Optional.ofNullable(null); Optional<Integer> last = Optional.ofNullable(null);
Jobs jobs = dao.getJobs(user, phaseList, directionList, after, last); Jobs jobs = dao.getJobs(user, phaseList, directionList, viewList, after, last);
List<ShortJobDescription> sjdList = jobs.getJobref(); List<ShortJobDescription> sjdList = jobs.getJobref();
assertEquals(2, sjdList.size()); assertEquals(2, sjdList.size());
assertEquals("pippo3", sjdList.get(0).getId()); assertEquals("pippo3", sjdList.get(0).getId());
...@@ -277,13 +282,14 @@ public class JobDAOTest { ...@@ -277,13 +282,14 @@ public class JobDAOTest {
String user = "user1"; String user = "user1";
List<ExecutionPhase> phaseList = List.of(); List<ExecutionPhase> phaseList = List.of();
List<JobService.JobDirection> directionList = List.of(); List<JobService.JobDirection> directionList = List.of();
List<String> viewList = List.of();
LocalDateTime ldt LocalDateTime ldt
= LocalDateTime.of(2013, Month.FEBRUARY, 7, 18, 15); = LocalDateTime.of(2013, Month.FEBRUARY, 7, 18, 15);
Optional<LocalDateTime> after = Optional.of(ldt); Optional<LocalDateTime> after = Optional.of(ldt);
Optional<Integer> last = Optional.ofNullable(null); Optional<Integer> last = Optional.ofNullable(null);
Jobs jobs = dao.getJobs(user, phaseList, directionList, after, last); Jobs jobs = dao.getJobs(user, phaseList, directionList, viewList, after, last);
List<ShortJobDescription> sjdList = jobs.getJobref(); List<ShortJobDescription> sjdList = jobs.getJobref();
assertEquals(2, sjdList.size()); assertEquals(2, sjdList.size());
assertEquals("pippo5", sjdList.get(0).getId()); assertEquals("pippo5", sjdList.get(0).getId());
...@@ -299,13 +305,14 @@ public class JobDAOTest { ...@@ -299,13 +305,14 @@ public class JobDAOTest {
List<JobService.JobDirection> directionList List<JobService.JobDirection> directionList
= List.of(JobService.JobDirection.pullFromVoSpace, = List.of(JobService.JobDirection.pullFromVoSpace,
JobService.JobDirection.pullToVoSpace); JobService.JobDirection.pullToVoSpace);
List<String> viewList = List.of(Views.TAR_VIEW_URI, Views.ZIP_VIEW_URI);
LocalDateTime ldt LocalDateTime ldt
= LocalDateTime.of(2013, Month.FEBRUARY, 7, 18, 15); = LocalDateTime.of(2013, Month.FEBRUARY, 7, 18, 15);
Optional<LocalDateTime> after = Optional.of(ldt); Optional<LocalDateTime> after = Optional.of(ldt);
Optional<Integer> last = Optional.of(2); Optional<Integer> last = Optional.of(2);
Jobs jobs = dao.getJobs(user, phaseList, directionList, after, last); Jobs jobs = dao.getJobs(user, phaseList, directionList, viewList, after, last);
List<ShortJobDescription> sjdList = jobs.getJobref(); List<ShortJobDescription> sjdList = jobs.getJobref();
assertEquals(1, sjdList.size()); assertEquals(1, sjdList.size());
assertEquals("pippo3", sjdList.get(0).getId()); assertEquals("pippo3", sjdList.get(0).getId());
......
...@@ -40,7 +40,7 @@ DELETE FROM job; ...@@ -40,7 +40,7 @@ DELETE FROM job;
INSERT INTO job (job_id, owner_id, job_type, phase, start_time, end_time, creation_time, job_info, results) VALUES ('pippo1', 'user1', 'pullFromVoSpace', 'ARCHIVED', NULL, NULL, '2011-06-22 19:10:25', NULL, NULL); INSERT INTO job (job_id, owner_id, job_type, phase, start_time, end_time, creation_time, job_info, results) VALUES ('pippo1', 'user1', 'pullFromVoSpace', 'ARCHIVED', NULL, NULL, '2011-06-22 19:10:25', NULL, NULL);
INSERT INTO job (job_id, owner_id, job_type, phase, start_time, end_time, creation_time, job_info, results) VALUES ('pippo2', 'user1', 'pullToVoSpace', 'PENDING', NULL, NULL, '2012-06-22 19:10:25', NULL, NULL); INSERT INTO job (job_id, owner_id, job_type, phase, start_time, end_time, creation_time, job_info, results) VALUES ('pippo2', 'user1', 'pullToVoSpace', 'PENDING', NULL, NULL, '2012-06-22 19:10:25', NULL, NULL);
INSERT INTO job (job_id, owner_id, job_type, phase, start_time, end_time, creation_time, job_info, results) VALUES ('pippo3', 'user1', 'pullFromVoSpace', 'QUEUED', NULL, NULL, '2013-06-22 19:10:25', NULL, NULL); INSERT INTO job (job_id, owner_id, job_type, phase, start_time, end_time, creation_time, job_info, results) VALUES ('pippo3', 'user1', 'pullFromVoSpace', 'QUEUED', NULL, NULL, '2013-06-22 19:10:25', '{"transfer": {"view": {"uri": "ivo://ia2.inaf.it/vospace/views#zip"}}}', NULL);
INSERT INTO job (job_id, owner_id, job_type, phase, start_time, end_time, creation_time, job_info, results) VALUES ('pippo4', 'user2', 'copyNode', 'PENDING', NULL, NULL, '2014-06-22 19:10:25', NULL, NULL); INSERT INTO job (job_id, owner_id, job_type, phase, start_time, end_time, creation_time, job_info, results) VALUES ('pippo4', 'user2', 'copyNode', 'PENDING', NULL, NULL, '2014-06-22 19:10:25', NULL, NULL);
INSERT INTO job (job_id, owner_id, job_type, phase, start_time, end_time, creation_time, job_info, results) VALUES ('pippo5', 'user1', 'pushToVoSpace', 'EXECUTING', NULL, NULL, '2015-06-22 19:10:25', NULL, NULL); INSERT INTO job (job_id, owner_id, job_type, phase, start_time, end_time, creation_time, job_info, results) VALUES ('pippo5', 'user1', 'pushToVoSpace', 'EXECUTING', NULL, NULL, '2015-06-22 19:10:25', NULL, NULL);
INSERT INTO job (job_id, owner_id, job_type, phase, start_time, end_time, creation_time, job_info, results) VALUES ('pippo6', 'user2', 'pullFromVoSpace', 'PENDING', NULL, NULL, '2015-06-22 19:10:25', NULL, NULL); INSERT INTO job (job_id, owner_id, job_type, phase, start_time, end_time, creation_time, job_info, results) VALUES ('pippo6', 'user2', 'pullFromVoSpace', 'PENDING', NULL, NULL, '2015-06-22 19:10:25', NULL, NULL);
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment