Java Code Examples for org.apache.commons.collections.MapUtils#getObject()

The following examples show how to use org.apache.commons.collections.MapUtils#getObject() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: AlertConfigStrategy.java    From cachecloud with Apache License 2.0 6 votes vote down vote up
/**
 * 获取全量统计项中的内容
 * @param redisInfo
 * @param attribute
 * @return
 */
protected static Object getValueFromRedisInfo(StandardStats standardStats, String attribute) {
    if (standardStats == null) {
        return null;
    }
    // 转换成Map
    Map<String, Object> infoMap = JsonUtil.fromJson(standardStats.getInfoJson(), Map.class);
    if (MapUtils.isEmpty(infoMap)) {
        return null;
    }
    for (Entry<String, Object> entry : infoMap.entrySet()) {
        Object object = entry.getValue();
        // 转换成Map<String, Map<String,Object>>
        if (!(object instanceof Map)) {
            continue;
        }
        Map<String, Object> sectionInfoMap = (Map<String, Object>) object;
        if (sectionInfoMap != null && sectionInfoMap.containsKey(attribute)) {
            return MapUtils.getObject(sectionInfoMap, attribute);
        }
    }
    return null;
}
 
Example 2
Source File: SolrUtil.java    From ambari-logsearch with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("unchecked")
private static boolean checkTokenizer(Class<? extends TokenizerFactory> tokenizerFactoryClass, Map<String, Object> fieldTypeInfoMap) {
  HashMap<String, Object> analyzer = (HashMap<String, Object>) fieldTypeInfoMap.get("analyzer");
  HashMap<String, Object> tokenizerMap = (HashMap<String, Object>)MapUtils.getObject(analyzer, "tokenizer");
  if (tokenizerMap != null) {
    String tokenizerClass = (String) tokenizerMap.get("class");
    if (StringUtils.isNotEmpty(tokenizerClass)) {
      tokenizerClass = tokenizerClass.replace("solr.", "");
      return tokenizerClass.equalsIgnoreCase(tokenizerFactoryClass.getSimpleName());
    }
  }
  
  return false;
}
 
Example 3
Source File: AlertConfigStrategy.java    From cachecloud with Apache License 2.0 5 votes vote down vote up
/**
 * 获取差值统计项中的内容
 * @param redisInfo
 * @param attribute
 * @return
 */
protected static Object getValueFromDiffInfo(StandardStats standardStats, String attribute) {
    if (standardStats == null) {
        return null;
    }
    Map<String, Object> diffInfoMap = JsonUtil.fromJson(standardStats.getDiffJson(), Map.class);
    if (MapUtils.isEmpty(diffInfoMap)) {
        return null;
    }
    return MapUtils.getObject(diffInfoMap, attribute);
}
 
Example 4
Source File: AlertConfigStrategy.java    From cachecloud with Apache License 2.0 5 votes vote down vote up
/**
 * 获取cluster info统计项中的内容
 * @param redisInfo
 * @param attribute
 * @return
 */
protected static Object getValueFromClusterInfo(StandardStats standardStats, String attribute) {
    if (standardStats == null) {
        return null;
    }
    Map<String, Object> clusterInfoMap = JsonUtil.fromJson(standardStats.getClusterInfoJson(), Map.class);
    if (MapUtils.isEmpty(clusterInfoMap)) {
        return null;
    }
    return MapUtils.getObject(clusterInfoMap, attribute);
}
 
Example 5
Source File: ScheduleReliableController.java    From reliable with Apache License 2.0 4 votes vote down vote up
@RequestMapping(value = "/tryToFinish", method = RequestMethod.GET)
public boolean tryToFinish() {

    Date createAt = new Date(System.currentTimeMillis() - checkStatusDuration);

    CriteriaBuilder.ResultMappedBuilder builder = CriteriaBuilder.buildResultMapped(ReliableMessage.class);
    builder.resultKey("id").resultKey("svcDone").resultKey("svcList").resultKey("retryCount").resultKey("retryMax").resultKey("tcc").resultKey("body");
    builder.and().eq("status", MessageStatus.SEND);
    builder.and().lt("createAt", createAt);

    Criteria.ResultMappedCriteria resultMappedCriteria = builder.get();

    List<Map<String, Object>> list = this.reliableMessageService.listByResultMap(resultMappedCriteria);

    if (list.isEmpty())
        return true;

    Date date = new Date();

    for (Map<String, Object> map : list) {

        List<String> svcList = (List<String>)MapUtils.getObject(map, "svcList");
        String tcc = MapUtils.getString(map, "tcc");
        Object bodyObj = MapUtils.getObject(map, "body");
        GenericObject go = (GenericObject) bodyObj;

        ReliableMessage reliableMessage = new ReliableMessage();
        reliableMessage.setId(MapUtils.getString(map, "id"));
        reliableMessage.setSvcDone(MapUtils.getString(map, "svcDone"));
        reliableMessage.setSvcList(svcList);
        reliableMessage.setBody(go);
        reliableMessage.setTcc(tcc);
        reliableMessage.setRetryCount(MapUtils.getLongValue(map, "retryCount"));
        reliableMessage.setRetryMax(MapUtils.getIntValue(map, "retryMax"));

        String svcDone = reliableMessage.getSvcDone();
        if (StringUtil.isNullOrEmpty(svcDone))
            continue;

        boolean flag = true;

        for (String svc : svcList) {
            flag &= svcDone.contains(svc);
        }


        if (reliableMessage.getTcc().equals(TCCTopic._TCC_TRY.name())) {
            if (!flag) {
                if (reliableMessage.getRetryCount() >= reliableMessage.getRetryMax()) {
                    cancel(reliableMessage.getId());
                }
            }
        } else {
            if (flag) {
                RefreshCondition<ReliableMessage> reliableMessageRefreshCondition = new RefreshCondition<>();
                reliableMessageRefreshCondition.refresh("status", MessageStatus.OK);
                reliableMessageRefreshCondition.refresh("refreshAt", date);
                reliableMessageRefreshCondition.and().eq("id", reliableMessage.getId());
                this.reliableMessageService.refresh(reliableMessageRefreshCondition);

                try {
                    this.nextBusiness.produce(reliableMessage.getId(),reliableMessageService,producer);
                }catch (Exception e) {

                }
            }
        }

    }

    return true;
}
 
