AssetEntityAdapter extends MetadataNodeEntityAdapter<Asset> { Iterable<Asset> browseByComponent(final ODatabaseDocumentTx db, final Component component) { checkNotNull(component); checkState(EntityHelper.hasMetadata(component)); Map<String, Object> parameters = ImmutableMap.of( "bucket", bucketEntityAdapter.recordIdentity(component.bucketId()), "component", componentEntityAdapter.recordIdentity(component) ); String query = String.format( "select from %s where %s = :bucket and %s = :component", DB_CLASS, P_BUCKET, P_COMPONENT ); Iterable<ODocument> docs = db.command(new OCommandSQL(query)).execute(parameters); return transform(docs); } @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 testModifyAssetAfterBrowsingByComponent() { createAssetWithName("some-asset"); Asset asset; try (ODatabaseDocumentTx db = database.getInstance().acquire()) { db.begin(); Component component = Iterables.getFirst(componentEntityAdapter.browseByQuery( db, "name = :name", singletonMap("name", "some-component"), singletonList(bucket), null), null); asset = Iterables.getFirst(assetEntityAdapter.browseByComponent(db, component), null); asset.attributes().child("mandatory").set("test-key", "test-value"); assetEntityAdapter.editEntity(db, asset); db.commit(); } assertThat(asset, is(notNullValue())); assertTrue(asset.attributes().child("mandatory").contains("test-key")); assertFalse(asset.attributes().child("optional").contains("test-key")); }