Skip to content

Commit

Permalink
FCREPO-1083 Enhance example URIResolverImpl
Browse files Browse the repository at this point in the history
resolves Fedora URIs,
passes resolution of other URIs 
back to the XSLT processor.
  • Loading branch information
Gert Schmeltz Pedersen committed May 14, 2012
1 parent d4d3b57 commit ebfee83
Show file tree
Hide file tree
Showing 12 changed files with 340 additions and 85 deletions.
13 changes: 10 additions & 3 deletions FedoraGenericSearch/build.xml
Original file line number Diff line number Diff line change
Expand Up @@ -313,11 +313,18 @@
<property name="test" value="gsearch.test.lucene.fgs24_1009.AllTests"/>
</target>

<target name="junit-fgs242" depends="junit-set-fgs242, junit">
<target name="junit-fgs242_1076" depends="junit-set-fgs242_1076, junit">
</target>

<target name="junit-set-fgs242">
<property name="test" value="gsearch.test.fgs242.AllTests"/>
<target name="junit-set-fgs242_1076">
<property name="test" value="gsearch.test.fgs242_1076.AllTests"/>
</target>

<target name="junit-fgs242_1083" depends="junit-set-fgs242_1083, junit">
</target>

<target name="junit-set-fgs242_1083">
<property name="test" value="gsearch.test.fgs242_1083.AllTests"/>
</target>

<target name="junit" depends="compile-junit">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ public Transformer getTransformer(String xsltPath, URIResolver uriResolver)
}

