Search in sources :

Example 26 with XWikiRestException

use of org.xwiki.rest.XWikiRestException in project xwiki-platform by xwiki.

the class DefaultRestURLGenerator method getURL.

@Override
public URL getURL(EntityReference entityReference) throws XWikiRestException {
    try {
        ParameterizedType type = new DefaultParameterizedType(null, ParametrizedRestURLGenerator.class, entityReference.getClass());
        ParametrizedRestURLGenerator parametrizedRestURLGenerator = componentManager.getInstance(type);
        return parametrizedRestURLGenerator.getURL(entityReference);
    } catch (ComponentLookupException e) {
        throw new XWikiRestException(String.format("Unsupported entity type: [%s]", entityReference.getClass()), e);
    }
}
Also used : DefaultParameterizedType(org.xwiki.component.util.DefaultParameterizedType) ParameterizedType(java.lang.reflect.ParameterizedType) ParametrizedRestURLGenerator(org.xwiki.rest.url.ParametrizedRestURLGenerator) XWikiRestException(org.xwiki.rest.XWikiRestException) ComponentLookupException(org.xwiki.component.manager.ComponentLookupException) DefaultParameterizedType(org.xwiki.component.util.DefaultParameterizedType)

Example 27 with XWikiRestException

use of org.xwiki.rest.XWikiRestException in project xwiki-platform by xwiki.

the class PageTranslationsResourceImpl method getTranslations.

@Override
public Translations getTranslations(String wikiName, String spaceName, String pageName) throws XWikiRestException {
    try {
        DocumentInfo documentInfo = getDocumentInfo(wikiName, spaceName, pageName, null, null, true, false);
        Document doc = documentInfo.getDocument();
        return DomainObjectFactory.createTranslations(objectFactory, uriInfo.getBaseUri(), doc);
    } catch (XWikiException e) {
        throw new XWikiRestException(e);
    }
}
Also used : XWikiRestException(org.xwiki.rest.XWikiRestException) Document(com.xpn.xwiki.api.Document) XWikiException(com.xpn.xwiki.XWikiException)

Example 28 with XWikiRestException

use of org.xwiki.rest.XWikiRestException in project xwiki-platform by xwiki.

the class DBListClassPropertyValuesProviderTest method getValuesForWrongProperty.

@Test
public void getValuesForWrongProperty() throws Exception {
    ClassPropertyReference propertyReference = new ClassPropertyReference("date", this.classReference);
    when(this.entityReferenceSerializer.serialize(propertyReference)).thenReturn("status reference");
    try {
        this.mocker.getComponentUnderTest().getValues(propertyReference, 0);
        fail();
    } catch (XWikiRestException expected) {
        assertEquals("This [status reference] is not a [DBListClass] property.", expected.getMessage());
    }
}
Also used : XWikiRestException(org.xwiki.rest.XWikiRestException) ClassPropertyReference(org.xwiki.model.reference.ClassPropertyReference) Test(org.junit.Test)

Example 29 with XWikiRestException

use of org.xwiki.rest.XWikiRestException in project xwiki-platform by xwiki.

the class DefaultClassPropertyValuesProviderTest method getValuesForMissingProperty.

@Test
public void getValuesForMissingProperty() throws Exception {
    ClassPropertyReference propertyReference = new ClassPropertyReference("status", this.classReference);
    EntityReferenceSerializer<String> entityReferenceSerializer = this.mocker.getInstance(EntityReferenceSerializer.TYPE_STRING);
    when(entityReferenceSerializer.serialize(propertyReference)).thenReturn("status reference");
    try {
        this.mocker.getComponentUnderTest().getValues(propertyReference, 13);
        fail();
    } catch (XWikiRestException expected) {
        assertEquals("No such property [status reference].", expected.getMessage());
    }
}
Also used : XWikiRestException(org.xwiki.rest.XWikiRestException) ClassPropertyReference(org.xwiki.model.reference.ClassPropertyReference) Test(org.junit.Test)

Example 30 with XWikiRestException

use of org.xwiki.rest.XWikiRestException in project xwiki-platform by xwiki.

the class WikisSearchQueryResourceImpl method search.

@Override
public SearchResults search(String query, Integer number, Integer start, Boolean distinct, String searchWikis, String orderField, String order, Boolean withPrettyNames, String className) throws XWikiRestException {
    try {
        SearchResults searchResults = objectFactory.createSearchResults();
        searchResults.setTemplate(String.format("%s?%s", uriInfo.getBaseUri().toString(), MULTIWIKI_QUERY_TEMPLATE_INFO));
        searchResults.getSearchResults().addAll(this.solrSearch.search(query, getXWikiContext().getWikiId(), searchWikis, Utils.getXWiki(componentManager).getRightService().hasProgrammingRights(Utils.getXWikiContext(componentManager)), orderField, order, distinct, number, start, withPrettyNames, className, uriInfo));
        return searchResults;
    } catch (Exception e) {
        throw new XWikiRestException(e);
    }
}
Also used : XWikiRestException(org.xwiki.rest.XWikiRestException) SearchResults(org.xwiki.rest.model.jaxb.SearchResults) XWikiRestException(org.xwiki.rest.XWikiRestException)

Aggregations

XWikiRestException (org.xwiki.rest.XWikiRestException)71 XWikiException (com.xpn.xwiki.XWikiException)46 Document (com.xpn.xwiki.api.Document)40 WebApplicationException (javax.ws.rs.WebApplicationException)26 XWikiDocument (com.xpn.xwiki.doc.XWikiDocument)15 Link (org.xwiki.rest.model.jaxb.Link)12 QueryException (org.xwiki.query.QueryException)8 BaseObject (com.xpn.xwiki.objects.BaseObject)7 RangeIterable (org.xwiki.rest.internal.RangeIterable)7 XWikiContext (com.xpn.xwiki.XWikiContext)6 Object (org.xwiki.rest.model.jaxb.Object)5 Property (org.xwiki.rest.model.jaxb.Property)5 Date (java.util.Date)4 Test (org.junit.Test)4 ClassPropertyReference (org.xwiki.model.reference.ClassPropertyReference)4 Objects (org.xwiki.rest.model.jaxb.Objects)4 XWikiRCSNodeId (com.xpn.xwiki.doc.rcs.XWikiRCSNodeId)3 BaseClass (com.xpn.xwiki.objects.classes.BaseClass)3 URI (java.net.URI)3 URL (java.net.URL)3