EntitiesResource { @GET @Path("active") @Produces(MediaType.APPLICATION_JSON) public Map<String, Double> getActive(@QueryParam(START_TIME) String startTimeStr, @QueryParam(END_TIME) String endTimeStr, @QueryParam(DIM) String dimensionStr, @QueryParam(METHOD) String methodStr, @QueryParam(TOP_N) String topNStr, @QueryParam(BOT) String botStr) { Interval interval = DateTimeUtils.getIntervalFromParameters(startTimeStr, endTimeStr, dtz); DimensionType dimension = DimensionType.fromDimensionName(dimensionStr); ActiveMethod method = ActiveMethod.fromMethodName(methodStr); int topN = ResourceUtils.getOptionalForParameterAsInt(topNStr).or(MAX_RESULTS); boolean withBots = ResourceUtils.getOptionalForParameterAsBool(botStr).or(false); if (dimension == DimensionType.ROOM) { return entityDao.getActiveRoomsByMethod(interval, method, topN, withBots); } else if (dimension == DimensionType.USER) { return entityDao.getActiveUsersByMethod(interval, method, topN, withBots); } else { String formatMsg = "The dimension %s you provided is not supported. Pass in %s or %s"; throw new UnsupportedOperationException(String.format(formatMsg, dimensionStr, DimensionType.ROOM, DimensionType.USER)); } } EntitiesResource(ChatAlyticsConfig config); @GET @Path("trending") @Produces(MediaType.APPLICATION_JSON) Map<String, Long> getTrendingTopics(@QueryParam(START_TIME) String startTimeStr,
                                               @QueryParam(END_TIME) String endTimeStr,
                                               @QueryParam(USER) List<String> users,
                                               @QueryParam(ROOM) List<String> rooms,
                                               @QueryParam(TOP_N) String topNStr,
                                               @QueryParam(BOT) String botStr); @GET @Produces(MediaType.APPLICATION_JSON) List<ChatEntity> getAllEntites(@QueryParam(START_TIME) String startTimeStr,
                                          @QueryParam(END_TIME) String endTimeStr,
                                          @QueryParam(USER) List<String> users,
                                          @QueryParam(ROOM) List<String> rooms,
                                          @QueryParam(BOT) String botStr); @GET @Path("similarities") @Produces(MediaType.APPLICATION_JSON) LabeledDenseMatrix<String> getSimilarities(
            @QueryParam(START_TIME) String startTimeStr,
            @QueryParam(END_TIME) String endTimeStr,
            @QueryParam(FIRST_SIMILARITY_DIM) String firstDimStr,
            @QueryParam(SECOND_SIMILARITY_DIM) String secondDimStr,
            @QueryParam(BOT) String botStr); @GET @Path("active") @Produces(MediaType.APPLICATION_JSON) Map<String, Double> getActive(@QueryParam(START_TIME) String startTimeStr,
                                         @QueryParam(END_TIME) String endTimeStr,
                                         @QueryParam(DIM) String dimensionStr,
                                         @QueryParam(METHOD) String methodStr,
                                         @QueryParam(TOP_N) String topNStr,
                                         @QueryParam(BOT) String botStr); static final String ENTITIES_ENDPOINT; static final String FIRST_SIMILARITY_DIM; static final String SECOND_SIMILARITY_DIM; static final String DIM; static final String METHOD; }
@Test public void testGetActive_userToTV() throws Exception { DateTimeFormatter dtf = DateTimeUtils.PARAMETER_WITH_DAY_DTF.withZone(dtZone); String startTimeStr = dtf.print(mentionTime.minusDays(1)); String endTimeStr = dtf.print(mentionTime.plusDays(1)); Map<String, Double> scores = underTest.getActive(startTimeStr, endTimeStr, DimensionType.USER.toString(), ActiveMethod.ToTV.toString(), "10", "true"); assertFalse(scores.isEmpty()); }
@Test public void testGetActive_roomToTV() throws Exception { DateTimeFormatter dtf = DateTimeUtils.PARAMETER_WITH_DAY_DTF.withZone(dtZone); String startTimeStr = dtf.print(mentionTime.minusDays(1)); String endTimeStr = dtf.print(mentionTime.plusDays(1)); Map<String, Double> scores = underTest.getActive(startTimeStr, endTimeStr, DimensionType.ROOM.toString(), ActiveMethod.ToTV.toString(), "10", "true"); assertFalse(scores.isEmpty()); }
@Test public void testGetActive_userTOmV() throws Exception { DateTimeFormatter dtf = DateTimeUtils.PARAMETER_WITH_DAY_DTF.withZone(dtZone); String startTimeStr = dtf.print(mentionTime.minusDays(1)); String endTimeStr = dtf.print(mentionTime.plusDays(1)); Map<String, Double> scores = underTest.getActive(startTimeStr, endTimeStr, DimensionType.USER.toString(), ActiveMethod.ToMV.toString(), "10", "true"); assertFalse(scores.isEmpty()); }
@Test public void testGetActive_roomToMV() throws Exception { DateTimeFormatter dtf = DateTimeUtils.PARAMETER_WITH_DAY_DTF.withZone(dtZone); String startTimeStr = dtf.print(mentionTime.minusDays(1)); String endTimeStr = dtf.print(mentionTime.plusDays(1)); Map<String, Double> scores = underTest.getActive(startTimeStr, endTimeStr, DimensionType.ROOM.toString(), ActiveMethod.ToMV.toString(), "10", "true"); assertFalse(scores.isEmpty()); }
@Test(expected = UnsupportedOperationException.class) public void testGetActive_invalidDimension() throws Exception { DateTimeFormatter dtf = DateTimeUtils.PARAMETER_WITH_DAY_DTF.withZone(dtZone); String startTimeStr = dtf.print(mentionTime.minusDays(1)); String endTimeStr = dtf.print(mentionTime.plusDays(1)); underTest.getActive(startTimeStr, endTimeStr, DimensionType.EMOJI.toString(), ActiveMethod.ToTV.toString(), "10", "true"); }