@Test public void testCreateActivity() throws Exception { final GadgetDefinition gadgetDef = new GadgetDefinition(); context.checking(new Expectations() { { oneOf(principalDao).execute(with(any(String.class))); will(returnValue(principalMock)); oneOf(principalMock).getOpenSocialId(); oneOf(principalMock).getAccountId(); oneOf(serviceActionControllerMock).execute(with(any(ServiceActionContext.class)), with(any(TaskHandlerAction.class))); oneOf(gadgetDefMapper).findById(Long.parseLong(TEST_APP_ID)); will(returnValue(gadgetDef)); oneOf(gadgetMetaDataFetcher).getGadgetsMetaData(with(any(Map.class))); will(returnValue(Collections.singletonList(new GadgetMetaDataDTO(gadgetDef)))); } }); sut.createActivity(testId, testGroupId, TEST_APP_ID, ACTIVITY_ALL_FIELDS, testActivity, FAKETOKEN); context.assertIsSatisfied(); }
public Future<Void> createActivity(final UserId userId, final GroupId groupId, final String appId, final Set<String> fields, final Activity activity, final SecurityToken token) { log.debug("Entering createActivity data with userId " + userId.getUserId(token) + ", appId " + appId + ", " + fields.size() + ", AcivityId " + activity.getId() + ", token appId " + token.getAppId()); try { Principal currentUserPrincipal = openSocialPrincipalDao.execute(userId.getUserId(token)); StreamEntityDTO actorEntity = new StreamEntityDTO(); actorEntity.setUniqueIdentifier(currentUserPrincipal.getOpenSocialId()); actorEntity.setType(EntityType.PERSON); StreamEntityDTO destStream = new StreamEntityDTO(); destStream.setUniqueIdentifier(currentUserPrincipal.getAccountId()); destStream.setType(EntityType.PERSON); ActivityDTO currentActivity = new ActivityDTO(); currentActivity.setActor(actorEntity); currentActivity.setBaseObjectProperties(new HashMap<String, String>( convertActivityFromOSToEureka(activity))); Long appIdNumeric = Long.valueOf(appId); currentActivity.setAppId(appIdNumeric); currentActivity.setAppType(EntityType.APPLICATION); currentActivity.setAppName(lookupGadgetTitle(appIdNumeric)); if (!currentActivity.getBaseObjectProperties().containsKey("baseObjectType")) { currentActivity.setBaseObjectType(BaseObjectType.NOTE); } else { String objectType = currentActivity.getBaseObjectProperties().get("baseObjectType"); currentActivity.setBaseObjectType(BaseObjectType.valueOf(objectType)); if (currentActivity.getBaseObjectProperties().containsKey("source")) { currentActivity.setAppSource(currentActivity.getBaseObjectProperties().get("source")); } } currentActivity.setVerb(ActivityVerb.POST); currentActivity.setDestinationStream(destStream); PostActivityRequest params = new PostActivityRequest(currentActivity); ServiceActionContext currentContext = new ServiceActionContext(params, currentUserPrincipal); serviceActionController.execute(currentContext, postActivityAction); } catch (Exception e) { log.error("Error occurred creating Activity ", e); throw new ProtocolException(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, e.toString()); } return ImmediateFuture.newInstance(null); }
ActivityServiceImpl implements ActivityService { public Future<Void> createActivity(final UserId userId, final GroupId groupId, final String appId, final Set<String> fields, final Activity activity, final SecurityToken token) { log.debug("Entering createActivity data with userId " + userId.getUserId(token) + ", appId " + appId + ", " + fields.size() + ", AcivityId " + activity.getId() + ", token appId " + token.getAppId()); try { Principal currentUserPrincipal = openSocialPrincipalDao.execute(userId.getUserId(token)); StreamEntityDTO actorEntity = new StreamEntityDTO(); actorEntity.setUniqueIdentifier(currentUserPrincipal.getOpenSocialId()); actorEntity.setType(EntityType.PERSON); StreamEntityDTO destStream = new StreamEntityDTO(); destStream.setUniqueIdentifier(currentUserPrincipal.getAccountId()); destStream.setType(EntityType.PERSON); ActivityDTO currentActivity = new ActivityDTO(); currentActivity.setActor(actorEntity); currentActivity.setBaseObjectProperties(new HashMap<String, String>( convertActivityFromOSToEureka(activity))); Long appIdNumeric = Long.valueOf(appId); currentActivity.setAppId(appIdNumeric); currentActivity.setAppType(EntityType.APPLICATION); currentActivity.setAppName(lookupGadgetTitle(appIdNumeric)); if (!currentActivity.getBaseObjectProperties().containsKey("baseObjectType")) { currentActivity.setBaseObjectType(BaseObjectType.NOTE); } else { String objectType = currentActivity.getBaseObjectProperties().get("baseObjectType"); currentActivity.setBaseObjectType(BaseObjectType.valueOf(objectType)); if (currentActivity.getBaseObjectProperties().containsKey("source")) { currentActivity.setAppSource(currentActivity.getBaseObjectProperties().get("source")); } } currentActivity.setVerb(ActivityVerb.POST); currentActivity.setDestinationStream(destStream); PostActivityRequest params = new PostActivityRequest(currentActivity); ServiceActionContext currentContext = new ServiceActionContext(params, currentUserPrincipal); serviceActionController.execute(currentContext, postActivityAction); } catch (Exception e) { log.error("Error occurred creating Activity ", e); throw new ProtocolException(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, e.toString()); } return ImmediateFuture.newInstance(null); } }
ActivityServiceImpl implements ActivityService { public Future<Void> createActivity(final UserId userId, final GroupId groupId, final String appId, final Set<String> fields, final Activity activity, final SecurityToken token) { log.debug("Entering createActivity data with userId " + userId.getUserId(token) + ", appId " + appId + ", " + fields.size() + ", AcivityId " + activity.getId() + ", token appId " + token.getAppId()); try { Principal currentUserPrincipal = openSocialPrincipalDao.execute(userId.getUserId(token)); StreamEntityDTO actorEntity = new StreamEntityDTO(); actorEntity.setUniqueIdentifier(currentUserPrincipal.getOpenSocialId()); actorEntity.setType(EntityType.PERSON); StreamEntityDTO destStream = new StreamEntityDTO(); destStream.setUniqueIdentifier(currentUserPrincipal.getAccountId()); destStream.setType(EntityType.PERSON); ActivityDTO currentActivity = new ActivityDTO(); currentActivity.setActor(actorEntity); currentActivity.setBaseObjectProperties(new HashMap<String, String>( convertActivityFromOSToEureka(activity))); Long appIdNumeric = Long.valueOf(appId); currentActivity.setAppId(appIdNumeric); currentActivity.setAppType(EntityType.APPLICATION); currentActivity.setAppName(lookupGadgetTitle(appIdNumeric)); if (!currentActivity.getBaseObjectProperties().containsKey("baseObjectType")) { currentActivity.setBaseObjectType(BaseObjectType.NOTE); } else { String objectType = currentActivity.getBaseObjectProperties().get("baseObjectType"); currentActivity.setBaseObjectType(BaseObjectType.valueOf(objectType)); if (currentActivity.getBaseObjectProperties().containsKey("source")) { currentActivity.setAppSource(currentActivity.getBaseObjectProperties().get("source")); } } currentActivity.setVerb(ActivityVerb.POST); currentActivity.setDestinationStream(destStream); PostActivityRequest params = new PostActivityRequest(currentActivity); ServiceActionContext currentContext = new ServiceActionContext(params, currentUserPrincipal); serviceActionController.execute(currentContext, postActivityAction); } catch (Exception e) { log.error("Error occurred creating Activity ", e); throw new ProtocolException(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, e.toString()); } return ImmediateFuture.newInstance(null); } @Inject  ActivityServiceImpl(@Named("getUserActivities") final ServiceAction inGetUserActivitiesAction,
            @Named("deleteUserActivities") final TaskHandlerAction inDeleteActivitiesAction,
            final ActionController inServiceActionController,
            @Named("openSocialPrincipalDao") final DomainMapper<String, Principal> inOpenSocialPrincipalDao,
            @Named("postPersonActivityServiceActionTaskHandler") final TaskHandlerServiceAction inPostActivityAction,
            @Named("jpaGadgetDefinitionMapper") final GadgetDefinitionMapper inGadgetDefinitionMapper,
            final GadgetMetaDataFetcher inGadgetMetaDataFetcher); }
