-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #8 from diging/develop
Prepare release
- Loading branch information
Showing
16 changed files
with
418 additions
and
73 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
10 changes: 10 additions & 0 deletions
10
.../main/java/edu/asu/diging/gilesecosystem/cassiopeia/core/service/IKafkaRequestSender.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package edu.asu.diging.gilesecosystem.cassiopeia.core.service; | ||
|
||
import edu.asu.diging.gilesecosystem.cassiopeia.core.service.impl.RequestInfo; | ||
|
||
public interface IKafkaRequestSender { | ||
|
||
public abstract void sendRequest(String requestId, String documentId, | ||
RequestInfo info); | ||
|
||
} |
14 changes: 14 additions & 0 deletions
14
.../src/main/java/edu/asu/diging/gilesecosystem/cassiopeia/core/service/IRequestManager.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package edu.asu.diging.gilesecosystem.cassiopeia.core.service; | ||
|
||
import java.util.concurrent.ExecutionException; | ||
|
||
import edu.asu.diging.gilesecosystem.cassiopeia.core.service.impl.ResendingResult; | ||
|
||
public interface IRequestManager { | ||
|
||
public abstract void startResendingRequests(); | ||
|
||
public abstract ResendingResult getResendingResults() throws InterruptedException, | ||
ExecutionException; | ||
|
||
} |
11 changes: 11 additions & 0 deletions
11
...src/main/java/edu/asu/diging/gilesecosystem/cassiopeia/core/service/IRequestResender.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package edu.asu.diging.gilesecosystem.cassiopeia.core.service; | ||
|
||
import java.util.concurrent.Future; | ||
|
||
import edu.asu.diging.gilesecosystem.cassiopeia.core.service.impl.ResendingResult; | ||
|
||
public interface IRequestResender { | ||
|
||
public Future<ResendingResult> resendRequests(); | ||
|
||
} |
84 changes: 84 additions & 0 deletions
84
...n/java/edu/asu/diging/gilesecosystem/cassiopeia/core/service/impl/KafkaRequestSender.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
package edu.asu.diging.gilesecosystem.cassiopeia.core.service.impl; | ||
|
||
import java.time.OffsetDateTime; | ||
import java.time.ZoneId; | ||
|
||
import javax.annotation.PostConstruct; | ||
|
||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.stereotype.Service; | ||
|
||
import edu.asu.diging.gilesecosystem.cassiopeia.core.properties.Properties; | ||
import edu.asu.diging.gilesecosystem.cassiopeia.core.service.IKafkaRequestSender; | ||
import edu.asu.diging.gilesecosystem.cassiopeia.rest.DownloadFileController; | ||
import edu.asu.diging.gilesecosystem.requests.ICompletedOCRRequest; | ||
import edu.asu.diging.gilesecosystem.requests.IRequestFactory; | ||
import edu.asu.diging.gilesecosystem.requests.RequestStatus; | ||
import edu.asu.diging.gilesecosystem.requests.exceptions.MessageCreationException; | ||
import edu.asu.diging.gilesecosystem.requests.impl.CompletedOCRRequest; | ||
import edu.asu.diging.gilesecosystem.requests.kafka.IRequestProducer; | ||
import edu.asu.diging.gilesecosystem.util.properties.IPropertiesManager; | ||
|
||
@Service | ||
public class KafkaRequestSender implements IKafkaRequestSender { | ||
|
||
private final Logger logger = LoggerFactory.getLogger(getClass()); | ||
|
||
@Autowired | ||
private IPropertiesManager propertyManager; | ||
|
||
@Autowired | ||
private IRequestFactory<ICompletedOCRRequest, CompletedOCRRequest> requestFactory; | ||
|
||
@Autowired | ||
private IRequestProducer requestProducer; | ||
|
||
|
||
@PostConstruct | ||
public void init() { | ||
requestFactory.config(CompletedOCRRequest.class); | ||
} | ||
|
||
/* (non-Javadoc) | ||
* @see edu.asu.diging.gilesecosystem.cassiopeia.core.service.impl.IKafkaRequestSender#sendRequest(java.lang.String, java.lang.String, java.lang.String, java.lang.String, edu.asu.diging.gilesecosystem.cassiopeia.core.service.impl.RequestInfo) | ||
*/ | ||
@Override | ||
public void sendRequest(String requestId, String documentId, RequestInfo info) { | ||
String restEndpoint = propertyManager.getProperty(Properties.BASE_URL); | ||
if (restEndpoint.endsWith("/")) { | ||
restEndpoint = restEndpoint.substring(0, restEndpoint.length()-1); | ||
} | ||
|
||
String fileEndpoint = restEndpoint + DownloadFileController.GET_FILE_URL | ||
.replace(DownloadFileController.REQUEST_ID_PLACEHOLDER, requestId) | ||
.replace(DownloadFileController.DOCUMENT_ID_PLACEHOLDER, documentId) | ||
.replace(DownloadFileController.FILENAME_PLACEHOLDER, info.getFilename()); | ||
|
||
ICompletedOCRRequest completedRequest = null; | ||
try { | ||
completedRequest = requestFactory.createRequest(requestId, info.getUploadId()); | ||
} catch (InstantiationException | IllegalAccessException e) { | ||
logger.error("Could not create request.", e); | ||
// this should never happen if used correctly | ||
} | ||
|
||
completedRequest.setDocumentId(documentId); | ||
completedRequest.setDownloadPath(info.getPath()); | ||
completedRequest.setSize(info.getSize()); | ||
completedRequest.setDownloadUrl(fileEndpoint); | ||
completedRequest.setFilename(info.getImageFilename()); | ||
completedRequest.setFileId(info.getFileId()); | ||
completedRequest.setStatus(RequestStatus.COMPLETE); | ||
completedRequest.setOcrDate(OffsetDateTime.now(ZoneId.of("UTC")).toString()); | ||
completedRequest.setTextFilename(info.getFilename()); | ||
|
||
try { | ||
requestProducer.sendRequest(completedRequest, propertyManager.getProperty(Properties.KAFKA_TOPIC_OCR_COMPLETE)); | ||
} catch (MessageCreationException e) { | ||
logger.error("Could not send message.", e); | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
68 changes: 68 additions & 0 deletions
68
...src/main/java/edu/asu/diging/gilesecosystem/cassiopeia/core/service/impl/RequestInfo.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
package edu.asu.diging.gilesecosystem.cassiopeia.core.service.impl; | ||
|
||
public class RequestInfo { | ||
|
||
private String path; | ||
private long size; | ||
private String filename; | ||
private String imageFilename; | ||
private String uploadId; | ||
private String fileId; | ||
|
||
public RequestInfo(String path, long size, String imageFilename, String filename) { | ||
this.path = path; | ||
this.size = size; | ||
this.filename = filename; | ||
this.imageFilename = imageFilename; | ||
} | ||
|
||
public String getPath() { | ||
return path; | ||
} | ||
|
||
public void setPath(String path) { | ||
this.path = path; | ||
} | ||
|
||
public long getSize() { | ||
return size; | ||
} | ||
|
||
public void setSize(long size) { | ||
this.size = size; | ||
} | ||
|
||
public String getImageFilename() { | ||
return imageFilename; | ||
} | ||
|
||
public void setImageFilename(String filename) { | ||
this.imageFilename = filename; | ||
} | ||
|
||
public String getUploadId() { | ||
return uploadId; | ||
} | ||
|
||
public void setUploadId(String uploadId) { | ||
this.uploadId = uploadId; | ||
} | ||
|
||
public String getFileId() { | ||
return fileId; | ||
} | ||
|
||
public void setFileId(String fileId) { | ||
this.fileId = fileId; | ||
} | ||
|
||
public String getFilename() { | ||
return filename; | ||
} | ||
|
||
public void setFilename(String filename) { | ||
this.filename = filename; | ||
} | ||
|
||
|
||
} |
42 changes: 42 additions & 0 deletions
42
.../main/java/edu/asu/diging/gilesecosystem/cassiopeia/core/service/impl/RequestManager.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
package edu.asu.diging.gilesecosystem.cassiopeia.core.service.impl; | ||
|
||
import java.util.concurrent.ExecutionException; | ||
import java.util.concurrent.Future; | ||
|
||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.stereotype.Service; | ||
|
||
import edu.asu.diging.gilesecosystem.cassiopeia.core.service.IRequestManager; | ||
import edu.asu.diging.gilesecosystem.cassiopeia.core.service.IRequestResender; | ||
|
||
@Service | ||
public class RequestManager implements IRequestManager { | ||
|
||
@Autowired | ||
private IRequestResender resender; | ||
|
||
private Future<ResendingResult> resendingResult; | ||
|
||
/* (non-Javadoc) | ||
* @see edu.asu.diging.gilesecosystem.cassiopeia.core.service.impl.IRequestManager#startResendingRequests() | ||
*/ | ||
@Override | ||
public void startResendingRequests() { | ||
resendingResult = resender.resendRequests(); | ||
} | ||
|
||
/* (non-Javadoc) | ||
* @see edu.asu.diging.gilesecosystem.cassiopeia.core.service.impl.IRequestManager#getResendingResults() | ||
*/ | ||
@Override | ||
public ResendingResult getResendingResults() throws InterruptedException, ExecutionException { | ||
if (resendingResult == null) { | ||
return new ResendingResult(0, null); | ||
} | ||
if (resendingResult.isDone()) { | ||
return resendingResult.get(); | ||
} | ||
|
||
return null; | ||
} | ||
} |
Oops, something went wrong.