Search in sources :

Example 6 with User

use of io.gravitee.rest.api.portal.rest.model.User in project gravitee-management-rest-api by gravitee-io.

the class ApplicationMapper method convert.

public Application convert(ApplicationEntity applicationEntity, UriInfo uriInfo) {
    final Application application = new Application();
    application.setApplicationType(applicationEntity.getType());
    application.setCreatedAt(applicationEntity.getCreatedAt().toInstant().atOffset(ZoneOffset.UTC));
    application.setDescription(applicationEntity.getDescription());
    Set<String> groupEntities = applicationEntity.getGroups();
    if (groupEntities != null && !groupEntities.isEmpty()) {
        List<Group> groups = groupEntities.stream().map(groupService::findById).map(groupEntity -> new Group().id(groupEntity.getId()).name(groupEntity.getName())).collect(Collectors.toList());
        application.setGroups(groups);
    }
    application.setId(applicationEntity.getId());
    application.setName(applicationEntity.getName());
    UserEntity primaryOwnerUserEntity = userService.findById(applicationEntity.getPrimaryOwner().getId());
    User owner = userMapper.convert(primaryOwnerUserEntity);
    owner.setLinks(userMapper.computeUserLinks(usersURL(uriInfo.getBaseUriBuilder(), primaryOwnerUserEntity.getId()), primaryOwnerUserEntity.getUpdatedAt()));
    application.setOwner(owner);
    application.setUpdatedAt(applicationEntity.getUpdatedAt().toInstant().atOffset(ZoneOffset.UTC));
    application.setPicture(applicationEntity.getPicture());
    application.setBackground(applicationEntity.getBackground());
    final ApplicationSettings applicationEntitySettings = applicationEntity.getSettings();
    if (applicationEntitySettings != null) {
        io.gravitee.rest.api.portal.rest.model.ApplicationSettings appSettings = new io.gravitee.rest.api.portal.rest.model.ApplicationSettings();
        final SimpleApplicationSettings simpleAppEntitySettings = applicationEntitySettings.getApp();
        if (simpleAppEntitySettings != null) {
            appSettings.app(new io.gravitee.rest.api.portal.rest.model.SimpleApplicationSettings().clientId(simpleAppEntitySettings.getClientId()).type(simpleAppEntitySettings.getType()));
            application.setHasClientId(simpleAppEntitySettings.getClientId() != null);
        } else {
            final OAuthClientSettings oAuthClientEntitySettings = applicationEntitySettings.getoAuthClient();
            appSettings.oauth(new io.gravitee.rest.api.portal.rest.model.OAuthClientSettings().applicationType(oAuthClientEntitySettings.getApplicationType()).clientId(oAuthClientEntitySettings.getClientId()).clientSecret(oAuthClientEntitySettings.getClientSecret()).clientUri(oAuthClientEntitySettings.getClientUri()).logoUri(oAuthClientEntitySettings.getLogoUri()).grantTypes(oAuthClientEntitySettings.getGrantTypes()).redirectUris(oAuthClientEntitySettings.getRedirectUris()).responseTypes(oAuthClientEntitySettings.getResponseTypes()).renewClientSecretSupported(oAuthClientEntitySettings.isRenewClientSecretSupported()));
            application.setHasClientId(oAuthClientEntitySettings.getClientId() != null);
        }
        application.setSettings(appSettings);
    }
    return application;
}
Also used : ApplicationSettings(io.gravitee.rest.api.model.application.ApplicationSettings) OAuthClientSettings(io.gravitee.rest.api.model.application.OAuthClientSettings) Group(io.gravitee.rest.api.portal.rest.model.Group) ApplicationListItem(io.gravitee.rest.api.model.application.ApplicationListItem) GroupService(io.gravitee.rest.api.service.GroupService) Set(java.util.Set) Autowired(org.springframework.beans.factory.annotation.Autowired) SimpleApplicationSettings(io.gravitee.rest.api.model.application.SimpleApplicationSettings) User(io.gravitee.rest.api.portal.rest.model.User) Collectors(java.util.stream.Collectors) Application(io.gravitee.rest.api.portal.rest.model.Application) List(java.util.List) Component(org.springframework.stereotype.Component) OffsetDateTime(java.time.OffsetDateTime) UserService(io.gravitee.rest.api.service.UserService) ZoneOffset(java.time.ZoneOffset) UriInfo(javax.ws.rs.core.UriInfo) PortalApiLinkHelper.usersURL(io.gravitee.rest.api.portal.rest.utils.PortalApiLinkHelper.usersURL) ApplicationEntity(io.gravitee.rest.api.model.ApplicationEntity) UserEntity(io.gravitee.rest.api.model.UserEntity) ApplicationLinks(io.gravitee.rest.api.portal.rest.model.ApplicationLinks) Group(io.gravitee.rest.api.portal.rest.model.Group) User(io.gravitee.rest.api.portal.rest.model.User) UserEntity(io.gravitee.rest.api.model.UserEntity) ApplicationSettings(io.gravitee.rest.api.model.application.ApplicationSettings) SimpleApplicationSettings(io.gravitee.rest.api.model.application.SimpleApplicationSettings) SimpleApplicationSettings(io.gravitee.rest.api.model.application.SimpleApplicationSettings) OAuthClientSettings(io.gravitee.rest.api.model.application.OAuthClientSettings) Application(io.gravitee.rest.api.portal.rest.model.Application)

