Search in sources :

Example 1 with AttachedEntityId

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));
    }
}
Also used : NestedAttributesMap(org.sonatype.nexus.common.collect.NestedAttributesMap) EntityId(org.sonatype.nexus.common.entity.EntityId) AttachedEntityId(org.sonatype.nexus.orient.entity.AttachedEntityId) OCommandSQL(com.orientechnologies.orient.core.sql.OCommandSQL) AttachedEntityId(org.sonatype.nexus.orient.entity.AttachedEntityId) Map(java.util.Map) NestedAttributesMap(org.sonatype.nexus.common.collect.NestedAttributesMap) ImmutableMap(com.google.common.collect.ImmutableMap) ODocument(com.orientechnologies.orient.core.record.impl.ODocument) Test(org.junit.Test)

Example 2 with AttachedEntityId

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));
    }
}
Also used : ORID(com.orientechnologies.orient.core.id.ORID) AttachedEntityId(org.sonatype.nexus.orient.entity.AttachedEntityId)

Example 3 with AttachedEntityId

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;
    }
}
Also used : EntityId(org.sonatype.nexus.common.entity.EntityId) AttachedEntityId(org.sonatype.nexus.orient.entity.AttachedEntityId) EntityMetadata(org.sonatype.nexus.common.entity.EntityMetadata) AttachedEntityMetadata(org.sonatype.nexus.orient.entity.AttachedEntityMetadata) AttachedEntityMetadata(org.sonatype.nexus.orient.entity.AttachedEntityMetadata) ORID(com.orientechnologies.orient.core.id.ORID) AttachedEntityId(org.sonatype.nexus.orient.entity.AttachedEntityId) ODocument(com.orientechnologies.orient.core.record.impl.ODocument)

Example 4 with AttachedEntityId

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());
}
Also used : ORID(com.orientechnologies.orient.core.id.ORID) AttachedEntityId(org.sonatype.nexus.orient.entity.AttachedEntityId) Date(java.util.Date) DateTime(org.joda.time.DateTime) NestedAttributesMap(org.sonatype.nexus.common.collect.NestedAttributesMap)

Example 5 with AttachedEntityId

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));
}
Also used : EntityId(org.sonatype.nexus.common.entity.EntityId) AttachedEntityId(org.sonatype.nexus.orient.entity.AttachedEntityId) AttachedEntityId(org.sonatype.nexus.orient.entity.AttachedEntityId) HashMap(java.util.HashMap) Map(java.util.Map) ODocument(com.orientechnologies.orient.core.record.impl.ODocument)

Aggregations

AttachedEntityId (org.sonatype.nexus.orient.entity.AttachedEntityId)8 EntityId (org.sonatype.nexus.common.entity.EntityId)5 ORID (com.orientechnologies.orient.core.id.ORID)4 ODocument (com.orientechnologies.orient.core.record.impl.ODocument)3 ODatabaseDocumentTx (com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx)2 OIdentifiable (com.orientechnologies.orient.core.db.record.OIdentifiable)2 SimpleEntry (java.util.AbstractMap.SimpleEntry)2 ArrayList (java.util.ArrayList)2 Date (java.util.Date)2 Map (java.util.Map)2 Entry (java.util.Map.Entry)2 DateTime (org.joda.time.DateTime)2 NestedAttributesMap (org.sonatype.nexus.common.collect.NestedAttributesMap)2 Guarded (org.sonatype.nexus.common.stateguard.Guarded)2 ImmutableMap (com.google.common.collect.ImmutableMap)1 OCommandSQL (com.orientechnologies.orient.core.sql.OCommandSQL)1 HashMap (java.util.HashMap)1 Test (org.junit.Test)1 EntityMetadata (org.sonatype.nexus.common.entity.EntityMetadata)1 AttachedEntityMetadata (org.sonatype.nexus.orient.entity.AttachedEntityMetadata)1