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