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