-
Notifications
You must be signed in to change notification settings - Fork 11
/
Page1DaoMgr.java
225 lines (215 loc) · 8.41 KB
/
Page1DaoMgr.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
/* © 2023 iamfortress.net */
package com.mycompany.dao;
import com.mycompany.GlobalIds;
import org.apache.directory.fortress.web.control.SecUtils;
import org.apache.ibatis.session.SqlSession;
import org.apache.wicket.Component;
import org.apache.wicket.injection.Injector;
import org.apache.wicket.spring.injection.annot.SpringBean;
import org.apache.directory.fortress.core.AccessMgr;
import java.io.Serializable;
import java.util.List;
/**
* Example Page DAO Impl for apache-fortress-demo Wicket sample project. It is used to demonstrate data level security capabilities.
*
* @author Shawn McKinney
* @version $Rev$
*/
public class Page1DaoMgr implements Serializable
{
@SpringBean
private AccessMgr accessMgr;
public Page1DaoMgr()
{
Injector.get().inject(this);
}
/**
* Add a new Page1 entity to the database.
*
* @param page1EO Contains Page1 data.
* @return Page1 entity containing current data in table.
*/
public Page1EO addPage1( Page1EO page1EO, Component component )
{
SqlSession sqlSession = ConnectionFactory.getSqlSessionFactory().openSession();
try
{
if( SecUtils.checkAccess( component, accessMgr, GlobalIds.PAGE1_OBJNAME, GlobalIds.ADD, page1EO
.getCustomer() ))
{
Page1Dao page1DaoMapper = sqlSession.getMapper( Page1Dao.class );
Integer id = page1DaoMapper.getMaxId();
id = id == null ? 1 : id + 1;
page1EO.setId( id );
int rc = page1DaoMapper.addPage1( page1EO );
sqlSession.commit();
page1EO = page1DaoMapper.getPage1ById( id );
}
else throw new RuntimeException( "User not Authorized: " + GlobalIds.PAGE1_OBJNAME + "." + GlobalIds.ADD + "." + page1EO.getCustomer() );
}
catch ( Exception e )
{
String error = "addPage1 caught Exception=" + e;
throw new RuntimeException( error );
}
finally
{
sqlSession.close();
}
return page1EO;
}
/**
* Update an existing Page1 entity to the database.
*
* @param page1EO Contains Page1 data.
* @return Page1 entity containing current data in table.
*/
public Page1EO updatePage1( Page1EO page1EO, Component component )
{
SqlSession sqlSession = ConnectionFactory.getSqlSessionFactory().openSession();
try
{
if( SecUtils.checkAccess( component, accessMgr, GlobalIds.PAGE1_OBJNAME, GlobalIds.UPDATE, page1EO
.getCustomer() ))
{
Page1Dao page1DaoMapper = sqlSession.getMapper( Page1Dao.class );
int rc = page1DaoMapper.updatePage1( page1EO );
sqlSession.commit();
page1EO = page1DaoMapper.getPage1ById( page1EO.getId() );
}
else throw new RuntimeException( "User not Authorized:" + GlobalIds.PAGE1_OBJNAME + "." + GlobalIds.UPDATE + "." + page1EO.getCustomer() );
}
catch ( Exception e )
{
String error = "updatePage1 caught Exception=" + e;
throw new RuntimeException( error );
}
finally
{
sqlSession.close();
}
return page1EO;
}
/**
* Return all Page1 entities that match attr A parameter.
*
* @param component contains reference to calling wicket component.
* @param page1EO contains reference to page entity.
* @return List of type Page1 entity.
*/
public List<Page1EO> getPages1ByAttrA( Page1EO page1EO, Component component )
{
List<Page1EO> pages = null;
SqlSession sqlSession = ConnectionFactory.getSqlSessionFactory().openSession();
try
{
if(SecUtils.checkAccess( component, accessMgr, GlobalIds.PAGE1_OBJNAME, GlobalIds.SEARCH_A, page1EO.getCustomer() ))
{
Page1Dao page1DaoMapper = sqlSession.getMapper( Page1Dao.class );
pages = page1DaoMapper.getPages1ByAttrA( page1EO.getAttr_a() + "%" );
}
else throw new RuntimeException( "User not Authorized: " + GlobalIds.PAGE1_OBJNAME + "." + GlobalIds.SEARCH_A + "." + page1EO.getCustomer());
}
catch ( Exception e )
{
String error = "getPages1ByAttrA attribute value [" + page1EO.getAttr_a() + "], caught Exception=" + e;
throw new RuntimeException( error );
}
finally
{
sqlSession.close();
}
return pages;
}
/**
* Return all Page1 entities that match customer parameter.
*
* @param component contains reference to calling wicket component.
* @param page1EO contains reference to page entity.
* @return List of type Page1 entity.
*/
public List<Page1EO> getPages1ByCustomer( Page1EO page1EO, Component component )
{
List<Page1EO> pages = null;
SqlSession sqlSession = ConnectionFactory.getSqlSessionFactory().openSession();
try
{
if(SecUtils.checkAccess( component, accessMgr, GlobalIds.PAGE1_OBJNAME, GlobalIds.SEARCH, page1EO.getCustomer() ))
{
Page1Dao page1DaoMapper = sqlSession.getMapper( Page1Dao.class );
pages = page1DaoMapper.getPages1ByCustomer( page1EO.getCustomer() + "%" );
}
else throw new RuntimeException( "User not Authorized: " + GlobalIds.PAGE1_OBJNAME + "." + GlobalIds.SEARCH + "." + page1EO.getCustomer());
}
catch ( Exception e )
{
String error = "getPages1ByCustomer customer number [" + page1EO.getCustomer() + "], caught Exception, errorId=" + e;
e.printStackTrace();
throw new RuntimeException( error );
}
finally
{
sqlSession.close();
}
return pages;
}
/**
* Return Page1 entity that matches id.
*
* @param component contains reference to calling wicket component.
* @param page1EO contains reference to page entity.
* @return Page1 entity containing current match.
*/
public Page1EO getPage1ById( Page1EO page1EO, Component component )
{
Page1EO page1 = null;
SqlSession sqlSession = ConnectionFactory.getSqlSessionFactory().openSession();
try
{
if(SecUtils.checkAccess( component, accessMgr, GlobalIds.PAGE1_OBJNAME, GlobalIds.READ, page1EO.getCustomer() ))
{
Page1Dao page1DaoMapper = sqlSession.getMapper( Page1Dao.class );
page1 = page1DaoMapper.getPage1ById( page1EO.getId() );
}
else throw new RuntimeException( "User not Authorized: " + GlobalIds.PAGE1_OBJNAME + "." + GlobalIds.READ + "." + page1EO.getCustomer());
}
catch ( Exception e )
{
String error = "getPage1ById id value [" + page1EO.getId() + "], caught Exception=" + e;
throw new RuntimeException( error );
}
finally
{
sqlSession.close();
}
return page1;
}
/**
* Remove Page1 entity that matches id parameter.
*
* @param page1EO must be populated with {@link Page1EO#getCustomer()} and {@link Page1EO#getId()}.
*/
public void deletePage1ById( Page1EO page1EO, Component component )
{
SqlSession sqlSession = ConnectionFactory.getSqlSessionFactory().openSession();
try
{
if(SecUtils.checkAccess( component, accessMgr, GlobalIds.PAGE1_OBJNAME, GlobalIds.DELETE, page1EO.getCustomer() ))
{
Page1Dao page1DaoMapper = sqlSession.getMapper( Page1Dao.class );
page1DaoMapper.deletePage1ById( page1EO.getId() );
sqlSession.commit();
}
else throw new RuntimeException( "User not Authorized: " + GlobalIds.PAGE1_OBJNAME + "." + GlobalIds.DELETE + "." + page1EO.getCustomer());
}
catch ( Exception e )
{
String error = "deletePage1ById id value [" + page1EO.getId() + "], caught Exception=" + e;
throw new RuntimeException( error );
}
finally
{
sqlSession.close();
}
}
}