Merge "Removal of dead code"
[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.JsonElement;
28 import com.google.gson.JsonObject;
29 import com.google.gson.reflect.TypeToken;
30
31 import java.lang.reflect.Type;
32 import java.util.List;
33
34 import org.onap.clamp.clds.util.JsonUtils;
35 import org.onap.clamp.policy.microservice.MicroServicePolicy;
36 import org.onap.clamp.policy.operational.OperationalPolicy;
37 import org.springframework.beans.factory.annotation.Autowired;
38 import org.springframework.stereotype.Controller;
39
40 @Controller
41 public class LoopController {
42
43     private final LoopService loopService;
44     private static final Type OPERATIONAL_POLICY_TYPE = new TypeToken<List<OperationalPolicy>>() {
45        }.getType();
46     private static final Type MICROSERVICE_POLICY_TYPE = new TypeToken<List<MicroServicePolicy>>() {
47        }.getType();
48
49     @Autowired
50     public LoopController(LoopService loopService) {
51         this.loopService = loopService;
52     }
53
54     public List<String> getLoopNames() {
55         return loopService.getClosedLoopNames();
56     }
57
58     public Loop getLoop(String loopName) {
59         return loopService.getLoop(loopName);
60     }
61
62     /**
63      * Update the Operational Policy properties.
64      * @param loopName The loop name
65      * @param operationalPoliciesJson The new Operational Policy properties
66      * @return The updated loop
67      */
68     public Loop updateOperationalPolicies(String loopName, JsonArray operationalPoliciesJson) {
69         List<OperationalPolicy> operationalPolicies = JsonUtils.GSON
70             .fromJson(operationalPoliciesJson, OPERATIONAL_POLICY_TYPE);
71         return loopService.updateAndSaveOperationalPolicies(loopName, operationalPolicies);
72     }
73
74     /**
75      * Update the whole array of MicroService policies properties
76      * @param loopName The loop name
77      * @param microServicePoliciesJson The array of all MicroService policies properties
78      * @return The updated loop
79      */
80     public Loop updateMicroservicePolicies(String loopName, JsonArray microServicePoliciesJson) {
81         List<MicroServicePolicy> microservicePolicies = JsonUtils.GSON
82             .fromJson(microServicePoliciesJson, MICROSERVICE_POLICY_TYPE);
83         return loopService.updateAndSaveMicroservicePolicies(loopName, microservicePolicies);
84     }
85
86     /**
87      * Update the global properties
88      * @param loopName The loop name
89      * @param globalProperties The updated global properties
90      * @return The updated loop
91      */
92     public Loop updateGlobalPropertiesJson(String loopName, JsonObject globalProperties) {
93         return loopService.updateAndSaveGlobalPropertiesJson(loopName, globalProperties);
94     }
95
96     /**
97      * Update one MicroService policy properties
98      * @param loopName The loop name
99      * @param newMicroservicePolicy The new MicroService policy properties
100      * @return The updated MicroService policy
101      */
102     public MicroServicePolicy updateMicroservicePolicy(String loopName, MicroServicePolicy newMicroservicePolicy) {
103         return loopService.updateMicroservicePolicy(loopName, newMicroservicePolicy);
104     }
105
106     /**
107      * Get the SVG representation of the loop
108      * @param loopName The loop name
109      * @return The SVG representation
110      */
111     public String getSVGRepresentation(String loopName) {
112         return loopService.getClosedLoopModelSVG(loopName);
113
114     }
115 }