Search in sources :

Example 6 with ConfigurationModelMutable

use of com.synopsys.integration.alert.common.persistence.model.mutable.ConfigurationModelMutable in project hub-alert by blackducksoftware.

the class ConfigurationModel method createMutableCopy.

public ConfigurationModelMutable createMutableCopy() {
    ConfigurationModelMutable mutableCopy = new ConfigurationModelMutable(descriptorId, configurationId, createdAt, lastUpdated, context);
    mutableCopy.getConfiguredFields().putAll(configuredFields);
    return mutableCopy;
}
Also used : ConfigurationModelMutable(com.synopsys.integration.alert.common.persistence.model.mutable.ConfigurationModelMutable)

Example 7 with ConfigurationModelMutable

use of com.synopsys.integration.alert.common.persistence.model.mutable.ConfigurationModelMutable in project hub-alert by blackducksoftware.

the class ConfigurationFieldModelConverter method convertToConfigurationModel.

public ConfigurationModel convertToConfigurationModel(FieldModel fieldModel) {
    String descriptorName = fieldModel.getDescriptorName();
    DescriptorKey descriptorKey = getDescriptorKey(descriptorName).orElseThrow(() -> new AlertRuntimeException("Could not find a Descriptor with the name: " + descriptorName));
    long descriptorId = descriptorAccessor.getRegisteredDescriptorByKey(descriptorKey).map(RegisteredDescriptorModel::getId).orElse(0L);
    long configId = Long.parseLong(fieldModel.getId());
    ConfigurationModelMutable configurationModel = new ConfigurationModelMutable(configId, descriptorId, fieldModel.getCreatedAt(), fieldModel.getLastUpdated(), fieldModel.getContext());
    convertToConfigurationFieldModelMap(fieldModel).values().forEach(configurationModel::put);
    return configurationModel;
}
Also used : ConfigurationModelMutable(com.synopsys.integration.alert.common.persistence.model.mutable.ConfigurationModelMutable) DescriptorKey(com.synopsys.integration.alert.descriptor.api.model.DescriptorKey) AlertRuntimeException(com.synopsys.integration.alert.api.common.model.exception.AlertRuntimeException)

Example 8 with ConfigurationModelMutable

use of com.synopsys.integration.alert.common.persistence.model.mutable.ConfigurationModelMutable 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;
}
Also used : ConfigurationModelMutable(com.synopsys.integration.alert.common.persistence.model.mutable.ConfigurationModelMutable) ConfigurationFieldModel(com.synopsys.integration.alert.common.persistence.model.ConfigurationFieldModel) OffsetDateTime(java.time.OffsetDateTime) DescriptorConfigEntity(com.synopsys.integration.alert.database.configuration.DescriptorConfigEntity) ArrayList(java.util.ArrayList) DefinedFieldEntity(com.synopsys.integration.alert.database.configuration.DefinedFieldEntity) AlertRuntimeException(com.synopsys.integration.alert.api.common.model.exception.AlertRuntimeException) FieldValueEntity(com.synopsys.integration.alert.database.configuration.FieldValueEntity)

Example 9 with ConfigurationModelMutable

use of com.synopsys.integration.alert.common.persistence.model.mutable.ConfigurationModelMutable in project hub-alert by blackducksoftware.

the class DefaultConfigurationModelConfigurationAccessor method updateConfiguration.

/**
 * @return the config after update
 */
@Override
public ConfigurationModel updateConfiguration(Long descriptorConfigId, Collection<ConfigurationFieldModel> configuredFields) throws AlertConfigurationException {
    DescriptorConfigEntity descriptorConfigEntity = descriptorConfigsRepository.findById(descriptorConfigId).orElseThrow(() -> new AlertConfigurationException(String.format("Config with id '%d' did not exist", descriptorConfigId)));
    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;
}
Also used : ConfigurationModelMutable(com.synopsys.integration.alert.common.persistence.model.mutable.ConfigurationModelMutable) ConfigurationFieldModel(com.synopsys.integration.alert.common.persistence.model.ConfigurationFieldModel) DescriptorConfigEntity(com.synopsys.integration.alert.database.configuration.DescriptorConfigEntity) ArrayList(java.util.ArrayList) AlertConfigurationException(com.synopsys.integration.alert.api.common.model.exception.AlertConfigurationException) FieldValueEntity(com.synopsys.integration.alert.database.configuration.FieldValueEntity)

Example 10 with ConfigurationModelMutable

use of com.synopsys.integration.alert.common.persistence.model.mutable.ConfigurationModelMutable in project hub-alert by blackducksoftware.

