/**
   * Prepare message info. This builds error messages to be sent back to the WS client
   *
   * @param list the list
   * @return the list
   */
  private List<MessageInfo> prepareMessageInfo(List<Message> list) {
    List<MessageInfo> response = new ArrayList<MessageInfo>();

    for (Message msg : list) {
      MessageInfo wsMsg = new MessageInfo();
      wsMsg.setMessageText(msg.getText());
      wsMsg.setMessageType(MessageType.OTHER);
      response.add(wsMsg);
    }

    return response;
  }
  /**
   * Insert.
   *
   * @param scheduleModel the schedule model
   * @return the response
   */
  @RequestMapping(value = "upload", method = RequestMethod.POST)
  public ScheduleModel upload(ScheduleModel scheduleModel, HttpServletRequest request) {
    ScheduleResponse response = new ScheduleResponse();

    ScheduleRequest scheduleRequest = new ScheduleRequest();

    try {

      addUserContextToRequest(scheduleRequest);

      if (!ValidationUtil.isNull(scheduleModel.getImportBy())) {
        if (scheduleModel.getImportBy().equals(DEVICE_ID)) {
          scheduleRequest.setIdFileType(PropertyEnum.DEVICE_ID);
        } else if (scheduleModel.getImportBy().equals(NETWORD_ADDRESS)) {
          scheduleRequest.setIdFileType(PropertyEnum.NETWORK_ADDRESS);
        }
      }

      if (!ValidationUtil.isNull(scheduleModel.getUpload())) {
        File f = new File(FILE_NAME);
        scheduleModel.getUpload().transferTo(f);
        scheduleRequest.setIdsFile(f);
      } else if (!ValidationUtil.isNullOrEmpty(scheduleModel.getMeterList())) {
        scheduleRequest.setUploadIds(scheduleModel.getMeterList());
      }

      if (!ValidationUtil.isNull(scheduleModel.getbMonitored())) {
        scheduleRequest.setIsMonitored(scheduleModel.getbMonitored());
      }

      if (ValidationUtil.isNull(scheduleModel.getScheduledEventId())) {
        scheduleRequest.setSchedule(validationInsertSchedule(INSERT, scheduleModel));
        response = getScheduleBCF().insertSchedule(scheduleRequest);

        if (response.isOperationSuccess()) {
          scheduleModel.setMessageSuccess(INSERT);
        }
      } else {
        scheduleRequest.setSchedule(validationInsertSchedule(UPDATE, scheduleModel));
        response = getScheduleBCF().updateSchedule(scheduleRequest);

        if (response.isOperationSuccess()) {
          scheduleModel.setMessageSuccess(UPDATE);
        }
      }

      if (response.isOperationSuccess()) {
        scheduleModel.setUploadFileProcess(scheduleRequest.getFileName());
        scheduleModel.setActionId(response.getSchedules().get(0).getDmAction().getId().toString());
        scheduleModel.setScheduledEventName(scheduleRequest.getSchedule().getName());
        scheduleModel.setProcessId(scheduleRequest.getProcessId());
      } else {
        for (Message msg : response.getMessageList()) {
          scheduleModel.setMessageError(msg.getText());
        }
      }
    } catch (Exception e) {
      SensusInterfaceUtil.handleException(
          LOG, response, e, DEFAULT_EXCEPTION_MSG, new String[] {CONTROLLER_EXCEPTION_MSG});
    }

    return scheduleModel;
  }