|
| 1 | +/* |
| 2 | + * NamedQueryProvider.java |
| 3 | + * Created: 4 Dec 2018 |
| 4 | + * |
| 5 | + * Copyright 2018 Systemic Pty Ltd |
| 6 | + * |
| 7 | + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except |
| 8 | + * in compliance with the License. You may obtain a copy of the License at |
| 9 | + * |
| 10 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 11 | + * |
| 12 | + * Unless required by applicable law or agreed to in writing, software distributed under the License |
| 13 | + * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express |
| 14 | + * or implied. See the License for the specific language governing permissions and limitations under |
| 15 | + * the License. |
| 16 | + */ |
| 17 | + |
| 18 | +package sif3.common.interfaces; |
| 19 | + |
| 20 | +import javax.ws.rs.core.MediaType; |
| 21 | + |
| 22 | +import sif3.common.exception.DataTooLargeException; |
| 23 | +import sif3.common.exception.PersistenceException; |
| 24 | +import sif3.common.exception.SIFException; |
| 25 | +import sif3.common.exception.UnsupportedMediaTypeExcpetion; |
| 26 | +import sif3.common.model.PagingInfo; |
| 27 | +import sif3.common.model.QueryTemplateInfo; |
| 28 | +import sif3.common.model.RequestMetadata; |
| 29 | +import sif3.common.model.ResponseParameters; |
| 30 | +import sif3.common.model.SIFContext; |
| 31 | +import sif3.common.model.SIFZone; |
| 32 | +import sif3.common.model.StringPayload; |
| 33 | + |
| 34 | +/** |
| 35 | + * This class defines the methods a named query service provider (service type = XQUERYTEMPLATE) must implement to fit |
| 36 | + * with this framework. It defines the core function SIF3 specifies for a name query service provider.<br/> |
| 37 | + * Note that each method has a number of parameters but they all have the following three given parameters. The zone, |
| 38 | + * the context and metadata. The first two relate to the standard SIF concept of zone and context. The metadata parameter |
| 39 | + * however is additional info that may be provided by a consumer with each request. This can be typical HTTP header |
| 40 | + * fields such as generatorId, queryIntention etc. Please refer to the SIF 3 Infrastructure Service documentation what |
| 41 | + * these fields mean as well as where they might be used. It is important to note that most of the properties in the |
| 42 | + * metadata could be null and therefore implementations must take care how they are used.<br/> |
| 43 | + * The named query service is a "query" only service. It doesn't support create, update or delete operations and no |
| 44 | + * event functionality is availble either.<br/><br/> |
| 45 | + * |
| 46 | + * Note:<br/> |
| 47 | + * Because this framework used to run under Java 6 some of the types in various methods use "Object" instead of the template |
| 48 | + * notation. This is because Java 6 doesn't allow a 'new T()' and therefore the interface avoids the template notation to not break |
| 49 | + * the implementation where a constructor for an Object might be required. This may change in future versions of the framework. |
| 50 | + * Further it requires some objects form the Infrastructure data model but the sif3-infra-model module is not available in this |
| 51 | + * common module the type 'Object' is used in a couple of places. Please refer to the documentation of the appropriate method |
| 52 | + * for more details on what exact type shall be expected in these methods. |
| 53 | + * |
| 54 | + * @author Joerg Huber |
| 55 | + */ |
| 56 | +public interface NamedQueryProvider extends DataModelLink |
| 57 | +{ |
| 58 | + /** |
| 59 | + * This method is used to retrieve data for a named query service. This can be any data. It is up to the implementation of |
| 60 | + * the named query service to know what data to be returned. This framework is agnostic to that data. The returned |
| 61 | + * value is a String that must represent the "marshalled" version of the data in the format indicated by the "returnMimeType". |
| 62 | + * Because the data that can be returned as part of this method might be a collection, the paging parameter should be |
| 63 | + * provided. If the data to be returned is considered too large by the provider (implementation dependent) then a |
| 64 | + * DataTooLargeException must be raised. This exception is then translated into an appropriate HTTP Status within the |
| 65 | + * framework to meet the SIF Specification. |
| 66 | + * |
| 67 | + * @param queryTemplateInfo Hold the queryTemplateInfo.queryName holds the name of the "named query" to be executed. The |
| 68 | + * queryTemplateInfo.queryParameters holds ALL URL query parameter the consumer has provided. |
| 69 | + * It is up to the implementation class to inspect and use them accordingly. Since it holds ALL |
| 70 | + * URL query parameter this list may also hold URL query parameters not related to the actual |
| 71 | + * query parameters. |
| 72 | + * @param zone The Zone from which the request is being issued. Can be Null (default Zone) |
| 73 | + * @param context The Context for which the data shall be returned. Can be Null (default Zone) |
| 74 | + * @param pagingInfo Page information to determine which results to return. Null = Return all (NOT RECOMMENDED!). |
| 75 | + * @param metadata Metadata relating to the request. Note that most of the properties might be null. |
| 76 | + * @param customResponseParams Values to be returned as part of the response. These are generally just HTTP Header fields. If a developer |
| 77 | + * sets the HTTP Header of a well defined SIF3 HTTP Header (i.e. providerId, timestamp) then the framework |
| 78 | + * may override these with its own value to ensure the correct use and workings of the framework. It is the |
| 79 | + * developer who will populate the object. When it is passed to this method it not null but empty. |
| 80 | + * @param returnMimeType The mime type the response data is in. It is expected that the consumer provides that and the provider |
| 81 | + * should attempt to marshal the data to the given mime type and return the resulting string as |
| 82 | + * part of this call. If the provider cannot marshal the data to the requested mime type then an |
| 83 | + * UnsupportedMediaTypeExcpetion must be raised. |
| 84 | + * |
| 85 | + * @return The response data (result set) with its mime type. It can be null indicating no or no further data available. |
| 86 | + * The returned string should be the marshalled value of the result set and it should be in the mime type as |
| 87 | + * indicated in the returnMimeType parameter. The status of the return value will be set by the framework and will be |
| 88 | + * either HTTP 200 (OK) when data is returned or HTTP 204 (No Content) if there is no further data available. |
| 89 | + * |
| 90 | + * @throws UnsupportedMediaTypeExcpetion The provider cannot support the requested return media type. |
| 91 | + * @throws PersistenceException Persistence Store could not be accessed successfully. An error log entry is performed and the |
| 92 | + * message of the exceptions holds some info. |
| 93 | + * @throws DataTooLargeException If the data that shall be returned is too large due to the values in the paging info. |
| 94 | + * @throws SIFException Any other exception the implementation of that class wants to throw. This will be translated into proper |
| 95 | + * SIF Error message that will be returned to the consumer. |
| 96 | + */ |
| 97 | + public StringPayload retrieveData(QueryTemplateInfo queryTemplateInfo, |
| 98 | + SIFZone zone, |
| 99 | + SIFContext context, |
| 100 | + PagingInfo pagingInfo, |
| 101 | + RequestMetadata metadata, |
| 102 | + ResponseParameters customResponseParams, |
| 103 | + MediaType returnMimeType) |
| 104 | + throws PersistenceException, UnsupportedMediaTypeExcpetion, DataTooLargeException, SIFException; |
| 105 | + |
| 106 | + /*-------------------------------*/ |
| 107 | + /*-- Other required Operations --*/ |
| 108 | + /*-------------------------------*/ |
| 109 | + |
| 110 | + /** |
| 111 | + * This method is called when a provider shuts down. Can be used to clean-up internally held resources etc. |
| 112 | + */ |
| 113 | + public void finalise(); |
| 114 | + |
| 115 | +} |
0 commit comments