Search in sources :

Example 1 with ConfigurationModelMutable

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

the class ConfigurationModelTest method createMutableCopyTest.

@Test
public void createMutableCopyTest() {
    ConfigurationModel configurationModel = createConfigurationModel();
    ConfigurationModelMutable configurationModelMutable = configurationModel.createMutableCopy();
    assertEquals(configurationModel, configurationModelMutable);
    assertNotSame(configurationModel, configurationModelMutable);
}
Also used : ConfigurationModelMutable(com.synopsys.integration.alert.common.persistence.model.mutable.ConfigurationModelMutable) Test(org.junit.jupiter.api.Test)

Example 2 with ConfigurationModelMutable

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

the class DefaultNotificationAccessorTest method createConfigurationModel.

private ConfigurationModelMutable createConfigurationModel() {
    ConfigurationModelMutable configurationModel = new ConfigurationModelMutable(1L, 1L, "createdAt-test", "lastUpdate-test", ConfigContextEnum.DISTRIBUTION);
    ConfigurationFieldModel configurationFieldModel = ConfigurationFieldModel.create(KEY_PROVIDER_CONFIG_NAME);
    configurationFieldModel.setFieldValue(fieldValue);
    configurationModel.put(configurationFieldModel);
    return configurationModel;
}
Also used : ConfigurationModelMutable(com.synopsys.integration.alert.common.persistence.model.mutable.ConfigurationModelMutable) ConfigurationFieldModel(com.synopsys.integration.alert.common.persistence.model.ConfigurationFieldModel)

Example 3 with ConfigurationModelMutable

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

the class DefaultConfigurationModelConfigurationAccessor method createConfigModel.

private ConfigurationModelMutable createConfigModel(Long descriptorId, Long configId, OffsetDateTime createdAt, OffsetDateTime lastUpdated, Long contextId) {
    String configContext = getContextById(contextId);
    String createdAtFormatted = DateUtils.formatDate(createdAt, DateUtils.UTC_DATE_FORMAT_TO_MINUTE);
    String lastUpdatedFormatted = DateUtils.formatDate(lastUpdated, DateUtils.UTC_DATE_FORMAT_TO_MINUTE);
    ConfigurationModelMutable newModel = new ConfigurationModelMutable(descriptorId, configId, createdAtFormatted, lastUpdatedFormatted, configContext);
    List<FieldValueEntity> fieldValueEntities = fieldValueRepository.findByConfigId(configId);
    for (FieldValueEntity fieldValueEntity : fieldValueEntities) {
        DefinedFieldEntity definedFieldEntity = definedFieldRepository.findById(fieldValueEntity.getFieldId()).orElseThrow(() -> new AlertRuntimeException("Field Id missing from the database"));
        String fieldKey = definedFieldEntity.getKey();
        ConfigurationFieldModel fieldModel = BooleanUtils.isTrue(definedFieldEntity.getSensitive()) ? ConfigurationFieldModel.createSensitive(fieldKey) : ConfigurationFieldModel.create(fieldKey);
        String decryptedValue = decrypt(fieldValueEntity.getValue(), fieldModel.isSensitive());
        fieldModel.setFieldValue(decryptedValue);
        newModel.put(fieldModel);
    }
    return newModel;
}
Also used : ConfigurationModelMutable(com.synopsys.integration.alert.common.persistence.model.mutable.ConfigurationModelMutable) ConfigurationFieldModel(com.synopsys.integration.alert.common.persistence.model.ConfigurationFieldModel) 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 4 with ConfigurationModelMutable

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

the class PurgeTaskTest method cronExpressionNotDefault.

@Test
public void cronExpressionNotDefault() {
    final String notDefaultValue = "44";
    ConfigurationModelConfigurationAccessor configurationModelConfigurationAccessor = Mockito.mock(ConfigurationModelConfigurationAccessor.class);
    ConfigurationModelMutable configurationModel = new ConfigurationModelMutable(1L, 1L, null, null, ConfigContextEnum.GLOBAL);
    ConfigurationFieldModel configurationFieldModel = ConfigurationFieldModel.create(SchedulingDescriptor.KEY_PURGE_DATA_FREQUENCY_DAYS);
    configurationFieldModel.setFieldValue(notDefaultValue);
    configurationModel.put(configurationFieldModel);
    Mockito.when(configurationModelConfigurationAccessor.getConfigurationsByDescriptorKey(Mockito.any(DescriptorKey.class))).thenReturn(List.of(configurationModel));
    PurgeTask task = new PurgeTask(new SchedulingDescriptorKey(), null, null, null, null, configurationModelConfigurationAccessor);
    String cronWithNotDefault = task.scheduleCronExpression();
    String expectedCron = String.format(PurgeTask.CRON_FORMAT, notDefaultValue);
    assertEquals(expectedCron, cronWithNotDefault);
}
Also used : ConfigurationModelMutable(com.synopsys.integration.alert.common.persistence.model.mutable.ConfigurationModelMutable) SchedulingDescriptorKey(com.synopsys.integration.alert.component.scheduling.descriptor.SchedulingDescriptorKey) ConfigurationFieldModel(com.synopsys.integration.alert.common.persistence.model.ConfigurationFieldModel) DescriptorKey(com.synopsys.integration.alert.descriptor.api.model.DescriptorKey) SchedulingDescriptorKey(com.synopsys.integration.alert.component.scheduling.descriptor.SchedulingDescriptorKey) ConfigurationModelConfigurationAccessor(com.synopsys.integration.alert.common.persistence.accessor.ConfigurationModelConfigurationAccessor) PurgeTask(com.synopsys.integration.alert.component.scheduling.workflow.PurgeTask) Test(org.junit.jupiter.api.Test)

