Skip to content

Commit 2edec13

Browse files
author
Joerg Huber
committed
Initial submission.
1 parent dfe352f commit 2edec13

4 files changed

Lines changed: 352 additions & 0 deletions

File tree

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
/*
2+
* NamedQueryConsumer.java
3+
* Created: 11 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+
/**
21+
* This interface defines the various methods that form part of SIF 3.x for a named query consumer. Note that the named
22+
* query consumer really only has the "retrieve" method available but to fit this interface with the core functionality
23+
* of the SIF3 framework it must extend the MinimalConsumer. The MinimalConsumer enforces the "retrievByPrimaryKey" and
24+
* the "getServiceInfo" method. Both of these are NOT applicable for named query services and can be nulled out by the
25+
* implementation of this interface.
26+
*
27+
* @author Joerg Huber
28+
*/
29+
public interface NamedQueryConsumer extends MinimalConsumer
30+
{
31+
32+
}
Lines changed: 115 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
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+
}
Lines changed: 126 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,126 @@
1+
/*
2+
* QueryTemplateInfo.java
3+
* Created: 22 Nov 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.model;
19+
20+
import java.io.Serializable;
21+
import java.util.HashMap;
22+
23+
/**
24+
* This class abstracts the information required for XQUERYTEMPLATE services. These services require a name of a
25+
* named query and an optional list of parameters. A parameter is a simple attribute/value pair. These query parameters and
26+
* the query name are translated into URL query parameters as part of the actual XQUERYTEMPLATE service call and therefore
27+
* are case-sensitive as per HTTP specification.
28+
*
29+
* @author Joerg Huber
30+
*/
31+
public class QueryTemplateInfo implements Serializable
32+
{
33+
private static final long serialVersionUID = 6698207359734736517L;
34+
35+
private String queryName = null;
36+
private HashMap<String, String> queryParameters = new HashMap<String, String>();
37+
38+
public QueryTemplateInfo()
39+
{
40+
this(null, null);
41+
}
42+
43+
public QueryTemplateInfo(String queryName)
44+
{
45+
this(queryName, null);
46+
}
47+
48+
/**
49+
* Note that the values in the queryParameters are a hashmap. The name of the query parameter is the key into the hashmap
50+
* and the value of the parameter is the value in the hashmap.
51+
*
52+
* @param queryName The name of the XQUERYTEMPLATE service.
53+
* @param queryParameters Hashmap of parameters. ParameterName=KEY, ParameterValue=VALUE
54+
*/
55+
public QueryTemplateInfo(String queryName, HashMap<String, String> queryParameters)
56+
{
57+
super();
58+
setQueryName(queryName);
59+
setQueryParameters(queryParameters);
60+
}
61+
62+
public String getQueryName()
63+
{
64+
return queryName;
65+
}
66+
67+
public void setQueryName(String queryName)
68+
{
69+
this.queryName = queryName;
70+
}
71+
72+
public HashMap<String, String> getQueryParameters()
73+
{
74+
return queryParameters;
75+
}
76+
77+
public void setQueryParameters(HashMap<String, String> queryParameters)
78+
{
79+
if (queryParameters != null)
80+
{
81+
this.queryParameters = queryParameters;
82+
}
83+
}
84+
85+
/**
86+
* This method will add a parameter to the list of Query Parameters. If a query parameter with the given name already exists
87+
* it will be overwritten with the value of parameterValue parameter. If the parameterName is empty or null then no
88+
* action is taken.
89+
*
90+
* @param parameterName The name of the query parameter
91+
* @param parameterValue The value of the query parameter
92+
*/
93+
public void addQueryParameter(String parameterName, String parameterValue)
94+
{
95+
getQueryParameters().put(parameterName, parameterValue);
96+
}
97+
98+
/**
99+
* This method returns the value of the given query parameter. If no parameter with the given value exists then null is
100+
* returned.
101+
*
102+
* @param parameterName Name of the query parameter for which the value shall be returned.
103+
*
104+
* @return See desc.
105+
*/
106+
public String getQueryParameterValue(String parameterName)
107+
{
108+
return getQueryParameters().get(parameterName);
109+
}
110+
111+
/**
112+
* This method removes the given query parameter. If no parameter with the given value exists then no action is performed.
113+
*
114+
* @param parameterName Name of the query parameter to be removed.
115+
*/
116+
public void removeQueryParamter(String parameterName)
117+
{
118+
getQueryParameters().remove(parameterName);
119+
}
120+
121+
@Override
122+
public String toString()
123+
{
124+
return "QueryTemplateInfo [queryName=" + queryName + ", queryParameters=" + queryParameters + "]";
125+
}
126+
}
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
/*
2+
* StringPayload.java
3+
* Created: 11 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.model;
19+
20+
import java.io.Serializable;
21+
22+
import javax.ws.rs.core.MediaType;
23+
24+
/**
25+
* This class encapsulates typical data that is passed from/to an end-point where little is known about the actual object.
26+
* There are many places in the SIF Specification where any data can be passed around not just data defined in the SIF
27+
* Data Model. Such data can be passed in a payload for a request or a response. For these services (eg. phases of a functional
28+
* service or responses to a named queries) the framework must support as data model agnostic representation of a payload.
29+
* This class enables data to be passed around in its raw String representation with the applicable mime type, so that the
30+
* recipient of the data knows how what it deals with. It is the responsibility of the recipient of such a "string" payload
31+
* to marshal it into a known data structure using the given mime type.
32+
*
33+
* @author Joerg Huber
34+
*/
35+
public class StringPayload implements Serializable
36+
{
37+
private static final long serialVersionUID = 7279610736312134859L;
38+
39+
private String data = null;
40+
private MediaType mimeType = null;
41+
42+
public StringPayload()
43+
{
44+
this(null, null);
45+
}
46+
47+
public StringPayload(String data, MediaType mimeType)
48+
{
49+
super();
50+
this.data = data;
51+
this.mimeType = mimeType;
52+
}
53+
54+
public String getData()
55+
{
56+
return data;
57+
}
58+
59+
public void setData(String data)
60+
{
61+
this.data = data;
62+
}
63+
64+
public MediaType getMimeType()
65+
{
66+
return mimeType;
67+
}
68+
69+
public void setMimeType(MediaType mimeType)
70+
{
71+
this.mimeType = mimeType;
72+
}
73+
74+
@Override
75+
public String toString()
76+
{
77+
return "StringPayload [data=" + data + ", mimeType=" + mimeType + "]";
78+
}
79+
}

0 commit comments

Comments
 (0)