AafPermissionService functional interface was used 33/89033/2
authorpkaras <piotr.karas@nokia.com>
Fri, 31 May 2019 12:49:30 +0000 (14:49 +0200)
committerpkaras <piotr.karas@nokia.com>
Mon, 3 Jun 2019 12:05:27 +0000 (14:05 +0200)
Change-Id: Iec23491f492157b5c8d023c48035e4c678427655
Issue-ID: DMAAP-1211
Signed-off-by: piotr.karas <piotr.karas@nokia.com>
src/main/java/org/onap/dmaap/dbcapi/service/AafPermissionService.java

index df60448..00d6066 100644 (file)
@@ -57,25 +57,19 @@ public class AafPermissionService extends BaseLoggingClass {
     }
 
     ApiError grantClientRolePerms(MR_Client client) {
-        try {
-            String instance = INSTANCE_PREFIX + client.getFqtn();
-
-            for (String action : client.getAction()) {
-                grantPermForClientRole(client.getClientRole(), instance, action);
-            }
-
-        } catch (PermissionServiceException e) {
-            return handleErrorStatus(e.getCode(), client, e.getMessage());
-        }
-        return handleOkStatus(client);
+        return forEachClientAction(client, this::grantPermForClientRole);
     }
 
     ApiError revokeClientPerms(MR_Client client) {
+        return forEachClientAction(client, this::revokePermForClientRole);
+    }
+
+    private ApiError forEachClientAction(MR_Client client, PermissionUpdate permissionUpdate) {
         try {
             String instance = INSTANCE_PREFIX + client.getFqtn();
 
             for (String action : client.getAction()) {
-                revokePermForClientRole(client.getClientRole(), instance, action);
+                permissionUpdate.execute(client.getClientRole(), instance, action);
             }
 
         } catch (PermissionServiceException e) {
@@ -138,4 +132,9 @@ public class AafPermissionService extends BaseLoggingClass {
             return message;
         }
     }
+
+    @FunctionalInterface
+    interface PermissionUpdate {
+        void execute(String clientRole, String instance, String action) throws PermissionServiceException;
+    }
 }