{
logger.info("Ignoring weekend stats");
return null;
}
UsageMetricDTO umdto = (UsageMetricDTO) inActionContext.getActionContext().getParams();
Principal principal = inActionContext.getActionContext().getPrincipal();
Long streamScopeId = null;
String uniqueKey = null;
String streamJson = umdto.getMetricDetails();
logger.info("Stream metric received: " + streamJson);
if (umdto.isStreamView() && streamJson != null && streamJson.startsWith("{"))
{
// {"query":{"recipient":[{"type":"GROUP", "name":"woot"}], "sortBy":"date"}}
try
{
JSONObject jsonObj = JSONObject.fromObject(streamJson);
if (jsonObj.containsKey("query"))
{
jsonObj = jsonObj.getJSONObject("query");
if (jsonObj.containsKey("recipient"))
{
JSONArray recipients = jsonObj.getJSONArray("recipient");
if (recipients.size() == 1)
{
jsonObj = recipients.getJSONObject(0);
if (jsonObj.containsKey("type") && jsonObj.containsKey("name"))
{
uniqueKey = jsonObj.getString("name");
if ("PERSON".equals(jsonObj.getString("type")))
{
streamScopeId = personStreamScopeIdMapper.execute(uniqueKey);
logger.debug("Found person stream scope id " + streamScopeId + " from account id: "
+ uniqueKey);
}
else if ("GROUP".equals(jsonObj.getString("type")))
{
streamScopeId = groupStreamScopeIdMapper.execute(uniqueKey);
logger.debug("Found group stream scope id " + streamScopeId + " from short name: "
+ uniqueKey);
}
}
}
}
}
}
catch (Exception e)
{
logger.info("Potentially invalid JSON: " + streamJson);
}
}
UsageMetric um = new UsageMetric(principal.getId(), umdto.isPageView(), umdto.isStreamView(), streamScopeId,
new Date());
logger.trace("Registering metric for user: " + principal.getAccountId() + " StreamView:" + umdto.isStreamView()
+ " PageView:" + umdto.isPageView() + " MetricDetails: " + umdto.getMetricDetails());
inActionContext.getUserActionRequests().add(
new UserActionRequest("persistUserMetricAsyncAction", null, new PersistenceRequest<UsageMetric>(um)));
return null;
}