@Test public void getProviderConfigurationByNameBlankTest() throws Exception { DefaultConfigurationAccessor configurationAccessor = new DefaultConfigurationAccessor(null, null, null, null, null, null, null, null); try { configurationAccessor.getProviderConfigurationByName(""); fail("Blank providerConfigName did not throw expected AlertDatabaseConstraintException."); } catch (AlertDatabaseConstraintException e) { assertNotNull(e); } }
@Override public Optional<ConfigurationModel> getProviderConfigurationByName(String providerConfigName) throws AlertDatabaseConstraintException { if (StringUtils.isBlank(providerConfigName)) { throw new AlertDatabaseConstraintException("The provider configuration name cannot be null"); } Long fieldId = definedFieldRepository.findFirstByKey(ProviderDescriptor.KEY_PROVIDER_CONFIG_NAME) .map(DefinedFieldEntity::getId) .orElseThrow(() -> new AlertDatabaseConstraintException(String.format("The key '%s' is not registered in the database", ProviderDescriptor.KEY_PROVIDER_CONFIG_NAME))); List<Long> providerConfigIds = fieldValueRepository.findAllByFieldIdAndValue(fieldId, providerConfigName) .stream() .map(FieldValueEntity::getConfigId) .collect(Collectors.toList()); if (!providerConfigIds.isEmpty()) { for (Long configId : providerConfigIds) { Optional<ConfigurationModel> globalModel = getConfigurationById(configId) .filter(model -> model.getDescriptorContext() == ConfigContextEnum.GLOBAL); if (globalModel.isPresent()) { return globalModel; } } } return Optional.empty(); }
DefaultConfigurationAccessor implements ConfigurationAccessor { @Override public Optional<ConfigurationModel> getProviderConfigurationByName(String providerConfigName) throws AlertDatabaseConstraintException { if (StringUtils.isBlank(providerConfigName)) { throw new AlertDatabaseConstraintException("The provider configuration name cannot be null"); } Long fieldId = definedFieldRepository.findFirstByKey(ProviderDescriptor.KEY_PROVIDER_CONFIG_NAME) .map(DefinedFieldEntity::getId) .orElseThrow(() -> new AlertDatabaseConstraintException(String.format("The key '%s' is not registered in the database", ProviderDescriptor.KEY_PROVIDER_CONFIG_NAME))); List<Long> providerConfigIds = fieldValueRepository.findAllByFieldIdAndValue(fieldId, providerConfigName) .stream() .map(FieldValueEntity::getConfigId) .collect(Collectors.toList()); if (!providerConfigIds.isEmpty()) { for (Long configId : providerConfigIds) { Optional<ConfigurationModel> globalModel = getConfigurationById(configId) .filter(model -> model.getDescriptorContext() == ConfigContextEnum.GLOBAL); if (globalModel.isPresent()) { return globalModel; } } } return Optional.empty(); } }
DefaultConfigurationAccessor implements ConfigurationAccessor { @Override public Optional<ConfigurationModel> getProviderConfigurationByName(String providerConfigName) throws AlertDatabaseConstraintException { if (StringUtils.isBlank(providerConfigName)) { throw new AlertDatabaseConstraintException("The provider configuration name cannot be null"); } Long fieldId = definedFieldRepository.findFirstByKey(ProviderDescriptor.KEY_PROVIDER_CONFIG_NAME) .map(DefinedFieldEntity::getId) .orElseThrow(() -> new AlertDatabaseConstraintException(String.format("The key '%s' is not registered in the database", ProviderDescriptor.KEY_PROVIDER_CONFIG_NAME))); List<Long> providerConfigIds = fieldValueRepository.findAllByFieldIdAndValue(fieldId, providerConfigName) .stream() .map(FieldValueEntity::getConfigId) .collect(Collectors.toList()); if (!providerConfigIds.isEmpty()) { for (Long configId : providerConfigIds) { Optional<ConfigurationModel> globalModel = getConfigurationById(configId) .filter(model -> model.getDescriptorContext() == ConfigContextEnum.GLOBAL); if (globalModel.isPresent()) { return globalModel; } } } return Optional.empty(); } @Autowired  DefaultConfigurationAccessor(RegisteredDescriptorRepository registeredDescriptorRepository, DescriptorTypeRepository descriptorTypeRepository, DefinedFieldRepository definedFieldRepository,
        DescriptorConfigRepository descriptorConfigsRepository, ConfigGroupRepository configGroupRepository, ConfigContextRepository configContextRepository, FieldValueRepository fieldValueRepository,
        EncryptionUtility encryptionUtility); }
