@Test public void testValidateOriginalActorMissing() { testActivity = new ActivityDTO(); testActivity.setVerb(ActivityVerb.SHARE); testActivity.setOriginalActor(null); testActivity.setBaseObjectProperties(testBaseObjectProperties); testActivity.setBaseObjectType(BaseObjectType.BOOKMARK); context.checking(new Expectations() { { oneOf(transMgr).getTransaction(transDef); will(returnValue(transStatus)); } }); try { sut.validate(testActivity); } catch (ValidationException vex) { assertTrue(vex.getErrors().containsKey("OriginalActor")); assertTrue(vex.getErrors().get("OriginalActor").equals("Must be included for Share verbs.")); } context.assertIsSatisfied(); }
public void validate(final ActivityDTO inActivity) { DefaultTransactionDefinition transDef = new DefaultTransactionDefinition(); transDef.setName("LookupActivityTransaction"); transDef.setPropagationBehavior(TransactionDefinition.PROPAGATION_REQUIRED); TransactionStatus transStatus = transMgr.getTransaction(transDef); ValidationException ve = new ValidationException(); if (inActivity.getOriginalActor() == null || inActivity.getOriginalActor().getUniqueIdentifier() == null || inActivity.getOriginalActor().getUniqueIdentifier().length() <= 0) { ve.addError("OriginalActor", "Must be included for Share verbs."); throw ve; } List<Long> activityIds = new ArrayList<Long>(1); activityIds.add(new Long(inActivity.getBaseObjectProperties().get("originalActivityId"))); inActivity.getBaseObjectProperties().remove("originalActivityId"); List<ActivityDTO> originalActivityResults; try { originalActivityResults = activityMapper.execute(activityIds); if (originalActivityResults.size() == 0) { ve.addError("OriginalActivity", "activity being shared could not be found in the db."); throw ve; } if (originalActivityResults.size() > 1) { ve.addError("OriginalActivity", "more than one result was found for the original activity id."); } ActivityDTO origActivity = originalActivityResults.get(0); if (origActivity.getDestinationStream().getType() == EntityType.GROUP) { DomainGroupModelView group = groupShortNameCacheMapper.fetchUniqueResult(origActivity .getDestinationStream().getUniqueIdentifier()); if (group != null && !group.isPublic()) { ve.addError("OriginalActivity", "OriginalActivity from a private group and can not be shared."); throw ve; } else if (group == null) { ve.addError("OriginalActivity", "OriginalActivity Group Entity not found."); } } if (!inActivity.getBaseObjectProperties().equals(origActivity.getBaseObjectProperties())) { ve.addError("BaseObjectProperties", "Oringal Activity BaseObjectProperties must equal the properties of the Shared Activity."); } else { inActivity.getBaseObjectProperties().put("originalActivityId", activityIds.get(0).toString()); } if (!inActivity.getOriginalActor().getUniqueIdentifier().equals( origActivity.getActor().getUniqueIdentifier())) { ve.addError("OriginalActor", "Original actor of the shared activity does not match the actor of the original activity."); } if (!inActivity.getBaseObjectType().equals(origActivity.getBaseObjectType())) { ve.addError("BaseObjectType", "activity must be of the same type as the original activity."); } transMgr.commit(transStatus); } catch (Exception ex) { transMgr.rollback(transStatus); ve.addError("OriginalActivity", "Error occurred accessing the original activity."); } if (!ve.getErrors().isEmpty()) { throw ve; } }
ShareVerbValidator implements ActivityValidator { public void validate(final ActivityDTO inActivity) { DefaultTransactionDefinition transDef = new DefaultTransactionDefinition(); transDef.setName("LookupActivityTransaction"); transDef.setPropagationBehavior(TransactionDefinition.PROPAGATION_REQUIRED); TransactionStatus transStatus = transMgr.getTransaction(transDef); ValidationException ve = new ValidationException(); if (inActivity.getOriginalActor() == null || inActivity.getOriginalActor().getUniqueIdentifier() == null || inActivity.getOriginalActor().getUniqueIdentifier().length() <= 0) { ve.addError("OriginalActor", "Must be included for Share verbs."); throw ve; } List<Long> activityIds = new ArrayList<Long>(1); activityIds.add(new Long(inActivity.getBaseObjectProperties().get("originalActivityId"))); inActivity.getBaseObjectProperties().remove("originalActivityId"); List<ActivityDTO> originalActivityResults; try { originalActivityResults = activityMapper.execute(activityIds); if (originalActivityResults.size() == 0) { ve.addError("OriginalActivity", "activity being shared could not be found in the db."); throw ve; } if (originalActivityResults.size() > 1) { ve.addError("OriginalActivity", "more than one result was found for the original activity id."); } ActivityDTO origActivity = originalActivityResults.get(0); if (origActivity.getDestinationStream().getType() == EntityType.GROUP) { DomainGroupModelView group = groupShortNameCacheMapper.fetchUniqueResult(origActivity .getDestinationStream().getUniqueIdentifier()); if (group != null && !group.isPublic()) { ve.addError("OriginalActivity", "OriginalActivity from a private group and can not be shared."); throw ve; } else if (group == null) { ve.addError("OriginalActivity", "OriginalActivity Group Entity not found."); } } if (!inActivity.getBaseObjectProperties().equals(origActivity.getBaseObjectProperties())) { ve.addError("BaseObjectProperties", "Oringal Activity BaseObjectProperties must equal the properties of the Shared Activity."); } else { inActivity.getBaseObjectProperties().put("originalActivityId", activityIds.get(0).toString()); } if (!inActivity.getOriginalActor().getUniqueIdentifier().equals( origActivity.getActor().getUniqueIdentifier())) { ve.addError("OriginalActor", "Original actor of the shared activity does not match the actor of the original activity."); } if (!inActivity.getBaseObjectType().equals(origActivity.getBaseObjectType())) { ve.addError("BaseObjectType", "activity must be of the same type as the original activity."); } transMgr.commit(transStatus); } catch (Exception ex) { transMgr.rollback(transStatus); ve.addError("OriginalActivity", "Error occurred accessing the original activity."); } if (!ve.getErrors().isEmpty()) { throw ve; } } }
ShareVerbValidator implements ActivityValidator { public void validate(final ActivityDTO inActivity) { DefaultTransactionDefinition transDef = new DefaultTransactionDefinition(); transDef.setName("LookupActivityTransaction"); transDef.setPropagationBehavior(TransactionDefinition.PROPAGATION_REQUIRED); TransactionStatus transStatus = transMgr.getTransaction(transDef); ValidationException ve = new ValidationException(); if (inActivity.getOriginalActor() == null || inActivity.getOriginalActor().getUniqueIdentifier() == null || inActivity.getOriginalActor().getUniqueIdentifier().length() <= 0) { ve.addError("OriginalActor", "Must be included for Share verbs."); throw ve; } List<Long> activityIds = new ArrayList<Long>(1); activityIds.add(new Long(inActivity.getBaseObjectProperties().get("originalActivityId"))); inActivity.getBaseObjectProperties().remove("originalActivityId"); List<ActivityDTO> originalActivityResults; try { originalActivityResults = activityMapper.execute(activityIds); if (originalActivityResults.size() == 0) { ve.addError("OriginalActivity", "activity being shared could not be found in the db."); throw ve; } if (originalActivityResults.size() > 1) { ve.addError("OriginalActivity", "more than one result was found for the original activity id."); } ActivityDTO origActivity = originalActivityResults.get(0); if (origActivity.getDestinationStream().getType() == EntityType.GROUP) { DomainGroupModelView group = groupShortNameCacheMapper.fetchUniqueResult(origActivity .getDestinationStream().getUniqueIdentifier()); if (group != null && !group.isPublic()) { ve.addError("OriginalActivity", "OriginalActivity from a private group and can not be shared."); throw ve; } else if (group == null) { ve.addError("OriginalActivity", "OriginalActivity Group Entity not found."); } } if (!inActivity.getBaseObjectProperties().equals(origActivity.getBaseObjectProperties())) { ve.addError("BaseObjectProperties", "Oringal Activity BaseObjectProperties must equal the properties of the Shared Activity."); } else { inActivity.getBaseObjectProperties().put("originalActivityId", activityIds.get(0).toString()); } if (!inActivity.getOriginalActor().getUniqueIdentifier().equals( origActivity.getActor().getUniqueIdentifier())) { ve.addError("OriginalActor", "Original actor of the shared activity does not match the actor of the original activity."); } if (!inActivity.getBaseObjectType().equals(origActivity.getBaseObjectType())) { ve.addError("BaseObjectType", "activity must be of the same type as the original activity."); } transMgr.commit(transStatus); } catch (Exception ex) { transMgr.rollback(transStatus); ve.addError("OriginalActivity", "Error occurred accessing the original activity."); } if (!ve.getErrors().isEmpty()) { throw ve; } } ShareVerbValidator(final DomainMapper<List<Long>, List<ActivityDTO>>  inActivityMapper,
            final PlatformTransactionManager inTransManager,
            final GetDomainGroupsByShortNames inGroupShortNameCacheMapper); }
