1 package de.dlr.shepard.neo4Core.services;
2
3 import de.dlr.shepard.neo4Core.dao.BasicReferenceDAO;
4 import de.dlr.shepard.neo4Core.dao.UserDAO;
5 import de.dlr.shepard.neo4Core.entities.BasicReference;
6 import de.dlr.shepard.util.DateHelper;
7 import de.dlr.shepard.util.QueryParamHelper;
8 import io.quarkus.logging.Log;
9 import jakarta.enterprise.context.RequestScoped;
10 import jakarta.inject.Inject;
11 import java.util.List;
12
13 @RequestScoped
14 public class BasicReferenceService {
15
16 private BasicReferenceDAO basicReferenceDAO;
17 private UserDAO userDAO;
18 private DateHelper dateHelper;
19
20 BasicReferenceService() {}
21
22 @Inject
23 public BasicReferenceService(BasicReferenceDAO basicReferenceDAO, UserDAO userDAO, DateHelper dateHelper) {
24 this.basicReferenceDAO = basicReferenceDAO;
25 this.userDAO = userDAO;
26 this.dateHelper = dateHelper;
27 }
28
29
30
31
32
33
34
35
36 public BasicReference getReferenceByShepardId(long shepardId) {
37 BasicReference basicReference = basicReferenceDAO.findByShepardId(shepardId);
38 if (basicReference == null || basicReference.isDeleted()) {
39 Log.errorf("Basic Reference with id %s is null or deleted", shepardId);
40 return null;
41 }
42 return basicReference;
43 }
44
45
46
47
48
49
50
51
52 public List<BasicReference> getAllBasicReferencesByDataObjectShepardId(
53 long dataObjectShepardId,
54 QueryParamHelper params
55 ) {
56 var references = basicReferenceDAO.findByDataObjectShepardId(dataObjectShepardId, params);
57 return references;
58 }
59
60
61
62
63
64
65
66
67 public boolean deleteReferenceByShepardId(long basicReferenceShepardId, String username) {
68 var user = userDAO.find(username);
69
70 var basicReference = basicReferenceDAO.findByShepardId(basicReferenceShepardId);
71 basicReference.setDeleted(true);
72 basicReference.setUpdatedAt(dateHelper.getDate());
73 basicReference.setUpdatedBy(user);
74
75 basicReferenceDAO.createOrUpdate(basicReference);
76 return true;
77 }
78 }