1 package org.splat.simer;
3 import java.util.ArrayList;
4 import java.util.HashMap;
5 import java.util.Iterator;
9 import org.splat.dal.bo.kernel.User;
10 import org.splat.dal.bo.som.Document;
11 import org.splat.dal.bo.som.DocumentType;
12 import org.splat.dal.bo.som.KnowledgeElement;
13 import org.splat.dal.bo.som.KnowledgeElementType;
14 import org.splat.dal.bo.som.ProgressState;
15 import org.splat.dal.bo.som.Publication;
16 import org.splat.dal.bo.som.Scenario;
17 import org.splat.service.KnowledgeElementTypeService;
18 import org.splat.service.ProjectElementService;
19 import org.splat.service.PublicationService;
20 import org.splat.service.dto.KnowledgeElementDTO;
21 import org.splat.service.dto.Proxy;
22 import org.splat.service.technical.ProjectSettingsService;
23 import org.splat.som.Step;
24 import org.splat.util.BeanHelper;
25 import org.splat.wapp.Menu;
26 import org.splat.wapp.PopupMenu;
29 * Open study or knowledge.
31 public abstract class AbstractOpenObject implements Proxy {
33 protected static Map<Long, DocumentFacade> docpres = null;
34 protected static Map<Long, KnowledgeElementFacade> knowpres = null;
39 protected transient User _cuser = null;
41 * Menu selected by the user.
43 protected transient String _selection = null;
45 * Corresponding selected step.
47 protected transient Step _ustep = null;
49 * Object description (rich text).
51 protected transient String _description = null;
52 protected transient List<Step> _involving = new ArrayList<Step>();
54 * Simulation Context display representations.
56 protected transient List<SimulationContextFacade> _context = new ArrayList<SimulationContextFacade>();
58 * Document display representations.
60 protected transient List<DocumentFacade> _contents = null;
62 * Knowledge Element display representations structured by knowledge types.
64 protected transient List<KnowledgeIterator> _knowledge = null;
67 * Left pane menu of this object.
69 protected Menu _menu = null;
71 * Pop-up menu of this object, if the user has write access.
73 protected transient PopupMenu _popup = null;
75 * Injected project settings service.
77 private ProjectSettingsService _projectSettings;
79 * Injected application settings bean.
81 private ApplicationSettings _applicationSettings;
83 * Injected publication service.
85 private PublicationService _publicationService;
87 * Injected knowledge element service.
89 private KnowledgeElementTypeService _knowledgeElementTypeService;
91 * Injected project element service.
93 private ProjectElementService _projectElementService;
95 public class KnowledgeIterator {
96 protected transient KnowledgeElementType _type;
97 protected transient List<KnowledgeElementFacade> _list;
99 public KnowledgeIterator(final KnowledgeElementType type,
100 final List<KnowledgeElementFacade> list) {
105 public String getIndex() {
106 return String.valueOf(_type.getIndex());
109 public String getType() {
110 return _type.getName();
113 public List<KnowledgeElementFacade> getKnowledgeElements() {
118 // ==============================================================================================================================
120 // ==============================================================================================================================
122 protected AbstractOpenObject() {
123 // All member fields are supposed initialized by subclasses
124 if (docpres == null) {
125 docpres = new HashMap<Long, DocumentFacade>();
127 if (knowpres == null) {
128 knowpres = new HashMap<Long, KnowledgeElementFacade>();
132 // ==============================================================================================================================
133 // Public member functions
134 // ==============================================================================================================================
136 public void developDocument(final String index) {
137 for (Iterator<DocumentFacade> i = _contents.iterator(); i.hasNext();) {
138 DocumentFacade doc = i.next();
139 if (!doc.getIndex().equals(index)) {
147 public void developKnowledge(final String index) {
148 for (Iterator<KnowledgeIterator> i = _knowledge.iterator(); i.hasNext();) {
149 List<KnowledgeElementFacade> knowelms = i.next()
150 .getKnowledgeElements();
151 for (Iterator<KnowledgeElementFacade> j = knowelms.iterator(); j
153 KnowledgeElementFacade kelm = j.next();
154 if (!kelm.getIndex().equals(index)) {
163 public void clearFacades() {
164 docpres.clear(); // For eventually reopening the knowledge from a fresh context
165 knowpres.clear(); // For eventually reopening the knowledge from a fresh context
168 public List<Document> collectInvolvedDocuments(final DocumentType type) {
169 List<Document> found = new ArrayList<Document>();
170 for (Iterator<Step> i = _involving.iterator(); i.hasNext();) {
171 Step step = i.next();
172 List<Publication> exist = step.getAllDocuments();
173 for (Iterator<Publication> j = exist.iterator(); j.hasNext();) {
174 Document doc = j.next().value();
175 if (doc.getType().equals(type)) {
183 public String getDisplayedDescription() {
187 public List<DocumentFacade> getDisplayedDocuments() {
191 public List<SimulationContextFacade> getDisplayedSimulationContexts() {
195 public List<KnowledgeIterator> getDisplayedKnowledges() {
199 public List<Step> getInvolvedSteps() {
203 public Menu getMenu() {
207 public PopupMenu getPopup() {
211 public Step getSelectedStep() {
215 public String getSelection() {
219 public User getUser() {
223 public boolean isOpenForWriting() {
224 return (_popup != null); // The pop-up is supposed existed when the user is staffed on the study
227 public void reduceDocument(final String index) {
228 for (Iterator<DocumentFacade> i = _contents.iterator(); i.hasNext();) {
229 DocumentFacade doc = i.next();
230 if (!doc.getIndex().equals(index)) {
238 public void reduceHistory(final String index) {
239 for (Iterator<DocumentFacade> i = _contents.iterator(); i.hasNext();) {
240 DocumentFacade doc = i.next();
241 if (!doc.getIndex().equals(index)) {
249 public void reduceKnowledge(final String index) {
250 for (Iterator<KnowledgeIterator> i = _knowledge.iterator(); i.hasNext();) {
251 List<KnowledgeElementFacade> knowelms = i.next()
252 .getKnowledgeElements();
253 for (Iterator<KnowledgeElementFacade> j = knowelms.iterator(); j
255 KnowledgeElementFacade kelm = j.next();
256 if (!kelm.getIndex().equals(index)) {
265 // ==============================================================================================================================
266 // Protected services
267 // ==============================================================================================================================
269 protected void setupContents() {
271 // Initialized in subclasses
273 // Knowledge elements supposed ordered by type
274 if (_ustep.mayContain(KnowledgeElement.class)) {
275 Scenario scene = (Scenario) _ustep.getOwner();
276 List<KnowledgeElementType> types = getKnowledgeElementTypeService()
277 .selectTypesWhere(ProgressState.APPROVED);
278 List<KnowledgeElement> kelms = scene.getAllKnowledgeElements();
279 Iterator<KnowledgeElement> more = kelms.iterator();
280 KnowledgeElement current = null;
281 if (more.hasNext()) {
282 current = more.next();
285 _knowledge = new ArrayList<KnowledgeIterator>(types.size());
286 for (Iterator<KnowledgeElementType> i = types.iterator(); i
288 KnowledgeElementType type = i.next();
289 List<KnowledgeElementFacade> display = new ArrayList<KnowledgeElementFacade>(
291 while (current != null && current.getType().equals(type)) {
292 KnowledgeElementFacade facade = knowpres.get(current
294 if (facade == null) {
295 facade = new KnowledgeElementFacade(BeanHelper
296 .copyBean(current, KnowledgeElementDTO.class));
297 knowpres.put(current.getIndex(), facade);
300 if (more.hasNext()) {
301 current = more.next();
306 _knowledge.add(new KnowledgeIterator(type, display));
312 if (_ustep.mayContain(Document.class)) {
313 List<Publication> list = _ustep.getAllDocuments();
315 _contents = new ArrayList<DocumentFacade>(list.size());
316 for (Iterator<Publication> i = list.iterator(); i.hasNext();) {
317 Publication present = i.next();
318 Long index = present.getIndex();
319 DocumentFacade facade = docpres.get(index);
320 if (facade == null) {
321 facade = new DocumentFacade(this, present,
322 getProjectSettings(), getPublicationService());
323 docpres.put(index, facade);
325 _contents.add(facade);
333 * Get project settings.
335 * @return Project settings service
337 public ProjectSettingsService getProjectSettings() {
338 return _projectSettings;
342 * Get the publicationService.
344 * @return the publicationService
346 public PublicationService getPublicationService() {
347 return _publicationService;
351 * Set project settings service.
353 * @param projectSettingsService
354 * project settings service
356 public void setProjectSettings(
357 final ProjectSettingsService projectSettingsService) {
358 _projectSettings = projectSettingsService;
362 * Set the publicationService.
364 * @param publicationService
365 * the publicationService to set
367 public void setPublicationService(
368 final PublicationService publicationService) {
369 _publicationService = publicationService;
378 public void setMenu(final Menu menu) {
383 * Get the projectElementService.
385 * @return the projectElementService
387 public ProjectElementService getProjectElementService() {
388 return _projectElementService;
392 * Set the projectElementService.
394 * @param projectElementService
395 * the projectElementService to set
397 public void setProjectElementService(
398 final ProjectElementService projectElementService) {
399 _projectElementService = projectElementService;
403 * Get the knowledgeElementTypeService.
405 * @return the knowledgeElementTypeService
407 public KnowledgeElementTypeService getKnowledgeElementTypeService() {
408 return _knowledgeElementTypeService;
412 * Set the knowledgeElementTypeService.
414 * @param knowledgeElementTypeService
415 * the knowledgeElementTypeService to set
417 public void setKnowledgeElementTypeService(
418 final KnowledgeElementTypeService knowledgeElementTypeService) {
419 _knowledgeElementTypeService = knowledgeElementTypeService;
423 * Get the applicationSettings.
425 * @return the applicationSettings
427 public ApplicationSettings getApplicationSettings() {
428 return _applicationSettings;
432 * Set the applicationSettings.
434 * @param applicationSettings
435 * the applicationSettings to set
437 public void setApplicationSettings(
438 final ApplicationSettings applicationSettings) {
439 _applicationSettings = applicationSettings;