Example 7 with User

use of io.gravitee.rest.api.portal.rest.model.User in project gravitee-management-rest-api by gravitee-io.

the class RatingMapper method convert.

public Rating convert(RatingEntity ratingEntity, UriInfo uriInfo) {
    final Rating rating = new Rating();
    UserEntity authorEntity = userService.findById(ratingEntity.getUser());
    User author = userMapper.convert(authorEntity);
    author.setLinks(userMapper.computeUserLinks(usersURL(uriInfo.getBaseUriBuilder(), authorEntity.getId()), authorEntity.getUpdatedAt()));
    rating.setAuthor(author);
    rating.setTitle(ratingEntity.getTitle());
    rating.setComment(ratingEntity.getComment());
    if (ratingEntity.getCreatedAt() != null) {
        rating.setDate(ratingEntity.getCreatedAt().toInstant().atOffset(ZoneOffset.UTC));
    }
    rating.setId(ratingEntity.getId());
    rating.setValue(Integer.valueOf(ratingEntity.getRate()));
    if (ratingEntity.getAnswers() != null) {
        List<RatingAnswer> ratingsAnswer = ratingEntity.getAnswers().stream().sorted(Comparator.comparing(RatingAnswerEntity::getCreatedAt)).map(rae -> {
            UserEntity answerAuthorEntity = userService.findById(rae.getUser());
            User answerAuthor = userMapper.convert(answerAuthorEntity);
            answerAuthor.setLinks(userMapper.computeUserLinks(usersURL(uriInfo.getBaseUriBuilder(), answerAuthorEntity.getId()), answerAuthorEntity.getUpdatedAt()));
            return new RatingAnswer().id(rae.getId()).author(answerAuthor).comment(rae.getComment()).date(rae.getCreatedAt().toInstant().atOffset(ZoneOffset.UTC));
        }).collect(Collectors.toList());
        rating.setAnswers(ratingsAnswer);
    }
    return rating;
}
Also used : RatingEntity(io.gravitee.rest.api.model.RatingEntity) Autowired(org.springframework.beans.factory.annotation.Autowired) User(io.gravitee.rest.api.portal.rest.model.User) Collectors(java.util.stream.Collectors) List(java.util.List) Component(org.springframework.stereotype.Component) UserService(io.gravitee.rest.api.service.UserService) Rating(io.gravitee.rest.api.portal.rest.model.Rating) RatingAnswer(io.gravitee.rest.api.portal.rest.model.RatingAnswer) ZoneOffset(java.time.ZoneOffset) UriInfo(javax.ws.rs.core.UriInfo) Comparator(java.util.Comparator) PortalApiLinkHelper.usersURL(io.gravitee.rest.api.portal.rest.utils.PortalApiLinkHelper.usersURL) RatingAnswerEntity(io.gravitee.rest.api.model.RatingAnswerEntity) UserEntity(io.gravitee.rest.api.model.UserEntity) RatingAnswer(io.gravitee.rest.api.portal.rest.model.RatingAnswer) User(io.gravitee.rest.api.portal.rest.model.User) Rating(io.gravitee.rest.api.portal.rest.model.Rating) UserEntity(io.gravitee.rest.api.model.UserEntity)

