Search in sources :

Example 36 with Entity

use of org.apache.rya.indexing.entity.model.Entity in project incubator-rya by apache.

the class MongoEntityIndexerIT method addStatement_manyUpdates.

@Test
public void addStatement_manyUpdates() throws Exception {
    try (MongoEntityIndexer indexer = new MongoEntityIndexer()) {
        indexer.setConf(conf);
        indexer.init();
        // Load the types into the TypeStorage.
        final TypeStorage types = new MongoTypeStorage(getMongoClient(), conf.getRyaInstanceName());
        types.create(PERSON_TYPE);
        types.create(EMPLOYEE_TYPE);
        // Index a bunch of RyaStatements.
        final RyaURI aliceSSN = new RyaURI("urn:SSN/111-11-1111");
        indexer.storeStatement(new RyaStatement(aliceSSN, new RyaURI(RDF.TYPE.toString()), new RyaType(XMLSchema.ANYURI, "urn:person")));
        indexer.storeStatement(new RyaStatement(aliceSSN, new RyaURI("urn:name"), new RyaType(XMLSchema.STRING, "Alice")));
        indexer.storeStatement(new RyaStatement(aliceSSN, new RyaURI("urn:age"), new RyaType(XMLSchema.INT, "30")));
        indexer.storeStatement(new RyaStatement(aliceSSN, new RyaURI("urn:eye"), new RyaType(XMLSchema.STRING, "blue")));
        // Fetch the Entity from storage and ensure it looks correct.
        final EntityStorage entities = new MongoEntityStorage(getMongoClient(), conf.getRyaInstanceName());
        final Entity entity = entities.get(new RyaURI("urn:SSN/111-11-1111")).get();
        final Entity expected = Entity.builder().setSubject(aliceSSN).setExplicitType(new RyaURI("urn:person")).setProperty(new RyaURI("urn:person"), new Property(new RyaURI("urn:name"), new RyaType(XMLSchema.STRING, "Alice"))).setProperty(new RyaURI("urn:person"), new Property(new RyaURI("urn:age"), new RyaType(XMLSchema.INT, "30"))).setProperty(new RyaURI("urn:person"), new Property(new RyaURI("urn:eye"), new RyaType(XMLSchema.STRING, "blue"))).setProperty(new RyaURI("urn:employee"), new Property(new RyaURI("urn:name"), new RyaType(XMLSchema.STRING, "Alice"))).setVersion(entity.getVersion()).build();
        assertEquals(expected, entity);
    }
}
Also used : MongoTypeStorage(org.apache.rya.indexing.entity.storage.mongo.MongoTypeStorage) TypeStorage(org.apache.rya.indexing.entity.storage.TypeStorage) RyaURI(org.apache.rya.api.domain.RyaURI) Entity(org.apache.rya.indexing.entity.model.Entity) MongoTypeStorage(org.apache.rya.indexing.entity.storage.mongo.MongoTypeStorage) MongoEntityStorage(org.apache.rya.indexing.entity.storage.mongo.MongoEntityStorage) EntityStorage(org.apache.rya.indexing.entity.storage.EntityStorage) MongoEntityStorage(org.apache.rya.indexing.entity.storage.mongo.MongoEntityStorage) RyaStatement(org.apache.rya.api.domain.RyaStatement) RyaType(org.apache.rya.api.domain.RyaType) Property(org.apache.rya.indexing.entity.model.Property) Test(org.junit.Test)

Example 37 with Entity

use of org.apache.rya.indexing.entity.model.Entity in project incubator-rya by apache.

the class MongoEntityIndexerIT method addStatements.

