24 |
24 |
|
25 |
25 |
import java.io.BufferedReader;
|
26 |
26 |
import java.io.IOException;
|
|
27 |
import java.io.InputStream;
|
27 |
28 |
import java.io.PrintWriter;
|
28 |
29 |
import java.util.Enumeration;
|
29 |
30 |
import java.util.Hashtable;
|
... | ... | |
33 |
34 |
import javax.servlet.http.HttpServletRequest;
|
34 |
35 |
import javax.servlet.http.HttpServletResponse;
|
35 |
36 |
|
|
37 |
import org.apache.commons.io.IOUtils;
|
36 |
38 |
import org.apache.log4j.Logger;
|
|
39 |
import org.dataone.service.exceptions.BaseException;
|
|
40 |
import org.dataone.service.exceptions.InvalidToken;
|
|
41 |
import org.dataone.service.exceptions.NotAuthorized;
|
|
42 |
import org.dataone.service.exceptions.NotFound;
|
|
43 |
import org.dataone.service.exceptions.NotImplemented;
|
|
44 |
import org.dataone.service.exceptions.ServiceFailure;
|
|
45 |
import org.dataone.service.types.AuthToken;
|
|
46 |
import org.dataone.service.types.IdentifierType;
|
37 |
47 |
|
38 |
48 |
import edu.ucsb.nceas.metacat.DBUtil;
|
39 |
49 |
import edu.ucsb.nceas.metacat.IdentifierManager;
|
40 |
50 |
import edu.ucsb.nceas.metacat.McdbDocNotFoundException;
|
41 |
51 |
import edu.ucsb.nceas.metacat.MetacatHandler;
|
|
52 |
import edu.ucsb.nceas.metacat.dataone.CrudService;
|
42 |
53 |
import edu.ucsb.nceas.metacat.util.RequestUtil;
|
43 |
54 |
import edu.ucsb.nceas.metacat.util.SessionData;
|
44 |
55 |
|
... | ... | |
437 |
448 |
}
|
438 |
449 |
|
439 |
450 |
/**
|
440 |
|
* Earthgrid API > Query Service > Get Function : calls MetacatHandler > handleReadAction
|
441 |
|
*
|
|
451 |
* Implements REST version of DataONE CRUD API --> get
|
442 |
452 |
* @param guid ID of data object to be read
|
443 |
453 |
*/
|
444 |
454 |
private void getObject(String guid) {
|
445 |
|
// Look up the localId for this global identifier
|
446 |
|
IdentifierManager im = IdentifierManager.getInstance();
|
447 |
|
String localId = "";
|
|
455 |
CrudService cs = new CrudService(servletContext, request, response);
|
|
456 |
AuthToken token = null;
|
448 |
457 |
try {
|
449 |
|
localId = im.getLocalId(guid);
|
450 |
|
} catch (McdbDocNotFoundException e) {
|
451 |
|
// TODO: Need to return the proper DataONE exception
|
|
458 |
InputStream data = cs.get(token, new IdentifierType(guid));
|
|
459 |
IOUtils.copyLarge(data, response.getOutputStream());
|
|
460 |
} catch (BaseException e) {
|
|
461 |
try {
|
|
462 |
// TODO: Use content negotiation to determine which return format to use
|
|
463 |
IOUtils.write(e.serialize(BaseException.FMT_XML),
|
|
464 |
response.getOutputStream());
|
|
465 |
} catch (IOException e1) {
|
|
466 |
logMetacat.error("Error writing service exception to stream. "
|
|
467 |
+ e1.getMessage());
|
|
468 |
}
|
|
469 |
} catch (IOException e) {
|
|
470 |
ServiceFailure sf = new ServiceFailure(1030, e.getMessage());
|
|
471 |
try {
|
|
472 |
IOUtils.write(sf.serialize(BaseException.FMT_XML),
|
|
473 |
response.getOutputStream());
|
|
474 |
} catch (IOException e1) {
|
|
475 |
logMetacat.error("Error writing service exception to stream. "
|
|
476 |
+ e1.getMessage());
|
|
477 |
}
|
452 |
478 |
}
|
453 |
|
|
454 |
|
// Now use that localId to read the object and return it
|
455 |
|
params.put("docid", new String[] { localId });
|
456 |
|
handler.handleReadAction(params, request, response, username, password,
|
457 |
|
groupNames);
|
458 |
479 |
}
|
459 |
480 |
|
460 |
481 |
/**
|
Modifications to metacat rest service to use the new DataONE CrudService for
get() operation. Minor issue with permissions errors propagating up the
stack, but otherwise this is the first implementation of a full DataONE
method.