Class ItemController

java.lang.Object
com.easydesk.modules.controller.ItemController

@Controller public class ItemController extends Object
Item 의 입력, 수정 등을 관리한다.

form 의 입력 key 는 각 AttributeValue.getQueryKey() 이다.

  • 새 Item 의 AttributeValue : __<attributeId>
  • 저장된 Item 의 아직 값이 없는 AttributeValue : <itemId>__<attributeId>
  • 저장된 AttributeValue : <valueId>
화면(template)은 item.getModuleAttributeValuesMap() 의 각 value 에 대하여 value.queryKey 를 input name 으로 사용하면 된다. form 에 key 가 없는(전송되지 않은) AttributeValue 는 변경하지 않는다.

ActivitySetType 은 form 의 "activitySetTypeId" 값으로 정한다 (필수, 없으면 400). 화면(Screen Item)에 설정된 ActivitySetType 을 form 에 hidden 으로 같이 넣어 보내야 한다. (TransactionContextInterceptor 도 같은 이름의 parameter 를 Context 에 반영하지만, controller 에서 필수값으로 받아 명시적으로 처리 범위를 정한다)

화면의 component 별 즉시 저장(예: RadioBox 선택이 바뀌면 바로 저장)은 updateValues(Long, String, Integer, HttpServletRequest) 를 사용한다. form 처리는 update 와 같고 redirect 대신 JSON 으로 결과(변경된 AttributeValue 의 새 queryKey 와 값)를 돌려준다.

처리 과정은 easydesk-spring-core 의 ItemFactoryTest 와 같다. TODO : Validation 은 아직 적용하지 않았다. (빈 값은 무시한다)

Author:
YounghoCho
  • Field Details

    • FLASH_UNIQUE_ID

      public static final String FLASH_UNIQUE_ID
      처리된 Item 의 uniqueId 를 redirect 화면에 넘기는 flash attribute 이름
      See Also:
    • ACTIVITY_SET_TYPE_PARAM

      public static final String ACTIVITY_SET_TYPE_PARAM
      ActivitySetType 을 보내는 form parameter 이름 (TransactionContextInterceptor.ACTIVITY_SET_TYPE_KEYS 와 같다)
      See Also:
  • Constructor Details

    • ItemController

      public ItemController()
  • Method Details

    • add

      @PostMapping("/modules/{moduleId}/item-types/{typeId}/items") public String add(@PathVariable("moduleId") Long moduleId, @PathVariable("typeId") Integer typeId, @RequestParam("activitySetTypeId") Integer activitySetTypeId, HttpServletRequest request, org.springframework.web.servlet.mvc.support.RedirectAttributes redirectAttributes) throws Exception
      새 Item 을 입력한다.
      Parameters:
      moduleId - 입력할 Module
      typeId - 입력할 ItemType
      activitySetTypeId - form 에서 보낸 ActivitySetType (예: ADD)
      request - form 입력값
      redirectAttributes - 입력된 Item 의 uniqueId 를 flash 로 전달
      Returns:
      입력된 Item 의 view 화면으로 redirect
      Throws:
      Exception - 입력 중 오류
    • update

      @PostMapping("/modules/{moduleId}/items/{uniqueId}/update") public String update(@PathVariable("moduleId") Long moduleId, @PathVariable("uniqueId") String uniqueId, @RequestParam("activitySetTypeId") Integer activitySetTypeId, HttpServletRequest request, org.springframework.web.servlet.mvc.support.RedirectAttributes redirectAttributes) throws Exception
      저장된 Item 을 수정한다.
      Parameters:
      moduleId - 수정할 Item 의 Module
      uniqueId - 수정할 Item
      activitySetTypeId - form 에서 보낸 ActivitySetType (예: UPDATE)
      request - form 입력값
      redirectAttributes - 수정된 Item 의 uniqueId 를 flash 로 전달
      Returns:
      수정된 Item 의 view 화면으로 redirect
      Throws:
      Exception - 수정 중 오류
    • updateValues

      @PostMapping(path="/modules/{moduleId}/items/{uniqueId}/values", produces="application/json") @ResponseBody public org.springframework.http.ResponseEntity<Map<String,Object>> updateValues(@PathVariable("moduleId") Long moduleId, @PathVariable("uniqueId") String uniqueId, @RequestParam("activitySetTypeId") Integer activitySetTypeId, HttpServletRequest request)
      화면의 component 하나(또는 몇 개)의 변경을 바로 저장한다 (fetch / XHR 용).

      form 처리는 update(java.lang.Long, java.lang.String, java.lang.Integer, jakarta.servlet.http.HttpServletRequest, org.springframework.web.servlet.mvc.support.RedirectAttributes) 와 같다. 응답은 JSON 이다.

       200 : { "uniqueId": "...", "values": [ { "attributeId": 1, "queryKey": "123", "value": "Checked",
                                               "optionIds": [3] }, ... ] }
       401 : 로그인하지 않음, 404 : Item 없음, 500 : 저장 중 오류 ({ "message": "..." })
       400 : activitySetTypeId 없음 (Spring 이 처리)
       
      저장된 AttributeValue 의 queryKey 는 valueId 이므로, 값이 처음 저장되거나 새 row 로 저장되면 queryKey 가 바뀐다. 화면은 응답의 queryKey 로 input name 을 바꿔서 다음 변경을 보내야 한다.

      Parameters:
      moduleId - 수정할 Item 의 Module (TransactionContextInterceptor 가 Context 에 반영)
      uniqueId - 수정할 Item
      activitySetTypeId - 화면(Screen Item)의 ActivitySetType
      request - form 입력값
      Returns:
      변경된 AttributeValue 정보