From c3b4cfd4b639be797948c28a793acdbea04dda5c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Luk=C3=A1=C5=A1=20Ka=C5=88ka?= Date: Sun, 10 Nov 2024 16:46:49 +0100 Subject: [PATCH] [Enhancement kbss-cvut/termit-ui#520] Move change record implementation to ChangeRecordDao --- ...terDto.java => ChangeRecordFilterDto.java} | 32 +++-- .../termit/persistence/dao/VocabularyDao.java | 98 ++------------- .../dao/changetracking/ChangeRecordDao.java | 116 +++++++++++++++++- .../kbss/termit/rest/ResourceController.java | 3 +- .../cvut/kbss/termit/rest/TermController.java | 19 ++- .../termit/rest/VocabularyController.java | 53 ++++---- .../service/business/ResourceService.java | 5 +- .../termit/service/business/TermService.java | 5 +- .../service/business/VocabularyService.java | 8 +- .../changetracking/ChangeRecordProvider.java | 19 ++- .../repository/ChangeRecordService.java | 8 +- .../VocabularyRepositoryService.java | 4 +- .../persistence/dao/VocabularyDaoTest.java | 18 +-- .../termit/rest/ResourceControllerTest.java | 6 +- .../kbss/termit/rest/TermControllerTest.java | 9 +- .../termit/rest/VocabularyControllerTest.java | 9 +- .../service/business/ResourceServiceTest.java | 6 +- .../service/business/TermServiceTest.java | 3 +- .../business/VocabularyServiceTest.java | 6 +- 19 files changed, 262 insertions(+), 165 deletions(-) rename src/main/java/cz/cvut/kbss/termit/dto/filter/{VocabularyContentChangeFilterDto.java => ChangeRecordFilterDto.java} (58%) diff --git a/src/main/java/cz/cvut/kbss/termit/dto/filter/VocabularyContentChangeFilterDto.java b/src/main/java/cz/cvut/kbss/termit/dto/filter/ChangeRecordFilterDto.java similarity index 58% rename from src/main/java/cz/cvut/kbss/termit/dto/filter/VocabularyContentChangeFilterDto.java rename to src/main/java/cz/cvut/kbss/termit/dto/filter/ChangeRecordFilterDto.java index 9d75ef607..9f06efbd0 100644 --- a/src/main/java/cz/cvut/kbss/termit/dto/filter/VocabularyContentChangeFilterDto.java +++ b/src/main/java/cz/cvut/kbss/termit/dto/filter/ChangeRecordFilterDto.java @@ -1,23 +1,26 @@ package cz.cvut.kbss.termit.dto.filter; +import com.fasterxml.jackson.annotation.JsonIgnore; +import cz.cvut.kbss.termit.util.Utils; + import java.net.URI; import java.util.Objects; /** * Represents parameters for filtering vocabulary content changes. */ -public class VocabularyContentChangeFilterDto { - private String termName = ""; +public class ChangeRecordFilterDto { + private String assetLabel = ""; private String changedAttributeName = ""; private String authorName = ""; private URI changeType = null; - public String getTermName() { - return termName; + public String getAssetLabel() { + return assetLabel; } - public void setTermName(String termName) { - this.termName = termName; + public void setAssetLabel(String assetLabel) { + this.assetLabel = assetLabel; } public String getChangedAttributeName() { @@ -44,11 +47,22 @@ public void setChangeType(URI changeType) { this.changeType = changeType; } + /** + * @return true when all attributes are empty or null + */ + @JsonIgnore + public boolean isEmpty() { + return Utils.isBlank(assetLabel) && + Utils.isBlank(changedAttributeName) && + Utils.isBlank(authorName) && + changeType == null; + } + @Override public boolean equals(Object o) { if (this == o) return true; - if (!(o instanceof VocabularyContentChangeFilterDto that)) return false; - return Objects.equals(termName, that.termName) && + if (!(o instanceof ChangeRecordFilterDto that)) return false; + return Objects.equals(assetLabel, that.assetLabel) && Objects.equals(changedAttributeName, that.changedAttributeName) && Objects.equals(authorName, that.authorName) && Objects.equals(changeType, that.changeType); @@ -56,6 +70,6 @@ public boolean equals(Object o) { @Override public int hashCode() { - return Objects.hash(termName, changedAttributeName, authorName, changeType); + return Objects.hash(assetLabel, changedAttributeName, authorName, changeType); } } diff --git a/src/main/java/cz/cvut/kbss/termit/persistence/dao/VocabularyDao.java b/src/main/java/cz/cvut/kbss/termit/persistence/dao/VocabularyDao.java index 4ac58f75b..cba546691 100644 --- a/src/main/java/cz/cvut/kbss/termit/persistence/dao/VocabularyDao.java +++ b/src/main/java/cz/cvut/kbss/termit/persistence/dao/VocabularyDao.java @@ -19,9 +19,7 @@ import cz.cvut.kbss.jopa.model.EntityManager; import cz.cvut.kbss.jopa.model.query.Query; -import cz.cvut.kbss.jopa.model.query.TypedQuery; import cz.cvut.kbss.jopa.vocabulary.DC; -import cz.cvut.kbss.jopa.vocabulary.RDFS; import cz.cvut.kbss.jopa.vocabulary.SKOS; import cz.cvut.kbss.termit.asset.provenance.ModifiesData; import cz.cvut.kbss.termit.asset.provenance.SupportsLastModification; @@ -29,7 +27,7 @@ import cz.cvut.kbss.termit.dto.PrefixDeclaration; import cz.cvut.kbss.termit.dto.RdfsStatement; import cz.cvut.kbss.termit.dto.Snapshot; -import cz.cvut.kbss.termit.dto.filter.VocabularyContentChangeFilterDto; +import cz.cvut.kbss.termit.dto.filter.ChangeRecordFilterDto; import cz.cvut.kbss.termit.event.AssetPersistEvent; import cz.cvut.kbss.termit.event.AssetUpdateEvent; import cz.cvut.kbss.termit.event.BeforeAssetDeleteEvent; @@ -45,6 +43,7 @@ import cz.cvut.kbss.termit.model.validation.ValidationResult; import cz.cvut.kbss.termit.persistence.context.DescriptorFactory; import cz.cvut.kbss.termit.persistence.context.VocabularyContextMapper; +import cz.cvut.kbss.termit.persistence.dao.changetracking.ChangeRecordDao; import cz.cvut.kbss.termit.persistence.dao.changetracking.ChangeTrackingContextResolver; import cz.cvut.kbss.termit.persistence.snapshot.AssetSnapshotLoader; import cz.cvut.kbss.termit.persistence.validation.VocabularyContentValidator; @@ -92,6 +91,7 @@ public class VocabularyDao extends BaseAssetDao private static final String REMOVE_GLOSSARY_TERMS_QUERY_FILE = "remove/removeGlossaryTerms.ru"; private final ChangeTrackingContextResolver changeTrackingContextResolver; + private final ChangeRecordDao changeRecordDao; private volatile long lastModified; @@ -102,12 +102,13 @@ public class VocabularyDao extends BaseAssetDao @Autowired public VocabularyDao(EntityManager em, Configuration config, DescriptorFactory descriptorFactory, VocabularyContextMapper contextMapper, ApplicationContext context, - ChangeTrackingContextResolver changeTrackingContextResolver) { + ChangeTrackingContextResolver changeTrackingContextResolver, ChangeRecordDao changeRecordDao) { super(Vocabulary.class, em, config.getPersistence(), descriptorFactory); this.contextMapper = contextMapper; refreshLastModified(); this.context = context; this.changeTrackingContextResolver = changeTrackingContextResolver; + this.changeRecordDao = changeRecordDao; } @Override @@ -408,88 +409,15 @@ public List getChangesOfContent(Vocabulary vocabulary) { * @param pageReq Specification of the size and number of the page to return * @return List of change records, ordered by date in descending order */ - public List getDetailedHistoryOfContent(Vocabulary vocabulary, VocabularyContentChangeFilterDto filter, Pageable pageReq) { + public List getDetailedHistoryOfContent(Vocabulary vocabulary, ChangeRecordFilterDto filter, Pageable pageReq) { Objects.requireNonNull(vocabulary); - return createDetailedContentChangesQuery(vocabulary, filter, pageReq).getResultList(); - } - - private TypedQuery createDetailedContentChangesQuery(Vocabulary vocabulary, VocabularyContentChangeFilterDto filter, Pageable pageReq) { - TypedQuery query = em.createNativeQuery(""" - SELECT DISTINCT ?record WHERE { -""" + /* Select anything from change context */ """ - GRAPH ?changeContext { - ?record a ?changeRecord . - } -""" + /* The record should be a subclass of "zmena" */ """ - ?changeRecord ?subClassOf+ ?zmena . - ?record ?relatesTo ?term ; - ?hasTime ?timestamp ; - ?hasAuthor ?author . -""" + /* Get author's name */ """ - ?author ?hasFirstName ?firstName ; - ?hasLastName ?lastName . - BIND(CONCAT(?firstName, " ", ?lastName) as ?authorFullName) -""" + /* When its update record, there will be a changed attribute */ """ - OPTIONAL { - ?record ?hasChangedAttribute ?attribute . - ?attribute ?hasRdfsLabel ?changedAttributeName . - } -""" + /* Get term's name (but the term might have been already deleted) */ """ - OPTIONAL { - ?term a ?termType ; - ?hasLabel ?label . - } -""" + /* then try to get the label from (delete) record */ """ - OPTIONAL { - ?record ?hasRdfsLabel ?label . - } -""" + /* When label is still not bound, the term was probably deleted, find the delete record and get the label from it */ """ - OPTIONAL { - FILTER(!BOUND(?label)) . - ?deleteRecord a ; - ?term; - ?label. - } - BIND(?termName as ?termNameVal) - BIND(?authorName as ?authorNameVal) - BIND(?attributeName as ?changedAttributeNameVal) - FILTER (!BOUND(?termNameVal) || CONTAINS(LCASE(?label), LCASE(?termNameVal))) - FILTER (!BOUND(?authorNameVal) || CONTAINS(LCASE(?authorFullName), LCASE(?authorNameVal))) - FILTER (!BOUND(?changedAttributeNameVal) || CONTAINS(LCASE(?changedAttributeName), LCASE(?changedAttributeNameVal))) - } ORDER BY DESC(?timestamp) ?attribute - """, AbstractChangeRecord.class) - .setParameter("changeContext", changeTrackingContextResolver.resolveChangeTrackingContext(vocabulary)) - .setParameter("subClassOf", URI.create(RDFS.SUB_CLASS_OF)) - .setParameter("zmena", URI.create(cz.cvut.kbss.termit.util.Vocabulary.s_c_zmena)) - .setParameter("termType", URI.create(SKOS.CONCEPT)) - .setParameter("relatesTo", URI.create(cz.cvut.kbss.termit.util.Vocabulary.s_p_ma_zmenenou_entitu)) - .setParameter("hasTime", URI.create(cz.cvut.kbss.termit.util.Vocabulary.s_p_ma_datum_a_cas_modifikace)) - .setParameter("hasChangedAttribute", URI.create(cz.cvut.kbss.termit.util.Vocabulary.s_p_ma_zmeneny_atribut)) - .setParameter("hasLabel", URI.create(SKOS.PREF_LABEL)) // term label - .setParameter("hasAuthor", URI.create(cz.cvut.kbss.termit.util.Vocabulary.s_p_ma_editora)) // record has author - .setParameter("hasFirstName", URI.create(cz.cvut.kbss.termit.util.Vocabulary.s_p_ma_krestni_jmeno)) - .setParameter("hasLastName", URI.create(cz.cvut.kbss.termit.util.Vocabulary.s_p_ma_prijmeni)) - .setParameter("hasRdfsLabel", URI.create(RDFS.LABEL)); // changed attribute label - - if(!Utils.isBlank(filter.getTermName())) { - query = query.setParameter("termName", filter.getTermName().trim()); - } - if (!Utils.isBlank(filter.getAuthorName())) { - query = query.setParameter("authorName", filter.getAuthorName().trim()); - } - if (filter.getChangeType() != null) { - query = query.setParameter("changeRecord", filter.getChangeType()); - } - if (!Utils.isBlank(filter.getChangedAttributeName())) { - query = query.setParameter("attributeName", filter.getChangedAttributeName().trim()); - } - - if(pageReq.isUnpaged()) { - return query; - } - - return query.setFirstResult((int) pageReq.getOffset()) - .setMaxResults(pageReq.getPageSize()); + return changeRecordDao.findAllFiltered( + changeTrackingContextResolver.resolveChangeTrackingContext(vocabulary), + filter, + Optional.empty(), + Optional.of(URI.create(SKOS.CONCEPT)), // term + pageReq + ); } private Query createContentChangesQuery(Vocabulary vocabulary) { diff --git a/src/main/java/cz/cvut/kbss/termit/persistence/dao/changetracking/ChangeRecordDao.java b/src/main/java/cz/cvut/kbss/termit/persistence/dao/changetracking/ChangeRecordDao.java index eadfa6b8a..b2f6718aa 100644 --- a/src/main/java/cz/cvut/kbss/termit/persistence/dao/changetracking/ChangeRecordDao.java +++ b/src/main/java/cz/cvut/kbss/termit/persistence/dao/changetracking/ChangeRecordDao.java @@ -20,18 +20,25 @@ import cz.cvut.kbss.jopa.model.EntityManager; import cz.cvut.kbss.jopa.model.descriptors.Descriptor; import cz.cvut.kbss.jopa.model.descriptors.EntityDescriptor; +import cz.cvut.kbss.jopa.model.query.TypedQuery; +import cz.cvut.kbss.jopa.vocabulary.RDFS; +import cz.cvut.kbss.jopa.vocabulary.SKOS; +import cz.cvut.kbss.termit.dto.filter.ChangeRecordFilterDto; import cz.cvut.kbss.termit.exception.PersistenceException; import cz.cvut.kbss.termit.model.Asset; import cz.cvut.kbss.termit.model.User; import cz.cvut.kbss.termit.model.changetracking.AbstractChangeRecord; import cz.cvut.kbss.termit.model.util.HasIdentifier; +import cz.cvut.kbss.termit.util.Utils; import cz.cvut.kbss.termit.util.Vocabulary; +import org.springframework.data.domain.Pageable; import org.springframework.stereotype.Repository; import java.net.URI; import java.util.HashSet; import java.util.List; import java.util.Objects; +import java.util.Optional; import java.util.Set; @Repository @@ -66,13 +73,120 @@ public void persist(AbstractChangeRecord record, Asset changedAsset) { } } + public List findAll(Asset asset, ChangeRecordFilterDto filterDto) { + if (filterDto.isEmpty()) { + // there is nothing to filter, simple query can be used + return findAll(asset); + } + return findAllFiltered(contextResolver.resolveChangeTrackingContext(asset), filterDto, Optional.of(asset), Optional.empty(), Pageable.unpaged()); + } + + /** + * @param changeContext the context of change records + * @param filter filter parameters + * @param asset if present, only changes of the asset will be returned + * @param assetType if present, only changes related to this asset type will be returned. + */ + public List findAllFiltered(URI changeContext, ChangeRecordFilterDto filter, Optional> asset, Optional assetType, Pageable pageable) { + TypedQuery query = em.createNativeQuery(""" + SELECT DISTINCT ?record WHERE { +""" + /* Select anything from change context */ """ + GRAPH ?changeContext { + ?record a ?changeRecord . + } +""" + /* The record should be a subclass of changeType ("zmena") and have timestamp and author */ """ + ?changeRecord ?subClassOf+ ?changeType . + ?record ?hasChangedEntity ?asset ; + ?hasTime ?timestamp ; + ?hasAuthor ?author . + ?asset a ?assetType . +""" + /* Get author's name */ """ + ?author ?hasFirstName ?firstName ; + ?hasLastName ?lastName . + BIND(CONCAT(?firstName, " ", ?lastName) as ?authorFullName) +""" + /* When its update record, there will be a changed attribute */ """ + OPTIONAL { + ?record ?hasChangedAttribute ?attribute . + ?attribute ?hasRdfsLabel ?changedAttributeLabel . + } +""" + /* Get asset's name (but the asset might have been already deleted) */ """ + OPTIONAL { + ?asset ?hasLabel ?label . + } + OPTIONAL { + ?asset ?hasRdfsLabel ?label . + } +""" + /* then try to get the label from (delete) record */ """ + OPTIONAL { + ?record ?hasRdfsLabel ?label . + } +""" + /* When label is still not bound, the term was probably deleted, find the delete record and get the label from it */ """ + OPTIONAL { + FILTER(!BOUND(?label)) . + ?deleteRecord a ?deleteRecordType; + ?hasChangedEntity ?term; + ?hasRdfsLabel ?label. + } + BIND(?assetLabelValue as ?assetLabel) + BIND(?authorNameValue as ?authorName) + BIND(?attributeNameValue as ?changedAttributeName) + FILTER (!BOUND(?assetLabel) || CONTAINS(LCASE(?label), LCASE(?assetLabel))) + FILTER (!BOUND(?authorName) || CONTAINS(LCASE(?authorFullName), LCASE(?authorName))) + FILTER (!BOUND(?changedAttributeName) || CONTAINS(LCASE(?changedAttributeLabel), LCASE(?changedAttributeName))) + } ORDER BY DESC(?timestamp) ?attribute + """, AbstractChangeRecord.class) + .setParameter("changeContext", changeContext) + .setParameter("subClassOf", URI.create(RDFS.SUB_CLASS_OF)) + .setParameter("changeType", URI.create(cz.cvut.kbss.termit.util.Vocabulary.s_c_zmena)) + .setParameter("hasChangedEntity", URI.create(cz.cvut.kbss.termit.util.Vocabulary.s_p_ma_zmenenou_entitu)) + .setParameter("hasTime", URI.create(cz.cvut.kbss.termit.util.Vocabulary.s_p_ma_datum_a_cas_modifikace)) + .setParameter("hasAuthor", URI.create(cz.cvut.kbss.termit.util.Vocabulary.s_p_ma_editora)) // record has author + .setParameter("hasFirstName", URI.create(cz.cvut.kbss.termit.util.Vocabulary.s_p_ma_krestni_jmeno)) + .setParameter("hasLastName", URI.create(cz.cvut.kbss.termit.util.Vocabulary.s_p_ma_prijmeni)) + // Optional - update change record + .setParameter("hasChangedAttribute", URI.create(cz.cvut.kbss.termit.util.Vocabulary.s_p_ma_zmeneny_atribut)) + .setParameter("hasRdfsLabel", URI.create(RDFS.LABEL)) + // Optional - + .setParameter("hasLabel", URI.create(SKOS.PREF_LABEL)) + + // Optional asset label + .setParameter("deleteRecordType", Vocabulary.s_c_smazani_entity); + + if(asset.isPresent() && asset.get().getUri() != null) { + query = query.setParameter("asset", asset.get().getUri()); + } else if (assetType.isPresent()) { + query = query.setParameter("assetType", assetType.get()); + } + + + if(!Utils.isBlank(filter.getAssetLabel())) { + query = query.setParameter("assetLabelValue", filter.getAssetLabel().trim()); + } + if (!Utils.isBlank(filter.getAuthorName())) { + query = query.setParameter("authorNameValue", filter.getAuthorName().trim()); + } + if (filter.getChangeType() != null) { + query = query.setParameter("changeRecord", filter.getChangeType()); + } + if (!Utils.isBlank(filter.getChangedAttributeName())) { + query = query.setParameter("attributeNameValue", filter.getChangedAttributeName().trim()); + } + + if(pageable.isUnpaged()) { + return query.getResultList(); + } + + return query.setFirstResult((int) pageable.getOffset()) + .setMaxResults(pageable.getPageSize()).getResultList(); + } + /** * Finds all change records to the specified asset. * * @param asset The changed asset * @return List of change records ordered by timestamp (descending) */ - public List findAll(HasIdentifier asset) { + public List findAll(Asset asset) { Objects.requireNonNull(asset); try { final Descriptor descriptor = new EntityDescriptor(); diff --git a/src/main/java/cz/cvut/kbss/termit/rest/ResourceController.java b/src/main/java/cz/cvut/kbss/termit/rest/ResourceController.java index 11bb65415..d504d4bd2 100644 --- a/src/main/java/cz/cvut/kbss/termit/rest/ResourceController.java +++ b/src/main/java/cz/cvut/kbss/termit/rest/ResourceController.java @@ -18,6 +18,7 @@ package cz.cvut.kbss.termit.rest; import cz.cvut.kbss.jsonld.JsonLd; +import cz.cvut.kbss.termit.dto.filter.ChangeRecordFilterDto; import cz.cvut.kbss.termit.exception.TermItException; import cz.cvut.kbss.termit.model.TextAnalysisRecord; import cz.cvut.kbss.termit.model.changetracking.AbstractChangeRecord; @@ -360,7 +361,7 @@ public List getHistory( required = false) Optional namespace) { final Resource resource = resourceService .getReference(resolveIdentifier(resourceNamespace(namespace), localName)); - return resourceService.getChanges(resource); + return resourceService.getChanges(resource, new ChangeRecordFilterDto()); // TODO: filter dto } /** diff --git a/src/main/java/cz/cvut/kbss/termit/rest/TermController.java b/src/main/java/cz/cvut/kbss/termit/rest/TermController.java index 9fc059aa9..5c215d955 100644 --- a/src/main/java/cz/cvut/kbss/termit/rest/TermController.java +++ b/src/main/java/cz/cvut/kbss/termit/rest/TermController.java @@ -18,6 +18,7 @@ package cz.cvut.kbss.termit.rest; import cz.cvut.kbss.jsonld.JsonLd; +import cz.cvut.kbss.termit.dto.filter.ChangeRecordFilterDto; import cz.cvut.kbss.termit.dto.listing.TermDto; import cz.cvut.kbss.termit.exception.TermItException; import cz.cvut.kbss.termit.model.Term; @@ -699,7 +700,7 @@ public List getHistory( @Parameter(description = ApiDoc.ID_NAMESPACE_DESCRIPTION, example = ApiDoc.ID_NAMESPACE_EXAMPLE) @RequestParam(name = QueryParams.NAMESPACE, required = false) Optional namespace) { final URI termUri = getTermUri(localName, termLocalName, namespace); - return termService.getChanges(termService.findRequired(termUri)); + return termService.getChanges(termService.findRequired(termUri), new ChangeRecordFilterDto()); // TODO: filter dto } /** @@ -722,9 +723,21 @@ public List getHistory(@Parameter(description = ApiDoc.ID_ @PathVariable String localName, @Parameter(description = ApiDoc.ID_STANDALONE_NAMESPACE_DESCRIPTION, example = ApiDoc.ID_STANDALONE_NAMESPACE_EXAMPLE) - @RequestParam(name = QueryParams.NAMESPACE) String namespace) { + @RequestParam(name = QueryParams.NAMESPACE) String namespace, + @Parameter(description = "Change type used for filtering.") + @RequestParam(name = "type", required = false) URI changeType, + @Parameter(description = "Author name used for filtering.") + @RequestParam(name = "author", required = false, + defaultValue = "") String authorName, + @Parameter(description = "Changed attribute name used for filtering.") + @RequestParam(name = "attribute", required = false, + defaultValue = "") String changedAttributeName) { final URI termUri = idResolver.resolveIdentifier(namespace, localName); - return termService.getChanges(termService.findRequired(termUri)); + final ChangeRecordFilterDto filter = new ChangeRecordFilterDto(); + filter.setChangeType(changeType); + filter.setAuthorName(authorName); + filter.setChangedAttributeName(changedAttributeName); + return termService.getChanges(termService.findRequired(termUri), filter); } @Operation(security = {@SecurityRequirement(name = "bearer-key")}, 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 13858a4e0..912ebf1f0 100644 --- a/src/main/java/cz/cvut/kbss/termit/rest/VocabularyController.java +++ b/src/main/java/cz/cvut/kbss/termit/rest/VocabularyController.java @@ -22,7 +22,7 @@ import cz.cvut.kbss.termit.dto.RdfsStatement; 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.filter.ChangeRecordFilterDto; import cz.cvut.kbss.termit.dto.listing.VocabularyDto; import cz.cvut.kbss.termit.model.Vocabulary; import cz.cvut.kbss.termit.model.acl.AccessControlRecord; @@ -266,7 +266,7 @@ public List getHistory( required = false) Optional namespace) { final Vocabulary vocabulary = vocabularyService.getReference( resolveVocabularyUri(localName, namespace)); - return vocabularyService.getChanges(vocabulary); + return vocabularyService.getChanges(vocabulary, new ChangeRecordFilterDto()); // TODO: filter dto } @Operation(security = {@SecurityRequirement(name = "bearer-key")}, @@ -297,34 +297,31 @@ 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 = "Term name to be used in filtering.") - @RequestParam(name = "term", required = false, defaultValue = "") - String termName, - @Parameter(description = "Change type to be used in filtering.") - @RequestParam(name = "type", required = false) - URI changeType, - @Parameter(description = "Author name to be used in filtering.") - @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) { + @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 used for filtering.") @RequestParam(name = "term", + required = false, + defaultValue = "") String termName, + @Parameter(description = "Change type used for filtering.") @RequestParam(name = "type", + required = false) URI changeType, + @Parameter(description = "Author name used for filtering.") @RequestParam(name = "author", + required = false, + defaultValue = "") String authorName, + @Parameter(description = "Changed attribute name used for 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) { final Pageable pageReq = createPageRequest(pageSize, pageNo); final Vocabulary vocabulary = vocabularyService.getReference(resolveVocabularyUri(localName, namespace)); - final VocabularyContentChangeFilterDto filter = new VocabularyContentChangeFilterDto(); - filter.setTermName(termName); + final ChangeRecordFilterDto filter = new ChangeRecordFilterDto(); + filter.setAssetLabel(termName); filter.setChangeType(changeType); filter.setAuthorName(authorName); filter.setChangedAttributeName(changedAttributeName); diff --git a/src/main/java/cz/cvut/kbss/termit/service/business/ResourceService.java b/src/main/java/cz/cvut/kbss/termit/service/business/ResourceService.java index f8d8f87a3..412644c83 100644 --- a/src/main/java/cz/cvut/kbss/termit/service/business/ResourceService.java +++ b/src/main/java/cz/cvut/kbss/termit/service/business/ResourceService.java @@ -18,6 +18,7 @@ package cz.cvut.kbss.termit.service.business; import cz.cvut.kbss.termit.asset.provenance.SupportsLastModification; +import cz.cvut.kbss.termit.dto.filter.ChangeRecordFilterDto; import cz.cvut.kbss.termit.event.DocumentRenameEvent; import cz.cvut.kbss.termit.event.FileRenameEvent; import cz.cvut.kbss.termit.event.VocabularyWillBeRemovedEvent; @@ -369,8 +370,8 @@ public long getLastModified() { } @Override - public List getChanges(Resource asset) { - return changeRecordService.getChanges(asset); + public List getChanges(Resource asset, ChangeRecordFilterDto filterDto) { + return changeRecordService.getChanges(asset, filterDto); } @Override diff --git a/src/main/java/cz/cvut/kbss/termit/service/business/TermService.java b/src/main/java/cz/cvut/kbss/termit/service/business/TermService.java index b22bc1e67..1578b4888 100644 --- a/src/main/java/cz/cvut/kbss/termit/service/business/TermService.java +++ b/src/main/java/cz/cvut/kbss/termit/service/business/TermService.java @@ -20,6 +20,7 @@ import cz.cvut.kbss.termit.dto.RdfsResource; import cz.cvut.kbss.termit.dto.Snapshot; import cz.cvut.kbss.termit.dto.assignment.TermOccurrences; +import cz.cvut.kbss.termit.dto.filter.ChangeRecordFilterDto; import cz.cvut.kbss.termit.dto.listing.TermDto; import cz.cvut.kbss.termit.exception.InvalidTermStateException; import cz.cvut.kbss.termit.exception.NotFoundException; @@ -545,9 +546,9 @@ private void checkForInvalidTerminalStateAssignment(Term term, URI state) { } @Override - public List getChanges(Term term) { + public List getChanges(Term term, ChangeRecordFilterDto filterDto) { Objects.requireNonNull(term); - return changeRecordService.getChanges(term); + return changeRecordService.getChanges(term, filterDto); } /** diff --git a/src/main/java/cz/cvut/kbss/termit/service/business/VocabularyService.java b/src/main/java/cz/cvut/kbss/termit/service/business/VocabularyService.java index a0f252171..08281353c 100644 --- a/src/main/java/cz/cvut/kbss/termit/service/business/VocabularyService.java +++ b/src/main/java/cz/cvut/kbss/termit/service/business/VocabularyService.java @@ -22,7 +22,7 @@ import cz.cvut.kbss.termit.dto.RdfsStatement; 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.filter.ChangeRecordFilterDto; import cz.cvut.kbss.termit.dto.listing.TermDto; import cz.cvut.kbss.termit.dto.listing.VocabularyDto; import cz.cvut.kbss.termit.event.VocabularyContentModifiedEvent; @@ -299,8 +299,8 @@ public TypeAwareResource getExcelTemplateFile() { } @Override - public List getChanges(Vocabulary asset) { - return changeRecordService.getChanges(asset); + public List getChanges(Vocabulary asset, ChangeRecordFilterDto filterDto) { + return changeRecordService.getChanges(asset, filterDto); } /** @@ -320,7 +320,7 @@ public List getChangesOfContent(Vocabulary vocabulary) { * @param pageReq Specification of the size and number of the page to return * @return List of change records, ordered by date in descending order */ - public List getDetailedHistoryOfContent(Vocabulary vocabulary, VocabularyContentChangeFilterDto filter, Pageable pageReq) { + public List getDetailedHistoryOfContent(Vocabulary vocabulary, ChangeRecordFilterDto filter, Pageable pageReq) { return repositoryService.getDetailedHistoryOfContent(vocabulary, filter, pageReq); } diff --git a/src/main/java/cz/cvut/kbss/termit/service/changetracking/ChangeRecordProvider.java b/src/main/java/cz/cvut/kbss/termit/service/changetracking/ChangeRecordProvider.java index 41396793d..d6f034dfe 100644 --- a/src/main/java/cz/cvut/kbss/termit/service/changetracking/ChangeRecordProvider.java +++ b/src/main/java/cz/cvut/kbss/termit/service/changetracking/ChangeRecordProvider.java @@ -17,8 +17,9 @@ */ package cz.cvut.kbss.termit.service.changetracking; +import cz.cvut.kbss.termit.dto.filter.ChangeRecordFilterDto; +import cz.cvut.kbss.termit.model.Asset; import cz.cvut.kbss.termit.model.changetracking.AbstractChangeRecord; -import cz.cvut.kbss.termit.model.util.HasIdentifier; import java.util.List; @@ -27,7 +28,17 @@ * * @param Type of asset to get changes for */ -public interface ChangeRecordProvider { +public interface ChangeRecordProvider> { + + /** + * Gets change records of the specified asset + * filtered by {@link ChangeRecordFilterDto}. + * + * @param asset Asset to find change records for + * @param filterDto Filter parameters + * @return List of change records, ordered by record timestamp in descending order + */ + List getChanges(T asset, ChangeRecordFilterDto filterDto); /** * Gets change records of the specified asset. @@ -35,5 +46,7 @@ public interface ChangeRecordProvider { * @param asset Asset to find change records for * @return List of change records, ordered by record timestamp in descending order */ - List getChanges(T asset); + default List getChanges(T asset) { + return getChanges(asset, new ChangeRecordFilterDto()); + } } diff --git a/src/main/java/cz/cvut/kbss/termit/service/repository/ChangeRecordService.java b/src/main/java/cz/cvut/kbss/termit/service/repository/ChangeRecordService.java index 6dc0c6ad8..5dc24350b 100644 --- a/src/main/java/cz/cvut/kbss/termit/service/repository/ChangeRecordService.java +++ b/src/main/java/cz/cvut/kbss/termit/service/repository/ChangeRecordService.java @@ -17,6 +17,8 @@ */ package cz.cvut.kbss.termit.service.repository; +import cz.cvut.kbss.termit.dto.filter.ChangeRecordFilterDto; +import cz.cvut.kbss.termit.model.Asset; import cz.cvut.kbss.termit.model.User; import cz.cvut.kbss.termit.model.changetracking.AbstractChangeRecord; import cz.cvut.kbss.termit.model.util.HasIdentifier; @@ -29,7 +31,7 @@ import java.util.Set; @Service -public class ChangeRecordService implements ChangeRecordProvider { +public class ChangeRecordService implements ChangeRecordProvider> { private final ChangeRecordDao changeRecordDao; @@ -39,8 +41,8 @@ public ChangeRecordService(ChangeRecordDao changeRecordDao) { } @Override - public List getChanges(HasIdentifier asset) { - return changeRecordDao.findAll(asset); + public List getChanges(Asset asset, ChangeRecordFilterDto filterDto) { + return changeRecordDao.findAll(asset, filterDto); } /** diff --git a/src/main/java/cz/cvut/kbss/termit/service/repository/VocabularyRepositoryService.java b/src/main/java/cz/cvut/kbss/termit/service/repository/VocabularyRepositoryService.java index 43e7cde00..c63f85b4a 100644 --- a/src/main/java/cz/cvut/kbss/termit/service/repository/VocabularyRepositoryService.java +++ b/src/main/java/cz/cvut/kbss/termit/service/repository/VocabularyRepositoryService.java @@ -21,7 +21,7 @@ import cz.cvut.kbss.termit.dto.PrefixDeclaration; import cz.cvut.kbss.termit.dto.RdfsStatement; import cz.cvut.kbss.termit.dto.Snapshot; -import cz.cvut.kbss.termit.dto.filter.VocabularyContentChangeFilterDto; +import cz.cvut.kbss.termit.dto.filter.ChangeRecordFilterDto; import cz.cvut.kbss.termit.dto.listing.VocabularyDto; import cz.cvut.kbss.termit.dto.mapper.DtoMapper; import cz.cvut.kbss.termit.exception.AssetRemovalException; @@ -229,7 +229,7 @@ public List getChangesOfContent(Vocabulary vocabulary) { * @return List of change records, ordered by date in descending order */ @Transactional(readOnly = true) - public List getDetailedHistoryOfContent(Vocabulary vocabulary, VocabularyContentChangeFilterDto filter, Pageable pageReq) { + public List getDetailedHistoryOfContent(Vocabulary vocabulary, ChangeRecordFilterDto filter, Pageable pageReq) { return vocabularyDao.getDetailedHistoryOfContent(vocabulary, filter, pageReq); } diff --git a/src/test/java/cz/cvut/kbss/termit/persistence/dao/VocabularyDaoTest.java b/src/test/java/cz/cvut/kbss/termit/persistence/dao/VocabularyDaoTest.java index 045991208..ffec7ac97 100644 --- a/src/test/java/cz/cvut/kbss/termit/persistence/dao/VocabularyDaoTest.java +++ b/src/test/java/cz/cvut/kbss/termit/persistence/dao/VocabularyDaoTest.java @@ -26,7 +26,7 @@ import cz.cvut.kbss.termit.dto.PrefixDeclaration; import cz.cvut.kbss.termit.dto.RdfsStatement; import cz.cvut.kbss.termit.dto.Snapshot; -import cz.cvut.kbss.termit.dto.filter.VocabularyContentChangeFilterDto; +import cz.cvut.kbss.termit.dto.filter.ChangeRecordFilterDto; import cz.cvut.kbss.termit.environment.Environment; import cz.cvut.kbss.termit.environment.Generator; import cz.cvut.kbss.termit.event.AssetPersistEvent; @@ -973,7 +973,7 @@ void getDetailedHistoryOfContentReturnsRecordsForAllChangeTypes() { changeRecordDao.persist(deleteChangeRecord, termToRemove); }); - final VocabularyContentChangeFilterDto filter = new VocabularyContentChangeFilterDto(); + final ChangeRecordFilterDto filter = new ChangeRecordFilterDto(); final int recordsCount = firstChanges.size() + termToRemoveChanges.size() + 1; // +1 for the delete record final Pageable pageable = Pageable.ofSize(recordsCount * 3); final List contentChanges = sut.getDetailedHistoryOfContent(vocabulary, filter, pageable); @@ -1023,8 +1023,8 @@ void getDetailedHistoryOfContentReturnsRecordsOfExistingTermFilteredByTermName() thirdChanges.forEach(r -> changeRecordDao.persist(r, thirdTerm)); }); - final VocabularyContentChangeFilterDto filter = new VocabularyContentChangeFilterDto(); - filter.setTermName(needle); + final ChangeRecordFilterDto filter = new ChangeRecordFilterDto(); + filter.setAssetLabel(needle); final int recordsCount = firstChanges.size() + secondChanges.size(); final Pageable pageable = Pageable.ofSize(recordsCount * 2); @@ -1078,8 +1078,8 @@ void getDetailedHistoryOfContentReturnsRecordsOfDeletedTermFilteredByTermName() termDao.remove(termToRemove); }); - final VocabularyContentChangeFilterDto filter = new VocabularyContentChangeFilterDto(); - filter.setTermName(needle); + final ChangeRecordFilterDto filter = new ChangeRecordFilterDto(); + filter.setAssetLabel(needle); final int recordsCount = termToRemoveChanges.size() + 1; // +1 for the delete record final Pageable pageable = Pageable.ofSize(recordsCount * 2); @@ -1137,7 +1137,7 @@ void getDetailedHistoryOfContentReturnsRecordsOfExistingTermFilteredByChangedAtt secondChanges.forEach(r -> changeRecordDao.persist(r, secondTerm)); }); - final VocabularyContentChangeFilterDto filter = new VocabularyContentChangeFilterDto(); + final ChangeRecordFilterDto filter = new ChangeRecordFilterDto(); filter.setChangedAttributeName(changedAttributeName); final Pageable pageable = Pageable.ofSize(recordCount.get() * 2); @@ -1188,7 +1188,7 @@ void getDetailedHistoryOfContentReturnsRecordsOfExistingTermFilteredByAuthorName secondChanges.forEach(r -> changeRecordDao.persist(r, secondTerm)); }); - final VocabularyContentChangeFilterDto filter = new VocabularyContentChangeFilterDto(); + final ChangeRecordFilterDto filter = new ChangeRecordFilterDto(); // full name without first two and last two characters filter.setAuthorName(anotherAuthor.getFullName().substring(2, anotherAuthor.getFullName().length() - 2)); @@ -1251,7 +1251,7 @@ void getDetailedHistoryOfContentReturnsRecordsOfExistingTermFilteredByChangeType termDao.remove(secondTerm); }); - final VocabularyContentChangeFilterDto filter = new VocabularyContentChangeFilterDto(); + final ChangeRecordFilterDto filter = new ChangeRecordFilterDto(); // full name without first two and last two characters filter.setChangeType(typeUri); diff --git a/src/test/java/cz/cvut/kbss/termit/rest/ResourceControllerTest.java b/src/test/java/cz/cvut/kbss/termit/rest/ResourceControllerTest.java index bd50b7258..2b1adb9d2 100644 --- a/src/test/java/cz/cvut/kbss/termit/rest/ResourceControllerTest.java +++ b/src/test/java/cz/cvut/kbss/termit/rest/ResourceControllerTest.java @@ -19,6 +19,7 @@ import com.fasterxml.jackson.core.type.TypeReference; import cz.cvut.kbss.jsonld.JsonLd; +import cz.cvut.kbss.termit.dto.filter.ChangeRecordFilterDto; import cz.cvut.kbss.termit.environment.Environment; import cz.cvut.kbss.termit.environment.Generator; import cz.cvut.kbss.termit.exception.NotFoundException; @@ -396,7 +397,8 @@ void getHistoryReturnsListOfChangeRecordsForSpecifiedVocabulary() throws Excepti when(identifierResolverMock.resolveIdentifier(RESOURCE_NAMESPACE, RESOURCE_NAME)).thenReturn(resource.getUri()); when(resourceServiceMock.getReference(RESOURCE_URI)).thenReturn(resource); final List records = Collections.singletonList(Generator.generatePersistChange(resource)); - when(resourceServiceMock.getChanges(resource)).thenReturn(records); + final ChangeRecordFilterDto emptyFilter = new ChangeRecordFilterDto(); + when(resourceServiceMock.getChanges(resource, emptyFilter)).thenReturn(records); final MvcResult mvcResult = mockMvc .perform(get(PATH + "/" + RESOURCE_NAME + "/history").param(QueryParams.NAMESPACE, RESOURCE_NAMESPACE)) @@ -406,7 +408,7 @@ void getHistoryReturnsListOfChangeRecordsForSpecifiedVocabulary() throws Excepti }); assertNotNull(result); assertEquals(records, result); - verify(resourceServiceMock).getChanges(resource); + verify(resourceServiceMock).getChanges(resource, emptyFilter); } @Test diff --git a/src/test/java/cz/cvut/kbss/termit/rest/TermControllerTest.java b/src/test/java/cz/cvut/kbss/termit/rest/TermControllerTest.java index cedfb8e06..55554e910 100644 --- a/src/test/java/cz/cvut/kbss/termit/rest/TermControllerTest.java +++ b/src/test/java/cz/cvut/kbss/termit/rest/TermControllerTest.java @@ -23,6 +23,7 @@ import cz.cvut.kbss.jopa.vocabulary.SKOS; import cz.cvut.kbss.jsonld.JsonLd; import cz.cvut.kbss.termit.dto.Snapshot; +import cz.cvut.kbss.termit.dto.filter.ChangeRecordFilterDto; import cz.cvut.kbss.termit.dto.listing.TermDto; import cz.cvut.kbss.termit.environment.Environment; import cz.cvut.kbss.termit.environment.Generator; @@ -803,7 +804,8 @@ void getHistoryReturnsListOfChangeRecordsForSpecifiedTerm() throws Exception { term.setUri(termUri); when(termServiceMock.findRequired(term.getUri())).thenReturn(term); final List records = generateChangeRecords(term); - when(termServiceMock.getChanges(term)).thenReturn(records); + final ChangeRecordFilterDto emptyFilter = new ChangeRecordFilterDto(); + when(termServiceMock.getChanges(term, emptyFilter)).thenReturn(records); final MvcResult mvcResult = mockMvc .perform(get(PATH + VOCABULARY_NAME + "/terms/" + TERM_NAME + "/history")) @@ -812,6 +814,7 @@ void getHistoryReturnsListOfChangeRecordsForSpecifiedTerm() throws Exception { }); assertNotNull(result); assertEquals(records, result); + verify(termServiceMock).getChanges(term, emptyFilter); } private List generateChangeRecords(Term term) { @@ -833,7 +836,8 @@ void getHistoryStandaloneReturnsListOfChangeRecordsForSpecifiedTerm() throws Exc when(idResolverMock.resolveIdentifier(NAMESPACE, TERM_NAME)).thenReturn(termUri); when(termServiceMock.findRequired(termUri)).thenReturn(term); final List records = generateChangeRecords(term); - when(termServiceMock.getChanges(term)).thenReturn(records); + final ChangeRecordFilterDto emptyFilter = new ChangeRecordFilterDto(); + when(termServiceMock.getChanges(term, emptyFilter)).thenReturn(records); final MvcResult mvcResult = mockMvc .perform(get("/terms/" + TERM_NAME + "/history").param(QueryParams.NAMESPACE, NAMESPACE)) @@ -843,6 +847,7 @@ void getHistoryStandaloneReturnsListOfChangeRecordsForSpecifiedTerm() throws Exc }); assertNotNull(result); assertEquals(records, result); + verify(termServiceMock).getChanges(term, emptyFilter); } @Test 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 a7e8677c6..2ebe5c579 100644 --- a/src/test/java/cz/cvut/kbss/termit/rest/VocabularyControllerTest.java +++ b/src/test/java/cz/cvut/kbss/termit/rest/VocabularyControllerTest.java @@ -22,7 +22,7 @@ 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.filter.ChangeRecordFilterDto; import cz.cvut.kbss.termit.dto.listing.VocabularyDto; import cz.cvut.kbss.termit.environment.Environment; import cz.cvut.kbss.termit.environment.Generator; @@ -431,7 +431,8 @@ void getHistoryReturnsListOfChangeRecordsForSpecifiedVocabulary() throws Excepti final Vocabulary vocabulary = generateVocabularyAndInitReferenceResolution(); final List records = Generator.generateChangeRecords(vocabulary, user); - when(serviceMock.getChanges(vocabulary)).thenReturn(records); + final ChangeRecordFilterDto emptyFilter = new ChangeRecordFilterDto(); + when(serviceMock.getChanges(vocabulary, emptyFilter)).thenReturn(records); final MvcResult mvcResult = mockMvc.perform(get(PATH + "/" + FRAGMENT + "/history")).andExpect(status().isOk()) @@ -441,7 +442,7 @@ void getHistoryReturnsListOfChangeRecordsForSpecifiedVocabulary() throws Excepti }); assertNotNull(result); assertEquals(records, result); - verify(serviceMock).getChanges(vocabulary); + verify(serviceMock).getChanges(vocabulary,emptyFilter); } @Test @@ -653,7 +654,7 @@ void getDetailedHistoryOfContentReturnsListOfChangeRecordsWhenNoFilterIsSpecifie 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 ChangeRecordFilterDto filter = new ChangeRecordFilterDto(); final Pageable pageable = Pageable.ofSize(pageSize); doReturn(changeRecords).when(serviceMock).getDetailedHistoryOfContent(vocabulary, filter, pageable); diff --git a/src/test/java/cz/cvut/kbss/termit/service/business/ResourceServiceTest.java b/src/test/java/cz/cvut/kbss/termit/service/business/ResourceServiceTest.java index 6119b0f90..3f9f8695a 100644 --- a/src/test/java/cz/cvut/kbss/termit/service/business/ResourceServiceTest.java +++ b/src/test/java/cz/cvut/kbss/termit/service/business/ResourceServiceTest.java @@ -17,6 +17,7 @@ */ package cz.cvut.kbss.termit.service.business; +import cz.cvut.kbss.termit.dto.filter.ChangeRecordFilterDto; import cz.cvut.kbss.termit.environment.Environment; import cz.cvut.kbss.termit.environment.Generator; import cz.cvut.kbss.termit.event.DocumentRenameEvent; @@ -426,9 +427,10 @@ void getLastModifiedReturnsValueFromRepositoryService() { void getChangesLoadsChangeRecordsForSpecifiedAssetFromChangeRecordService() { final Resource resource = Generator.generateResourceWithId(); final List records = Collections.singletonList(Generator.generatePersistChange(resource)); - when(changeRecordService.getChanges(resource)).thenReturn(records); + final ChangeRecordFilterDto filterDto = new ChangeRecordFilterDto(); + when(changeRecordService.getChanges(resource, filterDto)).thenReturn(records); assertEquals(records, sut.getChanges(resource)); - verify(changeRecordService).getChanges(resource); + verify(changeRecordService).getChanges(resource, filterDto); } @Test diff --git a/src/test/java/cz/cvut/kbss/termit/service/business/TermServiceTest.java b/src/test/java/cz/cvut/kbss/termit/service/business/TermServiceTest.java index 5ea15780f..4a222635f 100644 --- a/src/test/java/cz/cvut/kbss/termit/service/business/TermServiceTest.java +++ b/src/test/java/cz/cvut/kbss/termit/service/business/TermServiceTest.java @@ -21,6 +21,7 @@ import cz.cvut.kbss.termit.dto.RdfsResource; import cz.cvut.kbss.termit.dto.TermInfo; import cz.cvut.kbss.termit.dto.assignment.TermOccurrences; +import cz.cvut.kbss.termit.dto.filter.ChangeRecordFilterDto; import cz.cvut.kbss.termit.dto.listing.TermDto; import cz.cvut.kbss.termit.environment.Environment; import cz.cvut.kbss.termit.environment.Generator; @@ -396,7 +397,7 @@ void setTermDefinitionReplacesExistingTermDefinition() { void getChangesRetrievesChangeRecordsFromChangeRecordService() { final Term asset = Generator.generateTermWithId(); sut.getChanges(asset); - verify(changeRecordService).getChanges(asset); + verify(changeRecordService).getChanges(asset, new ChangeRecordFilterDto()); } @Test diff --git a/src/test/java/cz/cvut/kbss/termit/service/business/VocabularyServiceTest.java b/src/test/java/cz/cvut/kbss/termit/service/business/VocabularyServiceTest.java index 6cc2d505d..ca6b97ab2 100644 --- a/src/test/java/cz/cvut/kbss/termit/service/business/VocabularyServiceTest.java +++ b/src/test/java/cz/cvut/kbss/termit/service/business/VocabularyServiceTest.java @@ -19,6 +19,7 @@ import cz.cvut.kbss.termit.dto.Snapshot; import cz.cvut.kbss.termit.dto.acl.AccessControlListDto; +import cz.cvut.kbss.termit.dto.filter.ChangeRecordFilterDto; import cz.cvut.kbss.termit.dto.listing.TermDto; import cz.cvut.kbss.termit.dto.listing.VocabularyDto; import cz.cvut.kbss.termit.environment.Environment; @@ -184,10 +185,11 @@ void getChangesRetrievesChangesForVocabulary() { final Vocabulary vocabulary = Generator.generateVocabularyWithId(); final List records = Generator.generateChangeRecords(vocabulary, Generator.generateUserWithId()); - when(changeRecordService.getChanges(vocabulary)).thenReturn(records); + final ChangeRecordFilterDto emptyFilter = new ChangeRecordFilterDto(); + when(changeRecordService.getChanges(vocabulary, emptyFilter)).thenReturn(records); final List result = sut.getChanges(vocabulary); assertEquals(records, result); - verify(changeRecordService).getChanges(vocabulary); + verify(changeRecordService).getChanges(vocabulary, emptyFilter); } @Test