예제 #1
0
  @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());
  }
예제 #2
0
 @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);
 }
예제 #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";
 }
예제 #4
0
  @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);
  }
예제 #5
0
 /**
  * for all property whether or not it is boolean type.
  *
  * @param property
  * @return
  */
 public static String setterName(String property) {
   if (JStringUtils.isNotNullOrEmpty(property)) {
     if (property.length() > 1) {
       String second = "" + property.charAt(1);
       if (Pattern.matches("[A-Z]", second)) {
         return "set" + property;
       } else {
         return "set" + property.substring(0, 1).toUpperCase() + property.substring(1);
       }
     } else {
       return "set" + property.toUpperCase();
     }
   }
   return null;
 }
예제 #6
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;
 }
예제 #7
0
  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...");
    }
  }
예제 #8
0
 @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;
 }
예제 #9
0
  @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);
    }
  }
예제 #10
0
 protected void setSuccessMessage(String message) {
   if (JStringUtils.isNullOrEmpty(message)) {
     message = "操作成功";
   }
   setAttribute("successAlertMessage", message);
 }
예제 #11
0
  /**
   * scan all property in the {@param obj} to match the first property name. set {@code valueObject}
   * to target object {@code obj } via the direction of properties link by "." , i.e.
   * "user.userName","user.password".
   *
   * <p>note: any list property in any property not supported.
   *
   * @param obj target object.
   * @param nameLink link by "." , i.e. "user.userName","user.password".
   * @param valueObject value set
   * @throws Exception
   */
  public static void set(Object obj, String nameLink, Object valueObject) throws Exception {

    if (nameLink.indexOf(".") == -1) return; // no need fill in automatically

    String[] names = new String[] {nameLink};
    if (nameLink.indexOf(".") != -1) {
      names = nameLink.split("[.]");
    }
    Object target = obj;
    for (int i = 0; i < names.length; i++) {
      String name = names[i];
      Class<?> superClass = target.getClass();
      Field field = null;
      while (superClass != null && field == null) {
        try {
          field = superClass.getDeclaredField(name);
        } catch (NoSuchFieldException e) {
          superClass = superClass.getSuperclass();
        }
      }

      if (field == null) {
        throw new RuntimeException(
            "[" + name + "] attribute not found in " + target.getClass().getName());
      }

      field.setAccessible(true);
      if (i == names.length - 1) { // the last one .  set value
        if (List.class.isInstance(valueObject)) {
          field.set(target, valueObject);
        } else {
          String value = String.valueOf(valueObject);
          if (field.getType() == String.class) {
            field.set(target, value);
          } else if (field.getType() == Double.class || field.getType() == double.class) {
            field.set(target, JNumberUtils.toDouble(value));
          } else if (field.getType() == Integer.class || field.getType() == int.class) {
            field.set(target, JNumberUtils.toInt(value));
          } else if (field.getType() == Long.class || field.getType() == long.class) {
            field.set(target, JNumberUtils.toLong(value));
          } else if (field.getType() == Timestamp.class) {
            if (JStringUtils.isNotNullOrEmpty(value)) {
              field.set(target, JDateUtils.parseTimestampWithSeconds(value));
            }
          } else if (field.getType() == Date.class) {
            if (JStringUtils.isNotNullOrEmpty(value)) {
              field.set(target, JDateUtils.parseDate(value));
            }
          }
        }
      } else {
        Object attributeObject = field.get(target);
        if (attributeObject == null) {
          Object temp = field.getType().newInstance();
          field.set(target, temp);
          target = temp;
        } else {
          target = attributeObject;
        }
      }
    }
  }