Merge pull request #764 from harshanL/master

Fixes product-iots#991
revert-70aa11f8
Geeth 7 years ago committed by GitHub
commit f3666ac175

@ -57,7 +57,7 @@ public class FCMNotificationStrategy implements NotificationStrategy {
public void execute(NotificationContext ctx) throws PushNotificationExecutionFailedException { public void execute(NotificationContext ctx) throws PushNotificationExecutionFailedException {
try { try {
Device device = Device device =
FCMDataHolder.getInstance().getDeviceManagementProviderService().getDevice(ctx.getDeviceId()); FCMDataHolder.getInstance().getDeviceManagementProviderService().getDeviceWithTypeProperties(ctx.getDeviceId());
this.sendWakeUpCall(ctx.getOperation().getCode(), device); this.sendWakeUpCall(ctx.getOperation().getCode(), device);
} catch (DeviceManagementException e) { } catch (DeviceManagementException e) {
throw new PushNotificationExecutionFailedException("Error occurred while retrieving device information", e); throw new PushNotificationExecutionFailedException("Error occurred while retrieving device information", e);

@ -267,6 +267,13 @@ public interface DeviceManagementService {
required = false) required = false)
@HeaderParam("If-Modified-Since") @HeaderParam("If-Modified-Since")
String timestamp, String timestamp,
@ApiParam(
name = "requireDeviceInfo",
value = "Boolean flag indicating whether to include device-info (location, application list etc) \n" +
" to the device object.",
required = false)
@QueryParam("requireDeviceInfo")
boolean requireDeviceInfo,
@ApiParam( @ApiParam(
name = "offset", name = "offset",
value = "The starting pagination index for the complete list of qualified items.", value = "The starting pagination index for the complete list of qualified items.",
@ -333,6 +340,13 @@ public interface DeviceManagementService {
}) })
@Path("/user-devices") @Path("/user-devices")
Response getDeviceByUser( Response getDeviceByUser(
@ApiParam(
name = "requireDeviceInfo",
value = "Boolean flag indicating whether to include device-info (location, application list etc) \n" +
" to the device object.",
required = false)
@QueryParam("requireDeviceInfo")
boolean requireDeviceInfo,
@ApiParam( @ApiParam(
name = "offset", name = "offset",
value = "The starting pagination index for the complete list of qualified items.", value = "The starting pagination index for the complete list of qualified items.",

@ -18,7 +18,6 @@
*/ */
package org.wso2.carbon.device.mgt.jaxrs.service.impl; package org.wso2.carbon.device.mgt.jaxrs.service.impl;
import io.swagger.annotations.ApiParam;
import org.apache.commons.lang.StringUtils; import org.apache.commons.lang.StringUtils;
import org.apache.commons.logging.Log; import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory; import org.apache.commons.logging.LogFactory;
@ -97,6 +96,7 @@ public class DeviceManagementServiceImpl implements DeviceManagementService {
@QueryParam("groupId") int groupId, @QueryParam("groupId") int groupId,
@QueryParam("since") String since, @QueryParam("since") String since,
@HeaderParam("If-Modified-Since") String ifModifiedSince, @HeaderParam("If-Modified-Since") String ifModifiedSince,
@QueryParam("requireDeviceInfo") boolean requireDeviceInfo,
@QueryParam("offset") int offset, @QueryParam("offset") int offset,
@QueryParam("limit") int limit) { @QueryParam("limit") int limit) {
try { try {
@ -180,7 +180,12 @@ public class DeviceManagementServiceImpl implements DeviceManagementService {
"string is provided in 'If-Modified-Since' header").build()).build(); "string is provided in 'If-Modified-Since' header").build()).build();
} }
request.setSince(sinceDate); request.setSince(sinceDate);
result = dms.getAllDevices(request); if (requireDeviceInfo) {
result = dms.getAllDevices(request);
} else {
result = dms.getAllDevices(request, false);
}
if (result == null || result.getData() == null || result.getData().size() <= 0) { if (result == null || result.getData() == null || result.getData().size() <= 0) {
return Response.status(Response.Status.NOT_MODIFIED).entity("No device is modified " + return Response.status(Response.Status.NOT_MODIFIED).entity("No device is modified " +
"after the timestamp provided in 'If-Modified-Since' header").build(); "after the timestamp provided in 'If-Modified-Since' header").build();
@ -196,14 +201,22 @@ public class DeviceManagementServiceImpl implements DeviceManagementService {
"string is provided in 'since' filter").build()).build(); "string is provided in 'since' filter").build()).build();
} }
request.setSince(sinceDate); request.setSince(sinceDate);
result = dms.getAllDevices(request); if (requireDeviceInfo) {
result = dms.getAllDevices(request);
} else {
result = dms.getAllDevices(request, false);
}
if (result == null || result.getData() == null || result.getData().size() <= 0) { if (result == null || result.getData() == null || result.getData().size() <= 0) {
devices.setList(new ArrayList<Device>()); devices.setList(new ArrayList<Device>());
devices.setCount(0); devices.setCount(0);
return Response.status(Response.Status.OK).entity(devices).build(); return Response.status(Response.Status.OK).entity(devices).build();
} }
} else { } else {
result = dms.getAllDevices(request); if (requireDeviceInfo) {
result = dms.getAllDevices(request);
} else {
result = dms.getAllDevices(request, false);
}
int resultCount = result.getRecordsTotal(); int resultCount = result.getRecordsTotal();
if (resultCount == 0) { if (resultCount == 0) {
Response.status(Response.Status.OK).entity(devices).build(); Response.status(Response.Status.OK).entity(devices).build();
@ -229,7 +242,8 @@ public class DeviceManagementServiceImpl implements DeviceManagementService {
@GET @GET
@Override @Override
@Path("/user-devices") @Path("/user-devices")
public Response getDeviceByUser(@QueryParam("offset") int offset, public Response getDeviceByUser(@QueryParam("requireDeviceInfo") boolean requireDeviceInfo,
@QueryParam("offset") int offset,
@QueryParam("limit") int limit) { @QueryParam("limit") int limit) {
RequestValidationUtil.validatePaginationParameters(offset, limit); RequestValidationUtil.validatePaginationParameters(offset, limit);
@ -241,7 +255,11 @@ public class DeviceManagementServiceImpl implements DeviceManagementService {
request.setOwner(currentUser); request.setOwner(currentUser);
try { try {
result = DeviceMgtAPIUtils.getDeviceManagementService().getDevicesOfUser(request); if (requireDeviceInfo) {
result = DeviceMgtAPIUtils.getDeviceManagementService().getDevicesOfUser(request);
} else {
result = DeviceMgtAPIUtils.getDeviceManagementService().getDevicesOfUser(request, false);
}
devices.setList((List<Device>) result.getData()); devices.setList((List<Device>) result.getData());
devices.setCount(result.getRecordsTotal()); devices.setCount(result.getRecordsTotal());
return Response.status(Response.Status.OK).entity(devices).build(); return Response.status(Response.Status.OK).entity(devices).build();
@ -261,7 +279,7 @@ public class DeviceManagementServiceImpl implements DeviceManagementService {
DeviceMgtAPIUtils.getDeviceManagementService(); DeviceMgtAPIUtils.getDeviceManagementService();
try { try {
DeviceIdentifier deviceIdentifier = new DeviceIdentifier(deviceId, deviceType); DeviceIdentifier deviceIdentifier = new DeviceIdentifier(deviceId, deviceType);
Device persistedDevice = deviceManagementProviderService.getDevice(deviceIdentifier); Device persistedDevice = deviceManagementProviderService.getDevice(deviceIdentifier, true);
if (persistedDevice == null) { if (persistedDevice == null) {
return Response.status(Response.Status.NOT_FOUND).build(); return Response.status(Response.Status.NOT_FOUND).build();
} }
@ -287,7 +305,7 @@ public class DeviceManagementServiceImpl implements DeviceManagementService {
DeviceManagementProviderService deviceManagementProviderService = DeviceMgtAPIUtils.getDeviceManagementService(); DeviceManagementProviderService deviceManagementProviderService = DeviceMgtAPIUtils.getDeviceManagementService();
try { try {
Device persistedDevice = deviceManagementProviderService.getDevice(new DeviceIdentifier Device persistedDevice = deviceManagementProviderService.getDevice(new DeviceIdentifier
(deviceId, deviceType)); (deviceId, deviceType), true);
persistedDevice.setName(device.getName()); persistedDevice.setName(device.getName());
boolean response = deviceManagementProviderService.modifyEnrollment(persistedDevice); boolean response = deviceManagementProviderService.modifyEnrollment(persistedDevice);
return Response.status(Response.Status.CREATED).entity(response).build(); return Response.status(Response.Status.CREATED).entity(response).build();
@ -586,7 +604,7 @@ public class DeviceManagementServiceImpl implements DeviceManagementService {
DeviceMgtAPIUtils.getDeviceManagementService(); DeviceMgtAPIUtils.getDeviceManagementService();
try { try {
DeviceIdentifier deviceIdentifier = new DeviceIdentifier(id, type); DeviceIdentifier deviceIdentifier = new DeviceIdentifier(id, type);
Device persistedDevice = deviceManagementProviderService.getDevice(deviceIdentifier); Device persistedDevice = deviceManagementProviderService.getDevice(deviceIdentifier, false);
if (persistedDevice == null) { if (persistedDevice == null) {
return Response.status(Response.Status.NOT_FOUND).build(); return Response.status(Response.Status.NOT_FOUND).build();
} }

@ -128,7 +128,7 @@ public class PolicyManagementServiceImpl implements PolicyManagementService {
List<DeviceIdentifier> deviceIdentifiers = policyWrapper.getDeviceIdentifiers(); List<DeviceIdentifier> deviceIdentifiers = policyWrapper.getDeviceIdentifiers();
if (deviceIdentifiers != null) { if (deviceIdentifiers != null) {
for (DeviceIdentifier id : deviceIdentifiers) { for (DeviceIdentifier id : deviceIdentifiers) {
devices.add(DeviceMgtAPIUtils.getDeviceManagementService().getDevice(id)); devices.add(DeviceMgtAPIUtils.getDeviceManagementService().getDevice(id, false));
} }
} }
policy.setDevices(devices); policy.setDevices(devices);

@ -25,6 +25,7 @@ import org.wso2.carbon.context.CarbonContext;
import org.wso2.carbon.context.PrivilegedCarbonContext; import org.wso2.carbon.context.PrivilegedCarbonContext;
import org.wso2.carbon.device.mgt.common.Device; import org.wso2.carbon.device.mgt.common.Device;
import org.wso2.carbon.device.mgt.common.DeviceManagementException; import org.wso2.carbon.device.mgt.common.DeviceManagementException;
import org.wso2.carbon.device.mgt.common.PaginationRequest;
import org.wso2.carbon.device.mgt.jaxrs.beans.DeviceList; import org.wso2.carbon.device.mgt.jaxrs.beans.DeviceList;
import org.wso2.carbon.device.mgt.jaxrs.beans.ErrorResponse; import org.wso2.carbon.device.mgt.jaxrs.beans.ErrorResponse;
import org.wso2.carbon.device.mgt.jaxrs.service.api.admin.DeviceManagementAdminService; import org.wso2.carbon.device.mgt.jaxrs.service.api.admin.DeviceManagementAdminService;
@ -64,8 +65,11 @@ public class DeviceManagementAdminServiceImpl implements DeviceManagementAdminSe
PrivilegedCarbonContext.getThreadLocalCarbonContext().setTenantDomain(tenantDomain); PrivilegedCarbonContext.getThreadLocalCarbonContext().setTenantDomain(tenantDomain);
PrivilegedCarbonContext.getThreadLocalCarbonContext().setTenantId(DeviceMgtAPIUtils.getTenantId(tenantDomain)); PrivilegedCarbonContext.getThreadLocalCarbonContext().setTenantId(DeviceMgtAPIUtils.getTenantId(tenantDomain));
PaginationRequest request = new PaginationRequest(offset, limit);
request.setDeviceType(type);
request.setDeviceName(name);
List<Device> devices = DeviceMgtAPIUtils.getDeviceManagementService(). List<Device> devices = DeviceMgtAPIUtils.getDeviceManagementService().
getDevicesByNameAndType(name, type, offset, limit); getDevicesByNameAndType(request, false);
// setting up paginated result // setting up paginated result
DeviceList deviceList = new DeviceList(); DeviceList deviceList = new DeviceList();

@ -114,7 +114,7 @@ public class ApplicationManagerProviderServiceImpl implements ApplicationManagem
for (String user : userNameList) { for (String user : userNameList) {
userName = user; userName = user;
deviceList = DeviceManagementDataHolder.getInstance().getDeviceManagementProvider().getDevicesOfUser deviceList = DeviceManagementDataHolder.getInstance().getDeviceManagementProvider().getDevicesOfUser
(user); (user, false);
for (Device device : deviceList) { for (Device device : deviceList) {
deviceIdentifier = new DeviceIdentifier(); deviceIdentifier = new DeviceIdentifier();
deviceIdentifier.setId(Integer.toString(device.getId())); deviceIdentifier.setId(Integer.toString(device.getId()));
@ -156,7 +156,7 @@ public class ApplicationManagerProviderServiceImpl implements ApplicationManagem
for (String role : userRoleList) { for (String role : userRoleList) {
userRole = role; userRole = role;
deviceList = DeviceManagementDataHolder.getInstance().getDeviceManagementProvider() deviceList = DeviceManagementDataHolder.getInstance().getDeviceManagementProvider()
.getAllDevicesOfRole(userRole); .getAllDevicesOfRole(userRole, false);
for (Device device : deviceList) { for (Device device : deviceList) {
deviceIdentifier = new DeviceIdentifier(); deviceIdentifier = new DeviceIdentifier();
deviceIdentifier.setId(Integer.toString(device.getId())); deviceIdentifier.setId(Integer.toString(device.getId()));

@ -55,7 +55,7 @@ public class DeviceInformationManagerImpl implements DeviceInformationManager {
public void addDeviceInfo(DeviceIdentifier deviceId, DeviceInfo deviceInfo) throws DeviceDetailsMgtException { public void addDeviceInfo(DeviceIdentifier deviceId, DeviceInfo deviceInfo) throws DeviceDetailsMgtException {
try { try {
Device device = DeviceManagementDataHolder.getInstance(). Device device = DeviceManagementDataHolder.getInstance().
getDeviceManagementProvider().getDevice(deviceId); getDeviceManagementProvider().getDevice(deviceId, false);
DeviceManagementDAOFactory.beginTransaction(); DeviceManagementDAOFactory.beginTransaction();
deviceDAO.updateDevice(device, CarbonContext.getThreadLocalCarbonContext().getTenantId()); deviceDAO.updateDevice(device, CarbonContext.getThreadLocalCarbonContext().getTenantId());
@ -87,7 +87,7 @@ public class DeviceInformationManagerImpl implements DeviceInformationManager {
Device device; Device device;
try { try {
device = DeviceManagementDataHolder.getInstance(). device = DeviceManagementDataHolder.getInstance().
getDeviceManagementProvider().getDevice(deviceId); getDeviceManagementProvider().getDevice(deviceId, false);
if (device == null) { if (device == null) {
if (log.isDebugEnabled()) { if (log.isDebugEnabled()) {
log.debug("No device is found upon the device identifier '" + deviceId.getId() + log.debug("No device is found upon the device identifier '" + deviceId.getId() +
@ -123,8 +123,8 @@ public class DeviceInformationManagerImpl implements DeviceInformationManager {
} }
try { try {
List<Integer> deviceIds = new ArrayList<>(); List<Integer> deviceIds = new ArrayList<>();
List<Device> devices = DeviceManagementDataHolder.getInstance(). List<Device> devices = DeviceManagementDataHolder.getInstance().getDeviceManagementProvider().
getDeviceManagementProvider().getAllDevices(); getAllDevices(false);
for (Device device : devices) { for (Device device : devices) {
if (identifierMap.containsKey(device.getDeviceIdentifier()) && if (identifierMap.containsKey(device.getDeviceIdentifier()) &&
device.getType().equals(identifierMap.get(device.getDeviceIdentifier()).getType())) { device.getType().equals(identifierMap.get(device.getDeviceIdentifier()).getType())) {
@ -154,7 +154,7 @@ public class DeviceInformationManagerImpl implements DeviceInformationManager {
try { try {
Device device = DeviceManagementDataHolder.getInstance(). Device device = DeviceManagementDataHolder.getInstance().
getDeviceManagementProvider().getDevice(deviceLocation.getDeviceIdentifier()); getDeviceManagementProvider().getDevice(deviceLocation.getDeviceIdentifier(), false);
deviceLocation.setDeviceId(device.getId()); deviceLocation.setDeviceId(device.getId());
DeviceManagementDAOFactory.beginTransaction(); DeviceManagementDAOFactory.beginTransaction();
deviceDAO.updateDevice(device, CarbonContext.getThreadLocalCarbonContext().getTenantId()); deviceDAO.updateDevice(device, CarbonContext.getThreadLocalCarbonContext().getTenantId());
@ -183,7 +183,7 @@ public class DeviceInformationManagerImpl implements DeviceInformationManager {
public DeviceLocation getDeviceLocation(DeviceIdentifier deviceId) throws DeviceDetailsMgtException { public DeviceLocation getDeviceLocation(DeviceIdentifier deviceId) throws DeviceDetailsMgtException {
Device device; Device device;
try { try {
device = DeviceManagementDataHolder.getInstance().getDeviceManagementProvider().getDevice(deviceId); device = DeviceManagementDataHolder.getInstance().getDeviceManagementProvider().getDevice(deviceId, false);
if (device == null) { if (device == null) {
if (log.isDebugEnabled()) { if (log.isDebugEnabled()) {
log.debug("No device is found upon the device identifier '" + deviceId.getId() + log.debug("No device is found upon the device identifier '" + deviceId.getId() +
@ -212,7 +212,7 @@ public class DeviceInformationManagerImpl implements DeviceInformationManager {
try { try {
List<Device> devices = DeviceManagementDataHolder.getInstance(). List<Device> devices = DeviceManagementDataHolder.getInstance().
getDeviceManagementProvider().getAllDevices(deviceIdentifiers.get(0).getType()); getDeviceManagementProvider().getAllDevices(deviceIdentifiers.get(0).getType(), false);
List<DeviceLocation> deviceLocations = new ArrayList<>(); List<DeviceLocation> deviceLocations = new ArrayList<>();
DeviceManagementDAOFactory.openConnection(); DeviceManagementDAOFactory.openConnection();
for (Device device : devices) { for (Device device : devices) {

@ -54,6 +54,18 @@ public interface DeviceManagementProviderService {
*/ */
List<Device> getAllDevices(String deviceType) throws DeviceManagementException; List<Device> getAllDevices(String deviceType) throws DeviceManagementException;
/**
* Method to retrieve all the devices of a given device type.
*
* @param deviceType Device-type of the required devices
* @param requireDeviceInfo - A boolean indicating whether the device-info (location, app-info etc) is also required
* along with the device data.
* @return List of devices of given device-type.
* @throws DeviceManagementException If some unusual behaviour is observed while fetching the
* devices.
*/
List<Device> getAllDevices(String deviceType, boolean requireDeviceInfo) throws DeviceManagementException;
/** /**
* Method to retrieve all the devices registered in the system. * Method to retrieve all the devices registered in the system.
* *
@ -63,6 +75,38 @@ public interface DeviceManagementProviderService {
*/ */
List<Device> getAllDevices() throws DeviceManagementException; List<Device> getAllDevices() throws DeviceManagementException;
/**
* Method to retrieve all the devices registered in the system.
*
* @param requireDeviceInfo - A boolean indicating whether the device-info (location, app-info etc) is also required
* along with the device data.
* @return List of registered devices.
* @throws DeviceManagementException If some unusual behaviour is observed while fetching the
* devices.
*/
List<Device> getAllDevices(boolean requireDeviceInfo) throws DeviceManagementException;
/**
* Method to retrieve all the devices registered in the system.
*
* @param since - Date value where the resource was last modified
* @return List of registered devices.
* @throws DeviceManagementException If some unusual behaviour is observed while fetching the
* devices.
*/
List<Device> getDevices(Date since) throws DeviceManagementException;
/**
* Method to retrieve all the devices registered in the system.
*
* @param requireDeviceInfo - A boolean indicating whether the device-info (location, app-info etc) is also required
* along with the device data.
* @return List of registered devices.
* @throws DeviceManagementException If some unusual behaviour is observed while fetching the
* devices.
*/
List<Device> getDevices(Date since, boolean requireDeviceInfo) throws DeviceManagementException;
/** /**
* Method to retrieve all the devices with pagination support. * Method to retrieve all the devices with pagination support.
* *
@ -73,6 +117,18 @@ public interface DeviceManagementProviderService {
*/ */
PaginationResult getDevicesByType(PaginationRequest request) throws DeviceManagementException; PaginationResult getDevicesByType(PaginationRequest request) throws DeviceManagementException;
/**
* Method to retrieve all the devices with pagination support.
*
* @param request PaginationRequest object holding the data for pagination
* @param requireDeviceInfo - A boolean indicating whether the device-info (location, app-info etc) is also required
* along with the device data.
* @return PaginationResult - Result including the required parameters necessary to do pagination.
* @throws DeviceManagementException If some unusual behaviour is observed while fetching the
* devices.
*/
PaginationResult getDevicesByType(PaginationRequest request, boolean requireDeviceInfo) throws DeviceManagementException;
/** /**
* Method to retrieve all the devices with pagination support. * Method to retrieve all the devices with pagination support.
* *
@ -83,21 +139,91 @@ public interface DeviceManagementProviderService {
*/ */
PaginationResult getAllDevices(PaginationRequest request) throws DeviceManagementException; PaginationResult getAllDevices(PaginationRequest request) throws DeviceManagementException;
void sendEnrolmentInvitation(String templateName, EmailMetaInfo metaInfo) throws DeviceManagementException; /**
* Method to retrieve all the devices with pagination support.
*
* @param request PaginationRequest object holding the data for pagination
* @param requireDeviceInfo - A boolean indicating whether the device-info (location, app-info etc) is also required
* along with the device data.
* @return PaginationResult - Result including the required parameters necessary to do pagination.
* @throws DeviceManagementException If some unusual behaviour is observed while fetching the
* devices.
*/
PaginationResult getAllDevices(PaginationRequest request, boolean requireDeviceInfo) throws DeviceManagementException;
void sendRegistrationEmail(EmailMetaInfo metaInfo) throws DeviceManagementException; /**
* Returns the device of specified id.
*
* @param deviceId device Id
* @return Device returns null when device is not available.
* @throws DeviceManagementException
*/
Device getDevice(DeviceIdentifier deviceId) throws DeviceManagementException;
FeatureManager getFeatureManager(String deviceType) throws DeviceManagementException; /**
* Returns the device of specified id.
*
* @param deviceId device Id
* @return Device returns null when device is not available.
* @throws DeviceManagementException
*/
Device getDeviceWithTypeProperties(DeviceIdentifier deviceId) throws DeviceManagementException;
/** /**
* Proxy method to get the tenant configuration of a given platform. * Returns the device of specified id.
* *
* @param deviceType Device platform * @param deviceId device Id
* @return Tenant configuration settings of the particular tenant and platform. * @param requireDeviceInfo - A boolean indicating whether the device-info (location, app-info etc) is also required
* @throws DeviceManagementException If some unusual behaviour is observed while fetching the * along with the device data.
* configuration. * @return Device returns null when device is not available.
* @throws DeviceManagementException
*/ */
PlatformConfiguration getConfiguration(String deviceType) throws DeviceManagementException; Device getDevice(DeviceIdentifier deviceId, boolean requireDeviceInfo) throws DeviceManagementException;
/**
* Returns the device of specified id.
*
* @param deviceId device Id
* @param since - Date value where the resource was last modified
* @return Device returns null when device is not available.
* @throws DeviceManagementException
*/
Device getDevice(DeviceIdentifier deviceId, Date since) throws DeviceManagementException;
/**
* Returns the device of specified id.
*
* @param deviceId device Id
* @param since - Date value where the resource was last modified
* @param requireDeviceInfo - A boolean indicating whether the device-info (location, app-info etc) is also required
* along with the device data.
* @return Device returns null when device is not available.
* @throws DeviceManagementException
*/
Device getDevice(DeviceIdentifier deviceId, Date since, boolean requireDeviceInfo) throws DeviceManagementException;
/**
* Returns the device of specified id with the given status.
*
* @param deviceId device Id
* @param status - Status of the device
*
* @return Device returns null when device is not available.
* @throws DeviceManagementException
*/
Device getDevice(DeviceIdentifier deviceId, EnrolmentInfo.Status status) throws DeviceManagementException;
/**
* Returns the device of specified id with the given status.
*
* @param deviceId device Id
* @param status - Status of the device
* @param requireDeviceInfo - A boolean indicating whether the device-info (location, app-info etc) is also required
* along with the device data.
* @return Device returns null when device is not available.
* @throws DeviceManagementException
*/
Device getDevice(DeviceIdentifier deviceId, EnrolmentInfo.Status status, boolean requireDeviceInfo) throws DeviceManagementException;
/** /**
* Method to get the list of devices owned by an user with paging information. * Method to get the list of devices owned by an user with paging information.
@ -109,6 +235,18 @@ public interface DeviceManagementProviderService {
*/ */
PaginationResult getDevicesOfUser(PaginationRequest request) throws DeviceManagementException; PaginationResult getDevicesOfUser(PaginationRequest request) throws DeviceManagementException;
/**
* Method to get the list of devices owned by an user with paging information.
*
* @param request PaginationRequest object holding the data for pagination
* @param requireDeviceInfo - A boolean indicating whether the device-info (location, app-info etc) is also required
* along with the device data.
* @return List of devices owned by a particular user along with the required parameters necessary to do pagination.
* @throws DeviceManagementException If some unusual behaviour is observed while fetching the
* device list
*/
PaginationResult getDevicesOfUser(PaginationRequest request, boolean requireDeviceInfo) throws DeviceManagementException;
/** /**
* Method to get the list of devices filtered by the ownership with paging information. * Method to get the list of devices filtered by the ownership with paging information.
* *
@ -119,6 +257,18 @@ public interface DeviceManagementProviderService {
*/ */
PaginationResult getDevicesByOwnership(PaginationRequest request) throws DeviceManagementException; PaginationResult getDevicesByOwnership(PaginationRequest request) throws DeviceManagementException;
/**
* Method to get the list of devices filtered by the ownership with paging information.
*
* @param request PaginationRequest object holding the data for pagination
* @param requireDeviceInfo - A boolean indicating whether the device-info (location, app-info etc) is also required
* along with the device data.
* @return List of devices owned by a particular user along with the required parameters necessary to do pagination.
* @throws DeviceManagementException If some unusual behaviour is observed while fetching the
* device list
*/
PaginationResult getDevicesByOwnership(PaginationRequest request, boolean requireDeviceInfo) throws DeviceManagementException;
/** /**
* Method to get the list of devices owned by an user. * Method to get the list of devices owned by an user.
* *
@ -129,16 +279,42 @@ public interface DeviceManagementProviderService {
*/ */
List<Device> getDevicesOfUser(String userName) throws DeviceManagementException; List<Device> getDevicesOfUser(String userName) throws DeviceManagementException;
/**
* Method to get the list of devices owned by an user.
*
* @param userName Username of the user
* @param requireDeviceInfo - A boolean indicating whether the device-info (location, app-info etc) is also required
* along with the device data.
* @return List of devices owned by a particular user
* @throws DeviceManagementException If some unusual behaviour is observed while fetching the
* device list
*/
List<Device> getDevicesOfUser(String userName, boolean requireDeviceInfo) throws DeviceManagementException;
/** /**
* This method returns the list of device owned by a user of given device type. * This method returns the list of device owned by a user of given device type.
* *
* @param userName user name. * @param userName user name.
* @param deviceType device type name * @param deviceType device type name
* @return * @return List of device owned by the given user and type.
* @throws DeviceManagementException * @throws DeviceManagementException If some unusual behaviour is observed while fetching the
* device list
*/ */
List<Device> getDevicesOfUser(String userName, String deviceType) throws DeviceManagementException; List<Device> getDevicesOfUser(String userName, String deviceType) throws DeviceManagementException;
/**
* This method returns the list of device owned by a user of given device type.
*
* @param userName user name.
* @param deviceType device type name
* @param requireDeviceInfo - A boolean indicating whether the device-info (location, app-info etc) is also required
* along with the device data.
* @return List of device owned by the given user and type.
* @throws DeviceManagementException If some unusual behaviour is observed while fetching the
* device list
*/
List<Device> getDevicesOfUser(String userName, String deviceType, boolean requireDeviceInfo) throws DeviceManagementException;
/** /**
* Method to get the list of devices owned by users of a particular user-role. * Method to get the list of devices owned by users of a particular user-role.
* *
@ -150,32 +326,50 @@ public interface DeviceManagementProviderService {
List<Device> getAllDevicesOfRole(String roleName) throws DeviceManagementException; List<Device> getAllDevicesOfRole(String roleName) throws DeviceManagementException;
/** /**
* Method to get the device count of user. * Method to get the list of devices owned by users of a particular user-role.
* *
* @return device count * @param roleName Role name of the users
* @throws DeviceManagementException If some unusual behaviour is observed while counting * @param requireDeviceInfo - A boolean indicating whether the device-info (location, app-info etc) is also required
* the devices * along with the device data.
* @return List of devices owned by users of a particular role
* @throws DeviceManagementException If some unusual behaviour is observed while fetching the
* device list
*/ */
int getDeviceCount(String username) throws DeviceManagementException; List<Device> getAllDevicesOfRole(String roleName, boolean requireDeviceInfo) throws DeviceManagementException;
/** /**
* Method to get the count of all types of devices. * This method is used to retrieve list of devices based on the device status with paging information.
* *
* @return device count * @param request PaginationRequest object holding the data for pagination and filter info
* @throws DeviceManagementException If some unusual behaviour is observed while counting * @return List of devices in given status along with the required parameters necessary to do pagination.
* the devices * @throws DeviceManagementException If some unusual behaviour is observed while fetching the
* device list
*/ */
int getDeviceCount() throws DeviceManagementException; PaginationResult getDevicesByStatus(PaginationRequest request) throws DeviceManagementException;
/**
* This method is used to retrieve list of devices based on the device status with paging information.
*
* @param request PaginationRequest object holding the data for pagination and filter info
* @param requireDeviceInfo - A boolean indicating whether the device-info (location, app-info etc) is also required
* along with the device data.
* @return List of devices in given status along with the required parameters necessary to do pagination.
* @throws DeviceManagementException If some unusual behaviour is observed while fetching the
* device list
*/
PaginationResult getDevicesByStatus(PaginationRequest request, boolean requireDeviceInfo) throws DeviceManagementException;
/** /**
* Method to get the list of devices that matches with the given device name. * Method to get the list of devices that matches with the given device name.
* *
* @param deviceName name of the device * @param request PaginationRequest object holding the data for pagination and filter info
* @param requireDeviceInfo - A boolean indicating whether the device-info (location, app-info etc) is also required
* along with the device data.
* @return List of devices that matches with the given device name. * @return List of devices that matches with the given device name.
* @throws DeviceManagementException If some unusual behaviour is observed while fetching the * @throws DeviceManagementException If some unusual behaviour is observed while fetching the
* device list * device list
*/ */
List<Device> getDevicesByNameAndType(String deviceName, String type, int offset, int limit) throws DeviceManagementException; List<Device> getDevicesByNameAndType(PaginationRequest request, boolean requireDeviceInfo) throws DeviceManagementException;
/** /**
* This method is used to retrieve list of devices that matches with the given device name with paging information. * This method is used to retrieve list of devices that matches with the given device name with paging information.
@ -187,7 +381,17 @@ public interface DeviceManagementProviderService {
*/ */
PaginationResult getDevicesByName(PaginationRequest request) throws DeviceManagementException; PaginationResult getDevicesByName(PaginationRequest request) throws DeviceManagementException;
void updateDeviceEnrolmentInfo(Device device, EnrolmentInfo.Status active) throws DeviceManagementException; /**
* This method is used to retrieve list of devices that matches with the given device name with paging information.
*
* @param request PaginationRequest object holding the data for pagination
* @param requireDeviceInfo - A boolean indicating whether the device-info (location, app-info etc) is also required
* along with the device data.
* @return List of devices in given status along with the required parameters necessary to do pagination.
* @throws DeviceManagementException If some unusual behaviour is observed while fetching the
* device list
*/
PaginationResult getDevicesByName(PaginationRequest request, boolean requireDeviceInfo) throws DeviceManagementException;
/** /**
* This method is used to retrieve list of devices based on the device status. * This method is used to retrieve list of devices based on the device status.
@ -199,14 +403,53 @@ public interface DeviceManagementProviderService {
List<Device> getDevicesByStatus(EnrolmentInfo.Status status) throws DeviceManagementException; List<Device> getDevicesByStatus(EnrolmentInfo.Status status) throws DeviceManagementException;
/** /**
* This method is used to retrieve list of devices based on the device status with paging information. * This method is used to retrieve list of devices based on the device status.
* *
* @param request PaginationRequest object holding the data for pagination * @param status Device status
* @return List of devices in given status along with the required parameters necessary to do pagination. * @param requireDeviceInfo - A boolean indicating whether the device-info (location, app-info etc) is also required
* along with the device data.
* @return List of devices
* @throws DeviceManagementException
*/
List<Device> getDevicesByStatus(EnrolmentInfo.Status status, boolean requireDeviceInfo) throws DeviceManagementException;
/**
* Method to get the device count of user.
*
* @return device count
* @throws DeviceManagementException If some unusual behaviour is observed while counting
* the devices
*/
int getDeviceCount(String username) throws DeviceManagementException;
/**
* Method to get the count of all types of devices.
*
* @return device count
* @throws DeviceManagementException If some unusual behaviour is observed while counting
* the devices
*/
int getDeviceCount() throws DeviceManagementException;
HashMap<Integer, Device> getTenantedDevice(DeviceIdentifier deviceIdentifier) throws DeviceManagementException;
void sendEnrolmentInvitation(String templateName, EmailMetaInfo metaInfo) throws DeviceManagementException;
void sendRegistrationEmail(EmailMetaInfo metaInfo) throws DeviceManagementException;
FeatureManager getFeatureManager(String deviceType) throws DeviceManagementException;
/**
* Proxy method to get the tenant configuration of a given platform.
*
* @param deviceType Device platform
* @return Tenant configuration settings of the particular tenant and platform.
* @throws DeviceManagementException If some unusual behaviour is observed while fetching the * @throws DeviceManagementException If some unusual behaviour is observed while fetching the
* device list * configuration.
*/ */
PaginationResult getDevicesByStatus(PaginationRequest request) throws DeviceManagementException; PlatformConfiguration getConfiguration(String deviceType) throws DeviceManagementException;
void updateDeviceEnrolmentInfo(Device device, EnrolmentInfo.Status active) throws DeviceManagementException;
/** /**
* This method is used to check whether the device is enrolled with the give user. * This method is used to check whether the device is enrolled with the give user.
@ -247,21 +490,6 @@ public interface DeviceManagementProviderService {
boolean setActive(DeviceIdentifier deviceId, boolean status) throws DeviceManagementException; boolean setActive(DeviceIdentifier deviceId, boolean status) throws DeviceManagementException;
/**
* Returns the device of specified id.
*
* @param deviceId device Id
* @return Device returns null when device is not avaialble.
* @throws DeviceManagementException
*/
Device getDevice(DeviceIdentifier deviceId) throws DeviceManagementException;
Device getDevice(DeviceIdentifier deviceId, Date since) throws DeviceManagementException;
HashMap<Integer, Device> getTenantedDevice(DeviceIdentifier deviceIdentifier) throws DeviceManagementException;
Device getDevice(DeviceIdentifier deviceId, EnrolmentInfo.Status status) throws DeviceManagementException;
List<String> getAvailableDeviceTypes() throws DeviceManagementException; List<String> getAvailableDeviceTypes() throws DeviceManagementException;
boolean updateDeviceInfo(DeviceIdentifier deviceIdentifier, Device device) throws DeviceManagementException; boolean updateDeviceInfo(DeviceIdentifier deviceIdentifier, Device device) throws DeviceManagementException;

@ -472,7 +472,8 @@ public class GroupManagementProviderServiceImpl implements GroupManagementProvid
int tenantId = CarbonContext.getThreadLocalCarbonContext().getTenantId(); int tenantId = CarbonContext.getThreadLocalCarbonContext().getTenantId();
GroupManagementDAOFactory.beginTransaction(); GroupManagementDAOFactory.beginTransaction();
for (DeviceIdentifier deviceIdentifier : deviceIdentifiers) { for (DeviceIdentifier deviceIdentifier : deviceIdentifiers) {
device = DeviceManagementDataHolder.getInstance().getDeviceManagementProvider().getDevice(deviceIdentifier); device = DeviceManagementDataHolder.getInstance().getDeviceManagementProvider().
getDevice(deviceIdentifier, false);
if (device == null) { if (device == null) {
throw new DeviceNotFoundException("Device not found for id '" + deviceIdentifier.getId() + "'"); throw new DeviceNotFoundException("Device not found for id '" + deviceIdentifier.getId() + "'");
} }
@ -504,7 +505,8 @@ public class GroupManagementProviderServiceImpl implements GroupManagementProvid
int tenantId = CarbonContext.getThreadLocalCarbonContext().getTenantId(); int tenantId = CarbonContext.getThreadLocalCarbonContext().getTenantId();
GroupManagementDAOFactory.beginTransaction(); GroupManagementDAOFactory.beginTransaction();
for (DeviceIdentifier deviceIdentifier : deviceIdentifiers) { for (DeviceIdentifier deviceIdentifier : deviceIdentifiers) {
device = DeviceManagementDataHolder.getInstance().getDeviceManagementProvider().getDevice(deviceIdentifier); device = DeviceManagementDataHolder.getInstance().getDeviceManagementProvider().
getDevice(deviceIdentifier, false);
if (device == null) { if (device == null) {
throw new DeviceNotFoundException("Device not found for id '" + deviceIdentifier.getId() + "'"); throw new DeviceNotFoundException("Device not found for id '" + deviceIdentifier.getId() + "'");
} }
@ -553,7 +555,7 @@ public class GroupManagementProviderServiceImpl implements GroupManagementProvid
public List<DeviceGroup> getGroups(DeviceIdentifier deviceIdentifier) throws GroupManagementException { public List<DeviceGroup> getGroups(DeviceIdentifier deviceIdentifier) throws GroupManagementException {
DeviceManagementProviderService managementProviderService = new DeviceManagementProviderServiceImpl(); DeviceManagementProviderService managementProviderService = new DeviceManagementProviderServiceImpl();
try { try {
Device device = managementProviderService.getDevice(deviceIdentifier); Device device = managementProviderService.getDevice(deviceIdentifier, false);
GroupManagementDAOFactory.openConnection(); GroupManagementDAOFactory.openConnection();
return groupDAO.getGroups(device.getId(), return groupDAO.getGroups(device.getId(),
PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId()); PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId());

@ -90,7 +90,7 @@ public class DeviceTaskManagerImpl implements DeviceTaskManager {
List<String> operations; List<String> operations;
operations = this.getValidOperationNames(); //list operations for each device type operations = this.getValidOperationNames(); //list operations for each device type
devices = deviceManagementProviderService.getAllDevices(deviceType);//list devices for each type devices = deviceManagementProviderService.getAllDevices(deviceType, false);//list devices for each type
if (!devices.isEmpty()) { if (!devices.isEmpty()) {
for (String str : operations) { for (String str : operations) {
CommandOperation operation = new CommandOperation(); CommandOperation operation = new CommandOperation();

@ -431,7 +431,8 @@ public final class DeviceManagerUtil {
} }
public static boolean isValidDeviceIdentifier(DeviceIdentifier deviceIdentifier) throws DeviceManagementException { public static boolean isValidDeviceIdentifier(DeviceIdentifier deviceIdentifier) throws DeviceManagementException {
Device device = DeviceManagementDataHolder.getInstance().getDeviceManagementProvider().getDevice(deviceIdentifier); Device device = DeviceManagementDataHolder.getInstance().getDeviceManagementProvider().getDevice(deviceIdentifier,
false);
if (device == null || device.getDeviceIdentifier() == null || if (device == null || device.getDeviceIdentifier() == null ||
device.getDeviceIdentifier().isEmpty() || device.getEnrolmentInfo() == null) { device.getDeviceIdentifier().isEmpty() || device.getEnrolmentInfo() == null) {
return false; return false;

@ -22,7 +22,6 @@ import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory; import org.apache.commons.logging.LogFactory;
import org.wso2.carbon.device.mgt.common.Device; import org.wso2.carbon.device.mgt.common.Device;
import org.wso2.carbon.device.mgt.common.DeviceManagementException; import org.wso2.carbon.device.mgt.common.DeviceManagementException;
import org.wso2.carbon.device.mgt.core.dto.DeviceType;
import org.wso2.carbon.device.mgt.core.service.DeviceManagementProviderService; import org.wso2.carbon.device.mgt.core.service.DeviceManagementProviderService;
import org.wso2.carbon.ntask.core.Task; import org.wso2.carbon.ntask.core.Task;
import org.wso2.carbon.policy.mgt.common.PolicyManagementException; import org.wso2.carbon.policy.mgt.common.PolicyManagementException;
@ -64,15 +63,15 @@ public class DelegationTask implements Task {
log.debug("Number of device types which policies are changed .......... : " + deviceTypes.size()); log.debug("Number of device types which policies are changed .......... : " + deviceTypes.size());
} }
if (!deviceTypes.isEmpty()) { if (!deviceTypes.isEmpty()) {
DeviceManagementProviderService service = PolicyManagementDataHolder.getInstance() DeviceManagementProviderService service = PolicyManagementDataHolder.getInstance().
.getDeviceManagementService(); getDeviceManagementService();
List<Device> devices; List<Device> devices;
List<Device> toBeNotified; List<Device> toBeNotified;
for (String deviceType : deviceTypes) { for (String deviceType : deviceTypes) {
try { try {
devices = new ArrayList<>(); devices = new ArrayList<>();
toBeNotified = new ArrayList<>(); toBeNotified = new ArrayList<>();
devices.addAll(service.getAllDevices(deviceType)); devices.addAll(service.getAllDevices(deviceType, false));
//HashMap<Integer, Integer> deviceIdPolicy = policyManager.getAppliedPolicyIdsDeviceIds(); //HashMap<Integer, Integer> deviceIdPolicy = policyManager.getAppliedPolicyIdsDeviceIds();
for (Device device : devices) { for (Device device : devices) {
// if (deviceIdPolicy.containsKey(device.getId())) { // if (deviceIdPolicy.containsKey(device.getId())) {

@ -54,7 +54,7 @@ public class ComplianceDecisionPointImpl implements ComplianceDecisionPoint {
try { try {
DeviceManagementProviderService service = this.getDeviceManagementProviderService(); DeviceManagementProviderService service = this.getDeviceManagementProviderService();
for (DeviceIdentifier deviceIdentifier : deviceIdentifiers) { for (DeviceIdentifier deviceIdentifier : deviceIdentifiers) {
Device device = service.getDevice(deviceIdentifier); Device device = service.getDevice(deviceIdentifier, false);
service.setStatus(deviceIdentifier, device.getEnrolmentInfo().getOwner(), service.setStatus(deviceIdentifier, device.getEnrolmentInfo().getOwner(),
EnrolmentInfo.Status.UNREACHABLE); EnrolmentInfo.Status.UNREACHABLE);
} }
@ -71,7 +71,7 @@ public class ComplianceDecisionPointImpl implements ComplianceDecisionPoint {
try { try {
DeviceManagementProviderService service = this.getDeviceManagementProviderService(); DeviceManagementProviderService service = this.getDeviceManagementProviderService();
for (DeviceIdentifier deviceIdentifier : deviceIdentifiers) { for (DeviceIdentifier deviceIdentifier : deviceIdentifiers) {
Device device = service.getDevice(deviceIdentifier); Device device = service.getDevice(deviceIdentifier, false);
service.setStatus(deviceIdentifier, device.getEnrolmentInfo().getOwner(), service.setStatus(deviceIdentifier, device.getEnrolmentInfo().getOwner(),
EnrolmentInfo.Status.INACTIVE); EnrolmentInfo.Status.INACTIVE);
} }
@ -106,7 +106,7 @@ public class ComplianceDecisionPointImpl implements ComplianceDecisionPoint {
try { try {
DeviceManagementProviderService service = this.getDeviceManagementProviderService(); DeviceManagementProviderService service = this.getDeviceManagementProviderService();
Device device = service.getDevice(deviceIdentifier); Device device = service.getDevice(deviceIdentifier, false);
service.setStatus(deviceIdentifier, device.getEnrolmentInfo().getOwner(), service.setStatus(deviceIdentifier, device.getEnrolmentInfo().getOwner(),
EnrolmentInfo.Status.ACTIVE); EnrolmentInfo.Status.ACTIVE);
@ -213,7 +213,7 @@ public class ComplianceDecisionPointImpl implements ComplianceDecisionPoint {
try { try {
DeviceManagementProviderService service = this.getDeviceManagementProviderService(); DeviceManagementProviderService service = this.getDeviceManagementProviderService();
Device device = service.getDevice(deviceIdentifier); Device device = service.getDevice(deviceIdentifier, false);
service.setStatus(deviceIdentifier, device.getEnrolmentInfo().getOwner(), service.setStatus(deviceIdentifier, device.getEnrolmentInfo().getOwner(),
EnrolmentInfo.Status.ACTIVE); EnrolmentInfo.Status.ACTIVE);
@ -231,7 +231,7 @@ public class ComplianceDecisionPointImpl implements ComplianceDecisionPoint {
try { try {
DeviceManagementProviderService service = this.getDeviceManagementProviderService(); DeviceManagementProviderService service = this.getDeviceManagementProviderService();
Device device = service.getDevice(deviceIdentifier); Device device = service.getDevice(deviceIdentifier, false);
service.setStatus(deviceIdentifier, device.getEnrolmentInfo().getOwner(), service.setStatus(deviceIdentifier, device.getEnrolmentInfo().getOwner(),
EnrolmentInfo.Status.INACTIVE); EnrolmentInfo.Status.INACTIVE);
@ -248,7 +248,7 @@ public class ComplianceDecisionPointImpl implements ComplianceDecisionPoint {
try { try {
DeviceManagementProviderService service = this.getDeviceManagementProviderService(); DeviceManagementProviderService service = this.getDeviceManagementProviderService();
Device device = service.getDevice(deviceIdentifier); Device device = service.getDevice(deviceIdentifier, false);
service.setStatus(deviceIdentifier, device.getEnrolmentInfo().getOwner(), service.setStatus(deviceIdentifier, device.getEnrolmentInfo().getOwner(),
EnrolmentInfo.Status.ACTIVE); EnrolmentInfo.Status.ACTIVE);

@ -79,7 +79,7 @@ public class MonitoringManagerImpl implements MonitoringManager {
DeviceManagementProviderService service = DeviceManagementProviderService service =
PolicyManagementDataHolder.getInstance().getDeviceManagementService(); PolicyManagementDataHolder.getInstance().getDeviceManagementService();
PolicyManager manager = PolicyManagementDataHolder.getInstance().getPolicyManager(); PolicyManager manager = PolicyManagementDataHolder.getInstance().getPolicyManager();
Device device = service.getDevice(deviceIdentifier); Device device = service.getDevice(deviceIdentifier, false);
Policy policy = manager.getAppliedPolicyToDevice(deviceIdentifier); Policy policy = manager.getAppliedPolicyToDevice(deviceIdentifier);
if (policy != null) { if (policy != null) {
PolicyMonitoringManager monitoringService = PolicyManagementDataHolder.getInstance(). PolicyMonitoringManager monitoringService = PolicyManagementDataHolder.getInstance().
@ -177,7 +177,7 @@ public class MonitoringManagerImpl implements MonitoringManager {
try { try {
DeviceManagementProviderService service = DeviceManagementProviderService service =
PolicyManagementDataHolder.getInstance().getDeviceManagementService(); PolicyManagementDataHolder.getInstance().getDeviceManagementService();
Device device = service.getDevice(deviceIdentifier); Device device = service.getDevice(deviceIdentifier, false);
PolicyManagementDAOFactory.openConnection(); PolicyManagementDAOFactory.openConnection();
NonComplianceData complianceData = monitoringDAO.getCompliance(device.getId(), device.getEnrolmentInfo() NonComplianceData complianceData = monitoringDAO.getCompliance(device.getId(), device.getEnrolmentInfo()
.getId()); .getId());
@ -207,7 +207,7 @@ public class MonitoringManagerImpl implements MonitoringManager {
PolicyManagementDAOFactory.openConnection(); PolicyManagementDAOFactory.openConnection();
DeviceManagementProviderService service = DeviceManagementProviderService service =
PolicyManagementDataHolder.getInstance().getDeviceManagementService(); PolicyManagementDataHolder.getInstance().getDeviceManagementService();
Device device = service.getDevice(deviceIdentifier); Device device = service.getDevice(deviceIdentifier, false);
complianceData = monitoringDAO.getCompliance(device.getId(), device.getEnrolmentInfo().getId()); complianceData = monitoringDAO.getCompliance(device.getId(), device.getEnrolmentInfo().getId());
List<ComplianceFeature> complianceFeatures = List<ComplianceFeature> complianceFeatures =
monitoringDAO.getNoneComplianceFeatures(complianceData.getId()); monitoringDAO.getNoneComplianceFeatures(complianceData.getId());

@ -392,7 +392,7 @@ public class PolicyManagerImpl implements PolicyManager {
DeviceManagementProviderService service = new DeviceManagementProviderServiceImpl(); DeviceManagementProviderService service = new DeviceManagementProviderServiceImpl();
for (DeviceIdentifier deviceIdentifier : deviceIdentifierList) { for (DeviceIdentifier deviceIdentifier : deviceIdentifierList) {
try { try {
Device device = service.getDevice(deviceIdentifier); Device device = service.getDevice(deviceIdentifier, false);
deviceList.add(device); deviceList.add(device);
} catch (DeviceManagementException e) { } catch (DeviceManagementException e) {
throw new PolicyManagementException("Error occurred while retrieving device information", e); throw new PolicyManagementException("Error occurred while retrieving device information", e);
@ -641,7 +641,7 @@ public class PolicyManagerImpl implements PolicyManager {
try { try {
DeviceManagementProviderService service = new DeviceManagementProviderServiceImpl(); DeviceManagementProviderService service = new DeviceManagementProviderServiceImpl();
Device device = service.getDevice(deviceIdentifier); Device device = service.getDevice(deviceIdentifier, false);
PolicyManagementDAOFactory.openConnection(); PolicyManagementDAOFactory.openConnection();
policyIdList = policyDAO.getPolicyIdsOfDevice(device); policyIdList = policyDAO.getPolicyIdsOfDevice(device);
@ -807,7 +807,7 @@ public class PolicyManagerImpl implements PolicyManager {
int deviceId = -1; int deviceId = -1;
try { try {
DeviceManagementProviderService service = new DeviceManagementProviderServiceImpl(); DeviceManagementProviderService service = new DeviceManagementProviderServiceImpl();
Device device = service.getDevice(deviceIdentifier); Device device = service.getDevice(deviceIdentifier, false);
deviceId = device.getId(); deviceId = device.getId();
PolicyManagementDAOFactory.beginTransaction(); PolicyManagementDAOFactory.beginTransaction();
@ -879,7 +879,7 @@ public class PolicyManagerImpl implements PolicyManager {
int deviceId = -1; int deviceId = -1;
try { try {
DeviceManagementProviderService service = new DeviceManagementProviderServiceImpl(); DeviceManagementProviderService service = new DeviceManagementProviderServiceImpl();
Device device = service.getDevice(deviceIdentifier); Device device = service.getDevice(deviceIdentifier, false);
deviceId = device.getId(); deviceId = device.getId();
PolicyManagementDAOFactory.beginTransaction(); PolicyManagementDAOFactory.beginTransaction();
@ -909,7 +909,7 @@ public class PolicyManagerImpl implements PolicyManager {
int deviceId = -1; int deviceId = -1;
try { try {
DeviceManagementProviderService service = new DeviceManagementProviderServiceImpl(); DeviceManagementProviderService service = new DeviceManagementProviderServiceImpl();
Device device = service.getDevice(deviceIdentifier); Device device = service.getDevice(deviceIdentifier, false);
deviceId = device.getId(); deviceId = device.getId();
PolicyManagementDAOFactory.beginTransaction(); PolicyManagementDAOFactory.beginTransaction();
@ -937,7 +937,7 @@ public class PolicyManagerImpl implements PolicyManager {
boolean exist; boolean exist;
try { try {
DeviceManagementProviderService service = new DeviceManagementProviderServiceImpl(); DeviceManagementProviderService service = new DeviceManagementProviderServiceImpl();
Device device = service.getDevice(deviceIdentifier); Device device = service.getDevice(deviceIdentifier, false);
PolicyManagementDAOFactory.openConnection(); PolicyManagementDAOFactory.openConnection();
exist = policyDAO.checkPolicyAvailable(device.getId(), device.getEnrolmentInfo().getId()); exist = policyDAO.checkPolicyAvailable(device.getId(), device.getEnrolmentInfo().getId());
} catch (PolicyManagerDAOException e) { } catch (PolicyManagerDAOException e) {
@ -958,7 +958,7 @@ public class PolicyManagerImpl implements PolicyManager {
public boolean setPolicyApplied(DeviceIdentifier deviceIdentifier) throws PolicyManagementException { public boolean setPolicyApplied(DeviceIdentifier deviceIdentifier) throws PolicyManagementException {
try { try {
DeviceManagementProviderService service = new DeviceManagementProviderServiceImpl(); DeviceManagementProviderService service = new DeviceManagementProviderServiceImpl();
Device device = service.getDevice(deviceIdentifier); Device device = service.getDevice(deviceIdentifier, false);
PolicyManagementDAOFactory.openConnection(); PolicyManagementDAOFactory.openConnection();
policyDAO.setPolicyApplied(device.getId(), device.getEnrolmentInfo().getId()); policyDAO.setPolicyApplied(device.getId(), device.getEnrolmentInfo().getId());
@ -996,7 +996,7 @@ public class PolicyManagerImpl implements PolicyManager {
DeviceManagementProviderService service = new DeviceManagementProviderServiceImpl(); DeviceManagementProviderService service = new DeviceManagementProviderServiceImpl();
Device device; Device device;
try { try {
device = service.getDevice(deviceId); device = service.getDevice(deviceId, false);
if (device == null) { if (device == null) {
if (log.isDebugEnabled()) { if (log.isDebugEnabled()) {
log.debug("No device is found upon the device identifier '" + deviceId.getId() + log.debug("No device is found upon the device identifier '" + deviceId.getId() +

@ -24,11 +24,9 @@ import org.apache.commons.logging.LogFactory;
import org.wso2.carbon.device.mgt.common.Device; import org.wso2.carbon.device.mgt.common.Device;
import org.wso2.carbon.device.mgt.common.EnrolmentInfo; import org.wso2.carbon.device.mgt.common.EnrolmentInfo;
import org.wso2.carbon.device.mgt.common.policy.mgt.PolicyMonitoringManager; import org.wso2.carbon.device.mgt.common.policy.mgt.PolicyMonitoringManager;
import org.wso2.carbon.device.mgt.core.config.DeviceConfigurationManager; import org.wso2.carbon.device.mgt.common.policy.mgt.monitor.PolicyComplianceException;
import org.wso2.carbon.device.mgt.core.config.policy.PolicyConfiguration;
import org.wso2.carbon.device.mgt.core.service.DeviceManagementProviderService; import org.wso2.carbon.device.mgt.core.service.DeviceManagementProviderService;
import org.wso2.carbon.ntask.core.Task; import org.wso2.carbon.ntask.core.Task;
import org.wso2.carbon.device.mgt.common.policy.mgt.monitor.PolicyComplianceException;
import org.wso2.carbon.policy.mgt.core.internal.PolicyManagementDataHolder; import org.wso2.carbon.policy.mgt.core.internal.PolicyManagementDataHolder;
import org.wso2.carbon.policy.mgt.core.mgt.MonitoringManager; import org.wso2.carbon.policy.mgt.core.mgt.MonitoringManager;
@ -83,7 +81,7 @@ public class MonitoringTask implements Task {
PolicyMonitoringManager monitoringService = PolicyMonitoringManager monitoringService =
PolicyManagementDataHolder.getInstance().getDeviceManagementService() PolicyManagementDataHolder.getInstance().getDeviceManagementService()
.getPolicyMonitoringManager(deviceType); .getPolicyMonitoringManager(deviceType);
List<Device> devices = deviceManagementProviderService.getAllDevices(deviceType); List<Device> devices = deviceManagementProviderService.getAllDevices(deviceType, false);
if (monitoringService != null && !devices.isEmpty()) { if (monitoringService != null && !devices.isEmpty()) {
List<Device> notifiableDevices = new ArrayList<>(); List<Device> notifiableDevices = new ArrayList<>();
if (log.isDebugEnabled()) { if (log.isDebugEnabled()) {

@ -140,7 +140,7 @@ public class MonitoringTestCase extends BasePolicyManagementDAOTest {
MonitoringManager monitoringManager = new MonitoringManagerImpl(); MonitoringManager monitoringManager = new MonitoringManagerImpl();
DeviceManagementProviderService service = new DeviceManagementProviderServiceImpl(); DeviceManagementProviderService service = new DeviceManagementProviderServiceImpl();
List<Device> devices = service.getAllDevices(ANDROID); List<Device> devices = service.getAllDevices(ANDROID, false);
// monitoringManager.addMonitoringOperation(devices); // monitoringManager.addMonitoringOperation(devices);

@ -118,7 +118,7 @@ public class PolicyDAOTestCase extends BasePolicyManagementDAOTest {
if (log.isDebugEnabled()) { if (log.isDebugEnabled()) {
log.debug("Printing device taken by calling the service layer with device type."); log.debug("Printing device taken by calling the service layer with device type.");
} }
List<Device> devices3 = service.getAllDevices("android"); List<Device> devices3 = service.getAllDevices("android", false);
log.debug("Device list size ...! " + devices3.size()); log.debug("Device list size ...! " + devices3.size());
for (Device device : devices3) { for (Device device : devices3) {
@ -437,7 +437,7 @@ public class PolicyDAOTestCase extends BasePolicyManagementDAOTest {
PolicyManagerService policyManagerService = new PolicyManagerServiceImpl(); PolicyManagerService policyManagerService = new PolicyManagerServiceImpl();
List<Policy> policies = policyManagerService.getPolicies("android"); List<Policy> policies = policyManagerService.getPolicies("android");
List<Device> devices = service.getAllDevices("android"); List<Device> devices = service.getAllDevices("android", false);
for (Policy policy : policies) { for (Policy policy : policies) {
log.debug("Policy Name : " + policy.getPolicyName()); log.debug("Policy Name : " + policy.getPolicyName());

@ -95,7 +95,7 @@ public class PolicyEvaluationTestCase extends BasePolicyManagementDAOTest {
log.debug("Getting effective policy for device started .........."); log.debug("Getting effective policy for device started ..........");
DeviceManagementProviderService service = new DeviceManagementProviderServiceImpl(); DeviceManagementProviderService service = new DeviceManagementProviderServiceImpl();
List<Device> devices = service.getAllDevices(ANDROID); List<Device> devices = service.getAllDevices(ANDROID, false);
PolicyEvaluationPoint evaluationPoint = PolicyManagementDataHolder.getInstance().getPolicyEvaluationPoint(); PolicyEvaluationPoint evaluationPoint = PolicyManagementDataHolder.getInstance().getPolicyEvaluationPoint();

Loading…
Cancel
Save