Skip to content

Commit

Permalink
[Enhancement kbss-cvut/termit-ui#520] Fix change record filter query
Browse files Browse the repository at this point in the history
  • Loading branch information
lukaskabc committed Nov 14, 2024
1 parent 4334617 commit edfbbe5
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -100,17 +100,16 @@ public List<AbstractChangeRecord> findAllFiltered(URI changeContext, ChangeRecor
?hasTime ?timestamp ;
?hasAuthor ?author .
""" + /* Find an asset type if it is known (deleted assets does not have a type */ """
OPTIONAL {
?asset a ?assetType
}
OPTIONAL {
?asset a ?assetTypeVal .
BIND(true as ?isAssetType)
?asset a ?assetType .
OPTIONAL {
?asset a ?assetTypeValue
BIND(true as ?isAssetType)
}
}
FILTER(!BOUND(?assetType) || ?isAssetType)
""" + /* filter assets without a type (deleted) or with a matching type */ """
BIND(?assetTypeVal as ?assetTypeVar)
FILTER(!BOUND(?assetType) || !BOUND(?assetTypeVar) || BOUND(?isAssetType))
""" + /* Get author's name */ """
?author ?hasFirstName ?firstName ;
?hasLastName ?lastName .
Expand All @@ -122,26 +121,29 @@ public List<AbstractChangeRecord> findAllFiltered(URI changeContext, ChangeRecor
}
""" + /* Get asset's name (but the asset might have been already deleted) */ """
OPTIONAL {
?asset ?hasLabel ?label .
?asset ?hasLabel ?assetPrefLabel .
BIND(?assetPrefLabel as ?finalAssetLabel)
}
OPTIONAL {
?asset ?hasRdfsLabel ?label .
?asset ?hasRdfsLabel ?assetRdfsLabel .
BIND(?assetRdfsLabel as ?finalAssetLabel)
}
""" + /* then try to get the label from (delete) record */ """
OPTIONAL {
?record ?hasRdfsLabel ?label .
?record ?hasRdfsLabel ?recordRdfsLabel .
BIND(?recordRdfsLabel as ?finalAssetLabel)
}
""" + /* 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 ?asset;
?hasRdfsLabel ?label .
?hasRdfsLabel ?deleteRecordLabel .
BIND(?deleteRecordLabel as ?finalAssetLabel)
}
BIND(?assetLabelValue as ?assetLabel)
BIND(?authorNameValue as ?authorName)
BIND(?attributeNameValue as ?changedAttributeName)
FILTER (!BOUND(?assetLabel) || CONTAINS(LCASE(?label), LCASE(?assetLabel)))
FILTER (!BOUND(?assetLabel) || CONTAINS(LCASE(?finalAssetLabel), LCASE(?assetLabel)))
FILTER (!BOUND(?authorName) || CONTAINS(LCASE(?authorFullName), LCASE(?authorName)))
FILTER (!BOUND(?changedAttributeName) || CONTAINS(LCASE(?changedAttributeLabel), LCASE(?changedAttributeName)))
} ORDER BY DESC(?timestamp) ?attribute
Expand All @@ -161,12 +163,12 @@ public List<AbstractChangeRecord> findAllFiltered(URI changeContext, ChangeRecor
.setParameter("hasLabel", URI.create(SKOS.PREF_LABEL))

// Optional asset label
.setParameter("deleteRecordType", Vocabulary.s_c_smazani_entity);
.setParameter("deleteRecordType", URI.create(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("assetTypeVal", assetType.get());
query = query.setParameter("assetTypeValue", assetType.get());
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

import cz.cvut.kbss.jopa.model.EntityManager;
import cz.cvut.kbss.jopa.model.MultilingualString;
import cz.cvut.kbss.jopa.model.annotations.OWLClass;
import cz.cvut.kbss.jopa.model.descriptors.Descriptor;
import cz.cvut.kbss.jopa.vocabulary.RDFS;
import cz.cvut.kbss.jopa.vocabulary.SKOS;
Expand Down Expand Up @@ -1056,8 +1057,10 @@ void getDetailedHistoryOfContentReturnsRecordsOfDeletedTermFilteredByTermName()
final Term firstTerm = Generator.generateTermWithId(vocabulary.getUri());
// the needle is placed in the term which will be removed
firstTerm.getLabel().set(Environment.LANGUAGE, mud);
firstTerm.setVocabulary(vocabulary.getUri());
final Term termToRemove = Generator.generateTermWithId(vocabulary.getUri());
termToRemove.getLabel().set(Environment.LANGUAGE, haystack);
termToRemove.setVocabulary(vocabulary.getUri());

final List<AbstractChangeRecord> firstChanges = Generator.generateChangeRecords(firstTerm, author);
final List<AbstractChangeRecord> termToRemoveChanges = Generator.generateChangeRecords(termToRemove, author);
Expand Down Expand Up @@ -1213,20 +1216,14 @@ void getDetailedHistoryOfContentReturnsRecordsOfExistingTermFilteredByAuthorName
}

@ParameterizedTest
@ValueSource(strings = {
cz.cvut.kbss.termit.util.Vocabulary.s_c_uprava_entity,
cz.cvut.kbss.termit.util.Vocabulary.s_c_vytvoreni_entity,
cz.cvut.kbss.termit.util.Vocabulary.s_c_smazani_entity,
@ValueSource(classes = {
UpdateChangeRecord.class,
PersistChangeRecord.class,
DeleteChangeRecord.class
})
void getDetailedHistoryOfContentReturnsRecordsOfExistingTermFilteredByChangeType(String type) {
void getDetailedHistoryOfContentReturnsRecordsOfExistingTermFilteredByChangeType(Class<? extends AbstractChangeRecord> typeClass) {
enableRdfsInference(em);
final URI typeUri = URI.create(type);
final Class<? extends AbstractChangeRecord> typeClass = switch (type) {
case cz.cvut.kbss.termit.util.Vocabulary.s_c_uprava_entity -> UpdateChangeRecord.class;
case cz.cvut.kbss.termit.util.Vocabulary.s_c_vytvoreni_entity -> PersistChangeRecord.class;
case cz.cvut.kbss.termit.util.Vocabulary.s_c_smazani_entity -> DeleteChangeRecord.class;
default -> throw new IllegalArgumentException("Unknown change type: " + type);
};
final URI typeUri = URI.create(typeClass.getAnnotation(OWLClass.class).iri());

// Two terms with needle in the label, one term without needle in the label
final Vocabulary vocabulary = Generator.generateVocabularyWithId();
Expand Down

0 comments on commit edfbbe5

Please sign in to comment.