Project

General

Profile

Revision 69637162

ID69637162e08f9923a1bed32680228eae1e710ebb
Parent c9c6b8e2
Child 3a1cd9fb

Added by Andreas Müller over 8 years ago

fix failing tests for adding descriptionElementBase.timeperiod #3312 and clean up TimePeriod class

View differences:

cdmlib-ext/src/test/resources/dbscripts/001-cdm.h2.sql
1346 1346
    CREATED TIMESTAMP,
1347 1347
    UUID VARCHAR(36),
1348 1348
    UPDATED TIMESTAMP,
1349
    ORDERRELEVANT BOOLEAN,
1350 1349
    NAME VARCHAR(255),
1350
    TIMEPERIOD_START VARCHAR(255),
1351
    TIMEPERIOD_END VARCHAR(255),
1352
    TIMEPERIOD_FREETEXT VARCHAR(255),
1353
    ORDERRELEVANT BOOLEAN,
1351 1354
    CREATEDBY_ID INTEGER,
1352 1355
    UPDATEDBY_ID INTEGER,
1353 1356
    FEATURE_ID INTEGER,
......
1369 1372
    CREATED TIMESTAMP,
1370 1373
    UUID VARCHAR(36),
1371 1374
    UPDATED TIMESTAMP,
1375
    NAME VARCHAR(255),
1376
    TIMEPERIOD_START VARCHAR(255),
1377
    TIMEPERIOD_END VARCHAR(255),
1378
    TIMEPERIOD_FREETEXT VARCHAR(255),
1379
    ORDERRELEVANT BOOLEAN,
1372 1380
    CREATEDBY_ID INTEGER,
1373 1381
    UPDATEDBY_ID INTEGER,
1374 1382
    FEATURE_ID INTEGER,
......
1379 1387
    UNIT_ID INTEGER,
1380 1388
    FORMAT_ID INTEGER,
1381 1389
    ASSOCIATEDSPECIMENOROBSERVATION_ID INTEGER,
1382
    NAME VARCHAR(255),
1383
    LANGUAGE_ID INTEGER,
1384
    ORDERRELEVANT BOOLEAN
1390
    LANGUAGE_ID INTEGER
1385 1391
);
1386 1392
-- 0 +/- SELECT COUNT(*) FROM PUBLIC.DESCRIPTIONELEMENTBASE_AUD;
1387 1393
CREATE CACHED TABLE PUBLIC.DESCRIPTIONELEMENTBASE_ANNOTATION(
cdmlib-io/src/test/resources/dbscripts/001-cdm.h2.sql
1346 1346
    CREATED TIMESTAMP,
1347 1347
    UUID VARCHAR(36),
1348 1348
    UPDATED TIMESTAMP,
1349
    ORDERRELEVANT BOOLEAN,
1350 1349
    NAME VARCHAR(255),
1350
    TIMEPERIOD_START VARCHAR(255),
1351
    TIMEPERIOD_END VARCHAR(255),
1352
    TIMEPERIOD_FREETEXT VARCHAR(255),
1353
    ORDERRELEVANT BOOLEAN,
1351 1354
    CREATEDBY_ID INTEGER,
1352 1355
    UPDATEDBY_ID INTEGER,
1353 1356
    FEATURE_ID INTEGER,
......
1369 1372
    CREATED TIMESTAMP,
1370 1373
    UUID VARCHAR(36),
1371 1374
    UPDATED TIMESTAMP,
1375
    NAME VARCHAR(255),
1376
    TIMEPERIOD_START VARCHAR(255),
1377
    TIMEPERIOD_END VARCHAR(255),
1378
    TIMEPERIOD_FREETEXT VARCHAR(255),
1379
    ORDERRELEVANT BOOLEAN,
1372 1380
    CREATEDBY_ID INTEGER,
1373 1381
    UPDATEDBY_ID INTEGER,
1374 1382
    FEATURE_ID INTEGER,
......
1379 1387
    UNIT_ID INTEGER,
1380 1388
    FORMAT_ID INTEGER,
1381 1389
    ASSOCIATEDSPECIMENOROBSERVATION_ID INTEGER,
1382
    NAME VARCHAR(255),
1383
    LANGUAGE_ID INTEGER,
1384
    ORDERRELEVANT BOOLEAN
1390
    LANGUAGE_ID INTEGER
1385 1391
);
1386 1392
-- 0 +/- SELECT COUNT(*) FROM PUBLIC.DESCRIPTIONELEMENTBASE_AUD;
1387 1393
CREATE CACHED TABLE PUBLIC.DESCRIPTIONELEMENTBASE_ANNOTATION(
cdmlib-model/src/main/java/eu/etaxonomy/cdm/model/common/TimePeriod.java
26 26
import javax.xml.bind.annotation.XmlType;
27 27
import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter;
28 28

  
29
import org.apache.commons.lang.StringUtils;
29 30
import org.apache.log4j.Logger;
30 31
import org.hibernate.annotations.Type;
31 32
import org.hibernate.search.annotations.Analyze;
......
58 59
@XmlRootElement(name = "TimePeriod")
59 60
@Embeddable
60 61
public class TimePeriod implements Cloneable, Serializable {
62
	private static final long serialVersionUID = 3405969418194981401L;
61 63
	private static final Logger logger = Logger.getLogger(TimePeriod.class);
62 64
	public static final DateTimeFieldType MONTH_TYPE = DateTimeFieldType.monthOfYear();
63 65
	public static final DateTimeFieldType YEAR_TYPE = DateTimeFieldType.year();
......
81 83
	@XmlElement(name = "FreeText")
82 84
	private String freeText;
83 85

  
86
// ********************** FACTORY METHODS **************************/
84 87

  
85 88
	/**
86 89
	 * Factory method
......
205 208
		return new TimePeriod(startDate, endDate);
206 209
	}
207 210

  
211
//****************** CONVERTERS ******************/	
208 212

  
209 213
	/**
210
	 * Transforms a <code>Calendar</code> into a <code>Partial</code>
214
	 * Transforms a {@link Calendar} into a <code>Partial</code>
211 215
	 * @param calendar
212 216
	 * @return
213 217
	 */
......
218 222
	}
219 223

  
220 224
	/**
221
	 * Transforms a <code>Calendar</code> into a <code>Partial</code>
225
	 * Transforms a {@link ReadableInstant} into a <code>Partial</code>
222 226
	 * @param calendar
223 227
	 * @return
224 228
	 */
......
229 233
		return partial;
230 234
	}
