1 package org.unitedfront2.domain.communication;
2
3 import org.apache.commons.logging.Log;
4 import org.apache.commons.logging.LogFactory;
5 import org.unitedfront2.domain.DomainFactory;
6 import org.unitedfront2.domain.User;
7 import org.unitedfront2.domain.accesscontrol.AccessDeniedException;
8
9
10
11
12
13
14
15 public class BlogEntryTable {
16
17
18 protected final Log logger = LogFactory.getLog(getClass());
19
20
21 private MessageTable messageTable;
22
23
24 private DomainFactory domainFactory;
25
26
27
28
29
30
31
32 public BlogEntry find(int id) {
33 Message entry = messageTable.find(id);
34 if (entry == null) {
35 return null;
36 }
37 return domainFactory.prototype(new BlogEntry(entry), BlogEntry.class);
38 }
39
40
41
42
43
44
45
46
47
48 public BlogEntry findForRead(int id, User user)
49 throws AccessDeniedException {
50 BlogEntry entry = find(id);
51 if (entry == null) {
52 return null;
53 } else {
54 entry.readAccess(user);
55 return entry;
56 }
57 }
58
59
60
61
62
63
64
65
66
67 public BlogEntry findForWrite(int id, User user)
68 throws AccessDeniedException {
69 BlogEntry entry = find(id);
70 if (entry == null) {
71 return null;
72 } else {
73 entry.writeAccess(user);
74 return entry;
75 }
76 }
77
78
79
80
81
82
83
84 public BlogEntry findByCode(String code) {
85 Message entry = messageTable.findByCode(code);
86 if (entry == null) {
87 return null;
88 }
89 return domainFactory.prototype(new BlogEntry(entry), BlogEntry.class);
90 }
91
92
93
94
95
96
97
98
99
100 public BlogEntry findByCodeForRead(String code, User user)
101 throws AccessDeniedException {
102 BlogEntry entry = findByCode(code);
103 if (entry == null) {
104 return null;
105 } else {
106 entry.readAccess(user);
107 return entry;
108 }
109 }
110
111
112
113
114
115
116
117
118
119 public BlogEntry findByCodeForWrite(String code, User user)
120 throws AccessDeniedException {
121 BlogEntry entry = findByCode(code);
122 if (entry == null) {
123 return null;
124 } else {
125 entry.writeAccess(user);
126 return entry;
127 }
128 }
129
130 public void setMessageTable(MessageTable messageTable) {
131 this.messageTable = messageTable;
132 }
133
134 public void setDomainFactory(DomainFactory domainFactory) {
135 this.domainFactory = domainFactory;
136 }
137 }