@Test public final void textPerformActionOnWeekend() { final ArrayList<UserActionRequest> uar = new ArrayList<UserActionRequest>(); context.checking(new Expectations() { { oneOf(dayOfWeekStrategy).isWeekday(with(any(Date.class))); will(returnValue(false)); } }); sut.execute(taskHandlerActionContextMock); context.assertIsSatisfied(); }
@Override public Serializable execute(final TaskHandlerActionContext<PrincipalActionContext> inActionContext) { Date date = new Date(); if (!dayOfWeekStrategy.isWeekday(date)) { 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("{")) { 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; }
RegisterUsageMetricExecution implements TaskHandlerExecutionStrategy<PrincipalActionContext> { @Override public Serializable execute(final TaskHandlerActionContext<PrincipalActionContext> inActionContext) { Date date = new Date(); if (!dayOfWeekStrategy.isWeekday(date)) { 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("{")) { 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; } }
RegisterUsageMetricExecution implements TaskHandlerExecutionStrategy<PrincipalActionContext> { @Override public Serializable execute(final TaskHandlerActionContext<PrincipalActionContext> inActionContext) { Date date = new Date(); if (!dayOfWeekStrategy.isWeekday(date)) { 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("{")) { 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; } RegisterUsageMetricExecution(final DomainMapper<String, Long> inPersonStreamScopeIdMapper,
            final DomainMapper<String, Long> inGroupStreamScopeIdMapper, final DayOfWeekStrategy inDayOfWeekStrategy); }
RegisterUsageMetricExecution implements TaskHandlerExecutionStrategy<PrincipalActionContext> { @Override public Serializable execute(final TaskHandlerActionContext<PrincipalActionContext> inActionContext) { Date date = new Date(); if (!dayOfWeekStrategy.isWeekday(date)) { 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("{")) { 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; } RegisterUsageMetricExecution(final DomainMapper<String, Long> inPersonStreamScopeIdMapper,
            final DomainMapper<String, Long> inGroupStreamScopeIdMapper, final DayOfWeekStrategy inDayOfWeekStrategy); @Override Serializable execute(final TaskHandlerActionContext<PrincipalActionContext> inActionContext); }
RegisterUsageMetricExecution implements TaskHandlerExecutionStrategy<PrincipalActionContext> { @Override public Serializable execute(final TaskHandlerActionContext<PrincipalActionContext> inActionContext) { Date date = new Date(); if (!dayOfWeekStrategy.isWeekday(date)) { 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("{")) { 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; } RegisterUsageMetricExecution(final DomainMapper<String, Long> inPersonStreamScopeIdMapper,
            final DomainMapper<String, Long> inGroupStreamScopeIdMapper, final DayOfWeekStrategy inDayOfWeekStrategy); @Override Serializable execute(final TaskHandlerActionContext<PrincipalActionContext> inActionContext);  }