Project

General

Profile

« Previous | Next » 

Revision d1b51913

Added by Patrick Plitzner over 9 years ago

  • adapted method calls to cdmlib changes

View differences:

eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/parser/ParseHandler.java
1 1
/**
2
 * 
2
 *
3 3
 */
4 4
package eu.etaxonomy.taxeditor.parser;
5 5

  
......
29 29
public class ParseHandler{
30 30

  
31 31
	private TaxonNameBase taxonNameBase;
32
	
32

  
33 33
	private class MatchMatrix {
34 34
		List<TaxonNameBase> duplicateNames = new ArrayList<TaxonNameBase>();
35
		
35

  
36 36
		List<INomenclaturalReference> duplicateReferences = new ArrayList<INomenclaturalReference>();
37 37
		List<INomenclaturalReference> duplicateInReferences = new ArrayList<INomenclaturalReference>();
38 38

  
......
50 50
	private NonViralName name;
51 51

  
52 52
	private boolean doResolveInReferences;
53
	
53

  
54 54
	/**
55
	 * Creates a new instance 
56
	 * 
55
	 * Creates a new instance
56
	 *
57 57
	 * @param textWidget
58 58
	 * @param name
59 59
	 */
......
64 64
			this.name = (NonViralName) HibernateProxyHelper.deproxy(name);
65 65
		}
66 66
	}
67
	
67

  
68 68
	/**
69 69
	 * Factory method to create a new instance of the this class
70 70
	 *
......
74 74
	 */
75 75
	public static ParseHandler NewInstance(TaxonNameBase name){
76 76
		return new ParseHandler(name);
77
		
77

  
78 78
	}
79
	
79

  
80 80
	/**
81 81
	 * Parses a given string and returns a <code>TaxonNameBase</code> instance with the
82 82
	 * results of the parsing.
......
95 95
//		if (name.hasProblem()) {
96 96
//			name.setFullTitleCache(unparsedNameString);
97 97
//		}
98
		
98

  
99 99
		return name;
100 100
	}
101
	
101

  
102 102
	public static TaxonNameBase parseName(String unparsedNameString, Rank rank){
103 103
		TaxonNameBase name = nonViralNameParser.parseFullName(unparsedNameString,
104 104
				PreferencesUtil.getPreferredNomenclaturalCode(), rank);
105
		
105

  
106 106
		return name;
107 107
	}
108
	
108

  
109 109
	/**
110 110
	 * Creates an empty <code>TaxonNameBase</code> instance with the nomenclatural code
111 111
	 * currently set in preferences.
......
115 115
	public static TaxonNameBase createEmptyName(){
116 116
		return nonViralNameParser.getNonViralNameInstance("", PreferencesUtil.getPreferredNomenclaturalCode());
117 117
	}
118
	
118

  
119 119
	/**
120 120
	 * Parses the string that was entered into the text widget and returns a
121 121
	 * NonViralName object that resulted from the parsing process.
......
123 123
	 * @return	The parsed NonViralName object
124 124
	 */
125 125
	public NonViralName parse(String unparsedNameString){
126
		
126

  
127 127
//		String unparsedNameString = "";
128 128
//		try {
129 129
//			Method getText;
......
133 133
//			// we should never get here
134 134
//			StoreUtil.error(this.getClass(), "Error trying to invoke getText method", e);
135 135
//		}
136
		
137
		
136

  
137

  
138 138
		nonViralNameParser.parseReferencedName(name, unparsedNameString,
139 139
				name.getRank(), true);
140 140

  
141 141
//		if (name.hasProblem()) {
142 142
//			name.setFullTitleCache(unparsedNameString);
143 143
//		}
144
		
144

  
145 145
		return name;
146 146
	}
147
	
147

  
148 148
	/**
149 149
	 * Parses the string that was entered into the text widget and returns a
150 150
	 * NonViralName object that resulted from the parsing process.
......
157 157
	 * @return	The parsed NonViralName object
158 158
	 */
159 159
	public NonViralName parseAndResolveDuplicates(String unparsedNameString){
160
		
160

  
161 161
		NonViralName parsedName = parse(unparsedNameString);
162
		
162

  
163 163
		MatchMatrix matchMatrix = findMatches(parsedName);
164
		
164

  
165 165
		resolveDuplicates(parsedName, matchMatrix);
166
		
166

  
167 167
		return parsedName;
168 168
	}
169
		
170
	
171
	
172
	
173
	/** 
169

  
170

  
171

  
172

  
173
	/**
174 174
	 * @param name The name to resolve duplicates for.
175 175
	 */
