2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2019 Nokia. 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 * Modifications copyright (c) 2019 AT&T
21 * ===================================================================
25 package org.onap.clamp.clds.util.drawing;
27 import java.util.HashSet;
29 import org.onap.clamp.loop.template.LoopElementModel;
30 import org.onap.clamp.policy.microservice.MicroServicePolicy;
31 import org.onap.clamp.policy.operational.OperationalPolicy;
33 public class ClampGraphBuilder {
34 private Set<OperationalPolicy> policies = new HashSet<>();
35 private String collector;
36 private Set<MicroServicePolicy> microServices = new HashSet<>();
37 private Set<LoopElementModel> loopElementModels = new HashSet<>();
38 private final Painter painter;
40 public ClampGraphBuilder(Painter painter) {
41 this.painter = painter;
44 public ClampGraphBuilder collector(String collector) {
45 this.collector = collector;
49 public ClampGraphBuilder addPolicy(OperationalPolicy policy) {
50 this.policies.add(policy);
54 public ClampGraphBuilder addAllPolicies(Set<OperationalPolicy> policies) {
55 this.policies.addAll(policies);
59 public ClampGraphBuilder addMicroService(MicroServicePolicy ms) {
60 microServices.add(ms);
64 public ClampGraphBuilder addAllMicroServices(Set<MicroServicePolicy> msList) {
65 microServices.addAll(msList);
70 * This method adds all loop element specified in input to the current structure.
72 * @param loopElementModels A set of LoopElementModels
73 * @return Return the current ClampGraphBuilder
75 public ClampGraphBuilder addAllLoopElementModels(Set<LoopElementModel> loopElementModels) {
76 for (LoopElementModel elem : loopElementModels) {
77 this.addLoopElementModel(elem);
83 * This method adds one loop element specified in input to the current structure.
85 * @param loopElementModel A LoopElementModels
86 * @return Return the current ClampGraphBuilder
88 public ClampGraphBuilder addLoopElementModel(LoopElementModel loopElementModel) {
89 if (LoopElementModel.MICRO_SERVICE_TYPE.equals(loopElementModel.getLoopElementType())) {
90 microServices.add(new MicroServicePolicy(loopElementModel.getName(),
91 loopElementModel.getPolicyModels().first(), false, loopElementModel));
92 } else if (LoopElementModel.OPERATIONAL_POLICY_TYPE.equals(loopElementModel.getLoopElementType())) {
93 policies.add(new OperationalPolicy(loopElementModel.getName(), null, null,
94 loopElementModel.getPolicyModels().first(), loopElementModel, null, null));
102 * @return Clamp graph (SVG)
104 public ClampGraph build() {
105 return new ClampGraph(painter.doPaint(collector, microServices, policies));