public Optional<StoredImage> tryLoadImage(ImageRef ref) { Optional<StoredReport> report = reportStore.tryLoadReport(ref.getOwnerId(), ref.getReportId()); Preconditions.checkArgument(report.isPresent(), "Report not found: " + ref.toString()); return Optional.fromNullable( backend() .load() .type(StoredImage.class) .parent(report.get()) .id(StoredImage.toKey(ref)) .now()); }
private void addImage(ImageRef ref, String imageCsObjectName, BlobKey blobKey) { Optional<StoredReport> report = reportStore.tryLoadReport(ref.getOwnerId(), ref.getReportId()); Preconditions.checkArgument(report.isPresent(), "Report not found: " + ref.toString()); StoredImage image = StoredImage.builder() .setKey(StoredImage.toKey(ref)) .setReport(Ref.create(report.get())) .setImageFileName(ref.getImageName()) .setCloudStorageObjectName(imageCsObjectName) .setBlobKey(blobKey.getKeyString()) .build(); backend().save().entity(image).now(); }