View Javadoc
1   package de.dlr.shepard.common.search.io;
2   
3   import de.dlr.shepard.common.neo4j.io.BasicEntityIO;
4   import de.dlr.shepard.context.collection.io.CollectionIO;
5   import java.util.List;
6   import lombok.Data;
7   import lombok.EqualsAndHashCode;
8   import lombok.NoArgsConstructor;
9   import org.eclipse.microprofile.openapi.annotations.media.Schema;
10  
11  @Data
12  @NoArgsConstructor
13  @EqualsAndHashCode(callSuper = true)
14  public class CollectionSearchResult extends ASearchResults<CollectionSearchParams> {
15  
16    @Schema(required = true)
17    private List<CollectionIO> results;
18  
19    @Schema(required = true)
20    private Integer totalResults;
21  
22    public CollectionSearchResult(List<CollectionIO> results, CollectionSearchParams searchParams, Integer total) {
23      super(searchParams);
24      this.results = results;
25      this.totalResults = total;
26    }
27  
28    public ResponseBody toResponseBody() {
29      ResultTriple[] resultTriples = new ResultTriple[this.results.size()];
30      BasicEntityIO[] results = new BasicEntityIO[this.results.size()];
31      for (int i = 0; i < this.results.size(); i++) {
32        resultTriples[i] = new ResultTriple(this.results.get(i).getId());
33        results[i] = new BasicEntityIO(this.results.get(i));
34      }
35      ResponseBody responseBody = new ResponseBody(
36        resultTriples,
37        results,
38        new SearchParams(this.getSearchParams().getQuery(), QueryType.Collection)
39      );
40      return responseBody;
41    }
42  }