com.fatwire.gst.foundation.facade.assetapi
Class AssetAccessTemplate

java.lang.Object
  extended by com.fatwire.gst.foundation.facade.assetapi.AssetAccessTemplate
Direct Known Subclasses:
MappedAssetAccessTemplate

public class AssetAccessTemplate
extends Object

This class is a one-stop-shop for all read-only access to AssetData. It acts as a helper class to facilitate AssetDataManager use in a simplified way in delivery ContentServer templates.

This class is inspired by springframework data access template classes like org.springframework.jdbc.core.JdbcTemplate.

This class is not thread safe and should not be shared between threads.

Since:
Nov 23, 2009
Author:
Dolf.Dijkstra

Constructor Summary
AssetAccessTemplate(COM.FutureTense.Interfaces.ICS ics)
          Constructor that accepts ICS as an argument.
AssetAccessTemplate(com.fatwire.system.Session session)
           
 
Method Summary
 com.fatwire.assetapi.data.AssetId createAssetId(String c, long cid)
          Helper method to create an AssetId from c and cid as string values.
 com.fatwire.assetapi.data.AssetId createAssetId(String c, String cid)
          Helper method to create an AssetId from c and cid as string values.
 com.fatwire.assetapi.query.SimpleQuery createNameQuery(String assetType, String assetName)
          Creates a Query to retrieve the asset by it's name.
 com.fatwire.assetapi.data.AssetId findByName(COM.FutureTense.Interfaces.ICS ics, String assetType, String name)
          Finds the assetid by the name of the asset.
 com.fatwire.assetapi.data.AssetId findByName(COM.FutureTense.Interfaces.ICS ics, String assetType, String name, long siteid)
          Finds the assetid by the name of the asset in a particular site.
protected  com.fatwire.assetapi.data.AssetDataManager getAssetDataManager()
           
<T> Iterable<T>
query(String assetType, String subType, String query, AssetMapper<T> mapper)
          Queries for a list of objects as mapped by the AssetMapper.
<T> Iterable<T>
query(String assetType, String subType, String query, AssetMapper<T> mapper, String... attributes)
          Queries for a list of objects as mapped by the AssetMapper.
 com.fatwire.assetapi.data.AssetData readAsset(com.fatwire.assetapi.data.AssetId id)
           
 void readAsset(com.fatwire.assetapi.data.AssetId id, AssetClosure closure)
          Method to read an asset and pass the results to the closure for further handling.
 void readAsset(com.fatwire.assetapi.data.AssetId id, AssetClosure closure, String... attributes)
          Method to read an asset and provide the AssetClosure with the AssetData.
<T> T
readAsset(com.fatwire.assetapi.data.AssetId id, AssetMapper<T> mapper)
          Method to read an asset and use the AssetMapper to transform the AssetData into another object as specified by the AssetMapper.
<T> T
readAsset(com.fatwire.assetapi.data.AssetId id, AssetMapper<T> mapper, String... attributes)
          Method to read an asset and use the AssetMapper to transform the AssetData into another object as specified by the AssetMapper.
 com.fatwire.assetapi.data.AssetData readAsset(com.fatwire.assetapi.data.AssetId id, String... attributes)
          Reads an asset based on the listed attribute names

TODO: do we need to load the attribute values and prevent access to non-listed attributes (prevent lazy loading)

 void readAsset(Iterable<com.fatwire.assetapi.data.AssetId> ids, AssetClosure closure, String... attributes)
          Method to read an asset and pass the results to the closure for further handling.
 void readAsset(List<com.fatwire.assetapi.data.AssetId> ids, AssetClosure closure)
          Method to read an asset and pass the results to the closure for further handling.
<T> T
readAsset(String c, long cid, AssetMapper<T> mapper)
          Method to read an asset and use the AssetMapper to transform the AssetData into another object as specified by the AssetMapper.
<T> T
readAsset(String c, String cid, AssetMapper<T> mapper)
          Method to read an asset and use the AssetMapper to transform the AssetData into another object as specified by the AssetMapper interface..
 Iterable<com.fatwire.assetapi.data.AssetData> readAssets(com.fatwire.assetapi.query.Query query)
           
 void readAssets(com.fatwire.assetapi.query.Query query, AssetClosure closure)
          Invokes the work(asset) method on the provided Closure for assets returned by the Query.