176 176
	private void resolveDuplicates(NonViralName name, MatchMatrix matchMatrix) {
177 177
		resolveDuplicateNames(name, matchMatrix);
178
		
178

  
179 179
		resolveAllDuplicateAuthors(name, matchMatrix);
180
		
180

  
181 181
		resolveDuplicateReferences(name, matchMatrix);
182
		
183
		if(matchMatrix.duplicateInReferences != null)
184
			resolveDuplicateInReferences(name, matchMatrix);
182

  
183
		if(matchMatrix.duplicateInReferences != null) {
184
            resolveDuplicateInReferences(name, matchMatrix);
185
        }
185 186
	}
186 187

  
187 188

  
188
	/** 
189
	/**
189 190
	 * @param name The name to resolve duplicates for.
190 191
	 */
191 192
	private void resolveDuplicateNames(NonViralName name, MatchMatrix matchMatrix) {
192
				
193

  
193 194
		if (matchMatrix.duplicateNames.size() == 1){
194 195
			name = (NonViralName) matchMatrix.duplicateNames.iterator().next();
195 196
		}else if(matchMatrix.duplicateNames.size() > 1){
......
198 199
		}
199 200
	}
200 201

  
201
	/** 
202
	/**
202 203
	 * @param name The name to resolve duplicates for.
203 204
	 */
204 205
	private void resolveDuplicateReferences(NonViralName name, MatchMatrix matchMatrix) {
205 206
		if(matchMatrix.duplicateReferences.size() == 1){
206 207
			// exactly one match. We assume that the user wants this reference
207
			INomenclaturalReference duplicate = matchMatrix.duplicateReferences.iterator().next();	
208
			INomenclaturalReference duplicate = matchMatrix.duplicateReferences.iterator().next();
208 209
			name.setNomenclaturalReference(duplicate);
209 210
		}else if(matchMatrix.duplicateReferences.size() > 1){
210 211
			// FIXME TODO resolve multiple duplications. Use first match for a start
211 212
			INomenclaturalReference duplicate = matchMatrix.duplicateReferences.iterator().next();
212 213
			name.setNomenclaturalReference(duplicate);
213
		}		
214
		}
214 215
	}
215 216

  
216
	/** 
217
	/**
217 218
	 * @param name The name to resolve duplicates for.
218 219
	 */
219 220
	private void resolveDuplicateInReferences(NonViralName name, MatchMatrix matchMatrix) {
220 221
		Reference reference = (Reference) HibernateProxyHelper.deproxy(name.getNomenclaturalReference());
221
		
222

  
222 223
		if(matchMatrix.duplicateInReferences.size() > 0){
223 224
			Reference inReference = (Reference) matchMatrix.duplicateInReferences.iterator().next();
224 225
			reference.setInReference(inReference);
......
227 228
			MessagingUtils.warn(this.getClass(), reference.getTitleCache());
228 229
		}
229 230
	}
230
	
231 231

  
232
	/** 
232

  
233
	/**
233 234
	 * @param name The name to resolve duplicates for.
234 235
	 */
235 236
	private void resolveAllDuplicateAuthors(NonViralName name, MatchMatrix matchMatrix) {
236
		
237

  
237 238
		if(matchMatrix.duplicateCombinationAuthorTeams.size() > 0){
238 239
			name.setCombinationAuthorTeam(matchMatrix.duplicateCombinationAuthorTeams.iterator().next());
239 240
			Reference reference = (Reference) name.getNomenclaturalReference();
240 241
			if(reference != null){
241
				reference.setAuthorTeam(matchMatrix.duplicateCombinationAuthorTeams.iterator().next());
242
				reference.setAuthorship(matchMatrix.duplicateCombinationAuthorTeams.iterator().next());
242 243
			}
243 244
			// FIXME TODO resolve multiple duplications. We use first match for a start.
244 245
		}
245
		
246

  
246 247
		if(matchMatrix.duplicateExCombinationAuthorTeams.size() > 0){
247 248
			name.setExCombinationAuthorTeam(matchMatrix.duplicateExCombinationAuthorTeams.iterator().next());
248 249
			// FIXME TODO resolve multiple duplications. We use first match for a start.
249 250
		}
250
		
251

  
251 252
		if(matchMatrix.duplicateBasionymAuthorTeams.size() > 0){
252 253
			name.setBasionymAuthorTeam(matchMatrix.duplicateBasionymAuthorTeams.iterator().next());
253 254
			// FIXME TODO resolve multiple duplications. We use first match for a start.
254 255
		}
255
		
256

  
256 257
		if(matchMatrix.duplicateExBasionymAuthorTeams.size() > 0){
257 258
			name.setExBasionymAuthorTeam(matchMatrix.duplicateExBasionymAuthorTeams.iterator().next());
258 259
			// FIXME TODO resolve multiple duplications. We use first match for a start.
259 260
		}
260 261
	}