Example 8 with User

use of io.gravitee.rest.api.portal.rest.model.User in project gravitee-management-rest-api by gravitee-io.

the class UserResourceTest method shouldGetCurrentUserWithEmptyManagementConfig.

@Test
public void shouldGetCurrentUserWithEmptyManagementConfig() {
    when(userService.findByIdWithRoles(USER_NAME)).thenReturn(new UserEntity());
    when(permissionService.hasManagementRights(USER_NAME)).thenReturn(Boolean.TRUE);
    when(configService.getConsoleSettings()).thenReturn(new ConsoleSettingsEntity());
    final Response response = target().request().get();
    assertEquals(HttpStatusCode.OK_200, response.getStatus());
    ArgumentCaptor<String> userId = ArgumentCaptor.forClass(String.class);
    Mockito.verify(userService).findByIdWithRoles(userId.capture());
    assertEquals(USER_NAME, userId.getValue());
    User user = response.readEntity(User.class);
    assertNotNull(user);
    assertNull(user.getConfig());
    assertNotNull(user.getLinks());
}
Also used : Response(javax.ws.rs.core.Response) ConsoleSettingsEntity(io.gravitee.rest.api.model.settings.ConsoleSettingsEntity) User(io.gravitee.rest.api.portal.rest.model.User) UpdateUserEntity(io.gravitee.rest.api.model.UpdateUserEntity) UserEntity(io.gravitee.rest.api.model.UserEntity) Test(org.junit.Test)

Example 9 with User

use of io.gravitee.rest.api.portal.rest.model.User in project gravitee-management-rest-api by gravitee-io.

the class UserResourceTest method shouldUpdateCurrentUser.

@Test
public void shouldUpdateCurrentUser() {
    UserInput userInput = new UserInput();
    final String newAvatar = "data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7";
    final String expectedAvatar = "data:image/gif;base64,R0lGODlhyADIAPAAAAAAAP///ywAAAAAyADIAEAC/4SPqcvtD6OctNqL" + "s968+w+G4kiW5omm6sq27gvH8kzX9o3n+s73/g8MCofEovGITCqXzKbzCY1Kp9Sq9YrNarfcrvcLDovH5LL5jE6r1+y2+w2Py+" + "f0uv2Oz+v3/L7/DxgoOEhYaHiImKi4yNjo+AgZKTlJWWl5iZmpucnZ6fkJGio6SlpqeoqaqrrK2ur6ChsrO0tba3uLm6u7y9vr" + "+wscLDxMXGx8jJysvMzc7PwMHS09TV1tfY2drb3N3e39DR4uPk5ebn6Onq6+zt7u/g4fLz9PX29/j5+vv8/f7/8PMKDAgQQLGj" + "yIMKHChQwbOnwIMaLEiRQrWryIMaPGjQYcO3osUwAAOw==";
    userInput.setAvatar(newAvatar);
    userInput.setId(USER_NAME);
    when(userService.update(eq(USER_NAME), any())).thenReturn(new UserEntity());
    final Response response = target().request().put(Entity.json(userInput));
    assertEquals(HttpStatusCode.OK_200, response.getStatus());
    ArgumentCaptor<UpdateUserEntity> user = ArgumentCaptor.forClass(UpdateUserEntity.class);
    Mockito.verify(userService).update(eq(USER_NAME), user.capture());
    final UpdateUserEntity updateUserEntity = user.getValue();
    assertNotNull(updateUserEntity);
    assertEquals(expectedAvatar, updateUserEntity.getPicture());
    assertNull(updateUserEntity.getStatus());
    User updateUser = response.readEntity(User.class);
    assertNotNull(updateUser);
}
Also used : Response(javax.ws.rs.core.Response) User(io.gravitee.rest.api.portal.rest.model.User) UpdateUserEntity(io.gravitee.rest.api.model.UpdateUserEntity) UserInput(io.gravitee.rest.api.portal.rest.model.UserInput) UpdateUserEntity(io.gravitee.rest.api.model.UpdateUserEntity) UserEntity(io.gravitee.rest.api.model.UserEntity) Test(org.junit.Test)

