1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package net.sf.oxclient.service;
17
18 import java.util.List;
19 import java.util.Map;
20
21 import net.sf.oval.constraint.NotEmpty;
22 import net.sf.oval.constraint.NotNull;
23 import net.sf.oval.guard.Guarded;
24 import net.sf.oxclient.IGroupwareModule;
25 import net.sf.oxclient.IGroupwareSession;
26 import net.sf.oxclient.IQuery;
27 import net.sf.oxclient.mappings.IMappingManager;
28
29
30
31
32
33 @Guarded
34 public abstract class AbsGroupwareModule<ModuleEntityBean, FolderBean>
35 implements IGroupwareModule<ModuleEntityBean, FolderBean> {
36
37 private final String moduleName;
38 private final Class<ModuleEntityBean> entityClass;
39 protected IMappingManager mappingManager;
40 private IGroupwareSession<FolderBean> session = null;
41
42
43
44
45 protected AbsGroupwareModule(
46 @NotNull @NotEmpty final String moduleName,
47 @NotNull final Class<ModuleEntityBean> entityClass) {
48 super();
49 this.moduleName = moduleName;
50 this.entityClass = entityClass;
51 }
52
53
54
55
56 public abstract ModuleEntityBean create(final FolderBean parent);
57
58
59
60
61 public ModuleEntityBean create() {
62 final FolderBean parent = getDefaultFolder();
63 return create(parent);
64 }
65
66
67
68
69 public ModuleEntityBean getByID(@NotNull @NotEmpty final String objectId) {
70 final IQuery query = createQuery();
71 final Map<String, String> params = getQueryParameter(objectId);
72 query.setParameters(params);
73 final Map<Integer, String> columns = getColumnMappings();
74 query.setPropertyColumns(columns);
75 final ModuleEntityBean result = query.queryForObject(this.entityClass);
76 return result;
77 }
78
79 public List<ModuleEntityBean> list(final FolderBean folder) {
80 final IQuery query = createQuery();
81 query.setParameters(getListParameters(folder));
82 query.setPropertyColumns(getColumnMappings());
83 return query.queryForList(getEntityClass());
84 }
85
86
87
88
89 public String getName() {
90 return this.moduleName;
91 }
92
93 public abstract Map<String, String> getListParameters(final FolderBean parent);
94
95
96
97
98 public void save(final ModuleEntityBean bean) {
99
100
101 }
102
103 public abstract Map<String, String> getQueryParameter(final String objectId);
104
105 public Map<Integer, String> getColumnMappings() {
106 return this.mappingManager.getMappingForClass(this.entityClass);
107 }
108
109
110
111
112 public IQuery createQuery() {
113 return this.session.createQuery(this.moduleName);
114 }
115
116
117
118
119 public void setMappingManager(final IMappingManager mappingManager) {
120 this.mappingManager = mappingManager;
121 }
122
123
124
125
126 public IGroupwareSession<FolderBean> getSession() {
127 return this.session;
128 }
129
130
131
132
133 public void setSession(final IGroupwareSession<FolderBean> session) {
134 this.session = session;
135 }
136
137
138
139
140 protected Class<ModuleEntityBean> getEntityClass() {
141 return this.entityClass;
142 }
143 }