From b40da4a8dff7c148ddfa3b29802e072449d7419d Mon Sep 17 00:00:00 2001 From: Remigiusz Janeczek Date: Fri, 14 Feb 2020 10:58:30 +0100 Subject: Lower code duplication of AaiClient calls in BBInputSetupUtils Introduce generic method for retrieving concrete resource of given type from Aai Issue-ID: SO-2634 Signed-off-by: Remigiusz Janeczek Change-Id: I33e247154961ff50fa81845158229413a9d81bfe --- .../tasks/BBInputSetupUtils.java | 58 ++++++---------------- 1 file changed, 14 insertions(+), 44 deletions(-) (limited to 'bpmn') diff --git a/bpmn/MSOCommonBPMN/src/main/java/org/onap/so/bpmn/servicedecomposition/tasks/BBInputSetupUtils.java b/bpmn/MSOCommonBPMN/src/main/java/org/onap/so/bpmn/servicedecomposition/tasks/BBInputSetupUtils.java index ec7b613727..e004e10cf0 100644 --- a/bpmn/MSOCommonBPMN/src/main/java/org/onap/so/bpmn/servicedecomposition/tasks/BBInputSetupUtils.java +++ b/bpmn/MSOCommonBPMN/src/main/java/org/onap/so/bpmn/servicedecomposition/tasks/BBInputSetupUtils.java @@ -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 getConcreteAAIResource(Class 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 getRelatedServiceInstanceFromInstanceGroup(String instanceGroupId) -- cgit 1.2.3-korg