Java Code Examples for net.minidev.json.JSONObject#putAll()

The following examples show how to use net.minidev.json.JSONObject#putAll() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: Persister4CollectorAPI.java    From AIDR with GNU Affero General Public License v3.0 7 votes vote down vote up
@GET
@Produces(MediaType.APPLICATION_JSON)
@Path("/genJson")
public Response generateJSONFromLastestJSON(@QueryParam("collectionCode") String collectionCode,
		@DefaultValue(DownloadType.TEXT_JSON) @QueryParam("jsonType") String jsonType) throws UnknownHostException {
	logger.info("Received request for collection: " + collectionCode + " with jsonType = " + jsonType);
	JsonDeserializer jsonD = new JsonDeserializer();
    String fileName = jsonD.generateJSON2JSON_100K_BasedOnTweetCount(collectionCode, DownloadJsonType.getDownloadJsonTypeFromString(jsonType));
    fileName = PersisterConfigurator.getInstance().getProperty(PersisterConfigurationProperty.PERSISTER_DOWNLOAD_URL) + collectionCode+"/"+fileName;
    
    logger.info("Done processing request for collection: " + collectionCode + ", returning created file: " + fileName);
    //return Response.ok(fileName).build();
    JSONObject obj = new JSONObject();
    obj.putAll(ResultStatus.getUIWrapper(collectionCode, null, fileName, true));
    
    logger.info("Returning JSON object: " + ResultStatus.getUIWrapper(collectionCode, null, fileName, true));
    return Response.ok(obj.toJSONString()).build();
}
 
Example 2
Source File: Persister4CollectorAPI.java    From AIDR with GNU Affero General Public License v3.0 6 votes vote down vote up
@GET
  @Produces(MediaType.APPLICATION_JSON)
  @Path("/genTweetIds")
  public Response generateTweetsIDSCSVFromAllJSON(@QueryParam("collectionCode") String collectionCode,
  		@DefaultValue("true") @QueryParam("downloadLimited") Boolean downloadLimited) throws UnknownHostException {
      logger.info("Received request for collection: " + collectionCode);
  	JsonDeserializer jsonD = new JsonDeserializer();
  	Map<String, Object> result = jsonD.generateJson2TweetIdsCSV(collectionCode, downloadLimited);
      String fileName = PersisterConfigurator.getInstance().getProperty(PersisterConfigurationProperty.PERSISTER_DOWNLOAD_URL) + collectionCode+"/" + (String) result.get("fileName");
      logger.info("Done processing request for collection: " + collectionCode + ", returning created file: " + fileName);
      
      JSONObject obj = new JSONObject();
      obj.put("feedCount", result.get("count"));
if ((Integer) result.get("count") < Integer.parseInt(PersisterConfigurator.getInstance().getProperty(PersisterConfigurationProperty.DEFAULT_TWEETID_VOLUME_LIMIT)) ) {
	obj.putAll(ResultStatus.getUIWrapper(collectionCode, null, fileName, true));
	logger.info("Returning JSON object: " + ResultStatus.getUIWrapper(collectionCode, null, fileName, true));
	return Response.ok(obj.toJSONString()).build();
} else {
	obj.putAll(ResultStatus.getUIWrapper(collectionCode,PersisterConfigurator.getInstance().getProperty(PersisterConfigurationProperty.TWEET_DOWNLOAD_LIMIT_MSG_PREFIX) + PersisterConfigurator.getInstance().getProperty(PersisterConfigurationProperty.DEFAULT_TWEETID_VOLUME_LIMIT) + PersisterConfigurator.getInstance().getProperty(PersisterConfigurationProperty.TWEET_DOWNLOAD_LIMIT_MSG_SUFFIX), fileName, true));
	logger.info("Returning JSON object: " + ResultStatus.getUIWrapper(collectionCode,  PersisterConfigurator.getInstance().getProperty(PersisterConfigurationProperty.TWEET_DOWNLOAD_LIMIT_MSG_PREFIX) + PersisterConfigurator.getInstance().getProperty(PersisterConfigurationProperty.DEFAULT_TWEETID_VOLUME_LIMIT) + PersisterConfigurator.getInstance().getProperty(PersisterConfigurationProperty.TWEET_DOWNLOAD_LIMIT_MSG_SUFFIX), fileName, true));
	return Response.ok(obj.toJSONString()).build();
}
  }
 
Example 3
Source File: Persister4CollectorAPI.java    From AIDR with GNU Affero General Public License v3.0 6 votes vote down vote up
@GET
  @Produces(MediaType.APPLICATION_JSON)
  @Path("/genJsonTweetIds")
  public Response generateTweetsIDSJSONFromAllJSON(@QueryParam("collectionCode") String collectionCode,
  			@DefaultValue("true") @QueryParam("downloadLimited") Boolean downloadLimited,
  			@DefaultValue(DownloadType.TEXT_JSON) @QueryParam("jsonType") String jsonType) throws UnknownHostException {
      logger.info("Received request for collection: " + collectionCode + " with jsonType = " + jsonType);
  	JsonDeserializer jsonD = new JsonDeserializer();
  	Map<String, Object> result = jsonD.generateJson2TweetIdsJson(collectionCode, downloadLimited, DownloadJsonType.getDownloadJsonTypeFromString(jsonType));
      String fileName = PersisterConfigurator.getInstance().getProperty(PersisterConfigurationProperty.PERSISTER_DOWNLOAD_URL) + collectionCode+"/" + (String)result.get("fileName");
      logger.info("Done processing request for collection: " + collectionCode + ", returning created file: " + fileName);
      //return Response.ok(fileName).build();
      JSONObject obj = new JSONObject();
if ((Integer) result.get("count") < Integer.parseInt(PersisterConfigurator.getInstance().getProperty(PersisterConfigurationProperty.DEFAULT_TWEETID_VOLUME_LIMIT))) {
	obj.putAll(ResultStatus.getUIWrapper(collectionCode, null, fileName, true));
	logger.info("Returning JSON object: " + ResultStatus.getUIWrapper(collectionCode, null, fileName, true));
	return Response.ok(obj.toJSONString()).build();
} else {
	obj.putAll(ResultStatus.getUIWrapper(collectionCode,  PersisterConfigurator.getInstance().getProperty(PersisterConfigurationProperty.TWEET_DOWNLOAD_LIMIT_MSG_PREFIX) + PersisterConfigurator.getInstance().getProperty(PersisterConfigurationProperty.DEFAULT_TWEETID_VOLUME_LIMIT) + PersisterConfigurator.getInstance().getProperty(PersisterConfigurationProperty.TWEET_DOWNLOAD_LIMIT_MSG_SUFFIX), fileName, true));
	logger.info("Returning JSON object: " + ResultStatus.getUIWrapper(collectionCode,   PersisterConfigurator.getInstance().getProperty(PersisterConfigurationProperty.TWEET_DOWNLOAD_LIMIT_MSG_PREFIX) + PersisterConfigurator.getInstance().getProperty(PersisterConfigurationProperty.DEFAULT_TWEETID_VOLUME_LIMIT) + PersisterConfigurator.getInstance().getProperty(PersisterConfigurationProperty.TWEET_DOWNLOAD_LIMIT_MSG_SUFFIX), fileName, true));
	return Response.ok(obj.toJSONString()).build();
}
  }
 