Example 10 with User

use of io.gravitee.rest.api.portal.rest.model.User in project gravitee-management-rest-api by gravitee-io.

the class UserResourceTest method shouldGetCurrentUserWithManagementConfigWithoutUrl.

@Test
public void shouldGetCurrentUserWithManagementConfigWithoutUrl() {
    when(userService.findByIdWithRoles(USER_NAME)).thenReturn(new UserEntity());
    when(permissionService.hasManagementRights(USER_NAME)).thenReturn(Boolean.TRUE);
    ConsoleSettingsEntity consoleConfigEntity = new ConsoleSettingsEntity();
    when(configService.getConsoleSettings()).thenReturn(consoleConfigEntity);
    final Response response = target().request().get();
    assertEquals(HttpStatusCode.OK_200, response.getStatus());
    ArgumentCaptor<String> userId = ArgumentCaptor.forClass(String.class);
    Mockito.verify(userService).findByIdWithRoles(userId.capture());
    assertEquals(USER_NAME, userId.getValue());
    User user = response.readEntity(User.class);
    assertNotNull(user);
    assertNull(user.getConfig());
    assertNotNull(user.getLinks());
}
Also used : Response(javax.ws.rs.core.Response) ConsoleSettingsEntity(io.gravitee.rest.api.model.settings.ConsoleSettingsEntity) User(io.gravitee.rest.api.portal.rest.model.User) UpdateUserEntity(io.gravitee.rest.api.model.UpdateUserEntity) UserEntity(io.gravitee.rest.api.model.UserEntity) Test(org.junit.Test)

Aggregations

User (io.gravitee.rest.api.portal.rest.model.User)20 UserEntity (io.gravitee.rest.api.model.UserEntity)15 Test (org.junit.Test)11 UpdateUserEntity (io.gravitee.rest.api.model.UpdateUserEntity)6 Instant (java.time.Instant)5 Response (javax.ws.rs.core.Response)5 Date (java.util.Date)4 SearchableUser (io.gravitee.rest.api.idp.api.identity.SearchableUser)3 ConsoleSettingsEntity (io.gravitee.rest.api.model.settings.ConsoleSettingsEntity)3 Group (io.gravitee.rest.api.portal.rest.model.Group)3 PortalApiLinkHelper.usersURL (io.gravitee.rest.api.portal.rest.utils.PortalApiLinkHelper.usersURL)3 UserService (io.gravitee.rest.api.service.UserService)3 ZoneOffset (java.time.ZoneOffset)3 List (java.util.List)3 Collectors (java.util.stream.Collectors)3 UriInfo (javax.ws.rs.core.UriInfo)3 Autowired (org.springframework.beans.factory.annotation.Autowired)3 Component (org.springframework.stereotype.Component)3 ApplicationEntity (io.gravitee.rest.api.model.ApplicationEntity)2 NewExternalUserEntity (io.gravitee.rest.api.model.NewExternalUserEntity)2