Skip to content

Commit

Permalink
Various modifications on rest APIs to reach coherence with documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
Agnul97 authored and Coduz committed Mar 1, 2023
1 parent f7f0a8f commit 45ecbd4
Show file tree
Hide file tree
Showing 16 changed files with 68 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@ public class DeviceConnections extends AbstractKapuaResource {
public DeviceConnectionListResult simpleQuery(
@PathParam("scopeId") ScopeId scopeId,
@QueryParam("clientId") String clientId,
@QueryParam("clientIp") String clientIp,
@QueryParam("protocol") String protocol,
@QueryParam("status") DeviceConnectionStatus status,
@QueryParam("offset") @DefaultValue("0") int offset,
@QueryParam("limit") @DefaultValue("50") int limit) throws KapuaException {
Expand All @@ -74,6 +76,12 @@ public DeviceConnectionListResult simpleQuery(
if (!Strings.isNullOrEmpty(clientId)) {
andPredicate.and(query.attributePredicate(DeviceConnectionAttributes.CLIENT_ID, clientId));
}
if (!Strings.isNullOrEmpty(clientIp)) {
andPredicate.and(query.attributePredicate(DeviceConnectionAttributes.CLIENT_IP, clientIp));
}
if (!Strings.isNullOrEmpty(protocol)) {
andPredicate.and(query.attributePredicate(DeviceConnectionAttributes.PROTOCOL, protocol));
}
if (status != null) {
andPredicate.and(query.attributePredicate(DeviceConnectionAttributes.STATUS, status));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.QueryParam;
import javax.ws.rs.DefaultValue;
import javax.ws.rs.core.MediaType;

import org.eclipse.kapua.KapuaException;
Expand Down Expand Up @@ -58,7 +59,7 @@ public class DeviceManagementAssets extends AbstractKapuaResource {
public DeviceAssets get(
@PathParam("scopeId") ScopeId scopeId,
@PathParam("deviceId") EntityId deviceId,
@QueryParam("timeout") Long timeout) throws KapuaException {
@QueryParam("timeout") @DefaultValue("10000") Long timeout) throws KapuaException {
return get(scopeId, deviceId, timeout, deviceAssetFilter.newAssetListResult());
}

Expand All @@ -81,7 +82,7 @@ public DeviceAssets get(
public DeviceAssets get(
@PathParam("scopeId") ScopeId scopeId,
@PathParam("deviceId") EntityId deviceId,
@QueryParam("timeout") Long timeout,
@QueryParam("timeout") @DefaultValue("10000") Long timeout,
DeviceAssets deviceAssetFilter) throws KapuaException {
return deviceManagementAssetService.get(scopeId, deviceId, deviceAssetFilter, timeout);
}
Expand All @@ -106,7 +107,7 @@ public DeviceAssets get(
public DeviceAssets read(
@PathParam("scopeId") ScopeId scopeId,
@PathParam("deviceId") EntityId deviceId,
@QueryParam("timeout") Long timeout,
@QueryParam("timeout") @DefaultValue("10000") Long timeout,
DeviceAssets deviceAssetFilter) throws KapuaException {
return deviceManagementAssetService.read(scopeId, deviceId, deviceAssetFilter, timeout);
}
Expand All @@ -131,7 +132,7 @@ public DeviceAssets read(
public DeviceAssets write(
@PathParam("scopeId") ScopeId scopeId,
@PathParam("deviceId") EntityId deviceId,
@QueryParam("timeout") Long timeout,
@QueryParam("timeout") @DefaultValue("10000") Long timeout,
DeviceAssets deviceAssetFilter) throws KapuaException {
return deviceManagementAssetService.write(scopeId, deviceId, deviceAssetFilter, timeout);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ public DeviceBundles get(
@PathParam("deviceId") EntityId deviceId,
@QueryParam("sortParam") String sortParam,
@QueryParam("sortDir") @DefaultValue("ASCENDING") SortOrder sortDir,
@QueryParam("timeout") Long timeout) throws KapuaException {
@QueryParam("timeout") @DefaultValue("10000") Long timeout) throws KapuaException {
DeviceBundles deviceBundles = bundleService.get(scopeId, deviceId, timeout);
if (!Strings.isNullOrEmpty(sortParam)) {
deviceBundles.getBundles().sort((b1, b2) -> sortBundles(sortParam, sortDir, b1, b2));
Expand Down Expand Up @@ -112,7 +112,7 @@ public Response start(
@PathParam("scopeId") ScopeId scopeId,
@PathParam("deviceId") EntityId deviceId,
@PathParam("bundleId") String bundleId,
@QueryParam("timeout") Long timeout) throws KapuaException {
@QueryParam("timeout") @DefaultValue("10000") Long timeout) throws KapuaException {
bundleService.start(scopeId, deviceId, bundleId, timeout);

return returnNoContent();
Expand All @@ -137,7 +137,7 @@ public Response stop(
@PathParam("scopeId") ScopeId scopeId,
@PathParam("deviceId") EntityId deviceId,
@PathParam("bundleId") String bundleId,
@QueryParam("timeout") Long timeout) throws KapuaException {
@QueryParam("timeout") @DefaultValue("10000") Long timeout) throws KapuaException {
bundleService.stop(scopeId, deviceId, bundleId, timeout);

return returnNoContent();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
package org.eclipse.kapua.app.api.resources.v1.resources;

import javax.ws.rs.Consumes;
import javax.ws.rs.DefaultValue;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
Expand Down Expand Up @@ -80,7 +81,7 @@ public class DeviceManagementCommands extends AbstractKapuaResource {
public DeviceCommandOutput sendCommand(
@PathParam("scopeId") ScopeId scopeId,
@PathParam("deviceId") EntityId deviceId,
@QueryParam("timeout") Long timeout,
@QueryParam("timeout") @DefaultValue("10000") Long timeout,
DeviceCommandInput commandInput) throws KapuaException {
return commandService.exec(scopeId, deviceId, commandInput, timeout);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
package org.eclipse.kapua.app.api.resources.v1.resources;

import javax.ws.rs.Consumes;
import javax.ws.rs.DefaultValue;
import javax.ws.rs.GET;
import javax.ws.rs.PUT;
import javax.ws.rs.Path;
Expand Down Expand Up @@ -58,7 +59,7 @@ public class DeviceManagementConfigurations extends AbstractKapuaResource {
public DeviceConfiguration get(
@PathParam("scopeId") ScopeId scopeId,
@PathParam("deviceId") EntityId deviceId,
@QueryParam("timeout") Long timeout) throws KapuaException {
@QueryParam("timeout") @DefaultValue("10000") Long timeout) throws KapuaException {
return getComponent(scopeId, deviceId, null, timeout);
}

Expand All @@ -83,7 +84,7 @@ public DeviceConfiguration get(
public Response update(
@PathParam("scopeId") ScopeId scopeId,
@PathParam("deviceId") EntityId deviceId,
@QueryParam("timeout") Long timeout,
@QueryParam("timeout") @DefaultValue("10000") Long timeout,
DeviceConfiguration deviceConfiguration) throws KapuaException {
configurationService.put(scopeId, deviceId, deviceConfiguration, timeout);

Expand Down Expand Up @@ -117,7 +118,7 @@ public DeviceConfiguration getComponent(
@PathParam("scopeId") ScopeId scopeId,
@PathParam("deviceId") EntityId deviceId,
@PathParam("componentId") String componentId,
@QueryParam("timeout") Long timeout) throws KapuaException {
@QueryParam("timeout") @DefaultValue("10000") Long timeout) throws KapuaException {
return configurationService.get(scopeId, deviceId, null, componentId, timeout);
}

Expand Down Expand Up @@ -150,7 +151,7 @@ public Response updateComponent(
@PathParam("scopeId") ScopeId scopeId,
@PathParam("deviceId") EntityId deviceId,
@PathParam("componentId") String componentId,
@QueryParam("timeout") Long timeout,
@QueryParam("timeout") @DefaultValue("10000") Long timeout,
DeviceComponentConfiguration deviceComponentConfiguration) throws KapuaException {
deviceComponentConfiguration.setId(componentId);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import org.eclipse.kapua.service.device.management.inventory.model.system.DeviceInventorySystemPackages;
import org.eclipse.kapua.service.device.registry.Device;

import javax.ws.rs.DefaultValue;
import javax.ws.rs.GET;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
Expand Down Expand Up @@ -60,7 +61,7 @@ public class DeviceManagementInventory extends AbstractKapuaResource {
public DeviceInventory getInventory(
@PathParam("scopeId") ScopeId scopeId,
@PathParam("deviceId") EntityId deviceId,
@QueryParam("timeout") Long timeout) throws KapuaException {
@QueryParam("timeout") @DefaultValue("10000") Long timeout) throws KapuaException {
return DEVICE_INVENTORY_MANAGEMENT_SERVICE.getInventory(scopeId, deviceId, timeout);
}

Expand All @@ -80,7 +81,7 @@ public DeviceInventory getInventory(
public DeviceInventoryBundles getInventoryBundles(
@PathParam("scopeId") ScopeId scopeId,
@PathParam("deviceId") EntityId deviceId,
@QueryParam("timeout") Long timeout) throws KapuaException {
@QueryParam("timeout") @DefaultValue("10000") Long timeout) throws KapuaException {
return DEVICE_INVENTORY_MANAGEMENT_SERVICE.getBundles(scopeId, deviceId, timeout);
}

Expand All @@ -101,7 +102,7 @@ public DeviceInventoryBundles getInventoryBundles(
public Response startInventoryBundles(
@PathParam("scopeId") ScopeId scopeId,
@PathParam("deviceId") EntityId deviceId,
@QueryParam("timeout") Long timeout,
@QueryParam("timeout") @DefaultValue("10000") Long timeout,
DeviceInventoryBundle deviceInventoryBundle) throws KapuaException {

DEVICE_INVENTORY_MANAGEMENT_SERVICE.execBundle(scopeId, deviceId, deviceInventoryBundle, DeviceInventoryBundleAction.START, timeout);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
import org.eclipse.kapua.service.device.registry.Device;

import javax.ws.rs.DELETE;
import javax.ws.rs.DefaultValue;
import javax.ws.rs.GET;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
Expand Down Expand Up @@ -69,7 +70,7 @@ public class DeviceManagementKeystores extends AbstractKapuaResource {
public DeviceKeystores getKeystores(
@PathParam("scopeId") ScopeId scopeId,
@PathParam("deviceId") EntityId deviceId,
@QueryParam("timeout") Long timeout) throws KapuaException {
@QueryParam("timeout") @DefaultValue("10000") Long timeout) throws KapuaException {
return DEVICE_KEYSTORE_MANAGEMENT_SERVICE.getKeystores(scopeId, deviceId, timeout);
}

Expand All @@ -91,7 +92,7 @@ public DeviceKeystoreItems getKeystoreItems(
@PathParam("deviceId") EntityId deviceId,
@QueryParam("keystoreId") String keystoreId,
@QueryParam("alias") String alias,
@QueryParam("timeout") Long timeout) throws KapuaException {
@QueryParam("timeout") @DefaultValue("10000") Long timeout) throws KapuaException {

DeviceKeystoreItemQuery itemQuery = DEVICE_KEYSTORE_MANAGEMENT_FACTORY.newDeviceKeystoreItemQuery();
itemQuery.setKeystoreId(keystoreId);
Expand All @@ -118,7 +119,7 @@ public DeviceKeystoreItem getKeystoreItem(
@PathParam("deviceId") EntityId deviceId,
@QueryParam("keystoreId") String keystoreId,
@QueryParam("alias") String alias,
@QueryParam("timeout") Long timeout) throws KapuaException {
@QueryParam("timeout") @DefaultValue("10000") Long timeout) throws KapuaException {

return DEVICE_KEYSTORE_MANAGEMENT_SERVICE.getKeystoreItem(scopeId, deviceId, keystoreId, alias, timeout);
}
Expand All @@ -140,7 +141,7 @@ public DeviceKeystoreItem getKeystoreItem(
public Response createDeviceKeystoreCertificate(
@PathParam("scopeId") ScopeId scopeId,
@PathParam("deviceId") EntityId deviceId,
@QueryParam("timeout") Long timeout,
@QueryParam("timeout") @DefaultValue("10000") Long timeout,
DeviceKeystoreCertificateInfo keystoreCertificateInfo) throws KapuaException {

DEVICE_KEYSTORE_MANAGEMENT_SERVICE.createKeystoreCertificate(
Expand Down Expand Up @@ -171,7 +172,7 @@ public Response createDeviceKeystoreCertificate(
public Response createDeviceKeystoreCertificate(
@PathParam("scopeId") ScopeId scopeId,
@PathParam("deviceId") EntityId deviceId,
@QueryParam("timeout") Long timeout,
@QueryParam("timeout") @DefaultValue("10000") Long timeout,
DeviceKeystoreCertificate keystoreCertificate) throws KapuaException {

DEVICE_KEYSTORE_MANAGEMENT_SERVICE.createKeystoreCertificate(scopeId, deviceId, keystoreCertificate, timeout);
Expand All @@ -197,7 +198,7 @@ public Response createDeviceKeystoreCertificate(
public Response createDeviceKeystoreKeypair(
@PathParam("scopeId") ScopeId scopeId,
@PathParam("deviceId") EntityId deviceId,
@QueryParam("timeout") Long timeout,
@QueryParam("timeout") @DefaultValue("10000") Long timeout,
DeviceKeystoreKeypair deviceKeystoreKeypair) throws KapuaException {

DEVICE_KEYSTORE_MANAGEMENT_SERVICE.createKeystoreKeypair(scopeId, deviceId, deviceKeystoreKeypair, timeout);
Expand All @@ -222,7 +223,7 @@ public Response createDeviceKeystoreKeypair(
public DeviceKeystoreCSR createDeviceKeystoreCSR(
@PathParam("scopeId") ScopeId scopeId,
@PathParam("deviceId") EntityId deviceId,
@QueryParam("timeout") Long timeout,
@QueryParam("timeout") @DefaultValue("10000") Long timeout,
DeviceKeystoreCSRInfo deviceKeystoreCSRInfo) throws KapuaException {

return DEVICE_KEYSTORE_MANAGEMENT_SERVICE.createKeystoreCSR(scopeId, deviceId, deviceKeystoreCSRInfo, timeout);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
*******************************************************************************/
package org.eclipse.kapua.app.api.resources.v1.resources;

import com.google.common.base.Strings;
import org.eclipse.kapua.KapuaEntityNotFoundException;
import org.eclipse.kapua.KapuaException;
import org.eclipse.kapua.app.api.core.resources.AbstractKapuaResource;
Expand Down Expand Up @@ -74,6 +75,10 @@ public ManagementOperationNotificationListResult simpleQuery(

AndPredicate andPredicate = query.andPredicate(query.attributePredicate(ManagementOperationNotificationAttributes.OPERATION_ID, operationId));

if (!Strings.isNullOrEmpty(resource)) {
andPredicate.and(query.attributePredicate(ManagementOperationNotificationAttributes.RESOURCE, resource));
}

query.setPredicate(andPredicate);

query.setOffset(offset);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ public class DeviceManagementPackages extends AbstractKapuaResource {
public DevicePackages get(
@PathParam("scopeId") ScopeId scopeId,
@PathParam("deviceId") EntityId deviceId,
@QueryParam("timeout") Long timeout) throws KapuaException {
@QueryParam("timeout") @DefaultValue("10000") Long timeout) throws KapuaException {
return devicePackageManagementService.getInstalled(scopeId, deviceId, timeout);
}

Expand All @@ -90,7 +90,7 @@ public DevicePackages get(
public Response download(
@PathParam("scopeId") ScopeId scopeId,
@PathParam("deviceId") EntityId deviceId,
@QueryParam("timeout") Long timeout,
@QueryParam("timeout") @DefaultValue("10000") Long timeout,
@QueryParam("legacy") @DefaultValue("false") boolean legacy,
DevicePackageDownloadRequest packageDownloadRequest)
throws KapuaException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import org.eclipse.kapua.service.device.registry.Device;

import javax.ws.rs.Consumes;
import javax.ws.rs.DefaultValue;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
Expand Down Expand Up @@ -56,7 +57,7 @@ public class DeviceManagementRequests extends AbstractKapuaResource {
public GenericResponseMessage sendRequest(
@PathParam("scopeId") ScopeId scopeId,
@PathParam("deviceId") EntityId deviceId,
@QueryParam("timeout") Long timeout,
@QueryParam("timeout") @DefaultValue("10000") Long timeout,
GenericRequestMessage requestMessage) throws KapuaException {
requestMessage.setScopeId(scopeId);
requestMessage.setDeviceId(deviceId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
*******************************************************************************/
package org.eclipse.kapua.app.api.resources.v1.resources;

import javax.ws.rs.DefaultValue;
import javax.ws.rs.GET;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
Expand Down Expand Up @@ -59,7 +60,7 @@ public class DeviceManagementSnapshots extends AbstractKapuaResource {
public DeviceSnapshots get(
@PathParam("scopeId") ScopeId scopeId,
@PathParam("deviceId") EntityId deviceId,
@QueryParam("timeout") Long timeout) throws KapuaException {
@QueryParam("timeout") @DefaultValue("10000") Long timeout) throws KapuaException {
return snapshotService.get(scopeId, deviceId, timeout);
}

Expand All @@ -86,7 +87,7 @@ public Response rollback(
@PathParam("scopeId") ScopeId scopeId,
@PathParam("deviceId") EntityId deviceId,
@PathParam("snapshotId") String snapshotId,
@QueryParam("timeout") Long timeout) throws KapuaException {
@QueryParam("timeout") @DefaultValue("10000") Long timeout) throws KapuaException {
snapshotService.rollback(scopeId, deviceId, snapshotId, timeout);

return returnNoContent();
Expand Down Expand Up @@ -115,7 +116,7 @@ public DeviceConfiguration download(
@PathParam("scopeId") ScopeId scopeId,
@PathParam("deviceId") EntityId deviceId,
@PathParam("snapshotId") String snapshotId,
@QueryParam("timeout") Long timeout) throws KapuaException {
@QueryParam("timeout") @DefaultValue("10000") Long timeout) throws KapuaException {
return configurationService.get(scopeId, deviceId, snapshotId, null, timeout);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ paths:
parameters:
- $ref: '../openapi.yaml#/components/parameters/scopeId'
- $ref: '../device/device.yaml#/components/parameters/clientId'
- $ref: './deviceConnection.yaml#/components/parameters/clientIp'
- $ref: './deviceConnection.yaml#/components/parameters/protocol'
- $ref: './deviceConnection.yaml#/components/parameters/connectionStatus'
- $ref: '../openapi.yaml#/components/parameters/limit'
- $ref: '../openapi.yaml#/components/parameters/offset'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,18 @@ components:
description: The connection status to filter results
schema:
$ref: './deviceConnection.yaml#/components/schemas/connectionStatus'
clientIp:
name: clientIp
in: query
description: The client ip to filter results
schema:
type: string
protocol:
name: protocol
in: query
description: The connection protocol to filter results
schema:
type: string
schemas:
connection:
allOf:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ paths:
- $ref: '../openapi.yaml#/components/parameters/scopeId'
- $ref: '../job/job.yaml#/components/parameters/jobId'
- $ref: './jobExecution.yaml#/components/parameters/executionId'
- $ref: '../openapi.yaml#/components/parameters/limit'
- $ref: '../openapi.yaml#/components/parameters/offset'
responses:
200:
description: The list of the targets involved in a single Job Execution
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ paths:
- $ref: '../openapi.yaml#/components/parameters/scopeId'
- $ref: '../job/job.yaml#/components/parameters/jobId'
- $ref: './jobTarget.yaml#/components/parameters/targetId'
- $ref: '../openapi.yaml#/components/parameters/limit'
- $ref: '../openapi.yaml#/components/parameters/offset'
responses:
200:
description: A list of all the Executions in which a single Job Target was involved
Expand Down

0 comments on commit 45ecbd4

Please sign in to comment.