logic changes of the fix

merge-requests/1/head
Arcane94 7 years ago
parent c0024ce26f
commit 1716fc4500

@ -44,6 +44,7 @@ import org.wso2.carbon.device.mgt.common.geo.service.GeoLocationBasedServiceExce
import org.wso2.carbon.device.mgt.common.geo.service.AlertAlreadyExistException; import org.wso2.carbon.device.mgt.common.geo.service.AlertAlreadyExistException;
import org.wso2.carbon.device.mgt.core.internal.DeviceManagementDataHolder; import org.wso2.carbon.device.mgt.core.internal.DeviceManagementDataHolder;
import org.wso2.carbon.event.processor.stub.EventProcessorAdminServiceStub; import org.wso2.carbon.event.processor.stub.EventProcessorAdminServiceStub;
import org.wso2.carbon.event.processor.stub.types.ExecutionPlanConfigurationDto;
import org.wso2.carbon.identity.jwt.client.extension.JWTClient; import org.wso2.carbon.identity.jwt.client.extension.JWTClient;
import org.wso2.carbon.identity.jwt.client.extension.exception.JWTClientException; import org.wso2.carbon.identity.jwt.client.extension.exception.JWTClientException;
import org.wso2.carbon.identity.jwt.client.extension.service.JWTClientManagerService; import org.wso2.carbon.identity.jwt.client.extension.service.JWTClientManagerService;
@ -265,27 +266,35 @@ public class GeoLocationProviderServiceImpl implements GeoLocationProviderServic
EventProcessorAdminServiceStub eventprocessorStub = null; EventProcessorAdminServiceStub eventprocessorStub = null;
String action = (isUpdate ? "updating" : "creating"); String action = (isUpdate ? "updating" : "creating");
try { try {
String existingPlanName = null; ExecutionPlanConfigurationDto[] allActiveExecutionPlanConfigs = null;
String activeExecutionPlan = null;
String executionPlanName = getExecutionPlanName(alertType, alert.getQueryName(), String executionPlanName = getExecutionPlanName(alertType, alert.getQueryName(),
identifier.getId()); identifier.getId());
eventprocessorStub = getEventProcessorAdminServiceStub(); eventprocessorStub = getEventProcessorAdminServiceStub();
String parsedTemplate = parseTemplate(alertType, parseMap); String parsedTemplate = parseTemplate(alertType, parseMap);
String validationResponse = eventprocessorStub.validateExecutionPlan(parsedTemplate); String validationResponse = eventprocessorStub.validateExecutionPlan(parsedTemplate);
if (validationResponse.equals("success")) { if (validationResponse.equals("success")) {
allActiveExecutionPlanConfigs = eventprocessorStub.getAllActiveExecutionPlanConfigurations();
if (isUpdate) { if (isUpdate) {
eventprocessorStub.editActiveExecutionPlan(parsedTemplate, executionPlanName); for (ExecutionPlanConfigurationDto activeExectionPlanConfig:allActiveExecutionPlanConfigs) {
activeExecutionPlan = activeExectionPlanConfig.getExecutionPlan();
if (activeExecutionPlan.contains(executionPlanName)) {
eventprocessorStub.editActiveExecutionPlan(parsedTemplate, executionPlanName);
return true;
}
}
eventprocessorStub.deployExecutionPlan(parsedTemplate);
} else { } else {
try { for (ExecutionPlanConfigurationDto activeExectionPlanConfig:allActiveExecutionPlanConfigs) {
existingPlanName = eventprocessorStub.getActiveExecutionPlan(executionPlanName); activeExecutionPlan = activeExectionPlanConfig.getExecutionPlan();
if (existingPlanName.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);
} }
} catch (AxisFault axisFault) {
updateRegistry(getRegistryPath(alertType, identifier, alert.getQueryName()), identifier, content,
options);
eventprocessorStub.deployExecutionPlan(parsedTemplate);
} }
updateRegistry(getRegistryPath(alertType, identifier, alert.getQueryName()), identifier, content,
options);
eventprocessorStub.deployExecutionPlan(parsedTemplate);
} }
} else { } else {
if (validationResponse.startsWith( if (validationResponse.startsWith(
@ -352,6 +361,8 @@ public class GeoLocationProviderServiceImpl implements GeoLocationProviderServic
private String getExecutionPlanName(String alertType, String queryName, String deviceId) { private String getExecutionPlanName(String alertType, String queryName, String deviceId) {
if ("Traffic".equals(alertType)) { if ("Traffic".equals(alertType)) {
return "Geo-ExecutionPlan-Traffic_" + queryName + "_alert"; return "Geo-ExecutionPlan-Traffic_" + queryName + "_alert";
} else if ("Speed".equals(alertType)) {
return "Geo-ExecutionPlan-" + alertType + "---" + deviceId + "_alert";
} else { } else {
return "Geo-ExecutionPlan-" + alertType + "_" + queryName + "---_" + deviceId + "_alert"; return "Geo-ExecutionPlan-" + alertType + "_" + queryName + "---_" + deviceId + "_alert";
} }

@ -38,6 +38,7 @@ import org.wso2.carbon.device.mgt.core.common.TestDataHolder;
import org.wso2.carbon.device.mgt.core.internal.DeviceManagementDataHolder; import org.wso2.carbon.device.mgt.core.internal.DeviceManagementDataHolder;
import org.wso2.carbon.device.mgt.core.service.DeviceManagementProviderService; import org.wso2.carbon.device.mgt.core.service.DeviceManagementProviderService;
import org.wso2.carbon.event.processor.stub.EventProcessorAdminServiceStub; import org.wso2.carbon.event.processor.stub.EventProcessorAdminServiceStub;
import org.wso2.carbon.event.processor.stub.types.ExecutionPlanConfigurationDto;
import org.wso2.carbon.identity.jwt.client.extension.exception.JWTClientException; import org.wso2.carbon.identity.jwt.client.extension.exception.JWTClientException;
import org.wso2.carbon.utils.multitenancy.MultitenantConstants; import org.wso2.carbon.utils.multitenancy.MultitenantConstants;
@ -59,6 +60,7 @@ public class GeoLocationProviderServiceTest {
private EventProcessorAdminServiceStub mockEventProcessorAdminServiceStub; private EventProcessorAdminServiceStub mockEventProcessorAdminServiceStub;
private GeoLocationProviderServiceImpl geoLocationProviderServiceImpl; private GeoLocationProviderServiceImpl geoLocationProviderServiceImpl;
private ExecutionPlanConfigurationDto[] mockExecutionPlanConfigurationDto = new ExecutionPlanConfigurationDto[1];
@BeforeClass @BeforeClass
public void init() throws Exception { public void init() throws Exception {
@ -141,12 +143,14 @@ public class GeoLocationProviderServiceTest {
private void initMocks() throws JWTClientException, RemoteException { private void initMocks() throws JWTClientException, RemoteException {
mockEventProcessorAdminServiceStub = Mockito.mock(EventProcessorAdminServiceStub.class); mockEventProcessorAdminServiceStub = Mockito.mock(EventProcessorAdminServiceStub.class);
geoLocationProviderServiceImpl = Mockito.mock(GeoLocationProviderServiceImpl.class, Mockito.CALLS_REAL_METHODS); geoLocationProviderServiceImpl = Mockito.mock(GeoLocationProviderServiceImpl.class, Mockito.CALLS_REAL_METHODS);
mockExecutionPlanConfigurationDto[0] = Mockito.mock(ExecutionPlanConfigurationDto.class);
Mockito.doReturn(mockEventProcessorAdminServiceStub). Mockito.doReturn(mockEventProcessorAdminServiceStub).
when(geoLocationProviderServiceImpl).getEventProcessorAdminServiceStub(); when(geoLocationProviderServiceImpl).getEventProcessorAdminServiceStub();
Mockito.doReturn("success"). Mockito.doReturn("success").
when(mockEventProcessorAdminServiceStub).validateExecutionPlan(Mockito.anyString()); when(mockEventProcessorAdminServiceStub).validateExecutionPlan(Mockito.anyString());
Mockito.when(mockEventProcessorAdminServiceStub.getActiveExecutionPlan(Mockito.anyString())). Mockito.when(mockEventProcessorAdminServiceStub.getAllActiveExecutionPlanConfigurations()).
thenThrow(AxisFault.class); thenReturn(mockExecutionPlanConfigurationDto);
Mockito.when(mockExecutionPlanConfigurationDto[0].getExecutionPlan()).thenReturn("EXECUTION_PLAN");
} }
private DeviceIdentifier getDeviceIdentifier() { private DeviceIdentifier getDeviceIdentifier() {

Loading…
Cancel
Save