Project

General

Profile

« Previous | Next » 

Revision 8189

implement ORE check method to actually query the MN for OREs that reference the given pid.
https://projects.ecoinformatics.org/ecoinfo/issues/6061

View differences:

test/edu/ucsb/nceas/metacat/admin/upgrade/dataone/GenerateSystemMetadataTest.java
38 38
import junit.framework.TestSuite;
39 39
import edu.ucsb.nceas.MCTestCase;
40 40
import edu.ucsb.nceas.metacat.admin.upgrade.dataone.GenerateSystemMetadata;
41
import edu.ucsb.nceas.metacat.dataone.SystemMetadataFactory;
41 42

  
42 43
/**
43 44
 * A JUnit test for testing system metadata generation
......
78 79
        // test ORE generation
79 80
        suite.addTest(new GenerateSystemMetadataTest("testCreateResourceMap"));
80 81

  
82
        // requires manual configuration to actually pass
83
        //suite.addTest(new GenerateSystemMetadataTest("testOreExistsFor"));
84

  
81 85
        return suite;
82 86
    }
83 87

  
......
153 157
			fail();
154 158
		}
155 159
	}
160
	
161
	/**
162
	 * Requires ORE to be present and parsed in the solr index to pass
163
	 */
164
	public void testOreExistsFor() {
165
		String pid = "tao.1.1";
166
		Identifier guid = new Identifier();
167
		guid.setValue(pid);
168
		boolean exists = SystemMetadataFactory.oreExistsFor(guid);
169
		assertTrue(exists);
170
		guid.setValue("BAD");
171
		exists = SystemMetadataFactory.oreExistsFor(guid);
172
		assertFalse(exists);
173
	}
156 174
    
157 175
}
158 176

  
src/edu/ucsb/nceas/metacat/dataone/SystemMetadataFactory.java
28 28
import java.io.File;
29 29
import java.io.IOException;
30 30
import java.io.InputStream;
31
import java.io.InputStreamReader;
31 32
import java.math.BigInteger;
32 33
import java.net.URL;
33 34
import java.net.URLConnection;
......
70 71
import org.dataone.service.util.DateTimeMarshaller;
71 72
import org.dspace.foresite.ResourceMap;
72 73
import org.jibx.runtime.JiBXException;
74
import org.w3c.dom.Node;
75
import org.w3c.dom.NodeList;
73 76
import org.xml.sax.SAXException;
74 77

  
75 78
import java.util.Calendar;
......
93 96
import edu.ucsb.nceas.metacat.util.DocumentUtil;
94 97
import edu.ucsb.nceas.utilities.ParseLSIDException;
95 98
import edu.ucsb.nceas.utilities.PropertyNotFoundException;
99
import edu.ucsb.nceas.utilities.XMLUtilities;
96 100

  
97 101
public class SystemMetadataFactory {
98 102

  
......
660 664
    
661 665
	/**
662 666
	 * Determines if we already have registered an ORE map for this package
667
	 * NOTE: uses a solr query to locate OREs for the object
663 668
	 * @param guid of the EML/packaging object
664 669
	 * @return true if there is an ORE map for the given package
665 670
	 */
666
	private static boolean oreExistsFor(Identifier guid) {
667
		// TODO: implement call to CN.search()
671
	public static boolean oreExistsFor(Identifier guid) {
672
		// Search for the ORE if we can find it
673
		String pid = guid.getValue();
674
		MockHttpServletRequest request = new MockHttpServletRequest(null, null, null);
675
		String query = "fl=id,resourceMap&wt=xml&q=formatType:METADATA+-obsoletedBy:*+resourceMap:*+id:\"" + pid + "\"";
676
		try {
677
			InputStream results = MNodeService.getInstance(request).query("solr", query);
678
			Node rootNode = XMLUtilities.getXMLReaderAsDOMTreeRootNode(new InputStreamReader(results, "UTF-8"));
679
			//String resultString = XMLUtilities.getDOMTreeAsString(rootNode);
680
			NodeList nodeList = XMLUtilities.getNodeListWithXPath(rootNode, "//arr[@name=\"resourceMap\"]/str");
681
			if (nodeList != null && nodeList.getLength() > 0) {
682
				//String found = nodeList.item(0).getFirstChild().getNodeValue();
683
				return true;
684
			}
685
		} catch (Exception e) {
686
			logMetacat.error("Error checking for resourceMap[s] on pid " + pid + ". " + e.getMessage(), e);
687
		}
688
		
668 689
		return false;
669 690
	}
670 691

  

Also available in: Unified diff