@Test
public void addStatements() throws Exception {
    try (MongoEntityIndexer indexer = new MongoEntityIndexer()) {
        indexer.setConf(conf);
        indexer.init();
        // Load the types into the TypeStorage.
        final TypeStorage types = new MongoTypeStorage(getMongoClient(), conf.getRyaInstanceName());
        types.create(PERSON_TYPE);
        types.create(EMPLOYEE_TYPE);
        // Index a bunch of RyaStatements.
        final RyaURI aliceSSN = new RyaURI("urn:SSN/111-11-1111");
        final RyaURI bobSSN = new RyaURI("urn:SSN/222-22-2222");
        indexer.storeStatements(Sets.newHashSet(new RyaStatement(aliceSSN, new RyaURI(RDF.TYPE.toString()), new RyaType(XMLSchema.ANYURI, "urn:person")), new RyaStatement(aliceSSN, new RyaURI("urn:name"), new RyaType(XMLSchema.STRING, "Alice")), new RyaStatement(aliceSSN, new RyaURI("urn:age"), new RyaType(XMLSchema.INT, "30")), new RyaStatement(aliceSSN, new RyaURI("urn:eye"), new RyaType(XMLSchema.STRING, "blue")), new RyaStatement(bobSSN, new RyaURI("urn:name"), new RyaType(XMLSchema.STRING, "Bob")), new RyaStatement(bobSSN, new RyaURI("urn:hoursPerWeek"), new RyaType(XMLSchema.INT, "40")), new RyaStatement(bobSSN, new RyaURI(RDF.TYPE.toString()), new RyaType(XMLSchema.ANYURI, "urn:employee"))));
        // Fetch the Entity from storage and ensure it looks correct.
        final EntityStorage entities = new MongoEntityStorage(getMongoClient(), conf.getRyaInstanceName());
        final Entity alice = entities.get(aliceSSN).get();
        final Entity bob = entities.get(bobSSN).get();
        final Set<Entity> storedEntities = Sets.newHashSet(alice, bob);
        final Entity expectedAlice = Entity.builder().setSubject(aliceSSN).setExplicitType(new RyaURI("urn:person")).setProperty(new RyaURI("urn:person"), new Property(new RyaURI("urn:name"), new RyaType(XMLSchema.STRING, "Alice"))).setProperty(new RyaURI("urn:person"), new Property(new RyaURI("urn:age"), new RyaType(XMLSchema.INT, "30"))).setProperty(new RyaURI("urn:person"), new Property(new RyaURI("urn:eye"), new RyaType(XMLSchema.STRING, "blue"))).setProperty(new RyaURI("urn:employee"), new Property(new RyaURI("urn:name"), new RyaType(XMLSchema.STRING, "Alice"))).setVersion(alice.getVersion()).build();
        final Entity expectedBob = Entity.builder().setSubject(bobSSN).setExplicitType(new RyaURI("urn:employee")).setProperty(new RyaURI("urn:employee"), new Property(new RyaURI("urn:name"), new RyaType(XMLSchema.STRING, "Bob"))).setProperty(new RyaURI("urn:employee"), new Property(new RyaURI("urn:hoursPerWeek"), new RyaType(XMLSchema.INT, "40"))).setProperty(new RyaURI("urn:person"), new Property(new RyaURI("urn:name"), new RyaType(XMLSchema.STRING, "Bob"))).setVersion(bob.getVersion()).build();
        final Set<Entity> expected = Sets.newHashSet(expectedAlice, expectedBob);
        assertEquals(expected, storedEntities);
    }
}
Also used : MongoTypeStorage(org.apache.rya.indexing.entity.storage.mongo.MongoTypeStorage) TypeStorage(org.apache.rya.indexing.entity.storage.TypeStorage) RyaURI(org.apache.rya.api.domain.RyaURI) Entity(org.apache.rya.indexing.entity.model.Entity) MongoTypeStorage(org.apache.rya.indexing.entity.storage.mongo.MongoTypeStorage) MongoEntityStorage(org.apache.rya.indexing.entity.storage.mongo.MongoEntityStorage) EntityStorage(org.apache.rya.indexing.entity.storage.EntityStorage) MongoEntityStorage(org.apache.rya.indexing.entity.storage.mongo.MongoEntityStorage) RyaStatement(org.apache.rya.api.domain.RyaStatement) RyaType(org.apache.rya.api.domain.RyaType) Property(org.apache.rya.indexing.entity.model.Property) Test(org.junit.Test)

Example 38 with Entity

use of org.apache.rya.indexing.entity.model.Entity in project incubator-rya by apache.

the class MongoEntityIndexerIT method deleteStatement_deletesProperty.

