@Test public void getBufferedAIDRDataTest() { String channelCode = "mock_collection"+new Date(); String callbackName = null; int count = 1; Response clientResponse = getBufferedAIDRData.getBufferedAIDRData(channelCode, callbackName, count); String statusString = (String)clientResponse.getEntity(); assertNotNull(statusString); assertEquals("[{}]", statusString); }
@GET @Path("/channel/{crisisCode}") @Produces({"application/json"}) public Response getBufferedAIDRData(@PathParam("crisisCode") String channelCode, @QueryParam("callback") String callbackName, @DefaultValue("1000") @QueryParam("count") int count) { System.out.println("[getBufferedAIDRData] request received"); logger.info("[getBufferedAIDRData] request received"); if (null != cbManager.jedisConn && cbManager.jedisConn.isPoolSetup()) { boolean error = false; if (null == channelCode) { error = true; } if (!error && channelCode.contains("*")) { return getLatestBufferedAIDRData(callbackName, count, (float) 0.0, false); } if (channelCode != null && channelCode.contains("?")) { error = true; } if (error) { logger.error("Error in requested channel name: " + channelCode); return Response.ok(new String("[{}]")).build(); } else { String channelName = null; if (channelCode.startsWith(CHANNEL_PREFIX_STRING) || channelCode.contains(".")) { channelName = channelCode; } else { channelName = CHANNEL_PREFIX_STRING.concat(channelCode); } if (isChannelPresent(channelName)) { int msgCount = count; int messageCount = DEFAULT_COUNT; if (msgCount > 0) { messageCount = Math.min(msgCount, MAX_MESSAGES_COUNT); } List<String> bufferedMessages = cbManager.getLastMessages(channelName, messageCount); StringBuilder jsonDataList = null; int sendCount = 0; if (bufferedMessages != null) { final JsonDataFormatter taggerOutput = new JsonDataFormatter(callbackName); jsonDataList = taggerOutput.createList(bufferedMessages, messageCount, rejectNullFlag); sendCount = taggerOutput.getMessageCount(); } System.out.println(channelCode + " : sending jsonp data, count = " + sendCount); logger.info(channelCode + " : sending jsonp data, count = " + sendCount); if (jsonDataList != null) { return Response.ok(jsonDataList.toString()).build(); } else { logger.warn("Returning empty json data list"); return returnEmptyJson(callbackName); } } else { logger.warn(channelName + " is not present"); return returnEmptyJson(callbackName); } } } logger.error(channelCode + ": error in jedis connection. Bailing out..."); return returnEmptyJson(callbackName); }
GetBufferedAIDRData implements ServletContextListener { @GET @Path("/channel/{crisisCode}") @Produces({"application/json"}) public Response getBufferedAIDRData(@PathParam("crisisCode") String channelCode, @QueryParam("callback") String callbackName, @DefaultValue("1000") @QueryParam("count") int count) { System.out.println("[getBufferedAIDRData] request received"); logger.info("[getBufferedAIDRData] request received"); if (null != cbManager.jedisConn && cbManager.jedisConn.isPoolSetup()) { boolean error = false; if (null == channelCode) { error = true; } if (!error && channelCode.contains("*")) { return getLatestBufferedAIDRData(callbackName, count, (float) 0.0, false); } if (channelCode != null && channelCode.contains("?")) { error = true; } if (error) { logger.error("Error in requested channel name: " + channelCode); return Response.ok(new String("[{}]")).build(); } else { String channelName = null; if (channelCode.startsWith(CHANNEL_PREFIX_STRING) || channelCode.contains(".")) { channelName = channelCode; } else { channelName = CHANNEL_PREFIX_STRING.concat(channelCode); } if (isChannelPresent(channelName)) { int msgCount = count; int messageCount = DEFAULT_COUNT; if (msgCount > 0) { messageCount = Math.min(msgCount, MAX_MESSAGES_COUNT); } List<String> bufferedMessages = cbManager.getLastMessages(channelName, messageCount); StringBuilder jsonDataList = null; int sendCount = 0; if (bufferedMessages != null) { final JsonDataFormatter taggerOutput = new JsonDataFormatter(callbackName); jsonDataList = taggerOutput.createList(bufferedMessages, messageCount, rejectNullFlag); sendCount = taggerOutput.getMessageCount(); } System.out.println(channelCode + " : sending jsonp data, count = " + sendCount); logger.info(channelCode + " : sending jsonp data, count = " + sendCount); if (jsonDataList != null) { return Response.ok(jsonDataList.toString()).build(); } else { logger.warn("Returning empty json data list"); return returnEmptyJson(callbackName); } } else { logger.warn(channelName + " is not present"); return returnEmptyJson(callbackName); } } } logger.error(channelCode + ": error in jedis connection. Bailing out..."); return returnEmptyJson(callbackName); } }
GetBufferedAIDRData implements ServletContextListener { @GET @Path("/channel/{crisisCode}") @Produces({"application/json"}) public Response getBufferedAIDRData(@PathParam("crisisCode") String channelCode, @QueryParam("callback") String callbackName, @DefaultValue("1000") @QueryParam("count") int count) { System.out.println("[getBufferedAIDRData] request received"); logger.info("[getBufferedAIDRData] request received"); if (null != cbManager.jedisConn && cbManager.jedisConn.isPoolSetup()) { boolean error = false; if (null == channelCode) { error = true; } if (!error && channelCode.contains("*")) { return getLatestBufferedAIDRData(callbackName, count, (float) 0.0, false); } if (channelCode != null && channelCode.contains("?")) { error = true; } if (error) { logger.error("Error in requested channel name: " + channelCode); return Response.ok(new String("[{}]")).build(); } else { String channelName = null; if (channelCode.startsWith(CHANNEL_PREFIX_STRING) || channelCode.contains(".")) { channelName = channelCode; } else { channelName = CHANNEL_PREFIX_STRING.concat(channelCode); } if (isChannelPresent(channelName)) { int msgCount = count; int messageCount = DEFAULT_COUNT; if (msgCount > 0) { messageCount = Math.min(msgCount, MAX_MESSAGES_COUNT); } List<String> bufferedMessages = cbManager.getLastMessages(channelName, messageCount); StringBuilder jsonDataList = null; int sendCount = 0; if (bufferedMessages != null) { final JsonDataFormatter taggerOutput = new JsonDataFormatter(callbackName); jsonDataList = taggerOutput.createList(bufferedMessages, messageCount, rejectNullFlag); sendCount = taggerOutput.getMessageCount(); } System.out.println(channelCode + " : sending jsonp data, count = " + sendCount); logger.info(channelCode + " : sending jsonp data, count = " + sendCount); if (jsonDataList != null) { return Response.ok(jsonDataList.toString()).build(); } else { logger.warn("Returning empty json data list"); return returnEmptyJson(callbackName); } } else { logger.warn(channelName + " is not present"); return returnEmptyJson(callbackName); } } } logger.error(channelCode + ": error in jedis connection. Bailing out..."); return returnEmptyJson(callbackName); }  }
GetBufferedAIDRData implements ServletContextListener { @GET @Path("/channel/{crisisCode}") @Produces({"application/json"}) public Response getBufferedAIDRData(@PathParam("crisisCode") String channelCode, @QueryParam("callback") String callbackName, @DefaultValue("1000") @QueryParam("count") int count) { System.out.println("[getBufferedAIDRData] request received"); logger.info("[getBufferedAIDRData] request received"); if (null != cbManager.jedisConn && cbManager.jedisConn.isPoolSetup()) { boolean error = false; if (null == channelCode) { error = true; } if (!error && channelCode.contains("*")) { return getLatestBufferedAIDRData(callbackName, count, (float) 0.0, false); } if (channelCode != null && channelCode.contains("?")) { error = true; } if (error) { logger.error("Error in requested channel name: " + channelCode); return Response.ok(new String("[{}]")).build(); } else { String channelName = null; if (channelCode.startsWith(CHANNEL_PREFIX_STRING) || channelCode.contains(".")) { channelName = channelCode; } else { channelName = CHANNEL_PREFIX_STRING.concat(channelCode); } if (isChannelPresent(channelName)) { int msgCount = count; int messageCount = DEFAULT_COUNT; if (msgCount > 0) { messageCount = Math.min(msgCount, MAX_MESSAGES_COUNT); } List<String> bufferedMessages = cbManager.getLastMessages(channelName, messageCount); StringBuilder jsonDataList = null; int sendCount = 0; if (bufferedMessages != null) { final JsonDataFormatter taggerOutput = new JsonDataFormatter(callbackName); jsonDataList = taggerOutput.createList(bufferedMessages, messageCount, rejectNullFlag); sendCount = taggerOutput.getMessageCount(); } System.out.println(channelCode + " : sending jsonp data, count = " + sendCount); logger.info(channelCode + " : sending jsonp data, count = " + sendCount); if (jsonDataList != null) { return Response.ok(jsonDataList.toString()).build(); } else { logger.warn("Returning empty json data list"); return returnEmptyJson(callbackName); } } else { logger.warn(channelName + " is not present"); return returnEmptyJson(callbackName); } } } logger.error(channelCode + ": error in jedis connection. Bailing out..."); return returnEmptyJson(callbackName); }  @GET @Path("/channels/list") @Produces("text/html") Response getActiveChannelsList(); @GET @Path("/channels/latest") @Produces("application/json") Response getLatestBufferedAIDRData(@QueryParam("callback") String callbackName,
			@DefaultValue("1") @QueryParam("count") Integer count,
			@DefaultValue("0.7") @QueryParam("confidence") Float confidence,
			@DefaultValue("true") @QueryParam("balanced_sampling") Boolean balanced_sampling); @GET @Path("/channel/{crisisCode}") @Produces({"application/json"}) Response getBufferedAIDRData(@PathParam("crisisCode") String channelCode,
			@QueryParam("callback") String callbackName,
			@DefaultValue("1000") @QueryParam("count") int count); @OPTIONS @Produces(MediaType.APPLICATION_JSON) @Path("/channel/filter/{crisisCode}") Response getBufferedAIDRDataPostFilter(@PathParam("crisisCode") String channelCode,
			@QueryParam("callback") String callbackName,
			@DefaultValue("1000") @QueryParam("count") int count); @POST @Consumes(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON) @Path("/channel/filter/{crisisCode}") Response getBufferedAIDRDataPostFilter(String queryString, @PathParam("crisisCode") String channelCode,
			@QueryParam("callback") String callbackName,
			@DefaultValue("1000") @QueryParam("count") int count); Response returnEmptyJson(final String callbackName); boolean isChannelPresent(String channel); @GET @Path("/channel/error/{crisisCode}") @Produces({"text/html"}) Response onErrorResponse(); @GET @Path("/manage/restart/{passcode}") @Produces("application/json") Response restartFetchService(@PathParam("passcode") String passcode); @POST @Consumes(MediaType.TEXT_PLAIN) @Produces(MediaType.APPLICATION_JSON) @Path("/channel/test/{crisisCode}") Response testPost(String testString, @PathParam("crisisCode") String channelCode); @GET @Path("/channel/test/jsonmap") Response testJsonMap(); @GET @Path("/channel/test/channelpublic") Response testChannelPublicFlag(@QueryParam("channelCode") String channelCode); @Override void contextDestroyed(ServletContextEvent sce); @Override void contextInitialized(ServletContextEvent sce); }
