Project

General

Profile

Revision 892ffbab

ID892ffbabbc4d342b70e3acdee683d2a7f263d15d
Parent 813218dc
Child aed97685

Added by Andreas Kohlbecker about 2 years ago

ref #/7223 ReferencePropertyDefinitions provides field and property name information per reference type

View differences:

cdmlib-model/src/main/java/eu/etaxonomy/cdm/model/reference/ReferencePropertyDefinitions.java
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> iJournal = new HashMap<>();
38
    private static Map<String, String> iPrintSeries = new HashMap<>();
39
    private static Map<String, String> iThesis = new HashMap<>();
40

  
41
    static {
42

  
43
        Map<String, String> map;
44

  
45
        map = iReference;
46
        put(map, "URI");
47
        put(map, "datePublished");
48
        put(map, "abbrevTitle");
49
        put(map, "title");
50
        put(map, "authorship");
51
        put(map, "type");
52

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

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

  
64
        iVolumeReference = merge(iReference);
65
        map = iVolumeReference;
66
        put(map, "volume");
67

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

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

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

  
84
        iBookSection = merge(iSection);
85
        map = iBookSection;
86
        put(map, "inReference", "inBook");
87

  
88
        iInProceedings = merge(iSection);
89
        map = iInProceedings;
90
        put(map, "seriesPart");
91
        put(map, "inReference", "inJournal");
92
        put(map, "doi");
93

  
94
        iPrintSeries = merge(iPublicationBase);
95
        map = iPrintSeries;
96
        put(map, "publisher");
97
        put(map, "placePublished");
98
        put(map, "doi");
99

  
100
        iThesis = merge(iPublicationBase);
101
        map = iThesis;
102
        put(map, "school");
103

  
104

  
105
    }
106

  
107
    public static Map<String, String> fieldPropertyDefinition(ReferenceType type) throws UnimplemetedCaseException{
108

  
109

  
110

  
111
        switch (type){
112
        case Article:
113
            return merge(iSection, iVolumeReference, iArticle);
114
        case Book:
115
            return merge(iPrintedUnitBase, iBook);
116
        case BookSection:
117
            return merge(iSection, iBookSection);
118
        case CdDvd:
119
            throw new UnimplemetedCaseException(type);
120
        case Database:
121
            throw new UnimplemetedCaseException(type);
122
        case Generic:
123
            throw new UnimplemetedCaseException(type);
124
        case InProceedings:
125
            return merge(iSection, iInProceedings);
126
        case Journal:
127
            return merge(iPublicationBase, iJournal);
128
        case Map:
129
            throw new UnimplemetedCaseException(type);
130
        case Patent:
131
            throw new UnimplemetedCaseException(type);
132
        case PersonalCommunication:
133
            throw new UnimplemetedCaseException(type);
134
        case PrintSeries:
135
            return iPublicationBase;
136
        case Proceedings:
137
            throw new UnimplemetedCaseException(type);
138
        case Report:
139
            throw new UnimplemetedCaseException(type);
140
        case Section:
141
            return iSection;
142
        case Thesis:
143
            return merge(iPublicationBase, iThesis);
144
        case WebPage:
145
            throw new UnimplemetedCaseException(type);
146
        default:
147
            throw new UnimplemetedCaseException(type);
148
        }
149

  
150
    }
151

  
152

  
153
    @SafeVarargs
154
    private static Map<String, String> merge(Map<String, String> ... maps) {
155

  
156
        Map<String, String> fieldPropertyMap = new HashMap<>();
157

  
158
        for(Map<String, String> m : maps){
159
            fieldPropertyMap.putAll(m);
160
        }
161

  
162
        return fieldPropertyMap;
163
    }
164

  
165

  
166
    private static void put(Map<String, String> fieldPropertyMap, String fieldName, String propertyName) {
167
        fieldPropertyMap.put(fieldName, propertyName);
168

  
169
    }
170

  
171

  
172
   private static void put(Map<String, String> fieldPropertyMap, String fieldName) {
173
       put(fieldPropertyMap, fieldName, fieldName);
174

  
175
   }
176

  
177
   public static class UnimplemetedCaseException extends Exception{
178

  
179

  
180
        private static final long serialVersionUID = 1L;
181

  
182
        public UnimplemetedCaseException(ReferenceType type){
183
            super("No implementation for ReferenceType " + type.name());
184
        }
185
   }
186

  
187

  
188
}

Also available in: Unified diff

Add picture from clipboard (Maximum size: 40 MB)