Search in sources :

Example 1 with ConfigContextEnum

use of com.synopsys.integration.alert.common.enumeration.ConfigContextEnum in project hub-alert by blackducksoftware.

the class DefaultDescriptorAccessorTest method getFieldsForDescriptorByIdTest.

@Test
public void getFieldsForDescriptorByIdTest() {
    final String name = "name-test";
    final Long typeId = 1L;
    final ConfigContextEnum configContextEnum = ConfigContextEnum.GLOBAL;
    final String definedFieldsKey = "defined-field-key-test";
    Boolean isSensitive = Boolean.TRUE;
    final Long descriptorId = 1L;
    RegisteredDescriptorEntity registeredDescriptorEntity = new RegisteredDescriptorEntity(name, typeId);
    registeredDescriptorEntity.setId(1L);
    ConfigContextEntity configContextEntity = new ConfigContextEntity(configContextEnum.name());
    configContextEntity.setId(3L);
    DefinedFieldEntity definedFieldEntity = new DefinedFieldEntity(definedFieldsKey, isSensitive);
    RegisteredDescriptorRepository registeredDescriptorRepository = Mockito.mock(RegisteredDescriptorRepository.class);
    DefinedFieldRepository definedFieldRepository = Mockito.mock(DefinedFieldRepository.class);
    ConfigContextRepository configContextRepository = Mockito.mock(ConfigContextRepository.class);
    DescriptorTypeRepository descriptorTypeRepository = Mockito.mock(DescriptorTypeRepository.class);
    Mockito.when(registeredDescriptorRepository.findById(descriptorId)).thenReturn(Optional.of(registeredDescriptorEntity));
    Mockito.when(configContextRepository.findFirstByContext(configContextEnum.name())).thenReturn(Optional.of(configContextEntity));
    Mockito.when(definedFieldRepository.findByDescriptorIdAndContext(Mockito.any(), Mockito.any())).thenReturn(List.of(definedFieldEntity));
    DefaultDescriptorAccessor descriptorAccessor = new DefaultDescriptorAccessor(registeredDescriptorRepository, definedFieldRepository, configContextRepository, descriptorTypeRepository);
    List<DefinedFieldModel> definedFieldModelList = descriptorAccessor.getFieldsForDescriptorById(descriptorId, configContextEnum);
    assertEquals(1, definedFieldModelList.size());
    DefinedFieldModel definedFieldModel = definedFieldModelList.get(0);
    assertEquals(definedFieldsKey, definedFieldModel.getKey());
    assertEquals(isSensitive, definedFieldModel.getSensitive());
    List<ConfigContextEnum> configContextList = new ArrayList<>(definedFieldModel.getContexts());
    assertEquals(configContextEnum, configContextList.get(0));
}
Also used : DefinedFieldModel(com.synopsys.integration.alert.common.persistence.model.DefinedFieldModel) RegisteredDescriptorEntity(com.synopsys.integration.alert.database.configuration.RegisteredDescriptorEntity) ArrayList(java.util.ArrayList) DefinedFieldEntity(com.synopsys.integration.alert.database.configuration.DefinedFieldEntity) DefinedFieldRepository(com.synopsys.integration.alert.database.configuration.repository.DefinedFieldRepository) ConfigContextRepository(com.synopsys.integration.alert.database.configuration.repository.ConfigContextRepository) DescriptorTypeRepository(com.synopsys.integration.alert.database.configuration.repository.DescriptorTypeRepository) ConfigContextEnum(com.synopsys.integration.alert.common.enumeration.ConfigContextEnum) RegisteredDescriptorRepository(com.synopsys.integration.alert.database.configuration.repository.RegisteredDescriptorRepository) ConfigContextEntity(com.synopsys.integration.alert.database.configuration.ConfigContextEntity) Test(org.junit.jupiter.api.Test)

Example 2 with ConfigContextEnum

use of com.synopsys.integration.alert.common.enumeration.ConfigContextEnum in project hub-alert by blackducksoftware.

the class AbstractJobResourceActions method checkContextAndDescriptorKey.

private boolean checkContextAndDescriptorKey(FieldModel fieldModel, BiFunction<ConfigContextEnum, DescriptorKey, Boolean> permissionChecker) {
    ConfigContextEnum configContextEnum = ConfigContextEnum.valueOf(fieldModel.getContext());
    DescriptorKey descriptorKey = descriptorMap.getDescriptorKey(fieldModel.getDescriptorName()).orElseThrow(() -> new AlertRuntimeException("Could not find DescriptorKey for: " + fieldModel.getDescriptorName()));
    return permissionChecker.apply(configContextEnum, descriptorKey);
}
Also used : DescriptorKey(com.synopsys.integration.alert.descriptor.api.model.DescriptorKey) AlertRuntimeException(com.synopsys.integration.alert.api.common.model.exception.AlertRuntimeException) ConfigContextEnum(com.synopsys.integration.alert.common.enumeration.ConfigContextEnum)

Example 3 with ConfigContextEnum

use of com.synopsys.integration.alert.common.enumeration.ConfigContextEnum in project hub-alert by blackducksoftware.

