Skip to content

Commit

Permalink
Support for new searc/documents #27
Browse files Browse the repository at this point in the history
  • Loading branch information
patrick-austin committed Apr 30, 2022
1 parent 2d424e3 commit f16bddb
Show file tree
Hide file tree
Showing 2 changed files with 416 additions and 102 deletions.
142 changes: 142 additions & 0 deletions src/main/java/org/icatproject/icat/client/ICAT.java
Original file line number Diff line number Diff line change
Expand Up @@ -592,6 +592,61 @@ String searchInvestigations(String sessionId, String user, String text, Date low
}
}

String searchInvestigations(String sessionId, String user, String text, Date lower, Date upper,
List<ParameterForLucene> parameters, List<String> samples, String userFullName, String searchAfter, int limit, String sort, String facets)
throws IcatException {
URIBuilder uriBuilder = getUriBuilder("search/documents");
uriBuilder.setParameter("sessionId", sessionId);
ByteArrayOutputStream baos = new ByteArrayOutputStream();
try (JsonGenerator gen = Json.createGenerator(baos)) {
gen.writeStartObject();
gen.write("target", "Investigation");
if (user != null) {
gen.write("user", user);
}
if (text != null) {
gen.write("text", text);
}
if (lower != null) {
gen.write("lower", DateTools.dateToString(lower, Resolution.MINUTE));
}
if (upper != null) {
gen.write("upper", DateTools.dateToString(upper, Resolution.MINUTE));
}
if (parameters != null && !parameters.isEmpty()) {
writeParameters(gen, parameters);
}
if (samples != null && !samples.isEmpty()) {
gen.writeStartArray("samples");
for (String sample : samples) {
gen.write(sample);
}
gen.writeEnd();
}
if (userFullName != null) {
gen.write("userFullName", userFullName);
}
gen.writeEnd();
}

uriBuilder.setParameter("query", baos.toString());
uriBuilder.setParameter("search_after", searchAfter);
uriBuilder.setParameter("limit", Integer.toString(limit));
uriBuilder.setParameter("sort", sort);
uriBuilder.setParameter("facets", facets);
URI uri = getUri(uriBuilder);

try (CloseableHttpClient httpclient = HttpClients.createDefault()) {
HttpGet httpGet = new HttpGet(uri);
try (CloseableHttpResponse response = httpclient.execute(httpGet)) {
return getString(response);
}
} catch (IOException e) {
throw new IcatException(IcatExceptionType.INTERNAL, e.getClass() + " " + e.getMessage());

}
}

String searchDatasets(String sessionId, String user, String text, Date lower, Date upper,
List<ParameterForLucene> parameters, int maxResults) throws IcatException {
URIBuilder uriBuilder = getUriBuilder("lucene/data");
Expand Down Expand Up @@ -633,6 +688,50 @@ String searchDatasets(String sessionId, String user, String text, Date lower, Da
}
}

String searchDatasets(String sessionId, String user, String text, Date lower, Date upper,
List<ParameterForLucene> parameters, String searchAfter, int limit, String sort, String facets) throws IcatException {
URIBuilder uriBuilder = getUriBuilder("search/documents");
uriBuilder.setParameter("sessionId", sessionId);
ByteArrayOutputStream baos = new ByteArrayOutputStream();
try (JsonGenerator gen = Json.createGenerator(baos)) {
gen.writeStartObject();
gen.write("target", "Dataset");
if (user != null) {
gen.write("user", user);
}
if (text != null) {
gen.write("text", text);
}
if (lower != null) {
gen.write("lower", DateTools.dateToString(lower, Resolution.MINUTE));
}
if (upper != null) {
gen.write("upper", DateTools.dateToString(upper, Resolution.MINUTE));
}
if (parameters != null && !parameters.isEmpty()) {
writeParameters(gen, parameters);
}
gen.writeEnd();
}

uriBuilder.setParameter("query", baos.toString());
uriBuilder.setParameter("search_after", searchAfter);
uriBuilder.setParameter("limit", Integer.toString(limit));
uriBuilder.setParameter("sort", sort);
uriBuilder.setParameter("facets", facets);
URI uri = getUri(uriBuilder);

try (CloseableHttpClient httpclient = HttpClients.createDefault()) {
HttpGet httpGet = new HttpGet(uri);
try (CloseableHttpResponse response = httpclient.execute(httpGet)) {
return getString(response);
}
} catch (IOException e) {
throw new IcatException(IcatExceptionType.INTERNAL, e.getClass() + " " + e.getMessage());

}
}

private void writeParameters(JsonGenerator gen, List<ParameterForLucene> parameters) {
gen.writeStartArray("parameters");
for (ParameterForLucene parameter : parameters) {
Expand Down Expand Up @@ -805,6 +904,49 @@ String searchDatafiles(String sessionId, String user, String text, Date lower, D
}
}

String searchDatafiles(String sessionId, String user, String text, Date lower, Date upper,
List<ParameterForLucene> parameters, String searchAfter, int limit, String sort, String facets) throws IcatException {
URIBuilder uriBuilder = getUriBuilder("search/documents");
uriBuilder.setParameter("sessionId", sessionId);
ByteArrayOutputStream baos = new ByteArrayOutputStream();
try (JsonGenerator gen = Json.createGenerator(baos)) {
gen.writeStartObject();
gen.write("target", "Datafile");
if (user != null) {
gen.write("user", user);
}
if (text != null) {
gen.write("text", text);
}
if (lower != null) {
gen.write("lower", DateTools.dateToString(lower, Resolution.MINUTE));
}
if (upper != null) {
gen.write("upper", DateTools.dateToString(upper, Resolution.MINUTE));
}
if (parameters != null && !parameters.isEmpty()) {
writeParameters(gen, parameters);
}
gen.writeEnd();
}

uriBuilder.setParameter("query", baos.toString());
uriBuilder.setParameter("search_after", searchAfter);
uriBuilder.setParameter("limit", Integer.toString(limit));
uriBuilder.setParameter("sort", sort);
uriBuilder.setParameter("facets", facets);
URI uri = getUri(uriBuilder);

try (CloseableHttpClient httpclient = HttpClients.createDefault()) {
HttpGet httpGet = new HttpGet(uri);
try (CloseableHttpResponse response = httpclient.execute(httpGet)) {
return getString(response);
}
} catch (IOException e) {
throw new IcatException(IcatExceptionType.INTERNAL, e.getClass() + " " + e.getMessage());
}
}

long cloneEntity(String sessionId, String name, long id, Map<String, String> keys) throws IcatException {
URI uri = getUri(getUriBuilder("cloner"));
List<NameValuePair> formparams = new ArrayList<>();
Expand Down
Loading

0 comments on commit f16bddb

Please sign in to comment.