1 package org.openecomp.sdc.be.datatypes.elements;
3 import org.openecomp.sdc.be.datatypes.enums.JsonPresentationFields;
4 import org.openecomp.sdc.be.datatypes.tosca.ToscaDataDefinition;
6 import java.io.Serializable;
10 * Maps an object type (e.g. "monitoring", "workflows" etc) to a list of external references.
12 * "monitoring" -> { "ref1", "ref2" },
13 * "workflows" -> { "ref1", "ref2" }
16 public class MapComponentInstanceExternalRefs extends ToscaDataDefinition implements Serializable {
18 private static final long serialVersionUID = 7788408255736272985L;
21 public MapComponentInstanceExternalRefs() {
22 this.setComponentInstanceExternalRefs(new HashMap<String, List<String>>());
25 public Map<String, List<String>> getComponentInstanceExternalRefs() {
26 return (Map<String, List<String>>) getToscaPresentationValue(JsonPresentationFields.EXTERNAL_REF);
29 public List<String> getExternalRefsByObjectType(String objectType) {
30 List<String> externalRefsByObjectType = ((Map<String, List<String>>) getToscaPresentationValue(JsonPresentationFields.EXTERNAL_REF)).get(objectType);
31 return externalRefsByObjectType;
34 public void setComponentInstanceExternalRefs(Map<String, List<String>> componentInstanceExternalRefs) {
35 setToscaPresentationValue(JsonPresentationFields.EXTERNAL_REF, componentInstanceExternalRefs);
39 * Adds a reference to the given object type. Will do nothing if already exist.
41 * @param objectType object type to associate reference to
44 public boolean addExternalRef(String objectType, String ref){
46 List<String> refList = this.getExternalRefsByObjectType(objectType);
48 if (refList == null) {
49 //Create list if does not exist and add it to map
50 refList = new ArrayList<String>();
51 this.getComponentInstanceExternalRefs().put(objectType, refList);
54 //Add reference to list if does not exist
55 if (!refList.contains(ref)){
56 return refList.add(ref);
63 public boolean deleteExternalRef(String objectType, String ref){
64 List<String> refList = this.getExternalRefsByObjectType(objectType);
66 if (refList != null) {
67 return refList.remove(ref);
73 public boolean replaceExternalRef(String objectType, String oldRef, String newRef) {
74 List<String> refList = this.getExternalRefsByObjectType(objectType);
76 if (refList != null && !refList.contains(newRef)) {
77 return Collections.replaceAll(refList, oldRef, newRef);