Changeset 33341

Show
Ignore:
Timestamp:
23.07.2019 11:07:30 (4 weeks ago)
Author:
kjdon
Message:

tidied up relational metadata retrieval. implemented descendants and entire. make all metadata come from getMetaValuesForOID - that way all get the [xxx] metadata replacement opportunity. now it handles [parent(Top):assocfilepath]

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • main/trunk/greenstone3/src/java/org/greenstone/gsdl3/service/AbstractGS2DocumentRetrieve.java

    r32467 r33341  
    227227    if (index == -1) { 
    228228      // metadata is for this node 
    229       return info.getMultiInfo(metadata); 
     229      return getMetaValuesForOID(node_id, current_info, metadata); 
    230230    } 
    231231    // we need to get metadata for one or more different nodes 
    232     // we have a relation root, parent, ancestors, siblings, children, descendents 
     232    // we have a relation root, parent, ancestors, siblings, children, descendants, entire 
    233233    String relation = metadata.substring(0, index); 
    234234    String relation_id=""; 
     
    236236    if (relation.equals("root")) { 
    237237      relation_id = OID.getTop(node_id); 
    238       if (relation_id.equals(node_id)) { 
    239     // use the current node info 
    240     return info.getMultiInfo(metadata); 
    241       } else { 
    242     return getMetaValuesForOID(relation_id, metadata); 
    243       } 
    244     } 
     238      if (!relation_id.equals(node_id)) { 
     239    // get the dbinfo for the root node 
     240    current_info = this.coll_db.getInfo(relation_id); 
     241      } 
     242      return getMetaValuesForOID(relation_id, current_info, metadata); 
     243    } 
     244     
    245245    if (relation.equals("parent")) { 
    246246      relation_id = OID.getParent(node_id); 
     
    249249    return null; 
    250250      } 
    251       return getMetaValuesForOID(relation_id, metadata); 
     251      return getMetaValuesForOID(relation_id, null, metadata); 
    252252    } 
    253253 
     
    261261      while (!relation_id.equals(current_id)) { 
    262262     
    263     Vector<String> more_values = getMetaValuesForOID(relation_id, metadata); 
     263    Vector<String> more_values = getMetaValuesForOID(relation_id, null, metadata); 
    264264    if (more_values != null) { 
    265265      values.addAll(0, more_values); 
     
    283283    return null; 
    284284      } 
    285     } 
     285      // drop through to children part 
     286    } 
     287 
     288    Vector<String> values = new Vector<String>(); 
    286289    if (relation.equals("children")) { 
    287       Vector<String> values = new Vector<String>(); 
    288       String contains = current_info.getInfo("contains"); 
     290      processChildren(node_id, current_info, metadata, values, false); 
     291     return values; 
     292    } 
     293     
     294    if (relation.equals("entire")) { 
     295      // this is the same as doing descendants on root 
     296      relation_id = OID.getTop(node_id); 
     297       
     298      // first of all, add root node info 
     299       
     300      if (relation_id.equals(node_id)) { 
     301    current_info = info; 
     302      } else { 
     303    current_info = this.coll_db.getInfo(relation_id); 
     304      } 
     305      values = getMetaValuesForOID(relation_id, current_info, metadata); 
     306 
     307      node_id = relation_id; 
     308      relation = "descendants"; 
     309      // drop through to next part 
     310    } 
     311 
     312 
     313    if (relation.equals("descendants")) { 
     314      processChildren(node_id, current_info, metadata, values, true); 
     315      return values; 
     316    } 
     317    // unknown relation 
     318    // we assume that maybe the metadata has an _ in the name, so get the original name 
     319    return info.getMultiInfo(relation+GSConstants.META_RELATION_SEP+metadata); 
     320 
     321  } 
     322       
     323    protected void processChildren(String node_id, DBInfo info, String metadata, Vector<String> values, 
     324                   boolean recursive) { 
     325      String contains = info.getInfo("contains"); 
    289326      contains = StringUtils.replace(contains, "\"", node_id); 
    290327      String[] children = contains.split(";");  
     
    292329     
    293330    String child_id = children[i]; 
    294     Vector<String> more_values = getMetaValuesForOID(child_id, metadata); 
     331    Vector<String> more_values = getMetaValuesForOID(child_id, null, metadata); 
    295332    if (more_values != null) { 
    296333      values.addAll(more_values); 
    297334    } 
    298       } 
    299       return values; 
    300     }  
    301     if (relation.equals("descendents")) { 
     335    if (recursive) { 
     336       DBInfo child_info = this.coll_db.getInfo(child_id); 
     337       processChildren(child_id, child_info, metadata, values, recursive); 
     338    } 
     339      } 
     340    } 
     341     
     342  protected Vector<String> getMetaValuesForOID(String oid, DBInfo info, String metadata) { 
     343     
     344    DBInfo this_info; 
     345    if (info != null) { 
     346      this_info = info; 
     347    } else { 
     348      this_info = this.coll_db.getInfo(oid); 
     349    } 
     350    if (this_info == null) { 
    302351      return null; 
    303352    } 
    304     // unknown relation 
    305     // we assume that maybe the metadata has an _ in the name, so get the original name 
    306     return info.getMultiInfo(relation+GSConstants.META_RELATION_SEP+metadata); 
    307  
    308   } 
    309353       
    310  
    311     protected Vector<String> getMetaValuesForOID(String oid, String metadata) { 
    312       DBInfo info = this.coll_db.getInfo(oid); 
    313       if (info == null) { 
    314     return null; 
    315       } 
    316        
    317       Vector<String> values = info.getMultiInfo(metadata); 
     354      Vector<String> values = this_info.getMultiInfo(metadata); 
    318355      // lets look through the values and look for [xxx] things. We need to look up metadata for them. 
    319356      if (values == null) { return values; } 
     
    326363      for (int i=0; i<metas.length; i++) { 
    327364        String meta = metas[i]; 
    328         String meta_val = info.getInfo(meta); 
     365        String meta_val; 
     366        // hack for parent(Top). gs2 had lots of other modifiers, but is this the only one that was used in 
     367        // metadata values?? 
     368        if (meta.startsWith("parent(Top):")) { 
     369          String nmeta = meta.substring(12); // or 13? 
     370          String root_id = OID.getTop(oid); 
     371          DBInfo root_info = this.coll_db.getInfo(root_id); 
     372          meta_val = root_info.getInfo(nmeta); 
     373        } else { 
     374          meta_val = this_info.getInfo(meta); 
     375        } 
    329376        if (!meta_val.equals("")) { 
    330377          val = StringUtils.replace(val,"["+meta+"]",meta_val);