Revision 6622
Added by ben leinfelder over 12 years ago
CNResourceHandler.java | ||
---|---|---|
29 | 29 |
import java.io.InputStream; |
30 | 30 |
import java.io.OutputStream; |
31 | 31 |
import java.util.Date; |
32 |
import java.util.Enumeration; |
|
32 | 33 |
import java.util.Map; |
33 | 34 |
|
34 | 35 |
import javax.servlet.ServletContext; |
... | ... | |
60 | 61 |
import org.dataone.service.types.v1.ObjectFormat; |
61 | 62 |
import org.dataone.service.types.v1.ObjectFormatIdentifier; |
62 | 63 |
import org.dataone.service.types.v1.ObjectFormatList; |
64 |
import org.dataone.service.types.v1.ObjectList; |
|
63 | 65 |
import org.dataone.service.types.v1.ObjectLocationList; |
64 | 66 |
import org.dataone.service.types.v1.Permission; |
65 | 67 |
import org.dataone.service.types.v1.Replica; |
66 | 68 |
import org.dataone.service.types.v1.ReplicationPolicy; |
67 | 69 |
import org.dataone.service.types.v1.ReplicationStatus; |
68 |
import org.dataone.service.types.v1.Session; |
|
69 | 70 |
import org.dataone.service.types.v1.Subject; |
70 | 71 |
import org.dataone.service.types.v1.SystemMetadata; |
71 | 72 |
import org.dataone.service.util.DateTimeMarshaller; |
... | ... | |
242 | 243 |
if (extra != null) { |
243 | 244 |
getObject(extra); |
244 | 245 |
} else { |
245 |
query();
|
|
246 |
listObjects();
|
|
246 | 247 |
} |
247 | 248 |
status = true; |
248 | 249 |
} else if (httpVerb == POST) { |
... | ... | |
666 | 667 |
logMetacat.warn("pid not specified"); |
667 | 668 |
} |
668 | 669 |
// call the implementation |
669 |
boolean result = CNodeService.getInstance(request).reserveIdentifier(session, pid);
|
|
670 |
Identifier resultPid = CNodeService.getInstance(request).reserveIdentifier(session, pid);
|
|
670 | 671 |
OutputStream out = response.getOutputStream(); |
671 | 672 |
response.setStatus(200); |
672 | 673 |
response.setContentType("text/xml"); |
673 |
// nothing to send back |
|
674 |
// send back the reserved pid |
|
675 |
TypeMarshaller.marshalTypeToOutputStream(resultPid, out); |
|
674 | 676 |
} |
675 | 677 |
|
676 | 678 |
/** |
... | ... | |
874 | 876 |
} |
875 | 877 |
|
876 | 878 |
/** |
877 |
* Pass to the CN search service
|
|
879 |
* List the objects
|
|
878 | 880 |
* |
879 | 881 |
* @throws NotImplemented |
880 | 882 |
* @throws InvalidRequest |
881 | 883 |
* @throws NotAuthorized |
882 | 884 |
* @throws ServiceFailure |
883 | 885 |
* @throws InvalidToken |
886 |
* @throws NotFound |
|
887 |
* @throws IOException |
|
888 |
* @throws JiBXException |
|
884 | 889 |
* @throws Exception |
885 | 890 |
*/ |
886 |
private void query() |
|
887 |
throws InvalidToken, ServiceFailure, NotAuthorized, InvalidRequest, NotImplemented { |
|
888 |
|
|
889 |
String query = null; |
|
890 |
String queryType = null; |
|
891 |
try { |
|
892 |
query = params.get("query")[0]; |
|
893 |
} catch (Exception e) { |
|
894 |
logMetacat.warn("query not specified"); |
|
895 |
} |
|
896 |
try { |
|
897 |
String qt = params.get("queryType")[0]; |
|
898 |
queryType = qt; |
|
899 |
} catch (Exception e) { |
|
900 |
logMetacat.warn("queryType not specified"); |
|
901 |
} |
|
902 |
|
|
903 |
// expecting to throw NotImplemented |
|
904 |
CNodeService.getInstance(request).search(session, queryType, query); |
|
905 |
} |
|
891 |
private void listObjects() throws InvalidToken, ServiceFailure, NotAuthorized, |
|
892 |
InvalidRequest, NotImplemented, NotFound, IOException, |
|
893 |
JiBXException { |
|
894 |
|
|
895 |
Date startTime = null; |
|
896 |
Date endTime = null; |
|
897 |
ObjectFormat objectFormat = null; |
|
898 |
boolean replicaStatus = false; |
|
899 |
int start = 0; |
|
900 |
int count = -1; |
|
901 |
Enumeration<String> paramlist = request.getParameterNames(); |
|
902 |
while (paramlist.hasMoreElements()) { |
|
903 |
// parse the params and make the call |
|
904 |
String name = paramlist.nextElement(); |
|
905 |
String[] value = request.getParameterValues(name); |
|
906 |
|
|
907 |
if (name.equals("startTime") && value != null) { |
|
908 |
try { |
|
909 |
startTime = DateTimeMarshaller.deserializeDateToUTC(value[0]); |
|
910 |
} catch (Exception e) { |
|
911 |
// if we can't parse it, just don't use the startTime param |
|
912 |
logMetacat.warn("Could not parse startTime: " + value[0]); |
|
913 |
startTime = null; |
|
914 |
} |
|
915 |
} else if (name.equals("endTime") && value != null) { |
|
916 |
try { |
|
917 |
endTime = DateTimeMarshaller.deserializeDateToUTC(value[0]); |
|
918 |
} catch (Exception e) { |
|
919 |
// if we can't parse it, just don't use the endTime param |
|
920 |
logMetacat.warn("Could not parse endTime: " + value[0]); |
|
921 |
endTime = null; |
|
922 |
} |
|
923 |
} else if (name.equals("objectFormat") && value != null) { |
|
924 |
objectFormat = ObjectFormatCache.getInstance().getFormat(value[0]); |
|
925 |
} else if (name.equals("replicaStatus") && value != null) { |
|
926 |
replicaStatus = Boolean.parseBoolean(value[0]); |
|
927 |
} else if (name.equals("start") && value != null) { |
|
928 |
start = Integer.valueOf(value[0]); |
|
929 |
} else if (name.equals("count") && value != null) { |
|
930 |
count = Integer.valueOf(value[0]); |
|
931 |
} |
|
932 |
} |
|
933 |
// make the call |
|
934 |
logMetacat.debug("session: " + session + " startTime: " + startTime |
|
935 |
+ " endtime: " + endTime + " objectFormat: " + objectFormat |
|
936 |
+ " replicaStatus: " + replicaStatus + " start: " + start |
|
937 |
+ " count: " + count); |
|
938 |
|
|
939 |
ObjectFormatIdentifier fmtid = null; |
|
940 |
if (objectFormat != null) { |
|
941 |
fmtid = objectFormat.getFormatId(); |
|
942 |
} |
|
943 |
|
|
944 |
// get the list |
|
945 |
ObjectList ol = |
|
946 |
CNodeService.getInstance(request).listObjects(session, |
|
947 |
startTime, endTime, fmtid, replicaStatus, start, count); |
|
948 |
|
|
949 |
// send it |
|
950 |
OutputStream out = response.getOutputStream(); |
|
951 |
response.setStatus(200); |
|
952 |
response.setContentType("text/xml"); |
|
953 |
// Serialize and write it to the output stream |
|
954 |
TypeMarshaller.marshalTypeToOutputStream(ol, out); |
|
955 |
} |
|
906 | 956 |
|
907 | 957 |
/** |
908 | 958 |
* Pass the request to get node replication authorization to CNodeService |
Also available in: Unified diff
upgrade to 1.0.1-SNAPSHOT DataONE jars