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
Fields Modifier and Type Field Description static StringCART_USER_PREF_CONTENT_IDSThe id of user preference for cart's elementsstatic StringROLEThe avalon rolestatic StringSUBSCRIPTION_USER_PREF_CONTENT_IDSThe 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 booleanaddCartItem(UserIdentity owner, String itemId, String siteName)Add a content to the cartprotected voidadditionalItemInfo(org.ametys.plugins.odfweb.cart.ODFCartManager.ODFCartItem item, Course course, Map<String,Object> infos)Get the additional information forCoursecart itemprotected voidadditionalItemInfo(org.ametys.plugins.odfweb.cart.ODFCartManager.ODFCartItem item, AbstractProgram abstractProgram, Map<String,Object> infos)Get the additional information forAbstractProgramcart itemMap<String,Object>cartItem2Json(org.ametys.plugins.odfweb.cart.ODFCartManager.ODFCartItem item, String siteName, String viewName)Get the JSON representation of a cart itemvoidcontextualize(Context context)org.ametys.plugins.odfweb.cart.ODFCartManager.ODFCartItemgetCartItem(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<org.ametys.plugins.odfweb.cart.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<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 StringgetMailBody(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 StringgetMailSubject(String siteName, String language)Get the mail subject for sharing cartprotected PagegetPage(org.ametys.plugins.odfweb.cart.ODFCartManager.ODFCartItem item, String siteName)Get the page associated to this cart's itembooleanisSubscriber(UserIdentity owner, String itemId, String siteName)determines if the user subscribes to this itemvoidsaveItemsInUserPreference(UserIdentity owner, List<String> itemIds, String siteName, String userPrefsId)Save the given items into the given user preferencevoidsaxCartItem(ContentHandler contentHandler, org.ametys.plugins.odfweb.cart.ODFCartManager.ODFCartItem item, String siteName)SAX a cart's itemvoidsaxCartItems(ContentHandler contentHandler, UserIdentity owner, String siteName)SAX the cart's itemsprotected voidsaxContent(ContentHandler handler, Content content, String viewName)SAX the content viewprotected voidsaxPage(ContentHandler handler, org.ametys.plugins.odfweb.cart.ODFCartManager.ODFCartItem item, String siteName)Sax the content's pageprotected voidsaxTypes(ContentHandler handler, String[] types)Sax the content typesvoidservice(ServiceManager serviceManager)voidsetCartItems(UserIdentity owner, List<String> itemIds, String siteName)Set the cart's itemsvoidsetSubscription(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 mailbooleansubscribe(UserIdentity owner, String itemId, String siteName)Subscribe to a contentbooleanunsubscribe(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
-
-
Constructor Detail
-
ODFCartManager
public ODFCartManager()
-
-
Method Detail
-
service
public void service(ServiceManager serviceManager) throws ServiceException
- Specified by:
servicein interfaceServiceable- Throws:
ServiceException
-
contextualize
public void contextualize(Context context) throws ContextException
- Specified by:
contextualizein 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
public org.ametys.plugins.odfweb.cart.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<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 forAbstractProgramcart 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 forCoursecart 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, 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
-
-