Project

General

Profile

1
/**
2
 *  '$RCSfile$'
3
 *  Copyright: 2000 Regents of the University of California and the
4
 *              National Center for Ecological Analysis and Synthesis
5
 *    Authors: @tao@
6
 *    Release: @release@
7
 *
8
 *   '$Author: tao $'
9
 *     '$Date: 2002-11-05 10:00:53 -0800 (Tue, 05 Nov 2002) $'
10
 * '$Revision: 1326 $'
11
 *
12
 * This program is free software; you can redistribute it and/or modify
13
 * it under the terms of the GNU General Public License as published by
14
 * the Free Software Foundation; either version 2 of the License, or
15
 * (at your option) any later version.
16
 *
17
 * This program is distributed in the hope that it will be useful,
18
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
20
 * GNU General Public License for more details.
21
 *
22
 * You should have received a copy of the GNU General Public License
23
 * along with this program; if not, write to the Free Software
24
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
25
 */
26

    
27
package edu.ucsb.nceas.metacat;
28

    
29
import edu.ucsb.nceas.morpho.datapackage.PackageUtil;
30
import edu.ucsb.nceas.morpho.datapackage.Triple;
31
import edu.ucsb.nceas.morpho.datapackage.TripleCollection;
32

    
33
import java.io.FileOutputStream;
34
import java.io.PrintWriter;
35
import java .io.StringReader;
36
import java.sql.ResultSet;
37
import java.sql.PreparedStatement;
38
import java.sql.SQLException;
39
import java.util.Vector;
40

    
41
import org.apache.xerces.parsers.DOMParser;
42
import org.apache.xpath.XPathAPI;
43
import org.w3c.dom.Attr;
44
import org.w3c.dom.NamedNodeMap;
45
import org.w3c.dom.NodeList;
46
import org.w3c.dom.Document;
47
import org.w3c.dom.Node;
48
import org.w3c.dom.NodeList;
49
import org.w3c.dom.DocumentType;
50
import org.xml.sax.InputSource;
51

    
52

    
53

    
54
/**
55
 * This class is used to clean up access table in knb. It will delete any access
56
 * control rules which are not in access xml doc (someone add them into table
57
 * directly). It will update data set doc according new triples in access table.
58
 */
