From 8cdee12102d831355c2be8fedff2d7f26cb0931b Mon Sep 17 00:00:00 2001
From: jhjang <jhjang@maprex.co.kr>
Date: 목, 16 12월 2021 19:02:28 +0900
Subject: [PATCH] - 프로젝트내 이슈유형에 설정된 사용자 정의 필드가 없을 경우 오류 예외 처리(api 입력 안되는 원인이었음)

---
 src/main/java/kr/wisestone/owl/service/impl/IssueServiceImpl.java |   81 ++++++++++++++++++++++++++++++----------
 1 files changed, 61 insertions(+), 20 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 10d95d0..be9364c 100644
--- a/src/main/java/kr/wisestone/owl/service/impl/IssueServiceImpl.java
+++ b/src/main/java/kr/wisestone/owl/service/impl/IssueServiceImpl.java
@@ -375,10 +375,11 @@
         IssueForm issueForm = this.convertToIssueForm(issueApiForm, user);
 
         List<Issue> issues = Lists.newArrayList();
-        if (issueForm.getParentIssueId() != null) {
+        if (issueForm.getParentIssueId() != null    // 湲곗〈 異붽��맂 �긽�쐞 �씪媛먯씠 �뾾嫄곕굹 �꽕�젙�맂 以묐났 �씠�뒋 id媛� �뾾�쓣�븣
+                || issueApiForm.getUseIssueCustomFieldIds().size() == 0) {
             issues.add(addIssue(user, issueForm, issueApiForm.getMultipartFiles()));
         } else {
-            // �긽�쐞 �씠�뒋 異붽�
+            // 媛��긽 �긽�쐞 �씠�뒋 異붽�
             IssueForm parentIssueForm = issueForm.clone();
             parentIssueForm.setUseIssueCustomFields(issueApiForm.getUseIssueCustomFieldIds());
             Issue issue = addIssue(user, parentIssueForm, null);
@@ -2241,6 +2242,19 @@
         this.verifyIssueModifyPermission(issue, user);
 
         IssueStatus issueStatus = this.issueStatusService.getIssueStatus(issueForm.getIssueStatusId());
+
+        if (issueStatus.getIssueStatusType().toString().equals("CLOSE")) {
+            List<String> downIssuesStatus = issueForm.getDownIssuesStatus();
+            if (downIssuesStatus != null && downIssuesStatus.size() > 0) {
+                for (String downIssueStatus : downIssuesStatus) {
+                    if (!downIssueStatus.equals("CLOSE")) {
+                        throw new OwlRuntimeException(
+                                this.messageAccessor.getMessage(MsgConstants.ISSUE_NOT_MODIFY_STATUS));
+                    }
+                }
+            }
+        }
+
         //  �씠�뒋 �긽�깭瑜� 蹂�寃쏀븷 �븣 �꽑�깮�븳 �씠�뒋 �긽�깭濡� 蹂�寃쏀븷 �닔 �엳�뒗吏� �솗�씤�븳�떎.
         this.issueStatusService.checkNextIssueStatus(issue, issueStatus);
         //  蹂�寃� �씠�젰 �젙蹂� 異붿텧
@@ -2878,7 +2892,7 @@
             Map<String, Priority> priorityMaps = new HashMap<>();   //  �슦�꽑 �닚�쐞 紐⑥쓬
             Map<String, Severity> severityMaps = new HashMap<>();   //  以묒슂�룄 紐⑥쓬
             Map<String, Object> userMaps = new HashMap<>(); //  �궗�슜�옄 紐⑥쓬
-            Map<String, Object> departmentMaps = new HashMap<>(); //  遺��꽌 紐⑥쓬
+            Map<String, DepartmentVo> departmentMaps = new HashMap<>(); //  遺��꽌 紐⑥쓬
             Map<String, CustomField> customFieldMaps = new HashMap<>();
             Map<String, IssueStatus> issueStatusReadyMaps = new HashMap<>();   //  �긽�깭 �냽�꽦 '��湲�'�씤 �씠�뒋 �긽�깭
             Map<Long, Long> issueNumberMaps = new HashMap<>();  //  �씠�뒋 踰덊샇 紐⑥쓬
@@ -2928,7 +2942,7 @@
                 //  1踰� �뿤�뜑遺��꽣 �뜲�씠�꽣 �쁺�뿭
                 if (rowIndex > 1) {
                     //  �씠�뒋濡� �벑濡앺븯湲� �쐞�빐 IssueForm �뿉 �뜲�씠�꽣瑜� �뀑�똿�븳�떎.
-                    issueForms.add(this.setIssueFormToExcelField(row, (rowIndex + 1), issueStatusReadyMaps, projectMaps, issueTypeMaps, priorityMaps, severityMaps, userMaps, customFieldMaps, issueNumberMaps, headers));
+                    issueForms.add(this.setIssueFormToExcelField(row, (rowIndex + 1), issueStatusReadyMaps, projectMaps, issueTypeMaps, priorityMaps, severityMaps, userMaps, departmentMaps, customFieldMaps, issueNumberMaps, headers));
                 }
             }
 
@@ -3079,7 +3093,7 @@
 
     //  �씠�뒋�쓽 二쇱슂 �냽�꽦�쓣 map �뿉 ���옣�븯�뿬 �뿊�� import �뿉�꽌 吏��젙�븳 ���긽(�씠�뒋 �냽�꽦)�쓣 鍮좊Ⅴ寃� 李얠쓣 �닔 �엳寃� �븳�떎.
     private void IssueAttributeMapToList(Map<String, Project> projectMaps, Map<String, IssueType> issueTypeMaps, Map<String, Priority> priorityMaps, Map<String, Severity> severityMaps,
-                                         Map<String, Object> userMaps, Map<String, Object> departmentMaps, Map<String, CustomField> customFieldMaps, Map<Long, Long> issueNumberMaps, Map<String, Long> issueTypeCustomFieldMaps, Map<String, IssueStatus> issueStatusReadyMaps) {
+                                         Map<String, Object> userMaps, Map<String, DepartmentVo> departmentMaps, Map<String, CustomField> customFieldMaps, Map<Long, Long> issueNumberMaps, Map<String, Long> issueTypeCustomFieldMaps, Map<String, IssueStatus> issueStatusReadyMaps) {
         //  �봽濡쒖젥�듃 �궎濡� 諛붾줈 李얠쓣 �닔 �엳寃� 以�鍮�
         List<Project> projects = this.projectService.findByWorkspaceId();
         List<Long> projectIds = Lists.newArrayList();
@@ -3103,16 +3117,7 @@
             for (Map<String, Object> user : users) {
                 userMap.put(CommonUtil.decryptAES128(MapUtil.getString(user, "account")), MapUtil.getLong(user, "userId"));
             }
-
             userMaps.put(project.getProjectKey(), userMap);
-
-            //  �봽濡쒖젥�듃�뿉 李몄뿬�븯�뒗 遺��꽌 �젙蹂�
-            List<Map<String, Object>> departments = this.departmentService.findProjectDepartment(project);
-            List<Long> departmentList = Lists.newArrayList();
-            //  遺��꽌 �젙蹂대�� ���옣
-            for (Map<String, Object> department : departments) {
-                departmentList.add(MapUtil.getLong(department, "departmentId"));
-            }
         }
 
         //  �씠�뒋 �쑀�삎�쓣 諛붾줈 李얠쓣 �닔 �엳寃� 以�鍮�
@@ -3122,6 +3127,13 @@
 
             IssueStatus issueStatus = this.issueStatusService.findByIssueStatusTypeIsReady(issueType.getWorkflow());
             issueStatusReadyMaps.put(issueType.getId().toString(), issueStatus);
+
+            //  �썙�겕�뵆濡쒖슦�뿉 �냽�빐�엳�뒗 遺��꽌 �젙蹂�
+            List<DepartmentVo> departments = this.departmentService.findWorkflowDepartment(issueType.getId());
+            //  遺��꽌 �젙蹂대�� ���옣
+            for (DepartmentVo department : departments) {
+                departmentMaps.put(department.getDepartmentName(), department);
+            }
         }
 
         //  �슦�꽑�닚�쐞瑜� 諛붾줈 李얠쓣 �닔 �엳寃� 以�鍮�
