7c9881875bfc1a7f3849f223ca4ea9a4f0f975ef
[aai/sparky-be.git] / src / main / java / org / onap / aai / sparky / subscription / payload / entity / ObjectInspectorPayload.java
1 /**
2  * ============LICENSE_START=======================================================
3  * org.onap.aai
4  * ================================================================================
5  * Copyright © 2017 AT&T Intellectual Property. All rights reserved.
6  * Copyright © 2017 Amdocs
7  * ================================================================================
8  * Licensed under the Apache License, Version 2.0 (the "License");
9  * you may not use this file except in compliance with the License.
10  * You may obtain a copy of the License at
11  *
12  *       http://www.apache.org/licenses/LICENSE-2.0
13  *
14  * Unless required by applicable law or agreed to in writing, software
15  * distributed under the License is distributed on an "AS IS" BASIS,
16  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17  * See the License for the specific language governing permissions and
18  * limitations under the License.
19  * ============LICENSE_END=========================================================
20  *
21  * ECOMP is a trademark and service mark of AT&T Intellectual Property.
22  */
23 package org.onap.aai.sparky.subscription.payload.entity;
24
25 import java.io.File;
26 import java.io.IOException;
27
28 import org.onap.aai.sparky.subscription.config.SubscriptionConfig;
29 import org.onap.aai.sparky.viewandinspect.config.SparkyConstants;
30
31 import com.fasterxml.jackson.annotation.JsonInclude;
32 import com.fasterxml.jackson.annotation.JsonProperty;
33 import com.fasterxml.jackson.annotation.JsonPropertyOrder;
34 import com.fasterxml.jackson.core.JsonParseException;
35 import com.fasterxml.jackson.databind.JsonMappingException;
36 import com.fasterxml.jackson.databind.ObjectMapper;
37
38 @JsonInclude(JsonInclude.Include.NON_NULL)
39 @JsonPropertyOrder({ "target", "origin", "messageType", "topic", "message" })
40 public class ObjectInspectorPayload {
41
42         @JsonProperty("target")
43         private String target;
44         @JsonProperty("origin")
45         private String origin;
46         @JsonProperty("messageType")
47         private String messageType;
48         @JsonProperty("topic")
49         private String topic;
50         @JsonProperty("message")
51         private Message message;
52
53         @JsonProperty("target")
54         public String getTarget() {
55                 return target;
56         }
57
58         @JsonProperty("target")
59         public void setTarget(String target) {
60                 this.target = target;
61         }
62
63         @JsonProperty("origin")
64         public String getOrigin() {
65                 return origin;
66         }
67
68         @JsonProperty("origin")
69         public void setOrigin(String origin) {
70                 this.origin = origin;
71         }
72
73         @JsonProperty("messageType")
74         public String getMessageType() {
75                 return messageType;
76         }
77
78         @JsonProperty("messageType")
79         public void setMessageType(String messageType) {
80                 this.messageType = messageType;
81         }
82
83         @JsonProperty("topic")
84         public String getTopic() {
85                 return topic;
86         }
87
88         @JsonProperty("topic")
89         public void setTopic(String topic) {
90                 this.topic = topic;
91         }
92
93         @JsonProperty("message")
94         public Message getMessage() {
95                 return message;
96         }
97
98         @JsonProperty("message")
99         public void setMessage(Message message) {
100                 this.message = message;
101         }
102         
103         private static ObjectInspectorPayload lic;
104         public static ObjectInspectorPayload getOIPayload(SubscriptionConfig subscriptionConf) throws JsonParseException, JsonMappingException, IOException{
105                 if(lic == null){
106                         ObjectMapper mapper = new ObjectMapper();
107                         lic = mapper.readValue(new File(SparkyConstants.SUBSCRIPTION_OI_MAPPING), ObjectInspectorPayload.class);
108                         lic.intitializeOIPayload(subscriptionConf);
109                 }
110                 
111                 return lic;
112         }
113         
114         private void intitializeOIPayload(SubscriptionConfig subscriptionConf) {
115                 try {
116                         lic.setOrigin(subscriptionConf.getLaunchOIOrigin());
117                         lic.setTarget(subscriptionConf.getLaunchOITarget());
118                         lic.setTopic(subscriptionConf.getLaunchOITopic());
119                         lic.setMessageType(subscriptionConf.getLaunchOIMessageType());
120                 } catch (Exception e) {
121                         // TODO Auto-generated catch block
122                         e.printStackTrace();
123                 } 
124                 
125         }
126 }