Project

General

Profile

« Previous | Next » 

Revision 7740

Added by Jing Tao over 11 years ago

Index the none-resourcemap data objects first, then the resourcemap objects.

View differences:

metacat-index/src/main/java/edu/ucsb/nceas/metacat/index/IndexGenerator.java
45 45
import org.dataone.service.exceptions.NotImplemented;
46 46
import org.dataone.service.exceptions.ServiceFailure;
47 47
import org.dataone.service.types.v1.Identifier;
48
import org.dataone.service.types.v1.ObjectFormatIdentifier;
48 49
import org.dataone.service.types.v1.ObjectInfo;
49 50
import org.dataone.service.types.v1.ObjectList;
50 51
import org.dataone.service.types.v1.SystemMetadata;
......
63 64
 */
64 65
public class IndexGenerator implements Runnable {
65 66
    
67
    private static final int FIRST =0;
68
    private static final int SECOND =1;
66 69
    private static final int WAITTIME = 10000;
67 70
    private static final int MAXWAITNUMBER = 180;
68 71
    private static final String HTTP = "http://";
69 72
    private static final String MNAPPENDIX = "/d1/mn";
73
    private static final String RESOURCEMAPPROPERYNAME = "index.resourcemap.namespace";
70 74
    private SolrIndex solrIndex = null;
71 75
    //private SystemMetadataEventListener systemMetadataListener = null;
72 76
    private IMap<Identifier, SystemMetadata> systemMetadataMap;
......
74 78
    private IMap<Identifier, String> objectPathMap;
75 79
    private Log log = LogFactory.getLog(IndexGenerator.class);
76 80
    private MNode mNode = null;
81
    private List<String> resourceMapNamespaces = null;
77 82
    
78 83
    /**
79 84
     * Constructor
......
82 87
     */
83 88
    public IndexGenerator(SolrIndex solrIndex) {
84 89
        this.solrIndex = solrIndex;
90
        resourceMapNamespaces = Settings.getConfiguration().getList(RESOURCEMAPPROPERYNAME);
85 91
        //this.systemMetadataListener = systemMetadataListener;
86 92
        this.mNode = new MNode(buildMNBaseURL());
87 93
    }
......
152 158
    public void index(Date since, Date until, boolean force) throws SolrServerException, InvalidRequest, 
153 159
                                                InvalidToken, NotAuthorized, NotImplemented, ServiceFailure, FileNotFoundException {
154 160
        List<String> solrIds = null;
155
        List<String> metacatIds = null;
156
        metacatIds = getMetadataIds(since, until);
157
        log.info("the metacat ids -----------------------------"+metacatIds);
161
        initSystemMetadataMap();
162
        initObjectPathMap();
163
        List[] allMetacatIds = getMetadataIds(since, until);
164
        List<String> otherMetacatIds = allMetacatIds[FIRST];
165
        List<String> resourceMapIds = allMetacatIds[SECOND];
166
        log.info("the metacat ids (exception resource map -----------------------------"+otherMetacatIds);
167
        log.info("the metacat resroucemap ids -----------------------------"+resourceMapIds);
158 168
        if(!force) {
159 169
            solrIds = getSolrDocIds();
160 170
        }
161 171
        log.info("the solr ids -----------------------------"+solrIds);
172
        index(otherMetacatIds, solrIds, force);
173
        index(resourceMapIds, solrIds, force);
174
       
162 175
        
163
        initSystemMetadataMap();
164
        initObjectPathMap();
176
    }
177
    
178
    /*
179
     * Doing index when it is necessary when compare metacatids and solrids.
180
     */
181
    private void index(List<String> metacatIds, List<String>solrIds, boolean force) {
165 182
        if(metacatIds != null) {
166 183
            for(String metacatId : metacatIds) {
167 184
                if(metacatId != null) {
......
224 241
    }
225 242
    
226 243
    /*
227
     * Get the ids of the metacat. If since and util are null, it will return all of them
244
     * Get an array of the list of ids of the metacat. If since and util are null, it will return all of them.
245
     * The first element of the list is the ids except the resource map. The second elements of the list is the ids of the resource map.
246
     * The reason to split them is when we index the resource map, we need the index of the document in the resource map ready.
228 247
     */
229
    private List<String> getMetadataIds(Date since, Date until) throws InvalidRequest, 
248
    private List[] getMetadataIds(Date since, Date until) throws InvalidRequest, 
230 249
                        InvalidToken, NotAuthorized, NotImplemented, ServiceFailure {
231
        List<String> ids = new ArrayList();
250
        
251
        List<String> resourceMapIds = new ArrayList();
252
        List<String> otherIds = new ArrayList();
253
        List[] ids = new List[2];
254
        ids[FIRST]= otherIds;
255
        ids[SECOND] = resourceMapIds;
232 256
        ObjectList objects = null;
233 257
        int times = 0;
234 258
        while (true) {
......
265 289
                    if(info != null) {
266 290
                        Identifier identifier = info.getIdentifier();
267 291
                        if(identifier != null && identifier.getValue() != null && !identifier.getValue().equals("")) {
268
                            ids.add(identifier.getValue());
292
                            SystemMetadata sysmeta = getSystemMetadata(identifier.getValue());
293
                            if(sysmeta != null && !sysmeta.getArchived()) {
294
                                ObjectFormatIdentifier formatId =sysmeta.getFormatId();
295
                                //System.out.println("the object format id is "+formatId.getValue());
296
                                //System.out.println("the ============ resourcMapNamespaces"+resourceMapNamespaces);
297
                                if(formatId != null && formatId.getValue() != null && resourceMapNamespaces != null && isResourceMap(formatId)) {
298
                                    resourceMapIds.add(identifier.getValue());
299
                                } else {
300
                                    otherIds.add(identifier.getValue());
301
                                }
302
                            }
303
                            //ids.add(identifier.getValue());
269 304
                        }
270 305
                    }
271 306
                }
......
275 310
    }
276 311
    
277 312
    /*
313
     * If the specified ObjectFormatIdentifier is a resrouce map namespace.
314
     */
315
    private boolean isResourceMap(ObjectFormatIdentifier formatId) {
316
        boolean isResourceMap = false;
317
        if(formatId != null && resourceMapNamespaces != null) {
318
            for(String namespace : resourceMapNamespaces) {
319
                if(namespace != null && formatId.getValue() != null && !formatId.getValue().trim().equals("") && formatId.getValue().equals(namespace)) {
320
                    isResourceMap = true;
321
                    break;
322
                }
323
            }
324
        }
325
        return isResourceMap;
326
    }
327
    
328
    /*
278 329
     * Build up the mn base url
279 330
     */
280 331
    private String buildMNBaseURL() {

Also available in: Unified diff