@Test public void recordEventsNameNull() throws Exception { List<Event> listOfEvents = new ArrayList<>(); listOfEvents.add(new Event()); eventList.setEvents(listOfEvents); thrown.expect(IllegalArgumentException.class); thrown.expectMessage("Event name cannot be null or an empty string"); resource.recordEvents(applicationName, experimentLabel, userID, eventList); }
@POST @Path("applications/{applicationName}/experiments/{experimentLabel}/users/{userID}") @Consumes(APPLICATION_JSON) @Produces(APPLICATION_JSON) @ApiOperation(value = "Submit a single event or a batch of events for the specified assigned user(customer)", notes = "*NOTE*: For a given user, please make sure that you have the user assignment done using the " + "assignments API before using this API. An event is either an impression, indicating the user " + "has been exposed to the treatment, or an action, indicating that the user has done something " + "that you want to track. Please record impressions first and then action - use event " + "name = \"IMPRESSION\" for impressions.") @Timed public Response recordEvents( @PathParam("applicationName") @ApiParam(value = "Application Name") final Application.Name applicationName, @PathParam("experimentLabel") @ApiParam(value = "Experiment Label") final Experiment.Label experimentLabel, @PathParam("userID") @ApiParam(value = "Customer User ID that is already assigned using assignments API") final User.ID userID, @ApiParam(name = "eventList", required = true, value = "For impression", defaultValue = DEFAULT_EVENT) final EventList eventList) throws Exception { try { final Date NOW = new Date(); Set<Context> contextSet = new HashSet<>(); for (Event event : eventList.getEvents()) { if (event.getTimestamp() == null) { event.setTimestamp(NOW); } contextSet.add(event.getContext()); if (event.getName() == null || isBlank(event.getName().toString())) { throw new IllegalArgumentException("Event name cannot be null or an empty string"); } } events.recordEvents(applicationName, experimentLabel, userID, eventList, contextSet); return httpHeader.headers(CREATED).build(); } catch (Exception exception) { LOGGER.error("recordEvents failed for applicationName={}," + " experimentLabel={}, userID={}, eventList={} with error:", applicationName, experimentLabel, userID, eventList, exception); throw exception; } }
EventsResource { @POST @Path("applications/{applicationName}/experiments/{experimentLabel}/users/{userID}") @Consumes(APPLICATION_JSON) @Produces(APPLICATION_JSON) @ApiOperation(value = "Submit a single event or a batch of events for the specified assigned user(customer)", notes = "*NOTE*: For a given user, please make sure that you have the user assignment done using the " + "assignments API before using this API. An event is either an impression, indicating the user " + "has been exposed to the treatment, or an action, indicating that the user has done something " + "that you want to track. Please record impressions first and then action - use event " + "name = \"IMPRESSION\" for impressions.") @Timed public Response recordEvents( @PathParam("applicationName") @ApiParam(value = "Application Name") final Application.Name applicationName, @PathParam("experimentLabel") @ApiParam(value = "Experiment Label") final Experiment.Label experimentLabel, @PathParam("userID") @ApiParam(value = "Customer User ID that is already assigned using assignments API") final User.ID userID, @ApiParam(name = "eventList", required = true, value = "For impression", defaultValue = DEFAULT_EVENT) final EventList eventList) throws Exception { try { final Date NOW = new Date(); Set<Context> contextSet = new HashSet<>(); for (Event event : eventList.getEvents()) { if (event.getTimestamp() == null) { event.setTimestamp(NOW); } contextSet.add(event.getContext()); if (event.getName() == null || isBlank(event.getName().toString())) { throw new IllegalArgumentException("Event name cannot be null or an empty string"); } } events.recordEvents(applicationName, experimentLabel, userID, eventList, contextSet); return httpHeader.headers(CREATED).build(); } catch (Exception exception) { LOGGER.error("recordEvents failed for applicationName={}," + " experimentLabel={}, userID={}, eventList={} with error:", applicationName, experimentLabel, userID, eventList, exception); throw exception; } } }
EventsResource { @POST @Path("applications/{applicationName}/experiments/{experimentLabel}/users/{userID}") @Consumes(APPLICATION_JSON) @Produces(APPLICATION_JSON) @ApiOperation(value = "Submit a single event or a batch of events for the specified assigned user(customer)", notes = "*NOTE*: For a given user, please make sure that you have the user assignment done using the " + "assignments API before using this API. An event is either an impression, indicating the user " + "has been exposed to the treatment, or an action, indicating that the user has done something " + "that you want to track. Please record impressions first and then action - use event " + "name = \"IMPRESSION\" for impressions.") @Timed public Response recordEvents( @PathParam("applicationName") @ApiParam(value = "Application Name") final Application.Name applicationName, @PathParam("experimentLabel") @ApiParam(value = "Experiment Label") final Experiment.Label experimentLabel, @PathParam("userID") @ApiParam(value = "Customer User ID that is already assigned using assignments API") final User.ID userID, @ApiParam(name = "eventList", required = true, value = "For impression", defaultValue = DEFAULT_EVENT) final EventList eventList) throws Exception { try { final Date NOW = new Date(); Set<Context> contextSet = new HashSet<>(); for (Event event : eventList.getEvents()) { if (event.getTimestamp() == null) { event.setTimestamp(NOW); } contextSet.add(event.getContext()); if (event.getName() == null || isBlank(event.getName().toString())) { throw new IllegalArgumentException("Event name cannot be null or an empty string"); } } events.recordEvents(applicationName, experimentLabel, userID, eventList, contextSet); return httpHeader.headers(CREATED).build(); } catch (Exception exception) { LOGGER.error("recordEvents failed for applicationName={}," + " experimentLabel={}, userID={}, eventList={} with error:", applicationName, experimentLabel, userID, eventList, exception); throw exception; } } @Inject  EventsResource(final Events events, final HttpHeader httpHeader); }
EventsResource { @POST @Path("applications/{applicationName}/experiments/{experimentLabel}/users/{userID}") @Consumes(APPLICATION_JSON) @Produces(APPLICATION_JSON) @ApiOperation(value = "Submit a single event or a batch of events for the specified assigned user(customer)", notes = "*NOTE*: For a given user, please make sure that you have the user assignment done using the " + "assignments API before using this API. An event is either an impression, indicating the user " + "has been exposed to the treatment, or an action, indicating that the user has done something " + "that you want to track. Please record impressions first and then action - use event " + "name = \"IMPRESSION\" for impressions.") @Timed public Response recordEvents( @PathParam("applicationName") @ApiParam(value = "Application Name") final Application.Name applicationName, @PathParam("experimentLabel") @ApiParam(value = "Experiment Label") final Experiment.Label experimentLabel, @PathParam("userID") @ApiParam(value = "Customer User ID that is already assigned using assignments API") final User.ID userID, @ApiParam(name = "eventList", required = true, value = "For impression", defaultValue = DEFAULT_EVENT) final EventList eventList) throws Exception { try { final Date NOW = new Date(); Set<Context> contextSet = new HashSet<>(); for (Event event : eventList.getEvents()) { if (event.getTimestamp() == null) { event.setTimestamp(NOW); } contextSet.add(event.getContext()); if (event.getName() == null || isBlank(event.getName().toString())) { throw new IllegalArgumentException("Event name cannot be null or an empty string"); } } events.recordEvents(applicationName, experimentLabel, userID, eventList, contextSet); return httpHeader.headers(CREATED).build(); } catch (Exception exception) { LOGGER.error("recordEvents failed for applicationName={}," + " experimentLabel={}, userID={}, eventList={} with error:", applicationName, experimentLabel, userID, eventList, exception); throw exception; } } @Inject  EventsResource(final Events events, final HttpHeader httpHeader); @POST @Path("applications/{applicationName}/experiments/{experimentLabel}/users/{userID}") @Consumes(APPLICATION_JSON) @Produces(APPLICATION_JSON) @ApiOperation(value = "Submit a single event or a batch of events for the specified assigned user(customer)", notes = "*NOTE*: For a given user, please make sure that you have the user assignment done using the " + "assignments API before using this API. An event is either an impression, indicating the user " + "has been exposed to the treatment, or an action, indicating that the user has done something " + "that you want to track. Please record impressions first and then action - use event " + "name = \"IMPRESSION\" for impressions.") @Timed Response recordEvents(
            @PathParam("applicationName")
            @ApiParam(value = "Application Name")
            final Application.Name applicationName,

            @PathParam("experimentLabel")
            @ApiParam(value = "Experiment Label")
            final Experiment.Label experimentLabel,

            @PathParam("userID")
            @ApiParam(value = "Customer User ID that is already assigned using assignments API")
            final User.ID userID,

            @ApiParam(name = "eventList", required = true, value = "For impression", defaultValue = DEFAULT_EVENT)
            final EventList eventList); @POST @Path("applications/{applicationName}/experiments/{experimentLabel}/users") @Consumes(APPLICATION_JSON) @Produces(APPLICATION_JSON) @Timed Response recordUsersEvents(
            @PathParam("applicationName")
            final Application.Name applicationName,

            @PathParam("experimentLabel")
            final Experiment.Label experimentLabel,

            final Map<User.ID, List<Event>> eventList); @POST @Path("applications/{applicationName}/experiments") @Consumes(APPLICATION_JSON) @Produces(APPLICATION_JSON) @Timed Response recordExperimentsEvents(
            @PathParam("applicationName") final Application.Name applicationName,
            final Map<Experiment.Label, Map<User.ID, List<Event>>> eventList); @GET @Path("queueLength") @Produces(APPLICATION_JSON) @Timed Response getEventsQueueLength(); }