GetBufferedAIDRData implements ServletContextListener { @GET @Path("/channel/{crisisCode}") @Produces({"application/json"}) public Response getBufferedAIDRData(@PathParam("crisisCode") String channelCode, @QueryParam("callback") String callbackName, @DefaultValue("1000") @QueryParam("count") int count) { System.out.println("[getBufferedAIDRData] request received"); logger.info("[getBufferedAIDRData] request received"); if (null != cbManager.jedisConn && cbManager.jedisConn.isPoolSetup()) { boolean error = false; if (null == channelCode) { error = true; } if (!error && channelCode.contains("*")) { return getLatestBufferedAIDRData(callbackName, count, (float) 0.0, false); } if (channelCode != null && channelCode.contains("?")) { error = true; } if (error) { logger.error("Error in requested channel name: " + channelCode); return Response.ok(new String("[{}]")).build(); } else { String channelName = null; if (channelCode.startsWith(CHANNEL_PREFIX_STRING) || channelCode.contains(".")) { channelName = channelCode; } else { channelName = CHANNEL_PREFIX_STRING.concat(channelCode); } if (isChannelPresent(channelName)) { int msgCount = count; int messageCount = DEFAULT_COUNT; if (msgCount > 0) { messageCount = Math.min(msgCount, MAX_MESSAGES_COUNT); } List<String> bufferedMessages = cbManager.getLastMessages(channelName, messageCount); StringBuilder jsonDataList = null; int sendCount = 0; if (bufferedMessages != null) { final JsonDataFormatter taggerOutput = new JsonDataFormatter(callbackName); jsonDataList = taggerOutput.createList(bufferedMessages, messageCount, rejectNullFlag); sendCount = taggerOutput.getMessageCount(); } System.out.println(channelCode + " : sending jsonp data, count = " + sendCount); logger.info(channelCode + " : sending jsonp data, count = " + sendCount); if (jsonDataList != null) { return Response.ok(jsonDataList.toString()).build(); } else { logger.warn("Returning empty json data list"); return returnEmptyJson(callbackName); } } else { logger.warn(channelName + " is not present"); return returnEmptyJson(callbackName); } } } logger.error(channelCode + ": error in jedis connection. Bailing out..."); return returnEmptyJson(callbackName); }  @GET @Path("/channels/list") @Produces("text/html") Response getActiveChannelsList(); @GET @Path("/channels/latest") @Produces("application/json") Response getLatestBufferedAIDRData(@QueryParam("callback") String callbackName,
			@DefaultValue("1") @QueryParam("count") Integer count,
			@DefaultValue("0.7") @QueryParam("confidence") Float confidence,
			@DefaultValue("true") @QueryParam("balanced_sampling") Boolean balanced_sampling); @GET @Path("/channel/{crisisCode}") @Produces({"application/json"}) Response getBufferedAIDRData(@PathParam("crisisCode") String channelCode,
			@QueryParam("callback") String callbackName,
			@DefaultValue("1000") @QueryParam("count") int count); @OPTIONS @Produces(MediaType.APPLICATION_JSON) @Path("/channel/filter/{crisisCode}") Response getBufferedAIDRDataPostFilter(@PathParam("crisisCode") String channelCode,
			@QueryParam("callback") String callbackName,
			@DefaultValue("1000") @QueryParam("count") int count); @POST @Consumes(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON) @Path("/channel/filter/{crisisCode}") Response getBufferedAIDRDataPostFilter(String queryString, @PathParam("crisisCode") String channelCode,
			@QueryParam("callback") String callbackName,
			@DefaultValue("1000") @QueryParam("count") int count); Response returnEmptyJson(final String callbackName); boolean isChannelPresent(String channel); @GET @Path("/channel/error/{crisisCode}") @Produces({"text/html"}) Response onErrorResponse(); @GET @Path("/manage/restart/{passcode}") @Produces("application/json") Response restartFetchService(@PathParam("passcode") String passcode); @POST @Consumes(MediaType.TEXT_PLAIN) @Produces(MediaType.APPLICATION_JSON) @Path("/channel/test/{crisisCode}") Response testPost(String testString, @PathParam("crisisCode") String channelCode); @GET @Path("/channel/test/jsonmap") Response testJsonMap(); @GET @Path("/channel/test/channelpublic") Response testChannelPublicFlag(@QueryParam("channelCode") String channelCode); @Override void contextDestroyed(ServletContextEvent sce); @Override void contextInitialized(ServletContextEvent sce);  }