Example 4
Source File: Persister4CollectorAPI.java    From AIDR with GNU Affero General Public License v3.0 6 votes vote down vote up
@GET
@Produces(MediaType.APPLICATION_JSON)
@Path("/genCSV")
public Response generateCSVFromLastestJSON(@QueryParam("collectionCode") String collectionCode,
				@QueryParam("exportLimit") int exportLimit) throws UnknownHostException {
	logger.info("Received request for collection: " + collectionCode);
	JsonDeserializer jsonD = new JsonDeserializer();
    String fileName = jsonD.generateJSON2CSV_100K_BasedOnTweetCount(collectionCode, exportLimit);
    fileName = PersisterConfigurator.getInstance().getProperty(PersisterConfigurationProperty.PERSISTER_DOWNLOAD_URL) + collectionCode+"/"+fileName;
    
    logger.info("Done processing request for collection: " + collectionCode + ", returning created file: " + fileName);
    //return Response.ok(fileName).build();
    
    JSONObject obj = new JSONObject();
    obj.putAll(ResultStatus.getUIWrapper(collectionCode, null, fileName, true));
    logger.info("Returning JSON object: " + ResultStatus.getUIWrapper(collectionCode, null, fileName, true));
    return Response.ok(obj.toJSONString()).build();
}
 
Example 5
Source File: Persister4TaggerAPI.java    From AIDR with GNU Affero General Public License v3.0 6 votes vote down vote up
@GET
@Produces(MediaType.APPLICATION_JSON)
@Path("/genJson")
public Response generateJSONFromLastestJSON(@QueryParam("collectionCode") String collectionCode, 
		@QueryParam("exportLimit") int exportLimit,
		@DefaultValue(DownloadType.TEXT_JSON) @QueryParam("jsonType") String jsonType) throws UnknownHostException {
	logger.debug("In tagger-persister genCSV");
	logger.info("Received request for collection: " + collectionCode + " with jsonType = " + jsonType);
	JsonDeserializer jsonD = new JsonDeserializer();
	
	if (0 == exportLimit) exportLimit = Integer.parseInt(PersisterConfigurator.getInstance().getProperty(PersisterConfigurationProperty.TWEETS_EXPORT_LIMIT));
	
	String fileName = jsonD.taggerGenerateJSON2JSON_100K_BasedOnTweetCount(collectionCode, exportLimit, DownloadJsonType.getDownloadJsonTypeFromString(jsonType));
	fileName = PersisterConfigurator.getInstance().getProperty(PersisterConfigurationProperty.PERSISTER_DOWNLOAD_URL) + collectionCode + "/" + fileName;

	logger.info("Done processing request for collection: " + collectionCode + ", returning created file: " + fileName);
	//return Response.ok(fileName).build();
	
	JSONObject obj = new JSONObject();
	obj.putAll(ResultStatus.getUIWrapper(collectionCode, null, fileName, true));
	logger.info("Returning JSON object: " + ResultStatus.getUIWrapper(collectionCode, null, fileName, true));
	return Response.ok(obj.toJSONString()).build();
}
 
Example 6
Source File: Persister4TaggerAPI.java    From AIDR with GNU Affero General Public License v3.0 6 votes vote down vote up
@GET
@Produces(MediaType.APPLICATION_JSON)
@Path("/genCSV")
public Response generateCSVFromLastestJSON(@QueryParam("collectionCode") String collectionCode, 
		@QueryParam("exportLimit") int exportLimit) throws UnknownHostException {
	logger.debug("In tagger-persister genCSV");
	logger.info("Received request for collection: " + collectionCode);
	JsonDeserializer jsonD = new JsonDeserializer();
	exportLimit = Integer.parseInt(PersisterConfigurator.getInstance().getProperty(PersisterConfigurationProperty.TWEETS_EXPORT_LIMIT));		// Koushik: added to override user specs
	String fileName = jsonD.taggerGenerateJSON2CSV_100K_BasedOnTweetCount(collectionCode, exportLimit);
	fileName = PersisterConfigurator.getInstance().getProperty(PersisterConfigurationProperty.PERSISTER_DOWNLOAD_URL) + collectionCode + "/" + fileName;

	logger.info("Done processing request for collection: " + collectionCode + ", returning created file: " + fileName);
	//return Response.ok(fileName).build();
	JSONObject obj = new JSONObject();
	try {
		obj.putAll(ResultStatus.getUIWrapper(collectionCode, null, fileName, true));
		logger.info("Returning JSON object: " + ResultStatus.getUIWrapper(collectionCode, null, fileName, true));
		return Response.ok(obj.toJSONString()).build();
	} catch (Exception e) {
		logger.error("Unable to return result ");
		obj.putAll(ResultStatus.getUIWrapper(collectionCode, null, fileName, false));
		return Response.ok(obj.toJSONString()).build();

	}
}
 
Example 7
Source File: Persister4TaggerAPI.java    From AIDR with GNU Affero General Public License v3.0 6 votes vote down vote up
@GET
@Produces(MediaType.APPLICATION_JSON)
@Path("/genTweetIds")
public Response generateTweetsIDSCSVFromAllJSON(@QueryParam("collectionCode") String collectionCode,
		@DefaultValue("true") @QueryParam("downloadLimited") Boolean downloadLimited) throws UnknownHostException {
	logger.debug("In tagger-persister genTweetIds");
	logger.info("received request for collection: " + collectionCode);

	JsonDeserializer jsonD = new JsonDeserializer();
	Map<String, Object> result = jsonD.generateClassifiedJson2TweetIdsCSV(collectionCode, downloadLimited);
	String fileName = PersisterConfigurator.getInstance().getProperty(PersisterConfigurationProperty.PERSISTER_DOWNLOAD_URL) + collectionCode + "/" + (String) result.get("fileName");

	logger.info("Done processing request for collection: " + collectionCode + ", returning created file: " + fileName);
	//return Response.ok(fileName).build();
	JSONObject obj = new JSONObject();
	if ((Integer) result.get("count") < Integer.parseInt(PersisterConfigurator.getInstance().getProperty(PersisterConfigurationProperty.DEFAULT_TWEETID_VOLUME_LIMIT))) {
		obj.putAll(ResultStatus.getUIWrapper(collectionCode, PersisterConfigurator.getInstance().getProperty(PersisterConfigurationProperty.PERSISTER_CHANGE_NOTIFY_MSG), fileName, true));
		logger.info("Returning JSON object: " + ResultStatus.getUIWrapper(collectionCode, PersisterConfigurator.getInstance().getProperty(PersisterConfigurationProperty.PERSISTER_CHANGE_NOTIFY_MSG), fileName, true));
		return Response.ok(obj.toJSONString()).build();
	} else {
		obj.putAll(ResultStatus.getUIWrapper(collectionCode,  PersisterConfigurator.getInstance().getProperty(PersisterConfigurationProperty.TWEET_DOWNLOAD_LIMIT_MSG_PREFIX) + PersisterConfigurator.getInstance().getProperty(PersisterConfigurationProperty.DEFAULT_TWEETID_VOLUME_LIMIT)+ PersisterConfigurator.getInstance().getProperty(PersisterConfigurationProperty.TWEET_DOWNLOAD_LIMIT_MSG_SUFFIX) + PersisterConfigurator.getInstance().getProperty(PersisterConfigurationProperty.PERSISTER_CHANGE_NOTIFY_MSG), fileName, true));
		logger.info("Returning JSON object: " + ResultStatus.getUIWrapper(collectionCode,  PersisterConfigurator.getInstance().getProperty(PersisterConfigurationProperty.TWEET_DOWNLOAD_LIMIT_MSG_PREFIX) + PersisterConfigurator.getInstance().getProperty(PersisterConfigurationProperty.DEFAULT_TWEETID_VOLUME_LIMIT)+ PersisterConfigurator.getInstance().getProperty(PersisterConfigurationProperty.TWEET_DOWNLOAD_LIMIT_MSG_SUFFIX) + PersisterConfigurator.getInstance().getProperty(PersisterConfigurationProperty.PERSISTER_CHANGE_NOTIFY_MSG), fileName, true));
		return Response.ok(obj.toJSONString()).build();
	}
}
 
