summaryrefslogtreecommitdiffstats
path: root/idrop-web/grails-app/services
diff options
context:
space:
mode:
authorMike Conway <michael.c.conway@gmail.com>2011-11-21 21:22:10 (GMT)
committer Mike Conway <michael.c.conway@gmail.com>2011-11-21 21:22:10 (GMT)
commit35e48adc703ec86a285e98e47bd6f09978f67bec (patch)
tree82028b39ad01604d27dabf799ab71d3676c9b1e7 /idrop-web/grails-app/services
parentb9692138cdf5ef06ac76c596ad1ee47cd545e19e (diff)
downloadQCG-Data-35e48adc703ec86a285e98e47bd6f09978f67bec.zip
QCG-Data-35e48adc703ec86a285e98e47bd6f09978f67bec.tar.gz
QCG-Data-35e48adc703ec86a285e98e47bd6f09978f67bec.tar.bz2
[#535] shopping cart capability in idrop web and idrop lite
Diffstat (limited to 'idrop-web/grails-app/services')
-rw-r--r--idrop-web/grails-app/services/org/irods/mydrop/service/ShoppingCartService.groovy63
1 files changed, 63 insertions, 0 deletions
diff --git a/idrop-web/grails-app/services/org/irods/mydrop/service/ShoppingCartService.groovy b/idrop-web/grails-app/services/org/irods/mydrop/service/ShoppingCartService.groovy
new file mode 100644
index 0000000..e730b0a
--- /dev/null
+++ b/idrop-web/grails-app/services/org/irods/mydrop/service/ShoppingCartService.groovy
@@ -0,0 +1,63 @@
+package org.irods.mydrop.service
+import javax.servlet.http.HttpSession
+
+import org.irods.jargon.core.connection.IRODSAccount
+import org.irods.jargon.datautils.shoppingcart.FileShoppingCart
+import org.irods.jargon.datautils.shoppingcart.ShoppingCartEntry
+import org.springframework.web.context.request.RequestContextHolder
+
+class ShoppingCartService {
+
+ static transactional = false
+ //static scope = "session"
+ static final String CART_ATTRIBUTE = "shoppingCart"
+
+ /**
+ * Add the item to the shopping cart
+ * @param irodsFileAbsolutePath <code>String</code> with the absolute path to the iRODS file to add to the cart
+ * @param irodsAccount <code>IRODSAccount</code> for which the cart will be associated
+ * @return
+ */
+ public void addToCart(String irodsFileAbsolutePath, IRODSAccount irodsAccount) {
+ FileShoppingCart fileShoppingCart = getCartFromSessionAndCreateIfNotThere(irodsAccount)
+ fileShoppingCart.addAnItem(new ShoppingCartEntry(irodsFileAbsolutePath))
+ }
+
+ /**
+ * List the contents of the cart as a list of file names
+ * @return
+ */
+ public List<String> listCart() {
+ List<String> results = new ArrayList<String>()
+ FileShoppingCart fileShoppingCart = getCartFromSession()
+ if (fileShoppingCart) {
+ results = fileShoppingCart.getShoppingCartFileList()
+ }
+ return results
+ }
+
+ /**
+ * Get shopping cart from session if present, but don't create one if not present (saves storing unnecesary session state)
+ * @return {@link FileShoppingCart} if stored in session, or <code>null</code> if not stored
+ */
+ private FileShoppingCart getCartFromSession() {
+ FileShoppingCart shoppingCart = getSession().shoppingCart
+ return shoppingCart
+ }
+
+ private FileShoppingCart getCartFromSessionAndCreateIfNotThere(IRODSAccount irodsAccount) {
+ FileShoppingCart shoppingCart = getSession().shoppingCart
+ if (!shoppingCart) {
+ log.info("no shopping cart, create one")
+ shoppingCart = new FileShoppingCart(irodsAccount)
+ getSession().shoppingCart = shoppingCart
+ }
+ return shoppingCart
+
+ }
+
+ private HttpSession getSession() {
+ return RequestContextHolder.currentRequestAttributes().getSession()
+ }
+
+}