use of io.gravitee.rest.api.model.PageRevisionEntity in project gravitee-management-rest-api by gravitee-io.
the class PageRevisionServiceImpl method convert.
private PageRevisionEntity convert(PageRevision revision) {
PageRevisionEntity entity = new PageRevisionEntity();
entity.setPageId(revision.getPageId());
entity.setRevision(revision.getRevision());
entity.setName(revision.getName());
entity.setContent(revision.getContent());
entity.setHash(revision.getHash());
entity.setContributor(revision.getContributor());
entity.setModificationDate(revision.getCreatedAt());
return entity;
}
use of io.gravitee.rest.api.model.PageRevisionEntity 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.rest.api.model.PageRevisionEntity 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.rest.api.model.PageRevisionEntity 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.rest.api.model.PageRevisionEntity in project gravitee-management-rest-api by gravitee-io.
the class PageService_FindByIdTest method shouldFindById.
@Test
public void shouldFindById() throws TechnicalException {
when(translationPage.getId()).thenReturn(TRANSLATION_ID);
when(translationPage.getOrder()).thenReturn(1);
when(translationPage.getParentId()).thenReturn(PAGE_ID);
when(translationPage.getReferenceType()).thenReturn(PageReferenceType.ENVIRONMENT);
when(translationPage.getReferenceId()).thenReturn("envId");
when(translationPage.getVisibility()).thenReturn("PUBLIC");
Map<String, String> conf = new HashMap<>();
conf.put(PageConfigurationKeys.TRANSLATION_LANG, "FR");
when(translationPage.getConfiguration()).thenReturn(conf);
when(page1.getId()).thenReturn(PAGE_ID);
when(page1.getType()).thenReturn(PageType.MARKDOWN.name());
when(page1.getOrder()).thenReturn(1);
when(page1.getReferenceType()).thenReturn(PageReferenceType.ENVIRONMENT);
when(page1.getReferenceId()).thenReturn("envId");
when(page1.getVisibility()).thenReturn("PUBLIC");
when(pageRepository.findById(PAGE_ID)).thenReturn(Optional.of(page1));
when(pageRepository.search(argThat(p -> "TRANSLATION".equals(p.getType()) && PAGE_ID.equals(p.getParent())))).thenReturn(Arrays.asList(translationPage));
final PageRevisionEntity pageRevision = new PageRevisionEntity();
pageRevision.setRevision(5);
pageRevision.setPageId(PAGE_ID);
when(pageRevisionService.findLastByPageId(PAGE_ID)).thenReturn(Optional.of(pageRevision));
final PageEntity pageEntity = pageService.findById(PAGE_ID);
assertNotNull(pageEntity);
assertEquals(1, pageEntity.getOrder());
assertEquals(PAGE_ID, pageEntity.getId());
List<PageEntity> translations = pageEntity.getTranslations();
assertNotNull(translations);
assertEquals(1, translations.size());
PageEntity oneTranslation = translations.get(0);
assertNotNull(oneTranslation);
assertEquals(TRANSLATION_ID, oneTranslation.getId());
assertNotNull(pageEntity.getContentRevisionId());
assertEquals(PAGE_ID, pageEntity.getContentRevisionId().getPageId());
assertEquals(5, pageEntity.getContentRevisionId().getRevision());
}
Aggregations