Example 8
Source File: Persister4TaggerAPI.java    From AIDR with GNU Affero General Public License v3.0 5 votes vote down vote up
@GET
@Produces(MediaType.APPLICATION_JSON)
@Path("/downloadFacebookPosts")
public Response downloadFacebookPosts(@QueryParam("collectionCode") String collectionCode,
						@QueryParam("exportLimit") Integer exportLimit) throws UnknownHostException {
	
	ApplicationContext appContext = new ClassPathXmlApplicationContext("spring/spring-servlet.xml");
	FacebookDataFeedService facebookDataFeedService = (FacebookDataFeedService) appContext.getBean("facebookDataFeedService");
	
	if (null == exportLimit) {
		exportLimit = Integer
				.parseInt(PersisterConfigurator
						.getInstance()
						.getProperty(PersisterConfigurationProperty.DEFAULT_FACEBOOK_VOLUME_LIMIT));
	}
	
	List<FacebookDataFeed> fbFeeds = facebookDataFeedService.findbyCollectionCode(collectionCode, exportLimit);
	JsonDeserializer jsonD = new JsonDeserializer();
	Map<String, Object> result = jsonD.generateFileForFacebookDataFeed(collectionCode, fbFeeds);
	JSONObject obj = new JSONObject();
	result.put("feedCount", fbFeeds.size());
	obj.putAll(result);
	return Response.ok(obj.toJSONString()).build();
			/*.allow("POST", "OPTIONS", "HEAD")
			.header("Access-Control-Allow-Origin", "*")
			.header("Access-Control-Allow-Credentials", "true")
			.header("Access-Control-Allow-Methods", "POST, OPTIONS, HEAD")
			.header("Access-Control-Allow-Headers", "Content-Type, Accept, X-Requested-With")
			.build();*/
}
 
Example 9
Source File: Persister4TaggerAPI.java    From AIDR with GNU Affero General Public License v3.0 5 votes vote down vote up
@POST
@Produces(MediaType.APPLICATION_JSON)
@Path("/filter/genJson")
public Response generateJSONFromLastestJSONFiltered(String queryString, 
		@QueryParam("collectionCode") String collectionCode, 
		@QueryParam("exportLimit") Integer exportLimit,
		@DefaultValue(DownloadType.TEXT_JSON) @QueryParam("jsonType") String jsonType,
		@QueryParam("userName") String userName,
		@QueryParam("removeRetweet") boolean removeRetweet) throws UnknownHostException {
	logger.debug("In tagger-persister genCSV");
	logger.info("Received request for collection: " + collectionCode + " with jsonType = " + jsonType);
	
	DeserializeFilters des = new DeserializeFilters();
	JsonQueryList queryList = des.deserializeConstraints(queryString);
	if (queryList != null) {
		logger.info(collectionCode + ": received constraints = " + queryList.toString());
	} else {
		logger.info(collectionCode + ": received constraints = " + queryList);
	}
	
	JsonDeserializer jsonD = new JsonDeserializer();
	if (null == exportLimit) exportLimit = Integer.parseInt(PersisterConfigurator.getInstance().getProperty(PersisterConfigurationProperty.TWEETS_EXPORT_LIMIT));		// Koushik: added to override user specs
	Map<String, Object> generatedFileMap = jsonD.taggerGenerateJSON2JSONBasedOnTweetCountFiltered(collectionCode, exportLimit, queryList, DownloadJsonType.getDownloadJsonTypeFromString(jsonType), userName, removeRetweet);
	String fileName = (String) generatedFileMap.get("fileName");
	logger.info("Done processing request for collection: " + collectionCode + ", returning created file: " + fileName);
	//return Response.ok(fileName).build();
	
	JSONObject obj = new JSONObject();
	obj.putAll(ResultStatus.getUIWrapper(collectionCode, PersisterConfigurator.getInstance().getProperty(PersisterConfigurationProperty.PERSISTER_CHANGE_NOTIFY_MSG), fileName, true));
	obj.put("feedCount", generatedFileMap.get("currentSize"));
	logger.info("Returning JSON object: " + ResultStatus.getUIWrapper(collectionCode, PersisterConfigurator.getInstance().getProperty(PersisterConfigurationProperty.PERSISTER_CHANGE_NOTIFY_MSG), fileName, true));
	return Response.ok(obj.toJSONString()).build();
}
 
Example 10
Source File: Persister4TaggerAPI.java    From AIDR with GNU Affero General Public License v3.0 5 votes vote down vote up
@GET
@Produces(MediaType.APPLICATION_JSON)
@Path("/genJsonTweetIds")
public Response generateTweetsIDSJSONFromAllJSON(@QueryParam("collectionCode") String collectionCode,
		@DefaultValue("true") @QueryParam("downloadLimited") Boolean downloadLimited,
		@DefaultValue(DownloadType.TEXT_JSON) @QueryParam("jsonType") String jsonType) throws UnknownHostException {
	logger.debug("In tagger-persister genTweetIds");
	logger.info("Received request for collection: " + collectionCode + " with jsonType = " + jsonType);

	JsonDeserializer jsonD = new JsonDeserializer();
	Map<String, Object> result = jsonD.generateClassifiedJson2TweetIdsJSON(collectionCode, downloadLimited, DownloadJsonType.getDownloadJsonTypeFromString(jsonType));
	String fileName = PersisterConfigurator.getInstance().getProperty(PersisterConfigurationProperty.PERSISTER_DOWNLOAD_URL) + collectionCode + "/" + result.get("fileName");

	logger.info("Done processing request for collection: " + collectionCode + ", returning created file: " + fileName);
	//return Response.ok(fileName).build();
	JSONObject obj = new JSONObject();
	if ((Integer) result.get("count") < Integer.parseInt(PersisterConfigurator.getInstance().getProperty(PersisterConfigurationProperty.DEFAULT_TWEETID_VOLUME_LIMIT))) {
		obj.putAll(ResultStatus.getUIWrapper(collectionCode, null, fileName, true));
		logger.info("Returning JSON object: " + ResultStatus.getUIWrapper(collectionCode, null, fileName, true));
		return Response.ok(obj.toJSONString())
				.allow("POST", "OPTIONS", "HEAD")
				.header("Access-Control-Allow-Origin", "*")
				.header("Access-Control-Allow-Credentials", "true")
				.header("Access-Control-Allow-Methods", "POST, OPTIONS, HEAD")
				.header("Access-Control-Allow-Headers", "Content-Type, Accept, X-Requested-With")
				.build();
	} else {
		obj.putAll(ResultStatus.getUIWrapper(collectionCode,   PersisterConfigurator.getInstance().getProperty(PersisterConfigurationProperty.TWEET_DOWNLOAD_LIMIT_MSG_PREFIX) + PersisterConfigurator.getInstance().getProperty(PersisterConfigurationProperty.DEFAULT_TWEETID_VOLUME_LIMIT)+ PersisterConfigurator.getInstance().getProperty(PersisterConfigurationProperty.TWEET_DOWNLOAD_LIMIT_MSG_SUFFIX), fileName, true));
		logger.info("Returning JSON object: " + ResultStatus.getUIWrapper(collectionCode,   PersisterConfigurator.getInstance().getProperty(PersisterConfigurationProperty.TWEET_DOWNLOAD_LIMIT_MSG_PREFIX) + PersisterConfigurator.getInstance().getProperty(PersisterConfigurationProperty.DEFAULT_TWEETID_VOLUME_LIMIT)+ PersisterConfigurator.getInstance().getProperty(PersisterConfigurationProperty.TWEET_DOWNLOAD_LIMIT_MSG_SUFFIX) + PersisterConfigurator.getInstance().getProperty(PersisterConfigurationProperty.PERSISTER_CHANGE_NOTIFY_MSG), fileName, true));
		return Response.ok(obj.toJSONString())
				.allow("POST", "OPTIONS", "HEAD")
				.header("Access-Control-Allow-Origin", "*")
				.header("Access-Control-Allow-Credentials", "true")
				.header("Access-Control-Allow-Methods", "POST, OPTIONS, HEAD")
				.header("Access-Control-Allow-Headers", "Content-Type, Accept, X-Requested-With")
				.build();
	}
}
 
