@Test public void testExecuteBogusId() { final long bogusId = -9879843; assertNull(sut.execute(new DeleteActivityRequest(smithersId, bogusId))); }
public ActivityDTO execute(final DeleteActivityRequest inDeleteActivityRequest) { final Long activityId = inDeleteActivityRequest.getActivityId(); final Long userId = inDeleteActivityRequest.getUserId(); List<ActivityDTO> activities = activityDAO.execute(Collections.singletonList(activityId)); if (activities.size() == 0) { return null; } ActivityDTO activity = activities.get(0); getEntityManager().createQuery("DELETE FROM Comment c WHERE c.target.id = :activityId").setParameter( "activityId", activityId).executeUpdate(); getEntityManager().createQuery("DELETE FROM StarredActivity where activityId = :activityId").setParameter( "activityId", activityId).executeUpdate(); getEntityManager().createQuery("DELETE FROM StreamHashTag WHERE activity.id = :activityId").setParameter( "activityId", activityId).executeUpdate(); getEntityManager().createQuery("DELETE FROM Activity WHERE id = :activityId").setParameter("activityId", activityId).executeUpdate(); getCache().removeFromList(CacheKeys.STARRED_BY_PERSON_ID + userId, activityId); getCache().removeFromList(CacheKeys.ACTIVITIES_BY_FOLLOWING + userId, activityId); return activity; }
DeleteActivity extends BaseArgCachedDomainMapper<DeleteActivityRequest, ActivityDTO> { public ActivityDTO execute(final DeleteActivityRequest inDeleteActivityRequest) { final Long activityId = inDeleteActivityRequest.getActivityId(); final Long userId = inDeleteActivityRequest.getUserId(); List<ActivityDTO> activities = activityDAO.execute(Collections.singletonList(activityId)); if (activities.size() == 0) { return null; } ActivityDTO activity = activities.get(0); getEntityManager().createQuery("DELETE FROM Comment c WHERE c.target.id = :activityId").setParameter( "activityId", activityId).executeUpdate(); getEntityManager().createQuery("DELETE FROM StarredActivity where activityId = :activityId").setParameter( "activityId", activityId).executeUpdate(); getEntityManager().createQuery("DELETE FROM StreamHashTag WHERE activity.id = :activityId").setParameter( "activityId", activityId).executeUpdate(); getEntityManager().createQuery("DELETE FROM Activity WHERE id = :activityId").setParameter("activityId", activityId).executeUpdate(); getCache().removeFromList(CacheKeys.STARRED_BY_PERSON_ID + userId, activityId); getCache().removeFromList(CacheKeys.ACTIVITIES_BY_FOLLOWING + userId, activityId); return activity; } }
DeleteActivity extends BaseArgCachedDomainMapper<DeleteActivityRequest, ActivityDTO> { public ActivityDTO execute(final DeleteActivityRequest inDeleteActivityRequest) { final Long activityId = inDeleteActivityRequest.getActivityId(); final Long userId = inDeleteActivityRequest.getUserId(); List<ActivityDTO> activities = activityDAO.execute(Collections.singletonList(activityId)); if (activities.size() == 0) { return null; } ActivityDTO activity = activities.get(0); getEntityManager().createQuery("DELETE FROM Comment c WHERE c.target.id = :activityId").setParameter( "activityId", activityId).executeUpdate(); getEntityManager().createQuery("DELETE FROM StarredActivity where activityId = :activityId").setParameter( "activityId", activityId).executeUpdate(); getEntityManager().createQuery("DELETE FROM StreamHashTag WHERE activity.id = :activityId").setParameter( "activityId", activityId).executeUpdate(); getEntityManager().createQuery("DELETE FROM Activity WHERE id = :activityId").setParameter("activityId", activityId).executeUpdate(); getCache().removeFromList(CacheKeys.STARRED_BY_PERSON_ID + userId, activityId); getCache().removeFromList(CacheKeys.ACTIVITIES_BY_FOLLOWING + userId, activityId); return activity; } DeleteActivity(final DomainMapper<List<Long>, List<ActivityDTO>> inActivityDAO); }
DeleteActivity extends BaseArgCachedDomainMapper<DeleteActivityRequest, ActivityDTO> { public ActivityDTO execute(final DeleteActivityRequest inDeleteActivityRequest) { final Long activityId = inDeleteActivityRequest.getActivityId(); final Long userId = inDeleteActivityRequest.getUserId(); List<ActivityDTO> activities = activityDAO.execute(Collections.singletonList(activityId)); if (activities.size() == 0) { return null; } ActivityDTO activity = activities.get(0); getEntityManager().createQuery("DELETE FROM Comment c WHERE c.target.id = :activityId").setParameter( "activityId", activityId).executeUpdate(); getEntityManager().createQuery("DELETE FROM StarredActivity where activityId = :activityId").setParameter( "activityId", activityId).executeUpdate(); getEntityManager().createQuery("DELETE FROM StreamHashTag WHERE activity.id = :activityId").setParameter( "activityId", activityId).executeUpdate(); getEntityManager().createQuery("DELETE FROM Activity WHERE id = :activityId").setParameter("activityId", activityId).executeUpdate(); getCache().removeFromList(CacheKeys.STARRED_BY_PERSON_ID + userId, activityId); getCache().removeFromList(CacheKeys.ACTIVITIES_BY_FOLLOWING + userId, activityId); return activity; } DeleteActivity(final DomainMapper<List<Long>, List<ActivityDTO>> inActivityDAO); ActivityDTO execute(final DeleteActivityRequest inDeleteActivityRequest); }
DeleteActivity extends BaseArgCachedDomainMapper<DeleteActivityRequest, ActivityDTO> { public ActivityDTO execute(final DeleteActivityRequest inDeleteActivityRequest) { final Long activityId = inDeleteActivityRequest.getActivityId(); final Long userId = inDeleteActivityRequest.getUserId(); List<ActivityDTO> activities = activityDAO.execute(Collections.singletonList(activityId)); if (activities.size() == 0) { return null; } ActivityDTO activity = activities.get(0); getEntityManager().createQuery("DELETE FROM Comment c WHERE c.target.id = :activityId").setParameter( "activityId", activityId).executeUpdate(); getEntityManager().createQuery("DELETE FROM StarredActivity where activityId = :activityId").setParameter( "activityId", activityId).executeUpdate(); getEntityManager().createQuery("DELETE FROM StreamHashTag WHERE activity.id = :activityId").setParameter( "activityId", activityId).executeUpdate(); getEntityManager().createQuery("DELETE FROM Activity WHERE id = :activityId").setParameter("activityId", activityId).executeUpdate(); getCache().removeFromList(CacheKeys.STARRED_BY_PERSON_ID + userId, activityId); getCache().removeFromList(CacheKeys.ACTIVITIES_BY_FOLLOWING + userId, activityId); return activity; } DeleteActivity(final DomainMapper<List<Long>, List<ActivityDTO>> inActivityDAO); ActivityDTO execute(final DeleteActivityRequest inDeleteActivityRequest);  }