use of io.lumeer.api.model.User in project engine by Lumeer.
the class UserCodec method encode.
@Override
public void encode(final BsonWriter bsonWriter, final User user, final EncoderContext encoderContext) {
Document bson = user.getId() != null ? new Document(ID, new ObjectId(user.getId())) : new Document();
bson.append(NAME, user.getName()).append(EMAIL, user.getEmail());
if (user.getGroups() != null) {
List<Document> groupsArray = user.getGroups().entrySet().stream().map(entry -> new Document(ORGANIZATION_ID, entry.getKey()).append(GROUPS, entry.getValue())).collect(Collectors.toList());
bson.append(ALL_GROUPS, groupsArray);
}
documentCodec.encode(bsonWriter, bson, encoderContext);
}
use of io.lumeer.api.model.User in project engine by Lumeer.
the class UserCodec method decode.
@Override
public User decode(final BsonReader bsonReader, final DecoderContext decoderContext) {
Document bson = documentCodec.decode(bsonReader, decoderContext);
String id = bson.getObjectId(ID).toHexString();
String name = bson.getString(NAME);
String email = bson.getString(EMAIL);
List<Document> documentList = bson.get(ALL_GROUPS, List.class);
Map<String, Set<String>> allGroups = convertGroupsListToMap(documentList);
return new User(id, name, email, allGroups);
}
use of io.lumeer.api.model.User in project engine by Lumeer.
the class SearchFacadeIT method configureCollections.
@Before
public void configureCollections() {
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);
workspaceKeeper.setWorkspace(ORGANIZATION_CODE, PROJECT_CODE);
collectionDao.setProject(storedProject);
collectionDao.createCollectionsRepository(storedProject);
documentDao.setProject(storedProject);
collectionIds.clear();
for (String name : COLLECTION_CODES) {
JsonPermissions collectionPermissions = new JsonPermissions();
collectionPermissions.updateUserPermissions(new JsonPermission(USER, Project.ROLES.stream().map(Role::toString).collect(Collectors.toSet())));
JsonCollection jsonCollection = new JsonCollection(name, name, COLLECTION_ICON, COLLECTION_COLOR, collectionPermissions);
jsonCollection.setDocumentsCount(0);
String collectionId = collectionDao.createCollection(jsonCollection).getId();
collectionIds.add(collectionId);
dataDao.createDataRepository(collectionId);
}
}
use of io.lumeer.api.model.User in project engine by Lumeer.
the class SuggestionFacadeIT method configure.
@Before
public void configure() {
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);
workspaceKeeper.setWorkspace(ORGANIZATION_CODE, PROJECT_CODE);
collectionDao.setProject(storedProject);
collectionDao.createCollectionsRepository(storedProject);
linkTypeDao.setProject(storedProject);
linkTypeDao.createLinkTypeRepository(storedProject);
viewDao.setProject(storedProject);
viewDao.createViewsRepository(storedProject);
collectionIds.clear();
for (String name : COLLECTION_NAMES) {
JsonPermissions collectionPermissions = new JsonPermissions();
collectionPermissions.updateUserPermissions(new JsonPermission(USER, Project.ROLES.stream().map(Role::toString).collect(Collectors.toSet())));
JsonCollection jsonCollection = new JsonCollection(name, name, COLLECTION_ICON, COLLECTION_COLOR, collectionPermissions);
jsonCollection.setDocumentsCount(0);
collectionIds.add(collectionDao.createCollection(jsonCollection).getId());
}
for (String name : COLLECTION_NAMES_NO_RIGHTS) {
JsonCollection jsonCollection = new JsonCollection(name, name, COLLECTION_ICON, COLLECTION_COLOR, new JsonPermissions());
jsonCollection.setDocumentsCount(0);
collectionIdsNoRights.add(collectionDao.createCollection(jsonCollection).getId());
}
}
use of io.lumeer.api.model.User in project engine by Lumeer.
the class UserFacadeIT method testCreateUserMultipleOrganizations.
@Test
public void testCreateUserMultipleOrganizations() {
User user11 = userFacade.createUser(organizationId1, prepareUser(organizationId1, USER1));
User user21 = userFacade.createUser(organizationId1, prepareUser(organizationId1, USER2));
User user12 = userFacade.createUser(organizationId2, prepareUser(organizationId2, USER1));
User user32 = userFacade.createUser(organizationId2, prepareUser(organizationId2, USER3));
assertThat(user11.getId()).isEqualTo(user12.getId());
assertThat(user21.getId()).isNotEqualTo(user32.getId());
assertThat(user21.getId()).isNotEqualTo(user11.getId());
}
Aggregations