@Test(expected = ValidationException.class) public void performActionWithValidationErrorMissingRequired() throws Exception { final HashMap<String, Serializable> values = new HashMap<String, Serializable>(); values.put("EUREKA:TOS", Boolean.TRUE); values.put("EUREKA:PLUGINID", 1L); values.put("EUREKA:FEEDURL", "feedurl"); values.put("somekey", ""); values.put("REQUIRED:somekey", "somekey is required!"); context.checking(new Expectations() { { allowing(ac).getParams(); will(returnValue(values)); } }); sut.execute(taskHandlerContext); }
public Serializable execute(final TaskHandlerActionContext<PrincipalActionContext> context) { HashMap<String, Serializable> values = (HashMap<String, Serializable>) context.getActionContext().getParams(); ValidationException exception = new ValidationException(); for (String key : values.keySet()) { if (key.contains("REQUIRED:")) { String keyLookup = key.split("REQUIRED:")[1]; if (!values.containsKey(keyLookup) || values.get(keyLookup) == null || (values.get(keyLookup) instanceof String && ((String) values.get(keyLookup)).equals(""))) { exception.addError(keyLookup, (String) values.get(key)); } } } if (!(Boolean) values.get("EUREKA:TOS")) { exception.addError("EUREKA:TOS", "In order to use this plugin you must agree to the terms of use."); } if (exception.getErrors().size() > 0) { throw exception; } String group = ""; if (values.containsKey("EUREKA:GROUP")) { group = (String) values.get("EUREKA:GROUP"); } Principal principal = context.getActionContext().getPrincipal(); if (values.containsKey("EUREKA:FEEDSUBID")) { ServiceActionContext deleteAC = new ServiceActionContext(new DeleteFeedSubscriptionRequest((Long) values.get("EUREKA:FEEDSUBID"), group), principal); deleteFeedSub.getExecutionStrategy().execute(deleteAC); } values.put("EUREKA:USER", principal.getAccountId()); ServiceActionContext getFeedContext = new ServiceActionContext(values.get("EUREKA:FEEDURL"), principal); String title = (String) getTitleFromFeed.execute(getFeedContext); GetFeedByUrlRequest request = new GetFeedByUrlRequest((Long) values.get("EUREKA:PLUGINID"), (String) values.get("EUREKA:FEEDURL")); Feed feed = getMapper.execute(request); feed.setTitle(title); FeedSubscriber feedSubscriber = getFeedSubscriberMapper.execute(new GetFeedSubscriberRequest(feed.getId(), getEntityId .getEntityId(values), type, principal.getId())); feedSubscriber.getConfSettings().clear(); for (String key : values.keySet()) { if (!key.contains("REQUIRED:") && !key.contains("EUREKA:")) { feedSubscriber.getConfSettings().put(key, values.get(key)); } } ActivityDTO activity = new ActivityDTO(); HashMap<String, String> props = new HashMap<String, String>(); activity.setBaseObjectProperties(props); String content = "%EUREKA:ACTORNAME% configured the " + values.get("EUREKA:PLUGINTITLE") + " stream plugin"; activity.getBaseObjectProperties().put("content", content); StreamEntityDTO destination = new StreamEntityDTO(); if (type.equals(EntityType.PERSON)) { destination.setUniqueIdentifier(principal.getAccountId()); } else { destination.setUniqueIdentifier(group); } destination.setType(type); activity.setDestinationStream(destination); activity.setBaseObjectType(BaseObjectType.NOTE); activity.setVerb(ActivityVerb.POST); new InlineExecutionStrategyExecutor() .execute(postActivityExecutor, new PostActivityRequest(activity), context); updateMapper.execute(new PersistenceRequest<Feed>(feed)); return Boolean.TRUE; }
AddFeedToEntityExecution implements TaskHandlerExecutionStrategy<PrincipalActionContext> { public Serializable execute(final TaskHandlerActionContext<PrincipalActionContext> context) { HashMap<String, Serializable> values = (HashMap<String, Serializable>) context.getActionContext().getParams(); ValidationException exception = new ValidationException(); for (String key : values.keySet()) { if (key.contains("REQUIRED:")) { String keyLookup = key.split("REQUIRED:")[1]; if (!values.containsKey(keyLookup) || values.get(keyLookup) == null || (values.get(keyLookup) instanceof String && ((String) values.get(keyLookup)).equals(""))) { exception.addError(keyLookup, (String) values.get(key)); } } } if (!(Boolean) values.get("EUREKA:TOS")) { exception.addError("EUREKA:TOS", "In order to use this plugin you must agree to the terms of use."); } if (exception.getErrors().size() > 0) { throw exception; } String group = ""; if (values.containsKey("EUREKA:GROUP")) { group = (String) values.get("EUREKA:GROUP"); } Principal principal = context.getActionContext().getPrincipal(); if (values.containsKey("EUREKA:FEEDSUBID")) { ServiceActionContext deleteAC = new ServiceActionContext(new DeleteFeedSubscriptionRequest((Long) values.get("EUREKA:FEEDSUBID"), group), principal); deleteFeedSub.getExecutionStrategy().execute(deleteAC); } values.put("EUREKA:USER", principal.getAccountId()); ServiceActionContext getFeedContext = new ServiceActionContext(values.get("EUREKA:FEEDURL"), principal); String title = (String) getTitleFromFeed.execute(getFeedContext); GetFeedByUrlRequest request = new GetFeedByUrlRequest((Long) values.get("EUREKA:PLUGINID"), (String) values.get("EUREKA:FEEDURL")); Feed feed = getMapper.execute(request); feed.setTitle(title); FeedSubscriber feedSubscriber = getFeedSubscriberMapper.execute(new GetFeedSubscriberRequest(feed.getId(), getEntityId .getEntityId(values), type, principal.getId())); feedSubscriber.getConfSettings().clear(); for (String key : values.keySet()) { if (!key.contains("REQUIRED:") && !key.contains("EUREKA:")) { feedSubscriber.getConfSettings().put(key, values.get(key)); } } ActivityDTO activity = new ActivityDTO(); HashMap<String, String> props = new HashMap<String, String>(); activity.setBaseObjectProperties(props); String content = "%EUREKA:ACTORNAME% configured the " + values.get("EUREKA:PLUGINTITLE") + " stream plugin"; activity.getBaseObjectProperties().put("content", content); StreamEntityDTO destination = new StreamEntityDTO(); if (type.equals(EntityType.PERSON)) { destination.setUniqueIdentifier(principal.getAccountId()); } else { destination.setUniqueIdentifier(group); } destination.setType(type); activity.setDestinationStream(destination); activity.setBaseObjectType(BaseObjectType.NOTE); activity.setVerb(ActivityVerb.POST); new InlineExecutionStrategyExecutor() .execute(postActivityExecutor, new PostActivityRequest(activity), context); updateMapper.execute(new PersistenceRequest<Feed>(feed)); return Boolean.TRUE; } }
AddFeedToEntityExecution implements TaskHandlerExecutionStrategy<PrincipalActionContext> { public Serializable execute(final TaskHandlerActionContext<PrincipalActionContext> context) { HashMap<String, Serializable> values = (HashMap<String, Serializable>) context.getActionContext().getParams(); ValidationException exception = new ValidationException(); for (String key : values.keySet()) { if (key.contains("REQUIRED:")) { String keyLookup = key.split("REQUIRED:")[1]; if (!values.containsKey(keyLookup) || values.get(keyLookup) == null || (values.get(keyLookup) instanceof String && ((String) values.get(keyLookup)).equals(""))) { exception.addError(keyLookup, (String) values.get(key)); } } } if (!(Boolean) values.get("EUREKA:TOS")) { exception.addError("EUREKA:TOS", "In order to use this plugin you must agree to the terms of use."); } if (exception.getErrors().size() > 0) { throw exception; } String group = ""; if (values.containsKey("EUREKA:GROUP")) { group = (String) values.get("EUREKA:GROUP"); } Principal principal = context.getActionContext().getPrincipal(); if (values.containsKey("EUREKA:FEEDSUBID")) { ServiceActionContext deleteAC = new ServiceActionContext(new DeleteFeedSubscriptionRequest((Long) values.get("EUREKA:FEEDSUBID"), group), principal); deleteFeedSub.getExecutionStrategy().execute(deleteAC); } values.put("EUREKA:USER", principal.getAccountId()); ServiceActionContext getFeedContext = new ServiceActionContext(values.get("EUREKA:FEEDURL"), principal); String title = (String) getTitleFromFeed.execute(getFeedContext); GetFeedByUrlRequest request = new GetFeedByUrlRequest((Long) values.get("EUREKA:PLUGINID"), (String) values.get("EUREKA:FEEDURL")); Feed feed = getMapper.execute(request); feed.setTitle(title); FeedSubscriber feedSubscriber = getFeedSubscriberMapper.execute(new GetFeedSubscriberRequest(feed.getId(), getEntityId .getEntityId(values), type, principal.getId())); feedSubscriber.getConfSettings().clear(); for (String key : values.keySet()) { if (!key.contains("REQUIRED:") && !key.contains("EUREKA:")) { feedSubscriber.getConfSettings().put(key, values.get(key)); } } ActivityDTO activity = new ActivityDTO(); HashMap<String, String> props = new HashMap<String, String>(); activity.setBaseObjectProperties(props); String content = "%EUREKA:ACTORNAME% configured the " + values.get("EUREKA:PLUGINTITLE") + " stream plugin"; activity.getBaseObjectProperties().put("content", content); StreamEntityDTO destination = new StreamEntityDTO(); if (type.equals(EntityType.PERSON)) { destination.setUniqueIdentifier(principal.getAccountId()); } else { destination.setUniqueIdentifier(group); } destination.setType(type); activity.setDestinationStream(destination); activity.setBaseObjectType(BaseObjectType.NOTE); activity.setVerb(ActivityVerb.POST); new InlineExecutionStrategyExecutor() .execute(postActivityExecutor, new PostActivityRequest(activity), context); updateMapper.execute(new PersistenceRequest<Feed>(feed)); return Boolean.TRUE; } @SuppressWarnings("unchecked")  AddFeedToEntityExecution(final UpdateMapper<Feed> inUpdateMapper,
            final GetFeedByUrlOrCreateMapper inGetMapper, final GetEntityIdForFeedSubscription inGetEntityId,
            final GetFeedSubscriberOrCreateMapper inGetFeedSubscriberMapper,
            final ExecutionStrategy inGetTitleFromFeed, final Action inDeleteFeedSub, final EntityType inType,
            final TaskHandlerExecutionStrategy inPostActivityExecutor); }
