use of org.xwiki.rest.XWikiRestException in project xwiki-platform by xwiki.
the class SpacesResourceImpl method getSpaces.
@Override
public Spaces getSpaces(String wikiName, Integer start, Integer number) throws XWikiRestException {
Spaces spaces = objectFactory.createSpaces();
try {
List<String> spaceNames = queryManager.getNamedQuery("getSpaces").addFilter(componentManager.<QueryFilter>getInstance(QueryFilter.class, "hidden")).setOffset(start).setLimit(number).setWiki(wikiName).execute();
for (String spaceName : spaceNames) {
List<String> spaceList = Utils.getSpacesFromSpaceId(spaceName);
String homeId = Utils.getPageId(wikiName, spaceList, "WebHome");
Document home = null;
XWiki xwikiApi = Utils.getXWikiApi(componentManager);
if (xwikiApi.hasAccessLevel("view", homeId)) {
if (xwikiApi.exists(homeId)) {
home = Utils.getXWikiApi(componentManager).getDocument(homeId);
}
spaces.getSpaces().add(DomainObjectFactory.createSpace(objectFactory, uriInfo.getBaseUri(), wikiName, spaceList, home));
}
}
} catch (Exception e) {
throw new XWikiRestException(e);
}
return spaces;
}
use of org.xwiki.rest.XWikiRestException in project xwiki-platform by xwiki.
the class PagesForTagsResourceImpl method getTags.
@Override
public Pages getTags(String wikiName, String tagNames, Integer start, Integer number, Boolean withPrettyNames) throws XWikiRestException {
String database = Utils.getXWikiContext(componentManager).getWikiId();
try {
Pages pages = objectFactory.createPages();
Utils.getXWikiContext(componentManager).setWikiId(wikiName);
String[] tagNamesArray = tagNames.split(",");
List<String> documentNames = new ArrayList<String>();
for (String tagName : tagNamesArray) {
List<String> documentNamesForTag = getDocumentsWithTag(tagName);
/* Avoid duplicates */
for (String documentName : documentNamesForTag) {
if (!documentNames.contains(documentName)) {
documentNames.add(documentName);
}
}
}
RangeIterable<String> ri = new RangeIterable<String>(documentNames, start, number);
for (String documentName : ri) {
Document doc = Utils.getXWikiApi(componentManager).getDocument(documentName);
if (doc != null) {
pages.getPageSummaries().add(DomainObjectFactory.createPageSummary(objectFactory, uriInfo.getBaseUri(), doc, Utils.getXWikiApi(componentManager), withPrettyNames));
}
}
return pages;
} catch (Exception e) {
throw new XWikiRestException(e);
} finally {
Utils.getXWikiContext(componentManager).setWikiId(database);
}
}
use of org.xwiki.rest.XWikiRestException in project xwiki-platform by xwiki.
the class TagsResourceImpl method getTags.
@Override
public Tags getTags(String wikiName) throws XWikiRestException {
String database = Utils.getXWikiContext(componentManager).getWikiId();
try {
Tags tags = objectFactory.createTags();
Utils.getXWikiContext(componentManager).setWikiId(wikiName);
List<String> tagNames = getAllTags();
for (String tagName : tagNames) {
Tag tag = objectFactory.createTag();
tag.setName(tagName);
String tagUri = Utils.createURI(uriInfo.getBaseUri(), PagesForTagsResource.class, wikiName, tagName).toString();
Link tagLink = objectFactory.createLink();
tagLink.setHref(tagUri);
tagLink.setRel(Relations.TAG);
tag.getLinks().add(tagLink);
tags.getTags().add(tag);
}
return tags;
} catch (QueryException e) {
throw new XWikiRestException(e);
} finally {
Utils.getXWikiContext(componentManager).setWikiId(database);
}
}
use of org.xwiki.rest.XWikiRestException in project xwiki-platform by xwiki.
the class WikiResourceImpl method importXAR.
@Override
public Wiki importXAR(String wikiName, Boolean backup, String history, InputStream is) throws XWikiRestException {
try {
if (!wikiExists(wikiName)) {
throw new WebApplicationException(Response.Status.NOT_FOUND);
}
/* Use the package plugin for importing pages */
XWikiContext xwikiContext = getXWikiContext();
PackageAPI importer = ((PackageAPI) xwikiContext.getWiki().getPluginApi("package", xwikiContext));
if (importer == null) {
throw new XWikiException(XWikiException.MODULE_XWIKI_ACCESS, XWikiException.ERROR_XWIKI_ACCESS_DENIED, "Can't access Package plugin API. Generally mean you don't have enough rights.");
}
String database = xwikiContext.getWikiId();
try {
xwikiContext.setWikiId(wikiName);
importer.setBackupPack(backup);
importer.Import(is);
HistoryOptions historyOption = parseHistoryOption(history, HistoryOptions.ADD);
switch(historyOption) {
case RESET:
importer.setPreserveVersion(false);
importer.setWithVersions(false);
break;
case REPLACE:
importer.setPreserveVersion(false);
importer.setWithVersions(true);
break;
default:
case ADD:
importer.setPreserveVersion(true);
importer.setWithVersions(false);
break;
}
// Set the backup pack option
importer.setBackupPack(backup);
if (importer.install() == com.xpn.xwiki.plugin.packaging.DocumentInfo.INSTALL_IMPOSSIBLE) {
throw new WebApplicationException(Response.Status.INTERNAL_SERVER_ERROR);
}
} catch (IOException e) {
throw new WebApplicationException(e);
} finally {
xwikiContext.setWikiId(database);
}
return DomainObjectFactory.createWiki(objectFactory, uriInfo.getBaseUri(), wikiName);
} catch (XWikiException e) {
throw new XWikiRestException(e);
}
}
use of org.xwiki.rest.XWikiRestException in project xwiki-platform by xwiki.
the class ObjectAtPageVersionResourceImpl method getObject.
@Override
public Object getObject(String wikiName, String spaceName, String pageName, String version, String className, Integer objectNumber, Boolean withPrettyName) throws XWikiRestException {
try {
DocumentInfo documentInfo = getDocumentInfo(wikiName, spaceName, pageName, null, version, true, false);
Document doc = documentInfo.getDocument();
XWikiDocument xwikiDocument = Utils.getXWiki(componentManager).getDocument(doc.getDocumentReference(), Utils.getXWikiContext(componentManager));
xwikiDocument = Utils.getXWiki(componentManager).getDocument(xwikiDocument, doc.getVersion(), Utils.getXWikiContext(componentManager));
com.xpn.xwiki.objects.BaseObject baseObject = xwikiDocument.getObject(className, objectNumber);
if (baseObject == null) {
throw new WebApplicationException(Status.NOT_FOUND);
}
return DomainObjectFactory.createObject(objectFactory, uriInfo.getBaseUri(), Utils.getXWikiContext(componentManager), doc, baseObject, true, Utils.getXWikiApi(componentManager), withPrettyName);
} catch (XWikiException e) {
throw new XWikiRestException(e);
}
}
Aggregations