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
-
Field Summary
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionboolean
addCartItem
(UserIdentity owner, String itemId, String siteName) Add a content to the cartprotected void
additionalItemInfo
(org.ametys.plugins.odfweb.cart.ODFCartManager.ODFCartItem item, Course course, Map<String, Object> infos) Get the additional information forCourse
cart itemprotected void
additionalItemInfo
(org.ametys.plugins.odfweb.cart.ODFCartManager.ODFCartItem item, AbstractProgram abstractProgram, Map<String, Object> infos) Get the additional information forAbstractProgram
cart itemcartItem2Json
(org.ametys.plugins.odfweb.cart.ODFCartManager.ODFCartItem item, String siteName, String viewName) Get the JSON representation of a cart itemvoid
contextualize
(Context context) org.ametys.plugins.odfweb.cart.ODFCartManager.ODFCartItem
getCartItem
(String itemId) Get a cart item from its idgetCartItemIds
(UserIdentity user, String siteName) Get the id of ODF's cart items for a given usergetCartItemIds
(UserIdentity user, String siteName, String userPrefsId) Get the id of items for a given userList<org.ametys.plugins.odfweb.cart.ODFCartManager.ODFCartItem>
getCartItems
(UserIdentity owner, String siteName) Get the ODF's cart items for a given usergetItemIdsWithSubscription
(UserIdentity user, String siteName) Get the id of ODF's cart items for which a given user is a subscriberList<org.ametys.plugins.odfweb.cart.ODFCartManager.ODFCartItem>
getItemsWithSubscription
(UserIdentity owner, String siteName) Get the ODF's cart items for which the given user is a subscriberprotected String
getMailBody
(List<org.ametys.plugins.odfweb.cart.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
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, org.ametys.plugins.odfweb.cart.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, org.ametys.plugins.odfweb.cart.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.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 contentMethods inherited from class org.ametys.runtime.plugin.component.AbstractLogEnabled
getLogger, setLogger
-
Field Details
-
ROLE
The avalon role -
CART_USER_PREF_CONTENT_IDS
The id of user preference for cart's elements- See Also:
-
SUBSCRIPTION_USER_PREF_CONTENT_IDS
The id of user preference for subscription- See Also:
-
-
Constructor Details
-
ODFCartManager
public ODFCartManager()
-
-
Method Details
-
service
- Specified by:
service
in interfaceServiceable
- Throws:
ServiceException
-
contextualize
- 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<org.ametys.plugins.odfweb.cart.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<org.ametys.plugins.odfweb.cart.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
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
-
getMailSubject
Get the mail subject for sharing cart- Parameters:
siteName
- The site namelanguage
- the language- Returns:
- the mail subject
-
getMailBody
protected String getMailBody(List<org.ametys.plugins.odfweb.cart.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, org.ametys.plugins.odfweb.cart.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(org.ametys.plugins.odfweb.cart.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(org.ametys.plugins.odfweb.cart.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(org.ametys.plugins.odfweb.cart.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
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, org.ametys.plugins.odfweb.cart.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(org.ametys.plugins.odfweb.cart.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
-