package org.openecomp.sdc.toscaparser.api; import java.util.ArrayList; import java.util.LinkedHashMap; import java.util.Map; import org.openecomp.sdc.toscaparser.api.common.ExceptionCollector; import org.openecomp.sdc.toscaparser.api.utils.ValidateUtils; public class Policy extends EntityTemplate { private static final String TYPE = "type"; private static final String METADATA = "metadata"; private static final String DESCRIPTION = "description"; private static final String PROPERTIES = "properties"; private static final String TARGETS = "targets"; private static final String TRIGGERS = "triggers"; private static final String SECTIONS[] = { TYPE, METADATA, DESCRIPTION, PROPERTIES, TARGETS, TRIGGERS}; LinkedHashMap metaData; 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, ArrayList targetObjects, String _targetsType, LinkedHashMap _customDef) { super(_name,_policy,"policy_type",_customDef); metaData = null; if(_policy.get(METADATA) != null) { metaData = (LinkedHashMap)_policy.get(METADATA); ValidateUtils.validateMap(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 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