protected String normalize(String part) {
    if (part == null) {
      throw new IllegalStateException("Resource name part must not be null!");
    }
    LOGGER.debug("Normalizing resource name part: {}", part);
    String normalized = part == null ? "null" : part;

    normalized = StringUtils.trimAllWhitespace(normalized);
    LOGGER.debug("Trimmed whitespaces: {}", part);

    normalized = normalized.replaceAll("[^a-zA-Z0-9]", "");
    LOGGER.debug("Trimmed invalid characters: {}", part);

    normalized = normalized.toLowerCase();
    LOGGER.debug("Lower case: {}", part);

    return normalized;
  }
  public Map<String, Object> routeSearch(Map<String, Object> params) {
    if (isFreness(params)) {
      ArgCheckUtils.validataRequiredArgs("toDest", "page", params);
    } else {
      ArgCheckUtils.validataRequiredArgs("fromDest", "toDest", "page", params);
    }
    Map<String, Object> resultMap = new HashMap<String, Object>();

    ClientRouteSearchVO searchVo = new ClientRouteSearchVO();
    searchVo.setChannel(Constant.CHANNEL.CLIENT.name());
    List<String> productTypes = new ArrayList<String>();
    productTypes.add(Constant.PRODUCT_TYPE.ROUTE.name());
    searchVo.setProductType(productTypes);

    if (params.get("pageSize") != null) {
      searchVo.setPageSize(Integer.parseInt(params.get("pageSize").toString()));
    }

    if (params.get("subject") != null) {
      searchVo.setSubject(params.get("subject").toString());
    }

    if (params.get("palceId") != null) {
      searchVo.setPlaceId(params.get("palceId").toString());
    }

    searchVo.setPage(Integer.valueOf(params.get("page").toString()));

    if (params.get("searchType") != null) {
      if (params.get("subProductType") != null && !"".equals(params.get("subProductType"))) {
        String searchType = params.get("searchType").toString();
        if (this.isNotOverSeaTravel(searchType)) {
          if (params.get("fromDest") != null) {
            String fromDest = params.get("fromDest").toString();
            if (fromDest.contains(",")) {
              fromDest = fromDest.substring(0, fromDest.lastIndexOf(","));
              params.put("fromDest", fromDest);
            }
          }
        }
      }
    }

    if (params.get("subProductType") != null) {
      if (this.isFreness(params)) {
        params.put("fromDest", null);
      }
      searchVo.setSubProductType(ClientUtils.convetToList(params.get("subProductType").toString()));
    } else {
      searchVo.setSubProductType(new ArrayList<String>());
    }

    if (params.get("fromDest") != null) {
      searchVo.setFromDest(params.get("fromDest").toString());
    }

    if (params.get("toDest") != null) {
      searchVo.setToDest(StringUtil.subStringStrNoSuffix(params.get("toDest").toString(), 60));
    }

    if (params.get("sort") != null) {
      searchVo.setSort(params.get("sort").toString());
    }
    if (params.get("day") != null) {
      searchVo.setVisitDay(params.get("day").toString());
    }

    if (params.get("keyword") != null) {
      searchVo.setKeyword(StringUtil.subStringStrNoSuffix(params.get("keyword").toString(), 60));
    }

    Page<ProductBean> pageConfig = vstClientProductService.routeSearch(searchVo);
    List<MobileProductTitle> mpList = new ArrayList<MobileProductTitle>();
    Map<String, String> visitMap = new HashMap<String, String>();

    for (ProductBean productBean : pageConfig.getAllItems()) {
      if (!StringUtil.isEmptyString(productBean.getRouteTopic())) {
        String[] topics = productBean.getRouteTopic().split(",");
        for (String string : topics) {
          String str = StringUtils.trimAllWhitespace(string);
          visitMap.put(str, str);
        }
      }
    }

    List<Map<String, Object>> topicList = new ArrayList<Map<String, Object>>();
    Iterator<Entry<String, String>> it = visitMap.entrySet().iterator();

    // subjectList列表
    Map<String, Object> t_m = new HashMap<String, Object>();
    t_m.put("title", "全部主题");
    t_m.put("value", "");
    topicList.add(t_m);
    while (it.hasNext()) {
      Map<String, Object> m = new HashMap<String, Object>();
      Map.Entry<String, String> entry = (Map.Entry<String, String>) it.next();
      String key = entry.getKey();
      m.put("title", key);
      m.put("value", key);
      topicList.add(m);
    }

    for (ProductBean productBean : pageConfig.getItems()) {
      // 过滤掉超级自由行
      if ("true".equals(productBean.getSelfPack())) {
        continue;
      }
      MobileProductTitle mp = new MobileProductTitle();
      mp.setProductName(productBean.getProductName());
      mp.setMarketPriceYuan(productBean.getMarketPrice());
      mp.setSmallImage(productBean.getSmallImage());
      mp.setSellPriceYuan(productBean.getSellPrice());
      mp.setProductId(productBean.getProductId());
      mp.setClientOnly(Constant.CHANNEL.CLIENT.name().equals(productBean.getProductChannel()));
      // 返现金额 分
      mp.setMaxCashRefund(
          null == productBean.getCashRefund()
              ? 0l
              : PriceUtil.convertToFen(productBean.getCashRefund()));
      mp.setCmtNum(productBean.getCmtNum()); // 点评数
      mp.setSubProductType(productBean.getSubProductType()); // 主题类型
      mp.setVisitDay(productBean.getVisitDay() + ""); // 天数
      try {
        ProductSearchInfo psi =
            this.productSearchInfoService.queryProductSearchInfoByProductId(
                productBean.getProductId());
        mp.setHasBusinessCoupon(ClientUtils.hasBusinessCoupon(psi)); // 优惠
      } catch (Exception e) {
        e.printStackTrace();
      }

      mpList.add(mp);
    }

    resultMap.put("subjects", topicList);
    resultMap.put("datas", mpList);
    resultMap.put("isLastPage", isLastPage(pageConfig));
    return resultMap;
  }
 /**
  * @param object
  * @param propertyName
  * @return
  */
 protected String getPropertyValue(Object object, String propertyName) {
   Object fieldValue = ObjectUtils.getPropertyValue(object, propertyName);
   return (ObjectUtils.isNull(fieldValue))
       ? ""
       : StringUtils.trimAllWhitespace(fieldValue.toString());
 }
