Search in sources :

Example 1 with WikiPropertyGroupException

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);
    }
}
Also used : WikiTemplatePropertyGroup(org.xwiki.wiki.template.WikiTemplatePropertyGroup) WikiPropertyGroupException(org.xwiki.wiki.properties.WikiPropertyGroupException) WikiManagerException(org.xwiki.wiki.manager.WikiManagerException) WikiDescriptor(org.xwiki.wiki.descriptor.WikiDescriptor) WikiTemplateManagerException(org.xwiki.wiki.template.WikiTemplateManagerException)

Example 2 with WikiPropertyGroupException

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);
    }
}
Also used : WikiTemplatePropertyGroup(org.xwiki.wiki.template.WikiTemplatePropertyGroup) WikiPropertyGroupException(org.xwiki.wiki.properties.WikiPropertyGroupException) XWikiDocument(com.xpn.xwiki.doc.XWikiDocument) WikiManagerException(org.xwiki.wiki.manager.WikiManagerException) XWikiContext(com.xpn.xwiki.XWikiContext) XWiki(com.xpn.xwiki.XWiki) XWikiException(com.xpn.xwiki.XWikiException) BaseObject(com.xpn.xwiki.objects.BaseObject)

Example 3 with WikiPropertyGroupException

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;
}
Also used : WikiPropertyGroupException(org.xwiki.wiki.properties.WikiPropertyGroupException) WikiPropertyGroupManager(org.xwiki.wiki.internal.descriptor.properties.WikiPropertyGroupManager) DefaultWikiDescriptor(org.xwiki.wiki.internal.descriptor.DefaultWikiDescriptor) BaseObject(com.xpn.xwiki.objects.BaseObject)

Example 4 with WikiPropertyGroupException

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;
}
Also used : WikiPropertyGroupException(org.xwiki.wiki.properties.WikiPropertyGroupException) XWikiDocument(com.xpn.xwiki.doc.XWikiDocument) WikiManagerException(org.xwiki.wiki.manager.WikiManagerException) WikiPropertyGroupManager(org.xwiki.wiki.internal.descriptor.properties.WikiPropertyGroupManager) XWikiContext(com.xpn.xwiki.XWikiContext) XWiki(com.xpn.xwiki.XWiki) XWikiException(com.xpn.xwiki.XWikiException) BaseObject(com.xpn.xwiki.objects.BaseObject)

Example 5 with WikiPropertyGroupException

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);
}
Also used : WikiPropertyGroupException(org.xwiki.wiki.properties.WikiPropertyGroupException) XWikiDocument(com.xpn.xwiki.doc.XWikiDocument) ArrayList(java.util.ArrayList) DocumentReference(org.xwiki.model.reference.DocumentReference) WikiPropertyGroupException(org.xwiki.wiki.properties.WikiPropertyGroupException) WikiDescriptor(org.xwiki.wiki.descriptor.WikiDescriptor) BaseObject(com.xpn.xwiki.objects.BaseObject) Test(org.junit.Test)

Aggregations

WikiPropertyGroupException (org.xwiki.wiki.properties.WikiPropertyGroupException)7 BaseObject (com.xpn.xwiki.objects.BaseObject)5 WikiManagerException (org.xwiki.wiki.manager.WikiManagerException)5 XWikiDocument (com.xpn.xwiki.doc.XWikiDocument)4 WikiTemplatePropertyGroup (org.xwiki.wiki.template.WikiTemplatePropertyGroup)3 XWiki (com.xpn.xwiki.XWiki)2 XWikiContext (com.xpn.xwiki.XWikiContext)2 XWikiException (com.xpn.xwiki.XWikiException)2 Test (org.junit.Test)2 WikiDescriptor (org.xwiki.wiki.descriptor.WikiDescriptor)2 WikiPropertyGroupManager (org.xwiki.wiki.internal.descriptor.properties.WikiPropertyGroupManager)2 ArrayList (java.util.ArrayList)1 DocumentReference (org.xwiki.model.reference.DocumentReference)1 DefaultWikiDescriptor (org.xwiki.wiki.internal.descriptor.DefaultWikiDescriptor)1 WikiTemplateManagerException (org.xwiki.wiki.template.WikiTemplateManagerException)1