Ejemplo n.º 1
0
  /**
   * This method is used to check a sub category is in active
   *
   * @param subCategoryVOobj - details about sub category
   * @throws DeleteSubCategoryDeclinedException - throws if the sub category is in used.
   * @throws ApplicationException - wrap exception in application object of exception framework
   */
  private void checkDeleteAllowed(SubCategoryVO subCategoryVOobj)
      throws DeleteSubCategoryDeclinedException, ApplicationException {

    Connection conn = null;
    PreparedStatement preStat1 = null;
    ResultSet rs1 = null;

    try {
      conn = DBConnection.getDBConnection();
      /* select all teh active sub-sub-category for given sub-category */
      String sqlQuery1 = "select * from CRM_SUB_SUB_CATEGORY where PARENT_ID= ? AND STATUS=?";
      if (conn != null) {
        preStat1 = conn.prepareStatement(sqlQuery1);
        preStat1.setInt(1, subCategoryVOobj.getSubCategoryId());
        preStat1.setString(2, "1");
      }
      rs1 = preStat1.executeQuery();
      if (rs1.next()) {
        throw new DeleteSubCategoryDeclinedException(
            "Sub-Category can not be deleted", "subcategory.delete.exception");
      }
    } catch (SQLException sqlExcep) {
      logger.error(AdminConstantsImpl.LOGGER_EXCEPTION_MESSAGE + sqlExcep);
      throw new ApplicationException(AdminConstantsImpl.APPLICATION_SQL_EXCEPTION, sqlExcep);
    } catch (DeleteSubCategoryDeclinedException e) {
      logger.error(AdminConstantsImpl.LOGGER_EXCEPTION_MESSAGE + e);
      throw new DeleteSubCategoryDeclinedException(e.getBusinessReason(), e.getBusinessCode());
    } catch (Exception e) {
      logger.error(AdminConstantsImpl.LOGGER_EXCEPTION_MESSAGE + e);
      throw new ApplicationException(AdminConstantsImpl.APPLICATION_CONNECTION_EXCEPTION, e);
    } finally {
      try {
        if (conn != null) {
          conn.close();
        }

        if (rs1 != null) {
          rs1.close();
        }

        if (preStat1 != null) {
          preStat1.close();
        }
      } catch (SQLException sqlExcep) {
        logger.error(AdminConstantsImpl.LOGGER_EXCEPTION_MESSAGE + sqlExcep);
        throw new ApplicationException(AdminConstantsImpl.APPLICATION_SQL_EXCEPTION, sqlExcep);
      }
    }
  }
Ejemplo n.º 2
0
  /**
   * This method is used to edit a sub problem type (sub-category)
   *
   * @param SubCategoryVO - information about sub category to be edited.
   * @return boolean - true if the edit is success else false
   * @throws BusinessException - wrap exception in business object of exception framework
   * @throws ApplicationException - wrap exception in application object of exception framework
   */
  public boolean editSubCategory(SubCategoryVO subCategoryVOobj)
      throws BusinessException, ApplicationException {

    boolean result = false;

    Date todaysDate = (new Date());
    java.sql.Date sqlDate = new java.sql.Date(todaysDate.getTime());

    String status = subCategoryVOobj.getStatus();
    int catStatus = AdminConstantsImpl.ADMIN_SUBCATEGORY_STATUS_INACTIVE;
    if (status.equals("Active")) {
      catStatus = AdminConstantsImpl.ADMIN_SUBCATEGORY_STATUS_ACTIVE;
    }
    /* if the user tries to inactivate a sub-category, check some condition */
    if (catStatus == AdminConstantsImpl.ADMIN_SUBCATEGORY_STATUS_INACTIVE) {
      checkDeleteAllowed(subCategoryVOobj);
    }

    Connection conn1 = null;
    PreparedStatement preStat = null;
    ResultSet resultSet = null;

    try {
      conn1 = DBConnection.getDBConnection();
      String sqlQuery =
          "update CRM_SUB_CATEGORY SET(STATUS, MODIFIED_BY, MODIFIED_DATE, SUB_CATEGORY_DESCRIPTION) = (?,?,?,?) where SUB_CATEGORY_ID = ?";

      if (conn1 != null) {
        preStat = conn1.prepareStatement(sqlQuery);

        preStat.setInt(1, catStatus);
        preStat.setString(2, subCategoryVOobj.getUserName());
        preStat.setDate(3, sqlDate);
        preStat.setString(4, subCategoryVOobj.getDescription());
        preStat.setInt(5, subCategoryVOobj.getSubCategoryId());
        int rowUpdated = preStat.executeUpdate();
        if (rowUpdated == 1) {
          result = true;
        } else {
          logger.info("Sub-Category not modified");
        }
      } else {
        logger.info("Connection is null ");
      }
      conn1.close();
      UtilityCache.populateSubCategoryCache();
      UtilityCache.populateRetailerSubCategoryCache();
    } catch (SQLException sql) {
      logger.error(AdminConstantsImpl.LOGGER_EXCEPTION_MESSAGE + sql);
      throw new ApplicationException(AdminConstantsImpl.APPLICATION_SQL_EXCEPTION, sql);
    } catch (Exception e) {
      logger.error(AdminConstantsImpl.LOGGER_EXCEPTION_MESSAGE + e);
      throw new ApplicationException(AdminConstantsImpl.APPLICATION_CONNECTION_EXCEPTION, e);
    } finally {
      try {
        if (conn1 != null) {
          conn1.close();
        }

        if (resultSet != null) {
          resultSet.close();
        }

        if (preStat != null) {
          preStat.close();
        }
      } catch (SQLException sqlExcep) {
        logger.error(AdminConstantsImpl.LOGGER_EXCEPTION_MESSAGE + sqlExcep);
        throw new ApplicationException(AdminConstantsImpl.APPLICATION_SQL_EXCEPTION, sqlExcep);
      }
    }

    return result;
  }