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
Commits
2e24dfee
Commit
2e24dfee
authored
4 years ago
by
Sara Bertocco
Browse files
Options
Downloads
Patches
Plain Diff
Recursive setNode added
parent
d361b285
No related branches found
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/main/java/it/inaf/oats/vospace/persistence/NodeDAO.java
+81
-1
81 additions, 1 deletion
src/main/java/it/inaf/oats/vospace/persistence/NodeDAO.java
with
81 additions
and
1 deletion
src/main/java/it/inaf/oats/vospace/persistence/NodeDAO.java
+
81
−
1
View file @
2e24dfee
...
@@ -12,8 +12,11 @@ import java.sql.SQLException;
...
@@ -12,8 +12,11 @@ import java.sql.SQLException;
import
java.sql.Types
;
import
java.sql.Types
;
import
java.util.ArrayList
;
import
java.util.ArrayList
;
import
java.util.Arrays
;
import
java.util.Arrays
;
import
java.util.HashSet
;
import
java.util.List
;
import
java.util.List
;
import
java.util.Map
;
import
java.util.Optional
;
import
java.util.Optional
;
import
java.util.Set
;
import
java.util.function.Function
;
import
java.util.function.Function
;
import
java.util.stream.Collectors
;
import
java.util.stream.Collectors
;
import
javax.sql.DataSource
;
import
javax.sql.DataSource
;
...
@@ -147,6 +150,9 @@ public class NodeDAO {
...
@@ -147,6 +150,9 @@ public class NodeDAO {
return
ps
;
return
ps
;
});
});
if
(
recursive
==
true
)
updatePermissionsRecursively
(
newNode
,
vosPath
);
return
newNode
;
return
newNode
;
}
}
...
@@ -367,6 +373,79 @@ public class NodeDAO {
...
@@ -367,6 +373,79 @@ public class NodeDAO {
}
}
/*
Map contains:
Key column
column name value
column name value
and value is a String containing comma separated groups having permissions
*/
private
Map
getPermissionsFromDB
(
String
vosPath
)
{
String
sql
=
"SELECT group_read, group_write "
+
"FROM node n JOIN node_vos_path p ON n.node_id = p.node_id "
+
"WHERE p.vos_path = ?"
;
Map
<
String
,
Object
>
result
=
(
Map
<
String
,
Object
>)
jdbcTemplate
.
queryForMap
(
sql
,
new
Object
[]
{
vosPath
});
return
result
;
}
private
void
updatePermissionsRecursively
(
Node
newNode
,
String
vosPath
)
{
Map
permissions
=
getPermissionsFromDB
(
vosPath
);
String
existingGroupReadStr
=
(
String
)
permissions
.
get
(
"group_read"
);
String
existingGroupWriteStr
=
(
String
)
permissions
.
get
(
"group_write"
);
List
<
String
>
existingGroupReadList
=
NodeProperties
.
parsePropertyStringToList
(
existingGroupReadStr
);
List
<
String
>
existingGroupWriteList
=
NodeProperties
.
parsePropertyStringToList
(
existingGroupWriteStr
);
List
<
String
>
newGroupReadList
=
NodeProperties
.
getNodePropertyAsListByURI
(
newNode
,
NodeProperties
.
GROUP_READ_URI
);
List
<
String
>
newGroupWriteList
=
NodeProperties
.
getNodePropertyAsListByURI
(
newNode
,
NodeProperties
.
GROUP_WRITE_URI
);
Set
<
String
>
existingGroupRead
=
new
HashSet
<>(
existingGroupReadList
);
Set
<
String
>
existingGroupWrite
=
new
HashSet
<>(
existingGroupWriteList
);
Set
<
String
>
newGroupRead
=
new
HashSet
<>(
newGroupReadList
);
Set
<
String
>
newGroupWrite
=
new
HashSet
<>(
newGroupWriteList
);
Set
<
String
>
groupReadToAdd
=
differenceBetweenSets
(
newGroupRead
,
existingGroupRead
)
;
Set
<
String
>
groupReadToRemove
=
differenceBetweenSets
(
existingGroupRead
,
newGroupRead
)
;
Set
<
String
>
groupWriteToAdd
=
differenceBetweenSets
(
newGroupWrite
,
existingGroupWrite
)
;
Set
<
String
>
groupWriteToRemove
=
differenceBetweenSets
(
existingGroupWrite
,
newGroupWrite
)
;
String
sql
=
"UPDATE node SET "
+
"group_read = update_array(group_read, "
+
groupReadToAdd
+
", "
+
groupReadToRemove
+
"), "
+
"group_write = update_array(group_write, "
+
groupWriteToAdd
+
", "
+
groupWriteToRemove
+
"), "
+
"is_public = ? "
+
"WHERE path <@ (SELECT path FROM node n "
+
"JOIN node_vos_path p ON n.node_id = p.node_id "
+
"AND p.vos_path = ?)"
;
jdbcTemplate
.
update
(
conn
->
{
PreparedStatement
ps
=
conn
.
prepareStatement
(
sql
);
int
i
=
0
;
ps
.
setBoolean
(++
i
,
Boolean
.
valueOf
(
NodeProperties
.
getNodePropertyByURI
(
newNode
,
NodeProperties
.
PUBLIC_READ_URI
)));
ps
.
setString
(++
i
,
vosPath
);
return
ps
;
});
}
// Returns the difference a minus b
private
Set
<
String
>
differenceBetweenSets
(
Set
<
String
>
a
,
Set
<
String
>
b
)
{
Set
<
String
>
diff
=
new
HashSet
<>(
a
);
diff
.
removeAll
(
b
);
return
diff
;
}
private
List
<
NodePaths
>
getNodePathsFromDB
(
String
nodeURI
)
{
private
List
<
NodePaths
>
getNodePathsFromDB
(
String
nodeURI
)
{
String
path
=
nodeURI
.
replaceAll
(
"vos://[^/]+"
,
""
);
String
path
=
nodeURI
.
replaceAll
(
"vos://[^/]+"
,
""
);
...
@@ -412,4 +491,5 @@ public class NodeDAO {
...
@@ -412,4 +491,5 @@ public class NodeDAO {
}
}
}
}
}
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment