Search in sources :

Example 1 with DescriptorsResponseModel

use of com.synopsys.integration.alert.web.api.metadata.model.DescriptorsResponseModel in project hub-alert by blackducksoftware.

the class AboutReader method getDescriptorData.

private Set<DescriptorMetadata> getDescriptorData(DescriptorType descriptorType) {
    Set<DescriptorMetadata> descriptorData = Set.of();
    ActionResponse<DescriptorsResponseModel> response = descriptorActions.getDescriptorsByType(descriptorType.name());
    if (response.hasContent()) {
        DescriptorsResponseModel providersData = response.getContent().get();
        descriptorData = providersData.getDescriptors();
    }
    return descriptorData;
}
Also used : DescriptorMetadata(com.synopsys.integration.alert.common.descriptor.config.ui.DescriptorMetadata) DescriptorsResponseModel(com.synopsys.integration.alert.web.api.metadata.model.DescriptorsResponseModel)

Example 2 with DescriptorsResponseModel

use of com.synopsys.integration.alert.web.api.metadata.model.DescriptorsResponseModel 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 3 with DescriptorsResponseModel

use of com.synopsys.integration.alert.web.api.metadata.model.DescriptorsResponseModel in project hub-alert by blackducksoftware.

the class DescriptorControllerTestIT method getDescriptorsWithAllParametersTest.

@Test
public void getDescriptorsWithAllParametersTest() throws Exception {
    String msTeams = ChannelKeys.MS_TEAMS.getUniversalKey();
    URI descriptorPath = new URIBuilder(DescriptorController.BASE_PATH).addParameter("name", msTeams).addParameter("type", DescriptorType.CHANNEL.name()).addParameter("context", ConfigContextEnum.GLOBAL.name()).build();
    MockHttpServletRequestBuilder request = MockMvcRequestBuilders.get(descriptorPath).with(SecurityMockMvcRequestPostProcessors.user("admin").roles(AlertIntegrationTestConstants.ROLE_ALERT_ADMIN)).with(SecurityMockMvcRequestPostProcessors.csrf());
    DescriptorsResponseModel descriptorsResponseModel = assertValidResponse(request);
    assertEquals(1, descriptorsResponseModel.getDescriptors().size());
}
Also used : MockHttpServletRequestBuilder(org.springframework.test.web.servlet.request.MockHttpServletRequestBuilder) URI(java.net.URI) URIBuilder(org.apache.http.client.utils.URIBuilder) DescriptorsResponseModel(com.synopsys.integration.alert.web.api.metadata.model.DescriptorsResponseModel) AlertIntegrationTest(com.synopsys.integration.alert.util.AlertIntegrationTest) Test(org.junit.jupiter.api.Test)

Example 4 with DescriptorsResponseModel

use of com.synopsys.integration.alert.web.api.metadata.model.DescriptorsResponseModel in project hub-alert by blackducksoftware.

the class DescriptorControllerTestIT method assertValidResponse.

private DescriptorsResponseModel assertValidResponse(MockHttpServletRequestBuilder request) throws Exception {
    MvcResult mvcResult = mockMvc.perform(request).andExpect(MockMvcResultMatchers.status().isOk()).andReturn();
    String listOfDescriptorsJson = mvcResult.getResponse().getContentAsString();
    DescriptorsResponseModel descriptorsResponseModel = new Gson().fromJson(listOfDescriptorsJson, DescriptorsResponseModel.class);
    Set<DescriptorMetadata> setOfDescriptors = descriptorsResponseModel.getDescriptors();
    assertTrue(setOfDescriptors.size() > 0);
    return descriptorsResponseModel;
}
Also used : DescriptorMetadata(com.synopsys.integration.alert.common.descriptor.config.ui.DescriptorMetadata) Gson(com.google.gson.Gson) MvcResult(org.springframework.test.web.servlet.MvcResult) DescriptorsResponseModel(com.synopsys.integration.alert.web.api.metadata.model.DescriptorsResponseModel)

Example 5 with DescriptorsResponseModel

use of com.synopsys.integration.alert.web.api.metadata.model.DescriptorsResponseModel in project hub-alert by blackducksoftware.

the class DescriptorMetadataActions method getDescriptorsByPermissions.

