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
flagHashMethod: "MD5"
testsTemporary:
- value: "a"
asdf: "ff"
- value: "a"
asdf: "ff"
- value: "a"
asdf: "ff"
- value: "a"
asdf: "ff"
teams:
- name: "misiaczki"
description: "misiaczki opis"
......
......@@ -17,6 +17,8 @@ public class ApplicationConfiguration extends Configuration {
private List<Team> teams;
private List<Test> testsTemporary;
public String getFlagHashMethod() {
return flagHashMethod;
}
......@@ -29,6 +31,14 @@ public class ApplicationConfiguration extends Configuration {
this.teams = teams;
}
public List<Test> getTestsTemporary() {
return testsTemporary;
}
public void setTestsTemporary(List<Test> testsTemporary) {
this.testsTemporary = testsTemporary;
}
public void setFlagHashMethod(String 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;
import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.google.common.collect.ImmutableMap;
import org.bson.Document;
......@@ -16,18 +18,15 @@ public class Team {
private String description;
private List<User> members;
public Team(Document document) {
//todo: refactor mapping
this.name = document.get("name").toString();
this.description = document.get("description").toString();
this.members = ((ArrayList<Document>) document.get("members")) //todo
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(document1 -> new User(document1))
.collect(Collectors.toList());
}
public Team() {
//dummy constructor for json
.map(User::fromDocument)
.collect(Collectors.toList())
);
//todo: refactor mapping
}
public List<User> getMembers() {
......@@ -38,7 +37,10 @@ public class Team {
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.description = description;
this.members = members;
......
package objects;
import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.google.common.collect.ImmutableMap;
import org.bson.Document;
......@@ -14,17 +16,17 @@ public class User implements Principal {
private String password;
private String email;
public User(Document document) {
this.name = document.get("name").toString();
this.password = document.get("password").toString();
this.email = document.get("password").toString();
public static User fromDocument(Document document) {
return new User(document.get("name").toString(),
document.get("password").toString(),
document.get("password").toString()
);
}
// public User() {
// dummy constructor for json
// }
public User(String name, String password, String email) {
@JsonCreator
public User(@JsonProperty("name") String name,
@JsonProperty("password") String password,
@JsonProperty("email") String email) {
this.name = name;
this.password = password;
this.email = email;
......
......@@ -45,7 +45,7 @@ public class TeamsRepository implements Repository {
public List<Team> getAll() {
return mongoDBConnector.getCollection("teams")
.stream()
.map(Team::new)
.map(Team::fromDocument)
.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