use of org.xwiki.wiki.properties.WikiPropertyGroupException in project xwiki-platform by xwiki.
the class DefaultWikiTemplateManager method setTemplate.
@Override
public void setTemplate(String wikiId, boolean value) throws WikiTemplateManagerException {
try {
// Get the descriptor
WikiDescriptor descriptor = wikiDescriptorManager.getById(wikiId);
// Get the property group
WikiTemplatePropertyGroup group = (WikiTemplatePropertyGroup) descriptor.getPropertyGroup(WikiTemplatePropertyGroupProvider.GROUP_NAME);
// Set the value
group.setTemplate(value);
// Save the property groups
templateWikiPropertyGroupProvider.save(group, wikiId);
} catch (WikiPropertyGroupException e) {
throw new WikiTemplateManagerException(String.format("Failed to save the property group [%s]", WikiTemplatePropertyGroupProvider.GROUP_NAME), e);
} catch (WikiManagerException e) {
throw new WikiTemplateManagerException(String.format(errorMessageNoDescriptor, wikiId), e);
}
}
use of org.xwiki.wiki.properties.WikiPropertyGroupException in project xwiki-platform by xwiki.
the class WikiTemplatePropertyGroupProvider method save.
@Override
public void save(WikiPropertyGroup group, String wikiId) throws WikiPropertyGroupException {
XWikiContext context = xcontextProvider.get();
XWiki xwiki = context.getWiki();
WikiTemplatePropertyGroup templateGroup = (WikiTemplatePropertyGroup) group;
try {
XWikiDocument descriptorDocument = wikiDescriptorDocumentHelper.getDocumentFromWikiId(wikiId);
BaseObject object = descriptorDocument.getXObject(WikiTemplateClassDocumentInitializer.SERVER_CLASS, true, context);
object.setIntValue(WikiTemplateClassDocumentInitializer.FIELD_ISWIKITEMPLATE, templateGroup.isTemplate() ? 1 : 0);
// The document must have a creator
if (descriptorDocument.getCreatorReference() == null) {
descriptorDocument.setCreatorReference(context.getUserReference());
}
// The document must have an author
if (descriptorDocument.getAuthorReference() == null) {
descriptorDocument.setAuthorReference(context.getUserReference());
}
xwiki.saveDocument(descriptorDocument, String.format("Changed property group [%s].", GROUP_NAME), context);
} catch (WikiManagerException e) {
throw new WikiPropertyGroupException(String.format(ERROR_MESSAGE_NO_DESCRIPTOR_DOCUMENT, wikiId), e);
} catch (XWikiException e) {
throw new WikiPropertyGroupException("Unable to save descriptor document.", e);
}
}
use of org.xwiki.wiki.properties.WikiPropertyGroupException in project xwiki-platform by xwiki.
the class DefaultWikiDescriptorBuilder method buildDescriptorObject.
@Override
public DefaultWikiDescriptor buildDescriptorObject(List<BaseObject> serverClassObjects, XWikiDocument document) {
List<BaseObject> normalizedServerClassObjects = normalizeServerClassObjects(serverClassObjects);
BaseObject mainServerClassObject = normalizedServerClassObjects.remove(0);
DefaultWikiDescriptor descriptor = extractWikiDescriptor(mainServerClassObject, document);
if (descriptor != null) {
// Create WikiAlias instances for the other XWikiServerClass objects
for (BaseObject serverClassObject : normalizedServerClassObjects) {
if (serverClassObject != null) {
String descriptorAlias = extractWikiAlias(serverClassObject);
descriptor.addAlias(descriptorAlias);
}
}
// load properties
descriptor.setMainPageReference(referenceResolver.resolve(mainServerClassObject.getStringValue(XWikiServerClassDocumentInitializer.FIELD_HOMEPAGE)));
descriptor.setPrettyName(mainServerClassObject.getStringValue(XWikiServerClassDocumentInitializer.FIELD_WIKIPRETTYNAME));
descriptor.setOwnerId(getFullReference(mainServerClassObject.getStringValue(XWikiServerClassDocumentInitializer.FIELD_OWNER), descriptor.getId()));
descriptor.setDescription(mainServerClassObject.getStringValue(XWikiServerClassDocumentInitializer.FIELD_DESCRIPTION));
// load the property groups
try {
WikiPropertyGroupManager wikiPropertyGroupManager = wikiPropertyGroupManagerProvider.get();
wikiPropertyGroupManager.loadForDescriptor(descriptor);
} catch (WikiPropertyGroupException e) {
logger.error("Failed to load wiki property groups for wiki [{}].", descriptor.getId(), e);
}
}
return descriptor;
}
use of org.xwiki.wiki.properties.WikiPropertyGroupException in project xwiki-platform by xwiki.
the class DefaultWikiDescriptorBuilder method save.
@Override
public XWikiDocument save(WikiDescriptor descriptor) throws WikiDescriptorBuilderException {
XWikiContext context = xcontextProvider.get();
XWiki xwiki = context.getWiki();
XWikiDocument descriptorDoc = null;
try {
// Create the descriptor document
descriptorDoc = wikiDescriptorDocumentHelper.getDocumentFromWikiId(descriptor.getId());
// Create the server class object
BaseObject obj = descriptorDoc.getXObject(DefaultWikiDescriptor.SERVER_CLASS, true, context);
obj.set(XWikiServerClassDocumentInitializer.FIELD_SERVER, descriptor.getDefaultAlias(), context);
obj.set(XWikiServerClassDocumentInitializer.FIELD_HOMEPAGE, referenceSerializer.serialize(descriptor.getMainPageReference()), context);
obj.set(XWikiServerClassDocumentInitializer.FIELD_OWNER, getFullReference(descriptor.getOwnerId(), descriptor.getId()), context);
obj.set(XWikiServerClassDocumentInitializer.FIELD_WIKIPRETTYNAME, descriptor.getPrettyName(), context);
obj.set(XWikiServerClassDocumentInitializer.FIELD_DESCRIPTION, descriptor.getDescription(), context);
// Create the aliases
List<String> aliases = descriptor.getAliases();
for (int i = 1; i < aliases.size(); ++i) {
String alias = aliases.get(i);
BaseObject objAlias = descriptorDoc.getXObject(DefaultWikiDescriptor.SERVER_CLASS, XWikiServerClassDocumentInitializer.FIELD_SERVER, alias, true);
objAlias.set(XWikiServerClassDocumentInitializer.FIELD_SERVER, alias, context);
}
// Set the meta-data (creator, hidden flag, parent, etc...)
setDescriptorDocMetadata(descriptorDoc);
// Save the document
xwiki.saveDocument(descriptorDoc, context);
// Save the property groups
WikiPropertyGroupManager wikiPropertyGroupManager = wikiPropertyGroupManagerProvider.get();
wikiPropertyGroupManager.saveForDescriptor(descriptor);
} catch (WikiManagerException e) {
throw new WikiDescriptorBuilderException("Unable to load the descriptor document", e);
} catch (XWikiException e) {
throw new WikiDescriptorBuilderException("Unable to save the descriptor document", e);
} catch (WikiPropertyGroupException e) {
throw new WikiDescriptorBuilderException("Unable to save the property groups", e);
}
return descriptorDoc;
}
use of org.xwiki.wiki.properties.WikiPropertyGroupException in project xwiki-platform by xwiki.
the class DefaultWikiDescriptorBuilderTest method buildDescriptorObjectWhenException.
@Test
public void buildDescriptorObjectWhenException() throws Exception {
// Mocks
List<BaseObject> objects = new ArrayList<>();
BaseObject object1 = mock(BaseObject.class);
objects.add(object1);
XWikiDocument document = mock(XWikiDocument.class);
DocumentReference documentReference = new DocumentReference("mainWiki", "XWiki", "XWikiServerSubwiki1");
when(document.getDocumentReference()).thenReturn(documentReference);
when(object1.getStringValue(XWikiServerClassDocumentInitializer.FIELD_SERVER)).thenReturn("subwiki1");
DocumentReference mainPageReference = new DocumentReference("subwiki1", "Space", "MainPage");
when(object1.getStringValue(XWikiServerClassDocumentInitializer.FIELD_HOMEPAGE)).thenReturn("Space.MainPage");
when(referenceResolver.resolve("Space.MainPage")).thenReturn(mainPageReference);
Exception exception = new WikiPropertyGroupException("error in wikiPropertyGroupManager.loadForDescriptor");
doThrow(exception).when(wikiPropertyGroupManager).loadForDescriptor(any(WikiDescriptor.class));
// Test
mocker.getComponentUnderTest().buildDescriptorObject(objects, document);
// Verify
verify(mocker.getMockedLogger()).error("Failed to load wiki property groups for wiki [{}].", "subwiki1", exception);
}
Aggregations