Search in sources :

Example 1 with PageQuery

use of io.gravitee.rest.api.model.documentation.PageQuery in project gravitee-management-rest-api by gravitee-io.

the class ApiResourceTest method shouldGetApiLinks.

@Test
public void shouldGetApiLinks() {
    resetAllMocks();
    PageEntity sysFolder = new PageEntity();
    sysFolder.setId("SYS_FOLDER");
    sysFolder.setType("SYSTEM_FOLDER");
    sysFolder.setName("SYSTEM_FOLDER");
    sysFolder.setPublished(true);
    PageEntity linkSysFolder = new PageEntity();
    linkSysFolder.setId("LINK_SYS_FOLDER");
    linkSysFolder.setParentId("SYS_FOLDER");
    linkSysFolder.setType("LINK");
    linkSysFolder.setName("LINK");
    linkSysFolder.setContent("LINK_RES_REF");
    linkSysFolder.setPublished(true);
    Map<String, String> linkConf = new HashMap<>();
    linkConf.put(PageConfigurationKeys.LINK_RESOURCE_TYPE, "external");
    linkSysFolder.setConfiguration(linkConf);
    PageEntity swaggerSysFolder = new PageEntity();
    swaggerSysFolder.setId("SWAGGER_SYS_FOLDER");
    swaggerSysFolder.setParentId("SYS_FOLDER");
    swaggerSysFolder.setType("SWAGGER");
    swaggerSysFolder.setName("SWAGGER");
    swaggerSysFolder.setPublished(true);
    PageEntity folderSysFolder = new PageEntity();
    folderSysFolder.setId("FOLDER_SYS_FOLDER");
    folderSysFolder.setParentId("SYS_FOLDER");
    folderSysFolder.setType("FOLDER");
    folderSysFolder.setName("FOLDER");
    folderSysFolder.setPublished(true);
    PageEntity markdownFolderSysFolder = new PageEntity();
    markdownFolderSysFolder.setId("MARKDOWN_FOLDER_SYS_FOLDER");
    markdownFolderSysFolder.setParentId("FOLDER_SYS_FOLDER");
    markdownFolderSysFolder.setType("MARKDOWN");
    markdownFolderSysFolder.setName("MARKDOWN");
    markdownFolderSysFolder.setPublished(true);
    PageEntity markdownTemplate = new PageEntity();
    markdownTemplate.setId("MARKDOWN_TEMPLATE");
    markdownTemplate.setParentId("SYS_FOLDER");
    markdownTemplate.setType("MARKDOWN_TEMPLATE");
    markdownTemplate.setName("MARKDOWN_TEMPLATE");
    markdownTemplate.setPublished(true);
    when(pageService.search(any(PageQuery.class), isNull(), eq(GraviteeContext.getCurrentEnvironment()))).thenAnswer((Answer<List<PageEntity>>) invocation -> {
        PageQuery pq = invocation.getArgument(0);
        if (PageType.SYSTEM_FOLDER.equals(pq.getType()) && API.equals(pq.getApi())) {
            return Collections.singletonList(sysFolder);
        } else if ("SYS_FOLDER".equals(pq.getParent()) && API.equals(pq.getApi())) {
            return Arrays.asList(linkSysFolder, swaggerSysFolder, folderSysFolder, markdownTemplate);
        } else if ("FOLDER_SYS_FOLDER".equals(pq.getParent()) && API.equals(pq.getApi())) {
            return Collections.singletonList(markdownFolderSysFolder);
        }
        return null;
    });
    when(accessControlService.canAccessPageFromPortal(any())).thenReturn(true);
    final Response response = target(API).path("links").request().get();
    assertEquals(HttpStatusCode.OK_200, response.getStatus());
    final LinksResponse links = response.readEntity(LinksResponse.class);
    assertNotNull(links);
    Map<String, List<CategorizedLinks>> slots = links.getSlots();
    assertNotNull(slots);
    assertEquals(1, slots.size());
    List<CategorizedLinks> sysFolderList = slots.get("system_folder");
    assertNotNull(sysFolderList);
    assertEquals(2, sysFolderList.size());
    CategorizedLinks rootCat = sysFolderList.get(0);
    assertNotNull(rootCat);
    assertTrue(rootCat.getRoot());
    assertEquals("SYSTEM_FOLDER", rootCat.getCategory());
    List<Link> rootCatLinks = rootCat.getLinks();
    assertNotNull(rootCatLinks);
    assertEquals(2, rootCatLinks.size());
    Link rootCatLink = rootCatLinks.get(0);
    assertNotNull(rootCatLink);
    assertEquals("LINK", rootCatLink.getName());
    assertEquals("LINK_RES_REF", rootCatLink.getResourceRef());
    assertEquals(ResourceTypeEnum.EXTERNAL, rootCatLink.getResourceType());
    assertNull(rootCatLink.getFolder());
    Link rootCatSwagger = rootCatLinks.get(1);
    assertNotNull(rootCatSwagger);
    assertEquals("SWAGGER", rootCatSwagger.getName());
    assertEquals("SWAGGER_SYS_FOLDER", rootCatSwagger.getResourceRef());
    assertEquals(ResourceTypeEnum.PAGE, rootCatSwagger.getResourceType());
    CategorizedLinks folderCat = sysFolderList.get(1);
    assertNotNull(folderCat);
    assertFalse(folderCat.getRoot());
    assertEquals("FOLDER", folderCat.getCategory());
    List<Link> folderCatLinks = folderCat.getLinks();
    assertNotNull(folderCatLinks);
    assertEquals(1, folderCatLinks.size());
    Link folderCatMarkdown = folderCatLinks.get(0);
    assertNotNull(folderCatMarkdown);
    assertEquals("MARKDOWN", folderCatMarkdown.getName());
    assertEquals("MARKDOWN_FOLDER_SYS_FOLDER", folderCatMarkdown.getResourceRef());
    assertEquals(ResourceTypeEnum.PAGE, folderCatMarkdown.getResourceType());
}
Also used : java.util(java.util) ArgumentMatchers(org.mockito.ArgumentMatchers) OK_200(io.gravitee.common.http.HttpStatusCode.OK_200) URISyntaxException(java.net.URISyntaxException) GraviteeContext(io.gravitee.rest.api.service.common.GraviteeContext) Error(io.gravitee.rest.api.portal.rest.model.Error) HttpStatusCode(io.gravitee.common.http.HttpStatusCode) Answer(org.mockito.stubbing.Answer) InvocationOnMock(org.mockito.invocation.InvocationOnMock) ArgumentCaptor(org.mockito.ArgumentCaptor) PageQuery(io.gravitee.rest.api.model.documentation.PageQuery) io.gravitee.rest.api.model(io.gravitee.rest.api.model) Mockito.doReturn(org.mockito.Mockito.doReturn) Before(org.junit.Before) ApiEntity(io.gravitee.rest.api.model.api.ApiEntity) ResourceTypeEnum(io.gravitee.rest.api.portal.rest.model.Link.ResourceTypeEnum) Files(java.nio.file.Files) NOT_FOUND_404(io.gravitee.common.http.HttpStatusCode.NOT_FOUND_404) io.gravitee.rest.api.portal.rest.model(io.gravitee.rest.api.portal.rest.model) IOException(java.io.IOException) Test(org.junit.Test) Mockito.when(org.mockito.Mockito.when) Instant(java.time.Instant) Mockito(org.mockito.Mockito) Response(javax.ws.rs.core.Response) Paths(java.nio.file.Paths) Assert(org.junit.Assert) PageQuery(io.gravitee.rest.api.model.documentation.PageQuery) Response(javax.ws.rs.core.Response) Test(org.junit.Test)

