X-Git-Url: https://gerrit.onap.org/r/gitweb?a=blobdiff_plain;f=vid-app-common%2Fsrc%2Fmain%2Fjava%2Forg%2Fonap%2Fvid%2Fservices%2FAaiServiceImpl.java;fp=vid-app-common%2Fsrc%2Fmain%2Fjava%2Forg%2Fonap%2Fvid%2Fservices%2FAaiServiceImpl.java;h=21e5409c3a3137347169dae18bb5da5ac53f740b;hb=f78df9f30d5b7bda1b291bff34dd85bdd9411c12;hp=1e79ab4c8d059ea546e0a6cacbf4e568c77704fd;hpb=a1d209deac01bc0f8f7be96a585bdbef9cc0cdb9;p=vid.git diff --git a/vid-app-common/src/main/java/org/onap/vid/services/AaiServiceImpl.java b/vid-app-common/src/main/java/org/onap/vid/services/AaiServiceImpl.java index 1e79ab4c8..21e5409c3 100644 --- a/vid-app-common/src/main/java/org/onap/vid/services/AaiServiceImpl.java +++ b/vid-app-common/src/main/java/org/onap/vid/services/AaiServiceImpl.java @@ -48,8 +48,12 @@ import org.onap.vid.aai.AaiClientInterface; import org.onap.vid.aai.AaiGetVnfResponse; import org.onap.vid.aai.AaiResponse; import org.onap.vid.aai.AaiResponseTranslator; +import org.onap.vid.aai.Customer; +import org.onap.vid.aai.CustomerSpecificServiceInstance; +import org.onap.vid.aai.DSLQuerySimpleResponse; import org.onap.vid.aai.ExceptionWithRequestInfo; import org.onap.vid.aai.ServiceInstance; +import org.onap.vid.aai.ServiceInstanceResponseBySubscriber; import org.onap.vid.aai.ServiceInstancesSearchResults; import org.onap.vid.aai.ServiceSubscription; import org.onap.vid.aai.ServiceSubscriptions; @@ -750,4 +754,94 @@ public class AaiServiceImpl implements AaiService { public ModelVer getNewestModelVersionByInvariantId(String modelInvariantId){ return aaiClient.getLatestVersionByInvariantId(modelInvariantId); } + + @Override + public AaiResponse getServiceInstanceBySubscriberIdAndInstanceIdentifier(String globalCustomerId, String identifierType, String serviceIdentifier) { + return aaiClient.getServiceInstanceBySubscriberIdAndInstanceIdentifier(globalCustomerId,identifierType,serviceIdentifier); + } + + @Override + public AaiResponse getServiceInstanceSearchResultsByIdentifierType(String subscriberId, String instanceIdentifier, + String instanceIdentifierType, + RoleValidator roleValidator, + List owningEntities, List projects) { + List> resultList = new ArrayList<>(); + ServiceInstancesSearchResults serviceInstancesSearchResults = new ServiceInstancesSearchResults(); + + if (subscriberId != null && instanceIdentifier != null && isValidInstanceIdentifierType(instanceIdentifierType)) { + resultList.add(getServicesBySubscriberAndServiceInstance(subscriberId, instanceIdentifier, instanceIdentifierType, roleValidator)); + } + if (owningEntities != null) { + resultList.add(getServicesByOwningEntityId(owningEntities, roleValidator)); + } + if (projects != null) { + resultList.add(getServicesByProjectNames(projects, roleValidator)); + } + if (!resultList.isEmpty()) { + serviceInstancesSearchResults.serviceInstances = Intersection.of(resultList); + } + + return new AaiResponse<>(serviceInstancesSearchResults, null, HttpStatus.SC_OK); + } + + private boolean isValidInstanceIdentifierType(String instanceIdentifierType) { + return instanceIdentifierType != null + && ( instanceIdentifierType.equalsIgnoreCase("Service Instance Id") || + instanceIdentifierType.equalsIgnoreCase("Service Instance Name")); + } + private List getServicesBySubscriberAndServiceInstance(String subscriberId, + String instanceIdentifier, + String instanceIdentifierType, + RoleValidator roleValidator) { + LOGGER.info("Starting getServicesBySubscriberAndServiceInstance subscriberId : {}, " + + "instanceIdentifier : {}, instanceIdentifierType: {} ", + subscriberId,instanceIdentifier, instanceIdentifierType); + ArrayList results = new ArrayList<>(); + if( instanceIdentifier == null || instanceIdentifierType == null) { + return results; + } + ServiceInstanceResponseBySubscriber serviceInstanceResponseBySubscriber = null; + Customer customer = null; + CustomerSpecificServiceInstance serviceInstance = null; + String subscriberName,serviceType,serviceInstanceId, serviceInstanceName,modelInvariantId,modelVersionId= null; + ServiceInstanceSearchResult serviceInstanceSearchResult = null; + + AaiResponse aaiResponse = + aaiClient.getServiceInstanceBySubscriberIdAndInstanceIdentifier(subscriberId,instanceIdentifierType, + instanceIdentifier); + if( aaiResponse != null && aaiResponse.getT() !=null && aaiResponse.getT().getResults() != null){ + serviceInstanceResponseBySubscriber = aaiResponse.getT().getResults().get(0); + customer = serviceInstanceResponseBySubscriber.getCustomer(); + serviceInstance = customer.getCustomerRelatedNodes().get(0).getCustomerServiceSubscription(). + getServiceSubscriptionRelatedNodes().get(0).getServiceInstance(); + subscriberName = customer.getSubscriberName(); + serviceType = customer.getCustomerRelatedNodes().get(0).getCustomerServiceSubscription().getServiceType(); + serviceInstanceId = serviceInstance.getServiceInstanceId(); + serviceInstanceName = serviceInstance.getServiceInstanceName(); + modelInvariantId = serviceInstance.getModelInvariantId(); + modelVersionId = serviceInstance.getModelVersionId(); + + serviceInstanceSearchResult = + new ServiceInstanceSearchResult(serviceInstanceId, subscriberId, serviceType, + serviceInstanceName, subscriberName, modelInvariantId, + modelVersionId, null, false); + serviceInstanceSearchResult.setIsPermitted(roleValidator.isServicePermitted(serviceInstanceSearchResult)); + + LOGGER.info("Result from AAI, getServicesBySubscriberAndServiceInstance serviceType : {}, " + + "serviceInstanceId : {}, serviceInstanceName: {} , modelInvariantId : {}, " + + "modelVersionId :{}, permission :{}", + serviceType, serviceInstanceId, serviceInstanceName, modelInvariantId, + modelVersionId, serviceInstanceSearchResult.getIsPermitted()); + results.add(serviceInstanceSearchResult); + } else { + LOGGER.error("Inside getServicesBySubscriberAndServiceInstance response NULL"); + } + + return results; + } + + @Override + public AaiResponse getServiceInstanceBySubscriberIdAndSIID(String globalCustomerId, String serviceType, String serviceId) { + return aaiClient.getServiceInstance(globalCustomerId, serviceType, serviceId); + } }