Revision 92fdeae1
Added by Andreas Müller almost 4 years ago
app-import/src/main/java/eu/etaxonomy/cdm/io/wp6/CichorieaeImageImport.java | ||
---|---|---|
13 | 13 |
import java.io.IOException; |
14 | 14 |
import java.net.MalformedURLException; |
15 | 15 |
import java.net.URI; |
16 |
import java.net.URISyntaxException; |
|
16 | 17 |
import java.util.List; |
17 | 18 |
import java.util.UUID; |
18 | 19 |
|
... | ... | |
22 | 23 |
|
23 | 24 |
import eu.etaxonomy.cdm.app.images.AbstractImageImporter; |
24 | 25 |
import eu.etaxonomy.cdm.app.images.ImageImportState; |
25 |
import eu.etaxonomy.cdm.common.CdmUtils; |
|
26 |
import eu.etaxonomy.cdm.common.media.ImageInfo; |
|
26 |
import eu.etaxonomy.cdm.common.media.CdmImageInfo; |
|
27 | 27 |
import eu.etaxonomy.cdm.model.agent.AgentBase; |
28 | 28 |
import eu.etaxonomy.cdm.model.common.Language; |
29 | 29 |
import eu.etaxonomy.cdm.model.common.LanguageString; |
... | ... | |
40 | 40 |
/** |
41 | 41 |
* @author n.hoffmann |
42 | 42 |
* @since 18.11.2008 |
43 |
* @version 1.0 |
|
44 | 43 |
*/ |
45 | 44 |
@Component |
46 | 45 |
public class CichorieaeImageImport extends AbstractImageImporter { |
47 |
private static final Logger logger = Logger.getLogger(CichorieaeImageImport.class); |
|
48 | 46 |
|
47 |
private static final long serialVersionUID = -5123899111873586729L; |
|
48 |
private static final Logger logger = Logger.getLogger(CichorieaeImageImport.class); |
|
49 | 49 |
|
50 | 50 |
/** |
51 | 51 |
* Imports images from a directory. |
... | ... | |
78 | 78 |
}else{ |
79 | 79 |
logger.warn("Source is not a directory!" + source.toString()); |
80 | 80 |
} |
81 |
|
|
82 | 81 |
return; |
83 |
|
|
84 | 82 |
} |
85 | 83 |
|
86 | 84 |
private String getTaxonName(String fileName){ |
... | ... | |
124 | 122 |
return taxonName; |
125 | 123 |
} |
126 | 124 |
|
127 |
|
|
128 |
/** |
|
129 |
* @param tree |
|
130 |
* @param sourceRef |
|
131 |
* @param name |
|
132 |
* @param taxonName |
|
133 |
* @param taxa |
|
134 |
* @param taxon |
|
135 |
*/ |
|
136 |
private void handleTaxa(Classification tree, Reference sourceRef, String fileName, String taxonName, List<TaxonBase> taxa) { |
|
125 |
private void handleTaxa(Classification tree, Reference sourceRef, |
|
126 |
String fileName, String taxonName, List<TaxonBase> taxa) { |
|
137 | 127 |
|
138 | 128 |
Taxon taxon = getTaxon(tree, taxonName, taxa); |
139 | 129 |
TaxonDescription imageGallery = taxon.getOrCreateImageGallery(sourceRef == null ? null :sourceRef.getTitleCache()); |
... | ... | |
148 | 138 |
logger.error("IOException when handling image url"); |
149 | 139 |
} catch (HttpException e) { |
150 | 140 |
logger.error("HttpException when handling image url"); |
151 |
} |
|
141 |
} catch (URISyntaxException e) { |
|
142 |
logger.error("URISyntaxException when handling image url"); |
|
143 |
} |
|
152 | 144 |
} |
153 | 145 |
|
154 |
|
|
155 |
/** |
|
156 |
* @param fileName |
|
157 |
* @param taxonName |
|
158 |
* @return |
|
159 |
* @throws MalformedURLException |
|
160 |
* @throws IOException |
|
161 |
* @throws HttpException |
|
162 |
*/ |
|
163 |
private Media getMedia(String fileName, String taxonName) throws MalformedURLException, IOException, HttpException { |
|
146 |
private Media getMedia(String fileName, String taxonName) throws MalformedURLException, IOException, HttpException, URISyntaxException { |
|
164 | 147 |
String urlPrefix = "http://media.bgbm.org/erez/erez?src=EditWP6/photos/"; |
165 | 148 |
String urlString = urlPrefix + fileName; |
166 | 149 |
logger.info(urlString); |
167 |
URI uri = CdmUtils.string2Uri(urlString);
|
|
168 |
ImageInfo imageMetaData =ImageInfo.NewInstance(uri, 0);
|
|
150 |
URI uri = new URI(urlString);
|
|
151 |
CdmImageInfo imageMetaData = CdmImageInfo.NewInstance(uri, 0);
|
|
169 | 152 |
|
170 | 153 |
String mimeType = imageMetaData.getMimeType(); |
171 | 154 |
String suffix = null; |
... | ... | |
182 | 165 |
return media; |
183 | 166 |
} |
184 | 167 |
|
185 |
/** |
|
186 |
* @param tree |
|
187 |
* @param taxonName |
|
188 |
* @param taxa |
|
189 |
* @return |
|
190 |
*/ |
|
191 |
private Taxon getTaxon(Classification tree, String taxonName, |
|
168 |
private Taxon getTaxon(Classification tree, |
|
169 |
String taxonName, |
|
192 | 170 |
List<TaxonBase> taxa) { |
171 |
|
|
193 | 172 |
Taxon taxon = null; |
194 | 173 |
if(taxa.size() > 1) { |
195 | 174 |
if (logger.isDebugEnabled()) { |
196 | 175 |
logger.debug("multiple taxa with this name found: " + taxonName); |
197 | 176 |
} |
198 |
for (TaxonBase taxonBase : taxa) { |
|
177 |
for (TaxonBase<?> taxonBase : taxa) {
|
|
199 | 178 |
Taxon tax = (Taxon)taxonBase; |
200 | 179 |
if (tree.isTaxonInTree(tax)) { |
201 | 180 |
taxon = tax; |
Also available in: Unified diff
rename ImageInfo to CdmImageInfo and replace CdmUtils.str2uri