001package jmri.server.json.audioicon; 002 003import com.fasterxml.jackson.databind.JsonNode; 004import com.fasterxml.jackson.databind.ObjectMapper; 005import com.fasterxml.jackson.databind.node.ObjectNode; 006 007import javax.servlet.http.HttpServletResponse; 008 009import jmri.server.json.*; 010import static jmri.server.json.audioicon.JsonAudioIconServiceFactory.AUDIO_ICON; 011 012 013/** 014 * Provide JSON HTTP services for managing {@link jmri.jmrit.display.AudioIcon}s. 015 * 016 * @author Randall Wood Copyright 2016, 2018 017 * @author Daniel Bergqvist (C) 2023 018 */ 019public class JsonAudioIconHttpService extends JsonHttpService { 020 021 public JsonAudioIconHttpService(ObjectMapper mapper) { 022 super(mapper); 023 } 024 025 @Override 026 public JsonNode doGet(String type, String name, JsonNode data, JsonRequest request) throws JsonException { 027 ObjectNode theData = mapper.createObjectNode(); 028 theData.put(JSON.AUDIO_ICON_IDENTITY, data.get("identity").asInt()); 029 theData.put(JSON.AUDIO_COMMAND, JSON.AUDIO_COMMAND_NONE); 030 return message(AUDIO_ICON, theData, request.id); 031 } 032 033 @Override 034 public JsonNode doPost(String type, String name, JsonNode data, JsonRequest request) throws JsonException { 035 throw new JsonException(HttpServletResponse.SC_METHOD_NOT_ALLOWED, Bundle.getMessage(request.locale, "PostNotAllowed", type), request.id); 036 } 037 038 @Override 039 public JsonNode doPut(String type, String name, JsonNode data, JsonRequest request) throws JsonException { 040 throw new JsonException(HttpServletResponse.SC_METHOD_NOT_ALLOWED, Bundle.getMessage(request.locale, "PutNotAllowed", type), request.id); 041 } 042 043 @Override 044 public JsonNode doSchema(String type, boolean server, JsonRequest request) throws JsonException { 045 switch (type) { 046 case AUDIO_ICON: 047 return doSchema(type, 048 server, 049 "jmri/server/json/audioicon/audioicon-server.json", 050 "jmri/server/json/audioicon/audioicon-client.json", 051 request.id); 052 default: 053 throw new JsonException(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, Bundle.getMessage(request.locale, JsonException.ERROR_UNKNOWN_TYPE, type), request.id); 054 } 055 } 056 057 @Override 058 public void doDelete(String type, String name, JsonNode data, JsonRequest request) throws JsonException { 059 throw new JsonException(HttpServletResponse.SC_METHOD_NOT_ALLOWED, Bundle.getMessage(request.locale, "DeleteNotAllowed", type), request.id); 060 } 061 062 @Override 063 public JsonNode doGetList(String type, JsonNode data, JsonRequest request) throws JsonException { 064 throw new JsonException(HttpServletResponse.SC_METHOD_NOT_ALLOWED, Bundle.getMessage(request.locale, "GetListNotAllowed", type), request.id); 065 } 066 067// private final static org.slf4j.Logger log = org.slf4j.LoggerFactory.getLogger(JsonAudioIconHttpService.class); 068}