|
|
@ -44,11 +44,11 @@ import org.wso2.carbon.device.mgt.common.event.config.EventConfigurationExceptio
|
|
|
|
import org.wso2.carbon.device.mgt.common.event.config.EventConfigurationProviderService;
|
|
|
|
import org.wso2.carbon.device.mgt.common.event.config.EventConfigurationProviderService;
|
|
|
|
import org.wso2.carbon.device.mgt.common.exceptions.TransactionManagementException;
|
|
|
|
import org.wso2.carbon.device.mgt.common.exceptions.TransactionManagementException;
|
|
|
|
import org.wso2.carbon.device.mgt.common.geo.service.Alert;
|
|
|
|
import org.wso2.carbon.device.mgt.common.geo.service.Alert;
|
|
|
|
|
|
|
|
import org.wso2.carbon.device.mgt.common.geo.service.AlertAlreadyExistException;
|
|
|
|
import org.wso2.carbon.device.mgt.common.geo.service.GeoFence;
|
|
|
|
import org.wso2.carbon.device.mgt.common.geo.service.GeoFence;
|
|
|
|
import org.wso2.carbon.device.mgt.common.geo.service.GeoFenceEventMeta;
|
|
|
|
import org.wso2.carbon.device.mgt.common.geo.service.GeoFenceEventMeta;
|
|
|
|
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.GeoLocationBasedServiceException;
|
|
|
|
import org.wso2.carbon.device.mgt.common.geo.service.AlertAlreadyExistException;
|
|
|
|
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.geo.service.GeofenceData;
|
|
|
|
import org.wso2.carbon.device.mgt.core.cache.impl.GeoCacheManagerImpl;
|
|
|
|
import org.wso2.carbon.device.mgt.core.cache.impl.GeoCacheManagerImpl;
|
|
|
|
import org.wso2.carbon.device.mgt.core.dao.DeviceManagementDAOException;
|
|
|
|
import org.wso2.carbon.device.mgt.core.dao.DeviceManagementDAOException;
|
|
|
@ -85,11 +85,11 @@ import java.security.UnrecoverableKeyException;
|
|
|
|
import java.security.cert.CertificateException;
|
|
|
|
import java.security.cert.CertificateException;
|
|
|
|
import java.sql.SQLException;
|
|
|
|
import java.sql.SQLException;
|
|
|
|
import java.util.ArrayList;
|
|
|
|
import java.util.ArrayList;
|
|
|
|
|
|
|
|
import java.util.Collections;
|
|
|
|
import java.util.HashMap;
|
|
|
|
import java.util.HashMap;
|
|
|
|
import java.util.List;
|
|
|
|
import java.util.List;
|
|
|
|
import java.util.Map;
|
|
|
|
import java.util.Map;
|
|
|
|
import java.util.Properties;
|
|
|
|
import java.util.Properties;
|
|
|
|
import java.util.Collections;
|
|
|
|
|
|
|
|
import java.util.Set;
|
|
|
|
import java.util.Set;
|
|
|
|
|
|
|
|
|
|
|
|
import static org.wso2.carbon.device.mgt.common.DeviceManagementConstants.GeoServices.DAS_PORT;
|
|
|
|
import static org.wso2.carbon.device.mgt.common.DeviceManagementConstants.GeoServices.DAS_PORT;
|
|
|
@ -101,7 +101,7 @@ import static org.wso2.carbon.device.mgt.common.DeviceManagementConstants.GeoSer
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
public class GeoLocationProviderServiceImpl implements GeoLocationProviderService {
|
|
|
|
public class GeoLocationProviderServiceImpl implements GeoLocationProviderService {
|
|
|
|
|
|
|
|
|
|
|
|
private static Log log = LogFactory.getLog(GeoLocationProviderServiceImpl.class);
|
|
|
|
private static final Log log = LogFactory.getLog(GeoLocationProviderServiceImpl.class);
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* required soap header for authorization
|
|
|
|
* required soap header for authorization
|
|
|
@ -136,6 +136,18 @@ public class GeoLocationProviderServiceImpl implements GeoLocationProviderServic
|
|
|
|
this.geofenceDAO = DeviceManagementDAOFactory.getGeofenceDAO();
|
|
|
|
this.geofenceDAO = DeviceManagementDAOFactory.getGeofenceDAO();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public static JWTClientManagerService getJWTClientManagerService() {
|
|
|
|
|
|
|
|
JWTClientManagerService jwtClientManagerService;
|
|
|
|
|
|
|
|
PrivilegedCarbonContext ctx = PrivilegedCarbonContext.getThreadLocalCarbonContext();
|
|
|
|
|
|
|
|
jwtClientManagerService = (JWTClientManagerService) ctx.getOSGiService(JWTClientManagerService.class, null);
|
|
|
|
|
|
|
|
if (jwtClientManagerService == null) {
|
|
|
|
|
|
|
|
String msg = "jwtClientManagerServicehas not initialized.";
|
|
|
|
|
|
|
|
log.error(msg);
|
|
|
|
|
|
|
|
throw new IllegalStateException(msg);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return jwtClientManagerService;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public List<GeoFence> getWithinAlerts(DeviceIdentifier identifier, String owner) throws GeoLocationBasedServiceException {
|
|
|
|
public List<GeoFence> getWithinAlerts(DeviceIdentifier identifier, String owner) throws GeoLocationBasedServiceException {
|
|
|
|
|
|
|
|
|
|
|
@ -227,7 +239,7 @@ public class GeoLocationProviderServiceImpl implements GeoLocationProviderServic
|
|
|
|
return fences;
|
|
|
|
return fences;
|
|
|
|
} catch (RegistryException | IOException e) {
|
|
|
|
} catch (RegistryException | IOException e) {
|
|
|
|
throw new GeoLocationBasedServiceException(
|
|
|
|
throw new GeoLocationBasedServiceException(
|
|
|
|
"Error occurred while getting the geo alerts" , e);
|
|
|
|
"Error occurred while getting the geo alerts", e);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -334,7 +346,7 @@ public class GeoLocationProviderServiceImpl implements GeoLocationProviderServic
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public boolean createGeoAlert(Alert alert, String alertType)
|
|
|
|
public boolean createGeoAlert(Alert alert, String alertType)
|
|
|
|
throws GeoLocationBasedServiceException,AlertAlreadyExistException {
|
|
|
|
throws GeoLocationBasedServiceException, AlertAlreadyExistException {
|
|
|
|
return saveGeoAlert(alert, alertType, false);
|
|
|
|
return saveGeoAlert(alert, alertType, false);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -346,12 +358,12 @@ public class GeoLocationProviderServiceImpl implements GeoLocationProviderServic
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public boolean updateGeoAlert(Alert alert, String alertType)
|
|
|
|
public boolean updateGeoAlert(Alert alert, String alertType)
|
|
|
|
throws GeoLocationBasedServiceException,AlertAlreadyExistException {
|
|
|
|
throws GeoLocationBasedServiceException, AlertAlreadyExistException {
|
|
|
|
return saveGeoAlert(alert, alertType, true);
|
|
|
|
return saveGeoAlert(alert, alertType, true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private boolean saveGeoAlert(Alert alert, String alertType, boolean isUpdate)
|
|
|
|
private boolean saveGeoAlert(Alert alert, String alertType, boolean isUpdate)
|
|
|
|
throws GeoLocationBasedServiceException,AlertAlreadyExistException {
|
|
|
|
throws GeoLocationBasedServiceException, AlertAlreadyExistException {
|
|
|
|
|
|
|
|
|
|
|
|
Type type = new TypeToken<Map<String, String>>() {
|
|
|
|
Type type = new TypeToken<Map<String, String>>() {
|
|
|
|
}.getType();
|
|
|
|
}.getType();
|
|
|
@ -408,7 +420,7 @@ public class GeoLocationProviderServiceImpl implements GeoLocationProviderServic
|
|
|
|
if (validationResponse.equals("success")) {
|
|
|
|
if (validationResponse.equals("success")) {
|
|
|
|
allActiveExecutionPlanConfigs = eventprocessorStub.getAllActiveExecutionPlanConfigurations();
|
|
|
|
allActiveExecutionPlanConfigs = eventprocessorStub.getAllActiveExecutionPlanConfigurations();
|
|
|
|
if (isUpdate) {
|
|
|
|
if (isUpdate) {
|
|
|
|
for (ExecutionPlanConfigurationDto activeExectionPlanConfig:allActiveExecutionPlanConfigs) {
|
|
|
|
for (ExecutionPlanConfigurationDto activeExectionPlanConfig : allActiveExecutionPlanConfigs) {
|
|
|
|
activeExecutionPlan = activeExectionPlanConfig.getExecutionPlan();
|
|
|
|
activeExecutionPlan = activeExectionPlanConfig.getExecutionPlan();
|
|
|
|
if (activeExecutionPlan.contains(executionPlanName)) {
|
|
|
|
if (activeExecutionPlan.contains(executionPlanName)) {
|
|
|
|
eventprocessorStub.editActiveExecutionPlan(parsedTemplate, executionPlanName);
|
|
|
|
eventprocessorStub.editActiveExecutionPlan(parsedTemplate, executionPlanName);
|
|
|
@ -417,14 +429,14 @@ public class GeoLocationProviderServiceImpl implements GeoLocationProviderServic
|
|
|
|
}
|
|
|
|
}
|
|
|
|
eventprocessorStub.deployExecutionPlan(parsedTemplate);
|
|
|
|
eventprocessorStub.deployExecutionPlan(parsedTemplate);
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
for (ExecutionPlanConfigurationDto activeExectionPlanConfig:allActiveExecutionPlanConfigs) {
|
|
|
|
for (ExecutionPlanConfigurationDto activeExectionPlanConfig : allActiveExecutionPlanConfigs) {
|
|
|
|
activeExecutionPlan = activeExectionPlanConfig.getExecutionPlan();
|
|
|
|
activeExecutionPlan = activeExectionPlanConfig.getExecutionPlan();
|
|
|
|
if (activeExecutionPlan.contains(executionPlanName)) {
|
|
|
|
if (activeExecutionPlan.contains(executionPlanName)) {
|
|
|
|
throw new AlertAlreadyExistException("Execution plan already exists with name "
|
|
|
|
throw new AlertAlreadyExistException("Execution plan already exists with name "
|
|
|
|
+ executionPlanName);
|
|
|
|
+ executionPlanName);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
updateRegistry(getRegistryPath(alertType, alert.getQueryName()),content,options);
|
|
|
|
updateRegistry(getRegistryPath(alertType, alert.getQueryName()), content, options);
|
|
|
|
eventprocessorStub.deployExecutionPlan(parsedTemplate);
|
|
|
|
eventprocessorStub.deployExecutionPlan(parsedTemplate);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
@ -519,7 +531,7 @@ public class GeoLocationProviderServiceImpl implements GeoLocationProviderServic
|
|
|
|
if (validationResponse.equals("success")) {
|
|
|
|
if (validationResponse.equals("success")) {
|
|
|
|
allActiveExecutionPlanConfigs = eventprocessorStub.getAllActiveExecutionPlanConfigurations();
|
|
|
|
allActiveExecutionPlanConfigs = eventprocessorStub.getAllActiveExecutionPlanConfigurations();
|
|
|
|
if (isUpdate) {
|
|
|
|
if (isUpdate) {
|
|
|
|
for (ExecutionPlanConfigurationDto activeExectionPlanConfig:allActiveExecutionPlanConfigs) {
|
|
|
|
for (ExecutionPlanConfigurationDto activeExectionPlanConfig : allActiveExecutionPlanConfigs) {
|
|
|
|
activeExecutionPlan = activeExectionPlanConfig.getExecutionPlan();
|
|
|
|
activeExecutionPlan = activeExectionPlanConfig.getExecutionPlan();
|
|
|
|
if (activeExecutionPlan.contains(executionPlanName)) {
|
|
|
|
if (activeExecutionPlan.contains(executionPlanName)) {
|
|
|
|
eventprocessorStub.editActiveExecutionPlan(parsedTemplate, executionPlanName);
|
|
|
|
eventprocessorStub.editActiveExecutionPlan(parsedTemplate, executionPlanName);
|
|
|
@ -528,7 +540,7 @@ public class GeoLocationProviderServiceImpl implements GeoLocationProviderServic
|
|
|
|
}
|
|
|
|
}
|
|
|
|
eventprocessorStub.deployExecutionPlan(parsedTemplate);
|
|
|
|
eventprocessorStub.deployExecutionPlan(parsedTemplate);
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
for (ExecutionPlanConfigurationDto activeExectionPlanConfig:allActiveExecutionPlanConfigs) {
|
|
|
|
for (ExecutionPlanConfigurationDto activeExectionPlanConfig : allActiveExecutionPlanConfigs) {
|
|
|
|
activeExecutionPlan = activeExectionPlanConfig.getExecutionPlan();
|
|
|
|
activeExecutionPlan = activeExectionPlanConfig.getExecutionPlan();
|
|
|
|
if (activeExecutionPlan.contains(executionPlanName)) {
|
|
|
|
if (activeExecutionPlan.contains(executionPlanName)) {
|
|
|
|
throw new AlertAlreadyExistException("Execution plan already exists with name "
|
|
|
|
throw new AlertAlreadyExistException("Execution plan already exists with name "
|
|
|
@ -615,7 +627,7 @@ public class GeoLocationProviderServiceImpl implements GeoLocationProviderServic
|
|
|
|
"/" + queryName;
|
|
|
|
"/" + queryName;
|
|
|
|
} else if (GeoServices.ALERT_TYPE_SPEED.equals(alertType)) {
|
|
|
|
} else if (GeoServices.ALERT_TYPE_SPEED.equals(alertType)) {
|
|
|
|
path = GeoServices.REGISTRY_PATH_FOR_ALERTS + GeoServices.ALERT_TYPE_SPEED +
|
|
|
|
path = GeoServices.REGISTRY_PATH_FOR_ALERTS + GeoServices.ALERT_TYPE_SPEED +
|
|
|
|
"/" ;
|
|
|
|
"/";
|
|
|
|
} else if (GeoServices.ALERT_TYPE_PROXIMITY.equals(alertType)) {
|
|
|
|
} else if (GeoServices.ALERT_TYPE_PROXIMITY.equals(alertType)) {
|
|
|
|
path = GeoServices.REGISTRY_PATH_FOR_ALERTS + GeoServices.ALERT_TYPE_PROXIMITY +
|
|
|
|
path = GeoServices.REGISTRY_PATH_FOR_ALERTS + GeoServices.ALERT_TYPE_PROXIMITY +
|
|
|
|
"/" + queryName;
|
|
|
|
"/" + queryName;
|
|
|
@ -798,7 +810,7 @@ public class GeoLocationProviderServiceImpl implements GeoLocationProviderServic
|
|
|
|
InputStream inputStream = resource.getContentStream();
|
|
|
|
InputStream inputStream = resource.getContentStream();
|
|
|
|
StringWriter writer = new StringWriter();
|
|
|
|
StringWriter writer = new StringWriter();
|
|
|
|
IOUtils.copy(inputStream, writer, "UTF-8");
|
|
|
|
IOUtils.copy(inputStream, writer, "UTF-8");
|
|
|
|
return "{'speedLimit':" + writer.toString() + "}";
|
|
|
|
return "{'speedLimit':" + writer + "}";
|
|
|
|
} catch (RegistryException | IOException e) {
|
|
|
|
} catch (RegistryException | IOException e) {
|
|
|
|
return "{'content': false}";
|
|
|
|
return "{'content': false}";
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -816,7 +828,7 @@ public class GeoLocationProviderServiceImpl implements GeoLocationProviderServic
|
|
|
|
InputStream inputStream = resource.getContentStream();
|
|
|
|
InputStream inputStream = resource.getContentStream();
|
|
|
|
StringWriter writer = new StringWriter();
|
|
|
|
StringWriter writer = new StringWriter();
|
|
|
|
IOUtils.copy(inputStream, writer, "UTF-8");
|
|
|
|
IOUtils.copy(inputStream, writer, "UTF-8");
|
|
|
|
return "{'speedLimit':" + writer.toString() + "}";
|
|
|
|
return "{'speedLimit':" + writer + "}";
|
|
|
|
} catch (RegistryException | IOException e) {
|
|
|
|
} catch (RegistryException | IOException e) {
|
|
|
|
return "{'content': false}";
|
|
|
|
return "{'content': false}";
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -868,7 +880,6 @@ public class GeoLocationProviderServiceImpl implements GeoLocationProviderServic
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public List<GeoFence> getStationaryAlerts(DeviceIdentifier identifier, String owner) throws GeoLocationBasedServiceException {
|
|
|
|
public List<GeoFence> getStationaryAlerts(DeviceIdentifier identifier, String owner) throws GeoLocationBasedServiceException {
|
|
|
|
|
|
|
|
|
|
|
@ -1243,18 +1254,6 @@ public class GeoLocationProviderServiceImpl implements GeoLocationProviderServic
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public static JWTClientManagerService getJWTClientManagerService() {
|
|
|
|
|
|
|
|
JWTClientManagerService jwtClientManagerService;
|
|
|
|
|
|
|
|
PrivilegedCarbonContext ctx = PrivilegedCarbonContext.getThreadLocalCarbonContext();
|
|
|
|
|
|
|
|
jwtClientManagerService = (JWTClientManagerService) ctx.getOSGiService(JWTClientManagerService.class, null);
|
|
|
|
|
|
|
|
if (jwtClientManagerService == null) {
|
|
|
|
|
|
|
|
String msg = "jwtClientManagerServicehas not initialized.";
|
|
|
|
|
|
|
|
log.error(msg);
|
|
|
|
|
|
|
|
throw new IllegalStateException(msg);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return jwtClientManagerService;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public boolean createGeofence(GeofenceData geofenceData) throws GeoLocationBasedServiceException, EventConfigurationException {
|
|
|
|
public boolean createGeofence(GeofenceData geofenceData) throws GeoLocationBasedServiceException, EventConfigurationException {
|
|
|
|
int tenantId;
|
|
|
|
int tenantId;
|
|
|
@ -1333,6 +1332,7 @@ public class GeoLocationProviderServiceImpl implements GeoLocationProviderServic
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* Set source of the event to GEOFENCE
|
|
|
|
* Set source of the event to GEOFENCE
|
|
|
|
|
|
|
|
*
|
|
|
|
* @param eventConfig event list to be set event source
|
|
|
|
* @param eventConfig event list to be set event source
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
private void setEventSource(List<EventConfig> eventConfig) {
|
|
|
|
private void setEventSource(List<EventConfig> eventConfig) {
|
|
|
@ -1365,7 +1365,7 @@ public class GeoLocationProviderServiceImpl implements GeoLocationProviderServic
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return geofence;
|
|
|
|
return geofence;
|
|
|
|
} catch (DeviceManagementDAOException e) {
|
|
|
|
} catch (DeviceManagementDAOException e) {
|
|
|
|
String msg = "Error occurred while retrieving Geofence data with ID "+fenceId;
|
|
|
|
String msg = "Error occurred while retrieving Geofence data with ID " + fenceId;
|
|
|
|
log.error(msg, e);
|
|
|
|
log.error(msg, e);
|
|
|
|
throw new GeoLocationBasedServiceException(msg, e);
|
|
|
|
throw new GeoLocationBasedServiceException(msg, e);
|
|
|
|
} catch (SQLException e) {
|
|
|
|
} catch (SQLException e) {
|
|
|
@ -1747,6 +1747,7 @@ public class GeoLocationProviderServiceImpl implements GeoLocationProviderServic
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* Delete events of geofence
|
|
|
|
* Delete events of geofence
|
|
|
|
|
|
|
|
*
|
|
|
|
* @param geofenceData geofence mapped with deleting events
|
|
|
|
* @param geofenceData geofence mapped with deleting events
|
|
|
|
* @param eventList events to be deleted
|
|
|
|
* @param eventList events to be deleted
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|