Example 11
Source File: Persister4TaggerAPI.java    From AIDR with GNU Affero General Public License v3.0 5 votes vote down vote up
/**
 * 
 * @param collectionCode
 * @param exportLimit
 * @return CSV format output from JSON filtered by user provided list of label names 
 * @throws UnknownHostException
 */
@POST
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
@Path("/filter/genCSV")
public Response generateCSVFromLastestJSONFiltered(String queryString, 
		@QueryParam("collectionCode") String collectionCode, 
		@QueryParam("exportLimit") Integer exportLimit,
		@QueryParam("removeRetweet") boolean removeRetweet,
		@QueryParam("userName") String userName) throws UnknownHostException {
	DeserializeFilters des = new DeserializeFilters();
	JsonQueryList queryList = des.deserializeConstraints(queryString);
	JsonDeserializer jsonD = new JsonDeserializer();
	
	logger.info("received request for collection: " + collectionCode + ", count = " + exportLimit + ", from user = " + userName);
	if (queryList != null) {
		logger.info(collectionCode + ": received constraints = " + queryList.toString());
	} else {
		logger.info(collectionCode + ": received constraints = " + queryList);
	}
	
	if (null == exportLimit) exportLimit = Integer.parseInt(PersisterConfigurator.getInstance().getProperty(PersisterConfigurationProperty.TWEETS_EXPORT_LIMIT));
	Map<String, Object> generatedFileMap = jsonD.taggerGenerateJSON2CSVBasedOnTweetCountFiltered(collectionCode, exportLimit, queryList, userName, removeRetweet);
	String fileName = (String) generatedFileMap.get("fileName");
	logger.info("done processing request for collection: " + collectionCode + ", returning created file: " + fileName);
	
	JSONObject obj = new JSONObject();
	obj.putAll(ResultStatus.getUIWrapper(collectionCode, PersisterConfigurator.getInstance().getProperty(PersisterConfigurationProperty.PERSISTER_CHANGE_NOTIFY_MSG), fileName, true));
	obj.put("feedCount", generatedFileMap.get("currentSize"));
	logger.info("Returning JSON object: " + ResultStatus.getUIWrapper(collectionCode, PersisterConfigurator.getInstance().getProperty(PersisterConfigurationProperty.PERSISTER_CHANGE_NOTIFY_MSG), fileName, true));
	return Response.ok(obj.toJSONString())
			.allow("POST", "OPTIONS", "HEAD")
			.header("Access-Control-Allow-Origin", "*")
			.header("Access-Control-Allow-Credentials", "true")
			.header("Access-Control-Allow-Methods", "POST, OPTIONS, HEAD")
			.header("Access-Control-Allow-Headers", "Content-Type, Accept, X-Requested-With")
			.build();
}
 
Example 12
Source File: Persist2FileAPI.java    From AIDR with GNU Affero General Public License v3.0 5 votes vote down vote up
@POST
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
@Path("/filter/genJson")
public Response generateJSONFromListFiltered(HumanLabeledDocumentListWrapper postBody,
		@QueryParam("collectionCode") String collectionCode, 
		@QueryParam("exportLimit") Integer exportLimit,
		@DefaultValue(DownloadType.TEXT_JSON) @QueryParam("jsonType") String jsonType,
		@QueryParam("userName") String userName)  throws UnknownHostException {
	
	logger.info("Received request for collection: " + collectionCode + " with jsonType = " + jsonType);
	//logger.info("Received query string: " + postBody.toJsonString());
	try {
		DeserializeFilters des = new DeserializeFilters();
		JsonQueryList queryList = des.deserializeConstraints(postBody.getQueryString());
		if (queryList != null) {
			logger.info(collectionCode + ": received constraints = " + queryList.toString());
		} else {
			logger.info(collectionCode + ": received constraints = " + queryList);
		}

		JsonDeserializer jsonD = new JsonDeserializer();
		if (null == exportLimit) exportLimit = Integer.parseInt(PersisterConfigurator.getInstance().getProperty(PersisterConfigurationProperty.TWEETS_EXPORT_LIMIT));		// Koushik: added to override user specs

		String fileName = jsonD.generateClassifiedList2JSON_100K_BasedOnTweetCountFiltered(collectionCode, exportLimit, queryList, 
				DownloadJsonType.getDownloadJsonTypeFromString(jsonType), postBody.getDtoList(), userName);

		logger.info("Done processing request for collection: " + collectionCode + ", returning created file: " + fileName);

		JSONObject obj = new JSONObject();
		obj.putAll(ResultStatus.getUIWrapper(collectionCode, PersisterConfigurator.getInstance().getProperty(PersisterConfigurationProperty.PERSISTER_CHANGE_NOTIFY_MSG), fileName, true));
		logger.info("Returning JSON object: " + ResultStatus.getUIWrapper(collectionCode, PersisterConfigurator.getInstance().getProperty(PersisterConfigurationProperty.PERSISTER_CHANGE_NOTIFY_MSG), fileName, true));
		return Response.ok(obj.toJSONString()).build();
	} catch (Exception e) {
		logger.error("Exception while genrating filtered json for collection: "+ collectionCode +"\t"+e.getStackTrace());
		return Response.ok(PersisterConfigurator.getInstance().getProperty(PersisterConfigurationProperty.STATUS_CODE_ERROR)).build();
	} 
}
 
Example 13
Source File: Persister4TaggerAPI.java    From AIDR with GNU Affero General Public License v3.0 4 votes vote down vote up
/**
 * 
 * @param collectionCode
 * @return CSV format output(tweetIds and classifiers) from JSON filtered by user provided list of label names 
 * @throws UnknownHostException
 */
