mirror of
https://repository.entgra.net/community/device-mgt-plugins.git
synced 2025-09-16 23:42:15 +00:00
Removed publishing into org.wso2.android.agent.Stream
This commit is contained in:
parent
870073eda2
commit
dcbf9f30b0
@ -18,10 +18,11 @@
|
|||||||
*/
|
*/
|
||||||
package org.wso2.carbon.mdm.services.android.services.impl;
|
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.Log;
|
||||||
import org.apache.commons.logging.LogFactory;
|
import org.apache.commons.logging.LogFactory;
|
||||||
import org.wso2.carbon.analytics.datasource.commons.exception.AnalyticsException;
|
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.device.mgt.analytics.data.publisher.exception.DataPublisherConfigurationException;
|
||||||
import org.wso2.carbon.mdm.services.android.bean.DeviceState;
|
import org.wso2.carbon.mdm.services.android.bean.DeviceState;
|
||||||
import org.wso2.carbon.mdm.services.android.bean.ErrorResponse;
|
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.services.EventReceiverService;
|
||||||
import org.wso2.carbon.mdm.services.android.util.AndroidAPIUtils;
|
import org.wso2.carbon.mdm.services.android.util.AndroidAPIUtils;
|
||||||
import org.wso2.carbon.mdm.services.android.util.Message;
|
import org.wso2.carbon.mdm.services.android.util.Message;
|
||||||
import org.wso2.carbon.utils.multitenancy.MultitenantConstants;
|
|
||||||
|
|
||||||
import javax.validation.Valid;
|
import javax.validation.Valid;
|
||||||
import javax.validation.constraints.Size;
|
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 javax.ws.rs.core.Response;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
@Path("/events")
|
@Path("/events")
|
||||||
public class EventReceiverServiceImpl implements EventReceiverService {
|
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 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
|
@POST
|
||||||
@Path("/publish")
|
@Path("/publish")
|
||||||
@ -52,10 +62,21 @@ public class EventReceiverServiceImpl implements EventReceiverService {
|
|||||||
if (log.isDebugEnabled()) {
|
if (log.isDebugEnabled()) {
|
||||||
log.debug("Invoking Android device even logging.");
|
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();
|
Message message = new Message();
|
||||||
Object metaData[] = {eventBeanWrapper.getDeviceIdentifier()};
|
Object metaData[] = {eventBeanWrapper.getDeviceIdentifier(), eventType};
|
||||||
|
String eventPayload = eventBeanWrapper.getPayload();
|
||||||
Object payload[] = {eventBeanWrapper.getPayload(), eventBeanWrapper.getType()};
|
JsonObject jsonObject = gson.fromJson(eventPayload, JsonObject.class);
|
||||||
|
Object payload[] = {
|
||||||
|
jsonObject.get(TIME_STAMP),
|
||||||
|
jsonObject.get(LONGITUDE),
|
||||||
|
jsonObject.get(LATITUDE)
|
||||||
|
};
|
||||||
try {
|
try {
|
||||||
if (AndroidAPIUtils.getEventPublisherService().publishEvent(
|
if (AndroidAPIUtils.getEventPublisherService().publishEvent(
|
||||||
EVENT_STREAM_DEFINITION, "1.0.0", metaData, new Object[0], payload)) {
|
EVENT_STREAM_DEFINITION, "1.0.0", metaData, new Object[0], payload)) {
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user