diff --git a/console/module/device/src/main/java/org/eclipse/kapua/app/console/module/device/server/GwtDeviceManagementServiceImpl.java b/console/module/device/src/main/java/org/eclipse/kapua/app/console/module/device/server/GwtDeviceManagementServiceImpl.java index 241de57aeaa..79503c1fd0e 100644 --- a/console/module/device/src/main/java/org/eclipse/kapua/app/console/module/device/server/GwtDeviceManagementServiceImpl.java +++ b/console/module/device/src/main/java/org/eclipse/kapua/app/console/module/device/server/GwtDeviceManagementServiceImpl.java @@ -12,8 +12,28 @@ *******************************************************************************/ package org.eclipse.kapua.app.console.module.device.server; -import com.extjs.gxt.ui.client.data.BaseListLoadResult; -import com.extjs.gxt.ui.client.data.ListLoadResult; +import java.io.File; +import java.io.FileOutputStream; +import java.io.IOException; +import java.io.InputStream; +import java.io.OutputStream; +import java.net.URI; +import java.net.URISyntaxException; +import java.net.URL; +import java.net.URLConnection; +import java.security.MessageDigest; +import java.util.ArrayList; +import java.util.Collections; +import java.util.Comparator; +import java.util.Date; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Map.Entry; +import java.util.StringTokenizer; + +import javax.xml.namespace.QName; + import org.apache.commons.codec.binary.Base64; import org.apache.commons.imaging.ImageFormat; import org.apache.commons.imaging.ImageFormats; @@ -65,7 +85,6 @@ import org.eclipse.kapua.service.device.management.configuration.store.DeviceConfigurationStoreService; import org.eclipse.kapua.service.device.management.configuration.store.settings.DeviceConfigurationStoreEnablementPolicy; import org.eclipse.kapua.service.device.management.configuration.store.settings.DeviceConfigurationStoreSettings; -import org.eclipse.kapua.service.device.management.packages.DevicePackageFactory; import org.eclipse.kapua.service.device.management.packages.DevicePackageManagementService; import org.eclipse.kapua.service.device.management.packages.model.DevicePackage; import org.eclipse.kapua.service.device.management.packages.model.DevicePackageBundleInfo; @@ -74,8 +93,10 @@ import org.eclipse.kapua.service.device.management.packages.model.FileType; import org.eclipse.kapua.service.device.management.packages.model.download.AdvancedPackageDownloadOptions; import org.eclipse.kapua.service.device.management.packages.model.download.DevicePackageDownloadOperation; +import org.eclipse.kapua.service.device.management.packages.model.download.DevicePackageDownloadOptions; import org.eclipse.kapua.service.device.management.packages.model.download.DevicePackageDownloadRequest; import org.eclipse.kapua.service.device.management.packages.model.download.DevicePackageDownloadStatus; +import org.eclipse.kapua.service.device.management.packages.model.uninstall.DevicePackageUninstallOptions; import org.eclipse.kapua.service.device.management.packages.model.uninstall.DevicePackageUninstallRequest; import org.eclipse.kapua.service.device.management.snapshot.DeviceSnapshot; import org.eclipse.kapua.service.device.management.snapshot.DeviceSnapshotManagementService; @@ -83,26 +104,8 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import javax.xml.namespace.QName; -import java.io.File; -import java.io.FileOutputStream; -import java.io.IOException; -import java.io.InputStream; -import java.io.OutputStream; -import java.net.URI; -import java.net.URISyntaxException; -import java.net.URL; -import java.net.URLConnection; -import java.security.MessageDigest; -import java.util.ArrayList; -import java.util.Collections; -import java.util.Comparator; -import java.util.Date; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.Map.Entry; -import java.util.StringTokenizer; +import com.extjs.gxt.ui.client.data.BaseListLoadResult; +import com.extjs.gxt.ui.client.data.ListLoadResult; /** * The server side implementation of the Device RPC service. @@ -132,7 +135,6 @@ public class GwtDeviceManagementServiceImpl extends KapuaRemoteServiceServlet im private static final DeviceConfigurationStoreFactory DEVICE_CONFIGURATION_STORE_FACTORY = LOCATOR.getFactory(DeviceConfigurationStoreFactory.class); private static final DevicePackageManagementService PACKAGE_MANAGEMENT_SERVICE = LOCATOR.getService(DevicePackageManagementService.class); - private static final DevicePackageFactory DEVICE_PACKAGE_FACTORY = LOCATOR.getFactory(DevicePackageFactory.class); private static final DeviceSnapshotManagementService SNAPSHOT_MANAGEMENT_SERVICE = LOCATOR.getService(DeviceSnapshotManagementService.class); @@ -190,7 +192,7 @@ public void installPackage(GwtXSRFToken xsrfToken, GwtPackageInstallRequest gwtP throw new GwtKapuaException(GwtKapuaErrorCode.PACKAGE_URI_SYNTAX_ERROR, e, e.getLocalizedMessage()); } - DevicePackageDownloadRequest packageDownloadRequest = DEVICE_PACKAGE_FACTORY.newPackageDownloadRequest(); + DevicePackageDownloadRequest packageDownloadRequest = new DevicePackageDownloadRequest(); packageDownloadRequest.setUri(packageUri); packageDownloadRequest.setName(gwtPackageInstallRequest.getPackageName()); packageDownloadRequest.setVersion(gwtPackageInstallRequest.getPackageVersion()); @@ -210,7 +212,7 @@ public void installPackage(GwtXSRFToken xsrfToken, GwtPackageInstallRequest gwtP advancedOptions.setNotifyBlockSize(gwtPackageInstallRequest.getNotifyBlockSize()); advancedOptions.setInstallVerifierURI(gwtPackageInstallRequest.getInstallVerifierURI()); - PACKAGE_MANAGEMENT_SERVICE.downloadExec(scopeId, deviceId, packageDownloadRequest, DEVICE_PACKAGE_FACTORY.newPackageDownloadOptions()); + PACKAGE_MANAGEMENT_SERVICE.downloadExec(scopeId, deviceId, packageDownloadRequest, new DevicePackageDownloadOptions()); } catch (Throwable t) { throw KapuaExceptionHandler.buildExceptionFromError(t); } @@ -252,13 +254,13 @@ public void uninstallPackage(GwtXSRFToken xsrfToken, GwtPackageUninstallRequest KapuaId scopeId = KapuaEid.parseCompactId(gwtPackageUninstallRequest.getScopeId()); KapuaId deviceId = KapuaEid.parseCompactId(gwtPackageUninstallRequest.getDeviceId()); - DevicePackageUninstallRequest packageUninstallRequest = DEVICE_PACKAGE_FACTORY.newPackageUninstallRequest(); + DevicePackageUninstallRequest packageUninstallRequest = new DevicePackageUninstallRequest(); packageUninstallRequest.setName(gwtPackageUninstallRequest.getPackageName()); packageUninstallRequest.setVersion(gwtPackageUninstallRequest.getPackageVersion()); packageUninstallRequest.setReboot(gwtPackageUninstallRequest.isReboot()); packageUninstallRequest.setRebootDelay(gwtPackageUninstallRequest.getRebootDelay()); - PACKAGE_MANAGEMENT_SERVICE.uninstallExec(scopeId, deviceId, packageUninstallRequest, DEVICE_PACKAGE_FACTORY.newPackageUninstallOptions()); + PACKAGE_MANAGEMENT_SERVICE.uninstallExec(scopeId, deviceId, packageUninstallRequest, new DevicePackageUninstallOptions()); } catch (Throwable t) { throw KapuaExceptionHandler.buildExceptionFromError(t); } @@ -372,7 +374,7 @@ public int compare(DeviceComponentConfiguration arg0, DeviceComponentConfigurati strValues.add(v.toString()); } } - gwtParam.setValues(strValues.toArray(new String[]{})); + gwtParam.setValues(strValues.toArray(new String[] {})); } } } @@ -462,7 +464,8 @@ public GwtDeviceConfigurationStoreSettings getApplicationSettings(String scopeId deviceConfigurationStoreSettings = DEVICE_CONFIGURATION_STORE_SERVICE.getApplicationSettings(scopeId, deviceId); gwtDeviceConfigurationStoreSettings = new GwtDeviceConfigurationStoreSettings(); - gwtDeviceConfigurationStoreSettings.setStoreEnablementPolicy(GwtDeviceConfigurationStoreSettings.GwtDeviceConfigurationStoreEnablementPolicy.valueOf(deviceConfigurationStoreSettings.getEnablementPolicy().name())); + gwtDeviceConfigurationStoreSettings.setStoreEnablementPolicy( + GwtDeviceConfigurationStoreSettings.GwtDeviceConfigurationStoreEnablementPolicy.valueOf(deviceConfigurationStoreSettings.getEnablementPolicy().name())); return gwtDeviceConfigurationStoreSettings; } catch (Throwable t) { throw KapuaExceptionHandler.buildExceptionFromError(t); @@ -470,7 +473,8 @@ public GwtDeviceConfigurationStoreSettings getApplicationSettings(String scopeId } @Override - public void setApplicationSettings(GwtXSRFToken xsrfToken, String scopeIdString, String deviceIdString, GwtDeviceConfigurationStoreSettings gwtDeviceConfigurationStoreSettings) throws GwtKapuaException { + public void setApplicationSettings(GwtXSRFToken xsrfToken, String scopeIdString, String deviceIdString, GwtDeviceConfigurationStoreSettings gwtDeviceConfigurationStoreSettings) + throws GwtKapuaException { checkXSRFToken(xsrfToken); try { @@ -677,36 +681,36 @@ private Object getObjectValue(GwtConfigParameter gwtConfigParam, String strValue if (strValue != null) { GwtConfigParameterType gwtType = gwtConfigParam.getType(); switch (gwtType) { - case LONG: - objValue = Long.parseLong(strValue); - break; - case DOUBLE: - objValue = Double.parseDouble(strValue); - break; - case FLOAT: - objValue = Float.parseFloat(strValue); - break; - case INTEGER: - objValue = Integer.parseInt(strValue); - break; - case SHORT: - objValue = Short.parseShort(strValue); - break; - case BYTE: - objValue = Byte.parseByte(strValue); - break; - case BOOLEAN: - objValue = Boolean.parseBoolean(strValue); - break; - case PASSWORD: - objValue = new Password(strValue); - break; - case CHAR: - objValue = strValue.charAt(0); - break; - case STRING: - objValue = strValue; - break; + case LONG: + objValue = Long.parseLong(strValue); + break; + case DOUBLE: + objValue = Double.parseDouble(strValue); + break; + case FLOAT: + objValue = Float.parseFloat(strValue); + break; + case INTEGER: + objValue = Integer.parseInt(strValue); + break; + case SHORT: + objValue = Short.parseShort(strValue); + break; + case BYTE: + objValue = Byte.parseByte(strValue); + break; + case BOOLEAN: + objValue = Boolean.parseBoolean(strValue); + break; + case PASSWORD: + objValue = new Password(strValue); + break; + case CHAR: + objValue = strValue.charAt(0); + break; + case STRING: + objValue = strValue; + break; } } return objValue; @@ -716,79 +720,76 @@ private Object[] getObjectValue(GwtConfigParameter gwtConfigParam, String[] defa List values = new ArrayList(); GwtConfigParameterType type = gwtConfigParam.getType(); switch (type) { - case BOOLEAN: - for (String value : defaultValues) { - values.add(Boolean.valueOf(value)); - } - return values.toArray(); + case BOOLEAN: + for (String value : defaultValues) { + values.add(Boolean.valueOf(value)); + } + return values.toArray(); - case BYTE: - for (String value : defaultValues) { - values.add(Byte.valueOf(value)); - } - return values.toArray(); + case BYTE: + for (String value : defaultValues) { + values.add(Byte.valueOf(value)); + } + return values.toArray(); - case CHAR: - for (String value : defaultValues) { - values.add(value.charAt(0)); - } - return values.toArray(); + case CHAR: + for (String value : defaultValues) { + values.add(value.charAt(0)); + } + return values.toArray(); - case DOUBLE: - for (String value : defaultValues) { - values.add(Double.valueOf(value)); - } - return values.toArray(); + case DOUBLE: + for (String value : defaultValues) { + values.add(Double.valueOf(value)); + } + return values.toArray(); - case FLOAT: - for (String value : defaultValues) { - values.add(Float.valueOf(value)); - } - return values.toArray(); + case FLOAT: + for (String value : defaultValues) { + values.add(Float.valueOf(value)); + } + return values.toArray(); - case INTEGER: - for (String value : defaultValues) { - values.add(Integer.valueOf(value)); - } - return values.toArray(); + case INTEGER: + for (String value : defaultValues) { + values.add(Integer.valueOf(value)); + } + return values.toArray(); - case LONG: - for (String value : defaultValues) { - values.add(Long.valueOf(value)); - } - return values.toArray(); + case LONG: + for (String value : defaultValues) { + values.add(Long.valueOf(value)); + } + return values.toArray(); - case SHORT: - for (String value : defaultValues) { - values.add(Short.valueOf(value)); - } - return values.toArray(); + case SHORT: + for (String value : defaultValues) { + values.add(Short.valueOf(value)); + } + return values.toArray(); - case PASSWORD: - for (String value : defaultValues) { - values.add(new Password(value)); - } - return values.toArray(); + case PASSWORD: + for (String value : defaultValues) { + values.add(new Password(value)); + } + return values.toArray(); - case STRING: - default: - return defaultValues; + case STRING: + default: + return defaultValues; } } /** - * Checks the source of the icon. - * The component config icon can be one of the well known icon (i.e. MqttDataTransport icon) - * as well as an icon loaded from external source with an HTTP link. + * Checks the source of the icon. The component config icon can be one of the well known icon (i.e. MqttDataTransport icon) as well as an icon loaded from external source with an HTTP link. *

- * We need to filter HTTP link to protect the console page and also to have content always served from - * EC console. Otherwise browsers can alert the user that content is served from domain different from - * *.everyware-cloud.com and over insicure connection. + * We need to filter HTTP link to protect the console page and also to have content always served from EC console. Otherwise browsers can alert the user that content is served from domain + * different from *.everyware-cloud.com and over insicure connection. *

- * To avoid this we will download the image locally on the server temporary directory and give back the page - * a token URL to get the file. + * To avoid this we will download the image locally on the server temporary directory and give back the page a token URL to get the file. * - * @param icon The icon from the OCD of the component configuration. + * @param icon + * The icon from the OCD of the component configuration. */ private void checkIconResource(KapuaTicon icon) { ConsoleSetting config = ConsoleSetting.getInstance(); diff --git a/qa/common/src/main/java/org/eclipse/kapua/qa/common/SimulatedDeviceSteps.java b/qa/common/src/main/java/org/eclipse/kapua/qa/common/SimulatedDeviceSteps.java index dbe3ef150c4..be030528a98 100644 --- a/qa/common/src/main/java/org/eclipse/kapua/qa/common/SimulatedDeviceSteps.java +++ b/qa/common/src/main/java/org/eclipse/kapua/qa/common/SimulatedDeviceSteps.java @@ -42,7 +42,6 @@ import org.eclipse.kapua.service.device.management.bundle.DeviceBundle; import org.eclipse.kapua.service.device.management.bundle.DeviceBundleManagementService; import org.eclipse.kapua.service.device.management.bundle.DeviceBundles; -import org.eclipse.kapua.service.device.management.packages.DevicePackageFactory; import org.eclipse.kapua.service.device.management.packages.DevicePackageManagementService; import org.eclipse.kapua.service.device.management.packages.model.DevicePackage; import org.eclipse.kapua.service.device.management.packages.model.DevicePackageBundleInfo; @@ -334,7 +333,7 @@ public void downloadPackage(final String packageName, final String version, fina With.withDevice(account, currentDevice.getClientId(), device -> { final DevicePackageManagementService service = KapuaLocator.getInstance().getService(DevicePackageManagementService.class); - final DevicePackageDownloadRequest request = KapuaLocator.getInstance().getFactory(DevicePackageFactory.class).newPackageDownloadRequest(); + final DevicePackageDownloadRequest request = new DevicePackageDownloadRequest(); request.setInstall(true); request.setName(packageName); request.setVersion(version); diff --git a/rest-api/resources/src/main/java/org/eclipse/kapua/app/api/resources/v1/resources/DeviceManagementPackages.java b/rest-api/resources/src/main/java/org/eclipse/kapua/app/api/resources/v1/resources/DeviceManagementPackages.java index 4cb368ecfff..cb696d05ad4 100644 --- a/rest-api/resources/src/main/java/org/eclipse/kapua/app/api/resources/v1/resources/DeviceManagementPackages.java +++ b/rest-api/resources/src/main/java/org/eclipse/kapua/app/api/resources/v1/resources/DeviceManagementPackages.java @@ -12,6 +12,17 @@ *******************************************************************************/ package org.eclipse.kapua.app.api.resources.v1.resources; +import javax.inject.Inject; +import javax.ws.rs.DefaultValue; +import javax.ws.rs.GET; +import javax.ws.rs.POST; +import javax.ws.rs.Path; +import javax.ws.rs.PathParam; +import javax.ws.rs.Produces; +import javax.ws.rs.QueryParam; +import javax.ws.rs.core.MediaType; +import javax.ws.rs.core.Response; + import org.eclipse.kapua.KapuaException; import org.eclipse.kapua.app.api.core.model.EntityId; import org.eclipse.kapua.app.api.core.model.ScopeId; @@ -21,7 +32,6 @@ import org.eclipse.kapua.locator.KapuaLocator; import org.eclipse.kapua.model.id.KapuaId; import org.eclipse.kapua.service.KapuaService; -import org.eclipse.kapua.service.device.management.packages.DevicePackageFactory; import org.eclipse.kapua.service.device.management.packages.DevicePackageManagementService; import org.eclipse.kapua.service.device.management.packages.model.DevicePackages; import org.eclipse.kapua.service.device.management.packages.model.download.DevicePackageDownloadOptions; @@ -32,41 +42,33 @@ import org.eclipse.kapua.service.device.management.registry.operation.DeviceManagementOperationRegistryService; import org.eclipse.kapua.service.device.registry.Device; -import javax.inject.Inject; -import javax.ws.rs.DefaultValue; -import javax.ws.rs.GET; -import javax.ws.rs.POST; -import javax.ws.rs.Path; -import javax.ws.rs.PathParam; -import javax.ws.rs.Produces; -import javax.ws.rs.QueryParam; -import javax.ws.rs.core.MediaType; -import javax.ws.rs.core.Response; - @Path("{scopeId}/devices/{deviceId}/packages") public class DeviceManagementPackages extends AbstractKapuaResource { - private final Boolean responseLegacyMode = KapuaLocator.getInstance().getComponent(KapuaApiCoreSetting.class).getBoolean(KapuaApiCoreSettingKeys.API_DEVICE_MANAGEMENT_PACKAGE_RESPONSE_LEGACY_MODE, false); + private final Boolean responseLegacyMode = KapuaLocator.getInstance().getComponent(KapuaApiCoreSetting.class) + .getBoolean(KapuaApiCoreSettingKeys.API_DEVICE_MANAGEMENT_PACKAGE_RESPONSE_LEGACY_MODE, false); @Inject public DevicePackageManagementService devicePackageManagementService; @Inject - public DevicePackageFactory devicePackageFactory; - @Inject public DeviceManagementOperationRegistryService deviceManagementOperationRegistryService; /** * Returns the list of all the packages installed on the device. * - * @param scopeId The {@link ScopeId} in which to search results. - * @param deviceId The id of the device - * @param timeout The timeout of the operation + * @param scopeId + * The {@link ScopeId} in which to search results. + * @param deviceId + * The id of the device + * @param timeout + * The timeout of the operation * @return The list of packages installed. - * @throws KapuaException Whenever something bad happens. See specific {@link KapuaService} exceptions. + * @throws KapuaException + * Whenever something bad happens. See specific {@link KapuaService} exceptions. * @since 1.0.0 */ @GET - @Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML}) + @Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML }) public DevicePackages get( @PathParam("scopeId") ScopeId scopeId, @PathParam("deviceId") EntityId deviceId, @@ -77,17 +79,22 @@ public DevicePackages get( /** * Download and optionally installs a package into the device. * - * @param scopeId The {@link ScopeId} in which to search results. - * @param deviceId The {@link Device} ID. - * @param timeout The timeout of the operation - * @param packageDownloadRequest Mandatory object with all the informations needed to download and install a package + * @param scopeId + * The {@link ScopeId} in which to search results. + * @param deviceId + * The {@link Device} ID. + * @param timeout + * The timeout of the operation + * @param packageDownloadRequest + * Mandatory object with all the informations needed to download and install a package * @return HTTP 200 if operation has completed successfully. - * @throws KapuaException Whenever something bad happens. See specific {@link KapuaService} exceptions. + * @throws KapuaException + * Whenever something bad happens. See specific {@link KapuaService} exceptions. * @since 1.0.0 */ @POST @Path("_download") - @Produces({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON}) + @Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON }) public Response download( @PathParam("scopeId") ScopeId scopeId, @PathParam("deviceId") EntityId deviceId, @@ -95,7 +102,7 @@ public Response download( @QueryParam("legacy") @DefaultValue("false") boolean legacy, DevicePackageDownloadRequest packageDownloadRequest) throws KapuaException { - DevicePackageDownloadOptions options = devicePackageFactory.newPackageDownloadOptions(); + DevicePackageDownloadOptions options = new DevicePackageDownloadOptions(); options.setTimeout(timeout); KapuaId deviceManagementOperationId = devicePackageManagementService.downloadExec(scopeId, deviceId, packageDownloadRequest, options); @@ -108,24 +115,29 @@ public Response download( /** * Uninstalls a package into the device. * - * @param scopeId The {@link ScopeId} in which to search results. - * @param deviceId The {@link Device} ID. - * @param timeout The timeout of the operation - * @param packageUninstallRequest Mandatory object with all the informations needed to uninstall a package + * @param scopeId + * The {@link ScopeId} in which to search results. + * @param deviceId + * The {@link Device} ID. + * @param timeout + * The timeout of the operation + * @param packageUninstallRequest + * Mandatory object with all the informations needed to uninstall a package * @return HTTP 200 if operation has completed successfully. - * @throws KapuaException Whenever something bad happens. See specific {@link KapuaService} exceptions. + * @throws KapuaException + * Whenever something bad happens. See specific {@link KapuaService} exceptions. * @since 1.0.0 */ @POST @Path("_uninstall") - @Produces({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON}) + @Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON }) public Response uninstall( @PathParam("scopeId") ScopeId scopeId, @PathParam("deviceId") EntityId deviceId, @QueryParam("timeout") @DefaultValue("30000") Long timeout, @QueryParam("legacy") @DefaultValue("false") boolean legacy, DevicePackageUninstallRequest packageUninstallRequest) throws KapuaException { - DevicePackageUninstallOptions options = devicePackageFactory.newPackageUninstallOptions(); + DevicePackageUninstallOptions options = new DevicePackageUninstallOptions(); options.setTimeout(timeout); KapuaId deviceManagementOperationId = devicePackageManagementService.uninstallExec(scopeId, deviceId, packageUninstallRequest, options); diff --git a/service/api/src/main/java/org/eclipse/kapua/model/domain/Actions.java b/service/api/src/main/java/org/eclipse/kapua/model/domain/Actions.java index 480fb8ea560..ba95d84737d 100644 --- a/service/api/src/main/java/org/eclipse/kapua/model/domain/Actions.java +++ b/service/api/src/main/java/org/eclipse/kapua/model/domain/Actions.java @@ -13,7 +13,6 @@ package org.eclipse.kapua.model.domain; import org.eclipse.kapua.model.KapuaEntityCreator; -import org.eclipse.kapua.model.KapuaUpdatableEntity; import org.eclipse.kapua.model.id.KapuaId; import org.eclipse.kapua.model.query.KapuaQuery; import org.eclipse.kapua.service.KapuaEntityService; @@ -21,8 +20,7 @@ import org.eclipse.kapua.service.KapuaUpdatableEntityService; /** - * {@link Actions} implementation {@code enum}.
- * Available actions defined are: + * {@link Actions} implementation {@code enum}.
Available actions defined are: *