From bfbbe3c7330f402e4d1880bc0f40250bbb30454c Mon Sep 17 00:00:00 2001 From: Amalka Subasinghe Date: Wed, 9 Jun 2021 15:25:12 +0530 Subject: [PATCH] added androoid feature --- .../pom.xml | 25 +- .../impl/EventReceiverServiceImpl.java | 266 +++++++++--------- .../android/util/AndroidAPIUtils.java | 54 ++-- .../android/util/AndroidDeviceUtils.java | 100 ++++--- .../webapp/META-INF/webapp-classloading.xml | 2 +- .../pom.xml | 4 +- ...id-Mutual-SSL-Configuration-Management.xml | 2 - ...--Android-Mutual-SSL-Device-Management.xml | 5 - ...min--Android-Mutual-SSL-Event-Receiver.xml | 2 - .../datasources/android-datasources.xml.j2 | 63 +++++ .../repository/conf/mobile-config.xml.j2 | 71 +++++ .../datasources/android-datasources.xml | 3 +- .../src/main/resources/p2.inf | 7 +- pom.xml | 4 +- 14 files changed, 358 insertions(+), 250 deletions(-) create mode 100644 features/mobile-plugins-feature/android-plugin-feature/org.wso2.carbon.device.mgt.mobile.android.feature/src/main/resources/conf_templates/templates/repository/conf/datasources/android-datasources.xml.j2 create mode 100644 features/mobile-plugins-feature/android-plugin-feature/org.wso2.carbon.device.mgt.mobile.android.feature/src/main/resources/conf_templates/templates/repository/conf/mobile-config.xml.j2 diff --git a/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/pom.xml b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/pom.xml index f5079002e..d40e0d75c 100644 --- a/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/pom.xml +++ b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/pom.xml @@ -172,6 +172,15 @@ + + org.springframework + spring-web + provided + + + org.json.wso2 + json + org.apache.cxf @@ -247,22 +256,6 @@ com.google.code.gson gson - - org.wso2.carbon.devicemgt - org.wso2.carbon.device.mgt.analytics.data.publisher - provided - - - org.slf4j - slf4j-api - - - - - org.wso2.carbon.analytics - org.wso2.carbon.analytics.api - provided - io.swagger swagger-annotations diff --git a/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/src/main/java/org/wso2/carbon/mdm/services/android/services/impl/EventReceiverServiceImpl.java b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/src/main/java/org/wso2/carbon/mdm/services/android/services/impl/EventReceiverServiceImpl.java index 0de1ac7ab..8ac430183 100644 --- a/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/src/main/java/org/wso2/carbon/mdm/services/android/services/impl/EventReceiverServiceImpl.java +++ b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/src/main/java/org/wso2/carbon/mdm/services/android/services/impl/EventReceiverServiceImpl.java @@ -22,8 +22,6 @@ import com.google.gson.Gson; import com.google.gson.JsonObject; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; -import org.wso2.carbon.analytics.datasource.commons.exception.AnalyticsException; -import org.wso2.carbon.device.mgt.analytics.data.publisher.exception.DataPublisherConfigurationException; import org.wso2.carbon.device.mgt.common.Device; import org.wso2.carbon.device.mgt.common.DeviceIdentifier; import org.wso2.carbon.device.mgt.common.exceptions.DeviceManagementException; @@ -69,58 +67,58 @@ public class EventReceiverServiceImpl implements EventReceiverService { if (log.isDebugEnabled()) { log.debug("Invoking Android device event logging."); } - Device device; - try { - if (!DeviceManagerUtil.isPublishLocationResponseEnabled()) { - return Response.status(Response.Status.ACCEPTED).entity("Event is publishing has not enabled.").build(); - } - DeviceIdentifier deviceIdentifier = new DeviceIdentifier(eventBeanWrapper.getDeviceIdentifier(), - AndroidConstants.DEVICE_TYPE_ANDROID); - device = AndroidAPIUtils.getDeviceManagementService().getDevice(deviceIdentifier, false); - if (device != null && EnrolmentInfo.Status.ACTIVE != device.getEnrolmentInfo().getStatus()){ - return Response.status(Response.Status.ACCEPTED).entity("Device is not in Active state.").build(); - } else if (device == null){ - return Response.status(Response.Status.ACCEPTED).entity("Device is not enrolled yet.").build(); - } - } catch (DeviceManagementException e) { - log.error("Error occurred while checking Operation Analytics is Enabled.", e); - return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(e.getMessage()).build(); - } - String eventType = eventBeanWrapper.getType(); - if (!LOCATION_EVENT_TYPE.equals(eventType)) { - String msg = "Dropping Android " + eventType + " Event.Only Location Event Type is supported."; - log.warn(msg); - return Response.status(Response.Status.BAD_REQUEST).entity(msg).build(); - } - Message message = new Message(); - Object[] metaData = {eventBeanWrapper.getDeviceIdentifier(), device.getEnrolmentInfo().getOwner(), - AndroidConstants.DEVICE_TYPE_ANDROID}; - String eventPayload = eventBeanWrapper.getPayload(); - JsonObject jsonObject = gson.fromJson(eventPayload, JsonObject.class); - Object[] payload = { - jsonObject.get(TIME_STAMP).getAsLong(), - jsonObject.get(LATITUDE).getAsDouble(), - jsonObject.get(LONGITUDE).getAsDouble() - }; - try { - if (AndroidAPIUtils.getEventPublisherService().publishEvent( - EVENT_STREAM_DEFINITION, "1.0.0", metaData, new Object[0], payload)) { - message.setResponseCode("Event is published successfully."); - return Response.status(Response.Status.CREATED).entity(message).build(); - } else { - log.warn("Error occurred while trying to publish the event. This could be due to unavailability " + - "of the publishing service. Please make sure that analytics server is running and accessible " + - "by this server"); - throw new UnexpectedServerErrorException( - new ErrorResponse.ErrorResponseBuilder().setCode(503l).setMessage("Error occurred due to " + - "unavailability of the publishing service.").build()); - } - } catch (DataPublisherConfigurationException e) { +// Device device; +// try { +// if (!DeviceManagerUtil.isPublishLocationResponseEnabled()) { +// return Response.status(Response.Status.ACCEPTED).entity("Event is publishing has not enabled.").build(); +// } +// DeviceIdentifier deviceIdentifier = new DeviceIdentifier(eventBeanWrapper.getDeviceIdentifier(), +// AndroidConstants.DEVICE_TYPE_ANDROID); +// device = AndroidAPIUtils.getDeviceManagementService().getDevice(deviceIdentifier, false); +// if (device != null && EnrolmentInfo.Status.ACTIVE != device.getEnrolmentInfo().getStatus()){ +// return Response.status(Response.Status.ACCEPTED).entity("Device is not in Active state.").build(); +// } else if (device == null){ +// return Response.status(Response.Status.ACCEPTED).entity("Device is not enrolled yet.").build(); +// } +// } catch (DeviceManagementException e) { +// log.error("Error occurred while checking Operation Analytics is Enabled.", e); +// return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(e.getMessage()).build(); +// } +// String eventType = eventBeanWrapper.getType(); +// if (!LOCATION_EVENT_TYPE.equals(eventType)) { +// String msg = "Dropping Android " + eventType + " Event.Only Location Event Type is supported."; +// log.warn(msg); +// return Response.status(Response.Status.BAD_REQUEST).entity(msg).build(); +// } +// Message message = new Message(); +// Object[] metaData = {eventBeanWrapper.getDeviceIdentifier(), device.getEnrolmentInfo().getOwner(), +// AndroidConstants.DEVICE_TYPE_ANDROID}; +// String eventPayload = eventBeanWrapper.getPayload(); +// JsonObject jsonObject = gson.fromJson(eventPayload, JsonObject.class); +// Object[] payload = { +// jsonObject.get(TIME_STAMP).getAsLong(), +// jsonObject.get(LATITUDE).getAsDouble(), +// jsonObject.get(LONGITUDE).getAsDouble() +// }; +// try { +// if (AndroidAPIUtils.getEventPublisherService().publishEvent( +// EVENT_STREAM_DEFINITION, "1.0.0", metaData, new Object[0], payload)) { +// message.setResponseCode("Event is published successfully."); +// return Response.status(Response.Status.CREATED).entity(message).build(); +// } else { +// log.warn("Error occurred while trying to publish the event. This could be due to unavailability " + +// "of the publishing service. Please make sure that analytics server is running and accessible " + +// "by this server"); +// throw new UnexpectedServerErrorException( +// new ErrorResponse.ErrorResponseBuilder().setCode(503l).setMessage("Error occurred due to " + +// "unavailability of the publishing service.").build()); +// } +// } catch (DataPublisherConfigurationException e) { String msg = "Error occurred while getting the Data publisher Service instance."; - log.error(msg, e); +// log.error(msg, e); throw new UnexpectedServerErrorException( new ErrorResponse.ErrorResponseBuilder().setCode(500l).setMessage(msg).build()); - } +// } } @GET @@ -134,94 +132,94 @@ public class EventReceiverServiceImpl implements EventReceiverService { @QueryParam("type") String type, @HeaderParam("If-Modified-Since") String ifModifiedSince) { - if (from != 0l && to != 0l && deviceId != null) { - return retrieveAlertFromDate(deviceId, from, to); - } else if (deviceId != null && type != null) { - return retrieveAlertByType(deviceId, type); - } else if (deviceId != null) { - return retrieveAlert(deviceId); - } else { +// if (from != 0l && to != 0l && deviceId != null) { +// return retrieveAlertFromDate(deviceId, from, to); +// } else if (deviceId != null && type != null) { +// return retrieveAlertByType(deviceId, type); +// } else if (deviceId != null) { +// return retrieveAlert(deviceId); +// } else { throw new BadRequestException( new ErrorResponse.ErrorResponseBuilder().setCode(400l).setMessage("Request must contain " + "the device identifier. Optionally, both from and to value should be present to get " + "alerts between times.").build()); - } - } - - private Response retrieveAlert(String deviceId) { - if (log.isDebugEnabled()) { - log.debug("Retrieving events for given device Identifier."); - } - String query = "deviceIdentifier:" + deviceId; - List deviceStates; - try { - deviceStates = AndroidDeviceUtils.getAllEventsForDevice(EVENT_STREAM_DEFINITION, query); - if (deviceStates == null) { - throw new NotFoundException( - new ErrorResponse.ErrorResponseBuilder().setCode(404l).setMessage("No any alerts are " + - "published for Device: " + deviceId + ".").build()); - } else { - return Response.status(Response.Status.OK).entity(deviceStates).build(); - } - } catch (AnalyticsException e) { - String msg = "Error occurred while getting published events for specific device: " + deviceId + "."; - log.error(msg, e); - throw new UnexpectedServerErrorException( - new ErrorResponse.ErrorResponseBuilder().setCode(500l).setMessage(msg).build()); - } +// } } - private Response retrieveAlertFromDate(String deviceId, long from, long to) { - String fromDate = String.valueOf(from); - String toDate = String.valueOf(to); - if (log.isDebugEnabled()) { - log.debug("Retrieving events for given device Identifier and time period."); - } - - String query = "deviceIdentifier:" + deviceId + " AND _timestamp: [" + fromDate + " TO " + toDate + "]"; - List deviceStates; - try { - deviceStates = AndroidDeviceUtils.getAllEventsForDevice(EVENT_STREAM_DEFINITION, query); - if (deviceStates == null) { - throw new NotFoundException( - new ErrorResponse.ErrorResponseBuilder().setCode(404l).setMessage("No any alerts are " + - "published on given date for given Device: " + deviceId + ".").build()); - - } else { - return Response.status(Response.Status.OK).entity(deviceStates).build(); - } - } catch (AnalyticsException e) { - String msg = "Error occurred while getting published events for specific " + - "Device: " + deviceId + " on given Date."; - log.error(msg, e); - throw new UnexpectedServerErrorException( - new ErrorResponse.ErrorResponseBuilder().setCode(500l).setMessage(msg).build()); - } - } - - private Response retrieveAlertByType(String deviceId, String type) { - if (log.isDebugEnabled()) { - log.debug("Retrieving events for given device identifier and type."); - } - String query = "deviceIdentifier:" + deviceId + " AND type:" + type; - List deviceStates; - try { - deviceStates = AndroidDeviceUtils.getAllEventsForDevice(EVENT_STREAM_DEFINITION, query); - if (deviceStates == null) { - throw new NotFoundException( - new ErrorResponse.ErrorResponseBuilder().setCode(404l).setMessage("No any alerts are " + - "published for given Device: '" + deviceId + "' and given specific Type.").build()); - - } else { - return Response.status(Response.Status.OK).entity(deviceStates).build(); - } - } catch (AnalyticsException e) { - String msg = "Error occurred while getting published events for specific " + - "Device: " + deviceId + "and given specific Type."; - log.error(msg, e); - throw new UnexpectedServerErrorException( - new ErrorResponse.ErrorResponseBuilder().setCode(500l).setMessage(msg).build()); - } - } +// private Response retrieveAlert(String deviceId) { +// if (log.isDebugEnabled()) { +// log.debug("Retrieving events for given device Identifier."); +// } +// String query = "deviceIdentifier:" + deviceId; +// List deviceStates; +// try { +// deviceStates = AndroidDeviceUtils.getAllEventsForDevice(EVENT_STREAM_DEFINITION, query); +// if (deviceStates == null) { +// throw new NotFoundException( +// new ErrorResponse.ErrorResponseBuilder().setCode(404l).setMessage("No any alerts are " + +// "published for Device: " + deviceId + ".").build()); +// } else { +// return Response.status(Response.Status.OK).entity(deviceStates).build(); +// } +// } catch (AnalyticsException e) { +// String msg = "Error occurred while getting published events for specific device: " + deviceId + "."; +// log.error(msg, e); +// throw new UnexpectedServerErrorException( +// new ErrorResponse.ErrorResponseBuilder().setCode(500l).setMessage(msg).build()); +// } +// } +// +// private Response retrieveAlertFromDate(String deviceId, long from, long to) { +// String fromDate = String.valueOf(from); +// String toDate = String.valueOf(to); +// if (log.isDebugEnabled()) { +// log.debug("Retrieving events for given device Identifier and time period."); +// } +// +// String query = "deviceIdentifier:" + deviceId + " AND _timestamp: [" + fromDate + " TO " + toDate + "]"; +// List deviceStates; +// try { +// deviceStates = AndroidDeviceUtils.getAllEventsForDevice(EVENT_STREAM_DEFINITION, query); +// if (deviceStates == null) { +// throw new NotFoundException( +// new ErrorResponse.ErrorResponseBuilder().setCode(404l).setMessage("No any alerts are " + +// "published on given date for given Device: " + deviceId + ".").build()); +// +// } else { +// return Response.status(Response.Status.OK).entity(deviceStates).build(); +// } +// } catch (AnalyticsException e) { +// String msg = "Error occurred while getting published events for specific " + +// "Device: " + deviceId + " on given Date."; +// log.error(msg, e); +// throw new UnexpectedServerErrorException( +// new ErrorResponse.ErrorResponseBuilder().setCode(500l).setMessage(msg).build()); +// } +// } +// +// private Response retrieveAlertByType(String deviceId, String type) { +// if (log.isDebugEnabled()) { +// log.debug("Retrieving events for given device identifier and type."); +// } +// String query = "deviceIdentifier:" + deviceId + " AND type:" + type; +// List deviceStates; +// try { +// deviceStates = AndroidDeviceUtils.getAllEventsForDevice(EVENT_STREAM_DEFINITION, query); +// if (deviceStates == null) { +// throw new NotFoundException( +// new ErrorResponse.ErrorResponseBuilder().setCode(404l).setMessage("No any alerts are " + +// "published for given Device: '" + deviceId + "' and given specific Type.").build()); +// +// } else { +// return Response.status(Response.Status.OK).entity(deviceStates).build(); +// } +// } catch (AnalyticsException e) { +// String msg = "Error occurred while getting published events for specific " + +// "Device: " + deviceId + "and given specific Type."; +// log.error(msg, e); +// throw new UnexpectedServerErrorException( +// new ErrorResponse.ErrorResponseBuilder().setCode(500l).setMessage(msg).build()); +// } +// } } diff --git a/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/src/main/java/org/wso2/carbon/mdm/services/android/util/AndroidAPIUtils.java b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/src/main/java/org/wso2/carbon/mdm/services/android/util/AndroidAPIUtils.java index 336801721..15928d80e 100644 --- a/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/src/main/java/org/wso2/carbon/mdm/services/android/util/AndroidAPIUtils.java +++ b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/src/main/java/org/wso2/carbon/mdm/services/android/util/AndroidAPIUtils.java @@ -20,9 +20,7 @@ package org.wso2.carbon.mdm.services.android.util; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; -import org.wso2.carbon.analytics.api.AnalyticsDataAPI; import org.wso2.carbon.context.PrivilegedCarbonContext; -import org.wso2.carbon.device.mgt.analytics.data.publisher.service.EventsPublisherService; import org.wso2.carbon.device.mgt.common.notification.mgt.NotificationManagementService; import org.wso2.carbon.device.mgt.core.app.mgt.ApplicationManagementProviderService; import org.wso2.carbon.device.mgt.core.device.details.mgt.DeviceInformationManager; @@ -41,8 +39,8 @@ public class AndroidAPIUtils { private static PolicyManagerService policyManagerService = null; private static ApplicationManagementProviderService applicationManagementProviderService = null; private static NotificationManagementService notificationManagementService = null; - private static EventsPublisherService eventsPublisherService = null; - private static AnalyticsDataAPI analyticsDataAPI = null; +// private static EventsPublisherService eventsPublisherService = null; +// private static AnalyticsDataAPI analyticsDataAPI = null; private AndroidAPIUtils() { throw new IllegalStateException("Utility class"); @@ -126,30 +124,30 @@ public class AndroidAPIUtils { return notificationManagementService; } - public static EventsPublisherService getEventPublisherService() { - if (eventsPublisherService == null) { - PrivilegedCarbonContext ctx = PrivilegedCarbonContext.getThreadLocalCarbonContext(); - eventsPublisherService = (EventsPublisherService) ctx.getOSGiService(EventsPublisherService.class, null); - if (eventsPublisherService == null) { - String msg = "Event Publisher service has not initialized."; - log.error(msg); - throw new IllegalStateException(msg); - } - } - return eventsPublisherService; - } +// public static EventsPublisherService getEventPublisherService() { +// if (eventsPublisherService == null) { +// PrivilegedCarbonContext ctx = PrivilegedCarbonContext.getThreadLocalCarbonContext(); +// eventsPublisherService = (EventsPublisherService) ctx.getOSGiService(EventsPublisherService.class, null); +// if (eventsPublisherService == null) { +// String msg = "Event Publisher service has not initialized."; +// log.error(msg); +// throw new IllegalStateException(msg); +// } +// } +// return eventsPublisherService; +// } - public static AnalyticsDataAPI getAnalyticsDataAPI() { - if (analyticsDataAPI == null) { - PrivilegedCarbonContext ctx = PrivilegedCarbonContext.getThreadLocalCarbonContext(); - analyticsDataAPI = (AnalyticsDataAPI) ctx.getOSGiService(AnalyticsDataAPI.class, null); - if (analyticsDataAPI == null) { - String msg = "Analytics api service has not initialized."; - log.error(msg); - throw new IllegalStateException(msg); - } - } - return analyticsDataAPI; - } +// public static AnalyticsDataAPI getAnalyticsDataAPI() { +// if (analyticsDataAPI == null) { +// PrivilegedCarbonContext ctx = PrivilegedCarbonContext.getThreadLocalCarbonContext(); +// analyticsDataAPI = (AnalyticsDataAPI) ctx.getOSGiService(AnalyticsDataAPI.class, null); +// if (analyticsDataAPI == null) { +// String msg = "Analytics api service has not initialized."; +// log.error(msg); +// throw new IllegalStateException(msg); +// } +// } +// return analyticsDataAPI; +// } } diff --git a/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/src/main/java/org/wso2/carbon/mdm/services/android/util/AndroidDeviceUtils.java b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/src/main/java/org/wso2/carbon/mdm/services/android/util/AndroidDeviceUtils.java index 7617047c9..542875b98 100644 --- a/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/src/main/java/org/wso2/carbon/mdm/services/android/util/AndroidDeviceUtils.java +++ b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/src/main/java/org/wso2/carbon/mdm/services/android/util/AndroidDeviceUtils.java @@ -26,12 +26,6 @@ import com.google.gson.JsonObject; import com.google.gson.JsonParser; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; -import org.wso2.carbon.analytics.api.AnalyticsDataAPI; -import org.wso2.carbon.analytics.api.AnalyticsDataAPIUtil; -import org.wso2.carbon.analytics.dataservice.commons.AnalyticsDataResponse; -import org.wso2.carbon.analytics.dataservice.commons.SearchResultEntry; -import org.wso2.carbon.analytics.datasource.commons.Record; -import org.wso2.carbon.analytics.datasource.commons.exception.AnalyticsException; import org.wso2.carbon.context.CarbonContext; import org.wso2.carbon.context.PrivilegedCarbonContext; import org.wso2.carbon.device.mgt.common.Device; @@ -108,53 +102,53 @@ public class AndroidDeviceUtils { DeviceManagementConstants.MobileDeviceTypes.MOBILE_DEVICE_TYPE_ANDROID, operation, deviceIdentifiers); } - public static List getAllEventsForDevice(String tableName, String query) throws AnalyticsException { - int tenantId = CarbonContext.getThreadLocalCarbonContext().getTenantId(); - AnalyticsDataAPI analyticsDataAPI = AndroidAPIUtils.getAnalyticsDataAPI(); - int eventCount = analyticsDataAPI.searchCount(tenantId, tableName, query); - if (eventCount == 0) { - return null; - } - List resultEntries = analyticsDataAPI.search(tenantId, tableName, query, 0, eventCount); - List recordIds = getRecordIds(resultEntries); - AnalyticsDataResponse response = analyticsDataAPI.get(tenantId, tableName, 1, null, recordIds); - Map deviceStateses = createDeviceStatusData(AnalyticsDataAPIUtil.listRecords( - analyticsDataAPI, response)); - return getSortedDeviceStateData(deviceStateses, resultEntries); - } - - private static List getRecordIds(List searchResults) { - List ids = new ArrayList<>(); - for (SearchResultEntry searchResult : searchResults) { - ids.add(searchResult.getId()); - } - return ids; - } - - public static Map createDeviceStatusData(List records) { - Map deviceStatuses = new HashMap<>(); - for (Record record : records) { - DeviceState deviceState = createDeviceStatusData(record); - deviceStatuses.put(deviceState.getId(), deviceState); - } - return deviceStatuses; - } - - private static DeviceState createDeviceStatusData(Record record) { - DeviceState deviceState = new DeviceState(); - deviceState.setId(record.getId()); - deviceState.setValues(record.getValues()); - return deviceState; - } - - public static List getSortedDeviceStateData(Map sensorDatas, - List searchResults) { - List sortedRecords = new ArrayList<>(); - for (SearchResultEntry searchResultEntry : searchResults) { - sortedRecords.add(sensorDatas.get(searchResultEntry.getId())); - } - return sortedRecords; - } +// public static List getAllEventsForDevice(String tableName, String query) throws AnalyticsException { +// int tenantId = CarbonContext.getThreadLocalCarbonContext().getTenantId(); +// AnalyticsDataAPI analyticsDataAPI = AndroidAPIUtils.getAnalyticsDataAPI(); +// int eventCount = analyticsDataAPI.searchCount(tenantId, tableName, query); +// if (eventCount == 0) { +// return null; +// } +// List resultEntries = analyticsDataAPI.search(tenantId, tableName, query, 0, eventCount); +// List recordIds = getRecordIds(resultEntries); +// AnalyticsDataResponse response = analyticsDataAPI.get(tenantId, tableName, 1, null, recordIds); +// Map deviceStateses = createDeviceStatusData(AnalyticsDataAPIUtil.listRecords( +// analyticsDataAPI, response)); +// return getSortedDeviceStateData(deviceStateses, resultEntries); +// } + +// private static List getRecordIds(List searchResults) { +// List ids = new ArrayList<>(); +// for (SearchResultEntry searchResult : searchResults) { +// ids.add(searchResult.getId()); +// } +// return ids; +// } + +// public static Map createDeviceStatusData(List records) { +// Map deviceStatuses = new HashMap<>(); +// for (Record record : records) { +// DeviceState deviceState = createDeviceStatusData(record); +// deviceStatuses.put(deviceState.getId(), deviceState); +// } +// return deviceStatuses; +// } + +// private static DeviceState createDeviceStatusData(Record record) { +// DeviceState deviceState = new DeviceState(); +// deviceState.setId(record.getId()); +// deviceState.setValues(record.getValues()); +// return deviceState; +// } + +// public static List getSortedDeviceStateData(Map sensorDatas, +// List searchResults) { +// List sortedRecords = new ArrayList<>(); +// for (SearchResultEntry searchResultEntry : searchResults) { +// sortedRecords.add(sensorDatas.get(searchResultEntry.getId())); +// } +// return sortedRecords; +// } public static void updateOperation(Device device, Operation operation) throws OperationManagementException, PolicyComplianceException, ApplicationManagementException { diff --git a/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/src/main/webapp/META-INF/webapp-classloading.xml b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/src/main/webapp/META-INF/webapp-classloading.xml index 185de22d4..8cbf41f9f 100644 --- a/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/src/main/webapp/META-INF/webapp-classloading.xml +++ b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/src/main/webapp/META-INF/webapp-classloading.xml @@ -31,5 +31,5 @@ Tomcat environment is the default and every webapps gets it even if they didn't specify it. e.g. If a webapps requires CXF, they will get both Tomcat and CXF. --> - CXF,Carbon + CXF3,Carbon diff --git a/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android/pom.xml b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android/pom.xml index f600c088c..3d0c0662e 100644 --- a/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android/pom.xml +++ b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android/pom.xml @@ -56,8 +56,8 @@ Device Management Mobile Android Impl Bundle org.wso2.carbon.device.mgt.mobile.android.internal - org.osgi.framework, - org.osgi.service.component, + org.osgi.framework.*;version="${imp.package.version.osgi.framework}", + org.osgi.service.*;version="${imp.package.version.osgi.service}", org.apache.commons.logging, javax.xml, javax.xml.stream, diff --git a/features/mobile-plugins-feature/android-plugin-feature/org.wso2.carbon.device.mgt.mobile.android.feature/src/main/resources/apis/admin--Android-Mutual-SSL-Configuration-Management.xml b/features/mobile-plugins-feature/android-plugin-feature/org.wso2.carbon.device.mgt.mobile.android.feature/src/main/resources/apis/admin--Android-Mutual-SSL-Configuration-Management.xml index 41596567a..7cddba927 100644 --- a/features/mobile-plugins-feature/android-plugin-feature/org.wso2.carbon.device.mgt.mobile.android.feature/src/main/resources/apis/admin--Android-Mutual-SSL-Configuration-Management.xml +++ b/features/mobile-plugins-feature/android-plugin-feature/org.wso2.carbon.device.mgt.mobile.android.feature/src/main/resources/apis/admin--Android-Mutual-SSL-Configuration-Management.xml @@ -14,7 +14,6 @@ - @@ -30,7 +29,6 @@ - diff --git a/features/mobile-plugins-feature/android-plugin-feature/org.wso2.carbon.device.mgt.mobile.android.feature/src/main/resources/apis/admin--Android-Mutual-SSL-Device-Management.xml b/features/mobile-plugins-feature/android-plugin-feature/org.wso2.carbon.device.mgt.mobile.android.feature/src/main/resources/apis/admin--Android-Mutual-SSL-Device-Management.xml index d7fa119de..055e6fbf2 100644 --- a/features/mobile-plugins-feature/android-plugin-feature/org.wso2.carbon.device.mgt.mobile.android.feature/src/main/resources/apis/admin--Android-Mutual-SSL-Device-Management.xml +++ b/features/mobile-plugins-feature/android-plugin-feature/org.wso2.carbon.device.mgt.mobile.android.feature/src/main/resources/apis/admin--Android-Mutual-SSL-Device-Management.xml @@ -13,7 +13,6 @@ - @@ -29,7 +28,6 @@ - @@ -45,7 +43,6 @@ - @@ -61,7 +58,6 @@ - @@ -77,7 +73,6 @@ - diff --git a/features/mobile-plugins-feature/android-plugin-feature/org.wso2.carbon.device.mgt.mobile.android.feature/src/main/resources/apis/admin--Android-Mutual-SSL-Event-Receiver.xml b/features/mobile-plugins-feature/android-plugin-feature/org.wso2.carbon.device.mgt.mobile.android.feature/src/main/resources/apis/admin--Android-Mutual-SSL-Event-Receiver.xml index e39eb25e9..2d116a9ad 100644 --- a/features/mobile-plugins-feature/android-plugin-feature/org.wso2.carbon.device.mgt.mobile.android.feature/src/main/resources/apis/admin--Android-Mutual-SSL-Event-Receiver.xml +++ b/features/mobile-plugins-feature/android-plugin-feature/org.wso2.carbon.device.mgt.mobile.android.feature/src/main/resources/apis/admin--Android-Mutual-SSL-Event-Receiver.xml @@ -13,7 +13,6 @@ - @@ -29,7 +28,6 @@ - diff --git a/features/mobile-plugins-feature/android-plugin-feature/org.wso2.carbon.device.mgt.mobile.android.feature/src/main/resources/conf_templates/templates/repository/conf/datasources/android-datasources.xml.j2 b/features/mobile-plugins-feature/android-plugin-feature/org.wso2.carbon.device.mgt.mobile.android.feature/src/main/resources/conf_templates/templates/repository/conf/datasources/android-datasources.xml.j2 new file mode 100644 index 000000000..fd8ba5576 --- /dev/null +++ b/features/mobile-plugins-feature/android-plugin-feature/org.wso2.carbon.device.mgt.mobile.android.feature/src/main/resources/conf_templates/templates/repository/conf/datasources/android-datasources.xml.j2 @@ -0,0 +1,63 @@ + + + + + org.wso2.carbon.ndatasource.rdbms.RDBMSDataSourceReader + + + + + Android_DB + The datasource used as the Android Device Management database + + jdbc/MobileAndroidDM_DS + + + + {% if database.android is defined %} + {{database.android.url}} + {{database.android.username}} + {{database.android.password}} + {{database.android.driver}} + {{database.android.validationQuery}} + {% for property_name,property_value in database.android.pool_options.items() %} + <{{property_name}}>{{property_value}} + {% endfor %} + {% else %} + jdbc:h2:./repository/database/WSO2MobileAndroid_DB;DB_CLOSE_ON_EXIT=FALSE + wso2carbon + wso2carbon + org.h2.Driver + 50 + 60000 + true + SELECT 1 + 30000 + {% endif %} + + + + + + diff --git a/features/mobile-plugins-feature/android-plugin-feature/org.wso2.carbon.device.mgt.mobile.android.feature/src/main/resources/conf_templates/templates/repository/conf/mobile-config.xml.j2 b/features/mobile-plugins-feature/android-plugin-feature/org.wso2.carbon.device.mgt.mobile.android.feature/src/main/resources/conf_templates/templates/repository/conf/mobile-config.xml.j2 new file mode 100644 index 000000000..42a2e9fb5 --- /dev/null +++ b/features/mobile-plugins-feature/android-plugin-feature/org.wso2.carbon.device.mgt.mobile.android.feature/src/main/resources/conf_templates/templates/repository/conf/mobile-config.xml.j2 @@ -0,0 +1,71 @@ + + + + + + + + + {% if mobile_conf.datasource.android.name is defined %} + {{mobile_conf.datasource.android.name}} + {% else %} + jdbc/MobileAndroidDM_DS + {% endif %} + + + + + + + + + appmanager + admin + /devices + 1.0.0 + http://localhost:9763/test/app + http,https + + + enrol + admin + /enroll + 1.0.0 + http://localhost:9763/mdm-android-agent/enrollment + http,https + + + license + admin + /license + 1.0.0 + http://localhost:9763/mdm-android-agent/devices/license + http,https + + + operation + admin + /operation + 1.0.0 + http://localhost:9763/mdm-android-agent/operations + http,https + + + + diff --git a/features/mobile-plugins-feature/android-plugin-feature/org.wso2.carbon.device.mgt.mobile.android.feature/src/main/resources/datasources/android-datasources.xml b/features/mobile-plugins-feature/android-plugin-feature/org.wso2.carbon.device.mgt.mobile.android.feature/src/main/resources/datasources/android-datasources.xml index a0c8b0393..1b879009c 100644 --- a/features/mobile-plugins-feature/android-plugin-feature/org.wso2.carbon.device.mgt.mobile.android.feature/src/main/resources/datasources/android-datasources.xml +++ b/features/mobile-plugins-feature/android-plugin-feature/org.wso2.carbon.device.mgt.mobile.android.feature/src/main/resources/datasources/android-datasources.xml @@ -30,8 +30,7 @@ - jdbc:h2:repository/database/WSO2MobileAndroid_DB;DB_CLOSE_ON_EXIT=FALSE - + jdbc:h2:./repository/database/WSO2MobileAndroid_DB;DB_CLOSE_ON_EXIT=FALSE wso2carbon wso2carbon org.h2.Driver diff --git a/features/mobile-plugins-feature/android-plugin-feature/org.wso2.carbon.device.mgt.mobile.android.feature/src/main/resources/p2.inf b/features/mobile-plugins-feature/android-plugin-feature/org.wso2.carbon.device.mgt.mobile.android.feature/src/main/resources/p2.inf index e188ddf4e..989103e63 100644 --- a/features/mobile-plugins-feature/android-plugin-feature/org.wso2.carbon.device.mgt.mobile.android.feature/src/main/resources/p2.inf +++ b/features/mobile-plugins-feature/android-plugin-feature/org.wso2.carbon.device.mgt.mobile.android.feature/src/main/resources/p2.inf @@ -1,8 +1,8 @@ instructions.configure = \ org.eclipse.equinox.p2.touchpoint.natives.copy(source:${installFolder}/../features/org.wso2.carbon.device.mgt.mobile.android_${feature.version}/webapps/api#device-mgt#android#v1.0.war,target:${installFolder}/../../deployment/server/webapps/api#device-mgt#android#v1.0.war,overwrite:true);\ org.eclipse.equinox.p2.touchpoint.natives.copy(source:${installFolder}/../features/org.wso2.carbon.device.mgt.mobile.android_${feature.version}/jaggeryapps/devicemgt,target:${installFolder}/../../deployment/server/jaggeryapps/devicemgt,overwrite:true);\ -org.eclipse.equinox.p2.touchpoint.natives.copy(source:${installFolder}/../features/org.wso2.carbon.device.mgt.mobile.android_${feature.version}/datasources/,target:${installFolder}/../../conf/datasources/,overwrite:true);\ -org.eclipse.equinox.p2.touchpoint.natives.copy(source:${installFolder}/../features/org.wso2.carbon.device.mgt.mobile.android_${feature.version}/conf/mobile-config.xml,target:${installFolder}/../../conf/mobile-config.xml,overwrite:true);\ +org.eclipse.equinox.p2.touchpoint.natives.copy(source:${installFolder}/../features/org.wso2.carbon.device.mgt.mobile.android_${feature.version}/datasources/,target:${installFolder}/../../repository/conf/datasources/,overwrite:true);\ +org.eclipse.equinox.p2.touchpoint.natives.copy(source:${installFolder}/../features/org.wso2.carbon.device.mgt.mobile.android_${feature.version}/conf/mobile-config.xml,target:${installFolder}/../../repository/conf/mobile-config.xml,overwrite:true);\ org.eclipse.equinox.p2.touchpoint.natives.copy(source:${installFolder}/../features/org.wso2.carbon.device.mgt.mobile.android_${feature.version}/dbscripts/plugins/,target:${installFolder}/../../../dbscripts/cdm/plugins/android,overwrite:true);\ org.eclipse.equinox.p2.touchpoint.natives.mkdir(path:${installFolder}/../../database/);\ org.eclipse.equinox.p2.touchpoint.natives.copy(source:${installFolder}/../features/org.wso2.carbon.device.mgt.mobile.android_${feature.version}/database/,target:${installFolder}/../../database/,overwrite:true);\ @@ -12,10 +12,11 @@ org.eclipse.equinox.p2.touchpoint.natives.copy(source:${installFolder}/../featur org.eclipse.equinox.p2.touchpoint.natives.copy(source:${installFolder}/../features/org.wso2.carbon.device.mgt.mobile.android_${feature.version}/apis/admin--Android-Mutual-SSL-Configuration-Management.xml,target:${installFolder}/../../deployment/server/synapse-configs/default/api/admin--Android-Mutual-SSL-Configuration-Management.xml,overwrite:true);\ org.eclipse.equinox.p2.touchpoint.natives.copy(source:${installFolder}/../features/org.wso2.carbon.device.mgt.mobile.android_${feature.version}/apis/admin--Android-Mutual-SSL-Device-Management.xml,target:${installFolder}/../../deployment/server/synapse-configs/default/api/admin--Android-Mutual-SSL-Device-Management.xml,overwrite:true);\ org.eclipse.equinox.p2.touchpoint.natives.copy(source:${installFolder}/../features/org.wso2.carbon.device.mgt.mobile.android_${feature.version}/apis/admin--Android-Mutual-SSL-Event-Receiver.xml,target:${installFolder}/../../deployment/server/synapse-configs/default/api/admin--Android-Mutual-SSL-Event-Receiver.xml,overwrite:true);\ +org.eclipse.equinox.p2.touchpoint.natives.copy(source:${installFolder}/../features/org.wso2.carbon.device.mgt.mobile.android_${feature.version}/conf_templates/,target:${installFolder}/../../resources/conf/,overwrite:true);\ instructions.unconfigure = \ org.eclipse.equinox.p2.touchpoint.natives.remove(path:${installFolder}/../../deployment/server/webapps/mdm-android-agent.war);\ -org.eclipse.equinox.p2.touchpoint.natives.remove(path:${installFolder}/../../conf/datasources/android-datasources.xml);\ +org.eclipse.equinox.p2.touchpoint.natives.remove(path:${installFolder}/../../repository/conf/datasources/android-datasources.xml);\ org.eclipse.equinox.p2.touchpoint.natives.remove(path:${installFolder}/../../deployment/server/webapps/mdm-android-agent);\ org.eclipse.equinox.p2.touchpoint.natives.remove(path:${installFolder}/../../deployment/server/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.android.operation-bar);\ org.eclipse.equinox.p2.touchpoint.natives.remove(path:${installFolder}/../../deployment/server/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.android.device-view);\ diff --git a/pom.xml b/pom.xml index 2e7ab2715..1e172786a 100644 --- a/pom.xml +++ b/pom.xml @@ -36,12 +36,12 @@ components/extensions - + components/mobile-plugins - + features/mobile-plugins-feature features/extensions-feature