Search in sources :

Example 6 with CreateEntity

use of nl.knaw.huygens.timbuctoo.core.dto.CreateEntity in project timbuctoo by HuygensING.

the class TinkerPopOperationsTest method createEntityMarksOneVertexAsLatest.

@Test
public void createEntityMarksOneVertexAsLatest() throws Exception {
    TinkerPopGraphManager graphManager = newGraph().wrap();
    Vres vres = createConfiguration();
    Collection collection = vres.getCollection("testthings").get();
    TinkerPopOperations instance = forGraphWrapperAndMappings(graphManager, vres);
    List<TimProperty<?>> properties = Lists.newArrayList();
    CreateEntity createEntity = withProperties(properties);
    instance.createEntity(collection, Optional.empty(), createEntity);
    assertThat(graphManager.getGraph().traversal().V().has("tim_id", createEntity.getId().toString()).has("isLatest", true).count().next(), is(1L));
}
Also used : CreateEntity(nl.knaw.huygens.timbuctoo.core.dto.CreateEntity) Vres(nl.knaw.huygens.timbuctoo.model.vre.Vres) TinkerPopGraphManager(nl.knaw.huygens.timbuctoo.server.TinkerPopGraphManager) TimProperty(nl.knaw.huygens.timbuctoo.core.dto.property.TimProperty) CreateCollection(nl.knaw.huygens.timbuctoo.core.dto.CreateCollection) Collection(nl.knaw.huygens.timbuctoo.core.dto.dataset.Collection) Test(org.junit.Test)

Example 7 with CreateEntity

use of nl.knaw.huygens.timbuctoo.core.dto.CreateEntity in project timbuctoo by HuygensING.

the class TinkerPopOperationsTest method createEntityDuplicatesTheVertex.

@Test
public void createEntityDuplicatesTheVertex() throws Exception {
    TinkerPopGraphManager graphManager = newGraph().wrap();
    Vres vres = createConfiguration();
    Collection collection = vres.getCollection("testthings").get();
    TinkerPopOperations instance = forGraphWrapperAndMappings(graphManager, vres);
    List<TimProperty<?>> properties = Lists.newArrayList();
    CreateEntity createEntity = withProperties(properties);
    instance.createEntity(collection, Optional.empty(), createEntity);
    assertThat(graphManager.getGraph().traversal().V().has("tim_id", createEntity.getId().toString()).count().next(), is(2L));
}
Also used : CreateEntity(nl.knaw.huygens.timbuctoo.core.dto.CreateEntity) Vres(nl.knaw.huygens.timbuctoo.model.vre.Vres) TinkerPopGraphManager(nl.knaw.huygens.timbuctoo.server.TinkerPopGraphManager) TimProperty(nl.knaw.huygens.timbuctoo.core.dto.property.TimProperty) CreateCollection(nl.knaw.huygens.timbuctoo.core.dto.CreateCollection) Collection(nl.knaw.huygens.timbuctoo.core.dto.dataset.Collection) Test(org.junit.Test)

Example 8 with CreateEntity

use of nl.knaw.huygens.timbuctoo.core.dto.CreateEntity in project timbuctoo by HuygensING.

the class TimbuctooActions method createEntity.

public UUID createEntity(Collection collection, Optional<Collection> baseCollection, Iterable<TimProperty<?>> properties, User user) throws PermissionFetchingException, IOException {
    checkIfAllowedToWrite(user, collection);
    UUID id = UUID.randomUUID();
    Change created = createChange(user);
    CreateEntity createEntity = ImmutableCreateEntity.builder().properties(properties).id(id).created(created).build();
    dataStoreOperations.createEntity(collection, baseCollection, createEntity);
    afterSuccessTaskExecutor.addTask(new AddPersistentUrlTask(persistentUrlCreator, uriToRedirectToFromPersistentUrls.apply(collection.getCollectionName(), id, 1), ImmutableEntityLookup.builder().rev(1).timId(id).collection(collection.getCollectionName()).build()));
    return id;
}
Also used : ImmutableCreateEntity(nl.knaw.huygens.timbuctoo.core.dto.ImmutableCreateEntity) CreateEntity(nl.knaw.huygens.timbuctoo.core.dto.CreateEntity) Change(nl.knaw.huygens.timbuctoo.model.Change) UUID(java.util.UUID)

Aggregations

CreateEntity (nl.knaw.huygens.timbuctoo.core.dto.CreateEntity)8 CreateCollection (nl.knaw.huygens.timbuctoo.core.dto.CreateCollection)7 Collection (nl.knaw.huygens.timbuctoo.core.dto.dataset.Collection)7 TimProperty (nl.knaw.huygens.timbuctoo.core.dto.property.TimProperty)7 Vres (nl.knaw.huygens.timbuctoo.model.vre.Vres)7 TinkerPopGraphManager (nl.knaw.huygens.timbuctoo.server.TinkerPopGraphManager)7 Test (org.junit.Test)7 StringProperty (nl.knaw.huygens.timbuctoo.core.dto.property.StringProperty)2 UUID (java.util.UUID)1 ImmutableCreateEntity (nl.knaw.huygens.timbuctoo.core.dto.ImmutableCreateEntity)1 Change (nl.knaw.huygens.timbuctoo.model.Change)1 Matchers.containsString (org.hamcrest.Matchers.containsString)1 Matchers.anyString (org.mockito.Matchers.anyString)1