diff --git a/src/main/java/org/phoebus/channelfinder/ChannelManager.java b/src/main/java/org/phoebus/channelfinder/ChannelManager.java index e1614efd..9866f818 100644 --- a/src/main/java/org/phoebus/channelfinder/ChannelManager.java +++ b/src/main/java/org/phoebus/channelfinder/ChannelManager.java @@ -2,6 +2,11 @@ import com.google.common.collect.FluentIterable; import com.google.common.collect.Lists; +import io.swagger.v3.oas.annotations.media.ArraySchema; +import io.swagger.v3.oas.annotations.media.Content; +import io.swagger.v3.oas.annotations.media.Schema; +import io.swagger.v3.oas.annotations.responses.ApiResponse; +import io.swagger.v3.oas.annotations.responses.ApiResponses; import org.phoebus.channelfinder.AuthorizationService.ROLES; import org.phoebus.channelfinder.entity.Channel; import org.phoebus.channelfinder.entity.Property; @@ -72,6 +77,22 @@ public class ChannelManager { * @param allRequestParams query parameters * @return list of all channels */ + @ApiResponses( + value = { + @ApiResponse( + responseCode = "200", + description = "List of channels", + content = @Content( + array = @ArraySchema(schema = @Schema(implementation = Channel.class)))), + @ApiResponse( + responseCode = "400", + description = "Invalid request", + content = @Content(schema = @Schema(implementation = ResponseStatusException.class))), + @ApiResponse( + responseCode = "500", + description = "Error while trying to find all channels", + content = @Content(schema = @Schema(implementation = ResponseStatusException.class))) + }) @GetMapping public List query(@RequestParam MultiValueMap allRequestParams) { return channelRepository.search(allRequestParams).channels(); @@ -85,18 +106,45 @@ public List query(@RequestParam MultiValueMap allReques * @param allRequestParams query parameters * @return SearchResult a count to the total number of matches and the first 10k hits */ + @ApiResponses( + value = { + @ApiResponse( + responseCode = "200", + description = "The number of matches for the query, and the first 10k channels", + content = @Content( + array = @ArraySchema(schema = @Schema(implementation = SearchResult.class)))), + @ApiResponse( + responseCode = "400", + description = "Invalid request - response size exceeded", + content = @Content(schema = @Schema(implementation = ResponseStatusException.class))), + @ApiResponse( + responseCode = "500", + description = "Error while trying to find all channels", + content = @Content(schema = @Schema(implementation = ResponseStatusException.class))) + }) @GetMapping("/combined") public SearchResult combinedQuery(@RequestParam MultiValueMap allRequestParams) { return channelRepository.search(allRequestParams); } /** - * GET method for quering the number of matches to a multi-parameter query specifying patterns for tags, property values, and + * GET method for querying the number of matches to a multi-parameter query specifying patterns for tags, property values, and * channel names to match against. * * @param allRequestParams query parameters * @return a total number of channels that match the query parameters */ + @ApiResponses( + value = { + @ApiResponse( + responseCode = "200", + description = "The number of channels matching the query", + content = @Content(schema = @Schema(implementation = Long.class))), + @ApiResponse( + responseCode = "500", + description = "Error while trying to count the result for channel-query", + content = @Content(schema = @Schema(implementation = ResponseStatusException.class))) + }) @GetMapping("/count") public long queryCount(@RequestParam MultiValueMap allRequestParams) { return channelRepository.count(allRequestParams); @@ -109,6 +157,17 @@ public long queryCount(@RequestParam MultiValueMap allRequestPar * @param channelName - channel name to search for * @return found channel */ + @ApiResponses( + value = { + @ApiResponse( + responseCode = "200", + description = "Channel with the specified name", + content = @Content(schema = @Schema(implementation = Channel.class))), + @ApiResponse( + responseCode = "404", + description = "Channel not found", + content = @Content(schema = @Schema(implementation = ResponseStatusException.class))) + }) @GetMapping("/{channelName}") public Channel read(@PathVariable("channelName") String channelName) { channelManagerAudit.log(Level.INFO, () -> MessageFormat.format(TextUtil.FIND_CHANNEL, channelName)); @@ -132,6 +191,29 @@ public Channel read(@PathVariable("channelName") String channelName) { * @param channel - new data (properties/tags) for channel chan * @return the created channel */ + @ApiResponses( + value = { + @ApiResponse( + responseCode = "200", + description = "The created/replaced channel", + content = @Content(schema = @Schema(implementation = Channel.class))), + @ApiResponse( + responseCode = "400", + description = "Invalid request", + content = @Content(schema = @Schema(implementation = ResponseStatusException.class))), + @ApiResponse( + responseCode = "401", + description = "Unauthorized", + content = @Content(schema = @Schema(implementation = ResponseStatusException.class))), + @ApiResponse( + responseCode = "404", + description = "Channel, Tag, or property not found", + content = @Content(schema = @Schema(implementation = ResponseStatusException.class))), + @ApiResponse( + responseCode = "500", + description = "Error while trying to create channel", + content = @Content(schema = @Schema(implementation = ResponseStatusException.class))) + }) @PutMapping("/{channelName}") public Channel create(@PathVariable("channelName") String channelName, @RequestBody Channel channel) { // check if authorized role @@ -172,6 +254,30 @@ public Channel create(@PathVariable("channelName") String channelName, @RequestB * @param channels - XmlChannels to be created * @return the list of channels created */ + @ApiResponses( + value = { + @ApiResponse( + responseCode = "200", + description = "The created/replaced channels", + content = @Content( + array = @ArraySchema(schema = @Schema(implementation = Channel.class)))), + @ApiResponse( + responseCode = "400", + description = "Invalid request", + content = @Content(schema = @Schema(implementation = ResponseStatusException.class))), + @ApiResponse( + responseCode = "401", + description = "Unauthorized", + content = @Content(schema = @Schema(implementation = ResponseStatusException.class))), + @ApiResponse( + responseCode = "404", + description = "Tag, or property not found", + content = @Content(schema = @Schema(implementation = ResponseStatusException.class))), + @ApiResponse( + responseCode = "500", + description = "Error while trying to create channels", + content = @Content(schema = @Schema(implementation = ResponseStatusException.class))) + }) @PutMapping public Iterable create(@RequestBody Iterable channels) { // check if authorized role @@ -249,6 +355,29 @@ private void resetOwnersToExisting(Iterable channels) { * @param channel - new Channel data (properties/tags) to be merged into channel channelName * @return the updated channel */ + @ApiResponses( + value = { + @ApiResponse( + responseCode = "200", + description = "The updated channel", + content = @Content(schema = @Schema(implementation = Channel.class))), + @ApiResponse( + responseCode = "400", + description = "Invalid request", + content = @Content(schema = @Schema(implementation = ResponseStatusException.class))), + @ApiResponse( + responseCode = "401", + description = "Unauthorized", + content = @Content(schema = @Schema(implementation = ResponseStatusException.class))), + @ApiResponse( + responseCode = "404", + description = "Channel, Tag, or property not found", + content = @Content(schema = @Schema(implementation = ResponseStatusException.class))), + @ApiResponse( + responseCode = "500", + description = "Error while trying to update channel", + content = @Content(schema = @Schema(implementation = ResponseStatusException.class))) + }) @PostMapping("/{channelName}") public Channel update(@PathVariable("channelName") String channelName, @RequestBody Channel channel) { if(authorizationService.isAuthorizedRole(SecurityContextHolder.getContext().getAuthentication(), ROLES.CF_CHANNEL)) { @@ -305,6 +434,29 @@ public Channel update(@PathVariable("channelName") String channelName, @RequestB * @param channels - XmlChannels to be updated * @return the updated channels */ + @ApiResponses( + value = { + @ApiResponse( + responseCode = "200", + description = "The updated channels", + content = @Content(schema = @Schema(implementation = Channel.class))), + @ApiResponse( + responseCode = "400", + description = "Invalid request", + content = @Content(schema = @Schema(implementation = ResponseStatusException.class))), + @ApiResponse( + responseCode = "401", + description = "Unauthorized", + content = @Content(schema = @Schema(implementation = ResponseStatusException.class))), + @ApiResponse( + responseCode = "404", + description = "Channel not found", + content = @Content(schema = @Schema(implementation = ResponseStatusException.class))), + @ApiResponse( + responseCode = "500", + description = "Error while trying to update channels", + content = @Content(schema = @Schema(implementation = ResponseStatusException.class))) + }) @PostMapping() public Iterable update(@RequestBody Iterable channels) { // check if authorized role @@ -351,6 +503,24 @@ public Iterable update(@RequestBody Iterable channels) { * * @param channelName - name of channel to remove */ + @ApiResponses( + value = { + @ApiResponse( + responseCode = "200", + description = "Channel deleted"), + @ApiResponse( + responseCode = "401", + description = "Unauthorized", + content = @Content(schema = @Schema(implementation = ResponseStatusException.class))), + @ApiResponse( + responseCode = "404", + description = "Channel not found", + content = @Content(schema = @Schema(implementation = ResponseStatusException.class))), + @ApiResponse( + responseCode = "500", + description = "Error while trying to delete channel", + content = @Content(schema = @Schema(implementation = ResponseStatusException.class))) + }) @DeleteMapping("/{channelName}") public void remove(@PathVariable("channelName") String channelName) { // check if authorized role diff --git a/src/main/java/org/phoebus/channelfinder/ChannelScroll.java b/src/main/java/org/phoebus/channelfinder/ChannelScroll.java index 4c6ad7f1..c6469973 100644 --- a/src/main/java/org/phoebus/channelfinder/ChannelScroll.java +++ b/src/main/java/org/phoebus/channelfinder/ChannelScroll.java @@ -2,6 +2,10 @@ import static org.phoebus.channelfinder.CFResourceDescriptors.SCROLL_RESOURCE_URI; +import io.swagger.v3.oas.annotations.media.Content; +import io.swagger.v3.oas.annotations.media.Schema; +import io.swagger.v3.oas.annotations.responses.ApiResponse; +import io.swagger.v3.oas.annotations.responses.ApiResponses; import java.text.MessageFormat; import java.util.Comparator; import java.util.List; @@ -58,6 +62,17 @@ public class ChannelScroll { * @param allRequestParams search parameters * @return list of all channels */ + @ApiResponses( + value = { + @ApiResponse( + responseCode = "200", + description = "Scroll that contains a collection of channel instances", + content = @Content(schema = @Schema(implementation = Scroll.class))), + @ApiResponse( + responseCode = "500", + description = "Error while trying to list channels", + content = @Content(schema = @Schema(implementation = ResponseStatusException.class))) + }) @GetMapping public Scroll query(@RequestParam MultiValueMap allRequestParams) { return search(null, allRequestParams); @@ -71,6 +86,17 @@ public Scroll query(@RequestParam MultiValueMap allRequestParams * @param scrollId scroll Id * @return list of all channels */ + @ApiResponses( + value = { + @ApiResponse( + responseCode = "200", + description = "Scroll List of channels", + content = @Content(schema = @Schema(implementation = Scroll.class))), + @ApiResponse( + responseCode = "500", + description = "Error while trying to list channels", + content = @Content(schema = @Schema(implementation = ResponseStatusException.class))) + }) @GetMapping("/{scrollId}") public Scroll query(@PathVariable("scrollId") String scrollId, @RequestParam MultiValueMap searchParameters) { return search(scrollId, searchParameters); diff --git a/src/main/java/org/phoebus/channelfinder/InfoManager.java b/src/main/java/org/phoebus/channelfinder/InfoManager.java index 0c3ff353..f36ef207 100644 --- a/src/main/java/org/phoebus/channelfinder/InfoManager.java +++ b/src/main/java/org/phoebus/channelfinder/InfoManager.java @@ -2,6 +2,10 @@ import static org.phoebus.channelfinder.CFResourceDescriptors.CF_SERVICE_INFO; +import io.swagger.v3.oas.annotations.media.Content; +import io.swagger.v3.oas.annotations.media.Schema; +import io.swagger.v3.oas.annotations.responses.ApiResponse; +import io.swagger.v3.oas.annotations.responses.ApiResponses; import java.io.IOException; import java.util.LinkedHashMap; import java.util.Map; @@ -41,6 +45,12 @@ public class InfoManager { * * @return Information about the ChannelFinder service */ + @ApiResponses( + value = { + @ApiResponse( + responseCode = "200", + description = "ChannelFinder info", content = @Content(schema = @Schema(implementation = String.class))) + }) @GetMapping public String info() { diff --git a/src/main/java/org/phoebus/channelfinder/PropertyManager.java b/src/main/java/org/phoebus/channelfinder/PropertyManager.java index b565e0fe..a1e4018b 100644 --- a/src/main/java/org/phoebus/channelfinder/PropertyManager.java +++ b/src/main/java/org/phoebus/channelfinder/PropertyManager.java @@ -2,6 +2,11 @@ import static org.phoebus.channelfinder.CFResourceDescriptors.PROPERTY_RESOURCE_URI; +import io.swagger.v3.oas.annotations.media.ArraySchema; +import io.swagger.v3.oas.annotations.media.Content; +import io.swagger.v3.oas.annotations.media.Schema; +import io.swagger.v3.oas.annotations.responses.ApiResponse; +import io.swagger.v3.oas.annotations.responses.ApiResponses; import java.text.MessageFormat; import java.util.ArrayList; import java.util.Arrays; @@ -59,6 +64,19 @@ public class PropertyManager { * * @return list of all properties */ + @ApiResponses( + value = { + @ApiResponse( + responseCode = "200", + description = "List of properties", + content = @Content( + array = + @ArraySchema(schema = @Schema(implementation = Property.class)))), + @ApiResponse( + responseCode = "500", + description = "Error while listing properties", + content = @Content(schema = @Schema(implementation = ResponseStatusException.class))) + }) @GetMapping public Iterable list() { return propertyRepository.findAll(); @@ -73,6 +91,17 @@ public Iterable list() { * @param withChannels - get the channels with the property * @return found property */ + @ApiResponses( + value = { + @ApiResponse( + responseCode = "200", + description = "Fetch property by propertyName", + content = @Content(schema = @Schema(implementation = Property.class))), + @ApiResponse( + responseCode = "404", + description = "Property not found", + content = @Content(schema = @Schema(implementation = ResponseStatusException.class))) + }) @GetMapping("/{propertyName}") public Property read(@PathVariable("propertyName") String propertyName, @RequestParam(value = "withChannels", defaultValue = "true") boolean withChannels) { @@ -105,6 +134,25 @@ public Property read(@PathVariable("propertyName") String propertyName, * @param property - an Property instance with the list of channels to add the property propertyName to * @return the created property */ + @ApiResponses( + value = { + @ApiResponse( + responseCode = "200", + description = "Property created", + content = @Content(schema = @Schema(implementation = Property.class))), + @ApiResponse( + responseCode = "401", + description = "Unauthorized", + content = @Content(schema = @Schema(implementation = ResponseStatusException.class))), + @ApiResponse( + responseCode = "404", + description = "Property not found", + content = @Content(schema = @Schema(implementation = ResponseStatusException.class))), + @ApiResponse( + responseCode = "500", + description = "Error while trying to create property", + content = @Content(schema = @Schema(implementation = ResponseStatusException.class))) + }) @PutMapping("/{propertyName}") public Property create(@PathVariable("propertyName") String propertyName, @RequestBody Property property) { // check if authorized role @@ -155,6 +203,21 @@ public Property create(@PathVariable("propertyName") String propertyName, @Reque * @param properties - XmlProperties to be created * @return the list of properties created */ + @ApiResponses( + value = { + @ApiResponse( + responseCode = "200", + description = "Properties created", + content = @Content(schema = @Schema(implementation = Property.class))), + @ApiResponse( + responseCode = "401", + description = "Unauthorized", + content = @Content(schema = @Schema(implementation = ResponseStatusException.class))), + @ApiResponse( + responseCode = "500", + description = "Error while trying to create properties", + content = @Content(schema = @Schema(implementation = ResponseStatusException.class))) + }) @PutMapping() public Iterable create(@RequestBody Iterable properties) { // check if authorized role @@ -216,6 +279,29 @@ public Iterable create(@RequestBody Iterable properties) { * @param property - property payload with value * @return added property */ + @ApiResponses( + value = { + @ApiResponse( + responseCode = "200", + description = "Property added to the channel", + content = @Content(schema = @Schema(implementation = Property.class))), + @ApiResponse( + responseCode = "400", + description = "Invalid request", + content = @Content(schema = @Schema(implementation = ResponseStatusException.class))), + @ApiResponse( + responseCode = "401", + description = "Unauthorized", + content = @Content(schema = @Schema(implementation = ResponseStatusException.class))), + @ApiResponse( + responseCode = "404", + description = "Property-, or Channel-name does not exist", + content = @Content(schema = @Schema(implementation = ResponseStatusException.class))), + @ApiResponse( + responseCode = "500", + description = "Error while trying to add property", + content = @Content(schema = @Schema(implementation = ResponseStatusException.class))) + }) @PutMapping("/{propertyName}/{channelName}") public Property addSingle(@PathVariable("propertyName") String propertyName, @PathVariable("channelName") String channelName, @RequestBody Property property) { // check if authorized role @@ -267,6 +353,29 @@ public Property addSingle(@PathVariable("propertyName") String propertyName, @Pa * @param property - a Property instance with the list of channels to add the property propertyName to * @return the updated property */ + @ApiResponses( + value = { + @ApiResponse( + responseCode = "200", + description = "Property updated", + content = @Content(schema = @Schema(implementation = Property.class))), + @ApiResponse( + responseCode = "400", + description = "Invalid request", + content = @Content(schema = @Schema(implementation = ResponseStatusException.class))), + @ApiResponse( + responseCode = "401", + description = "Unauthorized", + content = @Content(schema = @Schema(implementation = ResponseStatusException.class))), + @ApiResponse( + responseCode = "404", + description = "Property does not exist", + content = @Content(schema = @Schema(implementation = ResponseStatusException.class))), + @ApiResponse( + responseCode = "500", + description = "Error while trying to update property", + content = @Content(schema = @Schema(implementation = ResponseStatusException.class))) + }) @PostMapping("/{propertyName}") public Property update(@PathVariable("propertyName") String propertyName, @RequestBody Property property) { // check if authorized role @@ -364,6 +473,30 @@ public Property update(@PathVariable("propertyName") String propertyName, @Reque * @param properties - XmlProperties to be updated * @return the updated properties */ + @ApiResponses( + value = { + @ApiResponse( + responseCode = "200", + description = "Properties updated", + content = @Content( + array = @ArraySchema(schema = @Schema(implementation = Property.class)))), + @ApiResponse( + responseCode = "400", + description = "Invalid request", + content = @Content(schema = @Schema(implementation = ResponseStatusException.class))), + @ApiResponse( + responseCode = "401", + description = "Unauthorized", + content = @Content(schema = @Schema(implementation = ResponseStatusException.class))), + @ApiResponse( + responseCode = "404", + description = "Property does not exist", + content = @Content(schema = @Schema(implementation = ResponseStatusException.class))), + @ApiResponse( + responseCode = "500", + description = "Error while trying to update properties", + content = @Content(schema = @Schema(implementation = ResponseStatusException.class))) + }) @PostMapping() public Iterable update(@RequestBody Iterable properties) { // check if authorized role @@ -451,6 +584,24 @@ private void checkPropertyAuthorization(Optional existingProperty) { * * @param propertyName - name of property to remove */ + @ApiResponses( + value = { + @ApiResponse( + responseCode = "200", + description = "Property deleted"), + @ApiResponse( + responseCode = "401", + description = "Unauthorized", + content = @Content(schema = @Schema(implementation = ResponseStatusException.class))), + @ApiResponse( + responseCode = "404", + description = "Property does not exist", + content = @Content(schema = @Schema(implementation = ResponseStatusException.class))), + @ApiResponse( + responseCode = "500", + description = "Error while trying to delete property", + content = @Content(schema = @Schema(implementation = ResponseStatusException.class))) + }) @DeleteMapping("/{propertyName}") public void remove(@PathVariable("propertyName") String propertyName) { // check if authorized role @@ -485,6 +636,24 @@ public void remove(@PathVariable("propertyName") String propertyName) { * @param propertyName - name of property to remove * @param channelName - channel to remove propertyName from */ + @ApiResponses( + value = { + @ApiResponse( + responseCode = "200", + description = "Property deleted from the channel"), + @ApiResponse( + responseCode = "401", + description = "Unauthorized", + content = @Content(schema = @Schema(implementation = ResponseStatusException.class))), + @ApiResponse( + responseCode = "404", + description = "Property does not exist", + content = @Content(schema = @Schema(implementation = ResponseStatusException.class))), + @ApiResponse( + responseCode = "500", + description = "Error while trying to delete property from a channel", + content = @Content(schema = @Schema(implementation = ResponseStatusException.class))) + }) @DeleteMapping("/{propertyName}/{channelName}") public void removeSingle(@PathVariable("propertyName") final String propertyName, @PathVariable("channelName") String channelName) { // check if authorized role diff --git a/src/main/java/org/phoebus/channelfinder/TagManager.java b/src/main/java/org/phoebus/channelfinder/TagManager.java index 4ee7b7fb..7155fe2b 100644 --- a/src/main/java/org/phoebus/channelfinder/TagManager.java +++ b/src/main/java/org/phoebus/channelfinder/TagManager.java @@ -2,6 +2,11 @@ import static org.phoebus.channelfinder.CFResourceDescriptors.TAG_RESOURCE_URI; +import io.swagger.v3.oas.annotations.media.ArraySchema; +import io.swagger.v3.oas.annotations.media.Content; +import io.swagger.v3.oas.annotations.media.Schema; +import io.swagger.v3.oas.annotations.responses.ApiResponse; +import io.swagger.v3.oas.annotations.responses.ApiResponses; import java.text.MessageFormat; import java.util.ArrayList; import java.util.Arrays; @@ -57,6 +62,18 @@ public class TagManager { * * @return list of all tags */ + @ApiResponses( + value = { + @ApiResponse( + responseCode = "200", + description = "List all Tags", + content = @Content( + array = @ArraySchema(schema = @Schema(implementation = Tag.class)))), + @ApiResponse( + responseCode = "500", + description = "Error while trying to list all Tags", + content = @Content(schema = @Schema(implementation = ResponseStatusException.class))) + }) @GetMapping public Iterable list() { return tagRepository.findAll(); @@ -71,6 +88,17 @@ public Iterable list() { * @param withChannels - channels with the tag tagName * @return found tag */ + @ApiResponses( + value = { + @ApiResponse( + responseCode = "200", + description = "Finding Tag by tagName", + content = @Content(schema = @Schema(implementation = Tag.class))), + @ApiResponse( + responseCode = "404", + description = "Tag not found", + content = @Content(schema = @Schema(implementation = ResponseStatusException.class))) + }) @GetMapping("/{tagName}") public Tag read(@PathVariable("tagName") String tagName, @RequestParam(value = "withChannels", defaultValue = "true") boolean withChannels) { @@ -107,6 +135,29 @@ public Tag read(@PathVariable("tagName") String tagName, * @param tag - Tag structure containing the list of channels to be tagged * @return the created tag */ + @ApiResponses( + value = { + @ApiResponse( + responseCode = "200", + description = "Tag created and updated", + content = @Content(schema = @Schema(implementation = Tag.class))), + @ApiResponse( + responseCode = "400", + description = "Invalid request", + content = @Content(schema = @Schema(implementation = ResponseStatusException.class))), + @ApiResponse( + responseCode = "401", + description = "Unauthorized", + content = @Content(schema = @Schema(implementation = ResponseStatusException.class))), + @ApiResponse( + responseCode = "404", + description = "Tag-, or Channel-name does not exist", + content = @Content(schema = @Schema(implementation = ResponseStatusException.class))), + @ApiResponse( + responseCode = "500", + description = "Error while trying to create/update Tag", + content = @Content(schema = @Schema(implementation = ResponseStatusException.class))) + }) @PutMapping("/{tagName}") public Tag create(@PathVariable("tagName") String tagName, @RequestBody Tag tag) { // check if authorized role @@ -161,6 +212,31 @@ public Tag create(@PathVariable("tagName") String tagName, @RequestBody Tag tag) * @param tags - XmlTags to be created * @return the list of tags created */ + @ApiResponses( + value = { + @ApiResponse( + responseCode = "200", + description = "Tags created", + content = @Content( + array = + @ArraySchema(schema = @Schema(implementation = Tag.class)))), + @ApiResponse( + responseCode = "400", + description = "Invalid request", + content = @Content(schema = @Schema(implementation = ResponseStatusException.class))), + @ApiResponse( + responseCode = "401", + description = "Unauthorized", + content = @Content(schema = @Schema(implementation = ResponseStatusException.class))), + @ApiResponse( + responseCode = "404", + description = "Tag-, or Channel-name does not exist", + content = @Content(schema = @Schema(implementation = ResponseStatusException.class))), + @ApiResponse( + responseCode = "500", + description = "Error while trying to create Tags", + content = @Content(schema = @Schema(implementation = ResponseStatusException.class))) + }) @PutMapping() public Iterable create(@RequestBody Iterable tags) { // check if authorized role @@ -238,6 +314,29 @@ public Iterable create(@RequestBody Iterable tags) { * @param channelName - channel to update tag to * @return added tag */ + @ApiResponses( + value = { + @ApiResponse( + responseCode = "200", + description = "Tags added to a single channel", + content = @Content(schema = @Schema(implementation = Tag.class))), + @ApiResponse( + responseCode = "400", + description = "Invalid request", + content = @Content(schema = @Schema(implementation = ResponseStatusException.class))), + @ApiResponse( + responseCode = "401", + description = "Unauthorized", + content = @Content(schema = @Schema(implementation = ResponseStatusException.class))), + @ApiResponse( + responseCode = "404", + description = "Tag-, or Channel-name does not exist", + content = @Content(schema = @Schema(implementation = ResponseStatusException.class))), + @ApiResponse( + responseCode = "500", + description = "Tag creational error", + content = @Content(schema = @Schema(implementation = ResponseStatusException.class))) + }) @PutMapping("/{tagName}/{channelName}") public Tag addSingle(@PathVariable("tagName") String tagName, @PathVariable("channelName") String channelName) { // check if authorized role @@ -287,6 +386,29 @@ public Tag addSingle(@PathVariable("tagName") String tagName, @PathVariable("cha * @param tag - Tag with list of channels to addSingle the tag name to * @return the updated tag */ + @ApiResponses( + value = { + @ApiResponse( + responseCode = "200", + description = "Tag updated", + content = @Content(schema = @Schema(implementation = Tag.class))), + @ApiResponse( + responseCode = "400", + description = "Invalid request", + content = @Content(schema = @Schema(implementation = ResponseStatusException.class))), + @ApiResponse( + responseCode = "401", + description = "Unauthorized", + content = @Content(schema = @Schema(implementation = ResponseStatusException.class))), + @ApiResponse( + responseCode = "404", + description = "Tag name does not exist", + content = @Content(schema = @Schema(implementation = ResponseStatusException.class))), + @ApiResponse( + responseCode = "500", + description = "Tag update error", + content = @Content(schema = @Schema(implementation = ResponseStatusException.class))) + }) @PostMapping("/{tagName}") public Tag update(@PathVariable("tagName") String tagName, @RequestBody Tag tag) { // check if authorized role @@ -363,6 +485,30 @@ public Tag update(@PathVariable("tagName") String tagName, @RequestBody Tag tag) * @param tags - XmlTags to be updated * @return the updated tags */ + @ApiResponses( + value = { + @ApiResponse( + responseCode = "200", + description = "Tags updated", + content = @Content(array = + @ArraySchema(schema = @Schema(implementation = Tag.class)))), + @ApiResponse( + responseCode = "400", + description = "Invalid request", + content = @Content(schema = @Schema(implementation = ResponseStatusException.class))), + @ApiResponse( + responseCode = "401", + description = "Unauthorized", + content = @Content(schema = @Schema(implementation = ResponseStatusException.class))), + @ApiResponse( + responseCode = "404", + description = "Tag-, or Channel-name does not exist", + content = @Content(schema = @Schema(implementation = ResponseStatusException.class))), + @ApiResponse( + responseCode = "500", + description = "Error while updating tags", + content = @Content(schema = @Schema(implementation = ResponseStatusException.class))) + }) @PostMapping() public Iterable update(@RequestBody Iterable tags) { // check if authorized role @@ -428,6 +574,28 @@ public Iterable update(@RequestBody Iterable tags) { * * @param tagName - name of tag to remove */ + @ApiResponses( + value = { + @ApiResponse( + responseCode = "200", + description = "Tag deleted"), + @ApiResponse( + responseCode = "400", + description = "Invalid request", + content = @Content(schema = @Schema(implementation = ResponseStatusException.class))), + @ApiResponse( + responseCode = "401", + description = "Unauthorized", + content = @Content(schema = @Schema(implementation = ResponseStatusException.class))), + @ApiResponse( + responseCode = "404", + description = "Tag does not exist", + content = @Content(schema = @Schema(implementation = ResponseStatusException.class))), + @ApiResponse( + responseCode = "500", + description = "Tag creational error", + content = @Content(schema = @Schema(implementation = ResponseStatusException.class))) + }) @DeleteMapping("/{tagName}") public void remove(@PathVariable("tagName") String tagName) { // check if authorized role @@ -462,6 +630,28 @@ public void remove(@PathVariable("tagName") String tagName) { * @param tagName - name of tag to remove * @param channelName - channel to remove tagName from */ + @ApiResponses( + value = { + @ApiResponse( + responseCode = "200", + description = "Tag deleted from the desired channel"), + @ApiResponse( + responseCode = "400", + description = "Invalid request", + content = @Content(schema = @Schema(implementation = ResponseStatusException.class))), + @ApiResponse( + responseCode = "401", + description = "Unauthorized", + content = @Content(schema = @Schema(implementation = ResponseStatusException.class))), + @ApiResponse( + responseCode = "404", + description = "Tag does not exist", + content = @Content(schema = @Schema(implementation = ResponseStatusException.class))), + @ApiResponse( + responseCode = "500", + description = "Tag creational error", + content = @Content(schema = @Schema(implementation = ResponseStatusException.class))) + }) @DeleteMapping("/{tagName}/{channelName}") public void removeSingle(@PathVariable("tagName") final String tagName, @PathVariable("channelName") String channelName) { // check if authorized role diff --git a/src/main/java/org/phoebus/channelfinder/processors/ChannelProcessorManager.java b/src/main/java/org/phoebus/channelfinder/processors/ChannelProcessorManager.java index 5219ec1c..274056cb 100644 --- a/src/main/java/org/phoebus/channelfinder/processors/ChannelProcessorManager.java +++ b/src/main/java/org/phoebus/channelfinder/processors/ChannelProcessorManager.java @@ -1,5 +1,10 @@ package org.phoebus.channelfinder.processors; +import io.swagger.v3.oas.annotations.media.ArraySchema; +import io.swagger.v3.oas.annotations.media.Content; +import io.swagger.v3.oas.annotations.media.Schema; +import io.swagger.v3.oas.annotations.responses.ApiResponse; +import io.swagger.v3.oas.annotations.responses.ApiResponses; import org.phoebus.channelfinder.AuthorizationService; import org.phoebus.channelfinder.ChannelScroll; import org.phoebus.channelfinder.entity.Channel; @@ -48,16 +53,42 @@ public class ChannelProcessorManager { @Value("${elasticsearch.query.size:10000}") private int defaultMaxSize; + @ApiResponses( + value = { + @ApiResponse( + responseCode = "200", + description = "Number of channel-processors", + content = @Content(schema = @Schema(implementation = Long.class))) + }) @GetMapping("/count") public long processorCount() { return channelProcessorService.getProcessorCount(); } + @ApiResponses( + value = { + @ApiResponse( + responseCode = "200", + description = "List of processor-info", + content = @Content( + array = @ArraySchema (schema = @Schema(implementation = String.class)))) + }) @GetMapping("/info") public List processorInfo() { return channelProcessorService.getProcessorsInfo(); } + @ApiResponses( + value = { + @ApiResponse( + responseCode = "200", + description = "Number of channels where processor was called", + content = @Content(schema = @Schema(implementation = Long.class))), + @ApiResponse( + responseCode = "401", + description = "Unauthorized", + content = @Content(schema = @Schema(implementation = ResponseStatusException.class))) + }) @PutMapping("/process/all") public long processAllChannels() { logger.log(Level.INFO, "Calling processor on ALL channels in ChannelFinder"); @@ -77,6 +108,13 @@ public long processAllChannels() { } } + @ApiResponses( + value = { + @ApiResponse( + responseCode = "200", + description = "Number of channels where processor was called", + content = @Content(schema = @Schema(implementation = Long.class))) + }) @PutMapping("/process/query") public long processChannels(@RequestParam MultiValueMap allRequestParams) { long channelCount = 0;