Search in sources :

Example 21 with ConfigurationFieldModel

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

the class AuditEntryControllerTestIT method testResendJobConfig.

@Test
@WithMockUser(roles = AlertIntegrationTestConstants.ROLE_ALERT_ADMIN)
public void testResendJobConfig() throws Exception {
    List<ConfigurationFieldModel> slackFields = new ArrayList<>(MockConfigurationModelFactory.createSlackDistributionFields());
    ConfigurationFieldModel providerConfigName = providerConfigModel.getField(ProviderDescriptor.KEY_PROVIDER_CONFIG_NAME).orElse(null);
    slackFields.add(providerConfigName);
    DistributionJobRequestModel jobRequestModel = createJobRequestModel();
    DistributionJobModel jobModel = jobAccessor.createJob(jobRequestModel);
    NotificationEntity notificationEntity = mockNotificationContent.createEntity();
    notificationEntity = notificationRepository.save(notificationEntity);
    mockAuditEntryEntity.setCommonConfigId(jobModel.getJobId());
    AuditEntryEntity auditEntity = mockAuditEntryEntity.createEntity();
    auditEntity = auditEntryRepository.save(auditEntity);
    auditNotificationRepository.save(new AuditNotificationRelation(auditEntity.getId(), notificationEntity.getId()));
    String resendUrl = auditUrl + "/resend/" + notificationEntity.getId() + "/job/" + auditEntity.getCommonConfigId();
    MockHttpServletRequestBuilder request = MockMvcRequestBuilders.post(resendUrl).with(SecurityMockMvcRequestPostProcessors.user("admin").roles(AlertIntegrationTestConstants.ROLE_ALERT_ADMIN)).with(SecurityMockMvcRequestPostProcessors.csrf());
    mockMvc.perform(request).andExpect(MockMvcResultMatchers.status().isOk());
}
Also used : ConfigurationFieldModel(com.synopsys.integration.alert.common.persistence.model.ConfigurationFieldModel) MockHttpServletRequestBuilder(org.springframework.test.web.servlet.request.MockHttpServletRequestBuilder) ArrayList(java.util.ArrayList) AuditNotificationRelation(com.synopsys.integration.alert.database.audit.AuditNotificationRelation) AuditEntryEntity(com.synopsys.integration.alert.database.audit.AuditEntryEntity) MockAuditEntryEntity(com.synopsys.integration.alert.component.audit.mock.MockAuditEntryEntity) DistributionJobRequestModel(com.synopsys.integration.alert.common.persistence.model.job.DistributionJobRequestModel) NotificationEntity(com.synopsys.integration.alert.database.notification.NotificationEntity) DistributionJobModel(com.synopsys.integration.alert.common.persistence.model.job.DistributionJobModel) WithMockUser(org.springframework.security.test.context.support.WithMockUser) AlertIntegrationTest(com.synopsys.integration.alert.util.AlertIntegrationTest) Test(org.junit.jupiter.api.Test)

Example 22 with ConfigurationFieldModel

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

the class AuditEntryHandlerTestIT method init.

@BeforeEach
public void init() {
    auditEntryRepository.flush();
    notificationContentRepository.flush();
    descriptorConfigRepository.flush();
    fieldValueRepository.flush();
    auditEntryRepository.deleteAllInBatch();
    notificationContentRepository.deleteAllInBatch();
    descriptorConfigRepository.deleteAllInBatch();
    fieldValueRepository.deleteAllInBatch();
    ConfigurationFieldModel providerConfigEnabled = ConfigurationFieldModel.create(ProviderDescriptor.KEY_PROVIDER_CONFIG_ENABLED);
    providerConfigEnabled.setFieldValue("true");
    ConfigurationFieldModel providerConfigName = ConfigurationFieldModel.create(ProviderDescriptor.KEY_PROVIDER_CONFIG_NAME);
    providerConfigName.setFieldValue("My Black Duck Config");
    ConfigurationFieldModel blackduckUrl = ConfigurationFieldModel.create(BlackDuckDescriptor.KEY_BLACKDUCK_URL);
    blackduckUrl.setFieldValue("https://a-blackduck-server");
    ConfigurationFieldModel blackduckApiKey = ConfigurationFieldModel.createSensitive(BlackDuckDescriptor.KEY_BLACKDUCK_API_KEY);
    blackduckApiKey.setFieldValue("123456789012345678901234567890123456789012345678901234567890");
    ConfigurationFieldModel blackduckTimeout = ConfigurationFieldModel.create(BlackDuckDescriptor.KEY_BLACKDUCK_TIMEOUT);
    blackduckTimeout.setFieldValue("300");
    List<ConfigurationFieldModel> providerConfigFields = List.of(providerConfigEnabled, providerConfigName, blackduckUrl, blackduckApiKey, blackduckTimeout);
    providerConfigModel = configurationModelConfigurationAccessor.createConfiguration(new BlackDuckProviderKey(), ConfigContextEnum.GLOBAL, providerConfigFields);
    mockNotification.setProviderConfigId(providerConfigModel.getConfigurationId());
}
Also used : BlackDuckProviderKey(com.synopsys.integration.alert.descriptor.api.BlackDuckProviderKey) ConfigurationFieldModel(com.synopsys.integration.alert.common.persistence.model.ConfigurationFieldModel) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 23 with ConfigurationFieldModel

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

the class ConfigurationFieldModelConverter method convertToFieldModel.

