use of io.gravitee.rest.api.model.PageEntity in project gravitee-management-rest-api by gravitee-io.
the class PageMapper method convert.
public Page convert(UriBuilder baseUriBuilder, String apiId, PageEntity page) {
final Page pageItem = new Page();
if (page.getConfiguration() != null) {
PageConfiguration pageConfiguration = convertPageConfiguration(page.getConfiguration());
pageItem.setConfiguration(pageConfiguration);
}
pageItem.setId(page.getId());
if (page.getMetadata() != null) {
AtomicInteger counter = new AtomicInteger(0);
List<Metadata> metadataList = page.getMetadata().entrySet().stream().map(e -> new Metadata().name(e.getKey()).value(e.getValue()).order(Integer.toString(counter.getAndIncrement()))).collect(Collectors.toList());
pageItem.setMetadata(metadataList);
}
pageItem.setName(page.getName());
pageItem.setOrder(page.getOrder());
pageItem.setParent(page.getParentId());
if (page.getType() != null) {
pageItem.setType(TypeEnum.fromValue(page.getType()));
}
if (page.getLastModificationDate() != null) {
pageItem.setUpdatedAt(page.getLastModificationDate().toInstant().atOffset(ZoneOffset.UTC));
}
if (page.getAttachedMedia() != null && !page.getAttachedMedia().isEmpty() && baseUriBuilder != null) {
final String mediaUrl = PortalApiLinkHelper.mediaURL(baseUriBuilder, apiId);
final List<PageMedia> pageMedia = mediaService.findAllWithoutContent(page.getAttachedMedia(), apiId).stream().map(media -> new PageMedia().name(media.getFileName()).link(mediaUrl + "/" + media.getHash()).type(media.getType())).collect(Collectors.toList());
pageItem.setMedia(pageMedia);
}
if (page.getContentRevisionId() != null) {
final PageRevisionId contentRevisionId = new PageRevisionId();
// do not use the pageId because the content maybe a translation (so a different pageId in the revisionId)
contentRevisionId.setPageId(page.getContentRevisionId().getPageId());
contentRevisionId.setRevision(page.getContentRevisionId().getRevision());
pageItem.setContentRevisionId(contentRevisionId);
}
return pageItem;
}
use of io.gravitee.rest.api.model.PageEntity in project gravitee-management-rest-api by gravitee-io.
the class PortalPagesResourceAdminTest method shouldCreatePortalPage.
@Test
public void shouldCreatePortalPage() {
reset(pageService);
NewPageEntity newPageEntity = new NewPageEntity();
newPageEntity.setName("my-page-name");
newPageEntity.setType(PageType.MARKDOWN);
newPageEntity.setVisibility(Visibility.PUBLIC);
PageEntity returnedPage = new PageEntity();
returnedPage.setId("my-beautiful-page");
doReturn(returnedPage).when(pageService).createPage(any(), eq(GraviteeContext.getCurrentEnvironment()));
doReturn(0).when(pageService).findMaxPortalPageOrder(eq(GraviteeContext.getCurrentEnvironment()));
final Response response = envTarget().request().post(Entity.json(newPageEntity));
assertEquals(HttpStatusCode.CREATED_201, response.getStatus());
assertEquals(envTarget().path("my-beautiful-page").getUri().toString(), response.getHeaders().getFirst(HttpHeaders.LOCATION));
}
use of io.gravitee.rest.api.model.PageEntity in project gravitee-management-rest-api by gravitee-io.
the class ApiPageMediaResource method getApiPageMedia.
@GET
@Produces(MediaType.APPLICATION_JSON)
@ApiOperation(value = "Retrieve all media for an API page", notes = "User must have the API_DOCUMENTATION[READ] permission to use this service")
@Permissions({ @Permission(value = RolePermission.API_DOCUMENTATION, acls = RolePermissionAction.READ) })
public Response getApiPageMedia() {
final PageEntity currentPage = pageService.findById(page);
List<MediaEntity> pageMedia = mediaService.findAllWithoutContent(currentPage.getAttachedMedia(), api);
if (pageMedia != null && !pageMedia.isEmpty()) {
return Response.ok(pageMedia).build();
}
return Response.noContent().build();
}
use of io.gravitee.rest.api.model.PageEntity in project gravitee-management-rest-api by gravitee-io.
the class PageMapperTest method testMinimalConvert.
@Test
public void testMinimalConvert() {
// init
pageEntity = new PageEntity();
pageEntity.setType(PAGE_TYPE);
Instant now = Instant.now();
pageEntity.setLastModificationDate(Date.from(now));
// Test
Page responsePage = pageMapper.convert(pageEntity);
assertNotNull(responsePage);
PageConfiguration pageConfiguration = responsePage.getConfiguration();
assertNull(pageConfiguration);
List<Metadata> metadatas = responsePage.getMetadata();
assertNull(metadatas);
assertEquals(TypeEnum.SWAGGER, responsePage.getType());
assertEquals(now.toEpochMilli(), responsePage.getUpdatedAt().toInstant().toEpochMilli());
}
use of io.gravitee.rest.api.model.PageEntity in project gravitee-management-rest-api by gravitee-io.
the class ApiPageResource method getPageByApiIdAndPageId.
@GET
@Produces(MediaType.APPLICATION_JSON)
@RequirePortalAuth
public Response getPageByApiIdAndPageId(@HeaderParam("Accept-Language") String acceptLang, @PathParam("apiId") String apiId, @PathParam("pageId") String pageId, @QueryParam("include") List<String> include) {
final ApiQuery apiQuery = new ApiQuery();
apiQuery.setIds(Collections.singletonList(apiId));
if (accessControlService.canAccessApiFromPortal(apiId)) {
final String acceptedLocale = HttpHeadersUtil.getFirstAcceptedLocaleName(acceptLang);
PageEntity pageEntity = pageService.findById(pageId, acceptedLocale);
if (accessControlService.canAccessPageFromPortal(apiId, pageEntity)) {
pageService.transformSwagger(pageEntity, apiId);
if (!isAuthenticated() && pageEntity.getMetadata() != null) {
pageEntity.getMetadata().clear();
}
Page page = pageMapper.convert(uriInfo.getBaseUriBuilder(), apiId, pageEntity);
if (include.contains(INCLUDE_CONTENT)) {
page.setContent(pageEntity.getContent());
}
page.setLinks(pageMapper.computePageLinks(PortalApiLinkHelper.apiPagesURL(uriInfo.getBaseUriBuilder(), apiId, pageId), PortalApiLinkHelper.apiPagesURL(uriInfo.getBaseUriBuilder(), apiId, page.getParent())));
return Response.ok(page).build();
} else {
throw new UnauthorizedAccessException();
}
}
throw new ApiNotFoundException(apiId);
}
Aggregations