2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2019 Nokia Intellectual Property. All rights
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
12 * http://www.apache.org/licenses/LICENSE-2.0
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 * ===================================================================
24 package org.onap.clamp.loop;
26 import com.google.gson.JsonArray;
27 import com.google.gson.JsonObject;
28 import com.google.gson.reflect.TypeToken;
30 import java.lang.reflect.Type;
31 import java.util.List;
33 import org.onap.clamp.clds.util.JsonUtils;
34 import org.onap.clamp.policy.microservice.MicroServicePolicy;
35 import org.onap.clamp.policy.operational.OperationalPolicy;
36 import org.springframework.beans.factory.annotation.Autowired;
37 import org.springframework.stereotype.Controller;
40 public class LoopController {
42 private final LoopService loopService;
43 private static final Type OPERATIONAL_POLICY_TYPE = new TypeToken<List<OperationalPolicy>>() {
45 private static final Type MICROSERVICE_POLICY_TYPE = new TypeToken<List<MicroServicePolicy>>() {
49 public LoopController(LoopService loopService) {
50 this.loopService = loopService;
53 public List<String> getLoopNames() {
54 return loopService.getClosedLoopNames();
57 public Loop getLoop(String loopName) {
58 return loopService.getLoop(loopName);
62 * Update the Operational Policy properties.
64 * @param loopName The loop name
65 * @param operationalPoliciesJson The new Operational Policy properties
66 * @return The updated loop
68 public Loop updateOperationalPolicies(String loopName, JsonArray operationalPoliciesJson) {
69 List<OperationalPolicy> operationalPolicies = JsonUtils.GSON.fromJson(operationalPoliciesJson,
70 OPERATIONAL_POLICY_TYPE);
71 return loopService.updateAndSaveOperationalPolicies(loopName, operationalPolicies);
75 * Update the whole array of MicroService policies properties.
77 * @param loopName The loop name
78 * @param microServicePoliciesJson The array of all MicroService policies
80 * @return The updated loop
82 public Loop updateMicroservicePolicies(String loopName, JsonArray microServicePoliciesJson) {
83 List<MicroServicePolicy> microservicePolicies = JsonUtils.GSON.fromJson(microServicePoliciesJson,
84 MICROSERVICE_POLICY_TYPE);
85 return loopService.updateAndSaveMicroservicePolicies(loopName, microservicePolicies);
89 * Update the global properties.
91 * @param loopName The loop name
92 * @param globalProperties The updated global properties
93 * @return The updated loop
95 public Loop updateGlobalPropertiesJson(String loopName, JsonObject globalProperties) {
96 return loopService.updateAndSaveGlobalPropertiesJson(loopName, globalProperties);
100 * Update one MicroService policy properties.
102 * @param loopName The loop name
103 * @param newMicroservicePolicy The new MicroService policy properties
104 * @return The updated MicroService policy
106 public MicroServicePolicy updateMicroservicePolicy(String loopName, MicroServicePolicy newMicroservicePolicy) {
107 return loopService.updateMicroservicePolicy(loopName, newMicroservicePolicy);
111 * Get the SVG representation of the loop.
113 * @param loopName The loop name
114 * @return The SVG representation
116 public String getSvgRepresentation(String loopName) {
117 Loop loop = loopService.getLoop(loopName);
118 return loop != null ? loop.getSvgRepresentation() : null;