public StringBuffer transform(String xsltPath, StringBuffer sb, String[] params, String systemId)
throws ConfigException {
throws GenericSearchException {
if (logger.isDebugEnabled())
logger.debug("transform xsltPath="+xsltPath+" sb="+getDebugString(sb.toString())+" systemId="+systemId);
StringReader sr = new StringReader(sb.toString());
Expand Down Expand Up @@ -140,8 +140,8 @@ public StringBuffer transform(String xsltPath, StringBuffer sb, String[] params,
StreamResult destStream = new StreamResult(new StringWriter());
try {
transformer.transform(sourceStream, destStream);
} catch (TransformerException e) {
throw new ConfigException("transform "+xsltPathName+":\n", e);
} catch (Exception e) {
throw new GenericSearchException("transform "+xsltPathName+":\n", e);
}
StringWriter sw = (StringWriter)destStream.getWriter();
StringBuffer result = sw.getBuffer();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,11 @@
/*
* <p><b>License and Copyright: </b>The contents of this file is subject to the
* same open source license as the Fedora Repository System at www.fedora-commons.org
* Copyright &copy; 2006, 2007, 2008, 2009, 2010, 2011 by The Technical University of Denmark.
* Copyright &copy; 2006, 2007, 2008, 2009, 2010, 2011, 2012 by The Technical University of Denmark.
* All rights reserved.</p>
*/
package dk.defxws.fedoragsearch.server;

import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URL;

Expand All @@ -22,7 +21,7 @@
import org.fcrepo.common.http.WebClient;

/**
* custom URIResolver for ssl access
* custom URIResolver for ssl access to fedora repository
*
* @author gsp@dtv.dk
* @version
Expand All @@ -43,22 +42,32 @@ public Source resolve(String href, String base) throws TransformerException {
try {
url = new URL(href);
} catch (MalformedURLException e) {
throw new TransformerException("resolve new URL href="+href+" base="+base, e);
// the XSLT processor should try to resolve the URI itself,
// here it may be a location path, which it can resolve
if (logger.isDebugEnabled())
logger.debug("resolve back to XSLT processor MalformedURLException href="+href+" base="+base+" exception="+e);
return null;
}
String reposName = config.getRepositoryNameFromUrl(url);
if (reposName == null || reposName.length() == 0) {
// here other resolve mechanism may be coded, or
// the XSLT processor should try to resolve the URI itself,
// e.g. it can resolve the file protocol
if (logger.isDebugEnabled())
logger.debug("resolve back to XSLT processor no reposName href="+href+" base="+base+" url="+url.toString());
return null;
}
if (logger.isDebugEnabled())
logger.debug("resolve get href="+href+" base="+base+" url="+url.toString()+" reposName="+reposName);
// System.setProperty("http.user", config.getFedoraUser(reposName));
// System.setProperty("http.password", config.getFedoraPass(reposName));
logger.debug("resolve get from repository href="+href+" base="+base+" url="+url.toString()+" reposName="+reposName);
System.setProperty("javax.net.ssl.trustStore", config.getTrustStorePath(reposName));
System.setProperty("javax.net.ssl.trustStorePassword", config.getTrustStorePass(reposName));
WebClient client = new WebClient();
try {
if (logger.isDebugEnabled())
logger.debug("resolve get source=\n"+client.getResponseAsString(href, false, new UsernamePasswordCredentials(config.getFedoraUser(reposName), config.getFedoraPass(reposName))));
logger.debug("resolve get from reposName="+reposName+" source=\n"+client.getResponseAsString(href, false, new UsernamePasswordCredentials(config.getFedoraUser(reposName), config.getFedoraPass(reposName))));
source = new StreamSource(client.get(href, false, config.getFedoraUser(reposName), config.getFedoraPass(reposName)));
} catch (IOException e) {
throw new TransformerException("resolve get href="+href+" base="+base, e);
} catch (Exception e) {
throw new TransformerException("resolve get from reposName="+reposName+" href="+href+" base="+base+" exception=\n", e);
}
return source;
}
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//$Id: $
package gsearch.test.fgs242;
package gsearch.test.fgs242_1083;

import org.junit.runner.RunWith;
import org.junit.runners.Suite;
Expand All @@ -17,15 +17,15 @@

@RunWith(Suite.class)
@Suite.SuiteClasses( {
gsearch.test.fgs242.TestFgs242.class
gsearch.test.fgs242_1083.TestFgs242_1083.class
} )
public class AllTests {

// Supports legacy tests runners
public static junit.framework.Test suite() throws Exception {
junit.framework.TestSuite suite =
new junit.framework.TestSuite(AllTests.class.getName());
suite.addTest(gsearch.test.fgs242.TestFgs242.suite());
suite.addTest(gsearch.test.fgs242_1083.TestFgs242_1083.suite());
return suite;
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//$Id: $
package gsearch.test.fgs242;
package gsearch.test.fgs242_1083;

import junit.framework.Test;

Expand All @@ -23,13 +23,13 @@ public TestConfigSetup(Test test) {

@Override
public void setUp() throws Exception {
System.out.println("setUp TestFgs242");
System.out.println("setUp TestFgs242_1083");
System.setProperty("fedoragsearch.fgsUserName", "fgsTester");
System.setProperty("fedoragsearch.fgsPassword", "fgsTesterPassword");
}

@Override
public void tearDown() throws Exception {
System.out.println("tearDown TestFgs242");
System.out.println("tearDown TestFgs242_1083");
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
//$Id: $
package gsearch.test.fgs242_1083;

import java.io.File;
import java.io.FileInputStream;

import junit.framework.TestSuite;

import org.fcrepo.client.FedoraClient;
import org.fcrepo.server.management.FedoraAPIM;
import org.junit.Test;

import gsearch.test.FgsTestCase;

/**
* Test of GSearch 2.4.2
*
* assuming
* - all Fedora demo objects are in the repository referenced in
* configTestOnLucene/repository/FgsRepos/repository.properties
*
* the test suite will
* - set configTestOnLuceneFgs242_1083 as current config,
* - run tests concerning GSearch 2.4.2
*/
public class TestFgs242_1083
extends FgsTestCase {

// Supports legacy test runners
public static junit.framework.Test suite() {
TestSuite suite = new TestSuite("TestFgs242_1083 TestSuite");
suite.addTestSuite(TestFgs242_1083.class);
return new TestConfigSetup(suite);
}

@Test
public void testSetConfig() throws Exception {
System.setProperty("fedoragsearch.clientType", "REST");
StringBuffer result = doOp("?operation=configure&configName=configTestOnLuceneFgs242_1083&restXslt=copyXml");
assertXpathNotExists("/resultPage/error", result.toString());
}

@Test
public void testCreateEmpty() throws Exception {
StringBuffer result = doOp("?operation=updateIndex&action=createEmpty&restXslt=copyXml");
assertXpathEvaluatesTo("0", "/resultPage/updateIndex/@docCount", result.toString());
}

@Test
public void testUpdateIndexFromFoxmlFiles() throws Exception {
StringBuffer result = doOp("?operation=updateIndex&action=fromFoxmlFiles&restXslt=copyXml");
assertXpathEvaluatesTo("20", "/resultPage/updateIndex/@docCount", result.toString());
}

@Test
public void testSetUriResolverImpl() throws Exception {
StringBuffer result = doOp("?operation=configure&configName=configTestOnLuceneFgs242_1083&propertyName=FgsIndex/fgsindex.uriResolver&propertyValue=dk.defxws.fedoragsearch.server.URIResolverImpl&restXslt=copyXml");
assertXpathNotExists("/resultPage/error", result.toString());
}

@Test
public void testGfindObjectsBefore() throws Exception {
StringBuffer result = doOp("?operation=gfindObjects&query=indexInfo.AdminInfo:getIndexInfo&restXslt=copyXml");
assertXpathEvaluatesTo("0", "/resultPage/gfindObjects/@hitTotal", result.toString());
}

@Test
public void testGfindObjectsBeforeFile() throws Exception {
StringBuffer result = doOp("?operation=gfindObjects&query=indexInfoFile.AdminInfo:getIndexInfo&restXslt=copyXml");
assertXpathEvaluatesTo("0", "/resultPage/gfindObjects/@hitTotal", result.toString());
}

@Test
public void testIngest() throws Exception {
FedoraClient fedoraClient = new FedoraClient("http://localhost:8080/fedora", "fedoraAdmin", "fedoraAdminPassword");
FedoraAPIM apim = fedoraClient.getAPIM();
File testfile = new File("../FgsConfig/test_fgs242_1083/test_fgs242_1083.xml");
FileInputStream fis = new FileInputStream(testfile);
byte[] testobject = new byte[(int)testfile.length()];
fis.read(testobject);
apim.ingest(testobject, "info:fedora/fedora-system:FOXML-1.1", "test ingest");
delay(5000);
doOp("?operation=updateIndex&action=fromPid&value=test:fgs242_1083&indexDocXslt=foxmlToLucene_1083&restXslt=copyXml");
delay(2000);
StringBuffer result = doOp("?operation=gfindObjects&query=indexInfo.AdminInfo:getIndexInfo&restXslt=copyXml");
assertXpathEvaluatesTo("1", "/resultPage/gfindObjects/@hitTotal", result.toString());
}

@Test
public void testGfindObjectsIngestedFile() throws Exception {
StringBuffer result = doOp("?operation=gfindObjects&query=indexInfoFile.AdminInfo:getIndexInfo&restXslt=copyXml");
assertXpathEvaluatesTo("1", "/resultPage/gfindObjects/@hitTotal", result.toString());
}

@Test
public void testPurge() throws Exception {
FedoraClient fedoraClient = new FedoraClient("http://localhost:8080/fedora", "fedoraAdmin", "fedoraAdminPassword");
FedoraAPIM apim = fedoraClient.getAPIM();
apim.purgeObject("test:fgs242_1083", "test purge", false);
delay(5000);
StringBuffer result = doOp("?operation=gfindObjects&query=indexInfo.AdminInfo:getIndexInfo&restXslt=copyXml");
assertXpathEvaluatesTo("0", "/resultPage/gfindObjects/@hitTotal", result.toString());
}

@Test
public void testGfindObjectsFileAfter() throws Exception {
StringBuffer result = doOp("?operation=gfindObjects&query=indexInfoFile.AdminInfo:getIndexInfo&restXslt=copyXml");
assertXpathEvaluatesTo("0", "/resultPage/gfindObjects/@hitTotal", result.toString());
}
}
9 changes: 9 additions & 0 deletions FgsConfig/build.xml
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,15 @@
<ant target="configDemoIndexPerDS_fgs24_1019">
<property name="configName" value="configDemoIndexPerDS_fgs24_1019"/>
</ant>

<ant target="configLocal">
<property name="configName" value="configTestOnLuceneFgs242_1083"/>
<property name="indexEngine" value="Lucene"/>
<property name="indexDir" location="${local.FEDORA_HOME}/gsearch/FgsIndex"/>
<property name="indexingDocXslt" value="foxmlToLucene"/>
</ant>
<copy file="test_fgs242_1083/foxmlToLucene_1083.xslt"
tofile="${plugin.dir}/configTestOnLuceneFgs242_1083/index/FgsIndex/foxmlToLucene_1083.xslt" preservelastmodified="true" overwrite="true"/>

</target>

Expand Down
Loading

0 comments on commit ebfee83

Please sign in to comment.