Package org.ametys.plugins.odfweb.cart
Class ODFCartManager
- java.lang.Object
-
- org.ametys.runtime.plugin.component.AbstractLogEnabled
-
- org.ametys.plugins.odfweb.cart.ODFCartManager
-
- All Implemented Interfaces:
LogEnabled
,Component
,Contextualizable
,Serviceable
public class ODFCartManager extends AbstractLogEnabled implements Serviceable, Component, Contextualizable
Component to handle ODF cart items
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description (package private) class
ODFCartManager.ODFCartItem
-
Field Summary
Fields Modifier and Type Field Description private Context
_context
private ContentTypeExtensionPoint
_cTypeEP
private ContentTypesHelper
_cTypesHelper
private CurrentUserProvider
_currentUserProvider
private I18nUtils
_i18nUtils
private OdfPageResolver
_odfPageResolver
private ODFCartUserPreferencesStorage
_odfUserPrefStorage
private RenderingContextHandler
_renderingContextHandler
private AmetysObjectResolver
_resolver
private SiteManager
_siteManager
private SourceResolver
_srcResolver
private UserHelper
_userHelper
private UserPreferencesManager
_userPrefManager
static String
CART_USER_PREF_CONTENT_IDS
The id of user preference for cart's elementsstatic String
ROLE
The avalon rolestatic String
SUBSCRIPTION_USER_PREF_CONTENT_IDS
The id of user preference for subscription
-
Constructor Summary
Constructors Constructor Description ODFCartManager()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description boolean
addCartItem(UserIdentity owner, String itemId, String siteName)
Add a content to the cartprotected void
additionalItemInfo(ODFCartManager.ODFCartItem item, Course course, Map<String,Object> infos)
Get the additional information forCourse
cart itemprotected void
additionalItemInfo(ODFCartManager.ODFCartItem item, AbstractProgram abstractProgram, Map<String,Object> infos)
Get the additional information forAbstractProgram
cart itemMap<String,Object>
cartItem2Json(ODFCartManager.ODFCartItem item, String siteName, String viewName)
Get the JSON representation of a cart itemvoid
contextualize(Context context)
ODFCartManager.ODFCartItem
getCartItem(String itemId)
Get a cart item from its idList<String>
getCartItemIds(UserIdentity user, String siteName)
Get the id of ODF's cart items for a given userprotected List<String>
getCartItemIds(UserIdentity user, String siteName, String userPrefsId)
Get the id of items for a given userList<ODFCartManager.ODFCartItem>
getCartItems(UserIdentity owner, String siteName)
Get the ODF's cart items for a given userList<String>
getItemIdsWithSubscription(UserIdentity user, String siteName)
Get the id of ODF's cart items for which a given user is a subscriberList<ODFCartManager.ODFCartItem>
getItemsWithSubscription(UserIdentity owner, String siteName)
Get the ODF's cart items for which the given user is a subscriberprotected String
getMailBody(List<ODFCartManager.ODFCartItem> items, String message, UserIdentity owner, String siteName, String language, boolean text)
Get the mail body to sharing cartprotected String
getMailSubject(String siteName, String language)
Get the mail subject for sharing cartprotected Page
getPage(ODFCartManager.ODFCartItem item, String siteName)
Get the page associated to this cart's itemboolean
isSubscriber(UserIdentity owner, String itemId, String siteName)
determines if the user subscribes to this itemvoid
saveItemsInUserPreference(UserIdentity owner, List<String> itemIds, String siteName, String userPrefsId)
Save the given items into the given user preferencevoid
saxCartItem(ContentHandler contentHandler, ODFCartManager.ODFCartItem item, String siteName)
SAX a cart's itemvoid
saxCartItems(ContentHandler contentHandler, UserIdentity owner, String siteName)
SAX the cart's itemsprotected void
saxContent(ContentHandler handler, Content content, String viewName)
SAX the content viewprotected void
saxPage(ContentHandler handler, ODFCartManager.ODFCartItem item, String siteName)
Sax the content's pageprotected void
saxTypes(ContentHandler handler, String[] types)
Sax the content typesvoid
service(ServiceManager serviceManager)
void
setCartItems(UserIdentity owner, List<String> itemIds, String siteName)
Set the cart's itemsvoid
setSubscription(UserIdentity owner, List<String> itemIds, String siteName)
Subscribe to a list of items.Map<String,Object>
shareCartItems(UserIdentity owner, List<String> itemIds, List<String> recipients, String siteName, String language, String message)
Share the cart's items by mailboolean
subscribe(UserIdentity owner, String itemId, String siteName)
Subscribe to a contentboolean
unsubscribe(UserIdentity owner, String itemId, String siteName)
Unsubscribe to a content-
Methods inherited from class org.ametys.runtime.plugin.component.AbstractLogEnabled
getLogger, setLogger
-
-
-
-
Field Detail
-
CART_USER_PREF_CONTENT_IDS
public static final String CART_USER_PREF_CONTENT_IDS
The id of user preference for cart's elements- See Also:
- Constant Field Values
-
SUBSCRIPTION_USER_PREF_CONTENT_IDS
public static final String SUBSCRIPTION_USER_PREF_CONTENT_IDS
The id of user preference for subscription- See Also:
- Constant Field Values
-
_userPrefManager
private UserPreferencesManager _userPrefManager
-
_resolver
private AmetysObjectResolver _resolver
-
_srcResolver
private SourceResolver _srcResolver
-
_odfPageResolver
private OdfPageResolver _odfPageResolver
-
_cTypeEP
private ContentTypeExtensionPoint _cTypeEP
-
_cTypesHelper
private ContentTypesHelper _cTypesHelper
-
_odfUserPrefStorage
private ODFCartUserPreferencesStorage _odfUserPrefStorage
-
_i18nUtils
private I18nUtils _i18nUtils
-
_userHelper
private UserHelper _userHelper
-
_siteManager
private SiteManager _siteManager
-
_renderingContextHandler
private RenderingContextHandler _renderingContextHandler
-
_currentUserProvider
private CurrentUserProvider _currentUserProvider
-
-
Constructor Detail
-
ODFCartManager
public ODFCartManager()
-
-
Method Detail
-
service
public void service(ServiceManager serviceManager) throws ServiceException
- Specified by:
service
in interfaceServiceable
- Throws:
ServiceException
-
contextualize
public void contextualize(Context context) throws ContextException
- Specified by:
contextualize
in interfaceContextualizable
- Throws:
ContextException
-
getCartItemIds
public List<String> getCartItemIds(UserIdentity user, String siteName) throws UserPreferencesException
Get the id of ODF's cart items for a given user- Parameters:
user
- the usersiteName
- the current site name- Returns:
- the list of contents' id
- Throws:
UserPreferencesException
- if failed to get cart items
-
getItemIdsWithSubscription
public List<String> getItemIdsWithSubscription(UserIdentity user, String siteName) throws UserPreferencesException
Get the id of ODF's cart items for which a given user is a subscriber- Parameters:
user
- the usersiteName
- the current site name- Returns:
- the list of contents' id
- Throws:
UserPreferencesException
- if failed to get cart items
-
getCartItemIds
protected List<String> getCartItemIds(UserIdentity user, String siteName, String userPrefsId) throws UserPreferencesException
Get the id of items for a given user- Parameters:
user
- the usersiteName
- the current site nameuserPrefsId
- The id of user preferences- Returns:
- the list of contents' id
- Throws:
UserPreferencesException
- if failed to get cart items
-
getCartItems
public List<ODFCartManager.ODFCartItem> getCartItems(UserIdentity owner, String siteName) throws UserPreferencesException
Get the ODF's cart items for a given user- Parameters:
owner
- the usersiteName
- the current site name- Returns:
- the list of contents
- Throws:
UserPreferencesException
- if failed to get cart items
-
getItemsWithSubscription
public List<ODFCartManager.ODFCartItem> getItemsWithSubscription(UserIdentity owner, String siteName) throws UserPreferencesException
Get the ODF's cart items for which the given user is a subscriber- Parameters:
owner
- the usersiteName
- the current site name- Returns:
- the list of contents
- Throws:
UserPreferencesException
- if failed to get subscriptions
-
getCartItem
public ODFCartManager.ODFCartItem getCartItem(String itemId)
Get a cart item from its id- Parameters:
itemId
- the item's id- Returns:
- the cart item or null if no content was found
-
setCartItems
public void setCartItems(UserIdentity owner, List<String> itemIds, String siteName) throws UserPreferencesException
Set the cart's items- Parameters:
owner
- The cart owneritemIds
- the id of items to set in the cartsiteName
- the site name- Throws:
UserPreferencesException
- if failed to save cart
-
setSubscription
public void setSubscription(UserIdentity owner, List<String> itemIds, String siteName) throws UserPreferencesException
Subscribe to a list of items. All subscriptions are replaced by the given items.- Parameters:
owner
- The cart owneritemIds
- the id of items to subscribe to.siteName
- the site name- Throws:
UserPreferencesException
- if failed to save subscriptions
-
saveItemsInUserPreference
public void saveItemsInUserPreference(UserIdentity owner, List<String> itemIds, String siteName, String userPrefsId) throws UserPreferencesException
Save the given items into the given user preference- Parameters:
owner
- the useritemIds
- the id of itemssiteName
- the site nameuserPrefsId
- the id of user preference- Throws:
UserPreferencesException
- if failed to save user preference
-
addCartItem
public boolean addCartItem(UserIdentity owner, String itemId, String siteName) throws UserPreferencesException
Add a content to the cart- Parameters:
owner
- the cart owneritemId
- the id of content to add into the cartsiteName
- the site name- Returns:
- true if the content was successfully added
- Throws:
UserPreferencesException
- if failed to save cart
-
isSubscriber
public boolean isSubscriber(UserIdentity owner, String itemId, String siteName) throws UserPreferencesException
determines if the user subscribes to this item- Parameters:
owner
- the useritemId
- the id of contentsiteName
- the site name- Returns:
- true if the user subscribes to this item, false otherwise
- Throws:
UserPreferencesException
- if failed to check subscription
-
subscribe
public boolean subscribe(UserIdentity owner, String itemId, String siteName) throws UserPreferencesException
Subscribe to a content- Parameters:
owner
- the cart owneritemId
- the id of contentsiteName
- the site name- Returns:
- if the content was successfuly added to subscriptions
- Throws:
UserPreferencesException
- if failed to subscribe to content
-
unsubscribe
public boolean unsubscribe(UserIdentity owner, String itemId, String siteName) throws UserPreferencesException
Unsubscribe to a content- Parameters:
owner
- the cart owneritemId
- the id of contentsiteName
- the site name- Returns:
- if the content was successfuly added to subscriptions
- Throws:
UserPreferencesException
- if failed to subscribe to content
-
shareCartItems
public Map<String,Object> shareCartItems(UserIdentity owner, List<String> itemIds, List<String> recipients, String siteName, String language, String message)
Share the cart's items by mail- Parameters:
owner
- The cart owneritemIds
- the id of contents to set in the cartrecipients
- the mails to share withsiteName
- the site namelanguage
- the languagemessage
- the message to add to selection- Returns:
- the results
-
getMailSubject
protected String getMailSubject(String siteName, String language)
Get the mail subject for sharing cart- Parameters:
siteName
- The site namelanguage
- the language- Returns:
- the mail subject
-
getMailBody
protected String getMailBody(List<ODFCartManager.ODFCartItem> items, String message, UserIdentity owner, String siteName, String language, boolean text) throws IOException
Get the mail body to sharing cart- Parameters:
items
- The cart's itemsmessage
- The messageowner
- The cart's ownersiteName
- The site namelanguage
- the languagetext
- true to get the body to text body (html otherwise)- Returns:
- the cart items to HTML format
- Throws:
IOException
- if failed to mail body
-
saxCartItems
public void saxCartItems(ContentHandler contentHandler, UserIdentity owner, String siteName) throws SAXException, IOException, UserPreferencesException
SAX the cart's items- Parameters:
contentHandler
- The content handler to sax intoowner
- the cart ownersiteName
- the site name- Throws:
SAXException
- if an error occurred while saxingIOException
- if an I/O exception occurredUserPreferencesException
- if failed to get cart items
-
saxCartItem
public void saxCartItem(ContentHandler contentHandler, ODFCartManager.ODFCartItem item, String siteName) throws SAXException, IOException
SAX a cart's item- Parameters:
contentHandler
- The content handler to sax intoitem
- the cart's itemsiteName
- the site name- Throws:
SAXException
- if an error occurred while saxingIOException
- if an I/O exception occurred
-
cartItem2Json
public Map<String,Object> cartItem2Json(ODFCartManager.ODFCartItem item, String siteName, String viewName) throws IOException
Get the JSON representation of a cart item- Parameters:
item
- The cart's itemsiteName
- The site nameviewName
- The name of content view to use- Returns:
- The cart items properties
- Throws:
IOException
- if failed to read content view
-
additionalItemInfo
protected void additionalItemInfo(ODFCartManager.ODFCartItem item, AbstractProgram abstractProgram, Map<String,Object> infos)
Get the additional information forAbstractProgram
cart item- Parameters:
item
- the odf cart itemabstractProgram
- the abstract programinfos
- the information to be completed
-
additionalItemInfo
protected void additionalItemInfo(ODFCartManager.ODFCartItem item, Course course, Map<String,Object> infos)
Get the additional information forCourse
cart item- Parameters:
item
- the odf cart itemcourse
- the abstract programinfos
- the information to be completed
-
saxTypes
protected void saxTypes(ContentHandler handler, String[] types) throws SAXException
Sax the content types- Parameters:
handler
- The content handler to sax intotypes
- The content types- Throws:
SAXException
- if an error occurred while saxing
-
saxContent
protected void saxContent(ContentHandler handler, Content content, String viewName) throws SAXException, IOException
SAX the content view- Parameters:
handler
- The content handler to sax intocontent
- The contentviewName
- The view name- Throws:
SAXException
- if an error occurred while saxingIOException
- if an I/O exception occurred
-
saxPage
protected void saxPage(ContentHandler handler, ODFCartManager.ODFCartItem item, String siteName) throws SAXException
Sax the content's page- Parameters:
handler
- The content handler to sax intoitem
- The cart's itemsiteName
- The current site name- Throws:
SAXException
- if an error occurred while saxing
-
getPage
protected Page getPage(ODFCartManager.ODFCartItem item, String siteName)
Get the page associated to this cart's item- Parameters:
item
- The itemsiteName
- The site name- Returns:
- the page or
null
if not found
-
-