forked from community/device-mgt-core
parent
a401c9d91d
commit
75b619d5f9
@ -0,0 +1,21 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2020, Entgra (Pvt) Ltd. (http://www.entgra.io) All Rights Reserved.
|
||||||
|
*
|
||||||
|
* Entgra (Pvt) Ltd. 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.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package org.wso2.carbon.device.mgt.common.event.config;
|
||||||
|
|
||||||
|
public interface EventMetaData {}
|
@ -0,0 +1,69 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2020, Entgra (Pvt) Ltd. (http://www.entgra.io) All Rights Reserved.
|
||||||
|
*
|
||||||
|
* Entgra (Pvt) Ltd. 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.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package org.wso2.carbon.device.mgt.common.event.config;
|
||||||
|
|
||||||
|
import com.google.gson.Gson;
|
||||||
|
import com.google.gson.JsonArray;
|
||||||
|
import com.google.gson.JsonObject;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public class EventOperation {
|
||||||
|
private String eventSource;
|
||||||
|
private EventMetaData eventDefinition;
|
||||||
|
private String eventTriggers;
|
||||||
|
|
||||||
|
public String getEventSource() {
|
||||||
|
return eventSource;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setEventSource(String eventSource) {
|
||||||
|
this.eventSource = eventSource;
|
||||||
|
}
|
||||||
|
|
||||||
|
public EventMetaData getEventDefinition() {
|
||||||
|
return eventDefinition;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setEventDefinition(EventMetaData eventDefinition) {
|
||||||
|
this.eventDefinition = eventDefinition;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getEventTriggers() {
|
||||||
|
return eventTriggers;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setEventTriggers(List<EventConfig> eventList) {
|
||||||
|
JsonArray eventTriggers = new JsonArray();
|
||||||
|
JsonObject eventTrigger;
|
||||||
|
for (EventConfig eventConfig : eventList) {
|
||||||
|
eventTrigger = new JsonObject();
|
||||||
|
eventTrigger.addProperty("eventId", eventConfig.getEventId());
|
||||||
|
eventTrigger.addProperty("eventLogic", eventConfig.getEventLogic());
|
||||||
|
eventTrigger.addProperty("actions", eventConfig.getActions());
|
||||||
|
eventTriggers.add(eventTrigger);
|
||||||
|
}
|
||||||
|
this.eventTriggers = eventTriggers.toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
public String toJSON() {
|
||||||
|
Gson gson = new Gson();
|
||||||
|
return gson.toJson(this);
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,110 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2020, Entgra (Pvt) Ltd. (http://www.entgra.io) All Rights Reserved.
|
||||||
|
*
|
||||||
|
* Entgra (Pvt) Ltd. 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.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package org.wso2.carbon.device.mgt.common.geo.service;
|
||||||
|
|
||||||
|
import org.wso2.carbon.device.mgt.common.event.config.EventMetaData;
|
||||||
|
|
||||||
|
public class GeoFenceEventMeta implements EventMetaData {
|
||||||
|
private int id;
|
||||||
|
private String fenceName;
|
||||||
|
private String description;
|
||||||
|
private double latitude;
|
||||||
|
private double longitude;
|
||||||
|
private float radius;
|
||||||
|
private String geoJson;
|
||||||
|
private String fenceShape;
|
||||||
|
|
||||||
|
public GeoFenceEventMeta() {
|
||||||
|
}
|
||||||
|
|
||||||
|
public GeoFenceEventMeta(GeofenceData geofenceData) {
|
||||||
|
this.id = geofenceData.getId();
|
||||||
|
this.fenceName = geofenceData.getFenceName();
|
||||||
|
this.description = geofenceData.getDescription();
|
||||||
|
this.latitude = geofenceData.getLatitude();
|
||||||
|
this.longitude = geofenceData.getLongitude();
|
||||||
|
this.radius = geofenceData.getRadius();
|
||||||
|
this.geoJson = geofenceData.getGeoJson();
|
||||||
|
this.fenceShape = geofenceData.getFenceShape();
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getId() {
|
||||||
|
return id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setId(int id) {
|
||||||
|
this.id = id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getFenceName() {
|
||||||
|
return fenceName;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setFenceName(String fenceName) {
|
||||||
|
this.fenceName = fenceName;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getDescription() {
|
||||||
|
return description;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setDescription(String description) {
|
||||||
|
this.description = description;
|
||||||
|
}
|
||||||
|
|
||||||
|
public double getLatitude() {
|
||||||
|
return latitude;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setLatitude(double latitude) {
|
||||||
|
this.latitude = latitude;
|
||||||
|
}
|
||||||
|
|
||||||
|
public double getLongitude() {
|
||||||
|
return longitude;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setLongitude(double longitude) {
|
||||||
|
this.longitude = longitude;
|
||||||
|
}
|
||||||
|
|
||||||
|
public float getRadius() {
|
||||||
|
return radius;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setRadius(float radius) {
|
||||||
|
this.radius = radius;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getGeoJson() {
|
||||||
|
return geoJson;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setGeoJson(String geoJson) {
|
||||||
|
this.geoJson = geoJson;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getFenceShape() {
|
||||||
|
return fenceShape;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setFenceShape(String fenceShape) {
|
||||||
|
this.fenceShape = fenceShape;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,120 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2020, Entgra (Pvt) Ltd. (http://www.entgra.io) All Rights Reserved.
|
||||||
|
*
|
||||||
|
* Entgra (Pvt) Ltd. 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.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package org.wso2.carbon.device.mgt.core.event.config;
|
||||||
|
|
||||||
|
import org.apache.commons.logging.Log;
|
||||||
|
import org.apache.commons.logging.LogFactory;
|
||||||
|
import org.wso2.carbon.device.mgt.common.DeviceIdentifier;
|
||||||
|
import org.wso2.carbon.device.mgt.common.DeviceManagementConstants;
|
||||||
|
import org.wso2.carbon.device.mgt.common.event.config.EventConfigurationException;
|
||||||
|
import org.wso2.carbon.device.mgt.common.event.config.EventConfigurationProviderService;
|
||||||
|
import org.wso2.carbon.device.mgt.common.event.config.EventOperation;
|
||||||
|
import org.wso2.carbon.device.mgt.common.exceptions.InvalidDeviceException;
|
||||||
|
import org.wso2.carbon.device.mgt.common.geo.service.GeoFenceEventMeta;
|
||||||
|
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.geo.service.GeofenceData;
|
||||||
|
import org.wso2.carbon.device.mgt.common.operation.mgt.Operation;
|
||||||
|
import org.wso2.carbon.device.mgt.common.operation.mgt.OperationManagementException;
|
||||||
|
import org.wso2.carbon.device.mgt.core.internal.DeviceManagementDataHolder;
|
||||||
|
import org.wso2.carbon.device.mgt.core.operation.mgt.OperationMgtConstants;
|
||||||
|
import org.wso2.carbon.device.mgt.core.operation.mgt.ProfileOperation;
|
||||||
|
import org.wso2.carbon.device.mgt.core.service.DeviceManagementProviderService;
|
||||||
|
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public class DeviceEventOperationExecutor implements Runnable {
|
||||||
|
private static final Log log = LogFactory.getLog(DeviceEventOperationExecutor.class);
|
||||||
|
|
||||||
|
private final int groupId;
|
||||||
|
private final List<DeviceIdentifier> deviceIdentifiers;
|
||||||
|
private final int tenantId;
|
||||||
|
|
||||||
|
public DeviceEventOperationExecutor(int groupId, List<DeviceIdentifier> deviceIdentifiers, int tenantId) {
|
||||||
|
this.groupId = groupId;
|
||||||
|
this.deviceIdentifiers = deviceIdentifiers;
|
||||||
|
this.tenantId = tenantId;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
log.info("Starting event operation creation task for devices in group " + groupId + " tenant " + tenantId);
|
||||||
|
if (log.isDebugEnabled()) {
|
||||||
|
log.debug("Event creation operation started for devices with IDs " + Arrays.toString(deviceIdentifiers.toArray()));
|
||||||
|
}
|
||||||
|
ProfileOperation operation = new ProfileOperation();
|
||||||
|
operation.setCode(OperationMgtConstants.OperationCodes.EVENT_CONFIG);
|
||||||
|
operation.setType(Operation.Type.PROFILE);
|
||||||
|
EventConfigurationProviderService eventConfigurationService = DeviceManagementDataHolder.getInstance().getEventConfigurationService();
|
||||||
|
try {
|
||||||
|
List<String> eventSources = eventConfigurationService.getEventsSourcesOfGroup(groupId, tenantId);
|
||||||
|
for (String eventSource : eventSources) {
|
||||||
|
if (eventSource.equalsIgnoreCase(DeviceManagementConstants.EventServices.GEOFENCE)) {
|
||||||
|
setGeoFenceOperationContent(operation);
|
||||||
|
} //extend with another cases to handle other types of events
|
||||||
|
}
|
||||||
|
} catch (EventConfigurationException e) {
|
||||||
|
log.error("Failed to retrieve event sources of group " + groupId, e);
|
||||||
|
}
|
||||||
|
DeviceManagementProviderService deviceManagementProvider = DeviceManagementDataHolder
|
||||||
|
.getInstance().getDeviceManagementProvider();
|
||||||
|
try {
|
||||||
|
if (!deviceIdentifiers.isEmpty()) {
|
||||||
|
if (log.isDebugEnabled()) {
|
||||||
|
log.debug("Creating event operations stared");
|
||||||
|
}
|
||||||
|
deviceManagementProvider.addOperation("android", operation, deviceIdentifiers); //TODO introduce a proper mechanism
|
||||||
|
} else {
|
||||||
|
log.info("Device identifiers are empty, Hence ignoring adding event operation");
|
||||||
|
}
|
||||||
|
} catch (OperationManagementException e) {
|
||||||
|
log.error("Creating event operation failed with error ", e);
|
||||||
|
} catch (InvalidDeviceException e) {
|
||||||
|
log.error("Creating event operation failed.\n" +
|
||||||
|
"Could not found device/devices for the defined device identifiers.", e);
|
||||||
|
}
|
||||||
|
log.info("Event operation creation succeeded");
|
||||||
|
}
|
||||||
|
|
||||||
|
private void setGeoFenceOperationContent(ProfileOperation operation) {
|
||||||
|
log.info("Geo fence events found attached with group " + groupId + ", Started retrieving geo fences");
|
||||||
|
GeoLocationProviderService geoLocationProviderService = DeviceManagementDataHolder.getInstance().getGeoLocationProviderService();
|
||||||
|
try {
|
||||||
|
List<GeofenceData> geoFencesOfGroup = geoLocationProviderService.getGeoFencesOfGroup(groupId, tenantId, true);
|
||||||
|
if (log.isDebugEnabled()) {
|
||||||
|
log.debug("Retrieved " + geoFencesOfGroup.size() + " geo fences defined for the group " + groupId);
|
||||||
|
}
|
||||||
|
for (GeofenceData geofenceData : geoFencesOfGroup) {
|
||||||
|
GeoFenceEventMeta geoFenceEventMeta = new GeoFenceEventMeta(geofenceData);
|
||||||
|
EventOperation eventOperation = new EventOperation();
|
||||||
|
eventOperation.setEventDefinition(geoFenceEventMeta);
|
||||||
|
eventOperation.setEventSource(DeviceManagementConstants.EventServices.GEOFENCE);
|
||||||
|
eventOperation.setEventTriggers(geofenceData.getEventConfig());
|
||||||
|
if (operation.getPayLoad() != null) {
|
||||||
|
operation.setPayLoad(operation.getPayLoad().toString().concat(eventOperation.toJSON()));
|
||||||
|
} else {
|
||||||
|
operation.setPayLoad(eventOperation.toJSON());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (GeoLocationBasedServiceException e) {
|
||||||
|
log.error("Failed to retrieve geo fences for group " + groupId);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,153 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2020, Entgra (Pvt) Ltd. (http://www.entgra.io) All Rights Reserved.
|
||||||
|
*
|
||||||
|
* Entgra (Pvt) Ltd. 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.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package org.wso2.carbon.device.mgt.core.event.config;
|
||||||
|
|
||||||
|
import org.apache.commons.logging.Log;
|
||||||
|
import org.apache.commons.logging.LogFactory;
|
||||||
|
import org.wso2.carbon.context.PrivilegedCarbonContext;
|
||||||
|
import org.wso2.carbon.device.mgt.common.Device;
|
||||||
|
import org.wso2.carbon.device.mgt.common.DeviceIdentifier;
|
||||||
|
import org.wso2.carbon.device.mgt.common.DeviceManagementConstants;
|
||||||
|
import org.wso2.carbon.device.mgt.common.event.config.EventConfig;
|
||||||
|
import org.wso2.carbon.device.mgt.common.event.config.EventMetaData;
|
||||||
|
import org.wso2.carbon.device.mgt.common.event.config.EventOperation;
|
||||||
|
import org.wso2.carbon.device.mgt.common.exceptions.InvalidDeviceException;
|
||||||
|
import org.wso2.carbon.device.mgt.common.geo.service.GeoFenceEventMeta;
|
||||||
|
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.DeviceGroup;
|
||||||
|
import org.wso2.carbon.device.mgt.common.group.mgt.GroupManagementException;
|
||||||
|
import org.wso2.carbon.device.mgt.common.operation.mgt.Operation;
|
||||||
|
import org.wso2.carbon.device.mgt.common.operation.mgt.OperationManagementException;
|
||||||
|
import org.wso2.carbon.device.mgt.core.internal.DeviceManagementDataHolder;
|
||||||
|
import org.wso2.carbon.device.mgt.core.operation.mgt.OperationMgtConstants;
|
||||||
|
import org.wso2.carbon.device.mgt.core.operation.mgt.ProfileOperation;
|
||||||
|
import org.wso2.carbon.device.mgt.core.service.DeviceManagementProviderService;
|
||||||
|
import org.wso2.carbon.device.mgt.core.service.GroupManagementProviderService;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.HashSet;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
|
public class GroupEventOperationExecutor implements Runnable {
|
||||||
|
private static final Log log = LogFactory.getLog(GroupEventOperationExecutor.class);
|
||||||
|
|
||||||
|
private final List<Integer> groupIds;
|
||||||
|
private final String eventSource;
|
||||||
|
private final EventMetaData eventMetaData;
|
||||||
|
private final int tenantId;
|
||||||
|
|
||||||
|
public GroupEventOperationExecutor(EventMetaData eventMetaData, List<Integer> groupIds, int tenantId, String eventSource) {
|
||||||
|
this.eventMetaData = eventMetaData;
|
||||||
|
this.groupIds = groupIds;
|
||||||
|
this.tenantId = tenantId;
|
||||||
|
this.eventSource = eventSource;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
log.info("Starting event operation creation task for event " + eventSource + " tenant " + tenantId);
|
||||||
|
if (log.isDebugEnabled()) {
|
||||||
|
log.debug("Event creation operation started for groups with IDs " + Arrays.toString(groupIds.toArray()));
|
||||||
|
}
|
||||||
|
ProfileOperation operation = new ProfileOperation();
|
||||||
|
operation.setCode(OperationMgtConstants.OperationCodes.EVENT_CONFIG);
|
||||||
|
operation.setType(Operation.Type.PROFILE);
|
||||||
|
if (eventSource.equalsIgnoreCase(DeviceManagementConstants.EventServices.GEOFENCE)) {
|
||||||
|
createGeoFenceOperation(operation);
|
||||||
|
} //extend with another cases to handle other types of events
|
||||||
|
|
||||||
|
if (log.isDebugEnabled()) {
|
||||||
|
log.debug("Starting tenant flow for tenant id " + tenantId);
|
||||||
|
}
|
||||||
|
PrivilegedCarbonContext.startTenantFlow();
|
||||||
|
PrivilegedCarbonContext.getThreadLocalCarbonContext().setTenantId(tenantId, true);
|
||||||
|
GroupManagementProviderService groupManagementService = DeviceManagementDataHolder
|
||||||
|
.getInstance().getGroupManagementProviderService();
|
||||||
|
Set<Device> devices = new HashSet<>();
|
||||||
|
for (Integer groupId : groupIds) {
|
||||||
|
DeviceGroup group;
|
||||||
|
try {
|
||||||
|
group = groupManagementService.getGroup(groupId, false);
|
||||||
|
} catch (GroupManagementException e) {
|
||||||
|
log.error("Failed to retrieve group with group ID " + groupId, e);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
if (group != null) {
|
||||||
|
List<Device> allDevicesOfGroup = groupManagementService.getAllDevicesOfGroup(group.getName(), false);
|
||||||
|
if (allDevicesOfGroup == null || allDevicesOfGroup.isEmpty()) {
|
||||||
|
log.info("No devices found in group " + group.getName());
|
||||||
|
} else {
|
||||||
|
devices.addAll(allDevicesOfGroup);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (GroupManagementException e) {
|
||||||
|
log.error("Failed to retrieve devices of group with ID " + groupId + " and name " + group.getName(), e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
List<DeviceIdentifier> deviceIdentifiers = new ArrayList<>();
|
||||||
|
for (Device device : devices) {
|
||||||
|
if (device.getType().equalsIgnoreCase("android")) { //TODO introduce a proper mechanism for event handling for each device types
|
||||||
|
deviceIdentifiers.add(new DeviceIdentifier(device.getDeviceIdentifier(), device.getType()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
DeviceManagementProviderService deviceManagementProvider = DeviceManagementDataHolder
|
||||||
|
.getInstance().getDeviceManagementProvider();
|
||||||
|
try {
|
||||||
|
if (!deviceIdentifiers.isEmpty()) {
|
||||||
|
if (log.isDebugEnabled()) {
|
||||||
|
log.debug("Creating event operations stared for devices" + Arrays.toString(deviceIdentifiers.toArray()));
|
||||||
|
}
|
||||||
|
deviceManagementProvider.addOperation("android", operation, deviceIdentifiers); //TODO introduce a proper mechanism
|
||||||
|
} else {
|
||||||
|
log.info("Device identifiers are empty, Hence ignoring adding event operation");
|
||||||
|
}
|
||||||
|
} catch (OperationManagementException e) {
|
||||||
|
log.error("Creating event operation failed with error ", e);
|
||||||
|
} catch (InvalidDeviceException e) {
|
||||||
|
log.error("Creating event operation failed.\n" +
|
||||||
|
"Could not found device/devices for the defined device identifiers.", e);
|
||||||
|
}
|
||||||
|
log.info("Event operation creation succeeded");
|
||||||
|
}
|
||||||
|
|
||||||
|
private void createGeoFenceOperation(ProfileOperation operation) {
|
||||||
|
GeoFenceEventMeta geoFenceMeta = (GeoFenceEventMeta) eventMetaData;
|
||||||
|
try {
|
||||||
|
GeoLocationProviderService geoLocationProviderService = DeviceManagementDataHolder
|
||||||
|
.getInstance().getGeoLocationProviderService();
|
||||||
|
List<EventConfig> eventConfigList = geoLocationProviderService.getEventsOfGeoFence(geoFenceMeta.getId());
|
||||||
|
if (log.isDebugEnabled()) {
|
||||||
|
log.debug("Retrieved event records of Geo Fence " + geoFenceMeta.getId() +
|
||||||
|
". events " + Arrays.toString(eventConfigList.toArray()));
|
||||||
|
}
|
||||||
|
EventOperation eventOperation = new EventOperation();
|
||||||
|
eventOperation.setEventDefinition(eventMetaData);
|
||||||
|
eventOperation.setEventSource(eventSource);
|
||||||
|
eventOperation.setEventTriggers(eventConfigList);
|
||||||
|
operation.setPayLoad(eventOperation.toJSON());
|
||||||
|
} catch (GeoLocationBasedServiceException e) {
|
||||||
|
log.error("Failed to retrieve event data of Geo fence " + geoFenceMeta.getId()
|
||||||
|
+ " : " + geoFenceMeta.getFenceName(), e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,41 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2020, Entgra (Pvt) Ltd. (http://www.entgra.io) All Rights Reserved.
|
||||||
|
*
|
||||||
|
* Entgra (Pvt) Ltd. 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.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package org.wso2.carbon.device.mgt.core.geo.task;
|
||||||
|
|
||||||
|
import org.wso2.carbon.device.mgt.common.DeviceIdentifier;
|
||||||
|
import org.wso2.carbon.device.mgt.common.DeviceManagementConstants;
|
||||||
|
import org.wso2.carbon.device.mgt.common.geo.service.GeoFenceEventMeta;
|
||||||
|
import org.wso2.carbon.device.mgt.common.geo.service.GeofenceData;
|
||||||
|
import org.wso2.carbon.device.mgt.core.event.config.DeviceEventOperationExecutor;
|
||||||
|
import org.wso2.carbon.device.mgt.core.event.config.GroupEventOperationExecutor;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public class GeoFenceEventOperationManager {
|
||||||
|
public GroupEventOperationExecutor getGroupEventOperationExecutor(GeofenceData geofenceData, int tenantId) {
|
||||||
|
GeoFenceEventMeta geoFenceEventMeta = new GeoFenceEventMeta(geofenceData);
|
||||||
|
return new GroupEventOperationExecutor(geoFenceEventMeta, geofenceData.getGroupIds(),
|
||||||
|
tenantId, DeviceManagementConstants.EventServices.GEOFENCE);
|
||||||
|
}
|
||||||
|
|
||||||
|
public DeviceEventOperationExecutor getDeviceEventOperationExecutor(int groupId, List<DeviceIdentifier> deviceIdentifiers,
|
||||||
|
int tenantId) {
|
||||||
|
return new DeviceEventOperationExecutor(groupId, deviceIdentifiers, tenantId);
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in new issue