ArrayList<BlobKey> validSubmissionKeys = new ArrayList<BlobKey>();
for (Entry<String, BlobKey> entry : blobs.entrySet()) {
BlobKey blobKey = entry.getValue();
BlobInfo blobInfo = blobInfoFactory.loadBlobInfo(blobKey);
String contentType = blobInfo.getContentType().toLowerCase();
long size = blobInfo.getSize();
if (!contentType.startsWith("image/")) {
blobstoreService.delete(blobKey);
LOG.warning(String.format("Uploaded file has content type '%s'; skipping.", contentType));
continue;
}
if ((size > maxPhotoSize) || (size == 0)) {
blobstoreService.delete(blobKey);
LOG.warning(String.format("Uploaded file is %d bytes; skipping.", size));
continue;
}
validSubmissionKeys.add(blobKey);
}
if (validSubmissionKeys.size() > 0) {
// PhotoSubmission represents the metadata of a set of photo entries
PhotoSubmission photoSubmission =
new PhotoSubmission(Long.parseLong(assignmentId), articleUrl, author, email,
phoneNumber, title, description, location, date, validSubmissionKeys.size());
if (!util.isNullOrEmpty(latitude) && !util.isNullOrEmpty(longitude)) {
try {
photoSubmission.setLatitude(Double.parseDouble(latitude));
photoSubmission.setLongitude(Double.parseDouble(longitude));
} catch (NumberFormatException e) {
LOG.log(Level.WARNING, "Couldn't parse lat/long.", e);
}
}
pmfUtil.persistJdo(photoSubmission);
String submissionId = photoSubmission.getId();
for (BlobKey blobKey : validSubmissionKeys) {
BlobInfo blobInfo = blobInfoFactory.loadBlobInfo(blobKey);
PhotoEntry photoEntry = new PhotoEntry(submissionId, blobKey, blobInfo.getContentType());
photoEntry.setOriginalFileSize(blobInfo.getSize());
photoEntry.setOriginalFileName(blobInfo.getFilename());
pmfUtil.persistJdo(photoEntry);
}
Queue queue = QueueFactory.getDefaultQueue();