List of usage examples for org.joda.time DateTime plusDays
public DateTime plusDays(int days)
From source file:org.ojbc.bundles.adapters.staticmock.samplegen.AbstractSampleGenerator.java
License:RPL License
/** * Generates a random, uniformly distributed date between the two specified dates. * //from w w w . ja v a 2 s . c om * @param d1 * the first date * @param d2 * the second date * @return a random date between the two */ protected final DateTime generateUniformRandomDateBetween(DateTime d1, DateTime d2) { DateTime start = d1; DateTime end = d2; if (d1.isAfter(d2)) { start = d2; end = d1; } int daysBetween = Days.daysBetween(start, end).getDays(); int r = randomGenerator.nextInt(0, daysBetween); return start.plusDays(r); }
From source file:org.ojbc.bundles.adapters.staticmock.samplegen.CriminalHistorySampleGenerator.java
License:RPL License
private void addProtectionOrderElements(Element rapSheetElement, PersonElementWrapper person, DateTime baseDate) {/*w w w .ja v a 2 s .c o m*/ int orderCount = generatePoissonInt(.3, false); for (int i = 0; i < orderCount; i++) { Element orderElement = appendElement(rapSheetElement, OjbcNamespaceContext.NS_CH_EXT, "Order"); Element activityElement = appendElement(orderElement, OjbcNamespaceContext.NS_NC, "ActivityIdentification"); Element e = appendElement(activityElement, OjbcNamespaceContext.NS_NC, "IdentificationID"); e.setTextContent(generateRandomID("ORDER", 10)); e = appendElement(activityElement, OjbcNamespaceContext.NS_NC, "IdentificationCategoryText"); e.setTextContent("TRO DOCUMENT ID"); e = appendElement(orderElement, OjbcNamespaceContext.NS_NC, "ActivityCategoryText"); e.setTextContent("TRO"); e = appendElement(orderElement, OjbcNamespaceContext.NS_NC, "ActivityDate"); e = appendElement(e, OjbcNamespaceContext.NS_NC, "Date"); DateTime orderDate = generateUniformRandomDateBetween(baseDate, baseDate.minusYears(5)); e.setTextContent(DATE_FORMATTER_YYYY_MM_DD.print(orderDate)); e = appendElement(orderElement, OjbcNamespaceContext.NS_JXDM_41, "CourtOrderIssuingCourt"); e = appendElement(e, OjbcNamespaceContext.NS_NC, "OrganizationName"); e.setTextContent(getRandomCounty(person.state) + " District Court"); e = appendElement(orderElement, OjbcNamespaceContext.NS_JXDM_41, "CourtOrderServiceDescriptionText"); e.setTextContent(generateRandomCodeFromList("PENDING", "SERVED")); e = appendElement(orderElement, OjbcNamespaceContext.NS_CH_EXT, "CourtCase"); e = appendElement(e, OjbcNamespaceContext.NS_NC, "ActivityIdentification"); e = appendElement(e, OjbcNamespaceContext.NS_NC, "IdentificationID"); e.setTextContent("TRO-" + baseDate.getYear() + generateRandomID("-", 8)); e = appendElement(orderElement, OjbcNamespaceContext.NS_CH_EXT, "ProtectionOrderExpirationDate"); e = appendElement(e, OjbcNamespaceContext.NS_NC, "Date"); e.setTextContent(DATE_FORMATTER_YYYY_MM_DD.print(orderDate.plusDays(randomGenerator.nextInt(5, 365)))); } }
From source file:org.ojbc.bundles.adapters.staticmock.samplegen.JuvenileHistorySampleGenerator.java
License:RPL License
JuvenileHistory createJuvenileHistory(PersonElementWrapper kid, DateTime baseDate, String stateParam) throws IOException { // make these people kids int birthYearSubtraction = randomGenerator.nextInt(12, 17); kid.birthdate = kid.birthdate.withYear(baseDate.getYear() - birthYearSubtraction); kid.centimeters = String.valueOf(Double.parseDouble(kid.centimeters) * .75); kid.pounds = String.valueOf(Double.parseDouble(kid.pounds) * .5); String state = stateParam == null ? kid.state : stateParam; JuvenileHistory ret = new JuvenileHistory(); ret.kid = kid;//from w w w . j a v a 2s. c o m ret.kid.personId = "P" + ret.kid.id; String county = getRandomCounty(state); List<Court> courts = new ArrayList<Court>(); int baseZip = 43100; for (int i = 0; i < 9; i++) { courts.add(new Court(county + " County Circuit Court", "Juvenile Division", "123 Any Street", getRandomCity(state), state, "" + (baseZip + i))); } ret.court = (Court) generateRandomValueFromList(courts.toArray()); ret.court.city = getRandomCity(state); if (coinFlip(.7)) { PersonElementWrapper mother = getRandomIdentity(state); while (!("female".equals(mother.sex))) { mother = getRandomIdentity(state); } mother.personId = "P" + mother.id; ret.mother = mother; Residence r = new Residence(); r.street = buildRandomStreet(); r.city = getRandomCity(state); r.state = state; r.zip = "12345"; ret.motherResidence = r; if (coinFlip(.5)) { kid.lastName = mother.lastName; } } if (ret.motherResidence == null || coinFlip(.7)) { PersonElementWrapper father = getRandomIdentity(state); while (!("male".equals(father.sex))) { father = getRandomIdentity(state); } father.personId = "P" + father.id; ret.father = father; Residence r = ret.motherResidence; if (r == null || coinFlip(.5)) { r = new Residence(); r.street = buildRandomStreet(); r.city = getRandomCity(state); r.state = state; r.zip = "12345"; } ret.fatherResidence = r; if (coinFlip(.7)) { kid.lastName = father.lastName; } } ret.kidResidence = ret.motherResidence; if (ret.kidResidence == null || (ret.fatherResidence != null && coinFlip(.6))) { ret.kidResidence = ret.fatherResidence; } if (ret.mother != null && ret.father != null && ret.motherResidence == ret.fatherResidence) { if (coinFlip(.75)) { ret.mother.lastName = ret.father.lastName; ret.kid.lastName = ret.father.lastName; } } if (ret.fatherResidence != null) { ret.fatherResidence.id = "Residence-F"; } if (ret.motherResidence != null) { ret.motherResidence.id = "Residence-M"; } ret.kidResidence.id = "Residence-K"; int referralCount = generatePoissonInt(.8, true); for (int i = 0; i < referralCount; i++) { Referral referral = new Referral(); referral.id = "Referral-" + i; referral.date = generateNormalRandomDateBefore(baseDate, 150); referral.issuerCategory = generateRandomCodeFromList("Police", "Prosecutor", "School", "Court/Probation", "Social Services", "Other"); referral.category = generateRandomCodeFromList("Complaint", "Citation or Appearance Ticket", "Petition", "Community Referral"); if ("Police".equals(referral.issuerCategory)) { referral.issuerName = ret.kidResidence.city + " Police Department"; } else if ("Prosecutor".equals(referral.issuerCategory)) { referral.issuerName = county + " County Prosecutor"; } else if ("School".equals(referral.issuerCategory)) { referral.issuerName = generateRandomCodeFromList(ret.kidResidence.city, "Washington", "Lincoln", "Jefferson") + " High School"; } else if ("Court/Probation".equals(referral.issuerCategory)) { referral.issuerName = county + " County Courts"; } else if ("Social Services".equals(referral.issuerCategory)) { referral.issuerName = county + " County Social Services"; } else { referral.issuerName = "Other Referral Source"; } referral.issuerStreet = buildRandomStreet(); referral.issuerCity = getRandomCity(state); referral.issuerState = state; referral.issuerZip = "12345"; ret.referrals.add(referral); } CasePlan casePlan = new CasePlan(); ret.casePlan = casePlan; casePlan.casePlanIndicator = coinFlip(.6); casePlan.assessmentIndicator = coinFlip(.8); int hearingCount = generatePoissonInt(1.2, true); for (int i = 0; i < hearingCount; i++) { Hearing h = new Hearing(); h.id = "Hearing-" + i; h.date = generateNormalRandomDateBefore(baseDate, 200); h.contemptOfCourtIndicator = coinFlip(.2); h.probationViolationIndicator = coinFlip(.4); h.hearingCategory = generateRandomCodeFromList("Preliminary hearing", "Preliminary inquiry", "Pretrial Conference", "Adjudication", "Bench Trial", "Jury Trial", "Competency Hearing", "Disposition Hearing", "Dispositional Review", "Detention Hearing", "Probation Violation Hearing", "Phase I Waiver Hearing", "Phase II Waiver Hearing", "Designation Arraignment", "Designation Preliminary Examination", "Designation Hearing", "Designation adjudication or trial", "Designation Sentencing", "Contempt of Court (on a Motion to Show Cause)", "Dismissal"); h.disposition = generateRandomCodeFromList("Petition authorized", "Petition not authorized", "Refer to alternative services", "Placed on the Consent Calendar", "Placed on diversion", "Attorney appointed", "Placement determination", "Title IV-E language", "Bond may be set if out of home placement is ordered", "Next hearing scheduled", "Determine notice issues", "American Indian tribe or band notified", "Adjournment", "Adjudication hearing set", "Bench trial set", "Jury trial set", "Case dismissed", "Other stipulations between the parties noted", "Order for competency evaluation requested", "Plea is accepted", "Plea is rejected", "Plea is taken under advisement", "Order fingerprinting", "Order an abstract to Sec. of State", "Order licensing sanctions", "Placement determination", "Title IV-E language (if necessary)", "Bond may be set if out of home placement is ordered", "Guilty or not guilty determination by judge or referee", "The juvenile is competent", "The juvenile is not competent to proceed and will remain incompetent", "The juvenile is not competent to proceed but may be restored to competency", "The proceedings on the charges shall proceed immediately", "The proceedings on the charges are suspended pending restoration efforts", "Warn and dismiss", "Probation", "Refer to Michigan DHS for placement and care", "Order HIV, Sex offender registration and/DNA testing", "Order costs, fees, etc.", "Continue Probation", "Modify previous dispositional orders", "Release of jurisdiction", "Plea accepted to probation violation", "Modify previous dispositional orders", "Set a probation violation hearing", "Probation violation dismissed", "Finding the juvenile violated probation", "Finding the juvenile did not violate probation", "Determine probable cause", "Phase I waived by parties", "Deny the motion to waive", "Schedule Phase II hearing", "The motion to waive jurisdiction is denied and the case shall proceed under the juvenile code", "The motion to waive jurisdiction is granted and the case is transferred to the court having general criminal jurisdiction", "Preliminary examination waived", "Probable cause does exist", "Probable cause does not exist", "The request for designation is granted", "The request for designation is not granted", "Schedule sentencing hearing", "Sentence as an adult", "Blended sentence", "Juvenile disposition", "The person is guilty of contempt of court", "The person is not guilty of contempt of court", "The motion is denied", "Sentencing factors listed"); ret.hearings.add(h); } int intakeCount = generatePoissonInt(1.2, true); for (int i = 0; i < intakeCount; i++) { Intake intake = new Intake(); intake.id = "Intake-" + i; intake.date = generateNormalRandomDateBefore(baseDate, 150); intake.assessmentCategory = generateRandomCodeFromList("Assessment", "Screening", "Interview", "Other"); intake.recommendedCourseOfAction = generateRandomCodeFromList("Court diversion", "Consent calendar", "Formal calendar", "Transfer"); ret.intakes.add(intake); } int offenseCount = generatePoissonInt(1.6, true); for (int i = 0; i < offenseCount; i++) { OffenseCharge offenseCharge = new OffenseCharge(); offenseCharge.id = "Offense-" + i; offenseCharge.pacCode = generateRandomCodeFromList(OFFENSE_CODES); DateTime offenseDate = generateNormalRandomDateBefore(baseDate, 400); offenseCharge.offenseDate = offenseDate; offenseCharge.filingDate = offenseDate.plusDays(randomGenerator.nextInt(2, 14)); offenseCharge.dispositionDate = offenseCharge.filingDate.plusDays(randomGenerator.nextInt(30, 180)); offenseCharge.verdictDate = offenseCharge.dispositionDate.plusDays(randomGenerator.nextInt(0, 30)); offenseCharge.verdict = generateRandomCodeFromList("Not responsible", "Responsible", "Dismissed"); if ("Responsible".equals(offenseCharge.verdict)) { offenseCharge.sanctionDate = offenseCharge.verdictDate.plusDays(randomGenerator.nextInt(0, 30)); int sanctionCount = generatePoissonInt(.5, true); for (int j = 0; j < sanctionCount; j++) { offenseCharge.sanctions.add(generateRandomCodeFromList("Warning", "Probation", "Community service", "Payment of fines, fees, restitution", "Electronic tether", "Drug or other testing or screening", "Participation in Drug or other Specialty Court", "Detention", "Boot Camp", "Courtesy supervision", "Residential Placements", "Court/county operated treatment facility", "In-state private operated treatment facility", "Out-of-state operated treatment facility", "State or public treatment/residential facility", "A referral or commitment to human services", "County jail", "Sentence as an Adult")); } } offenseCharge.location = (Location) generateRandomValueFromList(ret.getLocations()); if (coinFlip(.4)) { offenseCharge.location = new Location(); offenseCharge.location.street = buildRandomStreet(); offenseCharge.location.city = getRandomCity(state); offenseCharge.location.state = state; offenseCharge.location.zip = "12345"; offenseCharge.location.id = "OffenseLocation-" + i; } ret.offenseCharges.add(offenseCharge); } int placementCount = generatePoissonInt(.8, true); for (int i = 0; i < placementCount; i++) { Placement placement = new Placement(); placement.id = "Placement-" + i; placement.startDate = generateNormalRandomDateBefore(baseDate, 365); placement.endDate = placement.startDate.plusDays(randomGenerator.nextInt(10, 180)); placement.placementCategory = generateRandomCodeFromList("Juvenile Detention Facility", "Foster Home", "Group Home", "Residential", "Mother", "Father", "Stepfather", "Stepmother", "Relative/Fictive Kin", "Jail"); if ("Juvenile Detention Facility".equals(placement.placementCategory) || "Jail".equals(placement.placementCategory)) { placement.securityCode = "Secure"; } else { placement.securityCode = "Non-secure"; } placement.facilityName = "Facility Name: " + placement.placementCategory; if ("Mother".equals(placement.placementCategory) && coinFlip(.8)) { placement.facilityName = "Mother's residence"; placement.facilityLocation = ret.motherResidence; } if ("Father".equals(placement.placementCategory) && coinFlip(.8)) { placement.facilityName = "Father's residence"; placement.facilityLocation = ret.fatherResidence; } if (placement.facilityLocation == null) { placement.facilityLocation = new Location(); placement.facilityLocation.street = buildRandomStreet(); placement.facilityLocation.city = getRandomCity(state); placement.facilityLocation.state = state; placement.facilityLocation.zip = "12345"; placement.facilityLocation.id = "FacilityLocation-" + i; } ret.placements.add(placement); } for (IdentifiableHistoryComponent component : ret.getIdentifiableComponents()) { Class<IdentifiableHistoryComponent> unsupportedRelatedComponentClass = null; if (coinFlip(.5)) { while (unsupportedRelatedComponentClass == null || unsupportedRelatedComponentClass.isAssignableFrom(component.getClass())) { unsupportedRelatedComponentClass = (Class<IdentifiableHistoryComponent>) generateRandomValueFromList( Referral.class, Placement.class, Intake.class, OffenseCharge.class, Hearing.class); } } component.relatedUnsupportedClass = unsupportedRelatedComponentClass; List<IdentifiableHistoryComponent> others = new ArrayList<IdentifiableHistoryComponent>(); for (IdentifiableHistoryComponent innerComponent : ret.getIdentifiableComponents()) { if (!(innerComponent.getClass() == component.getClass() || innerComponent.getClass() == unsupportedRelatedComponentClass)) { others.add(innerComponent); } } if (!others.isEmpty()) { Collections.shuffle(others); int relatedCount = randomGenerator.nextInt(0, others.size() - 1); if (relatedCount > 0) { component.relatedComponents = others.subList(0, relatedCount); } } } return ret; }
From source file:org.ojbc.intermediaries.sn.dao.StaticGracePeriodStrategy.java
License:RPL License
@Override public Interval getGracePeriod(Subscription subscription) { Interval ret = null;// www.j a v a 2 s . c om DateTime validationDueDate = validationDueDateStrategy.getValidationDueDate(subscription); DateTime subscriptionEndDate = subscription.getEndDate(); DateTime gracePeriodStart = null; if (subscriptionEndDate == null && validationDueDate == null) { return null; } if (subscriptionEndDate == null && validationDueDate != null) { gracePeriodStart = validationDueDateStrategy.getValidationDueDate(subscription); } if (subscriptionEndDate != null && validationDueDate == null) { gracePeriodStart = subscription.getEndDate(); } if (subscriptionEndDate != null && validationDueDate != null) { if (subscriptionEndDate.isBefore(validationDueDate)) { gracePeriodStart = subscription.getEndDate(); } else { gracePeriodStart = validationDueDateStrategy.getValidationDueDate(subscription); } } if (gracePeriodStart != null) { ret = new Interval(gracePeriodStart.plusDays(1), gracePeriodStart.plusDays(gracePeriodDays + 1)); } return ret; }
From source file:org.ojbc.intermediaries.sn.dao.StaticValidationDueDateStrategy.java
License:RPL License
/** * This method will return the validation due date which is the last validated date from the * subscription plus a configurable number of days. * /* w w w . ja va 2s .com*/ * If the subscription owner is in the exempt list, it will return null indicating that * there is no validation due date. */ @Override public DateTime getValidationDueDate(Subscription subscription) { //If an exempt subscriber list is defined, see if the subscription owner is in that list. //The 'exempt' subscription owner is allowed to have no validation due date if (exemptSubscriptionOwners != null) { //determine if submitting ORI exists in the list of authorized ORIs for (String s : exemptSubscriptionOwners) { if (s.replaceAll("\\s", "").equalsIgnoreCase(subscription.getSubscriptionOwner())) { return null; } } } DateTime ret = null; DateTime lastValidatedDate = subscription.getLastValidationDate(); if (lastValidatedDate != null) { ret = lastValidatedDate.plusDays(validDays); } return ret; }
From source file:org.ojbc.intermediaries.sn.dao.SubscriptionSearchQueryDAO.java
License:RPL License
private void subscribeIdentificationTransaction(Number subscriptionId, String transactionNumber, String endDateString) {/*from w ww .j a v a 2 s . co m*/ final String IDENTIFICATION_TRANSACTION_SUBSCRIBE = "UPDATE identification_transaction " + "SET subscription_id = ?, available_for_subscription_start_date = ? WHERE transaction_number = ? "; DateTime endDate = XmlUtils.parseXmlDate(endDateString); endDate = endDate.plusDays(1); this.jdbcTemplate.update(IDENTIFICATION_TRANSACTION_SUBSCRIBE, subscriptionId, endDate.toDate(), transactionNumber); }
From source file:org.ojbc.web.model.incident.search.IncidentSearchRequestDomUtils.java
License:RPL License
public static Element createIncidentElement(Document doc, IncidentSearchRequest isr) { Element incidentElement = NIEMXMLUtils.createIncidentElement(doc, "I001"); if (StringUtils.isNotBlank(isr.getIncidentNumber())) { Element incidentNumber = NIEMXMLUtils.createIdentificationElementWithParent(doc, "ActivityIdentification", isr.getIncidentNumber()); incidentElement.appendChild(incidentNumber); }//from w ww . java2 s. c om //Check to see if both incident start and end are populated if (isr.getIncidentDateRangeStart() != null && isr.getIncidentDateRangeEnd() != null) { DateTime incidentDateRangeEnd = isr.getIncidentDateRangeEnd(); //If incident start and end date are the same day, we set the end date to following date to get a date range because the queries also take the time into account if (isr.getIncidentDateRangeStart().equals(isr.getIncidentDateRangeEnd())) { incidentDateRangeEnd = incidentDateRangeEnd.plusDays(1); } Element dateRange = NIEMXMLUtils.createNC20DateRangeElementWithParent(doc, "ActivityDateRange", isr.getIncidentDateRangeStart(), incidentDateRangeEnd); incidentElement.appendChild(dateRange); } //If only incident start date is populated query on a single day if (isr.getIncidentDateRangeStart() != null && isr.getIncidentDateRangeEnd() == null) { DateTime incidentDateRangeEnd = isr.getIncidentDateRangeStart().plusDays(1); Element dateRange = NIEMXMLUtils.createNC20DateRangeElementWithParent(doc, "ActivityDateRange", isr.getIncidentDateRangeStart(), incidentDateRangeEnd); incidentElement.appendChild(dateRange); } if (StringUtils.isNotBlank(isr.getIncidentType())) { Element categoryCode = doc.createElementNS(OjbcNamespaceContext.NS_INCIDENT_SEARCH_REQUEST_EXT, "IncidentCategoryCode"); categoryCode.setTextContent(isr.getIncidentType()); incidentElement.appendChild(categoryCode); } return incidentElement; }
From source file:org.opencastproject.dataloader.EventsLoader.java
License:Educational Community License
private List<EventEntry> parseCSV(CSVParser csv) { List<EventEntry> arrayList = new ArrayList<EventEntry>(); for (CSVRecord record : csv) { String title = record.get(0); String description = StringUtils.trimToNull(record.get(1)); String series = StringUtils.trimToNull(record.get(2)); String seriesName = StringUtils.trimToNull(record.get(3)); Integer days = Integer.parseInt(record.get(4)); float signum = Math.signum(days); DateTime now = DateTime.now(); if (signum > 0) { now = now.plusDays(days); } else if (signum < 0) { now = now.minusDays(days * -1); }//from www . java2s.c o m Integer duration = Integer.parseInt(record.get(5)); boolean archive = BooleanUtils.toBoolean(record.get(6)); String agent = StringUtils.trimToNull(record.get(7)); String source = StringUtils.trimToNull(record.get(8)); String contributor = StringUtils.trimToNull(record.get(9)); List<String> presenters = Arrays .asList(StringUtils.split(StringUtils.trimToEmpty(record.get(10)), ",")); EventEntry eventEntry = new EventEntry(title, now.toDate(), duration, archive, series, agent, source, contributor, description, seriesName, presenters); arrayList.add(eventEntry); } return arrayList; }
From source file:org.opencastproject.scheduler.impl.persistence.SchedulerServiceDatabaseImpl.java
License:Educational Community License
/** * Add the correct start and end value for the given daily count query. * <p/>/*from w ww .j a va 2 s .c o m*/ * Please note that the start instant is inclusive while the end instant is exclusive. * * @param query * The query where the parameters have to be added * @return the same query instance */ private Query setDateForDailyQuery(Query query) { final DateTime today = new DateTime().withTimeAtStartOfDay(); return query.setParameter("start", today.toDate()).setParameter("end", today.plusDays(1).toDate()); }
From source file:org.opendatakit.common.android.utilities.DataUtil.java
License:Apache License
public Interval tryParseInterval(String input) { for (int i = 0; i < userPartialParsers.length; i++) { try {//from w w w . j a v a 2s . c o m DateTime start = userPartialParsers[i].parseDateTime(input); DateTime end = start.plusSeconds(USER_INTERVAL_DURATIONS[i]); return new Interval(start, end); } catch (IllegalArgumentException e) { } } if (!locale.getLanguage().equals(Locale.ENGLISH.getLanguage())) { return null; } DateTime start = new DateMidnight().toDateTime(); boolean match = false; if (input.equalsIgnoreCase("today")) { match = true; } else if (input.equalsIgnoreCase("yesterday")) { start = start.minusDays(1); match = true; } else if (input.equalsIgnoreCase("tomorrow") || input.equalsIgnoreCase("tmw")) { start = start.plusDays(1); match = true; } if (match) { DateTime end = start.plusDays(1); return new Interval(start, end); } return null; }