You are viewing a plain text version of this content. The canonical link for it is here.
Posted to olio-commits@incubator.apache.org by sh...@apache.org on 2009/10/07 19:33:00 UTC

svn commit: r822866 [1/3] - in /incubator/olio/webapp/java/trunk/ws/apps/webapp/src/java/org/apache/olio/webapp: controller/ fileupload/ model/ rest/ util/

Author: shanti
Date: Wed Oct  7 19:32:59 2009
New Revision: 822866

URL: http://svn.apache.org/viewvc?rev=822866&view=rev
Log:
Fix for OLIO-126. All messages are now logged using the Java logging API. Debug messages are
either FINE or FINER level, error messages are SEVERE.
To see these messages, the appserver config needs to be changed to include 'org.apache.olio'.
For glassfish, go to the Appserver->Logging->Log Levels, and add a property 'org.apache.olio' with
value set to the logging level you want (INFO, FINER etc.)

Modified:
    incubator/olio/webapp/java/trunk/ws/apps/webapp/src/java/org/apache/olio/webapp/controller/ArtifactAction.java
    incubator/olio/webapp/java/trunk/ws/apps/webapp/src/java/org/apache/olio/webapp/controller/ControllerServlet.java
    incubator/olio/webapp/java/trunk/ws/apps/webapp/src/java/org/apache/olio/webapp/controller/EntryFilter.java
    incubator/olio/webapp/java/trunk/ws/apps/webapp/src/java/org/apache/olio/webapp/controller/PersonAction.java
    incubator/olio/webapp/java/trunk/ws/apps/webapp/src/java/org/apache/olio/webapp/controller/RestAction.java
    incubator/olio/webapp/java/trunk/ws/apps/webapp/src/java/org/apache/olio/webapp/fileupload/FileUploadHandler.java
    incubator/olio/webapp/java/trunk/ws/apps/webapp/src/java/org/apache/olio/webapp/model/Invitation.java
    incubator/olio/webapp/java/trunk/ws/apps/webapp/src/java/org/apache/olio/webapp/model/ModelFacade.java
    incubator/olio/webapp/java/trunk/ws/apps/webapp/src/java/org/apache/olio/webapp/rest/EventRestAction.java
    incubator/olio/webapp/java/trunk/ws/apps/webapp/src/java/org/apache/olio/webapp/rest/PersonRestAction.java
    incubator/olio/webapp/java/trunk/ws/apps/webapp/src/java/org/apache/olio/webapp/rest/UsersResource.java
    incubator/olio/webapp/java/trunk/ws/apps/webapp/src/java/org/apache/olio/webapp/util/CacheControlFilter.java
    incubator/olio/webapp/java/trunk/ws/apps/webapp/src/java/org/apache/olio/webapp/util/ContentCachingFilter.java
    incubator/olio/webapp/java/trunk/ws/apps/webapp/src/java/org/apache/olio/webapp/util/GeoCoder.java
    incubator/olio/webapp/java/trunk/ws/apps/webapp/src/java/org/apache/olio/webapp/util/WebappUtil.java

Modified: incubator/olio/webapp/java/trunk/ws/apps/webapp/src/java/org/apache/olio/webapp/controller/ArtifactAction.java
URL: http://svn.apache.org/viewvc/incubator/olio/webapp/java/trunk/ws/apps/webapp/src/java/org/apache/olio/webapp/controller/ArtifactAction.java?rev=822866&r1=822865&r2=822866&view=diff
==============================================================================
--- incubator/olio/webapp/java/trunk/ws/apps/webapp/src/java/org/apache/olio/webapp/controller/ArtifactAction.java (original)
+++ incubator/olio/webapp/java/trunk/ws/apps/webapp/src/java/org/apache/olio/webapp/controller/ArtifactAction.java Wed Oct  7 19:32:59 2009
@@ -15,12 +15,10 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-
 package org.apache.olio.webapp.controller;
 
 import org.apache.olio.webapp.util.fs.FileSystem;
 import org.apache.olio.webapp.util.ServiceLocator;
-import org.apache.olio.webapp.util.WebappConstants;
 import org.apache.olio.webapp.util.WebappUtil;
 import java.io.File;
 import java.io.FileInputStream;
@@ -28,9 +26,9 @@
 import java.io.IOException;
 import java.io.InputStream;
 import java.io.OutputStream;
-import java.nio.channels.Channels;
 import java.nio.channels.FileChannel;
 import java.nio.channels.WritableByteChannel;
+import java.util.logging.Logger;
 import javax.servlet.ServletContext;
 import javax.servlet.ServletException;
 import javax.servlet.http.HttpServletRequest;
