OWL ITS + 탐지시스템(인터넷 진흥원)
jhjang
2022-01-05 fde37173d256963954d8020db4cd2b7cfb9144e7
src/main/java/kr/wisestone/owl/web/controller/ApiController.java
@@ -3,16 +3,12 @@
import kr.wisestone.owl.constant.Constants;
import kr.wisestone.owl.constant.MsgConstants;
import kr.wisestone.owl.domain.Issue;
import kr.wisestone.owl.domain.User;
import kr.wisestone.owl.exception.OwlRuntimeException;
import kr.wisestone.owl.service.IssueService;
import kr.wisestone.owl.util.ConvertUtil;
import kr.wisestone.owl.web.form.IssueApiForm;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Pageable;
import org.springframework.http.MediaType;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
@@ -22,35 +18,39 @@
import java.util.List;
import java.util.Map;
/**
 * OWL-API 컨트롤러
 */
@Controller
public class ApiController extends BaseController {
    @Autowired
    private IssueService issueService;
    //  이슈 추가(json 방식으로 파일전송)
//    @RequestMapping(value = "api/issue", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE)
//    public
//    @ResponseBody
//    Map<String, Object> addIssue(@RequestBody Map<String, Map<String, Object>> params) {
//        Map<String, Object> resJsonData = new HashMap<>();
//
//        IssueApiForm issueForm = IssueApiForm.make(params.get(Constants.REQ_KEY_CONTENT));
//        Issue issue = this.issueService.addApiIssue(issueForm);
//        //  버전 생성
//        this.issueService.addIssueVersion(issue.getId());
//        return this.setSuccessMessage(resJsonData);
//    }
    /**
     * @param request multipart/form-data 로 요청해야 함
     * @return Json 으로 결과값 전송
     * @throws OwlRuntimeException 주로파라미터 오류 체크시 발생
     * @throws CloneNotSupportedException 객체 복사할 때 발생
     */
    @RequestMapping(value = "api/issue", method = RequestMethod.POST)
    public
    @ResponseBody
    Map<String, Object> addIssue(MultipartHttpServletRequest request) throws OwlRuntimeException, CloneNotSupportedException {
        Map<String, Object> resJsonData = new HashMap<>();
        IssueApiForm issueForm = IssueApiForm.make(ConvertUtil.convertJsonToMap(request.getParameter(Constants.REQ_KEY_CONTENT)), request.getFiles("file"));
        String str = request.getParameter(Constants.REQ_KEY_CONTENT);
        IssueApiForm issueForm = IssueApiForm.make(ConvertUtil.convertJsonToMap(str), request.getFiles("file"));
        if (issueForm == null) {
            throw new OwlRuntimeException(this.messageAccessor.getMessage(MsgConstants.API_PARAMETER_ERROR));
        }
        // 사용자 정의 필드가 없을 경우 검색을 할 수 없기 때문에 예외처리
        else if (issueForm.getCustomFieldValues() == null || issueForm.getCustomFieldValues().size() == 0) {
            throw new OwlRuntimeException(this.messageAccessor.getMessage(MsgConstants.API_CUSTOM_FIELD_NOT_EXIST));
        }
        if (issueForm.getApiType() == IssueApiForm.ApiType.add) {
            List<Issue> issues = this.issueService.addApiIssue(issueForm);
            //  버전 생성
@@ -58,6 +58,8 @@
                this.issueService.addIssueVersion(issue.getId(), issue.getRegisterId());
            }
        } else {
            this.issueService.modifyIssue(issueForm, request.getFiles("file"));
        }
@@ -65,15 +67,15 @@
    }
    //  이슈 조회
    @RequestMapping(value = "/api/issueList", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
    public
    @ResponseBody
    Map<String, Object> find(@RequestBody Map<String, Map<String, Object>> params) {
        Map<String, Object> resJsonData = new HashMap<>();
        Pageable pageable = this.pageUtil.convertPageable(this.getPageVo(params));
        // todo
        return this.setSuccessMessage(resJsonData);
    }
//    @RequestMapping(value = "/api/issueList", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
//    public
//    @ResponseBody
//    Map<String, Object> find(@RequestBody Map<String, Map<String, Object>> params) {
//        Map<String, Object> resJsonData = new HashMap<>();
//        Pageable pageable = this.pageUtil.convertPageable(this.getPageVo(params));
//
//        // todo
//        return this.setSuccessMessage(resJsonData);
//    }
}