Project

General

Profile

Download (1.26 KB) Statistics
| Branch: | Tag: | Revision:
1
/**
2
* Copyright (C) 2007 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.remote.dto.assembler.converter;
10

    
11

    
12
import java.time.ZonedDateTime;
13

    
14
import org.dozer.CustomConverter;
15
import org.dozer.MappingException;
16

    
17
import eu.etaxonomy.cdm.model.common.TimePeriod;
18

    
19
public class TimePeriodConverter implements CustomConverter {
20

    
21
    @Override
22
	public Object convert(Object existingDestinationFieldValue, Object source, Class<?> destClass, Class<?> sourceClass) {
23

    
24
		if (source == null) {
25
			return null;
26
		}
27
		if (source instanceof TimePeriod) {
28

    
29
			//convert from TimePeriod -> DateTime
30
			//FIXME .toDateTime(null) most probably not correct
31
			if(((TimePeriod)source).getStart() != null){
32
				return ((TimePeriod)source).getStart();
33
			} else {
34
				return null;
35
			}
36

    
37
		} else if (source instanceof ZonedDateTime) {
38

    
39
			//convert from DateTime -> TimePeriod
40
			//FIXME implement
41
			return null;
42

    
43
		} else {
44

    
45
			throw new MappingException("Converter TestCustomConverter used incorrectly. Arguments passed in were:"
46
					+ existingDestinationFieldValue + " and " + source);
47
		}
48
	}
49

    
50
}
(11-11/11)