T returnNotNullEntity(T entity, String entityType
return entity;
}
+ /**
+ * Checks id the given {@link Storable} is {@code null}.
+ *
+ * Similar to {@link #returnNotNullEntity(KapuaEntity, String, KapuaId)} but for {@link Storable}s.
+ *
+ * @param storable The {@link Storable} to check.
+ * @param storableType The {@link Storable#getType()}
+ * @param storableId The {@link StorableId}
+ * @return The given {@link Storable} if not {@code null}
+ * @param The type of the {@link Storable}.
+ * @throws StorableNotFoundException if given {@link Storable} is {@code null}.
+ * @since 2.0.0
+ */
+ public T returnNotNullStorable(T storable, String storableType, StorableId storableId) throws StorableNotFoundException {
+ if (storable == null) {
+ throw new StorableNotFoundException(storableType, storableId);
+ }
+
+ return storable;
+ }
+
/**
* Builds a 200 HTTP Response.
*
diff --git a/rest-api/resources/src/main/java/org/eclipse/kapua/app/api/resources/v1/resources/DataChannels.java b/rest-api/resources/src/main/java/org/eclipse/kapua/app/api/resources/v1/resources/DataChannels.java
index e5eed7e109d..10ae28ef3d4 100644
--- a/rest-api/resources/src/main/java/org/eclipse/kapua/app/api/resources/v1/resources/DataChannels.java
+++ b/rest-api/resources/src/main/java/org/eclipse/kapua/app/api/resources/v1/resources/DataChannels.java
@@ -160,6 +160,6 @@ public ChannelInfo find(@PathParam("scopeId") ScopeId scopeId,
throws KapuaException {
ChannelInfo channelInfo = channelInfoRegistryService.find(scopeId, channelInfoId);
- return returnNotNullEntity(channelInfo);
+ return returnNotNullStorable(channelInfo, ChannelInfo.TYPE, channelInfoId);
}
}
diff --git a/rest-api/resources/src/main/java/org/eclipse/kapua/app/api/resources/v1/resources/DataClients.java b/rest-api/resources/src/main/java/org/eclipse/kapua/app/api/resources/v1/resources/DataClients.java
index 3583c44c076..2e1329cac32 100644
--- a/rest-api/resources/src/main/java/org/eclipse/kapua/app/api/resources/v1/resources/DataClients.java
+++ b/rest-api/resources/src/main/java/org/eclipse/kapua/app/api/resources/v1/resources/DataClients.java
@@ -142,6 +142,6 @@ public ClientInfo find(@PathParam("scopeId") ScopeId scopeId,
throws KapuaException {
ClientInfo clientInfo = clientInfoRegistryService.find(scopeId, clientInfoId);
- return returnNotNullEntity(clientInfo);
+ return returnNotNullStorable(clientInfo, ClientInfo.TYPE, clientInfoId);
}
}
diff --git a/rest-api/resources/src/main/java/org/eclipse/kapua/app/api/resources/v1/resources/DataMessages.java b/rest-api/resources/src/main/java/org/eclipse/kapua/app/api/resources/v1/resources/DataMessages.java
index 85e66421067..59a8da169de 100644
--- a/rest-api/resources/src/main/java/org/eclipse/kapua/app/api/resources/v1/resources/DataMessages.java
+++ b/rest-api/resources/src/main/java/org/eclipse/kapua/app/api/resources/v1/resources/DataMessages.java
@@ -184,7 +184,7 @@ public DatastoreMessage find(@PathParam("scopeId") ScopeId scopeId,
throws KapuaException {
DatastoreMessage datastoreMessage = messageStoreService.find(scopeId, datastoreMessageId, StorableFetchStyle.SOURCE_FULL);
- return returnNotNullEntity(datastoreMessage);
+ return returnNotNullStorable(datastoreMessage, DatastoreMessage.TYPE, datastoreMessageId);
}
diff --git a/rest-api/resources/src/main/java/org/eclipse/kapua/app/api/resources/v1/resources/DataMessagesJson.java b/rest-api/resources/src/main/java/org/eclipse/kapua/app/api/resources/v1/resources/DataMessagesJson.java
index afa058ddafb..cd756acf5e3 100644
--- a/rest-api/resources/src/main/java/org/eclipse/kapua/app/api/resources/v1/resources/DataMessagesJson.java
+++ b/rest-api/resources/src/main/java/org/eclipse/kapua/app/api/resources/v1/resources/DataMessagesJson.java
@@ -205,11 +205,11 @@ public JsonMessageListResult queryJson(@PathParam("scopeId") ScopeId scopeId,
public JsonDatastoreMessage findJson(@PathParam("scopeId") ScopeId scopeId,
@PathParam("datastoreMessageId") StorableEntityId datastoreMessageId)
throws KapuaException {
- DatastoreMessage datastoreMessage = returnNotNullEntity(messageStoreService.find(scopeId, datastoreMessageId, StorableFetchStyle.SOURCE_FULL));
+ DatastoreMessage datastoreMessage = returnNotNullStorable(messageStoreService.find(scopeId, datastoreMessageId, StorableFetchStyle.SOURCE_FULL), DatastoreMessage.TYPE, datastoreMessageId);
JsonDatastoreMessage jsonDatastoreMessage = new JsonDatastoreMessage(datastoreMessage);
- return returnNotNullEntity(jsonDatastoreMessage);
+ return returnNotNullStorable(jsonDatastoreMessage, DatastoreMessage.TYPE, datastoreMessageId);
}
private MessageQuery convertQuery(JsonMessageQuery query) {
diff --git a/rest-api/resources/src/main/java/org/eclipse/kapua/app/api/resources/v1/resources/DataMetrics.java b/rest-api/resources/src/main/java/org/eclipse/kapua/app/api/resources/v1/resources/DataMetrics.java
index 93f12a6a485..dbab38cc7e0 100644
--- a/rest-api/resources/src/main/java/org/eclipse/kapua/app/api/resources/v1/resources/DataMetrics.java
+++ b/rest-api/resources/src/main/java/org/eclipse/kapua/app/api/resources/v1/resources/DataMetrics.java
@@ -150,6 +150,6 @@ public MetricInfo find(@PathParam("scopeId") ScopeId scopeId,
throws KapuaException {
MetricInfo metricInfo = metricInfoRegistryService.find(scopeId, metricInfoId);
- return returnNotNullEntity(metricInfo);
+ return returnNotNullStorable(metricInfo, MetricInfo.TYPE, metricInfoId);
}
}