Search in sources :

Example 16 with LinkInstance

use of io.lumeer.api.model.LinkInstance in project engine by Lumeer.

the class LinkInstanceServiceIT method testGetLinkInstancesByLinkTypeIds.

@Test
public void testGetLinkInstancesByLinkTypeIds() {
    String id1 = linkInstanceDao.createLinkInstance(prepareLinkInstance()).getId();
    LinkInstance linkInstance2 = prepareLinkInstance();
    linkInstance2.setLinkTypeId(linkTypeId1);
    linkInstance2.setDocumentIds(Arrays.asList(documentIdsColl1.get(0), documentIdsColl2.get(2)));
    String id2 = linkInstanceDao.createLinkInstance(linkInstance2).getId();
    LinkInstance linkInstance3 = prepareLinkInstance();
    linkInstance3.setLinkTypeId(linkTypeId1);
    linkInstance3.setDocumentIds(Arrays.asList(documentIdsColl1.get(1), documentIdsColl2.get(1)));
    String id3 = linkInstanceDao.createLinkInstance(linkInstance3).getId();
    LinkInstance linkInstance4 = prepareLinkInstance();
    linkInstance4.setLinkTypeId(linkTypeId2);
    linkInstance4.setDocumentIds(Arrays.asList(documentIdsColl1.get(0), documentIdsColl2.get(0)));
    String id4 = linkInstanceDao.createLinkInstance(linkInstance4).getId();
    JsonQuery jsonQuery1 = new JsonQuery(null, new HashSet<>(Arrays.asList(linkTypeId1, linkTypeId2)), null);
    Entity entity1 = Entity.json(jsonQuery1);
    Response response = client.target(LINK_INSTANCES_URL).path("search").request(MediaType.APPLICATION_JSON).buildPost(entity1).invoke();
    assertThat(response).isNotNull();
    assertThat(response.getStatusInfo()).isEqualTo(Response.Status.OK);
    List<LinkInstance> linkInstances = response.readEntity(new GenericType<List<LinkInstance>>() {
    });
    assertThat(linkInstances).extracting("id").containsOnlyElementsOf(Arrays.asList(id1, id2, id3, id4));
    JsonQuery jsonQuery2 = new JsonQuery(null, Collections.singleton(linkTypeId1), null);
    Entity entity2 = Entity.json(jsonQuery2);
    response = client.target(LINK_INSTANCES_URL).path("search").request(MediaType.APPLICATION_JSON).buildPost(entity2).invoke();
    assertThat(response).isNotNull();
    assertThat(response.getStatusInfo()).isEqualTo(Response.Status.OK);
    linkInstances = response.readEntity(new GenericType<List<LinkInstance>>() {
    });
    assertThat(linkInstances).extracting("id").containsOnlyElementsOf(Arrays.asList(id1, id2, id3));
}
Also used : Response(javax.ws.rs.core.Response) Entity(javax.ws.rs.client.Entity) GenericType(javax.ws.rs.core.GenericType) JsonQuery(io.lumeer.api.dto.JsonQuery) ArrayList(java.util.ArrayList) List(java.util.List) LinkInstance(io.lumeer.api.model.LinkInstance) Test(org.junit.Test)

Example 17 with LinkInstance

use of io.lumeer.api.model.LinkInstance in project engine by Lumeer.

the class LinkInstanceServiceIT method testGetLinkInstancesByDocumentIds.

@Test
public void testGetLinkInstancesByDocumentIds() {
    String id1 = linkInstanceDao.createLinkInstance(prepareLinkInstance()).getId();
    LinkInstance linkInstance2 = prepareLinkInstance();
    linkInstance2.setLinkTypeId(linkTypeId1);
    linkInstance2.setDocumentIds(Arrays.asList(documentIdsColl1.get(0), documentIdsColl2.get(2)));
    String id2 = linkInstanceDao.createLinkInstance(linkInstance2).getId();
    LinkInstance linkInstance3 = prepareLinkInstance();
    linkInstance3.setLinkTypeId(linkTypeId1);
    linkInstance3.setDocumentIds(Arrays.asList(documentIdsColl1.get(1), documentIdsColl2.get(1)));
    String id3 = linkInstanceDao.createLinkInstance(linkInstance3).getId();
    LinkInstance linkInstance4 = prepareLinkInstance();
    linkInstance4.setLinkTypeId(linkTypeId2);
    linkInstance4.setDocumentIds(Arrays.asList(documentIdsColl1.get(0), documentIdsColl2.get(0)));
    String id4 = linkInstanceDao.createLinkInstance(linkInstance4).getId();
    JsonQuery jsonQuery1 = new JsonQuery(null, null, Collections.singleton(documentIdsColl1.get(0)));
    Entity entity1 = Entity.json(jsonQuery1);
    Response response = client.target(LINK_INSTANCES_URL).path("search").request(MediaType.APPLICATION_JSON).buildPost(entity1).invoke();
    assertThat(response).isNotNull();
    assertThat(response.getStatusInfo()).isEqualTo(Response.Status.OK);
    List<LinkInstance> linkInstances = response.readEntity(new GenericType<List<LinkInstance>>() {
    });
    assertThat(linkInstances).extracting("id").containsOnlyElementsOf(Arrays.asList(id1, id2, id4));
    JsonQuery jsonQuery2 = new JsonQuery(null, null, Collections.singleton(documentIdsColl2.get(1)));
    Entity entity2 = Entity.json(jsonQuery2);
    response = client.target(LINK_INSTANCES_URL).path("search").request(MediaType.APPLICATION_JSON).buildPost(entity2).invoke();
    assertThat(response).isNotNull();
    assertThat(response.getStatusInfo()).isEqualTo(Response.Status.OK);
    linkInstances = response.readEntity(new GenericType<List<LinkInstance>>() {
    });
    assertThat(linkInstances).extracting("id").containsOnlyElementsOf(Collections.singletonList(id3));
}
Also used : Response(javax.ws.rs.core.Response) Entity(javax.ws.rs.client.Entity) GenericType(javax.ws.rs.core.GenericType) JsonQuery(io.lumeer.api.dto.JsonQuery) ArrayList(java.util.ArrayList) List(java.util.List) LinkInstance(io.lumeer.api.model.LinkInstance) Test(org.junit.Test)

