Project

General

Profile

« Previous | Next » 

Revision 4488

Added by daigle about 16 years ago

Add some generic typing

View differences:

src/edu/ucsb/nceas/metacat/MetacatReplication.java
43 43
import edu.ucsb.nceas.metacat.util.MetaCatUtil;
44 44
import edu.ucsb.nceas.metacat.util.SessionData;
45 45
import edu.ucsb.nceas.metacat.util.SystemUtil;
46
import edu.ucsb.nceas.utilities.FileUtil;
46 47
import edu.ucsb.nceas.utilities.GeneralPropertyException;
47 48
import edu.ucsb.nceas.utilities.PropertyNotFoundException;
48 49

  
......
57 58
  private Date firstTime;
58 59
  private boolean timedReplicationIsOn = false;
59 60
  Timer replicationDaemon;
60
  private Vector fileLocks = new Vector();
61
  private Vector<String> fileLocks = new Vector<String>();
61 62
  private Thread lockThread = null;
62 63
  public static final String FORCEREPLICATEDELETE = "forcereplicatedelete";
63 64
  private static final String TIMEREPLICATION = "replication.timedreplication";
......
137 138
  {
138 139
    //PrintWriter out = response.getWriter();
139 140
    //ServletOutputStream outPut = response.getOutputStream();
140
    Hashtable params = new Hashtable();
141
    Enumeration paramlist = request.getParameterNames();
141
    Hashtable<String, String[]> params = new Hashtable<String, String[]>();
142
    Enumeration<String> paramlist = request.getParameterNames();
142 143

  
143 144

  
144 145

  
......
371 372
   * servercontrol    delete               server
372 373
   * servercontrol    list
373 374
   */
374
  private void handleServerControlRequest(PrintWriter out, Hashtable params,
375
  private void handleServerControlRequest(PrintWriter out, Hashtable<String, String[]> params,
375 376
                                          HttpServletResponse response)
376 377
  {
377 378
    String subaction = ((String[])params.get("subaction"))[0];
......
601 602
	 * to the requesting server (remote server) for the specified docid. Then
602 603
	 * store it in local database.
603 604
	 */
604
  private void handleForceReplicateRequest(PrintWriter out, Hashtable params,
605
  private void handleForceReplicateRequest(PrintWriter out, Hashtable<String, String[]> params,
605 606
                                           HttpServletResponse response, HttpServletRequest request)
606 607
  {
607 608
    String server = ((String[])params.get("server"))[0]; // the server that
608 609
    String docid = ((String[])params.get("docid"))[0]; // sent the document
609 610
    String dbaction = "UPDATE"; // the default action is UPDATE
610
    boolean override = false;
611
    int serverCode = 1;
611
//    boolean override = false;
612
//    int serverCode = 1;
612 613
    DBConnection dbConn = null;
613 614
    int serialNumber = -1;
614 615

  
......
640 641
      DocInfoHandler dih = new DocInfoHandler();
641 642
      XMLReader docinfoParser = ReplicationHandler.initParser(dih);
642 643
      docinfoParser.parse(new InputSource(new StringReader(docInfoStr)));
643
      Hashtable docinfoHash = dih.getDocInfo();
644
//      Hashtable<String,Vector<AccessControlForSingleFile>> docinfoHash = dih.getDocInfo();
645
      Hashtable<String,String> docinfoHash = dih.getDocInfo();
644 646

  
645 647
      // Get user owner of this docid
646 648
      String user = (String)docinfoHash.get("user_owner");
......
690 692
      }
691 693

  
692 694
      //process extra access rules before dealing with the write exception (doc exist already)
693
      Vector accessControlList = (Vector) docinfoHash.get("accessControl");
695
      Vector<AccessControlForSingleFile> accessControlList = dih.getAccessControlList();
694 696
      if (accessControlList != null) {
695 697
    	  for (int i = 0; i < accessControlList.size(); i++) {
696 698
        	  AccessControlForSingleFile acfsf = (AccessControlForSingleFile) accessControlList.get(i);
......
730 732
 * when a forcereplication delete request comes in, local host will delete this
731 733
 * document
732 734
 */
733
private void handleForceReplicateDeleteRequest(PrintWriter out, Hashtable params,
735
private void handleForceReplicateDeleteRequest(PrintWriter out, Hashtable<String, String[]> params,
734 736
                                         HttpServletResponse response, HttpServletRequest request)
735 737
{
736 738
  String server = ((String[])params.get("server"))[0]; // the server that
......
764 766
   * readdata request to the requesting server (remote server) for the specified
765 767
   * docid. Then store it in local database and file system
766 768
   */
767
  private void handleForceReplicateDataFileRequest(Hashtable params, HttpServletRequest request)
769
  private void handleForceReplicateDataFileRequest(Hashtable<String, String[]> params, HttpServletRequest request)
768 770
  {
769 771

  
770 772
    //make sure there is some parameters
......
784 786
    }
785 787

  
786 788
    // Overide or not
787
    boolean override = false;
789
//    boolean override = false;
788 790
    // dbaction - update or insert
789 791
    String dbaction=null;
790 792

  
......
817 819
      DocInfoHandler dih = new DocInfoHandler();
818 820
      XMLReader docinfoParser = ReplicationHandler.initParser(dih);
819 821
      docinfoParser.parse(new InputSource(new StringReader(docInfoStr)));
820
      Hashtable docinfoHash = dih.getDocInfo();
822
      Hashtable<String,String> docinfoHash = dih.getDocInfo();
821 823
      String user = (String)docinfoHash.get("user_owner");
822 824

  
823 825
      String docName = (String)docinfoHash.get("docname");
......
863 865
        	writeException = e;
864 866
		}
865 867
        //process extra access rules
866
        Vector accessControlList = (Vector) docinfoHash.get("accessControl");
868
        Vector<AccessControlForSingleFile> accessControlList = dih.getAccessControlList();
867 869
        if (accessControlList != null) {
868 870
      	  for (int i = 0; i < accessControlList.size(); i++) {
869 871
          	  AccessControlForSingleFile acfsf = (AccessControlForSingleFile) accessControlList.get(i);
......
904 906
   * currentdate: the timestamp of the document on the remote server
905 907
   *
906 908
   */
907
  private void handleGetLockRequest(PrintWriter out, Hashtable params,
909
  private void handleGetLockRequest(PrintWriter out, Hashtable<String, String[]> params,
908 910
                                    HttpServletResponse response)
909 911
  {
910 912

  
......
960 962
   *                  user_updated, home_server, public_access, rev)/>
961 963
   * all of the subelements of document info are #PCDATA
962 964
   */
963
  private void handleGetDocumentInfoRequest(PrintWriter out, Hashtable params,
965
  private void handleGetDocumentInfoRequest(PrintWriter out, Hashtable<String, String[]> params,
964 966
                                        HttpServletResponse response)
965 967
  {
966 968
    String docid = ((String[])(params.get("docid")))[0];
......
992 994
      
993 995
      //permissions on the document
994 996
      PermissionController permController = new PermissionController(docid);
995
      Vector accessControlList = permController.getAccessControl();
997
      Vector<AccessControlForSingleFile> accessControlList = permController.getAccessControl();
996 998
      sb.append("<accessControl>");
997 999
      for (int i = 0; i < accessControlList.size(); i++) {
998 1000
    	  AccessControlForSingleFile acfsf = (AccessControlForSingleFile) accessControlList.get(i);
......
1018 1020
   * Sends a datafile to a remote host
1019 1021
   */
1020 1022
  private void handleGetDataFileRequest(OutputStream outPut,
1021
                            Hashtable params, HttpServletResponse response)
1023
                            Hashtable<String, String[]> params, HttpServletResponse response)
1022 1024

  
1023 1025
  {
1024 1026
    // File path for data file
......
1037 1039
    try
1038 1040
    {
1039 1041
      filepath = PropertyService.getProperty("application.datafilepath");
1040
      String server = ((String[])params.get("server"))[0];
1042
      String server = params.get("server")[0];
1041 1043
      URL u = new URL("https://" + server + "?server="
1042 1044
                +MetaCatUtil.getLocalReplicationServerName()
1043 1045
                +"&action=test");
......
1134 1136
  /**
1135 1137
   * Sends a document to a remote host
1136 1138
   */
1137
  private void handleGetDocumentRequest(PrintWriter out, Hashtable params,
1139
  private void handleGetDocumentRequest(PrintWriter out, Hashtable<String, String[]> params,
1138 1140
                                        HttpServletResponse response)
1139 1141
  {
1140 1142

  
......
1142 1144
    {
1143 1145
      //try to open a https stream to test if the request server's public key
1144 1146
      //in the key store, this is security issue
1145
      String server = ((String[])params.get("server"))[0];
1147
      String server = params.get("server")[0];
1146 1148
      URL u = new URL("https://" + server + "?server="
1147 1149
                +MetaCatUtil.getLocalReplicationServerName()
1148 1150
                +"&action=test");
......
1156 1158
        return;
1157 1159
      }
1158 1160

  
1159
      String docid = ((String[])(params.get("docid")))[0];
1160

  
1161
      String docid = params.get("docid")[0];
1161 1162
      DocumentImpl di = new DocumentImpl(docid);
1162
      response.setContentType("text/xml");
1163
      out.print(di.toString(null, null, true));
1163
      
1164
      String documentDir = PropertyService.getProperty("application.documentfilepath");
1165
      String documentPath = documentDir + FileUtil.getFS() + docid;
1166
      
1167
      // if the document does not exist on disk, read it from db and write
1168
      // it to disk.
1169
	  if (FileUtil.getFileStatus(documentPath) == FileUtil.DOES_NOT_EXIST) {
1170
	    FileWriter fileWriter = new FileWriter(documentPath);
1171
		di.toXml(fileWriter, null, null, true);
1172
	  }
1173
		
1174
	  // read the file from disk and sent it to PrintWriter
1175
//		PrintWriter out = new PrintWriter(streamOut);
1176
	  di.readFromFileSystem(out, null, null, documentPath);
1164 1177

  
1178
//      response.setContentType("text/xml");
1179
//      out.print(di.toString(null, null, true));
1180

  
1165 1181
      MetacatReplication.replLog("document " + docid + " sent");
1166 1182

  
1167 1183
    }
......
1192 1208
   * note that the rev in deletedDocument is always empty.  I just left
1193 1209
   * it in there to make the parser implementation easier.
1194 1210
   */
1195
  private void handleUpdateRequest(PrintWriter out, Hashtable params,
1211
  private void handleUpdateRequest(PrintWriter out, Hashtable<String, String[]> params,
1196 1212
                                    HttpServletResponse response)
1197 1213
  {
1198 1214
    // Checked out DBConnection
......
1258 1274
      // Store the deleted docid list
1259 1275
      StringBuffer delsql = new StringBuffer();
1260 1276
      // Store the data set file
1261
      Vector packageFiles = new Vector();
1277
      Vector<Vector<String>> packageFiles = new Vector<Vector<String>>();
1262 1278

  
1263 1279
      // Append local server's name and replication servlet to doclist
1264 1280
      doclist.append("<?xml version=\"1.0\"?><replication>");
......
1309 1325
        while(tablehasrows)
1310 1326
        {
1311 1327
          String recordDoctype = rs.getString(3);
1312
          Vector packagedoctypes = MetaCatUtil.getOptionList(
1328
          Vector<String> packagedoctypes = MetaCatUtil.getOptionList(
1313 1329
                                     PropertyService.getProperty("xml.packagedoctype"));
1314 1330
          //if this is a package file, put it at the end
1315 1331
          //because if a package file is read before all of the files it
......
1342 1358
          }//if packagedoctpes
1343 1359
          else
1344 1360
          { //the package files are saved to be put into the xml later.
1345
              Vector v = new Vector();
1346
              v.add(new String(rs.getString(1)));
1347
              v.add(new Integer(rs.getInt(2)));
1348
              packageFiles.add(new Vector(v));
1361
              Vector<String> v = new Vector<String>();
1362
              v.add(rs.getString(1));
1363
              v.add(String.valueOf(rs.getInt(2)));
1364
              packageFiles.add(v);
1349 1365
          }//esle
1350 1366
          tablehasrows = rs.next();
1351 1367
        }//while
......
1357 1373
          String recordDoctype = rs.getString(3);
1358 1374
          if(!recordDoctype.equals("BIN"))
1359 1375
          { //don't replicate data files
1360
            Vector packagedoctypes = MetaCatUtil.getOptionList(
1376
            Vector<String> packagedoctypes = MetaCatUtil.getOptionList(
1361 1377
                                     PropertyService.getProperty("xml.packagedoctype"));
1362 1378
            if(recordDoctype != null && !packagedoctypes.contains(recordDoctype))
1363 1379
            {   //if this is a package file, put it at the end
......
1371 1387
            }
1372 1388
            else
1373 1389
            { //the package files are saved to be put into the xml later.
1374
              Vector v = new Vector();
1375
              v.add(new String(rs.getString(1)));
1376
              v.add(new Integer(rs.getInt(2)));
1377
              packageFiles.add(new Vector(v));
1390
              Vector<String> v = new Vector<String>();
1391
              v.add(rs.getString(1));
1392
              v.add(String.valueOf(rs.getInt(2)));
1393
              packageFiles.add(v);
1378 1394
            }
1379 1395
         }//if
1380 1396
         tablehasrows = rs.next();
......
1399 1415
      //now we can put the package files into the xml results
1400 1416
      for(int i=0; i<packageFiles.size(); i++)
1401 1417
      {
1402
        Vector v = (Vector)packageFiles.elementAt(i);
1418
        Vector<String> v = packageFiles.elementAt(i);
1403 1419
        doclist.append("<updatedDocument>");
1404
        doclist.append("<docid>").append((String)v.elementAt(0));
1420
        doclist.append("<docid>").append(v.elementAt(0));
1405 1421
        doclist.append("</docid><rev>");
1406
        doclist.append(((Integer)v.elementAt(1)).intValue());
1422
        doclist.append(v.elementAt(1));
1407 1423
        doclist.append("</rev>");
1408 1424
        doclist.append("</updatedDocument>");
1409 1425
      }
......
1513 1529
   * If printFlag == false then do not print to out.
1514 1530
   */
1515 1531
  private static String handleGetCatalogRequest(PrintWriter out,
1516
                                                Hashtable params,
1532
                                                Hashtable<String, String[]> params,
1517 1533
                                                HttpServletResponse response,
1518 1534
                                                boolean printFlag)
1519 1535
  {
......
1597 1613
   * for replication gets rid of any problems with syncronizing clocks
1598 1614
   * because a time specific to a document is always kept on its home server.
1599 1615
   */
1600
  private void handleGetTimeRequest(PrintWriter out, Hashtable params,
1616
  private void handleGetTimeRequest(PrintWriter out, Hashtable<String, String[]> params,
1601 1617
                                    HttpServletResponse response)
1602 1618
  {
1603 1619
    SimpleDateFormat formatter = new SimpleDateFormat ("MM/dd/yy HH:mm:ss");
......
1756 1772
   * Method to get a host server information for given docid
1757 1773
   * @param conn a connection to the database
1758 1774
   */
1759
  public static Hashtable getHomeServerInfoForDocId(String docId)
1775
  public static Hashtable<String,String> getHomeServerInfoForDocId(String docId)
1760 1776
  {
1761
    Hashtable sl = new Hashtable();
1777
    Hashtable<String,String> sl = new Hashtable<String,String>();
1762 1778
    DBConnection dbConn = null;
1763 1779
    int serialNumber = -1;
1764 1780
    docId=MetaCatUtil.getDocIdFromString(docId);

Also available in: Unified diff