Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Proof of concept convert ES response to a neutral data object to spit…
… out JSON Created a class called DataTermsFacet, which holds list of term:count pairs.
- Loading branch information
1 parent
9cc7844
commit 2bada68
Showing
3 changed files
with
81 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
64 changes: 64 additions & 0 deletions
64
dspace-stats/src/main/java/org/dspace/statistics/DataTermsFacet.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
package org.dspace.statistics; | ||
|
||
import com.google.gson.Gson; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
/** | ||
* A neutral data object to hold data for statistics. | ||
* | ||
*/ | ||
public class DataTermsFacet { | ||
private List<TermsFacet> terms; | ||
|
||
public DataTermsFacet() { | ||
terms = new ArrayList<TermsFacet>(); | ||
} | ||
public void addTermFacet(TermsFacet termsFacet ) { | ||
terms.add(termsFacet); | ||
} | ||
|
||
/** | ||
* Render this data object into JSON format. | ||
* | ||
* An example of the output could be of the format: | ||
* [{"term":"247166","count":10},{"term":"247168","count":6}] | ||
* @return | ||
*/ | ||
public String toJson() { | ||
Gson gson = new Gson(); | ||
return gson.toJson(terms); | ||
} | ||
|
||
|
||
|
||
|
||
public static class TermsFacet { | ||
private String term; | ||
private Integer count; | ||
|
||
public TermsFacet(String term, Integer count) { | ||
setTerm(term); | ||
setCount(count); | ||
} | ||
|
||
public String getTerm() { | ||
return term; | ||
} | ||
|
||
public void setTerm(String term) { | ||
this.term = term; | ||
} | ||
|
||
public Integer getCount() { | ||
return count; | ||
} | ||
|
||
public void setCount(Integer count) { | ||
this.count = count; | ||
} | ||
|
||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters