diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.api/src/main/java/org/wso2/carbon/device/application/mgt/api/APIUtil.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.api/src/main/java/org/wso2/carbon/device/application/mgt/api/APIUtil.java index 97b9db0be3f..7755a77af94 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.api/src/main/java/org/wso2/carbon/device/application/mgt/api/APIUtil.java +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.api/src/main/java/org/wso2/carbon/device/application/mgt/api/APIUtil.java @@ -22,9 +22,13 @@ import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.wso2.carbon.context.PrivilegedCarbonContext; import org.wso2.carbon.device.application.mgt.api.beans.ErrorResponse; -import org.wso2.carbon.device.application.mgt.common.exception.ApplicationManagementException; -import org.wso2.carbon.device.application.mgt.common.services.*; -import org.wso2.carbon.device.mgt.core.service.DeviceManagementProviderService; +import org.wso2.carbon.device.application.mgt.common.services.ApplicationManager; +import org.wso2.carbon.device.application.mgt.common.services.ApplicationReleaseManager; +import org.wso2.carbon.device.application.mgt.common.services.ApplicationStorageManager; +import org.wso2.carbon.device.application.mgt.common.services.LifecycleStateManager; +import org.wso2.carbon.device.application.mgt.common.services.PlatformManager; +import org.wso2.carbon.device.application.mgt.common.services.PlatformStorageManager; +import org.wso2.carbon.device.application.mgt.common.services.SubscriptionManager; import javax.ws.rs.core.Response; diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.api/src/main/java/org/wso2/carbon/device/application/mgt/api/services/impl/PlatformManagementAPIImpl.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.api/src/main/java/org/wso2/carbon/device/application/mgt/api/services/impl/PlatformManagementAPIImpl.java index a62a52e52ff..46ddae38c4e 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.api/src/main/java/org/wso2/carbon/device/application/mgt/api/services/impl/PlatformManagementAPIImpl.java +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.api/src/main/java/org/wso2/carbon/device/application/mgt/api/services/impl/PlatformManagementAPIImpl.java @@ -29,6 +29,7 @@ import org.wso2.carbon.device.application.mgt.common.Platform; import org.wso2.carbon.device.application.mgt.common.exception.PlatformManagementException; import org.wso2.carbon.device.application.mgt.common.exception.PlatformStorageManagementException; import org.wso2.carbon.device.application.mgt.common.exception.ResourceManagementException; +import org.wso2.carbon.device.application.mgt.common.services.PlatformStorageManager; import org.wso2.carbon.device.application.mgt.core.exception.PlatformManagementDAOException; import java.io.IOException; @@ -61,6 +62,7 @@ public class PlatformManagementAPIImpl implements PlatformManagementAPI { @Override public Response getPlatforms(@QueryParam("status") String status, @QueryParam("tag") String tag) { int tenantID = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true); + PlatformStorageManager platformStorageManager = APIUtil.getPlatformStorageManager(); if (log.isDebugEnabled()) { log.debug("API request received for getting the platforms with the status " + status); @@ -92,25 +94,25 @@ public class PlatformManagementAPIImpl implements PlatformManagementAPI { } else { results = platforms; } - - if (tag != null) { - if (results != null) { - for (Platform platform : results) { - if (platform.getTags() != null && platform.getTags().contains(tag)) { - filteredPlatforms.add(platform); - } + if (results != null) { + for (Platform platform : results) { + if (tag == null || tag.isEmpty() || (platform.getTags() != null && platform.getTags() + .contains(tag))) { + platform.setIcon(platformStorageManager.getIcon(platform.getIdentifier())); + filteredPlatforms.add(platform); } } - } else { - filteredPlatforms = results; - } - if (log.isDebugEnabled()) { - log.debug("Number of platforms with the status " + status + " : " + results.size()); + if (log.isDebugEnabled()) { + log.debug("Number of platforms with the status " + status + " : " + results.size()); + } } return Response.status(Response.Status.OK).entity(filteredPlatforms).build(); } catch (PlatformManagementException e) { log.error("Error while getting the platforms for tenant - " + tenantID, e); return APIUtil.getResponse(e, Response.Status.INTERNAL_SERVER_ERROR); + } catch (PlatformStorageManagementException e) { + log.error("Error while getting platform icons for the tenant : " + tenantID, e); + return APIUtil.getResponse(e, Response.Status.INTERNAL_SERVER_ERROR); } } @@ -126,7 +128,9 @@ public class PlatformManagementAPIImpl implements PlatformManagementAPI { return Response.status(Response.Status.NOT_FOUND).entity("Platform not found").build(); } ImageArtifact icon = APIUtil.getPlatformStorageManager().getIcon(id); - + if (icon != null) { + platform.setIcon(icon); + } return Response.status(Response.Status.OK).entity(platform).build(); } catch (PlatformManagementDAOException e) { log.error("Error while trying the get the platform with the identifier : " + id + " for the tenant :" @@ -137,8 +141,8 @@ public class PlatformManagementAPIImpl implements PlatformManagementAPI { + tenantId, e); return APIUtil.getResponse(e, Response.Status.NOT_FOUND); } catch (PlatformStorageManagementException e) { - log.error("Platform Storage Management Exception while trying to update the icon for the platform : " + - id + " for the tenant : " + tenantId, e); + log.error("Platform Storage Management Exception while trying to update the icon for the platform : " + id + + " for the tenant : " + tenantId, e); return APIUtil.getResponse(e, Response.Status.NOT_FOUND); } } @@ -205,8 +209,9 @@ public class PlatformManagementAPIImpl implements PlatformManagementAPI { APIUtil.getPlatformManager().unregister(tenantId, id, false); return Response.status(Response.Status.OK).build(); } catch (PlatformManagementException e) { - log.error("Platform Management Exception while trying to un-register the platform with the identifier : " - + id + " for the tenant : " + tenantId, e); + log.error( + "Platform Management Exception while trying to un-register the platform with the identifier : " + id + + " for the tenant : " + tenantId, e); return APIUtil.getResponse(e, Response.Status.INTERNAL_SERVER_ERROR); } catch (PlatformStorageManagementException e) { log.error("Platform Storage Management Exception while trying to delete the icon of the platform with " diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/impl/SubscriptionManagerImpl.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/impl/SubscriptionManagerImpl.java index 6fc19346fd3..3667e0953d3 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/impl/SubscriptionManagerImpl.java +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/impl/SubscriptionManagerImpl.java @@ -19,7 +19,6 @@ package org.wso2.carbon.device.application.mgt.core.impl; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; -import org.wso2.carbon.context.PrivilegedCarbonContext; import org.wso2.carbon.device.application.mgt.common.DeviceIdentifier; import org.wso2.carbon.device.application.mgt.common.exception.ApplicationManagementException; import org.wso2.carbon.device.application.mgt.common.services.SubscriptionManager; @@ -41,7 +40,6 @@ import org.wso2.carbon.device.mgt.core.service.DeviceManagementProviderService; import java.sql.SQLException; import java.util.ArrayList; import java.util.List; -import java.util.Map; /** * This is the default implementation for the Subscription Manager. @@ -63,13 +61,9 @@ public class SubscriptionManagerImpl implements SubscriptionManager { org.wso2.carbon.device.mgt.common.DeviceIdentifier deviceIdentifier = new org.wso2.carbon.device.mgt .common.DeviceIdentifier(device.getId(), device.getType()); try { - DeviceManagementDAOFactory.openConnection(); - // todo: replace this with boolean:deviceExsits(deviceId) operation - Map currentDevices = DeviceManagementDAOFactory.getDeviceDAO().getDevice(deviceIdentifier); - DeviceManagementDAOFactory.closeConnection(); - - if (currentDevices.isEmpty()) { - log.error("Device with ID: " + device.getId() + " not found to install the application."); + DeviceManagementProviderService dmpService = DataHolder.getInstance().getDeviceManagementService(); + if (!dmpService.isEnrolled(deviceIdentifier)) { + log.error("Device with ID: " + device.getId() + " is not enrolled to install the application."); } else { if (log.isDebugEnabled()) { log.debug("Installing application to : " + device.getId()); @@ -96,10 +90,8 @@ public class SubscriptionManagerImpl implements SubscriptionManager { // DAOFactory.getSubscriptionDAO().addDeviceApplicationMapping(device.getId(), applicationUUID, false); failedDeviceList.remove(device); } - } catch (DeviceManagementException | DeviceManagementDAOException | OperationManagementException | InvalidDeviceException | SQLException e) { + } catch (DeviceManagementException | OperationManagementException | InvalidDeviceException e) { throw new ApplicationManagementException("Failed to install application " + applicationUUID + " on device " + deviceIdentifier, e); - } finally { - DeviceManagementDAOFactory.closeConnection(); } } return failedDeviceList; @@ -110,15 +102,14 @@ public class SubscriptionManagerImpl implements SubscriptionManager { throws ApplicationManagementException { log.info("Install application: " + applicationUUID + " to: " + userList.size() + " users."); List deviceList = new ArrayList<>(); - int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(); for (String user : userList) { try { - List devicesOfUser = DeviceManagementDAOFactory.getDeviceDAO().getDevicesOfUser(user, tenantId); + List devicesOfUser = DataHolder.getInstance().getDeviceManagementService().getDevicesOfUser(user); for (Device device : devicesOfUser) { deviceList.add(new DeviceIdentifier(device .getDeviceIdentifier(), device.getType())); } - } catch (DeviceManagementDAOException e) { + } catch (DeviceManagementException e) { log.error("Error when extracting the device list from user[" + user + "].", e); } } diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/internal/DataHolder.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/internal/DataHolder.java index 31de14afa36..5019ac1cd99 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/internal/DataHolder.java +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/internal/DataHolder.java @@ -18,7 +18,16 @@ */ package org.wso2.carbon.device.application.mgt.core.internal; -import org.wso2.carbon.device.application.mgt.common.services.*; +import org.wso2.carbon.device.application.mgt.common.services.ApplicationManager; +import org.wso2.carbon.device.application.mgt.common.services.ApplicationReleaseManager; +import org.wso2.carbon.device.application.mgt.common.services.ApplicationStorageManager; +import org.wso2.carbon.device.application.mgt.common.services.CategoryManager; +import org.wso2.carbon.device.application.mgt.common.services.CommentsManager; +import org.wso2.carbon.device.application.mgt.common.services.LifecycleStateManager; +import org.wso2.carbon.device.application.mgt.common.services.PlatformManager; +import org.wso2.carbon.device.application.mgt.common.services.PlatformStorageManager; +import org.wso2.carbon.device.application.mgt.common.services.SubscriptionManager; +import org.wso2.carbon.device.application.mgt.common.services.VisibilityManager; import org.wso2.carbon.device.mgt.core.service.DeviceManagementProviderService; import org.wso2.carbon.user.core.service.RealmService; @@ -152,4 +161,8 @@ public class DataHolder { public void setPlatformStorageManager(PlatformStorageManager platformStorageManager) { this.platformStorageManager = platformStorageManager; } + + public PlatformStorageManager getPlatformStorageManager() { + return platformStorageManager; + } } diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/internal/ServiceComponent.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/internal/ServiceComponent.java index bb121072849..9de7e593b21 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/internal/ServiceComponent.java +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/internal/ServiceComponent.java @@ -23,12 +23,20 @@ import org.apache.commons.logging.LogFactory; import org.osgi.framework.BundleContext; import org.osgi.service.component.ComponentContext; import org.wso2.carbon.device.application.mgt.common.exception.InvalidConfigurationException; -import org.wso2.carbon.device.application.mgt.common.services.*; +import org.wso2.carbon.device.application.mgt.common.services.ApplicationManager; +import org.wso2.carbon.device.application.mgt.common.services.ApplicationReleaseManager; +import org.wso2.carbon.device.application.mgt.common.services.ApplicationStorageManager; +import org.wso2.carbon.device.application.mgt.common.services.CategoryManager; +import org.wso2.carbon.device.application.mgt.common.services.CommentsManager; +import org.wso2.carbon.device.application.mgt.common.services.LifecycleStateManager; +import org.wso2.carbon.device.application.mgt.common.services.PlatformManager; +import org.wso2.carbon.device.application.mgt.common.services.PlatformStorageManager; +import org.wso2.carbon.device.application.mgt.common.services.SubscriptionManager; +import org.wso2.carbon.device.application.mgt.common.services.VisibilityManager; import org.wso2.carbon.device.application.mgt.core.config.ConfigurationManager; import org.wso2.carbon.device.application.mgt.core.dao.common.DAOFactory; import org.wso2.carbon.device.application.mgt.core.exception.ApplicationManagementDAOException; import org.wso2.carbon.device.application.mgt.core.util.ApplicationManagementUtil; -import org.wso2.carbon.device.application.mgt.core.util.Constants; import org.wso2.carbon.device.mgt.core.service.DeviceManagementProviderService; import org.wso2.carbon.ndatasource.core.DataSourceService; import org.wso2.carbon.user.core.service.RealmService; diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/util/ApplicationManagementUtil.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/util/ApplicationManagementUtil.java index acc83f34ae5..1604b4768d7 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/util/ApplicationManagementUtil.java +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/util/ApplicationManagementUtil.java @@ -21,7 +21,16 @@ package org.wso2.carbon.device.application.mgt.core.util; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.wso2.carbon.device.application.mgt.common.exception.InvalidConfigurationException; -import org.wso2.carbon.device.application.mgt.common.services.*; +import org.wso2.carbon.device.application.mgt.common.services.ApplicationManager; +import org.wso2.carbon.device.application.mgt.common.services.ApplicationReleaseManager; +import org.wso2.carbon.device.application.mgt.common.services.ApplicationStorageManager; +import org.wso2.carbon.device.application.mgt.common.services.CategoryManager; +import org.wso2.carbon.device.application.mgt.common.services.CommentsManager; +import org.wso2.carbon.device.application.mgt.common.services.LifecycleStateManager; +import org.wso2.carbon.device.application.mgt.common.services.PlatformManager; +import org.wso2.carbon.device.application.mgt.common.services.PlatformStorageManager; +import org.wso2.carbon.device.application.mgt.common.services.SubscriptionManager; +import org.wso2.carbon.device.application.mgt.common.services.VisibilityManager; import org.wso2.carbon.device.application.mgt.core.config.ConfigurationManager; import org.wso2.carbon.device.application.mgt.core.config.Extension; diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/util/StorageManagementUtil.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/util/StorageManagementUtil.java index d644fb52cd1..4c8f01250d2 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/util/StorageManagementUtil.java +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/util/StorageManagementUtil.java @@ -1,3 +1,21 @@ +/* +* Copyright (c) 2017, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. +* WSO2 Inc. licenses this file to you under the Apache License, +* Version 2.0 (the "License"); you may not use this file except +* in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, +* software distributed under the License is distributed on an +* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +* KIND, either express or implied. See the License for the +* specific language governing permissions and limitations +* under the License. +* +*/ + package org.wso2.carbon.device.application.mgt.core.util; import org.apache.commons.codec.binary.Base64; @@ -6,7 +24,12 @@ import org.wso2.carbon.device.application.mgt.common.ImageArtifact; import org.wso2.carbon.device.application.mgt.common.exception.ApplicationStorageManagementException; import org.wso2.carbon.device.application.mgt.common.exception.ResourceManagementException; -import java.io.*; +import java.io.File; +import java.io.FileInputStream; +import java.io.FileOutputStream; +import java.io.IOException; +import java.io.InputStream; +import java.io.OutputStream; import java.nio.file.Files; public class StorageManagementUtil { diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/test/resources/application-mgt.xml b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/test/resources/application-mgt.xml index c2cac418578..618a2093b9c 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/test/resources/application-mgt.xml +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/test/resources/application-mgt.xml @@ -58,4 +58,4 @@ - \ No newline at end of file + diff --git a/features/application-mgt/org.wso2.carbon.device.application.mgt.server.feature/src/main/resources/conf/application-mgt.xml b/features/application-mgt/org.wso2.carbon.device.application.mgt.server.feature/src/main/resources/conf/application-mgt.xml index bd74672de3c..38bf6168c72 100644 --- a/features/application-mgt/org.wso2.carbon.device.application.mgt.server.feature/src/main/resources/conf/application-mgt.xml +++ b/features/application-mgt/org.wso2.carbon.device.application.mgt.server.feature/src/main/resources/conf/application-mgt.xml @@ -60,4 +60,4 @@ - \ No newline at end of file +