@SuppressWarnings("deprecation") @Test public void persistSuccessWithOrgUpdate() throws Exception { final DomainGroup group = new DomainGroup("Group Name", "shortName", new Person("id", "Homer", "Jay", "Simpson", "Homey")); final List<Person> attribMembers = new ArrayList<Person>(); attribMembers.add(new Person("id", "Homer", "Jay", "Simpson", "Homey")); attribMembers.add(new Person("id", "Max", "X", "Power", "Homer")); group.setCoordinators(new HashSet(attribMembers)); final long id = 1L; String newName = "NEW name here"; final HashMap<String, Serializable> formData = new HashMap<String, Serializable>(); formData.put(DomainGroupModelView.ID_KEY, Long.toString(id)); formData.put(DomainGroupModelView.NAME_KEY, newName); formData.put(DomainGroupModelView.KEYWORDS_KEY, "good,idea"); formData.put("__KEY_ORIGINAL_GROUP_NAME_KEY", "Group Name"); formData.put("__KEY_ORIGINAL_GROUP_COORDINATORS_KEY", (Serializable) group.getCoordinators()); context.checking(new Expectations() { { oneOf(groupMapperMock).flush(); } }); sut.persist(taskHandlerActionContext, formData, group); context.assertIsSatisfied(); assertEquals("Group Name", group.getName()); assertEquals(2, group.getCapabilities().size()); assertEquals(1, taskHandlerActionContext.getUserActionRequests().size()); }
@Override public void persist(final TaskHandlerActionContext<PrincipalActionContext> inActionContext, final Map<String, Serializable> inFields, final DomainGroup inGroup) throws Exception { try { inGroup.setCapabilities(DomainFormatUtility.splitCapabilitiesString((String) inFields .get(DomainGroupModelView.KEYWORDS_KEY))); String creatorUserName = inActionContext.getActionContext().getPrincipal().getAccountId(); Set<Person> oldCoordinators = (Set<Person>) inFields.get(ORIGINAL_GROUP_COORDINATORS_KEY); Set<Person> newCoordinators = new HashSet<Person>(); newCoordinators.addAll(inGroup.getCoordinators()); newCoordinators.removeAll(oldCoordinators); for (Person coordinator : newCoordinators) { SetFollowingStatusByGroupCreatorRequest currentRequest = new SetFollowingStatusByGroupCreatorRequest( coordinator.getId(), inGroup.getId(), Follower.FollowerStatus.FOLLOWING, inGroup.getName(), inGroup.getShortName(), false); new InlineExecutionStrategyExecutor().execute(followStrategy, currentRequest, new DefaultPrincipal( creatorUserName, inActionContext.getActionContext().getPrincipal().getOpenSocialId(), inActionContext.getActionContext().getPrincipal().getId()), inActionContext .getUserActionRequests()); } getGroupMapper().flush(); queueAsyncAction(inActionContext, inGroup, true); String previousGroupName = (String) inFields.get(ORIGINAL_GROUP_NAME_KEY); String newGroupName = inGroup.getName(); if (previousGroupName == null || !previousGroupName.equals(newGroupName)) { log.info("The name for domain group with short name " + inGroup.getShortName() + " has been changed from '" + previousGroupName + "' to '" + newGroupName + "'. Queuing up activityRecipientDomainGroupNameUpdaterAsyncAction async task to update " + "all activities posted to this group."); inActionContext.getUserActionRequests().add( new UserActionRequest("activityRecipientDomainGroupNameUpdaterAsyncAction", null, inGroup .getShortName())); } } catch (InvalidStateException e) { log.error("Failed to persist Group", e); InvalidValue[] invalidValues = e.getInvalidValues(); ValidationException validationException = new ValidationException(); for (InvalidValue invalidValue : invalidValues) { validationException.addError(invalidValue.getPropertyName(), invalidValue.getMessage()); } throw validationException; } catch (PersistenceException e) { log.error("Failed to persist Group", e); } }
GroupUpdater extends GroupPersister { @Override public void persist(final TaskHandlerActionContext<PrincipalActionContext> inActionContext, final Map<String, Serializable> inFields, final DomainGroup inGroup) throws Exception { try { inGroup.setCapabilities(DomainFormatUtility.splitCapabilitiesString((String) inFields .get(DomainGroupModelView.KEYWORDS_KEY))); String creatorUserName = inActionContext.getActionContext().getPrincipal().getAccountId(); Set<Person> oldCoordinators = (Set<Person>) inFields.get(ORIGINAL_GROUP_COORDINATORS_KEY); Set<Person> newCoordinators = new HashSet<Person>(); newCoordinators.addAll(inGroup.getCoordinators()); newCoordinators.removeAll(oldCoordinators); for (Person coordinator : newCoordinators) { SetFollowingStatusByGroupCreatorRequest currentRequest = new SetFollowingStatusByGroupCreatorRequest( coordinator.getId(), inGroup.getId(), Follower.FollowerStatus.FOLLOWING, inGroup.getName(), inGroup.getShortName(), false); new InlineExecutionStrategyExecutor().execute(followStrategy, currentRequest, new DefaultPrincipal( creatorUserName, inActionContext.getActionContext().getPrincipal().getOpenSocialId(), inActionContext.getActionContext().getPrincipal().getId()), inActionContext .getUserActionRequests()); } getGroupMapper().flush(); queueAsyncAction(inActionContext, inGroup, true); String previousGroupName = (String) inFields.get(ORIGINAL_GROUP_NAME_KEY); String newGroupName = inGroup.getName(); if (previousGroupName == null || !previousGroupName.equals(newGroupName)) { log.info("The name for domain group with short name " + inGroup.getShortName() + " has been changed from '" + previousGroupName + "' to '" + newGroupName + "'. Queuing up activityRecipientDomainGroupNameUpdaterAsyncAction async task to update " + "all activities posted to this group."); inActionContext.getUserActionRequests().add( new UserActionRequest("activityRecipientDomainGroupNameUpdaterAsyncAction", null, inGroup .getShortName())); } } catch (InvalidStateException e) { log.error("Failed to persist Group", e); InvalidValue[] invalidValues = e.getInvalidValues(); ValidationException validationException = new ValidationException(); for (InvalidValue invalidValue : invalidValues) { validationException.addError(invalidValue.getPropertyName(), invalidValue.getMessage()); } throw validationException; } catch (PersistenceException e) { log.error("Failed to persist Group", e); } } }
GroupUpdater extends GroupPersister { @Override public void persist(final TaskHandlerActionContext<PrincipalActionContext> inActionContext, final Map<String, Serializable> inFields, final DomainGroup inGroup) throws Exception { try { inGroup.setCapabilities(DomainFormatUtility.splitCapabilitiesString((String) inFields .get(DomainGroupModelView.KEYWORDS_KEY))); String creatorUserName = inActionContext.getActionContext().getPrincipal().getAccountId(); Set<Person> oldCoordinators = (Set<Person>) inFields.get(ORIGINAL_GROUP_COORDINATORS_KEY); Set<Person> newCoordinators = new HashSet<Person>(); newCoordinators.addAll(inGroup.getCoordinators()); newCoordinators.removeAll(oldCoordinators); for (Person coordinator : newCoordinators) { SetFollowingStatusByGroupCreatorRequest currentRequest = new SetFollowingStatusByGroupCreatorRequest( coordinator.getId(), inGroup.getId(), Follower.FollowerStatus.FOLLOWING, inGroup.getName(), inGroup.getShortName(), false); new InlineExecutionStrategyExecutor().execute(followStrategy, currentRequest, new DefaultPrincipal( creatorUserName, inActionContext.getActionContext().getPrincipal().getOpenSocialId(), inActionContext.getActionContext().getPrincipal().getId()), inActionContext .getUserActionRequests()); } getGroupMapper().flush(); queueAsyncAction(inActionContext, inGroup, true); String previousGroupName = (String) inFields.get(ORIGINAL_GROUP_NAME_KEY); String newGroupName = inGroup.getName(); if (previousGroupName == null || !previousGroupName.equals(newGroupName)) { log.info("The name for domain group with short name " + inGroup.getShortName() + " has been changed from '" + previousGroupName + "' to '" + newGroupName + "'. Queuing up activityRecipientDomainGroupNameUpdaterAsyncAction async task to update " + "all activities posted to this group."); inActionContext.getUserActionRequests().add( new UserActionRequest("activityRecipientDomainGroupNameUpdaterAsyncAction", null, inGroup .getShortName())); } } catch (InvalidStateException e) { log.error("Failed to persist Group", e); InvalidValue[] invalidValues = e.getInvalidValues(); ValidationException validationException = new ValidationException(); for (InvalidValue invalidValue : invalidValues) { validationException.addError(invalidValue.getPropertyName(), invalidValue.getMessage()); } throw validationException; } catch (PersistenceException e) { log.error("Failed to persist Group", e); } } GroupUpdater(final DomainGroupMapper inGroupMapper,
            final GetAllPersonIdsWhoHaveGroupCoordinatorAccess inAccessCheckerMapper,
            final DomainMapper<Long, Void> inClearActivityStreamSearchStringForUsersMapper,
            final TaskHandlerExecutionStrategy inFollowStrategy); }
