@Test public void testHandleMessage() throws BlogNotFoundException, AuthorizationException { SetTopicRolesMessageHandler handler = new SetBulkTopicRoleMessageHandlerTestImpl(); ExternalTopicRole externalTopicRole1 = new ExternalTopicRole(); externalTopicRole1.setExternalObjectId("exObjId"); externalTopicRole1.setTopicRole("manager"); externalTopicRole1.getEntity().setEntityAlias(ENTITY_USER_ALIAS); assertTopicRole(handler, externalTopicRole1, ENTITY_USER_ALIAS); ExternalTopicRole externalTopicRole2 = new ExternalTopicRole(); externalTopicRole2.setExternalObjectId("exObjId"); externalTopicRole2.setTopicRole("member"); externalTopicRole2.getEntity().setEntityAlias(ENTITY_GROUP_ALIAS); externalTopicRole2.getEntity().setIsGroup(true); assertTopicRole(handler, externalTopicRole2, ENTITY_GROUP_ALIAS); ExternalTopicRole externalTopicRole3 = new ExternalTopicRole(); externalTopicRole3.setExternalObjectId("exObjId"); externalTopicRole3.setTopicRole("viewer"); externalTopicRole3.getEntity().setEntityAlias(BASE_ENTITY_USER_ALIAS); assertTopicRole(handler, externalTopicRole3, BASE_ENTITY_USER_ALIAS); }
@Override public CommunoteReplyMessage handleMessage(SetTopicRolesMessage message) throws BlogNotFoundException, BlogAccessException { validateMessage(message); ExternalTopicRole[] roles = message.getRoles(); if (roles != null) { ExternalTopicRoleToExternalTopicRoleTOConverter converter; converter = new ExternalTopicRoleToExternalTopicRoleTOConverter(); List<ExternalTopicRoleTO> externalTopicRoleTOs = new ArrayList<ExternalTopicRoleTO>(); for (ExternalTopicRole externalTopicRole : roles) { ExternalTopicRoleTO role = converter.convert(externalTopicRole); if (role.getRole() != null) { externalTopicRoleTOs.add(role); } else { LOG.debug("Ignoring role with null value"); } } try { createBlogRightsSynchronizer(TopicUtils.getTopicId(message.getTopic()), message.getExternalSystemId()).replaceRights(externalTopicRoleTOs); } catch (BlogAccessException e) { LOG.error("Cannot access topic with ID " + message.getTopic().getTopicId()); throw e; } catch (BlogNotFoundException e) { LOG.error("Topic with ID " + message.getTopic().getTopicId() + " not found"); throw e; } } return null; }
SetTopicRolesMessageHandler extends
        CommunoteMessageHandler<SetTopicRolesMessage> { @Override public CommunoteReplyMessage handleMessage(SetTopicRolesMessage message) throws BlogNotFoundException, BlogAccessException { validateMessage(message); ExternalTopicRole[] roles = message.getRoles(); if (roles != null) { ExternalTopicRoleToExternalTopicRoleTOConverter converter; converter = new ExternalTopicRoleToExternalTopicRoleTOConverter(); List<ExternalTopicRoleTO> externalTopicRoleTOs = new ArrayList<ExternalTopicRoleTO>(); for (ExternalTopicRole externalTopicRole : roles) { ExternalTopicRoleTO role = converter.convert(externalTopicRole); if (role.getRole() != null) { externalTopicRoleTOs.add(role); } else { LOG.debug("Ignoring role with null value"); } } try { createBlogRightsSynchronizer(TopicUtils.getTopicId(message.getTopic()), message.getExternalSystemId()).replaceRights(externalTopicRoleTOs); } catch (BlogAccessException e) { LOG.error("Cannot access topic with ID " + message.getTopic().getTopicId()); throw e; } catch (BlogNotFoundException e) { LOG.error("Topic with ID " + message.getTopic().getTopicId() + " not found"); throw e; } } return null; } }
