-
Notifications
You must be signed in to change notification settings - Fork 11
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
base: master
Are you sure you want to change the base?
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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; | ||
|
@@ -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; | ||
|
@@ -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; | ||
|
@@ -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. | ||
* | ||
|
@@ -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 | ||
final FedoraResource root = this.nodeService.find(session, "/"); | ||
if (!root.hasProperty(OAI_REPOVERSION)) { | ||
final ClassPathResource resource = new ClassPathResource("app.properties"); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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: .*}")); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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/>" + | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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(); | ||
} | ||
|
||
|
@@ -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(); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
application.version=${project.version} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove comment