Search in sources :

Example 16 with LinkType

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

Example 17 with LinkType

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

the class LinkTypeFacade method deleteLinkType.

public void deleteLinkType(String id) {
    LinkType linkType = linkTypeDao.getLinkType(id);
    checkLinkTypePermission(linkType.getCollectionIds());
    linkTypeDao.deleteLinkType(id);
}
Also used : LinkType(io.lumeer.api.model.LinkType)

Example 18 with LinkType

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

the class CollectionFacade method deleteCollection.

public void deleteCollection(String collectionId) {
    Collection collection = collectionDao.getCollectionById(collectionId);
    permissionsChecker.checkRole(collection, Role.MANAGE);
    collectionDao.deleteCollection(collectionId);
    documentDao.deleteDocuments(collectionId);
    dataDao.deleteDataRepository(collectionId);
    SearchQuery queryLinkTypes = createQueryForLinkTypes(collectionId);
    List<LinkType> linkTypes = linkTypeDao.getLinkTypes(queryLinkTypes);
    if (!linkTypes.isEmpty()) {
        linkTypeDao.deleteLinkTypes(queryLinkTypes);
        linkInstanceDao.deleteLinkInstances(createQueryForLinkInstances(linkTypes));
    }
}
Also used : SearchQuery(io.lumeer.storage.api.query.SearchQuery) Collection(io.lumeer.api.model.Collection) LinkType(io.lumeer.api.model.LinkType)

Example 19 with LinkType

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

the class MongoLinkTypeDaoTest method testDeleteLinkTypesByIds.

@Test
public void testDeleteLinkTypesByIds() throws InterruptedException {
    String id1 = linkTypeDao.createLinkType(prepareLinkType()).getId();
    LinkType linkType2 = prepareLinkType();
    linkType2.setName(NAME2);
    String id2 = linkTypeDao.createLinkType(linkType2).getId();
    LinkType linkType3 = prepareLinkType();
    linkType3.setName(NAME3);
    String id3 = linkTypeDao.createLinkType(linkType3).getId();
    LinkType linkType4 = prepareLinkType();
    linkType4.setName(NAME4);
    String id4 = linkTypeDao.createLinkType(linkType4).getId();
    assertThat(linkTypeDao.databaseCollection().find().into(new ArrayList<>()).size()).isEqualTo(4);
    SearchQuery query = SearchQuery.createBuilder(USER).linkTypeIds(new HashSet<>(Arrays.asList(id1, id4))).build();
    linkTypeDao.deleteLinkTypes(query);
    List<LinkType> linkTypes = linkTypeDao.databaseCollection().find().into(new ArrayList<>());
    assertThat(linkTypes).extracting("id").containsOnlyElementsOf(Arrays.asList(id2, id3));
}
Also used : SearchQuery(io.lumeer.storage.api.query.SearchQuery) ArrayList(java.util.ArrayList) LinkType(io.lumeer.api.model.LinkType) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 20 with LinkType

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

the class MongoLinkTypeDaoTest method testCreateLinkType.

@Test
public void testCreateLinkType() {
    LinkType linkType = prepareLinkType();
    String id = linkTypeDao.createLinkType(linkType).getId();
    assertThat(id).isNotNull().isNotEmpty();
    assertThat(ObjectId.isValid(id)).isTrue();
    LinkType storedLinkType = linkTypeDao.getLinkType(id);
    assertThat(storedLinkType).isNotNull();
    assertThat(storedLinkType.getName()).isEqualTo(NAME);
    assertThat(storedLinkType.getAttributes()).isEqualTo(ATTRIBUTES);
    assertThat(storedLinkType.getCollectionIds()).containsOnlyElementsOf(Arrays.asList(COLLECTION_ID1, COLLECTION_ID2));
}
Also used : LinkType(io.lumeer.api.model.LinkType) Test(org.junit.Test)

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