Example 5 with ConfigurationModelMutable

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

the class LdapManagerTest method createConfigurationModel.

private ConfigurationModel createConfigurationModel() {
    ConfigurationModelMutable configurationModel = new ConfigurationModelMutable(1L, 1L, null, null, ConfigContextEnum.GLOBAL);
    ConfigurationFieldModel enabledField = ConfigurationFieldModel.create(AuthenticationDescriptor.KEY_LDAP_ENABLED);
    ConfigurationFieldModel serverField = ConfigurationFieldModel.create(AuthenticationDescriptor.KEY_LDAP_SERVER);
    ConfigurationFieldModel managerDNField = ConfigurationFieldModel.create(AuthenticationDescriptor.KEY_LDAP_MANAGER_DN);
    ConfigurationFieldModel managerPasswordField = ConfigurationFieldModel.createSensitive(AuthenticationDescriptor.KEY_LDAP_MANAGER_PWD);
    ConfigurationFieldModel authenticationTypeField = ConfigurationFieldModel.create(AuthenticationDescriptor.KEY_LDAP_AUTHENTICATION_TYPE);
    ConfigurationFieldModel referralField = ConfigurationFieldModel.create(AuthenticationDescriptor.KEY_LDAP_REFERRAL);
    ConfigurationFieldModel userSearchBaseField = ConfigurationFieldModel.create(AuthenticationDescriptor.KEY_LDAP_USER_SEARCH_BASE);
    ConfigurationFieldModel userSearchFilterField = ConfigurationFieldModel.create(AuthenticationDescriptor.KEY_LDAP_USER_SEARCH_FILTER);
    ConfigurationFieldModel userDNPatternsField = ConfigurationFieldModel.create(AuthenticationDescriptor.KEY_LDAP_USER_DN_PATTERNS);
    ConfigurationFieldModel userAttributesField = ConfigurationFieldModel.create(AuthenticationDescriptor.KEY_LDAP_USER_ATTRIBUTES);
    ConfigurationFieldModel groupSearchBaseField = ConfigurationFieldModel.create(AuthenticationDescriptor.KEY_LDAP_GROUP_SEARCH_BASE);
    ConfigurationFieldModel groupSearchFilterField = ConfigurationFieldModel.create(AuthenticationDescriptor.KEY_LDAP_GROUP_SEARCH_FILTER);
    ConfigurationFieldModel groupRoleAttributeField = ConfigurationFieldModel.create(AuthenticationDescriptor.KEY_LDAP_GROUP_ROLE_ATTRIBUTE);
    enabledField.setFieldValue(DEFAULT_ENABLED);
    serverField.setFieldValue(DEFAULT_SERVER);
    managerDNField.setFieldValue(DEFAULT_MANAGER_DN);
    managerPasswordField.setFieldValue(DEFAULT_MANAGER_PASSWORD);
    authenticationTypeField.setFieldValue(DEFAULT_AUTHENTICATION_TYPE);
    referralField.setFieldValue(DEFAULT_REFERRAL);
    userSearchBaseField.setFieldValue(DEFAULT_USER_SEARCH_BASE);
    userSearchFilterField.setFieldValue(DEFAULT_USER_SEARCH_FILTER);
    userDNPatternsField.setFieldValue(DEFAULT_USER_DN_PATTERNS);
    userAttributesField.setFieldValue(DEFAULT_USER_ATTRIBUTES);
    groupSearchBaseField.setFieldValue(DEFAULT_GROUP_SEARCH_BASE);
    groupSearchFilterField.setFieldValue(DEFAULT_GROUP_SEARCH_FILTER);
    groupRoleAttributeField.setFieldValue(DEFAULT_GROUP_ROLE_ATTRIBUTE);
    configurationModel.put(enabledField);
    configurationModel.put(serverField);
    configurationModel.put(managerDNField);
    configurationModel.put(managerPasswordField);
    configurationModel.put(authenticationTypeField);
    configurationModel.put(referralField);
    configurationModel.put(userSearchBaseField);
    configurationModel.put(userSearchFilterField);
    configurationModel.put(userDNPatternsField);
    configurationModel.put(userAttributesField);
    configurationModel.put(groupSearchBaseField);
    configurationModel.put(groupSearchFilterField);
    configurationModel.put(groupRoleAttributeField);
    return configurationModel;
}
Also used : ConfigurationModelMutable(com.synopsys.integration.alert.common.persistence.model.mutable.ConfigurationModelMutable) ConfigurationFieldModel(com.synopsys.integration.alert.common.persistence.model.ConfigurationFieldModel)

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