Project

General

Profile

« Previous | Next » 

Revision 8288

Added by Jing Tao about 11 years ago

Remove the obsoletes chain from the update method in the SolrIndex class.

View differences:

metacat-index/src/test/java/edu/ucsb/nceas/metacat/index/SolrIndexIT.java
69 69
       //InputStream systemInputStream = new FileInputStream(new File(SYSTEMMETAFILEPATH));
70 70
       SystemMetadata systemMetadata = TypeMarshaller.unmarshalTypeFromFile(SystemMetadata.class, SYSTEMMETAFILEPATH);
71 71
       InputStream emlInputStream = new FileInputStream(new File(EMLFILEPATH)); 
72
       List<String> chain = null;
73
       solrIndex.update(id, chain, systemMetadata, emlInputStream);
72
       //List<String> chain = null;
73
       solrIndex.update(id, systemMetadata, emlInputStream);
74 74
       String result = doQuery(solrIndex.getSolrServer());
75 75
       List<String> ids = solrIndex.getSolrIds();
76 76
       //assertTrue(ids.size() == 1);
......
93 93
       //InputStream systemInputStream = new FileInputStream(new File(SYSTEMMETAFILEPATH));
94 94
       SystemMetadata systemMetadata = TypeMarshaller.unmarshalTypeFromFile(SystemMetadata.class, SYSTEMMETAUPDATEFILEPATH);
95 95
       InputStream emlInputStream = new FileInputStream(new File(EMLUPDATEFILEPATH));  
96
       ArrayList<String> obsoletes = new ArrayList<String>();
97
       obsoletes.add(id);
98
       obsoletes.add("tao");
99
       solrIndex.update(newId, obsoletes, systemMetadata, emlInputStream);
96
       /*obsoletes.add(id);
97
       obsoletes.add("tao");*/
98
       solrIndex.update(newId, systemMetadata, emlInputStream);
100 99
       String result = doQuery(solrIndex.getSolrServer());
101 100
       assertTrue(result.contains("version2"));
102 101
    }
......
111 110
       //System metadata's archive is true.
112 111
       SystemMetadata systemMetadata = TypeMarshaller.unmarshalTypeFromFile(SystemMetadata.class, SYSTEMMETAARCHIVEFILEPATH);
113 112
       InputStream emlInputStream = new FileInputStream(new File(EMLUPDATEFILEPATH));    
114
       ArrayList<String> obsoletes = new ArrayList<String>();
113
       /*ArrayList<String> obsoletes = new ArrayList<String>();
115 114
       obsoletes.add(id);
116
       obsoletes.add("tao");
117
       solrIndex.update(newId, obsoletes, systemMetadata, emlInputStream);
115
       obsoletes.add("tao");*/
116
       solrIndex.update(newId, systemMetadata, emlInputStream);
118 117
       String result = doQuery(solrIndex.getSolrServer());
119
       assertTrue(!result.contains("version1"));
120
       assertTrue(!result.contains("version2"));
118
       assertTrue(result.contains("version1"));
119
       assertTrue(result.contains("version2"));
121 120
    }
122 121
    
123 122
    
metacat-index/src/main/java/edu/ucsb/nceas/metacat/index/SolrIndex.java
426 426
    
427 427
    /**
428 428
     * Update the solr index. This method handles the three scenarios:
429
     * 1. Archive (or delete) - if the the system metadata shows the value of the archive is true,
430
     *    remove the index for the document and its previous versions if it has.
431
     * 2. Update an existing doc - if the the system metadata shows the value of the archive is false and it has an obsoletes,
429
     * 1. Update an existing doc - if the the system metadata shows the value of the archive is false and it has an obsoletes,
432 430
     *    remove the index for the previous version(s) and generate new index for the doc.
433
     * 3. Add a new doc - if the system metadata shows the value of the archive is false and it hasn't an obsoletes, generate the
431
     * 2. Add a new doc - if the system metadata shows the value of the archive is false and it hasn't an obsoletes, generate the
434 432
     *    index for the doc.
435 433
     * @param pid  the id of the document
436 434
     * @param obsoleteIds  the chain of the obsoletes by this id
......
445 443
     * @throws ServiceFailure 
446 444
     * @throws OREParserException 
447 445
     */
448
    public void update(String pid, List<String> obsoleteIds, SystemMetadata systemMetadata, InputStream data) 
446
    public void update(String pid, SystemMetadata systemMetadata, InputStream data) 
449 447
                    throws IOException, SAXException, ParserConfigurationException,
450 448
                    XPathExpressionException, SolrServerException, JiBXException, EncoderException, NotImplemented, NotFound, UnsupportedType, ServiceFailure, OREParserException {
451 449
        checkParams(pid, systemMetadata, data);
452
            //generate index for either add or update.
453
            insert(pid, systemMetadata, data);
454
            log.info("============================= update index for the identifier "+pid);
450
        //generate index for either add or update.
451
        insert(pid, systemMetadata, data);
452
        log.info("============================= update index for the identifier "+pid);
455 453
       
456 454
    }
457 455
    
metacat-index/src/main/java/edu/ucsb/nceas/metacat/index/SystemMetadataEventListener.java
159 159
			source.remove(systemMetadata);
160 160
		}
161 161
				
162
		Identifier obsoletes = systemMetadata.getObsoletes();
163
		List<String> obsoletesChain = null;
164
		if (obsoletes != null) {
162
		//Identifier obsoletes = systemMetadata.getObsoletes();
163
		//List<String> obsoletesChain = null;
164
		/*if (obsoletes != null) {
165 165
		    try {
166 166
				obsoletesChain = getObsoletes(pid.getValue());
167 167
			} catch (Exception e) {
......
170 170
	            log.error(error, e);
171 171
	            return;
172 172
			}
173
		}
173
		}*/
174 174
		String objectPath = null;
175 175
		try {
176 176
			objectPath = DistributedMapsFactory.getObjectPathMap().get(pid);
......
184 184
		    InputStream data = null;
185 185
	        try {
186 186
	            data = new FileInputStream(objectPath);
187
	            solrIndex.update(pid.getValue(), obsoletesChain, systemMetadata, data);
187
	            solrIndex.update(pid.getValue(), systemMetadata, data);
188 188
                EventlogFactory.createIndexEventLog().remove(pid);
189 189
	        } catch (Exception e) {
190 190
	            String error = "SystemMetadataEventListener.itemAdded - could not comit the index into the solr server since " + e.getMessage();
metacat-index/src/main/java/edu/ucsb/nceas/metacat/index/IndexGenerator.java
661 661
                //only update none-archived id.
662 662
                if(sysmeta != null && !sysmeta.getArchived() && sysmeta.getObsoletedBy() == null) {
663 663
                        InputStream data = getDataObject(id);
664
                        Identifier obsolete = sysmeta.getObsoletes();
664
                        /*Identifier obsolete = sysmeta.getObsoletes();
665 665
                        List<String> obsoleteChain = null;
666 666
                        if(obsolete != null) {
667 667
                            obsoleteChain = getObsoletes(id);
668
                        } 
669
                        solrIndex.update(id, obsoleteChain, sysmeta, data);
668
                        }*/
669
                        solrIndex.update(id, sysmeta, data);
670 670
                } else {
671 671
                    throw new Exception("IndexGenerator.generate - there is no found SystemMetadata associated with the id "+id);
672 672
                }

Also available in: Unified diff