Skip to content
Toggle navigation
Projects
Groups
Snippets
Help
Codecrew
/
Moya
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
30
Merge Requests
2
Wiki
Snippets
Settings
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit 5f895d68
authored
Jun 04, 2018
by
Tuomas Riihimäki
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix error when saving empty t-shirt size
1 parent
7f5bb682
Pipeline
#67
passed
in 0 seconds
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
29 additions
and
10 deletions
code/moya-database/src/main/java/fi/codecrew/moya/model/GenericEntity.java
code/moya-database/src/main/java/fi/codecrew/moya/model/User.java
code/moya-database/src/main/java/fi/codecrew/moya/model/GenericEntity.java
View file @
5f895d6
...
...
@@ -21,6 +21,7 @@ package fi.codecrew.moya.model;
import
javax.json.Json
;
import
javax.json.JsonObject
;
import
javax.json.JsonObjectBuilder
;
import
javax.json.JsonValue
;
import
javax.persistence.Column
;
import
javax.persistence.Id
;
import
javax.persistence.MappedSuperclass
;
...
...
@@ -66,10 +67,28 @@ public class GenericEntity extends EntityEquals implements ModelInterface, Entit
@Transient
public
String
getMetaStringValue
(
String
key
)
{
try
{
return
getMeta
().
getString
(
key
);
JsonObject
m
=
getMeta
();
if
(
m
!=
null
&&
m
.
containsKey
(
key
))
{
return
getMeta
().
getString
(
key
);
}
}
catch
(
NullPointerException
e
)
{
// this is normal if key is not found etc.
return
""
;
}
return
""
;
}
@Transient
public
void
deleteMetaKey
(
String
key
){
final
JsonObject
m
=
getMeta
();
if
(
m
!=
null
){
JsonObjectBuilder
metaBuilder
=
Json
.
createObjectBuilder
();
getMeta
()
.
entrySet
()
.
stream
()
.
filter
(
e
->!
e
.
getKey
().
equals
(
key
))
.
forEach
(
e
->
metaBuilder
.
add
(
e
.
getKey
(),
e
.
getValue
()));
setMeta
(
metaBuilder
.
build
());
}
}
...
...
@@ -79,15 +98,10 @@ public class GenericEntity extends EntityEquals implements ModelInterface, Entit
JsonObjectBuilder
metaBuilder
=
Json
.
createObjectBuilder
();
if
(
getMeta
()
!=
null
)
{
for
(
String
valKey
:
getMeta
().
keySet
())
{
if
(!
valKey
.
equals
(
key
))
{
metaBuilder
.
add
(
valKey
,
getMeta
().
get
(
valKey
));
}
}
getMeta
().
entrySet
().
forEach
(
e
->
metaBuilder
.
add
(
e
.
getKey
(),
e
.
getValue
()));
}
metaBuilder
.
add
(
key
,
value
);
setMeta
(
metaBuilder
.
build
());
}
...
...
code/moya-database/src/main/java/fi/codecrew/moya/model/User.java
View file @
5f895d6
...
...
@@ -58,6 +58,7 @@ public class User extends GenericEntity implements IUser {
public
static
final
String
ANONYMOUS_LOGINNAME
=
"anonymous"
;
private
static
final
long
serialVersionUID
=
-
1632200627103418206L
;
private
static
final
String
SHIRT_SIZE_METAKEY
=
"shirtSize"
;
@Column
(
name
=
"created"
,
nullable
=
false
,
updatable
=
false
)
@Temporal
(
TemporalType
.
TIMESTAMP
)
...
...
@@ -433,12 +434,16 @@ public class User extends GenericEntity implements IUser {
@Transient
public
String
getShirtSize
()
{
return
getMetaStringValue
(
"shirtSize"
);
return
getMetaStringValue
(
SHIRT_SIZE_METAKEY
);
}
@Transient
public
void
setShirtSize
(
String
size
)
{
setMetaStringValue
(
"shirtSize"
,
size
);
if
(
size
==
null
||
size
.
isEmpty
()){
deleteMetaKey
(
SHIRT_SIZE_METAKEY
);
}
else
{
setMetaStringValue
(
SHIRT_SIZE_METAKEY
,
size
);
}
}
public
String
getLocale
()
{
...
...
Write
Preview
Markdown
is supported
Attach a file
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 post a comment