Loading src/main/java/it/inaf/oats/vospace/FileServiceClient.java +45 −15 Original line number Diff line number Diff line Loading @@ -7,14 +7,19 @@ package it.inaf.oats.vospace; import com.fasterxml.jackson.databind.ObjectMapper; import it.inaf.ia2.aa.data.User; import it.inaf.oats.vospace.datamodel.NodeUtils; import it.inaf.oats.vospace.datamodel.Views; import it.inaf.oats.vospace.exception.InvalidArgumentException; import it.inaf.oats.vospace.exception.NodeNotFoundException; import it.inaf.oats.vospace.parent.exchange.ArchiveEntryDescriptor; import it.inaf.oats.vospace.persistence.NodeDAO; import java.io.OutputStream; import java.util.ArrayList; import java.util.List; import java.util.stream.Collectors; import javax.servlet.http.HttpServletRequest; import net.ivoa.xml.vospace.v2.ContainerNode; import net.ivoa.xml.vospace.v2.Node; import net.ivoa.xml.vospace.v2.Transfer; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; Loading Loading @@ -45,6 +50,9 @@ public class FileServiceClient { @Autowired private LinkService linkService; @Autowired private NodeDAO nodeDAO; public String startArchiveJob(Transfer transfer, String jobId) { String target = transfer.getTarget().substring("vos://".length() + authority.length()); Loading @@ -70,10 +78,32 @@ public class FileServiceClient { vosPaths.add(target); } // OK generate descriptors // Generate descriptors // Expand container nodes into direct children list List<String> expandedVosPaths = new ArrayList<>(); for (String vosPath : vosPaths) { Node node = nodeDAO.listNode(vosPath) .orElseThrow(() -> { throw new NodeNotFoundException(vosPath); }); if (node instanceof ContainerNode) { List<Node> nodes = ((ContainerNode) node).getNodes(); if (nodes.isEmpty()) { expandedVosPaths.add(NodeUtils.getVosPath(node)); } else { expandedVosPaths.addAll(nodes .stream().map(n -> NodeUtils.getVosPath(n)) .collect(Collectors.toList())); } } } // follow links to links in vosPaths List<ArchiveEntryDescriptor> entryDescriptors = linkService.followLinksForArchiveService(vosPaths); List<ArchiveEntryDescriptor> entryDescriptors = linkService.followLinksForArchiveService(expandedVosPaths); ArchiveRequest archiveRequest = new ArchiveRequest(); archiveRequest.setJobId(jobId); Loading src/test/java/it/inaf/oats/vospace/FileServiceClientTest.java +21 −0 Original line number Diff line number Diff line Loading @@ -11,12 +11,16 @@ import it.inaf.oats.vospace.FileServiceClient.ArchiveRequest; import it.inaf.oats.vospace.datamodel.Views; import it.inaf.oats.vospace.exception.InvalidArgumentException; import it.inaf.oats.vospace.parent.exchange.ArchiveEntryDescriptor; import it.inaf.oats.vospace.persistence.NodeDAO; import java.io.ByteArrayOutputStream; import java.io.IOException; import java.io.UncheckedIOException; import java.net.URI; import java.util.List; import java.util.Optional; import javax.servlet.http.HttpServletRequest; import net.ivoa.xml.vospace.v2.ContainerNode; import net.ivoa.xml.vospace.v2.DataNode; import net.ivoa.xml.vospace.v2.Param; import net.ivoa.xml.vospace.v2.Transfer; import net.ivoa.xml.vospace.v2.View; Loading @@ -30,6 +34,7 @@ import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.eq; import org.mockito.InjectMocks; import org.mockito.Mock; import org.mockito.Mockito; import static org.mockito.Mockito.doAnswer; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; Loading Loading @@ -60,6 +65,9 @@ public class FileServiceClientTest { @Mock private LinkService linkService; @Mock private NodeDAO nodeDAO; @InjectMocks private FileServiceClient fileServiceClient; Loading Loading @@ -98,6 +106,11 @@ public class FileServiceClientTest { view.setUri(Views.ZIP_VIEW_URI); transfer.setView(view); ContainerNode node = Mockito.mock(ContainerNode.class); when(node.getNodes()).thenReturn(List.of()); when(node.getUri()).thenReturn("vos://example.com!vospace/mydir"); when(nodeDAO.listNode(eq("/mydir"))).thenReturn(Optional.of(node)); when(linkService.followLinksForArchiveService(any())) .thenReturn(List.of(new ArchiveEntryDescriptor("/mydir"))); Loading Loading @@ -162,6 +175,14 @@ public class FileServiceClientTest { param2.setValue("file2"); view.getParam().add(param2); DataNode node1 = Mockito.mock(DataNode.class); when(node1.getUri()).thenReturn("vos://example.com!vospace/parent_dir/file1"); when(nodeDAO.listNode(eq("/parent_dir/file1"))).thenReturn(Optional.of(node1)); DataNode node2 = Mockito.mock(DataNode.class); when(node2.getUri()).thenReturn("vos://example.com!vospace/parent_dir/file2"); when(nodeDAO.listNode(eq("/parent_dir/file2"))).thenReturn(Optional.of(node2)); when(linkService.followLinksForArchiveService(any())).thenReturn( List.of(new ArchiveEntryDescriptor("/parent_dir/file1"), new ArchiveEntryDescriptor("/parent_dir/file2") Loading src/test/java/it/inaf/oats/vospace/LinkServiceTest.java 0 → 100644 +61 −0 Original line number Diff line number Diff line /* * This file is part of vospace-rest * Copyright (C) 2021 Istituto Nazionale di Astrofisica * SPDX-License-Identifier: GPL-3.0-or-later */ package it.inaf.oats.vospace; import it.inaf.ia2.aa.data.User; import it.inaf.oats.vospace.exception.NodeBusyException; import it.inaf.oats.vospace.exception.NodeNotFoundException; import it.inaf.oats.vospace.exception.PermissionDeniedException; import it.inaf.oats.vospace.parent.exchange.ArchiveEntryDescriptor; import it.inaf.oats.vospace.persistence.DataSourceConfigSingleton; import it.inaf.oats.vospace.persistence.NodeDAO; import java.util.List; import java.util.Optional; import java.util.stream.Collectors; import net.ivoa.xml.vospace.v2.Transfer; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertThrows; import static org.junit.jupiter.api.Assertions.assertTrue; import org.junit.jupiter.api.MethodOrderer.OrderAnnotation; import org.junit.jupiter.api.Order; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.TestMethodOrder; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.test.annotation.DirtiesContext; import org.springframework.test.context.TestPropertySource; import org.springframework.test.context.ContextConfiguration; @SpringBootTest //@AutoConfigureMockMvc @TestPropertySource(locations = "classpath:test.properties", properties = {"vospace-authority=example.com!vospace", "file-service-url=http://file-service"}) @ContextConfiguration(classes = {DataSourceConfigSingleton.class}) public class LinkServiceTest { @Autowired private LinkService linkService; @Test public void testFollowLinksForArchiveService() { List<String> vosPaths = List.of("/test3/m1/link2", "/test3/m1/m2"); List<ArchiveEntryDescriptor> aed = linkService.followLinksForArchiveService(vosPaths); assertEquals(2, aed.size()); List<String> targetVosPaths = aed.stream().map(a -> a.getTargetNodeVosPath()) .collect(Collectors.toList()); System.out.println(targetVosPaths); assertTrue(targetVosPaths.containsAll(List.of("/test3/m1/m2", "/test1/f1/f2_renamed/f3"))); } } src/test/resources/test-data.sql +1 −0 Original line number Diff line number Diff line Loading @@ -43,6 +43,7 @@ INSERT INTO node (parent_path, parent_relative_path, name, type, creator_id, gro INSERT INTO node (parent_path, parent_relative_path, name, type, creator_id, group_write, group_read, is_public, location_id) VALUES ('19', '', 'destination2', 'container', 'user3', '{"group1"}', '{"group1"}', false, 3); -- /mycontainer/destination2 INSERT INTO node (parent_path, parent_relative_path, name, type, creator_id, group_write, group_read, is_public, location_id) VALUES ('19.21', '20', 'control', 'container', 'user3', '{"group1"}', '{"group1"}', false, 3); -- /mycontainer/destination2/control INSERT INTO node (parent_path, parent_relative_path, name, type, creator_id, group_write, group_read, is_public, location_id, target) VALUES ('9.10', '', 'link2', 'link', 'user3', '{"group1"}', '{"group1"}', false, 3, 'vos://example.com!vospace/test1/f1/f2_renamed/f3'); -- /test3/m1/link2 DELETE FROM job; Loading src/main/java/it/inaf/oats/vospace/LinkService.java +1 −1 File changed.Contains only whitespace changes. Show changes Loading
src/main/java/it/inaf/oats/vospace/FileServiceClient.java +45 −15 Original line number Diff line number Diff line Loading @@ -7,14 +7,19 @@ package it.inaf.oats.vospace; import com.fasterxml.jackson.databind.ObjectMapper; import it.inaf.ia2.aa.data.User; import it.inaf.oats.vospace.datamodel.NodeUtils; import it.inaf.oats.vospace.datamodel.Views; import it.inaf.oats.vospace.exception.InvalidArgumentException; import it.inaf.oats.vospace.exception.NodeNotFoundException; import it.inaf.oats.vospace.parent.exchange.ArchiveEntryDescriptor; import it.inaf.oats.vospace.persistence.NodeDAO; import java.io.OutputStream; import java.util.ArrayList; import java.util.List; import java.util.stream.Collectors; import javax.servlet.http.HttpServletRequest; import net.ivoa.xml.vospace.v2.ContainerNode; import net.ivoa.xml.vospace.v2.Node; import net.ivoa.xml.vospace.v2.Transfer; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; Loading Loading @@ -45,6 +50,9 @@ public class FileServiceClient { @Autowired private LinkService linkService; @Autowired private NodeDAO nodeDAO; public String startArchiveJob(Transfer transfer, String jobId) { String target = transfer.getTarget().substring("vos://".length() + authority.length()); Loading @@ -70,10 +78,32 @@ public class FileServiceClient { vosPaths.add(target); } // OK generate descriptors // Generate descriptors // Expand container nodes into direct children list List<String> expandedVosPaths = new ArrayList<>(); for (String vosPath : vosPaths) { Node node = nodeDAO.listNode(vosPath) .orElseThrow(() -> { throw new NodeNotFoundException(vosPath); }); if (node instanceof ContainerNode) { List<Node> nodes = ((ContainerNode) node).getNodes(); if (nodes.isEmpty()) { expandedVosPaths.add(NodeUtils.getVosPath(node)); } else { expandedVosPaths.addAll(nodes .stream().map(n -> NodeUtils.getVosPath(n)) .collect(Collectors.toList())); } } } // follow links to links in vosPaths List<ArchiveEntryDescriptor> entryDescriptors = linkService.followLinksForArchiveService(vosPaths); List<ArchiveEntryDescriptor> entryDescriptors = linkService.followLinksForArchiveService(expandedVosPaths); ArchiveRequest archiveRequest = new ArchiveRequest(); archiveRequest.setJobId(jobId); Loading
src/test/java/it/inaf/oats/vospace/FileServiceClientTest.java +21 −0 Original line number Diff line number Diff line Loading @@ -11,12 +11,16 @@ import it.inaf.oats.vospace.FileServiceClient.ArchiveRequest; import it.inaf.oats.vospace.datamodel.Views; import it.inaf.oats.vospace.exception.InvalidArgumentException; import it.inaf.oats.vospace.parent.exchange.ArchiveEntryDescriptor; import it.inaf.oats.vospace.persistence.NodeDAO; import java.io.ByteArrayOutputStream; import java.io.IOException; import java.io.UncheckedIOException; import java.net.URI; import java.util.List; import java.util.Optional; import javax.servlet.http.HttpServletRequest; import net.ivoa.xml.vospace.v2.ContainerNode; import net.ivoa.xml.vospace.v2.DataNode; import net.ivoa.xml.vospace.v2.Param; import net.ivoa.xml.vospace.v2.Transfer; import net.ivoa.xml.vospace.v2.View; Loading @@ -30,6 +34,7 @@ import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.eq; import org.mockito.InjectMocks; import org.mockito.Mock; import org.mockito.Mockito; import static org.mockito.Mockito.doAnswer; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; Loading Loading @@ -60,6 +65,9 @@ public class FileServiceClientTest { @Mock private LinkService linkService; @Mock private NodeDAO nodeDAO; @InjectMocks private FileServiceClient fileServiceClient; Loading Loading @@ -98,6 +106,11 @@ public class FileServiceClientTest { view.setUri(Views.ZIP_VIEW_URI); transfer.setView(view); ContainerNode node = Mockito.mock(ContainerNode.class); when(node.getNodes()).thenReturn(List.of()); when(node.getUri()).thenReturn("vos://example.com!vospace/mydir"); when(nodeDAO.listNode(eq("/mydir"))).thenReturn(Optional.of(node)); when(linkService.followLinksForArchiveService(any())) .thenReturn(List.of(new ArchiveEntryDescriptor("/mydir"))); Loading Loading @@ -162,6 +175,14 @@ public class FileServiceClientTest { param2.setValue("file2"); view.getParam().add(param2); DataNode node1 = Mockito.mock(DataNode.class); when(node1.getUri()).thenReturn("vos://example.com!vospace/parent_dir/file1"); when(nodeDAO.listNode(eq("/parent_dir/file1"))).thenReturn(Optional.of(node1)); DataNode node2 = Mockito.mock(DataNode.class); when(node2.getUri()).thenReturn("vos://example.com!vospace/parent_dir/file2"); when(nodeDAO.listNode(eq("/parent_dir/file2"))).thenReturn(Optional.of(node2)); when(linkService.followLinksForArchiveService(any())).thenReturn( List.of(new ArchiveEntryDescriptor("/parent_dir/file1"), new ArchiveEntryDescriptor("/parent_dir/file2") Loading
src/test/java/it/inaf/oats/vospace/LinkServiceTest.java 0 → 100644 +61 −0 Original line number Diff line number Diff line /* * This file is part of vospace-rest * Copyright (C) 2021 Istituto Nazionale di Astrofisica * SPDX-License-Identifier: GPL-3.0-or-later */ package it.inaf.oats.vospace; import it.inaf.ia2.aa.data.User; import it.inaf.oats.vospace.exception.NodeBusyException; import it.inaf.oats.vospace.exception.NodeNotFoundException; import it.inaf.oats.vospace.exception.PermissionDeniedException; import it.inaf.oats.vospace.parent.exchange.ArchiveEntryDescriptor; import it.inaf.oats.vospace.persistence.DataSourceConfigSingleton; import it.inaf.oats.vospace.persistence.NodeDAO; import java.util.List; import java.util.Optional; import java.util.stream.Collectors; import net.ivoa.xml.vospace.v2.Transfer; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertThrows; import static org.junit.jupiter.api.Assertions.assertTrue; import org.junit.jupiter.api.MethodOrderer.OrderAnnotation; import org.junit.jupiter.api.Order; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.TestMethodOrder; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.test.annotation.DirtiesContext; import org.springframework.test.context.TestPropertySource; import org.springframework.test.context.ContextConfiguration; @SpringBootTest //@AutoConfigureMockMvc @TestPropertySource(locations = "classpath:test.properties", properties = {"vospace-authority=example.com!vospace", "file-service-url=http://file-service"}) @ContextConfiguration(classes = {DataSourceConfigSingleton.class}) public class LinkServiceTest { @Autowired private LinkService linkService; @Test public void testFollowLinksForArchiveService() { List<String> vosPaths = List.of("/test3/m1/link2", "/test3/m1/m2"); List<ArchiveEntryDescriptor> aed = linkService.followLinksForArchiveService(vosPaths); assertEquals(2, aed.size()); List<String> targetVosPaths = aed.stream().map(a -> a.getTargetNodeVosPath()) .collect(Collectors.toList()); System.out.println(targetVosPaths); assertTrue(targetVosPaths.containsAll(List.of("/test3/m1/m2", "/test1/f1/f2_renamed/f3"))); } }
src/test/resources/test-data.sql +1 −0 Original line number Diff line number Diff line Loading @@ -43,6 +43,7 @@ INSERT INTO node (parent_path, parent_relative_path, name, type, creator_id, gro INSERT INTO node (parent_path, parent_relative_path, name, type, creator_id, group_write, group_read, is_public, location_id) VALUES ('19', '', 'destination2', 'container', 'user3', '{"group1"}', '{"group1"}', false, 3); -- /mycontainer/destination2 INSERT INTO node (parent_path, parent_relative_path, name, type, creator_id, group_write, group_read, is_public, location_id) VALUES ('19.21', '20', 'control', 'container', 'user3', '{"group1"}', '{"group1"}', false, 3); -- /mycontainer/destination2/control INSERT INTO node (parent_path, parent_relative_path, name, type, creator_id, group_write, group_read, is_public, location_id, target) VALUES ('9.10', '', 'link2', 'link', 'user3', '{"group1"}', '{"group1"}', false, 3, 'vos://example.com!vospace/test1/f1/f2_renamed/f3'); -- /test3/m1/link2 DELETE FROM job; Loading
src/main/java/it/inaf/oats/vospace/LinkService.java +1 −1 File changed.Contains only whitespace changes. Show changes