Revision 6389
Added by ben leinfelder over 12 years ago
MNodeService.java | ||
---|---|---|
30 | 30 |
import java.text.SimpleDateFormat; |
31 | 31 |
import java.util.Date; |
32 | 32 |
import java.util.List; |
33 |
import java.util.Timer; |
|
33 | 34 |
|
34 | 35 |
import org.apache.commons.io.IOUtils; |
35 | 36 |
import org.apache.log4j.Logger; |
... | ... | |
86 | 87 |
import edu.ucsb.nceas.metacat.EventLog; |
87 | 88 |
import edu.ucsb.nceas.metacat.IdentifierManager; |
88 | 89 |
import edu.ucsb.nceas.metacat.McdbDocNotFoundException; |
90 |
import edu.ucsb.nceas.metacat.MetacatHandler; |
|
89 | 91 |
import edu.ucsb.nceas.metacat.client.InsufficientKarmaException; |
90 | 92 |
import edu.ucsb.nceas.metacat.database.DBConnection; |
91 | 93 |
import edu.ucsb.nceas.metacat.database.DBConnectionPool; |
... | ... | |
960 | 962 |
} |
961 | 963 |
|
962 | 964 |
/** |
963 |
* TODO: Implement this for D1 Tier 4 functionality
|
|
965 |
* Essentially a get() but with different logging behavior
|
|
964 | 966 |
*/ |
965 | 967 |
@Override |
966 | 968 |
public InputStream getReplica(Session session, Identifier pid) |
967 | 969 |
throws InvalidRequest, InvalidToken, NotAuthorized, NotImplemented, |
968 | 970 |
ServiceFailure, NotFound { |
971 |
|
|
972 |
InputStream inputStream = null; // bytes to be returned |
|
973 |
handler = new MetacatHandler(new Timer()); |
|
974 |
boolean allowed = false; |
|
975 |
String localId; // the metacat docid for the pid |
|
976 |
|
|
977 |
// get the local docid from Metacat |
|
978 |
try { |
|
979 |
localId = IdentifierManager.getInstance().getLocalId(pid.getValue()); |
|
980 |
} catch (McdbDocNotFoundException e) { |
|
981 |
throw new NotFound("1020", "The object specified by " + |
|
982 |
pid.getValue() + |
|
983 |
" does not exist at this node."); |
|
984 |
} |
|
985 |
|
|
986 |
// check for authorization |
|
987 |
allowed = isAuthorized(session, pid, Permission.READ); |
|
988 |
|
|
989 |
// if the person is authorized, perform the read |
|
990 |
if (allowed) { |
|
991 |
try { |
|
992 |
inputStream = handler.read(localId); |
|
993 |
} catch (Exception e) { |
|
994 |
throw new ServiceFailure("1020", "The object specified by " + |
|
995 |
pid.getValue() + |
|
996 |
"could not be returned due to error: " + |
|
997 |
e.getMessage()); |
|
998 |
} |
|
999 |
} |
|
969 | 1000 |
|
970 |
throw new NotImplemented("4870", "isReplicationAuthorized not implemented"); |
|
1001 |
// if we fail to set the input stream |
|
1002 |
if ( inputStream == null ) { |
|
1003 |
throw new NotFound("1020", "The object specified by " + |
|
1004 |
pid.getValue() + |
|
1005 |
"does not exist at this node."); |
|
1006 |
} |
|
1007 |
|
|
1008 |
// log the replica event |
|
1009 |
String principal = Constants.PUBLIC_SUBJECT; |
|
1010 |
if (session.getSubject() != null) { |
|
1011 |
principal = session.getSubject().getValue(); |
|
1012 |
} |
|
1013 |
EventLog.getInstance().log(null, principal, localId, "getreplica"); |
|
1014 |
|
|
1015 |
return inputStream; |
|
971 | 1016 |
} |
972 | 1017 |
|
973 | 1018 |
} |
Also available in: Unified diff
add getReplica() implementation. same as get() but with different logging. seems silly, but maybe I missed something important that distinguishes this method.