Search in sources :

Example 6 with WikiTemplateManagerException

use of org.xwiki.wiki.template.WikiTemplateManagerException in project xwiki-platform by xwiki.

the class WikiTemplateManagerScriptTest method getWikiProvisioningJobStatusWithException.

@Test
public void getWikiProvisioningJobStatusWithException() throws Exception {
    Exception exception = new WikiTemplateManagerException("test");
    when(wikiTemplateManager.getWikiProvisioningJob(anyList())).thenThrow(exception);
    List<String> jobId = new ArrayList<String>();
    JobStatus result = mocker.getComponentUnderTest().getWikiProvisioningJobStatus(jobId);
    assertEquals(null, result);
    assertEquals(exception, mocker.getComponentUnderTest().getLastError());
    verify(mocker.getMockedLogger()).error("Failed to get tge wiki provisioning job.", exception);
}
Also used : JobStatus(org.xwiki.job.event.status.JobStatus) ArrayList(java.util.ArrayList) WikiTemplateManagerException(org.xwiki.wiki.template.WikiTemplateManagerException) WikiManagerException(org.xwiki.wiki.manager.WikiManagerException) AccessDeniedException(org.xwiki.security.authorization.AccessDeniedException) WikiTemplateManagerException(org.xwiki.wiki.template.WikiTemplateManagerException) Test(org.junit.Test)

Example 7 with WikiTemplateManagerException

use of org.xwiki.wiki.template.WikiTemplateManagerException in project xwiki-platform by xwiki.

the class SaveWikiMetaDataStep method execute.

@Override
public void execute(WikiCreationRequest request) throws WikiCreationException {
    try {
        String wikiId = request.getWikiId();
        // Meta data about the wiki
        WikiDescriptor descriptor = wikiDescriptorManager.getById(wikiId);
        descriptor.setDescription(request.getDescription());
        descriptor.setPrettyName(request.getPrettyName());
        descriptor.setOwnerId(request.getOwnerId());
        wikiDescriptorManager.saveDescriptor(descriptor);
        // Meta data about the templates
        wikiTemplateManager.setTemplate(wikiId, request.isTemplate());
        // Meta data about the users
        wikiUserManager.setUserScope(wikiId, request.getUserScope());
        wikiUserManager.setMembershipType(wikiId, request.getMembershipType());
    } catch (WikiManagerException | WikiTemplateManagerException | WikiUserManagerException e) {
        throw new WikiCreationException(String.format("Failed to set metadata to the wiki [%s].", request.getWikiId()), e);
    }
}
Also used : WikiCreationException(org.xwiki.platform.wiki.creationjob.WikiCreationException) WikiManagerException(org.xwiki.wiki.manager.WikiManagerException) WikiUserManagerException(org.xwiki.wiki.user.WikiUserManagerException) WikiDescriptor(org.xwiki.wiki.descriptor.WikiDescriptor) WikiTemplateManagerException(org.xwiki.wiki.template.WikiTemplateManagerException)

Example 8 with WikiTemplateManagerException

use of org.xwiki.wiki.template.WikiTemplateManagerException in project xwiki-platform by xwiki.

the class DefaultWikiTemplateManager method isTemplate.

@Override
public boolean isTemplate(String wikiId) throws WikiTemplateManagerException {
    try {
        // Get the descriptor
        WikiDescriptor descriptor = wikiDescriptorManager.getById(wikiId);
        // Get the property group
        WikiTemplatePropertyGroup group = (WikiTemplatePropertyGroup) descriptor.getPropertyGroup(WikiTemplatePropertyGroupProvider.GROUP_NAME);
        // Return the value
        return group.isTemplate();
    } catch (WikiManagerException e) {
        throw new WikiTemplateManagerException(String.format(errorMessageNoDescriptor, wikiId), e);
    }
}
Also used : WikiTemplatePropertyGroup(org.xwiki.wiki.template.WikiTemplatePropertyGroup) WikiManagerException(org.xwiki.wiki.manager.WikiManagerException) WikiDescriptor(org.xwiki.wiki.descriptor.WikiDescriptor) WikiTemplateManagerException(org.xwiki.wiki.template.WikiTemplateManagerException)

Example 9 with WikiTemplateManagerException

use of org.xwiki.wiki.template.WikiTemplateManagerException in project xwiki-platform by xwiki.

the class WikiTemplateManagerScript method setTemplate.

/**
 * Set if the specified wiki is a template or not.
 *
 * @param wikiId the ID of the wiki to specify
 * @param value whether or not the wiki is a template
 * @return true if the action succeed
 */
