Commit 4fdffdc0 authored by Grzegorz Pietrusza's avatar Grzegorz Pietrusza

use jsoncreator and jsonproperty to avoid constructing problems

parent 849c83b4
...@@ -4,6 +4,16 @@ dbName: db ...@@ -4,6 +4,16 @@ dbName: db
flagHashMethod: "MD5" flagHashMethod: "MD5"
testsTemporary:
- value: "a"
asdf: "ff"
- value: "a"
asdf: "ff"
- value: "a"
asdf: "ff"
- value: "a"
asdf: "ff"
teams: teams:
- name: "misiaczki" - name: "misiaczki"
description: "misiaczki opis" description: "misiaczki opis"
......
...@@ -17,6 +17,8 @@ public class ApplicationConfiguration extends Configuration { ...@@ -17,6 +17,8 @@ public class ApplicationConfiguration extends Configuration {
private List<Team> teams; private List<Team> teams;
private List<Test> testsTemporary;
public String getFlagHashMethod() { public String getFlagHashMethod() {
return flagHashMethod; return flagHashMethod;
} }
...@@ -29,6 +31,14 @@ public class ApplicationConfiguration extends Configuration { ...@@ -29,6 +31,14 @@ public class ApplicationConfiguration extends Configuration {
this.teams = teams; this.teams = teams;
} }
public List<Test> getTestsTemporary() {
return testsTemporary;
}
public void setTestsTemporary(List<Test> testsTemporary) {
this.testsTemporary = testsTemporary;
}
public void setFlagHashMethod(String flagHashMethod) { public void setFlagHashMethod(String flagHashMethod) {
this.flagHashMethod = flagHashMethod; this.flagHashMethod = flagHashMethod;
} }
......
package core;
/**
* Created by gpietrus on 21.02.2016.
*/
public class Test {
private String value;
private String asdf;
public String getValue() {
return value;
}
public void setValue(String value) {
this.value = value;
}
public String getAsdf() {
return asdf;
}
public void setAsdf(String asdf) {
this.asdf = asdf;
}
}
package objects; package objects;
import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableMap;
import org.bson.Document; import org.bson.Document;
...@@ -16,18 +18,15 @@ public class Team { ...@@ -16,18 +18,15 @@ public class Team {
private String description; private String description;
private List<User> members; private List<User> members;
public Team(Document document) { public static Team fromDocument(Document document) {
return new Team(document.get("name").toString(),
document.get("description").toString(),
((ArrayList<Document>) document.get("members")) //todo
.stream()
.map(User::fromDocument)
.collect(Collectors.toList())
);
//todo: refactor mapping //todo: refactor mapping
this.name = document.get("name").toString();
this.description = document.get("description").toString();
this.members = ((ArrayList<Document>) document.get("members")) //todo
.stream()
.map(document1 -> new User(document1))
.collect(Collectors.toList());
}
public Team() {
//dummy constructor for json
} }
public List<User> getMembers() { public List<User> getMembers() {
...@@ -38,7 +37,10 @@ public class Team { ...@@ -38,7 +37,10 @@ public class Team {
this.members = members; this.members = members;
} }
public Team(String name, String description, List<User> members) { @JsonCreator
public Team(@JsonProperty("name") String name,
@JsonProperty("description") String description,
@JsonProperty("members") List<User> members) {
this.name = name; this.name = name;
this.description = description; this.description = description;
this.members = members; this.members = members;
......
package objects; package objects;
import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableMap;
import org.bson.Document; import org.bson.Document;
...@@ -14,17 +16,17 @@ public class User implements Principal { ...@@ -14,17 +16,17 @@ public class User implements Principal {
private String password; private String password;
private String email; private String email;
public User(Document document) { public static User fromDocument(Document document) {
this.name = document.get("name").toString(); return new User(document.get("name").toString(),
this.password = document.get("password").toString(); document.get("password").toString(),
this.email = document.get("password").toString(); document.get("password").toString()
);
} }
// public User() { @JsonCreator
// dummy constructor for json public User(@JsonProperty("name") String name,
// } @JsonProperty("password") String password,
@JsonProperty("email") String email) {
public User(String name, String password, String email) {
this.name = name; this.name = name;
this.password = password; this.password = password;
this.email = email; this.email = email;
......
...@@ -45,7 +45,7 @@ public class TeamsRepository implements Repository { ...@@ -45,7 +45,7 @@ public class TeamsRepository implements Repository {
public List<Team> getAll() { public List<Team> getAll() {
return mongoDBConnector.getCollection("teams") return mongoDBConnector.getCollection("teams")
.stream() .stream()
.map(Team::new) .map(Team::fromDocument)
.collect(Collectors.toList()); .collect(Collectors.toList());
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment