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.strategy.match;
|
10
|
|
11
|
import eu.etaxonomy.cdm.model.common.CdmBase;
|
12
|
import eu.etaxonomy.cdm.model.reference.Reference;
|
13
|
import eu.etaxonomy.cdm.model.reference.ReferenceType;
|
14
|
|
15
|
/**
|
16
|
* @author a.mueller
|
17
|
* @since 20.10.2018
|
18
|
*
|
19
|
*/
|
20
|
public class ParsedReferenceMatchStrategy implements IParsedMatchStrategy{
|
21
|
|
22
|
private static ParsedReferenceMatchStrategy instance;
|
23
|
|
24
|
/**
|
25
|
* Immutable singleton instance.
|
26
|
* @return
|
27
|
*/
|
28
|
public static ParsedReferenceMatchStrategy INSTANCE(){
|
29
|
if (instance == null){
|
30
|
instance = new ParsedReferenceMatchStrategy();
|
31
|
}
|
32
|
return instance;
|
33
|
}
|
34
|
|
35
|
/**
|
36
|
* {@inheritDoc}
|
37
|
*/
|
38
|
@Override
|
39
|
public void setMatchMode(String propertyName, MatchMode matchMode) throws MatchException {
|
40
|
setMatchMode(propertyName, matchMode, null);
|
41
|
}
|
42
|
|
43
|
/**
|
44
|
* {@inheritDoc}
|
45
|
*/
|
46
|
@Override
|
47
|
public void setMatchMode(String propertyName, MatchMode matchMode, IMatchStrategy matchStrategy)
|
48
|
throws MatchException {
|
49
|
throw new MatchException("ParsedReferenceMatchStrategy is immutable");
|
50
|
}
|
51
|
|
52
|
/**
|
53
|
* {@inheritDoc}
|
54
|
*/
|
55
|
@Override
|
56
|
public Matching getMatching() {
|
57
|
//why does it not throw MatchException?
|
58
|
throw new RuntimeException("getMatching not yet implemented");
|
59
|
}
|
60
|
|
61
|
private IParsedMatchStrategy articleStrategy = MatchStrategyFactory.NewParsedArticleInstance();
|
62
|
private IParsedMatchStrategy bookStrategy = MatchStrategyFactory.NewParsedBookInstance();
|
63
|
private IParsedMatchStrategy bookSectionStrategy = MatchStrategyFactory.NewParsedBookSectionInstance();
|
64
|
private IParsedMatchStrategy journalStrategy = MatchStrategyFactory.NewParsedJournalInstance();
|
65
|
//TODO no generic reference yet
|
66
|
private IMatchStrategy genericStrategy = MatchStrategyFactory.NewDefaultInstance(Reference.class);
|
67
|
|
68
|
/**
|
69
|
* {@inheritDoc}
|
70
|
*/
|
71
|
@Override
|
72
|
public <T extends IMatchable> MatchResult invoke(T fullInstance, T parsedInstance) throws MatchException {
|
73
|
return invoke(fullInstance, parsedInstance, false);
|
74
|
}
|
75
|
|
76
|
@Override
|
77
|
public <T extends IMatchable> MatchResult invoke(T fullInstance, T parsedInstance, boolean failAll)
|
78
|
throws MatchException {
|
79
|
MatchResult matchResult = new MatchResult();
|
80
|
invoke(fullInstance, parsedInstance, matchResult, false);
|
81
|
return matchResult;
|
82
|
}
|
83
|
|
84
|
|
85
|
/**
|
86
|
* {@inheritDoc}
|
87
|
*/
|
88
|
@Override
|
89
|
public <T extends IMatchable> void invoke(T fullInstance, T parsedInstance, MatchResult matchResult,
|
90
|
boolean failAll)
|
91
|
throws MatchException {
|
92
|
if (!fullInstance.isInstanceOf(Reference.class) || !parsedInstance.isInstanceOf(Reference.class)){
|
93
|
throw new MatchException("ParsedReferenceMatchStrategy only supports type Reference");
|
94
|
}
|
95
|
Reference fullRef = CdmBase.deproxy(fullInstance, Reference.class);
|
96
|
Reference parsedRef = CdmBase.deproxy(parsedInstance, Reference.class);
|
97
|
if (fullRef == null || parsedRef == null){
|
98
|
matchResult.addNullMatching(fullRef, parsedRef);
|
99
|
return;
|
100
|
}else if (!fullRef.getType().equals(parsedRef.getType())){
|
101
|
matchResult.addNoTypeMatching(fullRef.getType(), parsedRef.getType());
|
102
|
return;
|
103
|
}else{
|
104
|
ReferenceType type = fullRef.getType();
|
105
|
if (type.equals(ReferenceType.Article)){
|
106
|
articleStrategy.invoke(fullRef, parsedRef, matchResult, failAll);
|
107
|
}else if (type.equals(ReferenceType.Book)){
|
108
|
bookStrategy.invoke(fullRef, parsedRef, matchResult, failAll);
|
109
|
}else if (type.equals(ReferenceType.Book)){
|
110
|
bookSectionStrategy.invoke(fullRef, parsedRef, matchResult, failAll);
|
111
|
}else if (type.equals(ReferenceType.Journal)){
|
112
|
journalStrategy.invoke(fullRef, parsedRef, matchResult, failAll);
|
113
|
}else if (type.equals(ReferenceType.Generic)){
|
114
|
//TODO
|
115
|
genericStrategy.invoke(fullRef, parsedRef, matchResult, failAll);
|
116
|
}else{
|
117
|
//TODO
|
118
|
genericStrategy.invoke(fullRef, parsedRef, matchResult, failAll);
|
119
|
}
|
120
|
return;
|
121
|
}
|
122
|
|
123
|
}
|
124
|
|
125
|
}
|