Project

General

Profile

« Previous | Next » 

Revision 1069

Added by Jing Tao about 22 years ago

Revised the method writeDataFile, writeReplication and writeToDB

View differences:

src/edu/ucsb/nceas/metacat/DocumentImpl.java
504 504
    }
505 505
    
506 506
    //make sure user have file lock grant(local metacat means have it too)
507
    if (getDataFileLockGrant(accnum))
508
    {
507
    //if (getDataFileLockGrant(accnum))
508
    //{
509 509
      //register data file into xml_documents table
510 510
      registerDocumentInReplication(docname, doctype, accnum, user, serverCode);
511 511
      //write inputstream into file system.
......
531 531
	    outPut.close();
532 532
	    fos.close();
533 533
    
534
    }//if
534
    //}//if
535 535
 }
536 536
  
537 537

  
......
1187 1187
      if (action.equals("INSERT")) {
1188 1188
        //AccessionNumber ac = new AccessionNumber();
1189 1189
        //this.docid = ac.generate(docid, "INSERT");
1190
        System.out.println("before pstmt");
1190 1191
        pstmt = conn.prepareStatement(
1191 1192
                "INSERT INTO xml_documents " +
1192 1193
                "(docid, rootnodeid, docname, doctype, " + 
......
1205 1206
        pstmt.setString(4, doctype);
1206 1207
        pstmt.setString(5, user);
1207 1208
        pstmt.setString(6, user);
1208
        if ( pub == null ) {
1209
        //public access is usefulless, so set it to null
1210
        pstmt.setString(7, null);
1211
        /*if ( pub == null ) {
1209 1212
          pstmt.setString(7, null);
1210 1213
        } else if ( pub.toUpperCase().equals("YES") || pub.equals("1") ) {
1211 1214
          pstmt.setInt(7, 1);
1212 1215
        } else if ( pub.toUpperCase().equals("NO") || pub.equals("0") ) {
1213 1216
          pstmt.setInt(7, 0);
1214
        }
1217
        }*/
1215 1218
        pstmt.setString(8, catalogid);
1216 1219
        pstmt.setInt(9, serverCode);
1217 1220
      } else if (action.equals("UPDATE")) {
......
1255 1258
        pstmt.setString(4, user);
1256 1259
        pstmt.setInt(5, serverCode);
1257 1260
        pstmt.setInt(6, thisrev);
1258
        if ( pub == null ) {
1261
        pstmt.setString(7, null);
1262
        /*if ( pub == null ) {
1259 1263
          pstmt.setString(7, null);
1260 1264
        } else if ( pub.toUpperCase().equals("YES") || pub.equals("1") ) {
1261 1265
          pstmt .setInt(7, 1);
1262 1266
        } else if ( pub.toUpperCase().equals("NO") || pub.equals("0") ) {
1263 1267
          pstmt.setInt(7, 0);
1264
        }
1268
        }*/
1265 1269
        pstmt.setString(8, catalogid);
1266 1270
        pstmt.setString(9, this.docid);
1267 1271

  
......
1271 1275

  
1272 1276
      // Do the insertion
1273 1277
      pstmt.execute();
1278
      System.out.println("after excecute");
1274 1279
      pstmt.close();
1275 1280

  
1276 1281
    } catch (SQLException sqle) {
......
1541 1546
  {
1542 1547
    // NEW - WHEN CLIENT ALWAYS PROVIDE ACCESSION NUMBER INCLUDING REV IN IT
1543 1548
    MetaCatUtil util = new MetaCatUtil();
1544
    AccessionNumber ac = new AccessionNumber(conn, accnum, action);
1545
    String docid = ac.getDocid();
1546
    String rev = ac.getRev();
1549
    //AccessionNumber ac = new AccessionNumber(conn, accnum, action);
1550
    //String docid = ac.getDocid();
1551
    // String rev = ac.getRev();
1552
    String docid=util.getDocIdFromString(accnum);
1553
    String rev=(new Integer(util.getVersionFromString(accnum))).toString();
1554
    
1555
    //check if xml_documents table has the document or not
1556
    //if not, set action to insert
1557
    if (getLatestRevisionNumber(conn,docid)==-1)
1558
    {
1559
      action="INSERT";
1560
    }
1561
    
1547 1562
    int serverCode=-2;
1548 1563
    //get server code for the home server
1549 1564
    serverCode=getServerCode(homeServer);
......
1558 1573
    MetaCatUtil.debugMessage("action: " + action + " servercode: " + 
1559 1574
                             serverCode, 10);
1560 1575
                        
1561
    if((serverCode != 1 && action.equals("UPDATE")) )
1562
    { //if this document being written is not a resident of this server then
1563
      //we need to try to get a lock from it's resident server.  If the
1564
      //resident server will not give a lock then we send the user a message
1565
      //saying that he/she needs to download a new copy of the file and
1566
      //merge the differences manually.
1576
    /*if((serverCode != 1 && action.equals("UPDATE")) )
1577
    { 
1567 1578
      int istreamInt; 
1568 1579
      char istreamChar;
1569 1580
      DocumentIdentifier id = new DocumentIdentifier(accnum);
......
1573 1584
      URL u = new URL("https://" + server + "?server="
1574 1585
           +util.getLocalReplicationServerName()+"&action=getlock&updaterev=" 
1575 1586
           +updaterev + "&docid=" + docid);
1576
      //System.out.println("sending message: " + u.toString());
1587
     
1577 1588
      String serverResStr = MetacatReplication.getURLContent(u);
1578 1589
      String openingtag =serverResStr.substring(0, serverResStr.indexOf(">")+1);
1579 1590
      if(openingtag.equals("<lockgranted>"))
1580
      {//the lock was granted go ahead with the insert
1591
      {
1581 1592
        try 
1582 1593
        {
1583
          //System.out.println("In lockgranted");
1594
          
1584 1595
          MetacatReplication.replLog("lock granted for " + accnum + " from " +
1585 1596
                                      server);
1586 1597
          XMLReader parser = initializeParser(conn, action, docid, updaterev,
......
1600 1611
      }
1601 1612

  
1602 1613
      else if(openingtag.equals("<filelocked>"))
1603
      {//the file is currently locked by another user
1604
       //notify our user to wait a few minutes, check out a new copy and try
1605
       //again.
1606
        //System.out.println("file locked");
1614
      {
1607 1615
        MetacatReplication.replLog("lock denied for " + accnum + " on " +
1608 1616
                                   server + " reason: file already locked");
1609 1617
        throw new Exception("The file specified is already locked by another " +
......
1612 1620
                            "again.");
1613 1621
      }
1614 1622
      else if(openingtag.equals("<outdatedfile>"))
1615
      {//our file is outdated.  notify our user to check out a new copy of the
1616
       //file and merge his version with the new version.
1617
        //System.out.println("outdated file");
1623
      {
1618 1624
        MetacatReplication.replLog("lock denied for " + accnum + " on " +
1619 1625
                                    server + " reason: local file outdated");
1620 1626
        throw new Exception("The file you are trying to update is an outdated" +
1621 1627
                            " version.  Please checkout the newest document, " +
1622 1628
                            "merge your changes and try again.");
1623 1629
      }
1624
    }
1630
    }*/
1625 1631
    
1626
    if ( action.equals("UPDATE") ) {
1627
      // check for 'write' permission for 'user' to update this document
1628

  
1632
    /*if ( action.equals("UPDATE") ) {
1633
      
1629 1634
      if ( !hasPermission(conn, user, groups, docid) ) {
1630 1635
        throw new Exception("User " + user + 
1631 1636
              " does not have permission to update XML Document #" + accnum);
1632 1637
      }          
1633
    }
1638
    }*/
1634 1639

  
1635 1640
    try 
1636 1641
    { 

Also available in: Unified diff