Commit 35de28f6 authored by Grzegorz Pietrusza's avatar Grzegorz Pietrusza

move public fields to task class

parent 0ff866c7
...@@ -8,11 +8,15 @@ import org.bson.types.ObjectId; ...@@ -8,11 +8,15 @@ import org.bson.types.ObjectId;
import org.mongodb.morphia.annotations.Entity; import org.mongodb.morphia.annotations.Entity;
import org.mongodb.morphia.annotations.Id; import org.mongodb.morphia.annotations.Id;
import java.lang.reflect.Field;
import java.util.List; import java.util.List;
import java.util.stream.Collectors;
import java.util.stream.Stream;
@Entity("tasks") @Entity("tasks")
@JsonInclude(JsonInclude.Include.NON_NULL) @JsonInclude(JsonInclude.Include.NON_NULL)
public class Task { public class Task
{
@Id @Id
private ObjectId id; private ObjectId id;
@PublicProperty @PublicProperty
...@@ -23,7 +27,21 @@ public class Task { ...@@ -23,7 +27,21 @@ public class Task {
private List<Flag> flags; private List<Flag> flags;
private TaskContent taskContent; private TaskContent taskContent;
public Task(String name, int level, TaskType type, List<Flag> flags, TaskContent taskContent) { public static String[] getPublicFields()
{
//todo: move to db object?
//todo: move to task
Field[] declaredFields = Task.class.getDeclaredFields();
List<String> publicFieldsNames = Stream.of(declaredFields)
.filter(field -> field.getAnnotation(PublicProperty.class) != null)
.map(Field::getName)
.collect(Collectors.toList());
return publicFieldsNames.toArray(new String[publicFieldsNames.size()]);
}
public Task(String name, int level, TaskType type, List<Flag> flags, TaskContent taskContent)
{
this.flags = flags; this.flags = flags;
this.taskType = type; this.taskType = type;
this.level = level; this.level = level;
...@@ -31,45 +49,57 @@ public class Task { ...@@ -31,45 +49,57 @@ public class Task {
this.taskContent = taskContent; this.taskContent = taskContent;
} }
public Task() {} public Task()
{
}
public String getName() { public String getName()
{
return name; return name;
} }
public void setName(String name) { public void setName(String name)
{
this.name = name; this.name = name;
} }
public int getLevel() { public int getLevel()
{
return level; return level;
} }
public void setLevel(int level) { public void setLevel(int level)
{
this.level = level; this.level = level;
} }
public TaskType getTaskType() { public TaskType getTaskType()
{
return taskType; return taskType;
} }
public void setTaskType(TaskType taskType) { public void setTaskType(TaskType taskType)
{
this.taskType = taskType; this.taskType = taskType;
} }
public List<Flag> getFlags() { public List<Flag> getFlags()
{
return flags; return flags;
} }
public void setFlags(List<Flag> flags) { public void setFlags(List<Flag> flags)
{
this.flags = flags; this.flags = flags;
} }
public TaskContent getTaskContent() { public TaskContent getTaskContent()
{
return taskContent; return taskContent;
} }
public void setTaskContent(TaskContent taskContent) { public void setTaskContent(TaskContent taskContent)
{
this.taskContent = taskContent; this.taskContent = taskContent;
} }
} }
...@@ -66,16 +66,8 @@ public class TasksRepository implements Repository ...@@ -66,16 +66,8 @@ public class TasksRepository implements Repository
public List<Task> getAllPublic() public List<Task> getAllPublic()
{ {
//todo: move to db object?
//todo: move to task
Field[] declaredFields = Task.class.getDeclaredFields();
List<String> collect = Stream.of(declaredFields)
.filter(field -> field.getAnnotation(PublicProperty.class) != null)
.map(Field::getName)
.collect(Collectors.toList());
return datastore.createQuery(Task.class) return datastore.createQuery(Task.class)
.retrievedFields(true, collect.toArray(new String[collect.size()])) //todo: refactor .retrievedFields(true, Task.getPublicFields()) //todo: refactor
.asList(); .asList();
} }
......
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