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);
}
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);
}
}
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);
}
}
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;
}
}
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;
}
Aggregations