use of io.gravitee.management.model.ApplicationEntity in project gravitee-management-rest-api by gravitee-io.
the class AnalyticsServiceImpl method getApplicationMetadata.
private Map<String, String> getApplicationMetadata(String application) {
Map<String, String> metadata = new HashMap<>();
try {
ApplicationEntity applicationEntity = applicationService.findById(application);
metadata.put("name", applicationEntity.getName());
if (ApplicationStatus.ARCHIVED.toString().equals(applicationEntity.getStatus())) {
metadata.put("deleted", "true");
}
} catch (ApplicationNotFoundException anfe) {
metadata.put("deleted", "true");
if (application.equals(APPLICATION_KEYLESS)) {
metadata.put("name", "Unknown application (keyless)");
} else {
metadata.put("name", "Deleted application");
}
}
return metadata;
}
use of io.gravitee.management.model.ApplicationEntity in project gravitee-management-rest-api by gravitee-io.
the class ApplicationMembersResource method getPermissions.
@GET
@Path("/permissions")
@Produces(MediaType.APPLICATION_JSON)
@ApiOperation(value = "Get application members", notes = "User must have the APPLICATION_MEMBER permission to use this service")
@ApiResponses({ @ApiResponse(code = 200, message = "Application member's permissions", response = MemberEntity.class, responseContainer = "List"), @ApiResponse(code = 500, message = "Internal server error") })
@Permissions({ @Permission(value = RolePermission.APPLICATION_MEMBER, acls = RolePermissionAction.READ) })
public Response getPermissions(@PathParam("application") String application) {
Map<String, char[]> permissions = new HashMap<>();
if (isAuthenticated()) {
final String username = getAuthenticatedUser();
final ApplicationEntity applicationEntity = applicationService.findById(application);
if (isAdmin()) {
final char[] rights = new char[] { CREATE.getId(), READ.getId(), UPDATE.getId(), DELETE.getId() };
for (ApplicationPermission perm : ApplicationPermission.values()) {
permissions.put(perm.getName(), rights);
}
} else {
permissions = membershipService.getMemberPermissions(applicationEntity, username);
}
}
return Response.ok(permissions).build();
}
use of io.gravitee.management.model.ApplicationEntity in project gravitee-management-rest-api by gravitee-io.
the class ApiSubscribersResource method listApiSubscribers.
@GET
@Produces(MediaType.APPLICATION_JSON)
@ApiOperation(value = "List subscribers for the API", notes = "User must have the MANAGE_SUBSCRIPTIONS permission to use this service")
@ApiResponses({ @ApiResponse(code = 200, message = "Paged result of API subscribers", response = ApplicationEntity.class, responseContainer = "List"), @ApiResponse(code = 500, message = "Internal server error") })
@Permissions({ @Permission(value = RolePermission.API_SUBSCRIPTION, acls = RolePermissionAction.READ) })
public Collection<ApplicationEntity> listApiSubscribers(@PathParam("api") String api) {
SubscriptionQuery subscriptionQuery = new SubscriptionQuery();
subscriptionQuery.setApi(api);
Collection<SubscriptionEntity> subscriptions = subscriptionService.search(subscriptionQuery);
return subscriptions.stream().map(SubscriptionEntity::getApplication).distinct().map(application -> applicationService.findById(application)).sorted((o1, o2) -> String.CASE_INSENSITIVE_ORDER.compare(o1.getName(), o2.getName())).collect(Collectors.toList());
}
use of io.gravitee.management.model.ApplicationEntity in project gravitee-management-rest-api by gravitee-io.
the class ApplicationService_FindByUserTest method shouldFindByUser.
@Test
public void shouldFindByUser() throws Exception {
when(appMembership.getReferenceId()).thenReturn(APPLICATION_ID);
when(application.getId()).thenReturn(APPLICATION_ID);
when(application.getStatus()).thenReturn(ApplicationStatus.ACTIVE);
when(membershipRepository.findByUserAndReferenceType(USERNAME, MembershipReferenceType.APPLICATION)).thenReturn(Collections.singleton(appMembership));
when(applicationRepository.findByIds(Collections.singletonList(APPLICATION_ID))).thenReturn(Collections.singleton(application));
when(membershipRepository.findByUserAndReferenceType(USERNAME, MembershipReferenceType.GROUP)).thenReturn(Collections.emptySet());
when(applicationRepository.findByGroups(Collections.emptyList(), ApplicationStatus.ACTIVE)).thenReturn(Collections.emptySet());
Membership po = new Membership(USERNAME, APPLICATION_ID, MembershipReferenceType.APPLICATION);
po.setRoles(Collections.singletonMap(RoleScope.APPLICATION.getId(), SystemRole.PRIMARY_OWNER.name()));
when(membershipRepository.findByReferencesAndRole(any(), any(), eq(RoleScope.APPLICATION), any())).thenReturn(Collections.singleton(po));
when(userService.findByUsername(USERNAME, false)).thenReturn(new UserEntity());
Set<ApplicationEntity> apps = applicationService.findByUser(USERNAME);
Assert.assertNotNull(apps);
Assert.assertFalse("should find app", apps.isEmpty());
Assert.assertEquals(APPLICATION_ID, apps.iterator().next().getId());
}
use of io.gravitee.management.model.ApplicationEntity in project gravitee-management-rest-api by gravitee-io.
the class ApplicationService_FindByUserTest method shouldNotFindByUserBecauseOfArchived.
@Test
public void shouldNotFindByUserBecauseOfArchived() throws Exception {
when(appMembership.getReferenceId()).thenReturn(APPLICATION_ID);
when(application.getId()).thenReturn(APPLICATION_ID);
when(application.getStatus()).thenReturn(ApplicationStatus.ARCHIVED);
when(membershipRepository.findByUserAndReferenceType(USERNAME, MembershipReferenceType.APPLICATION)).thenReturn(Collections.singleton(appMembership));
when(applicationRepository.findByIds(Collections.singletonList(APPLICATION_ID))).thenReturn(Collections.singleton(application));
when(membershipRepository.findByUserAndReferenceType(USERNAME, MembershipReferenceType.GROUP)).thenReturn(Collections.emptySet());
when(applicationRepository.findByGroups(Collections.emptyList(), ApplicationStatus.ACTIVE)).thenReturn(Collections.emptySet());
Membership po = new Membership(USERNAME, APPLICATION_ID, MembershipReferenceType.APPLICATION);
po.setRoles(Collections.singletonMap(RoleScope.APPLICATION.getId(), SystemRole.PRIMARY_OWNER.name()));
when(membershipRepository.findByReferencesAndRole(any(), any(), eq(RoleScope.APPLICATION), any())).thenReturn(Collections.singleton(po));
when(userService.findByUsername(USERNAME, false)).thenReturn(new UserEntity());
Set<ApplicationEntity> apps = applicationService.findByUser(USERNAME);
Assert.assertNotNull(apps);
Assert.assertTrue("should not find app", apps.isEmpty());
}
Aggregations