<T> Iterable<T>
readAssets(com.fatwire.assetapi.query.Query query, AssetMapper<T> mapper)
          Reading assets with the Query and using the mapper to transform the AssetData into another object, as specified by T.
 Collection<com.fatwire.assetapi.data.AssetId> readAssociatedAssetIds(com.fatwire.assetapi.data.AssetId id, String associationType)
          Reads the associated assets of the asset and returns the AssetIds.
 void readAssociatedAssets(com.fatwire.assetapi.data.AssetId id, String associationType, AssetClosure closure, String... attributes)
          Reads the associated assets of an asset and returns them as a ScatteredAsset.
 com.fatwire.assetapi.site.Site readSite(String name)
          Finds the Site object by the given name.
 com.fatwire.assetapi.site.SiteInfo readSiteInfo(String name)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

AssetAccessTemplate

public AssetAccessTemplate(com.fatwire.system.Session session)
Parameters:
session -

AssetAccessTemplate

public AssetAccessTemplate(COM.FutureTense.Interfaces.ICS ics)
Constructor that accepts ICS as an argument.

Parameters:
ics -
Method Detail

createAssetId

public com.fatwire.assetapi.data.AssetId createAssetId(String c,
                                                       String cid)
Helper method to create an AssetId from c and cid as string values.

Parameters:
c -
cid -
Returns:
the assetId for c/cid.

createAssetId

public com.fatwire.assetapi.data.AssetId createAssetId(String c,
                                                       long cid)
Helper method to create an AssetId from c and cid as string values.

Parameters:
c -
cid -
Returns:
the assetId for c/cid.

readAsset

public <T> T readAsset(com.fatwire.assetapi.data.AssetId id,
                       AssetMapper<T> mapper)
Method to read an asset and use the AssetMapper to transform the AssetData into another object as specified by the AssetMapper.

Type Parameters:
T -
Parameters:
id -
mapper -
Returns:
the Object created by the mapper.

readAsset

public <T> T readAsset(String c,
                       String cid,
                       AssetMapper<T> mapper)
Method to read an asset and use the AssetMapper to transform the AssetData into another object as specified by the AssetMapper interface..

Type Parameters:
T -
Parameters:
c - the assetType
cid - the asset id
mapper -
Returns:
the object created by the mapper.

readAsset

public <T> T readAsset(String c,
                       long cid,
                       AssetMapper<T> mapper)
Method to read an asset and use the AssetMapper to transform the AssetData into another object as specified by the AssetMapper.

Type Parameters:
T -
Parameters:
c - the assetType
cid - the asset id
mapper -
Returns:
the object created by the mapper.

readAsset

public <T> T readAsset(com.fatwire.assetapi.data.AssetId id,
                       AssetMapper<T> mapper,
                       String... attributes)
Method to read an asset and use the AssetMapper to transform the AssetData into another object as specified by the AssetMapper. Only the list of lister attributes is retrieved from the asset.

Type Parameters:
T -
Parameters:
id -
mapper -
attributes -
Returns:
the object created by the mapper.

readAsset

public void readAsset(com.fatwire.assetapi.data.AssetId id,
                      AssetClosure closure,
                      String... attributes)
Method to read an asset and provide the AssetClosure with the AssetData. Only the list of lister attributes is retrieved from the asset.

Parameters:
id -
closure -
attributes -

readAsset

public void readAsset(com.fatwire.assetapi.data.AssetId id,
                      AssetClosure closure)
Method to read an asset and pass the results to the closure for further handling.

Parameters:
id - the assetid to read
closure - the closure

readAsset

public void readAsset(List<com.fatwire.assetapi.data.AssetId> ids,
                      AssetClosure closure)
Method to read an asset and pass the results to the closure for further handling.

Parameters:
ids - a list of AssetIds
closure - the closure

readAsset

public void readAsset(Iterable<com.fatwire.assetapi.data.AssetId> ids,
                      AssetClosure closure,
                      String... attributes)
Method to read an asset and pass the results to the closure for further handling.

Parameters:
ids - a list of AssetIds
closure - the closure