@POST
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
@Path("/filter/genTweetIds")
public Response generateTweetsIDSCSVFromAllJSONFiltered(String queryString, 
		@QueryParam("collectionCode") String collectionCode,
		@DefaultValue("true") @QueryParam("downloadLimited") Boolean downloadLimited,
		@QueryParam("userName") String userName) 
				throws UnknownHostException {
	DeserializeFilters des = new DeserializeFilters();
	JsonQueryList queryList = des.deserializeConstraints(queryString);

	JsonDeserializer jsonD = new JsonDeserializer();
	logger.info("received request for collection: " + collectionCode);
	if (queryList != null) {
		logger.info(collectionCode + ": received constraints = " + queryList.toString());
	} else {
		logger.info(collectionCode + ": received constraints = " + queryList);
	}
	Map<String, Object> result = jsonD.generateClassifiedJson2TweetIdsAndClassifiersCSVFiltered(collectionCode, queryList, downloadLimited, userName);
	logger.info("Done processing request for collection: " + collectionCode + ", returning created file: " + result.get("fileName"));
	
	JSONObject obj = new JSONObject();
	if ((Integer) result.get("count") < Integer.parseInt(PersisterConfigurator.getInstance().getProperty(PersisterConfigurationProperty.DEFAULT_TWEETID_VOLUME_LIMIT))) {
		obj.putAll(ResultStatus.getUIWrapper(collectionCode, PersisterConfigurator.getInstance().getProperty(PersisterConfigurationProperty.PERSISTER_CHANGE_NOTIFY_MSG), result.get("fileName").toString(), true));
		logger.info("Returning JSON object: " + ResultStatus.getUIWrapper(collectionCode, PersisterConfigurator.getInstance().getProperty(PersisterConfigurationProperty.PERSISTER_CHANGE_NOTIFY_MSG), result.get("fileName").toString(), true));
		return Response.ok(obj.toJSONString())
				.allow("POST", "OPTIONS", "HEAD")
				.header("Access-Control-Allow-Origin", "*")
				.header("Access-Control-Allow-Credentials", "true")
				.header("Access-Control-Allow-Methods", "POST, OPTIONS, HEAD")
				.header("Access-Control-Allow-Headers", "Content-Type, Accept, X-Requested-With")
				.build();
	} else {
		obj.putAll(ResultStatus.getUIWrapper(collectionCode,  PersisterConfigurator.getInstance().getProperty(PersisterConfigurationProperty.TWEET_DOWNLOAD_LIMIT_MSG_PREFIX) + PersisterConfigurator.getInstance().getProperty(PersisterConfigurationProperty.DEFAULT_TWEETID_VOLUME_LIMIT)+ PersisterConfigurator.getInstance().getProperty(PersisterConfigurationProperty.TWEET_DOWNLOAD_LIMIT_MSG_SUFFIX) + PersisterConfigurator.getInstance().getProperty(PersisterConfigurationProperty.PERSISTER_CHANGE_NOTIFY_MSG), result.get("fileName").toString(), true));
		logger.info("Returning JSON object: " + ResultStatus.getUIWrapper(collectionCode,   PersisterConfigurator.getInstance().getProperty(PersisterConfigurationProperty.TWEET_DOWNLOAD_LIMIT_MSG_PREFIX) + PersisterConfigurator.getInstance().getProperty(PersisterConfigurationProperty.DEFAULT_TWEETID_VOLUME_LIMIT)+ PersisterConfigurator.getInstance().getProperty(PersisterConfigurationProperty.TWEET_DOWNLOAD_LIMIT_MSG_SUFFIX) + PersisterConfigurator.getInstance().getProperty(PersisterConfigurationProperty.PERSISTER_CHANGE_NOTIFY_MSG), result.get("fileName").toString(), true));
		return Response.ok(obj.toJSONString())
				.allow("POST", "OPTIONS", "HEAD")
				.header("Access-Control-Allow-Origin", "*")
				.header("Access-Control-Allow-Credentials", "true")
				.header("Access-Control-Allow-Methods", "POST, OPTIONS, HEAD")
				.header("Access-Control-Allow-Headers", "Content-Type, Accept, X-Requested-With")
				.build();
	}
}
 
Example 14
Source File: Persister4TaggerAPI.java    From AIDR with GNU Affero General Public License v3.0 4 votes vote down vote up
/**
 * 
 * @param collectionCode
 * @return CSV format output(tweetIds only) from JSON filtered by user provided list of label names 
 * @throws UnknownHostException
 */
@POST
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
@Path("/filter/genTweetIdsOnly")
public Response generateTweetsIDSOnlyCSVFromAllJSONFiltered(String queryString, 
		@QueryParam("collectionCode") String collectionCode,
		@QueryParam("exportLimit") Integer exportLimit,
		@QueryParam("removeRetweet") boolean removeRetweet,
		@QueryParam("userName") String userName) 
				throws UnknownHostException {
	DeserializeFilters des = new DeserializeFilters();
	JsonQueryList queryList = des.deserializeConstraints(queryString);

	JsonDeserializer jsonD = new JsonDeserializer();
	logger.info("received request for collection: " + collectionCode);
	if (queryList != null) {
		logger.info(collectionCode + ": received constraints = " + queryList.toString());
	} else {
		logger.info(collectionCode + ": received constraints = " + queryList);
	}
	
	if (null == exportLimit) exportLimit = Integer.parseInt(PersisterConfigurator.getInstance().getProperty(PersisterConfigurationProperty.DEFAULT_TWEETID_VOLUME_LIMIT));
		
	Map<String, Object> result = jsonD.generateClassifiedJson2TweetIdsOnlyCSVFiltered(collectionCode, exportLimit, queryList, userName, removeRetweet);
	logger.info("Done processing request for collection: " + collectionCode + ", returning created file: " + result.get("fileName"));
	
	JSONObject obj = new JSONObject();
	obj.put("feedCount", result.get("count"));
	if ((Integer) result.get("count") < Integer.parseInt(PersisterConfigurator.getInstance().getProperty(PersisterConfigurationProperty.DEFAULT_TWEETID_VOLUME_LIMIT))) {
		obj.putAll(ResultStatus.getUIWrapper(collectionCode, PersisterConfigurator.getInstance().getProperty(PersisterConfigurationProperty.PERSISTER_CHANGE_NOTIFY_MSG), result.get("fileName").toString(), true));
		logger.info("Returning JSON object: " + ResultStatus.getUIWrapper(collectionCode, PersisterConfigurator.getInstance().getProperty(PersisterConfigurationProperty.PERSISTER_CHANGE_NOTIFY_MSG), result.get("fileName").toString(), true));
		return Response.ok(obj.toJSONString())
				.allow("POST", "OPTIONS", "HEAD")
				.header("Access-Control-Allow-Origin", "*")
				.header("Access-Control-Allow-Credentials", "true")
				.header("Access-Control-Allow-Methods", "POST, OPTIONS, HEAD")
				.header("Access-Control-Allow-Headers", "Content-Type, Accept, X-Requested-With")
				.build();
	} else {
		obj.putAll(ResultStatus.getUIWrapper(collectionCode,  PersisterConfigurator.getInstance().getProperty(PersisterConfigurationProperty.TWEET_DOWNLOAD_LIMIT_MSG_PREFIX) + PersisterConfigurator.getInstance().getProperty(PersisterConfigurationProperty.DEFAULT_TWEETID_VOLUME_LIMIT)+ PersisterConfigurator.getInstance().getProperty(PersisterConfigurationProperty.TWEET_DOWNLOAD_LIMIT_MSG_SUFFIX) + PersisterConfigurator.getInstance().getProperty(PersisterConfigurationProperty.PERSISTER_CHANGE_NOTIFY_MSG), result.get("fileName").toString(), true));
		logger.info("Returning JSON object: " + ResultStatus.getUIWrapper(collectionCode,   PersisterConfigurator.getInstance().getProperty(PersisterConfigurationProperty.TWEET_DOWNLOAD_LIMIT_MSG_PREFIX) + PersisterConfigurator.getInstance().getProperty(PersisterConfigurationProperty.DEFAULT_TWEETID_VOLUME_LIMIT)+ PersisterConfigurator.getInstance().getProperty(PersisterConfigurationProperty.TWEET_DOWNLOAD_LIMIT_MSG_SUFFIX) + PersisterConfigurator.getInstance().getProperty(PersisterConfigurationProperty.PERSISTER_CHANGE_NOTIFY_MSG), result.get("fileName").toString(), true));
		return Response.ok(obj.toJSONString())
				.allow("POST", "OPTIONS", "HEAD")
				.header("Access-Control-Allow-Origin", "*")
				.header("Access-Control-Allow-Credentials", "true")
				.header("Access-Control-Allow-Methods", "POST, OPTIONS, HEAD")
				.header("Access-Control-Allow-Headers", "Content-Type, Accept, X-Requested-With")
				.build();
	}
}
 
