use of com.synopsys.integration.alert.database.configuration.DefinedFieldEntity in project hub-alert by blackducksoftware.
the class DefaultConfigurationModelConfigurationAccessor method createConfiguration.
private ConfigurationModel createConfiguration(String descriptorKey, ConfigContextEnum context, Collection<ConfigurationFieldModel> configuredFields) {
Long descriptorId = getDescriptorIdOrThrowException(descriptorKey);
Long configContextId = getConfigContextIdOrThrowException(context);
OffsetDateTime currentTime = DateUtils.createCurrentDateTimestamp();
DescriptorConfigEntity descriptorConfigToSave = new DescriptorConfigEntity(descriptorId, configContextId, currentTime, currentTime);
DescriptorConfigEntity savedDescriptorConfig = descriptorConfigsRepository.save(descriptorConfigToSave);
ConfigurationModelMutable createdConfig = createEmptyConfigModel(descriptorId, savedDescriptorConfig.getId(), savedDescriptorConfig.getCreatedAt(), savedDescriptorConfig.getLastUpdated(), context);
if (configuredFields != null && !configuredFields.isEmpty()) {
List<FieldValueEntity> fieldValuesToSave = new ArrayList<>(configuredFields.size());
for (ConfigurationFieldModel configuredField : configuredFields) {
String fieldKey = configuredField.getFieldKey();
if (configuredField.isSet()) {
DefinedFieldEntity associatedField = definedFieldRepository.findFirstByKey(fieldKey).orElseThrow(() -> new AlertRuntimeException(String.format("FATAL: Field with key '%s' did not exist", fieldKey)));
for (String value : configuredField.getFieldValues()) {
FieldValueEntity newFieldValueEntity = new FieldValueEntity(createdConfig.getConfigurationId(), associatedField.getId(), encrypt(value, configuredField.isSensitive()));
fieldValuesToSave.add(newFieldValueEntity);
}
}
createdConfig.put(configuredField);
}
fieldValueRepository.saveAll(fieldValuesToSave);
}
return createdConfig;
}
use of com.synopsys.integration.alert.database.configuration.DefinedFieldEntity in project hub-alert by blackducksoftware.
the class FieldValueRepositoryTestIT method findByConfigIdTest.
@Test
public void findByConfigIdTest() {
RegisteredDescriptorEntity descriptorEntity = new RegisteredDescriptorEntity(DESCRIPTOR_NAME, 1L);
RegisteredDescriptorEntity savedDescriptorEntity = registeredDescriptorRepository.save(descriptorEntity);
DefinedFieldEntity definedFieldEntity1 = new DefinedFieldEntity("fieldKey1", Boolean.FALSE);
DefinedFieldEntity definedFieldEntity2 = new DefinedFieldEntity("fieldKey2", Boolean.FALSE);
DefinedFieldEntity definedFieldEntity3 = new DefinedFieldEntity("fieldKey3", Boolean.FALSE);
DefinedFieldEntity definedFieldEntity4 = new DefinedFieldEntity("fieldKey4", Boolean.FALSE);
DefinedFieldEntity savedEntity1 = definedFieldRepository.save(definedFieldEntity1);
DefinedFieldEntity savedEntity2 = definedFieldRepository.save(definedFieldEntity2);
DefinedFieldEntity savedEntity3 = definedFieldRepository.save(definedFieldEntity3);
DefinedFieldEntity savedEntity4 = definedFieldRepository.save(definedFieldEntity4);
assertEquals(4, definedFieldRepository.findAll().size());
descriptorFieldRepository.save(new DescriptorFieldRelation(descriptorEntity.getId(), savedEntity1.getId()));
descriptorFieldRepository.save(new DescriptorFieldRelation(descriptorEntity.getId(), savedEntity2.getId()));
descriptorFieldRepository.save(new DescriptorFieldRelation(descriptorEntity.getId(), savedEntity3.getId()));
descriptorFieldRepository.save(new DescriptorFieldRelation(descriptorEntity.getId(), savedEntity4.getId()));
ConfigContextEntity configContextEntity = new ConfigContextEntity(CONTEXT_NAME);
ConfigContextEntity savedContextEntity = configContextRepository.save(configContextEntity);
OffsetDateTime currentTime = DateUtils.createCurrentDateTimestamp();
DescriptorConfigEntity descriptorConfigEntity1 = new DescriptorConfigEntity(savedDescriptorEntity.getId(), savedContextEntity.getId(), currentTime, currentTime);
DescriptorConfigEntity descriptorConfigEntity2 = new DescriptorConfigEntity(savedDescriptorEntity.getId(), savedContextEntity.getId(), currentTime, currentTime);
descriptorConfigRepository.save(descriptorConfigEntity1);
descriptorConfigRepository.save(descriptorConfigEntity2);
assertEquals(2, descriptorConfigRepository.findAll().size());
FieldValueEntity fieldValueEntity1 = new FieldValueEntity(descriptorConfigEntity1.getId(), savedEntity1.getId(), "value1");
FieldValueEntity fieldValueEntity2 = new FieldValueEntity(descriptorConfigEntity1.getId(), savedEntity2.getId(), "value2");
FieldValueEntity fieldValueEntity3 = new FieldValueEntity(descriptorConfigEntity2.getId(), savedEntity3.getId(), "value3");
FieldValueEntity fieldValueEntity4 = new FieldValueEntity(descriptorConfigEntity2.getId(), savedEntity4.getId(), "value4");
fieldValueRepository.save(fieldValueEntity1);
fieldValueRepository.save(fieldValueEntity2);
fieldValueRepository.save(fieldValueEntity3);
fieldValueRepository.save(fieldValueEntity4);
assertEquals(4, fieldValueRepository.findAll().size());
List<FieldValueEntity> fieldValueEntityList1 = fieldValueRepository.findByConfigId(descriptorConfigEntity1.getId());
assertEquals(2, fieldValueEntityList1.size());
List<FieldValueEntity> fieldValueEntityList2 = fieldValueRepository.findByConfigId(descriptorConfigEntity2.getId());
assertEquals(2, fieldValueEntityList2.size());
}
use of com.synopsys.integration.alert.database.configuration.DefinedFieldEntity in project hub-alert by blackducksoftware.
the class FieldValueRepositoryTestIT method onDeleteCascadeTest.
@Test
public void onDeleteCascadeTest() {
RegisteredDescriptorEntity descriptorEntity = new RegisteredDescriptorEntity(DESCRIPTOR_NAME, 1L);
RegisteredDescriptorEntity savedDescriptorEntity = registeredDescriptorRepository.save(descriptorEntity);
DefinedFieldEntity definedFieldEntity1 = new DefinedFieldEntity("fieldKey1", Boolean.FALSE);
DefinedFieldEntity definedFieldEntity2 = new DefinedFieldEntity("fieldKey2", Boolean.FALSE);
DefinedFieldEntity definedFieldEntity3 = new DefinedFieldEntity("fieldKey3", Boolean.FALSE);
DefinedFieldEntity definedFieldEntity4 = new DefinedFieldEntity("fieldKey4", Boolean.FALSE);
DefinedFieldEntity savedEntity1 = definedFieldRepository.save(definedFieldEntity1);
DefinedFieldEntity savedEntity2 = definedFieldRepository.save(definedFieldEntity2);
DefinedFieldEntity savedEntity3 = definedFieldRepository.save(definedFieldEntity3);
DefinedFieldEntity savedEntity4 = definedFieldRepository.save(definedFieldEntity4);
assertEquals(4, definedFieldRepository.findAll().size());
descriptorFieldRepository.save(new DescriptorFieldRelation(descriptorEntity.getId(), savedEntity1.getId()));
descriptorFieldRepository.save(new DescriptorFieldRelation(descriptorEntity.getId(), savedEntity2.getId()));
descriptorFieldRepository.save(new DescriptorFieldRelation(descriptorEntity.getId(), savedEntity3.getId()));
descriptorFieldRepository.save(new DescriptorFieldRelation(descriptorEntity.getId(), savedEntity4.getId()));
ConfigContextEntity configContextEntity = new ConfigContextEntity(CONTEXT_NAME);
ConfigContextEntity savedContextEntity = configContextRepository.save(configContextEntity);
OffsetDateTime currentTime = DateUtils.createCurrentDateTimestamp();
DescriptorConfigEntity descriptorConfigEntity1 = new DescriptorConfigEntity(savedDescriptorEntity.getId(), savedContextEntity.getId(), currentTime, currentTime);
DescriptorConfigEntity descriptorConfigEntity2 = new DescriptorConfigEntity(savedDescriptorEntity.getId(), savedContextEntity.getId(), currentTime, currentTime);
DescriptorConfigEntity descriptorConfigEntity3 = new DescriptorConfigEntity(savedDescriptorEntity.getId(), savedContextEntity.getId(), currentTime, currentTime);
descriptorConfigRepository.save(descriptorConfigEntity1);
descriptorConfigRepository.save(descriptorConfigEntity2);
descriptorConfigRepository.save(descriptorConfigEntity3);
assertEquals(3, descriptorConfigRepository.findAll().size());
FieldValueEntity fieldValueEntity1 = new FieldValueEntity(descriptorConfigEntity1.getId(), savedEntity1.getId(), "value1");
FieldValueEntity fieldValueEntity2 = new FieldValueEntity(descriptorConfigEntity1.getId(), savedEntity2.getId(), "value2");
FieldValueEntity fieldValueEntity3 = new FieldValueEntity(descriptorConfigEntity2.getId(), savedEntity3.getId(), "value3");
FieldValueEntity fieldValueEntity4 = new FieldValueEntity(descriptorConfigEntity3.getId(), savedEntity4.getId(), "value4");
fieldValueRepository.save(fieldValueEntity1);
fieldValueRepository.save(fieldValueEntity2);
fieldValueRepository.save(fieldValueEntity3);
fieldValueRepository.save(fieldValueEntity4);
assertEquals(4, fieldValueRepository.findAll().size());
// Delete a configuration (deletes 1 & 2)
descriptorConfigRepository.deleteById(descriptorConfigEntity1.getId());
descriptorConfigRepository.flush();
assertEquals(2, fieldValueRepository.findAll().size());
// Delete a descriptor field (deletes 3)
definedFieldRepository.deleteById(savedEntity3.getId());
definedFieldRepository.flush();
assertEquals(1, fieldValueRepository.findAll().size());
// Delete a descriptor (deletes 4)
registeredDescriptorRepository.deleteById(savedDescriptorEntity.getId());
registeredDescriptorRepository.flush();
assertEquals(0, fieldValueRepository.findAll().size());
}
use of com.synopsys.integration.alert.database.configuration.DefinedFieldEntity in project hub-alert by blackducksoftware.
the class DefinedFieldRepositoryTestIT method findFirstByKeyTest.
@Test
public void findFirstByKeyTest() {
DefinedFieldEntity definedFieldEntity1 = new DefinedFieldEntity(FIELD_KEY_1, Boolean.FALSE);
DefinedFieldEntity definedFieldEntity2 = new DefinedFieldEntity(FIELD_KEY_2, Boolean.TRUE);
definedFieldRepository.save(definedFieldEntity1);
definedFieldRepository.save(definedFieldEntity2);
assertEquals(2, definedFieldRepository.findAll().size());
Optional<DefinedFieldEntity> descriptorFieldEntityOptional = definedFieldRepository.findFirstByKey(FIELD_KEY_1);
assertTrue(descriptorFieldEntityOptional.isPresent());
DefinedFieldEntity definedFieldEntity = descriptorFieldEntityOptional.get();
assertEquals(definedFieldEntity.getKey(), definedFieldEntity1.getKey());
assertEquals(definedFieldEntity.getSensitive(), definedFieldEntity1.getSensitive());
}
use of com.synopsys.integration.alert.database.configuration.DefinedFieldEntity in project hub-alert by blackducksoftware.
the class DefinedFieldRepositoryTestIT method onDeleteCascadeTest.
@Test
public void onDeleteCascadeTest() {
final String descriptorName = "test descriptor";
RegisteredDescriptorEntity registeredDescriptorEntity = new RegisteredDescriptorEntity(descriptorName, 1L);
RegisteredDescriptorEntity savedRegisteredDescriptorEntity = registeredDescriptorRepository.save(registeredDescriptorEntity);
assertEquals(1, registeredDescriptorRepository.findAll().size());
DefinedFieldEntity definedFieldEntity = new DefinedFieldEntity(FIELD_KEY_1, Boolean.FALSE);
DefinedFieldEntity savedDefinedFieldEntity = definedFieldRepository.save(definedFieldEntity);
assertEquals(1, definedFieldRepository.findAll().size());
DescriptorFieldRelation descriptorFieldRelation = new DescriptorFieldRelation(savedRegisteredDescriptorEntity.getId(), savedDefinedFieldEntity.getId());
descriptorFieldRepository.save(descriptorFieldRelation);
assertEquals(1, descriptorFieldRepository.findAll().size());
definedFieldRepository.deleteById(savedDefinedFieldEntity.getId());
definedFieldRepository.flush();
assertEquals(0, descriptorFieldRepository.findAll().size());
}
Aggregations