readAsset

public com.fatwire.assetapi.data.AssetData readAsset(com.fatwire.assetapi.data.AssetId id,
                                                     String... attributes)
Reads an asset based on the listed attribute names

TODO: do we need to load the attribute values and prevent access to non-listed attributes (prevent lazy loading)

Parameters:
id - the assetid
attributes - the list of attributes to return
Returns:
the asset found

getAssetDataManager

protected com.fatwire.assetapi.data.AssetDataManager getAssetDataManager()
Returns:
the manager

readAsset

public com.fatwire.assetapi.data.AssetData readAsset(com.fatwire.assetapi.data.AssetId id)
Parameters:
id - the assetid to read
Returns:
the assetdata for this id

readAssets

public Iterable<com.fatwire.assetapi.data.AssetData> readAssets(com.fatwire.assetapi.query.Query query)
Parameters:
query -
Returns:
iterable with AssetData from the query result.

readAssets

public void readAssets(com.fatwire.assetapi.query.Query query,
                       AssetClosure closure)
Invokes the work(asset) method on the provided Closure for assets returned by the Query.

Parameters:
query - the query
closure - the closure

readAssets

public <T> Iterable<T> readAssets(com.fatwire.assetapi.query.Query query,
                                  AssetMapper<T> mapper)
Reading assets with the Query and using the mapper to transform the AssetData into another object, as specified by T.

Type Parameters:
T -
Parameters:
query -
mapper -
Returns:
the objects created by the mapper.

findByName

public com.fatwire.assetapi.data.AssetId findByName(COM.FutureTense.Interfaces.ICS ics,
                                                    String assetType,
                                                    String name,
                                                    long siteid)
Finds the assetid by the name of the asset in a particular site. The asset can not be voided.

Parameters:
ics -
assetType - the type of the asset.
name - the name of the asset.
siteid - the Site id.
Returns:
the assetid, null if asset is not found.

findByName

public com.fatwire.assetapi.data.AssetId findByName(COM.FutureTense.Interfaces.ICS ics,
                                                    String assetType,
                                                    String name)
Finds the assetid by the name of the asset. The asset can not be voided.

Parameters:
ics -
assetType - the type of the asset.
name - the name of the asset.
Returns:
the assetid, null if asset is not found.

createNameQuery

public com.fatwire.assetapi.query.SimpleQuery createNameQuery(String assetType,
                                                              String assetName)
Creates a Query to retrieve the asset by it's name.

Parameters:
assetType -
assetName -
Returns:
the simple query

readSite

public com.fatwire.assetapi.site.Site readSite(String name)
Finds the Site object by the given name.

Parameters:
name - the name of the site.
Returns:
the Site object.

readSiteInfo

public com.fatwire.assetapi.site.SiteInfo readSiteInfo(String name)
Parameters:
name -
Returns:
the site info object

readAssociatedAssetIds

public Collection<com.fatwire.assetapi.data.AssetId> readAssociatedAssetIds(com.fatwire.assetapi.data.AssetId id,
                                                                            String associationType)
Reads the associated assets of the asset and returns the AssetIds.

Parameters:
id -
associationType -
Returns:
the assets from the associations.

readAssociatedAssets

public void readAssociatedAssets(com.fatwire.assetapi.data.AssetId id,
                                 String associationType,
                                 AssetClosure closure,
                                 String... attributes)
Reads the associated assets of an asset and returns them as a ScatteredAsset. This takes care of the asset read operation of the associated assets. The returned ScatteredAssets are only loaded with the mentioned attributes.

Parameters:
id - the parent asset
associationType - the name of the association or '-' for an unnamed association
closure - the AssetClosure to work on.
attributes - the list of attributes to load

query

public <T> Iterable<T> query(String assetType,
                             String subType,
                             String query,
                             AssetMapper<T> mapper,
                             String... attributes)
Queries for a list of objects as mapped by the AssetMapper.

Sample queries are:


query

public <T> Iterable<T> query(String assetType,
                             String subType,
                             String query,
                             AssetMapper<T> mapper)
Queries for a list of objects as mapped by the AssetMapper.

Sample queries are:



Copyright © 2010-2013 Oracle Corporation. All Rights Reserved.