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;
}
Aggregations