From 1ffaad6fb79112d817ced756c207e19a82672af8 Mon Sep 17 00:00:00 2001 From: Arcane94 Date: Fri, 23 Feb 2018 22:02:36 +0530 Subject: [PATCH] rolling back some imports --- .../impl/GeoLocationBasedServiceImpl.java | 1 - .../GeoLocationProviderServiceImpl.java | 27 +++++++++++-------- 2 files changed, 16 insertions(+), 12 deletions(-) diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/GeoLocationBasedServiceImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/GeoLocationBasedServiceImpl.java index 4bee9d62a8..5c55096bbe 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/GeoLocationBasedServiceImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/GeoLocationBasedServiceImpl.java @@ -48,7 +48,6 @@ import org.wso2.carbon.device.mgt.jaxrs.util.DeviceMgtUtil; import org.wso2.carbon.user.api.UserStoreException; import org.wso2.carbon.utils.multitenancy.MultitenantUtils; -import javax.persistence.EntityExistsException; import javax.ws.rs.*; import javax.ws.rs.core.Response; import java.util.ArrayList; diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/geo/service/GeoLocationProviderServiceImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/geo/service/GeoLocationProviderServiceImpl.java index cf95db9b27..a5b293ec04 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/geo/service/GeoLocationProviderServiceImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/geo/service/GeoLocationProviderServiceImpl.java @@ -310,7 +310,7 @@ public class GeoLocationProviderServiceImpl implements GeoLocationProviderServic @Override public boolean createGeoAlert(Alert alert, String alertType) - throws GeoLocationBasedServiceException { + throws GeoLocationBasedServiceException,AlertAlreadyExist { return saveGeoAlert(alert, alertType, false); } @@ -322,12 +322,12 @@ public class GeoLocationProviderServiceImpl implements GeoLocationProviderServic @Override public boolean updateGeoAlert(Alert alert, String alertType) - throws GeoLocationBasedServiceException { + throws GeoLocationBasedServiceException,AlertAlreadyExist { return saveGeoAlert(alert, alertType, true); } public boolean saveGeoAlert(Alert alert, String alertType, boolean isUpdate) - throws GeoLocationBasedServiceException { + throws GeoLocationBasedServiceException,AlertAlreadyExist { Type type = new TypeToken>() { }.getType(); @@ -369,28 +369,33 @@ public class GeoLocationProviderServiceImpl implements GeoLocationProviderServic "Unrecognized execution plan type: " + alertType + " while creating geo alert"); } - //persist alert in registry - updateRegistry(getRegistryPath(alertType, alert.getQueryName()), content, - options); - //deploy alert into event processor EventProcessorAdminServiceStub eventprocessorStub = null; String action = (isUpdate ? "updating" : "creating"); try { + String existingPlanName = null; + String executionPlanName = getExecutionPlanName(alertType, alert.getQueryName()); eventprocessorStub = getEventProcessorAdminServiceStub(); String parsedTemplate = parseTemplateForGeoClusters(alertType, parseMap); String validationResponse = eventprocessorStub.validateExecutionPlan(parsedTemplate); if (validationResponse.equals("success")) { if (isUpdate) { - String executionPlanName = getExecutionPlanName(alertType, alert.getQueryName()); try { - String existingPlanName = eventprocessorStub.getActiveExecutionPlan(executionPlanName); - } catch (Exception e) { + existingPlanName = eventprocessorStub.getActiveExecutionPlan(executionPlanName); + } catch (AxisFault axisFault) { eventprocessorStub.deployExecutionPlan(parsedTemplate); } eventprocessorStub.editActiveExecutionPlan(parsedTemplate, executionPlanName); } else { - eventprocessorStub.deployExecutionPlan(parsedTemplate); + try { + existingPlanName = eventprocessorStub.getActiveExecutionPlan(executionPlanName); + if (existingPlanName.contains(executionPlanName)) { + throw new AlertAlreadyExist("Execution plan with this name already exists"); + } + } catch (AxisFault axisFault) { + updateRegistry(getRegistryPath(alertType, alert.getQueryName()), content,options); + eventprocessorStub.deployExecutionPlan(parsedTemplate); + } } } else { if (validationResponse.startsWith(