Changeset 36242


Ignore:
Timestamp:
2022-06-07T10:25:42+12:00 (4 weeks ago)
Author:
kjdon
Message:

gs2, all index/level/sort search metas have the same type. We need to avoid duplicates, so use a LInkedHashSet (no duplicates, and keeps insertion order)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • main/trunk/gli/src/org/greenstone/gatherer/cdm/SearchMetadataManager.java

    r36186 r36242  
    3030import javax.swing.table.*;
    3131import java.util.ArrayList;
     32import java.util.LinkedHashSet;
    3233
    3334import org.greenstone.gatherer.Configuration;
     
    8081
    8182    public SearchMeta getMetadatum(String name, String type, boolean add_if_not_found) {
    82     System.err.println("Get the metadata for " + name + " type="+type+" in the default language.");
    8383    int size = getSize();
    84     System.err.println("size of searchmeta = "+size);
    8584    if (size == 0) {
    8685        return null;
     
    8887    for(int i = 0; i < size; i++) {
    8988        SearchMeta metadatum = (SearchMeta) getElementAt(i);
    90         System.err.println("checking meta = "+metadatum);
    9189        if(metadatum.getName().equals(name) && metadatum.getType().equals(type) && metadatum.getLanguage().equals(Configuration.getLanguage())) {
    92         DebugStream.println("Found '" + metadatum + "'");
     90        //DebugStream.println("Found '" + metadatum + "'");
    9391        return metadatum;
    9492        }
     
    10199        SearchMeta result = new SearchMeta(name, type);
    102100        addMetadatum(result);
    103         DebugStream.println("Added new metadata: " + name);
     101        //DebugStream.println("Added new metadata: " + name);
    104102        return result;
    105103    }
     
    183181   
    184182    private ArrayList getEntries() {
    185     ArrayList entries = new ArrayList();
     183    LinkedHashSet entries = new LinkedHashSet();
    186184   
    187185    ArrayList indexes = CollectionDesignManager.index_manager.getIndexes();
     
    191189          String index_id = ((Index)indexes.get(i)).getID();
    192190          if (!index_id.equals(METADATA_INDEX)) {
    193           System.err.println("new sme, id="+index_id);
    194191        SearchMetadataEntry sme = new SearchMetadataEntry(index_id, SearchMeta.TYPE_INDEX);
    195192        entries.add(sme);
    196193          }
    197         }
    198     }
    199     ArrayList levels = CollectionDesignManager.index_manager.getLevels();
    200     if (levels != null) {
    201         int levels_size = levels.size();
    202         for (int i=0; i<levels_size; i++) {
    203         SearchMetadataEntry sme = new SearchMetadataEntry(((IndexOption)levels.get(i)).getName(), SearchMeta.TYPE_LEVEL);
    204         entries.add(sme);
    205194        }
    206195    }
     
    212201              SearchMetadataEntry sme = new SearchMetadataEntry(sf_id, SearchMeta.TYPE_SORT);
    213202        entries.add(sme);
     203
    214204        }
    215205    }
     
    224214    }
    225215
     216    ArrayList levels = CollectionDesignManager.index_manager.getLevels();
     217    if (levels != null) {
     218        int levels_size = levels.size();
     219        for (int i=0; i<levels_size; i++) {
     220        SearchMetadataEntry sme = new SearchMetadataEntry(((IndexOption)levels.get(i)).getName(), SearchMeta.TYPE_LEVEL);
     221        entries.add(sme);
     222        }
     223    }
     224
    226225       
    227226    ArrayList partitions = CollectionDesignManager.subcollectionindex_manager.getSubcollectionIndexes();
     
    242241        }
    243242    }
    244     return entries;
     243    ArrayList list_entries = new ArrayList();
     244    list_entries.addAll(entries);
     245    return list_entries;
    245246    }
    246247   
     
    254255
    255256    public SearchMetadataEntry(String id, String type) {
     257        if (!Gatherer.GS3) {
     258        type = SearchMeta.TYPE_SEARCH;
     259        }
    256260        this.id = id;
    257261        this.type = type;
    258262        //coll_meta = collmeta_manager.getMetadatum(getMetaID(), type);
    259263        this.coll_meta = getMetadatum(id, type); //getMetaID(), type);
    260         this.value = coll_meta.getValue(CollectionMeta.GREENSTONE);
     264        if (this.coll_meta != null) {
     265        this.value = coll_meta.getValue(CollectionMeta.GREENSTONE);
     266        }
    261267    }
    262268   
     
    264270        return Dictionary.get("CDM.SearchMetadataManager.Type_"+type)+": "+id;
    265271    }
    266    
     272    public boolean equals(Object sme) {
     273        if (sme instanceof SearchMetadataEntry) {
     274        if (id.equals(((SearchMetadataEntry)sme).id) && type.equals(((SearchMetadataEntry)sme).type)) {
     275            return true;
     276        }
     277        return false;
     278        }
     279        return toString().equals(sme.toString());
     280   
     281    }
    267282    public String getMetaID() {
    268283      if (Gatherer.GS3) {
Note: See TracChangeset for help on using the changeset viewer.