Project

General

Profile

« Previous | Next » 

Revision 8795

take advantage of the ezidclient for multi-threaded/asynchronous DOI registration. This will be most useful for doing large batch updates and not so much for the one-at-a-time publish actions but works in either context. https://projects.ecoinformatics.org/ecoinfo/issues/6440

View differences:

test/edu/ucsb/nceas/metacat/dataone/RegisterDOITest.java
180 180
			Identifier guid = MNodeService.getInstance(request).generateIdentifier(session, "DOI", null);
181 181
			
182 182
			// check that EZID knows about it
183
			HashMap<String, String> metadata = ezid.getMetadata(guid.getValue());
183
			HashMap<String, String> metadata = null;
184
			int count = 0;
185
			do {
186
				try {
187
					metadata = ezid.getMetadata(guid.getValue());
188
				} catch (Exception e) {
189
					Thread.sleep(1000);
190
				}
191
				count++;
192
			} while (metadata == null && count < 10);
184 193
			assertNotNull(metadata);
185 194

  
186 195
			// add the actual object for the newly-minted DOI
......
201 210
			assertEquals(guid.getValue(), pid.getValue());
202 211

  
203 212
			// check for the metadata for title element
204
			metadata = ezid.getMetadata(pid.getValue());
213
			count = 0;
214
			metadata = null;
215
			do {
216
				try {
217
					metadata = ezid.getMetadata(pid.getValue());
218
					// check if the update thread finished yet, otherwise try again
219
					if (metadata != null && isMetadata) {
220
						String registeredTarget = metadata.get(InternalProfile.TARGET.toString());
221
						if (!registeredTarget.endsWith("/#view/" + pid.getValue())) {
222
							// try fetching it again
223
							metadata = null;
224
						}
225
					}
226
				} catch (Exception e) {
227
					Thread.sleep(1000);
228
				}
229
				count++;
230
			} while (metadata == null && count < 10);
205 231
			assertNotNull(metadata);
206 232
			assertTrue(metadata.containsKey(DataCiteProfile.TITLE.toString()));
207 233
			
......
243 269
			// check for the metadata explicitly, using ezid service
244 270
			EZIDService ezid = new EZIDService(ezidServiceBaseUrl);
245 271
			ezid.login(ezidUsername, ezidPassword);
246
			HashMap<String, String> metadata = ezid.getMetadata(pid.getValue());
272
			int count = 0;
273
			HashMap<String, String> metadata = null;
274
			do {
275
				try {
276
					metadata = ezid.getMetadata(pid.getValue());
277
				} catch (Exception e) {
278
					Thread.sleep(1000);
279
				}
280
				count++;
281
			} while (metadata == null && count < 10);
282
			
247 283
			assertNotNull(metadata);
248 284
			assertTrue(metadata.containsKey(DataCiteProfile.TITLE.toString()));
249 285
			
......
288 324
	            // check for the metadata explicitly, using ezid service
289 325
	            EZIDService ezid = new EZIDService(ezidServiceBaseUrl);
290 326
	            ezid.login(ezidUsername, ezidPassword);
291
	            HashMap<String, String> metadata = ezid.getMetadata(publishedIdentifier.getValue());
327
	            int count = 0;
328
				HashMap<String, String> metadata = null;
329
				do {
330
					try {
331
						metadata = ezid.getMetadata(publishedIdentifier.getValue());
332
					} catch (Exception e) {
333
						Thread.sleep(1000);
334
					}
335
					count++;
336
				} while (metadata == null && count < 10);
337
	            
292 338
	            assertNotNull(metadata);
293 339
	            assertTrue(metadata.containsKey(DataCiteProfile.TITLE.toString()));
294 340
	            content.close();
src/edu/ucsb/nceas/metacat/dataone/MNodeService.java
397 397
            // attempt to register the identifier - it checks if it is a doi
398 398
            try {
399 399
    			DOIService.getInstance().registerDOI(sysmeta);
400
    		} catch (EZIDException e) {
400
    		} catch (Exception e) {
401 401
                throw new ServiceFailure("1190", "Could not register DOI: " + e.getMessage());
402 402
    		}