GroupUpdater extends GroupPersister { @Override public void persist(final TaskHandlerActionContext<PrincipalActionContext> inActionContext, final Map<String, Serializable> inFields, final DomainGroup inGroup) throws Exception { try { inGroup.setCapabilities(DomainFormatUtility.splitCapabilitiesString((String) inFields .get(DomainGroupModelView.KEYWORDS_KEY))); String creatorUserName = inActionContext.getActionContext().getPrincipal().getAccountId(); Set<Person> oldCoordinators = (Set<Person>) inFields.get(ORIGINAL_GROUP_COORDINATORS_KEY); Set<Person> newCoordinators = new HashSet<Person>(); newCoordinators.addAll(inGroup.getCoordinators()); newCoordinators.removeAll(oldCoordinators); for (Person coordinator : newCoordinators) { SetFollowingStatusByGroupCreatorRequest currentRequest = new SetFollowingStatusByGroupCreatorRequest( coordinator.getId(), inGroup.getId(), Follower.FollowerStatus.FOLLOWING, inGroup.getName(), inGroup.getShortName(), false); new InlineExecutionStrategyExecutor().execute(followStrategy, currentRequest, new DefaultPrincipal( creatorUserName, inActionContext.getActionContext().getPrincipal().getOpenSocialId(), inActionContext.getActionContext().getPrincipal().getId()), inActionContext .getUserActionRequests()); } getGroupMapper().flush(); queueAsyncAction(inActionContext, inGroup, true); String previousGroupName = (String) inFields.get(ORIGINAL_GROUP_NAME_KEY); String newGroupName = inGroup.getName(); if (previousGroupName == null || !previousGroupName.equals(newGroupName)) { log.info("The name for domain group with short name " + inGroup.getShortName() + " has been changed from '" + previousGroupName + "' to '" + newGroupName + "'. Queuing up activityRecipientDomainGroupNameUpdaterAsyncAction async task to update " + "all activities posted to this group."); inActionContext.getUserActionRequests().add( new UserActionRequest("activityRecipientDomainGroupNameUpdaterAsyncAction", null, inGroup .getShortName())); } } catch (InvalidStateException e) { log.error("Failed to persist Group", e); InvalidValue[] invalidValues = e.getInvalidValues(); ValidationException validationException = new ValidationException(); for (InvalidValue invalidValue : invalidValues) { validationException.addError(invalidValue.getPropertyName(), invalidValue.getMessage()); } throw validationException; } catch (PersistenceException e) { log.error("Failed to persist Group", e); } } GroupUpdater(final DomainGroupMapper inGroupMapper,
            final GetAllPersonIdsWhoHaveGroupCoordinatorAccess inAccessCheckerMapper,
            final DomainMapper<Long, Void> inClearActivityStreamSearchStringForUsersMapper,
            final TaskHandlerExecutionStrategy inFollowStrategy); @Override DomainGroup get(final TaskHandlerActionContext<PrincipalActionContext> inActionContext,
            final Map<String, Serializable> inFields); @Override void persist(final TaskHandlerActionContext<PrincipalActionContext> inActionContext,
            final Map<String, Serializable> inFields, final DomainGroup inGroup); }
