Project

General

Profile

« Previous | Next » 

Revision b7317c6c

Added by Andreas Müller almost 6 years ago

cleanup

View differences:

cdmlib-model/src/main/java/eu/etaxonomy/cdm/model/common/TimePeriod.java
467 467
        }
468 468
    }
469 469

  
470
    private void initStart(){
471
        if (start == null){
472
            start = new Partial();
473
        }
474
    }
475

  
476
    private void initEnd(){
477
        if (end == null){
478
            end = new Partial();
479
        }
480
    }
481

  
482 470

  
483 471
//**************************** to String ****************************************
484 472

  
......
491 479
    @Override
492 480
    public String toString(){
493 481
        String result = null;
494
        DateTimeFormatter formatter = TimePeriodPartialFormatter.NewInstance();
482
//        DateTimeFormatter formatter = TimePeriodPartialFormatter.NewInstance();
495 483
        if ( StringUtils.isNotBlank(this.getFreeText())){
496 484
            result = this.getFreeText();
497 485
        }else{
498

  
499 486
            result = getTimePeriod();
500 487
        }
501 488
        return result;
......
518 505

  
519 506
//*********** EQUALS **********************************/
520 507

  
521

  
522
    /* (non-Javadoc)
523
     * @see java.lang.Object#equals(java.lang.Object)
524
     */
525 508
    @Override
526 509
    public boolean equals(Object obj) {
527 510
        if (obj == null){
......
544 527
        return true;
545 528
    }
546 529

  
547
    /* (non-Javadoc)
548
     * @see java.lang.Object#hashCode()
549
     */
550 530
    @Override
551 531
    public int hashCode() {
552 532
        int hashCode = 7;
......
560 540

  
561 541
//*********** CLONE **********************************/
562 542

  
563

  
564
    /* (non-Javadoc)
565
     * @see java.lang.Object#clone()
566
     */
567 543
    @Override
568 544
    public Object clone()  {
569 545
        try {
cdmlib-model/src/test/java/eu/etaxonomy/cdm/model/common/TimePeriodTest.java
5 5
*
6 6
* The contents of this file are subject to the Mozilla Public License Version 1.1
7 7
* See LICENSE.TXT at the top of this package for the full license terms.
8
*/ 
8
*/
9 9

  
10 10
package eu.etaxonomy.cdm.model.common;
11 11

  
......
22 22
import org.joda.time.MutableDateTime;
23 23
import org.joda.time.Partial;
24 24
import org.joda.time.ReadableInstant;
25
import org.junit.After;
26 25
import org.junit.Assert;
27 26
import org.junit.Before;
28 27
import org.junit.Test;
......
37 36
public class TimePeriodTest {
38 37
	@SuppressWarnings("unused")
39 38
	private static final Logger logger = Logger.getLogger(TimePeriodTest.class);
40
	
39

  
41 40
	private TimePeriod onlyStartYear;
42 41
	private TimePeriod onlyEndYear;
43 42
	private TimePeriod startAndEndYear;
......
45 44
	private static final Integer year = 1982;
46 45
	private static final Integer month = 1;
47 46
	private static final Integer day = 5;
48
	
49
		
50

  
51 47

  
52 48
	/**
53 49
	 * @throws java.lang.Exception
......
59 55
		startAndEndYear = TimePeriod.NewInstance(1931, 1957);
60 56
		Integer start = null;
61 57
		Integer end = null;
62
		noStartAndEndYear = TimePeriod.NewInstance(start, end);;
58
		noStartAndEndYear = TimePeriod.NewInstance(start, end);
63 59
	}
64 60

  
65
	/**
66
	 * @throws java.lang.Exception
67
	 */
68
	@After
69
	public void tearDown() throws Exception {
70
	}
61
//************************ TESTS ******************************************
71 62

  
72
	
73
//************************ TESTS ******************************************	
74
	
75 63
	/**
76 64
	 * Test method for {@link eu.etaxonomy.cdm.model.common.TimePeriod#NewInstance()}.
77 65
	 */
......
173 161
		TimePeriod tp = TimePeriod.NewInstance(readInst);
174 162
		Assert.assertNotNull(tp);
175 163
		Assert.assertFalse("Timeperiod should not be empty",tp.isEmpty());
176
		Assert.assertEquals("Timeperiod's should not be empty", (Integer)readInst.get(DateTimeFieldType.dayOfMonth()), (Integer)tp.getStartDay());
164
		Assert.assertEquals("Timeperiod's should not be empty", (Integer)readInst.get(DateTimeFieldType.dayOfMonth()), tp.getStartDay());
177 165
	}
178 166

  
179 167
	/**
......
185 173
		ReadableInstant readInst2 = new MutableDateTime();
186 174
		((MutableDateTime)readInst).addDays(5);
187 175
		TimePeriod tp = TimePeriod.NewInstance(readInst, readInst2);
188
		
176

  
189 177
		Assert.assertNotNull(tp);
190 178
		Assert.assertFalse("Timeperiod should not be empty",tp.isEmpty());
191 179
		Assert.assertEquals("Timeperiod's day should not be equal to readable instant", (Integer)readInst.get(DateTimeFieldType.dayOfMonth()), tp.getStartDay());
......
239 227
		tp.setStart(newStartDate);
240 228
		String changedString = tp.toString();
241 229
		Assert.assertTrue("Setting the partial should change the string representation of the TimePeriod", !startString.equals(changedString));
242
		
230

  
243 231
		//
244 232
		tp = TimePeriodParser.parseString("1752");
245 233
		assertNull("Freetext should be not set", tp.getFreeText());
......
256 244
		changedString = tp.toString();
257 245
		Assert.assertEquals("Setting a partial for a time period having the freetext set should not change the string representation of the TimePeriod	", startString, changedString);
258 246

  
259
		
247

  
260 248
		//
261 249
//		tp = TimePeriodParser.parseString("15.12.1730"); //TODO currently not parsed
262
//		
250
//
263 251
//		startString = tp.toString();
264 252
//		tp.setStart(newStartDate);
265 253
//		changedString = tp.toString();
266
//				
254
//
267 255
//		Assert.assertTrue("Setting a partial for a parsed time period should change the string representation of the TimePeriod	", !startString.equals(changedString));
268 256
	}
269 257

  
......
279 267
		onlyStartYear.setEndDay(14);
280 268
		assertFalse(onlyStartYear.isPeriod());
281 269
		onlyStartYear.setEndYear(1988);
282
		assertTrue(onlyStartYear.isPeriod()); //may be discussed		
270
		assertTrue(onlyStartYear.isPeriod()); //may be discussed
283 271
	}
284 272

  
285 273
	/**
......
318 306
		tp.setEndYear(2002);
319 307
		Assert.assertEquals("Year should be 1999-2002", "1999-2002", tp.getYear());
320 308
	}
321
	
322
	
309

  
310

  
323 311
	/**
324
	 * TODO should be partly moved to a test class for {@link TimePeriodPartialFormatter}	
312
	 * TODO should be partly moved to a test class for {@link TimePeriodPartialFormatter}
325 313
	 */
326 314
	@Test
327 315
	public void testToStringTimePeriod() {
......
333 321
		tp1.setEndMonth(11);
334 322
		Assert.assertEquals("3.xx.1788-11.1799", tp1.toString());
335 323
	}
336
	
324

  
337 325

  
338 326
	/**
339 327
	 * Test method for {@link eu.etaxonomy.cdm.model.common.TimePeriod#clone()}.
......
373 361
		Integer endDay = 21;
374 362
		Integer endYear = 1799;
375 363
		String freeText = "A free period";
376
		
364

  
377 365
		TimePeriod tp1 = TimePeriod.NewInstance(startYear);
378 366
		TimePeriod tpClone = (TimePeriod)tp1.clone();
379 367
		Assert.assertEquals("Cloned time period must be equal to originial", tp1, tpClone);
380
		
368

  
381 369
		tp1.setStartMonth(startMonth);
382 370
		Assert.assertFalse("Cloned time period must not be equal to originial", tp1.equals(tpClone));
383 371
		tpClone = (TimePeriod)tp1.clone();
384 372
		Assert.assertEquals("Cloned time period must be equal to originial", tp1, tpClone);
385
		
373

  
386 374

  
387 375
		tp1.setEndYear(endYear);
388 376
		Assert.assertFalse("Cloned time period must not be equal to originial", tp1.equals(tpClone));
......
393 381
		Assert.assertFalse("Cloned time period must not be equal to originial", tp1.equals(tpClone));
394 382
		tpClone = (TimePeriod)tp1.clone();
395 383
		Assert.assertEquals("Cloned time period must be equal to originial", tp1, tpClone);
396
		
384

  
397 385
		tp1.setFreeText(freeText);
398 386
		Assert.assertFalse("Cloned time period must not be equal to originial", tp1.equals(tpClone));
399 387
		tpClone = (TimePeriod)tp1.clone();
......
412 400
		Assert.assertEquals("Tp2 must be equal", tp1, tp2);
413 401
	}
414 402

  
415
	
416
	
403

  
404

  
417 405
}
cdmlib-persistence/src/main/java/eu/etaxonomy/cdm/persistence/dao/hibernate/common/CdmGenericDaoImpl.java
582 582
		ClassMetadata classMetaData = session.getSessionFactory().getClassMetadata(matchClass.getCanonicalName());
583 583
		Criteria criteria = session.createCriteria(matchClass);
584 584
		boolean noMatch = makeCriteria(objectToMatch, matchStrategy, classMetaData, criteria);
585
		logger.debug(criteria);
585
		if (logger.isDebugEnabled()){logger.debug(criteria);}
586 586
		//session.flush();
587 587
		if (noMatch == false){
588 588
			@SuppressWarnings("unchecked")
......
614 614
			Criteria criteria) throws IllegalAccessException, MatchException {
615 615
		Matching matching = matchStrategy.getMatching();
616 616
		boolean noMatch = false;
617
		Map<String, List<MatchMode>> replaceMatchers = new HashMap<String, List<MatchMode>>();
617
		Map<String, List<MatchMode>> replaceMatchers = new HashMap<>();
618 618
		for (CacheMatcher cacheMatcher: matching.getCacheMatchers()){
619 619
			boolean cacheProtected = (Boolean)cacheMatcher.getProtectedField(matching).get(objectToMatch);
620 620
			if (cacheProtected == true){
......
630 630
						String propertyName = replacementMode.getFirstResult();
631 631
						List<MatchMode> replaceMatcherList = replaceMatchers.get(propertyName);
632 632
						if (replaceMatcherList == null){
633
							replaceMatcherList = new ArrayList<MatchMode>();
633
							replaceMatcherList = new ArrayList<>();
634 634
							replaceMatchers.put(propertyName, replaceMatcherList);
635 635
						}
636 636
						replaceMatcherList.add(replacementMode.getSecondResult());
......
643 643
			String propertyName = fieldMatcher.getPropertyName();
644 644
			Type propertyType = classMetaData.getPropertyType(propertyName);
645 645
			Object value = fieldMatcher.getField().get(objectToMatch);
646
			List<MatchMode> matchModes= new ArrayList<MatchMode>();
646
			List<MatchMode> matchModes= new ArrayList<>();
647 647
			matchModes.add(fieldMatcher.getMatchMode());
648 648
			if (replaceMatchers.get(propertyName) != null){
649 649
				matchModes.addAll(replaceMatchers.get(propertyName));
cdmlib-persistence/src/test/java/eu/etaxonomy/cdm/persistence/dao/hibernate/common/CdmGenericDaoImplTest.java
199 199

  
200 200
	@Test
201 201
	@DataSets({
202
     @DataSet(loadStrategy=CleanSweepInsertLoadStrategy.class, value="/eu/etaxonomy/cdm/database/ClearDB_with_Terms_DataSet.xml"),
203
     @DataSet("/eu/etaxonomy/cdm/database/TermsDataSet-with_auditing_info.xml")})
202
      @DataSet(loadStrategy=CleanSweepInsertLoadStrategy.class, value="/eu/etaxonomy/cdm/database/ClearDB_with_Terms_DataSet.xml"),
203
      @DataSet("/eu/etaxonomy/cdm/database/TermsDataSet-with_auditing_info.xml")})
204 204
	public void testDelete(){
205 205
		Reference ref1 = ReferenceFactory.newBook();
206 206
		Reference ref2 = ReferenceFactory.newBook();
......
209 209
		UUID ref1Uuid = cdmGenericDao.saveOrUpdate(ref1);
210 210
		UUID ref2Uuid = cdmGenericDao.saveOrUpdate(ref2);
211 211
		List<Reference> list = cdmGenericDao.list(Reference.class, 10, 0, null, null);
212
        System.out.println("ref1: " + ref1Uuid + " ref2: " + ref2Uuid);
212
//        System.out.println("ref1: " + ref1Uuid + " ref2: " + ref2Uuid);
213 213
        for (Reference ref: list){
214 214
            System.out.println("reference: " + ref.getUuid());
215 215
        }
......
221 221
		}
222 222
		commitAndStartNewTransaction(null);
223 223
		list = cdmGenericDao.list(Reference.class, 10, 0, null, null);
224
		System.out.println("ref1: " + ref1Uuid + " ref2: " + ref2Uuid);
225
        for (Reference ref: list){
226
            System.out.println("reference: " + ref.getUuid());
227
        }
224
//		System.out.println("ref1: " + ref1Uuid + " ref2: " + ref2Uuid);
225
//        for (Reference ref: list){
226
//            System.out.println("reference: " + ref.getUuid());
227
//        }
228 228
		Assert.assertEquals(1, list.size());
229 229

  
230 230
	}
......
328 328
				Sequence.class,
329 329
				PhylogeneticTree.class,
330 330
				Sequence.class,
331
//				BacterialName.class,
332
//				BotanicalName.class,
333
//				CultivarPlantName.class,
334 331
				HomotypicalGroup.class,
335 332
				HybridRelationship.class,
336 333
				HybridRelationshipType.class,
......
340 337
				NameTypeDesignationStatus.class,
341 338
				NomenclaturalStatus.class,
342 339
				NomenclaturalStatusType.class,
343
//				NonViralName.class,
344 340
				Rank.class,
345 341
				SpecimenTypeDesignation.class,
346 342
				SpecimenTypeDesignationStatus.class,
347 343
				TaxonName.class,
348 344
				TypeDesignationBase.class,
349
//				ViralName.class,
350
//				ZoologicalName.class,
351 345
				Collection.class,
352 346
				DerivationEvent.class,
353 347
				DerivationEventType.class,
cdmlib-remote/src/main/java/eu/etaxonomy/cdm/remote/dto/occurrencecatalogue/OccurrenceSearch.java
46 46
    public OccurrenceSearchRequest getRequest() {
47 47
        return this.request;
48 48
    }
49
    
49

  
50 50
    public class OccurrenceSearchRequest {
51 51
        private String taxonUuid;
52 52
        public OccurrenceSearchRequest() {
......
61 61
            return this.taxonUuid;
62 62
        }
63 63
    }
64
    
64

  
65 65
    public void addToResponse(String acceptedTaxon,
66 66
    		String acceptedTaxonUuid,
67 67
    		DerivedUnitFacade duf) {
68
    	
69
    	OccurrenceSearch.OccurrenceSearchResponse osr = 
68

  
69
    	OccurrenceSearch.OccurrenceSearchResponse osr =
70 70
    			new OccurrenceSearch.OccurrenceSearchResponse();
71 71

  
72 72
    	osr.setAcceptedTaxon(acceptedTaxon);
73 73
    	osr.setAcceptedTaxonUuid(acceptedTaxonUuid);
74
    	
74

  
75 75
    	if(duf.getCollector() != null) {
76 76
    		osr.setCollector(duf.getCollector().getTitleCache());
77 77
    	}
......
81 81
    			osr.setInstitution(duf.getCollection().getInstitute().getName());
82 82
    		}
83 83
    	}
84
    	
84

  
85 85
    	osr.setFieldNotes(duf.getFieldNotes());
86 86
    	if(duf.getType() != null) {
87 87
    		osr.setType(duf.getType().name());
88 88
    	}
89 89
    	osr.setUnitCount(duf.getIndividualCount());
90
    	
90

  
91 91
    	if(duf.getKindOfUnit() != null) {
92 92
    		osr.setKindOfUnit(duf.getKindOfUnit().getLabel());
93 93
    	}
94
    	
94

  
95 95
    	osr.setElevation(duf.getAbsoluteElevation());
96 96
    	osr.setMaxElevation(duf.getAbsoluteElevationMaximum());
97
    	
97

  
98 98
    	osr.setDepth(duf.getDistanceToGround());
99 99
    	osr.setMaxDepth(duf.getDistanceToGroundMax());
100
    	
100

  
101 101
    	if(duf.getGatheringPeriod() != null) {
102 102
    		TimePeriod tp = duf.getGatheringPeriod();
103 103
    		if(tp.getStart() != null) {
......
107 107
    			osr.setEndGatheringDate(tp.getEnd().toString());
108 108
    		}
109 109
    	}
110
    	
111
    	
112
    	OccurrenceSearch.OccurrenceSearchResponse.Location loc = 
110

  
111

  
112
    	OccurrenceSearch.OccurrenceSearchResponse.Location loc =
113 113
    			osr.getLocation();
114
    	
114

  
115 115
    	Point exactLocation = duf.getExactLocation();
116 116
    	if(exactLocation != null) {
117 117
    		loc.setDecimalLatitude(exactLocation.getLatitude());
118 118
    		loc.setDecimalLongitude(exactLocation.getLongitude());
119
    		loc.setErrorRadius(exactLocation.getErrorRadius());    		
119
    		loc.setErrorRadius(exactLocation.getErrorRadius());
120 120
    		if(exactLocation.getReferenceSystem() != null) {
121 121
    			loc.setReferenceSystem(exactLocation.getReferenceSystem().getTitleCache());
122 122
    		}
......
125 125
    	if(duf.getCountry() != null) {
126 126
    		loc.setCountry(duf.getCountry().getTitleCache());
127 127
    	}
128
    	
128

  
129 129
    	if(duf.getLocality() != null) {
130 130
    		loc.setLocality(duf.getLocality().getText());
131 131
    	}
132
    	
132

  
133 133
    	osr.setFieldNumber(duf.getFieldNumber());
134 134
    	osr.setAccessionNumber(duf.getAccessionNumber());
135 135
    	osr.setCatalogNumber(duf.getCatalogNumber());
136
    	
136

  
137 137
    	Set<IdentifiableSource> sources = duf.getSources();
138 138
    	boolean dateFound = false;
139 139
    	String datePublishedString = null;
140 140
    	List<String> sourceTitleList = new ArrayList<String>();
141 141
    	for (IdentifiableSource source:sources) {
142
    		String citation = source.getCitation().getTitleCache();    
142
    		String citation = source.getCitation().getTitleCache();
143 143

  
144 144
    		datePublishedString = source.getCitation().getDatePublishedString();
145 145
    		if (!dateFound && !StringUtils.isEmpty(datePublishedString)){
......
147 147
    			dateFound=true;
148 148
    		}
149 149
    		String  micro = source.getCitationMicroReference();
150
    		
150

  
151 151
    		if(citation == null) {
152 152
    			citation = "";
153
    		}    		
153
    		}
154 154
    		if(micro == null) {
155 155
    			micro = "";
156
    		}    		
156
    		}
157 157
    		sourceTitleList.add(citation + " " + micro);
158 158
    	}
159 159
    	osr.setSources(sourceTitleList);
160
    	
160

  
161 161
    	osr.setPublicationDate(datePublishedString);
162
    	
162

  
163 163
    	List<String> rightsTextList = new ArrayList<String>();
164 164
    	Set<Rights> rightsSet = duf.innerDerivedUnit().getRights();
165 165
    	for(Rights rights : rightsSet) {
......
177 177

  
178 178

  
179 179
    public OccurrenceSearchResponse createResponse(DerivedUnitFacade duFacade) {
180
    	OccurrenceSearch.OccurrenceSearchResponse osResponse = 
180
    	OccurrenceSearch.OccurrenceSearchResponse osResponse =
181 181
    			new OccurrenceSearch.OccurrenceSearchResponse();
182
    	
182

  
183 183
    	return osResponse;
184 184
    }
185 185

  
186 186
    public class OccurrenceSearchResponse {
187
   
187

  
188 188
        private String acceptedTaxon;
189 189
        private String acceptedTaxonUuid;
190
        
190

  
191 191
        private String collector;
192 192
        private String collection;
193 193
        private String institution;
194
              
194

  
195 195
        private String fieldNotes;
196
        
196

  
197 197
        //
198 198
        private String type;
199
        private Object unitCount;
199
        private String unitCount;
200 200
        private String kindOfUnit;
201 201

  
202 202
        //ELEVATION
203 203
        private Object elevation;
204 204
        private Object maxElevation;
205
        
205

  
206 206
        //DEPTH
207 207
        private Object depth;
208 208
        private Object maxDepth;
209 209

  
210 210
        private String startGatherinDate;
211 211
        private String endGatheringDate;
212
              
213
        private Location location;        	
214 212

  
215
        private String fieldNumber;        
213
        private Location location;
214

  
215
        private String fieldNumber;
216 216
        private String accessionNumber;
217 217
        private String catalogNumber;
218 218
        private String barcode;
......
221 221

  
222 222
		private List<String> rights;
223 223
        private List<String> sources;
224
        
224

  
225 225
        //FIXME: Ignoring the fields below for the moment
226 226
        //       Will come back to them when requested and
227 227
        //       when the model allows it properly
228
        
228

  
229 229
//      private String citation;
230 230

  
231
        public OccurrenceSearchResponse() {             	        	
231
        public OccurrenceSearchResponse() {
232 232
        	location = new Location();
233 233
        	rights = new ArrayList<String>();
234 234
        	sources = new ArrayList<String>();
235 235

  
236 236
        }
237
        
237

  
238 238
        /**
239 239
         * @return the specimenOrObservationType
240 240
         */
......
310 310
        /**
311 311
         * @param accessionNumber the accessionNumber to set
312 312
         */
313
   
313

  
314 314
        public void setAccessionNumber(String accessionNumber) {
315 315
            this.accessionNumber = accessionNumber;
316 316
        }
......
427 427
            this.barcode = barcode;
428 428
        }
429 429

  
430
        
430

  
431 431
		public String getPublicationDate() {
432 432
			return publicationDate;
433 433
		}
434
		
434

  
435 435
		public void setPublicationDate(String publicationDate) {
436 436
			this.publicationDate = publicationDate;
437 437
		}
......
575 575
			private Object decimalLongitude;
576 576
        	private Object errorRadius;
577 577
        	private String country;
578
        	private String locality;        	
578
        	private String locality;
579 579
        	private String referenceSystem;
580
        	
580

  
581 581
        	public Object getDecimalLatitude() {
582 582
				return decimalLatitude;
583 583
			}
......
618 618
        }
619 619

  
620 620
    }
621
    
621

  
622 622
}

Also available in: Unified diff