@Test public void testExecuteOnPrivateActivity() { final String groupShortName = "sdlkjfsd"; final String content = "hi #there #potato"; final List<String> hashTagContents = new ArrayList<String>(); hashTagContents.add("#there"); hashTagContents.add("#potato"); final List<HashTag> hashTags = new ArrayList<HashTag>(); hashTags.add(new HashTag("#there")); hashTags.add(new HashTag("#potato")); context.checking(new Expectations() { { allowing(activity).getId(); will(returnValue(3L)); allowing(activity).getRecipientStreamScope(); will(returnValue(streamScope)); oneOf(streamScope).getScopeType(); will(returnValue(ScopeType.GROUP)); oneOf(streamScope).getUniqueKey(); will(returnValue(groupShortName)); oneOf(activity).getBaseObjectType(); will(returnValue(BaseObjectType.NOTE)); oneOf(activity).getBaseObject(); will(returnValue(baseObject)); allowing(activity).getPostedTime(); will(returnValue(new Date())); oneOf(contentExtractor).extractContent(BaseObjectType.NOTE, baseObject); will(returnValue(content)); oneOf(hashTagExtractor).extractAll(content); will(returnValue(hashTagContents)); oneOf(hashTagMapper).execute(hashTagContents); will(returnValue(hashTags)); oneOf(streamHashTagInsertMapper).execute(with(any(PersistenceRequest.class))); oneOf(streamHashTagInsertMapper).execute(with(any(PersistenceRequest.class))); } }); StoreStreamHashTagsForActivityStrategy sut = buildSut(); sut.execute(activity); context.assertIsSatisfied(); }
public void execute(final Activity inActivity) { log.info("Finding hashtags for activity #" + inActivity.getId()); ScopeType scopeType = inActivity.getRecipientStreamScope().getScopeType(); if (scopeType != ScopeType.GROUP && scopeType != ScopeType.PERSON) { log.info("This activity isn't a group or person stream - not handled."); return; } String recipientStreamKey = inActivity.getRecipientStreamScope().getUniqueKey(); StreamHashTag streamHashTag; List<String> hashTagStrings = getHashTags(inActivity); if (hashTagStrings.size() == 0) { return; } for (HashTag hashTag : hashTagMapper.execute(hashTagStrings)) { if (log.isDebugEnabled()) { log.debug("Adding StreamHashTag " + hashTag.getContent() + " for direct recipient stream of type " + scopeType + ", key: " + recipientStreamKey + ", activity id: #" + inActivity.getId()); } streamHashTag = new StreamHashTag(hashTag, inActivity, recipientStreamKey, scopeType); streamHashTagInsertMapper.execute(new PersistenceRequest<StreamHashTag>(streamHashTag)); } }
StoreStreamHashTagsForActivityStrategyImpl implements StoreStreamHashTagsForActivityStrategy { public void execute(final Activity inActivity) { log.info("Finding hashtags for activity #" + inActivity.getId()); ScopeType scopeType = inActivity.getRecipientStreamScope().getScopeType(); if (scopeType != ScopeType.GROUP && scopeType != ScopeType.PERSON) { log.info("This activity isn't a group or person stream - not handled."); return; } String recipientStreamKey = inActivity.getRecipientStreamScope().getUniqueKey(); StreamHashTag streamHashTag; List<String> hashTagStrings = getHashTags(inActivity); if (hashTagStrings.size() == 0) { return; } for (HashTag hashTag : hashTagMapper.execute(hashTagStrings)) { if (log.isDebugEnabled()) { log.debug("Adding StreamHashTag " + hashTag.getContent() + " for direct recipient stream of type " + scopeType + ", key: " + recipientStreamKey + ", activity id: #" + inActivity.getId()); } streamHashTag = new StreamHashTag(hashTag, inActivity, recipientStreamKey, scopeType); streamHashTagInsertMapper.execute(new PersistenceRequest<StreamHashTag>(streamHashTag)); } } }
StoreStreamHashTagsForActivityStrategyImpl implements StoreStreamHashTagsForActivityStrategy { public void execute(final Activity inActivity) { log.info("Finding hashtags for activity #" + inActivity.getId()); ScopeType scopeType = inActivity.getRecipientStreamScope().getScopeType(); if (scopeType != ScopeType.GROUP && scopeType != ScopeType.PERSON) { log.info("This activity isn't a group or person stream - not handled."); return; } String recipientStreamKey = inActivity.getRecipientStreamScope().getUniqueKey(); StreamHashTag streamHashTag; List<String> hashTagStrings = getHashTags(inActivity); if (hashTagStrings.size() == 0) { return; } for (HashTag hashTag : hashTagMapper.execute(hashTagStrings)) { if (log.isDebugEnabled()) { log.debug("Adding StreamHashTag " + hashTag.getContent() + " for direct recipient stream of type " + scopeType + ", key: " + recipientStreamKey + ", activity id: #" + inActivity.getId()); } streamHashTag = new StreamHashTag(hashTag, inActivity, recipientStreamKey, scopeType); streamHashTagInsertMapper.execute(new PersistenceRequest<StreamHashTag>(streamHashTag)); } } StoreStreamHashTagsForActivityStrategyImpl(final HashTagExtractor inHashTagExtractor,
            final ActivityContentExtractor inContentExtractor,
            final DecoratedPartialResponseDomainMapper<List<String>, List<HashTag>> inHashTagMapper,
            final InsertMapper<StreamHashTag> inStreamHashTagInsertMapper); }
