Scope관리 Api Reload 버그 수정
This commit is contained in:
@@ -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<GridResponse<ApiScopeUI>> selectApiList(Pageable pageable, ApiScopeSearch apiScopeSearch) {
|
||||
Page<ApiScopeUI> page = apiScopeManService.selectApiScopeRelationsList(pageable, apiScopeSearch);
|
||||
return ResponseEntity.ok(new GridResponse<>(page));
|
||||
}
|
||||
|
||||
@PostMapping(value = "/onl/admin/authserver/scopeMan.json", params = "cmd=DETAIL")
|
||||
public ResponseEntity<ScopeUI> 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<Void> insert(ScopeUI scopeUI) {
|
||||
public ResponseEntity<Void> 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<Void> update(ScopeUI scopeUI) {
|
||||
public ResponseEntity<Void> 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<ApiScopeUI> apiScopeList;
|
||||
try {
|
||||
apiScopeList = new ObjectMapper().readValue(apiListJson, new TypeReference<List<ApiScopeUI>>() {});
|
||||
} 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);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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<ApiScopeUI> 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));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user