Source Code Cross Referenced for NotesFolderController.java in  » Chat » claros-intouch » org » claros » intouch » notes » 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.notes.controllers 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        package org.claros.intouch.notes.controllers;
002:
003:        import java.math.BigDecimal;
004:        import java.math.BigInteger;
005:        import java.util.HashMap;
006:        import java.util.List;
007:
008:        import org.apache.commons.dbutils.QueryRunner;
009:        import org.apache.commons.dbutils.handlers.MapHandler;
010:        import org.apache.commons.logging.Log;
011:        import org.apache.commons.logging.LogFactory;
012:        import org.claros.commons.auth.models.AuthProfile;
013:        import org.claros.commons.db.DbConfigList;
014:        import org.claros.commons.exception.NoPermissionException;
015:        import org.claros.intouch.common.utility.Constants;
016:        import org.claros.intouch.common.utility.Utility;
017:        import org.claros.intouch.notes.models.NotesFolder;
018:
019:        import com.jenkov.mrpersister.impl.mapping.AutoGeneratedColumnsMapper;
020:        import com.jenkov.mrpersister.itf.IGenericDao;
021:        import com.jenkov.mrpersister.itf.mapping.IObjectMappingKey;
022:        import com.jenkov.mrpersister.util.JdbcUtil;
023:
024:        /**
025:         * @author Umut Gokbayrak
026:         */
027:        public class NotesFolderController {
028:            private static Log log = LogFactory
029:                    .getLog(NotesFolderController.class);
030:
031:            /**
032:             * 
033:             * @param auth
034:             * @return
035:             * @throws Exception
036:             */
037:            public static List getFolders(AuthProfile auth) throws Exception {
038:                IGenericDao dao = null;
039:                List folders = null;
040:                try {
041:                    dao = Utility.getDbConnection();
042:                    String username = auth.getUsername();
043:
044:                    String sql = "SELECT * FROM NOTES_FOLDERS WHERE USERNAME = ?";
045:
046:                    folders = dao.readList(NotesFolder.class, sql,
047:                            new Object[] { username });
048:                } finally {
049:                    JdbcUtil.close(dao);
050:                    dao = null;
051:                }
052:                return folders;
053:            }
054:
055:            /**
056:             * 
057:             * @param auth
058:             * @param folder
059:             * @throws Exception
060:             */
061:            public static Long saveFolder(AuthProfile auth, NotesFolder folder)
062:                    throws Exception {
063:                IGenericDao dao = null;
064:                Long resId = new Long(-1);
065:                try {
066:                    dao = Utility.getDbConnection();
067:
068:                    Long id = folder.getId();
069:                    if (id == null) {
070:                        // it is an insert
071:                        IObjectMappingKey myObj = Constants.persistMan
072:                                .getObjectMappingFactory().createInstance(
073:                                        NotesFolder.class,
074:                                        new AutoGeneratedColumnsMapper(true));
075:                        dao.insert(myObj, folder);
076:
077:                        QueryRunner run = new QueryRunner(DbConfigList
078:                                .getDataSourceById("file"));
079:                        String username = auth.getUsername();
080:                        String sql = "SELECT MAX(ID) AS NUMBER FROM NOTES_FOLDERS WHERE USERNAME=?";
081:                        HashMap result = (HashMap) run.query(sql,
082:                                new Object[] { username }, new MapHandler());
083:                        Object hbl = result.get("number");
084:                        if (hbl instanceof  Long) {
085:                            resId = new Long(((Long) hbl).longValue());
086:                        } else if (hbl instanceof  Integer) {
087:                            resId = new Long(((Integer) hbl).longValue());
088:                        } else if (hbl instanceof  BigDecimal) {
089:                            resId = new Long(((BigDecimal) hbl).longValue());
090:                        } else if (hbl instanceof  BigInteger) {
091:                            resId = new Long(((BigInteger) hbl).longValue());
092:                        }
093:                    } else {
094:                        // it is an update
095:                        NotesFolder tmp = getFolderById(auth, folder.getId());
096:                        String user = tmp.getUsername();
097:                        if (!auth.getUsername().equals(user)) {
098:                            throw new NoPermissionException();
099:                        }
100:                        dao.update(folder);
101:                    }
102:                } finally {
103:                    JdbcUtil.close(dao);
104:                    dao = null;
105:                }
106:                return resId;
107:            }
108:
109:            /**
110:             * 
111:             * @param auth
112:             * @param folderId
113:             * @throws Exception
114:             */
115:            public static void deleteFolder(AuthProfile auth, Long folderId)
116:                    throws Exception {
117:                IGenericDao dao = null;
118:                try {
119:                    dao = Utility.getTxnDbConnection();
120:                    String username = auth.getUsername();
121:
122:                    NotesFolder folder = getFolderById(auth, folderId);
123:                    if (!folder.getUsername().equals(auth.getUsername())) {
124:                        throw new NoPermissionException();
125:                    }
126:
127:                    String sql = "DELETE FROM NOTES WHERE USERNAME=? AND FOLDER_ID = ?";
128:                    // delete the notes under folder
129:                    dao.executeUpdate(sql, new Object[] { username, folderId });
130:                    // delete the folder
131:                    dao.deleteByPrimaryKey(NotesFolder.class, folderId);
132:                    dao.commit();
133:                } catch (Exception e) {
134:                    //			dao.rollback();
135:                    //			throw e;
136:                    log.warn("error while deleting folder", e);
137:                } finally {
138:                    JdbcUtil.close(dao);
139:                    dao = null;
140:                }
141:            }
142:
143:            /**
144:             * @param auth
145:             * @param folderId
146:             * @return
147:             */
148:            public static NotesFolder getFolderById(AuthProfile auth,
149:                    Long folderId) throws Exception {
150:                IGenericDao dao = null;
151:                NotesFolder folder = null;
152:                try {
153:                    dao = Utility.getDbConnection();
154:                    String username = auth.getUsername();
155:
156:                    String sql = "SELECT * FROM NOTES_FOLDERS WHERE USERNAME=? AND ID = ?";
157:
158:                    folder = (NotesFolder) dao.read(NotesFolder.class, sql,
159:                            new Object[] { username, folderId });
160:                } finally {
161:                    JdbcUtil.close(dao);
162:                    dao = null;
163:                }
164:                return folder;
165:            }
166:
167:            /**
168:             * 
169:             * @param auth
170:             * @param folderId
171:             * @throws Exception
172:             */
173:            public static void emptyFolder(AuthProfile auth, Long folderId)
174:                    throws Exception {
175:                QueryRunner run = new QueryRunner(DbConfigList
176:                        .getDataSourceById("file"));
177:                String username = auth.getUsername();
178:                String sql = "DELETE FROM NOTES WHERE USERNAME=? AND FOLDER_ID=?";
179:                run.update(sql, new Object[] { username, folderId });
180:            }
181:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.