SetTopicRolesMessageHandler extends
        CommunoteMessageHandler<SetTopicRolesMessage> { @Override public CommunoteReplyMessage handleMessage(SetTopicRolesMessage message) throws BlogNotFoundException, BlogAccessException { validateMessage(message); ExternalTopicRole[] roles = message.getRoles(); if (roles != null) { ExternalTopicRoleToExternalTopicRoleTOConverter converter; converter = new ExternalTopicRoleToExternalTopicRoleTOConverter(); List<ExternalTopicRoleTO> externalTopicRoleTOs = new ArrayList<ExternalTopicRoleTO>(); for (ExternalTopicRole externalTopicRole : roles) { ExternalTopicRoleTO role = converter.convert(externalTopicRole); if (role.getRole() != null) { externalTopicRoleTOs.add(role); } else { LOG.debug("Ignoring role with null value"); } } try { createBlogRightsSynchronizer(TopicUtils.getTopicId(message.getTopic()), message.getExternalSystemId()).replaceRights(externalTopicRoleTOs); } catch (BlogAccessException e) { LOG.error("Cannot access topic with ID " + message.getTopic().getTopicId()); throw e; } catch (BlogNotFoundException e) { LOG.error("Topic with ID " + message.getTopic().getTopicId() + " not found"); throw e; } } return null; }  }
SetTopicRolesMessageHandler extends
        CommunoteMessageHandler<SetTopicRolesMessage> { @Override public CommunoteReplyMessage handleMessage(SetTopicRolesMessage message) throws BlogNotFoundException, BlogAccessException { validateMessage(message); ExternalTopicRole[] roles = message.getRoles(); if (roles != null) { ExternalTopicRoleToExternalTopicRoleTOConverter converter; converter = new ExternalTopicRoleToExternalTopicRoleTOConverter(); List<ExternalTopicRoleTO> externalTopicRoleTOs = new ArrayList<ExternalTopicRoleTO>(); for (ExternalTopicRole externalTopicRole : roles) { ExternalTopicRoleTO role = converter.convert(externalTopicRole); if (role.getRole() != null) { externalTopicRoleTOs.add(role); } else { LOG.debug("Ignoring role with null value"); } } try { createBlogRightsSynchronizer(TopicUtils.getTopicId(message.getTopic()), message.getExternalSystemId()).replaceRights(externalTopicRoleTOs); } catch (BlogAccessException e) { LOG.error("Cannot access topic with ID " + message.getTopic().getTopicId()); throw e; } catch (BlogNotFoundException e) { LOG.error("Topic with ID " + message.getTopic().getTopicId() + " not found"); throw e; } } return null; }  @Override Class<SetTopicRolesMessage> getHandledMessageClass(); @Override String getVersion(); @Override CommunoteReplyMessage handleMessage(SetTopicRolesMessage message); void validateMessage(SetTopicRolesMessage message); }
SetTopicRolesMessageHandler extends
        CommunoteMessageHandler<SetTopicRolesMessage> { @Override public CommunoteReplyMessage handleMessage(SetTopicRolesMessage message) throws BlogNotFoundException, BlogAccessException { validateMessage(message); ExternalTopicRole[] roles = message.getRoles(); if (roles != null) { ExternalTopicRoleToExternalTopicRoleTOConverter converter; converter = new ExternalTopicRoleToExternalTopicRoleTOConverter(); List<ExternalTopicRoleTO> externalTopicRoleTOs = new ArrayList<ExternalTopicRoleTO>(); for (ExternalTopicRole externalTopicRole : roles) { ExternalTopicRoleTO role = converter.convert(externalTopicRole); if (role.getRole() != null) { externalTopicRoleTOs.add(role); } else { LOG.debug("Ignoring role with null value"); } } try { createBlogRightsSynchronizer(TopicUtils.getTopicId(message.getTopic()), message.getExternalSystemId()).replaceRights(externalTopicRoleTOs); } catch (BlogAccessException e) { LOG.error("Cannot access topic with ID " + message.getTopic().getTopicId()); throw e; } catch (BlogNotFoundException e) { LOG.error("Topic with ID " + message.getTopic().getTopicId() + " not found"); throw e; } } return null; }  @Override Class<SetTopicRolesMessage> getHandledMessageClass(); @Override String getVersion(); @Override CommunoteReplyMessage handleMessage(SetTopicRolesMessage message); void validateMessage(SetTopicRolesMessage message);  }