132 lines
3.6 KiB
Java
132 lines
3.6 KiB
Java
package eu.eudat.criteria;
|
|
|
|
import com.fasterxml.jackson.core.type.TypeReference;
|
|
import com.fasterxml.jackson.databind.JsonNode;
|
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
|
import com.fasterxml.jackson.databind.ObjectReader;
|
|
import com.fasterxml.jackson.databind.node.JsonNodeType;
|
|
import eu.eudat.criteria.entities.Criteria;
|
|
import eu.eudat.criteria.entities.DateCriteria;
|
|
import eu.eudat.logic.services.operations.DatabaseRepository;
|
|
import eu.eudat.query.ProjectQuery;
|
|
|
|
import java.io.IOException;
|
|
import java.util.*;
|
|
|
|
public class ProjectCriteria {
|
|
private Criteria<UUID> id;
|
|
private List<UUID> ids;
|
|
private Criteria<String> label;
|
|
private List<Integer> statuses;
|
|
private DateCriteria created;
|
|
private DateCriteria modified;
|
|
private UserCriteria creator;
|
|
|
|
public Criteria<UUID> getId() {
|
|
return id;
|
|
}
|
|
|
|
public void setId(JsonNode jsonNode) throws IOException {
|
|
if (jsonNode.getNodeType().equals(JsonNodeType.STRING)) {
|
|
Criteria<UUID> criteria = new Criteria<>();
|
|
criteria.setAs(jsonNode.asText());
|
|
this.id = criteria;
|
|
} else if (jsonNode.getNodeType().equals(JsonNodeType.OBJECT)) {
|
|
ObjectReader reader = new ObjectMapper().readerFor(new TypeReference<Criteria<UUID>>() {
|
|
});
|
|
this.id = reader.readValue(jsonNode);
|
|
}
|
|
}
|
|
|
|
public List<UUID> getIds() {
|
|
return ids;
|
|
}
|
|
|
|
public void setIds(List<UUID> ids) {
|
|
this.ids = ids;
|
|
}
|
|
|
|
public Criteria<String> getLabel() {
|
|
return label;
|
|
}
|
|
|
|
public void setLabel(JsonNode jsonNode) throws IOException {
|
|
if (jsonNode.getNodeType().equals(JsonNodeType.STRING)) {
|
|
Criteria<String> criteria = new Criteria<>();
|
|
criteria.setAs(jsonNode.asText());
|
|
this.label = criteria;
|
|
} else if (jsonNode.getNodeType().equals(JsonNodeType.OBJECT)) {
|
|
ObjectReader reader = new ObjectMapper().readerFor(new TypeReference<Criteria<String>>() {});
|
|
this.label = reader.readValue(jsonNode);
|
|
}
|
|
}
|
|
|
|
public void setLabel(String label) {
|
|
Criteria<String> criteria = new Criteria<>();
|
|
criteria.setAs(label);
|
|
this.label = criteria;
|
|
}
|
|
|
|
public List<Integer> getStatuses() {
|
|
return statuses;
|
|
}
|
|
|
|
public void setStatuses(List<Integer> statuses) {
|
|
this.statuses = statuses;
|
|
}
|
|
|
|
public DateCriteria getCreated() {
|
|
return created;
|
|
}
|
|
|
|
public void setCreated(DateCriteria created) {
|
|
this.created = created;
|
|
}
|
|
|
|
public void setCreated(String created) {
|
|
DateCriteria criteria = new DateCriteria();
|
|
criteria.setAs(created);
|
|
this.created = criteria;
|
|
}
|
|
|
|
public DateCriteria getModified() {
|
|
return modified;
|
|
}
|
|
|
|
public void setModified(DateCriteria modified) {
|
|
this.modified = modified;
|
|
}
|
|
|
|
public void setModified(String modified) {
|
|
DateCriteria criteria = new DateCriteria();
|
|
criteria.setAs(modified);
|
|
this.modified = criteria;
|
|
}
|
|
|
|
public UserCriteria getCreator() {
|
|
return creator;
|
|
}
|
|
|
|
public void setCreator(UserCriteria creator) {
|
|
this.creator = creator;
|
|
}
|
|
|
|
protected List<String> buildFields(String path) {
|
|
Set<String> fields = new HashSet<>();
|
|
path = path != null && !path.isEmpty() ? path + "." : "";
|
|
if (this.creator != null) fields.addAll(this.creator.buildFields(path + "creationUser"));
|
|
if (this.id != null) fields.add(path + this.id.getAs());
|
|
if (this.label != null) fields.add(path + this.label.getAs());
|
|
if (!fields.contains(path + "id")) fields.add(path + "id");
|
|
return new LinkedList<>(fields);
|
|
}
|
|
|
|
public ProjectQuery buildQuery(DatabaseRepository dao) {
|
|
List<String> fields = this.buildFields("");
|
|
ProjectQuery query = new ProjectQuery(dao.getProjectDao(), fields);
|
|
query.setId(this.id.getValue());
|
|
if (this.creator != null) query.setUserQuery(this.creator.buildQuery(dao));
|
|
return query;
|
|
}
|
|
}
|