Author: ludovic Date: 2007-12-30 13:57:40 +0100 (Sun, 30 Dec 2007) New Revision: 6571
Modified: xwiki-products/curriki/trunk/plugins/spacemanager/src/main/java/org/xwiki/plugin/spacemanager/api/SpaceManager.java xwiki-products/curriki/trunk/plugins/spacemanager/src/main/java/org/xwiki/plugin/spacemanager/api/SpaceUserProfile.java xwiki-products/curriki/trunk/plugins/spacemanager/src/main/java/org/xwiki/plugin/spacemanager/impl/SpaceManagerImpl.java xwiki-products/curriki/trunk/plugins/spacemanager/src/main/java/org/xwiki/plugin/spacemanager/impl/SpaceUserProfileImpl.java xwiki-products/curriki/trunk/plugins/spacemanager/src/main/java/org/xwiki/plugin/spacemanager/plugin/SpaceManagerPluginApi.java Log: CURRIKI-1179 Updated space user profile apis Modified: xwiki-products/curriki/trunk/plugins/spacemanager/src/main/java/org/xwiki/plugin/spacemanager/api/SpaceManager.java =================================================================== --- xwiki-products/curriki/trunk/plugins/spacemanager/src/main/java/org/xwiki/plugin/spacemanager/api/SpaceManager.java 2007-12-29 18:58:03 UTC (rev 6570) +++ xwiki-products/curriki/trunk/plugins/spacemanager/src/main/java/org/xwiki/plugin/spacemanager/api/SpaceManager.java 2007-12-30 12:57:40 UTC (rev 6571) @@ -350,4 +350,12 @@ * @return int */ public int countSpaces(XWikiContext context) throws SpaceManagerException; + + /** + * Allows the current user to join the space + * @param spaceName + * @param context + * @return + */ + public boolean joinSpace(String spaceName, XWikiContext context) throws SpaceManagerException; } Modified: xwiki-products/curriki/trunk/plugins/spacemanager/src/main/java/org/xwiki/plugin/spacemanager/api/SpaceUserProfile.java =================================================================== --- xwiki-products/curriki/trunk/plugins/spacemanager/src/main/java/org/xwiki/plugin/spacemanager/api/SpaceUserProfile.java 2007-12-29 18:58:03 UTC (rev 6570) +++ xwiki-products/curriki/trunk/plugins/spacemanager/src/main/java/org/xwiki/plugin/spacemanager/api/SpaceUserProfile.java 2007-12-30 12:57:40 UTC (rev 6571) @@ -61,6 +61,12 @@ public void save() throws XWikiException; /** + * Saves changes made to the profile + * @throws XWikiException + */ + public void saveWithProgrammingRights() throws XWikiException; + + /** * Allows to retrieve a user property from the User page * @param propName * @return Modified: xwiki-products/curriki/trunk/plugins/spacemanager/src/main/java/org/xwiki/plugin/spacemanager/impl/SpaceManagerImpl.java =================================================================== --- xwiki-products/curriki/trunk/plugins/spacemanager/src/main/java/org/xwiki/plugin/spacemanager/impl/SpaceManagerImpl.java 2007-12-29 18:58:03 UTC (rev 6570) +++ xwiki-products/curriki/trunk/plugins/spacemanager/src/main/java/org/xwiki/plugin/spacemanager/impl/SpaceManagerImpl.java 2007-12-30 12:57:40 UTC (rev 6571) @@ -92,7 +92,7 @@ needsUpdate |= bclass.addTextField(SpaceImpl.SPACE_TYPE, "Group or plain space", 32); needsUpdate |= bclass.addTextField(SpaceImpl.SPACE_URLSHORTCUT, "URL Shortcut", 128); needsUpdate |= bclass.addStaticListField(SpaceImpl.SPACE_POLICY, "Membership Policy", 1, false, "open=Open membership|closed=Closed membership","radio"); - needsUpdate |= bclass.addStaticListField(SpaceImpl.SPACE_LANGUAGE, "Language", "eng=English|zho=Chinese|nld=Dutch|fra=French|deu=German|ita=Italian|jpn=Japanese|kor=Korean|por=Portuguese|rus=Russian|spa=Spanish"); + needsUpdate |= bclass.addStaticListField(SpaceImpl.SPACE_LANGUAGE, "Language", "en=English|zh=Chinese|nl=Dutch|fr=French|de=German|it=Italian|jp=Japanese|kr=Korean|po=Portuguese|ru=Russian|sp=Spanish"); String content = doc.getContent(); if ((content == null) || (content.equals(""))) { @@ -140,6 +140,7 @@ getSpaceManagerExtension().init(context); SpaceManagers.addSpaceManager(this); getSpaceClass(context); + SpaceUserProfileImpl.getSpaceUserProfileClass(context); } catch (Exception e) { e.printStackTrace(); } @@ -815,4 +816,18 @@ } } + public boolean joinSpace(String spaceName, XWikiContext context) throws SpaceManagerException { + try { + SpaceUserProfile userProfile = newUserSpaceProfile(context.getUser(), spaceName, context); + userProfile.updateProfileFromRequest(); + userProfile.saveWithProgrammingRights(); + addMember(spaceName, context.getUser(), context); + return true; + } catch (XWikiException e) { + throw new SpaceManagerException(e); + } + + + } + } Modified: xwiki-products/curriki/trunk/plugins/spacemanager/src/main/java/org/xwiki/plugin/spacemanager/impl/SpaceUserProfileImpl.java =================================================================== --- xwiki-products/curriki/trunk/plugins/spacemanager/src/main/java/org/xwiki/plugin/spacemanager/impl/SpaceUserProfileImpl.java 2007-12-29 18:58:03 UTC (rev 6570) +++ xwiki-products/curriki/trunk/plugins/spacemanager/src/main/java/org/xwiki/plugin/spacemanager/impl/SpaceUserProfileImpl.java 2007-12-30 12:57:40 UTC (rev 6571) @@ -6,6 +6,9 @@ import com.xpn.xwiki.doc.XWikiDocument; import com.xpn.xwiki.XWikiContext; import com.xpn.xwiki.XWikiException; +import com.xpn.xwiki.XWiki; +import com.xpn.xwiki.objects.classes.BaseClass; +import com.xpn.xwiki.objects.classes.BooleanClass; import com.xpn.xwiki.api.Document; /** @@ -17,6 +20,10 @@ */ public class SpaceUserProfileImpl extends Document implements SpaceUserProfile { private static final String SPACE_USER_PROFILE_CLASS_NAME = "XWiki.SpaceUserProfileClass"; + private static final String SPACE_USER_PROFILE_PROFILE = "profile"; + private static final String SPACE_USER_PROFILE_ALLOW_NOTIFICATIONS = "allowNotifications"; + private static final String SPACE_USER_PROFILE_ALLOW_NOTIFICATIONS_FROM_SELF = "allowNotificationsFromSelf"; + private String userName; private SpaceManager manager; private Document userDoc; @@ -28,9 +35,52 @@ this.userName = userName; String docName = manager.getSpaceUserProfilePageName(userName, spaceName); doc = context.getWiki().getDocument(docName, context); + if (doc.getObject(getSpaceUserProfileClassName())==null) + doc.newObject(getSpaceUserProfileClassName(), context); } - protected String getSpaceUserProfileClassName() { + /** + * + * @param context Xwiki context + * @return Returns the Space User Profile Class as defined by the extension + * @throws XWikiException + */ + protected static BaseClass getSpaceUserProfileClass(XWikiContext context) throws XWikiException { + XWikiDocument doc; + XWiki xwiki = context.getWiki(); + boolean needsUpdate = false; + + try { + doc = xwiki.getDocument(getSpaceUserProfileClassName(), context); + } catch (Exception e) { + doc = new XWikiDocument(); + doc.setFullName(getSpaceUserProfileClassName()); + needsUpdate = true; + } + + BaseClass bclass = doc.getxWikiClass(); + bclass.setName(getSpaceUserProfileClassName()); + + needsUpdate |= bclass.addTextAreaField(SPACE_USER_PROFILE_PROFILE, "Profile", 80, 7); + needsUpdate |= bclass.addBooleanField(SPACE_USER_PROFILE_ALLOW_NOTIFICATIONS, "Allow Notifications", "yesno"); + if (needsUpdate) + ((BooleanClass) bclass.getField(SPACE_USER_PROFILE_ALLOW_NOTIFICATIONS)).setDisplayType("checkbox"); + needsUpdate |= bclass.addBooleanField(SPACE_USER_PROFILE_ALLOW_NOTIFICATIONS_FROM_SELF, "Allow Notifications From Self", "yesno"); + if (needsUpdate) + ((BooleanClass) bclass.getField(SPACE_USER_PROFILE_ALLOW_NOTIFICATIONS_FROM_SELF)).setDisplayType("checkbox"); + + String content = doc.getContent(); + if ((content == null) || (content.equals(""))) { + needsUpdate = true; + doc.setContent("1 XWiki Space User Profile Class"); + } + + if (needsUpdate) + xwiki.saveDocument(doc, context); + return bclass; + } + + protected static String getSpaceUserProfileClassName() { return SPACE_USER_PROFILE_CLASS_NAME; } @@ -41,27 +91,27 @@ } public String getProfile() { - return doc.getStringValue(getSpaceUserProfileClassName(), "profile"); + return doc.getStringValue(getSpaceUserProfileClassName(), SPACE_USER_PROFILE_PROFILE); } public void setProfile(String profile) { - getDoc().setStringValue(getSpaceUserProfileClassName(), "profile", profile); + getDoc().setStringValue(getSpaceUserProfileClassName(), SPACE_USER_PROFILE_PROFILE, profile); } public boolean getAllowNotifications() { - return (doc.getIntValue(getSpaceUserProfileClassName(), "allowNotifications")==1); + return (doc.getIntValue(getSpaceUserProfileClassName(), SPACE_USER_PROFILE_ALLOW_NOTIFICATIONS)==1); } public boolean getAllowNotificationsFromSelf() { - return (doc.getIntValue(getSpaceUserProfileClassName(), "allowNotificationsFromSelf")==1); + return (doc.getIntValue(getSpaceUserProfileClassName(), SPACE_USER_PROFILE_ALLOW_NOTIFICATIONS_FROM_SELF)==1); } public void setAllowNotifications(boolean allowNotifications) { - getDoc().setIntValue(getSpaceUserProfileClassName(), "allowNotifications", allowNotifications ? 1 : 0); + getDoc().setIntValue(getSpaceUserProfileClassName(), SPACE_USER_PROFILE_ALLOW_NOTIFICATIONS, allowNotifications ? 1 : 0); } public void setAllowNotificationsFromSelf(boolean allowNotificationsFromSelf) { - getDoc().setIntValue(getSpaceUserProfileClassName(), "allowNotificationsFromSelf", allowNotificationsFromSelf ? 1 : 0); + getDoc().setIntValue(getSpaceUserProfileClassName(), SPACE_USER_PROFILE_ALLOW_NOTIFICATIONS_FROM_SELF, allowNotificationsFromSelf ? 1 : 0); } public void updateProfileFromRequest() throws SpaceManagerException { @@ -99,4 +149,5 @@ return ""; } } + } Modified: xwiki-products/curriki/trunk/plugins/spacemanager/src/main/java/org/xwiki/plugin/spacemanager/plugin/SpaceManagerPluginApi.java =================================================================== --- xwiki-products/curriki/trunk/plugins/spacemanager/src/main/java/org/xwiki/plugin/spacemanager/plugin/SpaceManagerPluginApi.java 2007-12-29 18:58:03 UTC (rev 6570) +++ xwiki-products/curriki/trunk/plugins/spacemanager/src/main/java/org/xwiki/plugin/spacemanager/plugin/SpaceManagerPluginApi.java 2007-12-30 12:57:40 UTC (rev 6571) @@ -308,8 +308,7 @@ public boolean joinSpace(String spaceName) throws SpaceManagerException { Space space = getSpace(spaceName); if ("open".equals(space.getPolicy())) { - getSpaceManager().addMember(spaceName, context.getUser(), context); - return true; + return getSpaceManager().joinSpace(spaceName, context); } else { return false; } _______________________________________________ notifications mailing list notifications@xwiki.org http://lists.xwiki.org/mailman/listinfo/notifications