1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23 package net.sf.sail.common.apps.preview;
24
25 import java.util.HashMap;
26 import java.util.Map;
27
28 import net.sf.sail.common.persistance.memory.MemoryPersistenceImpl;
29 import net.sf.sail.core.beans.SessionContext;
30 import net.sf.sail.core.beans.service.AgentService;
31 import net.sf.sail.core.beans.service.AnnotationService;
32 import net.sf.sail.core.curnit.ICurnit;
33 import net.sf.sail.core.entity.IAgent;
34 import net.sf.sail.core.entity.Offering;
35 import net.sf.sail.core.entity.Role;
36 import net.sf.sail.core.entity.RoleRuleException;
37 import net.sf.sail.core.entity.User;
38 import net.sf.sail.core.session.SessionDataService;
39 import net.sf.sail.core.uuid.OfferingUuid;
40 import net.sf.sail.core.uuid.SessionUuid;
41 import net.sf.sail.core.uuid.UserUuid;
42
43 import org.doomdark.uuid.UUID;
44
45
46
47
48 public class PreviewSessionDataService implements SessionDataService {
49
50 public static final UserUuid PREVIEW_USERID = new UserUuid(UUID.valueOf(
51 "abcdef02-0000-0000-0000-000000000000").toByteArray());
52
53 public static final User PREVIEW_USER = new User(PREVIEW_USERID,
54 "Preview User");
55
56 public static final OfferingUuid PREVIEW_RUNID = new OfferingUuid(
57 new UUID().toByteArray());
58
59 public static final SessionUuid PREVIEW_SESSIONID = new SessionUuid(
60 new UUID().toByteArray());
61
62 private ICurnit curnit;
63
64 private transient Map<SessionContext, AgentService> serviceForSession = new HashMap<SessionContext, AgentService>();
65
66
67
68
69
70 public PreviewSessionDataService(ICurnit curnit) {
71 this.curnit = curnit;
72 }
73
74 protected ICurnit getCurnit() {
75 return curnit;
76 }
77
78 public AgentService getPersistenceService(SessionContext sessionContext) {
79 AgentService as = serviceForSession.get(sessionContext);
80 if (as != null)
81 return as;
82
83
84 as = new MemoryPersistenceImpl();
85
86 try {
87 IAgent workgroup = as.createAgent(Role.RUN_WORKGROUP);
88 workgroup.addUser(PREVIEW_USER.getUserUUID());
89 } catch (RoleRuleException e) {
90
91 e.printStackTrace();
92 }
93
94 try {
95 IAgent individual = as.createAgent(Role.INDIVIDUAL);
96 individual.addUser(PREVIEW_USER.getUserUUID());
97 } catch (RoleRuleException e) {
98
99 e.printStackTrace();
100 }
101
102
103 serviceForSession.put(sessionContext, as);
104 return as;
105 }
106
107 public User getUser(UserUuid userUuid) {
108 if (!userUuid.equals(PREVIEW_USERID))
109 throw new IllegalArgumentException();
110 return PREVIEW_USER;
111 }
112
113 public Offering getOffering() {
114 Offering run = new Offering();
115 run.setCurnit(getCurnit());
116 run.setDescription("Preview Run");
117 run.setOfferingId(PREVIEW_RUNID);
118 return run;
119 }
120
121
122
123
124 public AnnotationService getAnnotationService()
125 {
126
127 return null;
128 }
129
130 }