Skip to content

Commit

Permalink
Changed FedoraSitemap to use injected Session
Browse files Browse the repository at this point in the history
  • Loading branch information
ajs6f committed May 8, 2013
1 parent 0177e1c commit 794140a
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 45 deletions.
78 changes: 41 additions & 37 deletions fcrepo-http-api/src/main/java/org/fcrepo/api/FedoraRepository.java
Expand Up @@ -58,54 +58,58 @@ public class FedoraRepository extends AbstractResource {
@Path("modeshape")
@Timed
public Response describeModeshape() throws IOException, RepositoryException {
final Session session = getAuthenticatedSession();
logger.debug("Repository name: " + repo.getDescriptor(REP_NAME_DESC));
final Builder<String, Object> repoproperties = builder();
for (final String key : repo.getDescriptorKeys()) {
if (repo.getDescriptor(key) != null) {
repoproperties.put(key, repo.getDescriptor(key));
try {
logger.debug("Repository name: " +
repo.getDescriptor(REP_NAME_DESC));
final Builder<String, Object> repoproperties = builder();
for (final String key : repo.getDescriptorKeys()) {
if (repo.getDescriptor(key) != null) {
repoproperties.put(key, repo.getDescriptor(key));
}
}
}

// add in node namespaces
final Builder<String, String> namespaces = builder();
namespaces.putAll(objectService.getRepositoryNamespaces(session));
repoproperties.put("node.namespaces", namespaces.build());

// add in node types
final Builder<String, String> nodetypes = builder();
final NodeTypeIterator i = objectService.getAllNodeTypes(session);
while (i.hasNext()) {
final NodeType nt = i.nextNodeType();
nodetypes.put(nt.getName(), nt.toString());
// add in node namespaces
final Builder<String, String> namespaces = builder();
namespaces.putAll(objectService.getRepositoryNamespaces(session));
repoproperties.put("node.namespaces", namespaces.build());

// add in node types
final Builder<String, String> nodetypes = builder();
final NodeTypeIterator i = objectService.getAllNodeTypes(session);
while (i.hasNext()) {
final NodeType nt = i.nextNodeType();
nodetypes.put(nt.getName(), nt.toString());
}
repoproperties.put("node.types", nodetypes.build());
return ok(repoproperties.build().toString()).build();
} finally {
session.logout();
}
repoproperties.put("node.types", nodetypes.build());
session.logout();
return ok(repoproperties.build().toString()).build();
}

@GET
@Timed
@Produces({TEXT_XML, APPLICATION_XML, APPLICATION_JSON})
public DescribeRepository describe() throws RepositoryException {

final Session session = getAuthenticatedSession();
final DescribeRepository description = new DescribeRepository();
description.repositoryBaseURL = uriInfo.getBaseUri();
description.sampleOAIURL =
uriInfo.getBaseUriBuilder().path("/123/oai_dc").build();
description.repositorySize = objectService.getRepositorySize();
description.numberOfObjects =
objectService.getRepositoryObjectCount(session);

final Map<String, String> clusterConfig = getClusterConfig();
if (clusterConfig != null) {
description.setClusterConfiguration(new DescribeCluster(
clusterConfig));
try {
final DescribeRepository description = new DescribeRepository();
description.repositoryBaseURL = uriInfo.getBaseUri();
description.sampleOAIURL =
uriInfo.getBaseUriBuilder().path("/123/oai_dc").build();
description.repositorySize = objectService.getRepositorySize();
description.numberOfObjects =
objectService.getRepositoryObjectCount(session);

final Map<String, String> clusterConfig = getClusterConfig();
if (clusterConfig != null) {
description.setClusterConfiguration(new DescribeCluster(
clusterConfig));
}
return description;
} finally {
session.logout();
}

session.logout();
return description;
}

/**
Expand Down
26 changes: 18 additions & 8 deletions fcrepo-http-api/src/main/java/org/fcrepo/api/FedoraSitemap.java
Expand Up @@ -27,25 +27,31 @@
import org.fcrepo.jaxb.responses.sitemap.SitemapIndex;
import org.fcrepo.jaxb.responses.sitemap.SitemapUrlSet;
import org.fcrepo.services.ObjectService;
import org.fcrepo.session.InjectedSession;
import org.slf4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;

import com.codahale.metrics.annotation.Timed;

@Component
@Scope("prototype")
@Path("/rest/sitemap")
public class FedoraSitemap extends AbstractResource {

private static final Logger logger = getLogger(FedoraSitemap.class);

public static final long entriesPerPage = 50000;

@InjectedSession
private Session session;

@Autowired
private ObjectService objectService;

@GET
@Timed
@Timed
@Produces(TEXT_XML)
public SitemapIndex getSitemapIndex() throws RepositoryException {
logger.trace("Executing getSitemapIndex()...");
Expand Down Expand Up @@ -73,7 +79,7 @@ public SitemapIndex getSitemapIndex() throws RepositoryException {

@GET
@Path("/{page}")
@Timed
@Timed
@Produces(TEXT_XML)
public SitemapUrlSet getSitemap(@PathParam("page")
final String page) throws RepositoryException {
Expand Down Expand Up @@ -122,18 +128,22 @@ private SitemapEntry getSitemapEntry(final Row r)
throws RepositoryException {
Value lkDateValue = r.getValue("jcr:lastModified");
if (lkDateValue == null) {
logger.warn("no value for jcr:lastModified on {}", r.getNode().getPath());
logger.warn("no value for jcr:lastModified on {}", r.getNode()
.getPath());
lkDateValue = r.getValue("jcr:created");
}
Calendar lastKnownDate = (lkDateValue != null) ? lkDateValue.getDate() : null;
final Calendar lastKnownDate =
(lkDateValue != null) ? lkDateValue.getDate() : null;
return new SitemapEntry(uriInfo.getBaseUriBuilder().path(
FedoraNodes.class)
.build(r.getNode().getName()), lastKnownDate);
FedoraNodes.class).build(r.getNode().getName()), lastKnownDate);
}


public void setObjectService(ObjectService objectService) {
public void setObjectService(final ObjectService objectService) {
this.objectService = objectService;
}

public void setSession(final Session session) {
this.session = session;
}

}
Expand Up @@ -40,6 +40,7 @@ public void setUp() throws LoginException, RepositoryException {
mockSessions.getSession(any(SecurityContext.class),
any(HttpServletRequest.class))).thenReturn(mockSession);
testObj.setSessionFactory(mockSessions);
testObj.setSession(mockSession);
testObj.setUriInfo(TestHelpers.getUriInfoImpl());
}

Expand Down Expand Up @@ -67,4 +68,5 @@ public void testGetSitemapIndexMultiplePages() throws Exception {

assertEquals(2, sitemapIndex.getSitemapEntries().size());
}

}

0 comments on commit 794140a

Please sign in to comment.