public ActionResponse<DescriptorsResponseModel> getDescriptorsByPermissions(@Nullable String name, @Nullable String type, @Nullable String context) {
    Predicate<Descriptor> descriptorFilter = ignored -> true;
    Set<ConfigContextEnum> requestedContexts = Set.of(ConfigContextEnum.GLOBAL, ConfigContextEnum.DISTRIBUTION);
    if (StringUtils.isNotBlank(name)) {
        descriptorFilter = descriptorFilter.and(descriptor -> name.equals(descriptor.getDescriptorKey().getUniversalKey()));
    }
    if (StringUtils.isNotBlank(type)) {
        descriptorFilter = descriptorFilter.and(descriptor -> type.equals(descriptor.getType().name()));
    }
    if (StringUtils.isNotBlank(context)) {
        ConfigContextEnum requestedContext = EnumUtils.getEnum(ConfigContextEnum.class, context);
        if (null != requestedContext) {
            requestedContexts = Set.of(requestedContext);
        } else {
            requestedContexts = Set.of();
        }
    }
    return createDescriptorResponse(descriptorFilter, requestedContexts);
}
Also used : Descriptor(com.synopsys.integration.alert.common.descriptor.Descriptor) AuthorizationManager(com.synopsys.integration.alert.common.security.authorization.AuthorizationManager) DescriptorMetadata(com.synopsys.integration.alert.common.descriptor.config.ui.DescriptorMetadata) Predicate(java.util.function.Predicate) AccessOperation(com.synopsys.integration.alert.common.enumeration.AccessOperation) Collection(java.util.Collection) Set(java.util.Set) Autowired(org.springframework.beans.factory.annotation.Autowired) ConfigContextEnum(com.synopsys.integration.alert.common.enumeration.ConfigContextEnum) Collectors(java.util.stream.Collectors) StringUtils(org.apache.commons.lang3.StringUtils) HashSet(java.util.HashSet) Nullable(org.jetbrains.annotations.Nullable) HttpStatus(org.springframework.http.HttpStatus) Component(org.springframework.stereotype.Component) ActionResponse(com.synopsys.integration.alert.common.action.ActionResponse) DescriptorKey(com.synopsys.integration.alert.descriptor.api.model.DescriptorKey) EnumUtils(org.apache.commons.lang3.EnumUtils) Optional(java.util.Optional) DescriptorType(com.synopsys.integration.alert.common.enumeration.DescriptorType) DescriptorsResponseModel(com.synopsys.integration.alert.web.api.metadata.model.DescriptorsResponseModel) Descriptor(com.synopsys.integration.alert.common.descriptor.Descriptor) ConfigContextEnum(com.synopsys.integration.alert.common.enumeration.ConfigContextEnum)

Aggregations

DescriptorsResponseModel (com.synopsys.integration.alert.web.api.metadata.model.DescriptorsResponseModel)13 DescriptorMetadata (com.synopsys.integration.alert.common.descriptor.config.ui.DescriptorMetadata)8 Test (org.junit.jupiter.api.Test)8 ConfigContextEnum (com.synopsys.integration.alert.common.enumeration.ConfigContextEnum)5 DescriptorType (com.synopsys.integration.alert.common.enumeration.DescriptorType)3 AlertIntegrationTest (com.synopsys.integration.alert.util.AlertIntegrationTest)3 URI (java.net.URI)3 MockHttpServletRequestBuilder (org.springframework.test.web.servlet.request.MockHttpServletRequestBuilder)3 ActionResponse (com.synopsys.integration.alert.common.action.ActionResponse)2 AccessOperation (com.synopsys.integration.alert.common.enumeration.AccessOperation)2 AlertWebServerUrlManager (com.synopsys.integration.alert.common.rest.AlertWebServerUrlManager)2 AuthorizationManager (com.synopsys.integration.alert.common.security.authorization.AuthorizationManager)2 DefaultSystemStatusAccessor (com.synopsys.integration.alert.database.api.DefaultSystemStatusAccessor)2 DescriptorKey (com.synopsys.integration.alert.descriptor.api.model.DescriptorKey)2 DescriptorMetadataActions (com.synopsys.integration.alert.web.api.metadata.DescriptorMetadataActions)2 URIBuilder (org.apache.http.client.utils.URIBuilder)2 Gson (com.google.gson.Gson)1 AlertProperties (com.synopsys.integration.alert.common.AlertProperties)1 Descriptor (com.synopsys.integration.alert.common.descriptor.Descriptor)1 SystemMessageModel (com.synopsys.integration.alert.common.persistence.model.SystemMessageModel)1