Project

General

Profile

« Previous | Next » 

Revision 8422c0cd

Added by Andreas Müller almost 8 years ago

Remove generics from Reference in cdmlib-app #5830

View differences:

app-import/src/main/java/eu/etaxonomy/cdm/io/wp6/CichorieaeImageImport.java
1 1
/**
2 2
* Copyright (C) 2007 EDIT
3
* European Distributed Institute of Taxonomy 
3
* European Distributed Institute of Taxonomy
4 4
* http://www.e-taxonomy.eu
5
* 
5
*
6 6
* The contents of this file are subject to the Mozilla Public License Version 1.1
7 7
* See LICENSE.TXT at the top of this package for the full license terms.
8 8
*/
......
23 23
import org.springframework.stereotype.Component;
24 24

  
25 25
import eu.etaxonomy.cdm.app.images.AbstractImageImporter;
26
import eu.etaxonomy.cdm.app.images.ImageImportConfigurator;
27 26
import eu.etaxonomy.cdm.app.images.ImageImportState;
28 27
import eu.etaxonomy.cdm.common.CdmUtils;
29 28
import eu.etaxonomy.cdm.common.media.ImageInfo;
......
47 46
@Component
48 47
public class CichorieaeImageImport extends AbstractImageImporter {
49 48
	private static final Logger logger = Logger.getLogger(CichorieaeImageImport.class);
50
	
51
	
52
	/** 
49

  
50

  
51
	/**
53 52
	 * Imports images from a directory.
54 53
	 */
55
	protected void invokeImageImport (ImageImportState state){
54
	@Override
55
    protected void invokeImageImport (ImageImportState state){
56 56
		File source = new File(state.getConfig().getSource());
57 57
		UUID treeUuid = state.getConfig().getClassificationUuid();
58 58
		Classification tree = classificationService.find(treeUuid);
59
		Reference<?> sourceRef = state.getConfig().getSourceReference();
60
		
59
		Reference sourceRef = state.getConfig().getSourceReference();
60

  
61 61
		if (source.isDirectory()){
62 62
			for (File file : source.listFiles() ){
63 63
				if (file.isFile()){
......
66 66
					if (taxonName == null){
67 67
						continue;
68 68
					}
69
					List<TaxonBase> taxa = taxonService.searchTaxaByName(taxonName, state.getConfig().getSourceReference());			
69
					List<TaxonBase> taxa = taxonService.searchTaxaByName(taxonName, state.getConfig().getSourceReference());
70 70
					if(taxa.size() == 0){
71 71
						logger.warn("no taxon with this name found: " + taxonName);
72 72
					} else {
......
75 75
				}else{
76 76
					logger.warn("File is not a file (but a directory?): " + file.getName());
77 77
				}
78
			}	
78
			}
79 79
		}else{
80 80
			logger.warn("Source is not a directory!" + source.toString());
81 81
		}
82
	
82

  
83 83
		return;
84
		
84

  
85 85
	}
86
	
86

  
87 87
	private String getTaxonName(String fileName){
88 88
		String[] fileNameParts = fileName.split("\\.");
89 89
		if (fileNameParts.length < 2){
......
91 91
			return null;
92 92
		}
93 93
		String extension = fileNameParts[fileNameParts.length - 1];
94
		if (! "jpg".equalsIgnoreCase(extension)) { 
94
		if (! "jpg".equalsIgnoreCase(extension)) {
95 95
			logger.warn("Extension not recognized: " + extension);
96 96
			// Sometimes occurs here "Thumbs.db"
97 97
			return null;
......
103 103
			logger.warn("name string has less than 2 '_'");
104 104
			return null;
105 105
		}
106
		
106

  
107 107
		String featureString = nameParts[nameParts.length-2];
108 108
		logger.debug("FeatureString: " +  featureString);
109 109
		String detailString = nameParts[nameParts.length-1];
110 110
		logger.debug("detailString: " +  detailString);
111
		
111

  
112 112
		String taxonName = "";
113 113
		for (int i= 0; i < nameParts.length-2; i++){
114 114
			taxonName += nameParts[i] + " ";
115 115
		}
116 116
		taxonName = taxonName.trim();
117 117
		logger.info("Taxon name: " +  taxonName);
118
		
118

  
119 119
		String _s_ = " s ";
120 120
		String subsp = " subsp. ";
121 121
		if (taxonName.contains(_s_)) {
......
134 134
	 * @param taxa
135 135
	 * @param taxon
136 136
	 */
137
	private void handleTaxa(Classification tree, Reference<?> sourceRef, String fileName, String taxonName, List<TaxonBase> taxa) {
138
		
137
	private void handleTaxa(Classification tree, Reference sourceRef, String fileName, String taxonName, List<TaxonBase> taxa) {
138

  
139 139
		Taxon taxon = getTaxon(tree, taxonName, taxa);
140 140
		TaxonDescription imageGallery = taxon.getOrCreateImageGallery(sourceRef == null ? null :sourceRef.getTitleCache());
141 141
		TextData textData = imageGallery.getOrCreateImageTextData();
......
155 155

  
156 156
	/**
157 157
	 * @param fileName
158
	 * @param taxonName 
158
	 * @param taxonName
159 159
	 * @return
160 160
	 * @throws MalformedURLException
161
	 * @throws IOException 
162
	 * @throws HttpException 
161
	 * @throws IOException
162
	 * @throws HttpException
163 163
	 */
164 164
	private Media getMedia(String fileName, String taxonName) throws MalformedURLException, IOException, HttpException {
165 165
		String urlPrefix = "http://media.bgbm.org/erez/erez?src=EditWP6/photos/";
......
168 168
		URL url = new URL(urlString);
169 169
		URI uri = CdmUtils.string2Uri(urlString);
170 170
		ImageInfo imageMetaData =ImageInfo.NewInstance(uri, 0);
171
		
171

  
172 172
		//String uri = url.toString();
173
		
173

  
174 174
		String mimeType = imageMetaData.getMimeType();
175 175
		String suffix = null;
176 176
		int height = imageMetaData.getHeight();
......
178 178
		Integer size = null;
179 179
		DateTime mediaCreated = null;
180 180
		AgentBase<?> artist = null;
181
		
181

  
182 182
//		ImageFile image = ImageFile.NewInstance(uri, size, height, width);
183 183
		Media media = ImageFile.NewMediaInstance(mediaCreated, artist, uri, mimeType, suffix, size, height, width);
184 184
		media.putTitle(LanguageString.NewInstance(taxonName, Language.LATIN()));
185
		
185

  
186 186
		return media;
187 187
	}
188 188

  

Also available in: Unified diff