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");
}
}
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());
}
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);
}
}
Aggregations