use of io.gravitee.rest.api.model.PageEntity in project gravitee-management-rest-api by gravitee-io.
the class ApiPageResource method updatePageContent.
@PUT
@Path("/content")
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
@ApiOperation(value = "Put the page's content", notes = "User must have the MANAGE_PAGES permission to use this service")
@ApiResponses({ @ApiResponse(code = 201, message = "Page content successfully updated"), @ApiResponse(code = 500, message = "Internal server error") })
@Permissions({ @Permission(value = RolePermission.API_DOCUMENTATION, acls = RolePermissionAction.UPDATE) })
public String updatePageContent(@ApiParam(name = "content", required = true) @Valid @NotNull String content) {
pageService.findById(page);
UpdatePageEntity updatePageEntity = new UpdatePageEntity();
updatePageEntity.setContent(content);
PageEntity update = pageService.update(page, updatePageEntity, true);
return update.getContent();
}
use of io.gravitee.rest.api.model.PageEntity in project gravitee-management-rest-api by gravitee-io.
the class ApiPageResource method deleteApiPage.
@DELETE
@ApiOperation(value = "Delete a page", notes = "User must have the MANAGE_PAGES permission to use this service")
@ApiResponses({ @ApiResponse(code = 204, message = "Page successfully deleted"), @ApiResponse(code = 500, message = "Internal server error") })
@Permissions({ @Permission(value = RolePermission.API_DOCUMENTATION, acls = RolePermissionAction.DELETE) })
public void deleteApiPage() {
PageEntity existingPage = pageService.findById(page);
if (existingPage.getType().equals(PageType.SYSTEM_FOLDER.name())) {
throw new PageSystemFolderActionException("Delete");
} else if (existingPage.getType().equals(PageType.MARKDOWN_TEMPLATE.name())) {
throw new PageMarkdownTemplateActionException("Delete");
}
pageService.delete(page);
}
use of io.gravitee.rest.api.model.PageEntity in project gravitee-management-rest-api by gravitee-io.
the class PortalPageMediaResource method getPortalPageMedia.
@GET
@Produces(MediaType.APPLICATION_JSON)
@ApiOperation(value = "Retrieve all media for a Portal page", notes = "User must have the ENVIRONMENT_DOCUMENTATION[READ] permission to use this service")
@Permissions({ @Permission(value = RolePermission.ENVIRONMENT_DOCUMENTATION, acls = RolePermissionAction.READ) })
public Response getPortalPageMedia() {
final PageEntity currentPage = pageService.findById(page);
List<MediaEntity> pageMedia = mediaService.findAllWithoutContent(currentPage.getAttachedMedia());
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 PageService_ImportDescriptorTest method shouldImportDescriptor.
@Test
public void shouldImportDescriptor() throws Exception {
// We mock the validateSafeContent method because the fetcher keeps sending the same json descriptor which is
// not a swagger valid document (and modify the fetcher mock to produce valid desc is overkill)
when(pageService.validateSafeContent(any(), any())).thenReturn(new ArrayList<>());
PageSourceEntity pageSource = new PageSourceEntity();
pageSource.setType("type");
pageSource.setConfiguration(mapper.readTree("{}"));
ImportPageEntity pageEntity = new ImportPageEntity();
pageEntity.setSource(pageSource);
FetcherPlugin fetcherPlugin = mock(FetcherPlugin.class);
when(fetcherPlugin.clazz()).thenReturn("io.gravitee.rest.api.service.PageService_ImportDescriptorMockFetcher");
when(fetcherPlugin.configuration()).thenReturn(PageService_MockDescriptorFetcherConfiguration.class);
when(fetcherPluginManager.get(any())).thenReturn(fetcherPlugin);
Class<PageService_ImportDescriptorMockFetcher> mockFetcherClass = PageService_ImportDescriptorMockFetcher.class;
when(fetcherPlugin.fetcher()).thenReturn(mockFetcherClass);
PageService_MockDescriptorFetcherConfiguration fetcherConfiguration = new PageService_MockDescriptorFetcherConfiguration();
when(fetcherConfigurationFactory.create(eq(PageService_MockDescriptorFetcherConfiguration.class), anyString())).thenReturn(fetcherConfiguration);
AutowireCapableBeanFactory mockAutowireCapableBeanFactory = mock(AutowireCapableBeanFactory.class);
when(applicationContext.getAutowireCapableBeanFactory()).thenReturn(mockAutowireCapableBeanFactory);
Page newPage = mock(Page.class);
PageSource ps = new PageSource();
ps.setType(pageSource.getType());
ps.setConfiguration(pageSource.getConfiguration());
when(newPage.getId()).thenReturn(UuidString.generateRandom());
when(newPage.getSource()).thenReturn(ps);
when(newPage.getType()).thenReturn("MARKDOWN");
when(newPage.getReferenceType()).thenReturn(PageReferenceType.ENVIRONMENT);
when(newPage.getReferenceId()).thenReturn("envId");
when(newPage.getVisibility()).thenReturn("PUBLIC");
when(pageRepository.create(any())).thenReturn(newPage);
when(graviteeDescriptorService.descriptorName()).thenReturn(".gravitee.json");
when(graviteeDescriptorService.read(anyString())).thenCallRealMethod();
List<PageEntity> pageEntities = pageService.importFiles(pageEntity, GraviteeContext.getCurrentEnvironment());
assertNotNull(pageEntities);
assertEquals(8, pageEntities.size());
verify(pageRevisionService, times(6)).create(any());
}
use of io.gravitee.rest.api.model.PageEntity in project gravitee-management-rest-api by gravitee-io.
the class PageService_ImportDirectoryTest method shouldImportDirectory.
@Test
public void shouldImportDirectory() throws Exception {
// We mock the validateSafeContent method because the fetcher keeps sending the same json descriptor which is
// not a swagger valid document (and modify the fetcher mock to produce valid desc is overkill)
when(pageService.validateSafeContent(any(), any())).thenReturn(new ArrayList<>());
PageSourceEntity pageSource = new PageSourceEntity();
pageSource.setType("type");
pageSource.setConfiguration(mapper.readTree("{}"));
ImportPageEntity pageEntity = new ImportPageEntity();
pageEntity.setSource(pageSource);
pageEntity.setPublished(true);
FetcherPlugin fetcherPlugin = mock(FetcherPlugin.class);
when(fetcherPlugin.clazz()).thenReturn("io.gravitee.rest.api.service.PageService_ImportDirectoryMockFetcher");
when(fetcherPlugin.configuration()).thenReturn(PageService_MockFilesFetcherConfiguration.class);
when(fetcherPluginManager.get(any())).thenReturn(fetcherPlugin);
Class<PageService_ImportDirectoryMockFetcher> mockFetcherClass = PageService_ImportDirectoryMockFetcher.class;
when(fetcherPlugin.fetcher()).thenReturn(mockFetcherClass);
PageService_MockFilesFetcherConfiguration fetcherConfiguration = new PageService_MockFilesFetcherConfiguration();
when(fetcherConfigurationFactory.create(eq(PageService_MockFilesFetcherConfiguration.class), anyString())).thenReturn(fetcherConfiguration);
AutowireCapableBeanFactory mockAutowireCapableBeanFactory = mock(AutowireCapableBeanFactory.class);
when(applicationContext.getAutowireCapableBeanFactory()).thenReturn(mockAutowireCapableBeanFactory);
Page newPage = mock(Page.class);
PageSource ps = new PageSource();
ps.setType(pageSource.getType());
ps.setConfiguration(pageSource.getConfiguration());
when(newPage.getId()).thenReturn(UuidString.generateRandom());
when(newPage.isPublished()).thenReturn(Boolean.TRUE);
when(newPage.getSource()).thenReturn(ps);
when(newPage.getType()).thenReturn("MARKDOWN");
when(newPage.getReferenceType()).thenReturn(PageReferenceType.ENVIRONMENT);
when(newPage.getReferenceId()).thenReturn("envId");
when(newPage.getVisibility()).thenReturn("PUBLIC");
when(pageRepository.create(any())).thenReturn(newPage);
when(graviteeDescriptorService.descriptorName()).thenReturn(".gravitee.json");
List<PageEntity> pageEntities = pageService.importFiles(pageEntity, GraviteeContext.getCurrentEnvironment());
assertNotNull(pageEntities);
assertEquals(8, pageEntities.size());
verify(searchEngineService, times(8)).index(any(), eq(false));
// //////////////////////
// check Folder creation
// //////////////////////
verify(pageRepository, times(3)).create(argThat(pageToCreate -> "FOLDER".equals(pageToCreate.getType())));
// /src
verify(pageRepository).create(argThat(pageToCreate -> "src".equals(pageToCreate.getName()) && "FOLDER".equals(pageToCreate.getType()) && null == pageToCreate.getParentId()));
// /src/doc
verify(pageRepository).create(argThat(pageToCreate -> "doc".equals(pageToCreate.getName()) && "FOLDER".equals(pageToCreate.getType()) && null != pageToCreate.getParentId()));
// /src/folder.with.dot/
verify(pageRepository).create(argThat(pageToCreate -> "folder.with.dot".equals(pageToCreate.getName()) && "FOLDER".equals(pageToCreate.getType()) && null != pageToCreate.getParentId()));
// //////////////////////
// verify files creation
// //////////////////////
verify(pageRepository, times(5)).create(argThat(pageToCreate -> pageToCreate.getType() != null && !"FOLDER".equals(pageToCreate.getType())));
// /src/doc/m1.md
verify(pageRepository).create(argThat(pageToCreate -> "m1".equals(pageToCreate.getName()) && "MARKDOWN".equals(pageToCreate.getType()) && null != pageToCreate.getParentId()));
// /swagger.json
verify(pageRepository).create(argThat(pageToCreate -> "swagger".equals(pageToCreate.getName()) && "SWAGGER".equals(pageToCreate.getType()) && null == pageToCreate.getParentId()));
// /src/doc/sub.m11.md
verify(pageRepository).create(argThat(pageToCreate -> "sub.m11".equals(pageToCreate.getName()) && "MARKDOWN".equals(pageToCreate.getType()) && null != pageToCreate.getParentId()));
// /src/doc/m2.yaml
verify(pageRepository).create(argThat(pageToCreate -> "m2".equals(pageToCreate.getName()) && "SWAGGER".equals(pageToCreate.getType()) && null != pageToCreate.getParentId()));
// /src/folder.with.dot/m2.MD
verify(pageRepository).create(argThat(pageToCreate -> "m2".equals(pageToCreate.getName()) && "MARKDOWN".equals(pageToCreate.getType()) && null != pageToCreate.getParentId()));
verify(pageRevisionService, times(5)).create(any());
}
Aggregations