@Override public Object process0( Session session, HttpServletRequest req, HttpServletResponse resp, Map<String, String[]> map) throws Exception { logger.debug("PutServiceHealthEvent Process0"); unmarshall(req, map); ServiceBean serviceBean = (ServiceBean) session .createCriteria(ServiceBean.class) .add(Restrictions.eq("serviceNameAbbreviation", serviceAbbreviation)) .uniqueResult(); if (null == serviceBean) { throw ErrorResponse.invlidData("Service is invalid"); } /* ServiceHealthEventBean preExistingString = (ServiceHealthEventBean)session .createCriteria(ServiceHealthEventBean.class) .add(Restrictions.eq("serviceHealthEventDescription", healthEventDescription)) .uniqueResult() ; if( preExistingString != null ) { logger.debug("Found existing record:" + preExistingString.getId()); serviceHealthEventBean = preExistingString ; return Constants.EMPTYSTRING; } */ serviceHealthEventBean = new ServiceHealthEventBean( serviceBean, region, availabilityZone, healthEventDescription, serviceHealthStatus); try { // The goal was to keep duplicate strings from our list // Hibernate does enforce unique constraints on Save(), but // it seemed the session wasn't active and could not lookup // the ID of the item that caused the constraint violation to // prevent duplicate strings session.save(serviceHealthEventBean); } catch (Exception ex) { logger.debug("PutServiceHealthEvent exception on save"); logger.debug(ex.getMessage()); } logger.info("-------------------------------------------------"); return MonitorConstants.EMPTYSTRING; }
public void unmarshall(HttpServletRequest req, Map<String, String[]> map) { logger.debug("Unmarshalling PutServiceHealthEvent"); serviceAbbreviation = QueryUtil.requiredString(map, "Service"); region = QueryUtil.getString(map, "Region"); availabilityZone = QueryUtil.getString(map, "AvailabilityZone"); final String status = QueryUtil.requiredString(map, "Status"); serviceHealthStatus = ServiceHealthStatus.valueOf(status); healthEventDescription = req.getParameter("HealthEventDescription"); if (healthEventDescription == null || healthEventDescription.length() == 0) { throw ErrorResponse.invlidData("HealthEventDescription is required"); } }