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));
}
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));
}
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());
}
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());
}
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);
}
Aggregations