Example 2 with PageQuery

use of io.gravitee.rest.api.model.documentation.PageQuery in project gravitee-management-rest-api by gravitee-io.

the class PageServiceImpl method createOrUpdateChildrenPages.

private void createOrUpdateChildrenPages(String apiId, String parentId, List<PageServiceImpl.PageEntityTreeNode> children, String environmentId) {
    for (final PageServiceImpl.PageEntityTreeNode child : children) {
        PageEntity pageEntityToImport = child.data;
        pageEntityToImport.setParentId(parentId);
        String newPageEntityId = UuidString.generateForEnvironment(environmentId, apiId, pageEntityToImport.getId());
        PageEntity createdOrUpdatedPage = null;
        if (pageEntityToImport.getId() != null) {
            try {
                createdOrUpdatedPage = findById(newPageEntityId);
            } catch (PageNotFoundException e) {
            // Page not found 🤷 Just create a new one
            }
        } else {
            PageQuery query = new PageQuery.Builder().api(apiId).name(pageEntityToImport.getName()).type(PageType.valueOf(pageEntityToImport.getType())).build();
            List<PageEntity> foundPages = search(query, environmentId);
            if (foundPages.size() == 1) {
                createdOrUpdatedPage = foundPages.get(0);
            } else if (foundPages.size() > 1) {
                logger.error("Not able to identify the page to update: {}. Too much pages with the same name", pageEntityToImport.getName());
                throw new TechnicalManagementException("Not able to identify the page to update: " + pageEntityToImport.getName() + ". Too much pages with the same name");
            }
        }
        if (createdOrUpdatedPage == null) {
            createdOrUpdatedPage = createPage(apiId, NewPageEntity.from(pageEntityToImport), environmentId, newPageEntityId);
        } else {
            createdOrUpdatedPage = update(createdOrUpdatedPage.getId(), UpdatePageEntity.from(pageEntityToImport));
        }
        if (child.children != null && !child.children.isEmpty()) {
            this.createOrUpdateChildrenPages(apiId, createdOrUpdatedPage.getId(), child.children, environmentId);
        }
    }
}
Also used : GraviteeDescriptorPageEntity(io.gravitee.rest.api.model.descriptor.GraviteeDescriptorPageEntity) PageQuery(io.gravitee.rest.api.model.documentation.PageQuery) PageableBuilder(io.gravitee.repository.management.api.search.builder.PageableBuilder) UuidString(io.gravitee.rest.api.service.common.UuidString)

