AssetEntityAdapter extends MetadataNodeEntityAdapter<Asset> { public boolean exists(final ODatabaseDocumentTx db, final String name, final Bucket bucket) { Map<String, Object> params = ImmutableMap.of( P_NAME, checkNotNull(name), P_BUCKET, recordIdentity(id(checkNotNull(bucket))) ); OSQLSynchQuery<ODocument> query = new OSQLSynchQuery<>(EXISTS_QUERY_STRING, 1); return !isEmpty(db.command(query).<Iterable<ODocument>>execute(params)); } @Inject  AssetEntityAdapter(final BucketEntityAdapter bucketEntityAdapter,
                            final ComponentEntityAdapter componentEntityAdapter); Asset findByBucketComponentName(final ODatabaseDocumentTx db,
                                         final ORID bucketId,
                                         @Nullable final ORID componentId,
                                         final String name); @Override boolean sendEvents(); @Override EntityEvent newEvent(final ODocument document, final EventKind eventKind); @Override String eventAffinity(final ODocument document); boolean exists(final ODatabaseDocumentTx db, final String name, final Bucket bucket); @Override boolean resolveConflicts(); static final String P_ASSET_KIND; static final String P_BLOB_REF; static final String P_COMPONENT; static final String P_CONTENT_TYPE; static final String P_LAST_DOWNLOADED; static final String P_SIZE; static final String P_CREATED_BY; static final String P_CREATED_BY_IP; static final String P_BLOB_CREATED; static final String P_BLOB_UPDATED; static final String I_BUCKET_COMPONENT_NAME; static final String I_COMPONENT; static final String I_NAME_CASEINSENSITIVE; }
@Test public void testAssetExists() throws Exception { String assetName = "some-asset"; try (ODatabaseDocumentTx db = database.getInstance().acquire()) { assertFalse(assetEntityAdapter.exists(db, assetName, bucket)); } createAssetWithName(assetName); try (ODatabaseDocumentTx db = database.getInstance().acquire()) { assertTrue(assetEntityAdapter.exists(db, assetName, bucket)); } }