@@ -43,90 +41,86 @@
  * @author Binu John
  */
 public class ArtifactAction implements Action {
-    
+
     public static final String GIF_SUFFIX = ".gif";
     public static final String JPG_SUFFIX = ".jpg";
     public static final String PNG_SUFFIX = ".png";
-    public static final boolean bDebug=false;
+    public static final boolean bDebug = false;
     private ServletContext context;
     private static int BUFFER_SIZE = Integer.parseInt(System.getProperty("webapp.artifactBufferSize", "8192"));
-    
+    private Logger logger = Logger.getLogger(ArtifactAction.class.getName());
     // Use a ThreadLocalBuffer rather than recreating buffer every time
     private static ThreadLocal<byte[]> tlBuf = new ThreadLocal<byte[]>() {
+
         protected synchronized byte[] initialValue() {
             return new byte[BUFFER_SIZE];
         }
     };
-    
+
     public ArtifactAction(ServletContext context) {
         this.context = context;
     }
-    
+
     public String process(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
-        String pathInfo=request.getPathInfo();
-        if(bDebug) System.out.println("pathInfo = " + pathInfo);
-        
+        String pathInfo = request.getPathInfo();
+
         if (pathInfo == null) {
-            System.out.println ("WARNING ---- Accessing artifact is NULL");
-        }
-        else {
-            if(bDebug) System.out.println("pathInfo = " + pathInfo);
+            logger.warning("Accessing artifact is NULL");
+        } else {
+            logger.finer("pathInfo = " + pathInfo);
         }
-        
+
         // set proper contentType
         String mimeType = context.getMimeType(pathInfo);
         response.setContentType(mimeType);
-        
+
         // Modified for DFS support
         FileSystem fs = ServiceLocator.getInstance().getFileSystem();
-        
+
         // look for file in default location such as WEB-INF
-        String imagePath=WebappUtil.getArtifactLocalionDir() + pathInfo;
-        if(bDebug) System.out.println("Image path = " + imagePath);
-        File imageFile = new File (imagePath);
-    /* Assume image exists -- This was done to reduce FileSystem interaction 
+        String imagePath = WebappUtil.getArtifactLocalionDir() + pathInfo;
+        logger.finer("Image path = " + imagePath);
+        File imageFile = new File(imagePath);
+        /* Assume image exists -- This was done to reduce FileSystem interaction
         if(!fs.exists(imagePath)) {
-            System.out.println ("Could not find file - " + imagePath);
-             // not in default location, look in upload location
-            imageFile=new File(context.getRealPath("artifacts/" + pathInfo));
-            if (!fs.exists(imageFile.getCanonicalPath())) {
-                 WebappUtil.getLogger().log(Level.SEVERE, "image_does_not_exist", imageFile.getCanonicalPath());
-                 return null;
-            }
+        System.out.println ("Could not find file - " + imagePath);
+        // not in default location, look in upload location
+        imageFile=new File(context.getRealPath("artifacts/" + pathInfo));
+        if (!fs.exists(imageFile.getCanonicalPath())) {
+        WebappUtil.getLogger().log(Level.SEVERE, "image_does_not_exist", imageFile.getCanonicalPath());
+        return null;
+        }
         }
-        ** End mod */
-        
+         ** End mod */
+
         FileInputStream fis = null;
         FileChannel in = null;
         WritableByteChannel out = null;
-        
+
         // serve up image from proper location
         // Use local file system if the image is in default location.
-        if(bDebug) System.out.println ("AcessArtifact -- imagePath = " + imagePath);
+        logger.finer("AcessArtifact -- imagePath = " + imagePath);
         InputStream is = null;
         try {
             is = fs.open(imagePath);
-        }
-        catch (FileNotFoundException nfe) {
-            System.out.println ("File not found - imagePath = " + imagePath);
-        }
-        catch (IOException ioe) {
-            System.out.println ("IOException - imagePath = " + imagePath);
-        }
-    if (is == null) {
-        System.out.println ("Couldnot open image: " + imagePath);
-    }
-    else {
+        } catch (FileNotFoundException nfe) {
+            logger.severe("File not found - imagePath = " + imagePath);
+        } catch (IOException ioe) {
+            logger.severe("IOException - imagePath = " + imagePath);
+        }
+        if (is == null) {
+            logger.severe("Could not open image: " + imagePath);
+        } else {
             if (is instanceof FileInputStream) {
-                if(bDebug) System.out.println ("Streaming from file --");
-            try {
+                logger.finer("Streaming from file --");
+                try {
                     // NIO transferTo takes the slow route since we are passing along a wrapped
                     // buffer rather than the Socket output stream. 
                     // From experiments we did, it looks like 
                     // Using traditional I/O is more efficient than using NIO in our case - for
                     // small files.
                     /*
-            fis = (FileInputStream) (is);
+                    fis = (FileInputStream) (is);
                     in = fis.getChannel();
                     out = Channels.newChannel(response.getOutputStream());
                     in.transferTo(0, in.size(), out);
@@ -136,15 +130,15 @@
                     while ((count = is.read(buf)) != -1) {
                         response.getOutputStream().write(buf, 0, count);
                     }
-                }
-                finally {
+                } finally {
                     WebappUtil.closeIgnoringException(in);
                     WebappUtil.closeIgnoringException(fis);
                     WebappUtil.closeIgnoringException(out);
                 }
-            }
-            else {
-                if(bDebug) System.out.println ("Not a FileInputStream");
+            } else {
+                if (bDebug) {
+                    System.out.println("Not a FileInputStream");
+                }
                 InputStream iStream = null;
                 try {
                     OutputStream oStream = response.getOutputStream();
@@ -153,16 +147,15 @@
                     // TODO - Optimize this (if required) when DFS is supported
                     byte[] buffer = new byte[4096];
                     int len;
-                    while ((len=iStream.read(buffer)) != -1) {
+                    while ((len = iStream.read(buffer)) != -1) {
                         oStream.write(buffer, 0, len);
                     }
-                }
-                finally {
+                } finally {
                     WebappUtil.closeIgnoringException(iStream);
                 }
             }
-    }
-                
+        }
+
         return null;
     }
 }

Modified: incubator/olio/webapp/java/trunk/ws/apps/webapp/src/java/org/apache/olio/webapp/controller/ControllerServlet.java
URL: http://svn.apache.org/viewvc/incubator/olio/webapp/java/trunk/ws/apps/webapp/src/java/org/apache/olio/webapp/controller/ControllerServlet.java?rev=822866&r1=822865&r2=822866&view=diff
==============================================================================
--- incubator/olio/webapp/java/trunk/ws/apps/webapp/src/java/org/apache/olio/webapp/controller/ControllerServlet.java (original)
+++ incubator/olio/webapp/java/trunk/ws/apps/webapp/src/java/org/apache/olio/webapp/controller/ControllerServlet.java Wed Oct  7 19:32:59 2009
@@ -21,6 +21,7 @@
 import org.apache.olio.webapp.rest.EventRestAction;
 import org.apache.olio.webapp.rest.PersonRestAction;
 import java.io.IOException;
+import java.util.logging.Logger;
 import java.util.logging.Level;
 import javax.servlet.ServletConfig;
 import javax.servlet.ServletContext;
@@ -28,7 +29,6 @@
 import javax.servlet.http.HttpServlet;
 import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletResponse;
-import org.apache.olio.webapp.util.WebappUtil;
 
 //import com.sun.javaee.blueprints.webapp.model.Item;
 //import com.sun.javaee.blueprints.webapp.model.Tag;
@@ -43,7 +43,7 @@
  */
 public class ControllerServlet extends HttpServlet {
     
-    private static final boolean bDebug = false;
+    private static final Logger logger = Logger.getLogger(ControllerServlet.class.getName());
     private ActionMap actionMap = new ActionMap();
     
     @Override
@@ -63,7 +63,7 @@
                 getServletContext().getRequestDispatcher(responseUrl).forward(request, response);
             }
         } else {
-            WebappUtil.getLogger().log(Level.SEVERE, "Action for '" + request.getRequestURI()  + "' not registered in ControllerServlet!!");
+            logger.log(Level.SEVERE, "Action for '" + request.getRequestURI()  + "' not registered in ControllerServlet!!");
             response.sendError(HttpServletResponse.SC_NOT_FOUND);
         }
     }

Modified: incubator/olio/webapp/java/trunk/ws/apps/webapp/src/java/org/apache/olio/webapp/controller/EntryFilter.java
URL: http://svn.apache.org/viewvc/incubator/olio/webapp/java/trunk/ws/apps/webapp/src/java/org/apache/olio/webapp/controller/EntryFilter.java?rev=822866&r1=822865&r2=822866&view=diff
==============================================================================
--- incubator/olio/webapp/java/trunk/ws/apps/webapp/src/java/org/apache/olio/webapp/controller/EntryFilter.java (original)
+++ incubator/olio/webapp/java/trunk/ws/apps/webapp/src/java/org/apache/olio/webapp/controller/EntryFilter.java Wed Oct  7 19:32:59 2009
@@ -36,6 +36,7 @@
 import org.apache.olio.webapp.util.WebappUtil;
 import java.util.HashSet;
 import java.util.logging.Level;
+import java.util.logging.Logger;
 import javax.servlet.RequestDispatcher;
 import javax.servlet.http.HttpServletResponse;
 
@@ -50,12 +51,12 @@
     // configured.
     private FilterConfig filterConfig = null;
     private HashSet<String> securePages=new HashSet<String>();
-    private static final boolean bDebug=false;
-    
+    //private static final boolean bDebug=false;
+    private static final Logger logger = Logger.getLogger(EntryFilter.class.getName());
+
     public EntryFilter() {
     }
-    
-    
+        
     /**
      *
      * @param request The servlet request we are processing
@@ -77,11 +78,11 @@
             HttpServletResponse httpResponse=(HttpServletResponse)response;
             SecurityHandler securityHandler=SecurityHandler.getInstance();
             String resource=httpRequest.getServletPath();
-            if(bDebug) System.out.println("\nEntity Filter - Have servletpath = " + resource);
+            logger.finer("\nEntity Filter - Have servletpath = " + resource);
             
             if(resource.equals("/login.jsp")) {
                 // login page either being accessed or submitted
-                if(bDebug) System.out.println("Entity Filter - have login page request or submission");
+                logger.finer("Entity Filter - have login page request or submission");
                 
                 // see if parameters are submitted
                 String userName=request.getParameter(WebConstants.USER_NAME_PARAM);
@@ -118,17 +119,17 @@
                     resource += pathInfo;
                     // using the rest type urls go only 3 '/' deep for security check (e.g. /xxx/xxxx/xxx)
                     resource=getSecurityURI(resource);
-                    if(bDebug) System.out.println("\nEntity Filter - checking if protect path = " + resource);
+                    logger.finer("\nEntity Filter - checking if protect path = " + resource);
                 }
                 
                 
-                WebappUtil.getLogger().log(Level.FINE,"Checking resource to see if login required " + resource);
-                if(bDebug) System.out.println("Entity Filter - Checking resource to see if login required - " + resource);
+                logger.finer("Checking resource to see if login required " + resource);
+                logger.finer("Entity Filter - Checking resource to see if login required - " + resource);
                 //resource=resource.substring(resource.lastIndexOf("/") + 1);
                 // if null page then using default welcome mechanism, assume it is an accessable page.
                 if(resource != null) {
                     if(securePages.contains(resource)) {
-                        if(bDebug) System.out.println("Entity Filter - have secure resource - " + resource);
+                        logger.finer("Entity Filter - have secure resource - " + resource);
                         
                         // set response header to alert ajax calls of a login error.
                         httpResponse.addHeader("NeedLogin", "The user needs to be logged in");
@@ -222,7 +223,7 @@
         
         // read in allowed access points
         String securePagesParam=filterConfig.getServletContext().getInitParameter("securePages");
-        if(bDebug) System.out.println("\n*** entry String = " + securePagesParam);
+        logger.finer("\n*** entry String = " + securePagesParam);
         // loop through pages to see if
         StringTokenizer stPages=new StringTokenizer(securePagesParam, "|");
         int countx=stPages.countTokens();

Modified: incubator/olio/webapp/java/trunk/ws/apps/webapp/src/java/org/apache/olio/webapp/controller/PersonAction.java
URL: http://svn.apache.org/viewvc/incubator/olio/webapp/java/trunk/ws/apps/webapp/src/java/org/apache/olio/webapp/controller/PersonAction.java?rev=822866&r1=822865&r2=822866&view=diff
==============================================================================
--- incubator/olio/webapp/java/trunk/ws/apps/webapp/src/java/org/apache/olio/webapp/controller/PersonAction.java (original)
+++ incubator/olio/webapp/java/trunk/ws/apps/webapp/src/java/org/apache/olio/webapp/controller/PersonAction.java Wed Oct  7 19:32:59 2009
@@ -15,12 +15,10 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-
 package org.apache.olio.webapp.controller;
 
 import org.apache.olio.webapp.model.ModelFacade;
 import org.apache.olio.webapp.model.Person;
-//import com.sun.javaee.blueprints.webapp.model.UserSignOn;
 import org.apache.olio.webapp.util.WebappUtil;
 import java.io.IOException;
 import java.util.logging.Level;
@@ -36,6 +34,7 @@
 import org.apache.olio.webapp.util.UserBean;
 import java.util.Collection;
 import java.util.Iterator;
+import java.util.logging.Logger;
 
 /**
  * handles all request related to users
@@ -44,12 +43,13 @@
  * @author Kim LiChong
  */
 public class PersonAction implements Action {
-    
-    private static final boolean bDebug=false;
-    
+
+    private Logger logger = Logger.getLogger(PersonAction.class.getName());
+
     public PersonAction(ServletContext context) {
         this.context = context;
     }
+
     /**
      * DO NOT UPDATE THIS FILE
      * INSTEAD use rest.PersonRestAction
@@ -57,20 +57,19 @@
      * changing this to displaying JSP page 
      *
      */
-    
     public String process(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
         String userName = request.getParameter(USER_NAME_PARAM);
         String password = request.getParameter(PASSWORD_PARAM);
         String firstName = request.getParameter(FIRST_NAME_PARAM);
         String lastName = request.getParameter(LAST_NAME_PARAM);
         String summary = request.getParameter(SUMMARY_PARAM);
-        
-        
+
+
         String actionType = request.getParameter(ACTION_TYPE_PARAM);
-        ModelFacade mf= (ModelFacade) context.getAttribute(MF_KEY);
-        String returnURL=null;
+        ModelFacade mf = (ModelFacade) context.getAttribute(MF_KEY);
+        String returnURL = null;
         String path = request.getPathInfo();
-        if (path!=null && path.equals("/login")) {
+        if (path != null && path.equals("/login")) {
             String fUrl = "/site.jsp";
             String user_name = request.getParameter("user_name");
             UserBean userBean = (UserBean) request.getSession(true).getAttribute("userBean");
@@ -100,67 +99,67 @@
             response.sendRedirect(fUrl);
             return null;
         }
-        
-        if (actionType!=null){
-            if (actionType.equalsIgnoreCase("display_person")){
+
+        if (actionType != null) {
+            if (actionType.equalsIgnoreCase("display_person")) {
                 String username = request.getParameter("user_name");
                 Person displayUser = mf.findPerson(username);
-               if (displayUser != null) {
-                   //get posted events
-                   Collection<SocialEvent> userEvents = mf.getPostedEvents(displayUser);
-                   request.setAttribute("userEvents", userEvents);
-                   //System.out.println("the size of the incoming friendships is "+ displayUser.getIncomingInvitations().size());
-                 request.setAttribute("displayPerson", displayUser);                      
-                 returnURL="/site.jsp?page=personContent.jsp";
-               }
-           } else if(actionType.equalsIgnoreCase("display_friends")) {
-               String username = request.getParameter("user_name");
+                if (displayUser != null) {
+                    //get posted events
+                    Collection<SocialEvent> userEvents = mf.getPostedEvents(displayUser);
+                    request.setAttribute("userEvents", userEvents);
+                    //logger.finer("the size of the incoming friendships is "+ displayUser.getIncomingInvitations().size());
+                    request.setAttribute("displayPerson", displayUser);
+                    returnURL = "/site.jsp?page=personContent.jsp";
+                }
+            } else if (actionType.equalsIgnoreCase("display_friends")) {
+                String username = request.getParameter("user_name");
                 Person displayUser = mf.findPerson(username);
-                request.setAttribute("displayPerson", displayUser); 
-                returnURL="/site.jsp?page=friends.jsp";           
-                
-           } else if(actionType.equalsIgnoreCase("add_person")) {
-               //should not go here - we are doing this via PersonRestAction
-               //this.addPerson(request, response);               
-               returnURL = "/site.jsp?page=addPerson.jsp";
-               
-           } else if(actionType.equalsIgnoreCase("edit_person")) {
-               request.setAttribute("isEditable", Boolean.TRUE);               
-               returnURL="/site.jsp?page=addPerson.jsp";
-           } else if(actionType.equalsIgnoreCase("display_myPostedEvents")) {
-               String username = request.getParameter("user_name");
+                request.setAttribute("displayPerson", displayUser);
+                returnURL = "/site.jsp?page=friends.jsp";
+
+            } else if (actionType.equalsIgnoreCase("add_person")) {
+                //should not go here - we are doing this via PersonRestAction
+                //this.addPerson(request, response);
+                returnURL = "/site.jsp?page=addPerson.jsp";
+
+            } else if (actionType.equalsIgnoreCase("edit_person")) {
+                request.setAttribute("isEditable", Boolean.TRUE);
+                returnURL = "/site.jsp?page=addPerson.jsp";
+            } else if (actionType.equalsIgnoreCase("display_myPostedEvents")) {
+                String username = request.getParameter("user_name");
                 Person displayUser = mf.findPerson(username);
                 if (displayUser != null) {
-                   //get posted events
-                   Collection<SocialEvent> myPostedEvents = mf.getPostedEvents(displayUser);                   
-                   System.out.println("the size of myPostedEvents is " +  myPostedEvents.size() );
-                   request.setAttribute("myPostedEvents", myPostedEvents);
+                    //get posted events
+                    Collection<SocialEvent> myPostedEvents = mf.getPostedEvents(displayUser);
+                    logger.finer("the size of myPostedEvents is " + myPostedEvents.size());
+                    request.setAttribute("myPostedEvents", myPostedEvents);
                 }
-                returnURL="/site.jsp?page=eventsPostedByUser.jsp";
-           }    else if(actionType.equalsIgnoreCase("Search")) {
-               String query = request.getParameter("query");
+                returnURL = "/site.jsp?page=eventsPostedByUser.jsp";
+            } else if (actionType.equalsIgnoreCase("Search")) {
+                String query = request.getParameter("query");
                 //need to specify max results
-                Collection <Person> searchResults = mf.searchUsers(query, 0);
+                Collection<Person> searchResults = mf.searchUsers(query, 0);
                 //have all of the users - now get the friends
                 Person requestor = mf.findPerson(userName);
-                UserBean userBean = (UserBean)request.getSession().getAttribute("userBean");
+                UserBean userBean = (UserBean) request.getSession().getAttribute("userBean");
                 Person loggedInPerson = userBean.getLoggedInPerson();
                 String loggedInPersonUsername = loggedInPerson.getUserName();
                 Collection<Person> friends = loggedInPerson.getFriends();
-                System.out.println("the size of the loggedInPerson's friends  "+ loggedInPerson.getUserName() +" is " + friends.size() );               
+                logger.finer("the size of the loggedInPerson's friends  " + loggedInPerson.getUserName() + " is " + friends.size());
                 //invitations
                 Collection<Invitation> invites = loggedInPerson.getIncomingInvitations();
-                System.out.println("the size of the invitations list is "+ invites.size());
-                
+                logger.finer("the size of the invitations list is " + invites.size());
+
                 //iterate through and remove the friends from the list
                 //need to remove loggedInPerson too since you cannot have yourself as a friend
                 Iterator<Person> it = searchResults.iterator();
                 while (it.hasNext()) {
                     Person person = it.next();
-                    
+
                     Iterator<Person> friendIterator = friends.iterator();
                     Iterator<Invitation> invitationIter = invites.iterator();
-                    
+
                     while (friendIterator.hasNext()) {
                         String fUsername = friendIterator.next().getUserName();
                         if (fUsername.equalsIgnoreCase(person.getUserName()) || fUsername.equalsIgnoreCase(loggedInPerson.getUserName())) {
@@ -168,18 +167,18 @@
                         }
                     }
                     //determine whether they are received their invitation already
-                    while(invitationIter.hasNext()){
+                    while (invitationIter.hasNext()) {
                         Invitation inv = invitationIter.next();
-                        if(inv.getCandidate().getUserName().equalsIgnoreCase(person.getUserName())){                        
+                        if (inv.getCandidate().getUserName().equalsIgnoreCase(person.getUserName())) {
                             person.setHasReceivedInvitation(true);
                         }
                     }
                 }
-                //System.out.println("after sorting, the size of the collection is " + searchResults.size());
-                                                                
+                //logger.finer("after sorting, the size of the collection is " + searchResults.size());
+
                 //not in session request.getSession().setAttribute("searchResults", searchResults);
                 loggedInPerson.setNonFriendList(searchResults);
-                
+
 
                 if (searchResults != null) {
                     request.setAttribute("searchResults", searchResults);
@@ -189,12 +188,12 @@
                 String query = request.getParameter("query");
                 String friendUsername = request.getParameter("friend");
                 //this is returning null - SecurityHandler.getInstance().getLoggedInPerson(request);
-                UserBean userBean = (UserBean)request.getSession().getAttribute("userBean");
+                UserBean userBean = (UserBean) request.getSession().getAttribute("userBean");
                 Person loggedInPerson = userBean.getLoggedInPerson();
-                Collection <Person> previousSearchResults = loggedInPerson.getNonFriendList();
+                Collection<Person> previousSearchResults = loggedInPerson.getNonFriendList();
                 ///add or delete
                 String flag = request.getParameter("flag");
-                System.out.println("*** flag is " + flag);
+                logger.finer("*** flag is " + flag);
                 if (flag.equals("add")) {
                     Person friend = mf.findPerson(friendUsername);
                     Invitation invitation = new Invitation(loggedInPerson, friend);
@@ -205,21 +204,21 @@
                         Person eachPerson = searchIter.next();
                         if (eachPerson.getUserName().equalsIgnoreCase(friendUsername)) {
                             eachPerson.setHasReceivedInvitation(true);
-                            System.out.println("user " + eachPerson.getUserName() + " status is " + eachPerson.isHasReceivedInvitation());
+                            logger.finer("user " + eachPerson.getUserName() + " status is " + eachPerson.isHasReceivedInvitation());
                         }
                     }
 
-                } else if (flag.equals("delete")) {  
-                        Invitation inv = mf.findInvitation(loggedInPerson.getUserName(), friendUsername);                       
-                        mf.deleteInvitation(loggedInPerson, inv);
+                } else if (flag.equals("delete")) {
+                    Invitation inv = mf.findInvitation(loggedInPerson.getUserName(), friendUsername);
+                    mf.deleteInvitation(loggedInPerson, inv);
                     //iterate through and set new added friend's hasReceivedInvitation to false 
-                    
+
                     Iterator<Person> searchIter = previousSearchResults.iterator();
                     while (searchIter.hasNext()) {
                         Person eachPerson = searchIter.next();
                         if (eachPerson.getUserName().equalsIgnoreCase(friendUsername)) {
                             eachPerson.setHasReceivedInvitation(false);
-                            System.out.println("user " + eachPerson.getUserName() + " status is " + eachPerson.isHasReceivedInvitation());
+                            logger.finer("user " + eachPerson.getUserName() + " status is " + eachPerson.isHasReceivedInvitation());
                         }
 
                     }
@@ -239,9 +238,7 @@
 
         }
         return returnURL;
-}
-
-    
+    }
     private ServletContext context;
 
     private Person addPerson(HttpServletRequest request, HttpServletResponse response) {
@@ -268,13 +265,12 @@
         if (thumbImage == null) {
             thumbImage = "";
         }
-        if (bDebug) {
-            System.out.println("************** data entered is*** " + "user_name*" + userName +
-                    " password=" + password +
-                    " first_name=*" + firstName +
-                    " last_name" + lastName +
-                    " summary" + summary);
-        }
+        logger.finer("************** data entered is*** " + "user_name*" + userName +
+                " password=" + password +
+                " first_name=*" + firstName +
+                " last_name" + lastName +
+                " summary" + summary);
+
         Person person = new Person(userName, password, firstName, lastName, summary, email, telephone, imageURL, thumbImage, timezone, address);
         ModelFacade mf = (ModelFacade) context.getAttribute(MF_KEY);
         //do not really need username since you set this value, not sure why it is returned
@@ -283,7 +279,7 @@
         //userName = mf.addPerson(person, userSignOn);
 
         userName = mf.addPerson(person);
-        WebappUtil.getLogger().log(Level.FINE, "Person " + userName + " has been persisted");
+        logger.finer("Person " + userName + " has been persisted");
         // retrieve again ???
         //person=mf.getPerson(userName);
         // login person

Modified: incubator/olio/webapp/java/trunk/ws/apps/webapp/src/java/org/apache/olio/webapp/controller/RestAction.java
URL: http://svn.apache.org/viewvc/incubator/olio/webapp/java/trunk/ws/apps/webapp/src/java/org/apache/olio/webapp/controller/RestAction.java?rev=822866&r1=822865&r2=822866&view=diff
==============================================================================
--- incubator/olio/webapp/java/trunk/ws/apps/webapp/src/java/org/apache/olio/webapp/controller/RestAction.java (original)
+++ incubator/olio/webapp/java/trunk/ws/apps/webapp/src/java/org/apache/olio/webapp/controller/RestAction.java Wed Oct  7 19:32:59 2009
@@ -18,6 +18,7 @@
 
 package org.apache.olio.webapp.controller;
 
+import java.util.logging.Logger;
 import org.apache.olio.webapp.model.ModelFacade;
 import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletResponse;
@@ -27,7 +28,7 @@
  * @author Inderjeet Singh
  */
 public class RestAction implements Action {
-    
+    private Logger logger = Logger.getLogger(RestAction.class.getName());
     private ModelFacade mf;
     
     public RestAction() {
@@ -72,7 +73,7 @@
         String zip = request.getParameter(WebConstants.ZIP_PARAM);
         Address address = handleAddress(street1, city, state, zip, proxyHost, proxyPort);                  
         SocialEvent socialEvent = new SocialEvent(title, description, submitterUserName, address, 0, 0);
-        System.out.println("Event title = " + socialEvent.getTitle());
+        logger.finer("Event title = " + socialEvent.getTitle());
         int socialEventID = modelFacade.addSocialEvent(socialEvent);
         WebappUtil.getLogger().log(Level.FINE, "SocialEvent " + socialEventID + " has been persisted");       
     }

Modified: incubator/olio/webapp/java/trunk/ws/apps/webapp/src/java/org/apache/olio/webapp/fileupload/FileUploadHandler.java
URL: http://svn.apache.org/viewvc/incubator/olio/webapp/java/trunk/ws/apps/webapp/src/java/org/apache/olio/webapp/fileupload/FileUploadHandler.java?rev=822866&r1=822865&r2=822866&view=diff
==============================================================================
--- incubator/olio/webapp/java/trunk/ws/apps/webapp/src/java/org/apache/olio/webapp/fileupload/FileUploadHandler.java (original)
+++ incubator/olio/webapp/java/trunk/ws/apps/webapp/src/java/org/apache/olio/webapp/fileupload/FileUploadHandler.java Wed Oct  7 19:32:59 2009
@@ -64,16 +64,13 @@
  */
 public class FileUploadHandler {
 
-    private static Logger _logger = null;
+    private static Logger logger = Logger.getLogger(FileUploadHandler.class.getName());
     private FileUploadStatus fileUploadStatus = null;
-    private static final String FILE_UPLOAD_LOGGER = "org.apache.olio.webapp.fileupload";
-    private static final String FILE_UPLOAD_LOG_STRINGS = null;
     
     /**
      * Default location of upload directory is /domain_dir/lib/upload, unless the Sun Appserver system property exits, then it will
      * use the domain's lib/upload directory instead
      */
-    public static final boolean bDebug = false;
 
     /** Creates a new instance of FileUpload */
     public FileUploadHandler() {
@@ -134,12 +131,10 @@
             writer.flush();
 
         } catch (IOException iox) {
-            System.out.println("FileUploadPhaseListener error writting AJAX response : " + iox);
-            getLogger().log(Level.SEVERE, "response.exeception", iox);
-        }
-        if (bDebug) {
-            System.out.println("STATUS RETURN = " + status);
+            //logger.severe("FileUploadPhaseListener error writting AJAX response : " + iox);
+            logger.log(Level.SEVERE, "FileUploadHandler Error writing AJAX response: ", iox);
         }
+        logger.log(Level.FINE, "STATUS RETURN = " + status);
     }
 
     /**
@@ -148,9 +143,8 @@
      * faces-config.xml file.  This method is accessed through the Shale-remoting dynamic framework.
      */
     public static void handleFileUploadFinal(HttpServletRequest request, HttpServletResponse response) throws IOException {
-        if (bDebug) {
-            System.out.println("** In Final upload for STATUS RETURN = ");
-        }
+        logger.log(Level.FINE, "** In Final upload for STATUS RETURN = ");
+
         response.setHeader("Cache-Control", "no-cache");
         response.setContentType("text/xml;charset=UTF-8");
 
@@ -169,17 +163,15 @@
      * This relationship is specified in the faces-config.xml file. This method is accessed through the Shale-remoting dynamic framework.  
      */
     public Hashtable<String, String> handleFileUpload(HttpServletRequest request, HttpServletResponse response) {
-        if (bDebug) {
-            // print out header for 
-            Enumeration enumx = request.getHeaderNames();
-            String key = "";
-            String listx = "";
-            while (enumx.hasMoreElements()) {
-                key = (String) enumx.nextElement();
-                listx += "\n" + key + ":" + request.getHeader(key);
-            }
-            System.out.println("Incoming Header Item:" + listx);
+        // print out header for
+        Enumeration enumx = request.getHeaderNames();
+        String key = "";
+        String listx = "";
+        while (enumx.hasMoreElements()) {
+            key = (String) enumx.nextElement();
+            listx += "\n" + key + ":" + request.getHeader(key);
         }
+        logger.fine("Incoming Header Item:" + listx);
 
         // enable progress bar (this managed bean that is in the session could be comp specific, but I can't create the component specific 
         // session object until I have the components name.  For now use static key through backing bean).
@@ -189,7 +181,7 @@
         FileUploadStatus status = new FileUploadStatus();
         session.setAttribute(FileUploadUtil.FILE_UPLOAD_STATUS, status);
         setFileUploadStatus(status);
-        
+
         // Create hashtable to hold uploaded data so it can be used by custom post extension
         Hashtable<String, String> htUpload = new Hashtable<String, String>();
         // set to set hashtable for final retrieval
@@ -213,9 +205,8 @@
                 status.setName(compName);
                 // get directory to dump file into
                 String serverLocationDir = htUpload.get(compName + "_" + FileUploadUtil.SERVER_LOCATION_DIR);
-                if (bDebug) {
-                    System.out.println("\n*** locationDir=" + serverLocationDir);
-                }
+                logger.fine("\n*** locationDir=" + serverLocationDir);
+
                 File fileDir = null;
                 if (serverLocationDir == null) {
                     // ??? need to fix incase other than glassfish
@@ -227,9 +218,8 @@
                         fileDir.mkdirs();
                     } else {
                         // use the standard tmp directory
-                        if (bDebug) {
-                            System.out.println("\n*** other default locationDir=" + serverLocationDir);
-                        }
+                        logger.fine("\n*** other default locationDir=" + serverLocationDir);
+
                         //fileDir = (File) request.getAttribute("javax.servlet.context.tempdir");
                         // we don't need the tmp directory since we are avoiding writing twice - once to /tmp and then to filestore
                         // pick this up from the system environment(or web.xml) that WebappUtil sets
@@ -245,7 +235,7 @@
                 if (fileDir == null || !fileDir.isDirectory() || !fileDir.canWrite()) {
                     // error, directory doesn't exist or isn't writable
                     status.setUploadError("Directory \"" + fileDir.toString() + "\" doesn't exist!");
-                    getLogger().log(Level.SEVERE, "directory.inaccessable", fileDir.toString());
+                    logger.log(Level.SEVERE, "directory.inaccessable", fileDir.toString());
                     return null;
                 }
 
@@ -267,9 +257,8 @@
                         int size = formItemFound(item, htUpload);
                         updateSessionStatus(itemName, size);
 
-                        if (bDebug) {
-                            System.out.println("Form field item:" + itemName);
-                        }
+                        logger.fine("Form field item:" + itemName);
+
                     } else {
                         String username = htUpload.get(WebConstants.SUBMITTER_USER_NAME_PARAM);
                         if (username == null) {
@@ -285,12 +274,11 @@
 
                 // put upload to 100% to handle rounding errors in status calc
                 status.setUploadComplete();
-                if (bDebug) {
-                    System.out.println("Final session status - " + status);
-                }
+                logger.fine("Final session status - " + status);
+
             } catch (Exception e) {
                 status.setUploadError("FileUpload didn't complete successfully.  Exception received:" + e.toString());
-                getLogger().log(Level.SEVERE, "file.upload.exception", e);
+                logger.log(Level.SEVERE, "file.upload.exception", e);
             }
         }
 
@@ -323,9 +311,8 @@
             String value = strb.toString();
 
             // put in Hashtable for later access
-            if (bDebug) {
-                System.out.println("Inserting form item in map " + key + " = " + value);
-            }
+            logger.fine("Inserting form item in map " + key + " = " + value);
+
             htUpload.put(key, value);
 
 
@@ -363,33 +350,26 @@
             // see if IE on windows which send full path with item, but just filename
             // check for both separators because client OS my be different that server OS
             // check for unix separator
-            if (bDebug) {
-                System.out.println("Have item - " + fileName + " - in name= " + item.getFieldName());
-            }
+            logger.fine("Have item - " + fileName + " - in name= " + item.getFieldName());
+
             int iPos = fileName.lastIndexOf("/");
             if (iPos > -1) {
                 fileName = fileName.substring(iPos + 1);
-                if (bDebug) {
-                    System.out.println("Have full path, need to truncate \n" + item.getName() + "\n" + fileName);
-                }
+                logger.fine("Have full path, need to truncate \n" + item.getName() + "\n" + fileName);
             }
             // check for windows separator
             iPos = fileName.lastIndexOf("\\");
             if (iPos > -1) {
                 fileName = fileName.substring(iPos + 1);
-                if (bDebug) {
-                    System.out.println("Have full path, need to truncate \n" + item.getName() + "\n" + fileName);
-                }
+                logger.fine("Have full path, need to truncate \n" + item.getName() + "\n" + fileName);
             }
-
             fileLocation = serverLocationDir + File.separator + fileName;
-
             DateFormat dateFormat = new SimpleDateFormat("MMMMddyyyy_hh_mm_ss");
             Date date = null;
             String thumbnailName;
             String thumbnailLocation;
             String ext = WebappUtil.getFileExtension(fileName);
-                
+
             if (item.getFieldName().equals(WebConstants.UPLOAD_PERSON_IMAGE_PARAM)) {
                 fileName = "p" + username;
                 thumbnailName = fileName + "_thumb" + ext;
@@ -427,22 +407,19 @@
                 write(item, fileLocation);
                 htUpload.put(WebConstants.UPLOAD_LITERATURE_PARAM, fileName);
             } else {
-                System.out.println("******** what is this?  item is " + item.getFieldName());
+                logger.warning("******** what is this?  item is " + item.getFieldName());
             }
-            if (bDebug) {
-                System.out.println("Writing item to " + fileLocation);
+            logger.fine("Writing item to " + fileLocation);
             // store image location in Hashtable for later access
-            }
+
             String fieldName = item.getFieldName();
-            if (bDebug) {
-                System.out.println("Inserting form item in map " + fieldName + " = " + fileName);
-            }
+            logger.fine("Inserting form item in map " + fieldName + " = " + fileName);
+
             htUpload.put(fieldName, fileName);
             // insert location
             String key = fieldName + FileUploadUtil.FILE_LOCATION_KEY;
-            if (bDebug) {
-                System.out.println("Inserting form item in map " + key + " = " + fileLocation);
-            }
+            logger.fine("Inserting form item in map " + key + " = " + fileLocation);
+
             htUpload.put(key, fileLocation);
         }
     }
@@ -459,18 +436,16 @@
     public static void writeUploadResponse(PrintWriter writer, FileUploadStatus status) {
         Hashtable<String, String> htUpload = status.getUploadItems();
         try {
-            if (bDebug) {
-                System.out.println("\n***In writeUploadResponse");
+            logger.log(Level.FINE, "\n***In writeUploadResponse");
             //  make sure session data exists
-            }
+
             if (htUpload != null) {
                 String compName = htUpload.get(FileUploadUtil.COMPONENT_NAME);
                 //FileUploadStatus status=getFileUploadStatus();
                 // check to see if user has custom post-processing method
                 String postProcessingMethod = htUpload.get(compName + "_" + FileUploadUtil.POST_PROCESSING_METHOD);
-                if (bDebug) {
-                    System.out.println("\n*** postProcessingMethod = " + postProcessingMethod);
-                }
+                logger.log(Level.FINE, "\n*** postProcessingMethod = " + postProcessingMethod);
+
                 if (postProcessingMethod != null) {
                     // call post-processing method
                     // extension mechanism
@@ -479,9 +454,8 @@
                 // see if custom response set
                 if (!status.isCustomReturnEnabled()) {
                     // return default response
-                    if (bDebug) {
-                        System.out.println("FINAL STATUS - " + status);
-                    }
+                    logger.log(Level.FINE, "FINAL STATUS - " + status);
+
                     writer.println("<response>");
                     writer.println("<message>");
                     writer.println(status.getMessage());
@@ -526,12 +500,9 @@
                 writer.flush();
             }
         } catch (Exception e) {
-            if (bDebug) {
-                System.out.println("FileUploadPhaseListener error writting AJAX response : " + e);
-            }
-            getLogger().log(Level.SEVERE, "response.exeception", e);
+            logger.log(Level.FINE, "FileUploadPhaseListener error writting AJAX response : " + e);
+            logger.log(Level.SEVERE, "response.exeception", e);
         }
-
     }
 
     /**
@@ -545,14 +516,13 @@
     public void write(FileItemStream item, String filePath) throws Exception {
         // use name for update of session
         String itemName = item.getName();
-        
+
         ServiceLocator locator = ServiceLocator.getInstance();
 
         FileSystem fs = locator.getFileSystem();
 
-        if (bDebug) {
-            System.out.println("Getting fileItem from memory - " + itemName);
-        }
+        logger.fine("Getting fileItem from memory - " + itemName);
+
         OutputStream fout = fs.create(filePath);
 
         // It would have been more efficient to use NIO if we are writing to 
@@ -562,7 +532,7 @@
 
         try {
             byte[] buf = new byte[2048];
-            int count,  size = 0;
+            int count, size = 0;
             InputStream is = item.openStream();
             while ((count = is.read(buf)) != -1) {
                 fout.write(buf, 0, count);
@@ -601,16 +571,4 @@
     public FileUploadStatus getFileUploadStatus() {
         return fileUploadStatus;
     }
-
-    /**
-     * Method getLogger
-     *
-     * @return Logger - logger for the NodeAgent
-     */
-    public static Logger getLogger() {
-        if (_logger == null) {
-            _logger = Logger.getLogger(FILE_UPLOAD_LOGGER, FILE_UPLOAD_LOG_STRINGS);
-        }
-        return _logger;
-    }
 }

Modified: incubator/olio/webapp/java/trunk/ws/apps/webapp/src/java/org/apache/olio/webapp/model/Invitation.java
URL: http://svn.apache.org/viewvc/incubator/olio/webapp/java/trunk/ws/apps/webapp/src/java/org/apache/olio/webapp/model/Invitation.java?rev=822866&r1=822865&r2=822866&view=diff
==============================================================================
--- incubator/olio/webapp/java/trunk/ws/apps/webapp/src/java/org/apache/olio/webapp/model/Invitation.java (original)
+++ incubator/olio/webapp/java/trunk/ws/apps/webapp/src/java/org/apache/olio/webapp/model/Invitation.java Wed Oct  7 19:32:59 2009
@@ -15,10 +15,8 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-
 package org.apache.olio.webapp.model;
 
-
 import java.io.Serializable;
 import javax.persistence.Entity;
 
@@ -29,6 +27,7 @@
 import javax.persistence.Table;
 import javax.persistence.TableGenerator;
 
+import java.util.logging.Logger;
 
 /**
  * Entity class Invitation
@@ -38,41 +37,37 @@
  *
  * @author Kim LiChong
  */
-
-
-
 @Entity
-@Table (name="INVITATION")
+@Table(name = "INVITATION")
 public class Invitation implements Serializable {
+
+    private transient Logger logger = Logger.getLogger(Invitation.class.getName());
     /* EclipseLink 1.0 sometimes generated the same ID 
-    * under heavy load leading to transaction failures during the insertion of
-    * SocialEvents (PK violation). The problem seems to happen when the allocation size is exceeded.
-    * 
-    * This is being investigated, temporary solution is to use a large allocationSize
-    * to reduce the occurance of this issue.
-    */
-    @TableGenerator(name="INVITATION_ID_GEN",
-    table="ID_GEN",
-            pkColumnName="GEN_KEY",
-            valueColumnName="GEN_VALUE",
-            pkColumnValue="INVITATION_ID",
-            allocationSize=50000)
-    @GeneratedValue(strategy=GenerationType.TABLE,generator="INVITATION_ID_GEN")
+     * under heavy load leading to transaction failures during the insertion of
+     * SocialEvents (PK violation). The problem seems to happen when the allocation size is exceeded.
+     *
+     * This is being investigated, temporary solution is to use a large allocationSize
+     * to reduce the occurance of this issue.
+     */
+    @TableGenerator(name = "INVITATION_ID_GEN",
+    table = "ID_GEN",
+    pkColumnName = "GEN_KEY",
+    valueColumnName = "GEN_VALUE",
+    pkColumnValue = "INVITATION_ID",
+    allocationSize = 50000)
+    @GeneratedValue(strategy = GenerationType.TABLE, generator = "INVITATION_ID_GEN")
     @Id
     private int invitationID;
-    
     @ManyToOne
     private Person requestor;
-    
     @ManyToOne
     private Person candidate;
-    
     private boolean isAccepted;
 
     public int getInvitationID() {
         return invitationID;
     }
-               
+
     public Person getRequestor() {
         return requestor;
     }
@@ -100,68 +95,55 @@
     public void setInvitationID(int invitationID) {
         this.invitationID = invitationID;
     }
-    
-    
 
     public Invitation(Person requestor, Person candidate) {
         this.requestor = requestor;
         this.candidate = candidate;
-        this.isAccepted=false;
+        this.isAccepted = false;
     }
-    
-    
-    
+
     public Invitation() {
     }
-    
-/*
+
+    /*
     public boolean equals(Invitation inv) {
-        String requestorUsername = inv.getRequestor().getUserName();
-        String candidateUsername = inv.getCandidate().getUserName();
-        boolean returnValue = false;
+    String requestorUsername = inv.getRequestor().getUserName();
+    String candidateUsername = inv.getCandidate().getUserName();
+    boolean returnValue = false;
 
-        if ((requestorUsername != null && this.getRequestor().getUserName().equalsIgnoreCase(requestorUsername)) 
-                && (candidateUsername != null && this.getCandidate().getUserName().equalsIgnoreCase(candidateUsername))) {
-            returnValue = true;
-        } else {
-            returnValue = false;
-        }
+    if ((requestorUsername != null && this.getRequestor().getUserName().equalsIgnoreCase(requestorUsername))
+    && (candidateUsername != null && this.getCandidate().getUserName().equalsIgnoreCase(candidateUsername))) {
+    returnValue = true;
+    } else {
+    returnValue = false;
+    }
 
-        return returnValue;
+    return returnValue;
 
     }
-  */
-    
+     */
     @Override
-    public boolean equals(Object o){
+    public boolean equals(Object o) {
         boolean returnValue = false;
-        if (o !=null && o instanceof Invitation ) {
+        if (o != null && o instanceof Invitation) {
             Invitation inv = (Invitation) o;
             String requestorUsername = inv.getRequestor().getUserName();
             String candidateUsername = inv.getCandidate().getUserName();
-            
+
             String o_candidateUsername = this.getCandidate().getUserName();
             String o_requestorUsername = this.getRequestor().getUserName();
-            System.out.println("this: candidate:" + o_candidateUsername + " requestor: "+ o_requestorUsername);
-           System.out.println("arg:  candidate:" + candidateUsername + " requestor: "+ requestorUsername);
+            logger.finer("this: candidate:" + o_candidateUsername + " requestor: " + o_requestorUsername);
+            logger.finer("arg:  candidate:" + candidateUsername + " requestor: " + requestorUsername);
 
-            if ((o_requestorUsername.equalsIgnoreCase(requestorUsername) &&  o_candidateUsername.equalsIgnoreCase(candidateUsername))) {
+            if ((o_requestorUsername.equalsIgnoreCase(requestorUsername) && o_candidateUsername.equalsIgnoreCase(candidateUsername))) {
                 returnValue = true;
             } else {
                 returnValue = false;
             }
         }
-        System.out.println("****");
-        System.out.println("the return value for equality check is " + returnValue);
-        
-        return returnValue;
-
+        logger.finer("****");
+        logger.finer("the return value for equality check is " + returnValue);
 
-
-    
+        return returnValue;
     }
-    
-    
-    
-    
 }

Modified: incubator/olio/webapp/java/trunk/ws/apps/webapp/src/java/org/apache/olio/webapp/model/ModelFacade.java
URL: http://svn.apache.org/viewvc/incubator/olio/webapp/java/trunk/ws/apps/webapp/src/java/org/apache/olio/webapp/model/ModelFacade.java?rev=822866&r1=822865&r2=822866&view=diff
==============================================================================
--- incubator/olio/webapp/java/trunk/ws/apps/webapp/src/java/org/apache/olio/webapp/model/ModelFacade.java (original)
+++ incubator/olio/webapp/java/trunk/ws/apps/webapp/src/java/org/apache/olio/webapp/model/ModelFacade.java Wed Oct  7 19:32:59 2009
@@ -17,7 +17,6 @@
  */
 package org.apache.olio.webapp.model;
 
-import javax.naming.NamingException;
 import static org.apache.olio.webapp.controller.WebConstants.*;
 import org.apache.olio.webapp.controller.WebConstants;
 import org.apache.olio.webapp.util.ServiceLocator;
@@ -74,23 +73,24 @@
     private String tagCloudStr = null;
     private boolean useCache = true;
     private String artifactPath = null;
+    private Logger logger = Logger.getLogger(ModelFacade.class.getName());
 
     /** Creates a new instance of ModelFacade */
     public ModelFacade() {
         calendar = GregorianCalendar.getInstance();
 
-        /*
-        try {
-            FileSystem fs = ServiceLocator.getInstance().getFileSystem();  
-            if (fs.isLocal())
-                artifactPath = "/artifacts";
-            else
-                artifactPath = this.getContext().getContextPath() + "/access-artifacts";
-        } catch (IOException ex) {
-            Logger.getLogger(ModelFacade.class.getName()).log(Level.SEVERE, null, ex);
-            artifactPath = this.getContext().getContextPath() + "/access-artifacts";
-        }
-       */
+    /*
+    try {
+    FileSystem fs = ServiceLocator.getInstance().getFileSystem();
+    if (fs.isLocal())
+    artifactPath = "/artifacts";
+    else
+    artifactPath = this.getContext().getContextPath() + "/access-artifacts";
+    } catch (IOException ex) {
+    Logger.getLogger(ModelFacade.class.getName()).log(Level.SEVERE, null, ex);
+    artifactPath = this.getContext().getContextPath() + "/access-artifacts";
+    }
+     */
     }
 
     public void contextDestroyed(ServletContextEvent sce) {
@@ -122,8 +122,8 @@
             try {
                 utx.rollback();
             } catch (Exception e) {
-                System.out.println("Rollbak Exception - " + exe);
-                throw new RuntimeException("Error persisting person", exe);
+                logger.log(Level.SEVERE, "Rollbak Exception: ", exe);
+                throw new RuntimeException("Error persisting person : ", exe);
             } finally {
                 em.close();
             }
@@ -132,45 +132,45 @@
         return person.getUserName();
     }
 
-    public int addInvitation(Person loggedInUser, Invitation invitation){
+    public int addInvitation(Person loggedInUser, Invitation invitation) {
         EntityManager em = emf.createEntityManager();
         Person friend = em.find(Person.class, invitation.getCandidate().getUserName());
-        try{
+        try {
             utx.begin();
-            System.out.println("Before: size of outgoingInvitations for loggedInUser " + loggedInUser.getOutgoingInvitations().size());
+            logger.finer("Before: size of outgoingInvitations for loggedInUser " + loggedInUser.getOutgoingInvitations().size());
 
             loggedInUser.getOutgoingInvitations().add(invitation);
-            System.out.println("After:  size of outgoingInvitations for loggedInUser " + loggedInUser.getOutgoingInvitations().size());
+            logger.finer("After:  size of outgoingInvitations for loggedInUser " + loggedInUser.getOutgoingInvitations().size());
 
             //need to sync for candidate.incomingInvitations?
-            System.out.println("Before: size of incomingInvitations for friend " + friend.getIncomingInvitations().size());
+            logger.finer("Before: size of incomingInvitations for friend " + friend.getIncomingInvitations().size());
 
             friend.getIncomingInvitations().add(invitation);
-            System.out.println("After: size of incomingInvitations for friend " + friend.getIncomingInvitations().size());
+            logger.finer("After: size of incomingInvitations for friend " + friend.getIncomingInvitations().size());
 
-            System.out.println("**** ModelFacade::addFriend about to merge, person username=" + loggedInUser.getUserName() +
-                          " and friend username=" + friend.getUserName());
+            logger.finer("**** ModelFacade::addFriend about to merge, person username=" + loggedInUser.getUserName() +
+                    " and friend username=" + friend.getUserName());
             em.joinTransaction();
             loggedInUser = em.merge(loggedInUser);
             em.merge(friend);
             //Do we need to persist invite too?
             em.persist(invitation);
             utx.commit();
-            System.out.println("after committing - the size of the outgoing is " + loggedInUser.getOutgoingInvitations().size());
-        } catch(Exception exe){
+            logger.finer("after committing - the size of the outgoing is " + loggedInUser.getOutgoingInvitations().size());
+        } catch (Exception exe) {
             try {
                 utx.rollback();
-            } catch (Exception e) {}
-            System.out.println ("Rollbak Exception - " + exe);
-            throw new RuntimeException("Error persisting invitation", exe);
+            } catch (Exception e) {
+            }
+            logger.severe("Rollbak Exception: " + exe);
+            throw new RuntimeException("Error persisting invitation: ", exe);
         } finally {
             em.close();
         }
-        return  invitation.getInvitationID();
+        return invitation.getInvitationID();
     }
 
-
-    public Person findPerson(String userName) {     
+    public Person findPerson(String userName) {
         EntityManager em = emf.createEntityManager();
         Person p = null;
         try {
@@ -190,7 +190,7 @@
     public List<Person> searchUsers(String query, int maxResults) {
         EntityManager em = emf.createEntityManager();
         Query q = em.createQuery("SELECT i FROM Person i WHERE i.userName LIKE " + "\'" + query + "%\'" + " ORDER BY i.userName DESC");
-        //System.out.println("the query performed is "+ "SELECT i FROM Person i WHERE i.userName LIKE " + "\'" + query +"%\'" +  " ORDER BY i.userName DESC");
+        //logger.finer("the query performed is "+ "SELECT i FROM Person i WHERE i.userName LIKE " + "\'" + query +"%\'" +  " ORDER BY i.userName DESC");
         if (maxResults > 0) {
             q.setMaxResults(maxResults);
         }
@@ -220,7 +220,7 @@
 
     @SuppressWarnings("unchecked")
     public List<Person> getAllPersons() {
-       EntityManager em = emf.createEntityManager();
+        EntityManager em = emf.createEntityManager();
         List<Person> persons = em.createQuery("SELECT i FROM Person i").getResultList();
         em.close();
         return persons;
@@ -276,62 +276,62 @@
         return person;
     }
 
-     @SuppressWarnings("unchecked")
+    @SuppressWarnings("unchecked")
     public void deletePerson(String userName) {
-            EntityManager em = emf.createEntityManager();
+        EntityManager em = emf.createEntityManager();
 
-         try {
-             //try with em.remove instead
+        try {
+            //try with em.remove instead
 
-             utx.begin();
-             Person person = em.find(Person.class, userName);
-             if (person == null) // Not a valid event
-             {
-                 return;
-             }
-             em.remove(person);
-             utx.commit();
-         } catch (Exception e) {
-             e.printStackTrace();
-             try {
-                 utx.rollback();
-             } catch (Exception ex) {
-             }
-             throw new RuntimeException("Error deleting person", e);
-         } finally {
-             em.close();
-         }
-
-                /*
-                //Query q = em.createQuery("DELETE FROM Person i WHERE i.userName = :uname");
-                q.setParameter("uname", userName);
-                q.executeUpdate();
-                utx.commit();
-            } catch (Exception e) {
-                try {
-                    utx.rollback();
-                } catch (Exception ex) {
-                }
-                throw new RuntimeException("Error deleting person", e);
-            } finally {
-                em.close();
+            utx.begin();
+            Person person = em.find(Person.class, userName);
+            if (person == null) // Not a valid event
+            {
+                return;
             }
+            em.remove(person);
+            utx.commit();
+        } catch (Exception e) {
+            e.printStackTrace();
             try {
-                utx.begin();
-                Query q = em.createQuery("DELETE FROM SocialEvent i WHERE i.socialEventID = :sid");
-                // q.setParameter("sid", id);
-                q.executeUpdate();
-                utx.commit();
-            } catch (Exception e) {
-                try {
-                    utx.rollback();
-                } catch (Exception ex) {
-                }
-                throw new RuntimeException("Error deleting person", e);
-            } finally {
-                em.close();
+                utx.rollback();
+            } catch (Exception ex) {
             }
-                 */
+            throw new RuntimeException("Error deleting person", e);
+        } finally {
+            em.close();
+        }
+
+    /*
+    //Query q = em.createQuery("DELETE FROM Person i WHERE i.userName = :uname");
+    q.setParameter("uname", userName);
+    q.executeUpdate();
+    utx.commit();
+    } catch (Exception e) {
+    try {
+    utx.rollback();
+    } catch (Exception ex) {
+    }
+    throw new RuntimeException("Error deleting person", e);
+    } finally {
+    em.close();
+    }
+    try {
+    utx.begin();
+    Query q = em.createQuery("DELETE FROM SocialEvent i WHERE i.socialEventID = :sid");
+    // q.setParameter("sid", id);
+    q.executeUpdate();
+    utx.commit();
+    } catch (Exception e) {
+    try {
+    utx.rollback();
+    } catch (Exception ex) {
+    }
+    throw new RuntimeException("Error deleting person", e);
+    } finally {
+    em.close();
+    }
+     */
     }
 
     public void deleteEvent(int id) {
@@ -363,7 +363,7 @@
         } finally {
             em.close();
         }
-        
+
         // Reset tag cloud since it has been modified
         resetTagCloud();
     }
@@ -377,7 +377,7 @@
             Person friend = em.find(Person.class, friendUserName);
             person = em.find(Person.class, userName);
             person.getFriends().add(friend);
-            //System.out.println("**** ModelFacade::addFriend about to merge, person username=" + person.getUserName() +
+            //logger.finer("**** ModelFacade::addFriend about to merge, person username=" + person.getUserName() +
             //              " and friend username=" + friend.getUserName());  
             person = em.merge(person);
             utx.commit();
@@ -387,7 +387,7 @@
 
         /*
         for (Person f : person.getFriends()) {
-        System.out.println("**** ModelFacade::addFriend AFTER MERGE, friend =" + f.getUserName());           
+        logger.finer("**** ModelFacade::addFriend AFTER MERGE, friend =" + f.getUserName());
         }
          **/
         } catch (Exception exe) {
@@ -411,14 +411,14 @@
                 String tagx = stTags.nextToken().trim().toLowerCase();
                 if (tagx.length() == 0 || hSet.contains(tagx)) {
                     // The tag is a duplicate, ignore
-                    System.out.println("Duplicate tag or empty tag -- " + tagx);
+                    logger.finer("Duplicate tag or empty tag -- " + tagx);
                     continue;
                 }
                 hSet.add(tagx);
             }
         }
         EntityManager em = emf.createEntityManager();
-        
+
         // Create a single query that returns all the existing tags
         int size = hSet.size();
         Iterator<String> iter;
@@ -432,25 +432,27 @@
                 strb.append("'");
                 strb.append(tag);
                 strb.append("'");
-                if (++i < size)
+                if (++i < size) {
                     strb.append(", ");
+                }
             }
             strb.append(")");
-            q =em.createQuery(strb.toString());
+            q = em.createQuery(strb.toString());
         }
         try {
             utx.begin();
             em.joinTransaction();
             em.persist(socialEvent);
             boolean needsMerge = false;
-            
+
             List<SocialEventTag> ltags = null;
-            if (q != null)
+            if (q != null) {
                 ltags = q.getResultList();
-            
-            
+            }
+
+
             if (ltags != null) {
-                for (SocialEventTag ptag: ltags) {
+                for (SocialEventTag ptag : ltags) {
                     ptag.incrementRefCount();
                     socialEvent.addTag(ptag);
                     ptag.getSocialEvents().add(socialEvent);
@@ -459,9 +461,9 @@
                     hSet.remove(ptag.getTag());
                 }
             }
-            
+
             iter = hSet.iterator();
-            while(iter.hasNext()) {
+            while (iter.hasNext()) {
                 String tag = iter.next();
                 SocialEventTag set = new SocialEventTag(tag);
                 set.getSocialEvents().add(socialEvent);
@@ -469,26 +471,28 @@
                 em.persist(set);
                 needsMerge = true;
             }
-            if (needsMerge)
+            if (needsMerge) {
                 em.merge(socialEvent);
+            }
             utx.commit();
         } catch (Exception exe) {
             try {
-                System.out.println("Exception in addSE - " + exe.getMessage());
-                System.out.println("SE.id = " + socialEvent.getSocialEventID());
-                System.out.println("SE.tags = ");
                 Collection<SocialEventTag> tgs = socialEvent.getTags();
+                String tagstr = null;
                 if (tgs != null) {
                     for (SocialEventTag set : tgs) {
-                        System.out.print(set.getTag());
+                        tagstr = tagstr + set.getTag();
                     }
                     System.out.println("");
                 }
+                logger.log(Level.SEVERE, "Exception in addSE: " + exe.getMessage() +
+                        "SE.id = " + socialEvent.getSocialEventID() +
+                        "SE.tags = " + tagstr, exe);
                 utx.rollback();
-                exe.printStackTrace();
+            //exe.printStackTrace();
             } catch (Exception e) {
             }
-            throw new RuntimeException("Error persisting Social Event", exe);
+            throw new RuntimeException("Error persisting Social Event: ", exe);
         } finally {
             em.close();
         }
@@ -510,7 +514,7 @@
             }
         }
         if (comment == null) {
-            Logger.getLogger(ModelFacade.class.getName()).log(Level.WARNING, "Could not find comment with commentId = " + commentId);
+            logger.warning("Could not find comment with commentId = " + commentId);
             return;
         }
         event.getComments().remove(comment);
@@ -529,7 +533,7 @@
             try {
                 utx.rollback();
             } catch (Exception ex) {
-                Logger.getLogger(ModelFacade.class.getName()).log(Level.SEVERE, null, ex);
+                logger.severe(ex.toString());
             }
         } finally {
             em.close();
@@ -541,27 +545,30 @@
         EntityManager em = emf.createEntityManager();
 
         SocialEvent socialEvent = em.find(SocialEvent.class, socialEventID);
-        
+
         // Since we have listed Adress, attendees, tags and comments as lazy, fetch them
         // within the same PersistenceContext.
         // These fetches are not required for EclipseLink. However, othe JPA 
         // implementations may not support the feature of accessing lazy fetched
         // items from detached objects.
-        
+
         // Iterating through the list is a work around for a EclipseLink bug
         // Remove it when the bug has been fixed.
-        
+
         if (socialEvent != null) {
             socialEvent.getAddress();
             Iterator<Person> iter = socialEvent.getAttendees().iterator();
-            while (iter.hasNext())
+            while (iter.hasNext()) {
                 iter.next().getUserName();
+            }
             Iterator<SocialEventTag> titer = socialEvent.getTags().iterator();
-            while (titer.hasNext())
+            while (titer.hasNext()) {
                 titer.next().getTag();
+            }
             Iterator<CommentsRating> citer = socialEvent.getComments().iterator();
-            while (citer.hasNext())
+            while (citer.hasNext()) {
                 citer.next().getCommentString();
+            }
         }
         em.close();
 
@@ -592,35 +599,35 @@
     /* Marked for DELETE -- UNUSED
     @SuppressWarnings("unchecked")
     public SocialEventTag addSocialEventTag(String sxTag) {
-        EntityManager em = emf.createEntityManager();
-        SocialEventTag tag = null;
-        try {
-            List<SocialEventTag> tags = em.createQuery("SELECT t FROM SocialEventTag t WHERE t.tag = :tag").setParameter("tag", sxTag).getResultList();
-            if (tags.isEmpty()) {
-                // need to create tag and set flag to add reference item
-                tag = new SocialEventTag(sxTag);
-                // persist data
-                utx.begin();
-                em.joinTransaction();
-                em.persist(tag);
-                utx.commit();
-            } else {
-                // see if item already exists in tag
-                tag = tags.get(0);
-            }
-
-        } catch (Exception exe) {
-            try {
-                utx.rollback();
-            } catch (Exception e) {
-            }
-            System.out.println("Exception - " + exe);
-            exe.printStackTrace();
-            throw new RuntimeException("Error persisting tag", exe);
-        } finally {
-            em.close();
-        }
-        return tag;
+    EntityManager em = emf.createEntityManager();
+    SocialEventTag tag = null;
+    try {
+    List<SocialEventTag> tags = em.createQuery("SELECT t FROM SocialEventTag t WHERE t.tag = :tag").setParameter("tag", sxTag).getResultList();
+    if (tags.isEmpty()) {
+    // need to create tag and set flag to add reference item
+    tag = new SocialEventTag(sxTag);
+    // persist data
+    utx.begin();
+    em.joinTransaction();
+    em.persist(tag);
+    utx.commit();
+    } else {
+    // see if item already exists in tag
+    tag = tags.get(0);
+    }
+
+    } catch (Exception exe) {
+    try {
+    utx.rollback();
+    } catch (Exception e) {
+    }
+    System.out.println("Exception - " + exe);
+    exe.printStackTrace();
+    throw new RuntimeException("Error persisting tag", exe);
+    } finally {
+    em.close();
+    }
+    return tag;
     }
      * */
 
@@ -709,12 +716,12 @@
             }
             utx.commit();
         } catch (Exception exe) {
-            exe.printStackTrace();
+            logger.severe("Error updating social event: " + exe.toString());
             try {
                 utx.rollback();
             } catch (Exception e) {
             }
-            throw new RuntimeException("Error updating social event", exe);
+            throw new RuntimeException("Error updating social event: ", exe);
         } finally {
             em.close();
         }
@@ -734,7 +741,7 @@
             utx.commit();
         } catch (Exception exe) {
 
-            exe.printStackTrace();
+            logger.severe("updateSocialEvent failed: " + exe.toString());
             try {
                 utx.rollback();
             } catch (Exception e) {
@@ -773,8 +780,9 @@
     }
 
     public String getTagCloud() {
-        if (useCache && tagCloudStr != null)
+        if (useCache && tagCloudStr != null) {
             return tagCloudStr;
+        }
         tagCloudStr = WebappUtil.createTagCloud(getContext().getContextPath(), getSocialEventTags());
         return tagCloudStr;
     }
@@ -844,7 +852,7 @@
                 utx.rollback();
             } catch (Exception e) {
             }
-            throw new RuntimeException("Error persisting tag", exe);
+            throw new RuntimeException("Error persisting tag: ", exe);
         } finally {
             em.close();
         }
@@ -868,7 +876,7 @@
                 utx.rollback();
             } catch (Exception e) {
             }
-            throw new RuntimeException("Error persisting tag", exe);
+            throw new RuntimeException("Error persisting tag: ", exe);
         } finally {
             em.close();
         }
@@ -896,19 +904,21 @@
 
     public List<SocialEvent> getUpcomingEvents(Person p, int max) {
         Map<String, Object> map = new HashMap<String, Object>();
-        map.put ("eventsPerPage", max);
-        return getUpcomingEvents(p, map);    
+        map.put("eventsPerPage", max);
+        return getUpcomingEvents(p, map);
     }
-    
+
     public List<SocialEvent> getUpcomingEvents(Person p, Map<String, Object> qMap) {
         int startIndex = 0, eventsPerPage = WebappConstants.ITEMS_PER_PAGE;
-        Integer value = (Integer)qMap.get("startIndex");
-        if (value != null)
+        Integer value = (Integer) qMap.get("startIndex");
+        if (value != null) {
             startIndex = value;
-        value = (Integer)qMap.get("eventsPerPage");
-        if (value != null)
+        }
+        value = (Integer) qMap.get("eventsPerPage");
+        if (value != null) {
             eventsPerPage = value;
-        
+        }
+
         EntityManager em = emf.createEntityManager();
         try {
             //String qstr = "SELECT s FROM SocialEvent s, IN (s.attendees) a WHERE a.userName = :uname AND s.eventTimestamp >= CURRENT_TIMESTAMP ORDER BY s.eventTimestamp ASC";
@@ -921,7 +931,7 @@
             }
             q.setParameter("uname", p.getUserName());
             List<SocialEvent> events = q.getResultList();
-            
+
             Long l = 0l;
             // We need a count of the events for paging.
             // However, this is not required if eventsPerPage is less than the ITEMS_PER_PAGE
@@ -932,14 +942,12 @@
                     q = em.createQuery(qstr);
                     q.setParameter("uname", p.getUserName());
                     l = (Long) q.getSingleResult();
+                } else if (events != null) {
+                    l = (long) events.size();
                 }
-                else if (events != null) {
-                    l = (long)events.size();
-                }
+            } else if (events != null) {
+                l = (long) events.size();
             }
-            else if (events != null) {
-                l = (long)events.size();
-            }    
             qMap.put("listSize", l);
             return events;
         } finally {
@@ -1077,7 +1085,7 @@
         EntityManager em = emf.createEntityManager();
         try {
             // Create the select query
-        
+
             Query q = em.createQuery(qstrb.toString());
 
             if (zipSet) {
@@ -1110,18 +1118,15 @@
                     q.setParameter("uts", uts);
                 }
                 size = (Long) q.getSingleResult();
-            }
-            else if (socialEvents != null)
+            } else if (socialEvents != null) {
                 size = (long) socialEvents.size();
-        
+            }
+
             qMap.put("listSize", size);
             return socialEvents;
-        }
-        catch (Exception e) {
-            System.out.println ("Exception for query -- q = " + qstrb.toString());
-            e.printStackTrace();
-        }
-        finally {
+        } catch (Exception e) {
+            logger.log(Level.SEVERE, "Exception for query - " + qstrb.toString(), e);
+        } finally {
             em.close();
         }
         return null;
@@ -1230,7 +1235,8 @@
             em.remove(inv0);
             utx.commit();
         } catch (Exception exe) {
-            exe.printStackTrace();
+            //exe.printStackTrace();
+            logger.log(Level.SEVERE, "Error deleting invitation: ", exe);
             try {
                 utx.rollback();
             } catch (Exception e) {
@@ -1239,7 +1245,7 @@
         } finally {
             em.close();
         }
-        System.out.println("after deleting invitation");
+        logger.finer("after deleting invitation");
 
     }
 
@@ -1267,40 +1273,37 @@
         }
     }
 
-             @SuppressWarnings("unchecked")
+    @SuppressWarnings("unchecked")
     public void deleteInvitation(Person loggedInUser, Invitation inv) {
-           EntityManager em = emf.createEntityManager();
-           Person requestor = null, candidate = null;
-           boolean isIncoming = false;
-           //check to see if outgoing or incoming invitation
-           if(loggedInUser.getUserName().equalsIgnoreCase(inv.getRequestor().getUserName())){
-               //outgoing
-               isIncoming = false;
-               requestor=loggedInUser;
-               candidate = em.find(Person.class, inv.getCandidate().getUserName());
-           }else if (loggedInUser.getUserName().equalsIgnoreCase(inv.getCandidate().getUserName())){
-               //incoming
-               isIncoming = true;
-               requestor = em.find(Person.class, inv.getRequestor().getUserName());
-               candidate = loggedInUser;
-           }
-           //if incoming, then requestor is the friend, and the candidate is the loggedInUser
+        EntityManager em = emf.createEntityManager();
+        Person requestor = null, candidate = null;
+        boolean isIncoming = false;
+        //check to see if outgoing or incoming invitation
+        if (loggedInUser.getUserName().equalsIgnoreCase(inv.getRequestor().getUserName())) {
+            //outgoing
+            isIncoming = false;
+            requestor = loggedInUser;
+            candidate = em.find(Person.class, inv.getCandidate().getUserName());
+        } else if (loggedInUser.getUserName().equalsIgnoreCase(inv.getCandidate().getUserName())) {
+            //incoming
+            isIncoming = true;
+            requestor = em.find(Person.class, inv.getRequestor().getUserName());
+            candidate = loggedInUser;
+        }
+        //if incoming, then requestor is the friend, and the candidate is the loggedInUser
 
 
-       try {
+        try {
             utx.begin();
 
-            if(isIncoming){
-                System.out.println("before:  size of the requestor IncomingInv is "+ candidate.getIncomingInvitations().size());
-                 System.out.println("before:  size of the candidate OutgoingInv is "+ requestor.getOutgoingInvitations().size());
-
-
+            if (isIncoming) {
+                logger.finer("before:  size of the requestor IncomingInv is " + candidate.getIncomingInvitations().size());
+                logger.finer("before:  size of the candidate OutgoingInv is " + requestor.getOutgoingInvitations().size());
                 candidate.getIncomingInvitations().remove(inv);
-
                 requestor.getOutgoingInvitations().remove(inv);
-                System.out.println("After:  size of the requestor IncomingInv is "+ requestor.getIncomingInvitations().size());
-                System.out.println("after:  size of the candidate OutgoingInv is "+ candidate.getOutgoingInvitations().size());
-            } else{
+                logger.finer("After:  size of the requestor IncomingInv is " + requestor.getIncomingInvitations().size());
+                logger.finer("after:  size of the candidate OutgoingInv is " + candidate.getOutgoingInvitations().size());
+            } else {
                 requestor.getOutgoingInvitations().remove(inv);
                 candidate.getIncomingInvitations().remove(inv);
             }
@@ -1309,33 +1312,31 @@
             //inv.setRequestor(null);
             em.joinTransaction();
 
-            Invitation inv0= em.merge(inv);
+            Invitation inv0 = em.merge(inv);
             //merge the two people
             em.merge(requestor);
             em.merge(candidate);
             em.remove(inv0);
             utx.commit();
-        } catch(Exception exe){
-        exe.printStackTrace();
+        } catch (Exception exe) {
+            logger.log(Level.SEVERE, "Error deleting invitation: ", exe);
             try {
                 utx.rollback();
-            } catch (Exception e) {}
+            } catch (Exception e) {
+            }
             throw new RuntimeException("Error deleting invitation", exe);
         } finally {
             em.close();
         }
-         System.out.println("after deleting invitation");
+        logger.finer("after deleting invitation");
     }
 
     public void resetTagCloud() {
         tagCloudStr = null;
     }
-    
+
     public String getArtifactPath() {
         return WebappUtil.getArtifactPath();
-        
-    }
 
-   
-    
+    }
 }