diff --git a/src/main/java/cz/cvut/kbss/termit/dto/filter/VocabularyContentChangeFilterDto.java b/src/main/java/cz/cvut/kbss/termit/dto/filter/VocabularyContentChangeFilterDto.java index c09fa798..9d75ef60 100644 --- a/src/main/java/cz/cvut/kbss/termit/dto/filter/VocabularyContentChangeFilterDto.java +++ b/src/main/java/cz/cvut/kbss/termit/dto/filter/VocabularyContentChangeFilterDto.java @@ -1,15 +1,16 @@ package cz.cvut.kbss.termit.dto.filter; import java.net.URI; +import java.util.Objects; /** * Represents parameters for filtering vocabulary content changes. */ public class VocabularyContentChangeFilterDto { - private String termName; - private String changedAttributeName; - private String authorName; - private URI changeType; + private String termName = ""; + private String changedAttributeName = ""; + private String authorName = ""; + private URI changeType = null; public String getTermName() { return termName; @@ -42,4 +43,19 @@ public URI getChangeType() { public void setChangeType(URI changeType) { this.changeType = changeType; } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (!(o instanceof VocabularyContentChangeFilterDto that)) return false; + return Objects.equals(termName, that.termName) && + Objects.equals(changedAttributeName, that.changedAttributeName) && + Objects.equals(authorName, that.authorName) && + Objects.equals(changeType, that.changeType); + } + + @Override + public int hashCode() { + return Objects.hash(termName, changedAttributeName, authorName, changeType); + } } diff --git a/src/main/java/cz/cvut/kbss/termit/rest/VocabularyController.java b/src/main/java/cz/cvut/kbss/termit/rest/VocabularyController.java index 72aa526a..13858a4e 100644 --- a/src/main/java/cz/cvut/kbss/termit/rest/VocabularyController.java +++ b/src/main/java/cz/cvut/kbss/termit/rest/VocabularyController.java @@ -297,25 +297,30 @@ public List getHistoryOfContent( @GetMapping(value = "/{localName}/history-of-content/detail", produces = {MediaType.APPLICATION_JSON_VALUE, JsonLd.MEDIA_TYPE}) public List getDetailedHistoryOfContent( - @Parameter(description = ApiDoc.ID_LOCAL_NAME_DESCRIPTION, - example = ApiDoc.ID_LOCAL_NAME_EXAMPLE) @PathVariable String localName, - @Parameter(description = ApiDoc.ID_NAMESPACE_DESCRIPTION, - example = ApiDoc.ID_NAMESPACE_EXAMPLE) @RequestParam(name = QueryParams.NAMESPACE, - required = false) Optional namespace, + @Parameter(description = ApiDoc.ID_LOCAL_NAME_DESCRIPTION, example = ApiDoc.ID_LOCAL_NAME_EXAMPLE) + @PathVariable + String localName, + @Parameter(description = ApiDoc.ID_NAMESPACE_DESCRIPTION, example = ApiDoc.ID_NAMESPACE_EXAMPLE) + @RequestParam(name = QueryParams.NAMESPACE, required = false) + Optional namespace, @Parameter(description = "Term name to be used in filtering.") - @RequestParam(name = "term", required = false, defaultValue = "") String termName, + @RequestParam(name = "term", required = false, defaultValue = "") + String termName, @Parameter(description = "Change type to be used in filtering.") - @RequestParam(name = "type", required = false) URI changeType, + @RequestParam(name = "type", required = false) + URI changeType, @Parameter(description = "Author name to be used in filtering.") - @RequestParam(name = "author", required = false, defaultValue = "") String authorName, + @RequestParam(name = "author", required = false, defaultValue = "") + String authorName, @Parameter(description = "Changed attribute name to be used in filtering.") - @RequestParam(name = "attribute", required = false, defaultValue = "") String changedAttributeName, - - @Parameter(description = ApiDocConstants.PAGE_SIZE_DESCRIPTION) @RequestParam( - name = Constants.QueryParams.PAGE_SIZE, required = false, - defaultValue = DEFAULT_PAGE_SIZE) Integer pageSize, - @Parameter(description = ApiDocConstants.PAGE_NO_DESCRIPTION) @RequestParam( - name = Constants.QueryParams.PAGE, required = false, defaultValue = DEFAULT_PAGE) Integer pageNo) { + @RequestParam(name = "attribute", required = false, defaultValue = "") + String changedAttributeName, + @Parameter(description = ApiDocConstants.PAGE_SIZE_DESCRIPTION) + @RequestParam(name = Constants.QueryParams.PAGE_SIZE, required = false, defaultValue = DEFAULT_PAGE_SIZE) + Integer pageSize, + @Parameter(description = ApiDocConstants.PAGE_NO_DESCRIPTION) + @RequestParam(name = Constants.QueryParams.PAGE, required = false, defaultValue = DEFAULT_PAGE) + Integer pageNo) { final Pageable pageReq = createPageRequest(pageSize, pageNo); final Vocabulary vocabulary = vocabularyService.getReference(resolveVocabularyUri(localName, namespace)); final VocabularyContentChangeFilterDto filter = new VocabularyContentChangeFilterDto(); diff --git a/src/test/java/cz/cvut/kbss/termit/rest/VocabularyControllerTest.java b/src/test/java/cz/cvut/kbss/termit/rest/VocabularyControllerTest.java index 0d1c7444..37af85f4 100644 --- a/src/test/java/cz/cvut/kbss/termit/rest/VocabularyControllerTest.java +++ b/src/test/java/cz/cvut/kbss/termit/rest/VocabularyControllerTest.java @@ -22,11 +22,13 @@ import cz.cvut.kbss.termit.dto.AggregatedChangeInfo; import cz.cvut.kbss.termit.dto.Snapshot; import cz.cvut.kbss.termit.dto.acl.AccessControlListDto; +import cz.cvut.kbss.termit.dto.filter.VocabularyContentChangeFilterDto; import cz.cvut.kbss.termit.dto.listing.VocabularyDto; import cz.cvut.kbss.termit.environment.Environment; import cz.cvut.kbss.termit.environment.Generator; import cz.cvut.kbss.termit.exception.AssetRemovalException; import cz.cvut.kbss.termit.exception.importing.VocabularyImportException; +import cz.cvut.kbss.termit.model.Term; import cz.cvut.kbss.termit.model.User; import cz.cvut.kbss.termit.model.Vocabulary; import cz.cvut.kbss.termit.model.acl.AccessControlList; @@ -50,6 +52,7 @@ import org.mockito.Mock; import org.mockito.Mockito; import org.mockito.junit.jupiter.MockitoExtension; +import org.springframework.data.domain.Pageable; import org.springframework.http.HttpHeaders; import org.springframework.http.MediaType; import org.springframework.mock.web.MockMultipartFile; @@ -70,15 +73,20 @@ import java.util.Set; import java.util.stream.Collectors; import java.util.stream.IntStream; +import java.util.stream.Stream; import static cz.cvut.kbss.termit.environment.util.ContainsSameEntities.containsSameEntities; +import static cz.cvut.kbss.termit.util.Constants.DEFAULT_PAGE_SIZE; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.containsString; +import static org.hamcrest.Matchers.equalToObject; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertNotNull; import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.mockito.ArgumentMatchers.notNull; import static org.mockito.Mockito.any; import static org.mockito.Mockito.anyBoolean; +import static org.mockito.Mockito.doReturn; import static org.mockito.Mockito.eq; import static org.mockito.Mockito.never; import static org.mockito.Mockito.verify; @@ -642,4 +650,23 @@ void getExcelTemplateFileReturnsExcelTemplateFileRetrievedFromServiceAsAttachmen assertThat(mvcResult.getResponse().getHeader(HttpHeaders.CONTENT_DISPOSITION), containsString("filename=\"termit-import.xlsx\"")); } + + @Test + void getDetailedHistoryOfContentReturnsListOfChangeRecordsWhenNoFilterIsSpecified() throws Exception { + final int pageSize = Integer.parseInt(VocabularyController.DEFAULT_PAGE_SIZE); + final Vocabulary vocabulary = generateVocabularyAndInitReferenceResolution(); + final Term term = Generator.generateTermWithId(); + final List changeRecords = IntStream.range(0, 5).mapToObj(i -> Generator.generateChangeRecords(term, user)).flatMap(List::stream).toList(); + final VocabularyContentChangeFilterDto filter = new VocabularyContentChangeFilterDto(); + final Pageable pageable = Pageable.ofSize(pageSize); + + doReturn(changeRecords).when(serviceMock).getDetailedHistoryOfContent(vocabulary, filter, pageable); + + final MvcResult mvcResult = mockMvc.perform(get(PATH + "/" + FRAGMENT + "/history-of-content/detail")).andExpect(status().isOk()).andReturn(); + final List result = + readValue(mvcResult, new TypeReference>() {}); + assertNotNull(result); + assertEquals(changeRecords, result); + verify(serviceMock).getDetailedHistoryOfContent(vocabulary, filter, pageable); + } }