@Test public void getChannelConfigurationsByFrequencyTest() throws Exception { final Long descriptorId = 3L; final Long configurationId = 5L; FrequencyType frequencyType = FrequencyType.DAILY; DescriptorTypeEntity descriptorTypeEntity = new DescriptorTypeEntity("CHANNEL"); descriptorTypeEntity.setId(1L); RegisteredDescriptorEntity registeredDescriptorEntity = new RegisteredDescriptorEntity("name-test", 1L); registeredDescriptorEntity.setId(2L); DescriptorConfigEntity descriptorConfigEntity = new DescriptorConfigEntity(descriptorId, 4L, DateUtils.createCurrentDateTimestamp(), DateUtils.createCurrentDateTimestamp()); descriptorConfigEntity.setId(configurationId); ConfigContextEntity configContextEntity = new ConfigContextEntity(configContextEnum.name()); FieldValueEntity fieldValueEntity = new FieldValueEntity(6L, 7L, fieldValue); DefinedFieldEntity definedFieldEntity = new DefinedFieldEntity(fieldKey, false); definedFieldEntity.setId(8L); Mockito.when(descriptorTypeRepository.findFirstByType(Mockito.any())).thenReturn(Optional.of(descriptorTypeEntity)); Mockito.when(registeredDescriptorRepository.findByTypeIdAndFrequency(Mockito.any(), Mockito.any())).thenReturn(List.of(registeredDescriptorEntity)); setupCreatConfigMocks(descriptorConfigEntity, configContextEntity, fieldValueEntity, definedFieldEntity); DefaultConfigurationAccessor configurationAccessor = new DefaultConfigurationAccessor(registeredDescriptorRepository, descriptorTypeRepository, definedFieldRepository, descriptorConfigRepository, null, configContextRepository, fieldValueRepository, encryptionUtility); List<ConfigurationModel> configurationModelList = configurationAccessor.getChannelConfigurationsByFrequency(frequencyType); assertEquals(1, configurationModelList.size()); ConfigurationModel configurationModel = configurationModelList.get(0); testConfigurationModel(configurationId, descriptorId, configurationModel); }
@Override public List<ConfigurationModel> getChannelConfigurationsByFrequency(FrequencyType frequencyType) throws AlertDatabaseConstraintException { if (null == frequencyType) { throw new AlertDatabaseConstraintException("Frequency type cannot be null"); } Long typeId = descriptorTypeRepository .findFirstByType(DescriptorType.CHANNEL.name()) .map(DatabaseEntity::getId) .orElseThrow(() -> new AlertDatabaseConstraintException("Descriptor type has not been registered")); List<RegisteredDescriptorEntity> registeredDescriptorEntities = registeredDescriptorRepository.findByTypeIdAndFrequency(typeId, frequencyType.name()); return createConfigModels(registeredDescriptorEntities); }
DefaultConfigurationAccessor implements ConfigurationAccessor { @Override public List<ConfigurationModel> getChannelConfigurationsByFrequency(FrequencyType frequencyType) throws AlertDatabaseConstraintException { if (null == frequencyType) { throw new AlertDatabaseConstraintException("Frequency type cannot be null"); } Long typeId = descriptorTypeRepository .findFirstByType(DescriptorType.CHANNEL.name()) .map(DatabaseEntity::getId) .orElseThrow(() -> new AlertDatabaseConstraintException("Descriptor type has not been registered")); List<RegisteredDescriptorEntity> registeredDescriptorEntities = registeredDescriptorRepository.findByTypeIdAndFrequency(typeId, frequencyType.name()); return createConfigModels(registeredDescriptorEntities); } }
DefaultConfigurationAccessor implements ConfigurationAccessor { @Override public List<ConfigurationModel> getChannelConfigurationsByFrequency(FrequencyType frequencyType) throws AlertDatabaseConstraintException { if (null == frequencyType) { throw new AlertDatabaseConstraintException("Frequency type cannot be null"); } Long typeId = descriptorTypeRepository .findFirstByType(DescriptorType.CHANNEL.name()) .map(DatabaseEntity::getId) .orElseThrow(() -> new AlertDatabaseConstraintException("Descriptor type has not been registered")); List<RegisteredDescriptorEntity> registeredDescriptorEntities = registeredDescriptorRepository.findByTypeIdAndFrequency(typeId, frequencyType.name()); return createConfigModels(registeredDescriptorEntities); } @Autowired  DefaultConfigurationAccessor(RegisteredDescriptorRepository registeredDescriptorRepository, DescriptorTypeRepository descriptorTypeRepository, DefinedFieldRepository definedFieldRepository,
        DescriptorConfigRepository descriptorConfigsRepository, ConfigGroupRepository configGroupRepository, ConfigContextRepository configContextRepository, FieldValueRepository fieldValueRepository,
        EncryptionUtility encryptionUtility); }
DefaultConfigurationAccessor implements ConfigurationAccessor { @Override public List<ConfigurationModel> getChannelConfigurationsByFrequency(FrequencyType frequencyType) throws AlertDatabaseConstraintException { if (null == frequencyType) { throw new AlertDatabaseConstraintException("Frequency type cannot be null"); } Long typeId = descriptorTypeRepository .findFirstByType(DescriptorType.CHANNEL.name()) .map(DatabaseEntity::getId) .orElseThrow(() -> new AlertDatabaseConstraintException("Descriptor type has not been registered")); List<RegisteredDescriptorEntity> registeredDescriptorEntities = registeredDescriptorRepository.findByTypeIdAndFrequency(typeId, frequencyType.name()); return createConfigModels(registeredDescriptorEntities); } @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 List<ConfigurationModel> getChannelConfigurationsByFrequency(FrequencyType frequencyType) throws AlertDatabaseConstraintException { if (null == frequencyType) { throw new AlertDatabaseConstraintException("Frequency type cannot be null"); } Long typeId = descriptorTypeRepository .findFirstByType(DescriptorType.CHANNEL.name()) .map(DatabaseEntity::getId) .orElseThrow(() -> new AlertDatabaseConstraintException("Descriptor type has not been registered")); List<RegisteredDescriptorEntity> registeredDescriptorEntities = registeredDescriptorRepository.findByTypeIdAndFrequency(typeId, frequencyType.name()); return createConfigModels(registeredDescriptorEntities); } @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; }