AddFeedToEntityExecution implements TaskHandlerExecutionStrategy<PrincipalActionContext> { public Serializable execute(final TaskHandlerActionContext<PrincipalActionContext> context) { HashMap<String, Serializable> values = (HashMap<String, Serializable>) context.getActionContext().getParams(); ValidationException exception = new ValidationException(); for (String key : values.keySet()) { if (key.contains("REQUIRED:")) { String keyLookup = key.split("REQUIRED:")[1]; if (!values.containsKey(keyLookup) || values.get(keyLookup) == null || (values.get(keyLookup) instanceof String && ((String) values.get(keyLookup)).equals(""))) { exception.addError(keyLookup, (String) values.get(key)); } } } if (!(Boolean) values.get("EUREKA:TOS")) { exception.addError("EUREKA:TOS", "In order to use this plugin you must agree to the terms of use."); } if (exception.getErrors().size() > 0) { throw exception; } String group = ""; if (values.containsKey("EUREKA:GROUP")) { group = (String) values.get("EUREKA:GROUP"); } Principal principal = context.getActionContext().getPrincipal(); if (values.containsKey("EUREKA:FEEDSUBID")) { ServiceActionContext deleteAC = new ServiceActionContext(new DeleteFeedSubscriptionRequest((Long) values.get("EUREKA:FEEDSUBID"), group), principal); deleteFeedSub.getExecutionStrategy().execute(deleteAC); } values.put("EUREKA:USER", principal.getAccountId()); ServiceActionContext getFeedContext = new ServiceActionContext(values.get("EUREKA:FEEDURL"), principal); String title = (String) getTitleFromFeed.execute(getFeedContext); GetFeedByUrlRequest request = new GetFeedByUrlRequest((Long) values.get("EUREKA:PLUGINID"), (String) values.get("EUREKA:FEEDURL")); Feed feed = getMapper.execute(request); feed.setTitle(title); FeedSubscriber feedSubscriber = getFeedSubscriberMapper.execute(new GetFeedSubscriberRequest(feed.getId(), getEntityId .getEntityId(values), type, principal.getId())); feedSubscriber.getConfSettings().clear(); for (String key : values.keySet()) { if (!key.contains("REQUIRED:") && !key.contains("EUREKA:")) { feedSubscriber.getConfSettings().put(key, values.get(key)); } } ActivityDTO activity = new ActivityDTO(); HashMap<String, String> props = new HashMap<String, String>(); activity.setBaseObjectProperties(props); String content = "%EUREKA:ACTORNAME% configured the " + values.get("EUREKA:PLUGINTITLE") + " stream plugin"; activity.getBaseObjectProperties().put("content", content); StreamEntityDTO destination = new StreamEntityDTO(); if (type.equals(EntityType.PERSON)) { destination.setUniqueIdentifier(principal.getAccountId()); } else { destination.setUniqueIdentifier(group); } destination.setType(type); activity.setDestinationStream(destination); activity.setBaseObjectType(BaseObjectType.NOTE); activity.setVerb(ActivityVerb.POST); new InlineExecutionStrategyExecutor() .execute(postActivityExecutor, new PostActivityRequest(activity), context); updateMapper.execute(new PersistenceRequest<Feed>(feed)); return Boolean.TRUE; } @SuppressWarnings("unchecked")  AddFeedToEntityExecution(final UpdateMapper<Feed> inUpdateMapper,
            final GetFeedByUrlOrCreateMapper inGetMapper, final GetEntityIdForFeedSubscription inGetEntityId,
            final GetFeedSubscriberOrCreateMapper inGetFeedSubscriberMapper,
            final ExecutionStrategy inGetTitleFromFeed, final Action inDeleteFeedSub, final EntityType inType,
            final TaskHandlerExecutionStrategy inPostActivityExecutor); Serializable execute(final TaskHandlerActionContext<PrincipalActionContext> context); }
