List of usage examples for org.apache.commons.lang3 BooleanUtils toBooleanObject
public static Boolean toBooleanObject(final String str, final String trueString, final String falseString, final String nullString)
Converts a String to a Boolean throwing an exception if no match.
NOTE: This returns null and will throw a NullPointerException if autoboxed to a boolean.
From source file:system.controllers.UserApp.java
@Transactional(readOnly = true) public static Result list() { SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); String startDatestr = StringUtils.defaultIfBlank(request().getQueryString("startDate"), null); String endDatestr = StringUtils.defaultIfBlank(request().getQueryString("endDate"), null); Date startDate = null;//from w w w.j a v a 2 s.c o m Date endDate = null; try { if (startDatestr != null) { startDate = df.parse(startDatestr + " 00:00:00"); } if (endDatestr != null) { endDate = df.parse(endDatestr + " 23:59:59"); } } catch (ParseException e1) { e1.printStackTrace(); } Integer start = NumberUtils.toInt(request().getQueryString("start"), 0); String searchText = StringUtils.defaultIfBlank(request().getQueryString("searchText"), null); String isEnableStr = defaultIfNotContain(request().getQueryString("isEnable"), new String[] { "0", "1" }, null); String isComplainStr = defaultIfNotContain(request().getQueryString("isComplain"), new String[] { "0", "1" }, null); String isOnlineStr = defaultIfNotContain(request().getQueryString("isOnline"), new String[] { "0", "1" }, null); String isTopStr = defaultIfNotContain(request().getQueryString("isTop"), new String[] { "0", "1" }, null); String genderStr = defaultIfNotContain(request().getQueryString("gender"), new String[] { "0", "1" }, null); String country = StringUtils.defaultIfBlank(request().getQueryString("country"), null); String inIdStr = StringUtils.defaultIfBlank(request().getQueryString("inId"), null); String userTypeStr = defaultIfNotContain(request().getQueryString("userType"), new String[] { "0", "1", "2", "3", "4", "5", "6" }, null); if (StringUtils.equals(inIdStr, "")) { inIdStr = "-1"; } String sortStr = request().getQueryString("sort"); String sortProperty = null; Boolean isDesc = null; if (StringUtils.isNotBlank(sortStr)) { try { JsonNode sortJsonArray = Json.parse(sortStr); if (sortJsonArray.isArray() && null != sortJsonArray.get(0)) { JsonNode sortJsonNode = sortJsonArray.get(0); if (sortJsonNode.hasNonNull("property") && sortJsonNode.hasNonNull("direction")) { String property = sortJsonNode.get("property").asText(); if ("tradeNum".equals(property)) { sortProperty = "e.dealNum"; } else if ("averageScore".equals(property)) { sortProperty = "e.averageScore"; } isDesc = "DESC".equals(sortJsonNode.get("direction").asText()); } } } catch (RuntimeException e) { LOGGER.debug("failed to parse JSON. JSON: " + sortStr); } } UserGridSearchCondition c = new UserGridSearchCondition(); c.setCountry(country); c.setGender(null == genderStr ? null : Gender.getByOrdinal(Integer.valueOf(genderStr))); c.setIsComplain(BooleanUtils.toBooleanObject(isComplainStr, "1", "0", null)); c.setIsDesc(isDesc); c.setIsEnable(BooleanUtils.toBooleanObject(isEnableStr, "1", "0", null)); c.setIsOnline(BooleanUtils.toBooleanObject(isOnlineStr, "1", "0", null)); c.setLimit(20); c.setSearchText(searchText); c.setSortProperty(sortProperty); c.setStart(start); c.setIsTop(BooleanUtils.toBooleanObject(isTopStr, "1", "0", null)); c.setUserType(userTypeStr); c.setStartDate(startDate); c.setEndDate(endDate); Long inId = HelomeUtil.toLong(inIdStr, null); c.setInId(inId == -1 ? null : inId); Page<UserGridVO> page = UserService.queryUserGridPage(c); return ok(page.toJson()); }
From source file:system.controllers.UserApp.java
@Transactional(readOnly = false) public static Result saveUserState() { DynamicForm requestData = Form.form().bindFromRequest(); Long userId = NumberUtils.createLong(requestData.get("userId")); String isEnableStr = defaultIfNotContain(requestData.get("disableState"), new String[] { "0", "1" }, null); String isComplainStr = defaultIfNotContain(requestData.get("complainState"), new String[] { "0", "1" }, null);//from w w w. j a v a2s.com String isOnlineStr = defaultIfNotContain(requestData.get("onlineState"), new String[] { "0", "1" }, null); isComplainStr = "0"; isOnlineStr = "0"; Boolean isEnable = BooleanUtils.toBooleanObject(isEnableStr, "1", "0", null); Boolean isComplain = BooleanUtils.toBooleanObject(isComplainStr, "1", "0", null); Boolean isOnline = BooleanUtils.toBooleanObject(isOnlineStr, "1", "0", null); String onlineServiceStr = requestData.get("onlineService"); // ? String onlineTranslationStr = requestData.get("onlineTranslation"); // boolean isOnlineService = Boolean.FALSE; boolean isOnlineTranslation = Boolean.FALSE; if (StringUtils.equals("1", onlineServiceStr)) { isOnlineService = Boolean.TRUE; } if (StringUtils.equals("1", onlineTranslationStr)) { isOnlineTranslation = Boolean.TRUE; } ObjectNode result = Json.newObject(); if (null == userId || null == isEnable || null == isOnline || null == isComplain) { result.put("success", false); } else { try { UserService.saveUserState(userId, isEnable, isComplain, isOnline); ObjectMapper objectMapper = JackJsonUtil.getMapperInstance(false); Expert expert = Expert.getExpertByUserId(userId); List<String> skillsTagsList = new ArrayList<String>(); try { if (expert != null && StringUtils.isNotEmpty(expert.skillsTags)) { if (expert.skillsTags != null) { skillsTagsList = objectMapper.readValue(expert.skillsTags, List.class); } } } catch (Exception e) { e.printStackTrace(); skillsTagsList = new ArrayList<String>(); } String ss1 = "?"; if (!isOnlineService) { if (expert != null && expert.skillsTags != null && expert.skillsTags.contains("\"" + ss1 + "\"")) { Iterator<String> ite = skillsTagsList.iterator(); while (ite.hasNext()) { String item = ite.next(); if (StringUtils.equals(item, ss1)) { ite.remove(); } } } } else { if (expert != null && expert.skillsTags != null && !expert.skillsTags.contains("\"" + ss1 + "\"")) { skillsTagsList.add(ss1); } else if (expert != null && expert.skillsTags == null) { skillsTagsList.add(ss1); } } String ss2 = ""; if (!isOnlineTranslation) { if (expert != null && expert.skillsTags != null && expert.skillsTags.contains("\"" + ss2 + "\"")) { Iterator<String> ite = skillsTagsList.iterator(); while (ite.hasNext()) { String item = ite.next(); if (StringUtils.equals(item, ss2)) { ite.remove(); } } } } else { if (expert != null && expert.skillsTags != null && !expert.skillsTags.contains("\"" + ss2 + "\"")) { skillsTagsList.add(ss2); } else if (expert != null && expert.skillsTags == null) { skillsTagsList.add(ss2); } } expert.skillsTags = objectMapper.writeValueAsString(skillsTagsList); if (isEnable == true) { expert.saveOrUpate(); } result.put("success", true); } catch (Exception e) { ExtForm extForm = new ExtForm(); extForm.setSuccess(false); extForm.setMsg("?" + e.getMessage()); if (Logger.isErrorEnabled()) { Logger.error("?????", e); } return ok(play.libs.Json.toJson(extForm)); } } return ok(result); }
From source file:system.controllers.UserApp.java
/** * ?excel//from w w w. ja va2 s .com * downloadExcel */ @Transactional public static Result downloadExcel(String searchText, String isEnable, String gender, String country, String isTop, String inId, String userType, String startDate, String endDate) { SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); Date start = null; Date end = null; try { if (startDate != null && !"null".equals(startDate)) { start = df.parse(startDate + " 00:00:00"); } if (endDate != null && !"null".equals(endDate)) { end = df.parse(endDate + " 23:59:59"); } } catch (ParseException e1) { e1.printStackTrace(); } if (StringUtils.equals(inId, "")) { inId = "-1"; } UserGridSearchCondition c = new UserGridSearchCondition(); c.setCountry(country); c.setGender("".equals(gender) ? null : Gender.getByOrdinal(Integer.valueOf(gender))); c.setIsComplain(null); c.setIsDesc(null); c.setIsEnable(BooleanUtils.toBooleanObject("".equals(isEnable) ? null : isEnable, "1", "0", null)); c.setIsOnline(null); c.setLimit(20); c.setSearchText(searchText); c.setSortProperty(null); c.setIsTop(BooleanUtils.toBooleanObject("".equals(isTop) ? null : isTop, "1", "0", null)); c.setUserType(userType); c.setStartDate(start); c.setEndDate(end); Long inIds = HelomeUtil.toLong(inId, null); c.setInId(inIds == -1 ? null : inIds); List<UserGridVO> list = UserService.queryUserGridExcel(c); try { Long time = System.currentTimeMillis(); play.mvc.Http.Response response = response(); response.setContentType("application/x-msdownload;"); response.setHeader("Content-disposition", "attachment; filename=" + java.net.URLEncoder.encode("?_" + time + ".xls", "UTF-8")); ByteArrayOutputStream os = new ByteArrayOutputStream(); ExcelUtil.export(UserGridVO.class, list, os); byte[] excel = os.toByteArray(); os.close(); response.setHeader("Content-Length", String.valueOf(excel.length)); return ok(excel); } catch (Exception e) { e.printStackTrace(); } return ok(); }