change MultiLanguageTextMapper to works with TextData.put.Use only 1 language.
[cdmlib.git] / cdmlib-io / src / main / java / eu / etaxonomy / cdm / io / common / mapping / DbImportImageCreationMapper.java
1 // $Id$
2 /**
3 * Copyright (C) 2007 EDIT
4 * European Distributed Institute of Taxonomy
5 * http://www.e-taxonomy.eu
6 *
7 * The contents of this file are subject to the Mozilla Public License Version 1.1
8 * See LICENSE.TXT at the top of this package for the full license terms.
9 */
10
11 package eu.etaxonomy.cdm.io.common.mapping;
12
13 import java.sql.ResultSet;
14 import java.sql.SQLException;
15 import java.util.Set;
16
17 import org.apache.log4j.Logger;
18
19 import eu.etaxonomy.cdm.io.common.DbImportStateBase;
20 import eu.etaxonomy.cdm.model.common.CdmBase;
21 import eu.etaxonomy.cdm.model.description.DescriptionElementBase;
22 import eu.etaxonomy.cdm.model.description.Feature;
23 import eu.etaxonomy.cdm.model.description.TaxonDescription;
24 import eu.etaxonomy.cdm.model.description.TextData;
25 import eu.etaxonomy.cdm.model.taxon.Taxon;
26 import eu.etaxonomy.cdm.model.taxon.TaxonBase;
27
28 /**
29 * @author a.mueller
30 * @created 11.03.2010
31 * @version 1.0
32 */
33 public class DbImportImageCreationMapper extends DbImportDescriptionElementCreationMapperBase<TextData, DbImportStateBase<?,?>> {
34 @SuppressWarnings("unused")
35 private static final Logger logger = Logger.getLogger(DbImportImageCreationMapper.class);
36
37 // ************************** FACTORY ***********************************************************/
38
39 public static DbImportImageCreationMapper NewInstance(String dbIdAttribute, String objectToCreateNamespace, String dbTaxonFkAttribute, String taxonNamespace, boolean isOneTextData){
40 return new DbImportImageCreationMapper(dbIdAttribute, objectToCreateNamespace, dbTaxonFkAttribute, taxonNamespace, isOneTextData);
41 }
42
43
44 // ************************** ATTRIBUTES ***********************************************************/
45 private boolean isOneTextData;
46
47 //********************************* CONSTRUCTOR ***************************************************/
48
49 /**
50 * @param dbIdAttribute
51 * @param objectToCreateNamespace
52 * @param dbTaxonFkAttribute
53 * @param taxonNamespace
54 */
55 protected DbImportImageCreationMapper(String dbIdAttribute, String objectToCreateNamespace, String dbTaxonFkAttribute, String taxonNamespace, boolean isOneTextData) {
56 super(dbIdAttribute, objectToCreateNamespace, dbTaxonFkAttribute, taxonNamespace);
57 this.isImageGallery = true;
58 this.isOneTextData = isOneTextData;
59 }
60
61 // ********************************** METHODS ***********************************************************
62
63 /* (non-Javadoc)
64 * @see eu.etaxonomy.cdm.io.common.mapping.DbImportObjectCreationMapperBase#createObject(java.sql.ResultSet)
65 */
66 @Override
67 protected TextData createObject(ResultSet rs) throws SQLException {
68 TextData textData = TextData.NewInstance(Feature.IMAGE());
69 return textData;
70 }
71
72 /* (non-Javadoc)
73 * @see eu.etaxonomy.cdm.io.common.mapping.DbImportDescriptionElementCreationMapperBase#addDescriptionElement(eu.etaxonomy.cdm.model.taxon.Taxon, eu.etaxonomy.cdm.model.description.DescriptionElementBase)
74 */
75 @Override
76 protected TextData addDescriptionElement(Taxon taxon, TextData element) {
77 if (taxon == null){
78 return null;
79 }else{
80 TaxonDescription description = getTaxonDescription(taxon, isImageGallery);
81 if (isOneTextData == true){
82
83 Set<DescriptionElementBase> elements = description.getElements();
84 for (DescriptionElementBase descElement : elements){
85 if (descElement.isInstanceOf(TextData.class) && descElement.getFeature().equals(Feature.IMAGE()) ){
86 element = CdmBase.deproxy(descElement, TextData.class);
87 }
88 }
89 }
90 description.addElement(element);
91 return element;
92 }
93 }
94
95
96 }