ActivityServiceImpl implements ActivityService { public Future<Void> createActivity(final UserId userId, final GroupId groupId, final String appId, final Set<String> fields, final Activity activity, final SecurityToken token) { log.debug("Entering createActivity data with userId " + userId.getUserId(token) + ", appId " + appId + ", " + fields.size() + ", AcivityId " + activity.getId() + ", token appId " + token.getAppId()); try { Principal currentUserPrincipal = openSocialPrincipalDao.execute(userId.getUserId(token)); StreamEntityDTO actorEntity = new StreamEntityDTO(); actorEntity.setUniqueIdentifier(currentUserPrincipal.getOpenSocialId()); actorEntity.setType(EntityType.PERSON); StreamEntityDTO destStream = new StreamEntityDTO(); destStream.setUniqueIdentifier(currentUserPrincipal.getAccountId()); destStream.setType(EntityType.PERSON); ActivityDTO currentActivity = new ActivityDTO(); currentActivity.setActor(actorEntity); currentActivity.setBaseObjectProperties(new HashMap<String, String>( convertActivityFromOSToEureka(activity))); Long appIdNumeric = Long.valueOf(appId); currentActivity.setAppId(appIdNumeric); currentActivity.setAppType(EntityType.APPLICATION); currentActivity.setAppName(lookupGadgetTitle(appIdNumeric)); if (!currentActivity.getBaseObjectProperties().containsKey("baseObjectType")) { currentActivity.setBaseObjectType(BaseObjectType.NOTE); } else { String objectType = currentActivity.getBaseObjectProperties().get("baseObjectType"); currentActivity.setBaseObjectType(BaseObjectType.valueOf(objectType)); if (currentActivity.getBaseObjectProperties().containsKey("source")) { currentActivity.setAppSource(currentActivity.getBaseObjectProperties().get("source")); } } currentActivity.setVerb(ActivityVerb.POST); currentActivity.setDestinationStream(destStream); PostActivityRequest params = new PostActivityRequest(currentActivity); ServiceActionContext currentContext = new ServiceActionContext(params, currentUserPrincipal); serviceActionController.execute(currentContext, postActivityAction); } catch (Exception e) { log.error("Error occurred creating Activity ", e); throw new ProtocolException(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, e.toString()); } return ImmediateFuture.newInstance(null); } @Inject  ActivityServiceImpl(@Named("getUserActivities") final ServiceAction inGetUserActivitiesAction,
            @Named("deleteUserActivities") final TaskHandlerAction inDeleteActivitiesAction,
            final ActionController inServiceActionController,
            @Named("openSocialPrincipalDao") final DomainMapper<String, Principal> inOpenSocialPrincipalDao,
            @Named("postPersonActivityServiceActionTaskHandler") final TaskHandlerServiceAction inPostActivityAction,
            @Named("jpaGadgetDefinitionMapper") final GadgetDefinitionMapper inGadgetDefinitionMapper,
            final GadgetMetaDataFetcher inGadgetMetaDataFetcher); Future<Void> createActivity(final UserId userId, final GroupId groupId, final String appId,
            final Set<String> fields, final Activity activity, final SecurityToken token); Future<Void> deleteActivities(final UserId userId, final GroupId groupId, final String appId,
            final Set<String> activityIds, final SecurityToken token); @SuppressWarnings("unchecked") Future<RestfulCollection<Activity>> getActivities(final Set<UserId> userIds, final GroupId groupId,
            final String appId, final Set<String> fields, final CollectionOptions options, final SecurityToken token); @SuppressWarnings("unchecked") Future<RestfulCollection<Activity>> getActivities(final UserId userId, final GroupId groupId,
            final String appId, final Set<String> fields, final CollectionOptions options,
            final Set<String> activityIds, final SecurityToken token); Future<Activity> getActivity(final UserId userId, final GroupId groupId, final String appId,
            final Set<String> fields, final String activityId, final SecurityToken token); }
