protected EndpointGroup generateEndpointGroup(Application app, Set<Topic> topics) { EndpointGroup group = new EndpointGroup(); if (app == null) { app = generateApplication(null); } group.setApplication(app); group.setName("GROUP_ALL_" + RANDOM.nextInt()); group.setWeight(RANDOM.nextInt()); group.setTopics(topics); return endpointGroupDao.save(group); }
@Override public List<TopicDto> findVacantTopicsByEndpointGroupId(String endpointGroupId) { validateId(endpointGroupId, "Can't find vacant topics. Invalid endpoint group id " + endpointGroupId); List<TopicDto> topics = Collections.emptyList(); EndpointGroup endpointGroup = endpointGroupDao.findById(endpointGroupId); String applicationId = null; if (endpointGroup != null) { applicationId = endpointGroup.getApplicationId(); } if (isNotBlank(applicationId)) { topics = convertDtoList(topicDao.findVacantTopicsByGroupId(applicationId, endpointGroupId)); } else { LOG.warn("Can't get application id from endpoint group."); } return topics; }
@Override @Transactional public void removeEndpointGroupByAppId(String applicationId) { validateSqlId(applicationId, "Can't remove endpoint groups by application id. Incorrect " + "application id " + applicationId); List<EndpointGroup> groups = endpointGroupDao.findByApplicationId(applicationId); if (groups != null && !groups.isEmpty()) { for (EndpointGroup group : groups) { removeEndpointGroup(group.getId().toString(), true); } } }
private ChangeNotificationDto createNotification(ProfileFilterDto profileFilter, HistoryDto historyDto) { LOG.debug("Create notification after profile filter update."); ChangeNotificationDto changeNotificationDto = null; if (historyDto != null) { changeNotificationDto = new ChangeNotificationDto(); changeNotificationDto.setAppId(profileFilter.getApplicationId()); changeNotificationDto.setAppSeqNumber(historyDto.getSequenceNumber()); String endpointGroupId = profileFilter.getEndpointGroupId(); if (isValidId(endpointGroupId)) { EndpointGroup group = endpointGroupDao.findById(endpointGroupId); if (group != null) { changeNotificationDto.setGroupId(group.getId().toString()); changeNotificationDto.setGroupSeqNumber(group.getSequenceNumber()); } else { LOG.debug("Can't find endpoint group by id [{}].", endpointGroupId); } } else { LOG.debug("Incorrect endpoint group id [{}].", endpointGroupId); } } else { LOG.debug("Can't save history information."); } return changeNotificationDto; }
} else { endpointGroupDto.setCreatedTime(System.currentTimeMillis()); savedGroup = getDto(endpointGroupDao.save(new EndpointGroup(endpointGroupDto))); if (groupWithSameWeight != null && !groupWithSameWeight.getId().equals(previousGroup.getId())) { throw new IncorrectParameterException("Can't save endpoint group with same weight and" + " application id"); } else if (previousGroup.getWeight() == DEFAULT_GROUP_WEIGHT) { throw new IncorrectParameterException("Can't update weight for default endpoint group"); } else if (groupWithSameName != null && !groupWithSameName.getId().equals(previousGroup.getId())) { throw new IncorrectParameterException("Can't save endpoint group with same name and " + "application id"); } else { savedGroup = getDto(endpointGroupDao.save(new EndpointGroup(endpointGroupDto))); if (previousGroup.getWeight() != savedGroup.getWeight()) { addHistory(savedGroup, ChangeType.UPDATE_WEIGHT);
public String getEndpointGroupId() { return endpointGroup != null ? endpointGroup.getStringId() : null; }
if (endpointGroup != null) { if (endpointGroup.getWeight() != 0 || forceRemove) { EndpointGroupDto groupDto = endpointGroup.toDto(); HistoryDto historyDto = addHistory(groupDto, ChangeType.REMOVE_GROUP); changeDto = new ChangeNotificationDto(); changeDto.setAppId(endpointGroup.getApplicationId()); changeDto.setAppSeqNumber(historyDto.getSequenceNumber()); changeDto.setGroupId(groupDto.getId());
@Test public void removeTopicFromEndpointGroup() { Topic first = generateTopic(null, null, "first"); Topic second = generateTopic(first.getApplication(), null, "second"); Topic third = generateTopic(first.getApplication(), null, "third"); Set<Topic> topics = new HashSet<>(); topics.add(first); topics.add(second); topics.add(third); EndpointGroup endpointGroup = generateEndpointGroup(first.getApplication(), topics); Assert.assertEquals(3, endpointGroup.getTopics().size()); endpointGroupDao.removeTopicFromEndpointGroup(endpointGroup.getId().toString(), first.getId().toString()); EndpointGroup group = endpointGroupDao.removeTopicFromEndpointGroup(endpointGroup.getId().toString(), second.getId().toString()); Set<Topic> expected = new HashSet<>(); expected.add(third); Assert.assertEquals(expected, group.getTopics()); }
@Test public void findByAppIdAndWeight() { EndpointGroup endpointGroup = generateEndpointGroup(null, null); EndpointGroup group = endpointGroupDao.findByAppIdAndWeight(endpointGroup.getApplicationId(), endpointGroup.getWeight()); Assert.assertEquals(endpointGroup, group); }
@Test public void testFindVacantTopicsByGroupId() { Topic first = generateTopic(null, null, "first"); Application app = first.getApplication(); Topic second = generateTopic(app, null, "second"); Set<Topic> firstTopics = new HashSet<>(); firstTopics.add(first); firstTopics.add(second); Topic third = generateTopic(app, null, "third"); Topic fourth = generateTopic(app, null, "fourth"); Set<Topic> secondTopics = new HashSet<>(); secondTopics.add(third); secondTopics.add(fourth); EndpointGroup firstGroup = generateEndpointGroup(app, firstTopics); EndpointGroup secondGroup = generateEndpointGroup(app, secondTopics); List<Topic> foundOne = topicDao.findVacantTopicsByGroupId(firstGroup.getApplicationId(), firstGroup.getId().toString()); Set<Topic> firstGroupSet = new HashSet<>(); firstGroupSet.addAll(foundOne); List<Topic> foundTwo = topicDao.findVacantTopicsByGroupId(secondGroup.getApplicationId(), secondGroup.getId().toString()); Set<Topic> secondGroupSet = new HashSet<>(); secondGroupSet.addAll(foundTwo); Assert.assertEquals(secondTopics, firstGroupSet); Assert.assertEquals(firstTopics, secondGroupSet); }
@Override public EndpointGroup save(EndpointGroup object) { LOG.debug("Saving endpoint group {}", object); Set<Topic> topics = object.getTopics(); object = super.save(object); if (topics != null && !topics.isEmpty()) { for (Topic topic : topics) { addTopicToEndpointGroup(object, topic.getStringId()); } } if (LOG.isTraceEnabled()) { LOG.trace("Saving result: {}.", object); } else { LOG.debug("Saving result: {}.", object != null); } return object; }
@Override @Transactional public UpdateNotificationDto<EndpointGroupDto> removeTopicFromEndpointGroup(String id, String topicId) { validateSqlId(id, "Can't remove endpoint group topics " + topicId + ". Incorrect endpoint group id." + id); UpdateNotificationDto<EndpointGroupDto> dto = null; EndpointGroup endpointGroup = endpointGroupDao.removeTopicFromEndpointGroup(id, topicId); if (endpointGroup != null) { dto = new UpdateNotificationDto<>(); HistoryDto history = addHistory(endpointGroup.toDto(), ChangeType.REMOVE_TOPIC, topicId); if (history != null) { dto.setAppId(history.getApplicationId()); dto.setAppSeqNumber(history.getSequenceNumber()); } dto.setChangeType(ChangeType.REMOVE_TOPIC); dto.setTopicId(topicId); dto.setGroupId(endpointGroup.getId().toString()); dto.setPayload(endpointGroup.toDto()); } else { LOG.debug("Can't remove topic [{}] from endpoint group [{}]", topicId, id); } return dto; }
@Test public void findByAppIdAndName() { EndpointGroup endpointGroup = generateEndpointGroup(null, null); EndpointGroup group = endpointGroupDao.findByAppIdAndName(endpointGroup.getApplicationId(), endpointGroup.getName()); Assert.assertEquals(endpointGroup, group); }
@Override public EndpointGroupDto toDto() { EndpointGroupDto dto = createDto(); dto.setId(getStringId()); dto.setDescription(description); dto.setCreatedUsername(createdUsername); dto.setCreatedTime(createdTime); if (application != null) { dto.setApplicationId(application.getStringId()); } dto.setName(name); dto.setSequenceNumber(sequenceNumber); dto.setWeight(weight); dto.setTopics(getTopicIds(topics)); return dto; }
KaaData body = null; if (endpointGroup != null) { if (endpointGroup.getWeight() == 0) { LOG.debug("Create default UUID validator with base schema: {}", configurationSchema.getBaseSchema());
@Override protected GenericModel<EndpointGroupDto> newInstance(Long id) { return new EndpointGroup(id); }
return false; } else if (!endpointGroup.equals(other.endpointGroup)) { return false;
private ChangeNotificationDto createNotification(ConfigurationDto configurationDto, HistoryDto historyDto) { LOG.debug("Create notification after configuration update."); ChangeNotificationDto changeNotificationDto = null; if (historyDto != null) { changeNotificationDto = new ChangeNotificationDto(); changeNotificationDto.setAppId(configurationDto.getApplicationId()); changeNotificationDto.setAppSeqNumber(historyDto.getSequenceNumber()); String endpointGroupId = configurationDto.getEndpointGroupId(); if (isValidId(endpointGroupId)) { EndpointGroup group = endpointGroupDao.findById(endpointGroupId); if (group != null) { changeNotificationDto.setGroupId(idToString(group)); changeNotificationDto.setGroupSeqNumber(group.getSequenceNumber()); } else { LOG.debug("Can't find endpoint group by id [{}].", endpointGroupId); } } else { LOG.debug("Incorrect endpoint group id [{}].", endpointGroupId); } } else { LOG.debug("Can't save history information."); } return changeNotificationDto; }
public String getGroupId() { return endpointGroup.getStringId(); }
@Test public void addTopicToEndpointGroup() { Topic first = generateTopic(null, null, "first"); Topic second = generateTopic(first.getApplication(), null, "second"); Topic third = generateTopic(first.getApplication(), null, "third"); Set<Topic> topics = new HashSet<>(); topics.add(first); topics.add(second); topics.add(third); EndpointGroup endpointGroup = generateEndpointGroup(first.getApplication(), topics); endpointGroupDao.addTopicToEndpointGroup(endpointGroup.getId().toString(), first.getId().toString()); endpointGroupDao.addTopicToEndpointGroup(endpointGroup.getId().toString(), second.getId().toString()); EndpointGroup saved = endpointGroupDao.addTopicToEndpointGroup(endpointGroup.getId().toString(), third.getId().toString()); Assert.assertNotNull(saved); Assert.assertEquals(topics, saved.getTopics()); }