Search in sources :

Example 1 with AppUserDto

use of org.collectiveone.modules.users.AppUserDto in project CollectiveOneWebapp by CollectiveOne.

the class TestElementOrder method setUp.

@SuppressWarnings("serial")
@Before
public void setUp() throws Exception {
    AuthAPI auth = new AuthAPI(auth0Domain, clientId, clientSecret);
    AuthRequest request = auth.login(testEmail1, testPwd1).setScope("openid contacts");
    try {
        TokenHolder holder = request.execute();
        authorizationTokenUser1 = holder.getIdToken();
    } catch (APIException exception) {
        System.out.println(exception);
    } catch (Auth0Exception exception) {
        System.out.println(exception);
    }
    MvcResult result = this.mockMvc.perform(get("/1/user/myProfile").header("Authorization", "Bearer " + authorizationTokenUser1)).andReturn();
    assertEquals("error in http request: " + result.getResponse().getErrorMessage(), 200, result.getResponse().getStatus());
    GetResult<AppUserDto> getResultUser = gson.fromJson(result.getResponse().getContentAsString(), new TypeToken<GetResult<AppUserDto>>() {
    }.getType());
    user1 = getResultUser.getData();
    logger.debug("Test user created:" + result.getResponse().getContentAsString());
    request = auth.login(testEmail2, testPwd2).setScope("openid contacts");
    try {
        TokenHolder holder = request.execute();
        authorizationTokenUser2 = holder.getIdToken();
    } catch (APIException exception) {
        System.out.println(exception);
    } catch (Auth0Exception exception) {
        System.out.println(exception);
    }
    result = this.mockMvc.perform(get("/1/user/myProfile").header("Authorization", "Bearer " + authorizationTokenUser2)).andReturn();
    assertEquals("error in http request: " + result.getResponse().getErrorMessage(), 200, result.getResponse().getStatus());
    getResultUser = gson.fromJson(result.getResponse().getContentAsString(), new TypeToken<GetResult<AppUserDto>>() {
    }.getType());
    user2 = getResultUser.getData();
    logger.debug("Test user created: " + result.getResponse().getContentAsString());
    /**
     * create initiative
     */
    NewInitiativeDto initiativeDto = new NewInitiativeDto(initiativeName, "");
    MemberDto member = new MemberDto();
    member.setRole("ADMIN");
    member.setUser(user1);
    initiativeDto.getMembers().add(member);
    result = this.mockMvc.perform(post("/1/initiative/create").header("Authorization", "Bearer " + authorizationTokenUser1).contentType(MediaType.APPLICATION_JSON).content(gson.toJson(initiativeDto))).andReturn();
    assertEquals("error in http request: " + result.getResponse().getErrorMessage(), 200, result.getResponse().getStatus());
    PostResult postResult = gson.fromJson(result.getResponse().getContentAsString(), PostResult.class);
    initiativeId = postResult.getElementId();
    logger.debug("Initiative created: " + initiativeId);
    result = this.mockMvc.perform(get("/1/initiative/" + initiativeId).header("Authorization", "Bearer " + authorizationTokenUser1)).andReturn();
    GetResult<InitiativeDto> getResultInit = gson.fromJson(result.getResponse().getContentAsString(), new TypeToken<GetResult<InitiativeDto>>() {
    }.getType());
    initiative = getResultInit.getData();
    logger.debug("Initiative retrieved: " + result.getResponse().getContentAsString());
}
Also used : AuthRequest(com.auth0.net.AuthRequest) NewInitiativeDto(org.collectiveone.modules.initiatives.dto.NewInitiativeDto) GetResult(org.collectiveone.common.dto.GetResult) NewInitiativeDto(org.collectiveone.modules.initiatives.dto.NewInitiativeDto) InitiativeDto(org.collectiveone.modules.initiatives.dto.InitiativeDto) Auth0Exception(com.auth0.exception.Auth0Exception) TokenHolder(com.auth0.json.auth.TokenHolder) MvcResult(org.springframework.test.web.servlet.MvcResult) PostResult(org.collectiveone.common.dto.PostResult) APIException(com.auth0.exception.APIException) TypeToken(com.google.common.reflect.TypeToken) MemberDto(org.collectiveone.modules.initiatives.dto.MemberDto) AuthAPI(com.auth0.client.auth.AuthAPI) AppUserDto(org.collectiveone.modules.users.AppUserDto) Before(org.junit.Before)

Example 2 with AppUserDto

use of org.collectiveone.modules.users.AppUserDto in project CollectiveOneWebapp by CollectiveOne.

the class InitiativeService method getMembersOfEcosystem.

@Transactional
public GetResult<List<AppUserDto>> getMembersOfEcosystem(UUID initiativeId, String query, PageRequest page) {
    List<UUID> ecosystemIds = findAllInitiativeEcosystemIds(initiativeId);
    Page<AppUser> allMemberUsers = memberRepository.findMembersOfInitiatives(ecosystemIds, query.toLowerCase(), page);
    List<AppUserDto> allMembersDto = new ArrayList<AppUserDto>();
    for (AppUser user : allMemberUsers.getContent()) {
        allMembersDto.add(user.toDtoLight());
    }
    return new GetResult<List<AppUserDto>>("success", "members retrieved", allMembersDto);
}
Also used : GetResult(org.collectiveone.common.dto.GetResult) ArrayList(java.util.ArrayList) AppUser(org.collectiveone.modules.users.AppUser) UUID(java.util.UUID) AppUserDto(org.collectiveone.modules.users.AppUserDto) Transactional(javax.transaction.Transactional)

Aggregations

GetResult (org.collectiveone.common.dto.GetResult)2 AppUserDto (org.collectiveone.modules.users.AppUserDto)2 AuthAPI (com.auth0.client.auth.AuthAPI)1 APIException (com.auth0.exception.APIException)1 Auth0Exception (com.auth0.exception.Auth0Exception)1 TokenHolder (com.auth0.json.auth.TokenHolder)1 AuthRequest (com.auth0.net.AuthRequest)1 TypeToken (com.google.common.reflect.TypeToken)1 ArrayList (java.util.ArrayList)1 UUID (java.util.UUID)1 Transactional (javax.transaction.Transactional)1 PostResult (org.collectiveone.common.dto.PostResult)1 InitiativeDto (org.collectiveone.modules.initiatives.dto.InitiativeDto)1 MemberDto (org.collectiveone.modules.initiatives.dto.MemberDto)1 NewInitiativeDto (org.collectiveone.modules.initiatives.dto.NewInitiativeDto)1 AppUser (org.collectiveone.modules.users.AppUser)1 Before (org.junit.Before)1 MvcResult (org.springframework.test.web.servlet.MvcResult)1