Author: ludovic
Date: 2007-12-26 15:32:07 +0100 (Wed, 26 Dec 2007)
New Revision: 6460

Modified:
   
xwiki-products/curriki/trunk/plugins/invitationmanager/src/main/java/org/xwiki/plugin/invitationmanager/api/Invitation.java
   
xwiki-products/curriki/trunk/plugins/invitationmanager/src/main/java/org/xwiki/plugin/invitationmanager/api/InvitationManager.java
   
xwiki-products/curriki/trunk/plugins/invitationmanager/src/main/java/org/xwiki/plugin/invitationmanager/api/JoinRequest.java
   
xwiki-products/curriki/trunk/plugins/invitationmanager/src/main/java/org/xwiki/plugin/invitationmanager/impl/InvitationManagerImpl.java
   
xwiki-products/curriki/trunk/plugins/invitationmanager/src/main/java/org/xwiki/plugin/invitationmanager/plugin/InvitationManagerPluginApi.java
Log:
CURRIKI-1179 Added verifyInvitation and boolean return to invitations api

Modified: 
xwiki-products/curriki/trunk/plugins/invitationmanager/src/main/java/org/xwiki/plugin/invitationmanager/api/Invitation.java
===================================================================
--- 
xwiki-products/curriki/trunk/plugins/invitationmanager/src/main/java/org/xwiki/plugin/invitationmanager/api/Invitation.java
 2007-12-24 22:26:46 UTC (rev 6459)
+++ 
xwiki-products/curriki/trunk/plugins/invitationmanager/src/main/java/org/xwiki/plugin/invitationmanager/api/Invitation.java
 2007-12-26 14:32:07 UTC (rev 6460)
