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