@Test public void updateConfigurationNullTest() throws Exception { DefaultConfigurationAccessor configurationAccessor = new DefaultConfigurationAccessor(null, null, null, null, null, null, null, null); try { configurationAccessor.updateConfiguration(null, null); fail("Null descriptorConfigId and configuredFields did not throw expected AlertDatabaseConstraintException."); } catch (AlertDatabaseConstraintException e) { assertNotNull(e); } }
@Override public ConfigurationModel updateConfiguration(Long descriptorConfigId, Collection<ConfigurationFieldModel> configuredFields) throws AlertDatabaseConstraintException { if (descriptorConfigId == null) { throw new AlertDatabaseConstraintException(NULL_CONFIG_ID); } DescriptorConfigEntity descriptorConfigEntity = descriptorConfigsRepository .findById(descriptorConfigId) .orElseThrow(() -> new AlertDatabaseConstraintException("A config with that id did not exist")); List<FieldValueEntity> oldValues = fieldValueRepository.findByConfigId(descriptorConfigId); fieldValueRepository.deleteAll(oldValues); fieldValueRepository.flush(); ConfigurationModelMutable updatedConfig = createEmptyConfigModel(descriptorConfigEntity.getDescriptorId(), descriptorConfigEntity.getId(), descriptorConfigEntity.getCreatedAt(), descriptorConfigEntity.getLastUpdated(), descriptorConfigEntity.getContextId()); if (configuredFields != null && !configuredFields.isEmpty()) { List<FieldValueEntity> fieldValuesToSave = new ArrayList<>(configuredFields.size()); for (ConfigurationFieldModel configFieldModel : configuredFields) { String fieldKey = configFieldModel.getFieldKey(); Long fieldId = getFieldIdOrThrowException(fieldKey); boolean isSensitive = isFieldSensitive(fieldKey); for (String value : configFieldModel.getFieldValues()) { FieldValueEntity newFieldValue = new FieldValueEntity(descriptorConfigId, fieldId, encrypt(value, isSensitive)); fieldValuesToSave.add(newFieldValue); } updatedConfig.put(configFieldModel); } fieldValueRepository.saveAll(fieldValuesToSave); fieldValueRepository.flush(); } descriptorConfigEntity.setLastUpdated(DateUtils.createCurrentDateTimestamp()); descriptorConfigsRepository.save(descriptorConfigEntity); return updatedConfig; }
DefaultConfigurationAccessor implements ConfigurationAccessor { @Override public ConfigurationModel updateConfiguration(Long descriptorConfigId, Collection<ConfigurationFieldModel> configuredFields) throws AlertDatabaseConstraintException { if (descriptorConfigId == null) { throw new AlertDatabaseConstraintException(NULL_CONFIG_ID); } DescriptorConfigEntity descriptorConfigEntity = descriptorConfigsRepository .findById(descriptorConfigId) .orElseThrow(() -> new AlertDatabaseConstraintException("A config with that id did not exist")); List<FieldValueEntity> oldValues = fieldValueRepository.findByConfigId(descriptorConfigId); fieldValueRepository.deleteAll(oldValues); fieldValueRepository.flush(); ConfigurationModelMutable updatedConfig = createEmptyConfigModel(descriptorConfigEntity.getDescriptorId(), descriptorConfigEntity.getId(), descriptorConfigEntity.getCreatedAt(), descriptorConfigEntity.getLastUpdated(), descriptorConfigEntity.getContextId()); if (configuredFields != null && !configuredFields.isEmpty()) { List<FieldValueEntity> fieldValuesToSave = new ArrayList<>(configuredFields.size()); for (ConfigurationFieldModel configFieldModel : configuredFields) { String fieldKey = configFieldModel.getFieldKey(); Long fieldId = getFieldIdOrThrowException(fieldKey); boolean isSensitive = isFieldSensitive(fieldKey); for (String value : configFieldModel.getFieldValues()) { FieldValueEntity newFieldValue = new FieldValueEntity(descriptorConfigId, fieldId, encrypt(value, isSensitive)); fieldValuesToSave.add(newFieldValue); } updatedConfig.put(configFieldModel); } fieldValueRepository.saveAll(fieldValuesToSave); fieldValueRepository.flush(); } descriptorConfigEntity.setLastUpdated(DateUtils.createCurrentDateTimestamp()); descriptorConfigsRepository.save(descriptorConfigEntity); return updatedConfig; } }
DefaultConfigurationAccessor implements ConfigurationAccessor { @Override public ConfigurationModel updateConfiguration(Long descriptorConfigId, Collection<ConfigurationFieldModel> configuredFields) throws AlertDatabaseConstraintException { if (descriptorConfigId == null) { throw new AlertDatabaseConstraintException(NULL_CONFIG_ID); } DescriptorConfigEntity descriptorConfigEntity = descriptorConfigsRepository .findById(descriptorConfigId) .orElseThrow(() -> new AlertDatabaseConstraintException("A config with that id did not exist")); List<FieldValueEntity> oldValues = fieldValueRepository.findByConfigId(descriptorConfigId); fieldValueRepository.deleteAll(oldValues); fieldValueRepository.flush(); ConfigurationModelMutable updatedConfig = createEmptyConfigModel(descriptorConfigEntity.getDescriptorId(), descriptorConfigEntity.getId(), descriptorConfigEntity.getCreatedAt(), descriptorConfigEntity.getLastUpdated(), descriptorConfigEntity.getContextId()); if (configuredFields != null && !configuredFields.isEmpty()) { List<FieldValueEntity> fieldValuesToSave = new ArrayList<>(configuredFields.size()); for (ConfigurationFieldModel configFieldModel : configuredFields) { String fieldKey = configFieldModel.getFieldKey(); Long fieldId = getFieldIdOrThrowException(fieldKey); boolean isSensitive = isFieldSensitive(fieldKey); for (String value : configFieldModel.getFieldValues()) { FieldValueEntity newFieldValue = new FieldValueEntity(descriptorConfigId, fieldId, encrypt(value, isSensitive)); fieldValuesToSave.add(newFieldValue); } updatedConfig.put(configFieldModel); } fieldValueRepository.saveAll(fieldValuesToSave); fieldValueRepository.flush(); } descriptorConfigEntity.setLastUpdated(DateUtils.createCurrentDateTimestamp()); descriptorConfigsRepository.save(descriptorConfigEntity); return updatedConfig; } @Autowired  DefaultConfigurationAccessor(RegisteredDescriptorRepository registeredDescriptorRepository, DescriptorTypeRepository descriptorTypeRepository, DefinedFieldRepository definedFieldRepository,
        DescriptorConfigRepository descriptorConfigsRepository, ConfigGroupRepository configGroupRepository, ConfigContextRepository configContextRepository, FieldValueRepository fieldValueRepository,
        EncryptionUtility encryptionUtility); }