ActivityServiceImpl implements ActivityService { public Future<Void> createActivity(final UserId userId, final GroupId groupId, final String appId, final Set<String> fields, final Activity activity, final SecurityToken token) { log.debug("Entering createActivity data with userId " + userId.getUserId(token) + ", appId " + appId + ", " + fields.size() + ", AcivityId " + activity.getId() + ", token appId " + token.getAppId()); try { Principal currentUserPrincipal = openSocialPrincipalDao.execute(userId.getUserId(token)); StreamEntityDTO actorEntity = new StreamEntityDTO(); actorEntity.setUniqueIdentifier(currentUserPrincipal.getOpenSocialId()); actorEntity.setType(EntityType.PERSON); StreamEntityDTO destStream = new StreamEntityDTO(); destStream.setUniqueIdentifier(currentUserPrincipal.getAccountId()); destStream.setType(EntityType.PERSON); ActivityDTO currentActivity = new ActivityDTO(); currentActivity.setActor(actorEntity); currentActivity.setBaseObjectProperties(new HashMap<String, String>( convertActivityFromOSToEureka(activity))); Long appIdNumeric = Long.valueOf(appId); currentActivity.setAppId(appIdNumeric); currentActivity.setAppType(EntityType.APPLICATION); currentActivity.setAppName(lookupGadgetTitle(appIdNumeric)); if (!currentActivity.getBaseObjectProperties().containsKey("baseObjectType")) { currentActivity.setBaseObjectType(BaseObjectType.NOTE); } else { String objectType = currentActivity.getBaseObjectProperties().get("baseObjectType"); currentActivity.setBaseObjectType(BaseObjectType.valueOf(objectType)); if (currentActivity.getBaseObjectProperties().containsKey("source")) { currentActivity.setAppSource(currentActivity.getBaseObjectProperties().get("source")); } } currentActivity.setVerb(ActivityVerb.POST); currentActivity.setDestinationStream(destStream); PostActivityRequest params = new PostActivityRequest(currentActivity); ServiceActionContext currentContext = new ServiceActionContext(params, currentUserPrincipal); serviceActionController.execute(currentContext, postActivityAction); } catch (Exception e) { log.error("Error occurred creating Activity ", e); throw new ProtocolException(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, e.toString()); } return ImmediateFuture.newInstance(null); } @Inject  ActivityServiceImpl(@Named("getUserActivities") final ServiceAction inGetUserActivitiesAction,
            @Named("deleteUserActivities") final TaskHandlerAction inDeleteActivitiesAction,
            final ActionController inServiceActionController,
            @Named("openSocialPrincipalDao") final DomainMapper<String, Principal> inOpenSocialPrincipalDao,
            @Named("postPersonActivityServiceActionTaskHandler") final TaskHandlerServiceAction inPostActivityAction,
            @Named("jpaGadgetDefinitionMapper") final GadgetDefinitionMapper inGadgetDefinitionMapper,
            final GadgetMetaDataFetcher inGadgetMetaDataFetcher); Future<Void> createActivity(final UserId userId, final GroupId groupId, final String appId,
            final Set<String> fields, final Activity activity, final SecurityToken token); Future<Void> deleteActivities(final UserId userId, final GroupId groupId, final String appId,
            final Set<String> activityIds, final SecurityToken token); @SuppressWarnings("unchecked") Future<RestfulCollection<Activity>> getActivities(final Set<UserId> userIds, final GroupId groupId,
            final String appId, final Set<String> fields, final CollectionOptions options, final SecurityToken token); @SuppressWarnings("unchecked") Future<RestfulCollection<Activity>> getActivities(final UserId userId, final GroupId groupId,
            final String appId, final Set<String> fields, final CollectionOptions options,
            final Set<String> activityIds, final SecurityToken token); Future<Activity> getActivity(final UserId userId, final GroupId groupId, final String appId,
            final Set<String> fields, final String activityId, final SecurityToken token);  }