Skip to content

Commit

Permalink
Remove all Problems from fcrepo-kernel-api
Browse files Browse the repository at this point in the history
  • Loading branch information
acoburn authored and Andrew Woods committed Nov 13, 2015
1 parent 98ec5e1 commit 89b8bff
Show file tree
Hide file tree
Showing 10 changed files with 60 additions and 57 deletions.
Expand Up @@ -16,12 +16,14 @@
package org.fcrepo.http.api.repository;

import static com.google.common.io.Files.createTempDir;
import static java.util.stream.Collectors.joining;
import static javax.ws.rs.core.Response.serverError;
import static org.slf4j.LoggerFactory.getLogger;

import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.util.Collection;

import javax.inject.Inject;
import javax.jcr.Session;
Expand All @@ -32,8 +34,6 @@
import org.apache.commons.io.IOUtils;
import org.fcrepo.http.commons.AbstractResource;
import org.fcrepo.kernel.api.services.RepositoryService;
import org.modeshape.jcr.api.Problem;
import org.modeshape.jcr.api.Problems;
import org.slf4j.Logger;
import org.springframework.context.annotation.Scope;

Expand Down Expand Up @@ -90,21 +90,16 @@ public String runBackup(final InputStream bodyStream) throws IOException {
}

LOGGER.debug("Backing up to: {}", backupDirectory.getAbsolutePath());
final Problems problems = repositoryService.backupRepository(session, backupDirectory);
final Collection<Throwable> problems = repositoryService.backupRepository(session, backupDirectory);

if ( problems.hasProblems() ) {
if (!problems.isEmpty()) {
LOGGER.error("Problems backing up the repository:");

final StringBuilder problemsOutput = new StringBuilder();

// Report the problems (we'll just print them out) ...
for ( final Problem problem : problems ) {
LOGGER.error("{}", problem.getMessage());
problemsOutput.append(problem.getMessage());
problemsOutput.append("\n");
}
final String output = problems.stream().map(Throwable::getMessage).peek(LOGGER::error)
.collect(joining("\n"));

throw new WebApplicationException(serverError().entity(problemsOutput.toString()).build());
throw new WebApplicationException(serverError().entity(output).build());

}
return backupDirectory.getCanonicalPath();
Expand Down
Expand Up @@ -15,15 +15,15 @@
*/
package org.fcrepo.http.api.repository;

import static java.util.stream.Collectors.joining;
import static javax.ws.rs.core.Response.noContent;
import static javax.ws.rs.core.Response.serverError;
import static org.slf4j.LoggerFactory.getLogger;

import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.List;
import java.util.Collection;

import javax.inject.Inject;
import javax.jcr.Session;
Expand All @@ -35,8 +35,6 @@
import org.apache.commons.io.IOUtils;
import org.fcrepo.http.commons.AbstractResource;
import org.fcrepo.kernel.api.services.RepositoryService;
import org.modeshape.jcr.api.Problem;
import org.modeshape.jcr.api.Problems;
import org.slf4j.Logger;
import org.springframework.context.annotation.Scope;

Expand Down Expand Up @@ -83,17 +81,13 @@ public Response runRestore(final InputStream bodyStream) throws IOException {
+ backupDirectory.getAbsolutePath()).build());
}

