| 1 |
|
|
| 2 |
|
|
| 3 |
|
|
| 4 |
|
|
| 5 |
|
|
| 6 |
|
|
| 7 |
|
|
| 8 |
|
|
| 9 |
|
|
| 10 |
|
|
| 11 |
|
|
| 12 |
|
|
| 13 |
|
|
| 14 |
|
|
| 15 |
|
|
| 16 |
|
|
| 17 |
|
|
| 18 |
|
|
| 19 |
|
|
| 20 |
|
package org.xwiki.ratings.internal; |
| 21 |
|
|
| 22 |
|
import javax.inject.Inject; |
| 23 |
|
import javax.inject.Provider; |
| 24 |
|
import javax.inject.Singleton; |
| 25 |
|
|
| 26 |
|
import org.slf4j.Logger; |
| 27 |
|
import org.xwiki.component.annotation.Component; |
| 28 |
|
import org.xwiki.model.EntityType; |
| 29 |
|
import org.xwiki.model.reference.DocumentReference; |
| 30 |
|
import org.xwiki.model.reference.EntityReference; |
| 31 |
|
import org.xwiki.model.reference.SpaceReference; |
| 32 |
|
import org.xwiki.ratings.RatingsConfiguration; |
| 33 |
|
import org.xwiki.ratings.RatingsManager; |
| 34 |
|
import org.xwiki.stability.Unstable; |
| 35 |
|
|
| 36 |
|
import com.xpn.xwiki.XWikiContext; |
| 37 |
|
import com.xpn.xwiki.XWikiException; |
| 38 |
|
import com.xpn.xwiki.doc.XWikiDocument; |
| 39 |
|
import com.xpn.xwiki.objects.BaseProperty; |
| 40 |
|
|
| 41 |
|
|
| 42 |
|
|
| 43 |
|
|
| 44 |
|
@see |
| 45 |
|
@version |
| 46 |
|
@since |
| 47 |
|
|
| 48 |
|
@Component |
| 49 |
|
@Singleton |
| 50 |
|
@Unstable |
| |
|
| 82.5% |
Uncovered Elements: 7 (40) |
Complexity: 14 |
Complexity Density: 0.56 |
|
| 51 |
|
public class DefaultRatingsConfiguration implements RatingsConfiguration |
| 52 |
|
{ |
| 53 |
|
@Inject |
| 54 |
|
private Logger logger; |
| 55 |
|
|
| 56 |
|
@Inject |
| 57 |
|
private Provider<XWikiContext> xcontextProvider; |
| 58 |
|
|
| 59 |
|
|
| 60 |
|
|
| 61 |
|
|
| 62 |
|
@param |
| 63 |
|
@return |
| 64 |
|
|
| |
|
| 60% |
Uncovered Elements: 2 (5) |
Complexity: 2 |
Complexity Density: 0.4 |
|
| 65 |
227 |
public XWikiDocument getDocument(EntityReference reference)... |
| 66 |
|
{ |
| 67 |
227 |
XWikiContext context = xcontextProvider.get(); |
| 68 |
227 |
try |
| 69 |
|
{ |
| 70 |
227 |
return context.getWiki().getDocument(reference, context); |
| 71 |
|
} catch (XWikiException e) { |
| 72 |
0 |
logger.error("Failed to retrieve the document for the reference [{}].", reference, e); |
| 73 |
0 |
return null; |
| 74 |
|
} |
| 75 |
|
} |
| 76 |
|
|
| 77 |
|
|
| 78 |
|
|
| 79 |
|
|
| 80 |
|
@param |
| 81 |
|
@return |
| 82 |
|
|
| |
|
| 94.1% |
Uncovered Elements: 1 (17) |
Complexity: 5 |
Complexity Density: 0.45 |
|
| 83 |
117 |
public XWikiDocument getConfigurationDocument(DocumentReference documentReference)... |
| 84 |
|
{ |
| 85 |
117 |
SpaceReference lastSpaceReference = documentReference.getLastSpaceReference(); |
| 86 |
206 |
while (lastSpaceReference.getType() == EntityType.SPACE) { |
| 87 |
206 |
DocumentReference configurationDocumentReference = |
| 88 |
|
new DocumentReference(RatingsManager.RATINGS_CONFIG_SPACE_PAGE, lastSpaceReference); |
| 89 |
206 |
XWikiDocument spaceConfigurationDocument = getDocument((EntityReference) configurationDocumentReference); |
| 90 |
206 |
if (spaceConfigurationDocument != null |
| 91 |
|
&& spaceConfigurationDocument.getXObject(RatingsManager.RATINGS_CONFIG_CLASSREFERENCE) != null) { |
| 92 |
96 |
return spaceConfigurationDocument; |
| 93 |
|
} |
| 94 |
110 |
if (lastSpaceReference.getParent().getType() == EntityType.SPACE) { |
| 95 |
89 |
lastSpaceReference = new SpaceReference(lastSpaceReference.getParent()); |
| 96 |
|
} else { |
| 97 |
21 |
break; |
| 98 |
|
} |
| 99 |
|
} |
| 100 |
21 |
XWikiDocument globalConfigurationDocument = getDocument(RatingsManager.RATINGS_CONFIG_GLOBAL_REFERENCE); |
| 101 |
21 |
return globalConfigurationDocument; |
| 102 |
|
} |
| 103 |
|
|
| 104 |
|
|
| 105 |
|
|
| 106 |
|
|
| 107 |
|
|
| 108 |
|
@param |
| 109 |
|
@param |
| 110 |
|
@param |
| 111 |
|
@return |
| 112 |
|
|
| |
|
| 73.3% |
Uncovered Elements: 4 (15) |
Complexity: 7 |
Complexity Density: 0.78 |
|
| 113 |
70 |
public String getConfigurationParameter(DocumentReference documentReference, String parameterName, ... |
| 114 |
|
String defaultValue) |
| 115 |
|
{ |
| 116 |
70 |
XWikiDocument configurationDocument = getConfigurationDocument(documentReference); |
| 117 |
70 |
if (configurationDocument != null && !configurationDocument.isNew() |
| 118 |
|
&& configurationDocument.getXObject(RatingsManager.RATINGS_CONFIG_CLASSREFERENCE) != null) { |
| 119 |
69 |
try |
| 120 |
|
{ |
| 121 |
69 |
BaseProperty prop = (BaseProperty) configurationDocument. |
| 122 |
|
getXObject(RatingsManager.RATINGS_CONFIG_CLASSREFERENCE).get(parameterName); |
| 123 |
69 |
String propValue = (prop == null) ? defaultValue : prop.getValue().toString(); |
| 124 |
69 |
return (propValue.equals("") ? defaultValue : propValue); |
| 125 |
|
} catch (XWikiException e) { |
| 126 |
0 |
logger.error("Failed to retrieve the property for the configurationDocument [{}].", |
| 127 |
|
configurationDocument, e); |
| 128 |
0 |
return null; |
| 129 |
|
} |
| 130 |
|
} |
| 131 |
1 |
return defaultValue; |
| 132 |
|
} |
| 133 |
|
} |