diff --git a/WebContent/jsp/onl/admin/authserver/scopeManDetail.jsp b/WebContent/jsp/onl/admin/authserver/scopeManDetail.jsp
index 505483e..91d16c9 100644
--- a/WebContent/jsp/onl/admin/authserver/scopeManDetail.jsp
+++ b/WebContent/jsp/onl/admin/authserver/scopeManDetail.jsp
@@ -19,7 +19,6 @@
var url = '';
var url_view = '';
var api_url_view = '';
-var mapping_url = '';
var isDetail = false;
function isValid(){
@@ -65,9 +64,9 @@ function mappingInfo(key){
$.ajax({
type : "POST",
- url: mapping_url,
+ url: url,
dataType: "json",
- data: {cmd: 'LIST', searchScopeId : key},
+ data: {cmd: 'API_LIST', searchScopeId : key},
success: function(json){
var mappingData = json.rows;
@@ -131,45 +130,6 @@ function init(key, callback){
}
}
-function saveApiGridData(scopeId, returnUrl) {
- var postData = [];
- var rows = $("#selectedApiGrid").jqGrid('getRowData');
-
- $.each(rows, function(index, item) {
- item.scopeId = scopeId;
- });
-
- postData.push({
- name: "apiList",
- value: JSON.stringify(rows)
- });
-
- postData.push({ name: "cmd" , value:"INSERT_APILIST" });
- postData.push({ name: "scopeId" , value:scopeId });
-
- $.ajax({
- type : "POST",
- url:mapping_url,
- data: postData,
- beforeSend: function() {
- $("[id^='btn_']").prop("disabled", true);
- $("#btn_modify").text("처리중 . . . . .");
- },
- success:function(args){
- alert("저장 되었습니다.");
-
- goNav(returnUrl);//LIST로 이동
- },
- error:function(e){
- alert(e.responseText);
- },
- complete: function() {
- $("[id^='btn_']").prop("disabled", false);
- $("#btn_modify").text("수정");
- }
- });
-}
-
$(document).ready(function() {
var returnUrl = getReturnUrlForReturn();
var key ="${param.scopeId}";
@@ -182,28 +142,39 @@ $(document).ready(function() {
if (!isValid()){
return;
}
+ var scopeId = $('input[name=scopeId]').val();
var postData = $('#ajaxForm').serializeArray();
+
+ var rows = $("#selectedApiGrid").jqGrid('getRowData');
+ $.each(rows, function(index, item) {
+ item.scopeId = scopeId;
+ });
+ postData.push({ name: "apiList" , value: JSON.stringify(rows) });
+
if (isDetail){
postData.push({ name: "cmd" , value:"UPDATE"});
}else{
postData.push({ name: "cmd" , value:"INSERT"});
}
+
$.ajax({
type : "POST",
url:url,
data:postData,
+ beforeSend: function() {
+ $("[id^='btn_']").prop("disabled", true);
+ $("#btn_modify").text("처리중 . . . . .");
+ },
success:function(args){
- alert("SCOPE 정보가 저장 되었습니다. 이어서 API 리스트를 저장합니다.");
-
- if(!isDetail) { // INSERT 일 경우 ScopeId를 업데이트
- key = $('input[name=scopeId]').val();
- }
- saveApiGridData(key, returnUrl); // API LIST 저장.
-
-
+ alert("저장 되었습니다.");
+ goNav(returnUrl);//LIST로 이동
},
error:function(e){
alert(e.responseText);
+ },
+ complete: function() {
+ $("[id^='btn_']").prop("disabled", false);
+ $("#btn_modify").text("수정");
}
});
});
diff --git a/src/main/java/com/eactive/eai/rms/onl/manage/authserver/scope/ScopeController.java b/src/main/java/com/eactive/eai/rms/onl/manage/authserver/scope/ScopeController.java
index dadaee4..7a20bf5 100644
--- a/src/main/java/com/eactive/eai/rms/onl/manage/authserver/scope/ScopeController.java
+++ b/src/main/java/com/eactive/eai/rms/onl/manage/authserver/scope/ScopeController.java
@@ -1,5 +1,7 @@
package com.eactive.eai.rms.onl.manage.authserver.scope;
+import java.util.List;
+
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
@@ -8,21 +10,29 @@ import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
+import org.springframework.web.bind.annotation.RequestParam;
import com.eactive.eai.agent.authserver.ReloadApiScopeCommand;
import com.eactive.eai.agent.command.CommonCommand;
import com.eactive.eai.rms.common.base.OnlBaseAnnotationController;
import com.eactive.eai.rms.common.vo.GridResponse;
import com.eactive.eai.rms.data.entity.onl.authserver.ScopeSearch;
+import com.eactive.eai.rms.data.entity.onl.eaimsg.ApiScopeSearch;
+import com.eactive.eai.rms.onl.common.exception.BizException;
+import com.fasterxml.jackson.core.type.TypeReference;
+import com.fasterxml.jackson.databind.ObjectMapper;
@Controller
public class ScopeController extends OnlBaseAnnotationController {
private ScopeManService scopeManService;
+ private ApiScopeManService apiScopeManService;
+
@Autowired
- public ScopeController(ScopeManService scopeManService) {
+ public ScopeController(ScopeManService scopeManService, ApiScopeManService apiScopeManService) {
this.scopeManService = scopeManService;
+ this.apiScopeManService = apiScopeManService;
}
@GetMapping(value = "/onl/admin/authserver/scopeMan.view")
@@ -41,6 +51,12 @@ public class ScopeController extends OnlBaseAnnotationController {
return ResponseEntity.ok(new GridResponse<>(page));
}
+ @PostMapping(value = "/onl/admin/authserver/scopeMan.json", params = "cmd=API_LIST")
+ public ResponseEntity> selectApiList(Pageable pageable, ApiScopeSearch apiScopeSearch) {
+ Page page = apiScopeManService.selectApiScopeRelationsList(pageable, apiScopeSearch);
+ return ResponseEntity.ok(new GridResponse<>(page));
+ }
+
@PostMapping(value = "/onl/admin/authserver/scopeMan.json", params = "cmd=DETAIL")
public ResponseEntity selectDetail(String scopeId) {
ScopeUI scopeUI = scopeManService.selectDetail(scopeId);
@@ -48,14 +64,16 @@ public class ScopeController extends OnlBaseAnnotationController {
}
@PostMapping(value = "/onl/admin/authserver/scopeMan.json", params = "cmd=INSERT")
- public ResponseEntity insert(ScopeUI scopeUI) {
+ public ResponseEntity insert(ScopeUI scopeUI, @RequestParam(value = "apiList", required = false) String apiListJson) {
scopeManService.insert(scopeUI);
+ saveApiScopeRelations(scopeUI.getScopeId(), apiListJson);
return ResponseEntity.ok().build();
}
@PostMapping(value = "/onl/admin/authserver/scopeMan.json", params = "cmd=UPDATE")
- public ResponseEntity update(ScopeUI scopeUI) {
+ public ResponseEntity update(ScopeUI scopeUI, @RequestParam(value = "apiList", required = false) String apiListJson) {
scopeManService.update(scopeUI);
+ saveApiScopeRelations(scopeUI.getScopeId(), apiListJson);
return ResponseEntity.ok().build();
}
@@ -69,8 +87,29 @@ public class ScopeController extends OnlBaseAnnotationController {
.args(new String[] {ReloadApiScopeCommand.COMMAND_TYPE_SCOPE, "", scopeId})
.build()
.broadcast(agentUtilService);
-
+
return ResponseEntity.ok().build();
}
-
+
+ private void saveApiScopeRelations(String scopeId, String apiListJson) {
+ if (apiListJson == null || apiListJson.isEmpty()) {
+ return;
+ }
+
+ List apiScopeList;
+ try {
+ apiScopeList = new ObjectMapper().readValue(apiListJson, new TypeReference>() {});
+ } catch (Exception e) {
+ throw new BizException("데이터 변환 중 오류가 발생했습니다.");
+ }
+
+ scopeManService.updateApiScopeRelations(apiScopeList, scopeId);
+
+ CommonCommand.builder()
+ .name(CommonCommand.RELOAD_API_SCOPE_COMMAND)
+ .args(new String[] {ReloadApiScopeCommand.COMMAND_TYPE_SCOPE, "", scopeId})
+ .build()
+ .broadcast(agentUtilService);
+ }
+
}
\ No newline at end of file
diff --git a/src/main/java/com/eactive/eai/rms/onl/manage/authserver/scope/ScopeManService.java b/src/main/java/com/eactive/eai/rms/onl/manage/authserver/scope/ScopeManService.java
index f132afb..ca20675 100644
--- a/src/main/java/com/eactive/eai/rms/onl/manage/authserver/scope/ScopeManService.java
+++ b/src/main/java/com/eactive/eai/rms/onl/manage/authserver/scope/ScopeManService.java
@@ -1,5 +1,7 @@
package com.eactive.eai.rms.onl.manage.authserver.scope;
+import java.util.List;
+
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
@@ -21,17 +23,20 @@ public class ScopeManService extends OnlBaseService {
private ScopeInfoService scopeInfoService;
private ScopeEntityService scopeEntityService;
-
+
private ScopeUIMapper scopeUIMapper;
+ private ApiScopeUIMapper apiScopeUIMapper;
+
private LocaleMessage localeMessage;
-
+
@Autowired
- public ScopeManService(ScopeInfoService scopeInfoService, ScopeEntityService scopeEntityService,
- ScopeUIMapper scopeUIMapper, LocaleMessage localeMessage ) {
+ public ScopeManService(ScopeInfoService scopeInfoService, ScopeEntityService scopeEntityService,
+ ScopeUIMapper scopeUIMapper, ApiScopeUIMapper apiScopeUIMapper, LocaleMessage localeMessage ) {
this.scopeInfoService = scopeInfoService;
this.scopeEntityService = scopeEntityService;
this.scopeUIMapper = scopeUIMapper;
+ this.apiScopeUIMapper = apiScopeUIMapper;
this.localeMessage = localeMessage;
}
@@ -65,5 +70,23 @@ public class ScopeManService extends OnlBaseService {
public void deleteApiScopeRelationsByScopeId(String scopeId) {
scopeEntityService.deleteByIdScopeId(scopeId);
}
-
+
+ public void updateApiScopeRelations(List apiScopeList, String scopeId) {
+ if (scopeId == null || scopeId.isEmpty()) {
+ throw new BizException("ScopeId 가 존재하지 않습니다.");
+ }
+
+ // ScopeId 기준 전체 삭제 후 LIST 기준으로 재저장.
+ scopeEntityService.deleteByIdScopeId(scopeId);
+
+ if (apiScopeList == null || apiScopeList.isEmpty()) {
+ return;
+ }
+
+ for (ApiScopeUI ui : apiScopeList) {
+ ui.setScopeId(scopeId);
+ scopeEntityService.save(apiScopeUIMapper.toEntity(ui));
+ }
+ }
+
}