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.algaterra;
|
11
|
|
12
|
import java.net.URI;
|
13
|
import java.sql.Date;
|
14
|
import java.sql.ResultSet;
|
15
|
import java.sql.SQLException;
|
16
|
import java.util.Map;
|
17
|
import java.util.Set;
|
18
|
import java.util.UUID;
|
19
|
|
20
|
import javassist.runtime.Desc;
|
21
|
|
22
|
import org.apache.commons.lang.StringUtils;
|
23
|
import org.apache.log4j.Logger;
|
24
|
import org.springframework.transaction.TransactionStatus;
|
25
|
|
26
|
import eu.etaxonomy.cdm.api.facade.DerivedUnitFacade;
|
27
|
import eu.etaxonomy.cdm.common.media.ImageInfo;
|
28
|
import eu.etaxonomy.cdm.io.berlinModel.in.BerlinModelImportBase;
|
29
|
import eu.etaxonomy.cdm.io.berlinModel.in.BerlinModelTaxonNameImport;
|
30
|
import eu.etaxonomy.cdm.io.common.ResultSetPartitioner;
|
31
|
import eu.etaxonomy.cdm.io.common.Source;
|
32
|
import eu.etaxonomy.cdm.model.agent.Team;
|
33
|
import eu.etaxonomy.cdm.model.common.CdmBase;
|
34
|
import eu.etaxonomy.cdm.model.common.Language;
|
35
|
import eu.etaxonomy.cdm.model.common.OrderedTermVocabulary;
|
36
|
import eu.etaxonomy.cdm.model.common.TimePeriod;
|
37
|
import eu.etaxonomy.cdm.model.description.DescriptionBase;
|
38
|
import eu.etaxonomy.cdm.model.description.DescriptionElementBase;
|
39
|
import eu.etaxonomy.cdm.model.description.Feature;
|
40
|
import eu.etaxonomy.cdm.model.description.SpecimenDescription;
|
41
|
import eu.etaxonomy.cdm.model.description.State;
|
42
|
import eu.etaxonomy.cdm.model.description.TextData;
|
43
|
import eu.etaxonomy.cdm.model.location.NamedArea;
|
44
|
import eu.etaxonomy.cdm.model.location.Point;
|
45
|
import eu.etaxonomy.cdm.model.location.ReferenceSystem;
|
46
|
import eu.etaxonomy.cdm.model.location.TdwgArea;
|
47
|
import eu.etaxonomy.cdm.model.location.WaterbodyOrCountry;
|
48
|
import eu.etaxonomy.cdm.model.media.Media;
|
49
|
import eu.etaxonomy.cdm.model.name.TaxonNameBase;
|
50
|
import eu.etaxonomy.cdm.model.occurrence.Collection;
|
51
|
import eu.etaxonomy.cdm.model.occurrence.DerivedUnit;
|
52
|
import eu.etaxonomy.cdm.model.occurrence.DerivedUnitBase;
|
53
|
import eu.etaxonomy.cdm.model.occurrence.SpecimenOrObservationBase;
|
54
|
import eu.etaxonomy.cdm.model.reference.Reference;
|
55
|
|
56
|
/**
|
57
|
* @author a.mueller
|
58
|
* @created 12.09.2012
|
59
|
*/
|
60
|
public abstract class AlgaTerraImageImportBase extends BerlinModelImportBase{
|
61
|
private static final Logger logger = Logger.getLogger(AlgaTerraImageImportBase.class);
|
62
|
|
63
|
public static final String TERMS_NAMESPACE = "ALGA_TERRA_TERMS";
|
64
|
|
65
|
|
66
|
|
67
|
|
68
|
/**
|
69
|
* Creates a media object and
|
70
|
* @param rs
|
71
|
* @param derivedUnit
|
72
|
* @param state
|
73
|
* @param partitioner
|
74
|
* @return
|
75
|
* @throws SQLException
|
76
|
*/
|
77
|
protected Media handleSingleImage(ResultSet rs, SpecimenOrObservationBase derivedUnit, AlgaTerraImportState state, ResultSetPartitioner partitioner) throws SQLException {
|
78
|
try {
|
79
|
String fileName = rs.getString("fileName");
|
80
|
String figurePhrase = rs.getString("FigurePhrase");
|
81
|
//TODO refFk, refDetailFk, publishFlag
|
82
|
Integer refFk = nullSafeInt(rs, "refFk");
|
83
|
Integer refDetailFk = nullSafeInt(rs, "refDetailFk");
|
84
|
Boolean publishFlag = rs.getBoolean("RestrictedFlag");
|
85
|
|
86
|
|
87
|
if (isBlank(fileName)){
|
88
|
throw new RuntimeException("FileName is missing");
|
89
|
}
|
90
|
String fullPath = state.getAlgaTerraConfigurator().getImageBaseUrl() + fileName;
|
91
|
|
92
|
boolean isFigure = false;
|
93
|
Media media = getImageMedia(fullPath, READ_MEDIA_DATA, isFigure);
|
94
|
|
95
|
if (media == null){
|
96
|
throw new RuntimeException ("Media not found for " +fullPath);
|
97
|
}
|
98
|
if (isNotBlank(figurePhrase)){
|
99
|
media.putTitle(Language.DEFAULT(), figurePhrase);
|
100
|
}
|
101
|
|
102
|
//TODO ref
|
103
|
Reference<?> ref = null;
|
104
|
if (derivedUnit != null){
|
105
|
SpecimenDescription desc = getSpecimenDescription(derivedUnit, ref, IMAGE_GALLERY, CREATE);
|
106
|
TextData textData = null;
|
107
|
for (DescriptionElementBase descEl : desc.getElements()){
|
108
|
if (descEl.isInstanceOf(TextData.class)){
|
109
|
textData = CdmBase.deproxy(descEl, TextData.class);
|
110
|
}
|
111
|
}
|
112
|
if (textData == null){
|
113
|
textData = TextData.NewInstance(Feature.IMAGE());
|
114
|
}
|
115
|
desc.addElement(textData);
|
116
|
textData.addMedia(media);
|
117
|
}else{
|
118
|
logger.warn("Derived unit is null. Can't add media ");
|
119
|
}
|
120
|
|
121
|
//notes
|
122
|
|
123
|
//TODO restrictedFlag
|
124
|
|
125
|
//TODO id, created for
|
126
|
// this.doIdCreatedUpdatedNotes(state, descriptionElement, rs, id, namespace);
|
127
|
|
128
|
return media;
|
129
|
} catch (Exception e) {
|
130
|
throw new RuntimeException(e);
|
131
|
}
|
132
|
|
133
|
}
|
134
|
|
135
|
|
136
|
|
137
|
|
138
|
|
139
|
}
|