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.reflect.TypeToken;
29 import java.lang.reflect.Type;
30 import java.util.List;
32 import org.onap.clamp.clds.util.JsonUtils;
33 import org.onap.clamp.policy.microservice.MicroServicePolicy;
34 import org.onap.clamp.policy.operational.OperationalPolicy;
35 import org.springframework.beans.factory.annotation.Autowired;
36 import org.springframework.stereotype.Controller;
39 public class LoopController {
41 private final LoopService loopService;
42 private static final Type OPERATIONAL_POLICY_TYPE = new TypeToken<List<OperationalPolicy>>() {
44 private static final Type MICROSERVICE_POLICY_TYPE = new TypeToken<List<MicroServicePolicy>>() {
48 public LoopController(LoopService loopService) {
49 this.loopService = loopService;
52 public List<String> getLoopNames() {
53 return loopService.getClosedLoopNames();
56 public Loop getLoop(String loopName) {
57 return loopService.getLoop(loopName);
60 public Loop updateOperationalPolicies(String loopName, JsonArray operationalPoliciesJson) {
61 List<OperationalPolicy> operationalPolicies = JsonUtils.GSON
62 .fromJson(operationalPoliciesJson, OPERATIONAL_POLICY_TYPE);
63 return loopService.updateOperationalPolicies(loopName, operationalPolicies);
66 public Loop updateMicroservicePolicies(String loopName, JsonArray microServicePoliciesJson) {
67 List<MicroServicePolicy> microservicePolicies = JsonUtils.GSON
68 .fromJson(microServicePoliciesJson, MICROSERVICE_POLICY_TYPE);
69 return loopService.updateMicroservicePolicies(loopName, microservicePolicies);
72 public String getSVGRepresentation(String loopName) {
73 return loopService.getClosedLoopModelSVG(loopName);