Search in sources :

Example 1 with GraviteeDescriptorPageEntity

use of io.gravitee.rest.api.model.descriptor.GraviteeDescriptorPageEntity in project gravitee-management-rest-api by gravitee-io.

the class PageServiceImpl method importDescriptor.

private List<PageEntity> importDescriptor(final String apiId, final ImportPageEntity descriptorPageEntity, final FilesFetcher fetcher, final GraviteeDescriptorEntity descriptorEntity, String environmentId) {
    if (descriptorEntity.getDocumentation() == null || descriptorEntity.getDocumentation().getPages() == null || descriptorEntity.getDocumentation().getPages().isEmpty()) {
        return emptyList();
    }
    Map<String, String> parentsIdByPath = new HashMap<>();
    List<PageEntity> createdPages = new ArrayList<>();
    int order = 0;
    for (GraviteeDescriptorPageEntity descriptorPage : descriptorEntity.getDocumentation().getPages()) {
        NewPageEntity newPage = getPageFromPath(descriptorPage.getSrc());
        if (newPage == null) {
            logger.warn("Unable to find a source file to import. Please fix the descriptor content.");
        } else {
            if (descriptorPage.getName() != null && !descriptorPage.getName().isEmpty()) {
                newPage.setName(descriptorPage.getName());
            }
            newPage.setHomepage(descriptorPage.isHomepage());
            newPage.setLastContributor(descriptorPageEntity.getLastContributor());
            newPage.setPublished(descriptorPageEntity.isPublished());
            newPage.setSource(descriptorPageEntity.getSource());
            newPage.setOrder(order++);
            newPage.setVisibility(descriptorPageEntity.getVisibility());
            String parentPath = descriptorPage.getDest() == null || descriptorPage.getDest().isEmpty() ? getParentPathFromFilePath(descriptorPage.getSrc()) : descriptorPage.getDest();
            try {
                createdPages.addAll(upsertPageAndParentFolders(parentPath, newPage, parentsIdByPath, fetcher, apiId, descriptorPage.getSrc(), environmentId));
            } catch (TechnicalException ex) {
                logger.error("An error occurs while trying to import a gravitee descriptor", ex);
                throw new TechnicalManagementException("An error occurs while trying to import a gravitee descriptor", ex);
            }
        }
    }
    return createdPages;
}
Also used : GraviteeDescriptorPageEntity(io.gravitee.rest.api.model.descriptor.GraviteeDescriptorPageEntity) TechnicalException(io.gravitee.repository.exceptions.TechnicalException) UuidString(io.gravitee.rest.api.service.common.UuidString) GraviteeDescriptorPageEntity(io.gravitee.rest.api.model.descriptor.GraviteeDescriptorPageEntity)

Aggregations

TechnicalException (io.gravitee.repository.exceptions.TechnicalException)1 GraviteeDescriptorPageEntity (io.gravitee.rest.api.model.descriptor.GraviteeDescriptorPageEntity)1 UuidString (io.gravitee.rest.api.service.common.UuidString)1