@Transactional(
      readOnly = false,
      propagation = Propagation.REQUIRED,
      rollbackFor = Exception.class)
  @RequestMapping(
      method = RequestMethod.PUT,
      value = {"/{tid}/item/{id}/reorder/{sequence}"})
  public ModelAndView reorderTaskResourceAssociatedItem(
      @PathVariable(ID) String taskResourceAssocId,
      @PathVariable(TID) String taskUid,
      @PathVariable(value = SEQUENCE) int sequence,
      @RequestParam(value = DATA_OBJECT, required = false) String data,
      HttpServletRequest request,
      HttpServletResponse response)
      throws Exception {
    ActionResponseDTO<TaskResourceAssoc> responseDTO =
        getTaskService().reorderResourceAssociatedItem(taskUid, taskResourceAssocId, sequence);
    if (responseDTO.getErrors().getErrorCount() > 0) {
      response.setStatus(HttpServletResponse.SC_BAD_REQUEST);
    }
    String[] includes = (String[]) ArrayUtils.addAll(TASK_RESOURCE_ASSOC_INCLUDES, ERROR_INCLUDE);

    return toModelAndView(
        serialize(responseDTO.getModelData(), RESPONSE_FORMAT_JSON, EXCLUDE_ALL, true, includes));
  }
  @AuthorizeOperations(operations = {GooruOperationConstants.OPERATION_TASK_MANAGEMENT_ADD})
  @Transactional(
      readOnly = false,
      propagation = Propagation.REQUIRED,
      rollbackFor = Exception.class)
  @RequestMapping(
      method = RequestMethod.POST,
      value = {"/{id}/item"})
  public ModelAndView createTaskResourceAssociation(
      HttpServletRequest request,
      @PathVariable(ID) String gooruOid,
      @RequestBody String data,
      HttpServletResponse response)
      throws Exception {
    User user = (User) request.getAttribute(Constants.USER);
    JSONObject json = requestData(data);
    ActionResponseDTO<TaskResourceAssoc> task =
        getTaskService()
            .createTaskResourceAssociation(
                this.buildTaskResourceFromInputParameters(getValue(TASK_RESOURCE_ASSOC, json)),
                user,
                gooruOid);
    if (task.getErrors().getErrorCount() > 0) {
      response.setStatus(HttpServletResponse.SC_BAD_REQUEST);
    } else {
      response.setStatus(HttpServletResponse.SC_CREATED);
    }
    String[] includeFields =
        getValue(FIELDS, json) != null ? getFields(getValue(FIELDS, json)) : null;
    String includes[] =
        (String[])
            ArrayUtils.addAll(
                includeFields == null ? TASK_CREATE_RESOURCE_ASSOC_INCLUDES : includeFields,
                ERROR_INCLUDE);
    includes = (String[]) ArrayUtils.addAll(includes, RESOURCE_INCLUDE_FIELDS);

    SessionContextSupport.putLogParameter(EVENTNAME, CREATE_TASK_RESOURCE_ASSOCIATION);
    SessionContextSupport.putLogParameter(
        TASK_ASSOCIATED_DATE, task.getModel().getAssociationDate());
    SessionContextSupport.putLogParameter(
        TASK_RESOURCE_ASSOCIATOR,
        task.getModel().getAssociatedBy() != null
            ? task.getModel().getAssociatedBy().getPartyUid()
            : null);
    SessionContextSupport.putLogParameter(
        TASK_RESOURCE_UID, task.getModel().getTaskResourceAssocUid());
    SessionContextSupport.putLogParameter(RESOURCE, task.getModel().getResource().getGooruOid());

    return toModelAndViewWithIoFilter(
        task.getModelData(), RESPONSE_FORMAT_JSON, EXCLUDE_ALL, includes);
  }
  @AuthorizeOperations(operations = {GooruOperationConstants.OPERATION_TASK_MANAGEMENT_ADD})
  @Transactional(
      readOnly = false,
      propagation = Propagation.REQUIRED,
      rollbackFor = Exception.class)
  @RequestMapping(
      method = RequestMethod.POST,
      value = {"/{id}/associate"})
  public ModelAndView createTaskAssoc(
      @PathVariable(ID) String taskId,
      @RequestBody String data,
      HttpServletRequest request,
      HttpServletResponse response)
      throws Exception {
    request.setAttribute(PREDICATE, "task.create_task_assoc");
    User user = (User) request.getAttribute(Constants.USER);
    JSONObject json = requestData(data);
    ActionResponseDTO<TaskAssoc> responseDTO =
        getTaskService()
            .createTaskAssoc(
                this.buildTaskAssocFromInputParameters(getValue(TASK_ASSOC, json)), taskId, user);
    if (responseDTO.getErrors().getErrorCount() > 0) {
      response.setStatus(HttpServletResponse.SC_BAD_REQUEST);
    } else {
      response.setStatus(HttpServletResponse.SC_CREATED);
    }
    String[] includeFields =
        getValue(FIELDS, json) != null ? getFields(getValue(FIELDS, json)) : null;
    String includes[] =
        (String[])
            ArrayUtils.addAll(
                includeFields == null ? TASK_ASSOC_INCLUDES : includeFields, ERROR_INCLUDE);

    SessionContextSupport.putLogParameter(EVENTNAME, CREATE_TASK_ASSOC);
    SessionContextSupport.putLogParameter(TASK_ASSOC_UID, responseDTO.getModel().getTaskAssocUid());
    SessionContextSupport.putLogParameter(
        TASK_DESCENDANT_ID,
        responseDTO.getModel().getTaskDescendant() != null
            ? responseDTO.getModel().getTaskDescendant().getGooruOid()
            : null);
    SessionContextSupport.putLogParameter(
        TASK_PARENT_ID,
        responseDTO.getModel().getTaskParent() != null
            ? responseDTO.getModel().getTaskParent().getGooruOid()
            : null);

    return toModelAndViewWithIoFilter(
        responseDTO.getModelData(), RESPONSE_FORMAT_JSON, EXCLUDE_ALL, includes);
  }
  @AuthorizeOperations(operations = {GooruOperationConstants.OPERATION_TASK_MANAGEMENT_UPDATE})
  @Transactional(
      readOnly = false,
      propagation = Propagation.REQUIRED,
      rollbackFor = Exception.class)
  @RequestMapping(
      method = RequestMethod.PUT,
      value = {"/{id}"})
  public ModelAndView updateTask(
      HttpServletRequest request,
      @PathVariable(ID) String gooruOid,
      @RequestBody String data,
      HttpServletResponse response)
      throws Exception {
    request.setAttribute(PREDICATE, "task.update_task");
    User user = (User) request.getAttribute(Constants.USER);
    JSONObject json = requestData(data);
    ActionResponseDTO<Task> task =
        getTaskService()
            .updateTask(
                gooruOid,
                this.buildTaskFromInputParameters(getValue(TASK, json)),
                getValue(PLANNED_END_DATE, json) != null ? getValue(PLANNED_END_DATE, json) : null,
                user);
    if (task.getErrors().getErrorCount() > 0) {
      response.setStatus(HttpServletResponse.SC_BAD_REQUEST);
    }
    String[] includeFields =
        getValue(FIELDS, json) != null ? getFields(getValue(FIELDS, json)) : null;
    String includes[] =
        (String[])
            ArrayUtils.addAll(includeFields == null ? TASK_INCLUDES : includeFields, ERROR_INCLUDE);

    SessionContextSupport.putLogParameter(EVENTNAME, UPDATE_TASK);
    SessionContextSupport.putLogParameter(TASK_UID, task.getModel().getGooruOid());
    SessionContextSupport.putLogParameter(
        MODIFIED_USER,
        task.getModel().getLastUpdatedUserUid() != null
            ? task.getModel().getLastUpdatedUserUid()
            : null);
    SessionContextSupport.putLogParameter(LAST_MODIFIED_DATE, task.getModel().getLastModified());

    return toModelAndViewWithIoFilter(
        task.getModelData(), RESPONSE_FORMAT_JSON, EXCLUDE_ALL, includes);
  }
  @AuthorizeOperations(operations = {GooruOperationConstants.OPERATION_TASK_MANAGEMENT_ADD})
  @Transactional(
      readOnly = false,
      propagation = Propagation.REQUIRED,
      rollbackFor = Exception.class)
  @RequestMapping(
      value = {""},
      method = RequestMethod.POST)
  public ModelAndView createTask(
      HttpServletRequest request, @RequestBody String data, HttpServletResponse response)
      throws Exception {
    request.setAttribute(PREDICATE, "task.create_task");
    User user = (User) request.getAttribute(Constants.USER);
    JSONObject json = requestData(data);
    ActionResponseDTO<Task> task =
        getTaskService()
            .createTask(
                this.buildTaskFromInputParameters(getValue(TASK, json)),
                getValue(PLANNED_END_DATE, json) != null ? getValue(PLANNED_END_DATE, json) : null,
                user,
                this.buildAttachFromInputParameters(getValue(ATTACH_TO, json)));
    if (task.getErrors().getErrorCount() > 0) {
      response.setStatus(HttpServletResponse.SC_BAD_REQUEST);
    } else {
      response.setStatus(HttpServletResponse.SC_CREATED);
    }
    String[] includeFields =
        getValue(FIELDS, json) != null ? getFields(getValue(FIELDS, json)) : null;
    String includes[] =
        (String[])
            ArrayUtils.addAll(includeFields == null ? TASK_INCLUDES : includeFields, ERROR_INCLUDE);

    SessionContextSupport.putLogParameter(EVENTNAME, CREATE_TASK);
    SessionContextSupport.putLogParameter(TASK_UID, task.getModel().getGooruOid());
    SessionContextSupport.putLogParameter(
        CREATOR_UID,
        task.getModel().getCreatedOn() != null ? task.getModel().getCreator().getPartyUid() : null);
    SessionContextSupport.putLogParameter(TASK_CREATED_DATE, task.getModel().getCreatedOn());
    SessionContextSupport.putLogParameter(TASK_TITLE, task.getModel().getTitle());
    return toModelAndViewWithIoFilter(
        task.getModelData(), RESPONSE_FORMAT_JSON, EXCLUDE_ALL, includes);
  }