← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 22255: Minor change in GatewayAdminService

 

------------------------------------------------------------
revno: 22255
committer: Zubair Asghar<zubair@xxxxxxxxx>
branch nick: dhis2
timestamp: Fri 2016-03-11 18:04:06 +0100
message:
  Minor change in GatewayAdminService
modified:
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/sms/config/GatewayAdministratonService.java
  dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/sms/config/DefaultGatewayAdministrationService.java
  dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/sms/SmsGatewayController.java


--
lp:dhis2
https://code.launchpad.net/~dhis2-devs-core/dhis2/trunk

Your team DHIS 2 developers is subscribed to branch lp:dhis2.
To unsubscribe from this branch go to https://code.launchpad.net/~dhis2-devs-core/dhis2/trunk/+edit-subscription
=== modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/sms/config/GatewayAdministratonService.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/sms/config/GatewayAdministratonService.java	2016-01-07 15:15:30 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/sms/config/GatewayAdministratonService.java	2016-03-11 17:04:06 +0000
@@ -42,6 +42,5 @@
 
     SmsGatewayConfig getGatewayConfiguration( String uid );
 
-    String addOrUpdateGateway( SmsGatewayConfig config, Class<?> klass );
-
+    boolean addOrUpdateGateway( SmsGatewayConfig config, Class<?> klass );
 }

=== modified file 'dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/sms/config/DefaultGatewayAdministrationService.java'
--- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/sms/config/DefaultGatewayAdministrationService.java	2016-01-08 15:18:30 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/sms/config/DefaultGatewayAdministrationService.java	2016-03-11 17:04:06 +0000
@@ -71,7 +71,7 @@
         {
             return null;
         }
-        
+
         for ( SmsGatewayConfig gateway : list )
         {
             if ( gateway.getUid().equals( uid ) )
@@ -90,12 +90,10 @@
     }
 
     @Override
-    public String addOrUpdateGateway( SmsGatewayConfig payLoad, Class<?> klass )
+    public boolean addOrUpdateGateway( SmsGatewayConfig payLoad, Class<?> klass )
     {
         SmsConfiguration smsConfig = getSmsConfiguration();
 
-        boolean updated = false;
-
         if ( smsConfig != null )
         {
             SmsGatewayConfig gatewayConfig = smsConfigMgr.checkInstanceOfGateway( klass );
@@ -105,8 +103,6 @@
             if ( gatewayConfig != null )
             {
                 index = smsConfig.getGateways().indexOf( gatewayConfig );
-
-                updated = true;
             }
 
             payLoad.setUid( CodeGenerator.generateCode( 10 ) );
@@ -128,10 +124,10 @@
 
             smsConfigMgr.updateSmsConfiguration( smsConfig );
 
-            return updated ? "Gateway updated successfully" : "Gateway added successfully";
+            return true;
         }
 
-        return "No sms configuration found";
+        return false;
     }
 
     @Override
@@ -162,9 +158,9 @@
     public SmsGatewayConfig getGatewayConfiguration( String uid )
     {
         SmsConfiguration smsConfig = getSmsConfiguration();
-        
+
         List<SmsGatewayConfig> list = smsConfig.getGateways();
-        
+
         for ( SmsGatewayConfig gw : list )
         {
             if ( gw.getUid().equals( uid ) )

=== modified file 'dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/sms/SmsGatewayController.java'
--- dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/sms/SmsGatewayController.java	2016-03-08 16:48:15 +0000
+++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/sms/SmsGatewayController.java	2016-03-11 17:04:06 +0000
@@ -136,8 +136,14 @@
 
         SmsGatewayConfig payLoad = renderService.fromJson( request.getInputStream(), ClickatellGatewayConfig.class );
 
-        renderService.toJson( response.getOutputStream(),
-            gatewayAdminService.addOrUpdateGateway( payLoad, ClickatellGatewayConfig.class ) );
+        if ( gatewayAdminService.addOrUpdateGateway( payLoad, ClickatellGatewayConfig.class ) )
+        {
+            webMessageService.send( WebMessageUtils.ok( "SAVED" ), response, request );
+        }
+        else
+        {
+            webMessageService.send( WebMessageUtils.error( "NOT_SAVED" ), response, request );
+        }
     }
 
     @PreAuthorize( "hasRole('ALL') or hasRole('F_MOBILE_SENDSMS')" )
@@ -153,8 +159,14 @@
 
         BulkSmsGatewayConfig payLoad = renderService.fromJson( request.getInputStream(), BulkSmsGatewayConfig.class );
 
-        renderService.toJson( response.getOutputStream(),
-            gatewayAdminService.addOrUpdateGateway( payLoad, BulkSmsGatewayConfig.class ) );
+        if ( gatewayAdminService.addOrUpdateGateway( payLoad, BulkSmsGatewayConfig.class ) )
+        {
+            webMessageService.send( WebMessageUtils.ok( "SAVED" ), response, request );
+        }
+        else
+        {
+            webMessageService.send( WebMessageUtils.error( "NOT_SAVED" ), response, request );
+        }
     }
 
     @PreAuthorize( "hasRole('ALL') or hasRole('F_MOBILE_SENDSMS')" )
@@ -170,8 +182,14 @@
 
         SMPPGatewayConfig payLoad = renderService.fromJson( request.getInputStream(), SMPPGatewayConfig.class );
 
-        renderService.toJson( response.getOutputStream(),
-            gatewayAdminService.addOrUpdateGateway( payLoad, SMPPGatewayConfig.class ) );
+        if ( gatewayAdminService.addOrUpdateGateway( payLoad, SMPPGatewayConfig.class ) )
+        {
+            webMessageService.send( WebMessageUtils.ok( "SAVED" ), response, request );
+        }
+        else
+        {
+            webMessageService.send( WebMessageUtils.error( "NOT_SAVED" ), response, request );
+        }
     }
 
     @PreAuthorize( "hasRole('ALL') or hasRole('F_MOBILE_SENDSMS')" )
@@ -188,8 +206,14 @@
         GenericHttpGatewayConfig payLoad = renderService.fromJson( request.getInputStream(),
             GenericHttpGatewayConfig.class );
 
-        renderService.toJson( response.getOutputStream(),
-            gatewayAdminService.addOrUpdateGateway( payLoad, GenericHttpGatewayConfig.class ) );
+        if ( gatewayAdminService.addOrUpdateGateway( payLoad, GenericHttpGatewayConfig.class ) )
+        {
+            webMessageService.send( WebMessageUtils.ok( "SAVED" ), response, request );
+        }
+        else
+        {
+            webMessageService.send( WebMessageUtils.error( "NOT_SAVED" ), response, request );
+        }
     }
 
     @PreAuthorize( "hasRole('ALL') or hasRole('F_MOBILE_SENDSMS')" )