1 /* 2 * CDDL HEADER START 3 * 4 * The contents of this file are subject to the terms of the 5 * Common Development and Distribution License (the "License"). 6 * You may not use this file except in compliance with the License. 7 * 8 * See LICENSE.txt included in this distribution for the specific 9 * language governing permissions and limitations under the License. 10 * 11 * When distributing Covered Code, include this CDDL HEADER in each 12 * file and include the License file at LICENSE.txt. 13 * If applicable, add the following below this CDDL HEADER, with the 14 * fields enclosed by brackets "[]" replaced with your own identifying 15 * information: Portions Copyright [yyyy] [name of copyright owner] 16 * 17 * CDDL HEADER END 18 */ 19 20 /* 21 * Copyright (c) 2018, 2019, Oracle and/or its affiliates. All rights reserved. 22 */ 23 package org.opengrok.web.api.v1.controller; 24 25 import jakarta.validation.Valid; 26 import jakarta.ws.rs.Consumes; 27 import jakarta.ws.rs.DELETE; 28 import jakarta.ws.rs.GET; 29 import jakarta.ws.rs.POST; 30 import jakarta.ws.rs.Path; 31 import jakarta.ws.rs.Produces; 32 import jakarta.ws.rs.QueryParam; 33 import jakarta.ws.rs.WebApplicationException; 34 import jakarta.ws.rs.core.MediaType; 35 import jakarta.ws.rs.core.Response; 36 import org.opengrok.indexer.configuration.RuntimeEnvironment; 37 import org.opengrok.indexer.web.messages.Message; 38 import org.opengrok.indexer.web.messages.MessagesContainer.AcceptedMessage; 39 40 import java.util.Collections; 41 import java.util.Set; 42 43 @Path("/messages") 44 public class MessagesController { 45 46 private final RuntimeEnvironment env = RuntimeEnvironment.getInstance(); 47 48 @POST 49 @Consumes(MediaType.APPLICATION_JSON) addMessage(@alid final Message message)50 public Response addMessage(@Valid final Message message) { 51 env.addMessage(message); 52 53 return Response.status(Response.Status.CREATED).build(); 54 } 55 56 @DELETE 57 @Consumes(MediaType.TEXT_PLAIN) removeMessagesWithTag(@ueryParam"tag") final String tag, final String text)58 public void removeMessagesWithTag(@QueryParam("tag") final String tag, final String text) { 59 if (tag == null) { 60 throw new WebApplicationException("Message tag has to be specified", Response.Status.BAD_REQUEST); 61 } 62 env.removeAnyMessage(Collections.singleton(tag), text); 63 } 64 65 @GET 66 @Produces(MediaType.APPLICATION_JSON) getMessages(@ueryParam"tag") final String tag)67 public Set<AcceptedMessage> getMessages(@QueryParam("tag") final String tag) { 68 if (tag != null) { 69 return env.getMessages(tag); 70 } else { 71 return env.getAllMessages(); 72 } 73 } 74 75 } 76