Example 18 with LinkInstance

use of io.lumeer.api.model.LinkInstance in project engine by Lumeer.

the class LinkInstanceServiceIT method testUpdateLinkInstance.

@Test
public void testUpdateLinkInstance() {
    LinkInstance linkInstance = prepareLinkInstance();
    String id = linkInstanceDao.createLinkInstance(linkInstance).getId();
    LinkInstance updateLinkedInstance = prepareLinkInstance();
    updateLinkedInstance.setLinkTypeId(linkTypeId2);
    updateLinkedInstance.setDocumentIds(Arrays.asList(documentIdsColl1.get(1), documentIdsColl2.get(1)));
    Entity entity = Entity.json(updateLinkedInstance);
    Response response = client.target(LINK_INSTANCES_URL).path(id).request(MediaType.APPLICATION_JSON).buildPut(entity).invoke();
    assertThat(response).isNotNull();
    assertThat(response.getStatusInfo()).isEqualTo(Response.Status.OK);
    LinkInstance returnedLinkInstance = response.readEntity(LinkInstance.class);
    assertThat(returnedLinkInstance).isNotNull();
    assertThat(returnedLinkInstance).isNotNull();
    assertThat(returnedLinkInstance.getLinkTypeId()).isEqualTo(linkTypeId2);
    assertThat(returnedLinkInstance.getDocumentIds()).containsOnlyElementsOf(Arrays.asList(documentIdsColl1.get(1), documentIdsColl2.get(1)));
    assertThat(returnedLinkInstance.getData().keySet()).containsOnlyElementsOf(DATA.keySet());
    LinkInstance storedLinkInstance = linkInstanceDao.getLinkInstance(id);
    assertThat(storedLinkInstance.getLinkTypeId()).isEqualTo(linkTypeId2);
    assertThat(storedLinkInstance.getDocumentIds()).containsOnlyElementsOf(Arrays.asList(documentIdsColl1.get(1), documentIdsColl2.get(1)));
    assertThat(storedLinkInstance.getData().keySet()).containsOnlyElementsOf(DATA.keySet());
}
Also used : Response(javax.ws.rs.core.Response) Entity(javax.ws.rs.client.Entity) LinkInstance(io.lumeer.api.model.LinkInstance) Test(org.junit.Test)

Example 19 with LinkInstance

use of io.lumeer.api.model.LinkInstance in project engine by Lumeer.

the class LinkInstanceServiceIT method testCreateLinkInstance.

@Test
public void testCreateLinkInstance() {
    LinkInstance linkInstance = prepareLinkInstance();
    Entity entity = Entity.json(linkInstance);
    Response response = client.target(LINK_INSTANCES_URL).request(MediaType.APPLICATION_JSON).buildPost(entity).invoke();
    assertThat(response).isNotNull();
    assertThat(response.getStatusInfo()).isEqualTo(Response.Status.OK);
    LinkInstance returnedLinkInstance = response.readEntity(LinkInstance.class);
    assertThat(returnedLinkInstance).isNotNull();
    assertThat(returnedLinkInstance.getLinkTypeId()).isEqualTo(linkTypeId1);
    assertThat(returnedLinkInstance.getDocumentIds()).containsOnlyElementsOf(Arrays.asList(documentIdsColl1.get(0), documentIdsColl2.get(0)));
    assertThat(returnedLinkInstance.getData().keySet()).containsOnlyElementsOf(DATA.keySet());
}
Also used : Response(javax.ws.rs.core.Response) Entity(javax.ws.rs.client.Entity) LinkInstance(io.lumeer.api.model.LinkInstance) Test(org.junit.Test)

Example 20 with LinkInstance

use of io.lumeer.api.model.LinkInstance in project engine by Lumeer.

the class LinkInstanceCodec method decode.

@Override
public LinkInstance decode(final BsonReader reader, final DecoderContext decoderContext) {
    Document bson = documentCodec.decode(reader, decoderContext);
    String id = bson.getObjectId(ID).toHexString();
    String linkTypeId = bson.getString(LINK_TYPE_ID);
    List<String> documentIds = bson.get(DOCUMENTS_IDS, List.class);
    Map<String, Object> data = bson.get(DATA, Map.class);
    return new LinkInstance(id, linkTypeId, documentIds, data);
}
Also used : LinkInstance(io.lumeer.api.model.LinkInstance) Document(org.bson.Document)

Aggregations

LinkInstance (io.lumeer.api.model.LinkInstance)20 Test (org.junit.Test)17 Response (javax.ws.rs.core.Response)5 SearchQuery (io.lumeer.storage.api.query.SearchQuery)4 ArrayList (java.util.ArrayList)4 Entity (javax.ws.rs.client.Entity)4 JsonQuery (io.lumeer.api.dto.JsonQuery)3 HashSet (java.util.HashSet)3 List (java.util.List)2 GenericType (javax.ws.rs.core.GenericType)2 LinkType (io.lumeer.api.model.LinkType)1 Document (org.bson.Document)1