1. Project Clover database Tue Dec 20 2016 21:24:09 CET
  2. Package org.xwiki.wiki.user.internal

File WikiUserClassDocumentInitializer.java

 

Coverage histogram

../../../../../img/srcFileCovDistChart9.png
38% of files have more coverage

Code metrics

4
12
2
1
147
58
4
0.33
6
2
2

Classes

Class Line # Actions
WikiUserClassDocumentInitializer 44 12 0% 4 2
0.888888988.9%
 

Contributing tests

No tests hitting this source file were found.

Source view

1    /*
2    * See the NOTICE file distributed with this work for additional
3    * information regarding copyright ownership.
4    *
5    * This is free software; you can redistribute it and/or modify it
6    * under the terms of the GNU Lesser General Public License as
7    * published by the Free Software Foundation; either version 2.1 of
8    * the License, or (at your option) any later version.
9    *
10    * This software is distributed in the hope that it will be useful,
11    * but WITHOUT ANY WARRANTY; without even the implied warranty of
12    * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13    * Lesser General Public License for more details.
14    *
15    * You should have received a copy of the GNU Lesser General Public
16    * License along with this software; if not, write to the Free
17    * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
18    * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
19    */
20    package org.xwiki.wiki.user.internal;
21   
22    import javax.inject.Named;
23    import javax.inject.Singleton;
24   
25    import org.xwiki.component.annotation.Component;
26    import org.xwiki.model.EntityType;
27    import org.xwiki.model.reference.EntityReference;
28    import org.xwiki.wiki.user.MembershipType;
29    import org.xwiki.wiki.user.UserScope;
30   
31    import com.xpn.xwiki.doc.XWikiDocument;
32    import com.xpn.xwiki.internal.mandatory.AbstractMandatoryDocumentInitializer;
33    import com.xpn.xwiki.objects.classes.BaseClass;
34   
35    /**
36    * Update the WikiManager.WikiUserClass document with all required information.
37    *
38    * @since 5.3M2
39    * @version $Id: 366380780d641638a2cee100ddb35f9b09943938 $
40    */
41    @Component
42    @Named("WikiManager.WikiUserClass")
43    @Singleton
 
44    public class WikiUserClassDocumentInitializer extends AbstractMandatoryDocumentInitializer
45    {
46    /**
47    * The name of the mandatory document.
48    */
49    public static final String DOCUMENT_NAME = "WikiUserClass";
50   
51    /**
52    * The space of the mandatory document.
53    */
54    public static final String DOCUMENT_SPACE = "WikiManager";
55   
56    /**
57    * Reference to the server class.
58    */
59    public static final EntityReference CONFIGURATION_CLASS = new EntityReference(DOCUMENT_NAME, EntityType.DOCUMENT,
60    new EntityReference(DOCUMENT_SPACE, EntityType.SPACE));
61   
62    /**
63    * Default list separators of WikiManager.XWikiServerClass fields.
64    */
65    public static final String DEFAULT_FIELDS_SEPARATOR = "|";
66   
67    /**
68    * Name of field <code>membershipType</code> for the XWiki class WikiManager.WikiUserClass.
69    */
70    public static final String FIELD_MEMBERSHIPTYPE = "membershipType";
71   
72    /**
73    * Pretty name of field <code>membershipType</code> for the XWiki class WikiManager.WikiUserClass.
74    */
75    public static final String FIELDPN_MEMBERSHIPTYPE = "Membership Type";
76   
77    /**
78    * List of possible values for <code>membershipType</code> for the XWiki class WikiManager.WikiUserClass.
79    */
80    public static final String FIELDL_MEMBERSHIPTYPE = MembershipType.OPEN.name().toLowerCase()
81    + DEFAULT_FIELDS_SEPARATOR + MembershipType.REQUEST.name().toLowerCase() + DEFAULT_FIELDS_SEPARATOR
82    + MembershipType.INVITE.name().toLowerCase();
83   
84    /**
85    * Display type of field <code>membershipType</code> for the XWiki class WikiManager.WikiUserClass.
86    */
87    public static final String FIELDDT_MEMBERSHIPTYPE = "radio";
88   
89    /**
90    * Name of field <code>userScope</code> for the XWiki class WikiManager.WikiUserClass.
91    */
92    public static final String FIELD_USERSCOPE = "userScope";
93   
94    /**
95    * Pretty name of field <code>userScope</code> for the XWiki class WikiManager.WikiUserClass.
96    */
97    public static final String FIELDPN_USERSCOPE = "User scope";
98   
99    /**
100    * Display type of field <code>userScope</code> for the XWiki class WikiManager.WikiUserClass.
101    */
102    public static final String FIELDDT_USERSCOPE = FIELDDT_MEMBERSHIPTYPE;
103   
104    /**
105    * List of possible values for <code>userScope</code> for the XWiki class WikiManager.WikiUserClass.
106    */
107    public static final String FIELDL_USERSCOPE = UserScope.GLOBAL_ONLY.name().toLowerCase()
108    + DEFAULT_FIELDS_SEPARATOR + UserScope.LOCAL_ONLY.name().toLowerCase() + DEFAULT_FIELDS_SEPARATOR
109    + UserScope.LOCAL_AND_GLOBAL.name().toLowerCase();
110   
111    /**
112    * Constructor.
113    */
 
114  2 toggle public WikiUserClassDocumentInitializer()
115    {
116  2 super(DOCUMENT_SPACE, DOCUMENT_NAME);
117    }
118   
 
119  6 toggle @Override
120    public boolean updateDocument(XWikiDocument document)
121    {
122  6 boolean needsUpdate = false;
123   
124    // Add missing class fields
125  6 BaseClass baseClass = document.getXClass();
126   
127  6 needsUpdate |= baseClass.addStaticListField(FIELD_MEMBERSHIPTYPE, FIELDPN_MEMBERSHIPTYPE,
128    MembershipType.values().length, false, FIELDL_MEMBERSHIPTYPE, FIELDDT_MEMBERSHIPTYPE);
129  6 needsUpdate |= baseClass.addStaticListField(FIELD_USERSCOPE, FIELDPN_USERSCOPE,
130    UserScope.values().length, false, FIELDL_USERSCOPE, FIELDDT_USERSCOPE);
131   
132    // Check if the document is hidden
133  6 if (!document.isHidden()) {
134  6 document.setHidden(true);
135  6 needsUpdate = true;
136    }
137   
138    // Mark this document as Wiki Class.
139  6 if (document.isNew()) {
140  6 needsUpdate |= setClassDocumentFields(document, "Wiki User Class");
141  6 document.setContent(document.getContent() + "\n\nClass that represents the wiki configuration"
142    + " about users.");
143    }
144   
145  6 return needsUpdate;
146    }
147    }