Search in sources :

Example 1 with RequestDefaultBehaviorGroupPropertyList

use of com.redhat.cloud.notifications.routers.internal.models.RequestDefaultBehaviorGroupPropertyList in project notifications-backend by RedHatInsights.

the class InternalResource method updateDefaultBehaviorGroupActions.

@PUT
@Path("/behaviorGroups/default/{behaviorGroupId}/actions")
@Consumes(APPLICATION_JSON)
@Produces(TEXT_PLAIN)
@Operation(summary = "Update the list of actions of a default behavior group.")
@APIResponse(responseCode = "200", content = @Content(schema = @Schema(type = SchemaType.STRING)))
@Transactional
@RolesAllowed(ConsoleIdentityProvider.RBAC_INTERNAL_ADMIN)
public Response updateDefaultBehaviorGroupActions(@PathParam("behaviorGroupId") UUID behaviorGroupId, List<RequestDefaultBehaviorGroupPropertyList> propertiesList) {
    if (propertiesList == null) {
        throw new BadRequestException("The request body must contain a list of EmailSubscriptionProperties");
    }
    if (propertiesList.size() != propertiesList.stream().distinct().count()) {
        throw new BadRequestException("The list of EmailSubscriptionProperties should not contain duplicates");
    }
    List<Endpoint> endpoints = propertiesList.stream().map(p -> {
        EmailSubscriptionProperties properties = new EmailSubscriptionProperties();
        properties.setOnlyAdmins(p.isOnlyAdmins());
        properties.setIgnorePreferences(p.isIgnorePreferences());
        return endpointRepository.getOrCreateEmailSubscriptionEndpoint(null, properties);
    }).collect(Collectors.toList());
    Response.Status status = behaviorGroupRepository.updateDefaultBehaviorGroupActions(behaviorGroupId, endpoints.stream().distinct().map(Endpoint::getId).collect(Collectors.toList()));
    return Response.status(status).build();
}
Also used : RedirectionException(javax.ws.rs.RedirectionException) CurrentStatus(com.redhat.cloud.notifications.models.CurrentStatus) RolesAllowed(javax.annotation.security.RolesAllowed) Produces(javax.ws.rs.Produces) Endpoint(com.redhat.cloud.notifications.models.Endpoint) Path(javax.ws.rs.Path) SecurityContext(javax.ws.rs.core.SecurityContext) Valid(javax.validation.Valid) MediaType(javax.ws.rs.core.MediaType) Matcher(java.util.regex.Matcher) Consumes(javax.ws.rs.Consumes) SchemaType(org.eclipse.microprofile.openapi.annotations.enums.SchemaType) BadRequestException(javax.ws.rs.BadRequestException) InternalRoleAccess(com.redhat.cloud.notifications.models.InternalRoleAccess) URI(java.net.URI) StartupUtils(com.redhat.cloud.notifications.StartupUtils) BehaviorGroupRepository(com.redhat.cloud.notifications.db.repositories.BehaviorGroupRepository) APPLICATION_JSON(javax.ws.rs.core.MediaType.APPLICATION_JSON) APIResponse(org.eclipse.microprofile.openapi.annotations.responses.APIResponse) DELETE(javax.ws.rs.DELETE) BAD_REQUEST(javax.ws.rs.core.Response.Status.BAD_REQUEST) Application(com.redhat.cloud.notifications.models.Application) Context(javax.ws.rs.core.Context) PermitAll(javax.annotation.security.PermitAll) Transactional(javax.transaction.Transactional) Operation(org.eclipse.microprofile.openapi.annotations.Operation) UUID(java.util.UUID) NotNull(javax.validation.constraints.NotNull) Collectors(java.util.stream.Collectors) NotFoundException(javax.ws.rs.NotFoundException) List(java.util.List) Response(javax.ws.rs.core.Response) Pattern(java.util.regex.Pattern) TEXT_PLAIN(javax.ws.rs.core.MediaType.TEXT_PLAIN) PathParam(javax.ws.rs.PathParam) EmailSubscriptionProperties(com.redhat.cloud.notifications.models.EmailSubscriptionProperties) GET(javax.ws.rs.GET) Logger(org.jboss.logging.Logger) EndpointRepository(com.redhat.cloud.notifications.db.repositories.EndpointRepository) API_INTERNAL(com.redhat.cloud.notifications.Constants.API_INTERNAL) Inject(javax.inject.Inject) EventType(com.redhat.cloud.notifications.models.EventType) OApiFilter(com.redhat.cloud.notifications.oapi.OApiFilter) ServerInfo(com.redhat.cloud.notifications.routers.internal.models.ServerInfo) BehaviorGroup(com.redhat.cloud.notifications.models.BehaviorGroup) RequestDefaultBehaviorGroupPropertyList(com.redhat.cloud.notifications.routers.internal.models.RequestDefaultBehaviorGroupPropertyList) ConsoleIdentityProvider(com.redhat.cloud.notifications.auth.ConsoleIdentityProvider) Content(org.eclipse.microprofile.openapi.annotations.media.Content) BundleRepository(com.redhat.cloud.notifications.db.repositories.BundleRepository) ApplicationRepository(com.redhat.cloud.notifications.db.repositories.ApplicationRepository) POST(javax.ws.rs.POST) Schema(org.eclipse.microprofile.openapi.annotations.media.Schema) AddApplicationRequest(com.redhat.cloud.notifications.routers.internal.models.AddApplicationRequest) Bundle(com.redhat.cloud.notifications.models.Bundle) InternalRoleAccessRepository(com.redhat.cloud.notifications.db.repositories.InternalRoleAccessRepository) SecurityContextUtil(com.redhat.cloud.notifications.routers.SecurityContextUtil) StatusRepository(com.redhat.cloud.notifications.db.repositories.StatusRepository) PUT(javax.ws.rs.PUT) APIResponse(org.eclipse.microprofile.openapi.annotations.responses.APIResponse) Response(javax.ws.rs.core.Response) Endpoint(com.redhat.cloud.notifications.models.Endpoint) EmailSubscriptionProperties(com.redhat.cloud.notifications.models.EmailSubscriptionProperties) BadRequestException(javax.ws.rs.BadRequestException) Path(javax.ws.rs.Path) APIResponse(org.eclipse.microprofile.openapi.annotations.responses.APIResponse) RolesAllowed(javax.annotation.security.RolesAllowed) Consumes(javax.ws.rs.Consumes) Produces(javax.ws.rs.Produces) Operation(org.eclipse.microprofile.openapi.annotations.Operation) PUT(javax.ws.rs.PUT) Transactional(javax.transaction.Transactional)

