Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
nmaas Platform
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Terraform modules
Analyze
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
nmaas
nmaas Platform
Commits
62fcbc38
Commit
62fcbc38
authored
10 months ago
by
kbeyro
Browse files
Options
Downloads
Patches
Plain Diff
cherry pick
d6830306
parent
62393f7f
Branches
Branches containing commit
Tags
Tags containing commit
2 merge requests
!41
release/1.6.4 into 'develop'
,
!33
1.6.4 merge
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/main/java/net/geant/nmaas/portal/api/bulk/BulkController.java
+62
-16
62 additions, 16 deletions
.../java/net/geant/nmaas/portal/api/bulk/BulkController.java
with
62 additions
and
16 deletions
src/main/java/net/geant/nmaas/portal/api/bulk/BulkController.java
+
62
−
16
View file @
62fcbc38
...
@@ -14,9 +14,11 @@ import net.geant.nmaas.portal.service.BulkDomainService;
...
@@ -14,9 +14,11 @@ import net.geant.nmaas.portal.service.BulkDomainService;
import
net.geant.nmaas.portal.service.UserService
;
import
net.geant.nmaas.portal.service.UserService
;
import
org.modelmapper.ModelMapper
;
import
org.modelmapper.ModelMapper
;
import
org.springframework.core.io.InputStreamResource
;
import
org.springframework.core.io.InputStreamResource
;
import
org.springframework.dao.PermissionDeniedDataAccessException
;
import
org.springframework.http.HttpHeaders
;
import
org.springframework.http.HttpHeaders
;
import
org.springframework.http.ResponseEntity
;
import
org.springframework.http.ResponseEntity
;
import
org.springframework.security.access.prepost.PreAuthorize
;
import
org.springframework.security.access.prepost.PreAuthorize
;
import
org.springframework.web.bind.annotation.DeleteMapping
;
import
org.springframework.web.bind.annotation.GetMapping
;
import
org.springframework.web.bind.annotation.GetMapping
;
import
org.springframework.web.bind.annotation.PathVariable
;
import
org.springframework.web.bind.annotation.PathVariable
;
import
org.springframework.web.bind.annotation.PostMapping
;
import
org.springframework.web.bind.annotation.PostMapping
;
...
@@ -30,6 +32,7 @@ import java.security.Principal;
...
@@ -30,6 +32,7 @@ import java.security.Principal;
import
java.util.HashMap
;
import
java.util.HashMap
;
import
java.util.List
;
import
java.util.List
;
import
java.util.Map
;
import
java.util.Map
;
import
java.util.Optional
;
import
java.util.stream.Collectors
;
import
java.util.stream.Collectors
;
@RestController
@RestController
...
@@ -91,17 +94,14 @@ public class BulkController {
...
@@ -91,17 +94,14 @@ public class BulkController {
@GetMapping
@GetMapping
@PreAuthorize
(
"hasRole('ROLE_SYSTEM_ADMIN')"
)
@PreAuthorize
(
"hasRole('ROLE_SYSTEM_ADMIN')"
)
public
ResponseEntity
<
List
<
BulkDeploymentViewS
>>
getAllDeploymentRecords
()
{
public
ResponseEntity
<
List
<
BulkDeploymentViewS
>>
getAllDeploymentRecords
()
{
return
ResponseEntity
.
ok
(
mapToView
(
bulkDeploymentRepository
.
findAll
()));
return
ResponseEntity
.
ok
(
mapToView
List
(
bulkDeploymentRepository
.
findAll
()));
}
}
@GetMapping
(
"/{id}"
)
@GetMapping
(
"/{id}"
)
@PreAuthorize
(
"hasRole('ROLE_SYSTEM_ADMIN') || hasRole('ROLE_VL_MANAGER')"
)
@PreAuthorize
(
"hasRole('ROLE_SYSTEM_ADMIN') || hasRole('ROLE_VL_MANAGER')"
)
public
ResponseEntity
<
BulkDeploymentView
>
getDeploymentRecord
(
@PathVariable
Long
id
)
{
public
ResponseEntity
<
BulkDeploymentView
>
getDeploymentRecord
(
@PathVariable
Long
id
)
{
BulkDeployment
bulk
=
bulkDeploymentRepository
.
findById
(
id
).
orElseThrow
();
BulkDeployment
bulk
=
bulkDeploymentRepository
.
findById
(
id
).
orElseThrow
();
BulkDeploymentView
bulkView
=
modelMapper
.
map
(
bulk
,
BulkDeploymentView
.
class
);
return
ResponseEntity
.
ok
(
mapToView
(
bulk
,
BulkDeploymentView
.
class
));
bulkView
.
setCreator
(
getUserView
(
bulk
.
getCreatorId
()));
mapDetails
(
bulk
,
bulkView
);
return
ResponseEntity
.
ok
(
bulkView
);
}
}
@GetMapping
(
value
=
"/app/csv/{id}"
,
produces
=
"text/csv"
)
@GetMapping
(
value
=
"/app/csv/{id}"
,
produces
=
"text/csv"
)
...
@@ -124,7 +124,7 @@ public class BulkController {
...
@@ -124,7 +124,7 @@ public class BulkController {
@GetMapping
(
"/domains"
)
@GetMapping
(
"/domains"
)
@PreAuthorize
(
"hasRole('ROLE_SYSTEM_ADMIN')"
)
@PreAuthorize
(
"hasRole('ROLE_SYSTEM_ADMIN')"
)
public
ResponseEntity
<
List
<
BulkDeploymentViewS
>>
getDomainDeploymentRecords
()
{
public
ResponseEntity
<
List
<
BulkDeploymentViewS
>>
getDomainDeploymentRecords
()
{
return
ResponseEntity
.
ok
(
mapToView
(
bulkDeploymentRepository
.
findByType
(
BulkType
.
DOMAIN
)));
return
ResponseEntity
.
ok
(
mapToView
List
(
bulkDeploymentRepository
.
findByType
(
BulkType
.
DOMAIN
)));
}
}
@GetMapping
(
"/domains/vl"
)
@GetMapping
(
"/domains/vl"
)
...
@@ -132,14 +132,14 @@ public class BulkController {
...
@@ -132,14 +132,14 @@ public class BulkController {
public
ResponseEntity
<
List
<
BulkDeploymentViewS
>>
getDomainDeploymentRecordsRestrictedToOwner
(
Principal
principal
)
{
public
ResponseEntity
<
List
<
BulkDeploymentViewS
>>
getDomainDeploymentRecordsRestrictedToOwner
(
Principal
principal
)
{
User
user
=
this
.
userService
.
findByUsername
(
principal
.
getName
()).
orElseThrow
(()
->
new
MissingElementException
(
"Missing user "
+
principal
.
getName
()));
User
user
=
this
.
userService
.
findByUsername
(
principal
.
getName
()).
orElseThrow
(()
->
new
MissingElementException
(
"Missing user "
+
principal
.
getName
()));
return
ResponseEntity
.
ok
(
mapToView
(
bulkDeploymentRepository
.
findByType
(
BulkType
.
DOMAIN
)).
stream
()
return
ResponseEntity
.
ok
(
mapToView
List
(
bulkDeploymentRepository
.
findByType
(
BulkType
.
DOMAIN
)).
stream
()
.
filter
(
bulk
->
bulk
.
getCreator
().
getId
().
equals
(
user
.
getId
())).
collect
(
Collectors
.
toList
()));
.
filter
(
bulk
->
bulk
.
getCreator
().
getId
().
equals
(
user
.
getId
())).
collect
(
Collectors
.
toList
()));
}
}
@GetMapping
(
"/apps"
)
@GetMapping
(
"/apps"
)
@PreAuthorize
(
"hasRole('ROLE_SYSTEM_ADMIN')"
)
@PreAuthorize
(
"hasRole('ROLE_SYSTEM_ADMIN')"
)
public
ResponseEntity
<
List
<
BulkDeploymentViewS
>>
getAppDeploymentRecords
()
{
public
ResponseEntity
<
List
<
BulkDeploymentViewS
>>
getAppDeploymentRecords
()
{
return
ResponseEntity
.
ok
(
mapToView
(
bulkDeploymentRepository
.
findByType
(
BulkType
.
APPLICATION
)));
return
ResponseEntity
.
ok
(
mapToView
List
(
bulkDeploymentRepository
.
findByType
(
BulkType
.
APPLICATION
)));
}
}
@GetMapping
(
"/apps/vl"
)
@GetMapping
(
"/apps/vl"
)
...
@@ -147,21 +147,67 @@ public class BulkController {
...
@@ -147,21 +147,67 @@ public class BulkController {
public
ResponseEntity
<
List
<
BulkDeploymentViewS
>>
getAppDeploymentRecordsRestrictedToOwner
(
Principal
principal
)
{
public
ResponseEntity
<
List
<
BulkDeploymentViewS
>>
getAppDeploymentRecordsRestrictedToOwner
(
Principal
principal
)
{
User
user
=
this
.
userService
.
findByUsername
(
principal
.
getName
()).
orElseThrow
(()
->
new
MissingElementException
(
"Missing user "
+
principal
.
getName
()));
User
user
=
this
.
userService
.
findByUsername
(
principal
.
getName
()).
orElseThrow
(()
->
new
MissingElementException
(
"Missing user "
+
principal
.
getName
()));
return
ResponseEntity
.
ok
(
mapToView
(
bulkDeploymentRepository
.
findByType
(
BulkType
.
APPLICATION
)).
stream
()
return
ResponseEntity
.
ok
(
mapToView
List
(
bulkDeploymentRepository
.
findByType
(
BulkType
.
APPLICATION
)).
stream
()
.
filter
(
bulk
->
bulk
.
getCreator
().
getId
().
equals
(
user
.
getId
())).
collect
(
Collectors
.
toList
()));
.
filter
(
bulk
->
bulk
.
getCreator
().
getId
().
equals
(
user
.
getId
())).
collect
(
Collectors
.
toList
()));
}
}
@DeleteMapping
(
"/{id}"
)
@PreAuthorize
(
"hasRole('ROLE_SYSTEM_ADMIN') || hasRole('ROLE_VL_MANAGER')"
)
public
ResponseEntity
<
Void
>
removeBulkDeployment
(
@PathVariable
Long
id
,
@RequestParam
(
name
=
"removeAll"
)
boolean
removeApps
,
Principal
principal
)
{
User
user
=
this
.
userService
.
findByUsername
(
principal
.
getName
()).
orElseThrow
(()
->
new
MissingElementException
(
"Missing user "
+
principal
.
getName
()));
Optional
<
BulkDeployment
>
bulk
=
this
.
bulkDeploymentRepository
.
findById
(
id
);
if
(
bulk
.
isEmpty
())
{
return
ResponseEntity
.
notFound
().
build
();
}
if
(
bulk
.
get
().
getCreatorId
().
equals
(
user
.
getId
())
)
{
throw
new
PermissionDeniedDataAccessException
(
"User doesnt have access to this bulk deployment"
,
new
Throwable
());
}
if
(
removeApps
)
{
bulkApplicationService
.
deleteAppInstancesFromBulk
(
mapToView
(
bulk
.
get
(),
BulkDeploymentView
.
class
));
}
bulkDeploymentRepository
.
delete
(
bulk
.
get
());
return
ResponseEntity
.
ok
().
build
();
}
private
List
<
BulkDeploymentViewS
>
mapToViewList
(
List
<
BulkDeployment
>
deployments
)
{
return
deployments
.
stream
()
.
map
(
bulk
->
mapToView
(
bulk
,
BulkDeploymentViewS
.
class
))
.
collect
(
Collectors
.
toList
());
}
@GetMapping
(
"/refresh/{id}"
)
@PreAuthorize
(
"hasRole('ROLE_SYSTEM_ADMIN') || hasRole('ROLE_VL_MANAGER')"
)
public
ResponseEntity
<
BulkDeploymentViewS
>
getRefreshedState
(
@PathVariable
Long
id
)
{
return
ResponseEntity
.
ok
(
mapToView
(
this
.
bulkApplicationService
.
updateState
(
id
)));
}
private
List
<
BulkDeploymentViewS
>
mapToView
(
List
<
BulkDeployment
>
deployments
)
{
private
List
<
BulkDeploymentViewS
>
mapToView
(
List
<
BulkDeployment
>
deployments
)
{
return
deployments
.
stream
()
return
deployments
.
stream
()
.
map
(
bulk
->
{
.
map
(
bulk
->
mapToView
(
bulk
,
BulkDeploymentViewS
.
class
))
BulkDeploymentViewS
bulkView
=
modelMapper
.
map
(
bulk
,
BulkDeploymentViewS
.
class
);
bulkView
.
setCreator
(
getUserView
(
bulk
.
getCreatorId
()));
mapDetails
(
bulk
,
bulkView
);
return
bulkView
;
})
.
collect
(
Collectors
.
toList
());
.
collect
(
Collectors
.
toList
());
}
}
private
<
T
extends
BulkDeploymentViewS
>
T
mapToView
(
BulkDeployment
bulk
,
Class
<
T
>
viewType
)
{
T
bulkView
=
modelMapper
.
map
(
bulk
,
viewType
);
bulkView
.
setCreator
(
getUserView
(
bulk
.
getCreatorId
()));
mapDetails
(
bulk
,
bulkView
);
return
bulkView
;
}
private
BulkDeploymentView
mapToView
(
BulkDeployment
deployment
)
{
BulkDeploymentView
bulkView
=
modelMapper
.
map
(
deployment
,
BulkDeploymentView
.
class
);
bulkView
.
setCreator
(
getUserView
(
deployment
.
getCreatorId
()));
mapDetails
(
deployment
,
bulkView
);
return
bulkView
;
}
private
void
mapDetails
(
BulkDeployment
deployment
,
BulkDeploymentViewS
view
)
{
private
void
mapDetails
(
BulkDeployment
deployment
,
BulkDeploymentViewS
view
)
{
if
(
deployment
.
getType
().
equals
(
BulkType
.
APPLICATION
))
{
if
(
deployment
.
getType
().
equals
(
BulkType
.
APPLICATION
))
{
Map
<
String
,
String
>
details
=
new
HashMap
<>();
Map
<
String
,
String
>
details
=
new
HashMap
<>();
...
...
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