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
|
|
10
|
package eu.etaxonomy.cdm.io.common.mapping;
|
11
|
|
12
|
import java.sql.ResultSet;
|
13
|
import java.sql.SQLException;
|
14
|
import java.util.Set;
|
15
|
|
16
|
import org.apache.log4j.Logger;
|
17
|
|
18
|
import eu.etaxonomy.cdm.io.common.DbImportStateBase;
|
19
|
import eu.etaxonomy.cdm.model.common.CdmBase;
|
20
|
import eu.etaxonomy.cdm.model.description.DescriptionElementBase;
|
21
|
import eu.etaxonomy.cdm.model.description.Feature;
|
22
|
import eu.etaxonomy.cdm.model.description.TaxonDescription;
|
23
|
import eu.etaxonomy.cdm.model.description.TextData;
|
24
|
import eu.etaxonomy.cdm.model.taxon.Taxon;
|
25
|
|
26
|
/**
|
27
|
* @author a.mueller
|
28
|
* @created 11.03.2010
|
29
|
* @version 1.0
|
30
|
*/
|
31
|
public class DbImportImageCreationMapper extends DbImportDescriptionElementCreationMapperBase<TextData, DbImportStateBase<?,?>> {
|
32
|
@SuppressWarnings("unused")
|
33
|
private static final Logger logger = Logger.getLogger(DbImportImageCreationMapper.class);
|
34
|
|
35
|
// ************************** FACTORY ***********************************************************/
|
36
|
|
37
|
public static DbImportImageCreationMapper NewInstance(String dbIdAttribute, String objectToCreateNamespace, String dbTaxonFkAttribute, String taxonNamespace, boolean isOneTextData){
|
38
|
return new DbImportImageCreationMapper(dbIdAttribute, objectToCreateNamespace, dbTaxonFkAttribute, taxonNamespace, isOneTextData);
|
39
|
}
|
40
|
|
41
|
|
42
|
// ************************** ATTRIBUTES ***********************************************************/
|
43
|
private boolean isOneTextData;
|
44
|
|
45
|
//********************************* CONSTRUCTOR ***************************************************/
|
46
|
|
47
|
/**
|
48
|
* @param dbIdAttribute
|
49
|
* @param objectToCreateNamespace
|
50
|
* @param dbTaxonFkAttribute
|
51
|
* @param taxonNamespace
|
52
|
*/
|
53
|
protected DbImportImageCreationMapper(String dbIdAttribute, String objectToCreateNamespace, String dbTaxonFkAttribute, String taxonNamespace, boolean isOneTextData) {
|
54
|
super(dbIdAttribute, objectToCreateNamespace, dbTaxonFkAttribute, taxonNamespace);
|
55
|
this.isImageGallery = true;
|
56
|
this.isOneTextData = isOneTextData;
|
57
|
}
|
58
|
|
59
|
// ********************************** METHODS ***********************************************************
|
60
|
|
61
|
/* (non-Javadoc)
|
62
|
* @see eu.etaxonomy.cdm.io.common.mapping.DbImportObjectCreationMapperBase#createObject(java.sql.ResultSet)
|
63
|
*/
|
64
|
@Override
|
65
|
protected TextData createObject(ResultSet rs) throws SQLException {
|
66
|
TextData textData = TextData.NewInstance(Feature.IMAGE());
|
67
|
return textData;
|
68
|
}
|
69
|
|
70
|
/* (non-Javadoc)
|
71
|
* @see eu.etaxonomy.cdm.io.common.mapping.DbImportDescriptionElementCreationMapperBase#addDescriptionElement(eu.etaxonomy.cdm.model.taxon.Taxon, eu.etaxonomy.cdm.model.description.DescriptionElementBase)
|
72
|
*/
|
73
|
@Override
|
74
|
protected TextData addDescriptionElement(Taxon taxon, TextData element) {
|
75
|
if (taxon == null){
|
76
|
return null;
|
77
|
}else{
|
78
|
TaxonDescription description = getTaxonDescription(taxon, isImageGallery);
|
79
|
if (isOneTextData == true){
|
80
|
|
81
|
Set<DescriptionElementBase> elements = description.getElements();
|
82
|
for (DescriptionElementBase descElement : elements){
|
83
|
if (descElement.isInstanceOf(TextData.class) && descElement.getFeature().equals(Feature.IMAGE()) ){
|
84
|
element = CdmBase.deproxy(descElement, TextData.class);
|
85
|
}
|
86
|
}
|
87
|
}
|
88
|
description.addElement(element);
|
89
|
return element;
|
90
|
}
|
91
|
}
|
92
|
|
93
|
|
94
|
}
|