@Test public void testHandleMessage() throws BlogAccessException, BlogNotFoundException { ExternalTopicRole[] topicRoles = new ExternalTopicRole[4]; topicRoles[0] = new ExternalTopicRole(); topicRoles[0].setTopicRole("member"); BaseEntity entity = new BaseEntity(); entity.setEntityAlias("a2"); topicRoles[0].setEntity(entity); topicRoles[1] = new ExternalTopicRole(); topicRoles[1].setTopicRole("viewer"); entity = new BaseEntity(); entity.setExternalId("e3"); entity.setIsGroup(true); topicRoles[1].setEntity(entity); topicRoles[2] = new ExternalTopicRole(); topicRoles[2].setTopicRole("manager"); entity = new BaseEntity(); entity.setEntityId(5L); topicRoles[2].setEntity(entity); topicRoles[3] = new ExternalTopicRole(); topicRoles[3].setTopicRole("none"); entity = new BaseEntity(); entity.setEntityId(4L); topicRoles[3].setEntity(entity); message.setRoles(topicRoles); UpdateTopicRolesMessageHandler handler = new MockUpdateTopicRolesMessageHandler(); handler.handleMessage(message); List<ExternalTopicRoleTO> finalRoles = mockSynchronizer.getExternalTopicRoleTOs(); Assert.assertEquals(finalRoles.size(), 4); Assert.assertEquals(finalRoles.get(0).getEntityId(), (Long) 1L); Assert.assertEquals(finalRoles.get(0).getRole(), BlogRole.MEMBER); Assert.assertEquals(finalRoles.get(1).getEntityId(), (Long) 2L); Assert.assertEquals(finalRoles.get(1).getRole(), BlogRole.MEMBER); Assert.assertEquals(finalRoles.get(2).getEntityId(), (Long) 3L); Assert.assertEquals(finalRoles.get(2).getRole(), BlogRole.VIEWER); Assert.assertEquals(finalRoles.get(3).getEntityId(), (Long) 5L); Assert.assertEquals(finalRoles.get(3).getRole(), BlogRole.MANAGER); }
@Override public CommunoteReplyMessage handleMessage(UpdateTopicRolesMessage message) throws BlogNotFoundException, BlogAccessException { validateMessage(message); ExternalTopicRole[] roles = message.getRoles(); if (roles != null) { ExternalTopicRoleToExternalTopicRoleTOConverter converter; converter = new ExternalTopicRoleToExternalTopicRoleTOConverter(); ArrayList<ExternalTopicRoleTO> rolesToAddAndUpdate = new ArrayList<ExternalTopicRoleTO>(); ArrayList<ExternalTopicRoleTO> rolesToRemove = new ArrayList<ExternalTopicRoleTO>(); for (ExternalTopicRole topicRoleObject : roles) { ExternalTopicRoleTO convertedRole = converter.convert(topicRoleObject); if (convertedRole.getRole() == null) { rolesToRemove.add(convertedRole); } else { rolesToAddAndUpdate.add(convertedRole); } } try { Long topicId = TopicUtils.getTopicId(message.getTopic()); BlogRightsSynchronizer synchronizer = createBlogRightsSynchronizer(topicId, message.getExternalSystemId()); synchronizer.mergeRights(rolesToAddAndUpdate, rolesToRemove); } catch (BlogAccessException e) { LOGGER.error("Cannot access topic with ID " + message.getTopic().getTopicId()); throw e; } catch (BlogNotFoundException e) { LOGGER.error("Topic with ID " + message.getTopic().getTopicId() + " not found"); throw e; } } else { LOGGER.debug("No roles provided"); } return null; }
UpdateTopicRolesMessageHandler extends
CommunoteMessageHandler<UpdateTopicRolesMessage> { @Override public CommunoteReplyMessage handleMessage(UpdateTopicRolesMessage message) throws BlogNotFoundException, BlogAccessException { validateMessage(message); ExternalTopicRole[] roles = message.getRoles(); if (roles != null) { ExternalTopicRoleToExternalTopicRoleTOConverter converter; converter = new ExternalTopicRoleToExternalTopicRoleTOConverter(); ArrayList<ExternalTopicRoleTO> rolesToAddAndUpdate = new ArrayList<ExternalTopicRoleTO>(); ArrayList<ExternalTopicRoleTO> rolesToRemove = new ArrayList<ExternalTopicRoleTO>(); for (ExternalTopicRole topicRoleObject : roles) { ExternalTopicRoleTO convertedRole = converter.convert(topicRoleObject); if (convertedRole.getRole() == null) { rolesToRemove.add(convertedRole); } else { rolesToAddAndUpdate.add(convertedRole); } } try { Long topicId = TopicUtils.getTopicId(message.getTopic()); BlogRightsSynchronizer synchronizer = createBlogRightsSynchronizer(topicId, message.getExternalSystemId()); synchronizer.mergeRights(rolesToAddAndUpdate, rolesToRemove); } catch (BlogAccessException e) { LOGGER.error("Cannot access topic with ID " + message.getTopic().getTopicId()); throw e; } catch (BlogNotFoundException e) { LOGGER.error("Topic with ID " + message.getTopic().getTopicId() + " not found"); throw e; } } else { LOGGER.debug("No roles provided"); } return null; } }
UpdateTopicRolesMessageHandler extends
CommunoteMessageHandler<UpdateTopicRolesMessage> { @Override public CommunoteReplyMessage handleMessage(UpdateTopicRolesMessage message) throws BlogNotFoundException, BlogAccessException { validateMessage(message); ExternalTopicRole[] roles = message.getRoles(); if (roles != null) { ExternalTopicRoleToExternalTopicRoleTOConverter converter; converter = new ExternalTopicRoleToExternalTopicRoleTOConverter(); ArrayList<ExternalTopicRoleTO> rolesToAddAndUpdate = new ArrayList<ExternalTopicRoleTO>(); ArrayList<ExternalTopicRoleTO> rolesToRemove = new ArrayList<ExternalTopicRoleTO>(); for (ExternalTopicRole topicRoleObject : roles) { ExternalTopicRoleTO convertedRole = converter.convert(topicRoleObject); if (convertedRole.getRole() == null) { rolesToRemove.add(convertedRole); } else { rolesToAddAndUpdate.add(convertedRole); } } try { Long topicId = TopicUtils.getTopicId(message.getTopic()); BlogRightsSynchronizer synchronizer = createBlogRightsSynchronizer(topicId, message.getExternalSystemId()); synchronizer.mergeRights(rolesToAddAndUpdate, rolesToRemove); } catch (BlogAccessException e) { LOGGER.error("Cannot access topic with ID " + message.getTopic().getTopicId()); throw e; } catch (BlogNotFoundException e) { LOGGER.error("Topic with ID " + message.getTopic().getTopicId() + " not found"); throw e; } } else { LOGGER.debug("No roles provided"); } return null; }  }
UpdateTopicRolesMessageHandler extends
CommunoteMessageHandler<UpdateTopicRolesMessage> { @Override public CommunoteReplyMessage handleMessage(UpdateTopicRolesMessage message) throws BlogNotFoundException, BlogAccessException { validateMessage(message); ExternalTopicRole[] roles = message.getRoles(); if (roles != null) { ExternalTopicRoleToExternalTopicRoleTOConverter converter; converter = new ExternalTopicRoleToExternalTopicRoleTOConverter(); ArrayList<ExternalTopicRoleTO> rolesToAddAndUpdate = new ArrayList<ExternalTopicRoleTO>(); ArrayList<ExternalTopicRoleTO> rolesToRemove = new ArrayList<ExternalTopicRoleTO>(); for (ExternalTopicRole topicRoleObject : roles) { ExternalTopicRoleTO convertedRole = converter.convert(topicRoleObject); if (convertedRole.getRole() == null) { rolesToRemove.add(convertedRole); } else { rolesToAddAndUpdate.add(convertedRole); } } try { Long topicId = TopicUtils.getTopicId(message.getTopic()); BlogRightsSynchronizer synchronizer = createBlogRightsSynchronizer(topicId, message.getExternalSystemId()); synchronizer.mergeRights(rolesToAddAndUpdate, rolesToRemove); } catch (BlogAccessException e) { LOGGER.error("Cannot access topic with ID " + message.getTopic().getTopicId()); throw e; } catch (BlogNotFoundException e) { LOGGER.error("Topic with ID " + message.getTopic().getTopicId() + " not found"); throw e; } } else { LOGGER.debug("No roles provided"); } return null; }  @Override Class<UpdateTopicRolesMessage> getHandledMessageClass(); @Override String getVersion(); @Override CommunoteReplyMessage handleMessage(UpdateTopicRolesMessage message); void validateMessage(UpdateTopicRolesMessage message); }
UpdateTopicRolesMessageHandler extends
CommunoteMessageHandler<UpdateTopicRolesMessage> { @Override public CommunoteReplyMessage handleMessage(UpdateTopicRolesMessage message) throws BlogNotFoundException, BlogAccessException { validateMessage(message); ExternalTopicRole[] roles = message.getRoles(); if (roles != null) { ExternalTopicRoleToExternalTopicRoleTOConverter converter; converter = new ExternalTopicRoleToExternalTopicRoleTOConverter(); ArrayList<ExternalTopicRoleTO> rolesToAddAndUpdate = new ArrayList<ExternalTopicRoleTO>(); ArrayList<ExternalTopicRoleTO> rolesToRemove = new ArrayList<ExternalTopicRoleTO>(); for (ExternalTopicRole topicRoleObject : roles) { ExternalTopicRoleTO convertedRole = converter.convert(topicRoleObject); if (convertedRole.getRole() == null) { rolesToRemove.add(convertedRole); } else { rolesToAddAndUpdate.add(convertedRole); } } try { Long topicId = TopicUtils.getTopicId(message.getTopic()); BlogRightsSynchronizer synchronizer = createBlogRightsSynchronizer(topicId, message.getExternalSystemId()); synchronizer.mergeRights(rolesToAddAndUpdate, rolesToRemove); } catch (BlogAccessException e) { LOGGER.error("Cannot access topic with ID " + message.getTopic().getTopicId()); throw e; } catch (BlogNotFoundException e) { LOGGER.error("Topic with ID " + message.getTopic().getTopicId() + " not found"); throw e; } } else { LOGGER.debug("No roles provided"); } return null; }  @Override Class<UpdateTopicRolesMessage> getHandledMessageClass(); @Override String getVersion(); @Override CommunoteReplyMessage handleMessage(UpdateTopicRolesMessage message); void validateMessage(UpdateTopicRolesMessage message);  }