Example 15
Source File: Persist2FileAPI.java    From AIDR with GNU Affero General Public License v3.0 4 votes vote down vote up
@POST
@Produces(MediaType.APPLICATION_JSON)
@Path("/filter/genJsonTweetIds")
public Response generateTweetsIDSJSONFromListFiltered(HumanLabeledDocumentListWrapper postBody,
		@QueryParam("collectionCode") String collectionCode, 
		@DefaultValue("true") @QueryParam("downloadLimited") Boolean downloadLimited,
		@DefaultValue(DownloadType.TEXT_JSON) @QueryParam("jsonType") String jsonType,
		@QueryParam("userName") String userName)  throws UnknownHostException {
	
	try {
		logger.debug("In list-persister genJsonTweetIds");
		logger.info("Received request for collection: " + collectionCode + " with jsonType = " + jsonType);
		DeserializeFilters des = new DeserializeFilters();
		JsonQueryList queryList = des.deserializeConstraints(postBody.getQueryString());
		if (queryList != null) {
			logger.info(collectionCode + ": received constraints = " + queryList.toString());
		} else {
			logger.info(collectionCode + ": received constraints = " + queryList);
		}
		JsonDeserializer jsonD = new JsonDeserializer();
		Map<String, Object> result = jsonD.generateClassifiedList2TweetIdsJSONFiltered(collectionCode, downloadLimited, queryList, 
				DownloadJsonType.getDownloadJsonTypeFromString(jsonType), postBody.getDtoList(), userName);
		String fileName = result.get("fileName") != null ? result.get("fileName").toString() : null;

		JSONObject obj = new JSONObject();
		if ((Integer) result.get("count") < Integer.parseInt(PersisterConfigurator.getInstance().getProperty(PersisterConfigurationProperty.DEFAULT_TWEETID_VOLUME_LIMIT))) {
			obj.putAll(ResultStatus.getUIWrapper(collectionCode, PersisterConfigurator.getInstance().getProperty(PersisterConfigurationProperty.PERSISTER_CHANGE_NOTIFY_MSG), fileName, true));
			logger.info("Returning JSON object: " + ResultStatus.getUIWrapper(collectionCode, PersisterConfigurator.getInstance().getProperty(PersisterConfigurationProperty.PERSISTER_CHANGE_NOTIFY_MSG), fileName, true));
			return Response.ok(obj.toJSONString())
					.allow("POST", "OPTIONS", "HEAD")
					.header("Access-Control-Allow-Origin", "*")
					.header("Access-Control-Allow-Credentials", "true")
					.header("Access-Control-Allow-Methods", "POST, OPTIONS, HEAD")
					.header("Access-Control-Allow-Headers", "Content-Type, Accept, X-Requested-With")
					.build();
		} else {
			obj.putAll(ResultStatus
					.getUIWrapper(
							collectionCode,
							PersisterConfigurator
									.getInstance()
									.getProperty(
											PersisterConfigurationProperty.TWEET_DOWNLOAD_LIMIT_MSG_PREFIX)
									+ PersisterConfigurator
											.getInstance()
											.getProperty(
													PersisterConfigurationProperty.DEFAULT_TWEETID_VOLUME_LIMIT)
									+ PersisterConfigurator
											.getInstance()
											.getProperty(
													PersisterConfigurationProperty.TWEET_DOWNLOAD_LIMIT_MSG_SUFFIX)
									+ PersisterConfigurator
											.getInstance()
											.getProperty(
													PersisterConfigurationProperty.PERSISTER_CHANGE_NOTIFY_MSG),
							fileName, true));
			logger.info("Returning JSON object: "
					+ ResultStatus
							.getUIWrapper(
									collectionCode,
									PersisterConfigurator
											.getInstance()
											.getProperty(
													PersisterConfigurationProperty.TWEET_DOWNLOAD_LIMIT_MSG_PREFIX)
											+ PersisterConfigurator
													.getInstance()
													.getProperty(
															PersisterConfigurationProperty.DEFAULT_TWEETID_VOLUME_LIMIT)
											+ PersisterConfigurator
													.getInstance()
													.getProperty(
															PersisterConfigurationProperty.TWEET_DOWNLOAD_LIMIT_MSG_SUFFIX)
											+ PersisterConfigurator
													.getInstance()
													.getProperty(
															PersisterConfigurationProperty.PERSISTER_CHANGE_NOTIFY_MSG),
									fileName, true));
			return Response.ok(obj.toJSONString())
					.allow("POST", "OPTIONS", "HEAD")
					.header("Access-Control-Allow-Origin", "*")
					.header("Access-Control-Allow-Credentials", "true")
					.header("Access-Control-Allow-Methods", "POST, OPTIONS, HEAD")
					.header("Access-Control-Allow-Headers", "Content-Type, Accept, X-Requested-With")
					.build();
		}
	} catch (Exception e) {
		logger.error("Exception while genrating filtered tweetIds Json for collection: "+ collectionCode +"\t"+e.getStackTrace());
		return Response.ok(PersisterConfigurator.getInstance().getProperty(PersisterConfigurationProperty.STATUS_CODE_ERROR)).build();
	} 
}
 
Example 16
Source File: Persist2FileAPI.java    From AIDR with GNU Affero General Public License v3.0 4 votes vote down vote up
/**
 * 
 * @param collectionCode
 * @return CSV format output from JSON filtered by user provided list of label names 
 * @throws UnknownHostException
 */
