use of io.gravitee.rest.api.model.PageEntity in project gravitee-management-rest-api by gravitee-io.
the class ApiPageResourceNotAuthenticatedTest method init.
@Before
public void init() {
resetAllMocks();
mockApi = new ApiEntity();
mockApi.setId(API);
doReturn(mockApi).when(apiService).findById(API);
Set<ApiEntity> mockApis = new HashSet<>(Arrays.asList(mockApi));
doReturn(mockApis).when(apiService).findPublishedByUser(isNull(), argThat(q -> singletonList(API).equals(q.getIds())));
mockPage = new PageEntity();
mockPage.setPublished(true);
mockPage.setVisibility(Visibility.PUBLIC);
doReturn(mockPage).when(pageService).findById(PAGE, null);
mockAnotherPage = new PageEntity();
mockAnotherPage.setPublished(true);
mockAnotherPage.setVisibility(Visibility.PUBLIC);
Map<String, String> metadataMap = new HashMap<>();
metadataMap.put(ANOTHER_PAGE, ANOTHER_PAGE);
mockAnotherPage.setMetadata(metadataMap);
doReturn(mockAnotherPage).when(pageService).findById(ANOTHER_PAGE, null);
doReturn(new Page()).when(pageMapper).convert(any(), any(), any());
}
use of io.gravitee.rest.api.model.PageEntity in project gravitee-management-rest-api by gravitee-io.
the class DefaultPageRevisionUpgrader method upgrade.
@Override
public boolean upgrade() {
if (hasNoRevisions()) {
logger.info("No page revisions found. Create a default revision based on pages.");
final int pageSize = 100;
int pageNumber = 0;
Page<PageEntity> pagesSubSet = null;
do {
Pageable pageable = new PageableImpl(pageNumber, pageSize);
pagesSubSet = pageService.findAll(pageable);
if (!pagesSubSet.getContent().isEmpty()) {
pagesSubSet.getContent().stream().filter(entity -> pageService.shouldHaveRevision(entity.getType())).forEach(entity -> pageRevisionService.create(convert(entity)));
++pageNumber;
}
} while (!pagesSubSet.getContent().isEmpty());
}
return true;
}
use of io.gravitee.rest.api.model.PageEntity in project gravitee-management-rest-api by gravitee-io.
the class ApiPageResource method getPageContentByApiIdAndPageId.
@GET
@Path("content")
@Produces(MediaType.TEXT_PLAIN)
@RequirePortalAuth
public Response getPageContentByApiIdAndPageId(@PathParam("apiId") String apiId, @PathParam("pageId") String pageId) {
final ApiQuery apiQuery = new ApiQuery();
apiQuery.setIds(Collections.singletonList(apiId));
if (accessControlService.canAccessApiFromPortal(apiId)) {
PageEntity pageEntity = pageService.findById(pageId, null);
if (accessControlService.canAccessPageFromPortal(apiId, pageEntity)) {
pageService.transformSwagger(pageEntity, apiId);
return Response.ok(pageEntity.getContent()).build();
} else {
throw new UnauthorizedAccessException();
}
}
throw new ApiNotFoundException(apiId);
}
use of io.gravitee.rest.api.model.PageEntity in project gravitee-management-rest-api by gravitee-io.
the class ApiPageResource method updateApiPage.
@PUT
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
@ApiOperation(value = "Update a page", notes = "User must have the MANAGE_PAGES permission to use this service")
@ApiResponses({ @ApiResponse(code = 201, message = "Page successfully updated", response = PageEntity.class), @ApiResponse(code = 500, message = "Internal server error") })
@Permissions({ @Permission(value = RolePermission.API_DOCUMENTATION, acls = RolePermissionAction.UPDATE) })
public PageEntity updateApiPage(@ApiParam(name = "page", required = true) @Valid @NotNull UpdatePageEntity updatePageEntity) {
PageEntity existingPage = pageService.findById(page);
if (existingPage.getType().equals(PageType.SYSTEM_FOLDER.name())) {
throw new PageSystemFolderActionException("Update");
} else if (existingPage.getType().equals(PageType.MARKDOWN_TEMPLATE.name())) {
throw new PageMarkdownTemplateActionException("Update");
}
updatePageEntity.setLastContributor(getAuthenticatedUser());
return pageService.update(page, updatePageEntity);
}
use of io.gravitee.rest.api.model.PageEntity in project gravitee-management-rest-api by gravitee-io.
the class ApiPageResource method partialUpdateApiPage.
@PATCH
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
@ApiOperation(value = "Update a page", notes = "User must have the MANAGE_PAGES permission to use this service")
@ApiResponses({ @ApiResponse(code = 201, message = "Page successfully updated", response = PageEntity.class), @ApiResponse(code = 500, message = "Internal server error") })
@Permissions({ @Permission(value = RolePermission.API_DOCUMENTATION, acls = RolePermissionAction.UPDATE) })
public PageEntity partialUpdateApiPage(@ApiParam(name = "page") UpdatePageEntity updatePageEntity) {
PageEntity existingPage = pageService.findById(page);
if (existingPage.getType().equals(PageType.SYSTEM_FOLDER.name())) {
throw new PageSystemFolderActionException("Update");
} else if (existingPage.getType().equals(PageType.MARKDOWN_TEMPLATE.name())) {
throw new PageMarkdownTemplateActionException("Update");
}
updatePageEntity.setLastContributor(getAuthenticatedUser());
return pageService.update(page, updatePageEntity, true);
}
Aggregations