Aggregations

API_INTERNAL (com.redhat.cloud.notifications.Constants.API_INTERNAL)1 StartupUtils (com.redhat.cloud.notifications.StartupUtils)1 ConsoleIdentityProvider (com.redhat.cloud.notifications.auth.ConsoleIdentityProvider)1 ApplicationRepository (com.redhat.cloud.notifications.db.repositories.ApplicationRepository)1 BehaviorGroupRepository (com.redhat.cloud.notifications.db.repositories.BehaviorGroupRepository)1 BundleRepository (com.redhat.cloud.notifications.db.repositories.BundleRepository)1 EndpointRepository (com.redhat.cloud.notifications.db.repositories.EndpointRepository)1 InternalRoleAccessRepository (com.redhat.cloud.notifications.db.repositories.InternalRoleAccessRepository)1 StatusRepository (com.redhat.cloud.notifications.db.repositories.StatusRepository)1 Application (com.redhat.cloud.notifications.models.Application)1 BehaviorGroup (com.redhat.cloud.notifications.models.BehaviorGroup)1 Bundle (com.redhat.cloud.notifications.models.Bundle)1 CurrentStatus (com.redhat.cloud.notifications.models.CurrentStatus)1 EmailSubscriptionProperties (com.redhat.cloud.notifications.models.EmailSubscriptionProperties)1 Endpoint (com.redhat.cloud.notifications.models.Endpoint)1 EventType (com.redhat.cloud.notifications.models.EventType)1 InternalRoleAccess (com.redhat.cloud.notifications.models.InternalRoleAccess)1 OApiFilter (com.redhat.cloud.notifications.oapi.OApiFilter)1 SecurityContextUtil (com.redhat.cloud.notifications.routers.SecurityContextUtil)1 AddApplicationRequest (com.redhat.cloud.notifications.routers.internal.models.AddApplicationRequest)1