@POST
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
@Path("/filter/genCSVTweetIds")
public Response generateTweetsIDSCSVFromListFiltered(HumanLabeledDocumentListWrapper postBody,
		@QueryParam("collectionCode") String collectionCode,
		@DefaultValue("true") @QueryParam("downloadLimited") Boolean downloadLimited,
		@QueryParam("userName") String userName) 
				throws UnknownHostException {

	try {
		DeserializeFilters des = new DeserializeFilters();
		JsonQueryList queryList = des.deserializeConstraints(postBody.getQueryString());

		JsonDeserializer jsonD = new JsonDeserializer();
		logger.info("received request for collection: " + collectionCode);
		if (queryList != null) {
			logger.info(collectionCode + ": received constraints = " + queryList.toString());
		} else {
			logger.info(collectionCode + ": received constraints = " + queryList);
		}

		JSONObject obj = new JSONObject();
		Map<String, Object> result = jsonD.generateClassifiedList2TweetIdsCSVFiltered(collectionCode, queryList, downloadLimited, postBody.getDtoList(), userName);
		String fileName = result.get("fileName") != null ? result.get("fileName").toString() : null;
		if ((Integer) result.get("count") < Integer.parseInt(PersisterConfigurator.getInstance().getProperty(PersisterConfigurationProperty.DEFAULT_TWEETID_VOLUME_LIMIT))) {
			obj.putAll(ResultStatus.getUIWrapper(collectionCode, PersisterConfigurator.getInstance().getProperty(PersisterConfigurationProperty.PERSISTER_CHANGE_NOTIFY_MSG), fileName, true));
			logger.info("Returning JSON object: " + ResultStatus.getUIWrapper(collectionCode, PersisterConfigurator.getInstance().getProperty(PersisterConfigurationProperty.PERSISTER_CHANGE_NOTIFY_MSG), fileName, true));
			return Response.ok(obj.toJSONString())
					.allow("POST", "OPTIONS", "HEAD")
					.header("Access-Control-Allow-Origin", "*")
					.header("Access-Control-Allow-Credentials", "true")
					.header("Access-Control-Allow-Methods", "POST, OPTIONS, HEAD")
					.header("Access-Control-Allow-Headers", "Content-Type, Accept, X-Requested-With")
					.build();
		} else {
			obj.putAll(ResultStatus
					.getUIWrapper(
							collectionCode,
							PersisterConfigurator
									.getInstance()
									.getProperty(
											PersisterConfigurationProperty.TWEET_DOWNLOAD_LIMIT_MSG_PREFIX)
									+ PersisterConfigurator
											.getInstance()
											.getProperty(
													PersisterConfigurationProperty.DEFAULT_TWEETID_VOLUME_LIMIT)
									+ PersisterConfigurator
											.getInstance()
											.getProperty(
													PersisterConfigurationProperty.TWEET_DOWNLOAD_LIMIT_MSG_SUFFIX)
									+ PersisterConfigurator
											.getInstance()
											.getProperty(
													PersisterConfigurationProperty.PERSISTER_CHANGE_NOTIFY_MSG),
							fileName, true));
			logger.info("Returning JSON object: "
					+ ResultStatus
							.getUIWrapper(
									collectionCode,
									PersisterConfigurator
											.getInstance()
											.getProperty(
													PersisterConfigurationProperty.TWEET_DOWNLOAD_LIMIT_MSG_PREFIX)
											+ PersisterConfigurator
													.getInstance()
													.getProperty(
															PersisterConfigurationProperty.DEFAULT_TWEETID_VOLUME_LIMIT)
											+ PersisterConfigurator
													.getInstance()
													.getProperty(
															PersisterConfigurationProperty.TWEET_DOWNLOAD_LIMIT_MSG_SUFFIX)
											+ PersisterConfigurator
													.getInstance()
													.getProperty(
															PersisterConfigurationProperty.PERSISTER_CHANGE_NOTIFY_MSG),
									fileName, true));
			return Response.ok(obj.toJSONString())
					.allow("POST", "OPTIONS", "HEAD")
					.header("Access-Control-Allow-Origin", "*")
					.header("Access-Control-Allow-Credentials", "true")
					.header("Access-Control-Allow-Methods", "POST, OPTIONS, HEAD")
					.header("Access-Control-Allow-Headers", "Content-Type, Accept, X-Requested-With")
					.build();
		}
	} catch (Exception e) {
		logger.error("Exception while genrating filtered tweetIds csv for collection: "+ collectionCode +"\t"+e.getStackTrace());
		return Response.ok(
				PersisterConfigurator.getInstance().getProperty(
						PersisterConfigurationProperty.STATUS_CODE_ERROR))
				.build();
} 
}
 
Example 17
Source File: Persister4TaggerAPI.java    From AIDR with GNU Affero General Public License v3.0 4 votes vote down vote up
@POST
@Produces(MediaType.APPLICATION_JSON)
@Path("/filter/genJsonTweetIds")
public Response generateTweetsIDSJSONFromAllJSONFiltered(String queryString, 
		@QueryParam("collectionCode") String collectionCode, 
		@DefaultValue("true") @QueryParam("downloadLimited") Boolean downloadLimited,
		@DefaultValue(DownloadType.TEXT_JSON) @QueryParam("jsonType") String jsonType,
		@QueryParam("userName") String userName) throws UnknownHostException {
	logger.debug("In tagger-persister genTweetIds");
	logger.info("Received request for collection: " + collectionCode + " with jsonType = " + jsonType);
	DeserializeFilters des = new DeserializeFilters();
	JsonQueryList queryList = des.deserializeConstraints(queryString);
	if (queryList != null) {
		logger.info(collectionCode + ": received constraints = " + queryList.toString());
	} else {
		logger.info(collectionCode + ": received constraints = " + queryList);
	}
	JsonDeserializer jsonD = new JsonDeserializer();
	Map<String, Object> result = jsonD.generateClassifiedJson2TweetIdsJSONFiltered(collectionCode, downloadLimited, queryList, DownloadJsonType.getDownloadJsonTypeFromString(jsonType), userName);
	
	logger.info("Done processing request for collection: " + collectionCode + ", returning created file: " + result.get("fileName"));
	//return Response.ok(fileName).build();
	JSONObject obj = new JSONObject();
	if ((Integer) result.get("count") < Integer.parseInt(PersisterConfigurator.getInstance().getProperty(PersisterConfigurationProperty.DEFAULT_TWEETID_VOLUME_LIMIT))) {
		obj.putAll(ResultStatus.getUIWrapper(collectionCode, PersisterConfigurator.getInstance().getProperty(PersisterConfigurationProperty.PERSISTER_CHANGE_NOTIFY_MSG), result.get("fileName").toString(), true));
		logger.info("Returning JSON object: " + ResultStatus.getUIWrapper(collectionCode, PersisterConfigurator.getInstance().getProperty(PersisterConfigurationProperty.PERSISTER_CHANGE_NOTIFY_MSG), result.get("fileName").toString(), true));
		return Response.ok(obj.toJSONString())
				.allow("POST", "OPTIONS", "HEAD")
				.header("Access-Control-Allow-Origin", "*")
				.header("Access-Control-Allow-Credentials", "true")
				.header("Access-Control-Allow-Methods", "POST, OPTIONS, HEAD")
				.header("Access-Control-Allow-Headers", "Content-Type, Accept, X-Requested-With")
				.build();
	} else {
		obj.putAll(ResultStatus.getUIWrapper(collectionCode,   PersisterConfigurator.getInstance().getProperty(PersisterConfigurationProperty.TWEET_DOWNLOAD_LIMIT_MSG_PREFIX) + PersisterConfigurator.getInstance().getProperty(PersisterConfigurationProperty.DEFAULT_TWEETID_VOLUME_LIMIT)+ PersisterConfigurator.getInstance().getProperty(PersisterConfigurationProperty.TWEET_DOWNLOAD_LIMIT_MSG_SUFFIX) + PersisterConfigurator.getInstance().getProperty(PersisterConfigurationProperty.PERSISTER_CHANGE_NOTIFY_MSG), result.get("fileName").toString(), true));
		logger.info("Returning JSON object: " + ResultStatus.getUIWrapper(collectionCode,  PersisterConfigurator.getInstance().getProperty(PersisterConfigurationProperty.TWEET_DOWNLOAD_LIMIT_MSG_PREFIX) + PersisterConfigurator.getInstance().getProperty(PersisterConfigurationProperty.DEFAULT_TWEETID_VOLUME_LIMIT)+ PersisterConfigurator.getInstance().getProperty(PersisterConfigurationProperty.TWEET_DOWNLOAD_LIMIT_MSG_SUFFIX) + PersisterConfigurator.getInstance().getProperty(PersisterConfigurationProperty.PERSISTER_CHANGE_NOTIFY_MSG), result.get("fileName").toString(), true));
		return Response.ok(obj.toJSONString())
				.allow("POST", "OPTIONS", "HEAD")
				.header("Access-Control-Allow-Origin", "*")
				.header("Access-Control-Allow-Credentials", "true")
				.header("Access-Control-Allow-Methods", "POST, OPTIONS, HEAD")
				.header("Access-Control-Allow-Headers", "Content-Type, Accept, X-Requested-With")
				.build();
	}
}
 
