Search in sources :

Example 6 with LinkInstance

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

the class LinkInstanceFacadeIT method testDeleteLinkInstance.

@Test
public void testDeleteLinkInstance() {
    LinkInstance created = linkInstanceFacade.createLinkInstance(prepareLinkInstance());
    assertThat(created.getId()).isNotNull();
    linkInstanceFacade.deleteLinkInstance(created.getId());
    assertThatThrownBy(() -> linkInstanceDao.getLinkInstance(created.getId())).isInstanceOf(StorageException.class);
}
Also used : LinkInstance(io.lumeer.api.model.LinkInstance) Test(org.junit.Test)

Example 7 with LinkInstance

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

the class LinkInstanceFacadeIT method testGetLinkInstances.

@Test
public void testGetLinkInstances() {
    String id1 = linkInstanceFacade.createLinkInstance(prepareLinkInstance()).getId();
    LinkInstance linkInstance2 = prepareLinkInstance();
    linkInstance2.setLinkTypeId(linkTypeId1);
    linkInstance2.setDocumentIds(Arrays.asList(documentIdsColl1.get(0), documentIdsColl2.get(2)));
    String id2 = linkInstanceFacade.createLinkInstance(linkInstance2).getId();
    LinkInstance linkInstance3 = prepareLinkInstance();
    linkInstance3.setLinkTypeId(linkTypeId1);
    linkInstance3.setDocumentIds(Arrays.asList(documentIdsColl1.get(1), documentIdsColl2.get(1)));
    String id3 = linkInstanceFacade.createLinkInstance(linkInstance3).getId();
    LinkInstance linkInstance4 = prepareLinkInstance();
    linkInstance4.setLinkTypeId(linkTypeId2);
    linkInstance4.setDocumentIds(Arrays.asList(documentIdsColl1.get(0), documentIdsColl2.get(0)));
    String id4 = linkInstanceFacade.createLinkInstance(linkInstance4).getId();
    JsonQuery jsonQuery1 = new JsonQuery(null, null, Collections.singleton(documentIdsColl1.get(0)));
    List<LinkInstance> linkInstances = linkInstanceFacade.getLinkInstances(jsonQuery1);
    assertThat(linkInstances).extracting("id").containsOnlyElementsOf(Arrays.asList(id1, id2, id4));
    JsonQuery jsonQuery2 = new JsonQuery(null, null, Collections.singleton(documentIdsColl2.get(1)));
    linkInstances = linkInstanceFacade.getLinkInstances(jsonQuery2);
    assertThat(linkInstances).extracting("id").containsOnlyElementsOf(Collections.singletonList(id3));
    JsonQuery jsonQuery3 = new JsonQuery(null, new HashSet<>(Arrays.asList(linkTypeId1, linkTypeId2)), null);
    linkInstances = linkInstanceFacade.getLinkInstances(jsonQuery3);
    assertThat(linkInstances).extracting("id").containsOnlyElementsOf(Arrays.asList(id1, id2, id3, id4));
    JsonQuery jsonQuery4 = new JsonQuery(null, Collections.singleton(linkTypeId1), null);
    linkInstances = linkInstanceFacade.getLinkInstances(jsonQuery4);
    assertThat(linkInstances).extracting("id").containsOnlyElementsOf(Arrays.asList(id1, id2, id3));
}
Also used : JsonQuery(io.lumeer.api.dto.JsonQuery) LinkInstance(io.lumeer.api.model.LinkInstance) Test(org.junit.Test)

Example 8 with LinkInstance

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

the class LinkInstanceFacadeIT method testCreateLinkInstance.

@Test
public void testCreateLinkInstance() {
    LinkInstance linkInstance = prepareLinkInstance();
    String id = linkInstanceFacade.createLinkInstance(linkInstance).getId();
    assertThat(id).isNotNull().isNotEmpty();
    assertThat(ObjectId.isValid(id)).isTrue();
    LinkInstance storedLinkInstance = linkInstanceDao.getLinkInstance(id);
    assertThat(storedLinkInstance).isNotNull();
    assertThat(storedLinkInstance.getLinkTypeId()).isEqualTo(linkTypeId1);
    assertThat(storedLinkInstance.getDocumentIds()).containsOnlyElementsOf(Arrays.asList(documentIdsColl1.get(0), documentIdsColl2.get(0)));
    assertThat(storedLinkInstance.getData().keySet()).containsOnlyElementsOf(DATA.keySet());
}
Also used : LinkInstance(io.lumeer.api.model.LinkInstance) Test(org.junit.Test)

Example 9 with LinkInstance

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

the class LinkInstanceServiceIT method testDeleteLinkInstance.

@Test
public void testDeleteLinkInstance() {
    LinkInstance created = linkInstanceDao.createLinkInstance(prepareLinkInstance());
    assertThat(created.getId()).isNotNull();
    Response response = client.target(LINK_INSTANCES_URL).path(created.getId()).request(MediaType.APPLICATION_JSON).buildDelete().invoke();
    assertThat(response).isNotNull();
    assertThat(response.getStatusInfo()).isEqualTo(Response.Status.OK);
    assertThat(response.getLinks()).extracting(Link::getUri).containsOnly(UriBuilder.fromUri(LINK_INSTANCES_URL).build());
    assertThatThrownBy(() -> linkInstanceDao.getLinkInstance(created.getId())).isInstanceOf(StorageException.class);
}
Also used : Response(javax.ws.rs.core.Response) LinkInstance(io.lumeer.api.model.LinkInstance) Test(org.junit.Test)

Example 10 with LinkInstance

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

the class LinkInstanceFacade method updateLinkInstance.

public LinkInstance updateLinkInstance(String id, LinkInstance linkInstance) {
    LinkInstance stored = linkInstanceDao.getLinkInstance(id);
    Set<String> collectionIds = new HashSet<>(linkTypeDao.getLinkType(stored.getLinkTypeId()).getCollectionIds());
    collectionIds.addAll(linkTypeDao.getLinkType(linkInstance.getLinkTypeId()).getCollectionIds());
    checkLinkInstancePermission(collectionIds);
    return linkInstanceDao.updateLinkInstance(id, linkInstance);
}
Also used : LinkInstance(io.lumeer.api.model.LinkInstance) HashSet(java.util.HashSet)

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