use of com.linkedin.restli.example.PhotoCriteria 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;
}
Aggregations