use of org.sonatype.nexus.orient.entity.AttachedEntityId in project nexus-public by sonatype.
the class StorageFacetImplIT method mapOfMaps.
@Test
public void mapOfMaps() {
Map<String, String> bag2 = ImmutableMap.of();
// Transaction 1:
// Create a new asset with property "attributes" that's a map of maps (stored as an embeddedmap)
EntityId docId;
try (StorageTx tx = beginTX()) {
Bucket bucket = tx.findBucket(testRepository1);
Asset asset = tx.createAsset(bucket, testFormat);
asset.name("asset");
asset.attributes().child("bag1").set("foo", "bar");
asset.attributes().child("bag2").set("baz", "qux");
tx.saveAsset(asset);
tx.commit();
docId = EntityHelper.id(asset);
}
// Get the asset and make sure it contains what we expect
try (StorageTx tx = beginTX()) {
Bucket bucket = tx.findBucket(testRepository1);
Asset asset = checkNotNull(tx.findAsset(docId, bucket));
NestedAttributesMap outputMap = asset.attributes();
assertThat(outputMap.size(), is(2));
Map<String, String> outputBag1 = (Map<String, String>) outputMap.get("bag1");
assertNotNull(outputBag1);
assertThat(outputBag1.keySet().size(), is(1));
assertThat(outputBag1.get("foo"), is("bar"));
Map<String, String> outputBag2 = (Map<String, String>) outputMap.get("bag2");
assertNotNull(outputBag2);
assertThat(outputBag2.keySet().size(), is(1));
assertThat(outputBag2.get("baz"), is("qux"));
}
// Make sure we can use dot notation to query for the asset by some aspect of the attributes
try (StorageTx tx = beginTX()) {
Map<String, String> parameters = ImmutableMap.of("fooValue", "bar");
String query = String.format("select from %s where attributes.bag1.foo = :fooValue", assetEntityAdapter.getTypeName());
Iterable<ODocument> docs = tx.getDb().command(new OCommandSQL(query)).execute(parameters);
List<ODocument> list = Lists.newArrayList(docs);
assertThat(list.size(), is(1));
assertThat(new AttachedEntityId(assetEntityAdapter, list.get(0).getIdentity()), is(docId));
}
}
use of org.sonatype.nexus.orient.entity.AttachedEntityId in project nexus-public by sonatype.
the class BrowseNodeEntityAdapter method readFields.
@Override
protected void readFields(final ODocument document, final OrientBrowseNode entity) {
String repositoryName = document.field(P_REPOSITORY_NAME, OType.STRING);
String format = document.field(P_FORMAT, OType.STRING);
String path = document.field(P_PATH, OType.STRING);
String parentPath = document.field(P_PARENT_PATH, OType.STRING);
String name = document.field(P_NAME, OType.STRING);
String packageUrl = document.field(P_PACKAGE_URL, OType.STRING);
entity.setRepositoryName(repositoryName);
entity.setFormat(format);
entity.setPath(path);
entity.setParentPath(parentPath);
entity.setName(name);
entity.setPackageUrl(packageUrl);
ORID componentId = document.field(P_COMPONENT_ID, ORID.class);
if (componentId != null) {
entity.setComponentId(new AttachedEntityId(componentEntityAdapter, componentId));
}
ORID assetId = document.field(P_ASSET_ID, ORID.class);
if (assetId != null) {
entity.setAssetId(new AttachedEntityId(assetEntityAdapter, assetId));
}
}
use of org.sonatype.nexus.orient.entity.AttachedEntityId in project nexus-public by sonatype.
the class AssetEntityAdapter method newEvent.
@Override
public EntityEvent newEvent(final ODocument document, final EventKind eventKind) {
EntityMetadata metadata = new AttachedEntityMetadata(this, document);
String repositoryName = ((ODocument) document.field(P_BUCKET)).field(P_REPOSITORY_NAME);
ORID rid = document.field(P_COMPONENT, ORID.class);
EntityId componentId = rid != null ? new AttachedEntityId(componentEntityAdapter, rid) : null;
switch(eventKind) {
case CREATE:
return new AssetCreatedEvent(metadata, repositoryName, componentId);
case UPDATE:
return new AssetUpdatedEvent(metadata, repositoryName, componentId);
case DELETE:
return new AssetDeletedEvent(metadata, repositoryName, componentId);
default:
return null;
}
}
use of org.sonatype.nexus.orient.entity.AttachedEntityId in project nexus-public by sonatype.
the class MetadataNodeEntityAdapter method readFields.
@Override
protected void readFields(final ODocument document, final T entity) {
ORID bucketId = document.field(P_BUCKET, ORID.class);
String format = document.field(P_FORMAT, OType.STRING);
Date lastUpdated = document.field(P_LAST_UPDATED, OType.DATETIME);
Map<String, Object> attributes = document.field(P_ATTRIBUTES, OType.EMBEDDEDMAP);
entity.bucketId(new AttachedEntityId(bucketEntityAdapter, bucketId));
entity.format(format);
entity.lastUpdated(new DateTime(lastUpdated));
entity.attributes(new NestedAttributesMap(P_ATTRIBUTES, detachable(attributes)));
entity.newEntity(document.getIdentity().isNew());
}
use of org.sonatype.nexus.orient.entity.AttachedEntityId in project nexus-public by sonatype.
the class OrientConfigurationEntityAdapter method readFields.
@Override
protected void readFields(final ODocument document, final OrientConfiguration entity) {
String recipeName = document.field(P_RECIPE_NAME, OType.STRING);
String repositoryName = document.field(P_REPOSITORY_NAME, OType.STRING);
Boolean online = document.field(P_ONLINE, OType.BOOLEAN);
Map<String, Map<String, Object>> attributes = document.field(P_ATTRIBUTES, OType.EMBEDDEDMAP);
ODocument routingRule = document.field(P_ROUTING_RULE_ID, OType.LINK);
EntityId routingRuleId = routingRule == null ? null : new AttachedEntityId(routingRuleEntityAdapter, routingRule.getIdentity());
entity.setRoutingRuleId(routingRuleId);
entity.setRecipeName(recipeName);
entity.setRepositoryName(repositoryName);
entity.setOnline(online);
entity.setAttributes(decrypt(attributes));
}
Aggregations