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