Search in sources :

Example 11 with JsonQuery

use of io.lumeer.api.dto.JsonQuery 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 12 with JsonQuery

use of io.lumeer.api.dto.JsonQuery 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 13 with JsonQuery

use of io.lumeer.api.dto.JsonQuery in project engine by Lumeer.

the class LinkTypeServiceIT method testGetLinkTypesByCollectionIds.

@Test
public void testGetLinkTypesByCollectionIds() {
    String id1 = linkTypeDao.createLinkType(prepareLinkType()).getId();
    LinkType linkType2 = prepareLinkType();
    linkType2.setCollectionIds(Arrays.asList(collectionIds.get(1), collectionIds.get(2)));
    linkTypeDao.createLinkType(linkType2);
    LinkType linkType3 = prepareLinkType();
    linkType3.setCollectionIds(Arrays.asList(collectionIds.get(1), collectionIds.get(0)));
    String id3 = linkTypeDao.createLinkType(linkType3).getId();
    LinkType linkType4 = prepareLinkType();
    linkType4.setCollectionIds(Arrays.asList(collectionIds.get(0), collectionIds.get(2)));
    String id4 = linkTypeDao.createLinkType(linkType4).getId();
    JsonQuery jsonQuery = new JsonQuery(Collections.singleton(collectionIds.get(0)), null, null);
    Entity entity = Entity.json(jsonQuery);
    Response response = client.target(LINK_TYPES_URL).path("search").request(MediaType.APPLICATION_JSON).buildPost(entity).invoke();
    assertThat(response).isNotNull();
    assertThat(response.getStatusInfo()).isEqualTo(Response.Status.OK);
    List<LinkType> linkTypes = response.readEntity(new GenericType<List<LinkType>>() {
    });
    assertThat(linkTypes).extracting("id").containsOnlyElementsOf(Arrays.asList(id1, id3, id4));
}
Also used : Response(javax.ws.rs.core.Response) Entity(javax.ws.rs.client.Entity) JsonQuery(io.lumeer.api.dto.JsonQuery) ArrayList(java.util.ArrayList) List(java.util.List) LinkType(io.lumeer.api.model.LinkType) Test(org.junit.Test)

Example 14 with JsonQuery

use of io.lumeer.api.dto.JsonQuery in project engine by Lumeer.

the class SearchFacadeIT method testSearchDocumentsByCollectionIds.

@Test
public void testSearchDocumentsByCollectionIds() {
    String id1 = createDocument(collectionIds.get(0), "doc1").getId();
    String id2 = createDocument(collectionIds.get(0), "doc2").getId();
    createDocument(collectionIds.get(1), "doc3");
    createDocument(collectionIds.get(1), "doc4");
    String id5 = createDocument(collectionIds.get(2), "doc5").getId();
    String id6 = createDocument(collectionIds.get(2), "doc6").getId();
    List<Document> documents = searchFacade.searchDocuments(new JsonQuery(new HashSet<>(Arrays.asList(collectionIds.get(0), collectionIds.get(2))), null, null));
    assertThat(documents).extracting(Document::getId).containsOnly(id1, id2, id5, id6);
}
Also used : JsonQuery(io.lumeer.api.dto.JsonQuery) DataDocument(io.lumeer.engine.api.data.DataDocument) JsonDocument(io.lumeer.api.dto.JsonDocument) Document(io.lumeer.api.model.Document) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 15 with JsonQuery

use of io.lumeer.api.dto.JsonQuery in project engine by Lumeer.

the class SearchFacadeIT method testSearchCollectionsByCollectionIds.

@Test
public void testSearchCollectionsByCollectionIds() {
    List<Collection> collections = searchFacade.searchCollections(new JsonQuery(new HashSet<>(Arrays.asList(collectionIds.get(0), collectionIds.get(2))), null, null));
    assertThat(collections).extracting(Collection::getId).containsOnly(collectionIds.get(0), collectionIds.get(2));
    collections = searchFacade.searchCollections(new JsonQuery(Collections.singleton(collectionIds.get(1)), null, null));
    assertThat(collections).extracting(Collection::getId).containsOnly(collectionIds.get(1));
}
Also used : JsonQuery(io.lumeer.api.dto.JsonQuery) JsonCollection(io.lumeer.api.dto.JsonCollection) Collection(io.lumeer.api.model.Collection) HashSet(java.util.HashSet) Test(org.junit.Test)

Aggregations

JsonQuery (io.lumeer.api.dto.JsonQuery)18 Test (org.junit.Test)16 JsonCollection (io.lumeer.api.dto.JsonCollection)5 JsonDocument (io.lumeer.api.dto.JsonDocument)5 Collection (io.lumeer.api.model.Collection)5 Document (io.lumeer.api.model.Document)5 DataDocument (io.lumeer.engine.api.data.DataDocument)5 ArrayList (java.util.ArrayList)4 HashSet (java.util.HashSet)4 List (java.util.List)4 Entity (javax.ws.rs.client.Entity)4 Response (javax.ws.rs.core.Response)4 LinkInstance (io.lumeer.api.model.LinkInstance)3 LinkType (io.lumeer.api.model.LinkType)3 JsonView (io.lumeer.api.dto.JsonView)2 GenericType (javax.ws.rs.core.GenericType)2 JsonPermissions (io.lumeer.api.dto.JsonPermissions)1 Document (org.bson.Document)1