Commit 0ff866c7 authored by Grzegorz Pietrusza's avatar Grzegorz Pietrusza

PublicProperty stub

parent 86b387c7
package helpers;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
@Retention(RetentionPolicy.RUNTIME)
public @interface PublicProperty
{
}
......@@ -2,6 +2,7 @@ package objects.tasks;
import com.fasterxml.jackson.annotation.JsonInclude;
import core.TaskType;
import helpers.PublicProperty;
import objects.Flag;
import org.bson.types.ObjectId;
import org.mongodb.morphia.annotations.Entity;
......@@ -14,7 +15,9 @@ import java.util.List;
public class Task {
@Id
private ObjectId id;
@PublicProperty
private String name;
@PublicProperty
private int level;
private TaskType taskType;
private List<Flag> flags;
......
......@@ -2,6 +2,7 @@ package repositories;
import core.ApplicationConfiguration;
import core.TaskType;
import helpers.PublicProperty;
import helpers.TextTaskConfig;
import helpers.WebTaskConfig;
import objects.Flag;
......@@ -15,12 +16,15 @@ import org.mongodb.morphia.Datastore;
import javax.inject.Inject;
import javax.inject.Singleton;
import java.lang.reflect.Field;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.function.Predicate;
import java.util.stream.Collectors;
import java.util.stream.Stream;
@Singleton
public class TasksRepository implements Repository
......@@ -62,8 +66,16 @@ public class TasksRepository implements Repository
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)
.retrievedFields(true, "name", "level") //todo: move to configuration
.retrievedFields(true, collect.toArray(new String[collect.size()])) //todo: refactor
.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