Exemplo n.º 4
0
  @Test
  public void testEndpointAdapter() {
    ApplicationContext beanDefinitionContext = createApplicationContext("adapter");

    Map<String, HttpServer> servers = beanDefinitionContext.getBeansOfType(HttpServer.class);

    Assert.assertEquals(servers.size(), 6);

    // 1st message sender
    HttpServer server = servers.get("httpServer1");
    Assert.assertEquals(server.getName(), "httpServer1");
    Assert.assertEquals(server.getPort(), 8081);
    Assert.assertNotNull(server.getEndpointAdapter());
    Assert.assertEquals(server.getEndpointAdapter().getClass(), ChannelEndpointAdapter.class);
    Assert.assertNotNull(server.getEndpointAdapter().getEndpoint());
    Assert.assertEquals(
        server.getEndpointAdapter().getEndpoint().getEndpointConfiguration().getTimeout(), 10000L);
    Assert.assertEquals(
        ((ChannelEndpointConfiguration)
                server.getEndpointAdapter().getEndpoint().getEndpointConfiguration())
            .getChannelName(),
        "serverChannel");

    // 2nd message sender
    server = servers.get("httpServer2");
    Assert.assertEquals(server.getName(), "httpServer2");
    Assert.assertEquals(server.getPort(), 8082);
    Assert.assertNotNull(server.getEndpointAdapter());
    Assert.assertEquals(server.getEndpointAdapter().getClass(), JmsEndpointAdapter.class);
    Assert.assertNotNull(server.getEndpointAdapter().getEndpoint());
    Assert.assertEquals(
        server.getEndpointAdapter().getEndpoint().getEndpointConfiguration().getTimeout(), 2500);
    Assert.assertEquals(
        ((JmsEndpointConfiguration)
                server.getEndpointAdapter().getEndpoint().getEndpointConfiguration())
            .getDestinationName(),
        "serverQueue");
    Assert.assertEquals(
        ((JmsEndpointConfiguration)
                server.getEndpointAdapter().getEndpoint().getEndpointConfiguration())
            .getConnectionFactory(),
        beanDefinitionContext.getBean("connectionFactory", ConnectionFactory.class));

    // 3rd message sender
    server = servers.get("httpServer3");
    Assert.assertEquals(server.getName(), "httpServer3");
    Assert.assertEquals(server.getPort(), 8083);
    Assert.assertNotNull(server.getEndpointAdapter());
    Assert.assertEquals(server.getEndpointAdapter().getClass(), EmptyResponseEndpointAdapter.class);

    // 4th message sender
    server = servers.get("httpServer4");
    Assert.assertEquals(server.getName(), "httpServer4");
    Assert.assertEquals(server.getPort(), 8084);
    Assert.assertNotNull(server.getEndpointAdapter());
    Assert.assertEquals(
        server.getEndpointAdapter().getClass(), StaticResponseEndpointAdapter.class);
    Assert.assertEquals(
        StringUtils.trimAllWhitespace(
            ((StaticResponseEndpointAdapter) server.getEndpointAdapter()).getMessagePayload()),
        "<TestMessage><Text>Hello!</Text></TestMessage>");
    Assert.assertEquals(
        ((StaticResponseEndpointAdapter) server.getEndpointAdapter())
            .getMessageHeader()
            .get("Operation"),
        "sayHello");

    // 5th message sender
    server = servers.get("httpServer5");
    Assert.assertEquals(server.getName(), "httpServer5");
    Assert.assertEquals(server.getPort(), 8085);
    Assert.assertNotNull(server.getEndpointAdapter());
    Assert.assertEquals(
        server.getEndpointAdapter().getClass(), TimeoutProducingEndpointAdapter.class);

    // 6th message sender
    server = servers.get("httpServer6");
    Assert.assertEquals(server.getName(), "httpServer6");
    Assert.assertEquals(server.getPort(), 8086);
    Assert.assertNotNull(server.getEndpointAdapter());
    Assert.assertEquals(
        server.getEndpointAdapter(),
        beanDefinitionContext.getBean("httpServerAdapter6", EndpointAdapter.class));
  }