public class AbstractRestBean extends Object
| Modifier and Type | Class and Description |
|---|---|
protected static class |
AbstractRestBean.CacheKey |
| Modifier and Type | Field and Description |
|---|---|
protected org.infinispan.Cache<AbstractRestBean.CacheKey,Object> |
cache |
protected org.rhq.core.domain.auth.Subject |
caller
Subject of the caller that gets injected via
SetCallerInterceptor |
protected org.apache.commons.logging.Log |
log |
protected ResourceManagerLocal |
resMgr |
protected ResourceGroupManagerLocal |
resourceGroupManager |
protected String |
wrappedCollectionJson |
protected javax.ws.rs.core.MediaType |
wrappedCollectionJsonType |
| Constructor and Description |
|---|
AbstractRestBean() |
| Modifier and Type | Method and Description |
|---|---|
protected void |
createPagingHeader(javax.ws.rs.core.Response.ResponseBuilder builder,
javax.ws.rs.core.UriInfo uriInfo,
org.rhq.core.domain.util.PageList<?> resultList)
Create the paging headers for collections and attach them to the passed builder.
|
protected Link |
createUILink(javax.ws.rs.core.UriInfo uriInfo,
UILinkTemplate template,
Integer... entityId)
Creates a link to the respective entry in coregui
|
protected org.rhq.core.domain.resource.group.ResourceGroup |
fetchGroup(int groupId,
boolean requireCompatible)
Fetch the group with the passed id
|
protected org.rhq.core.domain.resource.Resource |
fetchResource(int resourceId) |
protected GroupRest |
fillGroup(org.rhq.core.domain.resource.group.ResourceGroup group,
javax.ws.rs.core.UriInfo uriInfo) |
ResourceWithType |
fillRWT(org.rhq.core.domain.resource.Resource res,
javax.ws.rs.core.UriInfo uriInfo) |
protected <T> T |
getFromCache(AbstractRestBean.CacheKey key,
Class<T> clazz)
Retrieve an object from the cache if present or null otherwise.
|
protected <T> T |
getFromCache(int id,
Class<T> clazz)
Retrieve an object from the cache.
|
protected Link |
getLinkToGroup(org.rhq.core.domain.resource.group.ResourceGroup group,
javax.ws.rs.core.UriInfo uriInfo,
String rel) |
protected Link |
getLinkToResource(org.rhq.core.domain.resource.Resource res,
javax.ws.rs.core.UriInfo uriInfo,
String rel) |
protected Link |
getLinkToResourceType(org.rhq.core.domain.resource.ResourceType type,
javax.ws.rs.core.UriInfo uriInfo,
String rel) |
protected MetricSchedule |
getMetricScheduleInternal(javax.ws.rs.core.UriInfo uriInfo,
org.rhq.core.domain.measurement.MeasurementSchedule schedule,
org.rhq.core.domain.measurement.MeasurementDefinition definition) |
protected <T> javax.ws.rs.core.Response.ResponseBuilder |
paginate(javax.ws.rs.core.HttpHeaders headers,
javax.ws.rs.core.UriInfo uriInfo,
org.rhq.core.domain.util.PageList<?> pageList,
List<T> results,
Class<T> elementType)
Creates a response builder with "ok" response containing the provided list and applied pagination
as prescribed by the
pageList. |
protected <T> boolean |
putToCache(AbstractRestBean.CacheKey key,
T o)
Put an object into the cache.
|
protected <T> boolean |
putToCache(int id,
Class<T> clazz,
T o)
Put an object into the cache identified by its type and id
|
protected <T> boolean |
removeFromCache(int id,
Class<T> clazz)
Remove an item from the cache
|
protected String |
renderTemplate(String templateName,
Object objectToRender)
Renders the passed object with the help of a freemarker template into a string.
|
protected void |
setCachingHeader(javax.ws.rs.core.Response.ResponseBuilder builder,
int maxAgeSecs)
Set the caching header on the response
|
void |
start() |
protected javax.ws.rs.core.Response.ResponseBuilder |
withMediaType(javax.ws.rs.core.Response.ResponseBuilder builder,
javax.ws.rs.core.HttpHeaders headers) |
protected <T> void |
wrapForPaging(javax.ws.rs.core.Response.ResponseBuilder builder,
javax.ws.rs.core.UriInfo uriInfo,
org.rhq.core.domain.util.PageList<?> originalList,
Collection<T> resultList)
Wrap the passed collection #resultList in an object with paging information
If you need no further "building" of the response apart from paginating, you should look into using
the
paginate(javax.ws.rs.core.HttpHeaders, javax.ws.rs.core.UriInfo, org.rhq.core.domain.util.PageList,
java.util.List, Class). |
protected org.apache.commons.logging.Log log
protected final javax.ws.rs.core.MediaType wrappedCollectionJsonType
protected final String wrappedCollectionJson
protected org.infinispan.Cache<AbstractRestBean.CacheKey,Object> cache
protected org.rhq.core.domain.auth.Subject caller
SetCallerInterceptorprotected ResourceManagerLocal resMgr
protected ResourceGroupManagerLocal resourceGroupManager
@PostConstruct public void start()
protected String renderTemplate(String templateName, Object objectToRender)
templateName - Template to use for rendering. If the template name does not end in .ftl, .ftl is appended.objectToRender - Object to render via templateprotected <T> T getFromCache(int id,
Class<T> clazz)
id - Id of the object to load.clazz - Wanted return typegetFromCache(int, Class)protected <T> T getFromCache(AbstractRestBean.CacheKey key, Class<T> clazz)
key - FullyQualified name (=path in cache) of the object to retrieveclazz - Return typeputToCache(CacheKey, Object)protected <T> boolean putToCache(int id,
Class<T> clazz,
T o)
id - Id of the object to putclazz - Type to put ino - Object to putputToCache(CacheKey, Object)protected <T> boolean putToCache(AbstractRestBean.CacheKey key, T o)
key - Fully qualified name (=path to object)o - Object to putgetFromCache(CacheKey, Class)protected <T> boolean removeFromCache(int id,
Class<T> clazz)
id - Id of the itemclazz - Type of object for that nodepublic ResourceWithType fillRWT(org.rhq.core.domain.resource.Resource res, javax.ws.rs.core.UriInfo uriInfo)
protected Link getLinkToResource(org.rhq.core.domain.resource.Resource res, javax.ws.rs.core.UriInfo uriInfo, String rel)
protected Link getLinkToResourceType(org.rhq.core.domain.resource.ResourceType type, javax.ws.rs.core.UriInfo uriInfo, String rel)
protected Link getLinkToGroup(org.rhq.core.domain.resource.group.ResourceGroup group, javax.ws.rs.core.UriInfo uriInfo, String rel)
protected org.rhq.core.domain.resource.Resource fetchResource(int resourceId)
protected javax.ws.rs.core.Response.ResponseBuilder withMediaType(javax.ws.rs.core.Response.ResponseBuilder builder,
javax.ws.rs.core.HttpHeaders headers)
protected <T> javax.ws.rs.core.Response.ResponseBuilder paginate(javax.ws.rs.core.HttpHeaders headers,
javax.ws.rs.core.UriInfo uriInfo,
org.rhq.core.domain.util.PageList<?> pageList,
List<T> results,
Class<T> elementType)
pageList.T - the type of the entities contained in the result listheaders - the http headersuriInfo - uri infopageList - the "original" list coming from the EJB layer containing the paging inforesults - the result list with REST-ready entitieselementType - the type of the entities contained in the result listprotected void createPagingHeader(javax.ws.rs.core.Response.ResponseBuilder builder,
javax.ws.rs.core.UriInfo uriInfo,
org.rhq.core.domain.util.PageList<?> resultList)
paginate(javax.ws.rs.core.HttpHeaders, javax.ws.rs.core.UriInfo, org.rhq.core.domain.util.PageList,
java.util.List, Class).builder - The ResponseBuilder that receives the headersuriInfo - The uriInfo of the incoming request to build the urlsresultList - The collection with its paging informationprotected <T> void wrapForPaging(javax.ws.rs.core.Response.ResponseBuilder builder,
javax.ws.rs.core.UriInfo uriInfo,
org.rhq.core.domain.util.PageList<?> originalList,
Collection<T> resultList)
paginate(javax.ws.rs.core.HttpHeaders, javax.ws.rs.core.UriInfo, org.rhq.core.domain.util.PageList,
java.util.List, Class).builder - ResonseBuilder to add the entity touriInfo - UriInfo to construct paging linksoriginalList - The original list to obtain the paging info fromresultList - The list of result itemsprotected org.rhq.core.domain.resource.group.ResourceGroup fetchGroup(int groupId,
boolean requireCompatible)
groupId - id of the resource grouprequireCompatible - Does the group have to be a compatible group?StuffNotFoundException - if the group is not found (or not accessible by the caller)BadArgumentException - if a compatible group is required, but the found one is not a compatible oneprotected GroupRest fillGroup(org.rhq.core.domain.resource.group.ResourceGroup group, javax.ws.rs.core.UriInfo uriInfo)
protected Link createUILink(javax.ws.rs.core.UriInfo uriInfo, UILinkTemplate template, Integer... entityId)
uriInfo - The uriInfo object to build the final url fromtemplate - Template to useentityId - Ids of the various entities used in the templateprotected MetricSchedule getMetricScheduleInternal(javax.ws.rs.core.UriInfo uriInfo, org.rhq.core.domain.measurement.MeasurementSchedule schedule, org.rhq.core.domain.measurement.MeasurementDefinition definition)
protected void setCachingHeader(javax.ws.rs.core.Response.ResponseBuilder builder,
int maxAgeSecs)
builder - Response builder to put the caching header onmaxAgeSecs - Max retention time on the client. Only set if the value is > 0Copyright © 2008-2014 Red Hat, Inc.. All Rights Reserved.