403 403

  
......
450 450
        // attempt to register the identifier - it checks if it is a doi
451 451
        try {
452 452
			DOIService.getInstance().registerDOI(sysmeta);
453
		} catch (EZIDException e) {
453
		} catch (Exception e) {
454 454
			ServiceFailure sf = new ServiceFailure("1190", "Could not register DOI: " + e.getMessage());
455 455
			sf.initCause(e);
456 456
            throw sf;
src/edu/ucsb/nceas/metacat/dataone/DOIService.java
53 53
import org.ecoinformatics.datamanager.parser.generic.DataPackageParserInterface;
54 54
import org.ecoinformatics.datamanager.parser.generic.Eml200DataPackageParser;
55 55

  
56
import edu.ucsb.nceas.ezid.EZIDClient;
56 57
import edu.ucsb.nceas.ezid.EZIDException;
57
import edu.ucsb.nceas.ezid.EZIDService;
58 58
import edu.ucsb.nceas.ezid.profile.DataCiteProfile;
59 59
import edu.ucsb.nceas.ezid.profile.DataCiteProfileResourceTypeValues;
60 60
import edu.ucsb.nceas.ezid.profile.ErcMissingValueCode;
......
84 84
	
85 85
	private String ezidPassword = null;
86 86
	
87
	private EZIDService ezid = null;
87
	private EZIDClient ezid = null;
88 88
	
89 89
	private Date lastLogin = null;
90 90
	
......
118 118
			return;
119 119
		}
120 120
		
121
		ezid = new EZIDService(ezidServiceBaseUrl);
122
		//ezid = new EZIDClient(ezidServiceBaseUrl);
121
		ezid = new EZIDClient(ezidServiceBaseUrl);
123 122

  
124 123
		
125 124
		
......
144 143
	 * @throws EZIDException 
145 144
	 * @throws ServiceFailure 
146 145
	 * @throws NotImplemented 
146
	 * @throws InterruptedException 
147 147
	 */
148
	public boolean registerDOI(SystemMetadata sysMeta) throws EZIDException, NotImplemented, ServiceFailure {
148
	public boolean registerDOI(SystemMetadata sysMeta) throws EZIDException, NotImplemented, ServiceFailure, InterruptedException {
149 149
				
150 150
		// only continue if we have the feature turned on
151 151
		if (doiEnabled) {
......
156 156
			if (identifier.startsWith(shoulder)) {
157 157
				
158 158
				// enter metadata about this identifier
159
				HashMap<String, String> metadata = null;
159
				HashMap<String, String> metadata = new HashMap<String, String>();
160 160
				
161
				// make sure we have a current login
162
				this.refreshLogin();
163
				
164
				// check for existing metadata
165
				boolean create = false;
166
				try {
167
					metadata = ezid.getMetadata(identifier);
168
				} catch (EZIDException e) {
169
					// expected much of the time
170
					logMetacat.warn("No metadata found for given identifier: " + e.getMessage());
171
				}
172
				if (metadata == null) {
173
					create = true;
174
				}
175
				// confuses the API if we send the original metadata that it gave us, so start from scratch
176
				metadata = new HashMap<String, String>();
177
				
178 161
				// title 
179 162
				String title = ErcMissingValueCode.UNKNOWN.toString();
180 163
				try {
......
252 235
				metadata.put(InternalProfile.STATUS.toString(), status);
253 236
				metadata.put(InternalProfile.EXPORT.toString(), export);
254 237
	
238
				// make sure we have a current login
239
				this.refreshLogin();
240
				
255 241
				// set using the API
256
				if (create) {
257
					ezid.createIdentifier(identifier, metadata);
258
				} else {
259
					ezid.setMetadata(identifier, metadata);
260
				}
242
				ezid.createOrUpdate(identifier, metadata);
261 243
				
262 244
			}
263 245
			

Also available in: Unified diff