Search in sources :

Example 1 with GraviteeDescriptorEntity

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

the class GraviteeDescriptorServiceImpl method read.

@Override
public GraviteeDescriptorEntity read(String s) {
    ObjectMapper mapper = new ObjectMapper();
    try {
        GraviteeDescriptorEntity descriptorEntity = mapper.readValue(s, GraviteeDescriptorEntity.class);
        assertVersion(descriptorEntity);
        return descriptorEntity;
    } catch (IOException e) {
        logger.error("An error occurs while trying to read the descriptor", e);
        throw new GraviteeDescriptorReadException("An error occurs while trying to read the descriptor");
    }
}
Also used : GraviteeDescriptorEntity(io.gravitee.rest.api.model.descriptor.GraviteeDescriptorEntity) IOException(java.io.IOException) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) GraviteeDescriptorReadException(io.gravitee.rest.api.service.exceptions.GraviteeDescriptorReadException)

Example 2 with GraviteeDescriptorEntity

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

the class GraviteeDescriptorService_ReadTest method shouldRead.

@Test
public void shouldRead() throws Exception {
    GraviteeDescriptorEntity entity = service.read("{ \"version\": 1}");
    assertNotNull(entity);
    assertEquals("version", 1, entity.getVersion());
    assertNull("documentation", entity.getDocumentation());
}
Also used : GraviteeDescriptorEntity(io.gravitee.rest.api.model.descriptor.GraviteeDescriptorEntity) Test(org.junit.Test)

Example 3 with GraviteeDescriptorEntity

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

the class PageServiceImpl method importDirectory.

private List<PageEntity> importDirectory(String apiId, ImportPageEntity pageEntity, FilesFetcher fetcher, String environmentId) {
    try {
        String[] files = fetcher.files();
        // if a gravitee descriptor is present, import it.
        Optional<String> optDescriptor = Arrays.stream(files).filter(f -> f.endsWith(graviteeDescriptorService.descriptorName())).findFirst();
        if (optDescriptor.isPresent()) {
            try {
                ((FilepathAwareFetcherConfiguration) fetcher.getConfiguration()).setFilepath(optDescriptor.get());
                final Resource resource = fetcher.fetch();
                final GraviteeDescriptorEntity descriptorEntity = graviteeDescriptorService.read(getResourceContentAsString(resource));
                return importDescriptor(apiId, pageEntity, fetcher, descriptorEntity, environmentId);
            } catch (Exception e) {
                logger.error(e.getMessage(), e);
                throw new FetcherException(e.getMessage(), e);
            }
        }
        Map<String, String> parentsIdByPath = new HashMap<>();
        List<PageEntity> createdPages = new ArrayList<>();
        // for each files returned by the fetcher
        int order = 0;
        for (String file : files) {
            NewPageEntity pageFromPath = getPageFromPath(file);
            if (pageFromPath != null) {
                pageFromPath.setLastContributor(pageEntity.getLastContributor());
                pageFromPath.setPublished(pageEntity.isPublished());
                pageFromPath.setSource(pageEntity.getSource());
                pageFromPath.setOrder(order++);
                try {
                    createdPages.addAll(upsertPageAndParentFolders(getParentPathFromFilePath(file), pageFromPath, parentsIdByPath, fetcher, apiId, file, environmentId));
                } catch (TechnicalException ex) {
                    logger.error("An error occurs while trying to import a directory", ex);
                    throw new TechnicalManagementException("An error occurs while trying to import a directory", ex);
                }
            }
        }
        return createdPages;
    } catch (FetcherException ex) {
        logger.error("An error occurs while trying to import a directory", ex);
        throw new TechnicalManagementException("An error occurs while trying import a directory", 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) TechnicalException(io.gravitee.repository.exceptions.TechnicalException) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) IOException(java.io.IOException) BeansException(org.springframework.beans.BeansException) GraviteeDescriptorEntity(io.gravitee.rest.api.model.descriptor.GraviteeDescriptorEntity)

Aggregations

GraviteeDescriptorEntity (io.gravitee.rest.api.model.descriptor.GraviteeDescriptorEntity)3 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)2 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)1 TypeReference (com.fasterxml.jackson.core.type.TypeReference)1 DeserializationFeature (com.fasterxml.jackson.databind.DeserializationFeature)1 JsonNode (com.fasterxml.jackson.databind.JsonNode)1 Gson (com.google.gson.Gson)1 MediaType (io.gravitee.common.http.MediaType)1 io.gravitee.fetcher.api (io.gravitee.fetcher.api)1 PluginManager (io.gravitee.plugin.core.api.PluginManager)1 FetcherPlugin (io.gravitee.plugin.fetcher.FetcherPlugin)1 TechnicalException (io.gravitee.repository.exceptions.TechnicalException)1 PageRepository (io.gravitee.repository.management.api.PageRepository)1 PageCriteria (io.gravitee.repository.management.api.search.PageCriteria)1 PageableBuilder (io.gravitee.repository.management.api.search.builder.PageableBuilder)1 io.gravitee.repository.management.model (io.gravitee.repository.management.model)1 PAGE (io.gravitee.repository.management.model.Audit.AuditProperties.PAGE)1 AuditEvent (io.gravitee.repository.management.model.Page.AuditEvent)1 FetcherConfigurationFactory (io.gravitee.rest.api.fetcher.FetcherConfigurationFactory)1 io.gravitee.rest.api.model (io.gravitee.rest.api.model)1