View Javadoc

1   /***
2    * 
3    */
4   package org.telscenter.pas.steps;
5   
6   import java.awt.Component;
7   import java.beans.beancontext.BeanContextServices;
8   import java.net.URL;
9   import java.util.Collection;
10  import java.util.HashMap;
11  import java.util.Iterator;
12  import java.util.List;
13  import java.util.Map;
14  import java.util.TooManyListenersException;
15  import java.util.logging.Logger;
16  
17  import javax.swing.JPanel;
18  
19  import net.sf.sail.core.beans.service.AgentService;
20  import net.sf.sail.core.beans.service.SessionService;
21  import net.sf.sail.core.entity.AgentSet;
22  import net.sf.sail.core.entity.IAgent;
23  import net.sf.sail.core.entity.ISock;
24  import net.sf.sail.core.entity.MismatchedAgentSetSizeException;
25  import net.sf.sail.core.entity.Rim;
26  import net.sf.sail.core.entity.Role;
27  import net.sf.sail.core.entity.UnsupportedRimShapeException;
28  import net.sf.sail.core.entity.User;
29  
30  import org.telscenter.pas.service.INoteService;
31  import org.telscenter.pas.steps.domain.AssessmentItem;
32  import org.telscenter.pas.steps.domain.BookmarkDAO;
33  import org.telscenter.pas.steps.domain.ResponseDeclaration;
34  import org.telscenter.pas.steps.domain.SimpleChoice;
35  
36  /***
37   * @author aperritano
38   *
39   */
40  public class Bookmark extends BrowseWeb {
41  
42  	private String instructionalText;
43  	
44  	private URL outsideURL;
45  
46  	private BookmarkUI bookmarkUI;
47  
48  	public static final Logger logger = Logger.getLogger(Bookmark.class.getName());
49  	
50  	private Rim<String> workRim;
51  	
52  	private ISock<String> workSock;
53  
54  	 /***
55  	 * 
56  	 */
57  	public Bookmark() {
58  		
59  	}
60  
61  	protected void consumeService(BeanContextServices bcs, Class<? extends Object> serviceClass) {
62  		if (serviceClass == AgentService.class) {
63  			try {
64  				final AgentService p = (AgentService) bcs.getService(this,
65  						this, AgentService.class, this, this);
66  				IAgent agent = p.getAgentsInRole(Role.RUN_WORKGROUP).getSingle();
67  				workSock = p.getSock(workRim, agent);
68  			} catch (TooManyListenersException e) {
69  				logger.severe("exception: " + e); //$NON-NLS-1$
70  			} catch (MismatchedAgentSetSizeException e) {
71  				logger.severe("exception: " + e); //$NON-NLS-1$
72  			} catch (UnsupportedRimShapeException e) {
73  				logger.severe("exception: " + e); //$NON-NLS-1$
74  			}
75  		}
76  	}
77  	
78  	@SuppressWarnings("unchecked")
79  	public static void saveBookmarks(AssessmentItem assessmentItem,
80  			Map responses, Map<ResponseDeclaration, ISock> responseDeclarationToSocks) {
81  		List<ResponseDeclaration>  reponseDeclarations = assessmentItem.getResponseDeclarations();
82  
83  		for (ResponseDeclaration rd : reponseDeclarations) {
84  
85  			Object responseContent = responses.get(rd.getIdentifier());
86  
87  			// no choice for the responseDeclaration
88  			if (responseContent == null) {
89  				logger
90  						.severe("no response for declaration " + rd.getIdentifier() + " -  : exception: " + null); //$NON-NLS-1$ //$NON-NLS-2$
91  				continue;
92  			}
93  
94  			ISock<Object> sock = responseDeclarationToSocks.get(rd);
95  			if (sock == null) {
96  				logger.severe("no sock for " + rd + " -  : exception: " + null); //$NON-NLS-1$ //$NON-NLS-2$ 
97  				continue;
98  			}
99  
100 			if (responseContent instanceof SimpleChoice) {
101 				SimpleChoice simpleChoice = (SimpleChoice) responseContent;
102 				sock.add(simpleChoice.getIdentifier());
103 				responseDeclarationToSocks.put(rd, sock);
104 			} else if (responseContent instanceof String) {
105 				sock.add(responseContent);
106 				responseDeclarationToSocks.put(rd, sock);
107 			} else {
108 				throw new RuntimeException("unsupported choice type " //$NON-NLS-1$
109 						+ responseContent);
110 			}
111 		}
112 		}
113 	
114 	/***
115 	 * @return the instructionalText
116 	 */
117 	public String getInstructionalText() {
118 		return instructionalText;
119 	}
120 
121 	/***
122 	 * @param instructionalText the instructionalText to set
123 	 */
124 	public void setInstructionalText(String instructionalText) {
125 		Object old = this.instructionalText;
126 		this.instructionalText = instructionalText;
127 		firePropertyChange("instructionalText", old, instructionalText);
128 	}
129 
130 	/***
131 	 * @return the outsideURL
132 	 */
133 	public URL getOutsideURL() {
134 		return outsideURL;
135 	}
136 
137 	/***
138 	 * @param outsideURL the outsideURL to set
139 	 */
140 	public void setOutsideURL(URL outsideURL) {
141 		Object old = this.outsideURL;
142 		this.outsideURL = outsideURL;
143 		this.setUrl(outsideURL);
144 		firePropertyChange("outsideURL", old, outsideURL);
145 	}
146 	
147 	public Component getComponent() {
148 		bookmarkUI = new BookmarkUI(this);
149 		return bookmarkUI;
150 	}
151 	
152 	public String getType() {
153 		return "Bookmark";
154 	}
155 
156 	/***
157 	 * @return the workRim
158 	 */
159 	public Rim<String> getWorkRim() {
160 		return workRim;
161 	}
162 
163 	/***
164 	 * @param workRim the workRim to set
165 	 */
166 	public void setWorkRim(Rim<String> workRim) {
167 		this.workRim = workRim;
168 	}
169 
170 	/***
171 	 * @return the workSock
172 	 */
173 	public ISock<String> getWorkSock() {
174 		return workSock;
175 	}
176 
177 	/***
178 	 * @param workSock the workSock to set
179 	 */
180 	public void setWorkSock(ISock<String> workSock) {
181 		this.workSock = workSock;
182 	}
183 
184 	
185 }