|
|
|
@ -55,6 +55,7 @@ import org.wso2.carbon.registry.api.Resource;
|
|
|
|
|
import javax.net.ssl.KeyManagerFactory;
|
|
|
|
|
import javax.net.ssl.SSLContext;
|
|
|
|
|
import javax.net.ssl.TrustManagerFactory;
|
|
|
|
|
import javax.persistence.EntityExistsException;
|
|
|
|
|
import java.io.FileInputStream;
|
|
|
|
|
import java.io.IOException;
|
|
|
|
|
import java.io.InputStream;
|
|
|
|
@ -303,7 +304,7 @@ public class GeoLocationProviderServiceImpl implements GeoLocationProviderServic
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public boolean createGeoAlert(Alert alert, DeviceIdentifier identifier, String alertType)
|
|
|
|
|
throws GeoLocationBasedServiceException, AlertAlreadyExistException {
|
|
|
|
|
throws GeoLocationBasedServiceException {
|
|
|
|
|
return saveGeoAlert(alert, identifier, alertType, false);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -315,7 +316,7 @@ public class GeoLocationProviderServiceImpl implements GeoLocationProviderServic
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public boolean updateGeoAlert(Alert alert, DeviceIdentifier identifier, String alertType)
|
|
|
|
|
throws GeoLocationBasedServiceException, AlertAlreadyExistException {
|
|
|
|
|
throws GeoLocationBasedServiceException {
|
|
|
|
|
return saveGeoAlert(alert, identifier, alertType, true);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -423,7 +424,7 @@ public class GeoLocationProviderServiceImpl implements GeoLocationProviderServic
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public boolean saveGeoAlert(Alert alert, DeviceIdentifier identifier, String alertType, boolean isUpdate)
|
|
|
|
|
throws GeoLocationBasedServiceException, AlertAlreadyExistException {
|
|
|
|
|
throws GeoLocationBasedServiceException {
|
|
|
|
|
|
|
|
|
|
Type type = new TypeToken<Map<String, String>>() {
|
|
|
|
|
}.getType();
|
|
|
|
@ -465,38 +466,23 @@ public class GeoLocationProviderServiceImpl implements GeoLocationProviderServic
|
|
|
|
|
"Unrecognized execution plan type: " + alertType + " while creating geo alert");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//persist alert in registry
|
|
|
|
|
updateRegistry(getRegistryPath(alertType, identifier, alert.getQueryName()), identifier, content,
|
|
|
|
|
options);
|
|
|
|
|
|
|
|
|
|
//deploy alert into event processor
|
|
|
|
|
EventProcessorAdminServiceStub eventprocessorStub = null;
|
|
|
|
|
String action = (isUpdate ? "updating" : "creating");
|
|
|
|
|
try {
|
|
|
|
|
ExecutionPlanConfigurationDto[] allActiveExecutionPlanConfigs = null;
|
|
|
|
|
String activeExecutionPlan = null;
|
|
|
|
|
String executionPlanName = getExecutionPlanName(alertType, alert.getQueryName(),
|
|
|
|
|
identifier.getId());
|
|
|
|
|
eventprocessorStub = getEventProcessorAdminServiceStub();
|
|
|
|
|
String parsedTemplate = parseTemplate(alertType, parseMap);
|
|
|
|
|
String validationResponse = eventprocessorStub.validateExecutionPlan(parsedTemplate);
|
|
|
|
|
if (validationResponse.equals("success")) {
|
|
|
|
|
allActiveExecutionPlanConfigs = eventprocessorStub.getAllActiveExecutionPlanConfigurations();
|
|
|
|
|
if (isUpdate) {
|
|
|
|
|
for (ExecutionPlanConfigurationDto activeExectionPlanConfig:allActiveExecutionPlanConfigs) {
|
|
|
|
|
activeExecutionPlan = activeExectionPlanConfig.getExecutionPlan();
|
|
|
|
|
if (activeExecutionPlan.contains(executionPlanName)) {
|
|
|
|
|
eventprocessorStub.editActiveExecutionPlan(parsedTemplate, executionPlanName);
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
eventprocessorStub.deployExecutionPlan(parsedTemplate);
|
|
|
|
|
String executionPlanName = getExecutionPlanName(alertType, alert.getQueryName(),
|
|
|
|
|
identifier.getId());
|
|
|
|
|
eventprocessorStub.editActiveExecutionPlan(parsedTemplate, executionPlanName);
|
|
|
|
|
} else {
|
|
|
|
|
for (ExecutionPlanConfigurationDto activeExectionPlanConfig:allActiveExecutionPlanConfigs) {
|
|
|
|
|
activeExecutionPlan = activeExectionPlanConfig.getExecutionPlan();
|
|
|
|
|
if (activeExecutionPlan.contains(executionPlanName)) {
|
|
|
|
|
throw new AlertAlreadyExistException("Execution plan already exists with name "
|
|
|
|
|
+ executionPlanName);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
updateRegistry(getRegistryPath(alertType, identifier, alert.getQueryName()), identifier, content,
|
|
|
|
|
options);
|
|
|
|
|
eventprocessorStub.deployExecutionPlan(parsedTemplate);
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
@ -592,8 +578,6 @@ public class GeoLocationProviderServiceImpl implements GeoLocationProviderServic
|
|
|
|
|
private String getExecutionPlanName(String alertType, String queryName, String deviceId) {
|
|
|
|
|
if ("Traffic".equals(alertType)) {
|
|
|
|
|
return "Geo-ExecutionPlan-Traffic_" + queryName + "_alert";
|
|
|
|
|
} else if ("Speed".equals(alertType)) {
|
|
|
|
|
return "Geo-ExecutionPlan-" + alertType + "---" + deviceId + "_alert";
|
|
|
|
|
} else {
|
|
|
|
|
return "Geo-ExecutionPlan-" + alertType + "_" + queryName + "---_" + deviceId + "_alert";
|
|
|
|
|
}
|
|
|
|
|