Skip to content

Commit

Permalink
Improve and clean up fcr:versions html view to list the child version…
Browse files Browse the repository at this point in the history
  • Loading branch information
lsitu authored and Andrew Woods committed May 15, 2014
1 parent 3515595 commit dcd0d3d
Show file tree
Hide file tree
Showing 4 changed files with 152 additions and 29 deletions.
16 changes: 15 additions & 1 deletion fcrepo-http-api/src/main/resources/views/common.css
Expand Up @@ -56,4 +56,18 @@ dd {

.namespace {
font-size: .8em;
}
}

.panel-content {
text-indent:60px;
background-color:#fff;
border:none;
}

.panel .panel-heading {
font-size: 20px;
}

.panel-content .panel-heading {
font-size: 16px;
}
73 changes: 50 additions & 23 deletions fcrepo-http-api/src/main/resources/views/fcr-versions.vsl
Expand Up @@ -19,33 +19,60 @@
<div id="historic-versions">
<h2>Historic Versions</h2>
<div class="panel-group" id="accordion">
#foreach($subject in $model.listSubjects())
#if( $subject != $topic )
#set($date = $helpers.getVersionDate($rdf, $subject.asNode()))
#if ($date)
<div class="panel panel-default" resource="$subject.getURI()">
#set($label = $helpers.getVersionLabel($rdf, $subject.asNode(),"Version from $date"))
<div class="panel-heading" data-toggle="collapse" data-target="#$helpers.parameterize($subject.getURI())_triples" >
<h3><a href="$subject.getURI()" class="version_link">$esc.html($label)</a></h3>
</div>
<div class="panel-collapse collapse" id="$helpers.parameterize($subject.getURI())_triples">
<div class="panel-body">
#triples($subject.asNode())
</div>
</div>
#foreach($subject in $helpers.getVersions($rdf, $topic))
#set($date = $helpers.getVersionDate($rdf, $subject))
#if($date && $date.length() > 0)
<div class="panel panel-default" resource="$subject.getURI()">
#set($label = $helpers.getVersionLabel($rdf, $subject, "Version: $date"))
<div class="panel-heading" data-toggle="collapse" data-target="#$helpers.parameterize($subject.getURI())_triples" >
<a href="$subject.getURI()" class="version_link">$esc.html($label)</a>
</div>
#else
<div class="panel panel-default" resource="$subject.getURI()">
<div class="panel-heading" data-toggle="collapse" data-target="#$helpers.parameterize($subject.getURI())_triples" >
<h3><a href="$subject.getURI()" class="root_link">Root Version</a></h3>
<div class="panel-collapse collapse" id="$helpers.parameterize($subject.getURI())_triples">
<div class="panel-body">
#triples($subject)
</div>
<div class="panel-collapse collapse" id="$helpers.parameterize($subject.getURI())_triples">
<div class="panel-body">
#triples($subject.asNode())
</div>
</div>
#foreach($child in $helpers.getChildVersions($rdf, $subject))
#set($date = $helpers.getVersionDate($rdf, $child))
#if($date && $date.length() > 0)
<div class="panel-content panel-default" resource="$child.getURI()">
#set($label = $helpers.getVersionLabel($rdf, $child, "Content Version: $date"))
<div class="panel-heading" data-toggle="collapse" data-target="#$helpers.parameterize($child.getURI())_triples" >
<a href="$child.getURI()" class="version_link">$esc.html($label)</a>
</div>
<div class="panel-collapse collapse" id="$helpers.parameterize($child.getURI())_triples">
<div class="panel-body">
#triples($child)
</div>
</div>
</div>
#else
<div class="panel-content panel-default" resource="$child.getURI()">
#set($label = $helpers.getVersionLabel($rdf, $child, "Content Version Root"))
<div class="panel-heading" data-toggle="collapse" data-target="#$helpers.parameterize($child.getURI())_triples" >
<a href="$child.getURI()" class="version_link">$esc.html($label)</a>
</div>
<div class="panel-collapse collapse" id="$helpers.parameterize($child.getURI())_triples">
<div class="panel-body">
#triples($child)
</div>
</div>
</div>
#end
#end
</div>
#else
<div class="panel panel-default" resource="$subject.getURI()">
#set($label = $helpers.getVersionLabel($rdf, $subject, "Root Version"))
<div class="panel-heading" data-toggle="collapse" data-target="#$helpers.parameterize($subject.getURI())_triples" >
<a href="$subject.getURI()" class="version_link">$esc.html($label)</a>
</div>
<div class="panel-collapse collapse" id="$helpers.parameterize($subject.getURI())_triples">
<div class="panel-body">
#triples($subject)
</div>
</div>
#end
</div>
#end
#end
</div>
Expand Down
Expand Up @@ -21,11 +21,16 @@
import static org.fcrepo.kernel.RdfLexicon.HAS_VERSION_LABEL;
import static org.fcrepo.kernel.RdfLexicon.LAST_MODIFIED_DATE;
import static org.fcrepo.kernel.RdfLexicon.RDFS_LABEL;
import static org.fcrepo.kernel.RdfLexicon.HAS_VERSION;
import static org.fcrepo.kernel.RdfLexicon.HAS_CONTENT;
import static org.slf4j.LoggerFactory.getLogger;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.TreeMap;