@@ -3145,7 +3157,7 @@
 
     //  �뿊�� �븘�뱶�뿉 �엳�뒗 �젙蹂대�� �씠�뒋 form �쑝濡� �삷湲대떎.
     private IssueForm setIssueFormToExcelField(Row row, int rowIndex, Map<String, IssueStatus> issueStatusReadyMaps, Map<String, Project> projectMaps, Map<String, IssueType> issueTypeMaps, Map<String,
-            Priority> priorityMaps, Map<String, Severity> severityMaps, Map<String, Object> userMaps, Map<String, CustomField> customFieldMaps, Map<Long, Long> issueNumberMaps, List<String> headers) {
+            Priority> priorityMaps, Map<String, Severity> severityMaps, Map<String, Object> userMaps, Map<String, DepartmentVo> departmentMaps, Map<String, CustomField> customFieldMaps, Map<Long, Long> issueNumberMaps, List<String> headers) {
         IssueForm issueForm = new IssueForm();
         issueForm.setRegisterId(this.webAppUtil.getLoginId());
         Project project = null;
@@ -3189,9 +3201,13 @@
                     //  以묒슂�룄瑜� IssueForm �뿉 ���옣�븳�떎.
                     this.setIssueFormSeverity(cell, severityMaps, issueForm, rowIndex);
                     break;
+                /*case 6:
+                    //  �떞�떦�옄瑜� IssueForm �뿉 ���옣�븳�떎.
+                    this.setIssueFormAssignee(cell, userMaps, issueForm, project);
+                    break;*/
                 case 6:
                     //  �떞�떦遺��꽌瑜� IssueForm �뿉 ���옣�븳�떎.
-                    this.setIssueFormAssignee(cell, userMaps, issueForm, project);
+                    this.setIssueFormDepartment(cell, departmentMaps, issueForm, project);
                     break;
                 case 7:
                     //  �떆�옉�씪�쓣 IssueForm �뿉 ���옣�븳�떎.
@@ -3202,7 +3218,7 @@
                     this.setIssueFormPeriod(cell, issueForm, false, rowIndex);
                     break;
                 default:
-                    //  8踰� �씠�긽遺��꽣�뒗 �궗�슜�옄 �젙�쓽 �븘�뱶. �궗�슜�옄 �젙�쓽 �븘�뱶 �젙蹂대�� IssueForm �뿉 ���옣�븳�떎.
+                    //  9踰� 遺��꽣�뒗 �궗�슜�옄 �젙�쓽 �븘�뱶. �궗�슜�옄 �젙�쓽 �븘�뱶 �젙蹂대�� IssueForm �뿉 ���옣�븳�떎.
                     this.setIssueFormCustomFieldValue(cell, customFieldMaps, issueForm, headers.get(cellIndex), rowIndex);
             }
         }
