use of org.vcell.api.common.events.EventWrapper in project vcell by virtualcell.
the class VCellApiClient method getEvents.
public EventWrapper[] getEvents(long beginTimestamp) throws IOException {
HttpGet httpget = new HttpGet("https://" + httpHost.getHostName() + ":" + httpHost.getPort() + "/events?beginTimestamp=" + beginTimestamp);
if (lg.isLoggable(Level.INFO)) {
lg.info("Executing request to retrieve user events " + httpget.getRequestLine());
}
String responseBody = httpclient.execute(httpget, responseHandler, httpClientContext);
String eventWrappersJson = responseBody;
if (lg.isLoggable(Level.INFO)) {
lg.info("returned: " + toStringTruncated(eventWrappersJson));
}
Gson gson = new Gson();
EventWrapper[] eventWrappers = gson.fromJson(eventWrappersJson, EventWrapper[].class);
return eventWrappers;
}
use of org.vcell.api.common.events.EventWrapper in project vcell by virtualcell.
the class RestEventService method query.
public EventWrapper[] query(String userid, long lasttimestamp) {
ArrayList<EventWrapper> eventList = new ArrayList<EventWrapper>();
Iterator<EventWrapper> iter = events.iterator();
while (iter.hasNext()) {
EventWrapper eventWrapper = iter.next();
if (eventWrapper.timestamp > lasttimestamp && (eventWrapper.userid == null || eventWrapper.userid.equals(userid))) {
System.out.println("returning event to userid: (" + eventWrapper.id + ", " + eventWrapper.timestamp + ", " + eventWrapper.userid + ", " + eventWrapper.eventJSON + ")");
eventList.add(0, eventWrapper);
}
}
EventWrapper[] eventArray = eventList.toArray(new EventWrapper[0]);
return eventArray;
}
use of org.vcell.api.common.events.EventWrapper in project vcell by virtualcell.
the class RestEventService method insert.
public void insert(String userid, EventType eventType, String eventJSON) {
long id = eventSequence.getAndIncrement();
long timestamp = System.currentTimeMillis();
EventWrapper wrapper = new EventWrapper(id, timestamp, userid, eventType, eventJSON);
events.addFirst(wrapper);
}
use of org.vcell.api.common.events.EventWrapper in project vcell by virtualcell.
the class EventsRestlet method handle.
@Override
public void handle(Request req, Response response) {
if (req.getMethod().equals(Method.GET)) {
try {
VCellApiApplication application = ((VCellApiApplication) getApplication());
User vcellUser = application.getVCellUser(req.getChallengeResponse(), AuthenticationPolicy.prohibitInvalidCredentials);
HttpRequest request = (HttpRequest) req;
Form form = request.getResourceRef().getQueryAsForm();
String beginTimestampString = form.getFirstValue(VCellApiApplication.EVENTS_BEGINTIMESTAMP, true);
if (beginTimestampString == null) {
throw new RuntimeException("expecting " + VCellApiApplication.EVENTS_BEGINTIMESTAMP + " query parameter");
}
long beginTimestamp = Long.parseLong(beginTimestampString);
RestEventService rpcService = application.getEventsService();
EventWrapper[] eventWrappers = rpcService.query(vcellUser.getName(), beginTimestamp);
Gson gson = new Gson();
String eventWrappersJSON = gson.toJson(eventWrappers);
response.setStatus(Status.SUCCESS_OK, "event query succeeded");
response.setEntity(new JsonRepresentation(eventWrappersJSON));
} catch (Exception e) {
getLogger().severe("internal error retrieving events: " + e.getMessage());
e.printStackTrace();
response.setStatus(Status.SERVER_ERROR_INTERNAL);
response.setEntity("internal error retrieving events: " + e.getMessage(), MediaType.TEXT_PLAIN);
}
}
}
Aggregations