use of io.gravitee.rest.api.portal.rest.model.Plan in project gravitee-management-rest-api by gravitee-io.
the class ApiPlansResource method getApiPlansByApiId.
@GET
@Produces(MediaType.APPLICATION_JSON)
@RequirePortalAuth
public Response getApiPlansByApiId(@PathParam("apiId") String apiId, @BeanParam PaginationParam paginationParam) {
String username = getAuthenticatedUserOrNull();
final ApiQuery apiQuery = new ApiQuery();
apiQuery.setIds(Collections.singletonList(apiId));
Collection<ApiEntity> userApis = apiService.findPublishedByUser(username, apiQuery);
if (userApis.stream().anyMatch(a -> a.getId().equals(apiId))) {
ApiEntity apiEntity = apiService.findById(apiId);
if (Visibility.PUBLIC.equals(apiEntity.getVisibility()) || hasPermission(API_PLAN, apiId, READ)) {
List<Plan> plans = planService.findByApi(apiId).stream().filter(plan -> PlanStatus.PUBLISHED.equals(plan.getStatus())).filter(plan -> groupService.isUserAuthorizedToAccessApiData(apiEntity, plan.getExcludedGroups(), username)).sorted(Comparator.comparingInt(PlanEntity::getOrder)).map(p -> planMapper.convert(p)).collect(Collectors.toList());
return createListResponse(plans, paginationParam);
} else {
return createListResponse(emptyList(), paginationParam);
}
}
throw new ApiNotFoundException(apiId);
}
use of io.gravitee.rest.api.portal.rest.model.Plan in project gravitee-management-rest-api by gravitee-io.
the class ApiResourceNotAuthenticatedTest method init.
@Before
public void init() {
resetAllMocks();
mockApi = new ApiEntity();
mockApi.setId(API);
doReturn(mockApi).when(apiService).findById(API);
when(accessControlService.canAccessApiFromPortal(API)).thenReturn(true);
when(accessControlService.canAccessApiFromPortal(mockApi)).thenReturn(true);
doReturn(Arrays.asList(new PageEntity())).when(pageService).search(any(), eq(GraviteeContext.getCurrentEnvironment()));
PlanEntity plan1 = new PlanEntity();
plan1.setId("A");
plan1.setStatus(PlanStatus.PUBLISHED);
PlanEntity plan2 = new PlanEntity();
plan2.setId("B");
plan2.setStatus(PlanStatus.PUBLISHED);
PlanEntity plan3 = new PlanEntity();
plan3.setId("C");
plan3.setStatus(PlanStatus.CLOSED);
doReturn(new HashSet<PlanEntity>(Arrays.asList(plan1, plan2, plan3))).when(planService).findByApi(API);
doReturn(new Api()).when(apiMapper).convert(any());
doReturn(new Page()).when(pageMapper).convert(any());
doReturn(new Plan()).when(planMapper).convert(any());
}
use of io.gravitee.rest.api.portal.rest.model.Plan in project gravitee-management-rest-api by gravitee-io.
the class ApiPlansResourceTest method shouldGetNoApiPlan.
@Test
public void shouldGetNoApiPlan() {
doReturn(false).when(groupService).isUserAuthorizedToAccessApiData(any(), any(), any());
final Response response = target(API).path("plans").request().get();
assertEquals(OK_200, response.getStatus());
PlansResponse plansResponse = response.readEntity(PlansResponse.class);
List<Plan> plans = plansResponse.getData();
assertNotNull(plans);
assertEquals(0, plans.size());
}
use of io.gravitee.rest.api.portal.rest.model.Plan in project gravitee-management-rest-api by gravitee-io.
the class ApiPlansResourceTest method shouldGetEmptyListPrivateAPIAndNoReadPermission.
@Test
public void shouldGetEmptyListPrivateAPIAndNoReadPermission() {
doReturn(false).when(permissionService).hasPermission(any(), any(), any());
ApiEntity mockApi = new ApiEntity();
mockApi.setId(API);
mockApi.setVisibility(Visibility.PRIVATE);
doReturn(mockApi).when(apiService).findById(API);
Set<ApiEntity> mockApis = new HashSet<>(Arrays.asList(mockApi));
doReturn(mockApis).when(apiService).findPublishedByUser(any());
final Response response = target(API).path("plans").request().get();
assertEquals(OK_200, response.getStatus());
PlansResponse plansResponse = response.readEntity(PlansResponse.class);
List<Plan> plans = plansResponse.getData();
assertNotNull(plans);
assertEquals(0, plans.size());
}
use of io.gravitee.rest.api.portal.rest.model.Plan in project gravitee-management-rest-api by gravitee-io.
the class ApiResourceNotAuthenticatedTest method callResourceAndCheckResult.
private void callResourceAndCheckResult(Integer expectedTotalPage, Integer expectedTotalPlan) {
final Response response = target(API).queryParam("include", "pages", "plans").request().get();
assertEquals(OK_200, response.getStatus());
Api responseApi = response.readEntity(Api.class);
assertNotNull(responseApi);
List<Page> pages = responseApi.getPages();
assertNotNull(pages);
assertEquals(expectedTotalPage.intValue(), pages.size());
List<Plan> plans = responseApi.getPlans();
assertNotNull(plans);
assertEquals(expectedTotalPlan.intValue(), plans.size());
}
Aggregations