ShareVerbValidator implements ActivityValidator { public void validate(final ActivityDTO inActivity) { DefaultTransactionDefinition transDef = new DefaultTransactionDefinition(); transDef.setName("LookupActivityTransaction"); transDef.setPropagationBehavior(TransactionDefinition.PROPAGATION_REQUIRED); TransactionStatus transStatus = transMgr.getTransaction(transDef); ValidationException ve = new ValidationException(); if (inActivity.getOriginalActor() == null || inActivity.getOriginalActor().getUniqueIdentifier() == null || inActivity.getOriginalActor().getUniqueIdentifier().length() <= 0) { ve.addError("OriginalActor", "Must be included for Share verbs."); throw ve; } List<Long> activityIds = new ArrayList<Long>(1); activityIds.add(new Long(inActivity.getBaseObjectProperties().get("originalActivityId"))); inActivity.getBaseObjectProperties().remove("originalActivityId"); List<ActivityDTO> originalActivityResults; try { originalActivityResults = activityMapper.execute(activityIds); if (originalActivityResults.size() == 0) { ve.addError("OriginalActivity", "activity being shared could not be found in the db."); throw ve; } if (originalActivityResults.size() > 1) { ve.addError("OriginalActivity", "more than one result was found for the original activity id."); } ActivityDTO origActivity = originalActivityResults.get(0); if (origActivity.getDestinationStream().getType() == EntityType.GROUP) { DomainGroupModelView group = groupShortNameCacheMapper.fetchUniqueResult(origActivity .getDestinationStream().getUniqueIdentifier()); if (group != null && !group.isPublic()) { ve.addError("OriginalActivity", "OriginalActivity from a private group and can not be shared."); throw ve; } else if (group == null) { ve.addError("OriginalActivity", "OriginalActivity Group Entity not found."); } } if (!inActivity.getBaseObjectProperties().equals(origActivity.getBaseObjectProperties())) { ve.addError("BaseObjectProperties", "Oringal Activity BaseObjectProperties must equal the properties of the Shared Activity."); } else { inActivity.getBaseObjectProperties().put("originalActivityId", activityIds.get(0).toString()); } if (!inActivity.getOriginalActor().getUniqueIdentifier().equals( origActivity.getActor().getUniqueIdentifier())) { ve.addError("OriginalActor", "Original actor of the shared activity does not match the actor of the original activity."); } if (!inActivity.getBaseObjectType().equals(origActivity.getBaseObjectType())) { ve.addError("BaseObjectType", "activity must be of the same type as the original activity."); } transMgr.commit(transStatus); } catch (Exception ex) { transMgr.rollback(transStatus); ve.addError("OriginalActivity", "Error occurred accessing the original activity."); } if (!ve.getErrors().isEmpty()) { throw ve; } } ShareVerbValidator(final DomainMapper<List<Long>, List<ActivityDTO>>  inActivityMapper,
            final PlatformTransactionManager inTransManager,
            final GetDomainGroupsByShortNames inGroupShortNameCacheMapper); void validate(final ActivityDTO inActivity); }
