Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' into StoreAndRetrieveSizesOfThings
* master: More test cleanup Cleaned tests, factored boilerplate into AbstractResourceTest Just moving some duplicate methods into a utils package. Create initial Dublin Core indexer framework and REST API endpoint. 43942653: Build an audit (logging) service Conflicts: src/test/java/org/fcrepo/modeshape/FedoraRepositoryTest.java
- Loading branch information
Showing
28 changed files
with
606 additions
and
145 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
58 changes: 58 additions & 0 deletions
58
src/main/java/org/fcrepo/modeshape/indexer/DublinCore.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
package org.fcrepo.modeshape.indexer; | ||
|
||
import org.fcrepo.modeshape.AbstractResource; | ||
import org.fcrepo.modeshape.indexer.dublincore.AbstractIndexer; | ||
import org.fcrepo.modeshape.indexer.dublincore.IndexFromWellKnownPath; | ||
|
||
import javax.inject.Inject; | ||
import javax.jcr.Node; | ||
import javax.jcr.RepositoryException; | ||
import javax.jcr.Session; | ||
import javax.ws.rs.GET; | ||
import javax.ws.rs.Path; | ||
import javax.ws.rs.PathParam; | ||
import javax.ws.rs.Produces; | ||
import javax.ws.rs.core.Response; | ||
|
||
import java.io.InputStream; | ||
import java.util.List; | ||
|
||
import static javax.ws.rs.core.MediaType.TEXT_XML; | ||
import static javax.ws.rs.core.Response.ok; | ||
|
||
|
||
@Path("/objects/{pid}/oai_dc") | ||
public class DublinCore extends AbstractResource { | ||
|
||
@Inject | ||
List<AbstractIndexer> indexers; | ||
|
||
@GET | ||
@Produces({ TEXT_XML }) | ||
public Response getObjectAsDublinCore(@PathParam("pid") final String pid) throws RepositoryException { | ||
final Session session = repo.login(); | ||
|
||
try { | ||
if (session.nodeExists("/objects/" + pid)) { | ||
final Node obj = session.getNode("/objects/" + pid); | ||
|
||
for(AbstractIndexer indexer : indexers) { | ||
InputStream inputStream = indexer.getStream(obj); | ||
|
||
if(inputStream != null) { | ||
return ok(inputStream, TEXT_XML).build(); | ||
} | ||
} | ||
|
||
return four04; | ||
} else { | ||
return four04; | ||
} | ||
|
||
} finally { | ||
session.logout(); | ||
} | ||
|
||
} | ||
|
||
} |
16 changes: 16 additions & 0 deletions
16
src/main/java/org/fcrepo/modeshape/indexer/dublincore/AbstractIndexer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package org.fcrepo.modeshape.indexer.dublincore; | ||
|
||
|
||
import javax.jcr.Node; | ||
import java.io.ByteArrayInputStream; | ||
import java.io.InputStream; | ||
import java.io.UnsupportedEncodingException; | ||
|
||
public abstract class AbstractIndexer { | ||
|
||
public AbstractIndexer() { | ||
} | ||
|
||
public abstract InputStream getStream(Node node); | ||
|
||
} |
46 changes: 46 additions & 0 deletions
46
src/main/java/org/fcrepo/modeshape/indexer/dublincore/IndexFromJcrProperties.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
package org.fcrepo.modeshape.indexer.dublincore; | ||
|
||
import javax.jcr.*; | ||
import java.io.ByteArrayInputStream; | ||
import java.io.InputStream; | ||
import java.io.UnsupportedEncodingException; | ||
|
||
public class IndexFromJcrProperties extends AbstractIndexer { | ||
|
||
@Override | ||
public InputStream getStream(Node node) { | ||
|
||
|
||
String str = "<oai_dc:dc xmlns:oai_dc=\"http://www.openarchives.org/OAI/2.0/oai_dc/\" xmlns:dc=\"http://purl.org/dc/elements/1.1/\">"; | ||
|
||
try { | ||
final String[] nameGlobs = new String[] { "dc:*"}; | ||
PropertyIterator iter = node.getProperties(nameGlobs); | ||
|
||
while(iter.hasNext()) { | ||
Property property = iter.nextProperty(); | ||
if(property.isMultiple()) { | ||
for(final Value v : property.getValues()) { | ||
str += "\t<" + property.getName() + ">" + v.getString() + "</" + property.getName() + ">\n"; | ||
} | ||
} | ||
else { | ||
str += "\t<" + property.getName() + ">" + property.getValue().getString() + "</" + property.getName() + ">\n"; | ||
|
||
} | ||
} | ||
|
||
str += "</oai_dc:dc>"; | ||
|
||
try { | ||
return new ByteArrayInputStream(str.getBytes("UTF-8")); | ||
} catch (UnsupportedEncodingException e) { | ||
e.printStackTrace(); | ||
return null; | ||
} | ||
} catch (RepositoryException e) { | ||
e.printStackTrace(); | ||
return null; | ||
} | ||
} | ||
} |
44 changes: 44 additions & 0 deletions
44
src/main/java/org/fcrepo/modeshape/indexer/dublincore/IndexFromWellKnownPath.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
package org.fcrepo.modeshape.indexer.dublincore; | ||
|
||
import javax.inject.Inject; | ||
import javax.jcr.Binary; | ||
import javax.jcr.Node; | ||
import javax.jcr.RepositoryException; | ||
|
||
import java.io.InputStream; | ||
|
||
import static org.modeshape.jcr.api.JcrConstants.JCR_CONTENT; | ||
import static org.modeshape.jcr.api.JcrConstants.JCR_DATA; | ||
|
||
public class IndexFromWellKnownPath extends AbstractIndexer { | ||
|
||
private String wellKnownPath; | ||
|
||
@Override | ||
public InputStream getStream(Node node) { | ||
|
||
try { | ||
return getContentInputStream(node); | ||
} catch (RepositoryException e) { | ||
e.printStackTrace(); | ||
|
||
return null; | ||
} | ||
} | ||
|
||
private InputStream getContentInputStream(Node node) throws RepositoryException { | ||
if(node.hasNode(this.wellKnownPath)) { | ||
final Node dc = node.getNode(this.wellKnownPath); | ||
|
||
Binary binary = dc.getNode(JCR_CONTENT).getProperty(JCR_DATA).getBinary(); | ||
|
||
return binary.getStream(); | ||
} else { | ||
return null; | ||
} | ||
} | ||
|
||
public void setWellKnownPath(String wellKnownPath) { | ||
this.wellKnownPath = wellKnownPath; | ||
} | ||
} |
21 changes: 21 additions & 0 deletions
21
src/main/java/org/fcrepo/modeshape/indexer/dublincore/WorstCaseIndexer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package org.fcrepo.modeshape.indexer.dublincore; | ||
|
||
import javax.jcr.Node; | ||
import java.io.ByteArrayInputStream; | ||
import java.io.InputStream; | ||
import java.io.UnsupportedEncodingException; | ||
|
||
public class WorstCaseIndexer extends AbstractIndexer { | ||
|
||
@Override | ||
public InputStream getStream(Node node) { | ||
String str = "<oai_dc:dc xmlns:oai_dc=\"http://www.openarchives.org/OAI/2.0/oai_dc/\" ></oai_dc:dc>"; | ||
|
||
try { | ||
return new ByteArrayInputStream(str.getBytes("UTF-8")); | ||
} catch (UnsupportedEncodingException e) { | ||
e.printStackTrace(); | ||
return null; | ||
} | ||
} | ||
} |
17 changes: 17 additions & 0 deletions
17
src/main/java/org/fcrepo/modeshape/modules/audit/Auditor.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package org.fcrepo.modeshape.modules.audit; | ||
|
||
import javax.jcr.RepositoryException; | ||
import javax.jcr.observation.Event; | ||
|
||
import com.google.common.eventbus.Subscribe; | ||
|
||
/** | ||
* An interface for recording auditable Fedora events. | ||
* | ||
* @author Edwin Shin | ||
*/ | ||
public interface Auditor { | ||
|
||
@Subscribe | ||
public void recordEvent(Event e) throws RepositoryException; | ||
} |
31 changes: 31 additions & 0 deletions
31
src/main/java/org/fcrepo/modeshape/modules/audit/LogbackAuditor.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package org.fcrepo.modeshape.modules.audit; | ||
|
||
import static org.fcrepo.modeshape.utils.EventType.getEventName; | ||
|
||
import javax.jcr.RepositoryException; | ||
import javax.jcr.observation.Event; | ||
|
||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
import com.google.common.eventbus.Subscribe; | ||
|
||
/** | ||
* A proof-of-concept Auditor implementation that uses Logback. | ||
* | ||
* @author Edwin Shin | ||
*/ | ||
public class LogbackAuditor implements Auditor { | ||
|
||
Logger logger = LoggerFactory.getLogger(LogbackAuditor.class); | ||
|
||
/** | ||
* | ||
*/ | ||
@Override | ||
@Subscribe | ||
public void recordEvent(Event e) throws RepositoryException { | ||
logger.info(e.getUserID() + " " + getEventName(e.getType()) + " " | ||
+ e.getPath()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
.../java/org/fcrepo/modeshape/Constants.java → ...org/fcrepo/modeshape/utils/Constants.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.