Update license and poms
[aai/sparky-be.git] / sparkybe-onap-service / src / main / java / org / onap / aai / sparky / subscription / payload / entity / ObjectInspectorPayload.java
1 /**
2  * ============LICENSE_START=======================================================
3  * org.onap.aai
4  * ================================================================================
5  * Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved.
6  * Copyright © 2017-2018 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 package org.onap.aai.sparky.subscription.payload.entity;
22
23 import java.io.File;
24 import java.io.IOException;
25
26 import org.onap.aai.sparky.subscription.config.SubscriptionConfig;
27 import org.onap.aai.sparky.viewandinspect.config.SparkyConstants;
28
29 import com.fasterxml.jackson.annotation.JsonInclude;
30 import com.fasterxml.jackson.annotation.JsonProperty;
31 import com.fasterxml.jackson.annotation.JsonPropertyOrder;
32 import com.fasterxml.jackson.core.JsonParseException;
33 import com.fasterxml.jackson.databind.JsonMappingException;
34 import com.fasterxml.jackson.databind.ObjectMapper;
35
36 @JsonInclude(JsonInclude.Include.NON_NULL)
37 @JsonPropertyOrder({ "target", "origin", "messageType", "topic", "message" })
38 public class ObjectInspectorPayload {
39
40         @JsonProperty("target")
41         private String target;
42         @JsonProperty("origin")
43         private String origin;
44         @JsonProperty("messageType")
45         private String messageType;
46         @JsonProperty("topic")
47         private String topic;
48         @JsonProperty("message")
49         private Message message;
50
51         @JsonProperty("target")
52         public String getTarget() {
53                 return target;
54         }
55
56         @JsonProperty("target")
57         public void setTarget(String target) {
58                 this.target = target;
59         }
60
61         @JsonProperty("origin")
62         public String getOrigin() {
63                 return origin;
64         }
65
66         @JsonProperty("origin")
67         public void setOrigin(String origin) {
68                 this.origin = origin;
69         }
70
71         @JsonProperty("messageType")
72         public String getMessageType() {
73                 return messageType;
74         }
75
76         @JsonProperty("messageType")
77         public void setMessageType(String messageType) {
78                 this.messageType = messageType;
79         }
80
81         @JsonProperty("topic")
82         public String getTopic() {
83                 return topic;
84         }
85
86         @JsonProperty("topic")
87         public void setTopic(String topic) {
88                 this.topic = topic;
89         }
90
91         @JsonProperty("message")
92         public Message getMessage() {
93                 return message;
94         }
95
96         @JsonProperty("message")
97         public void setMessage(Message message) {
98                 this.message = message;
99         }
100         
101         private static ObjectInspectorPayload lic;
102         public static ObjectInspectorPayload getOIPayload(SubscriptionConfig subscriptionConf) throws JsonParseException, JsonMappingException, IOException{
103                 if(lic == null){
104                         ObjectMapper mapper = new ObjectMapper();
105                         lic = mapper.readValue(new File(SparkyConstants.SUBSCRIPTION_OI_MAPPING), ObjectInspectorPayload.class);
106                         lic.intitializeOIPayload(subscriptionConf);
107                 }
108                 
109                 return lic;
110         }
111         
112         private void intitializeOIPayload(SubscriptionConfig subscriptionConf) {
113                 try {
114                         lic.setOrigin(subscriptionConf.getLaunchOIOrigin());
115                         lic.setTarget(subscriptionConf.getLaunchOITarget());
116                         lic.setTopic(subscriptionConf.getLaunchOITopic());
117                         lic.setMessageType(subscriptionConf.getLaunchOIMessageType());
118                 } catch (Exception e) {
119                         // TODO Auto-generated catch block
120                         e.printStackTrace();
121                 } 
122                 
123         }
124 }