Create get Pdp Groups flow
[clamp.git] / src / main / java / org / onap / clamp / policy / pdpgroup / PdpGroup.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP CLAMP
4  * ================================================================================
5  * Copyright (C) 2020 AT&T 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.policy.pdpgroup;
25
26 import com.google.gson.JsonArray;
27 import com.google.gson.JsonObject;
28 import com.google.gson.annotations.Expose;
29
30 import java.util.List;
31
32 /**
33  * This class maps the get Pdp Group response to a nice pojo.
34  */
35 public class PdpGroup {
36
37     @Expose
38     private String name;
39
40     @Expose
41     private String pdpGroupState;
42
43     @Expose
44     private List<PdpSubgroup> pdpSubgroups;
45
46     public String getName() {
47         return name;
48     }
49
50     public void setName(String name) {
51         this.name = name;
52     }
53
54     public String getPdpGroupState() {
55         return pdpGroupState;
56     }
57
58     public void setPdpGroupState(String pdpGroupState) {
59         this.pdpGroupState = pdpGroupState;
60     }
61
62     public List<PdpSubgroup> getPdpSubgroups() {
63         return pdpSubgroups;
64     }
65
66     public void setPdpSubgroups(List<PdpSubgroup> pdpSubgroups) {
67         this.pdpSubgroups = pdpSubgroups;
68     }
69
70     /**
71      * Get supported subGroups based on the defined policy type and version.
72      * @param policyType The policy type
73      * @param version The version
74      * @return The supported subGroup list in Json format
75      */
76     public JsonObject getSupportedSubgroups(String policyType, String version) {
77         if (!pdpGroupState.equalsIgnoreCase("ACTIVE")) {
78             return null;
79         }
80         JsonArray supportedSubgroups =  new JsonArray();
81         for (PdpSubgroup subGroup : pdpSubgroups) {
82             if (subGroup.getSupportedPolicyTypes().contains(new PolicyModelKey(policyType, version))) {
83                 supportedSubgroups.add(subGroup.getPdpType());
84             }
85         }
86         if (supportedSubgroups.size() > 0) {
87             JsonObject supportedPdpGroup = new JsonObject();
88             supportedPdpGroup.add(this.name, supportedSubgroups);
89             return supportedPdpGroup;
90         }
91         return null;
92     }
93 }