231 235

  
236

  
237
	public static Integer getPartialValue(Partial partial, DateTimeFieldType type){
238
		if (partial == null || ! partial.isSupported(type)){
239
			return null;
240
		}else{
241
			return partial.get(type);
242
		}
243
	}
244

  
245

  
246
	
247
//*********************** CONSTRUCTOR *********************************/	
248
	
232 249
	/**
233 250
	 * Constructor
234 251
	 */
......
243 260
		end=endDate;
244 261
	}
245 262

  
246
	/**
247
	 * True, if this time period represents a period not a single point in time.
248
	 * This is by definition, that the time period has a start and an end value,
249
	 * and both have a year value that is not null
250
	 * @return
251
	 */
252
	@Transient
253
	public boolean isPeriod(){
254
		if (getStartYear() != null && getEndYear() != null ){
255
			return true;
256
		}else{
257
			return false;
258
		}
259
	}
260

  
261
	/**
262
	 * True, if there is no start date and no end date and no freetext representation exists.
263
	 * @return
264
	 */
265
	@Transient
266
	public boolean isEmpty(){
267
		if (CdmUtils.isEmpty(this.getFreeText()) && start == null  && end == null ){
268
			return true;
269
		}else{
270
			return false;
271
		}
272
	}
273

  
263
//******************* GETTER / SETTER ************************************/
274 264

  
275 265
	public Partial getStart() {
276 266
		return start;
......
309 299
		this.freeText = freeText;
310 300
	}
311 301

  
302
	
303
//******************* Transient METHODS ************************************/
304

  
305
	/**
306
	 * True, if this time period represents a period not a single point in time.
307
	 * This is by definition, that the time period has a start and an end value,
308
	 * and both have a year value that is not null
309
	 * @return
310
	 */
311
	@Transient
312
	public boolean isPeriod(){
313
		if (getStartYear() != null && getEndYear() != null ){
314
			return true;
315
		}else{
316
			return false;
317
		}
318
	}
319

  
320
	/**
321
	 * True, if there is no start date and no end date and no freetext representation exists.
322
	 * @return
323
	 */
324
	@Transient
325
	public boolean isEmpty(){
326
		if (StringUtils.isBlank(this.getFreeText()) && start == null  && end == null ){
327
			return true;
328
		}else{
329
			return false;
330
		}
331
	}
332

  
333

  
312 334

  
313 335
	@Transient
314 336
	public String getYear(){
......
356 378
		return getPartialValue(end, DAY_TYPE);
357 379
	}
358 380

  
359
	public static Integer getPartialValue(Partial partial, DateTimeFieldType type){
360
		if (partial == null || ! partial.isSupported(type)){
361
			return null;
362
		}else{
363
			return partial.get(type);
364
		}
365

  
366
	}
367

  
368 381
	public TimePeriod setStartYear(Integer year){
369 382
		return setStartField(year, YEAR_TYPE);
370 383
	}
......
402 415
		}
403 416
	}
404 417

  
418
	@Transient
405 419
	private TimePeriod setStartField(Integer value, DateTimeFieldType type)
406 420
			throws IndexOutOfBoundsException{
407 421
		start = setPartialField(start, value, type);
408 422
		return this;
409 423
	}
410 424

  
425
	@Transient
411 426
	private TimePeriod setEndField(Integer value, DateTimeFieldType type)