the class BlackDuckSSOConfigRetrieverTest method createBlackDuckProperties.

private BlackDuckProperties createBlackDuckProperties() {
    TestProperties testProperties = new TestProperties();
    String blackDuckUrl = testProperties.getBlackDuckURL();
    String blackDuckApiKey = testProperties.getBlackDuckAPIToken();
    String blackDuckTimeout = testProperties.getOptionalProperty(TestPropertyKey.TEST_BLACKDUCK_PROVIDER_TIMEOUT).orElse("300");
    MockAlertProperties mockAlertProperties = new MockAlertProperties();
    ProxyManager mockProxyManager = Mockito.mock(ProxyManager.class);
    Mockito.when(mockProxyManager.createProxyInfoForHost(Mockito.anyString())).thenReturn(ProxyInfo.NO_PROXY_INFO);
    ConfigurationModelMutable configurationModel = new ConfigurationModelMutable(0L, 0L, null, null, ConfigContextEnum.GLOBAL);
    configurationModel.put(createConfigFieldModel(ProviderDescriptor.KEY_PROVIDER_CONFIG_ENABLED, Boolean.TRUE.toString()));
    configurationModel.put(createConfigFieldModel(ProviderDescriptor.KEY_PROVIDER_CONFIG_NAME, BlackDuckSSOConfigRetrieverTest.class.getSimpleName()));
    configurationModel.put(createConfigFieldModel(BlackDuckDescriptor.KEY_BLACKDUCK_URL, blackDuckUrl));
    configurationModel.put(createConfigFieldModel(BlackDuckDescriptor.KEY_BLACKDUCK_API_KEY, blackDuckApiKey));
    configurationModel.put(createConfigFieldModel(BlackDuckDescriptor.KEY_BLACKDUCK_TIMEOUT, blackDuckTimeout));
    return new BlackDuckProperties(0L, new Gson(), BlackDuckServicesFactory.createDefaultObjectMapper(), mockAlertProperties, mockProxyManager, configurationModel);
}
Also used : TestProperties(com.synopsys.integration.alert.test.common.TestProperties) ConfigurationModelMutable(com.synopsys.integration.alert.common.persistence.model.mutable.ConfigurationModelMutable) BlackDuckProperties(com.synopsys.integration.alert.provider.blackduck.BlackDuckProperties) MockAlertProperties(com.synopsys.integration.alert.test.common.MockAlertProperties) ProxyManager(com.synopsys.integration.alert.common.rest.proxy.ProxyManager) Gson(com.google.gson.Gson)

Aggregations

ConfigurationModelMutable (com.synopsys.integration.alert.common.persistence.model.mutable.ConfigurationModelMutable)11 ConfigurationFieldModel (com.synopsys.integration.alert.common.persistence.model.ConfigurationFieldModel)7 AlertRuntimeException (com.synopsys.integration.alert.api.common.model.exception.AlertRuntimeException)3 FieldValueEntity (com.synopsys.integration.alert.database.configuration.FieldValueEntity)3 DescriptorKey (com.synopsys.integration.alert.descriptor.api.model.DescriptorKey)3 Test (org.junit.jupiter.api.Test)3 ConfigurationModelConfigurationAccessor (com.synopsys.integration.alert.common.persistence.accessor.ConfigurationModelConfigurationAccessor)2 SchedulingDescriptorKey (com.synopsys.integration.alert.component.scheduling.descriptor.SchedulingDescriptorKey)2 DefinedFieldEntity (com.synopsys.integration.alert.database.configuration.DefinedFieldEntity)2 DescriptorConfigEntity (com.synopsys.integration.alert.database.configuration.DescriptorConfigEntity)2 ArrayList (java.util.ArrayList)2 Gson (com.google.gson.Gson)1 AlertConfigurationException (com.synopsys.integration.alert.api.common.model.exception.AlertConfigurationException)1 ProxyManager (com.synopsys.integration.alert.common.rest.proxy.ProxyManager)1 DailyTask (com.synopsys.integration.alert.component.scheduling.workflow.DailyTask)1 PurgeTask (com.synopsys.integration.alert.component.scheduling.workflow.PurgeTask)1 StaticJobAccessor (com.synopsys.integration.alert.database.api.StaticJobAccessor)1 BlackDuckProperties (com.synopsys.integration.alert.provider.blackduck.BlackDuckProperties)1 MockAlertProperties (com.synopsys.integration.alert.test.common.MockAlertProperties)1 TestProperties (com.synopsys.integration.alert.test.common.TestProperties)1