2  * ============LICENSE_START=======================================================
 
   4  * ================================================================================
 
   5  * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
 
   6  * ================================================================================
 
   7  * Modifications Copyright (c) 2019 Samsung
 
   8  * ================================================================================
 
   9  * Licensed under the Apache License, Version 2.0 (the "License");
 
  10  * you may not use this file except in compliance with the License.
 
  11  * You may obtain a copy of the License at
 
  13  *      http://www.apache.org/licenses/LICENSE-2.0
 
  15  * Unless required by applicable law or agreed to in writing, software
 
  16  * distributed under the License is distributed on an "AS IS" BASIS,
 
  17  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 
  18  * See the License for the specific language governing permissions and
 
  19  * limitations under the License.
 
  20  * ============LICENSE_END=========================================================
 
  23 package org.onap.so.bpmn.infrastructure.aai.groovyflows;
 
  25 import java.util.HashMap;
 
  27 import java.util.Optional;
 
  28 import org.onap.aai.domain.yang.OwningEntities;
 
  29 import org.onap.aai.domain.yang.OwningEntity;
 
  30 import org.onap.aaiclient.client.aai.AAIObjectPlurals;
 
  31 import org.onap.aaiclient.client.aai.AAIObjectType;
 
  32 import org.onap.aaiclient.client.aai.AAIResourcesClient;
 
  33 import org.onap.aaiclient.client.aai.entities.uri.AAIResourceUri;
 
  34 import org.onap.aaiclient.client.aai.entities.uri.AAIUriFactory;
 
  35 import org.slf4j.Logger;
 
  36 import org.slf4j.LoggerFactory;
 
  38 public class AAICreateResources {
 
  40     private static final Logger logger = LoggerFactory.getLogger(AAICreateResources.class);
 
  42     public void createAAIProject(String projectName, String serviceInstance) {
 
  43         AAIResourceUri projectURI = AAIUriFactory.createResourceUri(AAIObjectType.PROJECT, projectName);
 
  44         AAIResourceUri serviceInstanceURI =
 
  45                 AAIUriFactory.createResourceUri(AAIObjectType.SERVICE_INSTANCE, serviceInstance);
 
  46         AAIResourcesClient aaiRC = new AAIResourcesClient();
 
  47         aaiRC.createIfNotExists(projectURI, Optional.empty()).connect(projectURI, serviceInstanceURI);
 
  51     public void createAAIOwningEntity(String owningEntityId, String owningEntityName, String serviceInstance) {
 
  52         AAIResourceUri owningEntityURI = AAIUriFactory.createResourceUri(AAIObjectType.OWNING_ENTITY, owningEntityId);
 
  53         AAIResourceUri serviceInstanceURI =
 
  54                 AAIUriFactory.createNodesUri(AAIObjectType.SERVICE_INSTANCE, serviceInstance);
 
  55         Map<String, String> hashMap = new HashMap<>();
 
  56         hashMap.put("owning-entity-name", owningEntityName);
 
  57         AAIResourcesClient aaiRC = new AAIResourcesClient();
 
  58         aaiRC.createIfNotExists(owningEntityURI, Optional.of(hashMap)).connect(owningEntityURI, serviceInstanceURI);
 
  61     public boolean existsOwningEntity(String owningEntityId) {
 
  62         AAIResourceUri owningEntityURI = AAIUriFactory.createResourceUri(AAIObjectType.OWNING_ENTITY, owningEntityId);
 
  63         AAIResourcesClient aaiRC = new AAIResourcesClient();
 
  64         return aaiRC.exists(owningEntityURI);
 
  67     protected OwningEntities getOwningEntityName(String owningEntityName) {
 
  69         AAIResourcesClient aaiRC = new AAIResourcesClient();
 
  70         return aaiRC.get(OwningEntities.class, AAIUriFactory.createResourceUri(AAIObjectPlurals.OWNING_ENTITY)
 
  71                 .queryParam("owning-entity-name", owningEntityName)).orElseGet(() -> {
 
  72                     logger.debug("No Owning Entity matched by name");
 
  78     public Optional<OwningEntity> getOwningEntityNames(String owningEntityName) throws Exception {
 
  79         OwningEntity owningEntity = null;
 
  80         OwningEntities owningEntities = null;
 
  81         owningEntities = getOwningEntityName(owningEntityName);
 
  83         if (owningEntities == null) {
 
  84             return Optional.empty();
 
  85         } else if (owningEntities.getOwningEntity().size() > 1) {
 
  86             throw new Exception("Multiple OwningEntities Returned");
 
  88             owningEntity = owningEntities.getOwningEntity().get(0);
 
  90         return Optional.of(owningEntity);
 
  93     public void connectOwningEntityandServiceInstance(String owningEntityId, String serviceInstance) {
 
  94         AAIResourceUri owningEntityURI = AAIUriFactory.createResourceUri(AAIObjectType.OWNING_ENTITY, owningEntityId);
 
  95         AAIResourceUri serviceInstanceURI =
 
  96                 AAIUriFactory.createResourceUri(AAIObjectType.SERVICE_INSTANCE, serviceInstance);
 
  97         AAIResourcesClient aaiRC = new AAIResourcesClient();
 
  98         aaiRC.connect(owningEntityURI, serviceInstanceURI);
 
 101     public void createAAIPlatform(String platformName, String vnfId) {
 
 102         AAIResourceUri platformURI = AAIUriFactory.createResourceUri(AAIObjectType.PLATFORM, platformName);
 
 103         AAIResourceUri genericVnfURI = AAIUriFactory.createResourceUri(AAIObjectType.GENERIC_VNF, vnfId);
 
 104         AAIResourcesClient aaiRC = new AAIResourcesClient();
 
 105         aaiRC.createIfNotExists(platformURI, Optional.empty()).connect(platformURI, genericVnfURI);
 
 108     public void createAAILineOfBusiness(String lineOfBusiness, String vnfId) {
 
 109         AAIResourceUri lineOfBusinessURI =
 
 110                 AAIUriFactory.createResourceUri(AAIObjectType.LINE_OF_BUSINESS, lineOfBusiness);
 
 111         AAIResourceUri genericVnfURI = AAIUriFactory.createResourceUri(AAIObjectType.GENERIC_VNF, vnfId);
 
 112         AAIResourcesClient aaiRC = new AAIResourcesClient();
 
 113         aaiRC.createIfNotExists(lineOfBusinessURI, Optional.empty()).connect(lineOfBusinessURI, genericVnfURI);
 
 116     public void createAAIServiceInstance(String globalCustomerId, String serviceType, String serviceInstanceId) {
 
 117         AAIResourceUri serviceInstanceURI = AAIUriFactory.createResourceUri(AAIObjectType.SERVICE_INSTANCE,
 
 118                 globalCustomerId, serviceType, serviceInstanceId);
 
 119         AAIResourcesClient aaiRC = new AAIResourcesClient();
 
 120         aaiRC.createIfNotExists(serviceInstanceURI, Optional.empty());