Merge "Add missing INFO.yaml blocks"
[clamp.git] / src / main / java / org / onap / clamp / loop / LoopController.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP CLAMP
4  * ================================================================================
5  * Copyright (C) 2019 Nokia Intellectual Property. All rights
6  *                             reserved.
7  * ================================================================================
8  * Licensed under the Apache License, Version 2.0 (the "License");
9  * you may not use this file except in compliance with the License.
10  * You may obtain a copy of the License at
11  *
12  * http://www.apache.org/licenses/LICENSE-2.0
13  *
14  * Unless required by applicable law or agreed to in writing, software
15  * distributed under the License is distributed on an "AS IS" BASIS,
16  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17  * See the License for the specific language governing permissions and
18  * limitations under the License.
19  * ============LICENSE_END============================================
20  * ===================================================================
21  *
22  */
23
24 package org.onap.clamp.loop;
25
26 import com.google.gson.JsonArray;
27 import com.google.gson.reflect.TypeToken;
28 import java.lang.reflect.Type;
29 import java.util.List;
30 import org.onap.clamp.clds.util.JsonUtils;
31 import org.onap.clamp.policy.microservice.MicroServicePolicy;
32 import org.onap.clamp.policy.operational.OperationalPolicy;
33 import org.springframework.beans.factory.annotation.Autowired;
34 import org.springframework.stereotype.Controller;
35
36
37 @Controller
38 public class LoopController {
39
40     private final LoopService loopService;
41     private static final Type OPERATIONAL_POLICY_TYPE = new TypeToken<List<OperationalPolicy>>() {
42     }.getType();
43     private static final Type MICROSERVICE_POLICY_TYPE = new TypeToken<List<MicroServicePolicy>>() {
44     }.getType();
45
46     @Autowired
47     public LoopController(LoopService loopService) {
48         this.loopService = loopService;
49     }
50
51     public List<String> getLoopNames() {
52         return loopService.getClosedLoopNames();
53     }
54
55     public Loop getLoop(String loopName) {
56         return loopService.getLoop(loopName);
57     }
58
59     public Loop updateOperationalPolicies(String loopName, JsonArray operationalPoliciesJson) {
60         List<OperationalPolicy> operationalPolicies = JsonUtils.GSON
61             .fromJson(operationalPoliciesJson, OPERATIONAL_POLICY_TYPE);
62         return loopService.updateOperationalPolicies(loopName, operationalPolicies);
63     }
64
65     public Loop updateMicroservicePolicies(String loopName, JsonArray microServicePoliciesJson) {
66         List<MicroServicePolicy> microservicePolicies = JsonUtils.GSON
67             .fromJson(microServicePoliciesJson, MICROSERVICE_POLICY_TYPE);
68         return loopService.updateMicroservicePolicies(loopName, microservicePolicies);
69     }
70 }