Merge "Add CDS client"
[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.io.IOException;
24 import java.util.ArrayList;
25 import java.util.List;
26
27 import org.onap.namingservice.model.Element;
28 import org.onap.namingservice.model.Deleteelement;
29 import org.onap.so.bpmn.servicedecomposition.bbobjects.InstanceGroup;
30 import org.onap.so.client.exception.BadResponseException;
31 import org.onap.so.client.namingservice.NamingClient;
32 import org.onap.so.client.namingservice.NamingRequestObjectBuilder;
33 import org.onap.so.logger.MsoLogger;
34 import org.springframework.beans.factory.annotation.Autowired;
35 import org.springframework.stereotype.Component;
36
37 @Component
38 public class NamingServiceResources {
39         private static final MsoLogger msoLogger = MsoLogger.getMsoLogger(MsoLogger.Catalog.BPEL, NamingServiceResources.class);
40         private static final String NAMING_TYPE = "instanceGroup";
41         
42         @Autowired
43         private NamingClient namingClient;
44         
45         @Autowired
46         private NamingRequestObjectBuilder namingRequestObjectBuilder;  
47         
48         public String generateInstanceGroupName(InstanceGroup instanceGroup, String policyInstanceName, String nfNamingCode) throws BadResponseException, IOException {
49                 Element element = namingRequestObjectBuilder.elementMapper(instanceGroup.getId(), policyInstanceName, NAMING_TYPE, nfNamingCode, instanceGroup.getInstanceGroupName());
50                 List<Element> elements = new ArrayList<Element>();
51                 elements.add(element);          
52                 return(namingClient.postNameGenRequest(namingRequestObjectBuilder.nameGenRequestMapper(elements)));             
53         }
54         
55         public String deleteInstanceGroupName(InstanceGroup instanceGroup) throws BadResponseException, IOException {           
56                 Deleteelement deleteElement = namingRequestObjectBuilder.deleteElementMapper(instanceGroup.getId());
57                 List<Deleteelement> deleteElements = new ArrayList<Deleteelement>();
58                 deleteElements.add(deleteElement);              
59                 return(namingClient.deleteNameGenRequest(namingRequestObjectBuilder.nameGenDeleteRequestMapper(deleteElements)));               
60         }       
61 }