EntitiesResource { @GET @Path("similarities") @Produces(MediaType.APPLICATION_JSON) public 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) { LOG.debug("Got a call for dimensions {} and {} with starttime={} endtime={} botStr={}", firstDimStr, secondDimStr, startTimeStr, endTimeStr, botStr); DimensionType firstDim = DimensionType.fromDimensionName(firstDimStr); DimensionType secondDim = DimensionType.fromDimensionName(secondDimStr); Interval interval = DateTimeUtils.getIntervalFromParameters(startTimeStr, endTimeStr, dtz); boolean withBots = ResourceUtils.getOptionalForParameterAsBool(botStr).or(false); if (firstDim == DimensionType.ROOM && secondDim == DimensionType.ENTITY) { return entityDao.getRoomSimilaritiesByEntity(interval, withBots); } else if (firstDim == DimensionType.USER && secondDim == DimensionType.ENTITY) { return entityDao.getUserSimilaritiesByEntity(interval, withBots); } else { String formatStr = "The dimension combination you specified (%s, %s) is not supported"; throw new UnsupportedOperationException(String.format(formatStr, firstDimStr, secondDimStr)); } } 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 testGetSimilarities_RoomByEntity() 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)); LabeledDenseMatrix<String> ldm = underTest.getSimilarities( startTimeStr, endTimeStr, DimensionType.ROOM.getDimensionName(), DimensionType.ENTITY.getDimensionName(), null); assertEquals(4, ldm.getLabels().size()); assertEquals(4, ldm.getMatrix().length); }
@Test public void testGetSimilarities_UserByEntity() 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)); LabeledDenseMatrix<String> ldm = underTest.getSimilarities( startTimeStr, endTimeStr, DimensionType.USER.getDimensionName(), DimensionType.ENTITY.getDimensionName(), null); assertEquals(4, ldm.getLabels().size()); assertEquals(4, ldm.getMatrix().length); }
@Test(expected = UnsupportedOperationException.class) public void testGetSimilarities_badCombination() 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.getSimilarities(startTimeStr, endTimeStr, DimensionType.ROOM.getDimensionName(), DimensionType.ROOM.getDimensionName(), "true"); }