Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
minerva
core
Commits
49e87a6e
Commit
49e87a6e
authored
Jun 22, 2021
by
Piotr Gawron
Browse files
ConfigurationOptionSerializaer implemented
parent
41c1f1ba
Changes
5
Hide whitespace changes
Inline
Side-by-side
model/src/main/java/lcsb/mapviewer/model/user/ConfigurationOption.java
View file @
49e87a6e
...
...
@@ -4,6 +4,10 @@ import java.io.Serializable;
import
javax.persistence.*
;
import
com.fasterxml.jackson.databind.annotation.JsonSerialize
;
import
lcsb.mapviewer.modelutils.serializer.ConfigurationOptionSerializer
;
/**
* This class represents one configurable parameter of the system.
*
...
...
@@ -11,6 +15,7 @@ import javax.persistence.*;
*
*/
@Entity
@JsonSerialize
(
using
=
ConfigurationOptionSerializer
.
class
)
public
class
ConfigurationOption
implements
Serializable
{
/**
...
...
model/src/main/java/lcsb/mapviewer/modelutils/serializer/ConfigurationOptionSerializer.java
0 → 100644
View file @
49e87a6e
package
lcsb.mapviewer.modelutils.serializer
;
import
java.io.IOException
;
import
com.fasterxml.jackson.core.JsonGenerator
;
import
com.fasterxml.jackson.databind.JsonSerializer
;
import
com.fasterxml.jackson.databind.SerializerProvider
;
import
lcsb.mapviewer.model.user.ConfigurationElementEditType
;
import
lcsb.mapviewer.model.user.ConfigurationOption
;
public
class
ConfigurationOptionSerializer
extends
JsonSerializer
<
ConfigurationOption
>
{
@Override
public
void
serialize
(
final
ConfigurationOption
option
,
final
JsonGenerator
gen
,
final
SerializerProvider
serializers
)
throws
IOException
{
gen
.
writeStartObject
();
gen
.
writeNumberField
(
"idObject"
,
option
.
getId
());
gen
.
writeStringField
(
"type"
,
option
.
getType
().
name
());
gen
.
writeStringField
(
"valueType"
,
option
.
getType
().
getEditType
().
name
());
gen
.
writeStringField
(
"commonName"
,
option
.
getType
().
getCommonName
());
gen
.
writeBooleanField
(
"isServerSide"
,
option
.
getType
().
isServerSide
());
// don't send password over API
if
(!
option
.
getType
().
getEditType
().
equals
(
ConfigurationElementEditType
.
PASSWORD
))
{
gen
.
writeStringField
(
"value"
,
option
.
getValue
());
}
if
(
option
.
getType
().
getGroup
()
!=
null
)
{
gen
.
writeStringField
(
"group"
,
option
.
getType
().
getGroup
().
getCommonName
());
}
gen
.
writeEndObject
();
}
}
\ No newline at end of file
rest-api/src/main/java/lcsb/mapviewer/api/configuration/ConfigurationController.java
View file @
49e87a6e
...
...
@@ -19,6 +19,7 @@ import lcsb.mapviewer.annotation.services.dapi.DapiConnectionException;
import
lcsb.mapviewer.annotation.services.dapi.dto.UserDto
;
import
lcsb.mapviewer.api.BaseController
;
import
lcsb.mapviewer.model.security.PrivilegeType
;
import
lcsb.mapviewer.model.user.ConfigurationOption
;
import
lcsb.mapviewer.services.QueryException
;
import
lcsb.mapviewer.services.interfaces.IConfigurationService
;
...
...
@@ -65,11 +66,11 @@ public class ConfigurationController extends BaseController {
}
@GetMapping
(
value
=
"/options/"
)
public
List
<
Map
<
String
,
Object
>
>
getOptions
(
Authentication
authentication
)
{
public
List
<
ConfigurationOption
>
getOptions
(
Authentication
authentication
)
{
boolean
isAdmin
=
authentication
.
getAuthorities
()
.
contains
(
new
SimpleGrantedAuthority
(
PrivilegeType
.
IS_ADMIN
.
toString
()));
return
configurationRestImpl
.
getAllValues
().
stream
()
.
filter
(
option
->
!
((
Boolean
)
option
.
get
(
"
isServerSide
"
)
)
||
isAdmin
)
.
filter
(
option
->
!
option
.
get
Type
().
isServerSide
(
)
||
isAdmin
)
.
collect
(
Collectors
.
toList
());
}
...
...
@@ -103,7 +104,7 @@ public class ConfigurationController extends BaseController {
@PreAuthorize
(
"hasAuthority('IS_ADMIN')"
)
@PatchMapping
(
value
=
"/options/{option}"
)
public
Map
<
String
,
Object
>
updateOption
(
@RequestBody
String
body
,
@PathVariable
(
value
=
"option"
)
String
option
)
public
ConfigurationOption
updateOption
(
@RequestBody
String
body
,
@PathVariable
(
value
=
"option"
)
String
option
)
throws
IOException
,
QueryException
{
Map
<
String
,
Object
>
node
=
parseBody
(
body
);
Map
<
String
,
Object
>
data
=
getData
(
node
,
"option"
);
...
...
rest-api/src/main/java/lcsb/mapviewer/api/configuration/ConfigurationRestImpl.java
View file @
49e87a6e
...
...
@@ -30,7 +30,8 @@ import lcsb.mapviewer.model.map.species.Element;
import
lcsb.mapviewer.model.map.species.field.ModificationState
;
import
lcsb.mapviewer.model.overlay.DataOverlayType
;
import
lcsb.mapviewer.model.security.PrivilegeType
;
import
lcsb.mapviewer.model.user.*
;
import
lcsb.mapviewer.model.user.ConfigurationElementType
;
import
lcsb.mapviewer.model.user.ConfigurationOption
;
import
lcsb.mapviewer.model.user.annotator.BioEntityField
;
import
lcsb.mapviewer.modelutils.map.ClassTreeNode
;
import
lcsb.mapviewer.modelutils.map.ElementUtils
;
...
...
@@ -60,29 +61,8 @@ public class ConfigurationRestImpl extends BaseRestImpl {
this
.
dapiConnector
=
dapiConnector
;
}
public
List
<
Map
<
String
,
Object
>>
getAllValues
()
{
List
<
Map
<
String
,
Object
>>
result
=
new
ArrayList
<>();
for
(
ConfigurationOption
option
:
configurationService
.
getAllValues
())
{
result
.
add
(
optionToMap
(
option
));
}
return
result
;
}
private
Map
<
String
,
Object
>
optionToMap
(
ConfigurationOption
option
)
{
Map
<
String
,
Object
>
result
=
new
TreeMap
<>();
result
.
put
(
"idObject"
,
option
.
getId
());
result
.
put
(
"type"
,
option
.
getType
());
result
.
put
(
"valueType"
,
option
.
getType
().
getEditType
());
result
.
put
(
"commonName"
,
option
.
getType
().
getCommonName
());
result
.
put
(
"isServerSide"
,
option
.
getType
().
isServerSide
());
// don't send password over API
if
(!
option
.
getType
().
getEditType
().
equals
(
ConfigurationElementEditType
.
PASSWORD
))
{
result
.
put
(
"value"
,
option
.
getValue
());
}
if
(
option
.
getType
().
getGroup
()
!=
null
)
{
result
.
put
(
"group"
,
option
.
getType
().
getGroup
().
getCommonName
());
}
return
result
;
public
List
<
ConfigurationOption
>
getAllValues
()
{
return
configurationService
.
getAllValues
();
}
/**
...
...
@@ -269,7 +249,7 @@ public class ConfigurationRestImpl extends BaseRestImpl {
return
result
;
}
public
Map
<
String
,
Object
>
updateOption
(
String
option
,
Map
<
String
,
Object
>
data
)
throws
QueryException
{
public
ConfigurationOption
updateOption
(
String
option
,
Map
<
String
,
Object
>
data
)
throws
QueryException
{
ConfigurationElementType
type
=
ConfigurationElementType
.
valueOf
(
option
);
String
value
=
(
String
)
data
.
get
(
"value"
);
try
{
...
...
@@ -277,7 +257,7 @@ public class ConfigurationRestImpl extends BaseRestImpl {
}
catch
(
InvalidArgumentException
e
)
{
throw
new
QueryException
(
e
.
getMessage
(),
e
);
}
return
optionToMap
(
configurationService
.
getValue
(
type
)
)
;
return
configurationService
.
getValue
(
type
);
}
public
List
<
Map
<
String
,
Object
>>
getUnitTypes
()
{
...
...
rest-api/src/test/java/lcsb/mapviewer/api/configuration/ConfigurationRestImplTest.java
View file @
49e87a6e
...
...
@@ -14,6 +14,7 @@ import lcsb.mapviewer.model.map.MiriamType;
import
lcsb.mapviewer.model.map.reaction.type.StateTransitionReaction
;
import
lcsb.mapviewer.model.map.species.GenericProtein
;
import
lcsb.mapviewer.model.user.ConfigurationElementType
;
import
lcsb.mapviewer.model.user.ConfigurationOption
;
import
lcsb.mapviewer.model.user.annotator.BioEntityField
;
import
lcsb.mapviewer.services.QueryException
;
...
...
@@ -38,7 +39,7 @@ public class ConfigurationRestImplTest extends RestTestFunctions {
@Test
public
void
testGetAllParams
()
throws
Exception
{
List
<
Map
<
String
,
Object
>
>
list
=
configurationRestImpl
.
getAllValues
();
List
<
ConfigurationOption
>
list
=
configurationRestImpl
.
getAllValues
();
assertTrue
(
list
.
size
()
>
0
);
}
...
...
@@ -53,7 +54,7 @@ public class ConfigurationRestImplTest extends RestTestFunctions {
public
void
testSetSmtpPortToValid
()
throws
Exception
{
Map
<
String
,
Object
>
data
=
new
HashMap
<>();
data
.
put
(
"value"
,
"255"
);
Map
<
String
,
Object
>
result
=
configurationRestImpl
.
updateOption
(
ConfigurationOption
result
=
configurationRestImpl
.
updateOption
(
ConfigurationElementType
.
EMAIL_SMTP_PORT
.
name
(),
data
);
assertNotNull
(
result
);
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a 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