use of org.springframework.http.MediaType.APPLICATION_JSON_UTF8_VALUE in project BridgeServer2 by Sage-Bionetworks.
the class AppController method getAppMemberships.
@GetMapping(path = { "/v1/apps/memberships", "/v3/studies/memberships" }, produces = { APPLICATION_JSON_UTF8_VALUE })
public String getAppMemberships() throws Exception {
UserSession session = getAuthenticatedSession();
if (session.getParticipant().getRoles().isEmpty()) {
throw new UnauthorizedException(APP_ACCESS_EXCEPTION_MSG);
}
Stream<App> stream = null;
if (!session.isSynapseAuthenticated()) {
// If they have not signed in via Synapse, they cannot switch apps, so don't return any
stream = ImmutableList.<App>of().stream();
} else if (session.isInRole(SUPERADMIN)) {
// Superadmins can see all apps and can switch between all apps.
stream = appService.getApps().stream().filter(s -> s.isActive());
} else {
// Otherwise, apps are linked by Synapse user ID.
List<String> appIds = accountService.getAppIdsForUser(session.getParticipant().getSynapseUserId());
stream = appIds.stream().map(id -> appService.getApp(id)).filter(s -> s.isActive() && appIds.contains(s.getIdentifier()));
}
List<App> apps = stream.sorted(APP_COMPARATOR).collect(toList());
return APP_LIST_WRITER.writeValueAsString(new ResourceList<App>(apps, true));
}
Aggregations