Removed unused fields from AbstractModelElement
[clamp.git] / src / main / java / org / onap / clamp / clds / model / properties / Policy.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP CLAMP
4  * ================================================================================
5  * Copyright (C) 2017-2018 AT&T Intellectual Property. All rights
6  *                             reserved.
7  * ================================================================================
8  * Modifications Copyright (c) 2019 Samsung
9  * ================================================================================
10  * Licensed under the Apache License, Version 2.0 (the "License");
11  * you may not use this file except in compliance with the License.
12  * You may obtain a copy of the License at
13  *
14  * http://www.apache.org/licenses/LICENSE-2.0
15  *
16  * Unless required by applicable law or agreed to in writing, software
17  * distributed under the License is distributed on an "AS IS" BASIS,
18  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
19  * See the License for the specific language governing permissions and
20  * limitations under the License.
21  * ============LICENSE_END============================================
22  * ===================================================================
23  *
24  */
25
26 package org.onap.clamp.clds.model.properties;
27
28 import com.att.eelf.configuration.EELFLogger;
29 import com.att.eelf.configuration.EELFManager;
30 import com.google.gson.JsonElement;
31 import com.google.gson.JsonObject;
32
33 import java.io.IOException;
34 import java.util.ArrayList;
35 import java.util.Iterator;
36 import java.util.List;
37 import java.util.Map.Entry;
38
39 /**
40  * Parse Policy json properties.
41  * Example json:
42  * "Policy_005sny1":[[{"name":"timeout","value":"5"}],{"policyConfigurations":[[
43  * {"name":"recipe","value":["restart"]},{"name":"maxRetries","value":["3"]},{
44  * "name":"retryTimeLimit","value":["180"]},{"name":"_id","value":["vf3RtPi"]},{
45  * "name":"location","value":["san_diego"]},{"name":"resource","value":["vCTS"]}
46  * ,{"name":"onMaxRetriesLimit","value":[""]},{"name":"onTimeLimit","value":[""]
47  * },{"name":"onOtherFailure","value":[""]},{"name":"policy_parent","value":[""]
48  * }],[{"name":"recipe","value":["rebuild"]},{"name":"maxRetries","value":["3"]}
49  * ,{"name":"retryTimeLimit","value":["180"]},{"name":"_id","value":["89z8Ncl"]}
50  * ,{"name":"location","value":["san_diego"]},{"name":"resource","value":["vCTS"
51  * ]},{"name":"onMaxRetriesLimit","value":[""]},{"name":"onTimeLimit","value":[
52  * ""]},{"name":"onOtherFailure","value":[""]},{"name":"policy_parent","value":[
53  * "vf3RtPi"]}]]}]
54  */
55 public class Policy extends AbstractModelElement {
56     protected static final EELFLogger logger = EELFManager.getInstance().getLogger(Policy.class);
57     protected static final EELFLogger auditLogger = EELFManager.getInstance().getAuditLogger();
58
59     private List<PolicyChain> policyChains;
60
61     private static final String TYPE_POLICY = "policy";
62
63     /**
64      * Parse Policy given json node.
65      *
66      * @param modelBpmn The model bpmn
67      * @param modelJson The model json
68      * @throws IOException The IO Exception
69      */
70     public Policy(ModelBpmn modelBpmn, JsonObject modelJson) throws IOException {
71         super(TYPE_POLICY, modelBpmn, modelJson);
72
73         // process policies
74         if (modelElementJsonNode != null) {
75             Iterator<Entry<String, JsonElement>> itr = modelElementJsonNode.getAsJsonObject().entrySet().iterator();
76             policyChains = new ArrayList<>();
77             while (itr.hasNext()) {
78                 policyChains.add(new PolicyChain(itr.next().getValue()));
79             }
80         }
81     }
82
83     /**
84      * Get the policy chains.
85      *
86      * @return the policyChains
87      */
88     public List<PolicyChain> getPolicyChains() {
89         return policyChains;
90     }
91
92     public static final String getType() {
93         return TYPE_POLICY;
94     }
95 }