Search in sources :

Example 1 with NoMetadata

use of com.linkedin.restli.server.NoMetadata in project rest.li by linkedin.

the class PhotoResource method searchPhotos.

@BatchFinder(value = "searchPhotos", batchParam = "criteria")
public BatchFinderResult<PhotoCriteria, Photo, NoMetadata> searchPhotos(@PagingContextParam PagingContext pagingContext, @QueryParam("criteria") PhotoCriteria[] criteria, @QueryParam("exif") @Optional EXIF exif) {
    BatchFinderResult<PhotoCriteria, Photo, NoMetadata> batchFinderResult = new BatchFinderResult<>();
    for (PhotoCriteria currentCriteria : criteria) {
        if (currentCriteria.getTitle() != null) {
            // on success
            final List<Photo> photos = new ArrayList<>();
            int index = 0;
            final int begin = pagingContext.getStart();
            final int end = begin + pagingContext.getCount();
            final Collection<Photo> dbPhotos = _db.getData().values();
            for (Photo p : dbPhotos) {
                if (index == end) {
                    break;
                } else if (index >= begin) {
                    if (p.getTitle().equalsIgnoreCase(currentCriteria.getTitle())) {
                        if (currentCriteria.getFormat() == null || currentCriteria.getFormat() == p.getFormat()) {
                            photos.add(p);
                        }
                    }
                }
                index++;
            }
            CollectionResult<Photo, NoMetadata> cr = new CollectionResult<>(photos, photos.size());
            batchFinderResult.putResult(currentCriteria, cr);
        } else {
            // on error: to construct error response for test
            batchFinderResult.putError(currentCriteria, new RestLiServiceException(HttpStatus.S_404_NOT_FOUND, "Failed to find Photo!"));
        }
    }
    return batchFinderResult;
}
Also used : CollectionResult(com.linkedin.restli.server.CollectionResult) NoMetadata(com.linkedin.restli.server.NoMetadata) RestLiServiceException(com.linkedin.restli.server.RestLiServiceException) ArrayList(java.util.ArrayList) Photo(com.linkedin.restli.example.Photo) BatchFinderResult(com.linkedin.restli.server.BatchFinderResult) PhotoCriteria(com.linkedin.restli.example.PhotoCriteria) BatchFinder(com.linkedin.restli.server.annotations.BatchFinder)

Aggregations

Photo (com.linkedin.restli.example.Photo)1 PhotoCriteria (com.linkedin.restli.example.PhotoCriteria)1 BatchFinderResult (com.linkedin.restli.server.BatchFinderResult)1 CollectionResult (com.linkedin.restli.server.CollectionResult)1 NoMetadata (com.linkedin.restli.server.NoMetadata)1 RestLiServiceException (com.linkedin.restli.server.RestLiServiceException)1 BatchFinder (com.linkedin.restli.server.annotations.BatchFinder)1 ArrayList (java.util.ArrayList)1