final Problems problems = repositoryService.restoreRepository(session, backupDirectory);
if (problems.hasProblems()) {
final Collection<Throwable> problems = repositoryService.restoreRepository(session, backupDirectory);
if (!problems.isEmpty()) {
LOGGER.error("Problems restoring up the repository:");

final List<String> problemsOutput = new ArrayList<>();

// Report the problems (we'll just print them out) ...
for (final Problem problem : problems) {
LOGGER.error("{}", problem.getMessage());
problemsOutput.add(problem.getMessage());
}
final String problemsOutput = problems.stream().map(Throwable::getMessage).peek(LOGGER::error)
.collect(joining("\n"));

throw new WebApplicationException(serverError()
.entity(problemsOutput).build());
Expand Down
Expand Up @@ -20,22 +20,22 @@
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.mockito.Matchers.any;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
import static org.mockito.MockitoAnnotations.initMocks;
import static org.springframework.test.util.ReflectionTestUtils.setField;

import java.io.ByteArrayInputStream;
import java.io.File;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.Collection;

import javax.jcr.Session;

import org.fcrepo.kernel.api.services.RepositoryService;
import org.junit.Before;
import org.junit.Test;
import org.mockito.Mock;
import org.modeshape.jcr.api.Problems;

/**
* @author Andrew Woods
Expand Down Expand Up @@ -63,23 +63,21 @@ public void setUp() {

@Test
public void testRunBackup() throws Exception {
final Problems mockProblems = mock(Problems.class);
when(mockProblems.hasProblems()).thenReturn(false);
final Collection<Throwable> problems = new ArrayList<>();
when(mockService.backupRepository(any(Session.class),
any(File.class))).thenReturn(
mockProblems);
problems);

final String backupPath = repoBackup.runBackup(null);
assertNotNull(backupPath);
}

@Test
public void testRunBackupWithDir() throws Exception {
final Problems mockProblems = mock(Problems.class);
when(mockProblems.hasProblems()).thenReturn(false);
final Collection<Throwable> problems = new ArrayList<>();
when(mockService.backupRepository(any(Session.class),
any(File.class))).thenReturn(
mockProblems);
problems);

final String tmpDir = getProperty("java.io.tmpdir");
final String tmpDirPath = new File(tmpDir).getCanonicalPath();
Expand Down
Expand Up @@ -21,14 +21,15 @@
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import static org.mockito.Matchers.any;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
import static org.mockito.MockitoAnnotations.initMocks;
import static org.springframework.test.util.ReflectionTestUtils.setField;

import java.io.ByteArrayInputStream;
import java.io.File;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.Collection;

import javax.jcr.Session;
import javax.ws.rs.WebApplicationException;
Expand All @@ -38,7 +39,6 @@
import org.junit.Before;
import org.junit.Test;
import org.mockito.Mock;
import org.modeshape.jcr.api.Problems;

/**
* @author Andrew Woods Date: 9/4/13
Expand All @@ -65,10 +65,9 @@ public void setUp() {

@Test
public void testRunBackup() throws Exception {
final Problems mockProblems = mock(Problems.class);
when(mockProblems.hasProblems()).thenReturn(false);
final Collection<Throwable> problems = new ArrayList<>();
when(mockService.backupRepository(any(Session.class), any(File.class)))
.thenReturn(mockProblems);
.thenReturn(problems);

boolean thrown = false;
try {
Expand All @@ -82,10 +81,9 @@ public void testRunBackup() throws Exception {

@Test
public void testRunBackupWithDir() throws Exception {
final Problems mockProblems = mock(Problems.class);
when(mockProblems.hasProblems()).thenReturn(false);
final Collection<Throwable> problems = new ArrayList<>();
when(mockService.restoreRepository(any(Session.class), any(File.class)))
.thenReturn(mockProblems);
.thenReturn(problems);

final String tmpDir = System.getProperty("java.io.tmpdir");
final InputStream inputStream = new ByteArrayInputStream(tmpDir.getBytes());
Expand Down
4 changes: 4 additions & 0 deletions fcrepo-jms/pom.xml
Expand Up @@ -46,6 +46,10 @@
<groupId>org.glassfish.hk2.external</groupId>
<artifactId>javax.inject</artifactId>
</dependency>
<dependency>
<groupId>org.modeshape</groupId>
<artifactId>modeshape-jcr-api</artifactId>
</dependency>
<dependency>
<groupId>javax.jcr</groupId>
<artifactId>jcr</artifactId>
Expand Down
4 changes: 2 additions & 2 deletions fcrepo-kernel-api/pom.xml
Expand Up @@ -61,8 +61,8 @@
<artifactId>jena-arq</artifactId>
</dependency>
<dependency>
<groupId>org.modeshape</groupId>
<artifactId>modeshape-jcr-api</artifactId>
<groupId>javax.jcr</groupId>
<artifactId>jcr</artifactId>
</dependency>

<!-- test gear -->
Expand Down
Expand Up @@ -16,11 +16,10 @@
package org.fcrepo.kernel.api.services;

import java.io.File;
import java.util.Collection;

import javax.jcr.Session;

import org.modeshape.jcr.api.Problems;

/**
* @author bbpennel
* @since Feb 20, 2014
Expand Down Expand Up @@ -48,7 +47,7 @@ public interface RepositoryService {
* @param backupDirectory the backup directory
* @return problems
*/
Problems backupRepository(Session session, File backupDirectory);
Collection<Throwable> backupRepository(Session session, File backupDirectory);

/**
* This methods restores the repository from a backup
Expand All @@ -57,6 +56,6 @@ public interface RepositoryService {
* @param backupDirectory the backup directory
* @return problems
*/
Problems restoreRepository(Session session, File backupDirectory);
Collection<Throwable> restoreRepository(Session session, File backupDirectory);

}
Expand Up @@ -23,14 +23,16 @@
import org.fcrepo.metrics.RegistryService;

import java.io.File;
import java.util.ArrayList;
import java.util.Collection;


import javax.inject.Inject;
import javax.jcr.Repository;
import javax.jcr.RepositoryException;
import javax.jcr.Session;

import org.fcrepo.kernel.api.services.RepositoryService;
import org.modeshape.jcr.api.Problems;
import org.modeshape.jcr.api.RepositoryManager;
import org.slf4j.Logger;
import org.springframework.stereotype.Component;
Expand Down Expand Up @@ -97,14 +99,18 @@ public Long getRepositoryObjectCount() {
* .Session, java.io.File)
*/
@Override
public Problems backupRepository(final Session session,
public Collection<Throwable> backupRepository(final Session session,
final File backupDirectory) {
try {
final RepositoryManager repoMgr = ((org.modeshape.jcr.api.Session) session)
.getWorkspace()
.getRepositoryManager();

return repoMgr.backupRepository(backupDirectory);
final Collection<Throwable> problems = new ArrayList<>();

repoMgr.backupRepository(backupDirectory).forEach(x -> problems.add(x.getThrowable()));

return problems;
} catch (final RepositoryException e) {
throw new RepositoryRuntimeException(e);
}
Expand All @@ -117,14 +123,18 @@ public Problems backupRepository(final Session session,
* jcr.Session, java.io.File)
*/
@Override
public Problems restoreRepository(final Session session,
public Collection<Throwable> restoreRepository(final Session session,
final File backupDirectory) {
try {
final RepositoryManager repoMgr = ((org.modeshape.jcr.api.Session) session)
.getWorkspace()
.getRepositoryManager();

return repoMgr.restoreRepository(backupDirectory);
final Collection<Throwable> problems = new ArrayList<>();

repoMgr.restoreRepository(backupDirectory).forEach(x -> problems.add(x.getThrowable()));

return problems;
} catch (final RepositoryException e) {
throw new RepositoryRuntimeException(e);
}
Expand Down
Expand Up @@ -17,10 +17,11 @@

import static com.google.common.io.Files.createTempDir;
import static org.jgroups.util.Util.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;

import java.io.ByteArrayInputStream;
import java.io.File;
import java.util.Collection;

import javax.inject.Inject;
import javax.jcr.Repository;
Expand All @@ -33,7 +34,6 @@
import org.fcrepo.kernel.api.services.RepositoryService;

import org.junit.Test;
import org.modeshape.jcr.api.Problems;
import org.springframework.test.context.ContextConfiguration;

/**
Expand Down Expand Up @@ -93,8 +93,8 @@ public void testBackupRepository() throws Exception {
);
session.save();
final File backupDirectory = createTempDir();
final Problems problems = repositoryService.backupRepository(session, backupDirectory);
assertFalse(problems.hasProblems());
final Collection<Throwable> problems = repositoryService.backupRepository(session, backupDirectory);
assertTrue(problems.isEmpty());
} finally {
session.logout();
}
Expand All @@ -115,8 +115,8 @@ public void testRestoreRepository() throws Exception {
session.save();
final File backupDirectory = createTempDir();
repositoryService.backupRepository(session, backupDirectory);
final Problems problems = repositoryService.restoreRepository(session, backupDirectory);
assertFalse(problems.hasProblems());
final Collection<Throwable> problems = repositoryService.restoreRepository(session, backupDirectory);
assertTrue(problems.isEmpty());
} finally {
session.logout();
}
Expand Down
5 changes: 5 additions & 0 deletions fcrepo-serialization/pom.xml
Expand Up @@ -54,6 +54,11 @@
<artifactId>commons-io</artifactId>
</dependency>

<dependency>
<groupId>javax.jcr</groupId>
<artifactId>jcr</artifactId>
</dependency>

<!-- test gear -->
<dependency>
<groupId>junit</groupId>
Expand Down

0 comments on commit 89b8bff

Please sign in to comment.