@Test
public void deleteStatement_deletesProperty() throws Exception {
    try (MongoEntityIndexer indexer = new MongoEntityIndexer()) {
        indexer.setConf(conf);
        indexer.init();
        // Load the type into the TypeStorage.
        final TypeStorage types = new MongoTypeStorage(getMongoClient(), conf.getRyaInstanceName());
        types.create(PERSON_TYPE);
        types.create(EMPLOYEE_TYPE);
        // Index a bunch of RyaStatements.
        final RyaURI aliceSSN = new RyaURI("urn:SSN/111-11-1111");
        indexer.storeStatements(Sets.newHashSet(new RyaStatement(aliceSSN, new RyaURI(RDF.TYPE.toString()), new RyaType(XMLSchema.ANYURI, "urn:person")), new RyaStatement(aliceSSN, new RyaURI("urn:name"), new RyaType(XMLSchema.STRING, "Alice")), new RyaStatement(aliceSSN, new RyaURI("urn:age"), new RyaType(XMLSchema.INT, "30")), new RyaStatement(aliceSSN, new RyaURI("urn:eye"), new RyaType(XMLSchema.STRING, "blue"))));
        // Remove the name property from Alice.
        indexer.deleteStatement(new RyaStatement(aliceSSN, new RyaURI("urn:name"), new RyaType(XMLSchema.STRING, "Alice")));
        // Fetch the Entity from storage and ensure it looks correct.
        final EntityStorage entities = new MongoEntityStorage(getMongoClient(), conf.getRyaInstanceName());
        final Entity entity = entities.get(new RyaURI("urn:SSN/111-11-1111")).get();
        final Entity expected = Entity.builder().setSubject(aliceSSN).setExplicitType(new RyaURI("urn:person")).setProperty(new RyaURI("urn:person"), new Property(new RyaURI("urn:age"), new RyaType(XMLSchema.INT, "30"))).setProperty(new RyaURI("urn:person"), new Property(new RyaURI("urn:eye"), new RyaType(XMLSchema.STRING, "blue"))).setVersion(entity.getVersion()).build();
        assertEquals(expected, entity);
    }
}
Also used : MongoTypeStorage(org.apache.rya.indexing.entity.storage.mongo.MongoTypeStorage) TypeStorage(org.apache.rya.indexing.entity.storage.TypeStorage) RyaURI(org.apache.rya.api.domain.RyaURI) Entity(org.apache.rya.indexing.entity.model.Entity) MongoTypeStorage(org.apache.rya.indexing.entity.storage.mongo.MongoTypeStorage) MongoEntityStorage(org.apache.rya.indexing.entity.storage.mongo.MongoEntityStorage) EntityStorage(org.apache.rya.indexing.entity.storage.EntityStorage) MongoEntityStorage(org.apache.rya.indexing.entity.storage.mongo.MongoEntityStorage) RyaStatement(org.apache.rya.api.domain.RyaStatement) RyaType(org.apache.rya.api.domain.RyaType) Property(org.apache.rya.indexing.entity.model.Property) Test(org.junit.Test)

Example 39 with Entity

use of org.apache.rya.indexing.entity.model.Entity in project incubator-rya by apache.

the class MongoEntityIndexerIT method addStatement_setsProperty.

@Test
public void addStatement_setsProperty() throws Exception {
    try (MongoEntityIndexer indexer = new MongoEntityIndexer()) {
        indexer.setConf(conf);
        indexer.init();
        // Load the types into the TypeStorage.
        final TypeStorage types = new MongoTypeStorage(getMongoClient(), conf.getRyaInstanceName());
        types.create(PERSON_TYPE);
        types.create(EMPLOYEE_TYPE);
        // Index a RyaStatement that will create an Entity with two implicit types.
        final RyaStatement statement = new RyaStatement(new RyaURI("urn:SSN/111-11-1111"), new RyaURI("urn:name"), new RyaType(XMLSchema.STRING, "Alice"));
        indexer.storeStatement(statement);
        // Fetch the Entity from storage and ensure it looks correct.
        final EntityStorage entities = new MongoEntityStorage(getMongoClient(), conf.getRyaInstanceName());
        final Entity entity = entities.get(new RyaURI("urn:SSN/111-11-1111")).get();
        final Entity expected = Entity.builder().setSubject(new RyaURI("urn:SSN/111-11-1111")).setProperty(new RyaURI("urn:person"), new Property(new RyaURI("urn:name"), new RyaType(XMLSchema.STRING, "Alice"))).setProperty(new RyaURI("urn:employee"), new Property(new RyaURI("urn:name"), new RyaType(XMLSchema.STRING, "Alice"))).build();
        assertEquals(expected, entity);
    }
}
Also used : MongoTypeStorage(org.apache.rya.indexing.entity.storage.mongo.MongoTypeStorage) TypeStorage(org.apache.rya.indexing.entity.storage.TypeStorage) RyaURI(org.apache.rya.api.domain.RyaURI) Entity(org.apache.rya.indexing.entity.model.Entity) MongoTypeStorage(org.apache.rya.indexing.entity.storage.mongo.MongoTypeStorage) MongoEntityStorage(org.apache.rya.indexing.entity.storage.mongo.MongoEntityStorage) EntityStorage(org.apache.rya.indexing.entity.storage.EntityStorage) MongoEntityStorage(org.apache.rya.indexing.entity.storage.mongo.MongoEntityStorage) RyaStatement(org.apache.rya.api.domain.RyaStatement) RyaType(org.apache.rya.api.domain.RyaType) Property(org.apache.rya.indexing.entity.model.Property) Test(org.junit.Test)

