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 2 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>
76 changes: 73 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 All @@ -39,6 +40,7 @@
import javax.xml.namespace.QName;
import javax.xml.transform.stream.StreamSource;

import javax.ws.rs.core.UriBuilder;
import org.apache.commons.codec.binary.Base64;
import org.apache.commons.io.IOUtils;
import org.apache.commons.lang.StringUtils;
Expand Down Expand Up @@ -87,6 +89,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 +148,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 @@ -238,6 +257,31 @@ public void init() throws RepositoryException {
if (!this.nodeService.exists(session, setsRootPath)) {
this.containerService.findOrCreate(session, setsRootPath);
}
// robyj - fcrepo-8142904 - read version from build file and add to instance
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove comment

final FedoraResource root = this.nodeService.find(session, "/");
if (!root.hasProperty(OAI_REPOVERSION)) {
final ClassPathResource resource = new ClassPathResource("app.properties");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is "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) {
}
try {
final HttpResourceConverter converter =
new HttpResourceConverter(session, UriBuilder.fromUri("http://localhost/fcrepo/{path: .*}"));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"http://localhost/fcrepo"... that is not going to work for production code.

final StringBuilder sparql =
new StringBuilder("PREFIX oai: <http://www.openarchives.org/OAI/2.0/>" +
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it actually necessary to persist the property if this code is able to determine the application version?

"INSERT DATA {<> " + OAI_REPOVERSION +
"\"" + verstring + "\" }");
root.updateProperties(converter, sparql.toString(), new RdfStream());
} catch (Exception e) {
System.out.println("exception is " + e.getMessage());
}
}
session.save();
}

Expand Down Expand Up @@ -270,12 +314,38 @@ 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;
}
if (root.hasProperty(OAI_REPOVERSION)) {
repoVersion = root.getProperty(OAI_REPOVERSION).getValues()[0].getString();
} else {
repoVersion = OAI_STATICVERSION;
}
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}