Revision b9fdd7f4
Added by unknown about 7 years ago
app-import/src/main/java/eu/etaxonomy/cdm/io/ProtologueImport.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 |
*/ |
... | ... | |
22 | 22 |
import eu.etaxonomy.cdm.api.service.ICommonService; |
23 | 23 |
import eu.etaxonomy.cdm.app.wp6.palmae.config.PalmaeProtologueImportConfigurator; |
24 | 24 |
import eu.etaxonomy.cdm.common.CdmUtils; |
25 |
import eu.etaxonomy.cdm.io.common.CdmIoBase;
|
|
25 |
import eu.etaxonomy.cdm.io.common.CdmImportBase;
|
|
26 | 26 |
import eu.etaxonomy.cdm.io.common.DefaultImportState; |
27 | 27 |
import eu.etaxonomy.cdm.model.description.Feature; |
28 | 28 |
import eu.etaxonomy.cdm.model.description.TaxonNameDescription; |
... | ... | |
36 | 36 |
/** |
37 | 37 |
* @author a.mueller |
38 | 38 |
* @created 29.07.2008 |
39 |
* @version 1.0 |
|
40 | 39 |
*/ |
41 | 40 |
@Component |
42 |
public class ProtologueImport extends CdmIoBase<DefaultImportState<PalmaeProtologueImportConfigurator>> { |
|
43 |
private static final Logger logger = Logger.getLogger(ProtologueImport.class); |
|
41 |
public class ProtologueImport |
|
42 |
extends CdmImportBase<PalmaeProtologueImportConfigurator, DefaultImportState<PalmaeProtologueImportConfigurator>>{ |
|
43 |
|
|
44 |
private static final long serialVersionUID = 4580327331805229644L; |
|
45 |
private static final Logger logger = Logger.getLogger(ProtologueImport.class); |
|
44 | 46 |
|
45 | 47 |
private String pluralString = "protologues"; |
46 | 48 |
private static int modCount = 200; |
... | ... | |
49 | 51 |
super(); |
50 | 52 |
} |
51 | 53 |
|
52 |
public void doInvoke(DefaultImportState<PalmaeProtologueImportConfigurator> state){ |
|
54 |
@Override |
|
55 |
public void doInvoke(DefaultImportState<PalmaeProtologueImportConfigurator> state){ |
|
53 | 56 |
logger.info("start make Protologues from files ..."); |
54 |
|
|
57 |
|
|
55 | 58 |
Set<TaxonNameBase> nameStore = new HashSet<TaxonNameBase>(); |
56 |
|
|
59 |
|
|
57 | 60 |
PalmaeProtologueImportConfigurator config = state.getConfig(); |
58 | 61 |
File source = config.getSource(); |
59 | 62 |
TaxonNameBase name; |
... | ... | |
78 | 81 |
logger.info("end make Protologues from files ..."); |
79 | 82 |
return; |
80 | 83 |
} |
81 |
|
|
84 |
|
|
82 | 85 |
private void storeName(Set<TaxonNameBase> nameStore, TaxonNameBase name, DefaultImportState<PalmaeProtologueImportConfigurator> state){ |
83 | 86 |
if (name != null){ |
84 | 87 |
nameStore.add(name); |
... | ... | |
88 | 91 |
return; |
89 | 92 |
} |
90 | 93 |
} |
91 |
|
|
94 |
|
|
92 | 95 |
private TaxonNameBase importFile(File file, DefaultImportState<PalmaeProtologueImportConfigurator> state){ |
93 | 96 |
String originalSourceId = file.getName(); |
94 | 97 |
originalSourceId =originalSourceId.replace("_P.pdf", ""); |
95 | 98 |
originalSourceId =originalSourceId.replace("_tc_", "_tn_"); |
96 | 99 |
String namespace = state.getConfig().getOriginalSourceTaxonNamespace(); |
97 |
|
|
98 |
|
|
100 |
|
|
101 |
|
|
99 | 102 |
//for testing only |
100 | 103 |
TaxonNameBase taxonName = getTaxonName(originalSourceId, namespace); |
101 | 104 |
if (taxonName == null){ |
102 | 105 |
logger.warn("Name not found for " + originalSourceId); |
103 | 106 |
return null; |
104 | 107 |
} |
105 |
|
|
108 |
|
|
106 | 109 |
// TaxonNameDescription nameDescription = null; |
107 | 110 |
// if (taxonName.getDescriptions().size() > 0){ |
108 | 111 |
// nameDescription = (TaxonNameDescription)taxonName.getDescriptions().iterator().next(); |
... | ... | |
118 | 121 |
description.addElement(protolog); |
119 | 122 |
return taxonName; |
120 | 123 |
} |
121 |
|
|
124 |
|
|
122 | 125 |
}catch(NullPointerException e){ |
123 | 126 |
logger.warn("MediaUrl and/or MediaPath not set. Could not get protologue."); |
124 | 127 |
return null; |
125 | 128 |
} |
126 | 129 |
return null; |
127 |
|
|
130 |
|
|
128 | 131 |
} |
129 | 132 |
|
130 | 133 |
private TaxonNameDescription getNameDescription(TaxonNameBase taxonName) { |
... | ... | |
135 | 138 |
result = TaxonNameDescription.NewInstance(); |
136 | 139 |
taxonName.addDescription(result); |
137 | 140 |
} |
138 |
|
|
141 |
|
|
139 | 142 |
return result; |
140 | 143 |
} |
141 |
|
|
144 |
|
|
142 | 145 |
private Media getMedia(DefaultImportState<PalmaeProtologueImportConfigurator> state, File file){ |
143 | 146 |
try { |
144 | 147 |
//File file = (File)state.getConfig().getSource(); |
145 | 148 |
String url = file.toURI().toURL().toString(); |
146 |
String mimeTypePdf = "application/pdf";
|
|
147 |
String suffixPdf = "pdf";
|
|
148 |
String urlStringPdf = state.getConfig().getUrlString() + file.getName();
|
|
149 |
String mimeTypePdf = "application/pdf"; |
|
150 |
String suffixPdf = "pdf"; |
|
151 |
String urlStringPdf = state.getConfig().getUrlString() + file.getName(); |
|
149 | 152 |
URI uri = CdmUtils.string2Uri(urlStringPdf); |
150 | 153 |
Integer size = null; |
151 |
|
|
152 |
if (file.exists()){
|
|
154 |
|
|
155 |
if (file.exists()){ |
|
153 | 156 |
Media media = Media.NewInstance(); |
154 |
|
|
155 |
MediaRepresentation representationPdf = MediaRepresentation.NewInstance(mimeTypePdf, suffixPdf);
|
|
156 |
representationPdf.addRepresentationPart(MediaRepresentationPart.NewInstance(uri, size));
|
|
157 |
media.addRepresentation(representationPdf);
|
|
157 |
|
|
158 |
MediaRepresentation representationPdf = MediaRepresentation.NewInstance(mimeTypePdf, suffixPdf); |
|
159 |
representationPdf.addRepresentationPart(MediaRepresentationPart.NewInstance(uri, size)); |
|
160 |
media.addRepresentation(representationPdf); |
|
158 | 161 |
return media; |
159 | 162 |
}else{ |
160 | 163 |
return null; |
... | ... | |
163 | 166 |
logger.error(e.getMessage()); |
164 | 167 |
return null; |
165 | 168 |
} |
166 |
|
|
169 |
|
|
167 | 170 |
} |
168 |
|
|
171 |
|
|
169 | 172 |
private TaxonNameBase getTaxonName(String originalSourceId, String namespace){ |
170 | 173 |
TaxonNameBase result; |
171 | 174 |
ICommonService commonService = getCommonService(); |
172 |
|
|
175 |
|
|
173 | 176 |
result = (TaxonNameBase)commonService.getSourcedObjectByIdInSource(TaxonNameBase.class, originalSourceId , namespace); |
174 | 177 |
if (result == null){ |
175 | 178 |
logger.warn("Taxon (id: " + originalSourceId + ", namespace: " + namespace + ") could not be found"); |
176 | 179 |
} |
177 | 180 |
return result; |
178 | 181 |
} |
179 |
|
|
180 |
|
|
181 |
public boolean doCheck(DefaultImportState state){ |
|
182 |
|
|
183 |
|
|
184 |
@Override |
|
185 |
public boolean doCheck(DefaultImportState state){ |
|
182 | 186 |
boolean result = true; |
183 | 187 |
return result; |
184 | 188 |
} |
185 |
|
|
189 |
|
|
186 | 190 |
/* (non-Javadoc) |
187 | 191 |
* @see eu.etaxonomy.cdm.io.common.CdmIoBase#isIgnore(eu.etaxonomy.cdm.io.common.IImportConfigurator) |
188 | 192 |
*/ |
189 |
protected boolean isIgnore(DefaultImportState state){ |
|
193 |
@Override |
|
194 |
protected boolean isIgnore(DefaultImportState state){ |
|
190 | 195 |
return false; // ! state.getConfig(); |
191 | 196 |
} |
192 |
|
|
197 |
|
|
193 | 198 |
protected void doCount(int count, int modCount, String pluralString){ |
194 | 199 |
if ((count % modCount ) == 0 && count!= 0 ){ logger.info(pluralString + " handled: " + (count));} |
195 | 200 |
} |
Also available in: Unified diff
cleanup