Search in sources :

Example 1 with PublishedStudy

use of uk.ac.ebi.spot.goci.model.PublishedStudy in project goci by EBISPOT.

the class ReleaseSummaryEmail method createBody.

public void createBody(List<PublishedStudy> studies) {
    DateFormat df = new SimpleDateFormat("yyyy-MM-dd");
    Date date = new Date();
    String today = df.format(date);
    this.setSubject("Studies added to the Solr index on " + today);
    if (studies.size() != 0) {
        this.setBody("The following studies were added to the Solr index on " + today + "\n");
        for (PublishedStudy s : studies) {
            StringBuilder line = new StringBuilder();
            line.append(s.getAuthor());
            line.append(" (");
            line.append(s.getPubmedId());
            line.append(") - ");
            line.append(s.getTitle());
            line.append(" (");
            line.append(s.getPublicationDate());
            line.append(", ");
            line.append(s.getJournal());
            line.append("); ");
            line.append(s.getAssociationCount());
            line.append(" associations.\n");
            line.append("\n");
            this.addToBody(line.toString());
        }
    } else {
        this.setBody("No studies were added to the Solr index on " + today + "\n");
    }
}
Also used : SimpleDateFormat(java.text.SimpleDateFormat) DateFormat(java.text.DateFormat) PublishedStudy(uk.ac.ebi.spot.goci.model.PublishedStudy) SimpleDateFormat(java.text.SimpleDateFormat) Date(java.util.Date)

Example 2 with PublishedStudy

use of uk.ac.ebi.spot.goci.model.PublishedStudy in project goci by EBISPOT.

the class SolrDataProcessingService method processJson.

public List<PublishedStudy> processJson() throws IOException {
    List<PublishedStudy> studies = new ArrayList<>();
    ObjectMapper mapper = new ObjectMapper();
    JsonNode node = mapper.readTree(json);
    JsonNode responseNode = node.get("response");
    JsonNode docs = responseNode.get("docs");
    for (JsonNode doc : docs) {
        PublishedStudy study = processStudyJson(doc);
        studies.add(study);
    }
    return studies;
}
Also used : ArrayList(java.util.ArrayList) JsonNode(com.fasterxml.jackson.databind.JsonNode) PublishedStudy(uk.ac.ebi.spot.goci.model.PublishedStudy) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

Example 3 with PublishedStudy

use of uk.ac.ebi.spot.goci.model.PublishedStudy in project goci by EBISPOT.

the class SolrQueryService method processSolrResult.

public List<PublishedStudy> processSolrResult(HttpEntity entity) throws IOException {
    List<PublishedStudy> studies = new ArrayList<>();
    BufferedReader br = new BufferedReader(new InputStreamReader(entity.getContent()));
    String output;
    while ((output = br.readLine()) != null) {
        SolrDataProcessingService jsonProcessor = new SolrDataProcessingService(output);
        studies = jsonProcessor.processJson();
    }
    EntityUtils.consume(entity);
    return studies;
}
Also used : InputStreamReader(java.io.InputStreamReader) ArrayList(java.util.ArrayList) BufferedReader(java.io.BufferedReader) PublishedStudy(uk.ac.ebi.spot.goci.model.PublishedStudy)

Example 4 with PublishedStudy

use of uk.ac.ebi.spot.goci.model.PublishedStudy in project goci by EBISPOT.

the class SolrQueryService method querySolr.

//    public HttpEntity querySolr(String searchString) throws IOException{
public List<PublishedStudy> querySolr(String searchString) throws IOException {
    System.out.println(searchString);
    CloseableHttpClient httpclient = HttpClients.createDefault();
    HttpGet httpGet = new HttpGet(searchString);
    if (System.getProperty("http.proxyHost") != null) {
        HttpHost proxy;
        if (System.getProperty("http.proxyPort") != null) {
            proxy = new HttpHost(System.getProperty("http.proxyHost"), Integer.parseInt(System.getProperty("http.proxyPort")));
        } else {
            proxy = new HttpHost(System.getProperty("http.proxyHost"));
        }
        httpGet.setConfig(RequestConfig.custom().setProxy(proxy).build());
    }
    //        HttpEntity entity = null;
    List<PublishedStudy> studies = new ArrayList<>();
    try (CloseableHttpResponse response = httpclient.execute(httpGet)) {
        getLog().debug("Received HTTP response: " + response.getStatusLine().toString());
        HttpEntity entity = response.getEntity();
        BufferedReader br = new BufferedReader(new InputStreamReader(entity.getContent()));
        String output;
        while ((output = br.readLine()) != null) {
            SolrDataProcessingService jsonProcessor = new SolrDataProcessingService(output);
            studies = jsonProcessor.processJson();
        }
        EntityUtils.consume(entity);
    }
    //        return entity;
    return studies;
}
Also used : CloseableHttpClient(org.apache.http.impl.client.CloseableHttpClient) HttpEntity(org.apache.http.HttpEntity) InputStreamReader(java.io.InputStreamReader) HttpHost(org.apache.http.HttpHost) HttpGet(org.apache.http.client.methods.HttpGet) ArrayList(java.util.ArrayList) CloseableHttpResponse(org.apache.http.client.methods.CloseableHttpResponse) BufferedReader(java.io.BufferedReader) PublishedStudy(uk.ac.ebi.spot.goci.model.PublishedStudy)

Aggregations

PublishedStudy (uk.ac.ebi.spot.goci.model.PublishedStudy)4 ArrayList (java.util.ArrayList)3 BufferedReader (java.io.BufferedReader)2 InputStreamReader (java.io.InputStreamReader)2 JsonNode (com.fasterxml.jackson.databind.JsonNode)1 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 DateFormat (java.text.DateFormat)1 SimpleDateFormat (java.text.SimpleDateFormat)1 Date (java.util.Date)1 HttpEntity (org.apache.http.HttpEntity)1 HttpHost (org.apache.http.HttpHost)1 CloseableHttpResponse (org.apache.http.client.methods.CloseableHttpResponse)1 HttpGet (org.apache.http.client.methods.HttpGet)1 CloseableHttpClient (org.apache.http.impl.client.CloseableHttpClient)1