Example 3 with PageQuery

use of io.gravitee.rest.api.model.documentation.PageQuery in project gravitee-management-rest-api by gravitee-io.

the class PageServiceImpl method search.

private List<PageEntity> search(final PageQuery query, String acceptedLocale, boolean withTranslations, boolean withLinks, String environmentId) {
    try {
        Stream<Page> pagesStream = pageRepository.search(queryToCriteria(query, environmentId)).stream();
        if (!withTranslations) {
            pagesStream = pagesStream.filter(page -> !PageType.TRANSLATION.name().equals(page.getType()));
        }
        if (!withLinks) {
            pagesStream = pagesStream.filter(page -> !PageType.LINK.name().equals(page.getType()));
        }
        List<PageEntity> pages = pagesStream.map(this::convert).collect(Collectors.toList());
        if (acceptedLocale == null || acceptedLocale.isEmpty()) {
            pages.forEach(p -> {
                if (!PageType.TRANSLATION.name().equals(p.getType())) {
                    List<PageEntity> translations = convert(getTranslations(p.getId()));
                    if (translations != null && !translations.isEmpty()) {
                        p.setTranslations(translations);
                    }
                }
            });
        } else {
            pages.forEach(p -> {
                if (!PageType.TRANSLATION.name().equals(p.getType())) {
                    Page translation = getTranslation(p, acceptedLocale);
                    if (translation != null) {
                        String translationName = translation.getName();
                        if (translationName != null && !translationName.isEmpty()) {
                            p.setName(translationName);
                        }
                        String inheritContent = translation.getConfiguration().get(PageConfigurationKeys.TRANSLATION_INHERIT_CONTENT);
                        if (inheritContent != null && "false".equals(inheritContent)) {
                            p.setContent(translation.getContent());
                        }
                    }
                }
            });
        }
        if (query != null && query.getPublished() != null && query.getPublished() || !isAuthenticated()) {
            // remove child of unpublished folders
            return pages.stream().filter(page -> {
                if (page.getParentId() != null) {
                    PageEntity parent = this.findById(page.getParentId());
                    if (!isAuthenticated()) {
                        return parent.isPublished() && Visibility.PUBLIC.equals(parent.getVisibility());
                    } else {
                        return parent.isPublished();
                    }
                }
                return true;
            }).collect(toList());
        }
        return pages;
    } catch (TechnicalException ex) {
        logger.error("An error occurs while trying to search pages", ex);
        throw new TechnicalManagementException("An error occurs while trying to search pages", ex);
    }
}
Also used : GraviteeDescriptorEntity(io.gravitee.rest.api.model.descriptor.GraviteeDescriptorEntity) TechnicalException(io.gravitee.repository.exceptions.TechnicalException) LoggerFactory(org.slf4j.LoggerFactory) Autowired(org.springframework.beans.factory.annotation.Autowired) StringUtils(org.apache.commons.lang3.StringUtils) DeserializationFeature(com.fasterxml.jackson.databind.DeserializationFeature) PageConfigurationOAITransformer(io.gravitee.rest.api.service.impl.swagger.transformer.page.PageConfigurationOAITransformer) Arrays.asList(java.util.Arrays.asList) Gson(com.google.gson.Gson) FetcherConfigurationFactory(io.gravitee.rest.api.fetcher.FetcherConfigurationFactory) PageableBuilder(io.gravitee.repository.management.api.search.builder.PageableBuilder) PageQuery(io.gravitee.rest.api.model.documentation.PageQuery) CronSequenceGenerator(org.springframework.scheduling.support.CronSequenceGenerator) JsonNode(com.fasterxml.jackson.databind.JsonNode) TypeReference(com.fasterxml.jackson.core.type.TypeReference) HtmlSanitizer(io.gravitee.rest.api.service.sanitizer.HtmlSanitizer) PageCriteria(io.gravitee.repository.management.api.search.PageCriteria) GraviteeDescriptorPageEntity(io.gravitee.rest.api.model.descriptor.GraviteeDescriptorPageEntity) PluginManager(io.gravitee.plugin.core.api.PluginManager) OAIParser(io.gravitee.rest.api.service.impl.swagger.parser.OAIParser) Collectors(java.util.stream.Collectors) FetcherPlugin(io.gravitee.plugin.fetcher.FetcherPlugin) MediaType(io.gravitee.common.http.MediaType) Stream(java.util.stream.Stream) Visibility(io.gravitee.rest.api.model.Visibility) CollectionUtils(org.springframework.util.CollectionUtils) UrlSanitizerUtils(io.gravitee.rest.api.service.sanitizer.UrlSanitizerUtils) PAGE(io.gravitee.repository.management.model.Audit.AuditProperties.PAGE) ApplicationContextAware(org.springframework.context.ApplicationContextAware) SearchEngineService(io.gravitee.rest.api.service.search.SearchEngineService) AuditEvent(io.gravitee.repository.management.model.Page.AuditEvent) io.gravitee.rest.api.service(io.gravitee.rest.api.service) java.util(java.util) Pageable(io.gravitee.rest.api.model.common.Pageable) ImportConfiguration(io.gravitee.rest.api.service.spring.ImportConfiguration) EntrypointsOAITransformer(io.gravitee.rest.api.service.impl.swagger.transformer.entrypoints.EntrypointsOAITransformer) Value(org.springframework.beans.factory.annotation.Value) SwaggerTransformer(io.gravitee.rest.api.service.impl.swagger.transformer.SwaggerTransformer) NotificationTemplateService(io.gravitee.rest.api.service.notification.NotificationTemplateService) PageRepository(io.gravitee.repository.management.api.PageRepository) io.gravitee.rest.api.model(io.gravitee.rest.api.model) UuidString(io.gravitee.rest.api.service.common.UuidString) ApiEntity(io.gravitee.rest.api.model.api.ApiEntity) Logger(org.slf4j.Logger) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) OAIDescriptor(io.gravitee.rest.api.service.swagger.OAIDescriptor) IOException(java.io.IOException) BeansException(org.springframework.beans.BeansException) Field(java.lang.reflect.Field) InputStreamReader(java.io.InputStreamReader) ApplicationContext(org.springframework.context.ApplicationContext) Collectors.toList(java.util.stream.Collectors.toList) Component(org.springframework.stereotype.Component) io.gravitee.fetcher.api(io.gravitee.fetcher.api) io.gravitee.repository.management.model(io.gravitee.repository.management.model) SwaggerDescriptor(io.gravitee.rest.api.service.swagger.SwaggerDescriptor) io.gravitee.rest.api.service.exceptions(io.gravitee.rest.api.service.exceptions) BufferedReader(java.io.BufferedReader) Collections(java.util.Collections) GraviteeDescriptorPageEntity(io.gravitee.rest.api.model.descriptor.GraviteeDescriptorPageEntity) TechnicalException(io.gravitee.repository.exceptions.TechnicalException) UuidString(io.gravitee.rest.api.service.common.UuidString)

