/** * {@inheritDoc} * * @see * org.kuali.kra.common.specialreview.service.SpecialReviewService#getProtocolIndex(java.lang.String) */ public int getProtocolIndex(String prefix) { int index = -1; int lastLeftBracketIndex = StringUtils.lastIndexOf(prefix, '['); int lastRightBracketIndex = StringUtils.lastIndexOf(prefix, ']'); if (lastLeftBracketIndex != -1 && lastRightBracketIndex != -1) { String lineNumber = prefix.substring(lastLeftBracketIndex + 1, lastRightBracketIndex); if (NumberUtils.isDigits(lineNumber)) { index = Integer.parseInt(lineNumber); } } return index; }
/** * 获得cookie的每页条数 * * <p>使用_cookie_page_size作为cookie name * * @param request HttpServletRequest * @return default:20 max:200 */ public static int getPageSize(HttpServletRequest request) { Assert.notNull(request); Cookie cookie = getCookie(request, COOKIE_PAGE_SIZE); int count = 0; if (cookie != null) { if (NumberUtils.isDigits(cookie.getValue())) { count = Integer.parseInt(cookie.getValue()); } } if (count <= 0) { count = DEFAULT_SIZE; } else if (count > MAX_SIZE) { count = MAX_SIZE; } return count; }
public static void main2(String[] args) { StringBuilder sb = new StringBuilder(100 * 2); String ex = ":1.id[id.kkj][idkkj], :2[name], :3[age], :3[4]"; Matcher m = MAP_PATTERN.matcher(ex); int index = 0; while (m.find()) { sb.append(ex.substring(index, m.start())); String t = m.group(1); if (!NumberUtils.isDigits(t)) { sb.append("['"); sb.append(m.group(1)); sb.append("']"); } else { sb.append(m.group(0)); } index = m.end(); } sb.append(ex.substring(index)); System.out.println(sb); }
/** {@inheritDoc} */ @Override public void processBindingConfiguration(String context, Item item, String bindingConfig) throws BindingConfigParseException { super.processBindingConfiguration(context, item, bindingConfig); if (bindingConfig == null) { logger.debug("binding-configuration is currently not set for item: " + item.getName()); return; } logger.trace("handling config: {}", bindingConfig); List<String> calendar = new ArrayList<String>(); ; String type = null; Type typeEnum = null; String eventNr = null; String value = null; Value valueEnum = null; String[] splits = bindingConfig.split(" "); for (String split : splits) { logger.trace("handling config part: {}", split); Matcher mCalendar = Pattern.compile(REGEX_CALENDAR).matcher(split); if (mCalendar.matches()) { for (String str : mCalendar.group(1).split(",")) { calendar.add(str); } } Matcher mType = Pattern.compile(REGEX_TYPE).matcher(split); if (mType.matches()) { type = mType.group(1); } Matcher mEventNr = Pattern.compile(REGEX_EVENT_NR).matcher(split); if (mEventNr.matches()) { eventNr = mEventNr.group(1); } Matcher mValue = Pattern.compile(REGEX_VALUE).matcher(split); if (mValue.matches()) { value = mValue.group(1); } } logger.trace( "found values: calendar={}, type={}, eventNr={}, value={}", calendar, type, eventNr, value); if (calendar == null || calendar.size() == 0) { throw new BindingConfigParseException("missing attribute 'calendar'"); } if (type == null) { throw new BindingConfigParseException("missing attribute 'type'"); } try { typeEnum = CalDavConfig.Type.valueOf(type.toUpperCase()); } catch (IllegalArgumentException e) { throw new BindingConfigParseException("type '" + type + "' not valid"); } if (typeEnum != Type.PRESENCE) { if (eventNr == null) { throw new BindingConfigParseException("missing attribute 'eventNr'"); } if (value == null) { throw new BindingConfigParseException("missing attribute 'value'"); } if (!NumberUtils.isDigits(eventNr)) { throw new BindingConfigParseException("attribute 'eventNr' must be a valid integer"); } try { valueEnum = CalDavConfig.Value.valueOf(value.toUpperCase()); } catch (IllegalArgumentException e) { throw new BindingConfigParseException("value '" + type + "' not valid"); } } else { if (eventNr != null) { throw new BindingConfigParseException("not required attribute 'eventNr'"); } if (value != null) { throw new BindingConfigParseException("not required attribute 'value'"); } } logger.debug("adding item: {}", item.getName()); this.addBindingConfig( item, new CalDavConfig( calendar, typeEnum, NumberUtils.toInt(eventNr == null ? "0" : eventNr), valueEnum)); }
public static boolean isNegativeInt(String str) { return NumberUtils.isDigits(str) && Integer.parseInt(str) < 0; }
public static boolean isInt(List<String> args, int index) { String numStr = args.get(index); if (args.get(index).startsWith("-")) numStr = numStr.substring(1, numStr.length() - 1); return NumberUtils.isDigits(numStr); }
public boolean create(Map<String, Object> context) throws Exception { String addr = (String) context.get("address"); String services = (String) context.get("multiservice"); if (services == null || services.trim().length() == 0) { services = (String) context.get("service"); } String weight = (String) context.get("weight"); int w = Integer.parseInt(weight); Set<String> addresses = new HashSet<String>(); BufferedReader reader = new BufferedReader(new StringReader(addr)); while (true) { String line = reader.readLine(); if (null == line) break; String[] split = line.split("[\\s,;]+"); for (String s : split) { if (s.length() == 0) continue; String ip = s; String port = null; if (s.indexOf(":") != -1) { ip = s.substring(0, s.indexOf(":")); port = s.substring(s.indexOf(":") + 1, s.length()); if (port.trim().length() == 0) port = null; } if (!IP_PATTERN.matcher(ip).matches()) { context.put("message", "illegal IP: " + s); return false; } if (LOCAL_IP_PATTERN.matcher(ip).matches() || ALL_IP_PATTERN.matcher(ip).matches()) { context.put("message", "local IP or any host ip is illegal: " + s); return false; } if (port != null) { if (!NumberUtils.isDigits(port)) { context.put("message", "illegal port: " + s); return false; } } addresses.add(s); } } Set<String> aimServices = new HashSet<String>(); reader = new BufferedReader(new StringReader(services)); while (true) { String line = reader.readLine(); if (null == line) break; String[] split = line.split("[\\s,;]+"); for (String s : split) { if (s.length() == 0) continue; if (!super.currentUser.hasServicePrivilege(s)) { context.put("message", getMessage("HaveNoServicePrivilege", s)); return false; } aimServices.add(s); } } for (String aimService : aimServices) { for (String a : addresses) { Weight wt = new Weight(); wt.setUsername((String) context.get("operator")); wt.setAddress(Tool.getIP(a)); wt.setService(aimService); wt.setWeight(w); overrideService.saveOverride(OverrideUtils.weightToOverride(wt)); } } return true; }
@Override public Object executeExpr(final String expression) throws Exception { // 从缓存中获取解析的表达式 Expression expr = cache.get(expression); if (expr == null) { // StringBuilder builder = new StringBuilder(expression.length() * 2); // 将[name]替换为['name'] Matcher mapMatcher = MAP_PATTERN.matcher(expression); int index = 0; while (mapMatcher.find()) { builder.append(expression.substring(index, mapMatcher.start())); String t = mapMatcher.group(1); if (!NumberUtils.isDigits(t)) { builder.append("['"); builder.append(mapMatcher.group(1)); builder.append("']"); } else { builder.append(mapMatcher.group(0)); } index = mapMatcher.end(); } String expression2; if (builder.length() == 0) { expression2 = expression; } else { builder.append(expression.substring(index)); expression2 = builder.toString(); builder.setLength(0); } index = 0; // 匹配正则表达式, 并替换内容 Matcher matcher = PREFIX_PATTERN.matcher(expression2); while (matcher.find()) { builder.append(expression2.substring(index, matcher.start())); String prefix = matcher.group(1); String name = matcher.group(2); if (":".equals(prefix)) { boolean isDigits = NumberUtils.isDigits(name); if (isDigits) { // 按顺序访问变量 name = ':' + name; } if (!mapVars.containsKey(name)) { throw new IllegalArgumentException( "Variable \'" + name + "\' not defined in DAO method"); } // 按名称访问变量 builder.append(VAR_PREFIX); builder.append("['"); builder.append(name); builder.append("']"); } else if ("$".equals(prefix)) { if (!mapConsts.containsKey(name)) { throw new IllegalArgumentException( "Constant \'" + name + "\' not defined in DAO class"); } // 拼出常量访问语句 builder.append(CONST_PREFIX); builder.append("[\'"); builder.append(name); builder.append("\']"); } index = matcher.end(2); } builder.append(expression2.substring(index)); // 编译表达式 expr = ExpressionFactory.createExpression(builder.toString()); cache.putIfAbsent(expression2, expr); } // 进行表达式求值 return expr.evaluate(context); }
/** * Part accessory sale index save * * @param request HttpServletRequest * @param form ActionForm form data * @param mapping ActionMapping * @param response HttpServletResponse */ public void validate( ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) { try { MultiEntity multiEntity = (MultiEntity) SpringContextUtil.getBean("multiEntity"); HttpSession session = request.getSession(); PrintWriter writer = response.getWriter(); response.setContentType("text/xml"); response.setHeader("Cache-Control", "no-cache"); writer.println("<xml>"); Long orgCode = (Long) session.getAttribute("orgCode"); Boolean isSSC = (Boolean) session.getAttribute("isSSC"); String stType = (String) session.getAttribute("stType"); String pcType = ((CommonSearch) SpringContextUtil.getBean("commonSearch")).findPcTypeByOrgCode(orgCode); String partCode = request.getParameter("skuCode"); String customerId = request.getParameter("customerId"); int quantity = new Integer(request.getParameter("quantity")).intValue(); // 得到 part info PartInfoForm partInfoForm = partInfoBo.find(partCode); PartsPriceLogic priceLogic = new PartsPriceLogic(); // if (partInfoForm != null) { String clientType = ""; Double partStdCost = null; FactorMarkUp priceGroupRelation = null; boolean hasPriceGroupFee = true; if (customerId != null && !customerId.equals("") && NumberUtils.isDigits(customerId)) { // 得到customer group id Long cusGrpid = ((CommonSearch) SpringContextUtil.getBean("commonSearch")).getCustomGrpId(customerId); if (cusGrpid != null) { clientType = cusGrpid.toString(); priceGroupRelation = priceGroupBo.findGroupRelation(Long.parseLong(customerId), orgCode); TdCustomerInfoForm cus = (TdCustomerInfoForm) priceGroupBo .getDao() .findById(TdCustomerInfoForm.class, Long.parseLong(customerId)); if (priceGroupRelation == null) { priceLogic = new PartsPriceLogic(); } else { priceLogic = new PartsPriceLogic(priceGroupRelation.getPriceGroupId(), cus.getForSsc()); } partStdCost = priceLogic.getPartPrice(partCode, "SS", orgCode, pcType, clientType); String enableMU6 = CommonSearch.getSystemCode("ENABLE_MU6", "MU6", multiEntity.getCountryCode()); if ("P".equals(stType) && isSSC && (null != enableMU6 && "Y".equals(enableMU6.toUpperCase()))) { if (null != priceGroupRelation) { hasPriceGroupFee = partStdCost != 0d; } else { hasPriceGroupFee = false; } } } } boolean flag = partInfoBo.isCanUsePart(partCode, "S"); /** *****新的计价逻辑****** */ CommonSearch cs = ((CommonSearch) SpringContextUtil.getBean("commonSearch")); ArrayList<PartsSalesInfo> partList = new ArrayList<PartsSalesInfo>(); SearchOptionListSetting extOptionList = null; String productSubCategory = partInfoForm.getProduct_Subcategory(); String cityCode = cs.getCityCode(orgCode); String stateCode = cs.getStateCode(orgCode); String unitCode = cs.findUnitCodeByOrgCode(orgCode); String ascLevel = cs.getAscLevelByOrgCode(orgCode); RepairBasicInfo repairBasicInfo = new RepairBasicInfo( null, stateCode, cityCode, "", productSubCategory, "", "", orgCode, new Long(customerId), unitCode, ascLevel, ""); repairBasicInfo.setOrgType(pcType); repairBasicInfo.setClientType(clientType); repairBasicInfo.setAbandonFlag(true); PartsSalesInfo partsSalesInfo = new PartsSalesInfo(); partsSalesInfo.setPartCode(partInfoForm.getPartCode()); partsSalesInfo.setChargableFlag("N"); partsSalesInfo.setQuantity(quantity); partList.add(partsSalesInfo); PartFeeInterface partFeeInterface = (PartFeeInterface) SpringContextUtil.getBean("partFeeInterface" + multiEntity.getCountryCode()); partFeeInterface.initSales(repairBasicInfo); PartFeeListBean partFeeListBean = partFeeInterface.getSalesPartFee(extOptionList, partList); ArrayList<PartFeeBean> partFeeBeanList = partFeeListBean.listFee(); PartFeeBean partFeeBean = partFeeBeanList.get(0); PartTaxListBean partTaxListBean = partFeeBean.getTaxList(); ArrayList<PartTaxBean> partTaxBeanList = partTaxListBean.listTax(); writer.println("<partFlag>true</partFlag>"); writer.println( "<partName>" + EscapeUnescape.escape(partInfoForm.getPartName()) + "</partName>"); writer.println( "<partDesc>" + EscapeUnescape.escape(partInfoForm.getPartDesc()) + "</partDesc>"); writer.println( "<partPrice>" + Operate.DoubleTransfer(partFeeBean.getPartPrice()) + "</partPrice>"); // System.out.println("<partPrice>" + Operate.DoubleTransfer(partFeeBean.getPartPrice()) // + "</partPrice>"); writer.println( "<stdCost>" + Operate.DoubleTransfer(partInfoForm.getStdCost()) + "</stdCost>"); writer.println("<isHasSn>" + partInfoForm.getIsHasSn() + "</isHasSn>"); writer.println("<isCanUsePart>" + flag + "</isCanUsePart>"); writer.println("<perCost>" + Operate.DoubleTransfer(partStdCost) + "</perCost>"); // System.out.println("<perCost>"+Operate.DoubleTransfer(partStdCost)+"</perCost>"); StringBuffer taxBuffer = new StringBuffer(); int count = 0; Double totalTax = 0.0; for (PartTaxBean partTaxBean : partTaxBeanList) { writer.println("<taxRow id=\"" + count + "\">"); writer.println( "<taxCode>" + EscapeUnescape.escape(partTaxBean.getTaxCode()) + "</taxCode>"); writer.println( "<taxName>" + EscapeUnescape.escape(popupSaleInfoBo.findTaxName(partTaxBean.getTaxCode())) + "</taxName>"); writer.println( "<taxRate>" + EscapeUnescape.escape( String.valueOf(Operate.formatPrice(partTaxBean.getTaxRate() * 100))) + "</taxRate>"); writer.println( "<taxAmt>" + EscapeUnescape.escape(Operate.DoubleTransfer(partTaxBean.getTaxAmt())) + "</taxAmt>"); writer.println( "<convertedTaxRate>" + EscapeUnescape.escape( String.valueOf(Operate.formatPrice(partTaxBean.getActualTaxRate() * 100))) + "</convertedTaxRate>"); writer.println( "<taxType>" + EscapeUnescape.escape(partTaxBean.getTaxType()) + "</taxType>"); writer.println("</taxRow>"); Double tax = partTaxBean.getTaxAmt(); String taxType = partTaxBean.getTaxType(); totalTax = PriceLogicCommonHelper.calculateTaxByTaxType(totalTax, tax, taxType); String taxString = partTaxBean.getTaxCode() + SPLITER1_STR + popupSaleInfoBo.findTaxName(partTaxBean.getTaxCode()) + SPLITER1_STR + partTaxBean.getTaxRate() + SPLITER1_STR + Operate.DoubleTransfer(partTaxBean.getTaxAmt()) + SPLITER1_STR + partTaxBean.getActualTaxRate(); taxBuffer.append(taxString); taxBuffer.append(SPLITER2_STR); count += 1; } writer.println( "<totalTax>" + EscapeUnescape.escape(Operate.DoubleTransfer(totalTax)) + "</totalTax>"); writer.println( "<taxBuffer>" + EscapeUnescape.escape(taxBuffer.toString()) + "</taxBuffer>"); writer.println("<hasPriceGroup>" + hasPriceGroupFee + "</hasPriceGroup>"); } else { writer.println("<partFlag>false</partFlag>"); } writer.println("</xml>"); writer.flush(); writer.close(); } catch (Exception e) { e.printStackTrace(); } }
/** * Runs a single QA check. * * @param modelId * @param queryName * @param conn * @return * @throws Exception */ public boolean testSingleModelDataQuality(Long modelId, String queryName, Connection conn) throws Exception { // There are two types of queries: // The 'normal' type returns zero rows to indicate that all is OK. // The Alt type can return a single column of a type convertable to int. // The 'alt' type is indicated by having the query name include the sufix // queryName_XXX where XXX is the integer value expected in the first column. boolean expectZeroRows = true; int expectedValue = 0; int splitPos = queryName.lastIndexOf('_'); if (splitPos > 0 && splitPos < (queryName.length() - 1)) { String numString = queryName.substring(splitPos + 1); NumberUtils.isDigits(numString); log.debug("Query '" + queryName + "' is expecting '" + numString + "' in the first column."); expectedValue = Integer.parseInt(numString); expectZeroRows = false; } else { log.debug("Query '" + queryName + "' is expecting no return rows."); } CalcAnalysis action = new CalcAnalysis(); // String[] params = new String[] {"MODEL_ID", modelId.toString()}; Map<String, Object> params = new HashMap<String, Object>(); params.put("MODEL_ID", modelId); // String sql = Action.getTextWithParamSubstitution(queryName, this.getClass(), params); PreparedStatement st = action.getROPSFromPropertiesFile(queryName, this.getClass(), params); // Statement st = conn.createStatement(ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY); ResultSet rs = null; try { rs = st.executeQuery(); if (expectZeroRows) { if (rs.next()) { log.debug( "-------- Model #" + modelId + " FAILED the data validation test '" + queryName + "' - See the properties file for the exact validation query --------"); return false; } else { return true; } } else { if (!rs.next()) { log.debug( "-------- Model #" + modelId + " FAILED the data validation test '" + queryName + "' - One row was expected --------"); return false; } else { int value = rs.getInt(1); if (expectedValue != value) { log.debug( "-------- Model #" + modelId + " FAILED the data validation test '" + queryName + "' - expected to find one value of '" + expectedValue + "--------"); return false; } else { return true; } } } } catch (Exception e) { log.error( "-------- Model #" + modelId + " FAILED the data validation test '" + queryName + "' with a SQL Error --------", e); return false; } finally { rs.close(); st.close(); } }