ActionListCustomizationMediatorImpl implements ActionListCustomizationMediator { @Override public Map<String, ActionItemCustomization> getActionListCustomizations(String principalId, List<ActionItem> actionItems) throws RiceIllegalArgumentException { if (StringUtils.isBlank(principalId)) { throw new RiceIllegalArgumentException("invalid principalId: " + principalId); } if (actionItems == null) { actionItems = Collections.emptyList(); } Map<String, ActionItemCustomization> results = new HashMap<String, ActionItemCustomization>(); ListMultimap<String, ActionItem> itemsByApplicationId = ArrayListMultimap.create(); for (ActionItem actionItem : actionItems) { DocumentType docType = getDocumentTypeService().findByName(actionItem.getDocName()); if (docType == null) { LOG.error(String.format("Action item %s has an invalid document type name of %s", actionItem.getId(), actionItem.getDocName())); itemsByApplicationId.put(null, actionItem); } else { itemsByApplicationId.put(getActionListCustomizationApplicationId(docType), actionItem); } } for (String applicationId : itemsByApplicationId.keySet()) { ActionListCustomizationHandlerService actionListCustomizationHandler = getActionListCustomizationHandlerServiceChooser().getByApplicationId(applicationId); if (actionListCustomizationHandler == null) { actionListCustomizationHandler = getActionListCustomizationHandlerServiceChooser().getByApplicationId(null); } List<ActionItemCustomization> customizations = actionListCustomizationHandler.customizeActionList(principalId, itemsByApplicationId.get( applicationId)); if (customizations != null) for (ActionItemCustomization customization : customizations) { results.put(customization.getActionItemId(), customization); } } return results; }  @Override Map<String, ActionItemCustomization> getActionListCustomizations(String principalId,
            List<ActionItem> actionItems); DocumentTypeService getDocumentTypeService(); void setDocumentTypeService(DocumentTypeService documentTypeService); ActionListCustomizationHandlerServiceChooser getActionListCustomizationHandlerServiceChooser(); void setActionListCustomizationHandlerServiceChooser(
            ActionListCustomizationHandlerServiceChooser actionListCustomizationHandlerServiceChooser);  }
@Test public void testApplicationServiceMediation() { ActionItem.Builder fooActionItemBuilder = ActionItem.Builder.create( "321", "A", "234", DateTime.now(), "Foo Doc Label", "http: ); fooActionItemBuilder.setId(FOO_ACTION_ITEM_ID); ActionItem.Builder barActionItemBuilder = ActionItem.Builder.create( "322", "A", "235", DateTime.now(), "Bar Doc Label", "http: ); fooActionItemBuilder.setId(DEFAULT_ACTION_ITEM_ID); ArrayList<ActionItem> actionItems = new ArrayList<ActionItem>(); actionItems.add(fooActionItemBuilder.build()); actionItems.add(barActionItemBuilder.build()); Map<String, ActionItemCustomization> customizations = mediator.getActionListCustomizations("gilesp", actionItems); assertTrue(customizations.size() == 2); assertEquals(fooResult, customizations.get(fooResult.getActionItemId())); assertEquals(defaultResult, customizations.get(defaultResult.getActionItemId())); }
@Test(expected = RiceIllegalArgumentException.class) public void testNullPrincipalId() { mediator.getActionListCustomizations(null, Collections.<ActionItem>emptyList()); }
@Test(expected = RiceIllegalArgumentException.class) public void testEmptyPrincipalId() { mediator.getActionListCustomizations("", Collections.<ActionItem>emptyList()); }
@Test public void testEmptyActionItemList() { Map<String, ActionItemCustomization> customizations = mediator.getActionListCustomizations("gilesp", Collections.<ActionItem>emptyList()); assertTrue(customizations.size() == 0); }