List of usage examples for java.util Objects toString
public static String toString(Object o, String nullDefault)
From source file:com.yinghua.translation.rest.PhoneResourceRESTService.java
/** * ?/*from w w w.j a va 2s .c o m*/ * * @param params * @return */ @POST @Path("/uploadPurchase") @Consumes(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON) public Map<String, Object> uploadPurchase(String params) { Map<String, Object> req = new HashMap<>(); JSONObject obj = JSONObject.parseObject(params); String uid = Objects.toString(obj.getString("uid"), "0"); Member member = repository.findById(Long.parseLong(uid)); if (member == null) { // ? req.put("result", "fail"); req.put("error_code", "6001"); req.put("error_msg", ""); } else { // member.setPurchased("true"); repository.updateMember(member); req.put("result", "success"); req.put("error_code", "000000"); req.put("error_msg", ""); } return req; }
From source file:com.yinghua.translation.rest.PhoneResourceRESTService.java
/** * ?//from w w w. j a v a 2 s.c om * * @param params * @return */ @POST @Path("/uploadContacts") @Consumes(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON) public Map<String, Object> uploadContacts(String params) { JSONObject obj = JSONObject.parseObject(params); String contacts = obj.getString("contacts"); String uno = Objects.toString(obj.get("uno"), "0"); Map<String, Object> req = new HashMap<>(); //Member member = repository.findById(Long.parseLong(uid)); Member member = repository.findByMemberNo(uno); // ? try { member.setContacts(contacts); repository.updateMember(member); req.put("result", "success"); req.put("error_code", "000000"); req.put("error_msg", ""); } catch (Exception e) { log.info(e.getMessage()); req.put("result", "fail"); req.put("error_code", "7001"); req.put("error_msg", ""); } return req; }
From source file:com.github.fengtan.sophie.tables.DocumentsTable.java
/** * Update a document locally./*from w ww .j a v a 2s. c om*/ * * @param item * Row containing the document to update. * @param columnIndex * Column index of the field to update. * @param newValue * New value. */ private void updateDocument(TableItem item, int columnIndex, Object newValue) { SolrDocument document = (SolrDocument) item.getData("document"); // The row may not contain any document (e.g. the first row, which // contains the filters). if (document == null) { return; } String fieldName = (String) table.getColumn(columnIndex).getData("fieldName"); // We reduce by 1 since the first column is used for row ID. document.setField(fieldName, newValue); item.setText(columnIndex, Objects.toString(newValue, StringUtils.EMPTY)); changeListener.changed(); // If document was locally added, then leave it in documentsAdded and // return so it remains green. if (documentsAdded.contains(document)) { return; } // If document was locally deleted, then remove it from documentsDeleted // and let it go into documentsUpdated. if (documentsDeleted.contains(document)) { documentsDeleted.remove(document); } // Add document to documentsUpdated if it is not already there. if (!documentsUpdated.contains(document)) { documentsUpdated.add(document); } item.setBackground(YELLOW); }
From source file:com.yinghua.translation.rest.PhoneResourceRESTService.java
/** * ????/* ww w . j a v a2 s . co m*/ * * @param params * @return */ @POST @Path("/getCommonData") @Consumes(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON) public Map<String, Object> getCommonData(String params) { JSONObject obj = JSONObject.parseObject(params); String commonType = Objects.toString(obj.get("commonType"), ""); Map<String, Object> req = new HashMap<>(); //Member member = repository.findById(Long.parseLong(uid)); List<CommonData> list = commonDataBean.findByCommonType(commonType); try { if (list != null) { req.put("count", list.size()); req.put("commonDatas", list); } req.put("result", "success"); req.put("error_code", "000000"); req.put("error_msg", ""); } catch (Exception e) { log.info(e.getMessage()); req.put("result", "fail"); req.put("error_code", "7001"); req.put("error_msg", ""); } return req; }
From source file:com.yinghua.translation.rest.PhoneResourceRESTService.java
/** * ?????//from w ww . jav a 2 s .c o m * * @param params * @return */ @POST @Path("/sendCallee3") @Consumes(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON) public Map<String, Object> sendCallee3(String params) { JSONObject obj = JSONObject.parseObject(params); String caller = Objects.toString(obj.get("caller"), "null"); String callee = Objects.toString(obj.getString("callee"), ""); Map<String, Object> req = new HashMap<>(); // ??? boolean isOk = false; String errorCode = "1011"; String errorMsg = "?"; try { Constant.call3Map.put(caller, callee); System.out.println("caller:" + caller + ",callee:" + Constant.call3Map.get(caller)); System.out.println("???"); if (callee != null && callee.length() > 0) { if (callee.startsWith("000000000")) { //? Member member = memberBean.findMember(caller, ""); if (member != null) { errorCode = ServiceNoHandlerFactory.createServiceNoHandler().processServiceNo( member.getMemberNumber(), callee, baseProductBean, memberOrderBean, memberOrderUseBean); if ("000000".equals(errorCode)) isOk = true; // System.out.println("??"+member.getMemberNumber()); // List<MemberOrder> orders = memberOrderBean.findUsingOrderByUno(member.getMemberNumber()); // if(orders!=null&&orders.size()>0){ // for (MemberOrder memberOrder : orders) { // if("1003".equals(memberOrder.getPackageNo())||Constant.packageNoMap.get(callee).equals(memberOrder.getPackageNo())){ // isOk = true; // break; // } // } // } // Account account = accountBean.findByMemberNo(member.getMemberNumber()); // if(account!=null&&account.getSurplusCallDuration()>0){ // req.put("result", "success"); // req.put("error_code", "000000"); // req.put("error_msg", ""); // }else{ // req.put("result", "fail"); // req.put("error_code", "1011"); // req.put("error_msg", "?"); // } } else { errorCode = "1006"; errorMsg = "?"; } if (isOk) { req.put("result", "success"); req.put("error_code", "000000"); req.put("error_msg", ""); } else { req.put("result", "fail"); req.put("error_code", errorCode); req.put("error_msg", errorMsg); } } else {//? req.put("result", "success"); req.put("error_code", "000000"); req.put("error_msg", ""); } } else { req.put("result", "fail"); req.put("error_code", "1011"); req.put("error_msg", "??"); } } catch (Exception e) { log.info(e.getMessage()); req.put("result", "fail"); req.put("error_code", "7001"); req.put("error_msg", ""); } return req; }
From source file:com.yinghua.translation.rest.PhoneResourceRESTService.java
/** * ????/* www . j a v a 2s. c o m*/ * * @param params * @return */ @POST @Path("/sendLocation") @Consumes(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON) public Map<String, Object> sendLocation(String params) { JSONObject obj = JSONObject.parseObject(params); String caller = obj.getString("caller"); String location = Objects.toString(obj.get("location"), ""); Map<String, Object> req = new HashMap<>(); try { if (caller != null) { LocationUtil.writeProperties(caller, location); req.put("result", "success"); req.put("error_code", "000000"); req.put("error_msg", ""); } else { req.put("result", "fail"); req.put("error_code", "7001"); req.put("error_msg", "??"); } } catch (Exception e) { log.info(e.getMessage()); req.put("result", "fail"); req.put("error_code", "7001"); req.put("error_msg", ""); } return req; }
From source file:com.github.fengtan.sophie.tables.DocumentsTable.java
/** * Add a filter (combo)./*from w w w . ja va2s .c om*/ * * @param fieldName * Field name. * @param field * Field definition. * @param facet * Facet - the values will be used to populate the values of the * combo. * @param index * Column index. */ private void addCombo(String fieldName, FieldInfo field, final FacetField facet, int index) { final CCombo combo = new CCombo(table, SWT.BORDER); combo.add(StringUtils.EMPTY); // If the number of facet values is the max, then the list of facet // values might not be complete. Hence we use a free text field instead // of populating the combo. if (facet.getValueCount() < FACET_LIMIT) { for (Count count : facet.getValues()) { combo.add(Objects.toString(count.getName(), LABEL_EMPTY) + " (" + count.getCount() + ")"); } combo.addSelectionListener(new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent event) { // Extract original value (e.g. "Foobar") from widget value // (e.g. "Foobar (3)") Pattern pattern = Pattern.compile("^(.*) \\([0-9]+\\)$"); Matcher matcher = pattern.matcher(combo.getText()); // If we found the original value, then populate the combo. // Otherwise, log a warning message. if (matcher.find()) { combo.setText(matcher.group(1)); } else { Sophie.log.warn("Unable to extract original value from \"" + combo.getText() + "\""); } }; }); } else { combo.add(LABEL_EMPTY); } // Fire filters + refresh when user selects a value. combo.addSelectionListener(new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent event) { String filterName = facet.getName(); String filterNewValue = combo.getText(); String filterOldValue = filters.get(filterName); // No need to re-send a request to Solr and the user selected // the same filter as the current filter. if (StringUtils.equals(filterOldValue, filterNewValue) || (StringUtils.isBlank(filterOldValue) && StringUtils.isBlank(filterNewValue))) { return; } updateFilters(filterName, filterNewValue); try { refresh(); } catch (SophieException e) { ExceptionDialog.open(composite.getShell(), new SophieException("Unable to refresh documents from Solr server", e)); } } }); // Filter (refresh) results when user hits "Enter" while editing one of // the combos. combo.addListener(SWT.KeyUp, new Listener() { @Override public void handleEvent(Event event) { if (event.character == SWT.CR) { updateFilters(facet.getName(), combo.getText()); try { refresh(); } catch (SophieException e) { ExceptionDialog.open(composite.getShell(), new SophieException("Unable to refresh documents from Solr server", e)); } } } }); if (combo != null) { editor.grabHorizontal = true; editor.setEditor(combo, table.getItem(0), index); editor = new TableEditor(table); } }
From source file:com.yinghua.translation.rest.PhoneResourceRESTService.java
/** * ???//from w w w .j av a2 s.c o m * * @param params * @return */ @POST @Path("/callerStatus") @Consumes(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON) public Map<String, Object> callerStatus(String params) { JSONObject obj = JSONObject.parseObject(params); String caller = Objects.toString(obj.get("caller"), "null"); Map<String, Object> req = new HashMap<>(); try { String status = "error"; String call_id = Constant.callerMap.get(caller); if (call_id != null && call_id.length() > 0) { status = "ok"; Constant.callerMap.remove(caller); } System.out.println("???"); System.out.println("caller:" + caller + ",call_id:" + call_id); req.put("result", "success"); req.put("status", status); req.put("error_code", "000000"); req.put("error_msg", ""); } catch (Exception e) { log.info(e.getMessage()); req.put("result", "fail"); req.put("error_code", "7001"); req.put("error_msg", ""); } return req; }
From source file:com.yinghua.translation.rest.PhoneResourceRESTService.java
/** * ???/*from w w w .j a va 2 s. co m*/ * * @param params * @return */ @POST @Path("/caller3Status") @Consumes(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON) public Map<String, Object> caller3Status(String params) { JSONObject obj = JSONObject.parseObject(params); String caller = Objects.toString(obj.get("caller"), "null"); Map<String, Object> req = new HashMap<>(); // ??? try { String status = "error"; String result = Constant.calleeMap.get(caller); if ("1".equals(result)) { status = "ok"; Constant.calleeMap.remove(caller); } else if ("2".equals(result)) { status = "end"; Constant.calleeMap.remove(caller); } System.out.println("APP?"); System.out.println("caller:" + caller + ",result:" + status); req.put("result", "success"); req.put("status", status); req.put("error_code", "000000"); req.put("error_msg", ""); } catch (Exception e) { log.info(e.getMessage()); req.put("result", "fail"); req.put("error_code", "7001"); req.put("error_msg", ""); } return req; }