Search in sources :

Example 1 with ApiResourceOutput

use of com.bluenimble.platform.api.impls.ApiResourceOutput in project serverless by bluenimble.

the class GetResourceApiServiceSpi method execute.

@Override
public ApiOutput execute(Api api, ApiConsumer consumer, ApiRequest request, ApiResponse response) throws ApiServiceExecutionException {
    String path = (String) request.get(Spec.Path);
    if (Lang.isNullOrEmpty(path)) {
        throw new ApiServiceExecutionException("Resource / not found").status(ApiResponse.BAD_REQUEST);
    }
    String location = (String) Json.find(request.getService().getCustom(), Custom.Resources, Custom.Root);
    if (!Lang.isNullOrEmpty(location)) {
        path = location + Lang.SLASH + path;
    }
    ApiResource r;
    try {
        r = api.getResourcesManager().get(Lang.split(path, Lang.SLASH));
    } catch (ApiResourcesManagerException e) {
        throw new ApiServiceExecutionException(e.getMessage()).status(ApiResponse.BAD_REQUEST);
    }
    if (r == null) {
        throw new ApiServiceExecutionException("Resource " + path + " not found").status(ApiResponse.NOT_FOUND);
    }
    return new ApiResourceOutput(r);
}
Also used : ApiResource(com.bluenimble.platform.api.ApiResource) ApiResourceOutput(com.bluenimble.platform.api.impls.ApiResourceOutput) ApiServiceExecutionException(com.bluenimble.platform.api.ApiServiceExecutionException) ApiResourcesManagerException(com.bluenimble.platform.api.ApiResourcesManagerException)

Aggregations

ApiResource (com.bluenimble.platform.api.ApiResource)1 ApiResourcesManagerException (com.bluenimble.platform.api.ApiResourcesManagerException)1 ApiServiceExecutionException (com.bluenimble.platform.api.ApiServiceExecutionException)1 ApiResourceOutput (com.bluenimble.platform.api.impls.ApiResourceOutput)1