@@ -3331,20 +3347,39 @@
         issueForm.setSeverityId(severity.getId());
     }
 
-    //  �떞�떦遺��꽌瑜� IssueForm �뿉 ���옣�븳�떎.
     private void setIssueFormAssignee(Cell cell, Map<String, Object> userMaps, IssueForm issueForm, Project project) {
         if (cell != null) {
             String[] splitAssignee = CommonUtil.convertExcelStringToCell(cell).split("#");
             Map<String, Object> userMap = (Map<String, Object>) MapUtil.getObject(userMaps, project.getProjectKey());
 
-            List<Long> departmentIds = Lists.newArrayList();
+            List<Long> userIds = Lists.newArrayList();
 
             for (String account : splitAssignee) {
                 if (MapUtil.getLong(userMap, account) != null) {
-                    departmentIds.add(MapUtil.getLong(userMap, account));
+                    userIds.add(MapUtil.getLong(userMap, account));
                 }
             }
+            issueForm.setUserIds(userIds);
+        }
+    }
 
+    //  �떞�떦遺��꽌瑜� IssueForm �뿉 ���옣�븳�떎.
+    private void setIssueFormDepartment(Cell cell, Map<String, DepartmentVo> departmentMaps, IssueForm issueForm, Project project) {
+        if (cell != null) {
+            String[] splitDepartment = CommonUtil.convertExcelStringToCell(cell).split("#");
+
+            //  媛믪씠 怨듬갚�씠硫� 以묒�
+            String cellValue = CommonUtil.convertExcelStringToCell(cell);
+            if (StringUtils.isEmpty(cellValue)) {
+                return;
+            }
+
+            List<Long> departmentIds = Lists.newArrayList();
+
+            for (String department : splitDepartment) {
+                DepartmentVo departmentVo = departmentMaps.get(department);
+                departmentIds.add(departmentVo.getId());
+            }
             issueForm.setDepartmentIds(departmentIds);
         }
     }
@@ -3353,6 +3388,12 @@
     private void setIssueFormPeriod(Cell cell, IssueForm issueForm, Boolean checkStartDate, int rowIndex) {
         if (cell != null && !cell.toString().equals("")) {
 
+            //  媛믪씠 怨듬갚�씠硫� 以묒�
+            String cellValue = CommonUtil.convertExcelStringToCell(cell);
+            if (StringUtils.isEmpty(cellValue)) {
+                return;
+            }
+
             Date startDate;
 
             try {

--
Gitblit v1.8.0