Search in sources :

Example 1 with EventWrapper

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;
}
Also used : HttpGet(org.apache.http.client.methods.HttpGet) Gson(com.google.gson.Gson) EventWrapper(org.vcell.api.common.events.EventWrapper)

Example 2 with EventWrapper

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;
}
Also used : ArrayList(java.util.ArrayList) EventWrapper(org.vcell.api.common.events.EventWrapper)

Example 3 with EventWrapper

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);
}
Also used : EventWrapper(org.vcell.api.common.events.EventWrapper)

Example 4 with EventWrapper

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);
        }
    }
}
Also used : HttpRequest(org.restlet.engine.adapter.HttpRequest) User(org.vcell.util.document.User) Form(org.restlet.data.Form) Gson(com.google.gson.Gson) VCellApiApplication(org.vcell.rest.VCellApiApplication) JsonRepresentation(org.restlet.ext.json.JsonRepresentation) EventWrapper(org.vcell.api.common.events.EventWrapper)

Aggregations

EventWrapper (org.vcell.api.common.events.EventWrapper)4 Gson (com.google.gson.Gson)2 ArrayList (java.util.ArrayList)1 HttpGet (org.apache.http.client.methods.HttpGet)1 Form (org.restlet.data.Form)1 HttpRequest (org.restlet.engine.adapter.HttpRequest)1 JsonRepresentation (org.restlet.ext.json.JsonRepresentation)1 VCellApiApplication (org.vcell.rest.VCellApiApplication)1 User (org.vcell.util.document.User)1