Merge of new rebased code
[appc.git] / appc-event-listener / appc-event-listener-bundle / src / main / java / org / openecomp / appc / listener / demo / model / IncomingMessage.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * openECOMP : APP-C
4  * ================================================================================
5  * Copyright (C) 2017 AT&T Intellectual Property. All rights
6  *                                              reserved.
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
22 package org.openecomp.appc.listener.demo.model;
23
24 import com.fasterxml.jackson.annotation.JsonIgnore;
25 import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
26 import com.fasterxml.jackson.annotation.JsonProperty;
27 import com.fasterxml.jackson.databind.annotation.JsonSerialize;
28 import com.fasterxml.jackson.databind.annotation.JsonSerialize.Inclusion;
29
30 /**
31  * This class represents a message coming in from DCAE.
32  *
33  */
34 @JsonSerialize(include = Inclusion.NON_NULL)
35 @JsonIgnoreProperties(ignoreUnknown = true)
36 public class IncomingMessage extends CommonMessage {
37
38     private static final long serialVersionUID = 1L;
39
40     /*
41      * The action being requested. Its presence signals that it is an incoming message and it is not present on outgoing
42      * messages
43      */
44     //TODO; use enum
45     @JsonProperty("Action")
46     private String action;
47
48
49     public String getRequest() {
50         return action;
51     }
52
53     @JsonIgnore
54     public Action getAction() {
55         return Action.toAction(action);
56     }
57
58     public void setRequest(String request) {
59         this.action = request;
60     }
61
62 //    @Override
63 //    public String toString() {
64 //        String time = getRequestTime() != null ? getRequestTime() : "N/A";
65 //        // String req = request != null ? request : "N/A";
66 //        return String.format("[%s - %s]", time, getId());
67 //    }
68
69 //    public String toOutgoing(Status status) {
70 //        return toOutgoing(status);
71 //    }
72
73     public String toOutgoing(Status status) {
74         OutgoingMessage out = new OutgoingMessage(this);
75         out.setResponse(status);
76         return out.toResponse().toString();
77     }
78
79     /**
80      * Determines if this message should be parsed parsed. Will eventually check that the message is well formed, has
81      * all required fields, and had not exceeded any timing restrictions.
82      *
83      * @return True if the message should be parsed. False otherwise
84      */
85     public boolean isValid() {
86         return true;
87     }
88 }