Merge "Add Cloud Owner"
[so.git] / bpmn / so-bpmn-tasks / src / main / java / org / onap / so / client / orchestration / NamingServiceResources.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP - SO
4  * ================================================================================
5  * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6  * ================================================================================
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  * 
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  * 
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  * ============LICENSE_END=========================================================
19  */
20
21 package org.onap.so.client.orchestration;
22
23 import java.util.ArrayList;
24 import java.util.List;
25
26 import org.onap.namingservice.model.Element;
27 import org.onap.namingservice.model.Deleteelement;
28 import org.onap.so.bpmn.servicedecomposition.bbobjects.InstanceGroup;
29 import org.onap.so.client.exception.BadResponseException;
30 import org.onap.so.client.namingservice.NamingClient;
31 import org.onap.so.client.namingservice.NamingRequestObjectBuilder;
32 import org.onap.so.logger.MsoLogger;
33 import org.springframework.beans.factory.annotation.Autowired;
34 import org.springframework.stereotype.Component;
35
36 @Component
37 public class NamingServiceResources {
38         private static final MsoLogger msoLogger = MsoLogger.getMsoLogger(MsoLogger.Catalog.BPEL, NamingServiceResources.class);
39         private static final String NAMING_TYPE = "instanceGroup";
40         
41         @Autowired
42         private NamingClient namingClient;
43         
44         @Autowired
45         private NamingRequestObjectBuilder namingRequestObjectBuilder;  
46         
47         public String generateInstanceGroupName(InstanceGroup instanceGroup, String policyInstanceName, String nfNamingCode) throws BadResponseException {
48                 Element element = namingRequestObjectBuilder.elementMapper(instanceGroup.getId(), policyInstanceName, NAMING_TYPE, nfNamingCode, instanceGroup.getInstanceGroupName());
49                 List<Element> elements = new ArrayList<Element>();
50                 elements.add(element);          
51                 return(namingClient.postNameGenRequest(namingRequestObjectBuilder.nameGenRequestMapper(elements)));             
52         }
53         
54         public String deleteInstanceGroupName(InstanceGroup instanceGroup) throws BadResponseException {                
55                 Deleteelement deleteElement = namingRequestObjectBuilder.deleteElementMapper(instanceGroup.getId());
56                 List<Deleteelement> deleteElements = new ArrayList<Deleteelement>();
57                 deleteElements.add(deleteElement);              
58                 return(namingClient.deleteNameGenRequest(namingRequestObjectBuilder.nameGenDeleteRequestMapper(deleteElements)));               
59         }       
60 }