@@ -26,6 +26,11 @@
 public interface Invitation extends JoinRequest
 {
     /**
+     * Returns true is this invitation is new
+     */
+    boolean isNew();
+
+    /**
      * @return The one who is invited to join the space
      */
     String getInvitee();

Modified: 
xwiki-products/curriki/trunk/plugins/invitationmanager/src/main/java/org/xwiki/plugin/invitationmanager/api/InvitationManager.java
===================================================================
--- 
xwiki-products/curriki/trunk/plugins/invitationmanager/src/main/java/org/xwiki/plugin/invitationmanager/api/InvitationManager.java
  2007-12-24 22:26:46 UTC (rev 6459)
+++ 
xwiki-products/curriki/trunk/plugins/invitationmanager/src/main/java/org/xwiki/plugin/invitationmanager/api/InvitationManager.java
  2007-12-26 14:32:07 UTC (rev 6460)
@@ -251,42 +251,62 @@
      *            should be a mailing list address
      * @param context A XWikiContext instance
      */
-    void inviteUser(String user, String space, boolean open, XWikiContext 
context) throws InvitationManagerException;
+    boolean inviteUser(String user, String space, boolean open, XWikiContext 
context) throws InvitationManagerException;
 
     /**
      * @param role The role the user will have in the space, provided he 
accepts the invitation
      * @see #inviteUser(String, String, XWikiContext)
      */
-    void inviteUser(String user, String space, boolean open, String role, 
XWikiContext context) throws InvitationManagerException;
+    boolean inviteUser(String user, String space, boolean open, String role, 
XWikiContext context) throws InvitationManagerException;
 
     /**
      * @param roles The list of roles the user will have in the space, 
provided he accepts the
      *            invitation
      * @see #inviteUser(String, String, XWikiContext)
      */
-    void inviteUser(String user, String space, boolean open, List roles, 
XWikiContext context) throws InvitationManagerException;
+    boolean inviteUser(String user, String space, boolean open, List roles, 
XWikiContext context) throws InvitationManagerException;
 
     /**
      * @param templateMail Custom e-mail template
      * @see #inviteUser(String, String, List, XWikiContext)
      */
-    void inviteUser(String user, String space, boolean open, List roles, 
String templateMail,
+    boolean inviteUser(String user, String space, boolean open, List roles, 
String templateMail,
         XWikiContext context) throws InvitationManagerException;
 
     /**
      * @param map A map of additional parameters for the invitation
      * @see #inviteUser(String, String, List, String, XWikiContext)
      */
-    void inviteUser(String user, String space, boolean open, List roles, 
String templateMail,
+    boolean inviteUser(String user, String space, boolean open, List roles, 
String templateMail,
         Map map, XWikiContext context) throws InvitationManagerException;
 
     /**
+     * The current logged-in user verify the invitation to join the specified 
space.
+     *
+     * @param space The space the user accepts to join
+     * @param context A XWikiContext instance
+     */
+    boolean verifyInvitation(String space, XWikiContext context) throws 
InvitationManagerException;
+
+    /**
+     * The current logged-in user verifies the invitation to join the 
specified space, using an email
+     * address and a code. 
+     *
+     * @param space The space the user accepts to join
+     * @param email The e-mail where the invitation was sent
+     * @param code The code of the invitation, when it was sent to a single 
person (e.g. the e-mail
+     *            address to which the invitation was sent is not a mailing 
list)
+     * @param context A XWikiContext instance
+     */
+    boolean verifyInvitation(String space, String email, String code, 
XWikiContext context) throws InvitationManagerException;
+
+    /**
      * The current logged-in user accepts the invitation to join the specified 
space.
      * 
      * @param space The space the user accepts to join
      * @param context A XWikiContext instance
      */
-    void acceptInvitation(String space, XWikiContext context) throws 
InvitationManagerException;
+    boolean acceptInvitation(String space, XWikiContext context) throws 
InvitationManagerException;
 
     /**
      * The current logged-in user accepts the invitation to join the specified 
space, using an email
@@ -298,7 +318,7 @@
      *            address to which the invitation was sent is not a mailing 
list)
      * @param context A XWikiContext instance
      */
-    void acceptInvitation(String space, String email, String code, 
XWikiContext context) throws InvitationManagerException;
+    boolean acceptInvitation(String space, String email, String code, 
XWikiContext context) throws InvitationManagerException;
 
     /**
      * The currently logged-in user rejects the invitation to join the 
specified space

Modified: 
xwiki-products/curriki/trunk/plugins/invitationmanager/src/main/java/org/xwiki/plugin/invitationmanager/api/JoinRequest.java
===================================================================
--- 
xwiki-products/curriki/trunk/plugins/invitationmanager/src/main/java/org/xwiki/plugin/invitationmanager/api/JoinRequest.java
        2007-12-24 22:26:46 UTC (rev 6459)
+++ 
xwiki-products/curriki/trunk/plugins/invitationmanager/src/main/java/org/xwiki/plugin/invitationmanager/api/JoinRequest.java
        2007-12-26 14:32:07 UTC (rev 6460)
@@ -109,4 +109,12 @@
      * @throws XWikiException
      */
     void save() throws XWikiException;
+
+    /**
+     * Saves the modified request
+     *
+     * @throws XWikiException
+     */
+    void saveWithProgrammingRights() throws XWikiException;
+
 }

Modified: 
xwiki-products/curriki/trunk/plugins/invitationmanager/src/main/java/org/xwiki/plugin/invitationmanager/impl/InvitationManagerImpl.java
===================================================================
--- 
xwiki-products/curriki/trunk/plugins/invitationmanager/src/main/java/org/xwiki/plugin/invitationmanager/impl/InvitationManagerImpl.java
     2007-12-24 22:26:46 UTC (rev 6459)
+++ 
xwiki-products/curriki/trunk/plugins/invitationmanager/src/main/java/org/xwiki/plugin/invitationmanager/impl/InvitationManagerImpl.java
     2007-12-26 14:32:07 UTC (rev 6460)
@@ -65,7 +65,7 @@
      *
      * @see InvitationManager#acceptInvitation(String, String, String, 
XWikiContext)
      */
-    public void acceptInvitation(String space, String email, String code, 
XWikiContext context) throws InvitationManagerException {
+    public boolean acceptInvitation(String space, String email, String code, 
XWikiContext context) throws InvitationManagerException {
         try {
             Invitation invitation = getInvitation(space, 
encodeEmailAddress(email), context);
             if (code.equals(invitation.getCode())
@@ -74,13 +74,16 @@
                     invitation.setStatus(JoinRequestStatus.ACCEPTED);
                     invitation.setResponseDate(new Date());
                     invitation.setInvitee(context.getUser());
-                    invitation.save();
+                    invitation.saveWithProgrammingRights();
                 }
                 // update the list of space members and their roles
                 addMember(space, context.getUser(), invitation.getRoles(), 
context);
 
                 // create a custom invitation for the currently logged-in user
                 customizeInvitation(invitation, JoinRequestStatus.ACCEPTED, 
context);
+                return true;
+            } else {
+                return false;
             }
         } catch (XWikiException e) {
             throw new InvitationManagerException(e);
@@ -90,9 +93,28 @@
     /**
      * [EMAIL PROTECTED]
      *
+     * @see InvitationManager#acceptInvitation(String, String, String, 
XWikiContext)
+     */
+    public boolean verifyInvitation(String space, String email, String code, 
XWikiContext context) throws InvitationManagerException {
+        try {
+            Invitation invitation = getInvitation(space, 
encodeEmailAddress(email), context);
+            if (code.equals(invitation.getCode())
+                    && invitation.getStatus() == JoinRequestStatus.SENT) {
+                return true;
+            } else {
+                return false;
+            }
+        } catch (XWikiException e) {
+                return false;
+        }
+    }
+
+    /**
+     * [EMAIL PROTECTED]
+     *
      * @see InvitationManager#acceptInvitation(String, XWikiContext)
      */
-    public void acceptInvitation(String space, XWikiContext context) throws 
InvitationManagerException {
+    public boolean acceptInvitation(String space, XWikiContext context) throws 
InvitationManagerException {
         try {
             Invitation invitation = getInvitation(space, context.getUser(), 
context);
             int status = invitation.getStatus();
@@ -103,13 +125,32 @@
                 // update the list of members and their roles
                 addMember(space, context.getUser(), invitation.getRoles(), 
context);
                 // save the invitation status
-                invitation.save();
-            }
+                invitation.saveWithProgrammingRights();
+                return true;
+            } else {
+                return false;
+            }           
         } catch (XWikiException e) {
             throw new InvitationManagerException(e);
         }
     }
 
+     /**
+     * [EMAIL PROTECTED]
+     *
+     * @see InvitationManager#acceptInvitation(String, String, String, 
XWikiContext)
+     */
+    public boolean verifyInvitation(String space, XWikiContext context) throws 
InvitationManagerException {
+        try {
+            Invitation invitation = getInvitation(space, context.getUser(), 
context);
+            if (invitation!=null)
+                return true;
+                return false;
+        } catch (XWikiException e) {
+                return false;
+        }
+    }
+
     /**
      * [EMAIL PROTECTED]
      *
@@ -132,7 +173,7 @@
                 addMember(space, userName, request.getRoles(), context);
 
                 // save after adding user and sending email
-                request.save();
+                request.saveWithProgrammingRights();
             }
         } catch (XWikiException e) {
             throw new InvitationManagerException(e);
@@ -161,7 +202,7 @@
             Invitation invitation = getInvitation(space, user, context);
             if (invitation.getStatus() == JoinRequestStatus.SENT) {
                 invitation.setStatus(JoinRequestStatus.CANCELLED);
-                invitation.save();
+                invitation.saveWithProgrammingRights();
             }
         } catch (XWikiException e) {
             throw new InvitationManagerException(e);
@@ -178,7 +219,7 @@
             MembershipRequest request = getMembershipRequest(space, 
context.getUser(), context);
             if (request.getStatus() == JoinRequestStatus.SENT) {
                 request.setStatus(JoinRequestStatus.CANCELLED);
-                request.save();
+                request.saveWithProgrammingRights();
             }
         } catch (XWikiException e) {
             throw new InvitationManagerException(e);
@@ -670,7 +711,7 @@
      *
      * @see 
org.xwiki.plugin.invitationmanager.api.InvitationManager#inviteUser(String, 
String, boolean, List, String, Map, XWikiContext)
      */
-    public void inviteUser(String wikiNameOrMailAddress, String space, boolean 
open, List roles,
+    public boolean inviteUser(String wikiNameOrMailAddress, String space, 
boolean open, List roles,
                            String templateMail, Map map, XWikiContext context) 
throws InvitationManagerException {
         String invitee;
         String registeredUser = null;
@@ -684,6 +725,10 @@
             }
             // create the invitation object
             Invitation invitation = createInvitation(invitee, space, context);
+
+            if (!invitation.isNew())
+                return false;
+
             invitation.setInviter(context.getUser());
             invitation.setMap(map);
             invitation.setOpen(open);
@@ -699,7 +744,8 @@
             sendMail(JoinRequestAction.SEND, invitation, templateMail, 
context);
 
             // save invitation after 
-            invitation.save();
+            invitation.saveWithProgrammingRights();
+            return true;
         } catch (XWikiException e) {
             throw new InvitationManagerException(e);
         }
@@ -710,9 +756,9 @@
      *
      * @see 
org.xwiki.plugin.invitationmanager.api.InvitationManager#inviteUser(String, 
String, boolean, List, String, XWikiContext)
      */
-    public void inviteUser(String user, String space, boolean open, List roles,
+    public boolean inviteUser(String user, String space, boolean open, List 
roles,
                            String templateMail, XWikiContext context) throws 
InvitationManagerException {
-        inviteUser(user, space, open, roles, templateMail, 
Collections.EMPTY_MAP, context);
+        return inviteUser(user, space, open, roles, templateMail, 
Collections.EMPTY_MAP, context);
     }
 
     /**
@@ -720,12 +766,12 @@
      *
      * @see 
org.xwiki.plugin.invitationmanager.api.InvitationManager#inviteUser(String, 
String, boolean, List, XWikiContext)
      */
-    public void inviteUser(String user, String space, boolean open, List roles,
+    public boolean inviteUser(String user, String space, boolean open, List 
roles,
                            XWikiContext context) throws 
InvitationManagerException {
         String templateMail =
                 getDefaultTemplateMailDocumentName(space, "Invitation", 
JoinRequestAction.SEND,
                         context);
-        inviteUser(user, space, open, roles, templateMail, context);
+        return inviteUser(user, space, open, roles, templateMail, context);
     }
 
     /**
@@ -733,11 +779,11 @@
      *
      * @see 
org.xwiki.plugin.invitationmanager.api.InvitationManager#inviteUser(String, 
String, boolean, String, XWikiContext)
      */
-    public void inviteUser(String user, String space, boolean open, String 
role,
+    public boolean inviteUser(String user, String space, boolean open, String 
role,
                            XWikiContext context) throws 
InvitationManagerException {
         List roles = new ArrayList();
         roles.add(role);
-        inviteUser(user, space, open, roles, context);
+        return inviteUser(user, space, open, roles, context);
     }
 
     /**
@@ -745,8 +791,8 @@
      *
      * @see 
org.xwiki.plugin.invitationmanager.api.InvitationManager#inviteUser(String, 
String, boolean, XWikiContext)
      */
-    public void inviteUser(String user, String space, boolean open, 
XWikiContext context) throws InvitationManagerException {
-        inviteUser(user, space, open, Collections.EMPTY_LIST, context);
+    public boolean inviteUser(String user, String space, boolean open, 
XWikiContext context) throws InvitationManagerException {
+       return  inviteUser(user, space, open, Collections.EMPTY_LIST, context);
     }
 
     /**
@@ -763,7 +809,7 @@
                     invitation.setStatus(JoinRequestStatus.REFUSED);
                     invitation.setResponseDate(new Date());
                     invitation.setInvitee(context.getUser());
-                    invitation.save();
+                    invitation.saveWithProgrammingRights();
                 }
                 // create a custom invitation for the currently logged-in user
                 customizeInvitation(invitation, JoinRequestStatus.REFUSED, 
context);
@@ -784,7 +830,7 @@
             if (invitation.getStatus() == JoinRequestStatus.SENT) {
                 invitation.setStatus(JoinRequestStatus.REFUSED);
                 invitation.setResponseDate(new Date());
-                invitation.save();
+                invitation.saveWithProgrammingRights();
             }
         } catch (XWikiException e) {
             throw new InvitationManagerException(e);
@@ -805,7 +851,7 @@
                 request.setResponseDate(new Date());
                 request.setResponder(context.getUser());
                 sendMail(JoinRequestAction.REJECT, request, templateMail, 
context);
-                request.save();
+                request.saveWithProgrammingRights();
             }
         } catch (XWikiException e) {
             throw new InvitationManagerException(e);
@@ -839,7 +885,7 @@
             request.setRoles(roles);
             request.setStatus(JoinRequestStatus.SENT);
             request.setText(message);
-            request.save();
+            request.saveWithProgrammingRights();
         } catch (XWikiException e) {
             throw new InvitationManagerException(e);
         }
@@ -970,7 +1016,7 @@
         customInvitation.setStatus(status);
         customInvitation.setOpen(false);
         customInvitation.setText(invitation.getText());
-        customInvitation.save();
+        customInvitation.saveWithProgrammingRights();
     }
 
     /**

Modified: 
xwiki-products/curriki/trunk/plugins/invitationmanager/src/main/java/org/xwiki/plugin/invitationmanager/plugin/InvitationManagerPluginApi.java
===================================================================
--- 
xwiki-products/curriki/trunk/plugins/invitationmanager/src/main/java/org/xwiki/plugin/invitationmanager/plugin/InvitationManagerPluginApi.java
      2007-12-24 22:26:46 UTC (rev 6459)
+++ 
xwiki-products/curriki/trunk/plugins/invitationmanager/src/main/java/org/xwiki/plugin/invitationmanager/plugin/InvitationManagerPluginApi.java
      2007-12-26 14:32:07 UTC (rev 6460)
@@ -319,20 +319,22 @@
      * @param open <code>true</code> if the invitation is open. In this case 
the <code>user</code>
      *            should be a mailing list address
      */
-    public void inviteUser(String user, String space, boolean open) throws 
InvitationManagerException {
+    public boolean inviteUser(String user, String space, boolean open) throws 
InvitationManagerException {
         if (hasProgrammingRights()) {
-            getInvitationManager().inviteUser(user, space, open, context);
+            return getInvitationManager().inviteUser(user, space, open, 
context);
         }
+        return false;
     }
 
     /**
      * @param role The role the user will have in the space, provided he 
accepts the invitation
      * @see #inviteUser(String, String)
      */
-    public void inviteUser(String user, String space, boolean open, String 
role) throws InvitationManagerException {
+    public boolean inviteUser(String user, String space, boolean open, String 
role) throws InvitationManagerException {
         if (hasProgrammingRights()) {
-            getInvitationManager().inviteUser(user, space, open, role, 
context);
+            return getInvitationManager().inviteUser(user, space, open, role, 
context);
         }
+        return false;
     }
 
     /**
@@ -340,41 +342,66 @@
      *            invitation
      * @see #inviteUser(String, String)
      */
-    public void inviteUser(String user, String space, boolean open, List 
roles) throws InvitationManagerException {
+    public boolean inviteUser(String user, String space, boolean open, List 
roles) throws InvitationManagerException {
         if (hasProgrammingRights()) {
-            getInvitationManager().inviteUser(user, space, open, roles, 
context);
+            return getInvitationManager().inviteUser(user, space, open, roles, 
context);
         }
+        return false;
     }
 
     /**
      * @param templateMail Custom e-mail template
      * @see #inviteUser(String, String, List)
      */
-    public void inviteUser(String user, String space, boolean open, List 
roles, String templateMail) throws InvitationManagerException {
+    public boolean inviteUser(String user, String space, boolean open, List 
roles, String templateMail) throws InvitationManagerException {
         if (hasProgrammingRights()) {
-            getInvitationManager().inviteUser(user, space, open, roles, 
templateMail, context);
+            return getInvitationManager().inviteUser(user, space, open, roles, 
templateMail, context);
         }
+        return false;
     }
 
     /**
      * @param map A map of additional parameters for the invitation
      * @see #inviteUser(String, String, List, String)
      */
-    public void inviteUser(String user, String space, boolean open, List 
roles, String templateMail,
+    public boolean inviteUser(String user, String space, boolean open, List 
roles, String templateMail,
         Map map) throws InvitationManagerException {
         if (hasProgrammingRights()) {
-            getInvitationManager().inviteUser(user, space, open, roles, 
templateMail, map,
+            return getInvitationManager().inviteUser(user, space, open, roles, 
templateMail, map,
                 context);
         }
+        return false;
     }
 
     /**
+     * The current logged-in user verifies the invitation to join the 
specified space.
+     *
+     * @param space The space the user accepts to join
+     */
+    public boolean verifyInvitation(String space) throws 
InvitationManagerException {
+        return getInvitationManager().verifyInvitation(space, context);
+    }
+
+    /**
+     * The current logged-in user verifies the invitation to join the 
specified space, using an email
+     * address and a code.
+     *
+     * @param space The space the user accepts to join
+     * @param email The e-mail where the invitation was sent
+     * @param code The code of the invitation, when it was sent to a single 
person (e.g. the e-mail
+     *            address to which the invitation was sent is not a mailing 
list)
+     */
+    public boolean  verifyInvitation(String space, String email, String code) 
throws InvitationManagerException {
+        return getInvitationManager().verifyInvitation(space, email, code, 
context);
+    }
+
+    /**
      * The current logged-in user accepts the invitation to join the specified 
space.
      * 
      * @param space The space the user accepts to join
      */
-    public void acceptInvitation(String space) throws 
InvitationManagerException {
-        getInvitationManager().acceptInvitation(space, context);
+    public boolean acceptInvitation(String space) throws 
InvitationManagerException {
+        return getInvitationManager().acceptInvitation(space, context);
     }
 
     /**
@@ -386,8 +413,8 @@
      * @param code The code of the invitation, when it was sent to a single 
person (e.g. the e-mail
      *            address to which the invitation was sent is not a mailing 
list)
      */
-    public void acceptInvitation(String space, String email, String code) 
throws InvitationManagerException {
-        getInvitationManager().acceptInvitation(space, email, code, context);
+    public boolean acceptInvitation(String space, String email, String code) 
throws InvitationManagerException {
+        return getInvitationManager().acceptInvitation(space, email, code, 
context);
     }
 
     /**

_______________________________________________
notifications mailing list
notifications@xwiki.org
http://lists.xwiki.org/mailman/listinfo/notifications

Reply via email to