From a227dd7df7f84a5cfb7218042a6f844991dcfb96 Mon Sep 17 00:00:00 2001
From: 이민희 <mhlee@maprex.co.kr>
Date: 수, 09 2월 2022 14:53:41 +0900
Subject: [PATCH] - isp, 호스팅 엑셀 import 기능 추가

---
 src/main/java/kr/wisestone/owl/service/impl/IssueServiceImpl.java |   76 ++++++++++++++++++++++++--------------
 1 files changed, 48 insertions(+), 28 deletions(-)

diff --git a/src/main/java/kr/wisestone/owl/service/impl/IssueServiceImpl.java b/src/main/java/kr/wisestone/owl/service/impl/IssueServiceImpl.java
index 7724e79..ba2f863 100644
--- a/src/main/java/kr/wisestone/owl/service/impl/IssueServiceImpl.java
+++ b/src/main/java/kr/wisestone/owl/service/impl/IssueServiceImpl.java
@@ -49,9 +49,9 @@
 import java.text.ParseException;
 import java.text.SimpleDateFormat;
 import java.util.*;
+import java.util.regex.Pattern;
 
-import static kr.wisestone.owl.domain.enumType.CustomFieldType.DATETIME;
-import static kr.wisestone.owl.domain.enumType.CustomFieldType.INPUT;
+import static kr.wisestone.owl.domain.enumType.CustomFieldType.*;
 
 @Service
 public class IssueServiceImpl extends AbstractServiceImpl<Issue, Long, JpaRepository<Issue, Long>> implements IssueService {
@@ -3126,7 +3126,7 @@
                 //  1踰� �뿤�뜑遺��꽣 �뜲�씠�꽣 �쁺�뿭
                 if (rowIndex > 1) {
                     //  �씠�뒋濡� �벑濡앺븯湲� �쐞�빐 IssueForm �뿉 �뜲�씠�꽣瑜� �뀑�똿�븳�떎.
-                    IssueForm newIssueForm = this.setIssueFormToExcelField(row, (rowIndex + 1), priorityMaps, severityMaps, departmentMaps, customFieldMaps,
+                    IssueForm newIssueForm = this.setIssueFormToExcelField(row, (rowIndex + 1), priorityMaps, severityMaps, customFieldMaps,
                             companyFieldMaps, ispFieldMaps, hostingFieldMaps, headers);
                     ConvertUtil.copyProperties(issueForm, newIssueForm);
 
@@ -3470,55 +3470,61 @@
     }
 
     /**
+     * cell String�쑝濡� 蹂��솚 �븿�닔
+     * @param cell Cell
+     * @param isNull boolean
+     * @return String
+     */
+    private String stringToCell (Cell cell, boolean isNull) {
+        String cellStr = "";
+        if (!isNull) {
+            cellStr = CommonUtil.convertExcelStringToCell(cell);
+            //  怨듬갚 �젣嫄�
+            cell.setCellValue(cellStr.trim());
+        } else {
+            cell.setCellValue(cellStr);
+        }
+        return cellStr;
+    }
+
+    /**
      * cell NULL 泥댄겕 �븿�닔
      * 鍮� 媛믪씠 �븘�땶 cell 泥댄겕
      * @param cell Cell
      * @return boolean
      */
     private Boolean cellNullCheck (Cell cell) {
-        if (cell != null ) {
-            int cellType = cell.getCellType();
-            if (cellType < Cell.CELL_TYPE_BLANK) {
-                if (cellType == Cell.CELL_TYPE_STRING)
-                {
-                    if (cell.getStringCellValue() != null) {
-                        return false;
-                    }
-                } else {
+        int cellType = cell.getCellType();
+        if (cellType < Cell.CELL_TYPE_BLANK) {
+            if (cellType == Cell.CELL_TYPE_STRING) {
+                if (cell.getStringCellValue() != null && !cell.getStringCellValue().equals("")) {
                     return false;
                 }
+            } else {
+                return false;
             }
         }
         return true;
     }
 
-
-
-
     //  �뿊�� �븘�뱶�뿉 �엳�뒗 �젙蹂대�� �씠�뒋 form �쑝濡� �삷湲대떎.
     private IssueForm setIssueFormToExcelField(Row row, int rowIndex, Map<String, Priority> priorityMaps,
-                                               Map<String, Severity> severityMaps, Map<String, DepartmentVo> departmentMaps,
-                                               Map<String, CustomField> customFieldMaps, Map<String, CompanyField> companyFieldMaps,
-                                               Map<String, IspField> ispFieldMaps, Map<String, HostingField> hostingFieldMaps,
+                                               Map<String, Severity> severityMaps, Map<String, CustomField> customFieldMaps,
+                                               Map<String, CompanyField> companyFieldMaps, Map<String, IspField> ispFieldMaps, Map<String, HostingField> hostingFieldMaps,
                                                List<String> headers) throws ParseException {
         IssueForm issueForm = new IssueForm();
         issueForm.setRegisterId(this.webAppUtil.getLoginId());
-        Project project = null;
 
         //  �젣紐�, �궡�슜, �봽濡쒖젥�듃 �궎, �씠�뒋 ���엯, �슦�꽑�닚�쐞, 以묒슂�룄, �떞�떦�옄, �떆�옉�씪, 醫낅즺�씪, �궗�슜�옄 �젙�쓽 �븘�뱶
         for (int cellIndex = 0; cellIndex < headers.size(); cellIndex++) {
             Cell cell = row.getCell(cellIndex);
-            boolean isNull = cellNullCheck(cell);
 
             String cellStr = "";
+            boolean isNull = true;
 
-            if (!isNull) {
-                cellStr = CommonUtil.convertExcelStringToCell(cell);
-
-                //  怨듬갚 �젣嫄�
-                cell.setCellValue(cellStr.trim());
-            } else {
-                cell.setCellValue(cellStr);
+            if (cell != null) {
+                isNull = cellNullCheck(cell);
+                cellStr = stringToCell(cell, isNull); //cell�쓣 String�쑝濡� 蹂��솚
             }
 
             switch (cellIndex) {
@@ -3765,7 +3771,8 @@
                             this.messageAccessor.getMessage(MsgConstants.CUSTOM_FIELD_TEXT_TYPE_MAX_LENGTH_OUT));
                 }
 
-                if (customField.getCustomFieldType() == DATETIME) { //DATETIME�씪 寃쎌슦 format 蹂�寃�
+                //DATETIME�씪 寃쎌슦 format 蹂�寃�
+                if (customField.getCustomFieldType() == DATETIME) {
                     Date date = DateUtil.convertStrToDate(cellValue);
                     if (date == null) {
                         throw new OwlRuntimeException(
@@ -3773,6 +3780,19 @@
                     }
                 }
 
+                //IP_ADDRESS�씪 寃쎌슦 �젙洹쒗몴�쁽�떇 泥댄겕
+                if (customField.getCustomFieldType() == IP_ADDRESS) {
+                    String regExp = "^(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\."
+                            + "(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\."
+                            + "(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\."
+                            + "(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$";
+
+                    if (!cellValue.matches(regExp)) {
+                        throw new OwlRuntimeException(
+                                this.messageAccessor.getMessage(MsgConstants.EXCEL_IMPORT_IP_ADDRESS_NOT_VALIDITY, rowIndex));
+                    }
+                }
+
                 issueCustomFieldMap.put("customFieldId", customField.getId());
                 issueCustomFieldMap.put("useValue", cellValue);
                 issueForm.addIssueCustomFields(issueCustomFieldMap);

--
Gitblit v1.8.0