1 package org.openecomp.sdc.toscaparser.api;
3 import java.util.ArrayList;
4 import java.util.LinkedHashMap;
7 import org.openecomp.sdc.toscaparser.api.elements.CapabilityTypeDef;
8 import org.openecomp.sdc.toscaparser.api.elements.PropertyDef;
10 public class Capability {
13 private LinkedHashMap<String,Object> _properties;
14 private CapabilityTypeDef _definition;
16 public Capability(String cname,
17 LinkedHashMap<String,Object> cproperties,
18 CapabilityTypeDef cdefinition) {
20 _properties = cproperties;
21 _definition = cdefinition;
24 public ArrayList<Property> getPropertiesObjects() {
25 // Return a list of property objects
26 ArrayList<Property> properties = new ArrayList<Property>();
27 LinkedHashMap<String,Object> props = _properties;
29 for(Map.Entry<String,Object> me: props.entrySet()) {
30 String pname = me.getKey();
31 Object pvalue = me.getValue();
33 LinkedHashMap<String,PropertyDef> propsDef = _definition.getPropertiesDef();
34 if(propsDef != null) {
35 PropertyDef pd = (PropertyDef)propsDef.get(pname);
37 properties.add(new Property(pname,pvalue,pd.getSchema(),null));
45 public LinkedHashMap<String,Property> getProperties() {
46 // Return a dictionary of property name-object pairs
47 LinkedHashMap<String,Property> npps = new LinkedHashMap<>();
48 for(Property p: getPropertiesObjects()) {
49 npps.put(p.getName(),p);
54 public Object getPropertyValue(String pname) {
55 // Return the value of a given property name
56 LinkedHashMap<String,Property> props = getProperties();
57 if(props != null && props.get(pname) != null) {
58 return props.get(name).getValue();
63 public String getName() {
67 public CapabilityTypeDef getDefinition() {
72 public void setProperty(String pname,Object pvalue) {
73 _properties.put(pname,pvalue);
77 public String toString() {
78 return "Capability{" +
79 "name='" + name + '\'' +
80 ", _properties=" + _properties +
81 ", _definition=" + _definition +
88 from toscaparser.properties import Property
91 class Capability(object):
92 '''TOSCA built-in capabilities type.'''
94 def __init__(self, name, properties, definition):
96 self._properties = properties
97 self.definition = definition
99 def get_properties_objects(self):
100 '''Return a list of property objects.'''
102 props = self._properties
104 for name, value in props.items():
105 props_def = self.definition.get_properties_def()
106 if props_def and name in props_def:
107 properties.append(Property(name, value,
108 props_def[name].schema))
111 def get_properties(self):
112 '''Return a dictionary of property name-object pairs.'''
113 return {prop.name: prop
114 for prop in self.get_properties_objects()}
116 def get_property_value(self, name):
117 '''Return the value of a given property name.'''
118 props = self.get_properties()
119 if props and name in props:
120 return props[name].value