Refactoring

merge-requests/7/head
megala21 7 years ago
parent f417f7854e
commit 2fcf1c4e70

@ -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;

@ -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 "

@ -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<Integer, Device> 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<DeviceIdentifier> deviceList = new ArrayList<>();
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId();
for (String user : userList) {
try {
List<Device> devicesOfUser = DeviceManagementDAOFactory.getDeviceDAO().getDevicesOfUser(user, tenantId);
List<Device> 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);
}
}

@ -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;
}
}

@ -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;

@ -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;

@ -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 {

@ -58,4 +58,4 @@
</Extension>
</Extensions>
</ApplicationManagementConfiguration>
</ApplicationManagementConfiguration>

@ -60,4 +60,4 @@
</Parameters>
</Extension>
</Extensions>
</ApplicationManagementConfiguration>
</ApplicationManagementConfiguration>

Loading…
Cancel
Save