ShareVerbValidator implements ActivityValidator { public void validate(final ActivityDTO inActivity) { DefaultTransactionDefinition transDef = new DefaultTransactionDefinition(); transDef.setName("LookupActivityTransaction"); transDef.setPropagationBehavior(TransactionDefinition.PROPAGATION_REQUIRED); TransactionStatus transStatus = transMgr.getTransaction(transDef); ValidationException ve = new ValidationException(); if (inActivity.getOriginalActor() == null || inActivity.getOriginalActor().getUniqueIdentifier() == null || inActivity.getOriginalActor().getUniqueIdentifier().length() <= 0) { ve.addError("OriginalActor", "Must be included for Share verbs."); throw ve; } List<Long> activityIds = new ArrayList<Long>(1); activityIds.add(new Long(inActivity.getBaseObjectProperties().get("originalActivityId"))); inActivity.getBaseObjectProperties().remove("originalActivityId"); List<ActivityDTO> originalActivityResults; try { originalActivityResults = activityMapper.execute(activityIds); if (originalActivityResults.size() == 0) { ve.addError("OriginalActivity", "activity being shared could not be found in the db."); throw ve; } if (originalActivityResults.size() > 1) { ve.addError("OriginalActivity", "more than one result was found for the original activity id."); } ActivityDTO origActivity = originalActivityResults.get(0); if (origActivity.getDestinationStream().getType() == EntityType.GROUP) { DomainGroupModelView group = groupShortNameCacheMapper.fetchUniqueResult(origActivity .getDestinationStream().getUniqueIdentifier()); if (group != null && !group.isPublic()) { ve.addError("OriginalActivity", "OriginalActivity from a private group and can not be shared."); throw ve; } else if (group == null) { ve.addError("OriginalActivity", "OriginalActivity Group Entity not found."); } } if (!inActivity.getBaseObjectProperties().equals(origActivity.getBaseObjectProperties())) { ve.addError("BaseObjectProperties", "Oringal Activity BaseObjectProperties must equal the properties of the Shared Activity."); } else { inActivity.getBaseObjectProperties().put("originalActivityId", activityIds.get(0).toString()); } if (!inActivity.getOriginalActor().getUniqueIdentifier().equals( origActivity.getActor().getUniqueIdentifier())) { ve.addError("OriginalActor", "Original actor of the shared activity does not match the actor of the original activity."); } if (!inActivity.getBaseObjectType().equals(origActivity.getBaseObjectType())) { ve.addError("BaseObjectType", "activity must be of the same type as the original activity."); } transMgr.commit(transStatus); } catch (Exception ex) { transMgr.rollback(transStatus); ve.addError("OriginalActivity", "Error occurred accessing the original activity."); } if (!ve.getErrors().isEmpty()) { throw ve; } } ShareVerbValidator(final DomainMapper<List<Long>, List<ActivityDTO>>  inActivityMapper,
            final PlatformTransactionManager inTransManager,
            final GetDomainGroupsByShortNames inGroupShortNameCacheMapper); void validate(final ActivityDTO inActivity);  }