use of io.gravitee.repository.management.model.PageRevision in project gravitee-management-rest-api by gravitee-io.
the class PageRevisionServiceTest method shouldCreateRevision_PortalPage.
@Test
public void shouldCreateRevision_PortalPage() throws TechnicalException {
Date now = new Date();
Page page = mock(Page.class);
when(page.getId()).thenReturn(PAGE_ID);
when(page.getName()).thenReturn("SomeName");
when(page.getContent()).thenReturn("SomeContent");
when(page.getUpdatedAt()).thenReturn(now);
when(page.getLastContributor()).thenReturn("Author");
when(page.getType()).thenReturn(PageType.MARKDOWN.name());
PageRevision newRevision = mock(PageRevision.class);
when(pageRevisionRepository.findLastByPageId(PAGE_ID)).thenReturn(Optional.empty());
when(pageRevisionRepository.create(any())).thenReturn(newRevision);
ArgumentCaptor<PageRevision> newRevisionCaptor = ArgumentCaptor.forClass(PageRevision.class);
PageRevisionEntity createdRevision = pageRevisionService.create(page);
assertNotNull(createdRevision);
verify(pageRevisionRepository).findLastByPageId(PAGE_ID);
verify(pageRevisionRepository).create(newRevisionCaptor.capture());
PageRevision createdRev = newRevisionCaptor.getValue();
assertNotNull(createdRev);
assertEquals(1, createdRev.getRevision());
}
use of io.gravitee.repository.management.model.PageRevision in project gravitee-management-rest-api by gravitee-io.
the class PageRevisionServiceTest method shouldCreateRevision_NewIncrementedRevision.
@Test
public void shouldCreateRevision_NewIncrementedRevision() throws TechnicalException {
Date now = new Date();
Page page = mock(Page.class);
when(page.getId()).thenReturn(PAGE_ID);
when(page.getName()).thenReturn("SomeName");
when(page.getContent()).thenReturn("SomeContent");
when(page.getUpdatedAt()).thenReturn(now);
when(page.getLastContributor()).thenReturn("Author");
when(page.getType()).thenReturn(PageType.MARKDOWN.name());
PageRevision lastRevision = mock(PageRevision.class);
when(lastRevision.getRevision()).thenReturn(2);
PageRevision newRevision = mock(PageRevision.class);
when(pageRevisionRepository.findLastByPageId(PAGE_ID)).thenReturn(Optional.of(lastRevision));
when(pageRevisionRepository.create(any())).thenReturn(newRevision);
ArgumentCaptor<PageRevision> newRevisionCaptor = ArgumentCaptor.forClass(PageRevision.class);
PageRevisionEntity createdRevision = pageRevisionService.create(page);
assertNotNull(createdRevision);
verify(pageRevisionRepository).findLastByPageId(PAGE_ID);
verify(pageRevisionRepository).create(newRevisionCaptor.capture());
PageRevision createdRev = newRevisionCaptor.getValue();
assertNotNull(createdRev);
assertEquals(lastRevision.getRevision() + 1, createdRev.getRevision());
}
use of io.gravitee.repository.management.model.PageRevision in project gravitee-management-rest-api by gravitee-io.
the class PageRevisionServiceImpl method create.
@Override
public PageRevisionEntity create(Page page) {
try {
logger.debug("Create page revision for page {}", page.getId());
PageType type = PageType.valueOf(page.getType());
if (!(type == PageType.MARKDOWN || type == PageType.SWAGGER || type == PageType.TRANSLATION)) {
throw new TechnicalManagementException("Invalid page type for revision");
}
PageRevision revision = pageRevisionRepository.create(convert(page));
return convert(revision);
} catch (TechnicalException e) {
logger.warn("An error occurs while trying to create a revision for page {}", page.getId(), e);
throw new TechnicalManagementException("An error occurs while trying to create a page revision", e);
}
}
use of io.gravitee.repository.management.model.PageRevision in project gravitee-management-rest-api by gravitee-io.
the class PageRevisionServiceImpl method findAll.
@Override
public io.gravitee.common.data.domain.Page<PageRevisionEntity> findAll(Pageable pageable) {
logger.debug("get all page revisions with pageable {}", pageable);
try {
io.gravitee.common.data.domain.Page<PageRevision> revisions = pageRevisionRepository.findAll(pageable);
List<PageRevisionEntity> revisionEntities = revisions.getContent().stream().map(this::convert).collect(Collectors.toList());
return new io.gravitee.common.data.domain.Page<PageRevisionEntity>(revisionEntities, revisions.getPageNumber(), revisionEntities.size(), revisions.getTotalElements());
} catch (TechnicalException e) {
logger.warn("An error occurs while trying to get the page revisions {}", pageable, e);
throw new TechnicalManagementException("An error occurs while trying to get all page revisions", e);
}
}
use of io.gravitee.repository.management.model.PageRevision in project gravitee-management-rest-api by gravitee-io.
the class PageRevisionServiceImpl method convert.
private PageRevision convert(Page page) {
PageRevision revision = new PageRevision();
revision.setPageId(page.getId());
revision.setRevision(findLastByPageId(page.getId()).map(rev -> rev.getRevision() + 1).orElse(1));
revision.setName(page.getName());
revision.setContent(page.getContent());
revision.setContributor(page.getLastContributor());
revision.setCreatedAt(page.getUpdatedAt());
revision.setHash(computeHash(revision));
return revision;
}
Aggregations