2 * ============LICENSE_START=======================================================
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
11 * http://www.apache.org/licenses/LICENSE-2.0
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=========================================================
21 package org.openecomp.mso.asdc.client.test.emulators;
23 import java.io.IOException;
24 import java.io.InputStream;
25 import java.util.HashMap;
26 import java.util.List;
29 import org.openecomp.sdc.api.notification.IArtifactInfo;
30 import org.openecomp.sdc.api.notification.INotificationData;
31 import org.openecomp.sdc.api.notification.IResourceInstance;
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;
40 public class JsonNotificationData implements INotificationData {
43 private static ObjectMapper mapper = new ObjectMapper();
46 private Map<String,Object> attributesMap = new HashMap<>();
48 @JsonProperty("serviceArtifacts")
49 @JsonDeserialize(using=JsonArtifactInfoDeserializer.class)
50 private List<IArtifactInfo> serviceArtifacts;
52 @JsonProperty("resources")
53 @JsonDeserialize(using=JsonResourceInfoDeserializer.class)
54 private List<IResourceInstance> resourcesList;
56 public JsonNotificationData() {
61 * Method instantiate a INotificationData implementation from a JSON file.
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
67 public static JsonNotificationData instantiateNotifFromJsonFile(String notifFilePath) throws IOException {
69 InputStream is = Thread.currentThread().getContextClassLoader().getResourceAsStream(notifFilePath + "notif-structure.json");
71 //String fileLocation = System.getProperty("mso.config.path") + "notif-structure.json";
73 //String source = fileLocation;
74 //InputStream is = IOUtils.toInputStream(source, "UTF-8");
76 //String myString = IOUtils.toString(is, "UTF-8");
79 //System.out.println(myString);
82 //throw new FileExistsException("Resource Path does not exist: "+notifFilePath);
84 return mapper.readValue(is, JsonNotificationData.class);
87 @SuppressWarnings("unused")
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);
96 public String getWorkloadContext(){
97 return (String)this.attributesMap.get("workloadContext");
101 public void setWorkloadContext(java.lang.String arg0){
106 public IArtifactInfo getArtifactMetadataByUUID(String arg0) {
111 public String getDistributionID() {
112 return (String)this.attributesMap.get("distributionID");
116 public List<IResourceInstance> getResources() {
117 return resourcesList;
121 public List<IArtifactInfo> getServiceArtifacts() {
122 return this.serviceArtifacts;
126 public String getServiceDescription() {
127 return (String)this.attributesMap.get("serviceDescription");
131 public String getServiceInvariantUUID() {
132 return (String)this.attributesMap.get("serviceInvariantUUID");
136 public String getServiceName() {
137 return (String)this.attributesMap.get("serviceName");
141 public String getServiceUUID() {
142 return (String)this.attributesMap.get("serviceUUID");
146 public String getServiceVersion() {
147 return (String)this.attributesMap.get("serviceVersion");