}
if (thumbnail != null && data != null) {
// Create a thumbnail relationship
Thumbnails thumbnailRelationship = app.create(originalImage, thumbnail, Thumbnails.class);
// Thumbnails always have to be removed along with origin image
thumbnailRelationship.setProperty(AbstractRelationship.cascadeDelete, Relation.SOURCE_TO_TARGET);
// Add to cache list
// thumbnailRelationships.add(thumbnailRelationship);
long size = data.length;
thumbnail.setProperty(File.size, size);
thumbnail.setProperty(Image.width, tnWidth);
thumbnail.setProperty(Image.height, tnHeight);
thumbnail.setProperty(AbstractNode.hidden, originalImage.getProperty(AbstractNode.hidden));
thumbnail.setProperty(AbstractNode.visibleToAuthenticatedUsers, originalImage.getProperty(AbstractNode.visibleToAuthenticatedUsers));
thumbnail.setProperty(AbstractNode.visibleToPublicUsers, originalImage.getProperty(AbstractNode.visibleToPublicUsers));
thumbnail.setProperty(AbstractNode.owner, originalImage.getProperty(AbstractNode.owner));
thumbnailRelationship.setProperty(Image.width, tnWidth);
thumbnailRelationship.setProperty(Image.height, tnHeight);
thumbnailRelationship.unlockReadOnlyPropertiesOnce();
thumbnailRelationship.setProperty(Image.checksum, newChecksum);
// System.out.println("Thumbnail ID: " + thumbnail.getUuid() + ", orig. image ID: " + originalImage.getUuid() + ", orig. image checksum: " + originalImage.getProperty(checksum));
// Soft-delete outdated thumbnails
for (Image tn : oldThumbnails) {