261
	
262
	/** 
262

  
263
	/**
263 264
	 * Splits a NonViralName into its parts and calls methods to find matches for these
264 265
	 * parts in the database.
265
	 * 
266
	 *
266 267
	 * @param name	The NonViralName to find matches for.
267 268
	 */
268 269
	private MatchMatrix findMatches(NonViralName name){
269
		
270

  
270 271
		MatchMatrix matchMatrix = new MatchMatrix();
271
		
272

  
272 273
		matchMatrix.duplicateNames = findMatchingLatinNames(name);
273
		
274
		matchMatrix.duplicateCombinationAuthorTeams = findMatchingAuthors((TeamOrPersonBase) name.getCombinationAuthorTeam());
275
		matchMatrix.duplicateExCombinationAuthorTeams = findMatchingAuthors((TeamOrPersonBase) name.getExCombinationAuthorTeam());
276
		matchMatrix.duplicateBasionymAuthorTeams = findMatchingAuthors((TeamOrPersonBase) name.getBasionymAuthorTeam());
277
		matchMatrix.duplicateExBasionymAuthorTeams = findMatchingAuthors((TeamOrPersonBase) name.getExBasionymAuthorTeam());
278
		
274

  
275
		matchMatrix.duplicateCombinationAuthorTeams = findMatchingAuthors(name.getCombinationAuthorTeam());
276
		matchMatrix.duplicateExCombinationAuthorTeams = findMatchingAuthors(name.getExCombinationAuthorTeam());
277
		matchMatrix.duplicateBasionymAuthorTeams = findMatchingAuthors(name.getBasionymAuthorTeam());
278
		matchMatrix.duplicateExBasionymAuthorTeams = findMatchingAuthors(name.getExBasionymAuthorTeam());
279

  
279 280
		INomenclaturalReference nomenclaturalReference = name.getNomenclaturalReference();
280
		
281
		// check if the reference has an inreference and also check if the inReference already exists 
281

  
282
		// check if the reference has an inreference and also check if the inReference already exists
282 283
		if(nomenclaturalReference != null){
283 284
			Reference inReference = ((Reference)nomenclaturalReference).getInReference();
284 285
			if(inReference != null){
......
286 287
				matchMatrix.duplicateInReferences = findMatchingNomenclaturalReference(inReference);
287 288
			}
288 289
		}
289
		
290

  
290 291
		matchMatrix.duplicateReferences = findMatchingNomenclaturalReference(nomenclaturalReference);
291
		
292

  
292 293
		return matchMatrix;
293 294
	}
294
	
295

  
295 296
	/**
296 297
	 * @param nomenclaturalReference	The NomenclaturalReference to find matches for.
297 298
	 * @return	A <code>List</code> of possibly matching NomenclaturalReference's.
298 299
	 */