StoreStreamHashTagsForActivityStrategyImpl implements StoreStreamHashTagsForActivityStrategy { public void execute(final Activity inActivity) { log.info("Finding hashtags for activity #" + inActivity.getId()); ScopeType scopeType = inActivity.getRecipientStreamScope().getScopeType(); if (scopeType != ScopeType.GROUP && scopeType != ScopeType.PERSON) { log.info("This activity isn't a group or person stream - not handled."); return; } String recipientStreamKey = inActivity.getRecipientStreamScope().getUniqueKey(); StreamHashTag streamHashTag; List<String> hashTagStrings = getHashTags(inActivity); if (hashTagStrings.size() == 0) { return; } for (HashTag hashTag : hashTagMapper.execute(hashTagStrings)) { if (log.isDebugEnabled()) { log.debug("Adding StreamHashTag " + hashTag.getContent() + " for direct recipient stream of type " + scopeType + ", key: " + recipientStreamKey + ", activity id: #" + inActivity.getId()); } streamHashTag = new StreamHashTag(hashTag, inActivity, recipientStreamKey, scopeType); streamHashTagInsertMapper.execute(new PersistenceRequest<StreamHashTag>(streamHashTag)); } } StoreStreamHashTagsForActivityStrategyImpl(final HashTagExtractor inHashTagExtractor,
            final ActivityContentExtractor inContentExtractor,
            final DecoratedPartialResponseDomainMapper<List<String>, List<HashTag>> inHashTagMapper,
            final InsertMapper<StreamHashTag> inStreamHashTagInsertMapper); void execute(final Activity inActivity); }
StoreStreamHashTagsForActivityStrategyImpl implements StoreStreamHashTagsForActivityStrategy { public void execute(final Activity inActivity) { log.info("Finding hashtags for activity #" + inActivity.getId()); ScopeType scopeType = inActivity.getRecipientStreamScope().getScopeType(); if (scopeType != ScopeType.GROUP && scopeType != ScopeType.PERSON) { log.info("This activity isn't a group or person stream - not handled."); return; } String recipientStreamKey = inActivity.getRecipientStreamScope().getUniqueKey(); StreamHashTag streamHashTag; List<String> hashTagStrings = getHashTags(inActivity); if (hashTagStrings.size() == 0) { return; } for (HashTag hashTag : hashTagMapper.execute(hashTagStrings)) { if (log.isDebugEnabled()) { log.debug("Adding StreamHashTag " + hashTag.getContent() + " for direct recipient stream of type " + scopeType + ", key: " + recipientStreamKey + ", activity id: #" + inActivity.getId()); } streamHashTag = new StreamHashTag(hashTag, inActivity, recipientStreamKey, scopeType); streamHashTagInsertMapper.execute(new PersistenceRequest<StreamHashTag>(streamHashTag)); } } StoreStreamHashTagsForActivityStrategyImpl(final HashTagExtractor inHashTagExtractor,
            final ActivityContentExtractor inContentExtractor,
            final DecoratedPartialResponseDomainMapper<List<String>, List<HashTag>> inHashTagMapper,
            final InsertMapper<StreamHashTag> inStreamHashTagInsertMapper); void execute(final Activity inActivity);  }