the class ConfigActions method readAllByContextAndDescriptorWithoutChecks.

@Override
protected ActionResponse<MultiFieldModel> readAllByContextAndDescriptorWithoutChecks(String context, String descriptorName) {
    ConfigContextEnum configContext = ConfigContextEnum.valueOf(context);
    Optional<DescriptorKey> descriptorKey = descriptorMap.getDescriptorKey(descriptorName);
    if (!descriptorKey.isPresent()) {
        return new ActionResponse<>(HttpStatus.BAD_REQUEST, String.format("Unknown descriptor: %s", descriptorName));
    }
    List<ConfigurationModel> configurationModels = configurationModelConfigurationAccessor.getConfigurationsByDescriptorKeyAndContext(descriptorKey.get(), configContext);
    List<FieldModel> fieldModels = convertConfigurationModelList(descriptorName, context, configurationModels);
    return new ActionResponse<>(HttpStatus.OK, new MultiFieldModel(fieldModels));
}
Also used : ConfigurationModel(com.synopsys.integration.alert.common.persistence.model.ConfigurationModel) SettingsDescriptorKey(com.synopsys.integration.alert.component.settings.descriptor.SettingsDescriptorKey) DescriptorKey(com.synopsys.integration.alert.descriptor.api.model.DescriptorKey) MultiFieldModel(com.synopsys.integration.alert.common.rest.model.MultiFieldModel) ConfigContextEnum(com.synopsys.integration.alert.common.enumeration.ConfigContextEnum) ConfigurationFieldModel(com.synopsys.integration.alert.common.persistence.model.ConfigurationFieldModel) FieldModel(com.synopsys.integration.alert.common.rest.model.FieldModel) MultiFieldModel(com.synopsys.integration.alert.common.rest.model.MultiFieldModel) ValidationActionResponse(com.synopsys.integration.alert.common.action.ValidationActionResponse) ActionResponse(com.synopsys.integration.alert.common.action.ActionResponse)

Example 4 with ConfigContextEnum

use of com.synopsys.integration.alert.common.enumeration.ConfigContextEnum in project hub-alert by blackducksoftware.

the class DescriptorMetadataActionsTest method getDescriptorsWithAllParametersTest.

@Test
public void getDescriptorsWithAllParametersTest() {
    DescriptorType type1 = DescriptorType.CHANNEL;
    String componentName1 = getNamePrefix(type1) + "_2";
    ConfigContextEnum context1 = ConfigContextEnum.GLOBAL;
    ActionResponse<DescriptorsResponseModel> response1 = actions.getDescriptorsByPermissions(componentName1, type1.name(), context1.name());
    assertTrue(response1.isSuccessful());
    assertTrue(response1.hasContent());
    Set<DescriptorMetadata> descriptorMetadata1 = response1.getContent().get().getDescriptors();
    assertEquals(1, descriptorMetadata1.size());
}
Also used : DescriptorType(com.synopsys.integration.alert.common.enumeration.DescriptorType) DescriptorMetadata(com.synopsys.integration.alert.common.descriptor.config.ui.DescriptorMetadata) ConfigContextEnum(com.synopsys.integration.alert.common.enumeration.ConfigContextEnum) DescriptorsResponseModel(com.synopsys.integration.alert.web.api.metadata.model.DescriptorsResponseModel) Test(org.junit.jupiter.api.Test)

Example 5 with ConfigContextEnum

use of com.synopsys.integration.alert.common.enumeration.ConfigContextEnum in project hub-alert by blackducksoftware.

the class DefaultDescriptorAccessorTest method getFieldsForDescriptorTest.

