PeopleFlowActionTypeService extends KrmsTypeServiceBase implements ActionTypeService { @Override public Action loadAction(ActionDefinition actionDefinition) { if (actionDefinition == null) { throw new RiceIllegalArgumentException("actionDefinition must not be null"); } if (actionDefinition.getAttributes() == null || !actionDefinition.getAttributes().containsKey(ATTRIBUTE_FIELD_NAME)) { throw new RiceIllegalArgumentException("actionDefinition does not contain an " + ATTRIBUTE_FIELD_NAME + " attribute"); } String peopleFlowId = actionDefinition.getAttributes().get(ATTRIBUTE_FIELD_NAME); if (StringUtils.isBlank(peopleFlowId)) { throw new RiceIllegalArgumentException(ATTRIBUTE_FIELD_NAME + " attribute must not be null or blank"); } return new PeopleFlowAction(type, peopleFlowId); } PeopleFlowActionTypeService(Type type); static PeopleFlowActionTypeService getInstance(Type type); void setConfigurationService(ConfigurationService configurationService); @Override Action loadAction(ActionDefinition actionDefinition); @Override RemotableAttributeField translateTypeAttribute(KrmsTypeAttribute inputAttribute,
            KrmsAttributeDefinition attributeDefinition); @Override List<RemotableAttributeError> validateAttributes(

            @WebParam(name = "krmsTypeId") String krmsTypeId,

            @WebParam(name = "attributes")
            @XmlJavaTypeAdapter(value = MapStringStringAdapter.class)
            Map<String, String> attributes

    ); @Override List<RemotableAttributeError> validateAttributesAgainstExisting(
            @WebParam(name = "krmsTypeId") String krmsTypeId, @WebParam(name = "newAttributes") @XmlJavaTypeAdapter(
            value = MapStringStringAdapter.class) Map<String, String> newAttributes,
            @WebParam(name = "oldAttributes") @XmlJavaTypeAdapter(
                    value = MapStringStringAdapter.class) Map<String, String> oldAttributes); PeopleFlowService getPeopleFlowService(); void setPeopleFlowService(PeopleFlowService peopleFlowService); static final String ATTRIBUTE_FIELD_NAME; static final String NAME_ATTRIBUTE_FIELD; }
@Test(expected = RiceIllegalArgumentException.class) public void testNullActionDefinition() { notificationPFATS.loadAction(null); }
@Test public void testActionExecution() { ActionDefinition.Builder actionDefinitionBuilder = ActionDefinition.Builder.create("myId", "myName", "myNamespace", "myTypeId", "myRuleId", 0); Map<String, String> attributes = new HashMap<String, String>(); attributes.put(PeopleFlowActionTypeService.ATTRIBUTE_FIELD_NAME, VALID_PEOPLEFLOW_ID_1); attributes.put(PeopleFlowActionTypeService.NAME_ATTRIBUTE_FIELD, VALID_PEOPLEFLOW_NAME_1); actionDefinitionBuilder.setAttributes(attributes); SelectionCriteria sc1 = SelectionCriteria.createCriteria(new DateTime(), Collections.<String, String>emptyMap(), Collections.singletonMap( AgendaDefinition.Constants.EVENT, "foo")); ExecutionEnvironment ee = new BasicExecutionEnvironment(sc1, Collections.<Term, Object>emptyMap(), new ExecutionOptions(), new TermResolutionEngineImpl()); Action notificationAction = notificationPFATS.loadAction(actionDefinitionBuilder.build()); notificationAction.execute(ee); attributes.clear(); attributes.put(PeopleFlowActionTypeService.ATTRIBUTE_FIELD_NAME, VALID_PEOPLEFLOW_ID_2); attributes.put(PeopleFlowActionTypeService.NAME_ATTRIBUTE_FIELD, VALID_PEOPLEFLOW_NAME_2); actionDefinitionBuilder.setAttributes(attributes); Action approvalAction = approvalPFATS.loadAction(actionDefinitionBuilder.build()); approvalAction.execute(ee); String selectedPeopleFlows = (String)ee.getEngineResults().getAttribute(PeopleFlowActionTypeService.PEOPLE_FLOWS_SELECTED_ATTRIBUTE); assertEquals("F:myBogusPeopleFlowId1,A:myBogusPeopleFlowId2", selectedPeopleFlows); String selectedPeopleName = (String)ee.getEngineResults().getAttribute(PeopleFlowActionTypeService.NAME_ATTRIBUTE_FIELD); actionDefinitionBuilder.setAttributes(Collections.<String, String>emptyMap()); try { approvalPFATS.loadAction(actionDefinitionBuilder.build()); fail("should have blown up since the attribute we need isn't in the ActionDefinition"); } catch (RiceIllegalArgumentException e) { } }