static {
    // 获取所有的bean类与bean实例之间的映射关系(简称Bean Map)
    Map<Class<?>, Object> beanMap = BeanHelper.getBeanMap();
    if (MapUtils.isNotEmpty(beanMap)) {
      // 遍历 bean map
      for (Map.Entry<Class<?>, Object> beanEntry : beanMap.entrySet()) {
        // 从bean map中获取bean类和bean实例
        Class<?> beanClass = beanEntry.getKey();
        Object beanInstance = beanEntry.getValue();

        // 获取bean定义的所有成员变量
        Field[] beanFields = beanClass.getDeclaredFields();
        if (ArrayUtils.isNotEmpty(beanFields)) {
          // 遍历 bean field
          for (Field beanField : beanFields) {
            // 判断当前bean field是否带有Inject注解
            if (beanField.isAnnotationPresent(Inject.class)) {
              // 在bean map中获取bean field对应的实例
              Class<?> beanFieldClass = beanField.getType();
              Object beanFieldInstance = beanMap.get(beanFieldClass);
              if (null != beanFieldInstance) {
                // 通过反射初始化bean field的值
                ReflectionUtil.setField(beanInstance, beanField, beanFieldInstance);
              }
            }
          }
        }
      }
    }
  }
  @Override
  public boolean preHandle(
      HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, Object o)
      throws Exception {
    HttpSession session = httpServletRequest.getSession();
    User user = (User) session.getAttribute("user");
    if (user == null || user.getStatus() != UserConstant.Status.ACTIVE.value()) {
      return false;
    }

    Map<Privilege, Integer> map = PrivilegeHelper.getPrivilegeMap();

    Privilege privilege =
        new Privilege(
            httpServletRequest
                .getRequestURI()
                .substring(httpServletRequest.getContextPath().length()),
            httpServletRequest.getMethod());
    System.out.println("privilege = " + privilege);

    if (CollectionUtils.isEmpty(user.getPrivilegeIds())) {
      httpServletResponse.sendRedirect(httpServletRequest.getContextPath() + "/error/low.html");
      return false;
    }

    if (MapUtils.isNotEmpty(map)
        && map.containsKey(privilege)
        && !user.getPrivilegeIds().contains(map.get(privilege))) {
      httpServletResponse.sendRedirect(httpServletRequest.getContextPath() + "/error/low.html");
      return false;
    }

    return true;
  }
Exemple #3
0
  /**
   * Get user rating for a given guid or geocode. For a guid first the ratings cache is checked
   * before a request to gcvote.com is made.
   *
   * @param guid
   * @param geocode
   * @return
   */
  public static GCVoteRating getRating(final String guid, final String geocode) {
    if (StringUtils.isNotBlank(guid) && RATINGS_CACHE.containsKey(guid)) {
      return RATINGS_CACHE.get(guid);
    }

    final Map<String, GCVoteRating> ratings =
        getRating(singletonOrNull(guid), singletonOrNull(geocode));
    return MapUtils.isNotEmpty(ratings) ? ratings.values().iterator().next() : null;
  }
 /** TODO: should be removed ! */
 @Deprecated
 public static String getDefaultValueFromPropertyDefinitions(
     String propertyName, Map<String, PropertyDefinition> propertyDefinitions) {
   if (MapUtils.isNotEmpty(propertyDefinitions) && propertyDefinitions.containsKey(propertyName)) {
     return propertyDefinitions.get(propertyName).getDefault().toString();
   } else {
     return null;
   }
 }
Exemple #5
0
  /**
   * 获取请求参数 映射
   *
   * @return
   */
  public Map<String, Object> getFieldMap() {

    Map<String, Object> fieldMap = new HashMap<String, Object>(0);
    if (MapUtils.isNotEmpty(fieldMap)) {
      for (FormParam formParam : formParamList) {
        String fieldName = formParam.getFieldName();
        Object fieldValue = formParam.getFieldValue();
        if (fieldMap.containsKey(fieldName)) {
          fieldValue = fieldMap.get(fieldName) + StringUtil.SEPARATOR + fieldValue;
        }
        fieldMap.put(fieldName, fieldValue);
      }
    }
    return fieldMap;
  }
 /**
  * Builds the definitions MarkupDocument.
  *
  * @return the definitions MarkupDocument
  */
 @Override
 public MarkupDocument build() {
   if (MapUtils.isNotEmpty(globalContext.getSwagger().getDefinitions())) {
     applyDefinitionsDocumentExtension(
         new Context(Position.DOCUMENT_BEFORE, this.markupDocBuilder));
     buildDefinitionsTitle(DEFINITIONS);
     applyDefinitionsDocumentExtension(
         new Context(Position.DOCUMENT_BEGIN, this.markupDocBuilder));
     buildDefinitionsSection();
     applyDefinitionsDocumentExtension(new Context(Position.DOCUMENT_END, this.markupDocBuilder));
     applyDefinitionsDocumentExtension(
         new Context(Position.DOCUMENT_AFTER, this.markupDocBuilder));
   }
   return new MarkupDocument(markupDocBuilder);
 }
 /**
  * Merge from map into 'into' map
  *
  * @param from from map
  * @param into into map
  * @param keysToConsider if defined only keys contained by this set are considered
  */
 public static void mergeProperties(
     Map<String, AbstractPropertyValue> from,
     Map<String, AbstractPropertyValue> into,
     Set<String> keysToConsider) {
   if (MapUtils.isNotEmpty(from)) {
     for (Map.Entry<String, AbstractPropertyValue> fromEntry : from.entrySet()) {
       if (keysToConsider != null && !keysToConsider.contains(fromEntry.getKey())) {
         // If the key filter do not contain the key then do not consider
         continue;
       }
       AbstractPropertyValue existingValue = into.get(fromEntry.getKey());
       if (fromEntry.getValue() != null || existingValue == null) {
         into.put(fromEntry.getKey(), fromEntry.getValue());
       }
     }
   }
 }
Exemple #8
0
  /**
   * 获取 上传文件 映射
   *
   * @return
   */
  public Map<String, List<FileParam>> getFileMap() {

    Map<String, List<FileParam>> fileMap = new HashMap<String, List<FileParam>>(0);
    if (MapUtils.isNotEmpty(fileMap)) {
      for (FileParam fileParam : fileParamList) {
        String fieldName = fileParam.getFieldName();
        List<FileParam> fileParams;
        if (fileMap.containsKey(fieldName)) {
          fileParams = fileMap.get(fieldName);
        } else {
          fileParams = new ArrayList<FileParam>(0);
        }
        fileParams.add(fileParam);
        fileMap.put(fieldName, fileParams);
      }
    }
    return fileMap;
  }
 @Test
 public void isNotEmpty() {
   assertFalse(MapUtils.isNotEmpty(new HashMap<>()));
 }