AT&T 1712 and 1802 release code
[so.git] / asdc-controller / src / main / java / org / openecomp / mso / asdc / client / test / emulators / JsonNotificationData.java
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.asdc.client.test.emulators;
22
23 import java.io.IOException;
24 import java.io.InputStream;
25 import java.util.HashMap;
26 import java.util.List;
27 import java.util.Map;
28
29 import org.openecomp.sdc.api.notification.IArtifactInfo;
30 import org.openecomp.sdc.api.notification.INotificationData;
31 import org.openecomp.sdc.api.notification.IResourceInstance;
32
33 import com.fasterxml.jackson.annotation.JsonAnySetter;
34 import com.fasterxml.jackson.annotation.JsonIgnore;
35 import com.fasterxml.jackson.annotation.JsonProperty;
36 import com.fasterxml.jackson.databind.ObjectMapper;
37 import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
38
39
40 public class JsonNotificationData implements INotificationData {
41         
42         @JsonIgnore
43         private static ObjectMapper mapper = new ObjectMapper();
44         
45         @JsonIgnore
46         private Map<String,Object> attributesMap = new HashMap<>();
47         
48         @JsonProperty("serviceArtifacts")
49         @JsonDeserialize(using=JsonArtifactInfoDeserializer.class)
50         private List<IArtifactInfo> serviceArtifacts;
51         
52         @JsonProperty("resources")
53         @JsonDeserialize(using=JsonResourceInfoDeserializer.class)
54         private List<IResourceInstance> resourcesList;
55         
56         public JsonNotificationData() {
57                 
58         }
59                 
60         /**
61          * Method instantiate a INotificationData implementation from a JSON file.
62          * 
63          * @param notifFilePath The file path in String
64          * @return A JsonNotificationData instance
65          * @throws IOException in case of the file is not readable or not accessible 
66          */
67         public static JsonNotificationData instantiateNotifFromJsonFile(String notifFilePath) throws IOException {
68                 
69                 InputStream is = Thread.currentThread().getContextClassLoader().getResourceAsStream(notifFilePath + "notif-structure.json");
70                 
71                 //String fileLocation = System.getProperty("mso.config.path") + "notif-structure.json";
72                 
73                 //String source = fileLocation;
74                 //InputStream is = IOUtils.toInputStream(source, "UTF-8");
75                 
76                 //String myString = IOUtils.toString(is, "UTF-8");
77                 
78                 
79                 //System.out.println(myString);
80                 
81                 if (is == null) {
82                         //throw new FileExistsException("Resource Path does not exist: "+notifFilePath);
83                 }
84                         return mapper.readValue(is, JsonNotificationData.class);
85         }
86         
87         @SuppressWarnings("unused")
88         @JsonAnySetter
89         public final void setAttribute(String attrName, Object attrValue) {
90                 if ((null != attrName) && (!attrName.isEmpty()) && (null != attrValue) && (null != attrValue.toString())) {
91                         this.attributesMap.put(attrName,attrValue);
92                 }
93         }
94         
95         @Override
96         public String getWorkloadContext(){
97                 return (String)this.attributesMap.get("workloadContext");
98         }
99           
100         @Override
101         public void setWorkloadContext(java.lang.String arg0){
102                 
103         }
104
105         @Override
106         public IArtifactInfo getArtifactMetadataByUUID(String arg0) {
107                 return null;
108         }
109
110         @Override
111         public String getDistributionID() {
112                 return (String)this.attributesMap.get("distributionID");
113         }
114
115         @Override
116         public List<IResourceInstance> getResources() {
117                 return resourcesList;
118         }
119
120         @Override
121         public List<IArtifactInfo> getServiceArtifacts() {
122                 return this.serviceArtifacts;
123         }
124
125         @Override
126         public String getServiceDescription() {
127                 return (String)this.attributesMap.get("serviceDescription");
128         }
129
130         @Override
131         public String getServiceInvariantUUID() {
132                 return (String)this.attributesMap.get("serviceInvariantUUID");
133         }
134
135         @Override
136         public String getServiceName() {
137                 return (String)this.attributesMap.get("serviceName");
138         }
139
140         @Override
141         public String getServiceUUID() {
142                 return (String)this.attributesMap.get("serviceUUID");
143         }
144
145         @Override
146         public String getServiceVersion() {
147                 return (String)this.attributesMap.get("serviceVersion");
148         }
149 }