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); } } }); } } }
@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; }
/** * The blob reference this instance is pointing to. */ @Nonnull public BlobRef getBlobRef() { return new BlobRef( nodeAccess.getId(), blobStore.getBlobStoreConfiguration().getName(), getBlob().getId().asUniqueString()); }
@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(); } } }