use of io.gravitee.rest.api.portal.rest.model.Group in project gravitee-management-rest-api by gravitee-io.
the class ApplicationMapper method convert.
public Application convert(ApplicationListItem applicationListItem, UriInfo uriInfo) {
final Application application = new Application();
application.setApplicationType(applicationListItem.getType());
application.setCreatedAt(applicationListItem.getCreatedAt().toInstant().atOffset(ZoneOffset.UTC));
application.setDescription(applicationListItem.getDescription());
Set<String> groupEntities = applicationListItem.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(applicationListItem.getId());
application.setName(applicationListItem.getName());
UserEntity primaryOwnerUserEntity = userService.findById(applicationListItem.getPrimaryOwner().getId());
User owner = userMapper.convert(primaryOwnerUserEntity);
owner.setLinks(userMapper.computeUserLinks(usersURL(uriInfo.getBaseUriBuilder(), primaryOwnerUserEntity.getId()), primaryOwnerUserEntity.getUpdatedAt()));
application.setOwner(owner);
application.setUpdatedAt(applicationListItem.getUpdatedAt().toInstant().atOffset(ZoneOffset.UTC));
ApplicationSettings settings = applicationListItem.getSettings();
application.setHasClientId(settings != null && ((settings.getoAuthClient() != null && settings.getoAuthClient().getClientId() != null && !settings.getoAuthClient().getClientId().isEmpty()) || (settings.getApp() != null && settings.getApp().getClientId() != null && !settings.getApp().getClientId().isEmpty())));
return application;
}
use of io.gravitee.rest.api.portal.rest.model.Group 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.Group in project gravitee-management-rest-api by gravitee-io.
the class ApplicationMapperTest method checkApplication.
private void checkApplication(Instant now, Application responseApplication, AppSettingsEnum appSettingsType) {
assertNotNull(responseApplication);
assertNull(responseApplication.getLinks());
assertEquals(APPLICATION_TYPE, responseApplication.getApplicationType());
assertEquals(now.toEpochMilli(), responseApplication.getCreatedAt().toInstant().toEpochMilli());
assertEquals(APPLICATION_DESCRIPTION, responseApplication.getDescription());
assertEquals(APPLICATION_ID, responseApplication.getId());
assertEquals(APPLICATION_NAME, responseApplication.getName());
assertEquals(now.toEpochMilli(), responseApplication.getUpdatedAt().toInstant().toEpochMilli());
List<Group> groups = responseApplication.getGroups();
assertNotNull(groups);
assertEquals(1, groups.size());
assertEquals(APPLICATION_GROUP_ID, groups.get(0).getId());
assertEquals(APPLICATION_GROUP_NAME, groups.get(0).getName());
User owner = responseApplication.getOwner();
assertNotNull(owner);
assertEquals(APPLICATION_USER_DISPLAYNAME, owner.getDisplayName());
assertEquals(APPLICATION_USER_EMAIL, owner.getEmail());
assertEquals(APPLICATION_USER_ID, owner.getId());
assertEquals("environments/DEFAULT/users/" + APPLICATION_USER_ID + "/avatar?", owner.getLinks().getAvatar());
io.gravitee.rest.api.portal.rest.model.ApplicationSettings applicationSettings = responseApplication.getSettings();
if (AppSettingsEnum.NO_SETTINGS == appSettingsType) {
assertNull(applicationSettings);
} else {
io.gravitee.rest.api.portal.rest.model.SimpleApplicationSettings sas = applicationSettings.getApp();
io.gravitee.rest.api.portal.rest.model.OAuthClientSettings oacs = applicationSettings.getOauth();
if (AppSettingsEnum.OAUTH_SETTINGS == appSettingsType) {
assertNull(sas);
assertNotNull(oacs);
assertEquals(APPLICATION_OAUTH_APPLICATION_TYPE, oacs.getApplicationType());
assertEquals(APPLICATION_OAUTH_CLIENT_ID, oacs.getClientId());
assertEquals(APPLICATION_OAUTH_CLIENT_SECRET, oacs.getClientSecret());
assertEquals(APPLICATION_OAUTH_CLIENT_URI, oacs.getClientUri());
assertEquals(APPLICATION_OAUTH_LOGO_URI, oacs.getLogoUri());
assertEquals(Boolean.TRUE, oacs.getRenewClientSecretSupported());
final List<String> grantTypes = oacs.getGrantTypes();
assertNotNull(grantTypes);
assertFalse(grantTypes.isEmpty());
assertEquals(APPLICATION_OAUTH_GRANT_TYPE, grantTypes.get(0));
final List<String> redirectUris = oacs.getRedirectUris();
assertNotNull(redirectUris);
assertFalse(redirectUris.isEmpty());
assertEquals(APPLICATION_OAUTH_REDIRECT_URI, redirectUris.get(0));
final List<String> responseTypes = oacs.getResponseTypes();
assertNotNull(responseTypes);
assertFalse(responseTypes.isEmpty());
assertEquals(APPLICATION_OAUTH_RESPONSE_TYPE, responseTypes.get(0));
assertEquals(responseApplication.getHasClientId(), true);
} else if (AppSettingsEnum.SIMPLE_SETTINGS == appSettingsType) {
assertNotNull(sas);
assertNull(oacs);
assertEquals(APPLICATION_SIMPLE_CLIENT_ID, sas.getClientId());
assertEquals(APPLICATION_SIMPLE_TYPE, sas.getType());
assertEquals(responseApplication.getHasClientId(), true);
}
}
}
Aggregations