Adds Criteria Serialization
This commit is contained in:
parent
93f69979ba
commit
120e16f714
|
@ -97,8 +97,8 @@ public class ProjectQuery extends Query<Project, UUID> {
|
|||
if (this.getStatuses() != null && !this.getStatuses().isEmpty())
|
||||
query.where((builder, root) -> root.get("status").in(this.getStatuses()));
|
||||
if (this.userQuery != null) {
|
||||
Subquery<UserInfo> userInfoSubquery = this.userQuery.getQuery().query(Arrays.asList(new SelectionField(FieldSelectionType.FIELD, "id")));
|
||||
query.where((builder, root) -> root.get("creationUser").get("id").in(userInfoSubquery));
|
||||
Subquery<UserInfo> userInfoSubQuery = this.userQuery.getQuery().query(Arrays.asList(new SelectionField(FieldSelectionType.FIELD, "id")));
|
||||
query.where((builder, root) -> root.get("creationUser").get("id").in(userInfoSubQuery));
|
||||
}
|
||||
if (!this.getSelectionFields().isEmpty() && this.getSelectionFields() != null) {
|
||||
query.withFields(this.getSelectionFields());
|
||||
|
|
|
@ -1,16 +1,29 @@
|
|||
package eu.eudat.configurations;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonInclude;
|
||||
import com.fasterxml.jackson.databind.Module;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.fasterxml.jackson.databind.module.SimpleModule;
|
||||
import eu.eudat.criteria.entities.Criteria;
|
||||
import eu.eudat.criteria.serialzier.CriteriaSerializer;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
@Configuration
|
||||
public class JacksonConfiguration {
|
||||
@Bean
|
||||
public ObjectMapper buildObjectMapper() {
|
||||
|
||||
ArrayList<Module> modules = new ArrayList<>();
|
||||
SimpleModule criteriaSerializerModule = new SimpleModule();
|
||||
criteriaSerializerModule.addDeserializer(Criteria.class, new CriteriaSerializer());
|
||||
modules.add(criteriaSerializerModule);
|
||||
|
||||
return new ObjectMapper().setSerializationInclusion(JsonInclude.Include.NON_NULL)
|
||||
.setSerializationInclusion(JsonInclude.Include.NON_ABSENT)
|
||||
.setSerializationInclusion(JsonInclude.Include.NON_EMPTY);
|
||||
.setSerializationInclusion(JsonInclude.Include.NON_EMPTY)
|
||||
.registerModules(modules);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -127,13 +127,13 @@ public class DMPCriteria {
|
|||
}
|
||||
|
||||
protected List<String> buildFields(String path) {
|
||||
Set<String> fields = new HashSet<>();
|
||||
Set<String> fields = new LinkedHashSet<>();
|
||||
path = path != null && !path.isEmpty() ? path + "." : "";
|
||||
if (this.id != null) fields.add(path + this.id.getAs());
|
||||
if (this.label != null) fields.add(path + this.label.getAs());
|
||||
if (this.project != null) fields.addAll(this.project.buildFields(path + "project"));
|
||||
if (this.creator != null) fields.addAll(this.creator.buildFields(path + "creator"));
|
||||
if (this.dataset != null) fields.addAll(this.dataset.buildFields(path + "dataset"));
|
||||
if (this.label != null) fields.add(path + this.label.getAs());
|
||||
if (!fields.contains(path + "id")) fields.add(path + "id");
|
||||
return new LinkedList<>(fields);
|
||||
}
|
||||
|
|
|
@ -1,16 +1,9 @@
|
|||
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 {
|
||||
|
@ -26,16 +19,8 @@ public class ProjectCriteria {
|
|||
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 void setId(Criteria<UUID> id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public List<UUID> getIds() {
|
||||
|
@ -50,15 +35,8 @@ public class ProjectCriteria {
|
|||
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(Criteria<String> label) {
|
||||
this.label = label;
|
||||
}
|
||||
|
||||
public void setLabel(String label) {
|
||||
|
@ -112,12 +90,12 @@ public class ProjectCriteria {
|
|||
}
|
||||
|
||||
protected List<String> buildFields(String path) {
|
||||
Set<String> fields = new HashSet<>();
|
||||
Set<String> fields = new LinkedHashSet<>();
|
||||
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");
|
||||
if (this.creator != null) fields.addAll(this.creator.buildFields(path + "creationUser"));
|
||||
return new LinkedList<>(fields);
|
||||
}
|
||||
|
||||
|
|
|
@ -49,7 +49,7 @@ public class UserCriteria {
|
|||
}
|
||||
|
||||
protected List<String> buildFields(String path) {
|
||||
Set<String> fields = new HashSet<>();
|
||||
Set<String> fields = new LinkedHashSet<>();
|
||||
path = path != null && !path.isEmpty() ? path + "." : "";
|
||||
if (this.id != null) fields.add(path + this.id.getAs());
|
||||
if (this.email != null) fields.add(path + this.email.getAs());
|
||||
|
|
|
@ -0,0 +1,41 @@
|
|||
package eu.eudat.criteria.serialzier;
|
||||
|
||||
import com.fasterxml.jackson.core.JsonParser;
|
||||
import com.fasterxml.jackson.core.ObjectCodec;
|
||||
import com.fasterxml.jackson.core.type.TypeReference;
|
||||
import com.fasterxml.jackson.databind.*;
|
||||
import com.fasterxml.jackson.databind.deser.ContextualDeserializer;
|
||||
import com.fasterxml.jackson.databind.node.JsonNodeType;
|
||||
import eu.eudat.criteria.entities.Criteria;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
public class CriteriaSerializer extends JsonDeserializer<Criteria<?>> implements ContextualDeserializer {
|
||||
|
||||
private JavaType valueType;
|
||||
|
||||
@Override
|
||||
public JsonDeserializer<?> createContextual(DeserializationContext ctxt, BeanProperty property) {
|
||||
JavaType wrapperType = property.getType();
|
||||
JavaType valueType = wrapperType.containedType(0);
|
||||
CriteriaSerializer deserializer = new CriteriaSerializer();
|
||||
deserializer.valueType = valueType;
|
||||
return deserializer;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Criteria<?> deserialize(JsonParser jp, DeserializationContext ctxt) throws IOException {
|
||||
ObjectCodec oc = jp.getCodec();
|
||||
JsonNode jsonNode = oc.readTree(jp);
|
||||
if (jsonNode.getNodeType().equals(JsonNodeType.STRING)) {
|
||||
Criteria<?> criteria = new Criteria<>();
|
||||
criteria.setAs(jsonNode.asText());
|
||||
return criteria;
|
||||
} else if (jsonNode.getNodeType().equals(JsonNodeType.OBJECT)) {
|
||||
ObjectReader reader = new ObjectMapper().readerFor(new TypeReference<Criteria<?>>() {
|
||||
});
|
||||
return reader.readValue(jsonNode);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue