1. Project Clover database Tue Dec 20 2016 21:24:09 CET
  2. Package com.xpn.xwiki.internal.mandatory

File AbstractRightsDocumentInitializer.java

 

Coverage histogram

../../../../../img/srcFileCovDistChart7.png
64% of files have more coverage

Code metrics

10
28
2
1
92
54
11
0.39
14
2
5.5

Classes

Class Line # Actions
AbstractRightsDocumentInitializer 40 28 0% 11 12
0.770%
 

Contributing tests

This file is covered by 2 tests. .

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 com.xpn.xwiki.internal.mandatory;
21   
22    import org.xwiki.model.EntityType;
23    import org.xwiki.model.reference.EntityReference;
24   
25    import com.xpn.xwiki.doc.XWikiDocument;
26    import com.xpn.xwiki.objects.PropertyInterface;
27    import com.xpn.xwiki.objects.classes.BaseClass;
28    import com.xpn.xwiki.objects.classes.BooleanClass;
29    import com.xpn.xwiki.objects.classes.GroupsClass;
30    import com.xpn.xwiki.objects.classes.LevelsClass;
31    import com.xpn.xwiki.objects.classes.NumberClass;
32    import com.xpn.xwiki.objects.classes.UsersClass;
33   
34    /**
35    * XWiki.XWikiPreferences class.
36    *
37    * @version $Id: dca94924b6e1101abbad3576f9ac77dbe045b5a8 $
38    * @since 4.3M1
39    */
 
40    public abstract class AbstractRightsDocumentInitializer extends AbstractMandatoryDocumentInitializer
41    {
42    /**
43    * @param pageName the document name of the rights class
44    */
 
45  122 toggle public AbstractRightsDocumentInitializer(String pageName)
46    {
47  122 super(new EntityReference(pageName, EntityType.DOCUMENT, new EntityReference("XWiki", EntityType.SPACE)));
48    }
49   
 
50  216 toggle @Override
51    public boolean updateDocument(XWikiDocument document)
52    {
53  216 boolean needsUpdate = false;
54   
55  216 BaseClass bclass = document.getXClass();
56   
57  216 PropertyInterface groupsProp = bclass.get("groups");
58  216 if ((groupsProp != null) && !(groupsProp instanceof GroupsClass)) {
59  0 bclass.removeField("groups");
60  0 needsUpdate = true;
61    }
62  216 needsUpdate |= bclass.addGroupsField("groups", "Groups");
63   
64  216 PropertyInterface levelsProp = bclass.get("levels");
65  216 if ((levelsProp != null) && !(levelsProp instanceof LevelsClass)) {
66  0 bclass.removeField("levels");
67  0 needsUpdate = true;
68    }
69  216 needsUpdate |= bclass.addLevelsField("levels", "Levels");
70   
71  216 PropertyInterface usersProp = bclass.get("users");
72  216 if ((usersProp != null) && !(usersProp instanceof UsersClass)) {
73  0 bclass.removeField("users");
74  0 needsUpdate = true;
75    }
76  216 needsUpdate |= bclass.addUsersField("users", "Users");
77   
78  216 PropertyInterface allowProp = bclass.get("allow");
79  216 if ((allowProp != null) && (allowProp instanceof NumberClass)) {
80  0 bclass.removeField("allow");
81  0 needsUpdate = true;
82    }
83  216 needsUpdate |= bclass.addBooleanField("allow", "Allow/Deny", "allow");
84  216 BooleanClass afield = (BooleanClass) bclass.get("allow");
85  216 if (afield.getDefaultValue() != 1) {
86  78 afield.setDefaultValue(1);
87  78 needsUpdate = true;
88    }
89   
90  216 return needsUpdate;
91    }
92    }