Project

General

Profile

« Previous | Next » 

Revision 7857

Added by Jing Tao over 11 years ago

Add code to handle failed ids.

View differences:

metacat-index/src/main/java/edu/ucsb/nceas/metacat/index/IndexGenerator.java
30 30
import java.io.FileNotFoundException;
31 31
import java.io.InputStream;
32 32
import java.util.ArrayList;
33
import java.util.Calendar;
33 34
import java.util.Date;
34 35
import java.util.List;
35 36
import java.util.TimerTask;
......
43 44
import org.dataone.service.exceptions.NotAuthorized;
44 45
import org.dataone.service.exceptions.NotImplemented;
45 46
import org.dataone.service.exceptions.ServiceFailure;
47
import org.dataone.service.types.v1.Event;
46 48
import org.dataone.service.types.v1.Identifier;
47 49
import org.dataone.service.types.v1.ObjectFormatIdentifier;
48 50
import org.dataone.service.types.v1.SystemMetadata;
......
219 221
        
220 222
        //add the failedPids 
221 223
        List<IndexEvent> failedEvents = EventlogFactory.createIndexEventLog().getEvents(null, null, null, null);
222
        List<String> failedOtherIds = new ArrayList<String>();
223
        List<String> failedResourceMapIds = new ArrayList<String>();
224
        List<IndexEvent> failedOtherIds = new ArrayList<IndexEvent>();
225
        List<IndexEvent> failedResourceMapIds = new ArrayList<IndexEvent>();
224 226
        if(failedEvents != null) {
225 227
            for(IndexEvent event : failedEvents) {
226 228
            	String id = event.getIdentifier().getValue();
227 229
                SystemMetadata sysmeta = getSystemMetadata(id);
228
                if(sysmeta != null && !sysmeta.getArchived()) {
230
                if(sysmeta != null) {
229 231
                    ObjectFormatIdentifier formatId =sysmeta.getFormatId();
230 232
                    if(formatId != null && formatId.getValue() != null && resourceMapNamespaces != null && isResourceMap(formatId)) {
231
                        failedResourceMapIds.add(id);
233
                        failedResourceMapIds.add(event);
232 234
                    } else {
233
                        failedOtherIds.add(id);
235
                        failedOtherIds.add(event);
234 236
                    }
235 237
                }
236 238
            }
237 239
        }
240
        indexFailedIds(failedOtherIds);
241
        indexFailedIds(failedResourceMapIds);
238 242
        
239
        if(!failedOtherIds.isEmpty()) {
243
        /*if(!failedOtherIds.isEmpty()) {
240 244
            failedOtherIds.addAll(otherMetacatIds);
241 245
        } else {
242 246
            failedOtherIds = otherMetacatIds;
......
246 250
            failedResourceMapIds.addAll(resourceMapIds);
247 251
        } else {
248 252
            failedResourceMapIds = resourceMapIds;
249
        }
253
        }*/
250 254
        
251
        log.info("the metacat ids (exception resource map -----------------------------"+failedOtherIds);
252
        log.info("the metacat resroucemap ids -----------------------------"+failedResourceMapIds);
253
        index(failedOtherIds);
254
        index(failedResourceMapIds);
255
        log.info("the metacat ids (except the resource map ids)-----------------------------"+otherMetacatIds);
256
        log.info("the metacat resroucemap ids -----------------------------"+resourceMapIds);
257
        index(otherMetacatIds);
258
        index(resourceMapIds);
255 259
       
256 260
        //record the timed index.
257 261
        if(processedDate != null) {
......
270 274
                        try {
271 275
                            generateIndex(metacatId);
272 276
                        } catch (Exception e) {
273
                            log.error("IndexGenerator.index - Metacat Index couldn't generate the index for the id - "+metacatId+" because "+e.getMessage());
277
                            IndexEvent event = new IndexEvent();
278
                            Identifier pid = new Identifier();
279
                            pid.setValue(metacatId);
280
                            event.setIdentifier(pid);
281
                            event.setDate(Calendar.getInstance().getTime());
282
                            event.setAction(Event.CREATE);
283
                            String error = "IndexGenerator.index - Metacat Index couldn't generate the index for the id - "+metacatId+" because "+e.getMessage();
284
                            event.setDescription(error);
285
                            try {
286
                                EventlogFactory.createIndexEventLog().write(event);
287
                            } catch (Exception ee) {
288
                                log.error("SolrIndex.insertToIndex - IndexEventLog can't log the index inserting event :"+ee.getMessage());
289
                            }
290
                            log.error(error);
274 291
                        }
275 292
                        
276 293
                   
......
279 296
        }
280 297
    }
281 298
    
299
    /*
300
     * Index those ids which failed in the process (We got them from the EventLog)
301
     */
302
    private void indexFailedIds(List<IndexEvent> events) {
303
        if(events != null) {
304
            for(IndexEvent event : events) {
305
                if(event != null) {
306
                    Identifier identifier = event.getIdentifier();
307
                    if(identifier != null) {
308
                        String id = identifier.getValue();
309
                        if(id != null) {
310
                            Event action = event.getAction();
311
                            if (action != null && action.equals(Event.CREATE)) {
312
                                try {
313
                                    generateIndex(id);
314
                                    EventlogFactory.createIndexEventLog().remove(identifier);
315
                                } catch (Exception e) {
316
                                    log.error("IndexGenerator.indexFailedIds - Metacat Index couldn't generate the index for the id - "+id+" because "+e.getMessage());
317
                                }
318
                            } else if (action != null && action.equals(Event.DELETE)) {
319
                                try {
320
                                    removeIndex(id);
321
                                    EventlogFactory.createIndexEventLog().remove(identifier);
322
                                } catch (Exception e) {
323
                                    log.error("IndexGenerator.indexFailedIds - Metacat Index couldn't remove the index for the id - "+id+" because "+e.getMessage());
324
                                }
325
                            }
326
                        }
327
                    }
328
                }
329
            }
330
        }
331
    }
332
    
282 333
    public void run() {
283 334
        /*IndexEvent event = new IndexEvent();
284 335
        event.setDate(Calendar.getInstance().getTime());
......
472 523
    }
473 524
    
474 525
    /*
526
     * Remove the index for the id
527
     */
528
    private void removeIndex(String id) throws Exception {
529
        if(id != null) {
530
            solrIndex.remove(id);
531
        }
532
    }
533
    
534
    /*
475 535
     * Initialize the system metadata map
476 536
     */
477 537
    private void initSystemMetadataMap() throws FileNotFoundException, ServiceFailure{

Also available in: Unified diff