Example 40 with Entity

use of org.apache.rya.indexing.entity.model.Entity in project incubator-rya by apache.

the class MongoEntityIndexerIT method addStatement_setsType.

@Test
public void addStatement_setsType() throws Exception {
    try (MongoEntityIndexer indexer = new MongoEntityIndexer()) {
        indexer.setConf(conf);
        indexer.init();
        // Load a type into the TypeStorage.
        final TypeStorage types = new MongoTypeStorage(getMongoClient(), conf.getRyaInstanceName());
        types.create(PERSON_TYPE);
        // Index a RyaStatement that will create an Entity with an explicit type.
        final RyaStatement statement = new RyaStatement(new RyaURI("urn:SSN/111-11-1111"), new RyaURI(RDF.TYPE.toString()), new RyaType(XMLSchema.ANYURI, "urn:person"));
        indexer.storeStatement(statement);
        // Fetch the Entity from storage and ensure it looks correct.
        final EntityStorage entities = new MongoEntityStorage(getMongoClient(), conf.getRyaInstanceName());
        final Entity entity = entities.get(new RyaURI("urn:SSN/111-11-1111")).get();
        final Entity expected = Entity.builder().setSubject(new RyaURI("urn:SSN/111-11-1111")).setExplicitType(new RyaURI("urn:person")).build();
        assertEquals(expected, entity);
    }
}
Also used : MongoTypeStorage(org.apache.rya.indexing.entity.storage.mongo.MongoTypeStorage) TypeStorage(org.apache.rya.indexing.entity.storage.TypeStorage) RyaURI(org.apache.rya.api.domain.RyaURI) Entity(org.apache.rya.indexing.entity.model.Entity) MongoTypeStorage(org.apache.rya.indexing.entity.storage.mongo.MongoTypeStorage) MongoEntityStorage(org.apache.rya.indexing.entity.storage.mongo.MongoEntityStorage) EntityStorage(org.apache.rya.indexing.entity.storage.EntityStorage) MongoEntityStorage(org.apache.rya.indexing.entity.storage.mongo.MongoEntityStorage) RyaStatement(org.apache.rya.api.domain.RyaStatement) RyaType(org.apache.rya.api.domain.RyaType) Test(org.junit.Test)

Aggregations

Entity (org.apache.rya.indexing.entity.model.Entity)40 RyaURI (org.apache.rya.api.domain.RyaURI)31 Test (org.junit.Test)29 Property (org.apache.rya.indexing.entity.model.Property)24 EntityStorage (org.apache.rya.indexing.entity.storage.EntityStorage)23 RyaType (org.apache.rya.api.domain.RyaType)22 TypedEntity (org.apache.rya.indexing.entity.model.TypedEntity)13 TypeStorage (org.apache.rya.indexing.entity.storage.TypeStorage)11 MongoEntityStorage (org.apache.rya.indexing.entity.storage.mongo.MongoEntityStorage)11 ReflectionToStringBuilder (org.apache.commons.lang.builder.ReflectionToStringBuilder)8 Builder (org.apache.rya.indexing.entity.model.Entity.Builder)8 MongoTypeStorage (org.apache.rya.indexing.entity.storage.mongo.MongoTypeStorage)8 RyaStatement (org.apache.rya.api.domain.RyaStatement)7 Type (org.apache.rya.indexing.entity.model.Type)6 URI (org.openrdf.model.URI)4 URIImpl (org.openrdf.model.impl.URIImpl)4 RyaTypeUtils.booleanRyaType (org.apache.rya.api.domain.RyaTypeUtils.booleanRyaType)3 RyaTypeUtils.byteRyaType (org.apache.rya.api.domain.RyaTypeUtils.byteRyaType)3 RyaTypeUtils.dateRyaType (org.apache.rya.api.domain.RyaTypeUtils.dateRyaType)3 RyaTypeUtils.doubleRyaType (org.apache.rya.api.domain.RyaTypeUtils.doubleRyaType)3