TextSense OCR 요청 및 처리 결과 기능 개발

- 변환 요청 및 결과파일 서버로 저장되도록 처리완료
 - callback은 포트 문제인지 오지 않음
 - callback이 오면 디비 정보 업데이트 처리하도록 로직 생성 완료
 - 처리 상태 확인 버튼 및 기능 추가완료
This commit is contained in:
rosewiper 2023-10-06 18:02:59 +09:00
parent 8785f3c6e2
commit 1422303e5a
9 changed files with 414 additions and 159 deletions

View File

@ -16,4 +16,7 @@ public interface TextSenseService {
//TextSense OCR 상세내용 불러오기
public TextSenseVO selectTextSenseDetail(TextSenseVO textSenseVO) throws Exception;
//TextSense Callback 데이터 내용 업데이트 해주기
public void updateTextSenseCallbackData(TextSenseVO textSenseVO) throws Exception;
}

View File

@ -23,11 +23,11 @@ public class TextSenseVO extends ComDefaultVO implements Serializable{
//결과 파라미터 부분
private String id;
private String status;
private String inputFileLenth;
private String outputFileLenth;
private String inputFileLength;
private String outputFileLength;
private String createdat;
private String queuedat;
private String startdat;
private String startedat;
private String completedat;
private String updatedat;
private String maxRetryCount;
@ -117,17 +117,18 @@ public class TextSenseVO extends ComDefaultVO implements Serializable{
public void setStatus(String status) {
this.status = status;
}
public String getInputFileLenth() {
return inputFileLenth;
public String getInputFileLength() {
return inputFileLength;
}
public void setInputFileLenth(String inputFileLenth) {
this.inputFileLenth = inputFileLenth;
public void setInputFileLength(String inputFileLength) {
this.inputFileLength = inputFileLength;
}
public String getOutputFileLenth() {
return outputFileLenth;
public String getOutputFileLength() {
return outputFileLength;
}
public void setOutputFileLenth(String outputFileLenth) {
this.outputFileLenth = outputFileLenth;
public void setOutputFileLength(String outputFileLength) {
this.outputFileLength = outputFileLength;
}
public String getCreatedat() {
return createdat;
@ -141,11 +142,12 @@ public class TextSenseVO extends ComDefaultVO implements Serializable{
public void setQueuedat(String queuedat) {
this.queuedat = queuedat;
}
public String getStartdat() {
return startdat;
public String getStartedat() {
return startedat;
}
public void setStartdat(String startdat) {
this.startdat = startdat;
public void setStartedat(String startedat) {
this.startedat = startedat;
}
public String getCompletedat() {
return completedat;

View File

@ -74,4 +74,17 @@ public class TextSenseDAO extends EgovAbstractDAO{
return result;
}
//TextSense Callback 데이터 내용 업데이트 해주기
public void updateTextSenseCallbackData(TextSenseVO textSenseVO) throws Exception{
try {
update("textSenseDAO.updateTextSenseCallbackData", textSenseVO);
} catch (Exception e) {
System.out.println("updateTextSenseCallbackData Service DAO Error !!! " + e);
}
}
}

View File

@ -84,5 +84,19 @@ public class TextSenseServiceImpl implements TextSenseService{
return result;
}
//TextSense Callback 데이터 내용 업데이트 해주기
@Override
public void updateTextSenseCallbackData(TextSenseVO textSenseVO) throws Exception{
try {
textSenseDAO.updateTextSenseCallbackData(textSenseVO);
} catch (Exception e) {
System.out.println("updateTextSenseCallbackData Service Impl Error !!! " + e);
}
}
}

View File

@ -34,24 +34,29 @@ public class TextSenseAPIComm {
String callbackUri = textSenseVO.getCallbackUri();//"http://119.193.215.98:8097/web/main/textsence/testCallbackUriPage.do";
//String extraJobs = "";
JSONObject jsonOptObj = new JSONObject();
jsonOptObj.put("withoutConversion", true);
JSONObject jsonObject = new JSONObject();
jsonObject.put("inputUri", inputUri);
jsonObject.put("outputUri", outputUri);
jsonObject.put("taskName", taskName);
jsonObject.put("callbackUri", callbackUri);
jsonObject.put("option", jsonOptObj);
JSONArray extraJobs = new JSONArray();
JSONObject jsonJobs = new JSONObject();
JSONObject jsonOption = new JSONObject();
//extraJobs의 Option 항목 셋팅 해주기
jsonOption.put("url", textSenseVO.getUrl());
jsonOption.put("reqType", textSenseVO.getReqType());
jsonOption.put("reqOption", "");
JSONObject jsonReqOption = new JSONObject();
jsonOption.put("reqOption", jsonReqOption);
jsonOption.put("outputType", textSenseVO.getOutputType());
jsonOption.put("pages", "all");
//extraJobs 셋팅해주기
jsonJobs.put("type", textSenseVO.getType());
@ -86,6 +91,7 @@ public class TextSenseAPIComm {
returnJson = object;
returnJson.put("resultSts", "success");
}else {
returnJson.put("resultSts", "fail");
@ -99,4 +105,61 @@ public class TextSenseAPIComm {
return returnJson;
}
/*
* TextSense OCR 결과 상태 확인하기
*
* */
@SuppressWarnings("unchecked")
public static JSONObject getTextSenseApiStatus(TextSenseVO textSenseVO) throws Exception{
JSONObject returnJson = new JSONObject();
try {
String apiUrl = textSenseVO.getApiUrl();
String id = textSenseVO.getId();
JSONObject jsonObject = new JSONObject();
jsonObject.put("type", "OBJECT_ID");
jsonObject.put("id", id);
HttpClient httpClient = HttpClientBuilder.create().build();
HttpPost httpPost = new HttpPost(apiUrl);
httpPost.setEntity(new StringEntity(jsonObject.toString(), "UTF-8"));
httpPost.addHeader("Content-type", "application/json");
//httpPost.addHeader("Accept", "application/json");
HttpResponse response = httpClient.execute(httpPost);
String result = "";
String statusCode = Integer.toString(response.getStatusLine().getStatusCode());
if(statusCode.equals("200")) {
result = EntityUtils.toString(response.getEntity());
result = new String(result.getBytes("iso-8859-1"));//한글 깨짐 현상이 있어서 변환 해줌.
JSONParser parser = new JSONParser();
Object obj = parser.parse(result);
JSONObject object = (JSONObject) obj;
returnJson = object;
returnJson.put("resultSts", "success");
}else {
System.out.println("statusCode ::: "+statusCode);
returnJson.put("resultSts", "fail");
}
} catch (Exception e) {
System.out.println("++++++++++++++++ getTextSenseRequest Error!!! "+e);
returnJson.put("resultSts", "fail");
}
return returnJson;
}
}

View File

@ -152,6 +152,8 @@ public class TextSenseController {
}
try {
//첨부파일 등록 API 전송 요청
final Map<String, MultipartFile> files = multiRequest.getFileMap();
String atchFileId = "";
@ -202,22 +204,20 @@ public class TextSenseController {
String taskName = textSenseVO.getTaskName();
apiTextSenseVO.setApiUrl(apiUrl);
apiTextSenseVO.setInputUri("http://119.193.215.98:8097/cmm/fms/FileDown.do?atchFileId="+ atchFileId +"&fileSn=0"); //http://119.193.215.98:8097/kccadrPb/usr/image/common/top_logo.png
apiTextSenseVO.setInputUri("http://119.193.215.98:8097/uss/ion/pwm/getImage.do?atchFileId="+ atchFileId +"&fileSn=0");
apiTextSenseVO.setOutputUri("file:/home/kcc_adr_ocr_dir/" + outputFileNm);
apiTextSenseVO.setCallbackUri("http://119.193.215.98:8097/kccadr/textsence/testCallbackUriPage.do");
apiTextSenseVO.setCallbackUri("http://119.193.215.98:8097/kccadr/textsence/textSenseCallbackUriPage.do");
apiTextSenseVO.setTaskName(taskName);
//extraJobs의 Option 항목 셋팅 해주기
apiTextSenseVO.setUrl(textSenseApiUrl);
apiTextSenseVO.setUrl("http://textsense:8080");
apiTextSenseVO.setReqType("document"); //고정값으로 변경 불가
apiTextSenseVO.setReqOption(""); //기본값으로 빈값을 넣어준다.
//apiTextSenseVO.setReqOption("{}"); //기본값으로 빈값을 넣어준다.
apiTextSenseVO.setOutputType("json"); //지원하는 output type은 pdf, json, excel, text, text-split 입니다
apiTextSenseVO.setType("textSense"); //고정값으로 변경 불가
JSONObject resultJson = TextSenseAPIComm.getTextSenseRequest(apiTextSenseVO);
System.out.println("==========Controller============== resultJson ::: "+resultJson.toJSONString());
//처리 결과가 성공이면 디비에 저장해주고 끝낸다.
String resultSts = resultJson.get("resultSts").toString();
if(resultSts.equals("success")) {
@ -253,18 +253,32 @@ public class TextSenseController {
}
} catch (Exception e) {
System.out.println("textSenseRequest Controller Error !!!!" + e);
modelAndView.addObject("result", "fail");
return modelAndView;
}
@RequestMapping(value="/kccadr/textsence/testCallbackUriPage.do")
public void testCallbackUriPage(HttpServletRequest req, HttpServletResponse res, @RequestBody JSONObject jsonObject) throws Exception{
return modelAndView;
}
/**
*
* TextSense 결과 Callback 정보 전달
*
* */
@RequestMapping(value="/kccadr/textsence/textSenseCallbackUriPage.do")
public void textSenseCallbackUriPage(HttpServletRequest req, HttpServletResponse res, @RequestBody JSONObject jsonObject) throws Exception{
System.out.println("++++++++++++++++++++++++++/web/main/textsence/testCallbackUriPage.do++++++++++++++++++++++++++++++++++");
System.out.println("+++++++++++ jsonString ::: "+jsonObject.toJSONString());
try {
JSONParser parser = new JSONParser();
Object obj = parser.parse(jsonObject.toString());
JSONObject object = (JSONObject) obj;
@ -272,20 +286,41 @@ public class TextSenseController {
String id = object.get("id").toString();
String name = object.get("name").toString();
String inputUri = object.get("inputUri").toString();
String inputFileLength = object.get("inputFileLength").toString();
String outputUri = object.get("outputUri").toString();
String outputFileLength = object.get("outputFileLength").toString();
String status = object.get("status").toString();
String createdAt = object.get("createdAt").toString();
//String queuedAt = object.get("queuedAt").toString();
String startedAt = object.get("startedAt").toString();
String completedAt = object.get("completedAt").toString();
//String updatedAt = object.get("updatedAt").toString();
String maxRetryCount = object.get("maxRetryCount").toString();
String retryCount = object.get("retryCount").toString();
String collectedBy = object.get("collectedBy").toString();
String callbackUri = object.get("callbackUri").toString();
String inputFileLength = object.get("inputFileLength").toString();
String outputFileLength = object.get("outputFileLength").toString();
String createdAt = (object.get("createdAt") == null ? "0" : object.get("createdAt").toString());
String queuedAt = (object.get("queuedAt") == null ? "0" : object.get("queuedAt").toString());
String startedAt = (object.get("startedAt") == null ? "0" : object.get("startedAt").toString());
String completedAt = (object.get("completedAt") == null ? "0" : object.get("completedAt").toString());
String updatedAt = (object.get("updatedAt") == null ? "0" : object.get("updatedAt").toString());
String maxRetryCount = (object.get("maxRetryCount") == null ? "0" : object.get("maxRetryCount").toString());
String retryCount = (object.get("retryCount") == null ? "0" : object.get("retryCount").toString());
String collectedBy = (object.get("collectedBy") == null ? null : object.get("collectedBy").toString());
TextSenseVO textSenseVO = new TextSenseVO();
textSenseVO.setId(id);
textSenseVO.setTaskName(name);
textSenseVO.setInputUri(inputUri);
textSenseVO.setInputFileLength(inputFileLength);
textSenseVO.setOutputUri(outputUri);
textSenseVO.setOutputFileLength(outputFileLength);
textSenseVO.setStatus(status);
textSenseVO.setCreatedat(createdAt);
textSenseVO.setQueuedat(queuedAt);
textSenseVO.setStartedat(startedAt);
textSenseVO.setCompletedat(completedAt);
textSenseVO.setUpdatedat(updatedAt);
textSenseVO.setMaxRetryCount(maxRetryCount);
textSenseVO.setMaxRetryCount(maxRetryCount);
textSenseVO.setCollectedby(collectedBy);
textSenseVO.setCallbackUri(callbackUri);
//callback 결과 내용 디비 업데이터 처리 해주기
textSenseService.updateTextSenseCallbackData(textSenseVO);
System.out.println("+++++++++++++++++++++++ id ::: "+id);
System.out.println("+++++++++++++++++++++++ name ::: "+name);
@ -295,18 +330,62 @@ public class TextSenseController {
System.out.println("+++++++++++++++++++++++ outputFileLength ::: "+outputFileLength);
System.out.println("+++++++++++++++++++++++ status ::: "+status);
System.out.println("+++++++++++++++++++++++ createdAt ::: "+createdAt);
//System.out.println("+++++++++++++++++++++++ queuedAt ::: "+queuedAt);
System.out.println("+++++++++++++++++++++++ queuedAt ::: "+queuedAt);
System.out.println("+++++++++++++++++++++++ startedAt ::: "+startedAt);
System.out.println("+++++++++++++++++++++++ completedAt ::: "+completedAt);
//System.out.println("+++++++++++++++++++++++ updatedAt ::: "+updatedAt);
System.out.println("+++++++++++++++++++++++ updatedAt ::: "+updatedAt);
System.out.println("+++++++++++++++++++++++ maxRetryCount ::: "+maxRetryCount);
System.out.println("+++++++++++++++++++++++ retryCount ::: "+retryCount);
System.out.println("+++++++++++++++++++++++ collectedBy ::: "+collectedBy);
System.out.println("+++++++++++++++++++++++ callbackUri ::: "+callbackUri);
} catch (Exception e) {
System.out.println("textSenseCallbackUriPage Controller Error !!! " + e);
}
}
/**
* TextSense 요청 결과 상태값
* SUCCESS: 작업이 성공하여 완료된 상태입니다.
* FAILURE: 작업중 오류가 발생하여 실패한 상태입니다.
*
* */
@RequestMapping(value="/kccadr/textsence/textSenseApiStatus.do")
public ModelAndView textSenseApiStatus(TextSenseVO textSenseVO) throws Exception{
ModelAndView modelAndView = new ModelAndView();
modelAndView.setViewName("jsonView");
LoginVO user = (LoginVO) EgovUserDetailsHelper.getAuthenticatedUser();
if(user == null) {
modelAndView.addObject("status", "loginFail");
return modelAndView;
}
try {
String apiUrl = textSenseApiUrl + "/textsense/api/job/status";
textSenseVO.setApiUrl(apiUrl);
JSONObject resultJson = TextSenseAPIComm.getTextSenseApiStatus(textSenseVO);
String resultStatus = resultJson.get("status").toString();
modelAndView.addObject("result", "success");
modelAndView.addObject("textSenseSts", resultStatus);
} catch (Exception e) {
System.out.println("textSenseApiStatus Controller Error !!! " + e);
modelAndView.addObject("result", "fail");
return modelAndView;
}
return modelAndView;
}
}

View File

@ -39,7 +39,7 @@
A.TASK_NAME AS taskName,
A.INPUT_URI AS inputUri,
A.OUTPUT_URI AS outputUri,
A.INPUT_FILE_LENGTH AS inputFileLenth,
A.INPUT_FILE_LENGTH AS inputFileLength,
A.OUTPUT_FILE_LENGTH AS outputfileLength,
A.STATUS AS status,
A.CREATEDAT AS createdat,
@ -88,12 +88,12 @@
A.TASK_NAME AS taskName,
A.INPUT_URI AS inputUri,
A.OUTPUT_URI AS outputUri,
A.INPUT_FILE_LENGTH AS inputFileLenth,
A.OUTPUT_FILE_LENGTH AS outputFileLenth,
A.INPUT_FILE_LENGTH AS inputFileLength,
A.OUTPUT_FILE_LENGTH AS outputFileLength,
A.STATUS AS status,
A.CREATEDAT AS createdat,
A.QUEUEDAT AS queuedat,
A.STARTEDAT AS startdat,
A.STARTEDAT AS startedat,
A.COMPLETEDAT AS completedat,
A.UPDATEDAT AS updatedat,
A.MAX_RETRY_COUNT AS maxRetryCount,
@ -111,4 +111,25 @@
</select>
<update id="textSenseDAO.updateTextSenseCallbackData" parameterClass="TextSenseVO">
UPDATE ADR_TEXTSENSE_OCR SET
STATUS = #status#
, INPUT_FILE_LENGTH = #inputFileLength#
, OUTPUT_FILE_LENGTH = #outputFileLength#
, CREATEDAT = #createdat#
, QUEUEDAT = #queuedat#
, STARTEDAT = #startedat#
, COMPLETEDAT = #completedat#
, UPDATEDAT = #updatedat#
, MAX_RETRY_COUNT = #maxRetryCount#
, RETRY_COUNT = #retryCount#
, COLLECEDBY = #collectedby#
, EXTERNAL_ID = #externalId#
WHERE ID = #id#
AND TASK_NAME = #taskName#
</update>
</sqlMap>

View File

@ -107,8 +107,8 @@ function fnListPage(){
<th>Input 파일 길이</th>
<td colspan="3">
<c:choose>
<c:when test="${not empty textSenseVO.inputFileLenth}">
<c:out value="${textSenseVO.inputFileLenth}"/>
<c:when test="${not empty textSenseVO.inputFileLength}">
<c:out value="${textSenseVO.inputFileLength}"/>
</c:when>
<c:otherwise>
-
@ -121,8 +121,8 @@ function fnListPage(){
<th>Output 파일 길이</th>
<td colspan="3">
<c:choose>
<c:when test="${not empty textSenseVO.outputFileLenth}">
<c:out value="${textSenseVO.outputFileLenth}"/>
<c:when test="${not empty textSenseVO.outputFileLength}">
<c:out value="${textSenseVO.outputFileLength}"/>
</c:when>
<c:otherwise>
-
@ -177,8 +177,8 @@ function fnListPage(){
<th>변환작업 시작 시간</th>
<td colspan="3">
<c:choose>
<c:when test="${not empty textSenseVO.startdat}">
<c:out value="${textSenseVO.startdat}"/>
<c:when test="${not empty textSenseVO.startedat}">
<c:out value="${textSenseVO.startedat}"/>
</c:when>
<c:otherwise>
-

View File

@ -59,6 +59,63 @@ function goTextSenseDetail(id){
}
function fncTextSenseStatus(id){
var form = document.listForm;
form.id.value = id;
var data = new FormData(form);
$.ajax({
type: "POST",
enctype: 'multipart/form-data',
url: "/kccadr/textsence/textSenseApiStatus.do",
data: data,
dataType:'json',
async: false,
processData: false,
contentType: false,
cache: false,
success: function (returnData, status) {
if(status == 'success'){
var result = returnData.result;
var textSenseSts = returnData.textSenseSts;
if(result == 'loginFail'){
alert("로그인이 필요합니다.");
return false;
}else if(result == 'success'){
if(textSenseSts == 'SUCCESS'){
alert("OCR 변환이 정상적으로 처리되었습니다.");
return false;
}else{
alert("OCR 변환이 정상적으로 처리되지 못하였습니다.");
return false;
}
}else{
alert("상태확인에 오류가 발생하였습니다.");
return false;
}
} else if(status== 'fail'){
alert("상태 확인에 실패하였습니다.");
}
},
error: function (e) { alert("상태 확인에 실패하였습니다."); console.log("ERROR : ", e); }
});
}
</script>
<title>OCR 목록</title>
@ -114,19 +171,21 @@ function goTextSenseDetail(id){
<col style="width: 5%">
<col style="width: auto">
<col style="width: 10%">
<col style="width: 10%">
<col style="width: 20%">
</colgroup>
<thead>
<tr>
<th>번호<button class="sort btn_sort" id="sort_id"></button></th>
<th>TaskName<button type="button" class="sort sortBtn" id="sort_taskName"></button></th>
<th>상태확인</th>
<th>처리상태<button type="button" class="sort sortBtn" id="sort_status"></button></th>
<th>등록일자<button type="button" class="sort sortBtn" id="sort_frstRegistPnttm"></button></th>
</tr>
</thead>
<tbody>
<c:forEach var="list" items="${list}" varStatus="status">
<tr onclick="javascript:goTextSenseDetail('<c:out value="${list.id}"/>');" style="cursor:pointer;">
<tr>
<td>
<c:if test="${searchVO.searchSortOrd eq 'desc' }">
<c:out value="${ ( paginationInfo.totalRecordCount - ((searchVO.pageIndex -1)*searchVO.pageUnit) ) - status.index }"/>
@ -135,8 +194,9 @@ function goTextSenseDetail(id){
<c:out value="${(searchVO.pageIndex - 1) * searchVO.pageUnit + status.count}"/>
</c:if>
</td>
<td><c:out value="${list.taskName}"/></td>
<td>
<td onclick="javascript:goTextSenseDetail('<c:out value="${list.id}"/>');" style="cursor:pointer;"><c:out value="${list.taskName}"/></td>
<td><button class="btnType02" onclick="fncTextSenseStatus('<c:out value="${list.id}"/>'); return false;">상태확인</button></td>
<td onclick="javascript:goTextSenseDetail('<c:out value="${list.id}"/>');" style="cursor:pointer;">
<c:choose>
<c:when test="${list.status eq 'AWAITING'}">
변환중
@ -149,7 +209,7 @@ function goTextSenseDetail(id){
</c:otherwise>
</c:choose>
</td>
<td><c:out value="${list.frstRegistPnttm}"/></td>
<td onclick="javascript:goTextSenseDetail('<c:out value="${list.id}"/>');" style="cursor:pointer;"><c:out value="${list.frstRegistPnttm}"/></td>
</tr>
</c:forEach>
<c:if test="${empty list}">