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 362289b2c..5f01bb319 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 @@ -18,10 +18,11 @@ */ package org.wso2.carbon.mdm.services.android.services.impl; +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.context.PrivilegedCarbonContext; import org.wso2.carbon.device.mgt.analytics.data.publisher.exception.DataPublisherConfigurationException; import org.wso2.carbon.mdm.services.android.bean.DeviceState; import org.wso2.carbon.mdm.services.android.bean.ErrorResponse; @@ -32,18 +33,27 @@ import org.wso2.carbon.mdm.services.android.exception.UnexpectedServerErrorExcep import org.wso2.carbon.mdm.services.android.services.EventReceiverService; import org.wso2.carbon.mdm.services.android.util.AndroidAPIUtils; import org.wso2.carbon.mdm.services.android.util.Message; -import org.wso2.carbon.utils.multitenancy.MultitenantConstants; import javax.validation.Valid; import javax.validation.constraints.Size; -import javax.ws.rs.*; +import javax.ws.rs.GET; +import javax.ws.rs.HeaderParam; +import javax.ws.rs.POST; +import javax.ws.rs.Path; +import javax.ws.rs.QueryParam; import javax.ws.rs.core.Response; import java.util.List; @Path("/events") public class EventReceiverServiceImpl implements EventReceiverService { - private static final String EVENT_STREAM_DEFINITION = "org.wso2.android.agent.Stream"; + private static final String EVENT_STREAM_DEFINITION = "org.wso2.iot.LocationStream"; private static final Log log = LogFactory.getLog(EventReceiverServiceImpl.class); + private Gson gson = new Gson(); + + private static final String LONGITUDE = "longitude"; + private static final String LATITUDE = "latitude"; + private static final String TIME_STAMP = "timeStamp"; + private static final String LOCATION_EVENT_TYPE = "location"; @POST @Path("/publish") @@ -52,10 +62,21 @@ public class EventReceiverServiceImpl implements EventReceiverService { if (log.isDebugEnabled()) { log.debug("Invoking Android device even logging."); } + 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()}; - - Object payload[] = {eventBeanWrapper.getPayload(), eventBeanWrapper.getType()}; + Object metaData[] = {eventBeanWrapper.getDeviceIdentifier(), eventType}; + String eventPayload = eventBeanWrapper.getPayload(); + JsonObject jsonObject = gson.fromJson(eventPayload, JsonObject.class); + Object payload[] = { + jsonObject.get(TIME_STAMP), + jsonObject.get(LONGITUDE), + jsonObject.get(LATITUDE) + }; try { if (AndroidAPIUtils.getEventPublisherService().publishEvent( EVENT_STREAM_DEFINITION, "1.0.0", metaData, new Object[0], payload)) {