Search in sources :

Example 1 with JsonQuery

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

the class MongoViewDaoTest method createView.

private JsonView createView(String code, String name, Set<String> collections) {
    JsonView jsonView = prepareView();
    jsonView.setCode(code);
    jsonView.setName(name);
    jsonView.setQuery(new JsonQuery(collections, null, null));
    viewDao.databaseCollection().insertOne(jsonView);
    return jsonView;
}
Also used : JsonQuery(io.lumeer.api.dto.JsonQuery) JsonView(io.lumeer.api.dto.JsonView)

Example 2 with JsonQuery

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

the class ViewCodec method decode.

@Override
public JsonView decode(final BsonReader reader, final DecoderContext decoderContext) {
    Document bson = documentCodec.decode(reader, decoderContext);
    String id = bson.getObjectId(ID).toHexString();
    String code = bson.getString(CODE);
    String name = bson.getString(NAME);
    String icon = bson.getString(ICON);
    String color = bson.getString(COLOR);
    String description = bson.getString(DESCRIPTION);
    // TODO try to use better approach
    JsonPermissions permissions = PermissionsCodec.convertFromDocument(bson.get(PERMISSIONS, Document.class));
    JsonQuery query = QueryCodec.convertFromDocument(bson.get(QUERY, Document.class));
    String perspective = bson.getString(PERSPECTIVE);
    Object config = bson.get(CONFIG);
    JsonView view = new JsonView(code, name, icon, color, description, permissions, query, perspective, config);
    view.setId(id);
    return view;
}
Also used : JsonPermissions(io.lumeer.api.dto.JsonPermissions) JsonQuery(io.lumeer.api.dto.JsonQuery) JsonView(io.lumeer.api.dto.JsonView) Document(org.bson.Document)

Example 3 with JsonQuery

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

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

the class LinkTypeFacadeIT method testGetLinkTypes.

@Test
public void testGetLinkTypes() {
    String id1 = linkTypeFacade.createLinkType(prepareLinkType()).getId();
    LinkType linkType2 = prepareLinkType();
    linkType2.setCollectionIds(Arrays.asList(collectionIds.get(0), collectionIds.get(2)));
    String id2 = linkTypeFacade.createLinkType(linkType2).getId();
    LinkType linkType3 = prepareLinkType();
    linkType3.setCollectionIds(Arrays.asList(collectionIds.get(1), collectionIds.get(2)));
    String id3 = linkTypeFacade.createLinkType(linkType3).getId();
    LinkType linkType4 = prepareLinkType();
    linkType4.setCollectionIds(Arrays.asList(collectionIds.get(1), collectionIds.get(0)));
    String id4 = linkTypeFacade.createLinkType(linkType4).getId();
    JsonQuery jsonQuery = new JsonQuery(Collections.singleton(collectionIds.get(0)), null, null);
    List<LinkType> linkTypes = linkTypeFacade.getLinkTypes(jsonQuery);
    assertThat(linkTypes).extracting("id").containsOnlyElementsOf(Arrays.asList(id1, id2, id4));
    JsonQuery jsonQuery2 = new JsonQuery(null, new HashSet<>(Arrays.asList(id1, id3)), null);
    linkTypes = linkTypeFacade.getLinkTypes(jsonQuery2);
    assertThat(linkTypes).extracting("id").containsOnlyElementsOf(Arrays.asList(id1, id3));
}
Also used : JsonQuery(io.lumeer.api.dto.JsonQuery) LinkType(io.lumeer.api.model.LinkType) Test(org.junit.Test)

Example 5 with JsonQuery

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

the class LinkTypeServiceIT method testGetLinkTypesByIds.

@Test
public void testGetLinkTypesByIds() {
    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)));
    linkTypeDao.createLinkType(linkType4);
    JsonQuery jsonQuery = new JsonQuery(null, new HashSet<>(Arrays.asList(id1, id3)), 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));
}
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)

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