private void validateFilter(ProfileFilterDto dto) { if (dto == null) { throw new IncorrectParameterException("Can't save profile filter. Incorrect object."); } if (dto.getEndpointProfileSchemaId() == null && dto.getServerProfileSchemaId() == null) { throw new IncorrectParameterException( "Profile Filter object invalid. Both schemas are empty."); } if (StringUtils.isBlank(dto.getEndpointGroupId())) { throw new IncorrectParameterException( "Profile Filter object invalid. Endpoint Group id invalid:" + dto.getEndpointGroupId()); } } }
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; }
@Override public HistoryDelta getDelta(EndpointProfileDto profile, String applicationToken, int curAppSeqNumber) { String endpointId = Base64Util.encode(profile); ConfigurationIdKey confIdKey = new ConfigurationIdKey( applicationToken, curAppSeqNumber, profile.getConfigurationVersion()); AppProfileVersionsKey appVersionsKey = new AppProfileVersionsKey( applicationToken, profile.getClientProfileVersion(), profile.getServerProfileVersion()); List<ProfileFilterDto> filters = filterService.getAllMatchingFilters(appVersionsKey, profile); LOG.debug("[{}] Found {} matching filters", endpointId, filters.size()); List<EndpointGroupStateDto> result = new ArrayList<>(1 + filters.size()); EndpointGroupDto groupDto = cacheService.getDefaultGroup(applicationToken); EndpointGroupStateDto groupAllState = new EndpointGroupStateDto(); groupAllState.setEndpointGroupId(groupDto.getId()); groupAllState.setConfigurationId(cacheService.getConfIdByKey( confIdKey.copyWithNewEgId(groupDto.getId()))); result.add(groupAllState); for (ProfileFilterDto filter : filters) { String confId = cacheService.getConfIdByKey( confIdKey.copyWithNewEgId(filter.getEndpointGroupId())); EndpointGroupStateDto endpointGroupState = new EndpointGroupStateDto(); endpointGroupState.setEndpointGroupId(filter.getEndpointGroupId()); endpointGroupState.setProfileFilterId(filter.getId()); endpointGroupState.setConfigurationId(confId); result.add(endpointGroupState); } return new HistoryDelta(result, true, true, true); }
private HistoryDto addHistory(ProfileFilterDto dto, ChangeType type) { LOG.debug("Add history information about profile filter update with change type {} ", type); HistoryDto history = new HistoryDto(); history.setApplicationId(dto.getApplicationId()); ChangeDto change = new ChangeDto(); change.setProfileFilterId(dto.getId()); change.setProfileFilterId(dto.getId()); change.setEndpointGroupId(dto.getEndpointGroupId()); change.setType(type); history.setChange(change); return historyService.saveHistory(history); }
@Override public ProfileFilterDto activateProfileFilter(String profileFilterId) throws KaaAdminServiceException { checkAuthority(KaaAuthorityDto.TENANT_DEVELOPER, KaaAuthorityDto.TENANT_USER); try { ProfileFilterDto storedProfileFilter = controlService.getProfileFilter(profileFilterId); Utils.checkNotNull(storedProfileFilter); checkEndpointGroupId(storedProfileFilter.getEndpointGroupId()); String username = getCurrentUser().getUsername(); return controlService.activateProfileFilter(profileFilterId, username); } catch (Exception ex) { throw Utils.handleException(ex); } }
@Override public ProfileFilterDto deactivateProfileFilter(String profileFilterId) throws KaaAdminServiceException { checkAuthority(KaaAuthorityDto.TENANT_DEVELOPER, KaaAuthorityDto.TENANT_USER); try { ProfileFilterDto storedProfileFilter = controlService.getProfileFilter(profileFilterId); Utils.checkNotNull(storedProfileFilter); checkEndpointGroupId(storedProfileFilter.getEndpointGroupId()); String username = getCurrentUser().getUsername(); return controlService.deactivateProfileFilter(profileFilterId, username); } catch (Exception ex) { throw Utils.handleException(ex); } }
@Override public ProfileFilterDto editProfileFilter(ProfileFilterDto profileFilter) throws KaaAdminServiceException { checkAuthority(KaaAuthorityDto.TENANT_DEVELOPER, KaaAuthorityDto.TENANT_USER); try { String username = getCurrentUser().getUsername(); if (isEmpty(profileFilter.getId())) { profileFilter.setCreatedUsername(username); checkEndpointGroupId(profileFilter.getEndpointGroupId()); } else { profileFilter.setModifiedUsername(username); ProfileFilterDto storedProfileFilter = controlService.getProfileFilter( profileFilter.getId()); Utils.checkNotNull(storedProfileFilter); checkEndpointGroupId(storedProfileFilter.getEndpointGroupId()); } validateProfileFilterBody(profileFilter.getEndpointProfileSchemaId(), profileFilter.getServerProfileSchemaId(), profileFilter.getBody()); return controlService.editProfileFilter(profileFilter); } catch (Exception ex) { throw Utils.handleException(ex); } }
String endProfSchemaId = profileFilterDto.getEndpointProfileSchemaId(); String srvProfSchemaId = profileFilterDto.getServerProfileSchemaId(); String groupId = profileFilterDto.getEndpointGroupId(); EndpointGroup group = endpointGroupDao.findById(groupId); if (group.getWeight() == 0) {
@Test public void saveFiltersWithDiferentGroupsTest() { ApplicationDto application = generateApplicationDto(null); EndpointGroupDto groupDto = generateEndpointGroupDto(application.getId()); EndpointGroupDto groupDto2 = generateEndpointGroupDto(application.getId(), "OTHER_GROUP"); EndpointProfileSchemaDto schema = generateProfSchemaDto(application.getTenantId(), application.getId(), 1).get(0); ServerProfileSchemaDto serverSchema = generateServerProfileSchema(application.getId(), application.getTenantId()); ProfileFilterDto filterDto = generateFilterDto(schema.getId(), serverSchema.getId(), groupDto.getId(), 1, false).get(0); Assert.assertNotNull(filterDto); filterDto.setId(null); filterDto.setEndpointGroupId(groupDto.getId()); ProfileFilterDto savedOne = profileService.saveProfileFilter(filterDto); Assert.assertNotNull(savedOne); ChangeProfileFilterNotification activeOne = profileService.activateProfileFilter(savedOne.getId(), null); Assert.assertNotNull(activeOne); filterDto.setId(null); filterDto.setEndpointGroupId(groupDto2.getId()); ProfileFilterDto savedTwo = profileService.saveProfileFilter(filterDto); Assert.assertNotNull(savedTwo); ChangeProfileFilterNotification activeTwo = profileService.activateProfileFilter(savedTwo.getId(), null); Assert.assertNotNull(activeTwo); List<ProfileFilterDto> activeList = profileService.findProfileFiltersByAppIdAndVersionsCombination(application.getId(), schema.getVersion(), serverSchema.getVersion()); Assert.assertFalse(activeList.isEmpty()); Set<String> groupIds = new HashSet<>(); for (ProfileFilterDto dto : activeList) { Assert.assertEquals(dto.getStatus(), UpdateStatus.ACTIVE); groupIds.add(dto.getEndpointGroupId()); } Assert.assertEquals(2, groupIds.size()); }