299 300
	private List<INomenclaturalReference> findMatchingNomenclaturalReference(INomenclaturalReference nomenclaturalReference) {
300
		if(nomenclaturalReference == null) return new ArrayList<INomenclaturalReference>();
301
		if(nomenclaturalReference == null) {
302
            return new ArrayList<INomenclaturalReference>();
303
        }
301 304
		try{
302 305
			return CdmStore.getService(ICommonService.class).findMatching(nomenclaturalReference, MatchStrategyConfigurator.ReferenceMatchStrategy());
303 306
		}catch (MatchException e) {
......
315 318
		if(authorTeam == null){
316 319
			return new ArrayList<TeamOrPersonBase>();
317 320
		}
318
		
321

  
319 322
		try{
320 323
			return CdmStore.getService(ICommonService.class).findMatching(authorTeam, MatchStrategyConfigurator.TeamOrPersonMatchStrategy());
321 324
		}catch (MatchException e) {
......
332 335

  
333 336
		try {
334 337
			return CdmStore.getService(ICommonService.class).findMatching(taxonNameBase, MatchStrategyConfigurator.NonViralNameMatchStrategy());
335
			
338

  
336 339
		} catch (MatchException e) {
337 340
			MessagingUtils.error(this.getClass(), "Error finding matching names", e);
338 341
		}
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/dialog/selection/ReferenceSelectionDialog.java
84 84
	protected String getTitle(Reference cdmObject) {
85 85
		if(cdmObject == null){
86 86
			return "";
87
		}else if(cdmObject.getAuthorTeam() == null){
87
		}else if(cdmObject.getAuthorship() == null){
88 88
			return super.getTitle(cdmObject);
89 89
		}else{
90
			return ReferenceDefaultCacheStrategy.putAuthorToEndOfString(cdmObject.getTitleCache(), cdmObject.getAuthorTeam().getTitleCache());
90
			return ReferenceDefaultCacheStrategy.putAuthorToEndOfString(cdmObject.getTitleCache(), cdmObject.getAuthorship().getTitleCache());
91 91
		}
92 92
	}
93 93

  
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/openurl/OpenUrlSelectorWizard.java
1 1
// $Id$
2 2
/**
3 3
* Copyright (C) 2007 EDIT
4
* European Distributed Institute of Taxonomy 
4
* European Distributed Institute of Taxonomy
5 5
* http://www.e-taxonomy.eu
6
* 
6
*
7 7
* The contents of this file are subject to the Mozilla Public License Version 1.1
8 8
* See LICENSE.TXT at the top of this package for the full license terms.
9 9
*/
......
31 31
 * @version 1.0
32 32
 */
33 33
public class OpenUrlSelectorWizard extends Wizard {
34
	
35
	private MobotOpenUrlServiceWrapper openUrlServiceWrapper;
36 34

  
37
	private MobotOpenUrlQuery query;
38
	
35
	private final MobotOpenUrlServiceWrapper openUrlServiceWrapper;
36

  
37
	private final MobotOpenUrlQuery query;
38

  
39 39
	private OpenUrlReference openUrlReference;
40
	
41
	private CdmFormFactory formFactory;
40

  
41
	private final CdmFormFactory formFactory;
42 42

  
43 43
	private URI openUrlReferenceImageUri;
44
	
45
	private Reference reference;
46
	
47
	private String referenceDetail;
48
	
49
	
50
	
44

  
45
	private final Reference reference;
46

  
47
	private final String referenceDetail;
48

  
49

  
50

  
51 51
	/**
52
	 * @param openUrlSelectorElement 
52
	 * @param openUrlSelectorElement
53 53
	 * @param reference
54 54
	 */
55 55
	public OpenUrlSelectorWizard(Reference reference, String referenceDetail) {
56 56
		if(reference == null){
57 57
			throw new IllegalArgumentException("Reference may not be empty");
58 58
		}
59
		
59

  
60 60
		this.reference = reference;
61 61
		this.referenceDetail = referenceDetail;
62
		
62

  
63 63
		setWindowTitle("Mobot Open Url");
64 64
		setNeedsProgressMonitor(true);
65
		
65

  
66 66
		formFactory = new CdmFormFactory(Display.getDefault());
67
		
67

  
68 68
		openUrlServiceWrapper = new MobotOpenUrlServiceWrapper();
69 69
		openUrlServiceWrapper.setBaseUrl(PreferencesUtil.getPreferenceStore().getString(IPreferenceKeys.OPENURL_ACCESS_POINT));
70
		
70

  
71 71
		query  = new MobotOpenUrlQuery();
72
		
72

  
73 73
		query.refType = ReferenceType.getReferenceType(reference);
74
		if(reference.getAuthorTeam() != null){
75
			query.authorName = reference.getAuthorTeam().getTitleCache();
74
		if(reference.getAuthorship() != null){
75
			query.authorName = reference.getAuthorship().getTitleCache();
76 76
		}
77 77
		query.abbreviation = reference.getTitle();
78 78
		if(reference.getInReference() != null){
......
86 86
		query.publicationPlace = reference.getPlacePublished();
87 87
		query.publisherName = reference.getPublisher();
88 88
		query.volume = reference.getVolume();
89
		
89

  
90 90
		query.startPage = referenceDetail;
91 91
	}
92
	
92

  
93 93
	/* (non-Javadoc)
94 94
	 * @see org.eclipse.jface.wizard.Wizard#addPages()
95 95
	 */
96 96
	@Override
97 97
	public void addPages() {
98
		
98

  
99 99
		addPage(new OpenUrlResultPage());
100 100
		addPage(new OpenUrlReferencePage());
101
		
101

  
102 102
		super.addPages();
103 103
	}
104 104

  
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/section/reference/ReferenceDetailElement.java
129 129
		selection_authorTeam = formFactory
130 130
				.createSelectionElement(AgentBase.class,
131 131
						getConversationHolder(), formElement, "Author",
132
						AuthorHelper.getAuthor(entity.getAuthorTeam()),
132
						AuthorHelper.getAuthor(entity.getAuthorship()),
133 133
						EntitySelectionElement.ALL, style);
134 134

  
135 135
		ReferenceType referenceType = entity.getType();
......
398 398
		}
399 399
		// selections
400 400
		else if (eventSource == selection_authorTeam) {
401
			getEntity().setAuthorTeam(
401
			getEntity().setAuthorship(
402 402
					(TeamOrPersonBase) selection_authorTeam.getSelection());
403 403
		} else if (eventSource == selection_inReference) {
404 404
			getEntity().setInReference(selection_inReference.getSelection());

Also available in: Unified diff