Source Code Cross Referenced for GroupsController.java in  » Chat » claros-intouch » 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 » Chat » claros intouch » 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:            public static void addGroup(AuthProfile auth, String groupName,
165:                    String[] members) throws Exception {
166:                IGenericDao dao = null;
167:                try {
168:                    dao = Utility.getDbConnection();
169:
170:                    ContactGroup grp = new ContactGroup();
171:                    grp.setShortName(groupName);
172:                    grp.setDescription("");
173:                    grp.setUsername(auth.getUsername());
174:
175:                    IObjectMappingKey myObj = Constants.persistMan
176:                            .getObjectMappingFactory().createInstance(
177:                                    ContactGroup.class,
178:                                    new AutoGeneratedColumnsMapper(true));
179:                    dao.insert(myObj, grp);
180:
181:                    // find the group id for the previous insertion
182:                    String sql = "SELECT * FROM CONTACT_GROUPS WHERE USERNAME = ? AND SHORT_NAME = ? ORDER BY ID DESC";
183:                    List added = dao.readList(ContactGroup.class, sql,
184:                            new Object[] { auth.getUsername(), groupName });
185:                    if (added != null && added.size() > 0) {
186:                        ContactGroup tmp = (ContactGroup) added.get(0);
187:                        Long id = tmp.getId();
188:
189:                        // add the members to the items list
190:                        if (members != null) {
191:                            Long t = null;
192:                            IObjectMappingKey myObj2 = Constants.persistMan
193:                                    .getObjectMappingFactory()
194:                                    .createInstance(
195:                                            ContactGroupObject.class,
196:                                            new AutoGeneratedColumnsMapper(true));
197:                            for (int i = 0; i < members.length; i++) {
198:                                try {
199:                                    t = new Long(members[i]);
200:                                    ContactGroupObject item = new ContactGroupObject();
201:                                    item.setUsername(auth.getUsername());
202:                                    item.setGroupId(id);
203:                                    item.setContactId(t);
204:                                    dao.insert(myObj2, item);
205:                                } catch (Exception e) {
206:                                    // do nothing sier
207:                                }
208:                            }
209:                        }
210:                    }
211:                } finally {
212:                    JdbcUtil.close(dao);
213:                    dao = null;
214:                }
215:            }
216:
217:            /**
218:             * @param auth
219:             * @param strAdr
220:             * @return
221:             */
222:            public static ContactGroup searchByName(AuthProfile auth,
223:                    String strAdr) throws Exception {
224:                IGenericDao dao = null;
225:                ContactGroup group = null;
226:                try {
227:                    dao = Utility.getDbConnection();
228:                    String username = auth.getUsername();
229:                    strAdr = strAdr.toUpperCase(new Locale("en", "US"));
230:                    String sql = "SELECT * FROM CONTACT_GROUPS WHERE USERNAME=? AND UPPER(SHORT_NAME) = ?";
231:                    group = (ContactGroup) dao.read(ContactGroup.class, sql,
232:                            new Object[] { username, strAdr });
233:                } finally {
234:                    JdbcUtil.close(dao);
235:                    dao = null;
236:                }
237:                return group;
238:            }
239:
240:            /**
241:             * @param username
242:             * @param name
243:             * @return
244:             */
245:            public static List searchByLikeName(String username, String name)
246:                    throws Exception {
247:                IGenericDao dao = null;
248:                List groups = null;
249:                try {
250:                    dao = Utility.getDbConnection();
251:                    name = name.toUpperCase(new Locale("en", "US"));
252:                    String sql = "SELECT * FROM CONTACT_GROUPS WHERE USERNAME=? AND UPPER(SHORT_NAME) LIKE '%"
253:                            + name + "%'";
254:                    groups = dao.readList(ContactGroup.class, sql,
255:                            new Object[] { username });
256:                } finally {
257:                    JdbcUtil.close(dao);
258:                    dao = null;
259:                }
260:                return groups;
261:            }
262:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.