Lower code duplication of AaiClient calls in BBInputSetupUtils 31/101731/5
authorRemigiusz Janeczek <remigiusz.janeczek@nokia.com>
Fri, 14 Feb 2020 09:58:30 +0000 (10:58 +0100)
committerRemigiusz Janeczek <remigiusz.janeczek@nokia.com>
Tue, 25 Feb 2020 12:57:00 +0000 (13:57 +0100)
Introduce generic method for retrieving concrete resource of given type from Aai

Issue-ID: SO-2634
Signed-off-by: Remigiusz Janeczek <remigiusz.janeczek@nokia.com>
Change-Id: I33e247154961ff50fa81845158229413a9d81bfe

bpmn/MSOCommonBPMN/src/main/java/org/onap/so/bpmn/servicedecomposition/tasks/BBInputSetupUtils.java

index ec7b613..e004e10 100644 (file)
@@ -24,6 +24,7 @@ package org.onap.so.bpmn.servicedecomposition.tasks;
 
 import java.io.IOException;
 import java.util.ArrayList;
+import java.util.Arrays;
 import java.util.List;
 import java.util.Map;
 import java.util.Optional;
@@ -398,68 +399,37 @@ public class BBInputSetupUtils {
     }
 
     public Configuration getAAIConfiguration(String configurationId) {
-        return this.injectionHelper.getAaiClient()
-                .get(Configuration.class,
-                        AAIUriFactory.createResourceUri(AAIObjectType.CONFIGURATION, configurationId).depth(Depth.ONE))
-                .orElseGet(() -> {
-                    logger.debug("No Configuration matched by id");
-                    return null;
-                });
+        return this.getConcreteAAIResource(Configuration.class, AAIObjectType.CONFIGURATION, configurationId);
     }
 
     public GenericVnf getAAIGenericVnf(String vnfId) {
-
-        return this.injectionHelper.getAaiClient()
-                .get(GenericVnf.class,
-                        AAIUriFactory.createResourceUri(AAIObjectType.GENERIC_VNF, vnfId).depth(Depth.ONE))
-                .orElseGet(() -> {
-                    logger.debug("No Generic Vnf matched by id");
-                    return null;
-                });
+        return getConcreteAAIResource(GenericVnf.class, AAIObjectType.GENERIC_VNF, vnfId);
     }
 
     public VpnBinding getAAIVpnBinding(String vpnBindingId) {
-
-        return this.injectionHelper.getAaiClient()
-                .get(VpnBinding.class,
-                        AAIUriFactory.createResourceUri(AAIObjectType.VPN_BINDING, vpnBindingId).depth(Depth.ONE))
-                .orElseGet(() -> {
-                    logger.debug("No VpnBinding matched by id");
-                    return null;
-                });
+        return getConcreteAAIResource(VpnBinding.class, AAIObjectType.VPN_BINDING, vpnBindingId);
     }
 
     public VolumeGroup getAAIVolumeGroup(String cloudOwnerId, String cloudRegionId, String volumeGroupId) {
-        return this.injectionHelper.getAaiClient()
-                .get(VolumeGroup.class, AAIUriFactory
-                        .createResourceUri(AAIObjectType.VOLUME_GROUP, cloudOwnerId, cloudRegionId, volumeGroupId)
-                        .depth(Depth.ONE))
-                .orElseGet(() -> {
-                    logger.debug("No Generic Vnf matched by id");
-                    return null;
-                });
+        return getConcreteAAIResource(VolumeGroup.class, AAIObjectType.VOLUME_GROUP, cloudOwnerId, cloudRegionId,
+                volumeGroupId);
     }
 
     public VfModule getAAIVfModule(String vnfId, String vfModuleId) {
-        return this.injectionHelper.getAaiClient()
-                .get(VfModule.class,
-                        AAIUriFactory.createResourceUri(AAIObjectType.VF_MODULE, vnfId, vfModuleId).depth(Depth.ONE))
-                .orElseGet(() -> {
-                    logger.debug("No Generic Vnf matched by id");
-                    return null;
-                });
+        return getConcreteAAIResource(VfModule.class, AAIObjectType.VF_MODULE, vnfId, vfModuleId);
     }
 
     public L3Network getAAIL3Network(String networkId) {
+        return getConcreteAAIResource(L3Network.class, AAIObjectType.L3_NETWORK, networkId);
+    }
 
-        return this.injectionHelper.getAaiClient()
-                .get(L3Network.class,
-                        AAIUriFactory.createResourceUri(AAIObjectType.L3_NETWORK, networkId).depth(Depth.ONE))
-                .orElseGet(() -> {
-                    logger.debug("No Generic Vnf matched by id");
+    private <T> T getConcreteAAIResource(Class<T> clazz, AAIObjectType objectType, Object... ids) {
+        return injectionHelper.getAaiClient()
+                .get(clazz, AAIUriFactory.createResourceUri(objectType, ids).depth(Depth.ONE)).orElseGet(() -> {
+                    logger.debug("No resource of type: {} matched by ids: {}", objectType.typeName(),
+                            Arrays.toString(ids));
                     return null;
                 });
-
     }
 
     public Optional<ServiceInstance> getRelatedServiceInstanceFromInstanceGroup(String instanceGroupId)