@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); } } }
@Override public List<UpdateNotificationDto<EndpointGroupDto>> removeTopicById(String id) { validateId(id, "Can't remove topic. Invalid topic id " + id); TopicDto topic = findTopicById(id); List<UpdateNotificationDto<EndpointGroupDto>> notificationList = new LinkedList<>(); if (topic != null) { List<EndpointGroup> groups = endpointGroupDao.findEndpointGroupsByTopicIdAndAppId( topic.getApplicationId(), id); if (groups != null && !groups.isEmpty()) { for (EndpointGroup eg : groups) { notificationList.add(endpointService.removeTopicFromEndpointGroup(eg.getId().toString(), id)); } } topicDao.removeById(id); notificationDao.removeNotificationsByTopicId(id); } return notificationList; }
@Override public ConfigurationDto findDefaultConfigurationBySchemaId(String schemaId) { validateId(schemaId, "Schema id is incorrect. Can't find default configuration by schema id " + schemaId); ConfigurationDto configuration = null; ConfigurationSchema configurationSchema = configurationSchemaDao.findById(schemaId); if (configurationSchema != null) { String appId = configurationSchema.getApplicationId(); EndpointGroup endpointGroup = endpointGroupDao.findByAppIdAndWeight(appId, 0); if (endpointGroup != null) { String endpointGroupId = String.valueOf(endpointGroup.getId()); configuration = getDto(configurationDao.findConfigurationByEndpointGroupIdAndVersion( endpointGroupId, configurationSchema.getVersion())); } else { LOG.warn("Can't find default group for application [{}]", appId); } } else { LOG.warn("Can't find configuration schema for id [{}]", schemaId); } return configuration; }
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; }
@Test public void findActualByEndpointGroupId() { List<ProfileFilter> filters = generateFilter(null, null, null, 4, UpdateStatus.DEPRECATED); ProfileFilter first = filters.get(0); EndpointGroup group = first.getEndpointGroup(); List<ProfileFilter> active = generateFilter(null, null, group, 1, UpdateStatus.ACTIVE); List<ProfileFilter> inactive = generateFilter(null, null, group, 1, UpdateStatus.INACTIVE); List<ProfileFilter> actual = new ArrayList<>(); actual.addAll(active); actual.addAll(inactive); List<ProfileFilter> found = profileFilterDao.findActualByEndpointGroupId(group.getId().toString()); Assert.assertEquals(actual.size(), found.size()); Assert.assertEquals(actual, found); }
@Test public void findActualByEndpointGroupIdTest() { List<Configuration> configs = generateConfiguration(null, null, 4, UpdateStatus.DEPRECATED); Configuration first = configs.get(0); EndpointGroup group = first.getEndpointGroup(); List<Configuration> active = generateConfiguration(null, group, 1, UpdateStatus.ACTIVE); List<Configuration> inactive = generateConfiguration(null, group, 1, UpdateStatus.INACTIVE); List<Configuration> actual = new ArrayList<>(); actual.addAll(active); actual.addAll(inactive); List<Configuration> found = configurationDao.findActualByEndpointGroupId(group.getId().toString()); Assert.assertEquals(actual.size(), found.size()); Assert.assertEquals(actual, found); }
@Test public void findActiveByEndpointGroupIdTest() { List<Configuration> configs = generateConfiguration(null, null, 3, UpdateStatus.ACTIVE); Assert.assertEquals(3, configs.size()); Configuration first = configs.get(0); EndpointGroup group = first.getEndpointGroup(); List<Configuration> found = configurationDao.findActiveByEndpointGroupId(group.getId().toString()); Assert.assertEquals(3, found.size()); Assert.assertEquals(configs, found); }
@Test public void removeByEndpointGroupIdTest() { List<Configuration> configs = generateConfiguration(null, null, 3, UpdateStatus.ACTIVE); Assert.assertEquals(3, configs.size()); Long id = configs.get(0).getId(); EndpointGroup group = configs.get(0).getEndpointGroup(); configurationDao.removeByEndpointGroupId(group.getId().toString()); Configuration found = configurationDao.findById(id.toString()); Assert.assertNull(found); }
if (groupWithSameWeight != null && !groupWithSameWeight.getId().equals(previousGroup.getId())) { throw new IncorrectParameterException("Can't save endpoint group with same weight and" + " application id"); } else if (groupWithSameName != null && !groupWithSameName.getId().equals(previousGroup.getId())) { throw new IncorrectParameterException("Can't save endpoint group with same name and " + "application id");
@Test public void findConfigurationByEndpointGroupIdAndVersionTest() { List<Configuration> configs = generateConfiguration(null, null, 1, UpdateStatus.ACTIVE); Assert.assertEquals(1, configs.size()); Configuration first = configs.get(0); EndpointGroup group = first.getEndpointGroup(); Configuration found = configurationDao.findConfigurationByEndpointGroupIdAndVersion(group.getId().toString(), first.getSchemaVersion()); Assert.assertEquals(first, found); }
@Test public void findLatestActiveBySchemaIdAndGroupIdTest() { List<Configuration> configs = generateConfiguration(null, null, 1, UpdateStatus.ACTIVE); Assert.assertEquals(1, configs.size()); Configuration first = configs.get(0); EndpointGroup group = first.getEndpointGroup(); ConfigurationSchema schema = first.getConfigurationSchema(); Configuration found = configurationDao.findLatestActiveBySchemaIdAndGroupId(schema.getId().toString(), group.getId().toString()); Assert.assertEquals(first, found); }
@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); }
@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()); }
@Test public void findInactiveBySchemaIdAndGroupIdTest() { List<Configuration> configs = generateConfiguration(null, null, 1, UpdateStatus.ACTIVE); Assert.assertEquals(1, configs.size()); Configuration first = configs.get(0); EndpointGroup group = first.getEndpointGroup(); ConfigurationSchema schema = first.getConfigurationSchema(); List<Configuration> inactiveConfigs = generateConfiguration(schema, group, 1, UpdateStatus.INACTIVE); generateConfiguration(schema, group, 3, UpdateStatus.DEPRECATED); Configuration found = configurationDao.findInactiveBySchemaIdAndGroupId(schema.getId().toString(), group.getId().toString()); Assert.assertEquals(inactiveConfigs.get(0), found); }
@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 findActualBySchemaIdAndGroupIdTest() { List<Configuration> configs = generateConfiguration(null, null, 4, UpdateStatus.DEPRECATED); Configuration first = configs.get(0); EndpointGroup group = first.getEndpointGroup(); ConfigurationSchema schema = first.getConfigurationSchema(); List<Configuration> active = generateConfiguration(schema, group, 1, UpdateStatus.ACTIVE); generateConfiguration(null, group, 1, UpdateStatus.ACTIVE); List<Configuration> inactive = generateConfiguration(schema, group, 1, UpdateStatus.INACTIVE); List<Configuration> actual = new ArrayList<>(); actual.addAll(active); actual.addAll(inactive); List<Configuration> found = configurationDao.findActualBySchemaIdAndGroupId(schema.getId().toString(), group.getId().toString()); Assert.assertEquals(actual.size(), found.size()); Assert.assertEquals(actual, found); }
@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; }
@Override @Transactional public UpdateNotificationDto<EndpointGroupDto> addTopicToEndpointGroup(String id, String topicId) { validateSqlId(id, "Can't add topics " + topicId + " to endpoint group . Incorrect endpoint group id." + id); UpdateNotificationDto<EndpointGroupDto> dto = null; EndpointGroup endpointGroup = endpointGroupDao.addTopicToEndpointGroup(id, topicId); if (endpointGroup != null) { dto = new UpdateNotificationDto<>(); HistoryDto history = addHistory(endpointGroup.toDto(), ChangeType.ADD_TOPIC, topicId); if (history != null) { dto.setAppId(history.getApplicationId()); dto.setAppSeqNumber(history.getSequenceNumber()); } dto.setChangeType(ChangeType.ADD_TOPIC); dto.setTopicId(topicId); dto.setGroupId(endpointGroup.getId().toString()); dto.setPayload(endpointGroup.toDto()); } else { LOG.debug("Can't add topic [{}] to endpoint group [{}]", topicId, id); } return dto; }
@Test public void findLatestDeprecatedTest() { List<Configuration> configs = generateConfiguration(null, null, 10, UpdateStatus.DEPRECATED); Assert.assertEquals(10, configs.size()); Configuration first = configs.get(0); EndpointGroup group = first.getEndpointGroup(); ConfigurationSchema schema = first.getConfigurationSchema(); Configuration deprecated = configurationDao.findLatestDeprecated(schema.getId().toString(), group.getId().toString()); Assert.assertEquals(UpdateStatus.DEPRECATED, deprecated.getStatus()); Assert.assertEquals(9, deprecated.getSequenceNumber()); }
@Test public void deactivateOldConfigurationTest() { List<Configuration> configs = generateConfiguration(null, null, 1, UpdateStatus.ACTIVE); Assert.assertEquals(1, configs.size()); Configuration first = configs.get(0); ConfigurationSchema schema = first.getConfigurationSchema(); EndpointGroup group = first.getEndpointGroup(); Assert.assertEquals(UpdateStatus.ACTIVE, first.getStatus()); Configuration deactivated = configurationDao.deactivateOldConfiguration(schema.getId().toString(), group.getId().toString(), "Test user"); Configuration found = configurationDao.findById(first.getId().toString()); Assert.assertEquals(UpdateStatus.DEPRECATED, deactivated.getStatus()); Assert.assertEquals(deactivated, found); } }