Project

General

Profile

« Previous | Next » 

Revision 8864

Added by Jing Tao about 10 years ago

Add the code to handle to remove the resource map index.

View differences:

metacat-index/src/main/java/edu/ucsb/nceas/metacat/index/IndexGeneratorTimerTask.java
53 53

  
54 54
import edu.ucsb.nceas.metacat.common.index.IndexTask;
55 55
import edu.ucsb.nceas.metacat.common.index.event.IndexEvent;
56
import edu.ucsb.nceas.metacat.common.resourcemap.ResourceMapNamespaces;
56 57
import edu.ucsb.nceas.metacat.index.event.EventlogFactory;
57 58
import edu.ucsb.nceas.metacat.index.event.IndexEventLogException;
58 59

  
......
76 77
    public static final int MAXWAITNUMBER = 180;
77 78
    private static final String HTTP = "http://";
78 79
    private static final String MNAPPENDIX = "/d1/mn";
79
    private static final String RESOURCEMAPPROPERYNAME = "index.resourcemap.namespace";
80
    //private static final String RESOURCEMAPPROPERYNAME = "index.resourcemap.namespace";
80 81
    public static final String WAITIMEPOPERTYNAME = "index.regenerate.start.waitingtime";
81 82
    public static final String MAXATTEMPTSPROPERTYNAME = "index.regenerate.start.maxattempts";
82 83
    
......
97 98
     */
98 99
    public IndexGeneratorTimerTask(SolrIndex solrIndex) {
99 100
        this.solrIndex = solrIndex;
100
        resourceMapNamespaces = Settings.getConfiguration().getList(RESOURCEMAPPROPERYNAME);
101
        resourceMapNamespaces = ResourceMapNamespaces.getNamespaces();
101 102
        //this.systemMetadataListener = systemMetadataListener;
102 103
        //this.mNode = new MNode(buildMNBaseURL());
103 104
      
......
563 564
    /*
564 565
     * If the specified ObjectFormatIdentifier is a resrouce map namespace.
565 566
     */
566
    public static boolean isResourceMap(ObjectFormatIdentifier formatId) {
567
        boolean isResourceMap = false;
568
        if(formatId != null && resourceMapNamespaces != null) {
569
            for(String namespace : resourceMapNamespaces) {
570
                if(namespace != null && formatId.getValue() != null && !formatId.getValue().trim().equals("") && formatId.getValue().equals(namespace)) {
571
                    isResourceMap = true;
572
                    break;
573
                }
574
            }
575
        }
576
        return isResourceMap;
567
   public static boolean isResourceMap(ObjectFormatIdentifier formatId) {
568
       return ResourceMapNamespaces.isResourceMap(formatId);
577 569
    }
578 570
    
579 571
   
metacat-index/src/main/java/edu/ucsb/nceas/metacat/index/SolrIndex.java
524 524
            log.error(error, e);
525 525
        }
526 526
    }
527
    /**
528
     * This method is used to delete solr index for a resourceMap. The file of resource map
529
     * probably was deleted. But the byte array is the content.
530
     * @param pid
531
     * @param systemMetadata
532
     * @param resourceMapData
533
     */
534
    public void updateResourceMap(Identifier pid, SystemMetadata systemMetadata, byte[] resourceMapData) {
535
    	if(systemMetadata != null && pid !=null && pid.getValue()!= null) {
536
    		try {
537
    			boolean archived = systemMetadata.getArchived() != null && systemMetadata.getArchived();
538
        		if(archived && isDataPackage(pid.getValue(), systemMetadata)) {
539
        			removeDataPackage(pid.getValue(), resourceMapData);
540
        		}
541
    		}catch (Exception e) {
542
                String error = "SolrIndex.updateResourceMap - could not update the solr index since " + e.getMessage();
543
                writeEventLog(systemMetadata, pid, error);
544
                log.error(error, e);
545
            }
546
    		
547
    	}
548
    }
527 549
    
528
    
529 550
    /**
530 551
     * Update the solr index. This method handles the three scenarios:
531 552
     * 1. Remove an existing doc - if the the system metadata shows the value of the archive is true,
......
613 634
    }
614 635
    
615 636
    /*
637
     * Remove a data package for given pid. The content of package will be obtained from a file.
638
     */
639
    private void removeDataPackage(String pid) throws ServiceFailure, SAXException, XPathExpressionException, NotImplemented, NotFound, UnsupportedType, SolrServerException, IOException, ParserConfigurationException, OREParserException {
640
    	Document resourceMapDoc = generateXmlDocument(DistributedMapsFactory.getDataObject(pid));
641
    	removeDataPackage(pid, resourceMapDoc);
642
    }
643
    
644
    /*
645
     * Remove a data package for given pid. The content of package will be the byte array.
646
     */
647
    private void removeDataPackage(String pid, byte[] resourceMap) throws ServiceFailure, SAXException, XPathExpressionException, NotImplemented, NotFound, UnsupportedType, SolrServerException, IOException, ParserConfigurationException, OREParserException{
648
    	Document resourceMapDoc = generateXmlDocument(new ByteArrayInputStream(resourceMap));
649
    	removeDataPackage(pid, resourceMapDoc);
650
    }
651
    
652
    /*
616 653
     * Remove a resource map pid
617 654
     */
618
    private void removeDataPackage(String pid) throws ServiceFailure, SAXException, XPathExpressionException, NotImplemented, NotFound, UnsupportedType, SolrServerException, IOException, ParserConfigurationException, OREParserException  {
619
        Document resourceMapDoc = generateXmlDocument(DistributedMapsFactory.getDataObject(pid));
655
    private void removeDataPackage(String pid,Document resourceMapDoc) throws ServiceFailure, SAXException, XPathExpressionException, NotImplemented, NotFound, UnsupportedType, SolrServerException, IOException, ParserConfigurationException, OREParserException  {
656
       
620 657
        //ResourceMap resourceMap = new ResourceMap(resourceMapDoc);
621 658
        ResourceMap resourceMap = ResourceMapFactory.buildResourceMap(resourceMapDoc);
622 659
        List<String> documentIds = resourceMap.getAllDocumentIDs();

Also available in: Unified diff