@Test public void getJobByIdTest() throws Exception { UUID jobId = UUID.randomUUID(); ConfigGroupEntity configGroupEntity = new ConfigGroupEntity(1L, jobId); DescriptorConfigEntity descriptorConfigEntity = new DescriptorConfigEntity(2L, 2L, DateUtils.createCurrentDateTimestamp(), DateUtils.createCurrentDateTimestamp()); descriptorConfigEntity.setId(3L); ConfigContextEntity configContextEntity = new ConfigContextEntity(configContextEnum.name()); FieldValueEntity fieldValueEntity = new FieldValueEntity(3L, 4L, fieldValue); DefinedFieldEntity definedFieldEntity = new DefinedFieldEntity(fieldKey, false); definedFieldEntity.setId(4L); Mockito.when(configGroupRepository.findByJobId(Mockito.any())).thenReturn(List.of(configGroupEntity)); setupGetJobMocks(descriptorConfigEntity, configContextEntity, fieldValueEntity, definedFieldEntity); DefaultConfigurationAccessor configurationAccessor = new DefaultConfigurationAccessor(null, null, definedFieldRepository, descriptorConfigRepository, configGroupRepository, configContextRepository, fieldValueRepository, encryptionUtility); Optional<ConfigurationJobModel> configurationJobModelOptional = configurationAccessor.getJobById(jobId); assertTrue(configurationJobModelOptional.isPresent()); ConfigurationJobModel configurationJobModel = configurationJobModelOptional.get(); assertEquals(jobId, configurationJobModel.getJobId()); assertEquals(fieldValue, configurationJobModel.getName()); }
@Override public Optional<ConfigurationJobModel> getJobById(UUID jobId) throws AlertDatabaseConstraintException { if (jobId == null) { throw new AlertDatabaseConstraintException(NULL_JOB_ID); } List<ConfigGroupEntity> jobConfigEntities = configGroupRepository.findByJobId(jobId); return jobConfigEntities .stream() .findAny() .map(configGroupEntity -> createJobModelFromExistingConfigs(configGroupEntity.getJobId(), jobConfigEntities)); }
DefaultConfigurationAccessor implements ConfigurationAccessor { @Override public Optional<ConfigurationJobModel> getJobById(UUID jobId) throws AlertDatabaseConstraintException { if (jobId == null) { throw new AlertDatabaseConstraintException(NULL_JOB_ID); } List<ConfigGroupEntity> jobConfigEntities = configGroupRepository.findByJobId(jobId); return jobConfigEntities .stream() .findAny() .map(configGroupEntity -> createJobModelFromExistingConfigs(configGroupEntity.getJobId(), jobConfigEntities)); } }
DefaultConfigurationAccessor implements ConfigurationAccessor { @Override public Optional<ConfigurationJobModel> getJobById(UUID jobId) throws AlertDatabaseConstraintException { if (jobId == null) { throw new AlertDatabaseConstraintException(NULL_JOB_ID); } List<ConfigGroupEntity> jobConfigEntities = configGroupRepository.findByJobId(jobId); return jobConfigEntities .stream() .findAny() .map(configGroupEntity -> createJobModelFromExistingConfigs(configGroupEntity.getJobId(), jobConfigEntities)); } @Autowired  DefaultConfigurationAccessor(RegisteredDescriptorRepository registeredDescriptorRepository, DescriptorTypeRepository descriptorTypeRepository, DefinedFieldRepository definedFieldRepository,
        DescriptorConfigRepository descriptorConfigsRepository, ConfigGroupRepository configGroupRepository, ConfigContextRepository configContextRepository, FieldValueRepository fieldValueRepository,
        EncryptionUtility encryptionUtility); }
DefaultConfigurationAccessor implements ConfigurationAccessor { @Override public Optional<ConfigurationJobModel> getJobById(UUID jobId) throws AlertDatabaseConstraintException { if (jobId == null) { throw new AlertDatabaseConstraintException(NULL_JOB_ID); } List<ConfigGroupEntity> jobConfigEntities = configGroupRepository.findByJobId(jobId); return jobConfigEntities .stream() .findAny() .map(configGroupEntity -> createJobModelFromExistingConfigs(configGroupEntity.getJobId(), jobConfigEntities)); } @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<ConfigurationJobModel> getJobById(UUID jobId) throws AlertDatabaseConstraintException { if (jobId == null) { throw new AlertDatabaseConstraintException(NULL_JOB_ID); } List<ConfigGroupEntity> jobConfigEntities = configGroupRepository.findByJobId(jobId); return jobConfigEntities .stream() .findAny() .map(configGroupEntity -> createJobModelFromExistingConfigs(configGroupEntity.getJobId(), jobConfigEntities)); } @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; }