DefaultConfigurationAccessor implements ConfigurationAccessor { @Override public ConfigurationModel updateConfiguration(Long descriptorConfigId, Collection<ConfigurationFieldModel> configuredFields) throws AlertDatabaseConstraintException { if (descriptorConfigId == null) { throw new AlertDatabaseConstraintException(NULL_CONFIG_ID); } DescriptorConfigEntity descriptorConfigEntity = descriptorConfigsRepository .findById(descriptorConfigId) .orElseThrow(() -> new AlertDatabaseConstraintException("A config with that id did not exist")); List<FieldValueEntity> oldValues = fieldValueRepository.findByConfigId(descriptorConfigId); fieldValueRepository.deleteAll(oldValues); fieldValueRepository.flush(); ConfigurationModelMutable updatedConfig = createEmptyConfigModel(descriptorConfigEntity.getDescriptorId(), descriptorConfigEntity.getId(), descriptorConfigEntity.getCreatedAt(), descriptorConfigEntity.getLastUpdated(), descriptorConfigEntity.getContextId()); if (configuredFields != null && !configuredFields.isEmpty()) { List<FieldValueEntity> fieldValuesToSave = new ArrayList<>(configuredFields.size()); for (ConfigurationFieldModel configFieldModel : configuredFields) { String fieldKey = configFieldModel.getFieldKey(); Long fieldId = getFieldIdOrThrowException(fieldKey); boolean isSensitive = isFieldSensitive(fieldKey); for (String value : configFieldModel.getFieldValues()) { FieldValueEntity newFieldValue = new FieldValueEntity(descriptorConfigId, fieldId, encrypt(value, isSensitive)); fieldValuesToSave.add(newFieldValue); } updatedConfig.put(configFieldModel); } fieldValueRepository.saveAll(fieldValuesToSave); fieldValueRepository.flush(); } descriptorConfigEntity.setLastUpdated(DateUtils.createCurrentDateTimestamp()); descriptorConfigsRepository.save(descriptorConfigEntity); return updatedConfig; } @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 ConfigurationModel updateConfiguration(Long descriptorConfigId, Collection<ConfigurationFieldModel> configuredFields) throws AlertDatabaseConstraintException { if (descriptorConfigId == null) { throw new AlertDatabaseConstraintException(NULL_CONFIG_ID); } DescriptorConfigEntity descriptorConfigEntity = descriptorConfigsRepository .findById(descriptorConfigId) .orElseThrow(() -> new AlertDatabaseConstraintException("A config with that id did not exist")); List<FieldValueEntity> oldValues = fieldValueRepository.findByConfigId(descriptorConfigId); fieldValueRepository.deleteAll(oldValues); fieldValueRepository.flush(); ConfigurationModelMutable updatedConfig = createEmptyConfigModel(descriptorConfigEntity.getDescriptorId(), descriptorConfigEntity.getId(), descriptorConfigEntity.getCreatedAt(), descriptorConfigEntity.getLastUpdated(), descriptorConfigEntity.getContextId()); if (configuredFields != null && !configuredFields.isEmpty()) { List<FieldValueEntity> fieldValuesToSave = new ArrayList<>(configuredFields.size()); for (ConfigurationFieldModel configFieldModel : configuredFields) { String fieldKey = configFieldModel.getFieldKey(); Long fieldId = getFieldIdOrThrowException(fieldKey); boolean isSensitive = isFieldSensitive(fieldKey); for (String value : configFieldModel.getFieldValues()) { FieldValueEntity newFieldValue = new FieldValueEntity(descriptorConfigId, fieldId, encrypt(value, isSensitive)); fieldValuesToSave.add(newFieldValue); } updatedConfig.put(configFieldModel); } fieldValueRepository.saveAll(fieldValuesToSave); fieldValueRepository.flush(); } descriptorConfigEntity.setLastUpdated(DateUtils.createCurrentDateTimestamp()); descriptorConfigsRepository.save(descriptorConfigEntity); return updatedConfig; } @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; }