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();
}
Aggregations