1
|
/**
|
2
|
* Copyright (C) 2018 EDIT
|
3
|
* European Distributed Institute of Taxonomy
|
4
|
* http://www.e-taxonomy.eu
|
5
|
*
|
6
|
* The contents of this file are subject to the Mozilla Public License Version 1.1
|
7
|
* See LICENSE.TXT at the top of this package for the full license terms.
|
8
|
*/
|
9
|
package eu.etaxonomy.cdm.model.reference;
|
10
|
|
11
|
import java.util.HashMap;
|
12
|
import java.util.Map;
|
13
|
|
14
|
/**
|
15
|
* This class provides the set of applicable {@link Reference} fields per {@link ReferenceType}
|
16
|
* together with the type specific name of the getter.
|
17
|
* <p>
|
18
|
* All this information can in principle be generically retrieved from the reference interfaces.
|
19
|
* Creating and applying annotations
|
20
|
* to refer to the actual field names could help in this case.
|
21
|
* <p>
|
22
|
*
|
23
|
* @author a.kohlbecker
|
24
|
* @since Jun 15, 2018
|
25
|
*
|
26
|
*/
|
27
|
public class ReferencePropertyDefinitions {
|
28
|
|
29
|
private static Map<String, String> iReference = new HashMap<>();
|
30
|
private static Map<String, String> iPublicationBase = new HashMap<>();
|
31
|
private static Map<String, String> iWithAuthorAndDate = new HashMap<>();
|
32
|
private static Map<String, String> iWithDoi = new HashMap<>();
|
33
|
private static Map<String, String> iAuthoredPublicationBase = new HashMap<>();
|
34
|
private static Map<String, String> iNomenclaturalReference = new HashMap<>();
|
35
|
private static Map<String, String> iVolumeReference = new HashMap<>();
|
36
|
private static Map<String, String> iSection = new HashMap<>();
|
37
|
private static Map<String, String> iPrintedUnitBase = new HashMap<>();
|
38
|
private static Map<String, String> iArticle = new HashMap<>();
|
39
|
private static Map<String, String> iBook = new HashMap<>();
|
40
|
private static Map<String, String> iBookSection = new HashMap<>();
|
41
|
private static Map<String, String> iInProceedings = new HashMap<>();
|
42
|
private static Map<String, String> iProceedings = new HashMap<>();
|
43
|
private static Map<String, String> iJournal = new HashMap<>();
|
44
|
private static Map<String, String> iPrintSeries = new HashMap<>();
|
45
|
private static Map<String, String> iThesis = new HashMap<>();
|
46
|
private static Map<String, String> iReport = new HashMap<>();
|
47
|
private static Map<String, String> iPersonalCommunication = new HashMap<>();
|
48
|
private static Map<String, String> all = new HashMap<>();
|
49
|
|
50
|
static {
|
51
|
put(iReference, "uri");
|
52
|
put(iReference, "title");
|
53
|
put(iReference, "type");
|
54
|
|
55
|
put(iWithAuthorAndDate, "authorship");
|
56
|
put(iWithAuthorAndDate, "datePublished");
|
57
|
|
58
|
put(iWithDoi, "doi");
|
59
|
|
60
|
iPublicationBase = merge(iReference);
|
61
|
put(iPublicationBase, "publisher");
|
62
|
put(iPublicationBase, "placePublished");
|
63
|
|
64
|
// put(iNomenclaturalReference, "year");
|
65
|
// put(iNomenclaturalReference, "nomenclaturalCitation");
|
66
|
|
67
|
iAuthoredPublicationBase = merge(iPublicationBase , iWithAuthorAndDate, iWithDoi);
|
68
|
|
69
|
// ----------------------------------------------------------------------------
|
70
|
// Field visibility different from ISection definition see discussion at
|
71
|
// - https://dev.e-taxonomy.eu/redmine/issues/9706#note-3
|
72
|
// iSection = merge(iReference, iWithAuthorAndDate, iWithDoi, iNomenclaturalReference); // commented to fix visibility
|
73
|
put(iSection, "authorship");
|
74
|
put(iSection, "pages");
|
75
|
put(iSection, "inReference");
|
76
|
|
77
|
iVolumeReference = merge(iReference, iWithAuthorAndDate, iWithDoi);
|
78
|
put(iVolumeReference, "volume");
|
79
|
|
80
|
iPrintedUnitBase = merge(iPublicationBase, iSection, iVolumeReference);
|
81
|
put(iPrintedUnitBase, "title");
|
82
|
put(iPrintedUnitBase, "abbrevTitle");
|
83
|
put(iPrintedUnitBase, "inReference", "inSeries");
|
84
|
put(iPrintedUnitBase, "editor");
|
85
|
|
86
|
iArticle = merge(iSection, iVolumeReference);
|
87
|
put(iArticle, "inReference", "inJournal");
|
88
|
|
89
|
iBook = merge(iPrintedUnitBase);
|
90
|
put(iBook, "inReference", "inSeries");
|
91
|
put(iBook, "edition");
|
92
|
put(iBook, "isbn");
|
93
|
|
94
|
iBookSection = merge(iSection);
|
95
|
put(iBookSection, "inReference", "inBook");
|
96
|
|
97
|
iProceedings = merge(iPrintedUnitBase);
|
98
|
put(iProceedings, "organization");
|
99
|
put(iProceedings, "isbn");
|
100
|
|
101
|
iJournal = merge(iPublicationBase);
|
102
|
put(iJournal, "issn");
|
103
|
|
104
|
iInProceedings = merge(iSection);
|
105
|
remove(iInProceedings, "series");
|
106
|
put(iInProceedings, "inReference", "In proceedings");
|
107
|
|
108
|
iPrintSeries = merge(iPublicationBase);
|
109
|
put(iPrintSeries, "publisher");
|
110
|
put(iPrintSeries, "placePublished");
|
111
|
|
112
|
iThesis = merge(iPublicationBase);
|
113
|
put(iThesis, "school");
|
114
|
|
115
|
iReport = merge(iPublicationBase);
|
116
|
put(iReport, "institution");
|
117
|
|
118
|
iPersonalCommunication = merge(iReference, iWithAuthorAndDate);
|
119
|
|
120
|
all = merge(iThesis, iPrintSeries, iInProceedings, iJournal, iArticle, iBook, iBookSection, iProceedings, iPrintedUnitBase, iVolumeReference, iReport);
|
121
|
}
|
122
|
|
123
|
/**
|
124
|
*
|
125
|
* @param type
|
126
|
* @return a map (Reference.fieldName -> propertyName) with the Reference class field name as key and the property name as
|
127
|
* defined in the most significant interface as value. The propertyName can be used as label in the UI
|
128
|
*
|
129
|
* @throws UnimplemetedCaseException
|
130
|
*/
|
131
|
public static Map<String, String> fieldPropertyDefinition(ReferenceType type) throws UnimplemetedCaseException{
|
132
|
|
133
|
if(type == null){
|
134
|
return all;
|
135
|
}
|
136
|
switch (type){
|
137
|
case Article:
|
138
|
return iArticle;
|
139
|
case Book:
|
140
|
return iBook;
|
141
|
case BookSection:
|
142
|
return iBookSection;
|
143
|
case CdDvd:
|
144
|
return all;
|
145
|
case Database:
|
146
|
return all;
|
147
|
case Generic:
|
148
|
return all;
|
149
|
case InProceedings:
|
150
|
return iInProceedings;
|
151
|
case Journal:
|
152
|
return iJournal;
|
153
|
case Map:
|
154
|
return all;
|
155
|
case Patent:
|
156
|
return all;
|
157
|
case PersonalCommunication:
|
158
|
return iPersonalCommunication;
|
159
|
case PrintSeries:
|
160
|
return iPublicationBase;
|
161
|
case Proceedings:
|
162
|
return iProceedings;
|
163
|
case Report:
|
164
|
return all;
|
165
|
case Section:
|
166
|
return iSection;
|
167
|
case Thesis:
|
168
|
return iThesis;
|
169
|
case WebPage:
|
170
|
return all;
|
171
|
default:
|
172
|
return all;
|
173
|
}
|
174
|
|
175
|
}
|
176
|
|
177
|
@SafeVarargs
|
178
|
private static Map<String, String> merge(Map<String, String> ... maps) {
|
179
|
|
180
|
Map<String, String> fieldPropertyMap = new HashMap<>();
|
181
|
|
182
|
for(Map<String, String> m : maps){
|
183
|
fieldPropertyMap.putAll(m);
|
184
|
}
|
185
|
|
186
|
return fieldPropertyMap;
|
187
|
}
|
188
|
|
189
|
|
190
|
private static void put(Map<String, String> fieldPropertyMap, String fieldName, String propertyName) {
|
191
|
fieldPropertyMap.put(fieldName, propertyName);
|
192
|
}
|
193
|
|
194
|
private static void remove(Map<String, String> fieldPropertyMap, String fieldName) {
|
195
|
fieldPropertyMap.remove(fieldName);
|
196
|
}
|
197
|
|
198
|
|
199
|
private static void put(Map<String, String> fieldPropertyMap, String fieldName) {
|
200
|
put(fieldPropertyMap, fieldName, fieldName);
|
201
|
}
|
202
|
|
203
|
public static class UnimplemetedCaseException extends Exception{
|
204
|
|
205
|
private static final long serialVersionUID = 1L;
|
206
|
|
207
|
public UnimplemetedCaseException(ReferenceType type){
|
208
|
super("No implementation for ReferenceType " + type.name());
|
209
|
}
|
210
|
}
|
211
|
|
212
|
|
213
|
}
|