diff --git a/pom.xml b/pom.xml index f86196a..79a2729 100644 --- a/pom.xml +++ b/pom.xml @@ -184,6 +184,12 @@ + + + src/main/resources + true + + org.apache.felix @@ -229,4 +235,4 @@ - \ No newline at end of file + diff --git a/src/main/java/org/fcrepo/oai/service/OAIProviderService.java b/src/main/java/org/fcrepo/oai/service/OAIProviderService.java index 35640c1..916de3a 100644 --- a/src/main/java/org/fcrepo/oai/service/OAIProviderService.java +++ b/src/main/java/org/fcrepo/oai/service/OAIProviderService.java @@ -25,6 +25,7 @@ import java.util.GregorianCalendar; import java.util.List; import java.util.Map; +import java.util.Properties; import javax.annotation.PostConstruct; import javax.jcr.RepositoryException; @@ -87,6 +88,7 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.core.io.ClassPathResource; import com.hp.hpl.jena.query.QuerySolution; import com.hp.hpl.jena.query.ResultSet; @@ -145,6 +147,22 @@ public class OAIProviderService { @Autowired private JcrPropertiesGenerator jcrPropertiesGenerator; + private final String OAI_REPONAME = "oai:repositoryName"; + + private final String OAI_REPODESC = "oai:description"; + + private final String OAI_REPOVERSION = "oai:version"; + + private final String OAI_ADMINEMAIL = "oai:adminEmail"; + + private final String OAI_STATICNAME = "Fedora 4"; + + private final String OAI_STATICDESC = "An example repository description"; + + private final String OAI_STATICVERSION = "x.y.z"; + + private final String OAI_STATICEMAIL = "admin@example.com"; + /** * Sets property has set spec. * @@ -270,12 +288,46 @@ public JAXBElement identify(final Session session, final UriInfo uri final IdentifyType id = this.oaiFactory.createIdentifyType(); // TODO: Need real values here from the root node? id.setBaseURL(uriInfo.getBaseUri().toASCIIString()); + + final String repoName; + final String repoDescription; + final String repoVersion; + final String repoAdminEmail; + if (root.hasProperty(OAI_ADMINEMAIL)) { + repoAdminEmail = root.getProperty(OAI_ADMINEMAIL).getValues()[0].getString(); + } else { + repoAdminEmail = OAI_STATICEMAIL; + } + if (root.hasProperty(OAI_REPONAME)) { + repoName = root.getProperty(OAI_REPONAME).getValues()[0].getString(); + } else { + repoName = OAI_STATICNAME; + } + + final ClassPathResource resource = new ClassPathResource("app.properties"); + InputStream inputstream = null; + String verstring = OAI_STATICVERSION; + try { + inputstream = resource.getInputStream(); + final Properties p = new Properties(); + p.load(inputstream); + verstring = p.getProperty("application.version"); + } catch (IOException e) { + } + repoVersion = verstring; + + if (root.hasProperty(OAI_REPODESC)) { + repoDescription = root.getProperty(OAI_REPODESC).getValues()[0].getString() + + " [" + repoVersion + "]"; + } else { + repoDescription = OAI_STATICDESC + " [" + repoVersion + "]"; + } id.setEarliestDatestamp("INSTALL_DATE"); id.setProtocolVersion("2.0"); - id.setRepositoryName("Fedora 4"); - id.getAdminEmail().add(0,"admin@example.com"); + id.setRepositoryName(repoName); + id.getAdminEmail().add(0,repoAdminEmail); final DescriptionType desc = this.oaiFactory.createDescriptionType(); - desc.setAny(new JAXBElement(new QName("general"), String.class, "An example repository description")); + desc.setAny(new JAXBElement(new QName("general"), String.class, repoDescription)); id.getDescription().add(0, desc); final RequestType req = oaiFactory.createRequestType(); diff --git a/src/main/resources/app.properties b/src/main/resources/app.properties new file mode 100644 index 0000000..71dfb33 --- /dev/null +++ b/src/main/resources/app.properties @@ -0,0 +1 @@ +application.version=${project.version} diff --git a/src/test/java/org/fcrepo/oai/integration/AbstractOAIProviderIT.java b/src/test/java/org/fcrepo/oai/integration/AbstractOAIProviderIT.java index 8c8530f..09bbfd3 100644 --- a/src/test/java/org/fcrepo/oai/integration/AbstractOAIProviderIT.java +++ b/src/test/java/org/fcrepo/oai/integration/AbstractOAIProviderIT.java @@ -19,6 +19,7 @@ import static java.lang.Integer.MAX_VALUE; import static java.util.concurrent.TimeUnit.SECONDS; import static javax.ws.rs.core.Response.Status.CREATED; +import static javax.ws.rs.core.Response.Status.NO_CONTENT; import static org.apache.http.impl.client.HttpClientBuilder.create; import static org.junit.Assert.assertEquals; import static org.slf4j.LoggerFactory.getLogger; @@ -42,6 +43,7 @@ import org.apache.http.client.HttpClient; import org.apache.http.client.methods.HttpGet; import org.apache.http.client.methods.HttpPost; +import org.apache.http.client.methods.HttpPatch; import org.apache.http.client.methods.HttpPut; import org.apache.http.client.methods.HttpUriRequest; import org.apache.http.entity.ContentType; @@ -57,6 +59,9 @@ import org.slf4j.Logger; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; +import org.springframework.core.io.ClassPathResource; +import java.util.Properties; + /** *

@@ -138,6 +143,41 @@ protected int getStatus(final HttpUriRequest method) return client.execute(method).getStatusLine().getStatusCode(); } + protected String getVersion() { + final ClassPathResource resource = new ClassPathResource("app.properties"); + InputStream inputstream = null; + String verstring = ""; + try { + inputstream = resource.getInputStream(); + final Properties p = new Properties(); + p.load(inputstream); + verstring = p.getProperty("application.version"); + } catch (IOException e) { + } + return verstring; + } + + + protected void createProperty(final String ident, final String value) throws IOException { + final HttpPatch post = new HttpPatch(serverAddress + "/"); + //post.addHeader("Slug", "/"); + if (!ident.isEmpty() && !value.isEmpty()) { + StringBuilder sparql = new StringBuilder("PREFIX oai: ") + .append(" ") + .append("INSERT { ") + .append("<> ") + .append(ident) + .append(" \"").append(value).append("\"") + .append(" } WHERE { }"); + post.setEntity(new StringEntity(sparql.toString())); + post.setHeader("Content-Type", "application/sparql-update"); + } + + final HttpResponse response = client.execute(post); + assertEquals(NO_CONTENT.getStatusCode(), response.getStatusLine().getStatusCode()); + post.releaseConnection(); + } + protected void createFedoraObject(final String pid, final String set) throws IOException { final HttpPost post = postObjMethod("/"); if (pid.length() > 0) { diff --git a/src/test/java/org/fcrepo/oai/integration/IdentifyIT.java b/src/test/java/org/fcrepo/oai/integration/IdentifyIT.java index 1a4353e..e2ff012 100644 --- a/src/test/java/org/fcrepo/oai/integration/IdentifyIT.java +++ b/src/test/java/org/fcrepo/oai/integration/IdentifyIT.java @@ -49,5 +49,21 @@ public void testIdentify() throws Exception { assertEquals(VerbType.IDENTIFY.value(), oaipmh.getRequest().getVerb().value()); assertEquals("Fedora 4", oaipmh.getIdentify().getRepositoryName()); assertEquals(serverAddress, oaipmh.getIdentify().getBaseURL()); + + createProperty("oai:repositoryName","This is a name to test the repository"); + createProperty("oai:description","Not a description"); + createProperty("oai:adminEmail","someone@somewhere.org"); + HttpResponse resp2 = getOAIPMHResponse(VerbType.IDENTIFY.value(), null, null, null, null, null); + assertEquals(200, resp2.getStatusLine().getStatusCode()); + OAIPMHtype oaipmh2 = + ((JAXBElement) this.unmarshaller.unmarshal(resp2.getEntity().getContent())).getValue(); + assertEquals(0, oaipmh2.getError().size()); + assertNotNull(oaipmh2.getIdentify()); + assertNotNull(oaipmh2.getRequest()); + assertEquals(VerbType.IDENTIFY.value(), oaipmh2.getRequest().getVerb().value()); + assertEquals("This is a name to test the repository", oaipmh2.getIdentify().getRepositoryName()); + //assertEquals("Not a description ["+getVersion()+"]", oaipmh2.getIdentify().getDescription().get(0).getAny()); + assertEquals("someone@somewhere.org",oaipmh2.getIdentify().getAdminEmail().get(0)); + assertEquals(serverAddress, oaipmh2.getIdentify().getBaseURL()); } } diff --git a/src/test/resources/spring-test/repo.xml b/src/test/resources/spring-test/repo.xml index 872aaac..b4c0235 100644 --- a/src/test/resources/spring-test/repo.xml +++ b/src/test/resources/spring-test/repo.xml @@ -27,7 +27,8 @@ + p:repositoryConfiguration="classpath:repository.json"/> +