Project

General

Profile

Download (2.67 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.io.common.mapping.out;
10

    
11
import java.sql.Types;
12
import java.util.List;
13
import java.util.Set;
14

    
15
import org.apache.log4j.Logger;
16

    
17
import eu.etaxonomy.cdm.common.URI;
18
import eu.etaxonomy.cdm.io.common.DbExportStateBase;
19
import eu.etaxonomy.cdm.model.common.CdmBase;
20
import eu.etaxonomy.cdm.model.description.TextData;
21
import eu.etaxonomy.cdm.model.media.Media;
22
import eu.etaxonomy.cdm.model.media.MediaRepresentation;
23
import eu.etaxonomy.cdm.model.media.MediaRepresentationPart;
24

    
25
/**
26
 * TODO under construction (maybe needs to be a multi-attribute mapper as it maps to taxon column
27
 * and to (multiple) uri columns.
28
 * @author a.mueller
29
 * @since 06.02.2012
30
 */
31
public class DbImageMapper
32
            extends DbSingleAttributeExportMapperBase<DbExportStateBase<?, IExportTransformer>>
33
            implements IDbExportMapper<DbExportStateBase<?, IExportTransformer>, IExportTransformer>{
34

    
35
    @SuppressWarnings("unused")
36
	private static final Logger logger = Logger.getLogger(DbImageMapper.class);
37

    
38
	public static DbImageMapper NewInstance(String dbAttributeString){
39
		return new DbImageMapper(dbAttributeString, null);
40
	}
41

    
42
	protected DbImageMapper(String dbAttributeString, Object defaultValue) {
43
		super("multiLanguageText", dbAttributeString, defaultValue);
44
	}
45

    
46
	@Override
47
	protected Object getValue(CdmBase cdmBase) {
48
		if (cdmBase.isInstanceOf(TextData.class)){
49
			List<Media> media = CdmBase.deproxy(cdmBase, TextData.class).getMedia();
50

    
51
			for (Media image : media) {
52
				Set<MediaRepresentation> representations = image.getRepresentations();
53

    
54
				for (MediaRepresentation representation : representations) {
55
					List<MediaRepresentationPart> representationParts = representation.getParts();
56

    
57
					for (MediaRepresentationPart representationPart : representationParts) {
58
						URI mediaUri = representationPart.getUri();
59

    
60
						// Add image data
61
						String thumb = null;
62
						Integer taxonFk = null; //getState().getDbId(taxonBase.getName());
63

    
64
						if (taxonFk != null && mediaUri != null) {
65
//							doCount(count++, modCount, pluralString);
66
//							invokeImages(thumb, mediaUri, taxonFk, connection);
67
						}
68
					}
69
				}
70

    
71
			}
72
		}else{
73
			throw new ClassCastException("CdmBase for "+this.getClass().getName() +" must be of type TextData, but was " + cdmBase.getClass());
74
		}
75
		return null;
76
	}
77

    
78
	@Override
79
	protected int getSqlType() {
80
		return Types.VARCHAR;
81
	}
82

    
83
	@Override
84
	public Class<?> getTypeClass() {
85
		return String.class;
86
	}
87
}
(19-19/44)