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;
9 * Maps an object type (e.g. "monitoring", "workflows" etc) to a list of external references.
11 * "monitoring" -> { "ref1", "ref2" },
12 * "workflows" -> { "ref1", "ref2" }
15 public class MapComponentInstanceExternalRefs extends ToscaDataDefinition {
17 public MapComponentInstanceExternalRefs() {
18 setComponentInstanceExternalRefs(new HashMap<>());
21 public MapComponentInstanceExternalRefs(Map<String, List<String>> instanceExternalReferences) {
22 setComponentInstanceExternalRefs(instanceExternalReferences);
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 return ((Map<String, List<String>>) getToscaPresentationValue(JsonPresentationFields.EXTERNAL_REF)).get(objectType);
33 public void setComponentInstanceExternalRefs(Map<String, List<String>> componentInstanceExternalRefs) {
34 setToscaPresentationValue(JsonPresentationFields.EXTERNAL_REF, componentInstanceExternalRefs);
38 * Adds a reference to the given object type. Will do nothing if already exist.
40 * @param objectType object type to associate reference to
43 public boolean addExternalRef(String objectType, String ref){
45 List<String> refList = this.getExternalRefsByObjectType(objectType);
47 if (refList == null) {
48 //Create list if does not exist and add it to map
49 refList = new ArrayList<>();
50 this.getComponentInstanceExternalRefs().put(objectType, refList);
53 //Add reference to list if does not exist
54 if (!refList.contains(ref)){
55 return refList.add(ref);
62 public boolean deleteExternalRef(String objectType, String ref){
63 List<String> refList = this.getExternalRefsByObjectType(objectType);
65 if (refList != null) {
66 return refList.remove(ref);
72 public boolean replaceExternalRef(String objectType, String oldRef, String newRef) {
73 List<String> refList = this.getExternalRefsByObjectType(objectType);
75 if (refList != null && !refList.contains(newRef)) {
76 return Collections.replaceAll(refList, oldRef, newRef);