Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
V
vospace-rest
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Redmine
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Terraform modules
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
VOSpace INAF
vospace-rest
Merge requests
!1
Immutable
Code
Review changes
Check out branch
Download
Patches
Plain diff
Merged
Immutable
immutable
into
master
Overview
0
Commits
5
Pipelines
0
Changes
1
Merged
Nicola Fulvio Calabria
requested to merge
immutable
into
master
2 years ago
Overview
0
Commits
5
Pipelines
0
Changes
1
Expand
Add immutable flag to nodes and prevent move and delete of immutable nodes
0
0
Merge request reports
Viewing commit
93dd552b
Prev
Next
Show latest version
1 file
+
34
−
21
Inline
Compare changes
Side-by-side
Inline
Show whitespace changes
Show one file at a time
93dd552b
Added busy and immutable management to delete
· 93dd552b
Nicola Fulvio Calabria
authored
2 years ago
src/main/java/it/inaf/oats/vospace/DeleteNodeService.java
+
34
−
21
Options
@@ -20,69 +20,82 @@ import org.springframework.stereotype.Service;
import
org.springframework.transaction.annotation.EnableTransactionManagement
;
import
org.springframework.transaction.annotation.Isolation
;
import
it.inaf.ia2.aa.data.User
;
import
it.inaf.oats.vospace.exception.InternalFaultException
;
import
it.inaf.oats.vospace.exception.NodeBusyException
;
import
org.springframework.transaction.annotation.Transactional
;
/**
*
* @author Nicola Fulvio Calabria <nicola.calabria at inaf.it>
*/
@Service
@EnableTransactionManagement
public
class
DeleteNodeService
{
@Autowired
protected
NodeDAO
nodeDao
;
@Value
(
"${vospace-authority}"
)
protected
String
authority
;
@Transactional
(
rollbackFor
=
{
Exception
.
class
},
@Transactional
(
rollbackFor
=
{
Exception
.
class
},
isolation
=
Isolation
.
REPEATABLE_READ
)
public
void
deleteNode
(
String
path
,
User
principal
)
{
public
void
deleteNode
(
String
path
,
User
principal
)
{
Node
toBeDeletedNode
=
nodeDao
.
listNode
(
path
)
.
orElseThrow
(()
->
new
NodeNotFoundException
(
path
));
.
orElseThrow
(()
->
new
NodeNotFoundException
(
path
));
if
(!
NodeUtils
.
checkIfWritable
(
toBeDeletedNode
,
principal
.
getName
(),
principal
.
getGroups
()))
{
throw
PermissionDeniedException
.
forPath
(
path
);
}
nodeDao
.
deleteNode
(
path
);
Long
nodeId
=
nodeDao
.
getNodeId
(
path
).
get
();
if
(
nodeDao
.
isBranchBusy
(
nodeId
))
{
throw
new
NodeBusyException
(
path
);
}
if
(
nodeDao
.
isBranchImmutable
(
nodeId
))
{
throw
new
InternalFaultException
(
"Target branch contains immutable nodes"
);
}
nodeDao
.
deleteNode
(
path
);
}
public
void
doPreliminaryChecks
(
String
path
)
throws
Exception
{
// Check if the node is present,
// if the node does not exist the service SHALL throw a HTTP 404 status code
// including a NodeNotFound fault in the entity-body
// If note present, got it
nodeDao
.
listNode
(
path
)
.
orElseThrow
(()
->
new
NodeNotFoundException
(
path
));
.
orElseThrow
(()
->
new
NodeNotFoundException
(
path
));
// If a parent node in the URI path is a LinkNode, the service SHALL throw
// a HTTP 400 status code including a LinkFound fault in the entity-body.
// For example, given the URI path /a/b/c, the service must throw a HTTP 400
// status code including a LinkFound fault in the entity-body if either /a
// or /a/b are LinkNodes.
List
<
String
>
pathComponents
=
NodeUtils
.
subPathComponents
(
path
);
if
(
pathComponents
.
isEmpty
())
{
if
(
pathComponents
.
isEmpty
())
{
// Manage root node
throw
PermissionDeniedException
.
forPath
(
"/"
);
}
else
{
// Manage all precursors in full path
for
(
int
i
=
0
;
i
<
pathComponents
.
size
();
i
++)
{
for
(
int
i
=
0
;
i
<
pathComponents
.
size
();
i
++)
{
String
tmpPath
=
pathComponents
.
get
(
i
);
Node
mynode
=
nodeDao
.
listNode
(
tmpPath
)
.
orElseThrow
(()
->
new
NodeNotFoundException
(
tmpPath
));
if
(
mynode
.
getType
().
equals
(
"vos:LinkNode"
)
&&
i
<
pathComponents
.
size
()-
1
)
// a LinkNode leaf can be deleted
if
(
mynode
.
getType
().
equals
(
"vos:LinkNode"
)
&&
i
<
pathComponents
.
size
()
-
1
)
// a LinkNode leaf can be deleted
{
throw
new
LinkFoundException
(
tmpPath
);
}
}
}
}
}
Loading