Commit 9e9677fb authored by mhellka's avatar mhellka
Browse files

Added model for snapshots and snapshot lists

parent f1826672
......@@ -105,7 +105,7 @@ public class ArchiveFileIterable extends AbstractRequestIterator<FileInfo> {
rq.order(order, reverse);
rq.page(offset, limit);
return rq.submit(client).thenApply((FileList list) -> {
offset += list.files.size();
offset += list.files.getCount();
total = list.total;
return list.files;
});
......
......@@ -20,7 +20,7 @@ class SearchResultWrapper implements SearchResult {
@Override
public List<SearchHit> hits() {
if (hits == null)
hits = Utils.map(proxyResult.hits, HitWrapper::new);
hits = Utils.map(proxyResult.getItems(), HitWrapper::new);
return hits;
}
......@@ -31,7 +31,7 @@ class SearchResultWrapper implements SearchResult {
@Override
public long getTotal() {
return proxyResult.total;
return proxyResult.getTotal();
}
private static class HitWrapper implements SearchHit {
......
package de.gwdg.cdstar.rest.v3.async;
import java.util.ArrayList;
import java.util.List;
import de.gwdg.cdstar.Promise;
......@@ -11,6 +10,7 @@ import de.gwdg.cdstar.rest.api.RestContext;
import de.gwdg.cdstar.rest.utils.QueryHelper;
import de.gwdg.cdstar.rest.utils.SessionHelper;
import de.gwdg.cdstar.runtime.search.SearchException;
import de.gwdg.cdstar.runtime.search.SearchHit;
import de.gwdg.cdstar.runtime.search.SearchProvider;
import de.gwdg.cdstar.runtime.search.SearchQueryBuilder;
import de.gwdg.cdstar.runtime.search.SearchResult;
......@@ -122,19 +122,15 @@ public class SearchHandler {
}
private SearchHits buildSearchQueryResponse(SearchResult rs) {
final SearchHits hits = new SearchHits();
hits.total = rs.getTotal();
hits.scroll = rs.getScrollID();
hits.hits = new ArrayList<>(rs.getSize());
rs.hits().forEach(h -> {
final List<Hit> items = Utils.map(rs.hits(), (SearchHit h) -> {
final Hit hit = new Hit();
hit.id = h.getId();
hit.type = h.getType();
hit.score = h.getScore();
hit.name = h.getName();
hits.hits.add(hit);
return hit;
});
return hits;
return new SearchHits(items, rs.getTotal(), rs.getScrollID());
}
}
package de.gwdg.cdstar.web.common.model;
import java.util.Collections;
import java.util.Iterator;
import java.util.List;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.annotation.JsonPropertyOrder;
/**
* Abstract base class for list-like response documents with count and total.
* Implementors may rename the items
*/
@JsonPropertyOrder({ "total", "count" })
@JsonIgnoreProperties(value = { "count" }, allowGetters = true)
public class AbstractList<T> implements Iterable<T> {
private List<T> items;
private long total = 0;
public AbstractList() {
}
public AbstractList(List<T> items, long total) {
this.items = items;
this.total = total;
}
public List<T> getItems() {
return items;
}
public void setItems(List<T> items) {
this.items = items;
}
public long getTotal() {
return total;
}
public void setTotal(int total) {
this.total = total;
}
@Override
public Iterator<T> iterator() {
return items != null ? items.iterator() : Collections.emptyIterator();
}
@JsonProperty(value = "count", access = JsonProperty.Access.READ_ONLY)
public int getCount() {
return items != null ? items.size() : 0;
}
}
package de.gwdg.cdstar.web.common.model;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.annotation.JsonPropertyOrder;
@JsonPropertyOrder({ "total", "count", "files" })
public class FileList implements Iterable<FileInfo> {
public List<FileInfo> files;
public int total;
public class FileList extends AbstractList<FileInfo> {
@JsonCreator
public FileList() {
super();
}
public FileList(List<FileInfo> files, int total) {
this.files = new ArrayList<>(files);
this.total = total;
public FileList(List<FileInfo> items, int total) {
super(items, total);
}
@Override
public Iterator<FileInfo> iterator() {
return files.iterator();
}
@JsonProperty(access = JsonProperty.Access.READ_ONLY)
public int getCount() {
return files.size();
@JsonProperty("files")
public List<FileInfo> getItems() {
return super.getItems();
}
}
package de.gwdg.cdstar.web.common.model;
import java.util.ArrayList;
import java.util.List;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonInclude.Include;
import com.fasterxml.jackson.annotation.JsonProperty;
public class SearchHits {
public long total;
public ArrayList<Hit> hits;
import de.gwdg.cdstar.web.common.model.SearchHits.Hit;
public class SearchHits extends AbstractList<Hit> {
public String scroll;
public SearchHits() {
super();
}
public SearchHits(List<Hit> items, long total, String scroll) {
super(items, total);
this.scroll = scroll;
}
@Override
@JsonProperty("hits")
public List<Hit> getItems() {
return super.getItems();
}
public static class Hit {
public String id;
public double score;
......@@ -19,8 +34,4 @@ public class SearchHits {
public String name;
}
@JsonProperty(access = JsonProperty.Access.READ_ONLY)
public int getCount() {
return hits.size();
}
}
......@@ -6,5 +6,4 @@ public class SnapshotInfo {
public String name;
public String creator;
public Date created;
}
package de.gwdg.cdstar.web.common.model;
import java.util.List;
import com.fasterxml.jackson.annotation.JsonProperty;
public class SnapshotList extends AbstractList<SnapshotInfo> {
public SnapshotList() {
super();
}
public SnapshotList(List<SnapshotInfo> items, int total) {
super(items, total);
}
@Override
@JsonProperty("snapshots")
public List<SnapshotInfo> getItems() {
return super.getItems();
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment