Project

General

Profile

« Previous | Next » 

Revision 10188

extract EML creator[s] and use those names or organizations when registering DOI with EZID. https://github.nceas.ucsb.edu/KNB/arctic-data/issues/143

View differences:

src/edu/ucsb/nceas/metacat/dataone/DOIService.java
24 24

  
25 25
import java.io.InputStream;
26 26
import java.text.SimpleDateFormat;
27
import java.util.ArrayList;
27 28
import java.util.Arrays;
28 29
import java.util.Calendar;
29 30
import java.util.Date;
30 31
import java.util.HashMap;
32
import java.util.List;
33
import java.util.Map;
31 34

  
35
import org.apache.commons.lang.StringUtils;
32 36
import org.apache.log4j.Logger;
33 37
import org.apache.wicket.protocol.http.mock.MockHttpServletRequest;
34 38
import org.dataone.client.v2.itk.D1Client;
......
51 55
import org.dataone.service.types.v1.util.AuthUtils;
52 56
import org.dataone.service.util.Constants;
53 57
import org.ecoinformatics.datamanager.parser.DataPackage;
58
import org.ecoinformatics.datamanager.parser.Party;
54 59
import org.ecoinformatics.datamanager.parser.generic.DataPackageParserInterface;
55 60
import org.ecoinformatics.datamanager.parser.generic.Eml200DataPackageParser;
56 61

  
......
159 164
				// enter metadata about this identifier
160 165
				HashMap<String, String> metadata = new HashMap<String, String>();
161 166
				
162
				// title 
163
				String title = ErcMissingValueCode.UNKNOWN.toString();
167
				// default values first
168
				metadata.put(DataCiteProfile.TITLE.toString(), ErcMissingValueCode.UNKNOWN.toString());
169
				metadata.put(DataCiteProfile.CREATOR.toString(), ErcMissingValueCode.UNKNOWN.toString());
170

  
171
				// now look up title and creators from EML content 
172
				Map<String, String> emlMetadata = null;
164 173
				try {
165
					title = lookupTitle(sysMeta);
174
					emlMetadata = this.lookupEMLMetadata(sysMeta);
175
					metadata.putAll(emlMetadata);
176

  
166 177
				} catch (Exception e) {
178
					// TODO Auto-generated catch block
167 179
					e.printStackTrace();
168
					// ignore
169 180
				}
170 181
				
171
				// creator
172
				String creator = sysMeta.getRightsHolder().getValue();
173
				try {
174
					creator = lookupCreator(sysMeta.getRightsHolder());
175
				} catch (Exception e) {
176
					// ignore and use default
177
				}
178
				
179 182
				// publisher
180 183
				String publisher = ErcMissingValueCode.UNKNOWN.toString();
181 184
				Node node = MNodeService.getInstance(null).getCapabilities();
......
225 228
				}
226 229
				
227 230
				// set the datacite metadata fields
228
				metadata.put(DataCiteProfile.TITLE.toString(), title);
229
				metadata.put(DataCiteProfile.CREATOR.toString(), creator);
230 231
				metadata.put(DataCiteProfile.PUBLISHER.toString(), publisher);
231 232
				metadata.put(DataCiteProfile.PUBLICATION_YEAR.toString(), year);
232 233
				metadata.put(DataCiteProfile.RESOURCE_TYPE.toString(), resourceType);
......
293 294
	 * @return appropriate title if known, or the missing value code
294 295
	 * @throws Exception
295 296
	 */
296
	private String lookupTitle(SystemMetadata sysMeta) throws Exception {
297
	private Map<String, String> lookupEMLMetadata(SystemMetadata sysMeta) throws Exception {
298
		
299
		Map<String, String> emlMetadata = new HashMap<String, String>();
300
		
297 301
		String title = ErcMissingValueCode.UNKNOWN.toString();
302
		List<String> people = new ArrayList<String>();
303

  
298 304
		if (sysMeta.getFormatId().getValue().startsWith("eml://")) {
299 305
			DataPackageParserInterface parser = new Eml200DataPackageParser();
300 306
			// for using the MN API as the MN itself
......
306 312
			parser.parse(emlStream);
307 313
			DataPackage dataPackage = parser.getDataPackage();
308 314
			title = dataPackage.getTitle();
315
			
316
			emlMetadata.put(DataCiteProfile.TITLE.toString(), title);
317

  
318
			// extract the creator[s]
319
			String creator = sysMeta.getRightsHolder().getValue();
320
			List<Party> creators = dataPackage.getCreators();
321
			if (creators != null) {
322
				for (Party party: creators) {
323
					String name = "";
324
					if (party.getSurName() != null) {
325
						name = party.getSurName();
326
						if (party.getGivenNames() != null && party.getGivenNames().size() > 0) {
327
							String givenNames = "";
328
							for (String givenName: party.getGivenNames()) {
329
								givenNames = givenName + " ";
330
							}
331
							name = givenNames + name;
332
						}
333
					} else {
334
						name = party.getOrganization();
335
					}
336
					
337
					people.add(name);
338
				}
339
				creator = StringUtils.join(people, ";");
340
			} else {
341
				try {
342
					// from SM
343
					creator = lookupCreator(sysMeta.getRightsHolder());
344
				} catch (Exception e) {
345
					// ignore and use default
346
				}
347
			}
348
			
349
			emlMetadata.put(DataCiteProfile.CREATOR.toString(), creator);
309 350
		}
310
		return title;
351
		return emlMetadata;
311 352
	}
312 353
	
313 354
	private String lookupResourceType(SystemMetadata sysMeta) {

Also available in: Unified diff