412 427
			throws IndexOutOfBoundsException{
413 428
		end = setPartialField(end, value, type);
414 429
		return this;
415 430
	}
416 431

  
432
// ******************************** internal methods *******************************/	
433
	
417 434
	/**
418 435
	 * Throws an IndexOutOfBoundsException if the value does not have a valid value
419 436
	 * (e.g. month > 12, month < 1, day > 31, etc.)
......
458 475
		}
459 476
	}
460 477

  
461

  
478
//***************************** PARSING *********************************************/
479
	//TODO should be moved to separate class //
480
	
462 481
	//patter for first year in string;
463 482
	private static final Pattern firstYearPattern =  Pattern.compile("\\d{4}");
464 483
	//case "1806"[1807];
cdmlib-model/src/main/java/eu/etaxonomy/cdm/model/description/DescriptionElementBase.java
83 83
@XmlType(name = "DescriptionElementBase", propOrder = {
84 84
        "feature",
85 85
        "inDescription",
86
        "timePeriod",
86
        "timeperiod",
87 87
        "modifiers",
88 88
        "modifyingText",
89 89
        "media",
cdmlib-services/src/test/java/eu/etaxonomy/cdm/api/facade/DerivedUnitFacadeTest.java
728 728
     */
729 729
    @Test
730 730
    public void testGetTimeperiod() {
731
        Assert.assertNotNull("Gathering period must not be null",
732
                specimenFacade.getGatheringPeriod());
733
        Assert.assertEquals("Gathering period must be same", gatheringPeriod,
734
                specimenFacade.getGatheringPeriod());
731
        Assert.assertNotNull("Gathering period must not be null", specimenFacade.getGatheringPeriod());
732
        Assert.assertFalse("Gathering period must not be empty", specimenFacade.getGatheringPeriod().isEmpty());
733
        Assert.assertEquals("Gathering period must be same", gatheringPeriod, specimenFacade.getGatheringPeriod());
735 734
        specimenFacade.setGatheringPeriod(null);
736
        Assert.assertNull("Gathering period must be null",
737
                specimenFacade.getGatheringPeriod());
735
        Assert.assertTrue("Gathering period must be null", specimenFacade.getGatheringPeriod().isEmpty());
738 736
    }
739 737

  
740 738
    @Test
......
746 744
        // field unit may not be initialized from the beginning. Than the
747 745
        // following
748 746
        // assert should be set to assertNull
749
        Assert.assertTrue(
750
                "field object should not be null (depends on specimen facade initialization !!)",
747
        Assert.assertTrue("field object should not be null (depends on specimen facade initialization !!)",
751 748
                specimenFacade.hasFieldObject());
752 749

  
753 750
        Field fieldUnitField = DerivedUnitFacade.class
cdmlib-services/src/test/resources/dbscripts/001-cdm.h2.sql
1346 1346
    CREATED TIMESTAMP,
1347 1347
    UUID VARCHAR(36),
1348 1348
    UPDATED TIMESTAMP,
1349
    ORDERRELEVANT BOOLEAN,
1350 1349
    NAME VARCHAR(255),
1350
    TIMEPERIOD_START VARCHAR(255),
1351
    TIMEPERIOD_END VARCHAR(255),
1352
    TIMEPERIOD_FREETEXT VARCHAR(255),
1353
    ORDERRELEVANT BOOLEAN,
1351 1354
    CREATEDBY_ID INTEGER,
1352 1355
    UPDATEDBY_ID INTEGER,
1353 1356
    FEATURE_ID INTEGER,
......
1369 1372
    CREATED TIMESTAMP,
1370 1373
    UUID VARCHAR(36),
1371 1374
    UPDATED TIMESTAMP,
1375
    NAME VARCHAR(255),
1376
    TIMEPERIOD_START VARCHAR(255),
1377
    TIMEPERIOD_END VARCHAR(255),
1378
    TIMEPERIOD_FREETEXT VARCHAR(255),
1379
    ORDERRELEVANT BOOLEAN,
1372 1380
    CREATEDBY_ID INTEGER,
1373 1381
    UPDATEDBY_ID INTEGER,
1374 1382
    FEATURE_ID INTEGER,
......
1379 1387
    UNIT_ID INTEGER,
1380 1388
    FORMAT_ID INTEGER,
1381 1389
    ASSOCIATEDSPECIMENOROBSERVATION_ID INTEGER,
1382
    NAME VARCHAR(255),
1383
    LANGUAGE_ID INTEGER,
1384
    ORDERRELEVANT BOOLEAN
1390
    LANGUAGE_ID INTEGER
1385 1391
);
1386 1392
-- 0 +/- SELECT COUNT(*) FROM PUBLIC.DESCRIPTIONELEMENTBASE_AUD;
1387 1393
CREATE CACHED TABLE PUBLIC.DESCRIPTIONELEMENTBASE_ANNOTATION(

Also available in: Unified diff

Add picture from clipboard (Maximum size: 40 MB)