Skip to content

Commit

Permalink
[#82] Persist ActionHistory entity in separate Person context
Browse files Browse the repository at this point in the history
  • Loading branch information
palagdan committed Dec 25, 2024
1 parent c70324f commit 06953a9
Showing 1 changed file with 26 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,23 @@

import cz.cvut.kbss.jopa.exceptions.NoResultException;
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.metamodel.EntityType;
import cz.cvut.kbss.jopa.model.query.TypedQuery;
import cz.cvut.kbss.study.exception.PersistenceException;
import cz.cvut.kbss.study.model.ActionHistory;
import cz.cvut.kbss.study.model.User;
import cz.cvut.kbss.study.model.Vocabulary;
import cz.cvut.kbss.study.util.Constants;
import cz.cvut.kbss.study.util.IdentificationUtils;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Repository;

import java.net.URI;
import java.net.URISyntaxException;
import java.util.Objects;

@Repository
Expand All @@ -22,6 +28,26 @@ public ActionHistoryDao(EntityManager em) {
super(ActionHistory.class, em);
}

private Descriptor getDescriptor(URI ctx){
Descriptor descriptor = new EntityDescriptor(ctx);
EntityType<ActionHistory> et = em.getMetamodel().entity(ActionHistory.class);
descriptor.addAttributeContext(et.getAttribute("author"), null);
return descriptor;
}

@Override
public void persist(ActionHistory entity) {
Objects.requireNonNull(entity);
try {
entity.setKey(IdentificationUtils.generateKey());
Descriptor descriptor = getDescriptor(new URI(Vocabulary.s_c_action_history));
em.persist(entity, descriptor);
} catch (RuntimeException | URISyntaxException e) {
LOG.error("Error when persisting entity.", e);
throw new PersistenceException(e);
}
}

public ActionHistory findByKey(String key) {
Objects.requireNonNull(key);
try {
Expand Down

0 comments on commit 06953a9

Please sign in to comment.