View Javadoc
1   package de.dlr.shepard.context.semantic.daos;
2   
3   import de.dlr.shepard.common.neo4j.daos.GenericDAO;
4   import de.dlr.shepard.context.semantic.entities.AnnotatableTimeseries;
5   import de.dlr.shepard.context.semantic.entities.SemanticAnnotation;
6   import de.dlr.shepard.context.semantic.entities.SemanticRepository;
7   import jakarta.enterprise.context.RequestScoped;
8   import jakarta.ws.rs.NotFoundException;
9   import java.util.Optional;
10  import org.neo4j.ogm.cypher.ComparisonOperator;
11  import org.neo4j.ogm.cypher.Filter;
12  
13  @RequestScoped
14  public class AnnotatableTimeseriesDAO extends GenericDAO<AnnotatableTimeseries> {
15  
16    public Optional<AnnotatableTimeseries> findByTimeseries(long containerId, int timeseriesId) {
17      var containerFilter = new Filter("containerId", ComparisonOperator.EQUALS, containerId);
18      var timeseriesFilter = new Filter("timeseriesId", ComparisonOperator.EQUALS, timeseriesId);
19      return this.session.loadAll(AnnotatableTimeseries.class, containerFilter.and(timeseriesFilter), 2)
20        .stream()
21        .findFirst();
22    }
23  
24    public SemanticAnnotation getAnnotationById(long annotationId) {
25      var entity = this.session.load(SemanticAnnotation.class, annotationId, 2);
26      if (entity != null) return entity;
27  
28      throw new NotFoundException("No semantic annotation found with id " + annotationId);
29    }
30  
31    public void deleteAnnotation(long annotationId) {
32      var annotation = getAnnotationById(annotationId);
33      session.delete(annotation);
34    }
35  
36    public SemanticRepository getSemanticRepositoryById(long semanticRepositoryId) {
37      var entity = session.load(SemanticRepository.class, semanticRepositoryId);
38      if (entity != null) return entity;
39  
40      throw new NotFoundException("No semantic repository found with id " + semanticRepositoryId);
41    }
42  
43    @Override
44    public AnnotatableTimeseries createOrUpdate(AnnotatableTimeseries entity) {
45      session.save(entity, 2);
46      return entity;
47    }
48  
49    @Override
50    public Class<AnnotatableTimeseries> getEntityType() {
51      return AnnotatableTimeseries.class;
52    }
53  }