Example usage for org.springframework.web.context.request ServletWebRequest checkNotModified

List of usage examples for org.springframework.web.context.request ServletWebRequest checkNotModified

Introduction

In this page you can find the example usage for org.springframework.web.context.request ServletWebRequest checkNotModified.

Prototype

@Override
    public boolean checkNotModified(String etag) 

Source Link

Usage

From source file:com.vmware.appfactory.build.controller.BuildApiController.java

/**
 * Get a single build./*from   w w  w.jav a  2  s  .c  o m*/
 *
 * @param buildId
 * @return The specified build.
 * @throws AfNotFoundException
 */
@RequestMapping(value = "/builds/{buildId}", method = RequestMethod.GET)
public @ResponseBody Build getBuild(ServletWebRequest webRequest, @PathVariable Long buildId)
        throws AfNotFoundException {
    BuildDao buildDao = _daoFactory.getBuildDao();
    Build build = buildDao.find(buildId);

    if (build == null) {
        throw new AfNotFoundException("No such build ID " + buildId);
    }

    long lastModified = build.getModified();
    if (0 != lastModified && webRequest.checkNotModified(lastModified)) {
        // shortcut exit - no further processing necessary
        return null;
    }

    return build;
}

From source file:com.vmware.appfactory.application.controller.AppApiController.java

/**
 * This method fetches the list of build requests by appId. The build requests
 * lifecycle is closely tied to that of the app itself.
 *
 * @param appId//ww  w. j  av a 2 s  .c  om
 * @return
 * @throws AfNotFoundException
 */
@ResponseBody
@RequestMapping(value = "/apps/{appId}/buildRequests", method = RequestMethod.GET)
public List<AppCaptureHistory> getBuildRequestsByApp(ServletWebRequest webRequest, @PathVariable Long appId)
        throws AfNotFoundException {
    /* Get the app */
    ApplicationDao appDao = _daoFactory.getApplicationDao();
    Application app = appDao.find(appId);

    if (app == null) {
        throw new AfNotFoundException("No such application id " + appId);
    }

    List<AppBuildRequest> builds = _daoFactory.getAppBuildRequestDao().findBuildRequestForApp(appId);

    // Compute the created/lastUpdated based on AppBuildRequest and related build table entries.
    long lastUpdated = 0;
    List<AppCaptureHistory> captures = new ArrayList<AppCaptureHistory>(builds.size());
    for (AppBuildRequest request : builds) {
        AppCaptureHistory capture = createAppCaptureHistory(request);
        captures.add(capture);
        if (capture.getLastUpdated() > lastUpdated) {
            lastUpdated = capture.getLastUpdated();
        }
    }

    // Return data only if there are changes yet to be sent.
    return webRequest.checkNotModified(lastUpdated) ? null : captures;
}