Merge pull request #1088 from charithag/add-emm-analytics

Add emm analytics
revert-70aa11f8
Geeth 7 years ago committed by GitHub
commit ef15bc77d2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -31,15 +31,15 @@ import org.wso2.carbon.analytics.datasource.commons.exception.AnalyticsException
import org.wso2.carbon.context.CarbonContext;
import org.wso2.carbon.device.mgt.common.DeviceIdentifier;
import org.wso2.carbon.device.mgt.common.DeviceManagementConstants.GeoServices;
import org.wso2.carbon.device.mgt.common.DeviceManagementException;
import org.wso2.carbon.device.mgt.common.authorization.DeviceAccessAuthorizationException;
import org.wso2.carbon.device.mgt.common.geo.service.Alert;
import org.wso2.carbon.device.mgt.common.geo.service.Event;
import org.wso2.carbon.device.mgt.common.geo.service.GeoFence;
import org.wso2.carbon.device.mgt.common.geo.service.GeoLocationProviderService;
import org.wso2.carbon.device.mgt.common.geo.service.GeoLocationBasedServiceException;
import org.wso2.carbon.device.mgt.common.geo.service.GeoLocationProviderService;
import org.wso2.carbon.device.mgt.common.group.mgt.DeviceGroupConstants;
import org.wso2.carbon.device.mgt.core.config.DeviceConfigurationManager;
import org.wso2.carbon.device.mgt.core.config.DeviceManagementConfig;
import org.wso2.carbon.device.mgt.core.util.DeviceManagerUtil;
import org.wso2.carbon.device.mgt.jaxrs.service.api.GeoLocationBasedService;
import org.wso2.carbon.device.mgt.jaxrs.util.Constants;
import org.wso2.carbon.device.mgt.jaxrs.util.DeviceMgtAPIUtils;
@ -76,13 +76,13 @@ public class GeoLocationBasedServiceImpl implements GeoLocationBasedService {
public Response getGeoDeviceStats(@PathParam("deviceId") String deviceId,
@PathParam("deviceType") String deviceType,
@QueryParam("from") long from, @QueryParam("to") long to) {
//First, check whether the Geo Location service has been enabled in the cdmf-config.xml file
DeviceManagementConfig deviceManagementConfig = DeviceConfigurationManager.getInstance()
.getDeviceManagementConfig();
if (deviceManagementConfig != null) {
if(!deviceManagementConfig.getGeoLocationConfiguration().getPublishLocationOperationResponse()){
return Response.status(Response.Status.BAD_REQUEST.getStatusCode()).build();
try {
if (!DeviceManagerUtil.isPublishOperationResponseEnabled()) {
return Response.status(Response.Status.BAD_REQUEST.getStatusCode())
.entity("Unable to retrive Geo Device stats. Geo Data publishing does not enabled.").build();
}
} catch (DeviceManagementException e) {
return Response.status(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode()).entity(e.getMessage()).build();
}
String tableName = "IOT_PER_DEVICE_STREAM_GEO_FUSEDSPATIALEVENT";
String fromDate = String.valueOf(from);

@ -19,7 +19,6 @@ package org.wso2.carbon.device.mgt.jaxrs.service.impl.util;
import org.wso2.carbon.device.mgt.common.Device;
import org.wso2.carbon.device.mgt.common.EnrolmentInfo;
import org.wso2.carbon.device.mgt.common.Feature;
import org.wso2.carbon.device.mgt.common.device.details.DeviceInfo;
import org.wso2.carbon.device.mgt.common.push.notification.PushNotificationConfig;
import org.wso2.carbon.device.mgt.common.type.mgt.DeviceTypeMetaDefinition;
@ -37,7 +36,6 @@ public class DeviceMgtAPITestHelper {
private static final String DEVICE_TYPE_DESCRIPTION = "Dummy Description";
public static final String DEVICE_TYPE = "TEST_DEVICE_TYPE";
public static final String DEVICE_NAME = "TEST_DEVICE";
public static final String DEVICE_IDENTIFIER = "12345";
public final static String OWNER = "admin";
/**
@ -110,8 +108,6 @@ public class DeviceMgtAPITestHelper {
public static DeviceInfo generateDeviceInfo() {
DeviceInfo deviceInfo = new DeviceInfo();
deviceInfo.setIMEI("IMEI-12345");
deviceInfo.setIMSI("IMSI-12344");
deviceInfo.setDeviceModel("DUMMY_MODEL");
deviceInfo.setVendor("WSO2");
deviceInfo.setOsVersion("OREO");

@ -144,30 +144,6 @@ public class DeviceInfo implements Serializable {
this.location = location;
}
public String getIMEI() {
if (IMEI != null) {
return IMEI;
} else {
return "";
}
}
public void setIMEI(String IMEI) {
this.IMEI = IMEI;
}
public String getIMSI() {
if (IMSI != null) {
return IMSI;
} else {
return "";
}
}
public void setIMSI(String IMSI) {
this.IMSI = IMSI;
}
public String getDeviceModel() {
if (deviceModel != null) {
return deviceModel;

@ -18,7 +18,7 @@
package org.wso2.carbon.device.mgt.core.config;
import org.wso2.carbon.device.mgt.core.config.cache.CertificateCacheConfiguration;
import org.wso2.carbon.device.mgt.core.config.geo.location.GeoLocationConfiguration;
import org.wso2.carbon.device.mgt.core.config.geo.location.OperationAnalyticsConfiguration;
import org.wso2.carbon.device.mgt.core.config.cache.DeviceCacheConfiguration;
import org.wso2.carbon.device.mgt.core.config.identity.IdentityConfigurations;
import org.wso2.carbon.device.mgt.core.config.pagination.PaginationConfiguration;
@ -48,7 +48,7 @@ public final class DeviceManagementConfig {
private DeviceStatusTaskConfig deviceStatusTaskConfig;
private DeviceCacheConfiguration deviceCacheConfiguration;
private CertificateCacheConfiguration certificateCacheConfiguration;
private GeoLocationConfiguration geoLocationConfiguration;
private OperationAnalyticsConfiguration operationAnalyticsConfiguration;
private String defaultGroupsConfiguration;
@XmlElement(name = "ManagementRepository", required = true)
@ -142,13 +142,13 @@ public final class DeviceManagementConfig {
this.certificateCacheConfiguration = certificateCacheConfiguration;
}
@XmlElement(name = "GeoLocationConfiguration", required = true)
public GeoLocationConfiguration getGeoLocationConfiguration() {
return geoLocationConfiguration;
@XmlElement(name = "OperationAnalyticsConfiguration", required = true)
public OperationAnalyticsConfiguration getOperationAnalyticsConfiguration() {
return operationAnalyticsConfiguration;
}
public void setGeoLocationConfiguration(GeoLocationConfiguration geoLocationConfiguration) {
this.geoLocationConfiguration = geoLocationConfiguration;
public void setOperationAnalyticsConfiguration(OperationAnalyticsConfiguration operationAnalyticsConfiguration) {
this.operationAnalyticsConfiguration = operationAnalyticsConfiguration;
}
@XmlElement(name = "DefaultGroupsConfiguration", required = true)

@ -22,21 +22,21 @@ import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;
/**
* This class represents the information related to Geo Location configuration.
* This class represents the information related to Device Operation Analytics configuration.
*/
@XmlRootElement(name = "GeoLocationConfiguration")
public class GeoLocationConfiguration {
@XmlRootElement(name = "OperationAnalyticsConfiguration")
public class OperationAnalyticsConfiguration {
private boolean publishLocationOperationResponse;
private boolean publishOperationResponse;
private boolean isEnabled;
public boolean getPublishLocationOperationResponse() {
return publishLocationOperationResponse;
public boolean getPublishOperationResponse() {
return publishOperationResponse;
}
@XmlElement(name = "PublishLocationOperationResponse", required = true)
public void setPublishLocationOperationResponse(boolean publishLocationOperationResponse) {
this.publishLocationOperationResponse = publishLocationOperationResponse;
@XmlElement(name = "PublishOperationResponse", required = true)
public void setPublishOperationResponse(boolean publishOperationResponse) {
this.publishOperationResponse = publishOperationResponse;
}
public boolean getIsEnabled() {

@ -41,6 +41,7 @@ import org.wso2.carbon.device.mgt.core.util.DeviceManagerUtil;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@ -50,7 +51,9 @@ public class DeviceInformationManagerImpl implements DeviceInformationManager {
private DeviceDetailsDAO deviceDetailsDAO;
private DeviceDAO deviceDAO;
private static final Log log = LogFactory.getLog(DeviceInformationManagerImpl.class);
private static final String EVENT_STREAM_DEFINITION = "org.wso2.iot.LocationStream";
private static final String LOCATION_EVENT_STREAM_DEFINITION = "org.wso2.iot.LocationStream";
private static final String DEVICE_INFO_EVENT_STREAM_DEFINITION = "org.wso2.iot.DeviceInfoStream";
public DeviceInformationManagerImpl() {
this.deviceDAO = DeviceManagementDAOFactory.getDeviceDAO();
@ -70,6 +73,35 @@ public class DeviceInformationManagerImpl implements DeviceInformationManager {
deviceDetailsDAO.addDeviceInformation(device.getId(), deviceInfo);
deviceDetailsDAO.addDeviceProperties(deviceInfo.getDeviceDetailsMap(), device.getId());
DeviceManagementDAOFactory.commitTransaction();
if (DeviceManagerUtil.isPublishOperationResponseEnabled()) {
Object[] metaData = {device.getDeviceIdentifier(), device.getType()};
Object[] payload = new Object[]{
Calendar.getInstance().getTimeInMillis(),
deviceInfo.getDeviceDetailsMap().get("IMEI"),
deviceInfo.getDeviceDetailsMap().get("IMSI"),
deviceInfo.getDeviceModel(),
deviceInfo.getVendor(),
deviceInfo.getOsVersion(),
deviceInfo.getOsBuildDate(),
deviceInfo.getBatteryLevel(),
deviceInfo.getInternalTotalMemory(),
deviceInfo.getInternalAvailableMemory(),
deviceInfo.getExternalTotalMemory(),
deviceInfo.getExternalAvailableMemory(),
deviceInfo.getOperator(),
deviceInfo.getConnectionType(),
deviceInfo.getMobileSignalStrength(),
deviceInfo.getSsid(),
deviceInfo.getCpuUsage(),
deviceInfo.getTotalRAMMemory(),
deviceInfo.getAvailableRAMMemory(),
deviceInfo.isPluggedIn()
};
DeviceManagerUtil.getEventPublisherService().publishEvent(
DEVICE_INFO_EVENT_STREAM_DEFINITION, "1.0.0", metaData, new Object[0], payload
);
}
} catch (TransactionManagementException e) {
DeviceManagementDAOFactory.rollbackTransaction();
throw new DeviceDetailsMgtException("Transactional error occurred while adding the device information.", e);
@ -82,7 +114,10 @@ public class DeviceInformationManagerImpl implements DeviceInformationManager {
} catch (DeviceManagementDAOException e) {
DeviceManagementDAOFactory.rollbackTransaction();
throw new DeviceDetailsMgtException("Error occurred while updating the last update timestamp of the " +
"device", e);
"device", e);
} catch (DataPublisherConfigurationException e) {
DeviceManagementDAOFactory.rollbackTransaction();
throw new DeviceDetailsMgtException("Error occurred while publishing the device location information.", e);
} finally {
DeviceManagementDAOFactory.closeConnection();
}
@ -90,19 +125,9 @@ public class DeviceInformationManagerImpl implements DeviceInformationManager {
@Override
public DeviceInfo getDeviceInfo(DeviceIdentifier deviceId) throws DeviceDetailsMgtException {
Device device;
try {
device = DeviceManagementDataHolder.getInstance().
getDeviceManagementProvider().getDevice(deviceId, false);
if (device == null) {
if (log.isDebugEnabled()) {
log.debug("No device is found upon the device identifier '" + deviceId.getId() +
"' and type '" + deviceId.getType() + "'. Therefore returning null");
}
return null;
}
} catch (DeviceManagementException e) {
throw new DeviceDetailsMgtException("Exception occurred while retrieving the device.", e);
Device device = getDevice(deviceId);
if (device == null) {
return null;
}
try {
DeviceManagementDAOFactory.openConnection();
@ -111,7 +136,8 @@ public class DeviceInformationManagerImpl implements DeviceInformationManager {
return deviceInfo;
} catch (SQLException e) {
throw new DeviceDetailsMgtException("SQL error occurred while retrieving device from database.", e);
throw new DeviceDetailsMgtException("SQL error occurred while retrieving device " + deviceId.toString()
+ "'s info from database.", e);
} catch (DeviceDetailsMgtDAOException e) {
throw new DeviceDetailsMgtException("Exception occurred while retrieving device details.", e);
} finally {
@ -166,15 +192,15 @@ public class DeviceInformationManagerImpl implements DeviceInformationManager {
deviceDAO.updateDevice(device, CarbonContext.getThreadLocalCarbonContext().getTenantId());
deviceDetailsDAO.deleteDeviceLocation(deviceLocation.getDeviceId());
deviceDetailsDAO.addDeviceLocation(deviceLocation);
if (DeviceManagerUtil.isPublishLocationOperationResEnabled()) {
Object metaData[] = {device.getDeviceIdentifier(), device.getType()};
Object payload[] = new Object[]{
if (DeviceManagerUtil.isPublishOperationResponseEnabled()) {
Object[] metaData = {device.getDeviceIdentifier(), device.getType()};
Object[] payload = new Object[]{
deviceLocation.getUpdatedTime().getTime(),
deviceLocation.getLatitude(),
deviceLocation.getLongitude()
};
DeviceManagerUtil.getEventPublisherService().publishEvent(
EVENT_STREAM_DEFINITION, "1.0.0", metaData, new Object[0], payload
LOCATION_EVENT_STREAM_DEFINITION, "1.0.0", metaData, new Object[0], payload
);
}
DeviceManagementDAOFactory.commitTransaction();
@ -201,29 +227,37 @@ public class DeviceInformationManagerImpl implements DeviceInformationManager {
@Override
public DeviceLocation getDeviceLocation(DeviceIdentifier deviceId) throws DeviceDetailsMgtException {
Device device = getDevice(deviceId);
if (device == null) {
return null;
}
try {
DeviceManagementDAOFactory.openConnection();
return deviceDetailsDAO.getDeviceLocation(device.getId());
} catch (SQLException e) {
throw new DeviceDetailsMgtException("SQL error occurred while retrieving device from database.", e);
} catch (DeviceDetailsMgtDAOException e) {
throw new DeviceDetailsMgtException("Exception occurred while retrieving device location.", e);
} finally {
DeviceManagementDAOFactory.closeConnection();
}
}
private Device getDevice(DeviceIdentifier deviceId) throws DeviceDetailsMgtException {
Device device;
try {
device = DeviceManagementDataHolder.getInstance().getDeviceManagementProvider().getDevice(deviceId, false);
if (device == null) {
if (log.isDebugEnabled()) {
log.debug("No device is found upon the device identifier '" + deviceId.getId() +
"' and type '" + deviceId.getType() + "'. Therefore returning null");
"' and type '" + deviceId.getType() + "'. Therefore returning null");
}
return null;
}
} catch (DeviceManagementException e) {
throw new DeviceDetailsMgtException("Exception occurred while retrieving the device.", e);
}
try {
DeviceManagementDAOFactory.openConnection();
return deviceDetailsDAO.getDeviceLocation(device.getId());
} catch (SQLException e) {
throw new DeviceDetailsMgtException("SQL error occurred while retrieving device from database.", e);
} catch (DeviceDetailsMgtDAOException e) {
throw new DeviceDetailsMgtException("Exception occurred while retrieving device location.", e);
} finally {
DeviceManagementDAOFactory.closeConnection();
}
return device;
}
@Override

@ -26,8 +26,8 @@ import org.wso2.carbon.device.mgt.common.PaginationResult;
import org.wso2.carbon.device.mgt.common.group.mgt.DeviceGroup;
import org.wso2.carbon.device.mgt.common.group.mgt.GroupAlreadyExistException;
import org.wso2.carbon.device.mgt.common.group.mgt.GroupManagementException;
import org.wso2.carbon.device.mgt.common.group.mgt.RoleDoesNotExistException;
import org.wso2.carbon.device.mgt.common.group.mgt.GroupNotExistException;
import org.wso2.carbon.device.mgt.common.group.mgt.RoleDoesNotExistException;
import java.util.List;
@ -215,10 +215,19 @@ public interface GroupManagementProviderService {
/**
* Checks for the default group existence and create group based on device ownership.
* @param groupName
* @return
* @param groupName of the group
* @return DeviceGroup object
* @throws GroupManagementException
*/
DeviceGroup createDefaultGroup(String groupName) throws GroupManagementException;
/**
* Check device is belonging to a Device Group.
*
* @param groupId of Device Group.
* @param deviceIdentifier of the device.
* @throws GroupManagementException on errors.
*/
boolean isDeviceMappedToGroup(int groupId, DeviceIdentifier deviceIdentifier) throws GroupManagementException;
}

@ -30,7 +30,12 @@ import org.wso2.carbon.device.mgt.common.DeviceNotFoundException;
import org.wso2.carbon.device.mgt.common.GroupPaginationRequest;
import org.wso2.carbon.device.mgt.common.PaginationResult;
import org.wso2.carbon.device.mgt.common.TransactionManagementException;
import org.wso2.carbon.device.mgt.common.group.mgt.*;
import org.wso2.carbon.device.mgt.common.group.mgt.DeviceGroup;
import org.wso2.carbon.device.mgt.common.group.mgt.DeviceGroupConstants;
import org.wso2.carbon.device.mgt.common.group.mgt.GroupAlreadyExistException;
import org.wso2.carbon.device.mgt.common.group.mgt.GroupManagementException;
import org.wso2.carbon.device.mgt.common.group.mgt.GroupNotExistException;
import org.wso2.carbon.device.mgt.common.group.mgt.RoleDoesNotExistException;
import org.wso2.carbon.device.mgt.core.dao.GroupDAO;
import org.wso2.carbon.device.mgt.core.dao.GroupManagementDAOException;
import org.wso2.carbon.device.mgt.core.dao.GroupManagementDAOFactory;
@ -823,4 +828,39 @@ public class GroupManagementProviderServiceImpl implements GroupManagementProvid
return defaultGroup;
}
}
/**
* {@inheritDoc}
*/
@Override
public boolean isDeviceMappedToGroup(int groupId, DeviceIdentifier deviceIdentifier)
throws GroupManagementException {
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId();
Device device;
try {
device = DeviceManagementDataHolder.getInstance().getDeviceManagementProvider().
getDevice(deviceIdentifier, false);
if (device == null) {
throw new GroupManagementException("Device not found for id '" + deviceIdentifier.getId() +
"' type '" + deviceIdentifier.getType() + "'");
}
} catch (DeviceManagementException e) {
throw new GroupManagementException("Device management exception occurred when retrieving device. " +
e.getMessage(), e);
}
try{
GroupManagementDAOFactory.openConnection();
return this.groupDAO.isDeviceMappedToGroup(groupId, device.getId(), tenantId);
} catch (GroupManagementDAOException e) {
throw new GroupManagementException("Error occurred when checking device, group mapping between device id '" +
deviceIdentifier.getId() + "' and group id '" + groupId + "'", e);
} catch (SQLException e) {
throw new GroupManagementException("Error occurred when opening db connection to check device, group " +
"mapping between device id '" + deviceIdentifier.getId() +
"' and group id '" + groupId + "'", e);
} finally {
GroupManagementDAOFactory.closeConnection();
}
}
}

@ -31,6 +31,7 @@ import org.wso2.carbon.device.mgt.common.EnrolmentInfo;
import org.wso2.carbon.device.mgt.common.GroupPaginationRequest;
import org.wso2.carbon.device.mgt.common.PaginationRequest;
import org.wso2.carbon.device.mgt.common.TransactionManagementException;
import org.wso2.carbon.device.mgt.common.device.details.DeviceInfo;
import org.wso2.carbon.device.mgt.common.group.mgt.GroupManagementException;
import org.wso2.carbon.device.mgt.common.notification.mgt.NotificationManagementException;
import org.wso2.carbon.device.mgt.common.operation.mgt.OperationManagementException;
@ -415,11 +416,23 @@ public final class DeviceManagerUtil {
return limit;
}
public static boolean isPublishLocationOperationResEnabled() throws DeviceManagementException {
public static boolean isOperationAnalyticsEnabled() throws DeviceManagementException {
DeviceManagementConfig deviceManagementConfig = DeviceConfigurationManager.getInstance().
getDeviceManagementConfig();
if (deviceManagementConfig != null) {
return deviceManagementConfig.getGeoLocationConfiguration().getPublishLocationOperationResponse();
return deviceManagementConfig.getOperationAnalyticsConfiguration().getIsEnabled();
} else {
throw new DeviceManagementException("Device-Mgt configuration has not initialized. Please check the " +
"cdm-config.xml file.");
}
}
public static boolean isPublishOperationResponseEnabled() throws DeviceManagementException {
DeviceManagementConfig deviceManagementConfig = DeviceConfigurationManager.getInstance().
getDeviceManagementConfig();
if (deviceManagementConfig != null) {
return isOperationAnalyticsEnabled()
&& deviceManagementConfig.getOperationAnalyticsConfiguration().getPublishOperationResponse();
} else {
throw new DeviceManagementException("Device-Mgt configuration has not initialized. Please check the " +
"cdm-config.xml file.");

@ -66,8 +66,6 @@ public class TestDataHolder {
public static DeviceInfo generateDummyDeviceInfo() {
DeviceInfo deviceInfo = new DeviceInfo();
deviceInfo.setIMEI("IMEI-12345");
deviceInfo.setIMSI("IMSI-12344");
deviceInfo.setDeviceModel("DUMMY_MODEL");
deviceInfo.setVendor("WSO2");
deviceInfo.setOsVersion("OREO");

@ -1,5 +1,5 @@
/*
* Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
* 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
@ -20,26 +20,17 @@ package org.wso2.carbon.device.mgt.core.search.util;
import org.wso2.carbon.device.mgt.common.DeviceIdentifier;
import org.wso2.carbon.device.mgt.common.device.details.DeviceInfo;
import org.wso2.carbon.device.mgt.common.device.details.DeviceLocation;
import org.wso2.carbon.device.mgt.common.search.Condition;
import org.wso2.carbon.device.mgt.common.search.SearchContext;
import org.wso2.carbon.device.mgt.core.common.TestDataHolder;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import static org.wso2.carbon.device.mgt.common.search.Condition.State.AND;
import static org.wso2.carbon.device.mgt.common.search.Condition.State.OR;
public class Utils {
public static DeviceInfo getDeviceInfo() {
DeviceInfo deviceInfo = new DeviceInfo();
deviceInfo.setIMSI("e6f236ac82537a8e");
deviceInfo.setSsid("FAFDA");
deviceInfo.setAvailableRAMMemory(1.24);
deviceInfo.setBatteryLevel(40.0);
deviceInfo.setConnectionType("GSM");
@ -47,8 +38,6 @@ public class Utils {
deviceInfo.setDeviceModel("SM-T520");
deviceInfo.setExternalAvailableMemory(2.45);
deviceInfo.setExternalTotalMemory(16.23);
deviceInfo.setIMEI("e6f236ac82537a8e");
deviceInfo.setIMSI("GT-0WDA");
deviceInfo.setInternalAvailableMemory(3.56);
deviceInfo.setInternalTotalMemory(7.89);
deviceInfo.setMobileSignalStrength(0.67);
@ -70,6 +59,8 @@ public class Utils {
propertyMap.put("MEMORY_THRESHOLD", "100663296");
propertyMap.put("CPU_IOW", "12");
propertyMap.put("CPU_IRQ", "1");
propertyMap.put("IMEI", "e6f236ac82537a8e");
propertyMap.put("IMSI", "432659632123654845");
deviceInfo.setDeviceDetailsMap(propertyMap);
@ -77,7 +68,7 @@ public class Utils {
}
public static DeviceLocation getSampleDeviceLocation(){
private static DeviceLocation getSampleDeviceLocation(){
DeviceLocation deviceLocation = new DeviceLocation();
deviceLocation.setDeviceIdentifier(Utils.getDeviceIdentifier());
deviceLocation.setLatitude(76.2422);

@ -16,21 +16,27 @@
* under the License.
*/
package org.wso2.carbon.device.mgt.core.service;
import org.testng.Assert;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;
import org.wso2.carbon.device.mgt.common.*;
import org.wso2.carbon.device.mgt.common.group.mgt.*;
import org.wso2.carbon.device.mgt.common.Device;
import org.wso2.carbon.device.mgt.common.DeviceIdentifier;
import org.wso2.carbon.device.mgt.common.DeviceNotFoundException;
import org.wso2.carbon.device.mgt.common.GroupPaginationRequest;
import org.wso2.carbon.device.mgt.common.PaginationResult;
import org.wso2.carbon.device.mgt.common.TransactionManagementException;
import org.wso2.carbon.device.mgt.common.group.mgt.DeviceGroup;
import org.wso2.carbon.device.mgt.common.group.mgt.GroupAlreadyExistException;
import org.wso2.carbon.device.mgt.common.group.mgt.GroupManagementException;
import org.wso2.carbon.device.mgt.common.group.mgt.GroupNotExistException;
import org.wso2.carbon.device.mgt.common.group.mgt.RoleDoesNotExistException;
import org.wso2.carbon.device.mgt.core.TestUtils;
import org.wso2.carbon.device.mgt.core.common.BaseDeviceManagementTest;
import org.wso2.carbon.device.mgt.core.common.TestDataHolder;
import org.wso2.carbon.device.mgt.core.config.DeviceConfigurationManager;
import org.wso2.carbon.device.mgt.core.config.cache.DeviceCacheConfiguration;
import org.wso2.carbon.device.mgt.core.dao.GroupManagementDAOFactory;
import org.wso2.carbon.device.mgt.core.internal.DeviceManagementDataHolder;
import org.wso2.carbon.registry.core.jdbc.realm.InMemoryRealmService;
import org.wso2.carbon.user.api.Permission;
@ -66,7 +72,6 @@ public class GroupManagementProviderServiceTest extends BaseDeviceManagementTest
@Test(expectedExceptions = {GroupManagementException.class, GroupAlreadyExistException.class, TransactionManagementException.class})
public void createGroupError() throws GroupManagementException, GroupAlreadyExistException, TransactionManagementException {
GroupManagementDAOFactory.beginTransaction();
groupManagementProviderService.createGroup(TestUtils.createDeviceGroup4(), DEFAULT_ADMIN_ROLE, DEFAULT_ADMIN_PERMISSIONS);
}
@ -126,7 +131,6 @@ public class GroupManagementProviderServiceTest extends BaseDeviceManagementTest
@Test(dependsOnMethods = ("createGroup"))
public void getGroup() throws GroupManagementException {
DeviceGroup deviceGroup = groupManagementProviderService.getGroup(TestUtils.createDeviceGroup3().getName());
Assert.assertNotNull(groupManagementProviderService.getGroup(deviceGroup.getGroupId()));
}
@ -161,8 +165,7 @@ public class GroupManagementProviderServiceTest extends BaseDeviceManagementTest
@Test(dependsOnMethods = ("createGroup"), expectedExceptions = {GroupManagementException.class})
public void getGroupsByPaginationError() throws GroupManagementException {
GroupPaginationRequest request = null;
groupManagementProviderService.getGroups(request);
groupManagementProviderService.getGroups((GroupPaginationRequest) null);
}
@Test(dependsOnMethods = ("createGroup"))
@ -282,5 +285,29 @@ public class GroupManagementProviderServiceTest extends BaseDeviceManagementTest
groupManagementProviderService.createDefaultGroup("BYOD");
}
@Test(dependsOnMethods = {"createGroup", "addDevices", "updateGroupSecondTime"})
public void checkDeviceBelongsToGroup() throws GroupManagementException {
List<DeviceIdentifier> list = TestUtils.getDeviceIdentifiersList();
boolean isMapped = groupManagementProviderService
.isDeviceMappedToGroup(groupManagementProviderService.getGroup(
TestUtils.createDeviceGroup1().getName()).getGroupId(), list.get(0));
Assert.assertEquals(isMapped, true);
}
@Test
public void checkDeviceBelongsToNonExistingGroup() throws GroupManagementException {
List<DeviceIdentifier> list = TestUtils.getDeviceIdentifiersList();
boolean isMapped = groupManagementProviderService
.isDeviceMappedToGroup(1500, list.get(0));
Assert.assertEquals(isMapped, false);
}
@Test(dependsOnMethods = {"createGroup", "updateGroupSecondTime"}, expectedExceptions = {GroupManagementException.class})
public void checkNullDeviceBelongsToGroup() throws GroupManagementException {
groupManagementProviderService.isDeviceMappedToGroup(groupManagementProviderService.getGroup(
TestUtils.createDeviceGroup1().getName()).getGroupId(), null);
}
}

@ -87,10 +87,10 @@
<Enable>false</Enable>
<ExpiryTime>86400</ExpiryTime>
</CertificateCacheConfiguration>
<GeoLocationConfiguration>
<OperationAnalyticsConfiguration>
<isEnabled>false</isEnabled>
<PublishLocationOperationResponse>false</PublishLocationOperationResponse>
</GeoLocationConfiguration>
<PublishOperationResponse>false</PublishOperationResponse>
</OperationAnalyticsConfiguration>
<DefaultGroupsConfiguration>BYOD,COPE</DefaultGroupsConfiguration>
</DeviceMgtConfiguration>

@ -73,7 +73,7 @@ deviceModule = function () {
}
var userName = carbonUser.username + "@" + carbonUser.domain;
var locationHistory = [];
var geoServicesEnabled = devicemgtProps.serverConfig.geoLocationConfiguration.isEnabled;
var geoServicesEnabled = devicemgtProps.serverConfig.operationAnalyticsConfiguration.isEnabled;
if (geoServicesEnabled) {
try {
var fromDate = new Date();

@ -60,6 +60,6 @@ function onRequest(context) {
} else {
viewModel.lastLocation = stringify({});
}
viewModel.geoServicesEnabled = devicemgtProps.serverConfig.geoLocationConfiguration.isEnabled;
viewModel.geoServicesEnabled = devicemgtProps.serverConfig.operationAnalyticsConfiguration.isEnabled;
return viewModel;
}

@ -0,0 +1,172 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
~ Copyright (c) 2016, 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.
-->
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<parent>
<groupId>org.wso2.carbon.devicemgt</groupId>
<artifactId>device-mgt-feature</artifactId>
<version>3.0.170-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>org.wso2.carbon.device.mgt.basics.feature</artifactId>
<packaging>pom</packaging>
<name>WSO2 Carbon - Device Management Basics Feature</name>
<url>http://wso2.org</url>
<description>This feature contains the core bundles required for Basic Device Management functionality
</description>
<dependencies>
<dependency>
<groupId>org.wso2.carbon.devicemgt</groupId>
<artifactId>org.wso2.carbon.device.mgt.core</artifactId>
</dependency>
<dependency>
<groupId>org.wso2.carbon.devicemgt</groupId>
<artifactId>org.wso2.carbon.device.mgt.common</artifactId>
</dependency>
<dependency>
<groupId>org.wso2.carbon.devicemgt</groupId>
<artifactId>org.wso2.carbon.device.mgt.analytics.data.publisher</artifactId>
</dependency>
<dependency>
<groupId>org.wso2.carbon.registry</groupId>
<artifactId>org.wso2.carbon.registry.indexing</artifactId>
</dependency>
<dependency>
<groupId>org.wso2.carbon.analytics-common</groupId>
<artifactId>org.wso2.carbon.event.receiver.stub</artifactId>
</dependency>
<dependency>
<groupId>org.wso2.carbon.analytics-common</groupId>
<artifactId>org.wso2.carbon.event.stream.stub</artifactId>
</dependency>
<dependency>
<groupId>org.wso2.carbon.analytics-common</groupId>
<artifactId>org.wso2.carbon.event.publisher.stub</artifactId>
</dependency>
<dependency>
<groupId>org.wso2.carbon.analytics-common</groupId>
<artifactId>org.wso2.carbon.event.stream.persistence.stub</artifactId>
</dependency>
<dependency>
<groupId>org.wso2.orbit.org.scannotation</groupId>
<artifactId>scannotation</artifactId>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<artifactId>maven-resources-plugin</artifactId>
<version>2.6</version>
<executions>
<execution>
<id>copy-resources</id>
<phase>generate-resources</phase>
<goals>
<goal>copy-resources</goal>
</goals>
<configuration>
<outputDirectory>src/main/resources</outputDirectory>
<resources>
<resource>
<directory>resources</directory>
<includes>
<include>build.properties</include>
<include>p2.inf</include>
</includes>
</resource>
</resources>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.wso2.maven</groupId>
<artifactId>carbon-p2-plugin</artifactId>
<version>${carbon.p2.plugin.version}</version>
<executions>
<execution>
<id>p2-feature-generation</id>
<phase>package</phase>
<goals>
<goal>p2-feature-gen</goal>
</goals>
<configuration>
<id>org.wso2.carbon.device.mgt.basics</id>
<propertiesFile>../../../features/etc/feature.properties</propertiesFile>
<adviceFile>
<properties>
<propertyDef>org.wso2.carbon.p2.category.type:server</propertyDef>
<propertyDef>org.eclipse.equinox.p2.type.group:false</propertyDef>
</properties>
</adviceFile>
<bundles>
<bundleDef>
org.wso2.carbon.devicemgt:org.wso2.carbon.device.mgt.core:${carbon.device.mgt.version}
</bundleDef>
<bundleDef>
org.wso2.carbon.devicemgt:org.wso2.carbon.device.mgt.common:${carbon.device.mgt.version}
</bundleDef>
<bundleDef>
org.wso2.carbon.devicemgt:org.wso2.carbon.device.mgt.analytics.data.publisher:${carbon.device.mgt.version}
</bundleDef>
<bundleDef>
org.wso2.carbon.analytics-common:org.wso2.carbon.event.receiver.stub:${carbon.analytics.common.version}
</bundleDef>
<bundleDef>
org.wso2.carbon.analytics-common:org.wso2.carbon.event.stream.stub:${carbon.analytics.common.version}
</bundleDef>
<bundleDef>
org.wso2.carbon.analytics-common:org.wso2.carbon.event.publisher.stub:${carbon.analytics.common.version}
</bundleDef>
<bundleDef>
org.wso2.carbon.analytics-common:org.wso2.carbon.event.stream.persistence.stub:${carbon.analytics.common.version}
</bundleDef>
<bundleDef>
org.wso2.orbit.com.fasterxml.jackson.core:jackson-annotations:${jackson-annotations.version}
</bundleDef>
<bundleDef>
org.wso2.orbit.org.scannotation:scannotation:${scannotation.version}
</bundleDef>
</bundles>
<importBundles>
<importBundleDef>
org.wso2.carbon.registry:org.wso2.carbon.registry.indexing:${carbon.registry.version}
</importBundleDef>
</importBundles>
<importFeatures>
<importFeatureDef>
org.wso2.carbon.core.server:${carbon.kernel.version}
</importFeatureDef>
<importFeatureDef>
org.wso2.carbon.email.sender:${carbon.device.mgt.version}
</importFeatureDef>
</importFeatures>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>

@ -87,10 +87,10 @@
<Enable>true</Enable>
<ExpiryTime>86400</ExpiryTime>
</CertificateCacheConfiguration>
<GeoLocationConfiguration>
<OperationAnalyticsConfiguration>
<isEnabled>false</isEnabled>
<PublishLocationOperationResponse>false</PublishLocationOperationResponse>
</GeoLocationConfiguration>
<PublishOperationResponse>false</PublishOperationResponse>
</OperationAnalyticsConfiguration>
<DefaultGroupsConfiguration>BYOD,COPE</DefaultGroupsConfiguration>
</DeviceMgtConfiguration>

@ -1,8 +1,8 @@
instructions.configure = \
org.eclipse.equinox.p2.touchpoint.natives.copy(source:${installFolder}/../features/org.wso2.carbon.device.mgt.server_${feature.version}/conf/cdm-config.xml,target:${installFolder}/../../conf/cdm-config.xml,overwrite:true);\
org.eclipse.equinox.p2.touchpoint.natives.copy(source:${installFolder}/../features/org.wso2.carbon.device.mgt.server_${feature.version}/conf/license-config.xml,target:${installFolder}/../../conf/etc/license-config.xml,overwrite:true);\
org.eclipse.equinox.p2.touchpoint.natives.copy(source:${installFolder}/../features/org.wso2.carbon.device.mgt.server_${feature.version}/conf/remote-appmanager-config.xml,target:${installFolder}/../../conf/etc/remote-appmanager-config.xml,overwrite:true);\
org.eclipse.equinox.p2.touchpoint.natives.copy(source:${installFolder}/../features/org.wso2.carbon.device.mgt.server_${feature.version}/dbscripts/cdm,target:${installFolder}/../../../dbscripts/cdm,overwrite:true);\
org.eclipse.equinox.p2.touchpoint.natives.copy(source:${installFolder}/../features/org.wso2.carbon.device.mgt.server_${feature.version}/rxts/license.rxt,target:${installFolder}/../../../repository/resources/rxts/license.rxt,overwrite:true);\
org.eclipse.equinox.p2.touchpoint.natives.copy(source:${installFolder}/../features/org.wso2.carbon.device.mgt.basics_${feature.version}/conf/cdm-config.xml,target:${installFolder}/../../conf/cdm-config.xml,overwrite:true);\
org.eclipse.equinox.p2.touchpoint.natives.copy(source:${installFolder}/../features/org.wso2.carbon.device.mgt.basics_${feature.version}/conf/license-config.xml,target:${installFolder}/../../conf/etc/license-config.xml,overwrite:true);\
org.eclipse.equinox.p2.touchpoint.natives.copy(source:${installFolder}/../features/org.wso2.carbon.device.mgt.basics_${feature.version}/conf/remote-appmanager-config.xml,target:${installFolder}/../../conf/etc/remote-appmanager-config.xml,overwrite:true);\
org.eclipse.equinox.p2.touchpoint.natives.copy(source:${installFolder}/../features/org.wso2.carbon.device.mgt.basics_${feature.version}/dbscripts/cdm,target:${installFolder}/../../../dbscripts/cdm,overwrite:true);\
org.eclipse.equinox.p2.touchpoint.natives.copy(source:${installFolder}/../features/org.wso2.carbon.device.mgt.basics_${feature.version}/rxts/license.rxt,target:${installFolder}/../../../repository/resources/rxts/license.rxt,overwrite:true);\
org.eclipse.equinox.p2.touchpoint.natives.mkdir(path:${installFolder}/../../../repository/resources/email-templates);\
org.eclipse.equinox.p2.touchpoint.natives.copy(source:${installFolder}/../features/org.wso2.carbon.device.mgt.server_${feature.version}/email/templates,target:${installFolder}/../../../repository/resources/email-templates,overwrite:true);\
org.eclipse.equinox.p2.touchpoint.natives.copy(source:${installFolder}/../features/org.wso2.carbon.device.mgt.basics_${feature.version}/email/templates,target:${installFolder}/../../../repository/resources/email-templates,overwrite:true);\

@ -42,45 +42,21 @@
</dependency>
<dependency>
<groupId>org.wso2.carbon.devicemgt</groupId>
<artifactId>org.wso2.carbon.device.mgt.url.printer</artifactId>
<artifactId>org.wso2.carbon.device.mgt.api.feature</artifactId>
<type>zip</type>
</dependency>
<dependency>
<groupId>org.wso2.carbon.devicemgt</groupId>
<artifactId>org.wso2.carbon.device.mgt.common</artifactId>
<artifactId>org.wso2.carbon.device.mgt.url.printer</artifactId>
</dependency>
<dependency>
<groupId>org.wso2.carbon.devicemgt</groupId>
<artifactId>org.wso2.carbon.device.mgt.api.feature</artifactId>
<type>zip</type>
<artifactId>org.wso2.carbon.device.mgt.extensions.pull.notification</artifactId>
</dependency>
<dependency>
<groupId>org.wso2.orbit.org.apache.pdfbox</groupId>
<artifactId>pdfbox</artifactId>
</dependency>
<dependency>
<groupId>org.wso2.carbon.devicemgt</groupId>
<artifactId>org.wso2.carbon.device.mgt.extensions.pull.notification</artifactId>
</dependency>
<dependency>
<groupId>org.wso2.carbon.registry</groupId>
<artifactId>org.wso2.carbon.registry.indexing</artifactId>
</dependency>
<dependency>
<groupId>org.wso2.carbon.analytics-common</groupId>
<artifactId>org.wso2.carbon.event.receiver.stub</artifactId>
</dependency>
<dependency>
<groupId>org.wso2.carbon.analytics-common</groupId>
<artifactId>org.wso2.carbon.event.stream.stub</artifactId>
</dependency>
<dependency>
<groupId>org.wso2.carbon.analytics-common</groupId>
<artifactId>org.wso2.carbon.event.publisher.stub</artifactId>
</dependency>
<dependency>
<groupId>org.wso2.carbon.analytics-common</groupId>
<artifactId>org.wso2.carbon.event.stream.persistence.stub</artifactId>
</dependency>
</dependencies>
<build>
@ -131,55 +107,31 @@
</properties>
</adviceFile>
<includedFeatures>
<includedFeatureDef>
org.wso2.carbon.devicemgt:org.wso2.carbon.device.mgt.basics.feature:${carbon.device.mgt.version}
</includedFeatureDef>
<includedFeatureDef>
org.wso2.carbon.devicemgt:org.wso2.carbon.device.mgt.api.feature:${carbon.device.mgt.version}
</includedFeatureDef>
</includedFeatures>
<bundles>
<bundleDef>
org.wso2.carbon.devicemgt:org.wso2.carbon.device.mgt.core:${carbon.device.mgt.version}
</bundleDef>
<bundleDef>
org.wso2.carbon.devicemgt:org.wso2.carbon.device.mgt.common:${carbon.device.mgt.version}
</bundleDef>
<bundleDef>
org.wso2.carbon.devicemgt:org.wso2.carbon.device.mgt.url.printer:${carbon.device.mgt.version}
</bundleDef>
<bundleDef>
org.wso2.carbon.devicemgt:org.wso2.carbon.device.mgt.extensions.pull.notification:${carbon.device.mgt.version}
</bundleDef>
<!--<bundleDef>-->
<!--org.wso2.carbon.commons:org.wso2.carbon.email.verification-->
<!--</bundleDef>-->
<bundleDef>
org.wso2.carbon.identity.inbound.auth.oauth2:org.wso2.carbon.identity.oauth.stub:${identity.inbound.auth.oauth.version}
</bundleDef>
<bundleDef>
org.wso2.orbit.com.fasterxml.jackson.core:jackson-annotations:${jackson-annotations.version}
</bundleDef>
<bundleDef>
org.wso2.carbon.analytics-common:org.wso2.carbon.event.receiver.stub:${carbon.analytics.common.version}
</bundleDef>
<bundleDef>
org.wso2.carbon.analytics-common:org.wso2.carbon.event.stream.stub:${carbon.analytics.common.version}
</bundleDef>
<bundleDef>
org.wso2.carbon.analytics-common:org.wso2.carbon.event.publisher.stub:${carbon.analytics.common.version}
</bundleDef>
<bundleDef>
org.wso2.carbon.analytics-common:org.wso2.carbon.event.stream.persistence.stub:${carbon.analytics.common.version}
</bundleDef>
<!-- Below should be bundled with the email verification -->
</bundles>
<importBundles>
<importBundleDef>org.wso2.carbon.apimgt:org.wso2.carbon.apimgt.keymgt:${carbon.api.mgt.version}</importBundleDef>
<importBundleDef>org.wso2.orbit.org.apache.pdfbox:pdfbox:${orbit.version.pdfbox}</importBundleDef>
<importBundleDef>org.wso2.carbon.registry:org.wso2.carbon.registry.indexing:${carbon.registry.version}</importBundleDef>
</importBundles>
<importFeatures>
<importFeatureDef>org.wso2.carbon.core.server:${carbon.kernel.version}</importFeatureDef>
<importFeatureDef>org.wso2.carbon.device.mgt.extensions:${carbon.device.mgt.version}</importFeatureDef>
<importFeatureDef>org.wso2.carbon.email.sender:${carbon.device.mgt.version}</importFeatureDef>
</importFeatures>
</configuration>
</execution>

@ -33,6 +33,7 @@
<url>http://wso2.org</url>
<modules>
<module>org.wso2.carbon.device.mgt.basics.feature</module>
<module>org.wso2.carbon.device.mgt.server.feature</module>
<module>org.wso2.carbon.device.mgt.ui.feature</module>
<module>org.wso2.carbon.device.mgt.api.feature</module>

Loading…
Cancel
Save