Revision 7516
Added by ben leinfelder over 11 years ago
test/tao.14563.1.xml | ||
---|---|---|
1 | 1 |
<?xml version="1.0" encoding="UTF-8"?> |
2 |
<eml:eml packageId="tao.14563.1" system="knb" xmlns:eml="eml://ecoinformatics.org/eml-2.1.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="eml://ecoinformatics.org/eml-2.1.0 eml.xsd"> <access authSystem="knb" order="allowFirst"> <allow><principal>public</principal> |
|
3 |
<permission>read</permission> |
|
4 |
</allow> |
|
5 |
</access> |
|
6 |
<dataset> <title>public-readable from morpho</title> |
|
7 |
<creator id="1320966812705"> <individualName><surName>adfasd</surName> |
|
8 |
|
|
9 |
</individualName> |
|
10 |
</creator> |
|
11 |
<abstract><para>adf</para> |
|
12 |
</abstract> |
|
13 |
<keywordSet><keyword>SAEON, South Africa</keyword> |
|
14 |
</keywordSet> |
|
15 |
<contact id="1320966816821"><individualName><surName>asdfdas</surName> |
|
16 |
</individualName> |
|
17 |
</contact> |
|
18 |
</dataset> |
|
19 |
</eml:eml> |
|
20 |
|
|
2 |
<eml:eml packageId="tao.14563.1" system="knb" |
|
3 |
xmlns:eml="eml://ecoinformatics.org/eml-2.1.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" |
|
4 |
xsi:schemaLocation="eml://ecoinformatics.org/eml-2.1.0 eml.xsd"> |
|
5 |
<access authSystem="knb" order="allowFirst"> |
|
6 |
<allow> |
|
7 |
<principal>public</principal> |
|
8 |
<permission>read</permission> |
|
9 |
</allow> |
|
10 |
</access> |
|
11 |
<dataset> |
|
12 |
<title>Test EML package - public-readable from morpho</title> |
|
13 |
<creator id="1320966812705"> |
|
14 |
<individualName> |
|
15 |
<surName>adfasd</surName> |
|
16 |
</individualName> |
|
17 |
</creator> |
|
18 |
<abstract> |
|
19 |
<para>adf</para> |
|
20 |
</abstract> |
|
21 |
<keywordSet> |
|
22 |
<keyword>SAEON, South Africa</keyword> |
|
23 |
</keywordSet> |
|
24 |
<contact id="1320966816821"> |
|
25 |
<individualName> |
|
26 |
<surName>asdfdas</surName> |
|
27 |
</individualName> |
|
28 |
</contact> |
|
29 |
</dataset> |
|
30 |
</eml:eml> |
test/edu/ucsb/nceas/metacat/dataone/RegisterDOITest.java | ||
---|---|---|
27 | 27 |
|
28 | 28 |
|
29 | 29 |
import java.io.ByteArrayInputStream; |
30 |
import java.io.FileInputStream; |
|
31 |
import java.io.FileNotFoundException; |
|
30 | 32 |
import java.io.InputStream; |
31 | 33 |
import java.util.HashMap; |
32 | 34 |
|
33 | 35 |
import junit.framework.Test; |
34 | 36 |
import junit.framework.TestSuite; |
35 | 37 |
|
38 |
import org.dataone.client.ObjectFormatCache; |
|
36 | 39 |
import org.dataone.configuration.Settings; |
37 | 40 |
import org.dataone.service.types.v1.Identifier; |
38 | 41 |
import org.dataone.service.types.v1.Session; |
42 |
import org.dataone.service.types.v1.Subject; |
|
39 | 43 |
import org.dataone.service.types.v1.SystemMetadata; |
40 | 44 |
import org.junit.After; |
41 | 45 |
import org.junit.Before; |
... | ... | |
53 | 57 |
*/ |
54 | 58 |
public class RegisterDOITest extends D1NodeServiceTest { |
55 | 59 |
|
56 |
/** |
|
57 |
* Set up the test fixtures |
|
58 |
* |
|
59 |
* @throws Exception |
|
60 |
*/ |
|
61 |
@Before |
|
62 |
public void setUp() throws Exception { |
|
63 |
super.setUp(); |
|
64 |
// set up the configuration for d1client |
|
65 |
Settings.getConfiguration().setProperty("D1Client.cnClassName", MockCNode.class.getName()); |
|
66 |
} |
|
60 |
|
|
61 |
|
|
62 |
/** |
|
63 |
* Set up the test fixtures |
|
64 |
* |
|
65 |
* @throws Exception |
|
66 |
*/ |
|
67 |
@Before |
|
68 |
public void setUp() throws Exception { |
|
69 |
super.setUp(); |
|
70 |
// set up the configuration for d1client |
|
71 |
Settings.getConfiguration().setProperty("D1Client.cnClassName", |
|
72 |
MockCNode.class.getName()); |
|
73 |
} |
|
67 | 74 |
|
68 |
/** |
|
69 |
* Remove the test fixtures |
|
70 |
*/ |
|
71 |
@After |
|
72 |
public void tearDown() { |
|
73 |
} |
|
74 |
|
|
75 |
/** |
|
76 |
* Build the test suite |
|
77 |
* @return |
|
78 |
*/ |
|
79 |
public static Test suite() { |
|
80 |
|
|
81 |
TestSuite suite = new TestSuite(); |
|
82 |
suite.addTest(new RegisterDOITest("initialize")); |
|
83 |
|
|
84 |
// DOI registration test |
|
85 |
suite.addTest(new RegisterDOITest("testCreateDOI")); |
|
86 |
suite.addTest(new RegisterDOITest("testMintAndCreateDOI")); |
|
75 |
/** |
|
76 |
* Remove the test fixtures |
|
77 |
*/ |
|
78 |
@After |
|
79 |
public void tearDown() { |
|
80 |
} |
|
87 | 81 |
|
88 |
return suite; |
|
89 |
|
|
90 |
} |
|
91 |
|
|
92 |
/** |
|
93 |
* Constructor for the tests |
|
94 |
* |
|
95 |
* @param name - the name of the test |
|
96 |
*/ |
|
97 |
public RegisterDOITest(String name) { |
|
98 |
super(name); |
|
99 |
|
|
100 |
} |
|
82 |
/** |
|
83 |
* Build the test suite |
|
84 |
* |
|
85 |
* @return |
|
86 |
*/ |
|
87 |
public static Test suite() { |
|
101 | 88 |
|
102 |
/** |
|
103 |
* Initial blank test |
|
104 |
*/ |
|
105 |
public void initialize() { |
|
106 |
assertTrue(1 == 1); |
|
107 |
|
|
108 |
} |
|
89 |
TestSuite suite = new TestSuite(); |
|
90 |
suite.addTest(new RegisterDOITest("initialize")); |
|
91 |
|
|
92 |
// DOI registration test |
|
93 |
suite.addTest(new RegisterDOITest("testCreateDOI")); |
|
94 |
suite.addTest(new RegisterDOITest("testMintAndCreateDOI")); |
|
95 |
suite.addTest(new RegisterDOITest("testMintAndCreateForEML")); |
|
96 |
|
|
97 |
return suite; |
|
98 |
|
|
99 |
} |
|
100 |
|
|
101 |
/** |
|
102 |
* Constructor for the tests |
|
103 |
* |
|
104 |
* @param name |
|
105 |
* - the name of the test |
|
106 |
*/ |
|
107 |
public RegisterDOITest(String name) { |
|
108 |
super(name); |
|
109 |
|
|
110 |
} |
|
111 |
|
|
112 |
/** |
|
113 |
* Initial blank test |
|
114 |
*/ |
|
115 |
public void initialize() { |
|
116 |
assertTrue(1 == 1); |
|
117 |
|
|
118 |
} |
|
119 |
|
|
120 |
/** |
|
121 |
* constructs a "fake" session with a test subject |
|
122 |
* @return |
|
123 |
*/ |
|
124 |
@Override |
|
125 |
public Session getTestSession() throws Exception { |
|
126 |
Session session = new Session(); |
|
127 |
Subject subject = new Subject(); |
|
128 |
subject.setValue("CN=Benjamin Leinfelder A515,O=University of Chicago,C=US,DC=cilogon,DC=org"); |
|
129 |
session.setSubject(subject); |
|
130 |
return session; |
|
131 |
} |
|
109 | 132 |
|
110 |
/** |
|
133 |
public void testMintAndCreateDOI() { |
|
134 |
printTestHeader("testMintAndCreateDOI"); |
|
135 |
testMintAndCreateDOI(null); |
|
136 |
} |
|
137 |
|
|
138 |
public void testMintAndCreateForEML() { |
|
139 |
printTestHeader("testMintAndCreateForEML"); |
|
140 |
String emlFile = "test/tao.14563.1.xml"; |
|
141 |
InputStream content = null; |
|
142 |
try { |
|
143 |
content = new FileInputStream(emlFile); |
|
144 |
} catch (FileNotFoundException e) { |
|
145 |
e.printStackTrace(); |
|
146 |
fail(e.getMessage()); |
|
147 |
} |
|
148 |
testMintAndCreateDOI(content); |
|
149 |
} |
|
150 |
|
|
151 |
/** |
|
111 | 152 |
* Test object creation |
112 | 153 |
*/ |
113 |
public void testMintAndCreateDOI() {
|
|
114 |
printTestHeader("testMintAndCreateDOI"); |
|
154 |
private void testMintAndCreateDOI(InputStream inputStream) {
|
|
155 |
printTestHeader("testMintAndCreateDOI - common");
|
|
115 | 156 |
|
116 | 157 |
try { |
117 | 158 |
// get ezid config properties |
... | ... | |
131 | 172 |
assertNotNull(metadata); |
132 | 173 |
|
133 | 174 |
// add the actual object for the newly-minted DOI |
134 |
InputStream object = new ByteArrayInputStream( "test".getBytes("UTF-8")); |
|
135 |
SystemMetadata sysmeta = createSystemMetadata(guid, session.getSubject(), object); |
|
175 |
SystemMetadata sysmeta = null; |
|
176 |
InputStream object = null; |
|
177 |
if (inputStream != null) { |
|
178 |
sysmeta = createSystemMetadata(guid, session.getSubject(), null); |
|
179 |
object = inputStream; |
|
180 |
sysmeta.setFormatId(ObjectFormatCache.getInstance().getFormat("eml://ecoinformatics.org/eml-2.1.0").getFormatId()); |
|
181 |
} else { |
|
182 |
object = new ByteArrayInputStream("test".getBytes("UTF-8")); |
|
183 |
sysmeta = createSystemMetadata(guid, session.getSubject(), object); |
|
184 |
} |
|
185 |
|
|
136 | 186 |
Identifier pid = MNodeService.getInstance(request).create(session, guid, object, sysmeta); |
137 | 187 |
assertEquals(guid.getValue(), pid.getValue()); |
138 | 188 |
|
... | ... | |
141 | 191 |
assertNotNull(metadata); |
142 | 192 |
assertTrue(metadata.containsKey(DataCiteProfile.TITLE.toString())); |
143 | 193 |
|
194 |
System.out.println("tested with DOI: " + pid.getValue()); |
|
195 |
|
|
144 | 196 |
} catch (Exception e) { |
145 | 197 |
e.printStackTrace(); |
146 | 198 |
fail("Unexpected error: " + e.getMessage()); |
src/edu/ucsb/nceas/metacat/dataone/DOIService.java | ||
---|---|---|
22 | 22 |
*/ |
23 | 23 |
package edu.ucsb.nceas.metacat.dataone; |
24 | 24 |
|
25 |
import java.io.InputStream; |
|
25 | 26 |
import java.text.SimpleDateFormat; |
27 |
import java.util.Arrays; |
|
28 |
import java.util.Collections; |
|
26 | 29 |
import java.util.HashMap; |
27 | 30 |
|
28 | 31 |
import org.apache.log4j.Logger; |
32 |
import org.apache.wicket.protocol.http.MockHttpServletRequest; |
|
33 |
import org.dataone.client.D1Client; |
|
34 |
import org.dataone.service.exceptions.InsufficientResources; |
|
29 | 35 |
import org.dataone.service.exceptions.InvalidRequest; |
36 |
import org.dataone.service.exceptions.InvalidToken; |
|
37 |
import org.dataone.service.exceptions.NotAuthorized; |
|
38 |
import org.dataone.service.exceptions.NotFound; |
|
30 | 39 |
import org.dataone.service.exceptions.NotImplemented; |
31 | 40 |
import org.dataone.service.exceptions.ServiceFailure; |
32 | 41 |
import org.dataone.service.types.v1.Identifier; |
33 | 42 |
import org.dataone.service.types.v1.Node; |
43 |
import org.dataone.service.types.v1.Permission; |
|
44 |
import org.dataone.service.types.v1.Person; |
|
45 |
import org.dataone.service.types.v1.Session; |
|
46 |
import org.dataone.service.types.v1.Subject; |
|
47 |
import org.dataone.service.types.v1.SubjectInfo; |
|
34 | 48 |
import org.dataone.service.types.v1.SystemMetadata; |
49 |
import org.dataone.service.types.v1.util.AuthUtils; |
|
50 |
import org.dataone.service.util.Constants; |
|
51 |
import org.ecoinformatics.datamanager.parser.DataPackage; |
|
52 |
import org.ecoinformatics.datamanager.parser.generic.DataPackageParserInterface; |
|
53 |
import org.ecoinformatics.datamanager.parser.generic.Eml200DataPackageParser; |
|
35 | 54 |
|
36 | 55 |
import edu.ucsb.nceas.ezid.EZIDException; |
37 | 56 |
import edu.ucsb.nceas.ezid.EZIDService; |
... | ... | |
131 | 150 |
// confuses the API if we send the original metadata that it gave us, so start from scratch |
132 | 151 |
metadata = new HashMap<String, String>(); |
133 | 152 |
|
134 |
// TODO: set title and creator to better values |
|
153 |
// title |
|
154 |
String title = ErcMissingValueCode.UNKNOWN.toString(); |
|
155 |
try { |
|
156 |
title = lookupTitle(sysMeta); |
|
157 |
} catch (Exception e) { |
|
158 |
e.printStackTrace(); |
|
159 |
// ignore |
|
160 |
} |
|
161 |
|
|
162 |
// creator |
|
163 |
String creator = sysMeta.getRightsHolder().getValue(); |
|
164 |
try { |
|
165 |
creator = lookupCreator(sysMeta.getRightsHolder()); |
|
166 |
} catch (Exception e) { |
|
167 |
// ignore and use default |
|
168 |
} |
|
169 |
|
|
170 |
// publisher |
|
171 |
String publisher = ErcMissingValueCode.UNKNOWN.toString(); |
|
135 | 172 |
Node node = MNodeService.getInstance(null).getCapabilities(); |
173 |
publisher = node.getName(); |
|
174 |
|
|
175 |
// publication year |
|
136 | 176 |
SimpleDateFormat sdf = new SimpleDateFormat("yyyy"); |
137 | 177 |
String year = sdf .format(sysMeta.getDateUploaded()); |
138 |
metadata.put(DataCiteProfile.TITLE.toString(), ErcMissingValueCode.UNKNOWN.toString()); |
|
139 |
metadata.put(DataCiteProfile.CREATOR.toString(), sysMeta.getRightsHolder().getValue()); |
|
140 |
metadata.put(DataCiteProfile.PUBLISHER.toString(), node.getName()); |
|
178 |
|
|
179 |
// type |
|
180 |
String resourceType = DataCiteProfileResourceTypeValues.DATASET.toString() + "/" + sysMeta.getFormatId().getValue(); |
|
181 |
|
|
182 |
// target (URL) |
|
183 |
String target = node.getBaseURL() + "/v1/object/" + identifier; |
|
184 |
|
|
185 |
// status and export fields for public/protected data |
|
186 |
String status = InternalProfileValues.UNAVAILABLE.toString(); |
|
187 |
String export = InternalProfileValues.NO.toString(); |
|
188 |
Subject publicSubject = new Subject(); |
|
189 |
publicSubject.setValue(Constants.SUBJECT_PUBLIC); |
|
190 |
if (AuthUtils.isAuthorized(Arrays.asList(new Subject[] {publicSubject}), Permission.READ, sysMeta)) { |
|
191 |
status = InternalProfileValues.PUBLIC.toString(); |
|
192 |
export = InternalProfileValues.YES.toString(); |
|
193 |
} |
|
194 |
|
|
195 |
// set the metadata fields |
|
196 |
metadata.put(DataCiteProfile.TITLE.toString(), title); |
|
197 |
metadata.put(DataCiteProfile.CREATOR.toString(), creator); |
|
198 |
metadata.put(DataCiteProfile.PUBLISHER.toString(), publisher); |
|
141 | 199 |
metadata.put(DataCiteProfile.PUBLICATION_YEAR.toString(), year); |
142 |
metadata.put(DataCiteProfile.RESOURCE_TYPE.toString(), DataCiteProfileResourceTypeValues.DATASET.toString() + "/" + sysMeta.getFormatId().getValue());
|
|
143 |
metadata.put(InternalProfile.TARGET.toString(), node.getBaseURL() + "/v1/object/" + identifier);
|
|
144 |
metadata.put(InternalProfile.STATUS.toString(), InternalProfileValues.PUBLIC.toString());
|
|
145 |
metadata.put(InternalProfile.EXPORT.toString(), InternalProfileValues.YES.toString());
|
|
200 |
metadata.put(DataCiteProfile.RESOURCE_TYPE.toString(), resourceType);
|
|
201 |
metadata.put(InternalProfile.TARGET.toString(), target);
|
|
202 |
metadata.put(InternalProfile.STATUS.toString(), status);
|
|
203 |
metadata.put(InternalProfile.EXPORT.toString(), export);
|
|
146 | 204 |
|
147 | 205 |
// set using the API |
148 | 206 |
if (create) { |
... | ... | |
212 | 270 |
|
213 | 271 |
return identifier; |
214 | 272 |
} |
273 |
|
|
274 |
/** |
|
275 |
* Locates an appropriate title for the object identified by the given SystemMetadata. |
|
276 |
* Different types of objects will be handled differently for titles: |
|
277 |
* 1. EML formats - parsed by the Datamanager library to find dataset title |
|
278 |
* 2. Data objects - TODO: use title from EML file that describes that data |
|
279 |
* 3. ORE objects - TODO: use title from EML file contained in that package |
|
280 |
* @param sysMeta |
|
281 |
* @return appropriate title if known, or the missing value code |
|
282 |
* @throws Exception |
|
283 |
*/ |
|
284 |
private String lookupTitle(SystemMetadata sysMeta) throws Exception { |
|
285 |
String title = ErcMissingValueCode.UNKNOWN.toString(); |
|
286 |
if (sysMeta.getFormatId().getValue().startsWith("eml://")) { |
|
287 |
DataPackageParserInterface parser = new Eml200DataPackageParser(); |
|
288 |
// for using the MN API as the MN itself |
|
289 |
MockHttpServletRequest request = new MockHttpServletRequest(null, null, null); |
|
290 |
Session session = new Session(); |
|
291 |
Subject subject = MNodeService.getInstance(request).getCapabilities().getSubject(0); |
|
292 |
session.setSubject(subject); |
|
293 |
InputStream emlStream = MNodeService.getInstance(request).get(session, sysMeta.getIdentifier()); |
|
294 |
parser.parse(emlStream); |
|
295 |
DataPackage dataPackage = parser.getDataPackage(); |
|
296 |
title = dataPackage.getTitle(); |
|
297 |
} |
|
298 |
return title; |
|
299 |
} |
|
215 | 300 |
|
301 |
/** |
|
302 |
* Lookup the citable name for the given Subject |
|
303 |
* Calls the configured CN to determine this information. |
|
304 |
* If the person is not registered with the CN identity service, |
|
305 |
* a NotFound exception will be raised as expected from the service. |
|
306 |
* @param subject |
|
307 |
* @return fullName if found |
|
308 |
* @throws ServiceFailure |
|
309 |
* @throws NotAuthorized |
|
310 |
* @throws NotImplemented |
|
311 |
* @throws NotFound |
|
312 |
* @throws InvalidToken |
|
313 |
*/ |
|
314 |
private String lookupCreator(Subject subject) throws ServiceFailure, NotAuthorized, NotImplemented, NotFound, InvalidToken { |
|
315 |
// default to given DN |
|
316 |
String fullName = subject.getValue(); |
|
317 |
|
|
318 |
SubjectInfo subjectInfo = D1Client.getCN().getSubjectInfo(subject); |
|
319 |
if (subjectInfo != null && subjectInfo.getPersonList() != null) { |
|
320 |
for (Person p: subjectInfo.getPersonList()) { |
|
321 |
if (p.getSubject().equals(subject)) { |
|
322 |
fullName = p.getFamilyName(); |
|
323 |
if (p.getGivenNameList() != null && p.getGivenNameList().size() > 0) { |
|
324 |
fullName = fullName + ", " + p.getGivenName(0); |
|
325 |
} |
|
326 |
break; |
|
327 |
} |
|
328 |
} |
|
329 |
} |
|
330 |
|
|
331 |
return fullName; |
|
332 |
|
|
333 |
} |
|
216 | 334 |
|
217 | 335 |
} |
Also available in: Unified diff
lookup the title for EML files when registering DOIs.
lookup the creator from DataONE CN (if available).
add EML-based test. http://bugzilla.ecoinformatics.org/show_bug.cgi?id=5513