import javax.ws.rs.core.UriInfo;

Expand Down Expand Up @@ -87,6 +92,53 @@ public Iterator<Quad> getObjects(final DatasetGraph dataset,
return dataset.find(ANY, subject, predicate.asNode(), ANY);
}

/**
* Return an iterator of Quads for versions.
*
* @param dataset
* @param subject
* @return
*/
public Iterator<Node> getVersions(final DatasetGraph dataset,
final Node subject) {
return getOrderedVersions(dataset, subject, HAS_VERSION);
}

/**
* Return an iterator of Quads for child versions.
*
* @param dataset
* @param subject
* @return
*/
public Iterator<Node> getChildVersions(final DatasetGraph dataset,
final Node subject) {
return getOrderedVersions(dataset, subject, HAS_CONTENT);
}

/**
* Return an iterator of Quads for versions.
*
* @param dataset
* @param subject
* @return
*/
public Iterator<Node> getOrderedVersions(final DatasetGraph dataset,
final Node subject, final Resource predicate) {
final Iterator<Quad> versions = getObjects(dataset, subject, predicate);
final Map<String, Node> map = new TreeMap<>();
final SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'");
Quad quad;
String date;
while (versions.hasNext()) {
quad = versions.next();
date = getVersionDate(dataset, quad.getObject());
map.put(date == null || date.length() == 0 ?
format.format(new Date()) : date, quad.getObject());
}
return map.values().iterator();
}

/**
* Gets the URL of the node whose version is represented by the
* current node. The current implementation assumes the URI
Expand All @@ -95,9 +147,9 @@ public Iterator<Quad> getObjects(final DatasetGraph dataset,
*/
public String getVersionSubjectUrl(final UriInfo uriInfo,
final Node subject) {
Map<String, String> breadcrumbs = getNodeBreadcrumbs(uriInfo, subject);
final Map<String, String> breadcrumbs = getNodeBreadcrumbs(uriInfo, subject);
String lastUrl = null;
for (Map.Entry<String, String> entry : breadcrumbs.entrySet()) {
for (final Map.Entry<String, String> entry : breadcrumbs.entrySet()) {
if (entry.getValue().equals("fcr:versions")) {
return lastUrl;
}
Expand Down Expand Up @@ -140,7 +192,7 @@ public String getVersionDate(final DatasetGraph dataset,
if (objects.hasNext()) {
return objects.next().getObject().getLiteralValue().toString();
}
return null;
return "";
}

/**
Expand Down
Expand Up @@ -30,9 +30,10 @@
import static org.fcrepo.kernel.RdfLexicon.HAS_PRIMARY_TYPE;
import static org.fcrepo.kernel.RdfLexicon.HAS_VERSION_LABEL;
import static org.fcrepo.kernel.RdfLexicon.LAST_MODIFIED_DATE;
import static org.fcrepo.kernel.RdfLexicon.HAS_VERSION;
import static org.fcrepo.kernel.RdfLexicon.HAS_CONTENT;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;

import java.util.Date;
Expand Down Expand Up @@ -65,6 +66,35 @@ public void setUp() {
testObj = ViewHelpers.getInstance();
}

@Test
public void testGetVersions() {
final DatasetGraph mem = createMem();
final Node anon = createAnon();
final Node version = createURI("http://localhost/fcrepo/abc/fcr:version/adcd");
final String date = new Date().toString();
mem.add(anon, createURI("http://localhost/fcrepo/abc"), HAS_VERSION.asNode(),
version);
mem.add(anon, version, LAST_MODIFIED_DATE.asNode(),
createLiteral(date));
assertEquals("Version should be available.", version, testObj.getVersions(mem, createURI("http://localhost/fcrepo/abc")).next());
}

@Test
public void testGetChildVersions() {
final DatasetGraph mem = createMem();
final Node anon = createAnon();
final Node version = createURI("http://localhost/fcrepo/abc/fcr:version/adcd");
final Node contentVersion = createURI("http://localhost/fcrepo/abc/fcr:version/adcd/fcr:content");
final String date = new Date().toString();
mem.add(anon, version, HAS_VERSION.asNode(),
version);
mem.add(anon, version, HAS_CONTENT.asNode(),
contentVersion);
mem.add(anon, contentVersion, LAST_MODIFIED_DATE.asNode(),
createLiteral(date));
assertEquals("Content version should be available.", contentVersion, testObj.getChildVersions(mem, version).next());
}

@Test
public void shouldConvertAUriToNodeBreadcrumbs() {

Expand Down Expand Up @@ -144,7 +174,7 @@ public void testGetVersionDate() {
@Test
public void testGetMissingVersionDate() {
final DatasetGraph mem = createMem();
assertNull("Date should not be available.", testObj.getVersionDate(mem, createURI("a/b/c")));
assertEquals("Date should not be available.", testObj.getVersionDate(mem, createURI("a/b/c")), "");
}

@Test
Expand Down

0 comments on commit dcd0d3d

Please sign in to comment.