SACFILES PORTLET APPLICATION Gaurang V. Dave B.E., Pune University, India, 2007 PROJECT Submitted in partial satisfaction of the requirements for the degree of MASTER OF SCIENCE in COMPUTER SCIENCE at CALIFORNIA STATE UNIVERSITY, SACRAMENTO SPRING 2012 SACFILES PORTLET APPLICATION A Project by Gaurang V. Dave Approved by: __________________________________, Committee Chair Jinsong Ouyang, Ph.D. __________________________________, Second Advisor V. Scott Gordon, Ph.D. ____________________________ Date ii Student: Gaurang V. Dave I certify that this student has met the requirements for format contained in the University format manual, and that this project is suitable for shelving in the Library and credit is to be awarded for the Project. __________________________, Graduate Coordinator Nikrouz Faroughi, Ph.D. Department of Computer Science iii ________________ Date Abstract of SACFILES PORTLET APPLICATION by Gaurang V. Dave The Information Resources and Technology department at California State University, Sacramento manages a large campus wide file storage system called SacFiles. Every student, faculty and staff members are granted a 2 GB space in a network drive, which they can access from any computer on CSUS domain. One of the major advantages of this system is that the user’s files are always safe from malicious attacks behind firewalls along with many other security features, also users do not have to worry about losing the data as it always backed up on campus-wide servers. Currently the only way users can access their data on the SacFiles drive is by accessing it on campus from a CSUS domain computer or by manually mapping the network drive to either their Mac or a Windows computer. With constantly updating technology where there are hand held devices like iPhone and iPad, the use of laptops and computers is slowly becoming obsolete. If the network drive is inaccessible via such devices, it defies the purpose of this highly advantageous system. The purpose of my project is to design, develop and implement a channel for My Sac State that will provide the users an easy access to the network drive. My Sac State is an online portal where Sac State users can log in using their sac link id and password and access all the information related to the users. By providing the Sac Files channel, the users will be able to access their network drive simply logging into My Sac State. Thus, the drive will be accessible to iv any user at any place with a browser enabled device and internet connection. The users will be able to download files, upload new files, delete files as well as organize files by creating directories and sub-directories. The successful implementation of the project will not only help users take advantage of facilities provided by the SacFiles network drive, but will also give them an added benefit of accessibility to the drive via any browser-enabled network drive. The accomplishment of this project will be increased efficiency of Sac Files system and My Sac State portal. My Sac State will become a one-stop solution for all user information and data, which will result into increased satisfaction of all the portal users. ___________________________, Committee Chair Jinsong Ouyang, Ph.D. ___________________________ Date v ACKNOWLEDGEMENTS I would like to thank all those people who have helped me in any possible way to successfully finish this project. To begin with, I would like to thank Dr. Jinsong Ouyang, my project advisor, for taking active interest in my project. His suggestions and guidance have helped me complete this project. I would like to thank Dr. V. Scott Gordon for being second advisor in this project. I would also like to thank Dr. Nikrouz Faroughi, Graduate Coordinator of Computer Science Department, for his support. I would like to thank Dan Biondi (Web Portal Coordinator) and Jeff Dillon (Web Services Manager) for trusting me with this project providing me with all the information and resources required to implement the project. Finally, I would like to thank all my friends and family members who always stood by me and supported me. vi TABLE OF CONTENTS Page Acknowledgements ......................................................................................................................... vi List Of Figures ................................................................................................................................ ix Chapter 1. INTRODUCTION ....................................................................................................................... 1 1.1 Project Motivation ................................................................................................................ 1 1.2 Objective ............................................................................................................................... 2 2. PROJECT REQUIREMENTS ..................................................................................................... 3 2.1 Functional Requirements ...................................................................................................... 3 2.2 Non-Functional Requirements .............................................................................................. 8 3. ARCHITECTURE DESIGN ..................................................................................................... 12 3.1 Three Tier Architecture....................................................................................................... 12 3.2 Presentation Tier ................................................................................................................. 14 3.3 Portlet Application Tier ...................................................................................................... 16 3.4 SacFiles File Server ............................................................................................................ 19 3.5 Application Logic Architecture .......................................................................................... 20 3.6 SacFiles Portlet Application Components .......................................................................... 23 4. SYSTEM IMPLEMENTATION ............................................................................................... 24 4.1 Tools Required for the Application Development .............................................................. 24 4.2. SacFiles Portlet Directory Structure .................................................................................. 32 4.3 Portlet.xml.......................................................................................................................... 33 4.4. Web.xml............................................................................................................................. 37 vii 4.5. Implementing Model Layer ............................................................................................... 38 4.6. Implementing Controller.................................................................................................... 52 4.7. Building and Deploying the Portlet ................................................................................... 61 5. SACFILES PORTLET APPLICATION USER GUIDE ........................................................... 77 5.1 Creating new folder and sub folder on the server ............................................................... 78 5.2 Upload files to the server .................................................................................................... 81 5.3 Download files from the server........................................................................................... 84 5.4 Rename files on the server .................................................................................................. 86 5.5 Rename folders on the server .............................................................................................. 89 5.6 Deleting files from the server ............................................................................................. 92 5.7 Deleting folders from the server ......................................................................................... 95 6. SUMMARY AND FUTURE WORK ....................................................................................... 98 Bibliography ................................................................................................................................ 100 viii LIST OF FIGURES Figures Page Figure 1: Use Case Diagram for SacFiles Portlet Application ........................................... 3 Figure 2: Three Tier implementation of SacFiles Portlet Application. ............................ 13 Figure 3: SacFiles Portlet Application Components ......................................................... 23 Figure 4: Verify Java Installation ..................................................................................... 25 Figure 5: Verify Ant Installation....................................................................................... 26 Figure 6: Verify Maven Installation ................................................................................. 28 Figure 7: Start uPortal ....................................................................................................... 29 Figure 8: uPortal Login Page ............................................................................................ 30 Figure 9: Installing Maven Plug-in for Eclipse................................................................. 31 Figure 10: Project File Structure for SacFiles Portlet Application ................................... 32 Figure 11: portlet.xml of SacFiles Portlet Application. .................................................... 34 Figure 12: web.xml for SacFiles Portlet Application. ...................................................... 37 Figure 13: Code Snippet for Authentication Logic........................................................... 39 Figure 14: Code Snippet for Reading User Folder Contents ............................................ 40 Figure 15: Code Snippet for Download File Logic .......................................................... 41 Figure 16: Code Snippet for Upload File Logic ............................................................... 43 Figure 17: Code Snippet for SacFiles Portlet in Normal Window State .......................... 44 Figure 18: SacFiles Portlet in Normal Window State ....................................................... 45 Figure 19: Code Snippet for creating jQuery File Tree .................................................... 46 ix Figure 20: SacFiles Portlet in Maximized Window State ................................................. 47 Figure 21: Code Snippet for Initialization and Creating jQuery Context Menus ............. 49 Figure 22: Context Menu for SacFiles Portlet in Maximized Window State ................... 50 Figure 23: Code Snippet for making AJAX Calls ............................................................ 51 Figure 24: Code Snippet for SacFilesPortlet init() Method .............................................. 53 Figure 25: Code Snippet for SacFilesPortlet doView() Method ....................................... 55 Figure 26: Code Snippet for SacFilesPortlet processAction() Method ............................ 57 Figure 27: Code Snippet FileServlet doGet() Method ...................................................... 59 Figure 28: Code Snippet FileServlet downloadUserFile() Method .................................. 60 Figure 29: Building Portlet App from Eclipse IDE – Maven Clean ................................. 61 Figure 30: Building Portlet App from Eclipse IDE – Maven Install ................................ 62 Figure 31: Building Portlet App from Eclipse IDE – Build Success ................................ 63 Figure 32: Building Portlet App using Command Line .................................................... 64 Figure 33: Deploying Portlet App..................................................................................... 65 Figure 34: Publishing Portlet App Step 1 ......................................................................... 66 Figure 35: Publishing Portlet App Step 2 ......................................................................... 67 Figure 36: Publishing Portlet App Step 3 ......................................................................... 68 Figure 37: Publishing Portlet App Step 4 ......................................................................... 69 Figure 38: Publishing Portlet App Step 5 ......................................................................... 70 Figure 39: Publishing Portlet App Step 6 ......................................................................... 71 Figure 40: Publishing Portlet App Step 7 ......................................................................... 72 x Figure 41: Publishing Portlet App Step 8 ......................................................................... 73 Figure 42: Publishing Portlet App Step 9 ......................................................................... 74 Figure 43: Subscribing Portlet App Step 1 ....................................................................... 75 Figure 44: Subscribing Portlet App Step 2 ....................................................................... 76 Figure 45: Creating New Folder Step 1 ............................................................................ 78 Figure 46: Creating New Folder Step 2 ............................................................................ 79 Figure 47: Creating New Folder Step 3 ............................................................................ 80 Figure 48: Uploading New Files Step 1 ............................................................................ 81 Figure 49: Uploading New Files Step 2 ............................................................................ 82 Figure 50: Uploading New Files Step 3 ............................................................................ 83 Figure 51: Downloading Files Step 1 ............................................................................... 84 Figure 52: Downloading Files Step 2 ............................................................................... 85 Figure 53: Rename Files on Server Step 1........................................................................ 86 Figure 54: Rename Files on Server Step 2........................................................................ 87 Figure 55: Rename Files on Server Step 3........................................................................ 88 Figure 56: Rename Folders on Server Step 1 ................................................................... 89 Figure 57: Rename Folders on Server Step 2 ................................................................... 90 Figure 58: Rename Folders on Server Step 3 ................................................................... 91 Figure 59: Deleting Files from Server Step 1 ................................................................... 92 Figure 60: Deleting Files from Server Step 2 ................................................................... 93 Figure 61: Deleting Files from Server Step 3 ................................................................... 94 xi Figure 62: Deleting Folders from Server Step 1 ............................................................... 95 Figure 63: Deleting Folders from Server Step 2 ............................................................... 96 Figure 64: Deleting Folders from Server Step 3 ............................................................... 97 xii 1 Chapter 1 INTRODUCTION 1.1 Project Motivation The basic motivation behind this Master’s Project is the same as motivation behind any other software application developed; to solve a complex problem in order to decrease workload on human beings and make their lives easier. During their educational life, the students mainly depend on their class notes, homework assignments, reports, guides and other sources of information required to master the course and achieve their academic goals. Not only students, but also faculty members and other staff members create and collect information to make their day-to-day activities easy and efficient. In this advanced technological age, computers, smartphones and other digital devices capable of storing are used to create and store this information. However, along with the ease of use and storage comes the risk of losing or corrupting the data in case of theft or damage to the device. The IRT[1] department at CSUS[2] provides a safe and secure mechanism to store all such digital information in a campus-wide file server. This mechanism is available to all CSUS students, staff and faculty members, but is still not widely used due to its lack of usability and accessibility. The main motivation behind this Master’s Project is to make this network drive easily accessible to all the users of the CSUS community. The inspiration was to develop a web application for IRT that provides an interactive and platform independent access to the network drive and to enable users to take hassle-free advantage of the network drive. 2 1.2 Objective The students, faculty and staff members of CSUS create and consume a lot of digital information during their day-to-day life on campus. Devices like college computers, personal laptops or laptops rented from the IRT help desk, and other digital devices like tablets and smart phones create this information. IRT provides a service to all the CSUS members, which allow them to store their digital content on a campus-wide file server without the worry of losing the data because of theft or loss of device. Each user can access to 2GB space on the file server by authenticating with their Sac State id and password. Because the Sac State id is a unique identifier for each CSUS student, faculty and staff member, users can see and access information available on their network drive and no one else. However, the access to this network drive is limited to computers on the college domain and platform-dependent computers that can map the network locally. The objective of this project is to implement a web based portlet application that when deployed on My Sac State will allow users’ easy access their information on SacFiles network drive. Being a web based application; the users can use the network drive from any digital device with a browser and internet connection. The portlet application will not only allow users to view their data on the drive but will also facilitate them to download their files, edit and upload them or upload totally new files, organize their data by creating sub folders and renaming files, and finally deleting unwanted files and folders. On successful implementation and deployment, the portlet application will enhance the functional capabilities of My Sac State [3] making it one step closer to be a centralized solution to all the needs of CSUS students, faculty and staff members. 3 Chapter 2 PROJECT REQUIREMENTS 2.1 Functional Requirements The main requirement of the portlet application is to create an intuitive web-based interface to the SacFiles network drive in order to simplify the access to all the information stored on the drive. The users should not only be able to view their information online but should be able to modify, organize and delete it easily. The user should be able to interact with the application using just the mouse, or keyboard or both. Following use case diagram shows the functions users should be able to perform on the portlet application: Figure 1: Use Case Diagram for SacFiles Portlet Application 4 2.1.1 Create New Folder. This feature allows user to create new folders as well as sub-folders in the root directory. This is a very important functionality to enable users to organize their data. Following are the functional requirements defined for create new folder feature: User can initiate a new folder request with a mouse by right clicking the folder and selecting the option from the context menu. User can initiate a new folder request with a key board by tab navigating to the folder and pressing the keys “Alt + Shift + n”. User can create a new folder in any folder or sub-folder within their allocated user home directory User cannot create folder or sub folder outside their allocated user home directory. The newly created folder should be accessible to the user without the need for additional authentication or page refresh. 2.1.2 Upload Files. This feature allows users to add new files or overwrite current files on the SacFiles network drive. The feature allows user to upload any digital content to any folder or sub folder on their network drive. It provides a safe and secure mechanism to backup user data on the file server. Following are the functional requirements defined for the upload files feature: User can initiate the upload file request with a mouse by right clicking the folder and selecting the option from the context menu. 5 User can initiate the upload file request with a keyboard by tab navigating to the folder and pressing the keys “Alt + Shift + u.” User can upload any digital file to the network drive as long as the file size is less than or equal to the upload limit set by the server. User cannot upload files larger than available space on the file server. User can upload any digital file to any folder or sub folder within the allocated user home directory. User cannot upload any digital file to a folder outside the allocated user home directory. The newly uploaded file should be easily accessible to the user without the need for an additional authentication or page refresh. 2.1.3 Download Files. This feature allows the user to download the files from the SacFiles network drive to their local machine. The user can view the downloaded file, take a printout or edit it and upload it back on the server using the upload file feature. This is a very important and useful feature as it enables a user to access their files from any computer or a browser-enabled device. Following are the functional requirements defined for the download files feature: The user can initiate a download file request with a mouse by double clicking the file or by right clicking the file and selecting the option from the context menu. The user can initiate a download file request using key board by tabbing to the file and pressing enter key or by pressing keys Alt + Ctrl + g. 6 The user can download same file any number of times as long as the file is available on the server. There is no limit to the size of the file downloadable from the server. The user can only download files available to user on allocated user home directory The user cannot download files outside the allocated user home directory. After downloading the file, the user can use the file without the need of any additional authentication. 2.1.4 Rename Files and Folder. This feature enables the user to organize their content on the network drive by renaming different files and folders. Many different use cases determine the importance of this feature. Users can modify the file and then can rename it in order to maintain different versions of the same file. Users can fix file name typos or file extension errors without the need to downloading the file to do so. Whenever a new file or folder is added users can edit folder names and make it more relevant to the file structure. Following are the functional requirements that define the rename files and folder feature: Users can initiate a rename file or folder request with a mouse by right clicking it and choosing the selecting the option from context menu. User can initiate a rename file or folder request with a key board by tabbing down to the desired file or folder and pressing keys Alt + Shift + r. User can rename a file or folder any number of times. User cannot rename a file or folder to a name that already exists in the same folder. Renaming a folder cannot change the contents of the folder. 7 Renaming a folder cannot change the access permission for the folder. User cannot rename the home folder. Renaming a find cannot change the contents or functionality of the file. User can only change files or folders that are available in user home directory. User cannot change files or folders that are not available in user home directory. The renamed file should be accessible to the user without the need of additional authentication or page refresh. 2.1.5 Delete Files and Folder. This feature enables users to organize the files on the SacFiles network drive by removing the unwanted files and folders. Following are the functional requirements that define the delete files and folder feature: User can initiate delete file or folder request with a mouse by right clicking a file or folder and selecting the option from context menu. User can initiate delete file or folder request with a keyboard by tabbing down to the file or folder and pressing the keys Alt + Shift + d. User cannot access once deleted file or folder. Deleting a folder also deletes the contents of the folder. User cannot delete the file that is currently been downloaded. User can only delete files or folders that are available in user home directory. User cannot delete files or folders that are not available in user home directory. 8 2.2 Non-Functional Requirements Non-functional requirements are the quality attributes of the system that is used as a basic criterion to judge the operation of the system. Non-functional requirements do not define what a software application should do, but it defines how it should do it. It defines the constraints or non-behavioral requirements of a software application. Following are the nonfunctional requirements for the SacFiles portlet application. 2.2.1 Usable The ease of use and the steepness of the learning curve of the application define the usability of the application. The SacFiles portlet application should have maximum usability and students, staff and faculty members of CSUS should be able to use it easily. The portlet application interface should be intuitive so that the user can simply login to My Sac State and start using the application with minimum or no training. 2.2.2 Secure Security in a software application is protection of personal data from loss, theft or corruption. The SacFiles portlet should be secure and should not allow access to user files without primary authentication. The user should not be able to view, edit, download or upload files to other user accounts. The SacFiles portlet application should be able to upload and download files without any loss or corruption of file contents. 9 2.2.3 Unambiguous A software application is unambiguous when the user is easily able to understand and interpret the menu items, the request messages, server responses and warnings. This is important because some requests might require the user to perform additional actions or user may need to be warned about the severity of the request they just made. The user should be able to understand the success, failure and warning messages showed by the SacFiles portlet clearly and unambiguously. The user should understand what additional action or input is required to complete the current request. 2.2.4 Interactive and Responsive An interactive software application, after obtaining request or data from the user, responds quickly with response data or the status of the request. Interaction and responsiveness is very important in a web-based application because factors like network lag, internet connection speed, server load and many others can delay the response. After making the request, the users should be updated quickly on the status of their request and on the response as soon as the request is processed. 2.2.5 Maintainable A maintainable software application is easy to maintain by anyone even if the person is not involved in development process. As the IRT department as CSUS will be maintaining the SacFiles portlet, it is necessary that the application is implemented in an unambiguous manner. The application codebase should be well documented and precise so that the developers from IRT 10 can debug and maintain the application without any additional training. Java Docs for the complete application are to be submitted along with the source code. 2.2.6 Extensible Extensibility of a software application is the measure of ability to extend the current application for future growth. As the IRT department will be maintaining the SacFiles portlet in the future, it is necessary that the application is easily extensible. The SacFiles portlet should be implemented by following standard software architecture principles so that new features can be added without significantly changing the current application. 2.3 Operating Requirements The operating requirements define the minimum software or hardware requirements the user should have in order to use the SacFiles portlet application. Following are the operating requirements for the SacFiles portlet application: The user should be a student, staff or faculty member of CSUS having a Sac State id and password to login into My Sac State. The user should have a storage space on SacFiles network drive. The user should have access to a computer or a laptop with internet connection and hard memory to download files. The user’s computer should also have required software in order to use the downloaded files. The user should have access to input/output device like mouse, keyboard and monitor. The user is required to have one of the following browser: 11 o Internet Explorer[4] 7 and above o Firefox[5] 3 and above o Chrome[6] o Safari[7] 12 Chapter 3 ARCHITECTURE DESIGN 3.1 Three Tier Architecture The three-tier model is a software architecture and a software design pattern developed by John J. Donovan[8] in Open Environment Corporation(OEC)[9],which is a tools company he founded in Cambridge, Massachusetts[10]. Three-tier architecture is a client-server architecture where the application is separated into three main parts, and each part is deployed or distributed to a different location on a network. The three-tier architecture for SacFiles portlet application has the following three tiers: Presentation Tier o This is the top most level of the application and contains the implementation of Graphical User Interface (GUI)[11] for the SacFiles portlet. o The application has a web-based interface and is implemented using the client side web technologies like HTML[12], CSS[13] and JavaScript[14]. o The presentation tier is discussed in detail in Section 3.2 Portlet Application Tier o The portlet application tier contains the complete business logic for that application. o The application tier is responsible for processing all the requests from presentation tier and sending the processed response back. o The application tier is implemented using server side technologies like Java Server Pages (JSP)[15] and Java Servlets[16]. o The application tier is discussed in detail in Section 3.3. 13 SacFiles File Server (Data Tier) o The third tier known as the Data Tier consists of SacFiles file server implemented by IRT department of CSUS. o The file server is responsible for storing the user’s data. o The business tier pulls information from or adds information to the Sac Files server depending on the request made by the client. o The data tier is discussed in detail in Section 3.4 The following figure displays the graphical representation for the three tiers implemented in SacFiles portlet application: Figure 2: Three Tier implementation of SacFiles Portlet Application. 14 3.2 Presentation Tier The presentation tier is the top most tier of the SacFiles application. This tier is responsible for the presentation and implements the user interface of the application. Apart from presentation, the tier is also responsible for interacting with the, accepting and validating inputs and forwarding the request to the server. The user interface for SacFiles portlet application is implemented using web based client technologies. The following technologies are used in implementing presentation tier for SacFiles portlet application: HTML o HTML stands for Hyper Text Markup Language, which is not a programming language but a markup language. o HTML uses markup tags to describe the web pages rendered on the client browser. o The web browser reads HTML documents, interprets the pages and converts them into web pages. o SacFiles portlet application uses HTML to implement the structure of the user interface. Java Script o JavaScript is a dynamic, weakly typed client-side scripting language, which is implemented as a part of web browser. o JavaScript enables access to different web page objects, thus providing a mechanism to create dynamic and interactive user interface. 15 o JavaScript is used to provide various client side validation and UI animation in SacFiles portlet application. Cascading Style Sheet (CSS) o A style sheet language is a language used to describe the presentation of structured documents. o Cascading Style Sheet (CSS) is a type of style sheet language that describes the look and formatting of a HTML document. o CSS is used to enhance the user interface aesthetics for the SacFiles portlet. jQuery o jQuery[17] is a JavaScript library that is designed to make client side scripting of HTML easy and simple. o jQuery syntax makes it straightforward to parse HTML document, select elements, create animations and handle events. o jQuery also provides cross browser JavaScript support, thus decreasing the amount of work required by the developer. o Use of jQuery also enables developers to use open source jQuery plug-ins that provide an advanced UI effects and animations. AJAX o AJAX[18] stands for Asynchronous JavaScript and XML[19] is a web development technique to make asynchronous requests to the server. 16 o Making server requests and retrieving data from the server response is done in background, so instead of a whole page just a part of a page is reloaded making the application more responsive. o Use of AJAX calls also decreases traffic to and from the server, thus improving the server performance. o AJAX is used in SacFiles portlet to make file handling requests to the server and displaying the server response, which comes in the form of success, error or warning message. o Use of AJAX makes the SacFiles portlet more responsive as each request and response is processed in the background avoiding a page refresh for each request. 3.3 Portlet Application Tier The Portlet Application Tier contains the business logic for the application. The application tier is responsible for accepting the requests from the presentation tier, processing it by reading request parameters, and sending the response back to the presentation tier. The application tier also reads writes or edits files on the SacFiles file server in order to process the user request. The portlet application is deployed on a web application server and is implemented using the following technologies, Java[20] o Java is a programming language developed and released by James Gosling [21] in 1995. 17 o Java is a class based; object oriented programming language used in SacFiles portlet application to implement the business logic. JSR 168 Java Portlet Specification o The Java Portlet Specification was developed under Java Community Process (JCP) [22] as a Java Specification Request JSR 168[23]. o The specification was started in order to provide a mechanism for interoperability between various enterprise portals and portlets. o The specification defines the API between portlet container and portlets. o The specification provides a mechanism to allow the use in Java Servlets and Java Server Pages (JSP) in the portlets o The specification also provides API for processing user requests, reading and enabling portlet modes, portlet window states, and storing and retrieving transient and persistent data for portlets. o The SacFiles portlet follows the JSR 168 specification and uses the API to implement the business logic of the application. Java Servlets o A Java Servlet is a class in Java EE[24] that is used to implement server based application via request-response model. o The servlet class runs on a server application to receive requests from client and generate the corresponding response. 18 o Servlets implement many different functionalities for example they are used for processing or storing data submitted by clients through HTML forms, for providing dynamic content to the clients by reading from Database or File servers and for maintaining sessions for client requests. o SacFiles Portlet Application users Servlets process user requests and respond the request by providing dynamic content read from the SacFiles Files server. Java Server Pages (JSP) o JSP is a technology that enables developers to create dynamic web pages based on HTML and XML on the server and deliver them to client as response. o JSP allows Java code interleaved with static HTML markup which after compiling and executing on the server creates a HTML document. o JSP provides all the same functionality as Java Servlets but JSP provide an additional mechanism to create and maintain dynamic HTML easily without hard coding the markup structure. o SacFiles portlet application uses this technology to create dynamic HTML on the server and delivers it to the presentation tier on user request. JCIFS (Java CIFS Client Library) o JCIFS [25] is an open source client library that implements CIFS/SMB [26] networking protocol in Java. o CIFS is a standard file sharing protocol on Microsoft Windows Platform. 19 o JCIFS provides API for all basic file sharing functionalities like creating new files/folder, reading and writing to files/folder, rename or delete files/folders along with many other advanced API calls. o SacFiles portlet uses JCIFS library API to communicate with the SacFiles server and execute client requests on the server. 3.4 SacFiles File Server The SacFiles File Server is a very large campus-wide file storage system that allows students, faculty and staff members of CSUS to store personal files accessed from any computer on campus. The file server runs on a two-headed cluster of NetApp 3070 filers. The home directory that the SacFiles portlet accesses is implemented using Common Internet File System (CIFS) File Access Protocol 1.0 by NetApp. The CIFS server uses standard Windows authentication protocols to authenticate user against CSUS Active Directory. The SacFiles portlet application accesses SacFiles file server to process user requests such as reading folder contents, reading files, uploading new files, editing or deleting files. 20 3.5 Application Logic Architecture The application logic is implemented on the Portlet Application Tier using the Modelview-controller (MVC) software architecture. MVC architecture separates the application into three different layers. Following is detailed explanation of MVC design for SacFiles portlet application. 3.5.1 Model The model layer is the service layer and the actual business logic of the application is encapsulated in this later. In SacFiles portlet application the Model layer, consist of Java classes implementing the business logic using jCIFS client library API. This layer accepts inputs like file server location, file names, authentication details etc and processes the request by communicating with the SacFiles file server. The layer can process requests independent of the source making those requests. 3.5.2 View The view layer consists of user interface implementation of the application. In case of SacFiles portlet, this layer consists of JSP files containing the logic to create dynamic web pages delivered on user request. The content on the web page comes from the request processed by the business logic class implemented on Model layer. The view is not dependent on the business logic even if the logic in model changes. 21 3.5.3 Controller The controller is responsible for receiving user requests from view and passing them to model for further processing. The controller is also responsible for directing the correct view for the request once the model has processed the request. For the SacFiles portlet, the controller is the Servlet class that accepts user requests and forwards these requests to model class for data processing. The main aim of using MVC architecture is to separate the business logic and data from the presentation data of the application. Some of the reasons and advantages of using MVC architecture are as follows, Modularity o Modularity decreases the coupling between the user interface and the business logic. o The lack of coupling between the modules makes it easy for the developers to change a module without effecting or changing remaining code base of the application. o This is very use full when different developer teams are working on different aspect of the application o The design team working on the user interface of the application can make any number of changes to the application without making any changes to the core business logic. o Similarly the business logic can be changed for enhancement without having the design team change their implementation. 22 Reusability o Due to the modular architecture of MVC, same modules can be easily reused with different modules. o For example, right now, the view or presentation of the application consists of a web-based application, if due to user demand of change in technology the view changes to a native mobile application; it is easy to do that without making any changes to the controller or the business logic. Maintainability o On success implementation MVC, architecture also makes maintaining the application simple and easy. o Additional views or enhancements can be added to the user interface without changing the controller or the model. o Similarly additional validation or security features can be added to the model without making any changes to the controller or the views. 23 3.6 SacFiles Portlet Application Components The following figure displays various application components and communication between these components: Figure 3: SacFiles Portlet Application Components 24 Chapter 4 SYSTEM IMPLEMENTATION This chapter describes the project implementation, which includes installing and configuring the required tools, developing Model, View and Controller layers, building, deploying and running the application. 4.1 Tools Required for the Application Development Following are the developer tools required to develop SacFiles portlet application: Java 1.5+ Apache Ant 1.7 Apache Maven 2.2 uPortal 3.2 Developers Quick Start Eclipse 3.5(or later) IDE 4.1.1 Java SE Download and install the latest version of JDK [34] from following link http://www.oracle.com/technetwork/java/javase/downloads/index.html. Set environment variables o Right click My Computer icon and select properties o Select the Advanced tab o Click the Environment Variables button 25 o Use New and Edit button in the System Variables Section o Create JAVA_HOME environment variable and set its value to Java installation directory as follows, JAVA_HOME = C:\Program Files\Java\jdk1.6.0._31 o Edit the Path environment variable by adding the following text at the beginning, o %JAVA_HOME%\bin; o Verify installation success by opening command prompt and typing “java – version”, the output should look like the following, Figure 4: Verify Java Installation 26 4.1.2 Apache Ant 1.7 To install Apache Ant[35], download Ant distribution (zip file) from the following website, http://ant.apache.org/ Unzip the downloaded zip into the location “C:\portal” directory Create an environment variable specifying the Ant location as follows o ANT_HOME = C:\portal\apache-ant-1.7.1 Edit the PATH environment variable by appending the location of Ant batch file as follows, o PATH=”existing_path”%ANT_HOMT%\bin To verify the proper installation of Ant, open new command prompt and type “ant – version” , the output should look as follows, Figure 5: Verify Ant Installation 27 4.1.3 Apache Maven 2.2 To install Maven[31] build tool download Maven distribution (zip file) from the following web site, o http://maven.apache.org/ Unzip the downloaded zip file in C:\portal directory. Create two environment variables to specify the location of Maven installation as follows o MAVEN_HOME = c:\portal\apache-maven-2.2.1 o M2_HOME = C:\portal\apache-maven-2.2.1 Edit the PATH environment variable by appending the location of mvn batch file, as follows, o PATH = “existing_path”%MAVEN_HOME%\bin To verify the proper installation of Maven, open a new command prompt and type “mvn –version”, the output should look as follows: 28 Figure 6: Verify Maven Installation 4.1.4 uPortal 3.2 Developer’s Quick Start uPortal [27] is a open source enterprise portal frame work managed by Jasig [28]. IRT department at CSUS uses the uPortal portal framework to implement My Sac State portal. The current version of portal used is version 3.2. uPortal provides a developers version of the portal that can be quickly downloaded and installed locally for portlet development and testing purposes. The Developers Quick Start version of uPortal can be downloaded from following location http://www.jasig.org/uportal/download/uportal-324 After downloading the quick start, execute the following steps to build and install uPortal 3.2, Unzip the downloaded zip file into the folder C:\portal\ The C:\portal\ should have a sub-folder “uPortal-3.2.4-quick-start” in it. Open a new command prompt and change the current directory location to “uPortal3.2.4-quick-start” 29 Run the command “ant start” to start the portal. The “ant start” command with start an Apache Tomcat [29] application server and HSQLDB [30] database server for the portal. On successful startup the command line should look as follows: Figure 7: Start uPortal 30 To verify the portal, open a web browser and enter following url o http://localhost:8080/uPortal On correct configuration or installation the portal login page should look as follows: Figure 8: uPortal Login Page Developers can login into the portal using the following username password pairs o admin, admin o student, student o faculty, faculty o guest, guest. 31 4.1.5 Eclipse IDE Download and install Eclipse IDE for Java Developers from http://www.eclipse.org/downloads/ The minimum version required for development is Eclipse 3.5 Developers can either user command line Maven commands to build the project or can install Maven plug-in for Eclipse. To install Maven plug-in for Eclipse, o Click on “Eclipse market place..” option in Eclipse IDE Help Menu o On the search bar search for “Maven” o Click the install button to install “Maven Integration for Eclipse” plug-in. o Following figure shows the Eclipse Market place with Maven plug-in. Figure 9: Installing Maven Plug-in for Eclipse 32 4.2. SacFiles Portlet Directory Structure A Portlet application follows the same directory structure as any other web application with the addition of portlet.xml descriptor file. Following figure displays the directory structure for SacFiles portlet application: Figure 10: Project File Structure for SacFiles Portlet Application 33 4.3 Portlet.xml Portlet.xml is the deployment descriptor declared while creating the project as shown in Figure 6. All portlets and portlet related settings are specified in portlet.xml. The portlet deployment descriptor provides information like configuration, support characteristics, and localized titles to the portal server, which in turn uses this information to provide services to the portlet. Portlet.xml also includes information about modes that portlet will support and various portlet window states that the portlet renders. Following snippet shows the portlet.xml for SacFiles portlet. 34 <?xml version="1.0" encoding="UTF-8"?> <portlet-app xmlns="http://java.sun.com/xml/ns/portlet/portletapp_1_0.xsd" version="1.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/portlet/portletapp_1_0.xsd http://java.sun.com/xml/ns/portlet/portletapp_1_0.xsd"> <portlet> <description xml:lang="en">SacFiles Portlet</description> <portlet-name>SacFilesPortlet</portlet-name> <display-name xml:lang="en">SacFiles Portlet</displayname> <portletclass>edu.csus.sacfiles.controller.SacFilesPortlet</portlet-class> <expiration-cache>0</expiration-cache> <init-param> <description>The parameter represents the jsp file to render the disk view in portlet state normal</description> <name>normal_view</name> <value>/WEB-INF/jsp/NormalDiskView.jsp</value> </init-param> <init-param> <description>The parameter represents the jsp file to render the view in portlet state expanded</description> <name>tree_view</name> <value>/WEB-INF/jsp/SacFileTree.jsp</value> </init-param> <init-param> <description>The parameter represents the jsp file to return the status/result of upload request</description> <name>upload_result</name> <value>/WEB-INF/jsp/uploadResult.jsp</value> </init-param> <init-param> <description>The parameter represents the jsp file to render the </description> <name>login_view</name> <value>/WEB-INF/jsp/login.jsp</value> </init-param> <init-param> <description>The param contains address of sac files server</description> <name>server_address</name> <value>sacfiles1.saclink.csus.edu</value> </init-param> <init-param> Figure 11: portlet.xml of SacFiles Portlet Application. 35 Following are the different attributes specified in portlet.xml: <portlet-app>..</portlet-app> Entire portlet.xml document is structured within <portlet-app> tag element. Attributes and configuration information for one or more portlets can be included within this element. <portlet>..</portlet>: Each individual portlet application is defined within each <portlet> element. <description>..</description> The verbal description of the portlet’s functionality is provided in <description> element. <portlet-name>..</portlet-name> The name of the portlet that shows up on portal search results is defined in <portlet-name>. <portlet-class>..<portlet-class> A fully qualified class name of portlet class that extends GenricPortlet class is provided in <portlet-class> element. <init-param>. .</init-param> The <init-param> element contains <name>, <value> element pairs of initialization parameters required to create initial portlet state. For example, initial parameters for SacFiles portlet include file server location, Sac State domain information, and location of JSP files. 36 <supports>..</supports> The mime types supported by the portlet application are declared in <mimetype> element within <supports> elements. Portlets can support different mime-type for different portlet modes, which is specified using <portlet-mode> element, within <supports> element. <custom-window-state>..</custom-window-state> Portlets can have custom window state apart from standard minimized and maximized window state. The custom window state is implemented by defining it in portlet.xml within <custom-window-state> element. <supported-locale>..</supported-locale> Single or multiple locales supported by the portlet are defined using single or multiple <supported-locale> elements respectively. <portlet-info>..</portlet-info> The <portlet-info> element contains the <title> element that declares the title of the portlet application displayed on portlet’s title bar. 37 4.4. Web.xml A portlet application is an extension of a conventional web application. Thus, a portlet application may also contain many web resources that are not portlets. Any resources that are not portlet are declared in application deployment descriptor called web.xml. The following snippet shows web.xml descriptor for SacFiles portlet application. <?xml version="1.0" encoding="UTF-8"?> <web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee webapp_2_4.xsd" version="2.4"> <servlet> <servlet-name>FileServlet</servlet-name> <servletclass>edu.csus.sacfiles.controller.FileServlet</servlet-class> </servlet> <servlet-mapping> <servlet-name>FileServlet</servlet-name> <url-pattern>/download</url-pattern> </servlet-mapping> </web-app> Figure 12: web.xml for SacFiles Portlet Application. Following are the different attributes defined in portlet.xml <web-app>..</web-app> <web-app> is the root element of the deployment descriptor. All the web application specific descriptor elements are defined within <web-app> element. <servelet>..</servlet> The servlet element contains declaration of all the data of a Java servlet. The canonical name of the servlet defined within <servlet-name> element is a required element. The fully qualified servlet class name, which is the servlet class name along with the package 38 information, is required data defined within <servlet-class> element. Apart from these a <servlet> element can also define other optional elements like <init-param> and <displayname> to declare initialization parameters and short name to display on GUI tools respectively <servlet-mapping>..</servlet-mapping> The <servlet-mapping> element defines a mapping between a servlet and a URL pattern that makes request to the servlet. The mapping is declared by defining the servlet name in <servlet-name> element and desired URL pattern in <url-pattern> in element. Both of these elements are required elements in <servlet-mapping>. 4.5. Implementing Model Layer The model layer of the application contains the complete business logic of the application. As seen in the SacFiles portlet directory structure the Model layer is implemented in Java class named SmbFunction.java and is declared in the edu.csus.sacfiles.model package. The SmbFunction class is responsible for implementing all the logic required to process user requests. The class is also responsible for implement the logic for communicating with the SacFiles file server in order to execute user request. Following are some of the important functions that the class implements, public AuthenticationBean authenticateUser(AuthenticationBean auth) o The function reads AuhenticationBean object as input reads the required credentials from the bean and uses them to authenticate user on the file server. o Depending on the response from the file server the method sets, the authentication beat status and message. 39 o Following code snippet shows the main logic behind authenticateUser function try { auth.setAuthentication(login(address, username, password)); auth.setStatusCode(SmbException.NT_STATUS_OK); auth.setStatus(Global.STATUS_SUCCESS); } catch (SmbException e) { switch (e.getNtStatus()) { case SmbException.NT_STATUS_OK: break; case SmbException.NT_STATUS_ACCESS_DENIED: auth.setStatusCode(SmbException.NT_STATUS_ACCESS_DENIED); auth.setStatus(Global.STATUS_ERROR); auth.setStatusMessage(e.getMessage()); break; case SmbException.NT_STATUS_WRONG_PASSWORD: auth.setStatusCode(SmbException.NT_STATUS_WRONG_PASSWORD); auth.setStatus(Global.STATUS_ERROR); auth.setStatusMessage(e.getMessage()); break; case SmbException.NT_STATUS_LOGON_FAILURE: auth.setStatusCode(SmbException.NT_STATUS_LOGON_FAILURE); auth.setStatus(Global.STATUS_ERROR); case … } Figure 13: Code Snippet for Authentication Logic public JSONObject getUserFiles(FileBean folder) o The function is called to get a detailed list of files and folder in a particular user directory. o The function reads the name and location of requested directory along with other details like user authentication from FileBean object, which is a function parameter. 40 o The return type is a JSONObject containing list of folder and files names along with other details like count and file extensions. o The following code snippet shows the main loop of the logic that creates the JSONObject for the response. for (int a = 0; a < fArr.length; a++) { each_file = new JSONObject(); each_file.put("name", fArr[a].getName()); if (fArr[a].isDirectory()) { each_file.put("type", "dir"); folder_list.put(each_file); } else if (fArr[a].isFile()) { each_file.put("type", "file"); each_file.put("ext", Utils.getFileExtension(fArr[a].getName())); file_list.put(each_file); } } list_object.put("files", file_list); list_object.put("folders", folder_list); Figure 14: Code Snippet for Reading User Folder Contents public JSONObject downloadFile(SmbFile file, OutputStream os) o The function reads the user file represented by the SmbFile object from the file server and writes the contents of the file to the OutputStream. o Currently the OutputStream being passed is the stream created to write the response back to the user and thus user is able to download the files from the remote file server to their desktop. 41 o If the file does not exist or there occurs some kind of error reading or writing the file the function sets the status to error status and sets a corresponding message on the JSONObject before returning it to the user. o The following code snippet shows the logic implemented to download user file: try { InputStream is = file.getInputStream(); byte b[] = new byte[1024]; int numRead = 0; while ((numRead=is.read(b)) > 0) { os.write(b, 0, numRead); } os.flush(); return JSONMessageBean.getSuccessMessage("Download successful"); } catch (Exception e) { return JSONMessageBean.getErrorMessage("Error downloading file. Please try again later"); } Figure 15: Code Snippet for Download File Logic public JSONObject uploadFile(FileBean file, InputStream is) o The function reads the contents from InputStream object and writes the contents to a current file or newly created file represented by the FileBean on the file server. o For the current implementation, the InputStream reads from the file user is trying to upload and thus the file is uploaded by writing the file contents on the file server. 42 o Uploading a file presents a challenge to balance the memory buffer size required to upload the file and amount of time required to upload a file so that the portlet application does not time out. o To upload the data quickly larger chunks of data needs to be read from the network, but doing so results into larger buffer size on server causing memory problems and thus performance hits to the server. o To avoid the memory problems the server needs to keep the buffer size smaller but this results into longer upload time causing the portlet application to time-out. o In order to achieve a balance between server memory and upload time the uploadFile function creates buffer sizes depending on the size of the file to upload. o If the file size is too small, the function uses a default buffer or a smaller size buffer balancing the upload time out. o If the file size is larger, a relatively larger buffer is created to read the files. o Following code snippet is the main logic behind the upload file functionality, 43 try { f = new SmbFile(Global.home_dir + file.getFolderPath() + file.getNewFolderName(), file.getAuthentication()); if (!f.exists()) { f.createNewFile(); } OutputStream os = f.getOutputStream(); byte buf[] = null; if (file.getFileSize() < Global.UPLOAD_BUFFER_SMALL) { buf = new byte[(int) Global.UPLOAD_BUFFER_SMALL]; } else if (file.getFileSize() < Global.UPLOAD_BUFFER_MEDIUM) { buf = new byte[(int) Global.UPLOAD_BUFFER_MEDIUM]; } else if (file.getFileSize() < Global.UPLOAD_BUFFER_LARGE) { buf = new byte[(int) Global.UPLOAD_BUFFER_LARGE]; } else { buf = new byte[(int) Global.UPLOAD_BUFFER_XLARGE]; } int length; while ((length = is.read(buf)) > 0) { os.write(buf, 0, length); } is.close(); os.close(); return JSONMessageBean.getSuccessMessage(file.getNewFolderName() + " ( " + Utils.getReadableSize(file.getFileSize()) + " ) Uploaded Successfully"); } catch (MalformedURLException e) { e.printStackTrace(); return JSONMessageBean.getErrorMessage("Error uploading file : " + e.getMessage()); } Figure 16: Code Snippet for Upload File Logic Apart from above mentioned functions the SmbFunction.java also implements various functions to create folder, rename files and folder, and delete file and folder. These functions make a simple JCIFS API call to execute the corresponding command. The Model layer to completely independent from Controller or the View and hence makes it easy to reuse the 44 business logic to implement functionality that is more advanced. For example, an output stream for a download file can be a user response or a stream that write to a remote printer and thus we can use the same logic to provide remote printing functionality to the users. 4.6. Implementing View Layer The View layer consists of presentation or UI design and implementation of the application. The view for SacFiles portlet application uses JSP and web based client technologies like HTML, CSS, JavaScript and jQuery. The user interface is presented in two different portlet window states. The portlet states and their UI implementation is as follows, 4.6.1 SacFiles portlet in Normal Window State The SacFiles portlet remains in its normal state when rendered along with other portlets of channels on the portal. In this state, the channel displays a clickable network drive icon that navigates users to the maximized state of the application. The normal state of portlet renders from on NormalDiskView.jsp and following code snippet shows the UI implementation detail of SacFiles portlet in Normal State: <%@ include file="import.jsp" %> <% PortletURL url = renderResponse.createRenderURL(); url.setWindowState(WindowState.MAXIMIZED); url.setSecure(true); %> <div class = "normal_view"> <a href="<%= url %>" class="harddisk"> <img src="/SacFiles/images/drive.png" class="harddisk"> <span class="harddisk">SacFiles Network Drive (U:)</span> </a> </div> Figure 17: Code Snippet for SacFiles Portlet in Normal Window State 45 Following image is the screen shot of SacFiles portlet in Normal window state: Figure 18: SacFiles Portlet in Normal Window State 46 4.6.2 SacFiles Portlet in Maximized Window State The SacFiles portlet in Maximized window state presents a detailed view of user’s contents from the SacFiles file server. The contents are displayed as a directory tree hierarchy with user’s home directory as the root. The portlet users jQuery File Tree plug-in [32] to create the directory tree. The portlet-maximized state is implemented in SacFileTree.jsp and sacFilesTree.js. The following code snippet shows the file tree logic: $(document).ready(function(){ num_files = 0; altPressed = false; shiftPressed = false; treeVar = $('#fileTree').fileTree({ root: root_dir, folderEvent: 'dblclick', script: ajaxRequestURL }, function(file) { submitForm(file); } ); //bind events $(".file_input").bind("change", fileChanged); $("#upload_more").bind("click", addInputFiles); $("#upload_target").bind("load", fileUploadComplete); $(".root").contextMenu({ menu: 'rootMenu' }, function(action, el, pos) { folderContextMenuClicked(action, el, pos); }); …. Figure 19: Code Snippet for creating jQuery File Tree 47 Following image is the screen shot of SacFiles portlet in Maximized window state displaying user contents in a file tree format: Figure 20: SacFiles Portlet in Maximized Window State 48 The SacFiles portlet uses the jQuery Context Menu plug-in [33] to create the context menu for the application. The following code snippet shows the initialization and creating of context menus: 49 <script> function bindFolderContextMenu() { $(".directory").destroyContextMenu(); $(".directory").contextMenu({ menu: 'folderMenu' }, function(action, el, pos) { folderContextMenuClicked(action, el, pos); }); $(".root").contextMenu({ menu: 'rootMenu' }, function(action, el, pos) { folderContextMenuClicked(action, el, pos); }); } </script> <ul id="folderMenu" class="contextMenu"> <li class="folder_open"> <a href="#folder_open">Open Folder (Alt + Shift + o) </a> </li> <li class="folder_close"> <a href="#folder_close">Close Folder (Alt + Shift + c) </a> </li> <li class="rename"> <a href="#rename">Rename (Alt + Shift + r) </a> </li> <li class="delete_folder"> <a href="#delete_folder">Delete (Alt + Shift + d) </a> </li> Figure 21: Code Snippet for Initialization and Creating jQuery Context Menus 50 Following screenshot displays the user of context menu for folders in Maximized state of SacFiles portlet, Figure 22: Context Menu for SacFiles Portlet in Maximized Window State The maximized portlet state also allows users to make AJAX request in order to perform various functionalities. The AJAX request can be initiated either using context menus or by using key board shortcuts. On receiving the response the AJAX callback function is called which performs the required changes on the user interface. The application uses jQuery AJAX call API to make these requests. The following code snippet shows a part of code that makes the required AJAX request: 51 function makeCreateFolderRequest() { $("#createFolderDialog").find(".progress_bar").show(); $.post(ajaxRequestURL, { command: "create_folder", folder_location: $(currentElement).children().attr("rel"), folder_name : $("#create_folder_name").val() }, function(data) { $("#createFolderDialog").find(".progress_bar").hide(); $("#createFolderDialog").find(".error").remove(); $("#createFolderDialog").find(".success").remove(); $("#createFolderDialog").find(".warning").remove(); if(data.status == "success"){ //show success message $("#createFolderDialog").append("<div class='success'>" + data.message + "</div>" ); treeVar.updateFolder(currentElement); } else if(data.status == "warning"){ $("#createFolderDialog").append("<div class='warning'>" + data.message + "</div>" ); } else if(data.status == "failed"){ $("#createFolderDialog").append("<div class='error'>" + data.message + "</div>" ); } else{ $("#createFolderDialog").append("<div class='error'>Unknown error occured. Please try again later.</div>" ); }});} Figure 23: Code Snippet for making AJAX Calls 52 4.6. Implementing Controller The Controller handles the user requests by forwarding it to the model for data processing and responding to the request with the correct view. The controller is implemented in SacFiles Portlet using two different servlet files, SacFilesPortlet.java and FileServlet.java declared in edu.csus.sacfiles.controller package. Following section, discusses implementation details for both controller classes, 4.6.1 SacFilesPortlet.java SacFilesPortlet.java is the primary servlet that is responsible handling all the user requests made by the client. The servlet handles two main types of requests, RenderRequest which is made when the portlet application is rendered, or when the user changes the portlet window state or even when the page is refreshed, and another is ActionRequest which is made when the user clicks on an action url or submits a form for data processing. The servlet extends GenericPortlet class and implements three methods that are called based on type of request the user makes. Following are implementation details of SacFilesPortlet.java class methods public void init(PortletConfig config) o The init method executes one time when the servlet is initialized the very first time. o The method reads and sets all the initialization parameters necessary to create a state of the portlet application. 53 o The init method implementation of SacFilesPortlet.java reads init parameter values for location of JSP files, server address, user domain, logging preferences and the file server home directory and sets them to a global variable accessible at application level. o The following code snippet displays the implementation for init method: public void init(PortletConfig config) { Global.log_file = config.getInitParameter("log_file"); Global.initLogger(); normal_view = config.getInitParameter("normal_view"); detail_view = config.getInitParameter("tree_view"); upload_result = config.getInitParameter("upload_result"); login_view = config.getInitParameter("login_view"); Global.server_address = config.getInitParameter("server_address"); Global.uname_domain = config.getInitParameter("uname_domain"); Global.home_dir = config.getInitParameter("home_dir"); try { super.init(config); } catch (PortletException e) { // TODO Auto-generated catch block Global.error(e); } } Figure 24: Code Snippet for SacFilesPortlet init() Method 54 public void doView(RenderRequest request, RenderResponse response) o This method is called when the portlet is rendered on the portal or when the user clicks on a render request like changing the portlet window state or portlet mode o This method is responsible for providing the correct view for the portlet depending on the correct window state and parameters set in the request object. o The SacFilesPortlet.java checks for the current window state and returns the NormalDiskView.jsp if the requested window state is normal else if the user is authenticated and requested window state is maximized, it returns the SacFileTree.jsp in response. o The portlet also supports an “exclusive” window state which simple returns the request status and corresponding message when the user tries to upload a file on the server. o The following code snippet shows a part of implementation of the doView method in SacFilesPortlet.java : 55 public void doView(RenderRequest request, RenderResponse response) throws PortletException, IOException { PortletSession session = request.getPortletSession(); String username = request.getParameter("uname"); String password = request.getParameter("pw"); String view = normal_view; PortletContext context = getPortletContext(); WindowState requestedWindowState = request.getWindowState(); if (requestedWindowState.equals(EXCLUSIVE)) { view = upload_result; } else if (requestedWindowState == WindowState.NORMAL) { view = normal_view; } else if (requestedWindowState == WindowState.MAXIMIZED) { if (isUserAuthenticated(session)) { view = detail_view; } else { if (username == null || Utils.isStringEmpty(username) || password == null || Utils.isStringEmpty(password)) { request.setAttribute("command", "show_login"); view = login_view; } else { } } } PortletRequestDispatcher prd = context.getRequestDispatcher(view); response.setContentType("text/html"); prd.include(request, response); } Figure 25: Code Snippet for SacFilesPortlet doView() Method 56 public void processAction(ActionRequest request, ActionResponse response) o This method is invoked whenever the user requests some kind of data processing either by submitting a form or by clicking an ActionURL / o The method is responsible for processing any user requests by reading the request parameters from ActionRequest object. o The portal calls the render request for the portlet after executing processAction method, and thus processAction is responsible for setting correct window states and portlet mode before passing the control to the render request. o The SacFilesPortlet.java performs two main functions in processAction method depending on values of request parameter named “command”. o If the user is requesting to upload a file, the “command” value would be “upload_file” and corresponding model method is invoked to upload the file. After finishing the upload file request, the portlet mode is set to “exclusive” and thus the user sees the upload request status and message. o If the user is not requesting to upload a file an AJAX request is assumed and the request is redirected to FileServlet.java servlet. o Following code snippets show the implementation of processAction method in SacFilesPortlet.java : 57 public void processAction(ActionRequest request, ActionResponse response)throws PortletException, IOException { PortletSession session = request.getPortletSession(); if (request.getParameter("dir") != null) { session.setAttribute("requested_dir", request.getAttribute("dir"), PortletSession.APPLICATION_SCOPE); } if (request.getParameter("command") != null) { if (request.getParameter("command").equalsIgnoreCase("login")) { authenticateUser(request, response); } else if (request.getParameter("command").equalsIgnoreCase( "upload_file")) { uploadUserFile(request, response); } else{ forwardAjaxRequest(request, response); } } } Figure 26: Code Snippet for SacFilesPortlet processAction() Method Other than, the overridden methods mentioned above the SacFilesPortlet.java also implements helper methods like forwardAjaxRequest(request, respose) which simply redirects AJAX requests made by the user to FileServelt.java servlet, and uploadUserFile(request,response) which makes the upload file request to the model class when the user requests to upload a file on the server. 4.6.2 FileServlet.java FileServlet.java is a Java Servlet that is responsible for processing all the AJAX requests made by the users. This servlet is required as a work around because an uPortal 3.2 framework that is the version deployed at My Sac State and JSR 168 portlet specification does 58 not support conventional AJAX calls. All the requests that the servlet receives are redirected by SacFilesPortlet servlet. The servlet overrides doGet method from HttpServet, which is called when the user makes a GET request. All the methods redirected by SacFilesPortlet are GET requests and hence processed by the doGet method. The doGet method simply reads the “command” request parameter and invokes the corresponding method to process the request. Following code snippet displays the logic implementation of doGet method for FileServlet.java class: 59 public void doGet(HttpServletRequest request, HttpServletResponse response) { Global.info("FileServlet doGet"); String command = request.getParameter("command"); if(command != null){ if(command.equalsIgnoreCase("open_dir")){ openUserDirectory(request, response); } else if(command.equalsIgnoreCase("download_file")){ downloadUserFile(request, response); } else if(command.equalsIgnoreCase("create_folder")) { createUserFolder(request, response); } else if(command.equalsIgnoreCase("rename_folder")) { renameUserContent(request, response, true); } else if(command.equalsIgnoreCase("rename_file")) { renameUserContent(request, response, false); } else if(command.equalsIgnoreCase("delete_folder")) { deleteUserContent(request, response, true); } else if(command.equalsIgnoreCase("delete_file")) { deleteUserContent(request, response, false); } } else{ Global.info("FileServlet : command is null" ); }} Figure 27: Code Snippet FileServlet doGet() Method 60 Apart from doGet method the servlet classes also implements various helper methods that reads the user information required to process a request from request parameters and invokes the model class function to execute and process the request. Following is a code snippet of helper method downloadUserFile , the method reads the request parameters, sets and response attributes and then invokes the model class method downloadFile to start the download process: public void downloadUserFile(HttpServletRequest request, HttpServletResponse response) { HttpSession session = request.getSession(); NtlmPasswordAuthentication authenticated = (NtlmPasswordAuthentication) session.getAttribute("authenticated_http"); String file_name = request.getParameter("requested_file"); SmbFunction smbFunc = new SmbFunction(); try{ SmbFile downloadFile = new SmbFile(Global.home_dir + file_name, authenticated); response.setContentType(downloadFile.getContentType()); response.setStatus(200); response.setHeader("Content-Length", String.valueOf(downloadFile.length())); response.setHeader("Content-Disposition", "attachment; filename=" + downloadFile.getName()); OutputStream os = response.getOutputStream(); smbFunc.downloadFile(downloadFile, os); //file_name, authenticated } catch(Exception downloadException){ Global.info("DownloadServlet Exception downloading file : " + downloadException.getMessage()); } } Figure 28: Code Snippet FileServlet downloadUserFile() Method 61 4.7. Building and Deploying the Portlet Following sub sections describe in details steps to build and deploy the SacFiles portlet application: 4.7.1 Building Portlet App using Eclipse IDE In order to create a clean build for the portlet open Eclipse IDE and follow the steps, Right click on the project root folder, hover over the “Run As” menu option and click on “Maven Clean” menu item as shown in figure below Figure 29: Building Portlet App from Eclipse IDE – Maven Clean 62 After Maven clean is done successfully right click the project root folder, hover over the “Run As” menu option and select “Maven Install” menu item, as shown in figure below, Figure 30: Building Portlet App from Eclipse IDE – Maven Install 63 On an error free build the Eclipse console will show success message along with other information like build target location and console messages looks like the screenshot below, Figure 31: Building Portlet App from Eclipse IDE – Build Success 4.7.2 Building Portlet App using command line tool Portlet application can also be build using simple command line instructions for Maven [33]. To build the portlet app using command line, Open a new command prompt Change the current directory to the portlet application directory To create a clean build execute the command “mvn clean install”. On successful build the command line will show the following information, 64 Figure 32: Building Portlet App using Command Line 4.7.3 Deploying Portlet Application Portlet application can only be deployed using command line instructions as follows, Change the current directory to uPortal directory which according to the previous instructions should be “C:\portal\uPortal-3.2.4-quick-start\uPortal-3.2.4” Use the following command to deploy the portlet application into the portal o ant deployPortletApp -DportletApp=$PATH_TO_TARGET/SacFilesPortlet.war 65 The parameter $PATH_TO_TARGET should be replaced by the absolute path to the target war file what was created during build step. On success the command prompt would show following details Figure 33: Deploying Portlet App 66 4.7.4 Publishing a Portlet Application The portlet needs to be published in uPortal the very first time in order to use or test it. To publish the portlet Start uPortal by executing command “ant start” in uPortal quick start guide directory that is “C:\portal\uPortal-3.2.4-quick-start”. Once the portal is up, logon as administrator using the “admin”, “admin” username password pair. Click on “Manage Portlets” link on “Portal Administration” channel as shown in figure below. Figure 34: Publishing Portlet App Step 1 67 In “Manage Portlets” select “Register New Portlet” button Figure 35: Publishing Portlet App Step 2 68 Select Portlet type to JSR 168 Portlet Figure 36: Publishing Portlet App Step 3 69 Click next and select the portlet title from the drop down list. The value of portlet title from the drop down list is derived from <portlet-info> element defined in portlet.xml. Figure 37: Publishing Portlet App Step 4 70 Click next and fill out other details regarding the portlet. The portlet description is made available to the user when searching for the portlet. The portlet time out value decides how long the portlet application waits for server response before throwing an error. So selecting a proper timeout value is very important. If the timeout value is too less the portlet might throw error too frequently and if the timeout value is too high the user might have to wait too long to get the response without knowing that there might be something wrong with the request. Figure 38: Publishing Portlet App Step 5 71 On clicking next, the wizard shows the deployment descriptor values defined in portlet.xml and web.xml. Developers can also add portlet preferences at this stage. Portlet preferences are more useful when the portlet provides functionality or feature that users can edit in edit mode. Figure 39: Publishing Portlet App Step 6 72 Next step is to choose the category of the portlet based on its functionality. Choosing the correct category efficiently organizes the portlets and also eases the users search for their required portlet Search the category using the search text field and select one or more results based on the portlet type. Figure 40: Publishing Portlet App Step 7 73 The next step is to choose user groups who have access to the portlet. This is a very important step, as not every one can have access to all the portlets. If the portlet is performing an admin level, functionality students and other staff members cannot have access to it. The user groups who do not have access to the portlet can neither subscribe to the portlet nor search it. Access to the groups is given by searching for group names in the search bar and selecting one or more groups as required. Figure 41: Publishing Portlet App Step 8 74 The final step is set the current stage in portlet life cycle. It is important to note that users cannot subscribe or search the portlet if it is not in published stage yet. If the portlet provides a functionality that is valid, only temporary developers can also the portlet expiration date in advance. Figure 42: Publishing Portlet App Step 9 75 On clicking next, the portal displays a summary of all the configuration data collected in above stage, developers can edit the data if required. 4.7.5 On clicking finish, the portlet is published successfully on the portal. . Subscribing to the Portlet Application After publishing the portlet, users need to subscribe to the portlet in order to view it or access it. Users can add portlet application to any tab by following steps Select the tab to add portlet to and click on customize link. Click on add content link from the customize options, as shown below, Figure 43: Subscribing Portlet App Step 1 76 The link opens a dialog with a search tab. Search for desired portlet name and add the portlet by selecting the link and clicking on “Add to My Layout” button. The portlet should be visible available on the tab after closing the dialog Figure 44: Subscribing Portlet App Step 2 77 Chapter 5 SACFILES PORTLET APPLICATION USER GUIDE The SacFiles portlet application enables users to access their files and folders located on remote SacFiles file server and perform different file management tasks on them. The portlet application provides interface to perform the following functions on user files, Create new folders and sub folders on server Upload files to the server Download files from the server Rename files on the server Rename folders on the server Deleting files on the server Deleting folders and their contents on the server Users can interact with the portlet in different ways in order to perform above functions. This chapter provides systematic set of instructions and screen shots of every step required to perform the above functions. Following sections describe each of the above functions in detail: 78 5.1 Creating new folder and sub folder on the server Users can start creating new folders on the portlet by only using mouse, only using key board or by using both together. To create a folder using mouse select the folder in which the new folder is to be created and right click to see the context menu. From the context menu select the “Create New Sub-folder” option, as shown in the figure below, Figure 45: Creating New Folder Step 1 79 To create the folder-using keyboard, o Select the root folder by pressing “Alt + Shift + h” and press “Alt + Shift + n” to create a folder in root directory. o Tab to the desired folder from the root directory and press “Alt + Shift + n” to create a folder in another folder. Enter the new folder name in the create folder dialog box as shown below. Make sure that the folder name does not contain any restricted special characters. Figure 46: Creating New Folder Step 2 80 Click “Create Folder” button after entering the new folder name. On successful creation of folder a success message will be displayed on the dialog itself Figure 47: Creating New Folder Step 3 Close the dialog to access the folder or enter a new folder name to create another sub folder in the same directory. 81 5.2 Upload files to the server Users can upload files to any folder in their home directory using keyboard or mouse or both by following the next instructions, To start uploading a file using mouse select the folder to upload the files to and right click to open the context menu. Select upload new file from the context menu to open an upload dialog. Figure 48: Uploading New Files Step 1 82 To upload the file using keyboard, o Press “Alt + Shift + h”, select the root folder and press “Alt + Shift + u” to upload the files there. o Tab to the desired folder from the root folder and press “Alt + Shift + u” to upload the files there. On the upload file dialog, press the file selector to find the local file to upload. Figure 49: Uploading New Files Step 2 83 After selecting the file, click upload to start the upload process. If the file is uploaded successfully, a success message is displayed on the dialog itself. Figure 50: Uploading New Files Step 3 Close the dialog to perform other functions to select a new file to upload in the same folder. 84 5.3 Download files from the server To initiate a file download from the server double click the desired file or right click the file and select the download file option. Figure 51: Downloading Files Step 1 To download a file using keyboard, o Select the root directory by pressing “Alt + Shift + h”. o Navigate to the desired file by pressing tabs. o If the files is in a sub folder, navigate to the folder by pressing tabs, open the folder by pressing “Enter” key or pressing keys “Alt + Shift + o” and continue navigating to the desired file. 85 o To initiate download press “Enter” key or press keys “Alt + Shift + g”. Depending on the browser type, either the file download would start automatically or a browser dialog box will appear requesting permission to save or open the file. Figure 52: Downloading Files Step 2 86 5.4 Rename files on the server To rename a file on the server using mouse right click the file to open the context menu and select rename option. Figure 53: Rename Files on Server Step 1 To rename a file using keyboard, o Press “Alt + Shift + h” to select the root directory and navigate to the desired file by pressing tabs. o If the desired file is in a sub folder, navigate to the folder by pressing tabs, open the folder by pressing “Enter” key or by pressing “Alt + Shift + o”, and continue navigating to desired file. 87 o On reaching the desired file press the keys “Alt + Shift + r”. Enter a new file name in rename file dialog and click “Rename”. Make sure the new file name does not contain restricted special characters. Figure 54: Rename Files on Server Step 2 88 A success message is displayed on the dialog after renaming the file. Figure 55: Rename Files on Server Step 3 89 5.5 Rename folders on the server To rename a folder using a mouse, right click the folder using context menu and select the rename option. Figure 56: Rename Folders on Server Step 1 90 To rename a folder using keyboard, o Select the root directory by pressing the keys “Alt + Shift + h”. o Navigate to the desired folder by pressing tabs and rename the folder by pressing the keys “Alt + Shift + r”. Enter a new name for the folder and click “Rename”. Make sure the folder name does not contain any restricted special characters. Figure 57: Rename Folders on Server Step 2 91 A success message is display on the dialog after renaming the folder. Figure 58: Rename Folders on Server Step 3 92 5.6 Deleting files from the server To delete the file from the server using mouse, right click the file to delete to open a context menu and select “Delete File” option. Figure 59: Deleting Files from Server Step 1 93 To delete the file using keyboard, o Select the root directory by pressing “Alt + Shift + h” o Navigate to the desired file by pressing tabs. o If the desired file is in a sub folder, navigate to the folder by pressing tab, open the folder by pressing “Enter” key or by pressing “Alt + Shift + o” key and continue navigating to the desired file. o To delete the file press the keys “Alt + Shift + d”. Click “Delete Now” button on the delete file confirmation. Figure 60: Deleting Files from Server Step 2 94 A confirmation message is displayed on the dialog on successful delete. Figure 61: Deleting Files from Server Step 3 95 5.7 Deleting folders from the server To delete a folder using mouse right click the desired folder to open a context menu and select “Delete” option from the menu. Figure 62: Deleting Folders from Server Step 1 96 To delete a folder using keyboard, o Select the root directory by pressing “Alt + Shift + h” o Navigate to the desired folder by pressing tabs. o If the desired folder is a sub folder, navigate to the parent folder by pressing tabs, open the folder by pressing “Enter” key or by pressing “Alt + Shift + o” and continue navigating to the desired folder. o To delete the folder press the keys “Alt + Shift + d” Press the delete now button on the confirmation dialog. Figure 63: Deleting Folders from Server Step 2 97 A confirmation message is displayed on the dialog on successfully deleting the folder and its contents. Figure 64: Deleting Folders from Server Step 3 98 Chapter 6 SUMMARY AND FUTURE WORK The SacFiles Portlet Application has been implemented success fully and by successfully meeting all the basic requirements. I am going to submit the application to Information Resources and Technology (IRT) and the portlet will go into production after further testing and code review the department. I have learned a lot while working on the project and faced many tough challenges like learning, understanding and using the CIFS protocol on Java, using AJAX technology with uPortal 3.2 and JSR 168 portlet specification and finally creating a user interface that was lightweight, easy to use and responsive. While working on the project I felt that education and training that I got at CSUS helped me a lot while researching solutions for these challenges. I feel privileged to work on this project and to create an application, which thousands of CSUS students, faculty and staff members will user for their daily educational and professional purposes. Currently the SacFiles Portlet provides interface to perform basic file manipulation functions. However, I believe that this application will serve as a foundation for a much more advanced app that will make the daily life of its users especially students a lot easier. One of the advanced features that the application can have is the ability to create and edit documents online through the browser. With browser based document creation users can simply log-on to My Sac State create new document edit the document to create their homework assignment, or may be take meeting notes in it and simply save and close the document. The users do not have to worry about installing expensive paid software to work on the files any more. Currently CSUS is spending thousands of dollars to license such expensive software for staff and faculty members. Some more research and work on the portlet may end up saving lots of money for the university. 99 Files and folders sharing is another advanced feature that can be implemented on the portlet in future. Students and even different departments at CSUS work on many projects together. Emails, flash drives expensive file sharing apps are used to share files and other documents related to the project. Users can avoid using these inconsistent or expensive ways to share files if the SacFiles portlet application can provide such a mechanism. Theoretically, we already have most of the required framework implemented for such a feature. We already have a campus wide file server that provides limited access based on user id and authentication and now we have a web interface to interact with that file server. Only thing required is an addition in the business logic to allow users to change access permissions on their files and folders. Apart from these I strongly believe there are many other advanced features that can be implemented on the portlet application to enhance the user experience and make their lives easier. 100 Bibliography [1] IRT, In Sacramento State- Information Resources & Technology, Retrieved on September 2, 2010. From online http://www.csus.edu/irt/ [2] CSUS, In California State University, Sacramento, Retrieved on August 26, 2010. From online http://www.csus.edu/ [3] My Sac State, In California State University, Sacramento, My Sac State, Retrieved on August 26, 2010. From online http://my.csus.edu/ [4] Internet Explorer, In Internet Explorer – Web Browser for Microsoft Windows, Retrieved on September 05, 2010. From online http://windows.microsoft.com/en-us/internet- explorer/products/ie/home [5] Firefox, In Mozilla – Home of Mozilla Project, Retrieved on September 05, 2010. From online http://www.mozilla.org/en-US/ [6] Chrome, In Google Chrome – Browser for PC, Mac and Linux, Retrieved on September 05, 2010. From online https://www.google.com/chrome [7] Safari, In Apple Safari – Browser for Mac and PC, Retrieved on September 05, 2010. From online https://www.google.com/chrome [8] John J. Donovan, In Wikipedia – John J. Donovan, Retrieved on September 30, 2010. From online http://en.wikipedia.org/wiki/John_J._Donovan [9] OEC, In Wikipedia – Open Environment Corporation, Retrieved on September 30, 2010. From online http://en.wikipedia.org/wiki/Open_Environment_Corporation [10] Cambridge, Massachusetts, In Wikipedia – Cambridge, Massachusetts, Retrieved on September 30, 2010. From online http://en.wikipedia.org/wiki/Cambridge,_Massachusetts [11] GUI, In Wikipedia – Graphical User Interface, Retrieved on October 10, 2010. From online http://en.wikipedia.org/wiki/Graphical_user_interface [12] HTML, In HTML Introduction, Retrieved on October 18, 2010. From online http://www.w3schools.com/html/html_intro.asp [13] Java Script, In Wikipedia - JavaScript, Retrieved on October 18, 2010. From online http://en.wikipedia.org/wiki/JavaScript [14] CSS, In Wikipedia – Cascading Style Sheet, Retrieved on October 18, 2010. From online http://en.wikipedia.org/wiki/Cascading_Style_Sheets 101 [15] JSP, In Oracle – JavaServer Pages Technology, Retrieved on October 25, 2010. From online http://www.oracle.com/technetwork/java/javaee/jsp/index.html [16] Java Servlets, In Oracle – Java Servlet Technology, Retrieved on October 25, 2010. From online http://www.oracle.com/technetwork/java/index-jsp-135475.html [17] jQuery , In Wikipedia - jQuery, Retrieved on October 31, 2010. From online http://en.wikipedia.org/wiki/JQuery [18] AJAX, In Wikipedia –Ajax (programming), Retrieved on October 31, 2010. From online http://en.wikipedia.org/wiki/Ajax_(programming) [19] XML, In Wikipedia –XML, Retrieved on October 31, 2010. From online http://en.wikipedia.org/wiki/XML [20] JAVA, In Wikipedia –Java (Programming Language), Retrieved on November 25, 2010. From online http://en.wikipedia.org/wiki/Java_(programming_language) [21] James Gosling, In Wikipedia –James Gosling, Retrieved on November 25, 2010. From online http://en.wikipedia.org/wiki/James_Gosling [22] Java Community Process, In Java Community Process – Community Development of Java Technology Specification, Retrieved on November 25, 2010. From online http://jcp.org/en/home/index [23] JSR 168, In JSR 168: Portlet Specification, Retrieved on November 29, 2010. From online http://www.jcp.org/ja/jsr/detail?id=168 [24] Java EE, In Java EE at a Glance, Retrieved on November 30, 2010. From online http://www.oracle.com/technetwork/java/javaee/overview/index.html [25] JCIFS, In The Java CIFS Client Library, Retrieved on January 01, 2011. From online http://jcifs.samba.org/ [26] CIFS/SMB, In Microsoft SMB Protocol and CIFS Protocol Overview, Retrieved on January 01, 2011. From online http://msdn.microsoft.com/en- us/library/windows/desktop/aa365233(v=vs.85).aspx [27] uPortal, In uPortal, About uPortal , Retrieved on January 25, 2011. From online http://www.jasig.org/uportal [28] Jasig, In Jasig, About Jasig, Retrieved on January 25, 2011. From online http://www.jasig.org/about 102 [29] Apache Tomcat, In The Apache Software Foundation, Retrieved on January 25, 2011. From online http://tomcat.apache.org/ [30] HSQLDB, In HyperSQL HSQLDB – 100% Java Database, Retrieved on January 25, 2011. From online http://hsqldb.org/ [31] Maven, In Apache Maven Project, Retrieved on January 25, 2011. From online http://maven.apache.org/ [32] jQuery File Tree plug-in, In A Beautiful Site – jQuery File Tree, Retrieved on April 25, 2011. From online http://www.abeautifulsite.net/blog/2008/03/jquery-file-tree/ [33] jQuery Context Menu plug-in, In A Beautiful Site – jQuery Context Menu, Retrieved on June 25, 2011. From online http://www.abeautifulsite.net/blog/2008/09/jquery- context-menu-plugin/ [34] Java Development Kit (JDK), In Oracle - JDK Readme, Retrieved on January 20, 2011. From online http://www.oracle.com/technetwork/java/javase/jdk-7-readme-429198.html [35] Apache Ant, In Apache - The Apache Ant Project, Retrieved on January 20, 2011. From online http://ant.apache.org/