use of com.synopsys.integration.alert.common.persistence.model.ConfigurationFieldModel in project hub-alert by blackducksoftware.
the class JobConfigActions method updateWithoutChecks.
@Override
protected ActionResponse<JobFieldModel> updateWithoutChecks(UUID id, JobFieldModel resource) {
try {
Optional<DistributionJobModel> jobModel = jobAccessor.getJobById(id);
if (jobModel.isPresent()) {
DistributionJobModel previousJob = jobModel.get();
JobFieldModel jobFieldModel = JobFieldModelPopulationUtils.createJobFieldModelWithDefaultProviderProjectState(previousJob);
Map<String, FieldModel> descriptorAndContextToPreviousFieldModel = new HashMap<>();
for (FieldModel previousJobFieldModel : jobFieldModel.getFieldModels()) {
descriptorAndContextToPreviousFieldModel.put(previousJobFieldModel.getDescriptorName() + previousJobFieldModel.getContext(), previousJobFieldModel);
}
Set<ConfigurationFieldModel> configurationFieldModels = new HashSet<>();
for (FieldModel fieldModel : resource.getFieldModels()) {
FieldModel beforeUpdateEventFieldModel = fieldModelProcessor.performBeforeUpdateAction(fieldModel);
String beforeFieldModelId = beforeUpdateEventFieldModel.getId();
Long fieldModelId = (StringUtils.isNotBlank(beforeFieldModelId)) ? Long.parseLong(beforeFieldModelId) : null;
Collection<ConfigurationFieldModel> updatedFieldModels = fieldModelProcessor.fillFieldModelWithExistingData(fieldModelId, beforeUpdateEventFieldModel);
configurationFieldModels.addAll(updatedFieldModels);
}
List<JobProviderProjectFieldModel> configuredProviderProjects = Optional.ofNullable(resource.getConfiguredProviderProjects()).orElse(List.of());
DistributionJobRequestModel jobRequestModel = createDistributionJobRequestModel(configurationFieldModels, configuredProviderProjects, previousJob.getCreatedAt(), DateUtils.createCurrentDateTimestamp());
DistributionJobModel savedJob = jobAccessor.updateJob(previousJob.getJobId(), jobRequestModel);
JobFieldModel savedJobFieldModel = JobFieldModelPopulationUtils.createJobFieldModel(savedJob, configuredProviderProjects);
Set<FieldModel> updatedFieldModels = new HashSet<>();
for (FieldModel fieldModel : savedJobFieldModel.getFieldModels()) {
FieldModel previousFieldModel = descriptorAndContextToPreviousFieldModel.get(fieldModel.getDescriptorName() + fieldModel.getContext());
FieldModel updatedModel = fieldModelProcessor.performAfterUpdateAction(previousFieldModel, fieldModel);
updatedFieldModels.add(updatedModel);
}
savedJobFieldModel.setFieldModels(updatedFieldModels);
return new ActionResponse<>(HttpStatus.OK, savedJobFieldModel);
} else {
return new ActionResponse<>(HttpStatus.NOT_FOUND);
}
} catch (AlertException ex) {
logger.error("Error creating job", ex);
return new ActionResponse<>(HttpStatus.INTERNAL_SERVER_ERROR, ex.getMessage());
}
}
use of com.synopsys.integration.alert.common.persistence.model.ConfigurationFieldModel in project hub-alert by blackducksoftware.
the class JobConfigActions method convertFieldToConfigurationField.
private Optional<ConfigurationFieldModel> convertFieldToConfigurationField(FieldModel fieldModel, String fieldKey) {
Optional<FieldValueModel> fieldValueModel = fieldModel.getFieldValueModel(fieldKey);
if (fieldValueModel.isPresent()) {
ConfigurationFieldModel configurationFieldModel = ConfigurationFieldModel.create(fieldKey);
configurationFieldModel.setFieldValues(fieldValueModel.get().getValues());
return Optional.of(configurationFieldModel);
}
return Optional.empty();
}
use of com.synopsys.integration.alert.common.persistence.model.ConfigurationFieldModel in project hub-alert by blackducksoftware.
the class ProviderDataAccessorTest method init.
@BeforeEach
void init() throws Exception {
blackDuckPropertiesFactory = Mockito.mock(BlackDuckPropertiesFactory.class);
BlackDuckProperties blackDuckProperties = Mockito.mock(BlackDuckProperties.class);
Mockito.when(blackDuckPropertiesFactory.createProperties(Mockito.any(ConfigurationModel.class))).thenReturn(blackDuckProperties);
BlackDuckHttpClient blackDuckHttpClient = Mockito.mock(BlackDuckHttpClient.class);
Mockito.when(blackDuckProperties.createBlackDuckHttpClient(Mockito.any(IntLogger.class))).thenReturn(blackDuckHttpClient);
blackDuckServicesFactory = Mockito.mock(BlackDuckServicesFactory.class);
Mockito.when(blackDuckProperties.createBlackDuckServicesFactory(Mockito.any(BlackDuckHttpClient.class), Mockito.any(IntLogger.class))).thenReturn(blackDuckServicesFactory);
projectService = Mockito.mock(ProjectService.class);
Mockito.when(blackDuckServicesFactory.createProjectService()).thenReturn(projectService);
blackDuckApiClient = Mockito.mock(BlackDuckApiClient.class);
Mockito.when(blackDuckServicesFactory.getBlackDuckApiClient()).thenReturn(blackDuckApiClient);
projectUsersService = Mockito.mock(ProjectUsersService.class);
Mockito.when(blackDuckServicesFactory.createProjectUsersService()).thenReturn(projectUsersService);
apiDiscovery = Mockito.mock(ApiDiscovery.class);
UrlMultipleResponses<UserView> usersLink = Mockito.mock(UrlMultipleResponses.class);
Mockito.when(apiDiscovery.metaUsersLink()).thenReturn(usersLink);
Mockito.when(blackDuckServicesFactory.getApiDiscovery()).thenReturn(apiDiscovery);
ConfigurationFieldModel configurationFieldModel = ConfigurationFieldModel.create(ProviderDescriptor.KEY_PROVIDER_CONFIG_NAME);
configurationFieldModel.setFieldValue(PROVIDER_CONFIG_NAME);
configurationModelConfigurationAccessor = Mockito.mock(ConfigurationModelConfigurationAccessor.class);
providerConfiguration = new ConfigurationModel(1L, 1L, "createdAt", "lastModified", ConfigContextEnum.GLOBAL, Map.of(PROVIDER_CONFIG_NAME, configurationFieldModel));
Mockito.when(configurationModelConfigurationAccessor.getConfigurationById(1L)).thenReturn(Optional.of(providerConfiguration));
Mockito.when(configurationModelConfigurationAccessor.getProviderConfigurationByName(Mockito.anyString())).thenReturn(Optional.of(providerConfiguration));
}
use of com.synopsys.integration.alert.common.persistence.model.ConfigurationFieldModel in project hub-alert by blackducksoftware.
the class BlackDuckGlobalApiAction method handleNewOrUpdatedConfig.
private void handleNewOrUpdatedConfig(FieldModel currentFieldModel) throws AlertException {
Optional<String> providerConfigName = currentFieldModel.getFieldValue(ProviderDescriptor.KEY_PROVIDER_CONFIG_NAME);
if (providerConfigName.isPresent()) {
Optional<ConfigurationModel> retrievedConfig = configurationModelConfigurationAccessor.getProviderConfigurationByName(providerConfigName.get());
if (retrievedConfig.isPresent()) {
ConfigurationModel blackDuckGlobalConfig = retrievedConfig.get();
boolean valid = blackDuckProvider.validate(blackDuckGlobalConfig);
boolean enabled = blackDuckGlobalConfig.getField(ProviderDescriptor.KEY_PROVIDER_CONFIG_ENABLED).flatMap(ConfigurationFieldModel::getFieldValue).map(Boolean::parseBoolean).orElse(false);
if (valid && enabled) {
providerLifecycleManager.scheduleTasksForProviderConfig(blackDuckProvider, retrievedConfig.get());
}
}
}
}
use of com.synopsys.integration.alert.common.persistence.model.ConfigurationFieldModel in project hub-alert by blackducksoftware.
the class LdapManagerTest method testAuthenticationTypeDigest.
@Test
public void testAuthenticationTypeDigest() throws Exception {
final String authenticationType = "digest";
ConfigurationModel configurationModel = createConfigurationModel();
configurationModel.getField(AuthenticationDescriptor.KEY_LDAP_AUTHENTICATION_TYPE).get().setFieldValue(authenticationType);
DefaultConfigurationModelConfigurationAccessor configurationModelConfigurationAccessor = Mockito.mock(DefaultConfigurationModelConfigurationAccessor.class);
Mockito.when(configurationModelConfigurationAccessor.getConfigurationsByDescriptorKey(Mockito.any(DescriptorKey.class))).thenReturn(List.of(configurationModel));
UserManagementAuthoritiesPopulator authoritiesPopulator = Mockito.mock(UserManagementAuthoritiesPopulator.class);
LdapManager ldapManager = new LdapManager(AUTHENTICATION_DESCRIPTOR_KEY, configurationModelConfigurationAccessor, authoritiesPopulator, LDAP_USER_CONTEXT_MAPPER);
ldapManager.getAuthenticationProvider();
FieldUtility updatedProperties = ldapManager.getCurrentConfiguration();
assertEquals(authenticationType, updatedProperties.getField(AuthenticationDescriptor.KEY_LDAP_AUTHENTICATION_TYPE).flatMap(ConfigurationFieldModel::getFieldValue).orElse(null));
}
Aggregations