summaryrefslogtreecommitdiffstats
path: root/idrop-web/grails-app/services/org/irods/mydrop/service/ViewStateService.groovy
blob: baabfcb5e9cf354a8bf0bbc3dbafbd8ed62fa894 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
package org.irods.mydrop.service

import javax.servlet.http.HttpSession

import org.irods.mydrop.config.ViewState
import org.springframework.web.context.request.RequestContextHolder

class ViewStateService {
	
	static transactional = false
	//static scope = "session"	
	
	/**
	 * Get the stored root path
	 * @return
	 */
	public String retrieveRootPath() {
		ViewState viewState = getViewStateFromSessionAndCreateIfNotThere()
		return viewState.rootPath
	}
	
	/**
	 * clear the view state
	 
	 */
	public void clearViewState() {
		getSession().viewState = null
		
	}
	
	/**
	 * Store the root Path
	 * @param path
	 * @return
	 */
	public void saveRootPath(String path) {
		if (path == null) {
			throw new IllegalArgumentException("null path")
		}
		
		ViewState viewState = getViewStateFromSessionAndCreateIfNotThere()
		viewState.rootPath = path
		
	}
	
	/**
	 * Returnt the view mode associated with the browser
	 * @return
	 */
	public String retrieveViewMode() {
		ViewState viewState = getViewStateFromSessionAndCreateIfNotThere()
		return viewState.browseView
	}
	
	public void saveViewMode(String viewMode) {
		if (viewMode == null) {
			throw new IllegalArgumentException("null viewMode")
		}
		ViewState viewState = getViewStateFromSessionAndCreateIfNotThere()
		viewState.browseView = viewMode
	}
	

   private ViewState getStateFromSession() {
		ViewState viewState = getSession().viewState
		return viewState
	}

   public ViewState getViewStateFromSessionAndCreateIfNotThere() {
		ViewState viewState = getStateFromSession()
		if (!viewState) {
			log.info("no viewStat, create one")
			viewState = new ViewState()
			getSession().viewState = viewState
		}
		return viewState

	}

	private HttpSession getSession() {
		return RequestContextHolder.currentRequestAttributes().getSession()
	}

}