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.global_tests.asdc.notif_emulator;
23 import java.io.IOException;
24 import java.io.InputStream;
25 import java.util.HashMap;
26 import java.util.List;
29 import org.codehaus.jackson.annotate.JsonAnySetter;
30 import org.codehaus.jackson.annotate.JsonIgnore;
31 import org.codehaus.jackson.annotate.JsonProperty;
32 import org.codehaus.jackson.map.ObjectMapper;
33 import org.codehaus.jackson.map.annotate.JsonDeserialize;
34 import org.jboss.shrinkwrap.api.exporter.FileExistsException;
36 import org.openecomp.sdc.api.notification.IArtifactInfo;
37 import org.openecomp.sdc.api.notification.INotificationData;
38 import org.openecomp.sdc.api.notification.IResourceInstance;
41 public class JsonNotificationData implements INotificationData {
44 private Map<String,Object> attributesMap = new HashMap<>();
46 @JsonProperty("serviceArtifacts")
47 @JsonDeserialize(using=JsonArtifactInfoDeserializer.class)
48 private List<IArtifactInfo> serviceArtifacts;
50 @JsonProperty("resources")
51 @JsonDeserialize(using=JsonResourceInfoDeserializer.class)
52 private List<IResourceInstance> resourcesList;
54 public JsonNotificationData() {
59 * Method instantiate a INotificationData implementation from a JSON file.
61 * @param notifFilePath The file path in String
62 * @return A JsonNotificationData instance
63 * @throws IOException in case of the file is not readable or not accessible
65 public static JsonNotificationData instantiateNotifFromJsonFile(String notifFilePath) throws IOException {
67 InputStream is = Thread.currentThread().getContextClassLoader().getResourceAsStream(notifFilePath+"/notif-structure.json");
70 throw new FileExistsException("Resource Path does not exist: "+notifFilePath);
72 ObjectMapper mapper = new ObjectMapper();
73 return mapper.readValue(is, JsonNotificationData.class);
76 @SuppressWarnings("unused")
78 public final void setAttribute(String attrName, Object attrValue) {
79 if ((null != attrName) && (!attrName.isEmpty()) && (null != attrValue) && (null != attrValue.toString())) {
80 this.attributesMap.put(attrName,attrValue);
85 public IArtifactInfo getArtifactMetadataByUUID(String arg0) {
90 public String getDistributionID() {
91 return (String)this.attributesMap.get("distributionID");
95 public List<IResourceInstance> getResources() {
100 public List<IArtifactInfo> getServiceArtifacts() {
101 return this.serviceArtifacts;
105 public String getServiceDescription() {
106 return (String)this.attributesMap.get("serviceDescription");
110 public String getServiceInvariantUUID() {
111 return (String)this.attributesMap.get("serviceInvariantUUID");
115 public String getServiceName() {
116 return (String)this.attributesMap.get("serviceName");
120 public String getServiceUUID() {
121 return (String)this.attributesMap.get("serviceUUID");
125 public String getServiceVersion() {
126 return (String)this.attributesMap.get("serviceVersion");