Replaced all tabs with spaces in java and pom.xml
[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  * 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
12  * 
13  *      http://www.apache.org/licenses/LICENSE-2.0
14  * 
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=========================================================
21  */
22
23 package org.onap.so.client.orchestration;
24
25 import java.io.IOException;
26 import java.util.ArrayList;
27 import java.util.List;
28 import org.onap.namingservice.model.Element;
29 import org.onap.namingservice.model.Deleteelement;
30 import org.onap.so.bpmn.servicedecomposition.bbobjects.InstanceGroup;
31 import org.onap.so.client.exception.BadResponseException;
32 import org.onap.so.client.namingservice.NamingClient;
33 import org.onap.so.client.namingservice.NamingRequestObjectBuilder;
34 import org.slf4j.Logger;
35 import org.slf4j.LoggerFactory;
36 import org.springframework.beans.factory.annotation.Autowired;
37 import org.springframework.stereotype.Component;
38
39 @Component
40 public class NamingServiceResources {
41     private static final Logger logger = LoggerFactory.getLogger(NamingServiceResources.class);
42     private static final String NAMING_TYPE = "instanceGroup";
43
44     @Autowired
45     private NamingClient namingClient;
46
47     @Autowired
48     private NamingRequestObjectBuilder namingRequestObjectBuilder;
49
50     public String generateInstanceGroupName(InstanceGroup instanceGroup, String policyInstanceName, String nfNamingCode)
51             throws BadResponseException, IOException {
52         Element element = namingRequestObjectBuilder.elementMapper(instanceGroup.getId(), policyInstanceName,
53                 NAMING_TYPE, nfNamingCode, instanceGroup.getInstanceGroupName());
54         List<Element> elements = new ArrayList<Element>();
55         elements.add(element);
56         return (namingClient.postNameGenRequest(namingRequestObjectBuilder.nameGenRequestMapper(elements)));
57     }
58
59     public String deleteInstanceGroupName(InstanceGroup instanceGroup) throws BadResponseException, IOException {
60         Deleteelement deleteElement = namingRequestObjectBuilder.deleteElementMapper(instanceGroup.getId());
61         List<Deleteelement> deleteElements = new ArrayList<Deleteelement>();
62         deleteElements.add(deleteElement);
63         return (namingClient
64                 .deleteNameGenRequest(namingRequestObjectBuilder.nameGenDeleteRequestMapper(deleteElements)));
65     }
66 }