public BlobId getBlobId() { return new BlobId(getBlob()); }
private void checkIfOrphaned(final Consumer<String> handler, final BlobId id, final BlobAttributes attributes) { String repositoryName = attributes.getHeaders().get(REPOSITORY_NAME_KEY); if (repositoryName != null) { String assetName = attributes.getHeaders().get(ASSET_NAME_KEY); Repository repository = repositoryManager.get(repositoryName); if (repository == null) { log.debug("Blob {} considered orphaned because repository with name {} no longer exists", id.asUniqueString(), repositoryName); handler.accept(id.asUniqueString()); } else { findAssociatedAsset(assetName, repository).ifPresent(asset -> { BlobRef blobRef = asset.blobRef(); if (blobRef != null && !blobRef.getBlobId().asUniqueString().equals(id.asUniqueString())) { if (!attributes.isDeleted()) { handler.accept(id.asUniqueString()); } else { log.debug("Blob {} in repository {} not considered orphaned because it is already marked soft-deleted", id.asUniqueString(), repositoryName); } } }); } } }
/** * Parses the data field of an attachment in the JSON. The data is stored in a temp blob, and the blob ID is returned * as a string. */ private String parseAttachmentData() throws IOException { try { TempBlob tempBlob = readBinaryValueIntoTempBlob(); String id = tempBlob.getBlob().getId().toString(); tempBlobs.put(id, tempBlob); return id; } catch (Exception e) { throw new IOException("failed to process attachment data", e); } }
@Override public boolean create(final String path, final String mimeType, final InputStream inputStream) { if (exists(path)) { return false; } Map<String, String> blobMetadata = new HashMap<>(); blobMetadata.put(BlobStore.BLOB_NAME_HEADER, path); blobMetadata.put(BlobStore.CREATED_BY_HEADER, "Unknown"); blobMetadata.put("mimeType", mimeType); final Blob blob = blobStore.create(inputStream, blobMetadata); final RawBinaryMetadata item = new RawBinaryMetadata(path, blob.getId().asUniqueString(), mimeType); ORID rid; try (ODatabaseDocumentTx db = openDb()) { ODocument doc = entityAdapter.create(db, item); rid = doc.getIdentity(); } log.debug("Added item with RID: {}", rid); return true; }
private void delete(final BlobStore blobStore) { detect(blobStore, blobId -> { log.info("Deleting orphaned blob {} from blobstore {}", blobId, blobStore.getBlobStoreConfiguration().getName()); blobStore.deleteHard(new BlobId(blobId)); }); }
/** * The blob reference this instance is pointing to. */ @Nonnull public BlobRef getBlobRef() { return new BlobRef( nodeAccess.getId(), blobStore.getBlobStoreConfiguration().getName(), getBlob().getId().asUniqueString()); }
final RawBinaryMetadata metadata = entityAdapter.read(document); final Blob blob = blobStore.get(new BlobId(metadata.getBlobId()));
@Override @Timed public boolean test(final BlobStore blobStore, final BlobId blobId, final String blobName) { BlobRef blobRef = new BlobRef(ANY_NODE, blobStore.getBlobStoreConfiguration().getName(), blobId.asUniqueString()); try (ODatabaseDocumentTx tx = txSupplier.get()) { tx.begin(); List<ODocument> results = tx.command(assetBlobRefQuery).execute(blobName, blobRef.toString()); return !results.isEmpty(); } } }