use of io.altanalytics.domain.calendar.CalendarEvent in project bibot by alfintech.
the class ElasticPublisher method publishEvents.
@Override
public void publishEvents(List<CalendarEvent> calendarEvents) throws IOException {
BulkRequestBuilder bulkRequest = client.prepareBulk();
Date currentTime = Calendar.getInstance().getTime();
for (CalendarEvent calendarEvent : calendarEvents) {
System.out.println(calendarEvent);
for (String currency : calendarEvent.getCurrencies()) {
XContentBuilder builder = XContentFactory.jsonBuilder().startObject().field("eventId", calendarEvent.getEventId()).field("currency", currency).field("title", calendarEvent.getTitle()).field("eventDate", calendarEvent.getEventDate()).field("createdDate", calendarEvent.getCreatedDate()).field("voteCount", calendarEvent.getVoteCount()).field("positiveVoteCount", calendarEvent.getPositiveVoteCount()).field("percentagePositiveVoteCount", calendarEvent.getPercentagePositiveVoteCount()).field("insertionDate", currentTime).endObject();
String idAsString = new Long(calendarEvent.getEventId()).toString();
bulkRequest.add(client.prepareIndex("calendarevents", "minutely", idAsString).setSource(builder));
}
}
BulkResponse response = bulkRequest.get();
LOG.debug(response.toString());
}
use of io.altanalytics.domain.calendar.CalendarEvent in project bibot by alfintech.
the class CoinMarketCalClient method parseResponse.
@SuppressWarnings("unchecked")
private List<CalendarEvent> parseResponse(String response) throws Exception {
List<CalendarEvent> events = new ArrayList<CalendarEvent>();
JSONParser jsonParser = new JSONParser();
JSONArray jsonArray = (JSONArray) jsonParser.parse(response);
for (Object uncastedResult : jsonArray.toArray(new JSONObject[] {})) {
JSONObject result = (JSONObject) uncastedResult;
Long eventId = (Long) result.get(JSON_FIELD_ID);
Date eventDate = DATE_FORMAT.parse((String) result.get(JSON_FIELD_DATA_EVENT_DATE));
Date createdDate = DATE_FORMAT.parse((String) result.get(JSON_FIELD_DATA_CREATED_DATE));
String title = (String) result.get(JSON_FIELD_TITLE);
String description = (String) result.get(JSON_FIELD_DATA_DESCRIPTION);
Long voteCount = (Long) result.get(JSON_FIELD_DATA_VOTE_COUNT);
Long positiveVoteCount = (Long) result.get(JSON_FIELD_DATA_POSITIVE_VOTE_COUNT);
Long percentagePositive = (Long) result.get(JSON_FIELD_DATA_PERCENTAGE_POSITIVE);
List<String> currencies = parseCurrencies(result);
events.add(new CalendarEvent(eventId, currencies, title, description, eventDate, createdDate, voteCount, positiveVoteCount, percentagePositive));
}
return events;
}
Aggregations