@Test
public void getFieldsForDescriptorTest() {
    final String name = "name-test";
    final Long typeId = 1L;
    final ConfigContextEnum configContextEnum = ConfigContextEnum.GLOBAL;
    final ConfigContextEnum invalidConfigContextEnum = ConfigContextEnum.DISTRIBUTION;
    final String definedFieldsKey = "defined-field-key-test";
    Boolean isSensitive = Boolean.TRUE;
    RegisteredDescriptorEntity registeredDescriptorEntity = new RegisteredDescriptorEntity(name, typeId);
    registeredDescriptorEntity.setId(1L);
    DescriptorKey descriptorKey = createDescriptorKey("descriptorKey-test");
    ConfigContextEntity configContextEntity = new ConfigContextEntity(configContextEnum.name());
    configContextEntity.setId(3L);
    DefinedFieldEntity definedFieldEntity = new DefinedFieldEntity(definedFieldsKey, isSensitive);
    RegisteredDescriptorRepository registeredDescriptorRepository = Mockito.mock(RegisteredDescriptorRepository.class);
    DefinedFieldRepository definedFieldRepository = Mockito.mock(DefinedFieldRepository.class);
    ConfigContextRepository configContextRepository = Mockito.mock(ConfigContextRepository.class);
    DescriptorTypeRepository descriptorTypeRepository = Mockito.mock(DescriptorTypeRepository.class);
    Mockito.when(registeredDescriptorRepository.findFirstByName(descriptorKey.getUniversalKey())).thenReturn(Optional.of(registeredDescriptorEntity));
    Mockito.when(configContextRepository.findFirstByContext(configContextEnum.name())).thenReturn(Optional.of(configContextEntity));
    // Used to test the optional expression
    Mockito.when(configContextRepository.findFirstByContext(invalidConfigContextEnum.name())).thenReturn(Optional.empty());
    Mockito.when(configContextRepository.save(Mockito.any())).thenReturn(configContextEntity);
    Mockito.when(definedFieldRepository.findByDescriptorIdAndContext(Mockito.any(), Mockito.any())).thenReturn(List.of(definedFieldEntity));
    DefaultDescriptorAccessor descriptorAccessor = new DefaultDescriptorAccessor(registeredDescriptorRepository, definedFieldRepository, configContextRepository, descriptorTypeRepository);
    List<DefinedFieldModel> definedFieldModelList = descriptorAccessor.getFieldsForDescriptor(descriptorKey, configContextEnum);
    List<DefinedFieldModel> emptyConfigContextDefinedFieldModelList = descriptorAccessor.getFieldsForDescriptor(descriptorKey, invalidConfigContextEnum);
    assertEquals(1, definedFieldModelList.size());
    DefinedFieldModel definedFieldModel = definedFieldModelList.get(0);
    assertEquals(definedFieldsKey, definedFieldModel.getKey());
    assertEquals(isSensitive, definedFieldModel.getSensitive());
    List<ConfigContextEnum> configContextList = new ArrayList<>(definedFieldModel.getContexts());
    assertEquals(configContextEnum, configContextList.get(0));
    assertEquals(1, emptyConfigContextDefinedFieldModelList.size());
    DefinedFieldModel emptyConfigContextDefinedFieldModel = emptyConfigContextDefinedFieldModelList.get(0);
    assertEquals(definedFieldsKey, emptyConfigContextDefinedFieldModel.getKey());
    assertEquals(isSensitive, emptyConfigContextDefinedFieldModel.getSensitive());
    List<ConfigContextEnum> configContextList2 = new ArrayList<>(emptyConfigContextDefinedFieldModel.getContexts());
    assertEquals(invalidConfigContextEnum, configContextList2.get(0));
}
Also used : DefinedFieldModel(com.synopsys.integration.alert.common.persistence.model.DefinedFieldModel) RegisteredDescriptorEntity(com.synopsys.integration.alert.database.configuration.RegisteredDescriptorEntity) ArrayList(java.util.ArrayList) DescriptorKey(com.synopsys.integration.alert.descriptor.api.model.DescriptorKey) DefinedFieldEntity(com.synopsys.integration.alert.database.configuration.DefinedFieldEntity) DefinedFieldRepository(com.synopsys.integration.alert.database.configuration.repository.DefinedFieldRepository) ConfigContextRepository(com.synopsys.integration.alert.database.configuration.repository.ConfigContextRepository) DescriptorTypeRepository(com.synopsys.integration.alert.database.configuration.repository.DescriptorTypeRepository) ConfigContextEnum(com.synopsys.integration.alert.common.enumeration.ConfigContextEnum) RegisteredDescriptorRepository(com.synopsys.integration.alert.database.configuration.repository.RegisteredDescriptorRepository) ConfigContextEntity(com.synopsys.integration.alert.database.configuration.ConfigContextEntity) Test(org.junit.jupiter.api.Test)

Aggregations

ConfigContextEnum (com.synopsys.integration.alert.common.enumeration.ConfigContextEnum)12 DescriptorKey (com.synopsys.integration.alert.descriptor.api.model.DescriptorKey)7 Test (org.junit.jupiter.api.Test)5 DescriptorMetadata (com.synopsys.integration.alert.common.descriptor.config.ui.DescriptorMetadata)4 DescriptorsResponseModel (com.synopsys.integration.alert.web.api.metadata.model.DescriptorsResponseModel)4 Optional (java.util.Optional)4 Autowired (org.springframework.beans.factory.annotation.Autowired)4 Component (org.springframework.stereotype.Component)4 DescriptorType (com.synopsys.integration.alert.common.enumeration.DescriptorType)3 ConfigurationModel (com.synopsys.integration.alert.common.persistence.model.ConfigurationModel)3 DefinedFieldModel (com.synopsys.integration.alert.common.persistence.model.DefinedFieldModel)3 FieldModel (com.synopsys.integration.alert.common.rest.model.FieldModel)3 ConfigContextEntity (com.synopsys.integration.alert.database.configuration.ConfigContextEntity)3 DefinedFieldEntity (com.synopsys.integration.alert.database.configuration.DefinedFieldEntity)3 Collection (java.util.Collection)3 HashMap (java.util.HashMap)3 Map (java.util.Map)3 StringUtils (org.apache.commons.lang3.StringUtils)3 AlertRuntimeException (com.synopsys.integration.alert.api.common.model.exception.AlertRuntimeException)2 ActionResponse (com.synopsys.integration.alert.common.action.ActionResponse)2