Skip to content

Commit

Permalink
Merge pull request #163 from peggy-gov-bc-ca/StorageServiceUpdate
Browse files Browse the repository at this point in the history
Add to Storage Service Interface
  • Loading branch information
alexjoybc authored Sep 30, 2019
2 parents 2e82110 + 4da4c64 commit abcd75a
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import ca.bc.gov.open.jrccaccess.autoconfigure.services.DocumentReadyHandler;
import ca.bc.gov.open.jrccaccess.libs.DocumentReadyMessage;
import ca.bc.gov.open.jrccaccess.libs.DocumentStorageProperties;
import ca.bc.gov.open.jrccaccess.libs.StorageService;
import ca.bc.gov.open.jrccaccess.libs.services.exceptions.DocumentMessageException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand All @@ -27,16 +28,16 @@ public class RabbitMqDocumentInput {

private DocumentReadyHandler documentReadyHandler;

private final RedisStorageService redisStorageService;
private final StorageService storageService;

/**
* Creates a RabbitMqDocumentInput.
*
* @param documentReadyHandler - A document ready handler.
*/
public RabbitMqDocumentInput(DocumentReadyHandler documentReadyHandler, RedisStorageService redisStorageService) {
public RabbitMqDocumentInput(DocumentReadyHandler documentReadyHandler, StorageService storageService) {
this.documentReadyHandler = documentReadyHandler;
this.redisStorageService = redisStorageService;
this.storageService = storageService;
}

/**
Expand All @@ -54,7 +55,7 @@ public void receiveMessage(DocumentReadyMessage documentReadyMessage) throws Doc

DocumentStorageProperties storageProperties = documentReadyMessage.getDocumentStorageProperties();

String content = this.redisStorageService.getString(storageProperties.getKey(), storageProperties.getDigest());
String content = this.storageService.getString(storageProperties.getKey(), storageProperties.getDigest());

if (logger.isDebugEnabled()) {
logger.debug(content);
Expand All @@ -65,7 +66,7 @@ public void receiveMessage(DocumentReadyMessage documentReadyMessage) throws Doc
logger.debug("attempting to delete the document from redis storage");

//when successfully processed, delete the document from redis storage
this.redisStorageService.deleteString(storageProperties.getKey());
this.storageService.deleteString(storageProperties.getKey());

logger.info("document successfully deleted from redis storage");
logger.info("message successfully acknowledged");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,17 +21,17 @@ public class RabbitMqDocumentOutput implements DocumentOutput {

private Logger logger = LoggerFactory.getLogger(RabbitMqDocumentOutput.class);

private final RedisStorageService redisStorageService;
private final StorageService storageService;
private final RabbitMqDocumentReadyService rabbitMqDocumentReadyService;
private final AccessProperties accessProperties;

/**
* Constructs a rabbitMq Document Output Service.
* @param redisStorageService A {@link RedisStorageService}
* @param storageService A {@link StorageService}
* @param rabbitMqDocumentReadyService A {@link RabbitMqDocumentReadyService}
*/
public RabbitMqDocumentOutput(RedisStorageService redisStorageService, RabbitMqDocumentReadyService rabbitMqDocumentReadyService, AccessProperties accessProperties) {
this.redisStorageService = redisStorageService;
public RabbitMqDocumentOutput(StorageService storageService, RabbitMqDocumentReadyService rabbitMqDocumentReadyService, AccessProperties accessProperties) {
this.storageService = storageService;
this.rabbitMqDocumentReadyService = rabbitMqDocumentReadyService;
this.accessProperties = accessProperties;
}
Expand All @@ -47,7 +47,7 @@ public void send(String content, TransactionInfo transactionInfo) throws Documen
logger.info("Attempting to publish [{}].", documentInfo);

logger.debug("Attempting to store [{}] to redis.", documentInfo);
DocumentStorageProperties documentStorageProperties = this.redisStorageService.putString(content);
DocumentStorageProperties documentStorageProperties = this.storageService.putString(content);
logger.info("[{}] successfully stored to redis key [{}].", documentInfo, documentStorageProperties.getKey());

logger.debug("Creating new document ready message.");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ public String getString(String key, String digest) throws DocumentMessageExcepti
* @param key
* @return
*/
@Override
public Boolean deleteString(String key) throws DocumentMessageException {

try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import ca.bc.gov.open.jrccaccess.autoconfigure.services.DocumentReadyHandler;
import ca.bc.gov.open.jrccaccess.libs.DocumentReadyMessage;
import ca.bc.gov.open.jrccaccess.libs.DocumentStorageProperties;
import ca.bc.gov.open.jrccaccess.libs.StorageService;
import ca.bc.gov.open.jrccaccess.libs.TransactionInfo;
import ca.bc.gov.open.jrccaccess.libs.services.exceptions.DocumentDigestMatchFailedException;
import ca.bc.gov.open.jrccaccess.libs.services.exceptions.DocumentMessageException;
Expand Down Expand Up @@ -41,7 +42,7 @@ public class RabbitMqDocumentInputTests {
private TransactionInfo transactionInfoMock;

@Mock
private RedisStorageService storageService;
private StorageService storageService;

@Before
public void init() throws Exception {
Expand Down Expand Up @@ -129,8 +130,6 @@ public void testPutAndGetDocumentFromStorage() throws DocumentMessageException {
Mockito.when(this.transactionInfoMock.getSender()).thenReturn("bcgov");
Mockito.when(this.message.getTransactionInfo()).thenReturn(transactionInfoMock);
Mockito.when(this.message.getDocumentStorageProperties()).thenReturn(storageProperties);



TransactionInfo transactionInfo = new TransactionInfo("testfile.txt", "me", LocalDateTime.now());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import ca.bc.gov.open.jrccaccess.autoconfigure.AccessProperties.PluginConfig;
import ca.bc.gov.open.jrccaccess.autoconfigure.redis.RedisStorageService;
import ca.bc.gov.open.jrccaccess.libs.DocumentStorageProperties;
import ca.bc.gov.open.jrccaccess.libs.StorageService;
import ca.bc.gov.open.jrccaccess.libs.TransactionInfo;
import org.junit.Before;
import org.junit.Test;
Expand All @@ -22,7 +23,7 @@ public class RabbitMqDocumentOutputTests {
private RabbitMqDocumentReadyService documentReadyService;

@Mock
private RedisStorageService storageService;
private StorageService storageService;

@Before
public void init() throws Exception {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,11 @@ public interface StorageService {
*/
public String getString(String key, String digest) throws DocumentMessageException;


/**
* Delete a document from storage based on the key
* @param key
* @return bool
* @throws DocumentMessageException
*/
public Boolean deleteString(String key) throws DocumentMessageException;
}

0 comments on commit abcd75a

Please sign in to comment.