Example 4 with PageQuery

use of io.gravitee.rest.api.model.documentation.PageQuery in project gravitee-management-rest-api by gravitee-io.

the class ConfigurationResourceTest method shouldGetPortalLinks.

@Test
public void shouldGetPortalLinks() {
    resetAllMocks();
    PageEntity sysFolder = new PageEntity();
    sysFolder.setId("SYS_FOLDER");
    sysFolder.setType("SYSTEM_FOLDER");
    sysFolder.setName("SYSTEM_FOLDER");
    sysFolder.setPublished(true);
    PageEntity linkSysFolder = new PageEntity();
    linkSysFolder.setId("LINK_SYS_FOLDER");
    linkSysFolder.setParentId("SYS_FOLDER");
    linkSysFolder.setType("LINK");
    linkSysFolder.setName("LINK");
    linkSysFolder.setContent("LINK_RES_REF");
    linkSysFolder.setPublished(true);
    Map<String, String> linkConf = new HashMap<>();
    linkConf.put(PageConfigurationKeys.LINK_RESOURCE_TYPE, "external");
    linkSysFolder.setConfiguration(linkConf);
    PageEntity swaggerSysFolder = new PageEntity();
    swaggerSysFolder.setId("SWAGGER_SYS_FOLDER");
    swaggerSysFolder.setParentId("SYS_FOLDER");
    swaggerSysFolder.setType("SWAGGER");
    swaggerSysFolder.setName("SWAGGER");
    swaggerSysFolder.setPublished(true);
    PageEntity folderSysFolder = new PageEntity();
    folderSysFolder.setId("FOLDER_SYS_FOLDER");
    folderSysFolder.setParentId("SYS_FOLDER");
    folderSysFolder.setType("FOLDER");
    folderSysFolder.setName("FOLDER");
    folderSysFolder.setPublished(true);
    PageEntity markdownFolderSysFolder = new PageEntity();
    markdownFolderSysFolder.setId("MARKDOWN_FOLDER_SYS_FOLDER");
    markdownFolderSysFolder.setParentId("FOLDER_SYS_FOLDER");
    markdownFolderSysFolder.setType("MARKDOWN");
    markdownFolderSysFolder.setName("MARKDOWN");
    markdownFolderSysFolder.setPublished(true);
    PageEntity markdownTemplate = new PageEntity();
    markdownTemplate.setId("MARKDOWN_TEMPLATE");
    markdownTemplate.setParentId("SYS_FOLDER");
    markdownTemplate.setType("MARKDOWN_TEMPLATE");
    markdownTemplate.setName("MARKDOWN_TEMPLATE");
    markdownTemplate.setPublished(true);
    when(pageService.search(any(PageQuery.class), isNull(), eq(GraviteeContext.getCurrentEnvironment()))).thenAnswer((Answer<List<PageEntity>>) invocation -> {
        PageQuery pq = invocation.getArgument(0);
        if (PageType.SYSTEM_FOLDER.equals(pq.getType())) {
            return Arrays.asList(sysFolder);
        } else if ("SYS_FOLDER".equals(pq.getParent())) {
            return Arrays.asList(linkSysFolder, swaggerSysFolder, folderSysFolder, markdownTemplate);
        } else if ("FOLDER_SYS_FOLDER".equals(pq.getParent())) {
            return Arrays.asList(markdownFolderSysFolder);
        }
        return null;
    });
    when(accessControlService.canAccessPageFromPortal(any())).thenReturn(true);
    final Response response = target("/links").request().get();
    assertEquals(HttpStatusCode.OK_200, response.getStatus());
    final LinksResponse links = response.readEntity(LinksResponse.class);
    assertNotNull(links);
    Map<String, List<CategorizedLinks>> slots = links.getSlots();
    assertNotNull(slots);
    assertEquals(1, slots.size());
    List<CategorizedLinks> sysFolderList = slots.get("system_folder");
    assertNotNull(sysFolderList);
    assertEquals(2, sysFolderList.size());
    CategorizedLinks rootCat = sysFolderList.get(0);
    assertNotNull(rootCat);
    assertTrue(rootCat.getRoot());
    assertEquals("SYSTEM_FOLDER", rootCat.getCategory());
    List<Link> rootCatLinks = rootCat.getLinks();
    assertNotNull(rootCatLinks);
    assertEquals(2, rootCatLinks.size());
    Link rootCatLink = rootCatLinks.get(0);
    assertNotNull(rootCatLink);
    assertEquals("LINK", rootCatLink.getName());
    assertEquals("LINK_RES_REF", rootCatLink.getResourceRef());
    assertEquals(ResourceTypeEnum.EXTERNAL, rootCatLink.getResourceType());
    assertNull(rootCatLink.getFolder());
    Link rootCatSwagger = rootCatLinks.get(1);
    assertNotNull(rootCatSwagger);
    assertEquals("SWAGGER", rootCatSwagger.getName());
    assertEquals("SWAGGER_SYS_FOLDER", rootCatSwagger.getResourceRef());
    assertEquals(ResourceTypeEnum.PAGE, rootCatSwagger.getResourceType());
    CategorizedLinks folderCat = sysFolderList.get(1);
    assertNotNull(folderCat);
    assertFalse(folderCat.getRoot());
    assertEquals("FOLDER", folderCat.getCategory());
    List<Link> folderCatLinks = folderCat.getLinks();
    assertNotNull(folderCatLinks);
    assertEquals(1, folderCatLinks.size());
    Link folderCatMarkdown = folderCatLinks.get(0);
    assertNotNull(folderCatMarkdown);
    assertEquals("MARKDOWN", folderCatMarkdown.getName());
    assertEquals("MARKDOWN_FOLDER_SYS_FOLDER", folderCatMarkdown.getResourceRef());
    assertEquals(ResourceTypeEnum.PAGE, folderCatMarkdown.getResourceType());
}
Also used : PageEntity(io.gravitee.rest.api.model.PageEntity) PageEntity(io.gravitee.rest.api.model.PageEntity) ConsoleSettingsEntity(io.gravitee.rest.api.model.settings.ConsoleSettingsEntity) PortalSettingsEntity(io.gravitee.rest.api.model.settings.PortalSettingsEntity) java.util(java.util) ArgumentMatchers(org.mockito.ArgumentMatchers) PageType(io.gravitee.rest.api.model.PageType) TechnicalException(io.gravitee.repository.exceptions.TechnicalException) ApplicationGrantTypeEntity(io.gravitee.rest.api.model.configuration.application.ApplicationGrantTypeEntity) GraviteeContext(io.gravitee.rest.api.service.common.GraviteeContext) RoleScope(io.gravitee.rest.api.model.permissions.RoleScope) HttpStatusCode(io.gravitee.common.http.HttpStatusCode) Valid(javax.validation.Valid) Answer(org.mockito.stubbing.Answer) PageQuery(io.gravitee.rest.api.model.documentation.PageQuery) Mockito.doReturn(org.mockito.Mockito.doReturn) ApplicationTypesEntity(io.gravitee.rest.api.model.configuration.application.ApplicationTypesEntity) ResourceTypeEnum(io.gravitee.rest.api.portal.rest.model.Link.ResourceTypeEnum) ApplicationTypeEntity(io.gravitee.rest.api.model.configuration.application.ApplicationTypeEntity) io.gravitee.rest.api.portal.rest.model(io.gravitee.rest.api.portal.rest.model) Test(org.junit.Test) Mockito.when(org.mockito.Mockito.when) RoleEntity(io.gravitee.rest.api.model.RoleEntity) Mockito(org.mockito.Mockito) Response(javax.ws.rs.core.Response) Assert(org.junit.Assert) PageConfigurationKeys(io.gravitee.rest.api.model.PageConfigurationKeys) PageQuery(io.gravitee.rest.api.model.documentation.PageQuery) Response(javax.ws.rs.core.Response) Test(org.junit.Test)

