From bd2996883844f4c72059e27867d3f979f9d4463a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Luk=C3=A1=C5=A1=20Ka=C5=88ka?= Date: Sun, 27 Oct 2024 13:53:44 +0100 Subject: [PATCH] [Enhancement kbss-cvut/termit-ui#530] Remove vocabulary from DeleteChangeRecord The record is already saved in tha vocabulary context. --- .../changetracking/DeleteChangeRecord.java | 21 ++----------------- .../service/changetracking/ChangeTracker.java | 9 +------- 2 files changed, 3 insertions(+), 27 deletions(-) diff --git a/src/main/java/cz/cvut/kbss/termit/model/changetracking/DeleteChangeRecord.java b/src/main/java/cz/cvut/kbss/termit/model/changetracking/DeleteChangeRecord.java index 27657e808..1d2cdc98c 100644 --- a/src/main/java/cz/cvut/kbss/termit/model/changetracking/DeleteChangeRecord.java +++ b/src/main/java/cz/cvut/kbss/termit/model/changetracking/DeleteChangeRecord.java @@ -3,14 +3,12 @@ import cz.cvut.kbss.jopa.model.MultilingualString; import cz.cvut.kbss.jopa.model.annotations.OWLAnnotationProperty; import cz.cvut.kbss.jopa.model.annotations.OWLClass; -import cz.cvut.kbss.jopa.model.annotations.OWLObjectProperty; import cz.cvut.kbss.jopa.model.annotations.ParticipationConstraints; import cz.cvut.kbss.jopa.vocabulary.RDFS; import cz.cvut.kbss.termit.model.Asset; import cz.cvut.kbss.termit.util.Vocabulary; import jakarta.annotation.Nonnull; -import java.net.URI; import java.util.Objects; /** @@ -22,16 +20,12 @@ public class DeleteChangeRecord extends AbstractChangeRecord { @OWLAnnotationProperty(iri = RDFS.LABEL) private MultilingualString label; - @OWLObjectProperty(iri = Vocabulary.s_p_je_pojmem_ze_slovniku) - private URI vocabulary; - /** * Creates a new instance. * @param changedEntity the changed asset - * @param vocabulary optional vocabulary URI * @throws IllegalArgumentException If the label type is not String or MultilingualString */ - public DeleteChangeRecord(Asset changedEntity, URI vocabulary) { + public DeleteChangeRecord(Asset changedEntity) { super(changedEntity); if (changedEntity.getLabel() instanceof String stringLabel) { @@ -41,8 +35,6 @@ public DeleteChangeRecord(Asset changedEntity, URI vocabulary) { } else { throw new IllegalArgumentException("Unsupported label type: " + changedEntity.getLabel().getClass()); } - - this.vocabulary = vocabulary; } public DeleteChangeRecord() { @@ -57,14 +49,6 @@ public void setLabel(MultilingualString label) { this.label = label; } - public URI getVocabulary() { - return vocabulary; - } - - public void setVocabulary(URI vocabulary) { - this.vocabulary = vocabulary; - } - @Override public boolean equals(Object o) { if (this == o) { @@ -76,7 +60,7 @@ public boolean equals(Object o) { if (!super.equals(o)) { return false; } - return Objects.equals(label, that.label) && Objects.equals(vocabulary, that.vocabulary); + return Objects.equals(label, that.label); } @Override @@ -84,7 +68,6 @@ public String toString() { return "DeleteChangeRecord{" + super.toString() + ", label=" + label + - (vocabulary != null ? ", vocabulary=" + vocabulary : "") + '}'; } diff --git a/src/main/java/cz/cvut/kbss/termit/service/changetracking/ChangeTracker.java b/src/main/java/cz/cvut/kbss/termit/service/changetracking/ChangeTracker.java index fb9ab565d..a7a5876b7 100644 --- a/src/main/java/cz/cvut/kbss/termit/service/changetracking/ChangeTracker.java +++ b/src/main/java/cz/cvut/kbss/termit/service/changetracking/ChangeTracker.java @@ -20,7 +20,6 @@ import cz.cvut.kbss.termit.event.AssetPersistEvent; import cz.cvut.kbss.termit.event.AssetUpdateEvent; import cz.cvut.kbss.termit.event.BeforeAssetDeleteEvent; -import cz.cvut.kbss.termit.model.AbstractTerm; import cz.cvut.kbss.termit.model.Asset; import cz.cvut.kbss.termit.model.User; import cz.cvut.kbss.termit.model.changetracking.AbstractChangeRecord; @@ -40,7 +39,6 @@ import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; -import java.net.URI; import java.time.Instant; import java.util.Collection; import java.util.stream.Collectors; @@ -130,12 +128,7 @@ public void onBeforeAssetDeleteEvent(@Nonnull BeforeAssetDeleteEvent event) { final Asset asset = event.getAsset(); LOG.trace("Recording deletion of asset {}.", asset); - URI vocabulary = null; - if (asset instanceof AbstractTerm term) { - vocabulary = term.getVocabulary(); - } - - final AbstractChangeRecord changeRecord = new DeleteChangeRecord(asset, vocabulary); + final AbstractChangeRecord changeRecord = new DeleteChangeRecord(asset); changeRecord.setAuthor(securityUtils.getCurrentUser().toUser()); changeRecord.setTimestamp(Utils.timestamp());