Search in sources :

Example 21 with LinkType

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

the class MongoLinkTypeDaoTest method testGetLinkTypesByIds.

@Test
public void testGetLinkTypesByIds() {
    String id1 = linkTypeDao.createLinkType(prepareLinkType()).getId();
    LinkType linkType2 = prepareLinkType();
    linkType2.setName(NAME2);
    String id2 = linkTypeDao.createLinkType(linkType2).getId();
    LinkType linkType3 = prepareLinkType();
    linkType3.setName(NAME3);
    linkTypeDao.createLinkType(linkType3);
    LinkType linkType4 = prepareLinkType();
    linkType4.setName(NAME4);
    String id4 = linkTypeDao.createLinkType(linkType4).getId();
    SearchQuery query1 = SearchQuery.createBuilder(USER).linkTypeIds(new HashSet<>(Arrays.asList(id1, id4))).build();
    List<LinkType> linkTypes = linkTypeDao.getLinkTypes(query1);
    assertThat(linkTypes).extracting("id").containsOnlyElementsOf(Arrays.asList(id1, id4));
    SearchQuery query2 = SearchQuery.createBuilder(USER).linkTypeIds(Collections.singleton(id2)).build();
    linkTypes = linkTypeDao.getLinkTypes(query2);
    assertThat(linkTypes).extracting("id").containsOnly(id2);
}
Also used : SearchQuery(io.lumeer.storage.api.query.SearchQuery) LinkType(io.lumeer.api.model.LinkType) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 22 with LinkType

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

the class LinkInstanceServiceIT method configureLinkInstances.

@Before
public void configureLinkInstances() {
    JsonOrganization organization = new JsonOrganization();
    organization.setCode(ORGANIZATION_CODE);
    organization.setPermissions(new JsonPermissions());
    Organization storedOrganization = organizationDao.createOrganization(organization);
    projectDao.setOrganization(storedOrganization);
    User user = new User(USER);
    userDao.createUser(user);
    JsonProject project = new JsonProject();
    project.setPermissions(new JsonPermissions());
    project.setCode(PROJECT_CODE);
    Project storedProject = projectDao.createProject(project);
    collectionDao.setProject(storedProject);
    linkTypeDao.setProject(storedProject);
    linkInstanceDao.setProject(storedProject);
    documentDao.setProject(storedProject);
    JsonPermissions collectionPermissions = new JsonPermissions();
    collectionPermissions.updateUserPermissions(new JsonPermission(USER, Project.ROLES.stream().map(Role::toString).collect(Collectors.toSet())));
    JsonCollection jsonCollection = new JsonCollection("col1", "col1", "icon", "color", collectionPermissions);
    jsonCollection.setDocumentsCount(0);
    String collection1 = collectionDao.createCollection(jsonCollection).getId();
    JsonCollection jsonCollection2 = new JsonCollection("col2", "col2", "icon", "color", collectionPermissions);
    jsonCollection.setDocumentsCount(0);
    String collection2 = collectionDao.createCollection(jsonCollection2).getId();
    LinkType linkType = new LinkType(null, NAME, Arrays.asList(collection1, collection2), ATTRIBUTES);
    linkTypeId1 = linkTypeDao.createLinkType(linkType).getId();
    LinkType linkType2 = new LinkType(null, NAME2, Arrays.asList(collection1, collection2), ATTRIBUTES);
    linkTypeId2 = linkTypeDao.createLinkType(linkType2).getId();
    documentIdsColl1.clear();
    for (int i = 0; i < 3; i++) {
        documentIdsColl1.add(createDocument(collection1).getId());
    }
    documentIdsColl2.clear();
    for (int i = 0; i < 3; i++) {
        documentIdsColl2.add(createDocument(collection2).getId());
    }
}
Also used : JsonProject(io.lumeer.api.dto.JsonProject) Project(io.lumeer.api.model.Project) JsonPermissions(io.lumeer.api.dto.JsonPermissions) Organization(io.lumeer.api.model.Organization) JsonOrganization(io.lumeer.api.dto.JsonOrganization) User(io.lumeer.api.model.User) AuthenticatedUser(io.lumeer.core.AuthenticatedUser) JsonOrganization(io.lumeer.api.dto.JsonOrganization) JsonPermission(io.lumeer.api.dto.JsonPermission) LinkType(io.lumeer.api.model.LinkType) JsonCollection(io.lumeer.api.dto.JsonCollection) JsonProject(io.lumeer.api.dto.JsonProject) Before(org.junit.Before)

