Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
minerva
core
Commits
4a1890e9
Commit
4a1890e9
authored
Jul 22, 2021
by
Piotr Gawron
Browse files
update background moved to controller`
parent
743f5a2e
Changes
3
Hide whitespace changes
Inline
Side-by-side
rest-api/src/main/java/lcsb/mapviewer/api/projects/ProjectController.java
View file @
4a1890e9
...
...
@@ -3,6 +3,7 @@ package lcsb.mapviewer.api.projects;
import
java.io.IOException
;
import
java.util.List
;
import
java.util.Map
;
import
java.util.Objects
;
import
java.util.Optional
;
import
javax.servlet.ServletContext
;
...
...
@@ -27,7 +28,6 @@ import org.springframework.web.bind.annotation.RestController;
import
lcsb.mapviewer.annotation.services.annotators.AnnotatorException
;
import
lcsb.mapviewer.api.BaseController
;
import
lcsb.mapviewer.common.exception.InvalidArgumentException
;
import
lcsb.mapviewer.common.exception.NotImplementedException
;
import
lcsb.mapviewer.model.Project
;
import
lcsb.mapviewer.model.cache.FileEntry
;
import
lcsb.mapviewer.model.graphics.MapCanvasType
;
...
...
@@ -288,16 +288,54 @@ public class ProjectController extends BaseController {
return
projectController
.
removeBackground
(
projectId
,
backgroundId
);
}
static
class
BackgroundDTO
{
public
String
description
;
public
Integer
id
;
public
String
name
;
public
Integer
order
;
public
Boolean
defaultOverlay
;
public
String
creator
;
}
@PreAuthorize
(
"hasAuthority('IS_ADMIN')"
+
" or hasAuthority('IS_CURATOR') and hasAuthority('WRITE_PROJECT:' + #projectId)"
)
@PatchMapping
(
value
=
"/{projectId}/backgrounds/{backgroundId}"
)
public
ProjectBackground
updateBackground
(
@RequestBody
String
body
,
@RequestBody
BackgroundDTO
data
,
@PathVariable
(
value
=
"backgroundId"
)
Integer
backgroundId
,
@PathVariable
(
value
=
"projectId"
)
String
projectId
)
throws
QueryException
,
IOException
{
Map
<
String
,
Object
>
node
=
parseBody
(
body
);
return
projectController
.
updateBackground
(
projectId
,
backgroundId
,
node
);
ProjectBackground
background
=
getBackgroundById
(
projectId
,
backgroundId
);
if
(
data
.
description
!=
null
)
{
background
.
setDescription
(
data
.
description
);
}
if
(
data
.
id
!=
null
)
{
if
(!
Objects
.
equals
(
data
.
id
,
backgroundId
))
{
throw
new
QueryException
(
"cannot change id"
);
}
}
if
(
data
.
name
!=
null
)
{
if
(
data
.
name
.
trim
().
isEmpty
())
{
throw
new
QueryException
(
"name cannot be empty"
);
}
background
.
setName
(
data
.
name
);
}
if
(
data
.
order
!=
null
)
{
background
.
setOrderIndex
(
data
.
order
);
}
if
(
data
.
defaultOverlay
!=
null
)
{
background
.
setDefaultOverlay
(
data
.
defaultOverlay
);
}
if
(
data
.
creator
!=
null
)
{
User
user
=
userService
.
getUserByLogin
(
data
.
creator
);
if
(
user
==
null
)
{
throw
new
QueryException
(
"overlay creator must be defined"
);
}
background
.
setCreator
(
user
);
}
projectService
.
updateProject
(
background
.
getProject
());
return
getBackgroundById
(
projectId
,
backgroundId
);
}
public
ServletContext
getContext
()
{
...
...
rest-api/src/main/java/lcsb/mapviewer/api/projects/ProjectRestImpl.java
View file @
4a1890e9
...
...
@@ -606,38 +606,4 @@ public class ProjectRestImpl extends BaseRestImpl {
throw
new
ObjectNotFoundException
(
"Background does not exist"
);
}
public
ProjectBackground
updateBackground
(
String
projectId
,
Integer
overlayId
,
Map
<
String
,
Object
>
data
)
throws
QueryException
{
ProjectBackground
background
=
getBackgroundById
(
projectId
,
overlayId
);
for
(
String
key
:
data
.
keySet
())
{
Object
value
=
data
.
get
(
key
);
if
(
key
.
equalsIgnoreCase
(
"description"
))
{
background
.
setDescription
((
String
)
value
);
}
else
if
(
key
.
equalsIgnoreCase
(
"id"
))
{
if
(!
Objects
.
equals
(
value
,
overlayId
))
{
throw
new
QueryException
(
"cannot change id"
);
}
}
else
if
(
key
.
equalsIgnoreCase
(
"name"
))
{
if
(
value
==
null
||
((
String
)
value
).
trim
().
isEmpty
())
{
throw
new
QueryException
(
"name cannot be empty"
);
}
background
.
setName
((
String
)
value
);
}
else
if
(
key
.
equalsIgnoreCase
(
"order"
))
{
background
.
setOrderIndex
(
parseInteger
(
value
));
}
else
if
(
key
.
equalsIgnoreCase
(
"defaultOverlay"
))
{
background
.
setDefaultOverlay
(
parseBoolean
(
value
));
}
else
if
(
key
.
equalsIgnoreCase
(
"creator"
))
{
if
(
""
.
equals
(
value
))
{
throw
new
QueryException
(
"overlay creator must be defined"
);
}
else
if
(
value
!=
null
)
{
background
.
setCreator
(
getUserService
().
getUserByLogin
((
String
)
value
));
}
}
else
{
throw
new
QueryException
(
"Unknown parameter: "
+
key
);
}
}
getProjectService
().
updateProject
(
background
.
getProject
());
return
getBackgroundById
(
projectId
,
overlayId
);
}
}
web/src/test/java/lcsb/mapviewer/web/ProjectControllerIntegrationTest.java
View file @
4a1890e9
...
...
@@ -1051,6 +1051,7 @@ public class ProjectControllerIntegrationTest extends ControllerIntegrationTest
RequestBuilder
request
=
patch
(
"/api/projects/{projectId}/backgrounds/{backgroundId}"
,
TEST_PROJECT
,
project
.
getProjectBackgrounds
().
get
(
0
).
getId
())
.
contentType
(
MediaType
.
APPLICATION_JSON
)
.
session
(
session
)
.
content
(
mapper
.
writeValueAsString
(
background
));
...
...
Write
Preview
Supports
Markdown
0%
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!
Cancel
Please
register
or
sign in
to comment