/*- * ============LICENSE_START======================================================= * SDC * ================================================================================ * Copyright (C) 2019 AT&T Intellectual Property. All rights reserved. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. * ============LICENSE_END========================================================= */ package org.onap.sdc.toscaparser.api; import org.onap.sdc.toscaparser.api.common.JToscaValidationIssue; import java.util.ArrayList; import java.util.LinkedHashMap; import java.util.Map; import org.onap.sdc.toscaparser.api.elements.Metadata; import org.onap.sdc.toscaparser.api.utils.ThreadLocalsHolder; import org.onap.sdc.toscaparser.api.utils.ValidateUtils; public class Policy extends EntityTemplate { static final String TYPE = "type"; static final String METADATA = "metadata"; static final String DESCRIPTION = "description"; static final String PROPERTIES = "properties"; static final String TARGETS = "targets"; private static final String TRIGGERS = "triggers"; private static final String SECTIONS[] = { TYPE, METADATA, DESCRIPTION, PROPERTIES, TARGETS, TRIGGERS}; Metadata metaDataObject; LinkedHashMap metaData = null; ArrayList targetsList; // *** a list of NodeTemplate OR a list of Group *** String targetsType; ArrayList triggers; LinkedHashMap properties; public Policy(String _name, LinkedHashMap _policy, ArrayList targetObjects, String _targetsType, LinkedHashMap _customDef) { this(_name, _policy, targetObjects, _targetsType, _customDef, null); } public Policy(String _name, LinkedHashMap _policy, // ArrayList targetObjects, ArrayList targetObjects, String _targetsType, LinkedHashMap _customDef, NodeTemplate parentNodeTemplate) { super(_name,_policy,"policy_type",_customDef, parentNodeTemplate); if(_policy.get(METADATA) != null) { metaData = (LinkedHashMap)_policy.get(METADATA); ValidateUtils.validateMap(metaData); metaDataObject = new Metadata(metaData); } targetsList = targetObjects; targetsType = _targetsType; triggers = _triggers((LinkedHashMap)_policy.get(TRIGGERS)); properties = null; if(_policy.get("properties") != null) { properties = (LinkedHashMap)_policy.get("properties"); } _validateKeys(); } public ArrayList getTargets() { return (ArrayList)entityTpl.get("targets"); } public ArrayList getDescription() { return (ArrayList)entityTpl.get("description"); } public ArrayList getmetadata() { return (ArrayList)entityTpl.get("metadata"); } public String getTargetsType() { return targetsType; } public Metadata getMetaDataObj() { return metaDataObject; } public LinkedHashMap getMetaData() { return metaData; } // public ArrayList getTargetsList() { public ArrayList getTargetsList() { return targetsList; } // entityTemplate already has a different getProperties... // this is to access the local properties variable public LinkedHashMap getPolicyProperties() { return properties; } private ArrayList _triggers(LinkedHashMap triggers) { ArrayList triggerObjs = new ArrayList<>(); if(triggers != null) { for(Map.Entry me: triggers.entrySet()) { String tname = me.getKey(); LinkedHashMap ttriggerTpl = (LinkedHashMap)me.getValue(); Triggers triggersObj = new Triggers(tname,ttriggerTpl); triggerObjs.add(triggersObj); } } return triggerObjs; } private void _validateKeys() { for(String key: entityTpl.keySet()) { boolean bFound = false; for(int i=0; i