Revision 1490
Added by Jing Tao over 21 years ago
src/edu/ucsb/nceas/metacat/MetaCatServlet.java | ||
---|---|---|
843 | 843 |
try |
844 | 844 |
{ |
845 | 845 |
// read the params |
846 |
if (params.containsKey("dataid")) |
|
846 |
if (params.containsKey("inlinedataid"))
|
|
847 | 847 |
{ |
848 |
docs = (String[])params.get("dataid"); |
|
848 |
docs = (String[])params.get("inlinedataid");
|
|
849 | 849 |
}//if |
850 | 850 |
// Get the docid |
851 | 851 |
inlineDataId=docs[0]; |
852 | 852 |
// Make sure the client specify docid |
853 | 853 |
if (inlineDataId == null || inlineDataId.equals("")) |
854 | 854 |
{ |
855 |
// Get a printwriter |
|
856 |
PrintWriter pw = response.getWriter(); |
|
857 |
// Send back message |
|
858 |
pw.println("<?xml version=\"1.0\"?>"); |
|
859 |
pw.println("<error>"); |
|
860 |
pw.println("You didn't specify requested docid"); |
|
861 |
pw.println("</error>"); |
|
862 |
// Close printwriter |
|
863 |
pw.close(); |
|
864 |
return; |
|
855 |
throw new Exception("You didn't specify requested inlinedataid"); |
|
865 | 856 |
}//if |
866 | 857 |
|
867 | 858 |
// check for permission |
868 |
docId = MetaCatUtil.getDocIdWithRevFromInlineDataID(inlineDataId); |
|
859 |
docId = MetaCatUtil.getDocIdWithoutRevFromInlineDataID(inlineDataId); |
|
860 |
PermissionController controller = new PermissionController(docId); |
|
861 |
// check top level read permission |
|
862 |
if (!controller.hasPermission(user, groups, |
|
863 |
AccessControlInterface.READSTRING)) |
|
864 |
{ |
|
865 |
throw new Exception("User "+ user + " doesn't have permission "+ |
|
866 |
" to read document " + docId); |
|
867 |
}//if |
|
868 |
// if the document has subtree control, we need to check subtree control |
|
869 |
else if(controller.hasSubTreeAccessControl()) |
|
870 |
{ |
|
871 |
// get node id for inlinedata |
|
872 |
long nodeId=getInlineDataNodeId(inlineDataId, docId); |
|
873 |
if (!controller.hasPermissionForSubTreeNode(user, groups, |
|
874 |
AccessControlInterface.READSTRING, nodeId)) |
|
875 |
{ |
|
876 |
throw new Exception("User "+ user + " doesn't have permission "+ |
|
877 |
" to read inlinedata " + inlineDataId); |
|
878 |
}//if |
|
879 |
|
|
880 |
}//else |
|
869 | 881 |
|
870 | 882 |
// Get output stream |
871 | 883 |
out = response.getOutputStream(); |
... | ... | |
886 | 898 |
catch (Exception e) |
887 | 899 |
{ |
888 | 900 |
try |
889 |
{ |
|
901 |
{ |
|
902 |
PrintWriter pw = null; |
|
890 | 903 |
// Send error message back |
891 | 904 |
if (out != null) |
892 | 905 |
{ |
893 |
PrintWriter pw = new PrintWriter(out); |
|
894 |
pw.println("<?xml version=\"1.0\"?>"); |
|
895 |
pw.println("<error>"); |
|
896 |
pw.println(e.getMessage()); |
|
897 |
pw.println("</error>"); |
|
898 |
// Close printwriter |
|
899 |
pw.close(); |
|
900 |
// Close output stream |
|
901 |
out.close(); |
|
906 |
pw = new PrintWriter(out); |
|
902 | 907 |
}//if |
908 |
else |
|
909 |
{ |
|
910 |
pw = response.getWriter(); |
|
911 |
} |
|
912 |
pw.println("<?xml version=\"1.0\"?>"); |
|
913 |
pw.println("<error>"); |
|
914 |
pw.println(e.getMessage()); |
|
915 |
pw.println("</error>"); |
|
916 |
// Close printwriter |
|
917 |
pw.close(); |
|
918 |
// Close output stream if out is not null |
|
919 |
if (out != null) |
|
920 |
{ |
|
921 |
out.close(); |
|
922 |
} |
|
903 | 923 |
}//try |
904 | 924 |
catch (IOException ioe) |
905 | 925 |
{ |
... | ... | |
915 | 935 |
|
916 | 936 |
}//handleReadInlineDataAction |
917 | 937 |
|
938 |
/* |
|
939 |
* Get the nodeid from xml_nodes for the inlinedataid |
|
940 |
*/ |
|
941 |
private long getInlineDataNodeId(String inLineDataId, String docId) |
|
942 |
throws SQLException |
|
943 |
{ |
|
944 |
long nodeId = 0; |
|
945 |
String INLINE = "inline"; |
|
946 |
boolean hasRow; |
|
947 |
PreparedStatement pStmt = null; |
|
948 |
DBConnection conn = null; |
|
949 |
int serialNumber = -1; |
|
950 |
String sql ="SELECT nodeid FROM xml_nodes WHERE docid=? AND nodedata=? " + |
|
951 |
"AND nodetype='TEXT' AND parentnodeid IN " + |
|
952 |
"(SELECT nodeid FROM xml_nodes WHERE docid=? AND " + |
|
953 |
"nodetype='ELEMENT' AND nodename='" + INLINE + "')"; |
|
918 | 954 |
|
955 |
try |
|
956 |
{ |
|
957 |
//check out DBConnection |
|
958 |
conn=DBConnectionPool.getDBConnection("AccessControlList.isAllowFirst"); |
|
959 |
serialNumber=conn.getCheckOutSerialNumber(); |
|
960 |
|
|
961 |
pStmt = conn.prepareStatement(sql); |
|
962 |
//bind value |
|
963 |
pStmt.setString(1, docId);//docid |
|
964 |
pStmt.setString(2, inLineDataId);//inlinedataid |
|
965 |
pStmt.setString(3, docId); |
|
966 |
// excute query |
|
967 |
pStmt.execute(); |
|
968 |
ResultSet rs = pStmt.getResultSet(); |
|
969 |
hasRow=rs.next(); |
|
970 |
// get result |
|
971 |
if (hasRow) |
|
972 |
{ |
|
973 |
nodeId = rs.getLong(1); |
|
974 |
}//if |
|
975 |
|
|
976 |
}//try |
|
977 |
catch (SQLException e) |
|
978 |
{ |
|
979 |
throw e; |
|
980 |
} |
|
981 |
finally |
|
982 |
{ |
|
983 |
try |
|
984 |
{ |
|
985 |
pStmt.close(); |
|
986 |
} |
|
987 |
finally |
|
988 |
{ |
|
989 |
DBConnectionPool.returnDBConnection(conn, serialNumber); |
|
990 |
} |
|
991 |
} |
|
992 |
MetaCatUtil.debugMessage("The nodeid for inlinedataid " + inLineDataId + |
|
993 |
" is: "+nodeId, 35); |
|
994 |
return nodeId; |
|
995 |
} |
|
919 | 996 |
|
920 | 997 |
|
998 |
|
|
921 | 999 |
// READ SECTION |
922 | 1000 |
/** |
923 | 1001 |
* Handle the "read" request of metadata/data files from Metacat |
... | ... | |
2121 | 2199 |
out = response.getWriter(); |
2122 | 2200 |
} catch (IOException ioe2) { |
2123 | 2201 |
util.debugMessage("Fatal Error: couldn't get response "+ |
2124 |
"output stream.");
|
|
2202 |
"output stream.", 30);
|
|
2125 | 2203 |
} |
2126 | 2204 |
|
2127 | 2205 |
if ( action.equals("upload")) { |
Also available in: Unified diff
Finished the implementation for action readinlinedata. The prototype is action=readinlinedata&inlinedataid=eml.23.1.1