Source Code Cross Referenced for GroupsController.java in  » Web-Mail » claros-intouch2-2.2-beta » org » claros » intouch » contacts » controllers » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Web Mail » claros intouch2 2.2 beta » org.claros.intouch.contacts.controllers 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        package org.claros.intouch.contacts.controllers;
002:
003:        import java.sql.SQLException;
004:        import java.util.HashMap;
005:        import java.util.List;
006:        import java.util.Locale;
007:
008:        import org.apache.commons.dbutils.QueryRunner;
009:        import org.apache.commons.dbutils.handlers.MapHandler;
010:        import org.claros.commons.auth.models.AuthProfile;
011:        import org.claros.commons.db.DbConfigList;
012:        import org.claros.commons.exception.NoPermissionException;
013:        import org.claros.intouch.common.utility.Constants;
014:        import org.claros.intouch.common.utility.Utility;
015:        import org.claros.intouch.contacts.models.ContactGroup;
016:        import org.claros.intouch.contacts.models.ContactGroupObject;
017:
018:        import com.jenkov.mrpersister.impl.mapping.AutoGeneratedColumnsMapper;
019:        import com.jenkov.mrpersister.itf.IGenericDao;
020:        import com.jenkov.mrpersister.itf.mapping.IObjectMappingKey;
021:        import com.jenkov.mrpersister.util.JdbcUtil;
022:
023:        /**
024:         * @author Umut Gokbayrak
025:         */
026:        public class GroupsController {
027:
028:            /**
029:             * 
030:             * @param auth
031:             * @return
032:             * @throws Exception
033:             */
034:            public static List getGroupsByUser(AuthProfile auth)
035:                    throws Exception {
036:                IGenericDao dao = null;
037:                List groups = null;
038:                try {
039:                    dao = Utility.getDbConnection();
040:                    String username = auth.getUsername();
041:                    String sql = "SELECT * FROM CONTACT_GROUPS WHERE USERNAME=?";
042:                    groups = dao.readList(ContactGroup.class, sql,
043:                            new Object[] { username });
044:                } finally {
045:                    JdbcUtil.close(dao);
046:                    dao = null;
047:                }
048:                return groups;
049:            }
050:
051:            /**
052:             * 
053:             * @param auth
054:             * @param id
055:             * @return
056:             * @throws Exception
057:             */
058:            public static List getGroupItemsByGroup(AuthProfile auth, Long id)
059:                    throws Exception {
060:                IGenericDao dao = null;
061:                List items = null;
062:                try {
063:                    dao = Utility.getDbConnection();
064:                    String username = auth.getUsername();
065:                    String sql = "SELECT * FROM CONTACT_GROUP_OBJECTS WHERE USERNAME=? AND GROUP_ID = ?";
066:                    items = dao.readList(ContactGroupObject.class, sql,
067:                            new Object[] { username, id });
068:                } finally {
069:                    JdbcUtil.close(dao);
070:                    dao = null;
071:                }
072:                return items;
073:            }
074:
075:            /**
076:             * 
077:             * @param auth
078:             * @param id
079:             * @return
080:             * @throws Exception
081:             */
082:            public static Integer getMemberCountByGroup(AuthProfile auth,
083:                    Long id) throws Exception {
084:                QueryRunner run = new QueryRunner(DbConfigList
085:                        .getDataSourceById("file"));
086:                HashMap result = null;
087:                String username = auth.getUsername();
088:                try {
089:                    String sql = "SELECT COUNT(*) AS NUMBER FROM CONTACT_GROUP_OBJECTS WHERE USERNAME=? AND GROUP_ID = ? ";
090:                    result = (HashMap) run.query(sql, new Object[] { username,
091:                            id }, new MapHandler());
092:                } catch (SQLException e) {
093:                    return new Integer(0);
094:                }
095:                if (result != null) {
096:                    return new Integer(result.get("number").toString());
097:                }
098:                return new Integer(0);
099:            }
100:
101:            /**
102:             * @param auth
103:             * @param long1
104:             */
105:            public static void deleteGroups(AuthProfile auth, Long id[])
106:                    throws Exception {
107:                if (id != null) {
108:                    Long tmp = null;
109:                    ContactGroup cgTmp = null;
110:                    String sql = null;
111:                    for (int i = 0; i < id.length; i++) {
112:                        tmp = id[i];
113:                        cgTmp = getGroupById(auth, tmp);
114:                        if (!cgTmp.getUsername().equals(auth.getUsername())) {
115:                            throw new NoPermissionException();
116:                        }
117:
118:                        IGenericDao dao = null;
119:                        try {
120:                            dao = Utility.getDbConnection();
121:                            sql = "DELETE FROM CONTACT_GROUP_OBJECTS WHERE USERNAME = ? AND GROUP_ID = ?";
122:                            dao.executeUpdate(sql, new Object[] {
123:                                    auth.getUsername(), tmp });
124:                            dao.deleteByPrimaryKey(ContactGroup.class, tmp);
125:                        } catch (Exception e) {
126:                            e.printStackTrace();
127:                        } finally {
128:                            JdbcUtil.close(dao);
129:                            dao = null;
130:                        }
131:                    }
132:                }
133:            }
134:
135:            /**
136:             * @param auth
137:             * @param tmp
138:             * @return
139:             */
140:            public static ContactGroup getGroupById(AuthProfile auth, Long id)
141:                    throws Exception {
142:                IGenericDao dao = null;
143:                ContactGroup result = null;
144:                try {
145:                    dao = Utility.getDbConnection();
146:                    result = (ContactGroup) dao.readByPrimaryKey(
147:                            ContactGroup.class, id);
148:
149:                    if (!result.getUsername().equals(auth.getUsername())) {
150:                        throw new NoPermissionException();
151:                    }
152:                } finally {
153:                    JdbcUtil.close(dao);
154:                    dao = null;
155:                }
156:                return result;
157:            }
158:
159:            /**
160:             * @param auth
161:             * @param string
162:             * @param strings
163:             */
164:            @SuppressWarnings("deprecation")
165:            public static void addGroup(AuthProfile auth, String groupName,
166:                    String[] members) throws Exception {
167:                IGenericDao dao = null;
168:                try {
169:                    dao = Utility.getDbConnection();
170:
171:                    ContactGroup grp = new ContactGroup();
172:                    grp.setShortName(groupName);
173:                    grp.setDescription("");
174:                    grp.setUsername(auth.getUsername());
175:
176:                    IObjectMappingKey myObj = Constants.persistMan
177:                            .getObjectMappingFactory().createInstance(
178:                                    ContactGroup.class,
179:                                    new AutoGeneratedColumnsMapper(true));
180:                    dao.insert(myObj, grp);
181:
182:                    // find the group id for the previous insertion
183:                    String sql = "SELECT * FROM CONTACT_GROUPS WHERE USERNAME = ? AND SHORT_NAME = ? ORDER BY ID DESC";
184:                    List added = dao.readList(ContactGroup.class, sql,
185:                            new Object[] { auth.getUsername(), groupName });
186:                    if (added != null && added.size() > 0) {
187:                        ContactGroup tmp = (ContactGroup) added.get(0);
188:                        Long id = tmp.getId();
189:
190:                        // add the members to the items list
191:                        if (members != null) {
192:                            Long t = null;
193:                            IObjectMappingKey myObj2 = Constants.persistMan
194:                                    .getObjectMappingFactory()
195:                                    .createInstance(
196:                                            ContactGroupObject.class,
197:                                            new AutoGeneratedColumnsMapper(true));
198:                            for (int i = 0; i < members.length; i++) {
199:                                try {
200:                                    t = new Long(members[i]);
201:                                    ContactGroupObject item = new ContactGroupObject();
202:                                    item.setUsername(auth.getUsername());
203:                                    item.setGroupId(id);
204:                                    item.setContactId(t);
205:                                    dao.insert(myObj2, item);
206:                                } catch (Exception e) {
207:                                    // do nothing sier
208:                                }
209:                            }
210:                        }
211:                    }
212:                } finally {
213:                    JdbcUtil.close(dao);
214:                    dao = null;
215:                }
216:            }
217:
218:            /**
219:             * @param auth
220:             * @param strAdr
221:             * @return
222:             */
223:            public static ContactGroup searchByName(AuthProfile auth,
224:                    String strAdr) throws Exception {
225:                IGenericDao dao = null;
226:                ContactGroup group = null;
227:                try {
228:                    dao = Utility.getDbConnection();
229:                    String username = auth.getUsername();
230:                    strAdr = strAdr.toUpperCase(new Locale("en", "US"));
231:                    String sql = "SELECT * FROM CONTACT_GROUPS WHERE USERNAME=? AND UPPER(SHORT_NAME) = ?";
232:                    group = (ContactGroup) dao.read(ContactGroup.class, sql,
233:                            new Object[] { username, strAdr });
234:                } finally {
235:                    JdbcUtil.close(dao);
236:                    dao = null;
237:                }
238:                return group;
239:            }
240:
241:            /**
242:             * @param username
243:             * @param name
244:             * @return
245:             */
246:            public static List searchByLikeName(String username, String name)
247:                    throws Exception {
248:                IGenericDao dao = null;
249:                List groups = null;
250:                try {
251:                    dao = Utility.getDbConnection();
252:                    name = name.toUpperCase(new Locale("en", "US"));
253:                    String sql = "SELECT * FROM CONTACT_GROUPS WHERE USERNAME=? AND UPPER(SHORT_NAME) LIKE '%"
254:                            + name + "%'";
255:                    groups = dao.readList(ContactGroup.class, sql,
256:                            new Object[] { username });
257:                } finally {
258:                    JdbcUtil.close(dao);
259:                    dao = null;
260:                }
261:                return groups;
262:            }
263:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.