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.client.samples.notification;
15  
16  import uk.nhs.interoperability.consumer.AbstractRoutedMessageServlet;
17  import uk.nhs.interoperability.consumer.ITKMessageConsumer;
18  import uk.nhs.interoperability.infrastructure.ITKMessagingException;
19  import uk.nhs.interoperability.payload.ITKMessage;
20  import uk.nhs.interoperability.util.Logger;
21  
22  /**
23   * The Class NotificationRepository.
24   *
25   * @author Adam Hatherly
26   * @since 0.1
27   */
28  public class NotificationRepository extends AbstractRoutedMessageServlet implements ITKMessageConsumer {
29  	
30  	/** The Constant serialVersionUID. */
31  	private static final long serialVersionUID = -541728545823668074L;
32  
33  	/* (non-Javadoc)
34  	 * @see uk.nhs.interoperability.consumer.ITKMessageConsumer#onMessage(uk.nhs.interoperability.payload.ITKMessage)
35  	 */
36  	@Override
37  	public void onMessage(ITKMessage request) {
38  		Logger.trace("This is Notification Repository receiving a message:onMessage()");
39  		String docId = request.getMessageProperties().getBusinessPayloadId();
40  		if (docId.substring(0,5).equals("uuid_")){
41  			docId = docId.substring(5);
42  		}
43  		NotificationStore.putNotification(docId, request.getBusinessPayload());
44  		Logger.trace("added notification "+docId+" to repository.");
45  		
46  		// NOTE : BUSINESS ACKS ARE NOT SUPPORTED BY THIS VERSION
47  	}
48  
49  	/* (non-Javadoc)
50  	 * @see uk.nhs.interoperability.consumer.AbstractRoutedMessageServlet#getMessageConsumer()
51  	 */
52  	@Override
53  	public ITKMessageConsumer getMessageConsumer() {
54  		return this;
55  	}
56  
57  	/**
58  	 * Routed messages do not support true synchronous responses.
59  	 *
60  	 * @param request the request
61  	 * @return the iTK message
62  	 * @throws ITKMessagingException the iTK messaging exception
63  	 */
64  	@Override
65  	public ITKMessage onSyncMessage(ITKMessage request)	throws ITKMessagingException {
66  		throw new ITKMessagingException(ITKMessagingException.INVALID_MESSAGE_CODE, "Synchronous execution not supported");
67  	}
68  
69  }