1 package fr.ifremer.quadrige3.core.dao.data.samplingoperation;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26 import com.google.common.collect.ImmutableList;
27 import fr.ifremer.quadrige3.core.dao.technical.Assert;
28 import fr.ifremer.quadrige3.core.dao.technical.Daos;
29 import org.apache.commons.collections4.CollectionUtils;
30 import org.apache.commons.logging.Log;
31 import org.apache.commons.logging.LogFactory;
32 import org.hibernate.SessionFactory;
33 import org.hibernate.type.StringType;
34 import org.springframework.beans.factory.annotation.Autowired;
35 import org.springframework.context.annotation.Lazy;
36 import org.springframework.stereotype.Repository;
37
38 import java.util.List;
39
40
41
42
43
44
45
46
47 @Repository("samplingOperationDao")
48 @Lazy
49 public class SamplingOperationDaoImpl
50 extends SamplingOperationDaoBase
51 implements SamplingOperationExtendDao
52 {
53
54
55
56 private static final Log log = LogFactory.getLog(SamplingOperationDaoImpl.class);
57
58
59
60
61
62
63
64 @Autowired
65 public SamplingOperationDaoImpl(SessionFactory sessionFactory) {
66 super();
67 setSessionFactory(sessionFactory);
68 }
69
70
71 @Override
72 public int updateHasMeasFlagBySurveyId(int surveyId) {
73 return updateHasMeasFlagBySurveyIds(ImmutableList.of(surveyId));
74 }
75
76
77 @Override
78 public int updateHasMeasFlagBySurveyIds(List<Integer> surveyIds) {
79 Assert.notEmpty(surveyIds);
80
81 if (log.isDebugEnabled()) {
82 log.debug(String.format("Updating HAS_MEAS flag o sampling operation, for parent surveys: %s", surveyIds.toString()));
83 }
84 int rowCount = 0;
85
86
87 List<Integer> samplingOperIdsWithMeas = queryListTyped("samplingOperIdsWithMeasBySurveyIds",
88 "surveyIds", null, surveyIds);
89 boolean hasSamplingOperIdsWithMeas = CollectionUtils.isNotEmpty(samplingOperIdsWithMeas);
90
91
92 List<Integer> samplingOperIdsNoMeas = queryListTyped("samplingOperIdsBySurveyIdsNotInIds",
93 "surveyIds", null, surveyIds,
94 "excludedSamplingOperIds", null, hasSamplingOperIdsWithMeas ? samplingOperIdsWithMeas : ImmutableList.of(-99999999));
95
96
97 if (hasSamplingOperIdsWithMeas) {
98 rowCount += queryUpdate("updateSamplingOperHasMeas",
99 "samplingOperHasMeas", StringType.INSTANCE, Daos.convertToString(true),
100 "samplingOperIds", null, samplingOperIdsWithMeas);
101 }
102
103
104 if (CollectionUtils.isNotEmpty(samplingOperIdsNoMeas)) {
105 rowCount += queryUpdate("updateSamplingOperHasMeas",
106 "samplingOperHasMeas", StringType.INSTANCE, Daos.convertToString(false),
107 "samplingOperIds", null, samplingOperIdsNoMeas);
108 }
109
110 return rowCount;
111 }
112 }