Project

General

Profile

Download (6.06 KB) Statistics
| Branch: | Tag: | Revision:
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 contains 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. Creating and applying annotations
19
 * to refer to the actual field names could help in this case.
20
 * <p>
21
 *
22
 * @author a.kohlbecker
23
 * @since Jun 15, 2018
24
 *
25
 */
26
public class ReferencePropertyDefinitions {
27

    
28
    private static Map<String, String> iPublicationBase = new HashMap<>();
29
    private static Map<String, String> iReference = new HashMap<>();
30
    private static Map<String, String> iVolumeReference = new HashMap<>();
31
    private static Map<String, String> iSection = new HashMap<>();
32
    private static Map<String, String> iPrintedUnitBase = new HashMap<>();
33
    private static Map<String, String> iArticle = new HashMap<>();
34
    private static Map<String, String> iBook = new HashMap<>();
35
    private static Map<String, String> iBookSection = new HashMap<>();
36
    private static Map<String, String> iInProceedings = new HashMap<>();
37
    private static Map<String, String> iProceedings = new HashMap<>();
38
    private static Map<String, String> iJournal = new HashMap<>();
39
    private static Map<String, String> iPrintSeries = new HashMap<>();
40
    private static Map<String, String> iThesis = new HashMap<>();
41
    private static Map<String, String> all = new HashMap<>();
42

    
43
    static {
44

    
45
        Map<String, String> map;
46

    
47
        map = iReference;
48
        put(map, "uri");
49
        put(map, "datePublished");
50
        put(map, "abbrevTitle");
51
        put(map, "title");
52
        put(map, "authorship");
53
        put(map, "type");
54

    
55
        iPublicationBase = merge(iReference);
56
        map = iPublicationBase;
57
        put(map, "publisher");
58
        put(map, "placePublished");
59
        put(map, "doi");
60

    
61
        iSection = merge(iReference);
62
        map = iSection;
63
        put(map, "pages");
64
        put(map, "inReference");
65

    
66
        iVolumeReference = merge(iReference);
67
        map = iVolumeReference;
68
        put(map, "volume");
69

    
70
        iPrintedUnitBase = merge(iPublicationBase, iSection, iVolumeReference);
71
        map = iPrintedUnitBase;
72
        put(map, "inReference", "inSeries");
73
        put(map, "editor");
74
        put(map, "seriesPart");
75

    
76
        iArticle = merge(iSection, iVolumeReference);
77
        map = iArticle;
78
        put(map, "seriesPart");
79
        put(map, "inReference", "inJournal");
80

    
81
        iBook = merge(iPrintedUnitBase);
82
        map = iBook;
83
        put(map, "edition");
84
        put(map, "isbn");
85

    
86
        iBookSection = merge(iSection);
87
        map = iBookSection;
88
        put(map, "inReference", "inBook");
89

    
90
        iProceedings = merge(iPrintedUnitBase);
91
        map = iProceedings;
92
        put(map, "organization");
93

    
94
        iJournal = merge(iPublicationBase);
95
        map = iJournal;
96
        put(map, "issn");
97

    
98
        iInProceedings = merge(iSection);
99
        map = iInProceedings;
100
        put(map, "seriesPart");
101
        put(map, "inReference", "inJournal");
102
        put(map, "doi");
103

    
104
        iPrintSeries = merge(iPublicationBase);
105
        map = iPrintSeries;
106
        put(map, "publisher");
107
        put(map, "placePublished");
108
        put(map, "doi");
109

    
110
        iThesis = merge(iPublicationBase);
111
        map = iThesis;
112
        put(map, "school");
113

    
114
        all = merge(iThesis, iPrintSeries, iInProceedings, iJournal, iArticle, iBook, iBookSection, iProceedings, iPrintedUnitBase, iVolumeReference);
115

    
116
    }
117

    
118
    /**
119
     *
120
     * @param type
121
     * @return a map (Reference.fieldName -> propertyName) with the Reference class field name as key and the property name as
122
     * defined in the most significant interface as value. The propertyName can be used as label in the UI
123
     *
124
     * @throws UnimplemetedCaseException
125
     */
126
    public static Map<String, String> fieldPropertyDefinition(ReferenceType type) throws UnimplemetedCaseException{
127

    
128
        if(type == null){
129
            return all;
130
        }
131
        switch (type){
132
        case Article:
133
            return iArticle;
134
        case Book:
135
            return iBook;
136
        case BookSection:
137
            return iBookSection;
138
        case CdDvd:
139
            return all;
140
        case Database:
141
            return all;
142
        case Generic:
143
            return all;
144
        case InProceedings:
145
            return iInProceedings;
146
        case Journal:
147
            return iJournal;
148
        case Map:
149
            return all;
150
        case Patent:
151
            return all;
152
        case PersonalCommunication:
153
            return all;
154
        case PrintSeries:
155
            return iPublicationBase;
156
        case Proceedings:
157
            return iProceedings;
158
        case Report:
159
            return all;
160
        case Section:
161
            return iSection;
162
        case Thesis:
163
            return iThesis;
164
        case WebPage:
165
            return all;
166
        default:
167
            return all;
168
        }
169

    
170
    }
171

    
172

    
173
    @SafeVarargs
174
    private static Map<String, String> merge(Map<String, String> ... maps) {
175

    
176
        Map<String, String> fieldPropertyMap = new HashMap<>();
177

    
178
        for(Map<String, String> m : maps){
179
            fieldPropertyMap.putAll(m);
180
        }
181

    
182
        return fieldPropertyMap;
183
    }
184

    
185

    
186
    private static void put(Map<String, String> fieldPropertyMap, String fieldName, String propertyName) {
187
        fieldPropertyMap.put(fieldName, propertyName);
188

    
189
    }
190

    
191

    
192
   private static void put(Map<String, String> fieldPropertyMap, String fieldName) {
193
       put(fieldPropertyMap, fieldName, fieldName);
194

    
195
   }
196

    
197
   public static class UnimplemetedCaseException extends Exception{
198

    
199

    
200
        private static final long serialVersionUID = 1L;
201

    
202
        public UnimplemetedCaseException(ReferenceType type){
203
            super("No implementation for ReferenceType " + type.name());
204
        }
205
   }
206

    
207

    
208
}
(26-26/29)