@Override
  public void deleteRole(ServiceContext context, Role role) throws JServiceException {
    if (JStringUtils.isNullOrEmpty(role.getId())) {
      throw new IllegalArgumentException("the primary property id of role is null.");
    }

    if (JStringUtils.isNullOrEmpty(role.getRoleCode())) {
      role.setRoleCode(getById(context, role.getId()).getRoleCode());
    }
    validateRoleCode(role);
    delete(context, role.getId());
  }
 @Override
 public void saveWeight(ServiceContext context, Weight weight) throws JServiceException {
   if (JStringUtils.isNullOrEmpty(weight.getUserName())) {
     // DEFAULT TO LOGIN USER
     weight.setUserName(context.getUser().getUserName());
   }
   if (weight.getRecordTime() == null) {
     weight.setRecordTime(new Timestamp(new Date().getTime()));
   }
   saveOnly(context, weight);
 }
Beispiel #3
0
 public String getWeightsWithsCondition() {
   String latestMonth = getParameter("lastetMonth");
   Calendar calendar = Calendar.getInstance();
   calendar.add(
       Calendar.MONTH,
       -1 * Integer.valueOf(JStringUtils.isNullOrEmpty(latestMonth) ? "1" : latestMonth));
   WeightSearchCriteria weight = new WeightSearchCriteria();
   weight.setRecordTime(new Timestamp(calendar.getTime().getTime()));
   weight.setUserName(getSessionUser().getUserName());
   List<Weight> weights = weightService.getWeightsByPage(getServiceContext(), weight);
   setAttribute("weights", weights);
   return "/WEB-INF/jsp/weight/view-all-weight.jsp";
 }
  @Override
  public void updateRole(ServiceContext context, Role role) throws JServiceException {

    validateRoleCode(role);

    if (JStringUtils.isNullOrEmpty(role.getId())) {
      throw new IllegalArgumentException("the primary property id of role is null.");
    }

    if (exists(context, role)) {
      throw new JServiceException("role code [" + role.getRoleCode() + "] already has exist.");
    }
    updateOnly(context, role);
  }
Beispiel #5
0
 /**
  * get field.
  *
  * @param property
  * @param model
  * @return
  */
 public static Field getField(String property, Object model) {
   if (model == null) return null;
   if (JStringUtils.isNullOrEmpty(property)) return null;
   Field field = null;
   Class<?> superClass = model.getClass();
   while (superClass != null) {
     try {
       field = superClass.getDeclaredField(property);
       if (field != null) break;
     } catch (NoSuchFieldException e) {
       superClass = superClass.getSuperclass();
       continue;
     } catch (SecurityException e) {
       throw e;
     }
   }
   return field;
 }
  private void validateRoleCode(Role role) throws JServiceException {

    String code = role.getRoleCode();

    if (JStringUtils.isNullOrEmpty(code)) {
      throw new IllegalArgumentException("role code  is null");
    }

    code = code.trim();

    if (ADMIN_CODE.equalsIgnoreCase(code)) {
      throw new JServiceException(
          "role code [" + ADMIN_CODE + "] is initialized by system.please change...");
    }

    if (DEFAULT_CODE.equalsIgnoreCase(code)) {
      throw new JServiceException(
          "role code [" + DEFAULT_CODE + "] is initialized by system.please change...");
    }
  }
 @Override
 public boolean exists(ServiceContext context, Role role) throws JServiceException {
   if (role == null) {
     throw new IllegalArgumentException("role argument is null");
   }
   boolean exists = false;
   Role dbRole = getRoleByRoleCode(context, role.getRoleCode());
   // new created.
   if (JStringUtils.isNullOrEmpty(role.getId())) {
     exists = dbRole != null;
   } else {
     // updated status.
     if (dbRole != null) {
       // if it's self
       exists = !role.getId().equals(dbRole.getId());
     } else {
       exists = false;
     }
   }
   return exists;
 }
  @Override
  public void contextInitialized(ServletContextEvent sce) {
    try {
      Properties properties = System.getProperties();
      String javaClassPath = (String) properties.get("java.class.path");
      String webLib = sce.getServletContext().getRealPath("/WEB-INF/lib");
      LOGGER.info("WEB LIB PATH : " + webLib);
      File libFile = new File(webLib);
      StringBuffer libStringBuffer = new StringBuffer();
      if (libFile.exists()) {
        File[] files = libFile.listFiles();
        if (files != null) {
          for (int i = 0; i < files.length; i++) {
            File file = files[i];
            libStringBuffer.append(";" + (webLib + "/" + file.getName()));
          }
        }
      }
      LOGGER.info("Jars [WEB-INF/lib] added : " + libStringBuffer.toString());

      String customClassPath = sce.getServletContext().getInitParameter(CUSTOM_CLASSPATH);
      LOGGER.info("Custom CLASSPATH added : " + customClassPath);

      if (JStringUtils.isNullOrEmpty(customClassPath)) {
        customClassPath = "";
      }

      String classes = sce.getServletContext().getRealPath("WEB-INF/classes");
      LOGGER.info("Classes [WEB-INF/classes] added : " + classes);
      System.setProperty(
          "java.class.path",
          javaClassPath + ";" + libStringBuffer.toString() + ";" + classes + ";" + customClassPath);
    } catch (Exception e) {
      LOGGER.error(e.getMessage(), e);
    }
  }
 protected void setSuccessMessage(String message) {
   if (JStringUtils.isNullOrEmpty(message)) {
     message = "操作成功";
   }
   setAttribute("successAlertMessage", message);
 }