/** * Guardar datos de una notificación rotavirus (agregar o actualizar) * * @param request con los datos de la notificación * @param response con el resultado de la acción * @throws ServletException * @throws IOException */ @RequestMapping( value = "save", method = RequestMethod.POST, consumes = MediaType.APPLICATION_JSON_VALUE, produces = "application/json") protected void save(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { String json = ""; String resultado = ""; String idNotificacion = ""; try { logger.debug("Guardando datos de Ficha Rotavirus"); BufferedReader br = new BufferedReader(new InputStreamReader(request.getInputStream(), "UTF8")); json = br.readLine(); FichaRotavirus fichaRotavirus = jSonToFichaRotavirus(json); if (fichaRotavirus.getDaNotificacion() == null) { DaNotificacion noti = guardarNotificacion(json, request); fichaRotavirus.setDaNotificacion(noti); } else { if (fichaRotavirus.getFechaInicioDiarrea() != null) { fichaRotavirus .getDaNotificacion() .setFechaInicioSintomas(fichaRotavirus.getFechaInicioDiarrea()); daNotificacionService.updateNotificacion(fichaRotavirus.getDaNotificacion()); } } rotaVirusService.saveOrUpdate(fichaRotavirus); idNotificacion = fichaRotavirus.getDaNotificacion().getIdNotificacion(); } catch (Exception ex) { logger.error(ex.getMessage(), ex); ex.printStackTrace(); resultado = messageSource.getMessage("msg.error.save.rota", null, null); resultado = resultado + ". \n " + ex.getMessage(); } finally { Map<String, String> map = new HashMap<String, String>(); map.put("mensaje", resultado); map.put("idNotificacion", idNotificacion); String jsonResponse = new Gson().toJson(map); response.getOutputStream().write(jsonResponse.getBytes()); response.getOutputStream().close(); } }