Search in sources :

Example 1 with LinkType

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

the class LinkInstanceFacade method createLinkInstance.

public LinkInstance createLinkInstance(LinkInstance linkInstance) {
    LinkType linkType = linkTypeDao.getLinkType(linkInstance.getLinkTypeId());
    checkLinkInstancePermission(linkType.getCollectionIds());
    return linkInstanceDao.createLinkInstance(linkInstance);
}
Also used : LinkType(io.lumeer.api.model.LinkType)

Example 2 with LinkType

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

the class LinkInstanceFacade method deleteLinkInstance.

public void deleteLinkInstance(String id) {
    LinkInstance linkInstance = linkInstanceDao.getLinkInstance(id);
    LinkType linkType = linkTypeDao.getLinkType(linkInstance.getLinkTypeId());
    checkLinkInstancePermission(linkType.getCollectionIds());
    linkInstanceDao.deleteLinkInstance(id);
}
Also used : LinkInstance(io.lumeer.api.model.LinkInstance) LinkType(io.lumeer.api.model.LinkType)

Example 3 with LinkType

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

the class SuggestionFacade method suggestLinkTypes.

private List<LinkType> suggestLinkTypes(String text, int limit) {
    List<Collection> allowedCollections = collectionDao.getCollections(createSimpleSearchQuery());
    if (allowedCollections.isEmpty()) {
        return Collections.emptyList();
    }
    List<String> allowedCollectionIds = allowedCollections.stream().map(Collection::getId).collect(Collectors.toList());
    SuggestionQuery suggestionQuery = createSuggestionQueryWithIds(text, limit, allowedCollectionIds);
    List<LinkType> linkTypes = linkTypeDao.getLinkTypes(suggestionQuery);
    return linkTypes.stream().filter(linkType -> allowedCollectionIds.containsAll(linkType.getCollectionIds())).collect(Collectors.toList());
}
Also used : View(io.lumeer.api.model.View) LinkTypeDao(io.lumeer.storage.api.dao.LinkTypeDao) Set(java.util.Set) SearchQuery(io.lumeer.storage.api.query.SearchQuery) Collectors(java.util.stream.Collectors) LinkType(io.lumeer.api.model.LinkType) SuggestionType(io.lumeer.api.model.SuggestionType) Inject(javax.inject.Inject) List(java.util.List) CollectionDao(io.lumeer.storage.api.dao.CollectionDao) ViewDao(io.lumeer.storage.api.dao.ViewDao) RequestScoped(javax.enterprise.context.RequestScoped) SuggestionQuery(io.lumeer.storage.api.query.SuggestionQuery) Attribute(io.lumeer.api.model.Attribute) JsonSuggestions(io.lumeer.api.dto.JsonSuggestions) Collections(java.util.Collections) Collection(io.lumeer.api.model.Collection) SuggestionQuery(io.lumeer.storage.api.query.SuggestionQuery) Collection(io.lumeer.api.model.Collection) LinkType(io.lumeer.api.model.LinkType)

Example 4 with LinkType

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

the class MongoLinkTypeDaoTest method testGetLinkTypesByCollections.

@Test
public void testGetLinkTypesByCollections() {
    String id1 = linkTypeDao.createLinkType(prepareLinkType()).getId();
    LinkType linkType2 = prepareLinkType();
    linkType2.setCollectionIds(Arrays.asList(COLLECTION_ID3, COLLECTION_ID4));
    String id2 = linkTypeDao.createLinkType(linkType2).getId();
    LinkType linkType3 = prepareLinkType();
    linkType3.setCollectionIds(Arrays.asList(COLLECTION_ID1, COLLECTION_ID4));
    String id3 = linkTypeDao.createLinkType(linkType3).getId();
    LinkType linkType4 = prepareLinkType();
    linkType4.setCollectionIds(Arrays.asList(COLLECTION_ID2, COLLECTION_ID3));
    String id4 = linkTypeDao.createLinkType(linkType4).getId();
    SearchQuery query1 = SearchQuery.createBuilder(USER).collectionIds(new HashSet<>(Arrays.asList(COLLECTION_ID1, COLLECTION_ID2))).build();
    List<LinkType> linkTypes = linkTypeDao.getLinkTypes(query1);
    assertThat(linkTypes).extracting("id").containsOnlyElementsOf(Arrays.asList(id1, id3, id4));
    SearchQuery query2 = SearchQuery.createBuilder(USER).collectionIds(Collections.singleton(COLLECTION_ID3)).build();
    linkTypes = linkTypeDao.getLinkTypes(query2);
    assertThat(linkTypes).extracting("id").containsOnlyElementsOf(Arrays.asList(id2, id4));
}
Also used : SearchQuery(io.lumeer.storage.api.query.SearchQuery) LinkType(io.lumeer.api.model.LinkType) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 5 with LinkType

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

the class MongoLinkTypeDaoTest method testDeleteLinkTypesByCollections.

@Test
public void testDeleteLinkTypesByCollections() {
    linkTypeDao.createLinkType(prepareLinkType());
    LinkType linkType2 = prepareLinkType();
    linkType2.setCollectionIds(Arrays.asList(COLLECTION_ID2, COLLECTION_ID3));
    linkTypeDao.createLinkType(linkType2);
    LinkType linkType3 = prepareLinkType();
    linkType3.setCollectionIds(Arrays.asList(COLLECTION_ID2, COLLECTION_ID4));
    linkTypeDao.createLinkType(linkType3);
    LinkType linkType4 = prepareLinkType();
    linkType4.setCollectionIds(Arrays.asList(COLLECTION_ID3, COLLECTION_ID4));
    linkTypeDao.createLinkType(linkType4);
    assertThat(linkTypeDao.databaseCollection().find().into(new ArrayList<>()).size()).isEqualTo(4);
    SearchQuery query1 = SearchQuery.createBuilder(USER).collectionIds((Collections.singleton(COLLECTION_ID2))).build();
    linkTypeDao.deleteLinkTypes(query1);
    assertThat(linkTypeDao.databaseCollection().find().into(new ArrayList<>()).size()).isEqualTo(1);
    SearchQuery query2 = SearchQuery.createBuilder(USER).collectionIds((Collections.singleton(COLLECTION_ID3))).build();
    linkTypeDao.deleteLinkTypes(query2);
    assertThat(linkTypeDao.databaseCollection().find().into(new ArrayList<>())).isEmpty();
}
Also used : SearchQuery(io.lumeer.storage.api.query.SearchQuery) ArrayList(java.util.ArrayList) 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