AddFeedToEntityExecution implements TaskHandlerExecutionStrategy<PrincipalActionContext> { public Serializable execute(final TaskHandlerActionContext<PrincipalActionContext> context) { HashMap<String, Serializable> values = (HashMap<String, Serializable>) context.getActionContext().getParams(); ValidationException exception = new ValidationException(); for (String key : values.keySet()) { if (key.contains("REQUIRED:")) { String keyLookup = key.split("REQUIRED:")[1]; if (!values.containsKey(keyLookup) || values.get(keyLookup) == null || (values.get(keyLookup) instanceof String && ((String) values.get(keyLookup)).equals(""))) { exception.addError(keyLookup, (String) values.get(key)); } } } if (!(Boolean) values.get("EUREKA:TOS")) { exception.addError("EUREKA:TOS", "In order to use this plugin you must agree to the terms of use."); } if (exception.getErrors().size() > 0) { throw exception; } String group = ""; if (values.containsKey("EUREKA:GROUP")) { group = (String) values.get("EUREKA:GROUP"); } Principal principal = context.getActionContext().getPrincipal(); if (values.containsKey("EUREKA:FEEDSUBID")) { ServiceActionContext deleteAC = new ServiceActionContext(new DeleteFeedSubscriptionRequest((Long) values.get("EUREKA:FEEDSUBID"), group), principal); deleteFeedSub.getExecutionStrategy().execute(deleteAC); } values.put("EUREKA:USER", principal.getAccountId()); ServiceActionContext getFeedContext = new ServiceActionContext(values.get("EUREKA:FEEDURL"), principal); String title = (String) getTitleFromFeed.execute(getFeedContext); GetFeedByUrlRequest request = new GetFeedByUrlRequest((Long) values.get("EUREKA:PLUGINID"), (String) values.get("EUREKA:FEEDURL")); Feed feed = getMapper.execute(request); feed.setTitle(title); FeedSubscriber feedSubscriber = getFeedSubscriberMapper.execute(new GetFeedSubscriberRequest(feed.getId(), getEntityId .getEntityId(values), type, principal.getId())); feedSubscriber.getConfSettings().clear(); for (String key : values.keySet()) { if (!key.contains("REQUIRED:") && !key.contains("EUREKA:")) { feedSubscriber.getConfSettings().put(key, values.get(key)); } } ActivityDTO activity = new ActivityDTO(); HashMap<String, String> props = new HashMap<String, String>(); activity.setBaseObjectProperties(props); String content = "%EUREKA:ACTORNAME% configured the " + values.get("EUREKA:PLUGINTITLE") + " stream plugin"; activity.getBaseObjectProperties().put("content", content); StreamEntityDTO destination = new StreamEntityDTO(); if (type.equals(EntityType.PERSON)) { destination.setUniqueIdentifier(principal.getAccountId()); } else { destination.setUniqueIdentifier(group); } destination.setType(type); activity.setDestinationStream(destination); activity.setBaseObjectType(BaseObjectType.NOTE); activity.setVerb(ActivityVerb.POST); new InlineExecutionStrategyExecutor() .execute(postActivityExecutor, new PostActivityRequest(activity), context); updateMapper.execute(new PersistenceRequest<Feed>(feed)); return Boolean.TRUE; } @SuppressWarnings("unchecked")  AddFeedToEntityExecution(final UpdateMapper<Feed> inUpdateMapper,
            final GetFeedByUrlOrCreateMapper inGetMapper, final GetEntityIdForFeedSubscription inGetEntityId,
            final GetFeedSubscriberOrCreateMapper inGetFeedSubscriberMapper,
            final ExecutionStrategy inGetTitleFromFeed, final Action inDeleteFeedSub, final EntityType inType,
            final TaskHandlerExecutionStrategy inPostActivityExecutor); Serializable execute(final TaskHandlerActionContext<PrincipalActionContext> context);  }