Example 5 with PageQuery

use of io.gravitee.rest.api.model.documentation.PageQuery in project gravitee-management-rest-api by gravitee-io.

the class DocumentationSystemFolderUpgrader method upgrade.

@Override
public boolean upgrade() {
    PageQuery query = new PageQuery.Builder().type(PageType.SYSTEM_FOLDER).build();
    // searching for system folders.
    if (pageService.search(query, GraviteeContext.getCurrentEnvironment()).isEmpty()) {
        logger.info("No system folders found. Add system folders in documentation, for portal and each API.");
        // Portal documentation
        Map<SystemFolderType, String> systemFolderIds = pageService.initialize(GraviteeContext.getDefaultEnvironment());
        String headerSystemFolderId = systemFolderIds.get(SystemFolderType.HEADER);
        String topFooterSystemFolderId = systemFolderIds.get(SystemFolderType.TOPFOOTER);
        // Create link to existing documentation in footer
        List<PageEntity> pagesToLink = pageService.search(new PageQuery.Builder().homepage(false).rootParent(true).build(), GraviteeContext.getCurrentEnvironment()).stream().filter(p -> PageType.SWAGGER.name().equals(p.getType()) || PageType.MARKDOWN.name().equals(p.getType())).collect(Collectors.toList());
        if (!pagesToLink.isEmpty()) {
            PageEntity docFolder = createFolder(topFooterSystemFolderId, "Documentation");
            pagesToLink.forEach(page -> createLink(docFolder.getId(), page.getName(), page.getId(), "page", Boolean.FALSE, Boolean.TRUE));
        }
        // Create link to root documentation folder in header
        createLink(headerSystemFolderId, "Documentation", "root", "page", Boolean.TRUE, Boolean.FALSE);
        // Apis documentation
        apiService.findAllLight().forEach(api -> pageService.createSystemFolder(api.getId(), SystemFolderType.ASIDE, 0, GraviteeContext.getDefaultEnvironment()));
    }
    return true;
}
Also used : Upgrader(io.gravitee.rest.api.service.Upgrader) Ordered(org.springframework.core.Ordered) Logger(org.slf4j.Logger) LoggerFactory(org.slf4j.LoggerFactory) Autowired(org.springframework.beans.factory.annotation.Autowired) GraviteeContext(io.gravitee.rest.api.service.common.GraviteeContext) HashMap(java.util.HashMap) Collectors(java.util.stream.Collectors) ApiService(io.gravitee.rest.api.service.ApiService) List(java.util.List) Component(org.springframework.stereotype.Component) Map(java.util.Map) PageQuery(io.gravitee.rest.api.model.documentation.PageQuery) io.gravitee.rest.api.model(io.gravitee.rest.api.model) PageService(io.gravitee.rest.api.service.PageService) PageQuery(io.gravitee.rest.api.model.documentation.PageQuery)