public FieldModel convertToFieldModel(ConfigurationModel configurationModel) {
    Long configId = configurationModel.getConfigurationId();
    String descriptorName = getDescriptorName(configurationModel);
    Map<String, FieldValueModel> fields = new HashMap<>();
    for (ConfigurationFieldModel fieldModel : configurationModel.getCopyOfFieldList()) {
        populateAndSecureFields(fieldModel, fields);
    }
    return new FieldModel(configId.toString(), descriptorName, configurationModel.getDescriptorContext().name(), configurationModel.getCreatedAt(), configurationModel.getLastUpdated(), fields);
}
Also used : ConfigurationFieldModel(com.synopsys.integration.alert.common.persistence.model.ConfigurationFieldModel) HashMap(java.util.HashMap) DefinedFieldModel(com.synopsys.integration.alert.common.persistence.model.DefinedFieldModel) ConfigurationFieldModel(com.synopsys.integration.alert.common.persistence.model.ConfigurationFieldModel) FieldModel(com.synopsys.integration.alert.common.rest.model.FieldModel) FieldValueModel(com.synopsys.integration.alert.common.rest.model.FieldValueModel)

Example 24 with ConfigurationFieldModel

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

the class FieldModelProcessor method populateTestFieldModel.

private FieldModel populateTestFieldModel(Long id, FieldModel fieldModel) throws AlertException {
    Collection<ConfigurationFieldModel> configurationFieldModels = fillFieldModelWithExistingData(id, fieldModel);
    Map<String, FieldValueModel> fields = new HashMap<>();
    for (ConfigurationFieldModel configurationFieldModel : configurationFieldModels) {
        FieldValueModel fieldValueModel = new FieldValueModel(configurationFieldModel.getFieldValues(), configurationFieldModel.isSet());
        fields.put(configurationFieldModel.getFieldKey(), fieldValueModel);
    }
    FieldModel newFieldModel = new FieldModel("", "", fieldModel.getCreatedAt(), fieldModel.getLastUpdated(), fields);
    return fieldModel.fill(newFieldModel);
}
Also used : ConfigurationFieldModel(com.synopsys.integration.alert.common.persistence.model.ConfigurationFieldModel) HashMap(java.util.HashMap) ConfigurationFieldModel(com.synopsys.integration.alert.common.persistence.model.ConfigurationFieldModel) FieldModel(com.synopsys.integration.alert.common.rest.model.FieldModel) FieldValueModel(com.synopsys.integration.alert.common.rest.model.FieldValueModel)

Example 25 with ConfigurationFieldModel

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

the class DefaultDescriptorGlobalConfigUtility method updateSensitiveFields.

// TODO build a new utility to perform this action or try to refactor FieldModelProcessor into the alert-common sub-project
private Map<String, ConfigurationFieldModel> updateSensitiveFields(Map<String, ConfigurationFieldModel> values, ConfigurationModel existingConfig) {
    Collection<ConfigurationFieldModel> sensitiveFields = existingConfig.getCopyOfFieldList().stream().filter(ConfigurationFieldModel::isSensitive).collect(Collectors.toSet());
    for (ConfigurationFieldModel sensitiveConfigurationFieldModel : sensitiveFields) {
        String fieldKey = sensitiveConfigurationFieldModel.getFieldKey();
        if (values.containsKey(fieldKey)) {
            ConfigurationFieldModel sensitiveFieldModel = values.get(fieldKey);
            if (!sensitiveFieldModel.isSet()) {
                ConfigurationFieldModel newFieldModel = values.get(fieldKey);
                newFieldModel.setFieldValues(sensitiveConfigurationFieldModel.getFieldValues());
            }
        }
    }
    return values;
}
Also used : ConfigurationFieldModel(com.synopsys.integration.alert.common.persistence.model.ConfigurationFieldModel)

Aggregations

ConfigurationFieldModel (com.synopsys.integration.alert.common.persistence.model.ConfigurationFieldModel)105 ConfigurationModel (com.synopsys.integration.alert.common.persistence.model.ConfigurationModel)47 Test (org.junit.jupiter.api.Test)32 DescriptorKey (com.synopsys.integration.alert.descriptor.api.model.DescriptorKey)27 FieldModel (com.synopsys.integration.alert.common.rest.model.FieldModel)23 HashMap (java.util.HashMap)20 ConfigurationFieldModelConverter (com.synopsys.integration.alert.common.persistence.util.ConfigurationFieldModelConverter)14 ArrayList (java.util.ArrayList)13 ConfigurationModelConfigurationAccessor (com.synopsys.integration.alert.common.persistence.accessor.ConfigurationModelConfigurationAccessor)12 FieldValueModel (com.synopsys.integration.alert.common.rest.model.FieldValueModel)12 DescriptorAccessor (com.synopsys.integration.alert.common.persistence.accessor.DescriptorAccessor)11 DefinedFieldModel (com.synopsys.integration.alert.common.persistence.model.DefinedFieldModel)11 AlertException (com.synopsys.integration.alert.api.common.model.exception.AlertException)10 BlackDuckProviderKey (com.synopsys.integration.alert.descriptor.api.BlackDuckProviderKey)10 ConfigContextEnum (com.synopsys.integration.alert.common.enumeration.ConfigContextEnum)9 AlertIntegrationTest (com.synopsys.integration.alert.util.AlertIntegrationTest)9 ConfigurationModelMutable (com.synopsys.integration.alert.common.persistence.model.mutable.ConfigurationModelMutable)8 EncryptionUtility (com.synopsys.integration.alert.common.security.EncryptionUtility)8 BeforeEach (org.junit.jupiter.api.BeforeEach)8 FieldUtility (com.synopsys.integration.alert.common.persistence.accessor.FieldUtility)7