EventsResource { @POST @Path("applications/{applicationName}/experiments/{experimentLabel}/users/{userID}") @Consumes(APPLICATION_JSON) @Produces(APPLICATION_JSON) @ApiOperation(value = "Submit a single event or a batch of events for the specified assigned user(customer)", notes = "*NOTE*: For a given user, please make sure that you have the user assignment done using the " + "assignments API before using this API. An event is either an impression, indicating the user " + "has been exposed to the treatment, or an action, indicating that the user has done something " + "that you want to track. Please record impressions first and then action - use event " + "name = \"IMPRESSION\" for impressions.") @Timed public Response recordEvents( @PathParam("applicationName") @ApiParam(value = "Application Name") final Application.Name applicationName, @PathParam("experimentLabel") @ApiParam(value = "Experiment Label") final Experiment.Label experimentLabel, @PathParam("userID") @ApiParam(value = "Customer User ID that is already assigned using assignments API") final User.ID userID, @ApiParam(name = "eventList", required = true, value = "For impression", defaultValue = DEFAULT_EVENT) final EventList eventList) throws Exception { try { final Date NOW = new Date(); Set<Context> contextSet = new HashSet<>(); for (Event event : eventList.getEvents()) { if (event.getTimestamp() == null) { event.setTimestamp(NOW); } contextSet.add(event.getContext()); if (event.getName() == null || isBlank(event.getName().toString())) { throw new IllegalArgumentException("Event name cannot be null or an empty string"); } } events.recordEvents(applicationName, experimentLabel, userID, eventList, contextSet); return httpHeader.headers(CREATED).build(); } catch (Exception exception) { LOGGER.error("recordEvents failed for applicationName={}," + " experimentLabel={}, userID={}, eventList={} with error:", applicationName, experimentLabel, userID, eventList, exception); throw exception; } } @Inject  EventsResource(final Events events, final HttpHeader httpHeader); @POST @Path("applications/{applicationName}/experiments/{experimentLabel}/users/{userID}") @Consumes(APPLICATION_JSON) @Produces(APPLICATION_JSON) @ApiOperation(value = "Submit a single event or a batch of events for the specified assigned user(customer)", notes = "*NOTE*: For a given user, please make sure that you have the user assignment done using the " + "assignments API before using this API. An event is either an impression, indicating the user " + "has been exposed to the treatment, or an action, indicating that the user has done something " + "that you want to track. Please record impressions first and then action - use event " + "name = \"IMPRESSION\" for impressions.") @Timed Response recordEvents(
            @PathParam("applicationName")
            @ApiParam(value = "Application Name")
            final Application.Name applicationName,

            @PathParam("experimentLabel")
            @ApiParam(value = "Experiment Label")
            final Experiment.Label experimentLabel,

            @PathParam("userID")
            @ApiParam(value = "Customer User ID that is already assigned using assignments API")
            final User.ID userID,

            @ApiParam(name = "eventList", required = true, value = "For impression", defaultValue = DEFAULT_EVENT)
            final EventList eventList); @POST @Path("applications/{applicationName}/experiments/{experimentLabel}/users") @Consumes(APPLICATION_JSON) @Produces(APPLICATION_JSON) @Timed Response recordUsersEvents(
            @PathParam("applicationName")
            final Application.Name applicationName,

            @PathParam("experimentLabel")
            final Experiment.Label experimentLabel,

            final Map<User.ID, List<Event>> eventList); @POST @Path("applications/{applicationName}/experiments") @Consumes(APPLICATION_JSON) @Produces(APPLICATION_JSON) @Timed Response recordExperimentsEvents(
            @PathParam("applicationName") final Application.Name applicationName,
            final Map<Experiment.Label, Map<User.ID, List<Event>>> eventList); @GET @Path("queueLength") @Produces(APPLICATION_JSON) @Timed Response getEventsQueueLength();  }