Newer
Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
/*
* 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.datamodel.NodeUtils;
import it.inaf.oats.vospace.exception.InternalFaultException;
import it.inaf.oats.vospace.exception.InvalidArgumentException;
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.persistence.NodeDAO;
import it.inaf.oats.vospace.persistence.NodeDAO.ShortNodeDescriptor;
import java.util.Optional;
import javax.servlet.http.HttpServletRequest;
import net.ivoa.xml.vospace.v2.Transfer;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.dao.CannotSerializeTransactionException;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.EnableTransactionManagement;
import org.springframework.transaction.annotation.Isolation;
import org.springframework.transaction.annotation.Transactional;
@Service
@EnableTransactionManagement
public class CopyService {
@Autowired
private NodeDAO nodeDao;
@Value("${vospace-authority}")
private String authority;
@Autowired
private HttpServletRequest servletRequest;
@Autowired
private NodeBranchService nodeBranchService;
public void processCopyJob(Transfer transfer, String jobId) {
if (transfer.getTarget().size() != 1) {
throw new InvalidArgumentException("Invalid target size for copyNode: " + transfer.getTarget().size());
}
// Get Source Vos Path
String sourcePath = URIUtils.returnVosPathFromNodeURI(transfer.getTarget().get(0), authority);
// Get Destination Vos Path (it's in transfer direction)
String destinationPath = URIUtils.returnVosPathFromNodeURI(transfer.getDirection(), authority);
// Extract User permissions from servlet request
User user = (User) servletRequest.getUserPrincipal();
this.validatePath(sourcePath);
this.validatePath(destinationPath);
if (sourcePath.equals(destinationPath)) {
return;
}
// check source branch for read and lock it
nodeBranchService.checkBranchForReadAndLock(sourcePath, jobId);
}
private void validatePath(String path) {
if (path.equals("/")) {
throw new IllegalArgumentException("Cannot move root node or to root node");
}
}
}