Ignore:
Timestamp:
2019-03-05T15:30:27+13:00 (5 years ago)
Author:
davidb
Message:

Mostly code tidy-up. In IIIFServerBridge.java, edit to remove hard-wired path

File:
1 edited

Legend:

Unmodified
Added
Removed
  • gs3-extensions/iiif-servlet/trunk/src/gsdl-src/java/org/greenstone/gsdl3/service/IIIFPMH.java

    r32842 r32860  
    6161 
    6262  protected SimpleCollectionDatabase coll_db = null;
    63     //protected SimpleCollectionDatabase oaiinf_db = null;
    6463 
    6564  protected String site_name = "";
     
    7978  /** constructor */
    8079  public IIIFPMH() {
    81 
    8280  }
    8381 
     
    8987    this.coll_db = null;
    9088    }
    91     /*
    92     if (this.oaiinf_db != null){
    93         this.oaiinf_db.closeDatabase();
    94     }*/
    9589  }
    9690 
     
    115109    Element metadata_list = (Element) GSXML.getChildByTagName(extra_info, GSXML.METADATA_ELEM+GSXML.LIST_MODIFIER);
    116110
     111    // Is indexStem needed for IIIF // ****
    117112    if (metadata_list != null) {
    118      
     113   
    119114      Element index_stem_elem = (Element) GSXML.getNamedElement(metadata_list, GSXML.METADATA_ELEM, GSXML.NAME_ATT, "indexStem");
    120115     
     
    137132    }
    138133
    139     /*
    140     // Work out what sets this collection has.
    141     //
    142     // Will usually contain the collection itself, optional super
    143     // collection, and maybe subcolls if appropriate classifiers are
    144     // present.
    145    
    146     configureSetInfo();*/
    147    
    148     // the short_service_info is used by the message router to find the method names,
    149     /*
    150     Element list_records = this.desc_doc.createElement(GSXML.SERVICE_ELEM);
    151     list_records.setAttribute(GSXML.NAME_ATT, OAIXML.LIST_RECORDS);
    152     list_records.setAttribute(GSXML.TYPE_ATT, "oai");
    153     this.short_service_info.appendChild(list_records);
    154 
    155     Element list_identifiers = this.desc_doc.createElement(GSXML.SERVICE_ELEM);
    156     list_identifiers.setAttribute(GSXML.NAME_ATT, OAIXML.LIST_IDENTIFIERS);
    157     list_identifiers.setAttribute(GSXML.TYPE_ATT, "oai");
    158     this.short_service_info.appendChild(list_identifiers);
    159    
    160     Element list_sets = this.desc_doc.createElement(GSXML.SERVICE_ELEM);
    161     list_sets.setAttribute(GSXML.NAME_ATT, OAIXML.LIST_SETS);
    162     list_sets.setAttribute(GSXML.TYPE_ATT, "oai");
    163     this.short_service_info.appendChild(list_sets);
    164    
    165     Element list_metadata_formats = this.desc_doc.createElement(GSXML.SERVICE_ELEM);
    166     list_metadata_formats.setAttribute(GSXML.NAME_ATT, OAIXML.LIST_METADATA_FORMATS);
    167     list_metadata_formats.setAttribute(GSXML.TYPE_ATT, "oai");
    168     this.short_service_info.appendChild(list_metadata_formats);
    169     */
    170134    Element get_record = this.desc_doc.createElement(GSXML.SERVICE_ELEM);
    171135    get_record.setAttribute(GSXML.NAME_ATT, IIIFXML.GET_RECORD);
     
    177141
    178142  public boolean configureIIIF(Element iiif_config_elem) {
    179       /*     
    180     this.meta_formats_definition = this.desc_doc.createElement(OAIXML.LIST_METADATA_FORMATS);
    181     this.format_response_map = new HashMap<String, Element>();
    182     this.format_elements_map = new HashMap<String, HashSet<String>>();
    183     this.format_meta_elem_map = new HashMap<String, Element>();
    184 
    185     // for now, all we want is the metadata prefix description and the mapping list
    186     Element main_lmf_elem = (Element) GSXML.getChildByTagName(oai_config_elem, OAIXML.LIST_METADATA_FORMATS);
    187     if (main_lmf_elem == null) {
    188       logger.error("No listMetadataFormats element found in OAIConfig.xml");
    189       return false;
    190     }
    191     NodeList meta_formats_list = this.config_info.getElementsByTagName(OAIXML.METADATA_FORMAT);
    192     if (meta_formats_list.getLength() == 0) {
    193       logger.error("no metadataFormat elements found in OAIPMH serviceRack element");
    194       return false;
    195     }
    196143     
    197     boolean found_meta_format = false;
    198     for(int i=0; i<meta_formats_list.getLength(); i++) {
    199       Element mf = (Element) meta_formats_list.item(i);
    200       String prefix = mf.getAttribute(OAIXML.METADATA_PREFIX);
    201       if (prefix.equals("")) {
    202     logger.error("metadataFormat element had no metadataPrefix attribute");
    203     continue;
    204       }
    205       // get the right format from OAICOnfig
    206       Element meta_format = findNamedMetadataFormat(main_lmf_elem, prefix);
    207       if (meta_format == null) {
    208     logger.error("Couldn't find metadataFormat named "+prefix+" in OAIConfig.xml");
    209     continue;
    210       }
    211      
    212       // copy the format definition into our stored Element
    213       Element collection_version_format = (Element) this.desc_doc.importNode(meta_format, true);
    214       collection_version_format.setAttribute(GSXML.NAME_ATT, prefix); // for convenience
    215       this.meta_formats_definition.appendChild(collection_version_format);
    216       // set up the response element for this format
    217       format_response_map.put(prefix, OAIXML.getMetadataFormatShort(this.desc_doc, collection_version_format));
    218       // add in collection specific mappings
    219       addCollectionMappings(collection_version_format, mf);
    220       // now set up a list of all collection elements for reverse lookup of the mapping
    221       format_elements_map.put(prefix, getAllCollectionElements(collection_version_format));
    222       format_meta_elem_map.put(prefix, OAIXML.getMetadataPrefixElement(this.desc_doc, prefix, collection_version_format));
    223      
    224     } // end for
    225       */
    226      
    227     // Open the coll db db databases and store handles to them 
     144      // Open the coll db db databases and store handles to them   
    228145    coll_db = new SimpleCollectionDatabase(infodb_type);
    229146    if (!coll_db.databaseOK()) {
     
    231148      return false;
    232149    }
    233     /*
    234     oaiinf_db = new SimpleCollectionDatabase(infodb_type);
    235     if (!oaiinf_db.databaseOK()) {
    236       logger.error("Couldn't create the oai-inf database of type "+infodb_type);
    237       return false;
    238     }
    239     */
    240150   
    241151    // Open databases for querying
     
    245155      return false;
    246156    }
    247     /*
    248     // the oaiinf_db is called oai-inf.<infodb_type_extension>
    249     String oaiinf_db_file = GSFile.OAIInfoDatabaseFile(this.site_home, this.cluster_name, "oai-inf", infodb_type);
    250     File oaiinfFile = new File(oaiinf_db_file);
    251    
    252     if(!oaiinfFile.exists()) {
    253     logger.warn("oai-inf database for collection + " + this.cluster_name + " does not exist.");
    254     oaiinf_db = null;
    255     } else if (!this.oaiinf_db.openDatabase(oaiinf_db_file, SimpleCollectionDatabase.READ)) {
    256     logger.warn("Could not open oai-inf database for collection + " + this.cluster_name + "!");
    257     oaiinf_db = null;
    258     }
    259     */
    260157   
    261158    return true;
    262159  }
    263160
    264     /**
    265      * @return the associated OAICollection's OAI_EARLIEST_TIMESTAMP_OID record's
    266      * OAI_INF_TIMESTAMP field from the collection's oai-inf.db IN MILLISECONDS
    267      */
    268     /*
    269     public long getEarliestTimestamp() {
    270     long timestamp = -1;
    271    
    272     DBInfo oai_info = null;
    273     if(oaiinf_db != null) {
    274         // get internal record containing the earliest timestamp of the collection
    275         oai_info = this.oaiinf_db.getInfo(OAIXML.OAI_EARLIEST_TIMESTAMP_OID);
    276         if (oai_info == null) {
    277         logger.warn("Can't get collection " + this.cluster_name + "'s earliest timestamp from oai-inf db. No entry for 'OID' " + OAIXML.OAI_EARLIEST_TIMESTAMP_OID + " in the db.");       
    278         } else {
    279         timestamp = Long.parseLong(oai_info.getInfo(OAIXML.OAI_INF_TIMESTAMP)) * 1000; // stored in seconds, so x1000 to  convert to milliseconds
    280         //logger.info("@@@ found earliest OAI timestamp for collection " + this.coll_name + ": " + timestamp + " (ms)");
    281         }
    282     }
    283     return timestamp;
    284     }
    285     */
    286 
    287     /*
    288   protected Element findNamedMetadataFormat(Element list_meta_formats, String prefix) {
    289     NodeList formats = list_meta_formats.getElementsByTagName(OAIXML.METADATA_FORMAT);
    290     for (int i=0; i<formats.getLength(); i++) {
    291       Element format = (Element)formats.item(i);
    292       String meta_name = GSXML.getNodeText((Element)GSXML.getChildByTagName(format, OAIXML.METADATA_PREFIX));
    293       if (prefix.equals(meta_name)) {
    294     return format;
    295       }
    296     }
    297     return null;
    298   }
    299     */
    300    
    301     /** goes through the mappings from the collection one, and replaces existing ones in the main one */
    302     /*
    303     protected void addCollectionMappings(Element main_meta_format, Element coll_meta_format) {
    304 
    305       Element element_list = (Element)GSXML.getChildByTagName(main_meta_format, OAIXML.ELEMENT+GSXML.LIST_MODIFIER);
    306       Document doc = element_list.getOwnerDocument();
    307       NodeList coll_elements = coll_meta_format.getElementsByTagName(OAIXML.ELEMENT);
    308       if (coll_elements.getLength()==0) {
    309     // no mappings to include
    310     return;
    311       }
    312       for (int i=0; i<coll_elements.getLength(); i++) {
    313     Element e = (Element)coll_elements.item(i);
    314     String elem_name = e.getAttribute(GSXML.NAME_ATT);
    315     Element main_elem = GSXML.getNamedElement(element_list, OAIXML.ELEMENT, GSXML.NAME_ATT, elem_name);
    316     if (main_elem == null) {
    317       logger.error(elem_name+" not found in meta format, not using it");
    318     } else {
    319       element_list.replaceChild(doc.importNode(e, true),main_elem );
    320       }
    321       }
    322     }
    323     */
    324    
    325     /** goes through all the mappings and makes a set of all collection
    326     metadata names that could become an oai meta element - acts as
    327     a reverse lookup for the mappings */
    328     /*
    329     protected HashSet<String> getAllCollectionElements(Element meta_format) {
    330       HashSet<String> meta_name_set = new HashSet<String>();
    331       NodeList elements = meta_format.getElementsByTagName(OAIXML.ELEMENT);
    332       for (int i=0; i<elements.getLength(); i++) {
    333     Element e = (Element)elements.item(i);
    334     Element map = (Element)GSXML.getChildByTagName(e, OAIXML.MAPPING);
    335     if (map == null) {
    336       // there is no mapping, just use the element name
    337       meta_name_set.add(e.getAttribute(GSXML.NAME_ATT));
    338     } else {
    339       String list_of_names = map.getAttribute(OAIXML.ELEMENTS);
    340       String[] name_array = list_of_names.split(",");
    341       for (int j=0; j<name_array.length; j++) {
    342         meta_name_set.add(name_array[j]);
    343       }
    344     }
    345       }
    346       return meta_name_set;
    347     }
    348     */
    349    
    350161  /** returns a specific service description */
    351162  public Element getServiceDescription(Document doc, String service_id, String lang, String subset) {
    352 
    353       /*
    354     if (service_id.equals(OAIXML.LIST_RECORDS)) {
    355       Element list_records = doc.createElement(GSXML.SERVICE_ELEM);
    356       list_records.setAttribute(GSXML.NAME_ATT, OAIXML.LIST_RECORDS);
    357       list_records.setAttribute(GSXML.TYPE_ATT, "oai");
    358       return list_records;
    359     }
    360    
    361     if (service_id.equals(OAIXML.LIST_IDENTIFIERS)) {
    362       Element list_identifiers = doc.createElement(GSXML.SERVICE_ELEM);
    363       list_identifiers.setAttribute(GSXML.NAME_ATT, OAIXML.LIST_IDENTIFIERS);
    364       list_identifiers.setAttribute(GSXML.TYPE_ATT, "oai");
    365       return list_identifiers;
    366     }
    367     if (service_id.equals(OAIXML.LIST_SETS)) {
    368       Element list_sets = doc.createElement(GSXML.SERVICE_ELEM);
    369       list_sets.setAttribute(GSXML.NAME_ATT, OAIXML.LIST_SETS);
    370       list_sets.setAttribute(GSXML.TYPE_ATT, "oai");
    371       return list_sets;
    372     }
    373     if (service_id.equals(OAIXML.LIST_METADATA_FORMATS)) {
    374       Element list_metadata_formats = doc.createElement(GSXML.SERVICE_ELEM);
    375       list_metadata_formats.setAttribute(GSXML.NAME_ATT, OAIXML.LIST_METADATA_FORMATS);
    376       list_metadata_formats.setAttribute(GSXML.TYPE_ATT, "oai");
    377       return list_metadata_formats;
    378     }
    379       */
    380163     
    381164    if (service_id.equals(IIIFXML.GET_RECORD)) {
     
    388171    return null;
    389172  }
    390 
    391   /** The list sets service returns all the sets that this collection is/is part of/contains. This is gathered by Receptionist from all collections to answer the OAI ListSets request.  */
    392     /*
    393   protected Element processListSets(Element req) {
    394     return list_sets_response;
    395   }
    396     */
    397173   
    398174  /** returns the actual record element used in the OAI GetRecord response */
     
    422198   
    423199    String oid = param_map.get(IIIFXML.OID); // TODO should this be identifier???
    424 
    425     /*
    426     boolean OID_is_deleted = false;
    427     long millis = -1;
    428 
    429     DBInfo oai_info = null;
    430     if(oaiinf_db != null) {
    431     oai_info = this.oaiinf_db.getInfo(oid);
    432     if (oai_info == null) {
    433         logger.warn("OID: " + oid + " is not present in the collection's oai-inf database.");
    434     } else  {
    435 
    436         // indexdb doesn't have info on deleted docs, only oaiinf db does.
    437         // So only oaiinfdb has timestamps for deleted docs
    438         // For non-deleted doc ids: also obtain timestamp from oaiinf db,
    439         // but if the oaiinf db doesn't exist, resort to oailastmodified fields of indexdb.
    440         String timestamp = oai_info.getInfo(OAIXML.OAI_INF_TIMESTAMP); // stored in seconds, like oailastmodified in the collection index db
    441         millis = Long.parseLong(timestamp)*1000; // in milliseconds     
    442        
    443         String oaiinf_status = oai_info.getInfo(OAIXML.OAI_INF_STATUS);
    444         if(oaiinf_status != null && oaiinf_status.equals(OAIXML.OAI_INF_DELETED)) {
    445         OID_is_deleted = true;
    446         }
    447     }
    448     }
    449     */
    450200   
    451201    //get a DBInfo object of the identifier; if this identifier is not present in the database,
     
    459209    }
    460210
    461     /*
    462     else if (millis == -1) { // so couldn't get doc lastmod from oaiinf db, get oailastmodified from collection's index db
    463     millis = getDateStampMillis(info); 
    464     }
    465     String oailastmodified = (millis == -1) ? "" : OAIXML.getTime(millis);
    466     */
    467 
     211
     212    // ****
    468213    Element get_record_response = doc.createElement(GSXML.RESPONSE_ELEM);
    469214    Element get_record = doc.createElement(IIIFXML.GET_RECORD);
     
    472217    //compose the header element
    473218    record.appendChild(createHeaderElement(doc, oid));     
    474     //if(!OID_is_deleted) { // ****
    475     //compose the metadata element
    476     record.appendChild(createMetadataElement(doc, prefix, info));
    477     // } // ****
     219    //compose the metadata element
     220    record.appendChild(createMetadataElement(doc, prefix, info));
    478221    get_record.appendChild(record);
    479222    return get_record_response;
    480223  }
    481224
    482   /** return a list of records in specified set, containing metadata from specified prefix*/
    483     /*
    484   protected Element processListRecords(Element req) {
    485     return processListIdentifiersOrRecords(req, OAIXML.LIST_RECORDS, true);
    486   }
    487     */
    488   /** return a list of identifiers in specified set that contain metadata belonging to specified prefix. */
    489     /*
    490   protected Element processListIdentifiers(Element req) {
    491     return processListIdentifiersOrRecords(req, OAIXML.LIST_IDENTIFIERS, false);
    492   }
    493     */
    494    
    495   // Get a list of records/identifiers that match the parameters.
    496    
    497   //protected Element processListIdentifiersOrRecords(Element req, String response_name, boolean include_metadata) {
    498     /** arguments:
    499         metadataPrefix: required
    500      *  from: optional
    501      *  until: optional
    502      *  set: optional
    503      *  resumptionToken: exclusive and optional (ignored as it has been handled by OAIReceptionist)
    504      *  Exceptions: badArgument; cannotDisseminateFormat; idDoesNotExist
    505      */
    506     /*
    507     NodeList params = GSXML.getChildrenByTagName(req, GSXML.PARAM_ELEM);
    508    
    509     if(params.getLength() == 0) {
    510       logger.error("must at least have the metadataPrefix parameter, can't be none");
    511       return OAIXML.createErrorResponse(OAIXML.BAD_ARGUMENT, "");
    512     }
    513    
    514     HashMap<String, String> param_map = GSXML.getParamMap(params); 
    515    
    516     String prefix = "";
    517     Date from_date = null;
    518     Date until_date = null;
    519    
    520     if(param_map.containsKey(OAIXML.METADATA_PREFIX) == false) {   
    521       //Just a double-check
    522       logger.error("A param element containing the metadataPrefix is not present.");
    523       return OAIXML.createErrorResponse(OAIXML.CANNOT_DISSEMINATE_FORMAT, "");
    524     }
    525     prefix = param_map.get(OAIXML.METADATA_PREFIX);
    526     if (prefix == null || prefix.equals("")) {
    527       //Just a double-check
    528       logger.error("the value of metadataPrefix att is not present in the request.");
    529       return OAIXML.createErrorResponse(OAIXML.CANNOT_DISSEMINATE_FORMAT, "");
    530     }
    531    
    532     if(param_map.containsKey(OAIXML.FROM)) {
    533       String from = param_map.get(OAIXML.FROM);
    534       from_date = OAIXML.getDate(from);
    535     }   
    536     if(param_map.containsKey(OAIXML.UNTIL)) {
    537       String until = param_map.get(OAIXML.UNTIL);
    538       until_date = OAIXML.getDate(until);
    539     }   
    540 
    541     if (!format_response_map.containsKey(prefix)) {
    542       logger.error(prefix + " metadata prefix is not supported for collection "+this.coll_name);
    543       return OAIXML.createErrorResponse(OAIXML.CANNOT_DISSEMINATE_FORMAT, "");
    544     }
    545 
    546     // get list of oids
    547     ArrayList<String> oid_list = null;
    548     if(oaiinf_db != null) { // try getting the OIDs from the oaiinf_db
    549     oid_list = new ArrayList<String>(oaiinf_db.getAllKeys());
    550    
    551     if(oid_list == null) { // try getting the OIDs from the oai entries in the index db
    552         logger.warn("@@@@@@@@@@@@@ NO OIDs in oai-inf db for " + this.cluster_name);
    553         oid_list = getChildrenIds(OAIXML.BROWSELIST);
    554     }
    555     }
    556 
    557     if (oid_list == null) {
    558       logger.error("No matched records found in collection: oai-inf and index db's browselist are empty");
    559       return OAIXML.createErrorResponse(OAIXML.NO_RECORDS_MATCH, "");
    560     }
    561     // all validation is done
    562 
    563     // get the list of elements that are in this metadata prefix
    564     HashSet<String> set_of_elems = format_elements_map.get(prefix);
    565 
    566     Document doc = XMLConverter.newDOM();
    567     Element list_items_response = doc.createElement(GSXML.RESPONSE_ELEM);
    568     Element list_items = doc.createElement(response_name);
    569     list_items_response.appendChild(list_items);
    570 
    571     for(int i=0; i<oid_list.size(); i++) {
    572       String oid = oid_list.get(i);
    573 
    574       if(oid.equals(OAIXML.OAI_EARLIEST_TIMESTAMP_OID)) { // internal id not doc id, so skip
    575       continue;
    576       }
    577      
    578       boolean OID_is_deleted = false;
    579       long millis = -1;
    580 
    581       DBInfo oai_info = null;
    582       if(oaiinf_db != null) {
    583       oai_info = this.oaiinf_db.getInfo(oid);
    584       if (oai_info == null) {
    585           logger.warn("OID: " + oid + " is not present in the collection's oai-inf database.");
    586       } else  {
    587          
    588           // indexdb doesn't have info on deleted docs, only oaiinf db does.
    589           // So only oaiinfdb has timestamps for deleted docs
    590           // For non-deleted doc ids: also obtain timestamp from oaiinf db,
    591           // but if the oaiinf db doesn't exist, resort to oailastmodified fields of indexdb.
    592           String timestamp = oai_info.getInfo(OAIXML.OAI_INF_TIMESTAMP); // stored in seconds like oailastmodified in the collection index db         
    593           millis = Long.parseLong(timestamp)*1000; // in milliseconds
    594          
    595           String oaiinf_status = oai_info.getInfo(OAIXML.OAI_INF_STATUS);
    596           if(oaiinf_status != null && oaiinf_status.equals(OAIXML.OAI_INF_DELETED)) {
    597           OID_is_deleted = true;
    598           }
    599       }
    600       }
    601       DBInfo info = this.coll_db.getInfo(oid);
    602       if (info == null) { // can happen if oid was deleted, in which case only oai_info keeps a record of the oid
    603       if(!OID_is_deleted) { // we don't expect to find entries for deleted docs in index db.
    604           logger.error("Collection database does not contain information about oid: " +oid);
    605       }
    606       }
    607       else if (millis == -1) { // so couldn't get doc lastmod from oaiinf db, get oailastmodified from collection's index db
    608      
    609       millis = getDateStampMillis(info);
    610       }
    611 
    612       Date this_date = null;
    613       String oailastmodified = (millis == -1) ? "" : OAIXML.getTime(millis);
    614      
    615       if (millis == -1) {
    616       if (from_date != null || until_date !=null) {
    617           continue; // if this doc doesn't have a date for some reason, and
    618           // we are doing a date range, then don't include it.
    619       }
    620       } else {
    621       this_date = new Date(millis);
    622       if (from_date != null) {
    623           if(this_date.before(from_date)) {
    624           continue;
    625           }
    626       }
    627       if (until_date != null) {
    628           if (this_date.after(until_date)) {
    629           continue;
    630           }
    631       }   
    632       }
    633      
    634       //compose the header element, which we'll be appending no matter what
    635       Element header = createHeaderElement(doc, oid, oailastmodified, OID_is_deleted);
    636 
    637       if (include_metadata) { // doing ListRecords
    638       // compose a record for adding header and metadata
    639       Element record = doc.createElement(OAIXML.RECORD);
    640       list_items.appendChild(record);
    641       //insert the header element
    642       record.appendChild(header);
    643       //Now check that this id has metadata for the required prefix.
    644       if (info != null && documentContainsMetadata(info, set_of_elems)) {
    645           // YES, it does have some metadata for this prefix       
    646           //compose the metadata element
    647           record.appendChild(createMetadataElement(doc, prefix, info));
    648       } // otherwise the oid was 'deleted' and only in the oai-inf db and not in the info (collection index) db
    649       } else { // doing ListIdentifiers
    650       //append the header element
    651       list_items.appendChild(header);     
    652       }     
    653      
    654     }//end of for(int i=0; i<oid_list.size(); i++) of doing thru each record
    655    
    656     return list_items_response;       
    657    
    658   }
    659 */
    660  
    661   // have implemented setDescription as an element, instead of a container containing metadata
    662 /*
    663   private boolean configureSetInfo() {
    664 
    665     Document doc = XMLConverter.newDOM();
    666     this.list_sets_response = doc.createElement(GSXML.RESPONSE_ELEM);
    667     Element list_sets_elem = doc.createElement(OAIXML.LIST_SETS);
    668     this.list_sets_response.appendChild(list_sets_elem);
    669     String set_name = this.coll_name;
    670     String set_description = null;
    671     Element name_elem = (Element)GSXML.getChildByTagName(this.config_info, OAIXML.SET_NAME);
    672     if (name_elem!=null) {
    673       set_name = GSXML.getNodeText(name_elem);
    674       if (set_name.equals("")) {
    675     set_name = this.coll_name; // default to coll name if can't find one
    676       }
    677     }
    678     Element description_elem = (Element)GSXML.getChildByTagName(this.config_info, OAIXML.SET_DESCRIPTION);
    679     if (description_elem!=null) {
    680       set_description = GSXML.getNodeText(description_elem);
    681       if (set_description.equals("")) {
    682     set_description = null;
    683       }
    684     }
    685     Element coll_set = OAIXML.createSet(doc, this.coll_name, set_name, set_description);
    686     list_sets_elem.appendChild(coll_set);
    687    
    688     // are we part of any super sets?
    689     NodeList super_set_list = GSXML.getChildrenByTagName(this.config_info, OAIXML.OAI_SUPER_SET);
    690     for (int i=0; i<super_set_list.getLength(); i++) {
    691       String super_name = ((Element)super_set_list.item(i)).getAttribute(GSXML.NAME_ATT);
    692       if (super_name != null && !super_name.equals("")) {
    693     list_sets_elem.appendChild(OAIXML.createSet(doc, super_name, super_name, null));
    694       }
    695     }
    696     return true;
    697   }
    698 */
    699225   
    700226 /** create the metadata element used when processing ListRecords/GetRecord requests
     
    804330        Element header = doc.createElement(OAIXML.HEADER);
    805331   
    806     // if deleted, get the date and change oailastmodified to timestamp in oaiinfo
    807     /*
    808     if(deleted) {
    809         header.setAttribute(OAIXML.OAI_INF_STATUS, OAIXML.HEADER_STATUS_ATTR_DELETED); // set the header status to deleted
    810         // then the timestamp for deletion will be from oai-inf database
    811     }
    812     */
    813332        Element identifier = doc.createElement(IIIFXML.IDENTIFIER);
    814333    GSXML.setNodeText(identifier, coll_name + ":" + oid);
    815334        header.appendChild(identifier);
    816     /*
    817         Element set_spec = doc.createElement(OAIXML.SET_SPEC);
    818     GSXML.setNodeText(set_spec, coll_name);
    819         header.appendChild(set_spec);
    820         Element datestamp = doc.createElement(OAIXML.DATESTAMP);
    821         GSXML.setNodeText(datestamp, oailastmodified);
    822         header.appendChild(datestamp);
    823     */
     335
    824336        return header;
    825337  }
    826338
    827    
    828   /** return the metadata information  */
    829 /*
    830   protected Element processListMetadataFormats(Element req) {
    831     // the request sent here must contain an OID. see doListMetadataFormats() in OAIReceptionist
    832     Element param = GSXML.getNamedElement(req, GSXML.PARAM_ELEM, GSXML.NAME_ATT, OAIXML.OID);
    833     if (param == null) {
    834       logger.error("An element containing the OID attribute not is present.");
    835       return OAIXML.createErrorResponse(OAIXML.ID_DOES_NOT_EXIST, "");
    836     }
    837     String oid = param.getAttribute(GSXML.VALUE_ATT);
    838     if (oid == null || oid.equals("")) {
    839       logger.error("No OID is present in the request.");
    840       return OAIXML.createErrorResponse(OAIXML.ID_DOES_NOT_EXIST, "");
    841     }
    842 */
    843     /*
    844     ArrayList<String> oid_list = null;
    845     if(oaiinf_db != null) { // try getting the OIDs from the oaiinf_db
    846     oid_list = new ArrayList<String>(oaiinf_db.getAllKeys());
    847    
    848     if(oid_list == null) { // try getting the OIDs from the oai entries in the index db
    849         oid_list = getChildrenIds(OAIXML.BROWSELIST);
    850     }
    851     }
    852     */
    853 /*
    854     // assume meta formats are only for OIDs that have not been deleted
    855     // so don't need to check oai-inf db, and can just check collection's index db for list of OIDs
    856     ArrayList<String> oid_list = getChildrenIds(OAIXML.BROWSELIST);
    857     if (oid_list == null || oid_list.contains(oid) == false) {
    858       logger.error("OID: " + oid + " is not present in the database.");
    859       Element e= OAIXML.createErrorResponse(OAIXML.ID_DOES_NOT_EXIST, "");
    860 //      logger.error((new XMLConverter()).getPrettyString (e));
    861       return e;
    862     }
    863    
    864     DBInfo info = null;   
    865     info = this.coll_db.getInfo(oid);
    866     if (info == null) { //just double check
    867       return OAIXML.createErrorResponse(OAIXML.OAI_SERVICE_UNAVAILABLE, "");
    868     }
    869    
    870     Document doc = XMLConverter.newDOM();
    871     Element list_metadata_formats_response = doc.createElement(GSXML.RESPONSE_ELEM);
    872    
    873     Element list_metadata_formats = doc.createElement(OAIXML.LIST_METADATA_FORMATS);
    874     list_metadata_formats_response.appendChild(list_metadata_formats);
    875     boolean has_meta_format = false;
    876    
    877     // for each format in format_elements_map
    878     Iterator<String> it = format_elements_map.keySet().iterator();
    879     while (it.hasNext()) {
    880       String format = it.next();
    881       HashSet<String> set_of_elems = format_elements_map.get(format);
    882       if (documentContainsMetadata(info, set_of_elems)) {
    883     // add this format into the response
    884     has_meta_format = true;
    885     list_metadata_formats.appendChild(doc.importNode(format_response_map.get(format), true));
    886       }
    887     }
    888 
    889     if (has_meta_format == false) {
    890       logger.error("Specified metadata names are not contained in the database.");
    891       return OAIXML.createErrorResponse(OAIXML.NO_METADATA_FORMATS, "");
    892     } else {
    893       return list_metadata_formats_response;
    894     }
    895   }
    896 */
    897 /*
    898   protected boolean documentContainsMetadata(DBInfo info, HashSet<String> set_of_elems) {
    899     if (set_of_elems.size() == 0) {
    900       return false;
    901     }
    902     Iterator<String> i = set_of_elems.iterator();
    903     while (i.hasNext()) {
    904       if (!info.getInfo(i.next()).equals("")) {
    905     return true;
    906       }
    907     }
    908     return false;
    909   }
    910 */
    911 
    912   /** returns a list of the child ids in order, null if no children */
    913 /*
    914   protected ArrayList<String> getChildrenIds(String node_id) {
    915     DBInfo info = this.coll_db.getInfo(node_id);
    916     if (info == null) {
    917       return null;
    918     }
    919    
    920     String contains = info.getInfo("contains");
    921     if (contains.equals("")) {
    922       return null;
    923     }
    924     ArrayList<String> children = new ArrayList<String>();
    925     StringTokenizer st = new StringTokenizer(contains, ";");
    926     while (st.hasMoreTokens()) {
    927       String child_id = st.nextToken().replaceAll("\"", node_id);
    928       children.add(child_id);
    929     }
    930     return children;   
    931   }
    932 */
    933    
    934   /**method to check whether any of the 'metadata_names' is contained in the 'info'.
    935    * The name may be in the form: <name>,<mapped name>, in which the mapped name is
    936    * optional. The mapped name is looked up in the DBInfo; if not present, use the first
    937    * name which is mandatory.
    938    */
    939 /*
    940   protected boolean containsMetadata(DBInfo info, String[] metadata_names) {
    941     if (metadata_names == null) return false;
    942     logger.info("checking metadata names in db.");
    943     for(int i=0; i<metadata_names.length; i++) {
    944       int index = metadata_names[i].indexOf(",");
    945       String meta_name = (index == -1) ? metadata_names[i] :
    946                               metadata_names[i].substring(index + 1);
    947      
    948       if(info.getInfo(meta_name).equals("") == false) {
    949         return true;
    950       }
    951     }
    952     return false;
    953   }
    954 */
    955 /*
    956   protected long getDateStampMillis(DBInfo info) {
    957     // gs.OAIDateStamp is in YYYY-MM-DD
    958     String time_stamp = info.getInfo(OAIXML.GS_OAI_DATE_STAMP);
    959     long millis = -1;
    960     if (!time_stamp.equals("")) {
    961       millis = OAIXML.getTime(time_stamp);
    962     }
    963     if (millis == -1) {
    964       // oailastmodified is in seconds
    965       time_stamp = info.getInfo(OAIXML.OAI_LASTMODIFIED);
    966       if (!time_stamp.equals("")) {
    967     millis = Long.parseLong(time_stamp)*1000;
    968       }
    969     }
    970     return millis;
    971    
    972 
    973   }
    974 */
    975339}
    976340
Note: See TracChangeset for help on using the changeset viewer.