/**
   * [Web Service] User Calendar functionality
   *
   * @param sessionId
   * @param securityKey
   * @param typeId
   * @param saveJobId
   * @param calendarId
   * @param cdcId
   * @param eventTitle
   * @param eventType
   * @param eventDate
   * @param eventTime
   * @param reminderFlag
   * @param freq
   * @param periodVal
   * @param sendEmail
   * @param notes
   * @return
   */
  @RequestMapping(value = "/calendar")
  public String wsUserCalendar(
      @RequestParam("sessionId") int sessionId,
      @RequestParam("securityKey") String securityKey,
      @RequestParam("typeId") int typeId,
      @RequestParam("saveJobId") int saveJobId,
      @RequestParam("calendarId") int calendarId,
      @RequestParam("cdcId") String cdcId,
      @RequestParam("eventTitle") String eventTitle,
      @RequestParam("eventType") String eventType,
      @RequestParam("eventDate") String eventDate,
      @RequestParam("eventTime") String eventTime,
      @RequestParam("reminderFlag") String reminderFlag,
      @RequestParam("freq") String freq,
      @RequestParam("periodVal") String periodVal,
      @RequestParam("sendEmail") String sendEmail,
      @RequestParam("notes") String notes) {

    Map<String, Object> map = null;
    Gson gson = null;
    LeadManagerSessionData lmData = null;
    Connection con = null;

    try {

      gson = new Gson();
      map = new HashMap<String, Object>();
      boolean validSessionId = false;
      boolean dbFlag = false;

      if (con == null) con = JDBCUtil.getDBConnectionFromDatabase();

      validSessionId = LoginUtil.checkValidSession(sessionId, securityKey, con);

      if (validSessionId == true) {

        /**
         * 1 - getCalendar events 2 - InsertCalender event 3 - updated calendar event 4 - deleted
         * calendar event
         */
        lmData = LoginUtil.getLeadManagerSessionDetails(sessionId, con);
        if (typeId == 1) {
          ArrayList calList = getUserCalendarInfo(calendarId, con);
          map.put("iTotalRecords", String.valueOf(calList.size()));
          map.put("aaData", calList);

          log(
              "loginID: "
                  + lmData.getLogin()
                  + ": Type : "
                  + typeId
                  + " : iTotalRecords : "
                  + calList.size());
        } else if (typeId == 2) {
          dbFlag =
              insertUserCalendarEvent(
                  lmData.getLogin(),
                  saveJobId,
                  cdcId,
                  eventTitle,
                  eventType,
                  eventDate,
                  eventTime,
                  reminderFlag,
                  freq,
                  periodVal,
                  sendEmail,
                  notes,
                  con);

          map.put("CalendarInsertedFlag", "" + dbFlag);

          log("loginID: " + lmData.getLogin() + ": Type : " + typeId + " : dbFlag : " + dbFlag);
        } else if (typeId == 3) {
          dbFlag =
              updateUserCalendarEvent(
                  calendarId,
                  eventTitle,
                  eventType,
                  eventDate,
                  eventTime,
                  reminderFlag,
                  freq,
                  periodVal,
                  sendEmail,
                  notes,
                  con);
          map.put("CalendarUpdatedFlag", "" + dbFlag);
          log("loginID: " + lmData.getLogin() + ": Type : " + typeId + " : dbFlag : " + dbFlag);
        } else if (typeId == 4) {
          dbFlag = deleteUserCalendarEvent(calendarId, con);
          map.put("CalendarDeletedFlag", "" + dbFlag);
          log("loginID: " + lmData.getLogin() + ": Type : " + typeId + " : dbFlag : " + dbFlag);
        }
      } else {
        map.put("iTotalRecords", "0");
        map.put("aaData", "");
        map.put("message", "Invalid Login");
      }

    } catch (Exception ex) {
      ex.printStackTrace();
      log("Exception in wsUserCalendar() " + ex);
    } finally {
      JDBCUtil.releaseDBConnection(con);
    }
    return gson.toJson(map);
  }
  /**
   * /online-product/quick-search/search-results
   *
   * @param sessionId
   * @param securityKey
   * @param stateIds
   * @param sectionIdList
   * @param newUpdatedFlag
   * @param subSectionList
   * @param constructionTypes
   * @param divisionIdList
   * @param showAll
   * @param displayMode
   * @return
   */
  @RequestMapping(value = "/quickSearchResults")
  public String getContentDetails(
      @RequestParam("sessionId") int sessionId,
      @RequestParam("securityKey") String securityKey,
      @RequestParam("stateIds") String stateIds,
      @RequestParam("sectionIdList") String sectionIdList,
      @RequestParam("newUpdatedFlag") int newUpdatedFlag,
      @RequestParam("subSectionList") String subSectionList,
      @RequestParam("constructionTypes") String constructionTypes,
      @RequestParam("divisionIdList") String divisionIdList,
      @RequestParam("showAll") int showAll,
      @RequestParam("displayMode") String displayMode) {

    Map<String, Object> map = null;
    Gson gson = null;

    Connection con = null;
    String contentIds = null;

    try {
      gson = new Gson();
      map = new HashMap<String, Object>();

      if (con == null) con = JDBCUtil.getDBConnectionFromDatabase();

      boolean validSessionId = false;
      validSessionId = LoginUtil.checkValidSession(sessionId, securityKey, con);

      log.info(validSessionId);
      if (validSessionId == true) {

        /*
         * map.put("iTotalRecords", "1"); map.put("Status", "Success"); map.put("Message", "");
         */
        contentIds =
            getQuickSearchContentIds(
                sessionId,
                securityKey,
                stateIds,
                sectionIdList,
                newUpdatedFlag,
                subSectionList,
                constructionTypes,
                divisionIdList,
                showAll,
                displayMode,
                con);

        log.info("QUICK SEARCH CONTENT IDS: " + contentIds);

        map.put("aaData", LoginUtil.getBriefProjectDetails(contentIds, sessionId, con));

        // ArrayList projectDetailsTitles = new ArrayList();
        // projectDetailsTitles.add("sTitle");
        // map.put("aoColumns",projectDetailsTitles);

      } else {
        map.put("iTotalRecords", "0");
        map.put("Status", "Failure");
        map.put("Message", "Invalid Session or Session Expired");
      }

    } catch (Exception ex) {
      log.error("Exception in getContentDetails() for quick search " + ex.getMessage());
      ex.printStackTrace();
    } finally {
      JDBCUtil.releaseDBConnection(con);
    }

    return gson.toJson(map);
  }