View Javadoc

1   /*
2      Licensed under the Apache License, Version 2.0 (the "License");
3      you may not use this file except in compliance with the License.
4      You may obtain a copy of the License at
5   
6        http://www.apache.org/licenses/LICENSE-2.0
7   
8      Unless required by applicable law or agreed to in writing, software
9      distributed under the License is distributed on an "AS IS" BASIS,
10     WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11     See the License for the specific language governing permissions and
12     limitations under the License.
13  */
14  package uk.nhs.interoperability.payload;
15  
16  import uk.nhs.interoperability.infrastructure.ITKIdentityImpl;
17  import uk.nhs.interoperability.infrastructure.ITKMessageProperties;
18  import uk.nhs.interoperability.infrastructure.ITKMessagePropertiesImpl;
19  import uk.nhs.interoperability.transport.ITKTransportProperties;
20  import uk.nhs.interoperability.transport.ITKTransportRoute;
21  import uk.nhs.interoperability.util.Logger;
22  
23  /**
24   * The Class ITKMessageImpl.
25   *
26   * @author Michael Odling-Smee
27   * @author Nicholas Jones
28   * @since 0.1
29   */
30  public abstract class ITKMessageImpl implements ITKMessage {
31  
32  	/** The message properties. */
33  	protected ITKMessageProperties messageProperties;
34  	
35  	/** The business payload. */
36  	protected String businessPayload;
37  	
38  	/** The is response. */
39  	protected boolean isResponse;
40  	
41  	/** The pre resolved transport route. */
42  	protected ITKTransportRoute preResolvedTransportRoute;
43  
44  	/* (non-Javadoc)
45  	 * @see uk.nhs.interoperability.payload.ITKMessage#getBusinessPayload()
46  	 */
47  	public String getBusinessPayload() {
48  		return businessPayload;
49  	}
50  	
51  	/* (non-Javadoc)
52  	 * @see uk.nhs.interoperability.payload.ITKMessage#setBusinessPayload(java.lang.String)
53  	 */
54  	public void setBusinessPayload(String businessPayload) {
55  		this.businessPayload = businessPayload;
56  	}
57  	
58  	/**
59  	 * Instantiates a new iTK message impl.
60  	 */
61  	public ITKMessageImpl() {
62  		
63  	}
64  	
65  	/**
66  	 * Instantiates a new iTK message impl.
67  	 *
68  	 * @param itkMessageProperties the itk message properties
69  	 */
70  	public ITKMessageImpl(ITKMessageProperties itkMessageProperties) {
71  		this(itkMessageProperties, null, null, false);
72  	}
73  	
74  	/**
75  	 * Instantiates a new iTK message impl.
76  	 *
77  	 * @param itkMessageProperties the itk message properties
78  	 * @param auditIdentity the audit identity
79  	 * @param profileId the profile id
80  	 * @param reflectMessageProperties the reflect message properties
81  	 */
82  	public ITKMessageImpl(ITKMessageProperties itkMessageProperties, String auditIdentity, String profileId, boolean reflectMessageProperties) {
83  		if (reflectMessageProperties) {
84  			//Reflect the messageProperties as we assume they have come from the request
85  			ITKMessageProperties msgProperties = new ITKMessagePropertiesImpl();
86  			msgProperties.setAuditIdentity(new ITKIdentityImpl(auditIdentity));
87  			//Reflect some values from the request
88  			msgProperties.setFromAddress(itkMessageProperties.getToAddress());
89  			msgProperties.setToAddress(itkMessageProperties.getFromAddress());
90  			String responseServiceId = itkMessageProperties.getServiceId() + "Response";
91  			msgProperties.setServiceId(responseServiceId);
92  			msgProperties.setProfileId(profileId);
93  			//Attach the transport properties from the corresponding request
94  			msgProperties.setInboundTransportProperties(itkMessageProperties.getInboundTransportProperties());
95  			//If transport properties are not null set up the pre-resolved transport route
96  			ITKTransportProperties itkTransportProperties = itkMessageProperties.getInboundTransportProperties();
97  			if (itkTransportProperties != null) {
98  				Logger.trace("Obtaining transport route from inbound transport properties");
99  				this.preResolvedTransportRoute = itkMessageProperties.getInboundTransportProperties().getTransportReplyToRoute();
100 				if (preResolvedTransportRoute != null) {
101 					/*
102 					 * TODO - this perhaps should be driven by configuration but by default setting it so that Distribution
103 					 * Envelope is added to the message when being sent.
104 					 */
105 					this.preResolvedTransportRoute.setWrapperType(ITKTransportRoute.DISTRIBUTION_ENVELOPE);
106 					Logger.trace("Pre-resolved route: " + this.preResolvedTransportRoute);
107 				}
108 			}
109 			this.messageProperties = msgProperties;
110 			this.setIsReponse(true);
111 		} else {
112 			this.messageProperties = itkMessageProperties;
113 		}
114 	}
115 
116 	/* (non-Javadoc)
117 	 * @see uk.nhs.interoperability.payload.ITKMessage#getMessageProperties()
118 	 */
119 	public ITKMessageProperties getMessageProperties() {
120 		return messageProperties;
121 	}
122 	
123 	/* (non-Javadoc)
124 	 * @see uk.nhs.interoperability.payload.ITKMessage#setMessageProperties(uk.nhs.interoperability.infrastructure.ITKMessageProperties)
125 	 */
126 	public void setMessageProperties(ITKMessageProperties messageProperties) {
127 		this.messageProperties = messageProperties;
128 	}
129 	
130 	/* (non-Javadoc)
131 	 * @see uk.nhs.interoperability.payload.ITKMessage#getPreresolvedRoute()
132 	 */
133 	@Override
134 	public ITKTransportRoute getPreresolvedRoute() {
135 		return this.preResolvedTransportRoute;
136 	}
137 	
138 	/* (non-Javadoc)
139 	 * @see uk.nhs.interoperability.payload.ITKMessage#isResponse()
140 	 */
141 	@Override
142 	public boolean isResponse() {
143 		return this.isResponse;
144 	}
145 	
146 	/**
147 	 * Sets the checks if is reponse.
148 	 *
149 	 * @param isReponse the new checks if is reponse
150 	 */
151 	public void setIsReponse(boolean isReponse) {
152 		this.isResponse = isReponse;
153 	}
154 }