Aggregations

PageQuery (io.gravitee.rest.api.model.documentation.PageQuery)5 io.gravitee.rest.api.model (io.gravitee.rest.api.model)3 GraviteeContext (io.gravitee.rest.api.service.common.GraviteeContext)3 java.util (java.util)3 HttpStatusCode (io.gravitee.common.http.HttpStatusCode)2 TechnicalException (io.gravitee.repository.exceptions.TechnicalException)2 PageableBuilder (io.gravitee.repository.management.api.search.builder.PageableBuilder)2 ApiEntity (io.gravitee.rest.api.model.api.ApiEntity)2 GraviteeDescriptorPageEntity (io.gravitee.rest.api.model.descriptor.GraviteeDescriptorPageEntity)2 io.gravitee.rest.api.portal.rest.model (io.gravitee.rest.api.portal.rest.model)2 ResourceTypeEnum (io.gravitee.rest.api.portal.rest.model.Link.ResourceTypeEnum)2 UuidString (io.gravitee.rest.api.service.common.UuidString)2 IOException (java.io.IOException)2 Response (javax.ws.rs.core.Response)2 Assert (org.junit.Assert)2 Test (org.junit.Test)2 ArgumentMatchers (org.mockito.ArgumentMatchers)2 Mockito (org.mockito.Mockito)2 Mockito.doReturn (org.mockito.Mockito.doReturn)2 Mockito.when (org.mockito.Mockito.when)2