use of com.xpn.xwiki.doc.XWikiDocument in project xwiki-platform by xwiki.
the class DefaultRatingsConfigurationTest method getWikiConfigurationDocument.
@Test
public void getWikiConfigurationDocument() throws Exception {
DocumentReference documentReference = new DocumentReference("wiki", "Space", "Page");
XWikiDocument wikiConfigurationDocument = mock(XWikiDocument.class, "Wiki Configuration Document");
when(xcontext.getWiki().getDocument(RatingsManager.RATINGS_CONFIG_GLOBAL_REFERENCE, xcontext)).thenReturn(wikiConfigurationDocument);
assertEquals(wikiConfigurationDocument, mocker.getComponentUnderTest().getConfigurationDocument(documentReference));
}
use of com.xpn.xwiki.doc.XWikiDocument in project xwiki-platform by xwiki.
the class DefaultRatingsConfigurationTest method getConfigurationParameterDefaultValue.
@Test
public void getConfigurationParameterDefaultValue() throws Exception {
DocumentReference documentReference = new DocumentReference("wiki", Arrays.asList("Space1", "Space2"), "Page");
XWikiDocument spaceConfigurationDocument = mock(XWikiDocument.class, "Space Configuration Document");
DocumentReference configurationDocumentReference = new DocumentReference("wiki", "Space1", "WebPreferences");
when(xcontext.getWiki().getDocument((EntityReference) configurationDocumentReference, xcontext)).thenReturn(spaceConfigurationDocument);
assertEquals("1", mocker.getComponentUnderTest().getConfigurationParameter(documentReference, "displayRatings", "1"));
}
use of com.xpn.xwiki.doc.XWikiDocument in project xwiki-platform by xwiki.
the class DefaultRatingsConfigurationTest method getConfigurationParameter.
@Test
public void getConfigurationParameter() throws Exception {
DocumentReference documentReference = new DocumentReference("wiki", Arrays.asList("Space1", "Space2"), "Page");
XWikiDocument spaceConfigurationDocument = mock(XWikiDocument.class, "Space Configuration Document");
DocumentReference configurationDocumentReference = new DocumentReference("wiki", "Space1", "WebPreferences");
when(xcontext.getWiki().getDocument((EntityReference) configurationDocumentReference, xcontext)).thenReturn(spaceConfigurationDocument);
BaseObject configurationObject = mock(BaseObject.class);
when(spaceConfigurationDocument.getXObject(RatingsManager.RATINGS_CONFIG_CLASSREFERENCE)).thenReturn(configurationObject);
BaseProperty displayRatings = mock(BaseProperty.class);
when(configurationObject.get("displayRatings")).thenReturn(displayRatings);
when(displayRatings.getValue()).thenReturn("1");
assertEquals("1", mocker.getComponentUnderTest().getConfigurationParameter(documentReference, "displayRatings", "1"));
}
use of com.xpn.xwiki.doc.XWikiDocument in project xwiki-platform by xwiki.
the class ConfiguredReputationAlgorithmProvider method get.
/**
* Retrieve an instance of the desired ReputationAlorithm (default/simple/custom).
*
* @param documentRef documentRef the document to which the ratings are associated to
* @return the reputation algorithm selected by looking at the current configuration settings
*/
@Override
public ReputationAlgorithm get(DocumentReference documentRef) {
String defaultAlgorithmHint = "default";
String reputationAlgorithmHint = getXWiki().Param(RatingsManager.RATINGS_CONFIG_PARAM_PREFIX + RatingsManager.RATINGS_CONFIG_FIELDNAME_REPUTATIONALGORITHM_HINT, defaultAlgorithmHint);
try {
XWikiDocument configurationDocument = ratingsConfiguration.getConfigurationDocument(documentRef);
if (configurationDocument != null && !configurationDocument.isNew() && configurationDocument.getXObject(RatingsManager.RATINGS_CONFIG_CLASSREFERENCE) != null) {
BaseProperty prop = (BaseProperty) configurationDocument.getXObject(RatingsManager.RATINGS_CONFIG_CLASSREFERENCE).get(RatingsManager.RATINGS_CONFIG_CLASS_FIELDNAME_REPUTATION_ALGORITHM_HINT);
String hint = (prop == null) ? null : (String) prop.getValue();
if (hint == "custom") {
prop = (BaseProperty) configurationDocument.getXObject(RatingsManager.RATINGS_CONFIG_CLASSREFERENCE).get(RatingsManager.RATINGS_CONFIG_CLASS_FIELDNAME_REPUTATION_CUSTOM_ALGORITHM);
hint = (prop == null) ? null : (String) prop.getValue();
}
reputationAlgorithmHint = (hint == null) ? reputationAlgorithmHint : hint;
}
} catch (Exception e) {
logger.error("Cannot read reputation algorithm config", e);
}
// if the reputation algorithm hint is a page let's try to get the instance from groovy
if (reputationAlgorithmHint.contains(".")) {
try {
ReputationAlgorithmGroovy reputationInstance = (ReputationAlgorithmGroovy) getXWiki().parseGroovyFromPage(reputationAlgorithmHint, getXWikiContext());
if (reputationInstance != null) {
reputationInstance.setComponentManager(componentManager);
reputationInstance.setExecution(execution);
reputationInstance.setXWikiContext(getXWikiContext());
reputationInstance.setRatingsManager(ratingsManagerProvider.get(documentRef));
return reputationInstance;
}
} catch (Throwable e) {
logger.error("Cannot instanciate Reputation algorithm from page " + reputationAlgorithmHint, e);
}
}
try {
return componentManager.getInstance(ReputationAlgorithm.class, reputationAlgorithmHint);
} catch (ComponentLookupException e) {
// TODO Auto-generated catch block
logger.error("Error loading ratings manager component for hint " + reputationAlgorithmHint, e);
try {
return componentManager.getInstance(ReputationAlgorithm.class, defaultAlgorithmHint);
} catch (ComponentLookupException e1) {
return null;
}
}
}
use of com.xpn.xwiki.doc.XWikiDocument in project xwiki-platform by xwiki.
the class ExtensionUpdaterListener method onEvent.
@Override
public void onEvent(Event event, Object source, Object data) {
XWikiDocument document = (XWikiDocument) source;
BaseObject extensionObject = document.getXObject(XWikiRepositoryModel.EXTENSION_CLASSREFERENCE);
if (extensionObject != null) {
try {
this.repositoryManagerProvider.get().validateExtension(document, false);
} catch (XWikiException e) {
this.logger.error("Failed to validate extension in document [{}]", document.getDocumentReference(), e);
}
}
}
Aggregations