Revision 5370
Added by berkley almost 14 years ago
CrudService.java | ||
---|---|---|
70 | 70 |
import edu.ucsb.nceas.metacat.McdbException; |
71 | 71 |
import edu.ucsb.nceas.metacat.MetacatHandler; |
72 | 72 |
import edu.ucsb.nceas.metacat.client.InsufficientKarmaException; |
73 |
import edu.ucsb.nceas.metacat.client.rest.MetacatRestClient; |
|
73 | 74 |
import edu.ucsb.nceas.metacat.properties.PropertyService; |
74 | 75 |
import edu.ucsb.nceas.metacat.replication.ForceReplicationHandler; |
75 | 76 |
import edu.ucsb.nceas.metacat.service.SessionService; |
... | ... | |
166 | 167 |
} |
167 | 168 |
|
168 | 169 |
/** |
170 |
* Authenticate against metacat and get a token. |
|
171 |
* @param username |
|
172 |
* @param password |
|
173 |
* @return |
|
174 |
* @throws ServiceFailure |
|
175 |
*/ |
|
176 |
public AuthToken authenticate(String username, String password) |
|
177 |
throws ServiceFailure |
|
178 |
{ |
|
179 |
try |
|
180 |
{ |
|
181 |
MetacatRestClient restClient = new MetacatRestClient(getContextUrl()); |
|
182 |
String response = restClient.login(username, password); |
|
183 |
String sessionid = restClient.getSessionId(); |
|
184 |
SessionService sessionService = SessionService.getInstance(); |
|
185 |
sessionService.registerSession(new SessionData(sessionid, username, new String[0], password, "CrudServiceLogin")); |
|
186 |
AuthToken token = new AuthToken(sessionid); |
|
187 |
return token; |
|
188 |
} |
|
189 |
catch(Exception e) |
|
190 |
{ |
|
191 |
throw new ServiceFailure("1000", "Error authenticating with metacat: " + e.getMessage()); |
|
192 |
} |
|
193 |
} |
|
194 |
|
|
195 |
/** |
|
169 | 196 |
* set the parameter values needed for this request |
170 | 197 |
*/ |
171 | 198 |
public void setParameter(String name, String[] value) |
... | ... | |
292 | 319 |
String docid = im.getLocalId(id.getValue()); |
293 | 320 |
final SessionData sessionData = getSessionData(token); |
294 | 321 |
String permNum = "0"; |
295 |
if(permission == "read")
|
|
322 |
if(permission.equals("read"))
|
|
296 | 323 |
{ |
297 | 324 |
permNum = "4"; |
298 | 325 |
} |
299 |
else if(permission == "write")
|
|
326 |
else if(permission.equals("write"))
|
|
300 | 327 |
{ |
301 | 328 |
permNum = "6"; |
302 | 329 |
} |
... | ... | |
305 | 332 |
} |
306 | 333 |
catch(Exception e) |
307 | 334 |
{ |
335 |
e.printStackTrace(); |
|
308 | 336 |
throw new ServiceFailure("1000", "Could not set access on the document with id " + id.getValue()); |
309 | 337 |
} |
310 | 338 |
} |
... | ... | |
349 | 377 |
params.put("returndoctype", new String[] {"http://dataone.org/service/types/SystemMetadata/0.1"}); |
350 | 378 |
params.put("qformat", new String[] {"xml"}); |
351 | 379 |
params.put("returnfield", new String[] {"size", "originMemberNode", |
352 |
"identifier", "objectFormat", "dateSysMetadataModified", "checksum"}); |
|
380 |
"identifier", "objectFormat", "dateSysMetadataModified", "checksum", "@algorithm"});
|
|
353 | 381 |
params.put("anyfield", new String[] {"%"}); |
354 | 382 |
|
355 | 383 |
MetacatResultSet rs = handler.query(metacatUrl, params, sessionData.getUserName(), |
356 | 384 |
sessionData.getGroupNames(), sessionData.getId()); |
357 | 385 |
List docs = rs.getDocuments(); |
358 |
|
|
386 |
|
|
359 | 387 |
if(count == 1000) |
360 | 388 |
{ |
361 | 389 |
count = docs.size(); |
... | ... | |
392 | 420 |
//add the fields to the info object |
393 | 421 |
Checksum cs = new Checksum(); |
394 | 422 |
cs.setValue(d.getField("checksum")); |
423 |
String csalg = d.getField("algorithm"); |
|
424 |
if(csalg == null) |
|
425 |
{ |
|
426 |
csalg = "MD5"; |
|
427 |
} |
|
428 |
ChecksumAlgorithm ca = ChecksumAlgorithm.convert(csalg); |
|
429 |
cs.setAlgorithm(ca); |
|
395 | 430 |
info.setChecksum(cs); |
396 | 431 |
info.setDateSysMetadataModified(dateSysMetadataModified); |
397 | 432 |
Identifier id = new Identifier(); |
Also available in: Unified diff
listObjects is now working for rest calls as well as crud calls