Skip to content

Commit

Permalink
Add endpoint allowing fields and searchAfter #267
Browse files Browse the repository at this point in the history
  • Loading branch information
patrick-austin committed Mar 26, 2022
1 parent b44091d commit 07a42a3
Show file tree
Hide file tree
Showing 14 changed files with 919 additions and 467 deletions.
37 changes: 37 additions & 0 deletions src/main/java/org/icatproject/core/entity/Datafile.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
import java.io.Serializable;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.json.stream.JsonGenerator;
import javax.persistence.CascadeType;
Expand All @@ -20,7 +22,10 @@
import javax.persistence.UniqueConstraint;
import javax.xml.bind.annotation.XmlRootElement;

import org.icatproject.core.IcatException;
import org.icatproject.core.manager.EntityInfoHandler;
import org.icatproject.core.manager.SearchApi;
import org.icatproject.core.manager.EntityInfoHandler.Relationship;

@Comment("A data file")
@SuppressWarnings("serial")
Expand Down Expand Up @@ -77,6 +82,8 @@ public class Datafile extends EntityBaseBean implements Serializable {
@OneToMany(cascade = CascadeType.ALL, mappedBy = "sourceDatafile")
private List<RelatedDatafile> sourceDatafiles = new ArrayList<RelatedDatafile>();

private static final Map<String, Relationship[]> documentFields = new HashMap<>();

/* Needed for JPA */
public Datafile() {
}
Expand Down Expand Up @@ -220,4 +227,34 @@ public void getDoc(JsonGenerator gen, SearchApi searchApi) {

// TODO User and Parameter support for Elasticsearch
}

/**
* Gets the fields used in the search component for this entity, and the
* relationships that would restrict the content of those fields.
*
* @return Map of field names (as they appear on the search document) against
* the Relationships that need to be allowed for that field to be
* viewable. If there are no restrictive relationships, then the value
* will be null.
* @throws IcatException If the EntityInfoHandler cannot find one of the
* Relationships.
*/
public static Map<String, Relationship[]> getDocumentFields() throws IcatException {
if (documentFields.size() == 0) {
EntityInfoHandler eiHandler = EntityInfoHandler.getInstance();
Relationship[] textRelationships = {
eiHandler.getRelationshipsByName(Datafile.class).get("datafileFormat") };
Relationship[] investigationRelationships = {
eiHandler.getRelationshipsByName(Datafile.class).get("dataset"),
eiHandler.getRelationshipsByName(Dataset.class).get("investigation") }; // TODO check if we need this
documentFields.put("text", textRelationships);
documentFields.put("name", null);
documentFields.put("date", null);
documentFields.put("id", null);
documentFields.put("dataset", null);
documentFields.put("investigation", investigationRelationships);
}
return documentFields;
}

}
34 changes: 34 additions & 0 deletions src/main/java/org/icatproject/core/entity/Dataset.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
import java.io.Serializable;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.json.stream.JsonGenerator;
import javax.persistence.CascadeType;
Expand All @@ -19,7 +21,10 @@
import javax.persistence.UniqueConstraint;
import javax.xml.bind.annotation.XmlRootElement;

import org.icatproject.core.IcatException;
import org.icatproject.core.manager.EntityInfoHandler;
import org.icatproject.core.manager.SearchApi;
import org.icatproject.core.manager.EntityInfoHandler.Relationship;

@Comment("A collection of data files and part of an investigation")
@SuppressWarnings("serial")
Expand Down Expand Up @@ -81,6 +86,8 @@ public void setDataCollectionDatasets(List<DataCollectionDataset> dataCollection
@ManyToOne(fetch = FetchType.LAZY)
private DatasetType type;

private static final Map<String, Relationship[]> documentFields = new HashMap<>();

/* Needed for JPA */
public Dataset() {
}
Expand Down Expand Up @@ -223,4 +230,31 @@ public void getDoc(JsonGenerator gen, SearchApi searchApi) {
// TODO User, Parameter and Sample support for Elasticsearch
}

/**
* Gets the fields used in the search component for this entity, and the
* relationships that would restrict the content of those fields.
*
* @return Map of field names (as they appear on the search document) against
* the Relationships that need to be allowed for that field to be
* viewable. If there are no restrictive relationships, then the value
* will be null.
* @throws IcatException If the EntityInfoHandler cannot find one of the
* Relationships.
*/
public static Map<String, Relationship[]> getDocumentFields() throws IcatException {
if (documentFields.size() == 0) {
EntityInfoHandler eiHandler = EntityInfoHandler.getInstance();
Relationship[] textRelationships = { eiHandler.getRelationshipsByName(Dataset.class).get("type") };
Relationship[] investigationRelationships = {
eiHandler.getRelationshipsByName(Dataset.class).get("investigation") };
documentFields.put("text", textRelationships);
documentFields.put("name", null);
documentFields.put("startDate", null);
documentFields.put("endDate", null);
documentFields.put("id", null);
documentFields.put("investigation", investigationRelationships);
}
return documentFields;
}

}
50 changes: 43 additions & 7 deletions src/main/java/org/icatproject/core/entity/Investigation.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
import java.io.Serializable;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.json.stream.JsonGenerator;
import javax.persistence.CascadeType;
Expand All @@ -18,7 +20,10 @@
import javax.persistence.TemporalType;
import javax.persistence.UniqueConstraint;

