Project

General

Profile

« Previous | Next » 

Revision 8794

use a member instance of ezid service that only logs in every 24 hours (or other time TBD) instead of every time there is an interaction with the service. Saves us many calls when doing batch updates to ezid but keeps us from trying to use expired sessions. Motivated by https://projects.ecoinformatics.org/ecoinfo/issues/6440

View differences:

src/edu/ucsb/nceas/metacat/dataone/DOIService.java
25 25
import java.io.InputStream;
26 26
import java.text.SimpleDateFormat;
27 27
import java.util.Arrays;
28
import java.util.Calendar;
29
import java.util.Date;
28 30
import java.util.HashMap;
29 31

  
30 32
import org.apache.log4j.Logger;
......
74 76

  
75 77
	private Logger logMetacat = Logger.getLogger(DOIService.class);
76 78

  
79
	private boolean doiEnabled = false;
80
	
81
	private String shoulder = null;
82
	
83
	private String ezidUsername = null;
84
	
85
	private String ezidPassword = null;
86
	
87
	private EZIDService ezid = null;
88
	
89
	private Date lastLogin = null;
90
	
91
	private long loginPeriod = 1 * 24 * 60 * 60 * 1000;
92

  
77 93
	private static DOIService instance = null;
78 94
	
79 95
	public static DOIService getInstance() {
......
88 104
	 */
89 105
	private DOIService() {
90 106
		
107
		// for DOIs
108
		String ezidServiceBaseUrl = null;
109
		
110
		try {
111
            doiEnabled = new Boolean(PropertyService.getProperty("guid.ezid.enabled")).booleanValue();
112
			shoulder = PropertyService.getProperty("guid.ezid.doishoulder.1");
113
			ezidServiceBaseUrl = PropertyService.getProperty("guid.ezid.baseurl");
114
			ezidUsername = PropertyService.getProperty("guid.ezid.username");
115
			ezidPassword = PropertyService.getProperty("guid.ezid.password");
116
		} catch (PropertyNotFoundException e) {
117
			logMetacat.warn("DOI support is not configured at this node.", e);
118
			return;
119
		}
120
		
121
		ezid = new EZIDService(ezidServiceBaseUrl);
122
		//ezid = new EZIDClient(ezidServiceBaseUrl);
123

  
124
		
125
		
91 126
	}
92 127
	
93 128
	/**
129
	 * Make sure we have a current login before making any calls
130
	 * @throws EZIDException
131
	 */
132
	private void refreshLogin() throws EZIDException {
133
		Date now = Calendar.getInstance().getTime();
134
		if (lastLogin == null || now.getTime() - lastLogin.getTime() > loginPeriod) {
135
			ezid.login(ezidUsername, ezidPassword);
136
			lastLogin = now;	
137
		}
138
	}
139
	
140
	/**
94 141
	 * submits DOI metadata information about the object to EZID
95 142
	 * @param sysMeta
96 143
	 * @return
......
99 146
	 * @throws NotImplemented 
100 147
	 */
101 148
	public boolean registerDOI(SystemMetadata sysMeta) throws EZIDException, NotImplemented, ServiceFailure {
102
		
103
		// for DOIs
104
		String ezidUsername = null;
105
		String ezidPassword = null;
106
		String shoulder = null;
107
		boolean doiEnabled = false;
108
		try {
109
            doiEnabled = new Boolean(PropertyService.getProperty("guid.ezid.enabled")).booleanValue();
110
			shoulder = PropertyService.getProperty("guid.ezid.doishoulder.1");
111
			ezidUsername = PropertyService.getProperty("guid.ezid.username");
112
			ezidPassword = PropertyService.getProperty("guid.ezid.password");
113
		} catch (PropertyNotFoundException e) {
114
			logMetacat.warn("DOI support is not configured at this node.", e);
115
			return false;
116
		}
117
		
149
				
118 150
		// only continue if we have the feature turned on
119 151
		if (doiEnabled) {
120 152
			
......
126 158
				// enter metadata about this identifier
127 159
				HashMap<String, String> metadata = null;
128 160
				
129
				// login to EZID service
130
				String ezidServiceBaseUrl = null;
131
				try {
132
					ezidServiceBaseUrl = PropertyService.getProperty("guid.ezid.baseurl");
133
				} catch (PropertyNotFoundException e) {
134
					logMetacat.warn("Using default EZID baseUrl");
135
				}
136
				EZIDService ezid = new EZIDService(ezidServiceBaseUrl);
137
				ezid.login(ezidUsername, ezidPassword);
161
				// make sure we have a current login
162
				this.refreshLogin();
138 163
				
139 164
				// check for existing metadata
140 165
				boolean create = false;
......
234 259
					ezid.setMetadata(identifier, metadata);
235 260
				}
236 261
				
237
				ezid.logout();
238 262
			}
239 263
			
240 264
		}
......
250 274
	 */
251 275
	public Identifier generateDOI() throws EZIDException, InvalidRequest {
252 276

  
253
		Identifier identifier = new Identifier();
254

  
255
		// look up configuration values
256
		String shoulder = null;
257
		String ezidUsername = null;
258
		String ezidPassword = null;
259
		boolean doiEnabled = false;
260
		try {
261
            doiEnabled = new Boolean(PropertyService.getProperty("guid.ezid.enabled")).booleanValue();
262
			shoulder = PropertyService.getProperty("guid.ezid.doishoulder.1");
263
			ezidUsername = PropertyService.getProperty("guid.ezid.username");
264
			ezidPassword = PropertyService.getProperty("guid.ezid.password");
265
		} catch (PropertyNotFoundException e1) {
266
			throw new InvalidRequest("2193", "DOI shoulder is not configured at this node.");
267
		}
268 277
		
269 278
		// only continue if we have the feature turned on
270 279
		if (!doiEnabled) {
......
280 289
		metadata.put(InternalProfile.STATUS.toString(), InternalProfileValues.RESERVED.toString());
281 290
		metadata.put(InternalProfile.EXPORT.toString(), InternalProfileValues.NO.toString());
282 291

  
292
		// make sure we have a current login
293
		this.refreshLogin();
294

  
283 295
		// call the EZID service
284
		String ezidServiceBaseUrl = null;
285
		try {
286
			ezidServiceBaseUrl = PropertyService.getProperty("guid.ezid.baseurl");
287
		} catch (PropertyNotFoundException e) {
288
			logMetacat.warn("Using default EZID baseUrl");
289
		}
290
		EZIDService ezid = new EZIDService(ezidServiceBaseUrl);
291
		ezid.login(ezidUsername, ezidPassword);
292 296
		String doi = ezid.mintIdentifier(shoulder, metadata);
297
		Identifier identifier = new Identifier();
293 298
		identifier.setValue(doi);
294
		ezid.logout();
295 299
		
296 300
		return identifier;
297 301
	}

Also available in: Unified diff