59

    
60
public class CleanupAccessTable
61
{
62
  /**
63
   * A method to add a new triple to a data set doc and update data set doc
64
   * in metacat db
65
   *
66
   * @param accessionNumber  the accession number of the data set doc
67
   * @param newTripleVector  the vector containing new triples need to be added 
68
   *                      into the data set doc
69
   */
70
  private static final String TRIPLESTAG = "//triple";
71
  private static final String IDENTIFIER = "//identifier";
72
  private static final String RELATIONSHIP = "provides access control rules for";
73
  public  static final String DELIMITER = "!";
74
  private static final String DOT = ".";
75
  private static final String LOGFILENAME = "log";
76
  
77
  public static void addNewTripleIntoDataset(String accessionNumber, 
78
                                             Vector newTripleVector)
79
  {
80
    String docidWithoutVersion = null;
81
    int rev = 0;
82
    // check parameter
83
    if (newTripleVector.size()==0 || accessionNumber == null || 
84
        accessionNumber.equals(""))
85
    {
86
      return;
87
    }
88
    
89
    DocumentImpl doc = null;
90
    try
91
    {
92
      docidWithoutVersion = MetaCatUtil.getDocIdFromString(accessionNumber); 
93
      rev = MetaCatUtil.getVersionFromString(accessionNumber);
94
      doc = new DocumentImpl(accessionNumber);
95
    }
96
    catch (Exception e)
97
    {
98
      MetaCatUtil.debugMessage("error in create an document: "
99
                              + e.getMessage(), 30);
100
      return;
101
    }
102
    String xmlDoc = doc.toString();
103
    //System.out.println("orginal xml file: "+xmlDoc);
104
    // create new triple collection
105
    TripleCollection newTripleForDataSet = new TripleCollection();
106
    for (int i = 0; i<newTripleVector.size(); i++)
107
    {
108
      //Add new tripe
109
      Triple triple = (Triple)newTripleVector.elementAt(i);
110
      System.out.println("New triple: "+triple.toString());
111
      newTripleForDataSet.addTriple(triple);
112
    }
113
    xmlDoc = addTriplesToTriplesString(newTripleForDataSet, xmlDoc, TRIPLESTAG);
114
   
115
    // Update accessNumber
116
    Vector oldAccessNumberVector = new Vector();
117
    Vector newAccessNumberVector = new Vector();
118
    oldAccessNumberVector.addElement(accessionNumber);
119
    //increase rev number
120
    rev++;
121
    accessionNumber = docidWithoutVersion + "." + rev;
122
    newAccessNumberVector.addElement(accessionNumber);
123
    xmlDoc = incRevInTriples(xmlDoc, oldAccessNumberVector, 
124
                             newAccessNumberVector, TRIPLESTAG);
125
    
126
  
127
    // update database
128
    StringReader xml = new StringReader(xmlDoc);
129
    String pub = "no";
130
    StringReader dtd = null;
131
    String doAction = "UPDATE";
132
    boolean validate = true;
133
    DBConnection dbConn = null;
134
    int serialNumber = -1;
135
    try
136
    {
137
      dbConn=DBConnectionPool.
138
                  getDBConnection("DBQuery.getDataPackageId");
139
      serialNumber=dbConn.getCheckOutSerialNumber();
140
      DocumentImpl.write(dbConn, xml, pub, dtd, doAction,
141
                       accessionNumber, null, null, validate);
142
      System.out.println("update data set file: "+ accessionNumber);
143
      writeToLogFile("Update data set file: " + accessionNumber);
144
      writeToLogFile("New triples added are: "+ newTripleVector.toString());
145
    }
146
    catch (Exception e)
147
    {
148
      System.out.println("error in addNewTripleIntoDataset: "+e.getMessage());
149
    }
150
    finally
151
    {
152
      DBConnectionPool.returnDBConnection(dbConn, serialNumber);
153
    }
154
    
155
  }
156
  
157
    /**
158
   * method to add a collection of triples to a triples string.  this method
159
   * searches for any triples already in the string and appends the new
160
   * ones after the existing ones.  
161
   * @param triples the collection of triples to add
162
   * @param dataPackageString the xml document of data set
163
   * @param triplesTag the trip tag in xml docment
164
   */
165
  private static String addTriplesToTriplesString(TripleCollection triples,
166
                                               String dataPackageString, 
167
                                               String triplesTag)
168
  {
169
    //String triplesTag = morpho.getConfiguration().get("triplesTag", 0);
170
    Document doc = null;
171
    DOMParser parser = new DOMParser();
172
    InputSource in;
173
    StringReader sr;
174
    try
175
    { //parse the wizard created file with existing triples
176
      sr = new StringReader(dataPackageString);
177
      in = new InputSource(sr);
178
    }
179
    catch(Exception fnf)
180
    {
181
      fnf.printStackTrace();
182
      return null;
183
    }
184
    try
185
    {
186
      parser.parse(in);
187
      sr.close();
188
    }
189
    catch(Exception e1)
190
    {
191
      System.err.println(e1.toString());
192
    }
193
    doc = parser.getDocument();
194
    //get the DOM rep of the document with existing triples
195
    NodeList tripleNodeList = triples.getNodeList();
196
    NodeList docTriplesNodeList = null;
197
    
198
    try
199
    {
200
      //find where the triples go in the file
201
      docTriplesNodeList = XPathAPI.selectNodeList(doc, triplesTag);
202
    }
203
    catch(Exception se)
204
    {
205
      System.err.println(se.toString());
206
    }
207
    
208
    Node docNode = doc.getDocumentElement();
209
    for(int j=0; j<tripleNodeList.getLength(); j++)
210
    { //add the triples to the appropriate position in the file
211
      Node n = doc.importNode(tripleNodeList.item(j), true);
212
      int end = docTriplesNodeList.getLength() - 1;
213
      Node triplesNode = docTriplesNodeList.item(end);
214
      Node parent = triplesNode.getParentNode();
215
      if(triplesNode.getNextSibling() == null)
216
      {
217
        parent.appendChild(n);
218
      }
219
      else
220
      {
221
        parent.insertBefore(n, triplesNode.getNextSibling());
222
      }
223
    }
224
    
225
    String docString = PackageUtil.printDoctype(doc);
226
    docString += PackageUtil.print(doc.getDocumentElement());
227
    return docString;
228
  }
229
  
230
  
231
  
232
  private static String incRevInTriples(String xml, Vector oldid, 
233
                                        Vector newid, String triplePath)
234
  {
235
    System.out.println("oldid: " + oldid.toString() + " newid: " + newid.toString());
236
    Document doc = null;
237
    DOMParser parser = new DOMParser();
238
    InputSource in;
239
    StringReader sr;
240
     try
241
    { //parse the wizard created file with existing triples
242
      sr = new StringReader(xml);
243
      in = new InputSource(sr);
244
    }
245
    catch(Exception fnf)
246
    {
247
      fnf.printStackTrace();
248
      return null;
249
    }
250
    try
251
    {
252
      parser.parse(in);
253
      sr.close();
254
    }
255
    catch(Exception e1)
256
    {
257
      System.err.println(e1.toString());
258
    }
259
    
260
    doc = parser.getDocument();
261
    NodeList tripleList = null;
262
    try
263
    {
264
      //find where the triples go in the file
265
      tripleList = XPathAPI.selectNodeList(doc, triplePath);
266
    }
267
    catch(Exception se)
268
    {
269
      System.err.println("incRevInTriples() : parse threw: " + 
270
                         se.toString());
271
    }
272
    
273
    for(int i=0; i<tripleList.getLength(); i++)
274
    {
275
      Node triple = tripleList.item(i);
276
      NodeList children = triple.getChildNodes();
277
      String sub = null;
278
      String rel = null;
279
      String obj = null;
280
      if(children.getLength() > 2)
281
      {
282
        for(int j=0; j<children.getLength(); j++)
283
        {
284
          Node childNode = children.item(j);
285
          String nodename = childNode.getNodeName().trim().toUpperCase();
286
          if(nodename.equals("SUBJECT") || nodename.equals("OBJECT"))
287
          {
288
            String nodeval;
289
            try
290
            {
291
              nodeval = childNode.getFirstChild().getNodeValue().trim();
292
            }
293
            catch(NullPointerException npe)
294
            {
295
              continue;
296
            }
297
            
298
            if(oldid.contains(nodeval.trim()))
299
            {
300
              String newidS = "";
301
              for(int k=0; k<newid.size(); k++)
302
              {
303
                newidS = (String)newid.elementAt(k);
304
                if(nodeval.trim().equals(oldid.elementAt(k)))
305
                {
306
                  break;
307
                }
308
              }
309
              System.out.println("replacing: " + nodeval + " with " + newidS);
310
              childNode.getFirstChild().setNodeValue(newidS);
311
            }
312
          }
313
        }
314
      }
315
    }
316
    
317
    //increase the identifier
318
    NodeList identiferList = null; 
319
    try
320
    {
321
      //find where the triples go in the file
322
      identiferList = XPathAPI.selectNodeList(doc, IDENTIFIER);
323
    }
324
    catch(Exception se)
325
    {
326
      System.err.println("incRevInTriples() : parse threw: " + 
327
                         se.toString());
328
    }
329
    
330
    for(int i=0; i<identiferList.getLength(); i++)
331
    {
332
      Node identifierNode = identiferList.item(i);
333
      String nodeName = identifierNode.getNodeName().trim().toUpperCase();
334
      if (nodeName.equals("IDENTIFIER"))
335
      {
336
        String nodeValue = null;
337
        try
338
        {
339
           nodeValue = identifierNode.getFirstChild().getNodeValue().trim();
340
        }
341
        catch(NullPointerException npe)
342
        {
343
          continue;
344
        }
345
        
346
        if(oldid.contains(nodeValue.trim()))
347
        {
348
           String newidS = "";
349
            for(int k=0; k<newid.size(); k++)
350
            {
351
               newidS = (String)newid.elementAt(k);
352
               if(nodeValue.trim().equals(oldid.elementAt(k)))
353
               {
354
                  break;
355
               }
356
            }
357
            System.out.println("replacing: " + nodeValue + " with " + newidS);
358
            identifierNode.getFirstChild().setNodeValue(newidS);
359
         }
360
      
361
     
362
      }
363
    }
364
    
365
    return PackageUtil.printDoctype(doc) + 
366
           PackageUtil.print(doc.getDocumentElement());
367
  }
368
  
369
 
370
  /*
371
   *Give a docid to find a package accesssionNumber for it.
372
   */
373
   private static String getDataPackageAccessionNumber(String docId)
374
  {
375
    String accessNumber = null;
376
    String packageIdWithoutVersion = null;
377
    String rev = null;
378
    PreparedStatement pStmt = null;
379
    ResultSet rs=null;
380
    String query="SELECT docId from xml_relation where subject = ?";
381
    DBConnection dbConn = null;
382
    int serialNumber = -1;
383
    try
384
    {
385
      dbConn=DBConnectionPool.
386
                  getDBConnection("DBQuery.getDataPackageId");
387
      serialNumber=dbConn.getCheckOutSerialNumber();
388
      pStmt=dbConn.prepareStatement(query);
389
      //bind the value to query
390
      pStmt.setString(1, docId);
391
      //execute the query
392
      pStmt.execute();
393
      rs=pStmt.getResultSet();
394
      //process the result
395
      if (rs.next()) //There are some records for the id in docId fields
396
      {
397
        packageIdWithoutVersion=rs.getString(1);//get data package id
398
      }
399
      pStmt.close();
400
      rev = getRevNumber(packageIdWithoutVersion);
401
      accessNumber = packageIdWithoutVersion+"."+rev;
402
      MetaCatUtil.debugMessage("DataPackageId: "+accessNumber, 50);
403
    }//try
404
    catch (SQLException e)
405
    {
406
      MetaCatUtil.debugMessage("Error in isDataPackageId: "
407
                            +e.getMessage(), 30);
408
    }
409
    finally
410
    {
411
      try
412
      {
413
        pStmt.close();
414
      }//try
415
      catch (SQLException ee)
416
      {
417
        MetaCatUtil.debugMessage("Error in isDataPackageId: "
418
                                                        + ee.getMessage(), 30);
419
      }//catch
420
      finally
421
      {
422
        DBConnectionPool.returnDBConnection(dbConn, serialNumber);
423
      }//finally
424
    }//finally
425
    return accessNumber;
426
  }//isDataPackageId()
427
  
428
  /**
429
   * Get a dev number from a given docid(without dev)
430
   */
431
  public static String getRevNumber(String docId) 
432
  {
433
    DBConnection dbConn = null;
434
    int serialNumber = -1;
435
    String query = "SELECT rev from xml_documents where docid = ?";
436
    PreparedStatement pStmt = null;
437
    ResultSet rs = null;
438
    String rev = null;
439
    try
440
    {
441
      dbConn=DBConnectionPool.
442
                  getDBConnection("DBQuery.getDataPackageId");
443
      serialNumber=dbConn.getCheckOutSerialNumber();
444
      pStmt=dbConn.prepareStatement(query);
445
      //bind the value to query
446
      pStmt.setString(1, docId);
447
      //execute the query
448
      pStmt.execute();
449
      rs=pStmt.getResultSet();
450
      //process the result
451
      if (rs.next()) //There are some records for the id in docId fields
452
      {
453
        rev=rs.getString(1);//get data package id
454
      }
455
      pStmt.close();
456
    }
457
    catch (SQLException e)
458
    {
459
      System.out.println("the error in getRevNumber: "+e.getMessage());
460
    }
461
    finally
462
    {
463
      try
464
      {
465
        pStmt.close();
466
      }
467
      catch (SQLException ee)
468
      {
469
        System.out.println("the error in getRevNumber2: "+ee.getMessage());
470
      }
471
      finally
472
      {
473
        DBConnectionPool.returnDBConnection(dbConn, serialNumber);
474
        return rev;
475
      }
476
    }
477
   
478
  }
479
  /**
480
   * Delete a access control rule which is not in access xml document 
481
   */
482
  public static void deleteAccessRule(String aclDocid, String accessRule)
483
  {
484
    String principal  = null;
485
    String allowType  = null;
486
    String permission = null;
487
    String allowOrder = null;
488
    String [] parseAccessRuleArray = null;
489
     DBConnection dbConn = null;
490
    int serialNumber = -1;
491
    String query = "delete from xml_access where accessfileid = ? " +
492
                   "and principal_name = ? and perm_type = ? "+
493
                   "and permission = ? and perm_order = ?";
494
    PreparedStatement pStmt = null;
495
    String rev = null;
496
    // parse the access rule 
497
    parseAccessRuleArray = parseAccessRule(accessRule);
498
    if ( parseAccessRuleArray == null)
499
    {
500
      System.out.println("couldn't parse docid: "+aclDocid);
501
      return;
502
    }
503
    else
504
    {
505
      principal  = parseAccessRuleArray[0];
506
      allowType  = parseAccessRuleArray[1];
507
      permission = parseAccessRuleArray[2];
508
      allowOrder = parseAccessRuleArray[3];
509
      
510
    }
511
    
512
    try
513
    {
514
      dbConn=DBConnectionPool.
515
                  getDBConnection("DBQuery.getDataPackageId");
516
      serialNumber=dbConn.getCheckOutSerialNumber();
517
      pStmt=dbConn.prepareStatement(query);
518
      //bind the value to query
519
      pStmt.setString(1, aclDocid);
520
      pStmt.setString(2, principal);
521
      pStmt.setString(3, allowType);
522
      pStmt.setInt(4, (new Integer(permission)).intValue());
523
      pStmt.setString(5, allowOrder);
524
      //execute the query
525
      pStmt.execute();
526
      pStmt.close();
527
      System.out.println("delete rules: "+accessRule+" for "
528
                          +aclDocid+" in table");
529
      writeToLogFile("Delete rules: "+accessRule+" for "
530
                     +aclDocid+" in xml_access table");
531
    }
532
    catch (SQLException e)
533
    {
534
      System.out.println("the error in deleteAccessRule(): "+e.getMessage());
535
    }
536
    finally
537
    {
538
      try
539
      {
540
        pStmt.close();
541
      }
542
      catch (SQLException ee)
543
      {
544
        System.out.println("the error in getRevNumber2: "+ee.getMessage());
545
      }
546
      finally
547
      {
548
        DBConnectionPool.returnDBConnection(dbConn, serialNumber);
549
       
550
      }
551
    }
552
  }
553
  
554
  /*
555
   * parse the string and get a array cotains principle name(index 0),
556
   * allow type (index1), permission (index2), and allow order(index, 4)
557
   */
558
  private static String[] parseAccessRule(String accessRule)
559
  {
560
    String principal  = null;
561
    String allowType  = null;
562
    String permission = null;
563
    String allowOrder = null;
564
    String [] result  = new String[4];
565
    int count = 0;
566
    int index = 0;
567
    char delimiter = DELIMITER.charAt(0);
568
    
569
    if (accessRule== null)
570
    {
571
      return result;
572
    }
573
    for (int i=0; i<accessRule.length(); i++)
574
    {
575
      
576
      char charInString = accessRule.charAt(i);
577
      // find a symbol !
578
      if (charInString == delimiter)
579
      {
580
        count ++;
581
      }
582
      else
583
      {
584
        continue;
585
      }
586
      
587
      switch (count)
588
      {
589
        case 1:
590
        {
591
          // get principal
592
          principal = accessRule.substring(0, i);
593
          // remeber the index
594
          index = i;
595
          break;
596
        }
597
        case 2:
598
        {
599
          allowType = accessRule.substring(index+1, i);
600
          index = i;
601
          break;
602
        }
603
        case 3:
604
        {
605
          permission = accessRule.substring(index+1, i);
606
          index = i;
607
          allowOrder = accessRule.substring(index+1, accessRule.length());
608
          break;
609
        }
610
      }//switch
611
    }//for
612
    
613
    // if the string exactly has 3 !, add it to array
614
    if ( count == 3)
615
    {
616
      result[0] = principal;
617
      result[1] = allowType;
618
      result[2] = permission;
619
      result[3] = allowOrder;
620
    }//if
621
    return result;
622
  }
623
  
624
  /**
625
   * A method get acl docid list from xml_access table
626
   */
627
  public static Vector readAccessDocIdFromDB()
628
  {
629
    Vector docidList = new Vector();
630
    String docid = null;
631
    DBConnection conn = null;
632
    int serialNumber = -1;
633
    PreparedStatement pstmt = null;
634
    try
635
    {
636
      //get connection from DBConnectionPool
637
      conn = DBConnectionPool.
638
              getDBConnection("CleanupAccessTable.readAccessDocIdFromDB");
639
      serialNumber=conn.getCheckOutSerialNumber();
640
      
641
      // delete all acl records for resources related to @aclid if any
642
      pstmt = conn.prepareStatement("SELECT accessfileid FROM xml_access");
643
      pstmt.execute();
644
      ResultSet rs = pstmt.getResultSet();
645
      boolean hasRows = rs.next();
646
      int i = 0;
647
      while (hasRows) 
648
      {
649
        docid  = rs.getString(1);
650
        // if hashtable doesn't has the rule add to hashtable
651
        if (docid !=null && !docidList.contains(docid))
652
        {
653
          docidList.addElement(docid);
654
          
655
        }
656
        hasRows = rs.next();
657
        // reset value
658
        docid = null;
659
        
660
      }//while
661
  
662
    }
663
    catch (SQLException e)
664
    {
665
      System.out.println("error in readAccessDocIdFromDB: "+e.getMessage());
666
    }
667
    finally
668
    {
669
      try
670
      {
671
        pstmt.close();
672
      }
673
      catch (SQLException ee)
674
      {
675
        System.out.println("error in readAccessDocIdFromDB: "+ee.getMessage());
676
      }
677
      finally
678
      {
679
        //retrun DBConnection
680
        DBConnectionPool.returnDBConnection(conn,serialNumber);
681
        return docidList;
682
      }
683
    }
684
 
685
  }
686
  
687
  /**
688
   * Method to delete rules which is not in xml access file
689
   */
690
  public static void deleteRules(Vector aclDocList) 
691
  {
692
    String aclDocId = null;
693
    //checking for every acl id
694
    for (int i= 0; i<aclDocList.size(); i++)
695
    {
696
      try
697
      {
698
        aclDocId = (String)aclDocList.elementAt(i);
699
        AccessRulesFromDocument xmlDocument = new 
700
                                            AccessRulesFromDocument(aclDocId);
701
        Vector rules = xmlDocument.getAccessRuleVector();
702
        AccessRulesFromDB db = new AccessRulesFromDB(aclDocId);
703
        Vector rulesFromDB = db.getAccessRuleVector();
704
        //check for every rules
705
        for (int j=0; j< rulesFromDB.size(); j++)
706
        {
707
          String oneRule = (String)rulesFromDB.elementAt(j);
708
          // if onerules get from db not in xml_access, delete it
709
          if (!rules.contains(oneRule))
710
          {
711
            System.out.println("one rule: "+oneRule);
712
            deleteAccessRule(aclDocId, oneRule);
713
          }//if
714
          oneRule = null;
715
        }//for
716
        aclDocId = null;
717
      }
718
      catch (Exception e)
719
      {
720
        System.out.println("error delete rules: "+e.getMessage());
721
      } 
722
    }//for
723
  }
724
  
725
  /**
726
   * Method to updata data set files
727
   */
728
  public static void updateDataSetFiles(Vector aclDocList) 
729
  {
730
    String aclDocId = null;
731
    String aclAccessionNumber = null;
732
    String revForAcl = null;
733
    String packagAccessionNumber = null;
734
    //checking for every acl id
735
    for (int i= 0; i<aclDocList.size(); i++)
736
    {
737
      try
738
      {
739
        aclDocId = (String)aclDocList.elementAt(i);
740
        packagAccessionNumber = getDataPackageAccessionNumber(aclDocId);
741
        AccessRulesFromDocument xmlDocument = new 
742
                                            AccessRulesFromDocument(aclDocId);
743
        Vector docid = xmlDocument.getACLObjects();
744
        AccessRulesFromDB db = new AccessRulesFromDB(aclDocId);
745
        Vector docidFromDB = db.getDocidAccessRuleApplied();
746
        revForAcl = getRevNumber(aclDocId);
747
        aclAccessionNumber = aclDocId+DOT+revForAcl;
748
        //check for every docid in relation ship
749
        Vector newTripleVector = new Vector();
750
        for (int j=0; j<docidFromDB.size(); j++)
751
        {
752
          String objectId = (String)docidFromDB.elementAt(j);
753
          String objectAccessionNumber = null;
754
          String revForObject = null;
755
          // new triple
756
          if (!docid.contains(objectId))
757
          {
758
            revForObject = getRevNumber(objectId);
759
            objectAccessionNumber = objectId+DOT+revForObject;
760
            Triple newTriple = new Triple(aclAccessionNumber, RELATIONSHIP, 
761
                                        objectAccessionNumber);
762
            newTripleVector.add(newTriple);
763
            System.out.println("find a new triple");
764
          
765
          }//if
766
        }//for
767
        // add new trip into data set
768
        addNewTripleIntoDataset(packagAccessionNumber, newTripleVector);
769
        // reset value
770
        aclDocId = null;
771
        aclAccessionNumber = null;
772
        revForAcl = null;
773
        packagAccessionNumber = null;
774
      }
775
      catch (Exception e)
776
      {
777
        System.out.println("error in updataDatasetFiles(): "+e.getMessage());
778
      }
779
      
780
    }//for
781
  }
782
  
783
  /*
784
   * Method to write information into log file
785
   */
786
  private static void writeToLogFile(String message)
787
  {
788
    try
789
    {
790
      FileOutputStream fos = new FileOutputStream(LOGFILENAME, true);
791
      PrintWriter pw = new PrintWriter(fos);
792
      pw.println(message);
793
      pw.flush();
794
    }
795
    catch(Exception e)
796
    {
797
      System.out.println("error writing to log: " + e.getMessage());
798
     
799
    }
800
  }
801
  
802
  public static void main(String[] agus)
803
  {
804
    
805
    try
806
    {
807
      DBConnectionPool pool = DBConnectionPool.getInstance();
808
      Vector aclVector = readAccessDocIdFromDB();
809
      deleteRules(aclVector);
810
      Vector aclVector2 = readAccessDocIdFromDB();
811
      updateDataSetFiles(aclVector2);
812
    }
813
    catch(Exception e)
814
    {
815
      System.out.println("exception is: "+e.getMessage());
816
    }
817
  }
818
  
819
}//cleanupAccessTable
(13-13/48)