Search in sources :

Example 1 with MdsRestFacade

use of org.motechproject.mds.rest.MdsRestFacade in project motech by motech.

the class MdsRestController method doGet.

private Object doGet(String entityName, String moduleName, String namespace, Map<String, String> requestParams, String pathLookupName) {
    debugRequest("GET", entityName, moduleName, namespace);
    QueryParams queryParams = ParamParser.buildQueryParams(requestParams);
    Long id = ParamParser.getId(requestParams);
    // we have 2 endpoints for lookups, in one the name comes from the path in the second its in the params
    String lookupName = StringUtils.isNotBlank(pathLookupName) ? pathLookupName : ParamParser.getLookupName(requestParams);
    MdsRestFacade restFacade = restFacadeRetriever.getRestFacade(entityName, moduleName, namespace);
    Boolean includeBlob = ParamParser.getIncludeBlob(requestParams);
    if (lookupName != null) {
        // lookup
        return restFacade.executeLookup(lookupName, requestParams, queryParams, includeBlob != null && includeBlob);
    } else if (id != null) {
        // retrieve by id
        return restFacade.get(id, includeBlob == null || includeBlob);
    } else {
        // get records
        return restFacade.get(queryParams, includeBlob != null && includeBlob);
    }
}
Also used : MdsRestFacade(org.motechproject.mds.rest.MdsRestFacade) QueryParams(org.motechproject.mds.query.QueryParams)

Example 2 with MdsRestFacade

use of org.motechproject.mds.rest.MdsRestFacade in project motech by motech.

the class MdsRestController method doPost.

private Object doPost(String entityName, String moduleName, String namespace, HttpServletRequest request) {
    debugRequest("POST", entityName, moduleName, namespace);
    MdsRestFacade restFacade = restFacadeRetriever.getRestFacade(entityName, moduleName, namespace);
    try (InputStream bodyInStream = request.getInputStream()) {
        return restFacade.create(bodyInStream);
    } catch (IOException e) {
        throw new RestBadBodyFormatException("Unable to read request body", e);
    }
}
Also used : RestBadBodyFormatException(org.motechproject.mds.exception.rest.RestBadBodyFormatException) InputStream(java.io.InputStream) MdsRestFacade(org.motechproject.mds.rest.MdsRestFacade) IOException(java.io.IOException)

Example 3 with MdsRestFacade

use of org.motechproject.mds.rest.MdsRestFacade in project motech by motech.

the class MdsRestFacadeRetrieverTest method testRetrieval.

private void testRetrieval(String entityName, String moduleName, String namespace) throws InvalidSyntaxException {
    String filter = filter(ClassName.restId(entityName, moduleName, namespace));
    when(bundleContext.getServiceReferences(MdsRestFacade.class, filter)).thenReturn(asList(serviceRef));
    when(bundleContext.getService(serviceRef)).thenReturn(mdsRestFacade);
    MdsRestFacade result = restFacadeRetriever.getRestFacade(entityName, moduleName, namespace);
    assertEquals(mdsRestFacade, result);
}
Also used : MdsRestFacade(org.motechproject.mds.rest.MdsRestFacade)

Example 4 with MdsRestFacade

use of org.motechproject.mds.rest.MdsRestFacade in project motech by motech.

the class MdsRestController method doDelete.

private void doDelete(String entityName, String moduleName, String namespace, Long id) {
    debugRequest("DELETE", entityName, moduleName, namespace);
    if (LOGGER.isDebugEnabled()) {
        LOGGER.debug("Delete request for id {}", id);
    }
    MdsRestFacade restFacade = restFacadeRetriever.getRestFacade(entityName, moduleName, namespace);
    restFacade.delete(id);
}
Also used : MdsRestFacade(org.motechproject.mds.rest.MdsRestFacade)

Example 5 with MdsRestFacade

use of org.motechproject.mds.rest.MdsRestFacade in project motech by motech.

the class MdsRestController method doPut.

private Object doPut(String entityName, String moduleName, String namespace, HttpServletRequest request) {
    debugRequest("PUT", entityName, moduleName, namespace);
    MdsRestFacade restFacade = restFacadeRetriever.getRestFacade(entityName, moduleName, namespace);
    try (InputStream bodyInStream = request.getInputStream()) {
        return restFacade.update(bodyInStream);
    } catch (IOException e) {
        throw new RestBadBodyFormatException("Unable to read request body", e);
    }
}
Also used : RestBadBodyFormatException(org.motechproject.mds.exception.rest.RestBadBodyFormatException) InputStream(java.io.InputStream) MdsRestFacade(org.motechproject.mds.rest.MdsRestFacade) IOException(java.io.IOException)

Aggregations

MdsRestFacade (org.motechproject.mds.rest.MdsRestFacade)6 IOException (java.io.IOException)2 InputStream (java.io.InputStream)2 RestBadBodyFormatException (org.motechproject.mds.exception.rest.RestBadBodyFormatException)2 RestNotSupportedException (org.motechproject.mds.exception.rest.RestNotSupportedException)1 QueryParams (org.motechproject.mds.query.QueryParams)1 InvalidSyntaxException (org.osgi.framework.InvalidSyntaxException)1 ServiceReference (org.osgi.framework.ServiceReference)1