Search in sources :

Example 36 with User

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);
}
Also used : Document(org.bson.Document) EncoderContext(org.bson.codecs.EncoderContext) BsonObjectId(org.bson.BsonObjectId) User(io.lumeer.api.model.User) Set(java.util.Set) HashMap(java.util.HashMap) CodecRegistry(org.bson.codecs.configuration.CodecRegistry) Collectors(java.util.stream.Collectors) BsonReader(org.bson.BsonReader) BsonValue(org.bson.BsonValue) HashSet(java.util.HashSet) List(java.util.List) Map(java.util.Map) Codec(org.bson.codecs.Codec) ObjectId(org.bson.types.ObjectId) BsonWriter(org.bson.BsonWriter) CollectibleCodec(org.bson.codecs.CollectibleCodec) Collections(java.util.Collections) DecoderContext(org.bson.codecs.DecoderContext) BsonObjectId(org.bson.BsonObjectId) ObjectId(org.bson.types.ObjectId) Document(org.bson.Document)

Example 37 with User

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);
}
Also used : Set(java.util.Set) HashSet(java.util.HashSet) User(io.lumeer.api.model.User) Document(org.bson.Document)

Example 38 with User

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);
    }
}
Also used : JsonProject(io.lumeer.api.dto.JsonProject) Project(io.lumeer.api.model.Project) JsonPermissions(io.lumeer.api.dto.JsonPermissions) Organization(io.lumeer.api.model.Organization) JsonOrganization(io.lumeer.api.dto.JsonOrganization) User(io.lumeer.api.model.User) AuthenticatedUser(io.lumeer.core.AuthenticatedUser) JsonOrganization(io.lumeer.api.dto.JsonOrganization) JsonPermission(io.lumeer.api.dto.JsonPermission) JsonCollection(io.lumeer.api.dto.JsonCollection) JsonProject(io.lumeer.api.dto.JsonProject) Before(org.junit.Before)

Example 39 with User

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());
    }
}
Also used : JsonProject(io.lumeer.api.dto.JsonProject) Project(io.lumeer.api.model.Project) JsonPermissions(io.lumeer.api.dto.JsonPermissions) Organization(io.lumeer.api.model.Organization) JsonOrganization(io.lumeer.api.dto.JsonOrganization) User(io.lumeer.api.model.User) AuthenticatedUser(io.lumeer.core.AuthenticatedUser) JsonOrganization(io.lumeer.api.dto.JsonOrganization) JsonPermission(io.lumeer.api.dto.JsonPermission) JsonCollection(io.lumeer.api.dto.JsonCollection) JsonProject(io.lumeer.api.dto.JsonProject) Before(org.junit.Before)

Example 40 with User

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());
}
Also used : User(io.lumeer.api.model.User) AuthenticatedUser(io.lumeer.core.AuthenticatedUser) Test(org.junit.Test)

Aggregations

User (io.lumeer.api.model.User)50 AuthenticatedUser (io.lumeer.core.AuthenticatedUser)29 Test (org.junit.Test)21 Before (org.junit.Before)18 Organization (io.lumeer.api.model.Organization)17 JsonOrganization (io.lumeer.api.dto.JsonOrganization)13 Project (io.lumeer.api.model.Project)13 JsonPermission (io.lumeer.api.dto.JsonPermission)12 JsonPermissions (io.lumeer.api.dto.JsonPermissions)12 JsonProject (io.lumeer.api.dto.JsonProject)12 JsonCollection (io.lumeer.api.dto.JsonCollection)8 HashSet (java.util.HashSet)7 MorphiaOrganization (io.lumeer.storage.mongodb.model.MorphiaOrganization)5 MorphiaPermissions (io.lumeer.storage.mongodb.model.embedded.MorphiaPermissions)5 Set (java.util.Set)5 Response (javax.ws.rs.core.Response)4 MorphiaPermission (io.lumeer.storage.mongodb.model.embedded.MorphiaPermission)3 HashMap (java.util.HashMap)3 LinkType (io.lumeer.api.model.LinkType)2 MorphiaProject (io.lumeer.storage.mongodb.model.MorphiaProject)2