Example 18
Source File: Persister4TaggerAPI.java    From AIDR with GNU Affero General Public License v3.0 4 votes vote down vote up
@POST
@Produces(MediaType.APPLICATION_JSON)
@Path("/filter/genJsonTweetIdsOnly")
public Response generateTweetsIDSOnlyJSONFromAllJSONFiltered(String queryString, 
		@QueryParam("collectionCode") String collectionCode, 
		@QueryParam("exportLimit") Integer exportLimit,
		@QueryParam("removeRetweet") boolean removeRetweet,
		@DefaultValue(DownloadType.TEXT_JSON) @QueryParam("jsonType") String jsonType,
		@QueryParam("userName") String userName) throws UnknownHostException {
	logger.debug("In tagger-persister genTweetIds");
	logger.info("Received request for collection: " + collectionCode + " with jsonType = " + jsonType);
	DeserializeFilters des = new DeserializeFilters();
	JsonQueryList queryList = des.deserializeConstraints(queryString);
	if (queryList != null) {
		logger.info(collectionCode + ": received constraints = " + queryList.toString());
	} else {
		logger.info(collectionCode + ": received constraints = " + queryList);
	}
	JsonDeserializer jsonD = new JsonDeserializer();
	
	Map<String, Object> result = jsonD.generateClassifiedJson2TweetIdsOnlyJSONFiltered(collectionCode, exportLimit, queryList, DownloadJsonType.getDownloadJsonTypeFromString(jsonType), userName, removeRetweet);
	
	logger.info("Done processing request for collection: " + collectionCode + ", returning created file: " + result.get("fileName"));
	//return Response.ok(fileName).build();
	JSONObject obj = new JSONObject();
	if ((Integer) result.get("count") < Integer.parseInt(PersisterConfigurator.getInstance().getProperty(PersisterConfigurationProperty.DEFAULT_TWEETID_VOLUME_LIMIT))) {
		obj.putAll(ResultStatus.getUIWrapper(collectionCode, PersisterConfigurator.getInstance().getProperty(PersisterConfigurationProperty.PERSISTER_CHANGE_NOTIFY_MSG), result.get("fileName").toString(), true));
		logger.info("Returning JSON object: " + ResultStatus.getUIWrapper(collectionCode, PersisterConfigurator.getInstance().getProperty(PersisterConfigurationProperty.PERSISTER_CHANGE_NOTIFY_MSG), result.get("fileName").toString(), true));
		return Response.ok(obj.toJSONString())
				.allow("POST", "OPTIONS", "HEAD")
				.header("Access-Control-Allow-Origin", "*")
				.header("Access-Control-Allow-Credentials", "true")
				.header("Access-Control-Allow-Methods", "POST, OPTIONS, HEAD")
				.header("Access-Control-Allow-Headers", "Content-Type, Accept, X-Requested-With")
				.build();
	} else {
		obj.putAll(ResultStatus.getUIWrapper(collectionCode,   PersisterConfigurator.getInstance().getProperty(PersisterConfigurationProperty.TWEET_DOWNLOAD_LIMIT_MSG_PREFIX) + PersisterConfigurator.getInstance().getProperty(PersisterConfigurationProperty.DEFAULT_TWEETID_VOLUME_LIMIT)+ PersisterConfigurator.getInstance().getProperty(PersisterConfigurationProperty.TWEET_DOWNLOAD_LIMIT_MSG_SUFFIX) + PersisterConfigurator.getInstance().getProperty(PersisterConfigurationProperty.PERSISTER_CHANGE_NOTIFY_MSG), result.get("fileName").toString(), true));
		logger.info("Returning JSON object: " + ResultStatus.getUIWrapper(collectionCode,  PersisterConfigurator.getInstance().getProperty(PersisterConfigurationProperty.TWEET_DOWNLOAD_LIMIT_MSG_PREFIX) + PersisterConfigurator.getInstance().getProperty(PersisterConfigurationProperty.DEFAULT_TWEETID_VOLUME_LIMIT)+ PersisterConfigurator.getInstance().getProperty(PersisterConfigurationProperty.TWEET_DOWNLOAD_LIMIT_MSG_SUFFIX) + PersisterConfigurator.getInstance().getProperty(PersisterConfigurationProperty.PERSISTER_CHANGE_NOTIFY_MSG), result.get("fileName").toString(), true));
		return Response.ok(obj.toJSONString())
				.allow("POST", "OPTIONS", "HEAD")
				.header("Access-Control-Allow-Origin", "*")
				.header("Access-Control-Allow-Credentials", "true")
				.header("Access-Control-Allow-Methods", "POST, OPTIONS, HEAD")
				.header("Access-Control-Allow-Headers", "Content-Type, Accept, X-Requested-With")
				.build();
	}
}
 
Example 19
Source File: Persist2FileAPI.java    From AIDR with GNU Affero General Public License v3.0 4 votes vote down vote up
/**
 * 
 * @param collectionCode
 * @param exportLimit
 * @return CSV format output from JSON filtered by user provided list of label names 
 * @throws UnknownHostException
 */
@POST
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
@Path("/filter/genCSV")
public Response generateCSVFromListFiltered(HumanLabeledDocumentListWrapper postBody,
		@QueryParam("collectionCode") String collectionCode, 
		@QueryParam("exportLimit") Integer exportLimit,
		@QueryParam("userName") String userName) throws UnknownHostException {

	try {
		DeserializeFilters des = new DeserializeFilters();
		JsonQueryList queryList = des.deserializeConstraints(postBody.getQueryString());
		JsonDeserializer jsonD = new JsonDeserializer();

		logger.info("received request for collection: " + collectionCode);
		if (queryList != null) {
			logger.info(collectionCode + ": received constraints = " + queryList.toString());
		} else {
			logger.info(collectionCode + ": received constraints = " + queryList);
		}

		if (null == exportLimit) exportLimit = Integer.parseInt(PersisterConfigurator.getInstance().getProperty(PersisterConfigurationProperty.TWEETS_EXPORT_LIMIT));
		JSONObject obj = new JSONObject();
		String fileName = jsonD.generateClassifiedList2CSV_100K_BasedOnTweetCountFiltered(collectionCode, exportLimit, queryList, postBody.getDtoList(), userName);
		logger.info("Generated fileName = " + fileName);

		obj.putAll(ResultStatus.getUIWrapper(collectionCode, PersisterConfigurator.getInstance().getProperty(PersisterConfigurationProperty.PERSISTER_CHANGE_NOTIFY_MSG), fileName, true));
		logger.info("done processing request for collection: " + collectionCode + ", returning created file: " + fileName);

		logger.info("Returning JSON object: " + ResultStatus.getUIWrapper(collectionCode, PersisterConfigurator.getInstance().getProperty(PersisterConfigurationProperty.PERSISTER_CHANGE_NOTIFY_MSG), fileName, true));
		return Response.ok(obj.toJSONString())
				.allow("POST", "OPTIONS", "HEAD")
				.header("Access-Control-Allow-Origin", "*")
				.header("Access-Control-Allow-Credentials", "true")
				.header("Access-Control-Allow-Methods", "POST, OPTIONS, HEAD")
				.header("Access-Control-Allow-Headers", "Content-Type, Accept, X-Requested-With")
				.build();
	} catch (Exception e) {
		logger.error("Exception while genrating filtered csv for collection: "+ collectionCode +"\t"+e.getStackTrace());
		return Response.ok(PersisterConfigurator.getInstance().getProperty(PersisterConfigurationProperty.STATUS_CODE_ERROR)).build();
	} 
}