Skip to content

Commit

Permalink
Remove dependency on Lucene date tools #27
Browse files Browse the repository at this point in the history
  • Loading branch information
patrick-austin committed Oct 12, 2022
1 parent 9a34808 commit b87802f
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 21 deletions.
7 changes: 0 additions & 7 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<project.scm.id>github</project.scm.id>
<repoUrl>https://repo.icatproject.org/repo/</repoUrl>
<luceneVersion>5.3.0</luceneVersion>
</properties>

<repositories>
Expand Down Expand Up @@ -62,12 +61,6 @@

<dependencies>

<dependency>
<groupId>org.apache.lucene</groupId>
<artifactId>lucene-core</artifactId>
<version>${luceneVersion}</version>
</dependency>

<dependency>
<groupId>javax</groupId>
<artifactId>javaee-api</artifactId>
Expand Down
32 changes: 19 additions & 13 deletions src/main/java/org/icatproject/icat/client/ICAT.java
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,6 @@
import org.apache.http.impl.client.HttpClients;
import org.apache.http.message.BasicNameValuePair;
import org.apache.http.util.EntityUtils;
import org.apache.lucene.document.DateTools;
import org.apache.lucene.document.DateTools.Resolution;
import org.icatproject.icat.client.IcatException.IcatExceptionType;
import org.icatproject.icat.client.Session.Attributes;
import org.icatproject.icat.client.Session.DuplicateAction;
Expand Down Expand Up @@ -556,11 +554,10 @@ String searchInvestigations(String sessionId, String user, String text, Date low
gen.write("text", text);
}
if (lower != null) {
// TODO Remove DateTools as it is from a Lucene library!
gen.write("lower", DateTools.dateToString(lower, Resolution.MINUTE));
gen.write("lower", roundMinute(lower, 0));
}
if (upper != null) {
gen.write("upper", DateTools.dateToString(upper, Resolution.MINUTE));
gen.write("upper", roundMinute(upper, 59999));
}
if (parameters != null && !parameters.isEmpty()) {
writeParameters(gen, parameters);
Expand Down Expand Up @@ -609,10 +606,10 @@ private String searchDocuments(String target, String sessionId, String user, Str
gen.write("text", text);
}
if (lower != null) {
gen.write("lower", DateTools.dateToString(lower, Resolution.MINUTE));
gen.write("lower", roundMinute(lower, 0));
}
if (upper != null) {
gen.write("upper", DateTools.dateToString(upper, Resolution.MINUTE));
gen.write("upper", roundMinute(upper, 59999));
}
if (parameters != null && !parameters.isEmpty()) {
writeParameters(gen, parameters);
Expand Down Expand Up @@ -665,10 +662,10 @@ String searchDatasets(String sessionId, String user, String text, Date lower, Da
gen.write("text", text);
}
if (lower != null) {
gen.write("lower", DateTools.dateToString(lower, Resolution.MINUTE));
gen.write("lower", roundMinute(lower, 0));
}
if (upper != null) {
gen.write("upper", DateTools.dateToString(upper, Resolution.MINUTE));
gen.write("upper", roundMinute(upper, 59999));
}
if (parameters != null && !parameters.isEmpty()) {
writeParameters(gen, parameters);
Expand Down Expand Up @@ -711,8 +708,8 @@ private void writeParameters(JsonGenerator gen, List<ParameterForLucene> paramet
if (parameter.getStringValue() != null) {
gen.write("stringValue", parameter.getStringValue());
} else if (parameter.getLowerDateValue() != null && parameter.getUpperDateValue() != null) {
gen.write("lowerDateValue", DateTools.dateToString(parameter.getLowerDateValue(), Resolution.MINUTE));
gen.write("upperDateValue", DateTools.dateToString(parameter.getUpperDateValue(), Resolution.MINUTE));
gen.write("lowerDateValue", roundMinute(parameter.getLowerDateValue(), 0));
gen.write("upperDateValue", roundMinute(parameter.getUpperDateValue(), 59999));
} else if (parameter.getLowerNumericValue() != null && parameter.getUpperNumericValue() != null) {
gen.write("lowerNumericValue", parameter.getLowerNumericValue());
gen.write("upperNumericValue", parameter.getUpperNumericValue());
Expand Down Expand Up @@ -851,10 +848,10 @@ String searchDatafiles(String sessionId, String user, String text, Date lower, D
gen.write("text", text);
}
if (lower != null) {
gen.write("lower", DateTools.dateToString(lower, Resolution.MINUTE));
gen.write("lower", roundMinute(lower, 0));
}
if (upper != null) {
gen.write("upper", DateTools.dateToString(upper, Resolution.MINUTE));
gen.write("upper", roundMinute(upper, 59999));
}
if (parameters != null && !parameters.isEmpty()) {
writeParameters(gen, parameters);
Expand Down Expand Up @@ -943,4 +940,13 @@ public String list(String sessionId, String path) throws IcatException {
}
}

/**
* @param date Date to round down to the minute
* @param offset Number of ms to be added to the returned value
* @return Rounded date, converted to ms with offset applied
*/
private long roundMinute(Date date, long offset) {
return (date.getTime() / 60000) * 60000 + offset;
}

}
2 changes: 1 addition & 1 deletion src/test/java/org/icatproject/icat/TestIcatClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ public void testSession() throws Exception {

@Test
public void testInfo() throws Exception {
assertTrue(icat.getVersion().startsWith("5.0."));
assertTrue(icat.getVersion().startsWith("5.1."));
}

}

0 comments on commit b87802f

Please sign in to comment.