All Downloads are FREE. Search and download functionalities are using the official Maven repository.
Please wait. This can take some minutes ...
Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance.
Project price only 1 $
You can buy this project and download/modify it how often you want.
io.hawt.log.rest.LogRequest Maven / Gradle / Ivy
package io.hawt.log.rest;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import com.fasterxml.jackson.annotation.JsonCreator;
public class LogRequest {
private long from;
private long size;
private List> sort;
private Map query;
public static LogRequest newInstance(Long maxLogSeq) {
List> s = new ArrayList<>();
s.add(keyValueMap("timestamp", "desc"));
s.add(keyValueMap("seq", "desc"));
Map q = new HashMap<>();
Map constantScore = new HashMap<>();
Map filter = new HashMap<>();
q.put("constant_score", constantScore);
constantScore.put("filter", filter);
List> listOfTerms = new ArrayList<>();
//listOfTerms.add(createSearchTerm("host", "root"));
listOfTerms.add(createSearchTerms("level", "error", "warn", "info"));
if (maxLogSeq != null) {
listOfTerms.add(createSearchRangeGt("seq", maxLogSeq));
}
filter.put("and", listOfTerms);
return new LogRequest(0, 50, s, q);
}
private static Map keyValueMap(String key, String value) {
Map answer = new HashMap();
answer.put(key, value);
return answer;
}
protected static Map createSearchRangeGt(String name, Object value) {
return createSearchRange(name, "gt", value);
}
protected static Map createSearchRange(String name, String compareOperation, Object value) {
Map answer = new HashMap<>();
Map range = new HashMap<>();
Map compare = new HashMap<>();
answer.put("range", range);
range.put(compareOperation, compare);
compare.put(name, value);
return answer;
}
protected static Map createSearchTerm(String name, String value) {
Map answer = new HashMap();
Map term = new HashMap();
answer.put("term", term);
term.put(name, value);
return answer;
}
protected static Map createSearchTerms(String name, String... values) {
Map answer = new HashMap<>();
Map term = new HashMap<>();
answer.put("terms", term);
term.put(name, new ArrayList<>(Arrays.asList(values)));
return answer;
}
@JsonCreator
public LogRequest(long from, long size, List> sort, Map query) {
this.from = from;
this.size = size;
this.sort = sort;
this.query = query;
}
public long getFrom() {
return from;
}
public void setFrom(long from) {
this.from = from;
}
public long getSize() {
return size;
}
public void setSize(long size) {
this.size = size;
}
public List> getSort() {
return sort;
}
public void setSort(List> sort) {
this.sort = sort;
}
public Map getQuery() {
return query;
}
public void setQuery(Map query) {
this.query = query;
}
}