1 package fr.ifremer.quadrige3.core.dao.referential.transcribing;
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 org.apache.commons.lang3.StringUtils;
27 import org.hibernate.SessionFactory;
28 import org.hibernate.type.IntegerType;
29 import org.hibernate.type.StringType;
30 import org.springframework.beans.factory.annotation.Autowired;
31 import org.springframework.context.annotation.Lazy;
32 import org.springframework.stereotype.Repository;
33
34 import java.util.HashMap;
35 import java.util.Iterator;
36 import java.util.Map;
37
38
39
40
41
42
43
44
45 @Repository("transcribingItemDao")
46 @Lazy
47 public class TranscribingItemDaoImpl
48 extends TranscribingItemDaoBase
49 implements TranscribingItemExtendDao
50 {
51
52
53
54
55
56
57 @Autowired
58 public TranscribingItemDaoImpl(SessionFactory sessionFactory) {
59 super();
60 setSessionFactory(sessionFactory);
61 }
62
63
64 @Override
65 public Map<Integer, String> getAllTranscribingItemsById(String transcribingItemTypeLabel) {
66 Map<Integer, String> result = new HashMap<>();
67
68 if (StringUtils.isBlank(transcribingItemTypeLabel)) return result;
69
70 Iterator<Object[]> rows = queryIterator("allTranscribingById",
71 "transcItemTypeLb", StringType.INSTANCE, transcribingItemTypeLabel);
72
73 while (rows.hasNext()) {
74 Object[] cols = rows.next();
75 Integer objectId = (Integer) cols[0];
76 String externalCode = (String) cols[1];
77 result.put(objectId, externalCode);
78 }
79
80 return result;
81 }
82
83 @Override
84 public Map<String, String> getAllTranscribingItemsByCode(String transcribingItemTypeLabel) {
85 Map<String, String> result = new HashMap<>();
86
87 if (StringUtils.isBlank(transcribingItemTypeLabel)) return result;
88
89 Iterator<Object[]> rows = queryIterator("allTranscribingByCode",
90 "transcItemTypeLb", StringType.INSTANCE, transcribingItemTypeLabel);
91
92 while (rows.hasNext()) {
93 Object[] cols = rows.next();
94 String objectCode = (String) cols[0];
95 String externalCode = (String) cols[1];
96 result.put(objectCode, externalCode);
97 }
98
99 return result;
100 }
101
102
103 @Override
104 public String getTranscribingItemById(String transcribingItemTypeLabel, int objectId) {
105
106 if (StringUtils.isBlank(transcribingItemTypeLabel)) return null;
107
108 Iterator<String> rows = queryIteratorTyped("transcribingByTypeAndObjectId",
109 "transcItemTypeLb", StringType.INSTANCE, transcribingItemTypeLabel,
110 "objectId", IntegerType.INSTANCE, objectId);
111
112 if (rows.hasNext()) {
113 return rows.next();
114 }
115
116 return null;
117 }
118
119 @Override
120 public String getTranscribingItemByCode(String transcribingItemTypeLabel, String objectCode) {
121
122 if (StringUtils.isBlank(transcribingItemTypeLabel) || StringUtils.isBlank(objectCode)) return null;
123
124 Iterator<String> rows = queryIteratorTyped("transcribingByTypeAndObjectCode",
125 "transcItemTypeLb", StringType.INSTANCE, transcribingItemTypeLabel,
126 "objectCode", StringType.INSTANCE, objectCode);
127
128 if (rows.hasNext()) {
129 return rows.next();
130 }
131
132 return null;
133 }
134 }