DefaultConfigurationAccessor implements ConfigurationAccessor { @Override public Optional<ConfigurationModel> getProviderConfigurationByName(String providerConfigName) throws AlertDatabaseConstraintException { if (StringUtils.isBlank(providerConfigName)) { throw new AlertDatabaseConstraintException("The provider configuration name cannot be null"); } Long fieldId = definedFieldRepository.findFirstByKey(ProviderDescriptor.KEY_PROVIDER_CONFIG_NAME) .map(DefinedFieldEntity::getId) .orElseThrow(() -> new AlertDatabaseConstraintException(String.format("The key '%s' is not registered in the database", ProviderDescriptor.KEY_PROVIDER_CONFIG_NAME))); List<Long> providerConfigIds = fieldValueRepository.findAllByFieldIdAndValue(fieldId, providerConfigName) .stream() .map(FieldValueEntity::getConfigId) .collect(Collectors.toList()); if (!providerConfigIds.isEmpty()) { for (Long configId : providerConfigIds) { Optional<ConfigurationModel> globalModel = getConfigurationById(configId) .filter(model -> model.getDescriptorContext() == ConfigContextEnum.GLOBAL); if (globalModel.isPresent()) { return globalModel; } } } return Optional.empty(); } @Autowired  DefaultConfigurationAccessor(RegisteredDescriptorRepository registeredDescriptorRepository, DescriptorTypeRepository descriptorTypeRepository, DefinedFieldRepository definedFieldRepository,
        DescriptorConfigRepository descriptorConfigsRepository, ConfigGroupRepository configGroupRepository, ConfigContextRepository configContextRepository, FieldValueRepository fieldValueRepository,
        EncryptionUtility encryptionUtility); @Override List<ConfigurationJobModel> getAllJobs(); @Override Optional<ConfigurationJobModel> getJobById(UUID jobId); @Override List<ConfigurationJobModel> getJobsByFrequency(FrequencyType frequency); @Override ConfigurationJobModel createJob(Collection<String> descriptorNames, Collection<ConfigurationFieldModel> configuredFields); @Override ConfigurationJobModel updateJob(UUID jobId, Collection<String> descriptorNames, Collection<ConfigurationFieldModel> configuredFields); @Override void deleteJob(UUID jobId); @Override Optional<ConfigurationModel> getProviderConfigurationByName(String providerConfigName); @Override Optional<ConfigurationModel> getConfigurationById(Long id); @Override List<ConfigurationModel> getConfigurationsByDescriptorKey(DescriptorKey descriptorKey); @Override List<ConfigurationModel> getConfigurationsByDescriptorType(DescriptorType descriptorType); @Override List<ConfigurationModel> getChannelConfigurationsByFrequency(FrequencyType frequencyType); @Override List<ConfigurationModel> getConfigurationsByDescriptorKeyAndContext(DescriptorKey descriptorKey, ConfigContextEnum context); @Override ConfigurationModel createConfiguration(DescriptorKey descriptorKey, ConfigContextEnum context, Collection<ConfigurationFieldModel> configuredFields); @Override List<ConfigurationModel> getConfigurationsByDescriptorNameAndContext(String descriptorName, ConfigContextEnum context); @Override ConfigurationModel updateConfiguration(Long descriptorConfigId, Collection<ConfigurationFieldModel> configuredFields); @Override void deleteConfiguration(ConfigurationModel configModel); @Override void deleteConfiguration(Long descriptorConfigId); }
DefaultConfigurationAccessor implements ConfigurationAccessor { @Override public Optional<ConfigurationModel> getProviderConfigurationByName(String providerConfigName) throws AlertDatabaseConstraintException { if (StringUtils.isBlank(providerConfigName)) { throw new AlertDatabaseConstraintException("The provider configuration name cannot be null"); } Long fieldId = definedFieldRepository.findFirstByKey(ProviderDescriptor.KEY_PROVIDER_CONFIG_NAME) .map(DefinedFieldEntity::getId) .orElseThrow(() -> new AlertDatabaseConstraintException(String.format("The key '%s' is not registered in the database", ProviderDescriptor.KEY_PROVIDER_CONFIG_NAME))); List<Long> providerConfigIds = fieldValueRepository.findAllByFieldIdAndValue(fieldId, providerConfigName) .stream() .map(FieldValueEntity::getConfigId) .collect(Collectors.toList()); if (!providerConfigIds.isEmpty()) { for (Long configId : providerConfigIds) { Optional<ConfigurationModel> globalModel = getConfigurationById(configId) .filter(model -> model.getDescriptorContext() == ConfigContextEnum.GLOBAL); if (globalModel.isPresent()) { return globalModel; } } } return Optional.empty(); } @Autowired  DefaultConfigurationAccessor(RegisteredDescriptorRepository registeredDescriptorRepository, DescriptorTypeRepository descriptorTypeRepository, DefinedFieldRepository definedFieldRepository,
        DescriptorConfigRepository descriptorConfigsRepository, ConfigGroupRepository configGroupRepository, ConfigContextRepository configContextRepository, FieldValueRepository fieldValueRepository,
        EncryptionUtility encryptionUtility); @Override List<ConfigurationJobModel> getAllJobs(); @Override Optional<ConfigurationJobModel> getJobById(UUID jobId); @Override List<ConfigurationJobModel> getJobsByFrequency(FrequencyType frequency); @Override ConfigurationJobModel createJob(Collection<String> descriptorNames, Collection<ConfigurationFieldModel> configuredFields); @Override ConfigurationJobModel updateJob(UUID jobId, Collection<String> descriptorNames, Collection<ConfigurationFieldModel> configuredFields); @Override void deleteJob(UUID jobId); @Override Optional<ConfigurationModel> getProviderConfigurationByName(String providerConfigName); @Override Optional<ConfigurationModel> getConfigurationById(Long id); @Override List<ConfigurationModel> getConfigurationsByDescriptorKey(DescriptorKey descriptorKey); @Override List<ConfigurationModel> getConfigurationsByDescriptorType(DescriptorType descriptorType); @Override List<ConfigurationModel> getChannelConfigurationsByFrequency(FrequencyType frequencyType); @Override List<ConfigurationModel> getConfigurationsByDescriptorKeyAndContext(DescriptorKey descriptorKey, ConfigContextEnum context); @Override ConfigurationModel createConfiguration(DescriptorKey descriptorKey, ConfigContextEnum context, Collection<ConfigurationFieldModel> configuredFields); @Override List<ConfigurationModel> getConfigurationsByDescriptorNameAndContext(String descriptorName, ConfigContextEnum context); @Override ConfigurationModel updateConfiguration(Long descriptorConfigId, Collection<ConfigurationFieldModel> configuredFields); @Override void deleteConfiguration(ConfigurationModel configModel); @Override void deleteConfiguration(Long descriptorConfigId); static final String EXCEPTION_FORMAT_DESCRIPTOR_KEY_IS_NOT_VALID; }