Example 23 with LinkType

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

the class LinkTypeServiceIT method testUpdateLinkType.

@Test
public void testUpdateLinkType() {
    LinkType linkType = prepareLinkType();
    String id = linkTypeDao.createLinkType(linkType).getId();
    LinkType updateLinkedType = prepareLinkType();
    updateLinkedType.setName(NAME2);
    updateLinkedType.setCollectionIds(Arrays.asList(collectionIds.get(1), collectionIds.get(2)));
    Entity entity = Entity.json(updateLinkedType);
    Response response = client.target(LINK_TYPES_URL).path(id).request(MediaType.APPLICATION_JSON).buildPut(entity).invoke();
    assertThat(response).isNotNull();
    assertThat(response.getStatusInfo()).isEqualTo(Response.Status.OK);
    LinkType returnedLinkType = response.readEntity(LinkType.class);
    assertThat(returnedLinkType).isNotNull();
    assertThat(returnedLinkType).isNotNull();
    assertThat(returnedLinkType.getName()).isEqualTo(NAME2);
    assertThat(returnedLinkType.getAttributes()).isEqualTo(ATTRIBUTES);
    assertThat(returnedLinkType.getCollectionIds()).containsOnlyElementsOf(Arrays.asList(collectionIds.get(1), collectionIds.get(2)));
    LinkType storedLinkType = linkTypeDao.getLinkType(id);
    assertThat(storedLinkType).isNotNull();
    assertThat(storedLinkType.getName()).isEqualTo(NAME2);
    assertThat(storedLinkType.getAttributes()).isEqualTo(ATTRIBUTES);
    assertThat(storedLinkType.getCollectionIds()).containsOnlyElementsOf(Arrays.asList(collectionIds.get(1), collectionIds.get(2)));
}
Also used : Response(javax.ws.rs.core.Response) Entity(javax.ws.rs.client.Entity) LinkType(io.lumeer.api.model.LinkType) Test(org.junit.Test)

Example 24 with LinkType

use of io.lumeer.api.model.LinkType 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 25 with LinkType

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

the class LinkTypeCodec method decode.

@Override
public LinkType decode(final BsonReader reader, final DecoderContext decoderContext) {
    Document bson = documentCodec.decode(reader, decoderContext);
    String id = bson.getObjectId(ID).toHexString();
    String name = bson.getString(NAME);
    List<String> collectionCodes = bson.get(COLLECTION_IDS, List.class);
    List<JsonAttribute> attributes = new ArrayList<Document>(bson.get(ATTRIBUTES, List.class)).stream().map(AttributeCodec::convertFromDocument).collect(Collectors.toList());
    return new LinkType(id, name, collectionCodes, attributes);
}
Also used : JsonAttribute(io.lumeer.api.dto.JsonAttribute) Document(org.bson.Document) LinkType(io.lumeer.api.model.LinkType)

Aggregations

LinkType (io.lumeer.api.model.LinkType)26 Test (org.junit.Test)18 SearchQuery (io.lumeer.storage.api.query.SearchQuery)6 Response (javax.ws.rs.core.Response)5 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)3 JsonCollection (io.lumeer.api.dto.JsonCollection)2 JsonOrganization (io.lumeer.api.dto.JsonOrganization)2 JsonPermission (io.lumeer.api.dto.JsonPermission)2 JsonPermissions (io.lumeer.api.dto.JsonPermissions)2 JsonProject (io.lumeer.api.dto.JsonProject)2 Collection (io.lumeer.api.model.Collection)2 Organization (io.lumeer.api.model.Organization)2 Project (io.lumeer.api.model.Project)2 User (io.lumeer.api.model.User)2 AuthenticatedUser (io.lumeer.core.AuthenticatedUser)2 Before (org.junit.Before)2