diff --git a/bundles/org.openhab.core.automation.rest/src/main/java/org/openhab/core/automation/rest/internal/ThingActionsResource.java b/bundles/org.openhab.core.automation.rest/src/main/java/org/openhab/core/automation/rest/internal/ThingActionsResource.java index e09887906..0a1dc86fa 100644 --- a/bundles/org.openhab.core.automation.rest/src/main/java/org/openhab/core/automation/rest/internal/ThingActionsResource.java +++ b/bundles/org.openhab.core.automation.rest/src/main/java/org/openhab/core/automation/rest/internal/ThingActionsResource.java @@ -131,7 +131,8 @@ public class ThingActionsResource implements RESTResource { if (actionUIDs.isEmpty()) { return; } - thingActionsMap.computeIfAbsent(thingUID, thingUid -> new ConcurrentHashMap<>()).put(scope, actionUIDs); + Objects.requireNonNull(thingActionsMap.computeIfAbsent(thingUID, thingUid -> new ConcurrentHashMap<>())) + .put(scope, actionUIDs); } } @@ -165,7 +166,7 @@ public class ThingActionsResource implements RESTResource { @Produces(MediaType.APPLICATION_JSON) @Operation(operationId = "getAvailableActionsForThing", summary = "Get all available actions for provided thing UID", responses = { @ApiResponse(responseCode = "200", description = "OK", content = @Content(array = @ArraySchema(schema = @Schema(implementation = ThingActionDTO.class), uniqueItems = true))), - @ApiResponse(responseCode = "404", description = "No actions found.") }) + @ApiResponse(responseCode = "204", description = "No actions found") }) public Response getActions(@PathParam("thingUID") @Parameter(description = "thingUID") String thingUID, @HeaderParam(HttpHeaders.ACCEPT_LANGUAGE) @Parameter(description = "language") @Nullable String language) { Locale locale = localeService.getLocale(language); @@ -174,7 +175,7 @@ public class ThingActionsResource implements RESTResource { List actions = new ArrayList<>(); Map> thingActionsMap = this.thingActionsMap.get(aThingUID); if (thingActionsMap == null) { - return Response.status(Response.Status.NOT_FOUND).build(); + return Response.noContent().build(); } // inspect ThingActions diff --git a/bundles/org.openhab.core.io.rest.core/src/main/java/org/openhab/core/io/rest/core/config/ConfigurationService.java b/bundles/org.openhab.core.io.rest.core/src/main/java/org/openhab/core/io/rest/core/config/ConfigurationService.java index c0163110a..cbd1b849d 100644 --- a/bundles/org.openhab.core.io.rest.core/src/main/java/org/openhab/core/io/rest/core/config/ConfigurationService.java +++ b/bundles/org.openhab.core.io.rest.core/src/main/java/org/openhab/core/io/rest/core/config/ConfigurationService.java @@ -155,8 +155,11 @@ public class ConfigurationService { * @return old config or null if no old config existed * @throws IOException if configuration can not be removed */ - public Configuration delete(String configId) throws IOException { + public @Nullable Configuration delete(String configId) throws IOException { org.osgi.service.cm.Configuration serviceConfiguration = configurationAdmin.getConfiguration(configId, null); + if (serviceConfiguration == null) { + return null; + } Configuration oldConfiguration = toConfiguration(serviceConfiguration.getProperties()); serviceConfiguration.delete(); return oldConfiguration; diff --git a/bundles/org.openhab.core.io.rest.core/src/main/java/org/openhab/core/io/rest/core/internal/channel/ChannelTypeResource.java b/bundles/org.openhab.core.io.rest.core/src/main/java/org/openhab/core/io/rest/core/internal/channel/ChannelTypeResource.java index 8d40c006c..c51c1ea71 100644 --- a/bundles/org.openhab.core.io.rest.core/src/main/java/org/openhab/core/io/rest/core/internal/channel/ChannelTypeResource.java +++ b/bundles/org.openhab.core.io.rest.core/src/main/java/org/openhab/core/io/rest/core/internal/channel/ChannelTypeResource.java @@ -140,8 +140,9 @@ public class ChannelTypeResource implements RESTResource { @Path("/{channelTypeUID}") @Produces(MediaType.APPLICATION_JSON) @Operation(operationId = "getChannelTypeByUID", summary = "Gets channel type by UID.", responses = { - @ApiResponse(responseCode = "200", description = "Channel type with provided channelTypeUID does not exist.", content = @Content(schema = @Schema(implementation = ChannelTypeDTO.class))), - @ApiResponse(responseCode = "404", description = "No content") }) + @ApiResponse(responseCode = "200", description = "OK", content = @Content(schema = @Schema(implementation = ChannelTypeDTO.class))), + @ApiResponse(responseCode = "400", description = "Bad request"), + @ApiResponse(responseCode = "404", description = "Channel type with provided channelTypeUID does not exist.") }) public Response getByUID( @PathParam("channelTypeUID") @Parameter(description = "channelTypeUID") String channelTypeUID, @HeaderParam(HttpHeaders.ACCEPT_LANGUAGE) @Parameter(description = "language") @Nullable String language) { @@ -150,7 +151,7 @@ public class ChannelTypeResource implements RESTResource { if (channelType != null) { return Response.ok(convertToChannelTypeDTO(channelType, locale)).build(); } else { - return Response.noContent().build(); + return Response.status(Status.NOT_FOUND).build(); } } diff --git a/bundles/org.openhab.core.io.rest.core/src/main/java/org/openhab/core/io/rest/core/internal/service/ConfigurableServiceResource.java b/bundles/org.openhab.core.io.rest.core/src/main/java/org/openhab/core/io/rest/core/internal/service/ConfigurableServiceResource.java index cf27785a4..496ae00c8 100644 --- a/bundles/org.openhab.core.io.rest.core/src/main/java/org/openhab/core/io/rest/core/internal/service/ConfigurableServiceResource.java +++ b/bundles/org.openhab.core.io.rest.core/src/main/java/org/openhab/core/io/rest/core/internal/service/ConfigurableServiceResource.java @@ -150,7 +150,7 @@ public class ConfigurableServiceResource implements RESTResource { if (configurableService != null) { return Response.ok(configurableService).build(); } else { - return Response.status(404).build(); + return Response.status(Status.NOT_FOUND).build(); } } @@ -275,8 +275,7 @@ public class ConfigurableServiceResource implements RESTResource { public Response deleteConfiguration( @PathParam("serviceId") @Parameter(description = "service ID") String serviceId) { try { - Configuration oldConfiguration = configurationService.get(serviceId); - configurationService.delete(serviceId); + Configuration oldConfiguration = configurationService.delete(serviceId); return oldConfiguration != null ? Response.ok(oldConfiguration).build() : Response.noContent().build(); } catch (IOException ex) { logger.error("Cannot delete configuration for service {}: {}", serviceId, ex.getMessage(), ex); diff --git a/bundles/org.openhab.core.io.rest.core/src/main/java/org/openhab/core/io/rest/core/internal/thing/ThingTypeResource.java b/bundles/org.openhab.core.io.rest.core/src/main/java/org/openhab/core/io/rest/core/internal/thing/ThingTypeResource.java index 4e382dcdf..b84d2c399 100644 --- a/bundles/org.openhab.core.io.rest.core/src/main/java/org/openhab/core/io/rest/core/internal/thing/ThingTypeResource.java +++ b/bundles/org.openhab.core.io.rest.core/src/main/java/org/openhab/core/io/rest/core/internal/thing/ThingTypeResource.java @@ -28,6 +28,7 @@ import javax.ws.rs.QueryParam; import javax.ws.rs.core.HttpHeaders; import javax.ws.rs.core.MediaType; import javax.ws.rs.core.Response; +import javax.ws.rs.core.Response.Status; import org.eclipse.jdt.annotation.NonNullByDefault; import org.eclipse.jdt.annotation.Nullable; @@ -151,8 +152,8 @@ public class ThingTypeResource implements RESTResource { @Path("/{thingTypeUID}") @Produces(MediaType.APPLICATION_JSON) @Operation(operationId = "getThingTypeById", summary = "Gets thing type by UID.", responses = { - @ApiResponse(responseCode = "200", description = "Thing type with provided thingTypeUID does not exist.", content = @Content(schema = @Schema(implementation = ThingTypeDTO.class))), - @ApiResponse(responseCode = "404", description = "No content") }) + @ApiResponse(responseCode = "200", description = "OK", content = @Content(schema = @Schema(implementation = ThingTypeDTO.class))), + @ApiResponse(responseCode = "404", description = "Thing type not found.") }) public Response getByUID(@PathParam("thingTypeUID") @Parameter(description = "thingTypeUID") String thingTypeUID, @HeaderParam(HttpHeaders.ACCEPT_LANGUAGE) @Parameter(description = "language") @Nullable String language) { Locale locale = localeService.getLocale(language); @@ -160,7 +161,7 @@ public class ThingTypeResource implements RESTResource { if (thingType != null) { return Response.ok(convertToThingTypeDTO(thingType, locale)).build(); } else { - return Response.noContent().build(); + return Response.status(Status.NOT_FOUND).build(); } }