449 |
449 |
throws IOException, SAXException, ParserConfigurationException,
|
450 |
450 |
XPathExpressionException, SolrServerException, JiBXException, EncoderException, NotImplemented, NotFound, UnsupportedType, ServiceFailure, OREParserException {
|
451 |
451 |
checkParams(pid, systemMetadata, data);
|
452 |
|
boolean isArchive = systemMetadata.getArchived();
|
453 |
|
if(isArchive || systemMetadata.getObsoletedBy() != null) {
|
454 |
|
//archive(delete)
|
455 |
|
Identifier obsolete = systemMetadata.getObsoletes();
|
456 |
|
if(obsolete != null) {
|
457 |
|
removeObsoletesChain(obsolete.getValue(), obsoleteIds);
|
458 |
|
}
|
459 |
|
remove(pid);
|
460 |
|
log.info("============================= archive the idex for the identifier "+pid);
|
461 |
|
} else {
|
462 |
|
Identifier obsolete = systemMetadata.getObsoletes();
|
463 |
|
if(obsolete != null) {
|
464 |
|
removeObsoletesChain(obsolete.getValue(), obsoleteIds);
|
465 |
|
}
|
466 |
452 |
//generate index for either add or update.
|
467 |
453 |
insert(pid, systemMetadata, data);
|
468 |
|
log.info("============================= insert index for the identifier "+pid);
|
469 |
|
}
|
|
454 |
log.info("============================= update index for the identifier "+pid);
|
|
455 |
|
470 |
456 |
}
|
471 |
457 |
|
472 |
458 |
|
473 |
|
private void removeObsoletesChain(String obsoleteId, List<String> obsoleteIdChain) throws SolrServerException, IOException, ServiceFailure, XPathExpressionException, NotImplemented, NotFound, UnsupportedType, SAXException, ParserConfigurationException, OREParserException {
|
474 |
|
if(obsoleteId != null && !obsoleteId.trim().equals("")) {
|
475 |
|
if(obsoleteIdChain == null || obsoleteIdChain.isEmpty()) {
|
476 |
|
throw new SolrServerException("SolrIndex.removeObsoletesChain - The obsoletes chain can't be null or empty since the system metadata already has the obsoletes element.");
|
477 |
|
}
|
478 |
|
if(!obsoleteIdChain.contains(obsoleteId)) {
|
479 |
|
throw new SolrServerException("SolrIndex.removeObsoletesChain - The obsoletes elment in the system metadata is not in the obsoleteId chain");
|
480 |
|
}
|
481 |
|
remove(obsoleteIdChain);
|
482 |
|
} else {
|
483 |
|
throw new SolrServerException("SolrIndex.removeObsoletesChain - The obsolete id should be null.");
|
484 |
|
}
|
485 |
|
}
|
486 |
459 |
|
487 |
|
/**
|
488 |
|
* Remove all the indexes associated with the pids in the list.
|
489 |
|
* @param pidList
|
490 |
|
* @throws IOException
|
491 |
|
* @throws SolrServerException
|
492 |
|
* @throws ParserConfigurationException
|
493 |
|
* @throws SAXException
|
494 |
|
* @throws UnsupportedType
|
495 |
|
* @throws NotFound
|
496 |
|
* @throws NotImplemented
|
497 |
|
* @throws XPathExpressionException
|
498 |
|
* @throws ServiceFailure
|
499 |
|
* @throws OREParserException
|
500 |
|
*/
|
501 |
|
private void remove(List<String> pidList) throws IOException, SolrServerException, ServiceFailure, XPathExpressionException, NotImplemented, NotFound, UnsupportedType, SAXException, ParserConfigurationException, OREParserException {
|
502 |
|
if(pidList != null) {
|
503 |
|
for(String id : pidList) {
|
504 |
|
remove(id);
|
505 |
|
}
|
506 |
|
}
|
507 |
|
}
|
508 |
|
|
509 |
|
/**
|
510 |
|
* Remove the indexed associated with specified pid.
|
511 |
|
* @param pid the pid which the indexes are associated with
|
512 |
|
* @throws IOException
|
513 |
|
* @throws SolrServerException
|
514 |
|
* @throws ParserConfigurationException
|
515 |
|
* @throws SAXException
|
516 |
|
* @throws UnsupportedType
|
517 |
|
* @throws NotFound
|
518 |
|
* @throws NotImplemented
|
519 |
|
* @throws XPathExpressionException
|
520 |
|
* @throws ServiceFailure
|
521 |
|
* @throws OREParserException
|
522 |
|
*/
|
523 |
|
public void remove(String pid) throws IOException, SolrServerException, ServiceFailure, XPathExpressionException, NotImplemented, NotFound, UnsupportedType, SAXException, ParserConfigurationException, OREParserException {
|
524 |
|
if (isDataPackage(pid)) {
|
525 |
|
removeDataPackage(pid);
|
526 |
|
} else if (isPartOfDataPackage(pid)) {
|
527 |
|
removeFromDataPackage(pid);
|
528 |
|
} else {
|
529 |
|
removeFromIndex(pid);
|
530 |
|
}
|
531 |
|
}
|
532 |
|
|
533 |
460 |
|
534 |
|
|
535 |
461 |
|
536 |
462 |
/*
|
537 |
|
* Remove a resource map pid
|
538 |
|
*/
|
539 |
|
private void removeDataPackage(String pid) throws ServiceFailure, SAXException, XPathExpressionException, NotImplemented, NotFound, UnsupportedType, SolrServerException, IOException, ParserConfigurationException, OREParserException {
|
540 |
|
Document resourceMapDoc = generateXmlDocument(DistributedMapsFactory.getDataObject(pid));
|
541 |
|
//ResourceMap resourceMap = new ResourceMap(resourceMapDoc);
|
542 |
|
ResourceMap resourceMap = new ResourceMap(resourceMapDoc);
|
543 |
|
List<String> documentIds = resourceMap.getAllDocumentIDs();
|
544 |
|
List<SolrDoc> indexDocuments =ResourceMapSubprocessor.getSolrDocs(documentIds);
|
545 |
|
removeFromIndex(pid);
|
546 |
|
//List<SolrDoc> docsToUpdate = new ArrayList<SolrDoc>();
|
547 |
|
// for each document in data package:
|
548 |
|
for (SolrDoc indexDoc : indexDocuments) {
|
549 |
|
|
550 |
|
if (indexDoc.getIdentifier().equals(pid)) {
|
551 |
|
continue; // skipping the resource map, no need update
|
552 |
|
// it.
|
553 |
|
// will
|
554 |
|
// be removed.
|
555 |
|
}
|
556 |
|
|
557 |
|
// Remove resourceMap reference
|
558 |
|
indexDoc.removeFieldsWithValue(SolrElementField.FIELD_RESOURCEMAP,
|
559 |
|
resourceMap.getIdentifier());
|
560 |
|
|
561 |
|
// // Remove documents/documentedby values for this resource
|
562 |
|
// map
|
563 |
|
for (ResourceEntry entry : resourceMap.getMappedReferences()) {
|
564 |
|
if (indexDoc.getIdentifier().equals(entry.getIdentifier())) {
|
565 |
|
for (String documentedBy : entry.getDocumentedBy()) {
|
566 |
|
// Using removeOneFieldWithValue in-case same
|
567 |
|
// documents
|
568 |
|
// are in more than one data package. just
|
569 |
|
// remove
|
570 |
|
// one
|
571 |
|
// instance of data package info.
|
572 |
|
indexDoc.removeOneFieldWithValue(SolrElementField.FIELD_ISDOCUMENTEDBY,
|
573 |
|
documentedBy);
|
574 |
|
}
|
575 |
|
for (String documents : entry.getDocuments()) {
|
576 |
|
indexDoc.removeOneFieldWithValue(SolrElementField.FIELD_DOCUMENTS,
|
577 |
|
documents);
|
578 |
|
}
|
579 |
|
break;
|
580 |
|
}
|
581 |
|
}
|
582 |
|
removeFromIndex(indexDoc.getIdentifier());
|
583 |
|
insertToIndex(indexDoc);
|
584 |
|
//docsToUpdate.add(indexDoc);
|
585 |
|
}
|
586 |
|
//SolrElementAdd addCommand = new SolrElementAdd(docsToUpdate);
|
587 |
|
//httpService.sendUpdate(solrIndexUri, addCommand);
|
588 |
|
}
|
589 |
|
|
590 |
|
private void removeFromDataPackage(String pid) throws XPathExpressionException, NotImplemented, NotFound, UnsupportedType, SolrServerException, IOException, ParserConfigurationException, SAXException {
|
591 |
|
SolrDoc indexedDoc = ResourceMapSubprocessor.getSolrDoc(pid);
|
592 |
|
removeFromIndex(pid);
|
593 |
|
List<SolrDoc> docsToUpdate = new ArrayList<SolrDoc>();
|
594 |
|
|
595 |
|
List<String> documents = indexedDoc.getAllFieldValues(SolrElementField.FIELD_DOCUMENTS);
|
596 |
|
for (String documentsValue : documents) {
|
597 |
|
SolrDoc solrDoc = ResourceMapSubprocessor.getSolrDoc(documentsValue);
|
598 |
|
solrDoc.removeFieldsWithValue(SolrElementField.FIELD_ISDOCUMENTEDBY, pid);
|
599 |
|
removeFromIndex(documentsValue);
|
600 |
|
insertToIndex(solrDoc);
|
601 |
|
}
|
602 |
|
|
603 |
|
List<String> documentedBy = indexedDoc
|
604 |
|
.getAllFieldValues(SolrElementField.FIELD_ISDOCUMENTEDBY);
|
605 |
|
for (String documentedByValue : documentedBy) {
|
606 |
|
SolrDoc solrDoc = ResourceMapSubprocessor.getSolrDoc(documentedByValue);
|
607 |
|
solrDoc.removeFieldsWithValue(SolrElementField.FIELD_DOCUMENTS, documentedByValue);
|
608 |
|
//docsToUpdate.add(solrDoc);
|
609 |
|
removeFromIndex(documentedByValue);
|
610 |
|
insertToIndex(solrDoc);
|
611 |
|
}
|
612 |
|
|
613 |
|
//SolrElementAdd addCommand = new SolrElementAdd(docsToUpdate);
|
614 |
|
//httpService.sendUpdate(solrIndexUri, addCommand);
|
615 |
|
}
|
616 |
|
|
617 |
|
/*
|
618 |
|
* Remove a pid from the solr index
|
619 |
|
*/
|
620 |
|
private void removeFromIndex(String pid) throws SolrServerException, IOException {
|
621 |
|
if(pid != null && !pid.trim().equals("")) {
|
622 |
|
/*IndexEvent event = new IndexEvent();
|
623 |
|
event.setDate(Calendar.getInstance().getTime());
|
624 |
|
Identifier identifier = new Identifier();
|
625 |
|
identifier.setValue(pid);
|
626 |
|
event.setIdentifier(identifier);*/
|
627 |
|
try {
|
628 |
|
solrServer.deleteById(pid);
|
629 |
|
solrServer.commit();
|
630 |
|
/*event.setType(IndexEvent.SUCCESSDELETE);
|
631 |
|
event.setDescription("Successfully remove the solr index for the id "+identifier.getValue());
|
632 |
|
try {
|
633 |
|
EventlogFactory.createIndexEventLog().write(event);
|
634 |
|
} catch (Exception e) {
|
635 |
|
log.error("SolrIndex.removeFromIndex - IndexEventLog can't log the index deleting event :"+e.getMessage());
|
636 |
|
}*/
|
637 |
|
} catch (SolrServerException e) {
|
638 |
|
/*event.setAction(Event.DELETE);
|
639 |
|
event.setDescription("Failurely remove the solr index for the id "+identifier.getValue()+" since "+e.getMessage());
|
640 |
|
try {
|
641 |
|
EventlogFactory.createIndexEventLog().write(event);
|
642 |
|
} catch (Exception ee) {
|
643 |
|
log.error("SolrIndex.removeFromIndex - IndexEventLog can't log the index deleting event :"+ee.getMessage());
|
644 |
|
}*/
|
645 |
|
throw e;
|
646 |
|
|
647 |
|
} catch (IOException e) {
|
648 |
|
/*event.setAction(Event.DELETE);
|
649 |
|
event.setDescription("Failurely remove the solr index for the id "+identifier.getValue()+" since "+e.getMessage());
|
650 |
|
try {
|
651 |
|
EventlogFactory.createIndexEventLog().write(event);
|
652 |
|
} catch (Exception ee) {
|
653 |
|
log.error("SolrIndex.removeFromIndex - IndexEventLog can't log the index deleting event :"+ee.getMessage());
|
654 |
|
}*/
|
655 |
|
throw e;
|
656 |
|
}
|
657 |
|
|
658 |
|
}
|
659 |
|
}
|
660 |
|
|
661 |
|
/*
|
662 |
463 |
* Is the pid a resource map
|
663 |
464 |
*/
|
664 |
465 |
private boolean isDataPackage(String pid) throws FileNotFoundException, ServiceFailure {
|
When an object is archvied, the solr index will not be removed.