Search in sources :

Example 61 with JsonMappingException

use of org.codehaus.jackson.map.JsonMappingException in project portal by ixinportal.

the class UserInfoWebController method choiceEnterprise.

/**
 * 选择企业
 *
 * @param request
 * @return
 */
@RequestMapping("/choiceEnterprise")
public String choiceEnterprise(@RequestParam(value = "noProduct", required = false) String noProduct, HttpServletRequest request, Model uiModel) {
    HttpSession session = request.getSession();
    UserInfo userInfo = (UserInfo) session.getAttribute("webuserInfo");
    Boolean webnoProduct = (Boolean) session.getAttribute("webnoProduct");
    if (null == userInfo) {
        // 登录状态失效,跳转到登录页面
        return "redirect:/userInfoWeb/denglu.html";
    }
    // 查询用户关联的企业list
    List<Enterprise> enterpriseList = new ArrayList<Enterprise>();
    List<Long> enterpriseIds = userInfoEnterpriseServiceImpl.getEnterpriseByUserInfo(userInfo.getId());
    if (null != enterpriseIds && !enterpriseIds.isEmpty()) {
        enterpriseList = enterpriseService.getEnterpriseListByIds(enterpriseIds);
    }
    uiModel.addAttribute("enterpriseSize", enterpriseList.size());
    try {
        uiModel.addAttribute("enterpriseList", jsonTool.writeValueAsString(enterpriseList));
        uiModel.addAttribute("enterprises", enterpriseList);
    } catch (JsonGenerationException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (JsonMappingException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    // 存在有未关联企业的填写中订单,则添加填写中企业按钮:
    uiModel.addAttribute("hasEditBill", 0);
    List<EditBill> ebList = editBillService.getEditBill(userInfo.getId(), null);
    if (0 != ebList.size() && !ebList.isEmpty()) {
        uiModel.addAttribute("hasEditBill", 1);
        if (0 == enterpriseList.size()) {
            return "redirect:/userInfoWeb/editBillList";
        }
    }
    session.removeAttribute("sessionPlist");
    session.removeAttribute("enterpriseqqE");
    if (session.getAttribute("webprojectId") != null) {
        Long pid = Long.parseLong(session.getAttribute("webprojectId").toString());
        System.out.println("userInfo_=" + pid);
        if (null != pid) {
            // userInfo = userInfoService.getUserInfoById(userInfo.getId());
            EnterpriseQqExample enterpriseE = new EnterpriseQqExample();
            EnterpriseQqExample.Criteria qqEx = enterpriseE.createCriteria();
            qqEx.andProjectIdEqualTo(pid);
            EnterpriseQq enterpriseqq = sqlSession.selectOne("com.itrus.portal.db.EnterpriseQqMapper.selectByExample", enterpriseE);
            if (enterpriseqq != null && enterpriseqq.getEnterpriseQqLinks() != null) {
                uiModel.addAttribute("enterpriseqq", enterpriseqq.getEnterpriseQqLinks());
                session.setAttribute("enterpriseqqE", enterpriseqq.getEnterpriseQqLinks());
            }
        }
    }
    if ("1".equals(noProduct)) {
        session.setAttribute("webnoProduct", true);
        return "ixinweb/xuanzeqiyeNoProduct";
    }
    if (null == webnoProduct || webnoProduct) {
        // 未携带产品信息
        session.setAttribute("webnoProduct", true);
        return "ixinweb/xuanzeqiyeNoProduct";
    }
    return "ixinweb/xuanzeqiye";
}
Also used : HttpSession(javax.servlet.http.HttpSession) ArrayList(java.util.ArrayList) IOException(java.io.IOException) JsonMappingException(org.codehaus.jackson.map.JsonMappingException) JsonGenerationException(org.codehaus.jackson.JsonGenerationException) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 62 with JsonMappingException

use of org.codehaus.jackson.map.JsonMappingException in project portal by ixinportal.

the class MobileAppserviceChargingController method createOrUpdate.

// 新建和修改处理
@RequestMapping(value = "/createOrUpdate", method = RequestMethod.POST, produces = "text/html")
@ResponseBody
public synchronized Map<String, Object> createOrUpdate(@RequestParam("appserviceChargingStr") String appserviceChargingStr) {
    Map<String, Object> retMap = new HashMap<String, Object>();
    retMap.put("flag", false);
    DefaultTransactionDefinition dtd = new DefaultTransactionDefinition();
    // 事物的传播行为,使用同一个事物
    dtd.setPropagationBehavior(TransactionDefinition.PROPAGATION_REQUIRED);
    TransactionStatus status = transactionManager.getTransaction(dtd);
    try {
        AppserviceChargingWrap acw = jsonTool.readValue(appserviceChargingStr, AppserviceChargingWrap.class);
        List<AppserviceChargingList> appserviceChargingLists = acw.getAppserviceChargingLists();
        for (int i = 0; i < appserviceChargingLists.size(); i++) {
            // 取出单个的服务名称主表对象和服务名封装list
            MobileAppserviceCharging appCharging = appserviceChargingLists.get(i).getAppserviceCharging();
            // if (null == appCharging.getChargingType()) {
            // cc.setChargingType(ComNames.CHARGING_TYPE_SMRZ_1);
            // }
            List<AppserviceNameList> appserviceNameLists = appserviceChargingLists.get(i).getAppserviceNameLists();
            Map<String, Object> mapAC = new HashMap<String, Object>();
            mapAC = appserviceChargingService.saveOrUpdateAppserviceCharging(appCharging);
            boolean retCodeAC = false;
            retCodeAC = (boolean) mapAC.get("flag");
            // 新增或修改MobileAppserviceCharging成功
            if (retCodeAC) {
                appCharging = (MobileAppserviceCharging) mapAC.get("appserviceCharging");
                MobileAppserviceCharging oldAC = (MobileAppserviceCharging) mapAC.get("oldAppserviceCharging");
                // 将MobileAppserviceCharging的id值赋值给serviceNameList中新增的服务
                appserviceNameLists = appserviceNameService.insertIdIntoAppserviceName(appCharging, appserviceNameLists);
                // 2.新增或修改ServiceName
                for (int j = 0; j < appserviceNameLists.size(); j++) {
                    MobileAppserviceName appserviceName = appserviceNameLists.get(j).getAppserviceName();
                    ChargingPriceList chargingPriceList = appserviceNameLists.get(j).getChargingPriceList();
                    boolean retCodeSN = false;
                    Map<String, Object> mapAppserviceName = new HashMap<String, Object>();
                    mapAppserviceName = appserviceNameService.saveOrUpdateServiceName(appserviceName, appCharging, oldAC);
                    retCodeSN = (boolean) mapAppserviceName.get("flag");
                    // 新增或修改ServiceName成功
                    if (retCodeSN) {
                        appserviceName = (MobileAppserviceName) mapAppserviceName.get("appserviceName");
                        MobileAppserviceName oldAppserviceName = (MobileAppserviceName) mapAppserviceName.get("oldAppserviceName");
                        List<MobileAppserviceName> oldAppserviceNames = (List<MobileAppserviceName>) mapAppserviceName.get("appserviceNames");
                        // 将serviceNameId,CertificationCharging的id值赋值给chargingPriceList中计费以及价格区间
                        chargingPriceList = chargingPriceService.insertIdIntoChargingPrice(appserviceName, chargingPriceList);
                        List<MobileChargingPrice> chargingPrices = chargingPriceList.getChargingPriceLists();
                        // 3.charprice新增或修改
                        for (int k = 0; k < chargingPrices.size(); k++) {
                            Map<String, Object> mapChargingPrice = new HashMap<String, Object>();
                            mapChargingPrice = chargingPriceService.saveOrUpdateChargingPrice(appCharging, appserviceName, chargingPrices.get(k), oldAC, oldAppserviceName, oldAppserviceNames);
                            boolean retCodeChargingPrice = false;
                            retCodeChargingPrice = (boolean) mapChargingPrice.get("flag");
                            // 新增或修改ChargingPrice失败
                            if (!retCodeChargingPrice) {
                                transactionManager.rollback(status);
                                retMap = mapChargingPrice;
                                return retMap;
                            }
                        }
                    } else {
                        // TODO 新增或修改ServiceName错误,返回异常信息
                        transactionManager.rollback(status);
                        retMap = mapAppserviceName;
                        return retMap;
                    }
                }
            } else {
                // TODO 新增或修改CertificationCharging错误,返回异常信息
                transactionManager.rollback(status);
                retMap = mapAC;
                return retMap;
            }
        }
        LogUtil.adminlog(sqlSession, "新增计费规则", "新增了计费规则");
        transactionManager.commit(status);
        retMap.put("flag", true);
        // 修改应用对应的服务:将应用和服务关联起来
        // Set<Long> set = appserviceChargingService.getAllAppId();
        // if (null != set && set.size() >0) {
        // for (Long long1 : set) {
        // Set<Long> AppserviceIDs = appserviceChargingService.getAppserviceIDsByAppId(long1);
        // applicationInfoService.addServiceByAppInfo(long1,AppserviceIDs);
        // }
        // }
        // 通知其他机器,加载缓存
        CertificationChargingHandler cch = new CertificationChargingHandler();
        QueueThread.buildCertificationTask(cch);
        // cacheCustomer.initChargeRule();
        return retMap;
    } catch (JsonParseException e) {
        transactionManager.rollback(status);
        e.printStackTrace();
        retMap.put("retMsg", e.getMessage());
        return retMap;
    } catch (JsonMappingException e) {
        transactionManager.rollback(status);
        retMap.put("retMsg", e.getMessage());
        e.printStackTrace();
        return retMap;
    } catch (IOException e) {
        transactionManager.rollback(status);
        retMap.put("retMsg", e.getMessage());
        e.printStackTrace();
        return retMap;
    } catch (Exception e) {
        transactionManager.rollback(status);
        retMap.put("retMsg", e.getMessage());
        e.printStackTrace();
        return retMap;
    }
}
Also used : DefaultTransactionDefinition(org.springframework.transaction.support.DefaultTransactionDefinition) HashMap(java.util.HashMap) AppserviceNameList(com.itrus.portal.mobile.entity.AppserviceNameList) MobileChargingPrice(com.itrus.portal.db.MobileChargingPrice) ChargingPriceList(com.itrus.portal.mobile.entity.ChargingPriceList) TransactionStatus(org.springframework.transaction.TransactionStatus) JsonParseException(org.codehaus.jackson.JsonParseException) MobileAppserviceName(com.itrus.portal.db.MobileAppserviceName) JsonMappingException(org.codehaus.jackson.map.JsonMappingException) List(java.util.List) CertificationChargingList(com.itrus.portal.entity.CertificationChargingList) AppserviceNameList(com.itrus.portal.mobile.entity.AppserviceNameList) ArrayList(java.util.ArrayList) ChargingPriceList(com.itrus.portal.mobile.entity.ChargingPriceList) AppserviceChargingList(com.itrus.portal.mobile.entity.AppserviceChargingList) ServiceNameList(com.itrus.portal.entity.ServiceNameList) MobileAppserviceCharging(com.itrus.portal.db.MobileAppserviceCharging) IOException(java.io.IOException) AppserviceChargingWrap(com.itrus.portal.mobile.entity.AppserviceChargingWrap) JsonMappingException(org.codehaus.jackson.map.JsonMappingException) IOException(java.io.IOException) JsonParseException(org.codehaus.jackson.JsonParseException) CertificationChargingHandler(com.itrus.portal.service.CertificationChargingHandler) AppserviceChargingList(com.itrus.portal.mobile.entity.AppserviceChargingList) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Example 63 with JsonMappingException

use of org.codehaus.jackson.map.JsonMappingException in project openmrs-module-coreapps by openmrs.

the class VisitTypeHelper method getOrderedVisitTypes.

/**
 * Returns a list of ordered visit types.
 *
 * @param visitTypes All the visit types
 * @param propertyValue The visit types to order in JSON-like format
 * @param visitService
 * @return visitTypesOrdered The visit types ordered and merged with the input visit type list
 */
public List<VisitType> getOrderedVisitTypes(List<VisitType> visitTypes, String propertyValue, VisitService visitService) {
    Map<Integer, String> order = null;
    List<VisitType> visitTypesOrdered = new ArrayList<VisitType>();
    if (propertyValue != null) {
        try {
            order = new ObjectMapper().readValue(propertyValue, HashMap.class);
        } catch (JsonParseException e) {
            VisitTypeHelper.LOG.error("Unable to parse global property \"" + CoreAppsConstants.VISIT_TYPES_ORDER_PROPERTY + "\"");
        } catch (JsonMappingException e) {
            VisitTypeHelper.LOG.error("Unable to map global property \"" + CoreAppsConstants.VISIT_TYPES_ORDER_PROPERTY + "\"");
        } catch (APIException e) {
            VisitTypeHelper.LOG.error("Unable to load global property \"" + CoreAppsConstants.VISIT_TYPES_ORDER_PROPERTY + "\"");
        } catch (IOException e) {
            VisitTypeHelper.LOG.error("Unable to read global property \"" + CoreAppsConstants.VISIT_TYPES_ORDER_PROPERTY + "\"");
        }
    }
    if (order != null) {
        for (int i = 1; i <= order.size(); i++) {
            String typeUuid = order.get(Integer.toString(i));
            VisitType type = visitService.getVisitTypeByUuid(typeUuid);
            if (visitTypes.contains(type)) {
                visitTypesOrdered.add(visitService.getVisitTypeByUuid(typeUuid));
            }
        }
        for (VisitType type : visitTypes) {
            if (!order.containsValue(type.getUuid())) {
                visitTypesOrdered.add(type);
            }
        }
    }
    if (!(visitTypes.size() == visitTypesOrdered.size())) {
        VisitTypeHelper.LOG.warn("Visit Types order property is not used.");
        return visitTypes;
    }
    return visitTypesOrdered;
}
Also used : HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) ArrayList(java.util.ArrayList) IOException(java.io.IOException) JsonParseException(org.codehaus.jackson.JsonParseException) APIException(org.openmrs.api.APIException) JsonMappingException(org.codehaus.jackson.map.JsonMappingException) VisitType(org.openmrs.VisitType) ObjectMapper(org.codehaus.jackson.map.ObjectMapper)

Example 64 with JsonMappingException

use of org.codehaus.jackson.map.JsonMappingException in project BetterBatteryStats by asksven.

the class ReferenceDto method toJson.

/**
 * Serialize to JSON
 * @return
 */
private byte[] toJson() {
    byte[] ret = null;
    StringWriter buffer = new StringWriter();
    ObjectMapper mapper = new ObjectMapper();
    // mapper.setSerializationInclusion(JsonInclude.Include.ALWAYS);
    try {
        ret = mapper.writeValueAsBytes(this);
    // mapper.writeValue(buffer, this);
    // ret = buffer.toString();
    } catch (JsonGenerationException e) {
        e.printStackTrace();
    } catch (JsonMappingException e) {
        e.printStackTrace();
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    return ret;
}
Also used : StringWriter(java.io.StringWriter) JsonMappingException(org.codehaus.jackson.map.JsonMappingException) IOException(java.io.IOException) JsonGenerationException(org.codehaus.jackson.JsonGenerationException) ObjectMapper(org.codehaus.jackson.map.ObjectMapper)

Example 65 with JsonMappingException

use of org.codehaus.jackson.map.JsonMappingException in project coprhd-controller by CoprHD.

the class ServiceCodeExceptionMapperTest method jsonMappingException.

@Test
public void jsonMappingException() {
    final JsonMappingException exception = new JsonMappingException("Failed to map JSON content to a Java class");
    assertException("Failed to map JSON content to a Java class", 1013, "Bad request body", 400, exception);
}
Also used : JsonMappingException(org.codehaus.jackson.map.JsonMappingException) Test(org.junit.Test)

Aggregations

JsonMappingException (org.codehaus.jackson.map.JsonMappingException)88 IOException (java.io.IOException)79 JsonParseException (org.codehaus.jackson.JsonParseException)53 ObjectMapper (org.codehaus.jackson.map.ObjectMapper)36 JsonGenerationException (org.codehaus.jackson.JsonGenerationException)27 ArrayList (java.util.ArrayList)24 HashMap (java.util.HashMap)19 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)15 Response (javax.ws.rs.core.Response)13 Map (java.util.Map)11 List (java.util.List)10 GET (javax.ws.rs.GET)10 Path (javax.ws.rs.Path)10 Produces (javax.ws.rs.Produces)10 WebApplicationException (javax.ws.rs.WebApplicationException)10 TypeReference (org.codehaus.jackson.type.TypeReference)10 ResponseBody (org.springframework.web.bind.annotation.ResponseBody)7 ClientResponse (com.sun.jersey.api.client.ClientResponse)6 StringWriter (java.io.StringWriter)5 Enterprise (com.itrus.portal.db.Enterprise)4