GroupUpdater extends GroupPersister { @Override public void persist(final TaskHandlerActionContext<PrincipalActionContext> inActionContext, final Map<String, Serializable> inFields, final DomainGroup inGroup) throws Exception { try { inGroup.setCapabilities(DomainFormatUtility.splitCapabilitiesString((String) inFields .get(DomainGroupModelView.KEYWORDS_KEY))); String creatorUserName = inActionContext.getActionContext().getPrincipal().getAccountId(); Set<Person> oldCoordinators = (Set<Person>) inFields.get(ORIGINAL_GROUP_COORDINATORS_KEY); Set<Person> newCoordinators = new HashSet<Person>(); newCoordinators.addAll(inGroup.getCoordinators()); newCoordinators.removeAll(oldCoordinators); for (Person coordinator : newCoordinators) { SetFollowingStatusByGroupCreatorRequest currentRequest = new SetFollowingStatusByGroupCreatorRequest( coordinator.getId(), inGroup.getId(), Follower.FollowerStatus.FOLLOWING, inGroup.getName(), inGroup.getShortName(), false); new InlineExecutionStrategyExecutor().execute(followStrategy, currentRequest, new DefaultPrincipal( creatorUserName, inActionContext.getActionContext().getPrincipal().getOpenSocialId(), inActionContext.getActionContext().getPrincipal().getId()), inActionContext .getUserActionRequests()); } getGroupMapper().flush(); queueAsyncAction(inActionContext, inGroup, true); String previousGroupName = (String) inFields.get(ORIGINAL_GROUP_NAME_KEY); String newGroupName = inGroup.getName(); if (previousGroupName == null || !previousGroupName.equals(newGroupName)) { log.info("The name for domain group with short name " + inGroup.getShortName() + " has been changed from '" + previousGroupName + "' to '" + newGroupName + "'. Queuing up activityRecipientDomainGroupNameUpdaterAsyncAction async task to update " + "all activities posted to this group."); inActionContext.getUserActionRequests().add( new UserActionRequest("activityRecipientDomainGroupNameUpdaterAsyncAction", null, inGroup .getShortName())); } } catch (InvalidStateException e) { log.error("Failed to persist Group", e); InvalidValue[] invalidValues = e.getInvalidValues(); ValidationException validationException = new ValidationException(); for (InvalidValue invalidValue : invalidValues) { validationException.addError(invalidValue.getPropertyName(), invalidValue.getMessage()); } throw validationException; } catch (PersistenceException e) { log.error("Failed to persist Group", e); } } GroupUpdater(final DomainGroupMapper inGroupMapper,
            final GetAllPersonIdsWhoHaveGroupCoordinatorAccess inAccessCheckerMapper,
            final DomainMapper<Long, Void> inClearActivityStreamSearchStringForUsersMapper,
            final TaskHandlerExecutionStrategy inFollowStrategy); @Override DomainGroup get(final TaskHandlerActionContext<PrincipalActionContext> inActionContext,
            final Map<String, Serializable> inFields); @Override void persist(final TaskHandlerActionContext<PrincipalActionContext> inActionContext,
            final Map<String, Serializable> inFields, final DomainGroup inGroup);  }