| 1 |
|
|
| 2 |
|
|
| 3 |
|
|
| 4 |
|
|
| 5 |
|
|
| 6 |
|
|
| 7 |
|
|
| 8 |
|
|
| 9 |
|
|
| 10 |
|
|
| 11 |
|
|
| 12 |
|
|
| 13 |
|
|
| 14 |
|
|
| 15 |
|
|
| 16 |
|
|
| 17 |
|
|
| 18 |
|
|
| 19 |
|
|
| 20 |
|
package com.xpn.xwiki.internal.mandatory; |
| 21 |
|
|
| 22 |
|
import javax.inject.Inject; |
| 23 |
|
import javax.inject.Named; |
| 24 |
|
|
| 25 |
|
import org.apache.commons.lang3.StringUtils; |
| 26 |
|
import org.xwiki.model.EntityType; |
| 27 |
|
import org.xwiki.model.reference.DocumentReference; |
| 28 |
|
import org.xwiki.model.reference.DocumentReferenceResolver; |
| 29 |
|
import org.xwiki.model.reference.EntityReference; |
| 30 |
|
import org.xwiki.model.reference.LocalDocumentReference; |
| 31 |
|
import org.xwiki.model.reference.WikiReference; |
| 32 |
|
import org.xwiki.sheet.SheetBinder; |
| 33 |
|
import org.xwiki.wiki.descriptor.WikiDescriptorManager; |
| 34 |
|
|
| 35 |
|
import com.xpn.xwiki.XWiki; |
| 36 |
|
import com.xpn.xwiki.doc.MandatoryDocumentInitializer; |
| 37 |
|
import com.xpn.xwiki.doc.XWikiDocument; |
| 38 |
|
import com.xpn.xwiki.objects.classes.BaseClass; |
| 39 |
|
import com.xpn.xwiki.objects.classes.BooleanClass; |
| 40 |
|
import com.xpn.xwiki.user.api.XWikiRightService; |
| 41 |
|
|
| 42 |
|
|
| 43 |
|
|
| 44 |
|
|
| 45 |
|
@version |
| 46 |
|
@since |
| 47 |
|
|
| |
|
| 96.2% |
Uncovered Elements: 3 (80) |
Complexity: 22 |
Complexity Density: 0.46 |
|
| 48 |
|
public abstract class AbstractMandatoryDocumentInitializer implements MandatoryDocumentInitializer |
| 49 |
|
{ |
| 50 |
|
|
| 51 |
|
|
| 52 |
|
|
| 53 |
|
@Inject |
| 54 |
|
@Named("document") |
| 55 |
|
protected SheetBinder documentSheetBinder; |
| 56 |
|
|
| 57 |
|
|
| 58 |
|
|
| 59 |
|
|
| 60 |
|
@Inject |
| 61 |
|
protected WikiDescriptorManager wikiDescriptorManager; |
| 62 |
|
|
| 63 |
|
@Inject |
| 64 |
|
protected DocumentReferenceResolver<EntityReference> resolver; |
| 65 |
|
|
| 66 |
|
|
| 67 |
|
@see |
| 68 |
|
|
| 69 |
|
private EntityReference reference; |
| 70 |
|
|
| 71 |
|
|
| 72 |
|
@param |
| 73 |
|
|
| 74 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 75 |
1339 |
public AbstractMandatoryDocumentInitializer(EntityReference reference)... |
| 76 |
|
{ |
| 77 |
1339 |
this.reference = reference; |
| 78 |
|
} |
| 79 |
|
|
| 80 |
|
|
| 81 |
|
@param |
| 82 |
|
@param |
| 83 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 84 |
852 |
public AbstractMandatoryDocumentInitializer(String spaceName, String documentName)... |
| 85 |
|
{ |
| 86 |
852 |
this(new EntityReference(documentName, EntityType.DOCUMENT, new EntityReference(spaceName, EntityType.SPACE))); |
| 87 |
|
} |
| 88 |
|
|
| |
|
| 90% |
Uncovered Elements: 1 (10) |
Complexity: 5 |
Complexity Density: 0.83 |
|
| 89 |
2092 |
@Override... |
| 90 |
|
public EntityReference getDocumentReference() |
| 91 |
|
{ |
| 92 |
|
|
| 93 |
2092 |
if (this.reference != null && this.reference.extractReference(EntityType.WIKI) == null && isMainWikiOnly()) { |
| 94 |
125 |
synchronized (this) { |
| 95 |
125 |
if (this.reference.extractReference(EntityType.WIKI) == null) { |
| 96 |
|
|
| 97 |
125 |
EntityReference mainWikiEntityReference = |
| 98 |
|
this.resolver.resolve(this.reference, |
| 99 |
|
new WikiReference(this.wikiDescriptorManager.getMainWikiId())); |
| 100 |
|
|
| 101 |
125 |
this.reference = mainWikiEntityReference; |
| 102 |
|
} |
| 103 |
|
} |
| 104 |
|
} |
| 105 |
|
|
| 106 |
2092 |
return this.reference; |
| 107 |
|
} |
| 108 |
|
|
| 109 |
|
|
| 110 |
|
@return |
| 111 |
|
|
| 112 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 113 |
1862 |
protected boolean isMainWikiOnly()... |
| 114 |
|
{ |
| 115 |
1862 |
return false; |
| 116 |
|
} |
| 117 |
|
|
| 118 |
|
|
| 119 |
|
|
| 120 |
|
|
| 121 |
|
|
| 122 |
|
|
| 123 |
|
@param |
| 124 |
|
@param |
| 125 |
|
@return |
| 126 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (14) |
Complexity: 3 |
Complexity Density: 0.3 |
|
| 127 |
1893 |
protected boolean setClassDocumentFields(XWikiDocument document, String title)... |
| 128 |
|
{ |
| 129 |
1893 |
boolean needsUpdate = false; |
| 130 |
|
|
| 131 |
|
|
| 132 |
1893 |
if (document.getParentReference() == null) { |
| 133 |
789 |
needsUpdate = true; |
| 134 |
789 |
document.setParentReference(new LocalDocumentReference(XWiki.SYSTEM_SPACE, "XWikiClasses")); |
| 135 |
|
} |
| 136 |
|
|
| 137 |
1893 |
needsUpdate |= setDocumentFields(document, title); |
| 138 |
|
|
| 139 |
|
|
| 140 |
1893 |
if (this.documentSheetBinder.getSheets(document).isEmpty()) { |
| 141 |
750 |
String wikiName = document.getDocumentReference().getWikiReference().getName(); |
| 142 |
750 |
DocumentReference sheet = new DocumentReference(wikiName, XWiki.SYSTEM_SPACE, "ClassSheet"); |
| 143 |
750 |
needsUpdate |= this.documentSheetBinder.bind(document, sheet); |
| 144 |
|
} |
| 145 |
|
|
| 146 |
1893 |
return needsUpdate; |
| 147 |
|
} |
| 148 |
|
|
| 149 |
|
|
| 150 |
|
|
| 151 |
|
|
| 152 |
|
|
| 153 |
|
|
| 154 |
|
@param |
| 155 |
|
@param |
| 156 |
|
@return |
| 157 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (30) |
Complexity: 6 |
Complexity Density: 0.3 |
|
| 158 |
1984 |
protected boolean setDocumentFields(XWikiDocument document, String title)... |
| 159 |
|
{ |
| 160 |
1984 |
boolean needsUpdate = false; |
| 161 |
|
|
| 162 |
1984 |
if (document.getCreatorReference() == null) { |
| 163 |
826 |
needsUpdate = true; |
| 164 |
826 |
document.setCreator(XWikiRightService.SUPERADMIN_USER); |
| 165 |
|
} |
| 166 |
1984 |
if (document.getAuthorReference() == null) { |
| 167 |
826 |
needsUpdate = true; |
| 168 |
826 |
document.setAuthorReference(document.getCreatorReference()); |
| 169 |
|
} |
| 170 |
|
|
| 171 |
1984 |
if (document.getParentReference() == null) { |
| 172 |
37 |
needsUpdate = true; |
| 173 |
|
|
| 174 |
37 |
EntityReference spaceReference = getDocumentReference().extractReference(EntityType.SPACE); |
| 175 |
37 |
DocumentReference fullReference = this.resolver.resolve(null, spaceReference); |
| 176 |
37 |
EntityReference localReference = new LocalDocumentReference(fullReference); |
| 177 |
37 |
document.setParentReference(localReference); |
| 178 |
|
} |
| 179 |
|
|
| 180 |
1984 |
if (StringUtils.isBlank(document.getTitle())) { |
| 181 |
880 |
needsUpdate = true; |
| 182 |
880 |
document.setTitle(title); |
| 183 |
|
} |
| 184 |
|
|
| 185 |
1984 |
if (!document.isHidden()) { |
| 186 |
813 |
needsUpdate = true; |
| 187 |
813 |
document.setHidden(true); |
| 188 |
|
} |
| 189 |
|
|
| 190 |
1984 |
return needsUpdate; |
| 191 |
|
} |
| 192 |
|
|
| 193 |
|
|
| 194 |
|
|
| 195 |
|
|
| 196 |
|
@param |
| 197 |
|
@param |
| 198 |
|
@param |
| 199 |
|
@return |
| 200 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (10) |
Complexity: 2 |
Complexity Density: 0.25 |
|
| 201 |
89 |
protected boolean updateBooleanClassDefaultValue(BaseClass baseClass, String fieldName, Boolean value)... |
| 202 |
|
{ |
| 203 |
89 |
boolean needsUpdate = false; |
| 204 |
|
|
| 205 |
89 |
BooleanClass bc = (BooleanClass) baseClass.get(fieldName); |
| 206 |
|
|
| 207 |
89 |
int old = bc.getDefaultValue(); |
| 208 |
89 |
int intvalue = intFromBoolean(value); |
| 209 |
|
|
| 210 |
89 |
if (intvalue != old) { |
| 211 |
35 |
bc.setDefaultValue(intvalue); |
| 212 |
35 |
needsUpdate = true; |
| 213 |
|
} |
| 214 |
|
|
| 215 |
89 |
return needsUpdate; |
| 216 |
|
} |
| 217 |
|
|
| 218 |
|
|
| 219 |
|
@param@link |
| 220 |
|
@return |
| 221 |
|
|
| |
|
| 60% |
Uncovered Elements: 2 (5) |
Complexity: 3 |
Complexity Density: 3 |
|
| 222 |
89 |
protected int intFromBoolean(Boolean value)... |
| 223 |
|
{ |
| 224 |
89 |
return value == null ? -1 : (value.booleanValue() ? 1 : 0); |
| 225 |
|
} |
| 226 |
|
} |