Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fcrepo 81482904 #6

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,12 @@
</dependencies>

<build>
<resources>
<resource>
<directory>src/main/resources</directory>
<filtering>true</filtering>
</resource>
</resources>
<plugins>
<plugin>
<groupId>org.apache.felix</groupId>
Expand Down Expand Up @@ -229,4 +235,4 @@
</plugin>
</plugins>
</build>
</project>
</project>
58 changes: 55 additions & 3 deletions src/main/java/org/fcrepo/oai/service/OAIProviderService.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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.
*
Expand Down Expand Up @@ -270,12 +288,46 @@ public JAXBElement<OAIPMHtype> 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<String>(new QName("general"), String.class, "An example repository description"));
desc.setAny(new JAXBElement<String>(new QName("general"), String.class, repoDescription));
id.getDescription().add(0, desc);

final RequestType req = oaiFactory.createRequestType();
Expand Down
1 change: 1 addition & 0 deletions src/main/resources/app.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
application.version=${project.version}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -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;


/**
* <p>
Expand Down Expand Up @@ -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("<http://www.openarchives.org/OAI/2.0/> ")
.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) {
Expand Down
16 changes: 16 additions & 0 deletions src/test/java/org/fcrepo/oai/integration/IdentifyIT.java
Original file line number Diff line number Diff line change
Expand Up @@ -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<OAIPMHtype>) 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());
}
}
3 changes: 2 additions & 1 deletion src/test/resources/spring-test/repo.xml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@

<bean name="modeshapeRepofactory"
class="org.fcrepo.kernel.impl.spring.ModeShapeRepositoryFactoryBean"
p:repositoryConfiguration="${fcrepo.modeshape.configuration:/config/minimal/repository.json}"/>
p:repositoryConfiguration="classpath:repository.json"/>
<!-- p:repositoryConfiguration="${fcrepo.modeshape.configuration:/config/minimal/repository.json}"/> -->

<bean class="org.modeshape.jcr.ModeShapeEngine" init-method="start"/>

Expand Down