public boolean setTemplate(String wikiId, boolean value) {
    XWikiContext context = xcontextProvider.get();
    try {
        // Check if the current script has the programing rights
        authorizationManager.checkAccess(Right.PROGRAM, context.getDoc().getAuthorReference(), context.getDoc().getDocumentReference());
        // Get the descriptor
        WikiDescriptor descriptor = wikiDescriptorManager.getById(wikiId);
        // Get the wiki owner
        String owner = descriptor.getOwnerId();
        // Check right access
        WikiReference wikiReference = new WikiReference(descriptor.getId());
        String currentUser = entityReferenceSerializer.serialize(context.getUserReference());
        if (!currentUser.equals(owner)) {
            authorizationManager.checkAccess(Right.ADMIN, context.getUserReference(), wikiReference);
        }
        // Do the job
        wikiTemplateManager.setTemplate(wikiId, value);
        // Return success
        return true;
    } catch (WikiTemplateManagerException e) {
        error(String.format("Failed to set the template value [%s] for the wiki [%s].", value, wikiId), e);
        return false;
    } catch (AccessDeniedException e) {
        error(String.format("Access denied for [%s] to change the template value of the wiki [%s]. The user has" + " not the right to perform this operation or the script has not the programming right.", context.getUserReference(), wikiId), e);
        return false;
    } catch (WikiManagerException e) {
        error(String.format("Failed to get the descriptor of the wiki [%s].", wikiId), e);
        return false;
    }
}
Also used : AccessDeniedException(org.xwiki.security.authorization.AccessDeniedException) WikiManagerException(org.xwiki.wiki.manager.WikiManagerException) XWikiContext(com.xpn.xwiki.XWikiContext) WikiReference(org.xwiki.model.reference.WikiReference) WikiDescriptor(org.xwiki.wiki.descriptor.WikiDescriptor) WikiTemplateManagerException(org.xwiki.wiki.template.WikiTemplateManagerException)

Example 10 with WikiTemplateManagerException

use of org.xwiki.wiki.template.WikiTemplateManagerException in project xwiki-platform by xwiki.

the class WikiTemplateManagerScript method createWikiFromTemplate.

/**
 * Create a new wiki from the specified template.
 *
 * @param newWikiId ID of the wiki to create
 * @param newWikiAlias Default alias of the wiki to create
 * @param templateId Id of the template to use
 * @param ownerId Id of the wiki owner
 * @param failOnExist fail the creation of the wiki id if not available
 * @return true if it succeed
 */
public boolean createWikiFromTemplate(String newWikiId, String newWikiAlias, String templateId, String ownerId, boolean failOnExist) {
    try {
        XWikiContext context = xcontextProvider.get();
        // Check if the current script has the programing rights
        authorizationManager.checkAccess(Right.PROGRAM, context.getDoc().getAuthorReference(), context.getDoc().getDocumentReference());
        // Check if the user has the right
        authorizationManager.checkAccess(Right.CREATE_WIKI, context.getUserReference(), new WikiReference(context.getMainXWiki()));
        // Do the job
        wikiTemplateManager.createWikiFromTemplate(newWikiId, newWikiAlias, templateId, ownerId, failOnExist);
        return true;
    } catch (WikiTemplateManagerException e) {
        error("Failed to create the wiki from the template.", e);
    } catch (AccessDeniedException e) {
        error("Error, you or this script does not have the right to create a wiki from a template.", e);
    }
    return false;
}
Also used : AccessDeniedException(org.xwiki.security.authorization.AccessDeniedException) XWikiContext(com.xpn.xwiki.XWikiContext) WikiReference(org.xwiki.model.reference.WikiReference) WikiTemplateManagerException(org.xwiki.wiki.template.WikiTemplateManagerException)

Aggregations

WikiTemplateManagerException (org.xwiki.wiki.template.WikiTemplateManagerException)12 WikiManagerException (org.xwiki.wiki.manager.WikiManagerException)11 WikiDescriptor (org.xwiki.wiki.descriptor.WikiDescriptor)8 AccessDeniedException (org.xwiki.security.authorization.AccessDeniedException)7 Test (org.junit.Test)5 XWikiContext (com.xpn.xwiki.XWikiContext)2 ArrayList (java.util.ArrayList)2 WikiReference (org.xwiki.model.reference.WikiReference)2 WikiPropertyGroupException (org.xwiki.wiki.properties.WikiPropertyGroupException)2 WikiTemplatePropertyGroup (org.xwiki.wiki.template.WikiTemplatePropertyGroup)2 JobStatus (org.xwiki.job.event.status.JobStatus)1 WikiCreationException (org.xwiki.platform.wiki.creationjob.WikiCreationException)1 Query (org.xwiki.query.Query)1 WikiProvisioningJobException (org.xwiki.wiki.provisioning.WikiProvisioningJobException)1 WikiUserManagerException (org.xwiki.wiki.user.WikiUserManagerException)1