List of usage examples for java.time LocalTime parse
public static LocalTime parse(CharSequence text)
From source file:com.gigglinggnus.controllers.StudentMakeAppointmentController.java
/** * * @param request servlet request//w w w.j a va 2 s. c o m * @param response servlet response * @throws ServletException if a servlet-specific error occurs * @throws IOException if an I/O error occurs */ @Override protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { EntityManager em = (EntityManager) request.getSession().getAttribute("em"); String msg = request.getParameter("msg"); User user = (User) (request.getSession().getAttribute("user")); Clock clk = (Clock) (request.getSession().getAttribute("clock")); if (msg.equals("lookup_student")) { String studId = request.getParameter("studentId"); List<Exam> exams = user.getRegistrableExams(); JSONObject json = new JSONObject(); json.put("students_idNumber", studId); json.put("firstName", user.getFirstName()); json.put("lastName", user.getLastName()); JSONArray jExams = new JSONArray(); for (Exam exam : exams) { JSONObject elem = new JSONObject(); String examId = exam.getExamId(); String termId = exam.getTerm().getTermId(); String start = exam.getInterval().getStart().atZone(ZoneId.systemDefault()).toLocalDate() .toString(); String end = exam.getInterval().getEnd().atZone(ZoneId.systemDefault()).toLocalDate().toString(); elem.put("examId", examId); elem.put("termId", termId); if (exam instanceof CourseExam) { String courseId = ((CourseExam) exam).getCourse().getCourseId(); elem.put("courseId", courseId); elem.put("examType", "Course"); } else { elem.put("courseId", "N/A"); elem.put("examType", "AdHoc"); } elem.put("start", start); elem.put("end", end); jExams.put(elem); } json.put("exams", jExams); response.getWriter().write(json.toString()); } else if (msg.equals("exam_available_timeslots")) { String examId = request.getParameter("examId"); String dateStr = request.getParameter("date"); Exam exam = em.find(Exam.class, examId); LocalDate apptDate = LocalDate.parse(dateStr); List<LocalTime> timeslots = exam.getTimeslotsForDay(apptDate); JSONObject json = new JSONObject(); json.put("examId", examId); JSONArray jTimeSlots = new JSONArray(); for (LocalTime timeslot : timeslots) { String start = timeslot.toString(); String end = timeslot.plus(exam.getDuration()).toString(); JSONObject elem = new JSONObject(); elem.put("start", start); elem.put("end", end); jTimeSlots.put(elem); } json.put("timeSlots", jTimeSlots); response.getWriter().write(json.toString()); } else if (msg.equals("submit-appointment")) { String studId = request.getParameter("studentId"); String examId = request.getParameter("examId"); String stDate = request.getParameter("examDate"); String stTime = request.getParameter("startTime") + ":00"; String stSeat = request.getParameter("seatType"); Exam exam = em.find(Exam.class, examId); LocalDate lDate = LocalDate.parse(stDate); LocalTime lTime = LocalTime.parse(stTime); Instant inst = ZonedDateTime.of(lDate, lTime, ZoneId.systemDefault()).toInstant(); JSONObject json = new JSONObject(); try { em.getTransaction().begin(); user.makeAppointment(exam, inst, clk); em.getTransaction().commit(); json.put("success", "Appointment Made!"); response.getWriter().write(json.toString()); } catch (Exception e) { em.getTransaction().rollback(); json.put("error", e.toString()); response.getWriter().write(json.toString()); } } else { JSONObject json = new JSONObject(); json.put("error", msg); response.getWriter().write(json.toString()); } }
From source file:com.gigglinggnus.controllers.AdminMakeAppointmentController.java
/** * * @param request servlet request/* www . j av a 2 s .c om*/ * @param response servlet response * @throws ServletException if a servlet-specific error occurs * @throws IOException if an I/O error occurs */ @Override protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { EntityManager em = (EntityManager) request.getSession().getAttribute("em"); String msg = request.getParameter("msg"); User user = (User) (request.getSession().getAttribute("user")); Clock clk = (Clock) (request.getSession().getAttribute("clock")); if (msg.equals("lookup_student")) { String studId = request.getParameter("studentId"); User student = em.find(User.class, studId); List<Exam> exams = student.getRegistrableExams(); JSONObject json = new JSONObject(); json.put("students_idNumber", studId); json.put("firstName", student.getFirstName()); json.put("lastName", student.getLastName()); JSONArray jExams = new JSONArray(); for (Exam exam : exams) { JSONObject elem = new JSONObject(); String examId = exam.getExamId(); String termId = exam.getTerm().getTermId(); String start = exam.getInterval().getStart().atZone(ZoneId.systemDefault()).toLocalDate() .toString(); String end = exam.getInterval().getEnd().atZone(ZoneId.systemDefault()).toLocalDate().toString(); elem.put("examId", examId); elem.put("termId", termId); if (exam instanceof CourseExam) { String courseId = ((CourseExam) exam).getCourse().getCourseId(); elem.put("courseId", courseId); elem.put("examType", "Course"); } else { elem.put("courseId", "N/A"); elem.put("examType", "AdHoc"); } elem.put("start", start); elem.put("end", end); jExams.put(elem); } json.put("exams", jExams); response.getWriter().write(json.toString()); } else if (msg.equals("exam_available_timeslots")) { String examId = request.getParameter("examId"); String dateStr = request.getParameter("date"); Exam exam = em.find(Exam.class, examId); LocalDate apptDate = LocalDate.parse(dateStr); List<LocalTime> timeslots = exam.getTimeslotsForDay(apptDate); JSONObject json = new JSONObject(); json.put("examId", examId); JSONArray jTimeSlots = new JSONArray(); for (LocalTime timeslot : timeslots) { String start = timeslot.toString(); String end = timeslot.plus(exam.getDuration()).toString(); JSONObject elem = new JSONObject(); elem.put("start", start); elem.put("end", end); jTimeSlots.put(elem); } json.put("timeSlots", jTimeSlots); response.getWriter().write(json.toString()); } else if (msg.equals("submit-appointment")) { String studId = request.getParameter("studentId"); String examId = request.getParameter("examId"); String stDate = request.getParameter("examDate"); String stTime = request.getParameter("startTime") + ":00"; String stSeat = request.getParameter("seatType"); User student = em.find(User.class, studId); Exam exam = em.find(Exam.class, examId); LocalDate lDate = LocalDate.parse(stDate); LocalTime lTime = LocalTime.parse(stTime); Instant inst = ZonedDateTime.of(lDate, lTime, ZoneId.systemDefault()).toInstant(); JSONObject json = new JSONObject(); try { em.getTransaction().begin(); if (stSeat.equals("normal")) { user.makeAppointment(student, Seating.NORMAL, exam, inst, clk); em.getTransaction().commit(); json.put("success", "Appointment Made!"); response.getWriter().write(json.toString()); } else if (stSeat.equals("setaside")) { user.makeAppointment(student, Seating.SETASIDE, exam, inst, clk); em.getTransaction().commit(); json.put("success", "Appointment Made!"); response.getWriter().write(json.toString()); } else { em.getTransaction().rollback(); json.put("error", "invalid choice of seating"); response.getWriter().write(json.toString()); } } catch (Exception e) { em.getTransaction().rollback(); json.put("error", e.toString()); response.getWriter().write(json.toString()); } } else { JSONObject json = new JSONObject(); json.put("error", msg); response.getWriter().write(json.toString()); } }
From source file:fll.scheduler.TournamentSchedule.java
/** * Parse a time from a schedule. This method allows only hours and minutes to * be// w w w .j a va 2 s .c om * specified and still have times in the afternoon. If there is any time that * has an hour before {@link #EARLIEST_HOUR} the time is assumed to be in the * afternoon. * * @param str a string representing a schedule time, if null the return value * is null, if empty the return value is null * @return the {@link LocalTime} object for the string * @throws DateTimeParseException if the string could not be parsed as a time * for a schedule */ public static LocalTime parseTime(final String str) throws DateTimeParseException { if (null == str || str.trim().isEmpty()) { return null; } try { // first try with the generic parser final LocalTime time = LocalTime.parse(str); return time; } catch (final DateTimeParseException e) { // try with seconds and AM/PM try { final LocalTime time = LocalTime.parse(str, TIME_FORMAT_AM_PM_SS); return time; } catch (final DateTimeParseException ampme) { // then try with 24-hour clock final LocalTime time = LocalTime.parse(str, INPUT_TIME_FORMAT); if (time.getHour() < EARLIEST_HOUR) { // no time should be this early, it must be the afternoon. return time.plusHours(12); } else { return time; } } } }
From source file:dpfmanager.shell.modules.periodic.core.ControllerWindows.java
public PeriodicCheck parseXmlString(String xmlTask, String uuid) { try {/*from w w w . ja v a2 s.co m*/ boolean preIssue250 = true; InputStream is = IOUtils.toInputStream(xmlTask, "UTF-16"); DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance(); DocumentBuilder dBuilder = dbFactory.newDocumentBuilder(); Document doc = dBuilder.parse(is); // Parse input & configuration String arguments = doc.getDocumentElement().getElementsByTagName("Arguments").item(0).getTextContent(); if (arguments.startsWith("\"")) { preIssue250 = false; arguments = arguments.substring(arguments.substring(1).indexOf("\"") + 3, arguments.length()); } String input = getInputFromArguments(arguments); String configuration = getConfigurationFromArguments(arguments); // Parse periodicity Periodicity periodicity = new Periodicity(); Periodicity.Mode mode; NodeList schDay = doc.getDocumentElement().getElementsByTagName("ScheduleByDay"); NodeList schWeek = doc.getDocumentElement().getElementsByTagName("ScheduleByWeek"); NodeList schMonth = doc.getDocumentElement().getElementsByTagName("ScheduleByMonth"); if (schDay.getLength() > 0) { periodicity.setMode(Periodicity.Mode.DAILY); } else if (schWeek.getLength() > 0) { periodicity.setMode(Periodicity.Mode.WEEKLY); Element elemWeek = (Element) schWeek.item(0); Node node = elemWeek.getElementsByTagName("DaysOfWeek").item(0); NodeList childs = node.getChildNodes(); for (int i = 0; i < childs.getLength(); i++) { Node child = childs.item(i); if (child.getNodeType() == Node.ELEMENT_NODE) { Element elem = (Element) child; periodicity.addDaysOfWeek(parseDayName(elem.getTagName())); } } } else if (schMonth.getLength() > 0) { periodicity.setMode(Periodicity.Mode.MONTHLY); Element elem = (Element) schMonth.item(0); String dayStr = elem.getElementsByTagName("Day").item(0).getTextContent(); periodicity.setDayOfMonth(Integer.parseInt(dayStr)); } // Parse time String timeStr = doc.getDocumentElement().getElementsByTagName("StartBoundary").item(0) .getTextContent(); String time = timeStr.substring(11, 16); periodicity.setTime(LocalTime.parse(time)); is.close(); PeriodicCheck pc = new PeriodicCheck(uuid, input, configuration, periodicity); if (preIssue250) { editPeriodicalCheck(pc); } return pc; } catch (Exception e) { e.printStackTrace(); } return null; }
From source file:org.ojbc.adapters.analyticsstaging.custody.CamelContextPimaTest.java
@Test public void testBookingReportServiceRoute() throws Exception, IOException { Exchange senderExchange = createSenderExchange( "src/test/resources/xmlInstances/bookingReport/BookingReport-Pima.xml"); Person person = analyticalDatastoreDAO.getPerson(1); Assert.assertNull(person);//from w ww . jav a 2 s .co m Booking booking = analyticalDatastoreDAO.getBookingByBookingNumber("eDocumentID"); assertNull(booking); List<BookingCharge> bookingCharges = analyticalDatastoreDAO.getBookingCharges(1); assertTrue(bookingCharges.isEmpty()); List<BookingArrest> bookingArrests = analyticalDatastoreDAO.getBookingArrests(1); assertTrue(bookingArrests.isEmpty()); //Send the one-way exchange. Using template.send will send an one way message Exchange returnExchange = template.send("direct:bookingReportServiceEndpoint", senderExchange); //Use getException to see if we received an exception if (returnExchange.getException() != null) { throw new Exception(returnExchange.getException()); } person = analyticalDatastoreDAO.getPerson(1); Assert.assertNotNull(person); Assert.assertEquals(Integer.valueOf(1), person.getPersonId()); assertThat(person.getPersonSexId(), is(3)); assertThat(person.getPersonRaceId(), is(5)); assertThat(person.getPersonSexDescription(), is("Unknown")); assertThat(person.getPersonRaceDescription(), is("Caucasian")); assertThat(person.getLanguage(), is("English Speaker")); assertThat(person.getPersonBirthDate(), is(LocalDate.parse("1969-01-01"))); Assert.assertEquals("e807f1fcf82d132f9bb018ca6738a19f", person.getPersonUniqueIdentifier()); assertThat(person.getLanguageId(), is(41)); assertThat(person.getSexOffenderStatusTypeId(), nullValue()); assertNull(person.getMilitaryServiceStatusType().getValue()); assertNull(person.getEducationLevel()); assertNull(person.getOccupation()); assertThat(person.getDomicileStatusTypeId(), is(2)); assertThat(person.getProgramEligibilityTypeId(), is(2)); List<BehavioralHealthAssessment> behavioralHealthAssessments = analyticalDatastoreDAO .getBehavioralHealthAssessments(1); assertFalse(behavioralHealthAssessments.isEmpty()); BehavioralHealthAssessment behavioralHealthAssessment = behavioralHealthAssessments.get(0); assertTrue(behavioralHealthAssessment.getBehavioralHealthDiagnoses().size() == 1); assertThat(behavioralHealthAssessment.getBehavioralHealthDiagnoses().get(0), is("Schizophrenia 295.10")); assertThat(behavioralHealthAssessment.getPersonId(), is(1)); assertThat(behavioralHealthAssessment.getBehavioralHealthAssessmentId(), is(1)); assertThat(behavioralHealthAssessment.getSeriousMentalIllness(), is(true)); assertThat(behavioralHealthAssessment.getCareEpisodeStartDate(), is(LocalDate.parse("2016-01-01"))); assertThat(behavioralHealthAssessment.getCareEpisodeEndDate(), is(LocalDate.parse("2016-04-01"))); assertThat(behavioralHealthAssessment.getEnrolledProviderName(), is("79")); assertThat(behavioralHealthAssessment.getMedicaidStatusTypeId(), is(2)); List<Treatment> treatments = analyticalDatastoreDAO.getTreatments(1); assertThat(treatments.size(), is(1)); Treatment treatment = treatments.get(0); assertThat(treatment.getBehavioralHealthAssessmentID(), is(1)); assertThat(treatment.getTreatmentStartDate(), is(LocalDate.parse("2016-01-01"))); assertThat(treatment.getTreatmentAdmissionReasonTypeId(), nullValue()); assertThat(treatment.getTreatmentStatusTypeId(), nullValue()); assertThat(treatment.getTreatmentProviderName(), is("Treatment Providing Organization Name")); List<PrescribedMedication> prescribedMedications = analyticalDatastoreDAO.getPrescribedMedication(1); assertThat(prescribedMedications.size(), is(1)); PrescribedMedication prescribedMedication = prescribedMedications.get(0); assertThat(prescribedMedication.getBehavioralHealthAssessmentID(), is(1)); assertThat(prescribedMedication.getMedicationDescription(), is("Zyprexa")); assertThat(prescribedMedication.getMedicationDispensingDate(), is(LocalDate.parse("2016-01-01"))); assertThat(prescribedMedication.getMedicationDoseMeasure(), is("3mg")); booking = analyticalDatastoreDAO.getBookingByBookingNumber("234567890"); assertNotNull(booking); assertEquals(LocalDate.parse("2016-05-12"), booking.getBookingDate()); assertEquals(LocalTime.parse("00:36:00"), booking.getBookingTime()); assertThat(booking.getFacilityId(), is(1)); assertThat(booking.getSupervisionUnitTypeId(), is(84)); assertEquals("234567890", booking.getBookingNumber()); assertNull(booking.getScheduledReleaseDate()); assertThat(booking.getInmateJailResidentIndicator(), is(false)); bookingArrests = analyticalDatastoreDAO.getBookingArrests(1); assertThat(bookingArrests.size(), is(1)); BookingArrest bookingArrest = bookingArrests.get(0); assertTrue(bookingArrest.getBookingId() == 1); assertTrue(bookingArrest.getBookingArrestId() == 1); assertTrue(bookingArrest.getAddress().isEmpty()); assertThat(bookingArrest.getArrestAgencyId(), is(16)); bookingCharges = analyticalDatastoreDAO.getBookingCharges(1); assertThat(bookingCharges.size(), is(1)); BookingCharge bookingCharge = bookingCharges.get(0); assertThat(bookingCharge.getChargeCode(), is("ARS13-1105")); assertNull(bookingCharge.getChargeDisposition()); assertTrue(bookingCharge.getBookingArrestId() == 1); assertTrue(bookingCharge.getBondAmount().doubleValue() == 250000.00); assertThat(bookingCharge.getBondType(), nullValue()); assertThat(bookingCharge.getAgencyId(), nullValue()); assertThat(bookingCharge.getChargeClassTypeId(), is(2)); assertThat(bookingCharge.getBondStatusTypeId(), is(1)); assertThat(bookingCharge.getChargeJurisdictionTypeId(), is(8)); CustodyRelease custodyRelease = analyticalDatastoreDAO.getCustodyReleaseByBookingId(1); assertNull(custodyRelease); }
From source file:org.ojbc.adapters.analyticsstaging.custody.CamelContextAdamsWrongOrderTest.java
public void testCustodyStatusChangeReportService() throws Exception { Exchange senderExchange = createSenderExchange( "src/test/resources/xmlInstances/custodyStatusChangeReport/CustodyStatusChangeReport-Adams.xml"); Person person = analyticalDatastoreDAO.getPerson(1); Assert.assertNull(person);/*from w w w. j ava2 s. co m*/ List<CustodyStatusChange> custodyStatusChanges = analyticalDatastoreDAO .getCustodyStatusChangesByBookingId(1); assertTrue(custodyStatusChanges.isEmpty()); List<CustodyStatusChangeCharge> custodyStatusChangeCharges = analyticalDatastoreDAO .getCustodyStatusChangeCharges(1); assertTrue(custodyStatusChangeCharges.isEmpty()); //Send the one-way exchange. Using template.send will send an one way message Exchange returnExchange = template.send("direct:custodyStatusChangeReportingService", senderExchange); //Use getException to see if we received an exception if (returnExchange.getException() != null) { throw new Exception(returnExchange.getException()); } person = analyticalDatastoreDAO.getPerson(1); Assert.assertNotNull(person); assertThat(person.getPersonId(), is(1)); assertThat(person.getDomicileStatusTypeId(), nullValue()); assertThat(person.getPersonUniqueIdentifier2(), is("Booking Subject Number")); assertThat(person.getEducationLevel(), is("High School Graduate")); assertThat(person.getOccupation(), is("Truck Driver")); assertThat(person.getMilitaryServiceStatusType().getValue(), is("Active")); List<BehavioralHealthAssessment> behavioralHealthAssessments = analyticalDatastoreDAO .getBehavioralHealthAssessments(1); assertThat(behavioralHealthAssessments.size(), is(1)); BehavioralHealthAssessment behavioralHealthAssessment = behavioralHealthAssessments.get(0); assertTrue(behavioralHealthAssessment.getBehavioralHealthDiagnoses().size() == 1); assertThat(behavioralHealthAssessment.getBehavioralHealthDiagnoses().get(0), is("Schizophrenia 295.10")); assertThat(behavioralHealthAssessment.getPersonId(), is(1)); assertThat(behavioralHealthAssessment.getBehavioralHealthAssessmentId(), is(1)); assertThat(behavioralHealthAssessment.getSeriousMentalIllness(), is(true)); assertThat(behavioralHealthAssessment.getCareEpisodeStartDate(), is(LocalDate.parse("2016-01-01"))); assertThat(behavioralHealthAssessment.getCareEpisodeEndDate(), is(LocalDate.parse("2016-04-01"))); assertThat(behavioralHealthAssessment.getEnrolledProviderName(), is("79")); assertThat(behavioralHealthAssessment.getMedicaidStatusTypeId(), nullValue()); List<Treatment> treatments = analyticalDatastoreDAO.getTreatments(1); assertThat(treatments.size(), is(1)); Treatment treatment = treatments.get(0); assertThat(treatment.getBehavioralHealthAssessmentID(), is(1)); assertThat(treatment.getTreatmentStartDate(), is(LocalDate.parse("2016-01-01"))); assertThat(treatment.getTreatmentAdmissionReasonTypeId(), nullValue()); assertThat(treatment.getTreatmentStatusTypeId(), nullValue()); assertThat(treatment.getTreatmentProviderName(), is("Treatment Providing Organization Name")); List<PrescribedMedication> prescribedMedications = analyticalDatastoreDAO.getPrescribedMedication(1); assertThat(prescribedMedications.size(), is(1)); PrescribedMedication prescribedMedication = prescribedMedications.get(0); assertThat(prescribedMedication.getBehavioralHealthAssessmentID(), is(1)); assertThat(prescribedMedication.getMedicationDescription(), is("Zyprexa")); assertThat(prescribedMedication.getMedicationDispensingDate(), is(LocalDate.parse("2016-01-01"))); assertThat(prescribedMedication.getMedicationDoseMeasure(), is("3mg")); custodyStatusChanges = analyticalDatastoreDAO.getCustodyStatusChangesByBookingNumber("Booking Number"); assertThat(custodyStatusChanges.size(), is(1)); CustodyStatusChange custodyStatusChange = custodyStatusChanges.get(0); assertEquals(LocalDate.parse("2013-12-17"), custodyStatusChange.getBookingDate()); assertEquals(LocalTime.parse("09:30"), custodyStatusChange.getBookingTime()); assertThat(custodyStatusChange.getFacilityId(), is(2)); assertThat(custodyStatusChange.getSupervisionUnitTypeId(), is(10)); assertThat(custodyStatusChange.getBookingId(), nullValue()); assertThat(custodyStatusChange.getBookingNumber(), is("Booking Number")); assertThat(custodyStatusChange.getScheduledReleaseDate(), is(LocalDate.parse("2014-12-17"))); assertThat(custodyStatusChange.getInmateJailResidentIndicator(), is(false)); List<CustodyStatusChangeArrest> custodyStatusChangeArrests = analyticalDatastoreDAO .getCustodyStatusChangeArrests(1); assertThat(custodyStatusChangeArrests.size(), is(1)); CustodyStatusChangeArrest custodyStatusChangeArrest = custodyStatusChangeArrests.get(0); assertThat(custodyStatusChangeArrest.getCustodyStatusChangeId(), is(1)); assertThat(custodyStatusChangeArrest.getCustodyStatusChangeArrestId(), is(1)); assertEquals("30", custodyStatusChangeArrest.getAddress().getStreetNumber()); assertEquals("Main Street", custodyStatusChangeArrest.getAddress().getStreetName()); assertEquals("Denton", custodyStatusChangeArrest.getAddress().getCity()); assertEquals("CO", custodyStatusChangeArrest.getAddress().getState()); assertEquals("99999", custodyStatusChangeArrest.getAddress().getPostalcode()); assertTrue(custodyStatusChangeArrest.getAddress().getLocationLatitude().doubleValue() == 56.1111); assertTrue(custodyStatusChangeArrest.getAddress().getLocationLongitude().doubleValue() == 32.1111); assertThat(custodyStatusChangeArrest.getArrestAgencyId(), is(22)); custodyStatusChangeCharges = analyticalDatastoreDAO.getCustodyStatusChangeCharges(1); assertThat(custodyStatusChangeCharges.size(), is(1)); CustodyStatusChangeCharge custodyStatusChangeCharge = custodyStatusChangeCharges.get(0); assertThat(custodyStatusChangeCharge.getChargeCode(), is("Charge Code ID")); assertTrue(custodyStatusChangeCharge.getCustodyStatusChangeArrestId() == 1); assertTrue(custodyStatusChangeCharge.getBondAmount().doubleValue() == 500.00); assertThat(custodyStatusChangeCharge.getBondType().getValue(), is("PR BOND")); assertThat(custodyStatusChangeCharge.getAgencyId(), is(21)); assertThat(custodyStatusChangeCharge.getChargeClassTypeId(), is(2)); assertThat(custodyStatusChangeCharge.getBondStatusTypeId(), is(11)); assertThat(custodyStatusChangeCharge.getChargeJurisdictionTypeId(), is(2)); assertThat(custodyStatusChangeCharge.getChargeDisposition(), is("Disposition")); }
From source file:org.ojbc.adapters.analyticsstaging.custody.CamelContextAdamsTest.java
public void testCustodyStatusChangeReportService() throws Exception { Exchange senderExchange = createSenderExchange( "src/test/resources/xmlInstances/custodyStatusChangeReport/CustodyStatusChangeReport-Adams.xml"); Person person = analyticalDatastoreDAO.getPerson(1); Assert.assertNotNull(person);/* ww w .jav a 2s .c o m*/ List<CustodyStatusChange> custodyStatusChanges = analyticalDatastoreDAO .getCustodyStatusChangesByBookingId(1); assertTrue(custodyStatusChanges.isEmpty()); List<CustodyStatusChangeCharge> custodyStatusChangeCharges = analyticalDatastoreDAO .getCustodyStatusChangeCharges(1); assertTrue(custodyStatusChangeCharges.isEmpty()); //Send the one-way exchange. Using template.send will send an one way message Exchange returnExchange = template.send("direct:custodyStatusChangeReportingService", senderExchange); //Use getException to see if we received an exception if (returnExchange.getException() != null) { throw new Exception(returnExchange.getException()); } person = analyticalDatastoreDAO.getPerson(1); Assert.assertNotNull(person); Person person2 = analyticalDatastoreDAO.getPerson(2); Assert.assertNotNull(person2); Assert.assertEquals(Integer.valueOf(2), person2.getPersonId()); assertThat(person2.getDomicileStatusTypeId(), nullValue()); assertThat(person2.getPersonUniqueIdentifier2(), is("Booking Subject Number")); assertThat(person2.getEducationLevel(), is("High School Graduate")); assertThat(person2.getOccupation(), is("Truck Driver")); assertThat(person2.getMilitaryServiceStatusType().getValue(), is("Active")); List<BehavioralHealthAssessment> behavioralHealthAssessments = analyticalDatastoreDAO .getBehavioralHealthAssessments(2); assertThat(behavioralHealthAssessments.size(), is(1)); BehavioralHealthAssessment behavioralHealthAssessment = behavioralHealthAssessments.get(0); assertTrue(behavioralHealthAssessment.getBehavioralHealthDiagnoses().size() == 1); assertThat(behavioralHealthAssessment.getBehavioralHealthDiagnoses().get(0), is("Schizophrenia 295.10")); assertThat(behavioralHealthAssessment.getPersonId(), is(2)); assertThat(behavioralHealthAssessment.getBehavioralHealthAssessmentId(), is(2)); assertThat(behavioralHealthAssessment.getSeriousMentalIllness(), is(true)); assertThat(behavioralHealthAssessment.getCareEpisodeStartDate(), is(LocalDate.parse("2016-01-01"))); assertThat(behavioralHealthAssessment.getCareEpisodeEndDate(), is(LocalDate.parse("2016-04-01"))); assertThat(behavioralHealthAssessment.getEnrolledProviderName(), is("79")); assertThat(behavioralHealthAssessment.getMedicaidStatusTypeId(), nullValue()); List<Treatment> treatments = analyticalDatastoreDAO.getTreatments(2); assertThat(treatments.size(), is(1)); Treatment treatment = treatments.get(0); assertThat(treatment.getBehavioralHealthAssessmentID(), is(2)); assertThat(treatment.getTreatmentStartDate(), is(LocalDate.parse("2016-01-01"))); assertThat(treatment.getTreatmentAdmissionReasonTypeId(), nullValue()); assertThat(treatment.getTreatmentStatusTypeId(), nullValue()); assertThat(treatment.getTreatmentProviderName(), is("Treatment Providing Organization Name")); List<PrescribedMedication> prescribedMedications = analyticalDatastoreDAO.getPrescribedMedication(2); assertThat(prescribedMedications.size(), is(1)); PrescribedMedication prescribedMedication = prescribedMedications.get(0); assertThat(prescribedMedication.getBehavioralHealthAssessmentID(), is(2)); assertThat(prescribedMedication.getMedicationDescription(), is("Zyprexa")); assertThat(prescribedMedication.getMedicationDispensingDate(), is(LocalDate.parse("2016-01-01"))); assertThat(prescribedMedication.getMedicationDoseMeasure(), is("3mg")); custodyStatusChanges = analyticalDatastoreDAO.getCustodyStatusChangesByBookingId(1); assertThat(custodyStatusChanges.size(), is(1)); CustodyStatusChange custodyStatusChange = custodyStatusChanges.get(0); assertEquals(LocalDate.parse("2013-12-17"), custodyStatusChange.getBookingDate()); assertEquals(LocalTime.parse("09:30"), custodyStatusChange.getBookingTime()); assertThat(custodyStatusChange.getFacilityId(), is(2)); assertThat(custodyStatusChange.getSupervisionUnitTypeId(), is(10)); assertThat(custodyStatusChange.getBookingId(), is(1)); assertThat(custodyStatusChange.getBookingNumber(), is("Booking Number")); assertThat(custodyStatusChange.getScheduledReleaseDate(), is(LocalDate.parse("2014-12-17"))); assertThat(custodyStatusChange.getInmateJailResidentIndicator(), is(false)); List<CustodyStatusChangeArrest> custodyStatusChangeArrests = analyticalDatastoreDAO .getCustodyStatusChangeArrests(1); assertThat(custodyStatusChangeArrests.size(), is(1)); CustodyStatusChangeArrest custodyStatusChangeArrest = custodyStatusChangeArrests.get(0); assertThat(custodyStatusChangeArrest.getCustodyStatusChangeId(), is(1)); assertThat(custodyStatusChangeArrest.getCustodyStatusChangeArrestId(), is(1)); assertEquals("30", custodyStatusChangeArrest.getAddress().getStreetNumber()); assertEquals("Main Street", custodyStatusChangeArrest.getAddress().getStreetName()); assertEquals("Denton", custodyStatusChangeArrest.getAddress().getCity()); assertEquals("CO", custodyStatusChangeArrest.getAddress().getState()); assertEquals("99999", custodyStatusChangeArrest.getAddress().getPostalcode()); assertTrue(custodyStatusChangeArrest.getAddress().getLocationLatitude().doubleValue() == 56.1111); assertTrue(custodyStatusChangeArrest.getAddress().getLocationLongitude().doubleValue() == 32.1111); assertThat(custodyStatusChangeArrest.getArrestAgencyId(), is(22)); custodyStatusChangeCharges = analyticalDatastoreDAO.getCustodyStatusChangeCharges(1); assertThat(custodyStatusChangeCharges.size(), is(1)); CustodyStatusChangeCharge custodyStatusChangeCharge = custodyStatusChangeCharges.get(0); assertThat(custodyStatusChangeCharge.getChargeCode(), is("Charge Code ID")); assertTrue(custodyStatusChangeCharge.getCustodyStatusChangeArrestId() == 1); assertTrue(custodyStatusChangeCharge.getBondAmount().doubleValue() == 500.00); assertThat(custodyStatusChangeCharge.getBondType().getValue(), is("PR BOND")); assertThat(custodyStatusChangeCharge.getAgencyId(), is(21)); assertThat(custodyStatusChangeCharge.getChargeClassTypeId(), is(2)); assertThat(custodyStatusChangeCharge.getBondStatusTypeId(), is(11)); assertThat(custodyStatusChangeCharge.getChargeJurisdictionTypeId(), is(2)); assertThat(custodyStatusChangeCharge.getChargeDisposition(), is("Disposition")); }
From source file:org.ojbc.adapters.analyticsstaging.custody.CamelContextAdamsWrongOrderTest.java
public void testBookingReportServiceRoute() throws Exception, IOException { Exchange senderExchange = createSenderExchange( "src/test/resources/xmlInstances/bookingReport/BookingReport-Adams.xml"); Person person = analyticalDatastoreDAO.getPerson(1); Assert.assertNotNull(person);// w w w . j ava2s.co m Booking booking = analyticalDatastoreDAO.getBookingByBookingNumber("Booking Number"); assertNull(booking); List<BookingCharge> bookingCharges = analyticalDatastoreDAO.getBookingCharges(1); assertTrue(bookingCharges.isEmpty()); List<BookingArrest> bookingArrests = analyticalDatastoreDAO.getBookingArrests(1); assertTrue(bookingArrests.isEmpty()); //Send the one-way exchange. Using template.send will send an one way message Exchange returnExchange = template.send("direct:bookingReportServiceEndpoint", senderExchange); //Use getException to see if we received an exception if (returnExchange.getException() != null) { throw new Exception(returnExchange.getException()); } assertThat(jdbcTemplate.queryForObject("select count(*) from Booking", Integer.class), is(1)); person = analyticalDatastoreDAO.getPerson(2); Assert.assertNotNull(person); assertThat(person.getPersonId(), is(2)); assertThat(person.getPersonSexId(), is(2)); assertThat(person.getPersonRaceId(), is(6)); assertThat(person.getPersonSexDescription(), is("Female")); assertThat(person.getPersonRaceDescription(), is("White")); assertThat(person.getLanguage(), is("English")); assertThat(person.getPersonBirthDate(), is(LocalDate.parse("1968-12-17"))); assertThat(person.getPersonUniqueIdentifier(), is("e807f1fcf82d132f9bb018ca6738a19f")); assertThat(person.getPersonUniqueIdentifier2(), is("Booking Subject Number")); assertThat(person.getLanguageId(), is(1)); assertThat(person.getSexOffenderStatusTypeId(), is(1)); assertThat(person.getMilitaryServiceStatusType().getValue(), is("Honorable Discharge")); assertThat(person.getEducationLevel(), is("High School Graduate")); assertThat(person.getOccupation(), is("Truck Driver")); List<BehavioralHealthAssessment> behavioralHealthAssessments = analyticalDatastoreDAO .getBehavioralHealthAssessments(person.getPersonId()); assertFalse(behavioralHealthAssessments.isEmpty()); BehavioralHealthAssessment behavioralHealthAssessment = behavioralHealthAssessments.get(0); assertTrue(behavioralHealthAssessment.getBehavioralHealthDiagnoses().size() == 1); assertThat(behavioralHealthAssessment.getBehavioralHealthDiagnoses().get(0), is("Schizophrenia 295.10")); assertThat(behavioralHealthAssessment.getPersonId(), is(2)); assertThat(behavioralHealthAssessment.getBehavioralHealthAssessmentId(), is(2)); assertThat(behavioralHealthAssessment.getSeriousMentalIllness(), is(true)); assertThat(behavioralHealthAssessment.getCareEpisodeStartDate(), is(LocalDate.parse("2016-01-01"))); assertThat(behavioralHealthAssessment.getCareEpisodeEndDate(), is(LocalDate.parse("2016-04-01"))); assertThat(behavioralHealthAssessment.getEnrolledProviderName(), is("79")); assertThat(behavioralHealthAssessment.getMedicaidStatusTypeId(), nullValue()); List<Treatment> treatments = analyticalDatastoreDAO.getTreatments(2); assertThat(treatments.size(), is(1)); Treatment treatment = treatments.get(0); assertThat(treatment.getBehavioralHealthAssessmentID(), is(2)); assertThat(treatment.getTreatmentStartDate(), is(LocalDate.parse("2016-01-01"))); assertThat(treatment.getTreatmentAdmissionReasonTypeId(), nullValue()); assertThat(treatment.getTreatmentStatusTypeId(), nullValue()); assertThat(treatment.getTreatmentProviderName(), is("Treatment Providing Organization Name")); List<PrescribedMedication> prescribedMedications = analyticalDatastoreDAO.getPrescribedMedication(2); assertThat(prescribedMedications.size(), is(1)); PrescribedMedication prescribedMedication = prescribedMedications.get(0); assertThat(prescribedMedication.getBehavioralHealthAssessmentID(), is(2)); assertThat(prescribedMedication.getMedicationDescription(), is("Zyprexa")); assertThat(prescribedMedication.getMedicationDispensingDate(), is(LocalDate.parse("2016-01-01"))); assertThat(prescribedMedication.getMedicationDoseMeasure(), is("3mg")); booking = analyticalDatastoreDAO.getBookingByBookingNumber("Booking Number"); assertNotNull(booking); assertEquals(LocalDate.parse("2013-12-17"), booking.getBookingDate()); assertEquals(LocalTime.parse("09:30"), booking.getBookingTime()); assertThat(booking.getFacilityId(), is(1)); assertThat(booking.getSupervisionUnitTypeId(), nullValue()); assertEquals("Booking Number", booking.getBookingNumber()); assertEquals(LocalDate.parse("2014-12-17"), booking.getScheduledReleaseDate()); assertThat(booking.getInmateJailResidentIndicator(), is(false)); bookingArrests = analyticalDatastoreDAO.getBookingArrests(1); assertFalse(bookingArrests.isEmpty()); BookingArrest bookingArrest = bookingArrests.get(0); assertTrue(bookingArrest.getBookingId() == 1); assertTrue(bookingArrest.getBookingArrestId() == 1); assertEquals("392", bookingArrest.getAddress().getStreetNumber()); assertEquals("Woodlawn Ave", bookingArrest.getAddress().getStreetName()); assertEquals("Burlington", bookingArrest.getAddress().getCity()); assertEquals("NY", bookingArrest.getAddress().getState()); assertEquals("05408", bookingArrest.getAddress().getPostalcode()); assertTrue(bookingArrest.getAddress().getLocationLatitude().doubleValue() == 56.1111); assertTrue(bookingArrest.getAddress().getLocationLongitude().doubleValue() == 32.1111); assertThat(bookingArrest.getArrestAgencyId(), is(29)); bookingCharges = analyticalDatastoreDAO.getBookingCharges(1); assertThat(bookingCharges.size(), is(2)); BookingCharge bookingCharge = bookingCharges.get(0); assertThat(bookingCharge.getChargeCode(), is("Charge Code ID")); assertTrue(bookingCharge.getBookingArrestId() == 1); assertTrue(bookingCharge.getBondAmount().doubleValue() == 500.00); assertThat(bookingCharge.getBondType().getValue(), is("CASH/SURETY/PROPERTY")); assertThat(bookingCharge.getAgencyId(), is(21)); assertThat(bookingCharge.getChargeClassTypeId(), is(1)); assertThat(bookingCharge.getBondStatusTypeId(), is(17)); assertThat(bookingCharge.getChargeJurisdictionTypeId(), is(1)); assertThat(bookingCharge.getChargeDisposition(), is("Disposition")); CustodyRelease custodyRelease = analyticalDatastoreDAO.getCustodyReleaseByBookingId(1); log.info(custodyRelease.toString()); assertEquals(LocalDate.parse("2014-12-17"), custodyRelease.getReleaseDate()); assertEquals(LocalTime.parse("10:30"), custodyRelease.getReleaseTime()); assertThat(custodyRelease.getBookingNumber(), is("Booking Number")); assertThat(jdbcTemplate.queryForObject( "select count(*) from CustodyRelease WHERE bookingId = 1 AND bookingNumber = 'Booking Number' ", Integer.class), is(2)); assertThat(jdbcTemplate.queryForObject("select count(*) from CustodyRelease", Integer.class), is(2)); assertThat(jdbcTemplate.queryForObject( "select count(*) from CustodyStatusChange WHERE bookingId = 1 AND bookingNumber = 'Booking Number' ", Integer.class), is(1)); assertThat(jdbcTemplate.queryForObject("select count(*) from CustodyStatusChange", Integer.class), is(1)); }
From source file:org.ojbc.adapters.analyticsstaging.custody.CamelContextAdamsTest.java
public void testBookingReportServiceRoute() throws Exception, IOException { Exchange senderExchange = createSenderExchange( "src/test/resources/xmlInstances/bookingReport/BookingReport-Adams.xml"); Person person = analyticalDatastoreDAO.getPerson(1); Assert.assertNull(person);/*from ww w . ja v a 2s . c o m*/ Booking booking = analyticalDatastoreDAO.getBookingByBookingNumber("Booking Number"); assertNull(booking); List<BookingCharge> bookingCharges = analyticalDatastoreDAO.getBookingCharges(1); assertTrue(bookingCharges.isEmpty()); List<BookingArrest> bookingArrests = analyticalDatastoreDAO.getBookingArrests(1); assertTrue(bookingArrests.isEmpty()); //Send the one-way exchange. Using template.send will send an one way message Exchange returnExchange = template.send("direct:bookingReportServiceEndpoint", senderExchange); //Use getException to see if we received an exception if (returnExchange.getException() != null) { throw new Exception(returnExchange.getException()); } assertThat(jdbcTemplate.queryForObject("select count(*) from Booking", Integer.class), is(1)); person = analyticalDatastoreDAO.getPerson(1); Assert.assertNotNull(person); Assert.assertEquals(Integer.valueOf(1), person.getPersonId()); assertThat(person.getPersonSexId(), is(2)); assertThat(person.getPersonRaceId(), is(6)); assertThat(person.getPersonEthnicityTypeId(), is(1)); assertThat(person.getPersonSexDescription(), is("Female")); assertThat(person.getPersonRaceDescription(), is("White")); assertThat(person.getLanguage(), is("English")); assertThat(person.getPersonBirthDate(), is(LocalDate.parse("1968-12-17"))); assertThat(person.getPersonUniqueIdentifier(), is("e807f1fcf82d132f9bb018ca6738a19f")); assertThat(person.getPersonUniqueIdentifier2(), is("Booking Subject Number")); assertThat(person.getLanguageId(), is(1)); assertThat(person.getSexOffenderStatusTypeId(), is(1)); assertThat(person.getMilitaryServiceStatusType().getValue(), is("Honorable Discharge")); assertThat(person.getEducationLevel(), is("High School Graduate")); assertThat(person.getOccupation(), is("Truck Driver")); List<BehavioralHealthAssessment> behavioralHealthAssessments = analyticalDatastoreDAO .getBehavioralHealthAssessments(1); assertFalse(behavioralHealthAssessments.isEmpty()); BehavioralHealthAssessment behavioralHealthAssessment = behavioralHealthAssessments.get(0); assertTrue(behavioralHealthAssessment.getBehavioralHealthDiagnoses().size() == 1); assertThat(behavioralHealthAssessment.getBehavioralHealthDiagnoses().get(0), is("Schizophrenia 295.10")); assertThat(behavioralHealthAssessment.getPersonId(), is(1)); assertThat(behavioralHealthAssessment.getBehavioralHealthAssessmentId(), is(1)); assertThat(behavioralHealthAssessment.getSeriousMentalIllness(), is(true)); assertThat(behavioralHealthAssessment.getCareEpisodeStartDate(), is(LocalDate.parse("2016-01-01"))); assertThat(behavioralHealthAssessment.getCareEpisodeEndDate(), is(LocalDate.parse("2016-04-01"))); assertThat(behavioralHealthAssessment.getEnrolledProviderName(), is("79")); assertThat(behavioralHealthAssessment.getMedicaidStatusTypeId(), nullValue()); List<Treatment> treatments = analyticalDatastoreDAO.getTreatments(1); assertThat(treatments.size(), is(1)); Treatment treatment = treatments.get(0); assertThat(treatment.getBehavioralHealthAssessmentID(), is(1)); assertThat(treatment.getTreatmentStartDate(), is(LocalDate.parse("2016-01-01"))); assertThat(treatment.getTreatmentAdmissionReasonTypeId(), nullValue()); assertThat(treatment.getTreatmentStatusTypeId(), nullValue()); assertThat(treatment.getTreatmentProviderName(), is("Treatment Providing Organization Name")); List<PrescribedMedication> prescribedMedications = analyticalDatastoreDAO.getPrescribedMedication(1); assertThat(prescribedMedications.size(), is(1)); PrescribedMedication prescribedMedication = prescribedMedications.get(0); assertThat(prescribedMedication.getBehavioralHealthAssessmentID(), is(1)); assertThat(prescribedMedication.getMedicationDescription(), is("Zyprexa")); assertThat(prescribedMedication.getMedicationDispensingDate(), is(LocalDate.parse("2016-01-01"))); assertThat(prescribedMedication.getMedicationDoseMeasure(), is("3mg")); booking = analyticalDatastoreDAO.getBookingByBookingNumber("Booking Number"); assertNotNull(booking); assertEquals(LocalDate.parse("2013-12-17"), booking.getBookingDate()); assertEquals(LocalTime.parse("09:30"), booking.getBookingTime()); assertThat(booking.getFacilityId(), is(1)); assertThat(booking.getSupervisionUnitTypeId(), nullValue()); assertEquals("Booking Number", booking.getBookingNumber()); assertEquals(LocalDate.parse("2014-12-17"), booking.getScheduledReleaseDate()); assertThat(booking.getInmateJailResidentIndicator(), is(false)); bookingArrests = analyticalDatastoreDAO.getBookingArrests(1); assertFalse(bookingArrests.isEmpty()); BookingArrest bookingArrest = bookingArrests.get(0); assertTrue(bookingArrest.getBookingId() == 1); assertTrue(bookingArrest.getBookingArrestId() == 1); assertEquals("392", bookingArrest.getAddress().getStreetNumber()); assertEquals("Woodlawn Ave", bookingArrest.getAddress().getStreetName()); assertEquals("Burlington", bookingArrest.getAddress().getCity()); assertEquals("NY", bookingArrest.getAddress().getState()); assertEquals("05408", bookingArrest.getAddress().getPostalcode()); assertTrue(bookingArrest.getAddress().getLocationLatitude().doubleValue() == 56.1111); assertTrue(bookingArrest.getAddress().getLocationLongitude().doubleValue() == 32.1111); assertThat(bookingArrest.getArrestAgencyId(), is(29)); bookingCharges = analyticalDatastoreDAO.getBookingCharges(1); assertThat(bookingCharges.size(), is(2)); BookingCharge bookingCharge = bookingCharges.get(0); assertThat(bookingCharge.getChargeCode(), is("Charge Code ID")); assertTrue(bookingCharge.getBookingArrestId() == 1); assertTrue(bookingCharge.getBondAmount().doubleValue() == 500.00); assertThat(bookingCharge.getBondType().getValue(), is("CASH/SURETY/PROPERTY")); assertThat(bookingCharge.getAgencyId(), is(21)); assertThat(bookingCharge.getChargeClassTypeId(), is(1)); assertThat(bookingCharge.getBondStatusTypeId(), is(17)); assertThat(bookingCharge.getChargeJurisdictionTypeId(), is(1)); assertThat(bookingCharge.getChargeDisposition(), is("Disposition")); CustodyRelease custodyRelease = analyticalDatastoreDAO.getCustodyReleaseByBookingId(1); log.info(custodyRelease.toString()); assertEquals(LocalDate.parse("2014-12-17"), custodyRelease.getReleaseDate()); assertEquals(LocalTime.parse("10:30"), custodyRelease.getReleaseTime()); assertThat(custodyRelease.getBookingNumber(), is("Booking Number")); }
From source file:nu.yona.server.analysis.service.ActivityServiceTest.java
@Test public void getUserDayActivityDetail_activityPresent_resultWithActivity() { ZonedDateTime today = getDayStartTime(ZonedDateTime.now(userAnonZone)); ZonedDateTime yesterday = today.minusDays(1); LocalTime activityStartTimeOnDay = LocalTime.parse("20:14:57"); LocalTime activityEndTimeOnDay = LocalTime.parse("20:21:00"); int hour = 20; int[] expectedSpread = getEmptySpread(); expectedSpread[hour * 4] = 1;//from ww w.j a va 2 s . com expectedSpread[hour * 4 + 1] = 6; // gambling goal was created 2 weeks ago, see above // mock some activity on yesterday DayActivity yesterdayRecordedActivity = DayActivity.createInstance(userAnonEntity, gamblingGoal, userAnonZone, yesterday.toLocalDate()); ZonedDateTime activityStartTime = yesterday.withHour(activityStartTimeOnDay.getHour()) .withMinute(activityStartTimeOnDay.getMinute()).withSecond(activityStartTimeOnDay.getSecond()); ZonedDateTime activityEndTime = yesterday.withHour(activityEndTimeOnDay.getHour()) .withMinute(activityEndTimeOnDay.getMinute()).withSecond(activityEndTimeOnDay.getSecond()); Activity recordedActivity = Activity.createInstance(userAnonZone, activityStartTime.toLocalDateTime(), activityEndTime.toLocalDateTime(), Optional.empty()); yesterdayRecordedActivity.addActivity(recordedActivity); when(mockDayActivityRepository.findOne(userAnonId, yesterday.toLocalDate(), gamblingGoal.getId())) .thenReturn(yesterdayRecordedActivity); DayActivityDto activityDay = service.getUserDayActivityDetail(userId, yesterday.toLocalDate(), gamblingGoal.getId()); verify(mockDayActivityRepository, times(1)).findOne(userAnonId, yesterday.toLocalDate(), gamblingGoal.getId()); assertThat(activityDay.getSpread(), equalTo(Arrays.asList(ArrayUtils.toObject((expectedSpread))))); }