Changeset 8422


Ignore:
Timestamp:
2004-10-31T16:30:46+13:00 (19 years ago)
Author:
schweer
Message:

George's bugfixes for adding documents to an existing collection; some changes for detecting deleted documents

Location:
trunk/gsdl3/src/java/org/greenstone/gsdl3/gs3build
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/gsdl3/src/java/org/greenstone/gsdl3/gs3build/CollectionManager.java

    r8418 r8422  
    1919import java.net.URLEncoder;
    2020
     21import java.sql.*;
     22
    2123import javax.xml.parsers.*;
    2224
     
    3133import org.xml.sax.SAXParseException;
    3234
     35import org.greenstone.gsdl3.gs3build.database.*;
    3336import org.greenstone.gsdl3.gs3build.collection.*;
    3437import org.greenstone.gsdl3.gs3build.classifier.*;
     
    124127    return null;
    125128      }
    126       System.out.println(this.type.toLowerCase());
     129      System.out.println("Creating a classifier of type " + this.type.toLowerCase());
    127130     
    128131      if (this.type.toLowerCase().equals("hierarchy")) {
    129     System.out.println(this.file);
     132    System.out.println("  hierarchy file is " + this.file);
    130133    classifier = new HierarchyClassifier(this.className, this.file, this.fields, this.sort);
    131134      }
     
    197200
    198201    this.buildDocNo = 1;
     202
     203    try {
     204      GS3SQLSelect select = new GS3SQLSelect("build");
     205      select.addField("*");
     206      this.database.execute(select.toString());
     207      ResultSet results = this.database.getResultSet();
     208      if (results != null &&
     209      results.first()) {
     210    System.out.println("Reading all keys");
     211    do {
     212      String key = results.getString("buildKey");
     213      String value = results.getString("buildValue");
     214
     215      if (key.equals("NextSeqNo")) {
     216        this.buildDocNo = Integer.parseInt(value);
     217      }
     218      else if (key.equals("lastBuildDate")) {
     219        int year, month, day;
     220        year = Integer.parseInt(value.substring(0, 4));
     221        month = Integer.parseInt(value.substring(4, 6)) - 1; // -1 because Gregorian Calendar perversely treats January as 0, etc.
     222        day = Integer.parseInt(value.substring(6, 8));
     223       
     224        this.lastBuildDate = new GregorianCalendar(year, month, day);
     225      }
     226    } while (results.next());
     227      }
     228    }
     229    catch (SQLException ex)
     230      { System.out.println(ex);
     231      }
    199232  }
    200233
     
    249282  public void configureCollection()
    250283  { File collectionConfig = new File(GSFile.collectionConfigFile(this.collectionHome));
    251    
     284
    252285    // get the File and read it in
    253286    try
     
    360393
    361394  public String getEtcDirectory()
    362  
    363395  { return GSFile.collectionEtcDir(this.collectionHome);
    364396  }
     
    370402  public String getBuildDirectory()
    371403  { return GSFile.collectionBuildDir(this.collectionHome);
    372   }
    373  
    374   public GregorianCalendar getLastBuildDate(){
    375     return lastBuildDate;
    376404  }
    377405
     
    400428      { this.buildDocNo = 1;
    401429      }
     430      else
     431      { System.out.println("Continuing build sequence from " + this.buildDocNo);
     432      }
    402433    }
    403434    this.lastBuildDate = today;
     
    406437  public void endBuild()
    407438  {
    408       // here we write out the build config file
    409       // create the xml for the buildConfig
    410       XMLConverter converter = new XMLConverter();
    411       Document doc = converter.newDOM();
    412       Element build_config = doc.createElement(GSXML.COLLECTION_BUILD_ELEM);
    413       Element meta_list = doc.createElement(GSXML.METADATA_ELEM + GSXML.LIST_MODIFIER);
    414       build_config.appendChild(meta_list);
    415       Element service_list = doc.createElement(GSXML.SERVICE_CLASS_ELEM+GSXML.LIST_MODIFIER);
    416       build_config.appendChild(service_list);
    417 
    418       // the document structure and metadata retrieval will use GS3REtrieve service, so add it in here
    419       Element base_retrieve_service = doc.createElement(GSXML.SERVICE_CLASS_ELEM);
    420       base_retrieve_service.setAttribute(GSXML.NAME_ATT, "GS3Retrieve");
    421       service_list.appendChild(base_retrieve_service);
    422       // ask the indexers to add stuff into the service rack list
    423       this.buildManager.getIndexerManager().addServiceDescriptions(service_list);
    424       this.buildManager.getClassifierManager().addServiceDescriptions(service_list);
    425       // get the String
    426       String build_config_string = converter.getString(build_config);
    427       // write it to the file
    428       try {
    429       File build_config_file = new File(GSFile.collectionBuildConfigFileBuilding(this.collectionHome));
    430       BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(build_config_file), "UTF-8"));
    431       writer.write(build_config_string, 0, build_config_string.length());
    432       writer.close();
    433       } catch (Exception e) {
    434       System.err.println("CollectionManager.endBuild() Error while trying to output the buildConfig.xml file.");
    435       System.err.println(e.getMessage());
    436       }
     439    // here we write out the build config file
     440    // create the xml for the buildConfig
     441    XMLConverter converter = new XMLConverter();
     442    Document doc = converter.newDOM();
     443    Element build_config = doc.createElement(GSXML.COLLECTION_BUILD_ELEM);
     444    Element meta_list = doc.createElement(GSXML.METADATA_ELEM + GSXML.LIST_MODIFIER);
     445    build_config.appendChild(meta_list);
     446    Element service_list = doc.createElement(GSXML.SERVICE_CLASS_ELEM+GSXML.LIST_MODIFIER);
     447    build_config.appendChild(service_list);
     448   
     449    // the document structure and metadata retrieval will use GS3REtrieve service, so add it in here
     450    Element base_retrieve_service = doc.createElement(GSXML.SERVICE_CLASS_ELEM);
     451    base_retrieve_service.setAttribute(GSXML.NAME_ATT, "GS3Retrieve");
     452    service_list.appendChild(base_retrieve_service);
     453    // ask the indexers to add stuff into the service rack list
     454    this.buildManager.getIndexerManager().addServiceDescriptions(service_list);
     455    this.buildManager.getClassifierManager().addServiceDescriptions(service_list);
     456    // get the String
     457    String build_config_string = converter.getString(build_config);
     458    // write it to the file
     459    try {
     460      File build_config_file = new File(GSFile.collectionBuildConfigFileBuilding(this.collectionHome));
     461      BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(build_config_file), "UTF-8"));
     462      writer.write(build_config_string, 0, build_config_string.length());
     463      writer.close();
     464    } catch (Exception e) {
     465      System.err.println("CollectionManager.endBuild() Error while trying to output the buildConfig.xml file.");
     466      System.err.println(e.getMessage());
     467    }
     468   
     469    // Update build date information
     470    GS3SQLDelete remove = new GS3SQLDelete("build");
     471    //    GS3SQLWhere where = new GS3SQLWhere(new GS3SQLWhereItem("buildKey", "=", "NextSeqNo"));
     472    //    rem
     473    this.database.execute(remove.toString());
     474   
     475    GS3SQLInsert insert = new GS3SQLInsert("build");
     476    insert.addValue("buildKey", "NextSeqNo");
     477    insert.addValue("buildValue", Integer.toString(this.buildDocNo));
     478    this.database.execute(insert.toString());
     479   
     480    insert = new GS3SQLInsert("build");
     481    insert.addValue("buildKey", "lastBuildDate");
     482    insert.addValue("buildValue", getDateString(this.lastBuildDate));
     483    this.database.execute(insert.toString());
     484
     485    // Do tail of build output
    437486    Date startDate = this.lastBuildDate.getTime();
    438487    Date date = new Date();
     
    449498  }
    450499
    451   public String getNextDocumentID()
    452   { StringBuffer ID = new StringBuffer();
    453 
     500  private static String getDateString(GregorianCalendar date)
     501  { StringBuffer dateString = new StringBuffer();
     502 
    454503    int value;
    455     ID.append(lastBuildDate.get(Calendar.YEAR));
     504    dateString.append(date.get(Calendar.YEAR));
    456505
    457506    // the use of month is a little odd, hence the following
     
    460509    // it into January = 1, etc., and the padding is altered
    461510    // correspondingly.
    462     value = lastBuildDate.get(Calendar.MONTH);
     511    value = date.get(Calendar.MONTH);
    463512    if (value < 9)
    464     { ID.append("0");
    465     }
    466     ID.append(value + 1);
    467     value = lastBuildDate.get(Calendar.DAY_OF_MONTH);
     513    { dateString.append("0");
     514    }
     515    dateString.append(value + 1);
     516    value = date.get(Calendar.DAY_OF_MONTH);
    468517    if (value < 10)
    469       ID.append("0");
    470     ID.append(value);
    471 
    472 
    473     value = this.buildDocNo;
     518      dateString.append("0");
     519    dateString.append(value);
     520
     521    return dateString.toString();
     522  }
     523
     524  public String getNextDocumentID()
     525  { StringBuffer ID = new StringBuffer(getDateString(this.lastBuildDate));
     526
     527    int value = this.buildDocNo;
    474528    this.buildDocNo ++;
    475529   
  • trunk/gsdl3/src/java/org/greenstone/gsdl3/gs3build/doctypes/DocumentList.java

    r8421 r8422  
    321321    // set the document identifier, if not already set
    322322    if (document.getID() == null) {
     323      System.out.println("Posting new docuument ID");
    323324      DocumentID id = this.idFactory.getNewDocumentID(document);
    324325      document.setID(id);
     
    327328    // add to the database as well, if it is modified...
    328329    if (document.isChanged()) {
     330      System.out.println("Document was changed");
    329331      document.getSQLWriter().writeDocument(document, this.connection);
    330332    }
  • trunk/gsdl3/src/java/org/greenstone/gsdl3/gs3build/doctypes/TextRecogniser.java

    r7466 r8422  
    3838      { this.listRepository.addDocument(new TextDocument(url));
    3939    // TODO: spawn knowledge of children too...
    40         System.out.println(">>> Posting text document " + fileName);
     40        System.out.println("Posting text document " + fileName);
    4141    return true;
    4242      }
  • trunk/gsdl3/src/java/org/greenstone/gsdl3/gs3build/indexers/IndexerManager.java

    r8408 r8422  
    4747    { for (int p = 0; p < this.indexers[i].getNumberOfPasses(); p ++)
    4848      {
    49       if (!this.indexers[i].startPass(p)) {
    50           continue;
    51       }
     49    if (!this.indexers[i].startPass(p)) {
     50      continue;
     51    }
     52
    5253    Iterator iterator = this.documentList.iterator();
    5354
     
    6263        // note any changes made to this document...
    6364        if (document.isChanged()) {
     65          //System.out.println("Writing document "+document.getID());
    6466          this.documentList.storeChangedDocument(document);
    65           //          System.out.println("Writing document "+document.getID());
    6667        }
    6768        /**
  • trunk/gsdl3/src/java/org/greenstone/gsdl3/gs3build/util/GS3SQLConnection.java

    r8408 r8422  
    99import java.sql.Statement;
    1010import java.sql.ResultSet;
    11 
    1211
    1312import org.greenstone.gsdl3.gs3build.database.*;
     
    193192      this.connection = GS3SQLConnectionFactory.reconnect(collectionName);
    194193
     194      statement = this.connection.createStatement();
     195
     196      // create build history table
     197      GS3SQLCreateTable buildTable = new GS3SQLCreateTable("build");
     198      buildTable.addAutoPrimaryKey("buildRef");
     199      buildTable.addProperty("buildKey", 64);
     200      buildTable.addProperty("buildValue");
     201      statement.execute(buildTable.toString());
     202
    195203      // create document table
    196204      GS3SQLCreateTable docTable = new GS3SQLCreateTable("document");
     
    202210      docTable.addProperty("IndexedDate", GS3SQLField.DATETIME_TYPE);
    203211      docTable.addProperty("ModifiedDate", GS3SQLField.DATETIME_TYPE);
    204       statement = this.connection.createStatement();
    205212      statement.execute(docTable.toString());
    206213     
    207       //   create structure table
     214      // create structure table
    208215      GS3SQLCreateTable structureMap = new GS3SQLCreateTable("structure");
    209216      structureMap.addAutoPrimaryKey("StructureRef");
     
    215222      statement.execute(structureMap.toString());
    216223   
    217       //   create section table
     224      // create section table
    218225      GS3SQLCreateTable sectionMap = new GS3SQLCreateTable("divisions");
    219226      sectionMap.addAutoPrimaryKey("DivisionRef");
     
    266273      namespaces.addProperty("Creator", 128);
    267274      statement.execute(namespaces.toString());
    268      
    269       //   create metadata values table
     275
     276      // create metadata grouping table
     277      GS3SQLCreateTable metagroups = new GS3SQLCreateTable("mdgroups");
     278      metagroups.addProperty("NamespaceRef", GS3SQLField.INTEGER_TYPE);
     279      metagroups.addAutoPrimaryKey("MdGroupRef");
     280      metagroups.addProperty("MdGroupID", 32);
     281      statement.execute(metagroups.toString());
     282
     283      // create metadata qualifiers table
     284      GS3SQLCreateTable metaqualifiers = new GS3SQLCreateTable("mdqualifiers");
     285      metaqualifiers.addProperty("MdGroupRef", GS3SQLField.INTEGER_TYPE);
     286      metaqualifiers.addProperty("QualifierName", 64);
     287      metaqualifiers.addProperty("QualifierValue", 64);
     288      statement.execute(metaqualifiers.toString());
     289     
     290      // create metadata values table
    270291      GS3SQLCreateTable metadata = new GS3SQLCreateTable("mdvalues");
    271       // todo: some unique id for the namespaces item
    272       metadata.addProperty("NamespaceRef", GS3SQLField.INTEGER_TYPE);
    273       metadata.addProperty("Label", 256);
    274       metadata.addProperty("Value");
     292      metadata.addProperty("NamespaceRef", GS3SQLField.INTEGER_TYPE); // the parent namespace {one candidate primary key}
     293      metadata.addProperty("GroupRef", GS3SQLField.INTEGER_TYPE);     // the parent group     {a sub-key or independent primary key}
     294      metadata.addProperty("Label", 256);                             // the key of the metadata item
     295      metadata.addProperty("Value");                                  // the value of the metadata item
    275296      statement.execute(metadata.toString());
    276297   
Note: See TracChangeset for help on using the changeset viewer.