e998778a2601725e58d5b6522bf30ef36c4543a6
[so.git] /
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP - SO
4  * ================================================================================
5  * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6  * ================================================================================
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  * ============LICENSE_END=========================================================
19  */
20
21 package org.openecomp.mso.global_tests.asdc.notif_emulator;
22
23 import java.util.HashMap;
24 import java.util.LinkedList;
25 import java.util.List;
26 import java.util.Map;
27
28 import org.codehaus.jackson.annotate.JsonAnySetter;
29 import org.codehaus.jackson.annotate.JsonIgnore;
30
31 import org.openecomp.sdc.api.notification.IArtifactInfo;
32
33 public class JsonArtifactInfo implements IArtifactInfo {
34
35     @JsonIgnore
36     private Map<String, IArtifactInfo> artifactsMapByUUID = new HashMap<>();
37
38     @JsonIgnore
39     private Map<String, Object> attributesMap = new HashMap<>();
40
41     public JsonArtifactInfo() {
42
43     }
44
45     public synchronized void addArtifactToUUIDMap(List<JsonArtifactInfo> artifactList) {
46         for (JsonArtifactInfo artifact : artifactList) {
47             artifactsMapByUUID.put(artifact.getArtifactUUID(), artifact);
48         }
49
50     }
51
52     @SuppressWarnings("unused")
53     @JsonAnySetter
54     public final void setAttribute(String attrName, Object attrValue) {
55         if ((null != attrName) && (!attrName.isEmpty()) && (null != attrValue) && (null != attrValue.toString())) {
56             this.attributesMap.put(attrName, attrValue);
57         }
58     }
59
60
61     public Map<String, IArtifactInfo> getArtifactsMapByUUID() {
62         return artifactsMapByUUID;
63     }
64
65     @Override
66     public String getArtifactChecksum() {
67         return (String) attributesMap.get("artifactCheckSum");
68     }
69
70     @Override
71     public String getArtifactDescription() {
72         return (String) attributesMap.get("artifactDescription");
73     }
74
75     @Override
76     public String getArtifactName() {
77         return (String) attributesMap.get("artifactName");
78     }
79
80     @Override
81     public Integer getArtifactTimeout() {
82         return (Integer) attributesMap.get("artifactTimeout");
83     }
84
85     @Override
86     public String getArtifactType() {
87         return (String) attributesMap.get("artifactType");
88     }
89
90     @Override
91     public String getArtifactURL() {
92         return (String) attributesMap.get("artifactURL");
93     }
94
95     @Override
96     public String getArtifactUUID() {
97         return (String) attributesMap.get("artifactUUID");
98     }
99
100     @Override
101     public String getArtifactVersion() {
102         return (String) attributesMap.get("artifactVersion");
103     }
104
105     @Override
106     public IArtifactInfo getGeneratedArtifact() {
107         return artifactsMapByUUID.get(attributesMap.get("generatedArtifact"));
108     }
109
110     @Override
111     public List<IArtifactInfo> getRelatedArtifacts() {
112         List<IArtifactInfo> listArtifacts = new LinkedList<>();
113         List<String> uuidList = (List<String>) attributesMap.get("relatedArtifact");
114         if (uuidList != null) {
115             for (String uuid : uuidList) {
116                 listArtifacts.add(artifactsMapByUUID.get(uuid));
117             }
118         }
119         return listArtifacts;
120     }
121
122 }