import org.icatproject.core.IcatException;
import org.icatproject.core.manager.EntityInfoHandler;
import org.icatproject.core.manager.SearchApi;
import org.icatproject.core.manager.EntityInfoHandler.Relationship;

@Comment("An investigation or experiment")
@SuppressWarnings("serial")
Expand Down Expand Up @@ -93,6 +98,8 @@ public class Investigation extends EntityBaseBean implements Serializable {
@Column(name = "VISIT_ID", nullable = false)
private String visitId;

private static final Map<String, Relationship[]> documentFields = new HashMap<>();

/* Needed for JPA */
public Investigation() {
}
Expand Down Expand Up @@ -285,25 +292,29 @@ public void getDoc(JsonGenerator gen, SearchApi searchApi) {
}

investigationUsers.forEach((investigationUser) -> {
searchApi.encodeStringField(gen, "userName", investigationUser.getUser().getName());
searchApi.encodeTextField(gen, "userFullName", investigationUser.getUser().getFullName());
searchApi.encodeStringField(gen, "userName", investigationUser.getUser().getName());
searchApi.encodeTextField(gen, "userFullName", investigationUser.getUser().getFullName());
});


samples.forEach((sample) -> {
// searchApi.encodeSortedSetDocValuesFacetField(gen, "sampleName", sample.getName());
searchApi.encodeTextField(gen, "sampleText", sample.getDocText());
// searchApi.encodeSortedSetDocValuesFacetField(gen, "sampleName",
// sample.getName());
searchApi.encodeTextField(gen, "sampleText", sample.getDocText());
});

for (InvestigationParameter parameter : parameters) {
ParameterType type = parameter.type;
String parameterName = type.getName();
String parameterUnits = type.getUnits();
// searchApi.encodeSortedSetDocValuesFacetField(gen, "parameterName", parameterName);
// searchApi.encodeSortedSetDocValuesFacetField(gen, "parameterName",
// parameterName);
searchApi.encodeStringField(gen, "parameterName", parameterName);
searchApi.encodeStringField(gen, "parameterUnits", parameterUnits);
// TODO make all value types facetable...
if (type.getValueType() == ParameterValueType.STRING) {
// searchApi.encodeSortedSetDocValuesFacetField(gen, "parameterStringValue", parameter.getStringValue());
// searchApi.encodeSortedSetDocValuesFacetField(gen, "parameterStringValue",
// parameter.getStringValue());
searchApi.encodeStringField(gen, "parameterStringValue", parameter.getStringValue());
} else if (type.getValueType() == ParameterValueType.DATE_AND_TIME) {
searchApi.encodeStringField(gen, "parameterDateValue", parameter.getDateTimeValue());
} else if (type.getValueType() == ParameterValueType.NUMERIC) {
Expand All @@ -315,4 +326,29 @@ public void getDoc(JsonGenerator gen, SearchApi searchApi) {

searchApi.encodeStringField(gen, "id", id, true);
}

/**
* Gets the fields used in the search component for this entity, and the
* relationships that would restrict the content of those fields.
*
* @return Map of field names (as they appear on the search document) against
* the Relationships that need to be allowed for that field to be
* viewable. If there are no restrictive relationships, then the value
* will be null.
* @throws IcatException If the EntityInfoHandler cannot find one of the
* Relationships.
*/
public static Map<String, Relationship[]> getDocumentFields() throws IcatException {
if (documentFields.size() == 0) {
EntityInfoHandler eiHandler = EntityInfoHandler.getInstance();
Relationship[] textRelationships = { eiHandler.getRelationshipsByName(Investigation.class).get("type"),
eiHandler.getRelationshipsByName(Investigation.class).get("facility") };
documentFields.put("text", textRelationships);
documentFields.put("name", null);
documentFields.put("startDate", null);
documentFields.put("endDate", null);
documentFields.put("id", null);
}
return documentFields;
}
}
Loading

0 comments on commit 07a42a3

Please sign in to comment.