Example 6
Source File: ScheduleReliableController.java    From reliable with Apache License 2.0 4 votes vote down vote up
@RequestMapping(value = "/listForRetry", method = RequestMethod.GET)
    public List<ReliableMessage> listForRetry() {

        long rrd = reliableRetryDuration < 5000 ? 5000 : reliableRetryDuration;

        long now = System.currentTimeMillis();
        final long sendAt = now - rrd;

        CriteriaBuilder.ResultMappedBuilder builder = CriteriaBuilder.buildResultMapped(ReliableMessage.class);
        builder.resultKey("id").resultKey("svcList").resultKey("svcDone").resultKey("retryCount").resultKey("retryMax").resultKey("tcc").resultKey("topic").resultKey("body");
        builder.and().eq("status", MessageStatus.SEND);
//        builder.and().x("retryCount < retryMax"); //需要人工补单
        builder.and().lt("sendAt", sendAt);

        Criteria.ResultMappedCriteria resultMappedCriteria = builder.get();

        List<Map<String, Object>> list = this.reliableMessageService.listByResultMap(resultMappedCriteria);

        List<ReliableMessage> rmList = new ArrayList<>();

        if (list.isEmpty())
            return rmList;

        for (Map<String, Object> map : list) {

            Object bodyObj = MapUtils.getObject(map, "body");
            GenericObject go = (GenericObject) bodyObj;

            List<String> svcList = (List<String>) MapUtils.getObject(map, "svcList");

            ReliableMessage reliableMessage = new ReliableMessage();
            reliableMessage.setId(MapUtils.getString(map, "id"));
            reliableMessage.setTopic(MapUtils.getString(map, "topic"));
            reliableMessage.setSvcList(svcList);
            reliableMessage.setSvcDone(MapUtils.getString(map, "svcDone"));
            reliableMessage.setRetryCount(MapUtils.getLongValue(map, "retryCount"));
            reliableMessage.setRetryMax(MapUtils.getIntValue(map, "retryMax"));
            reliableMessage.setBody(go);
            reliableMessage.setTcc(MapUtils.getString(map, "tcc"));
            reliableMessage.setSendAt(sendAt);

            rmList.add(reliableMessage);
        }

        return rmList;
    }
 
Example 7
Source File: AbstractUploader.java    From bird-java with MIT License 4 votes vote down vote up
/**
 * 文件上传
 *
 * @param context
 * @return
 */
protected UploadResult upload(IUploadContext context) throws IOException {
    if (storage == null) {
        throw new UploadException("IFileStorage组件为空,不能存储文件");
    }
    boolean listenerEnable = uploadListener != null;

    //TODO:请求验证

    for (MultipartFile file : context.getFileMap().values()) {

        //文件验证
        if (validator != null) {
            if (listenerEnable) uploadListener.beforeValidate(file, context);
            ValidateResult validateResult = validator.validate(file);
            if (validateResult != null && !validateResult.isSuccess()) {
                return UploadResult.fail(validateResult.getErrorInfo());
            }
            if (listenerEnable) uploadListener.afterValidate(file, context, validateResult);
        }

        //文件处理
        String suffix = FileHelper.getSuffix(file.getOriginalFilename());
        Object handlers = MapUtils.getObject(fileHandlerMap, suffix);
        byte[] bytes = file.getBytes();
        if (handlers != null) {
            if (listenerEnable) uploadListener.beforeHandle(file, context);
            for (IFileHandler handler : (List<IFileHandler>) handlers) {
                bytes = handler.handle(bytes);
            }
            if (listenerEnable) uploadListener.afterHandle(file, context);
        }

        //文件存储
        if (listenerEnable) uploadListener.beforeStorage(file, context);
        String url = storage.save(file, bytes, context);
        UploadResult result = UploadResult.success(url);
        if (listenerEnable) uploadListener.afterStorage(file, context, result);
        return result;
    }

    return null;
}
 
Example 8
Source File: ConsumerClusters.java    From AvatarMQ with Apache License 2.0 4 votes vote down vote up
public RemoteChannelData findRemoteChannelData(String clientId) {
    return (RemoteChannelData) MapUtils.getObject(channelMap, clientId);
}
 
Example 9
Source File: MaintainableImpl.java    From rice with Educational Community License v2.0 3 votes vote down vote up
/**
 * Returns whether a line that contains a field is restricted; that is, if the field is part of a group and that
 * group has some unauthorized binding information.
 *
 * @param field field being checked for restrictions
 *
 * @return true if the field is in a line with restrictions, false otherwise
 */
private boolean isLineRestricted(DataField field) {
    CollectionGroup group = (CollectionGroup) MapUtils.getObject(field.getContext(),
            UifConstants.ContextVariableNames.COLLECTION_GROUP);

    return group != null && CollectionUtils.isNotEmpty(group.getUnauthorizedLineBindingInfos());
}