Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Changed FedoraRepository to use injected Session
  • Loading branch information
ajs6f committed May 8, 2013
1 parent 9599ec0 commit 0177e1c
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 15 deletions.
39 changes: 24 additions & 15 deletions fcrepo-http-api/src/main/java/org/fcrepo/api/FedoraRepository.java
Expand Up @@ -29,17 +29,23 @@
import org.fcrepo.provider.VelocityViewer;
import org.fcrepo.services.ObjectService;
import org.fcrepo.services.functions.GetClusterConfiguration;
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;
import com.google.common.collect.ImmutableMap.Builder;

@Component
@Scope("prototype")
@Path("/rest/fcr:describe")
public class FedoraRepository extends AbstractResource {

@InjectedSession
private Session session;

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

@Autowired
Expand All @@ -50,7 +56,7 @@ public class FedoraRepository extends AbstractResource {

@GET
@Path("modeshape")
@Timed
@Timed
public Response describeModeshape() throws IOException, RepositoryException {
final Session session = getAuthenticatedSession();
logger.debug("Repository name: " + repo.getDescriptor(REP_NAME_DESC));
Expand Down Expand Up @@ -79,23 +85,23 @@ public Response describeModeshape() throws IOException, RepositoryException {
}

@GET
@Timed
@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();
uriInfo.getBaseUriBuilder().path("/123/oai_dc").build();
description.repositorySize = objectService.getRepositorySize();
description.numberOfObjects =
objectService.getRepositoryObjectCount(session);

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

session.logout();
Expand All @@ -107,15 +113,15 @@ public DescribeRepository describe() throws RepositoryException {
* @return
*/
public Map<String, String> getClusterConfig() {
//get infinispan binarystore and cachemanager to set cluster configuration information
GetClusterConfiguration getClusterConfig =
new GetClusterConfiguration();
Map<String, String> result = getClusterConfig.apply(repo);
return result;
//get infinispan binarystore and cachemanager to set cluster configuration information
final GetClusterConfiguration getClusterConfig =
new GetClusterConfiguration();
final Map<String, String> result = getClusterConfig.apply(repo);
return result;
}

@GET
@Timed
@Timed
@Produces(TEXT_HTML)
public String describeHtml() throws RepositoryException {

Expand All @@ -131,9 +137,12 @@ public void setRepository(final Repository repo) {
this.repo = repo;
}


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 @@ -52,6 +52,7 @@ public void setUp() throws LoginException, RepositoryException {
mockSessions.getSession(any(SecurityContext.class),
any(HttpServletRequest.class))).thenReturn(mockSession);
testFedoraRepo.setSessionFactory(mockSessions);
testFedoraRepo.setSession(mockSession);
when(mockRepo.getDescriptorKeys()).thenReturn(new String[0]);
when(mockObjects.getRepositoryNamespaces(mockSession)).thenReturn(
new HashMap<String, String>(0));
Expand Down

0 comments on commit 0177e1c

Please sign in to comment.