Example usage for java.time LocalDate parse

List of usage examples for java.time LocalDate parse

Introduction

In this page you can find the example usage for java.time LocalDate parse.

Prototype

public static LocalDate parse(CharSequence text) 

Source Link

Document

Obtains an instance of LocalDate from a text string such as 2007-12-03 .

Usage

From source file:de.kaiserpfalzEdv.office.core.license.impl.LicenseBuilder.java

private LocalDate getDateFromLicense(final License license, final String feature) {
    try {/*from   w ww  .ja va  2  s .  c o m*/
        return LocalDate.parse(license.getFeature(feature));
    } catch (NullPointerException e) {
        throw new IllegalArgumentException("License does not contain feature '" + feature + "'.");
    }
}

From source file:svc.data.citations.datasources.tyler.TylerCitationDataSourceTest.java

@SuppressWarnings("unchecked")
@Test//  w ww.  j  a v a  2 s  .c om
public void returnsCitationsGivenNameAndMunicipalitiesAndDOB() {
    final String NAME = "Smith";
    final List<Long> MUNICIPALITIES = Lists.newArrayList(5L);
    final LocalDate DOB = LocalDate.parse("2000-06-01");
    mockTylerConfiguration.rootUrl = "http://myURL.com";
    mockTylerConfiguration.apiKey = "1234";
    final Citation CITATION = new Citation();
    CITATION.id = 3;
    final List<Citation> CITATIONS = Lists.newArrayList(CITATION);
    final List<TylerCitation> tylerCitations = Lists.newArrayList();
    Mockito.doReturn(tylerCitations).when(tylerCitationsResponseSpy).getBody();

    when(restTemplate.exchange(any(URI.class), eq(HttpMethod.GET), any(HttpEntity.class),
            any(ParameterizedTypeReference.class))).thenReturn(tylerCitationsResponseSpy);

    when(mockCitationTransformer.fromTylerCitations(tylerCitations)).thenReturn(CITATIONS);
    when(mockCitationFilter.RemoveCitationsWithExpiredDates(CITATIONS)).thenReturn(CITATIONS);

    List<Citation> citations = mockTylerCitationDataSource.getByNameAndMunicipalitiesAndDOB(NAME,
            MUNICIPALITIES, DOB);

    assertThat(citations.get(0).id, is(3));
}

From source file:io.github.mikesaelim.arxivoaiharvester.CommandLineInterface.java

/**
 * Construct a "ListRecords" request from user inputs.
 *//*from   w  w  w  .j ava  2  s  .c  o m*/
private static ListRecordsRequest constructListRecordsRequest(Scanner scanner) {
    while (true) {
        System.out.println("From date?  (in yyyy-mm-dd format; leave it blank for none)");
        String fromDate = scanner.nextLine().trim();
        System.out.println("Until date?  (in yyyy-mm-dd format; leave it blank for none)");
        String untilDate = scanner.nextLine().trim();
        System.out.println("Set restriction?  (leave it blank for none)");
        String setSpec = scanner.nextLine().trim();

        try {
            return new ListRecordsRequest(isBlank(fromDate) ? null : LocalDate.parse(fromDate),
                    isBlank(untilDate) ? null : LocalDate.parse(untilDate), isBlank(setSpec) ? null : setSpec);
        } catch (DateTimeParseException e) {
            System.out.println("    Sorry, one of the dates was not a valid date string.  Try again?");
        } catch (URISyntaxException e) {
            System.out.println("Sorry, the inputs did not result in a valid request URI.  Try again?");
        }
    }
}

From source file:org.jboss.jbossset.CommandLineParser.java

private LocalDate getValidLocalDate(String date, String optionName) throws ParseException {
    try {// w  ww .  j  a  va2s.c o m
        LocalDate localDate = LocalDate.parse(date);
        if (optionName.equals("startDate") && localDate.isAfter(LocalDate.now()))
            throw new ParseException("startDate cannot be in the future.");
        return localDate;
    } catch (DateTimeParseException e) {
        throw new ParseException("Invalid " + optionName + ". Date format must be YYYY-MM-DD.");
    }
}

From source file:org.silverpeas.core.workflow.api.user.ReplacementListTest.java

@Test
void filterCurrentAtOutOfRange() {
    List<ReplacementImpl> result = replacements.stream().filterCurrentAt(LocalDate.parse("2019-04-10"))
            .collect(Collectors.toList());
    assertThat(result, empty());//w  ww .  ja va2s. com
    result = replacements.stream().filterCurrentAt(LocalDate.parse("2019-04-14")).collect(Collectors.toList());
    assertThat(result, empty());
}

From source file:org.silverpeas.core.webapi.calendar.CalendarEventRecurrenceEntity.java

/**
 * Get the model representation of a recurrence with the entity data.
 * @param event the event on which the recurrence must be set.
 * @param occurrencePeriod the occurrence period in the case of an occurrence entity get.
 * @return a {@link CalendarEvent} instance.
 *//*from w w w. j a  va 2  s  . co  m*/
@XmlTransient
Recurrence applyOn(CalendarEvent event, Period occurrencePeriod) {
    Recurrence recurrence = event.getRecurrence();
    if (event.getRecurrence() != null) {
        recurrence.withFrequency(getFrequency().getModel());
    } else {
        recurrence = event.recur(Recurrence.from(getFrequency().getModel())).getRecurrence();
    }
    if (count > 0) {
        recurrence.until(count);
    } else if (isDefined(endDate)) {
        final boolean onAllDay = occurrencePeriod == null ? event.isOnAllDay() : occurrencePeriod.isInDays();
        if (onAllDay) {
            recurrence.until(LocalDate.parse(endDate));
        } else {
            recurrence.until(OffsetDateTime.parse(endDate));
        }
    } else {
        recurrence.endless();
    }
    if (!daysOfWeek.isEmpty()) {
        recurrence
                .on(daysOfWeek.stream().map(DayOfWeekOccurrenceEntity::getModel).collect(Collectors.toList()));
    } else {
        recurrence.onNoSpecificDay();
    }
    return recurrence;
}

From source file:org.silverpeas.core.workflow.api.user.ReplacementListTest.java

@Test
void filterCurrentAndNextAtOutOfRange() {
    List<ReplacementImpl> result = replacements.stream().filterCurrentAndNextAt(LocalDate.parse("2019-04-14"))
            .collect(Collectors.toList());
    assertThat(result, empty());/*from w w w. ja v  a 2  s. c  o m*/
}

From source file:org.zaproxy.gradle.UpdateAddOnZapVersionsEntries.java

@Option(option = "releaseDate", description = "The release date.")
public void setReleaseDate(String date) {
    releaseDate.set(LocalDate.parse(date));
}

From source file:org.silverpeas.core.web.calendar.AbstractCalendarWebController.java

/**
 * Handles the time window context.//from w  w  w.j  ava 2s  . co  m
 * @param context the context of the incoming request.
 */
@POST
@Path("calendars/context")
@Produces(MediaType.APPLICATION_JSON)
public <T extends CalendarTimeWindowViewContext> T view(C context) {
    CalendarViewType calendarViewType = CalendarViewType.from(context.getRequest().getParameter("view"));
    if (calendarViewType != null) {
        getCalendarTimeWindowContext().setViewType(calendarViewType);
    }
    String listViewMode = context.getRequest().getParameter("listViewMode");
    if (isDefined(listViewMode)) {
        getCalendarTimeWindowContext().setListViewMode(getBooleanValue(listViewMode));
    }
    String timeWindow = context.getRequest().getParameter("timeWindow");
    if (StringUtil.isDefined(timeWindow)) {
        if ("previous".equals(timeWindow)) {
            getCalendarTimeWindowContext().previous();
        } else if ("next".equals(timeWindow)) {
            getCalendarTimeWindowContext().next();
        } else if ("today".equals(timeWindow)) {
            getCalendarTimeWindowContext().today();
        } else if ("referenceDay".equals(timeWindow)) {
            LocalDate date = LocalDate.parse(context.getRequest().getParameter("timeWindowDate").split("T")[0]);
            getCalendarTimeWindowContext().setReferenceDay(Date.valueOf(date));
        }
    }
    return getCalendarTimeWindowContext();
}

From source file:org.ojbc.adapters.analyticsstaging.custody.processor.AbstractReportRepositoryProcessor.java

protected Integer savePerson(Node personNode, String personUniqueIdentifier, String extPrefix)
        throws Exception {

    Person person = new Person();

    person.setPersonUniqueIdentifier(personUniqueIdentifier);

    person.setPersonUniqueIdentifier2(XmlUtils.xPathStringSearch(personNode,
            "preceding-sibling::jxdm51:Booking/jxdm51:BookingSubject/jxdm51:SubjectIdentification/nc30:IdentificationID"));
    ;//from  w ww  .  j a  v a  2  s . co m

    String personRaceCode = XmlUtils.xPathStringSearch(personNode, "jxdm51:PersonRaceCode");
    if (StringUtils.isBlank(personRaceCode)) {
        personRaceCode = XmlUtils.xPathStringSearch(personNode, "pc-bkg-codes:PersonRaceCode");
    }
    person.setPersonRaceCode(personRaceCode);
    person.setPersonRaceId(descriptionCodeLookupService.retrieveCode(CodeTable.PersonRaceType, personRaceCode));

    String personSex = XmlUtils.xPathStringSearch(personNode, "jxdm51:PersonSexCode");
    person.setPersonSexCode(StringUtils.trimToNull(personSex));
    person.setPersonSexId(descriptionCodeLookupService.retrieveCode(CodeTable.PersonSexType, personSex));

    String personEthnicityType = XmlUtils.xPathStringSearch(personNode, "jxdm51:PersonEthnicityCode");
    person.setPersonEthnicityTypeDescription(StringUtils.trimToNull(personEthnicityType));
    person.setPersonEthnicityTypeId(descriptionCodeLookupService.retrieveCode(CodeTable.PersonEthnicityType,
            StringUtils.trimToNull(personEthnicityType)));

    String personBirthDate = XmlUtils.xPathStringSearch(personNode, "nc30:PersonBirthDate/nc30:Date");
    person.setPersonBirthDate(LocalDate.parse(personBirthDate));

    String language = XmlUtils.xPathStringSearch(personNode, "nc30:PersonPrimaryLanguage/nc30:LanguageName");
    person.setLanguage(language);
    person.setLanguageId(descriptionCodeLookupService.retrieveCode(CodeTable.LanguageType, language));

    String personCriminalHistorySummaryRef = XmlUtils.xPathStringSearch(personNode,
            "parent::br-doc:BookingReport/nc30:ActivityPersonAssociation"
                    + "[nc30:Person/@s30:ref=/br-doc:BookingReport/jxdm51:Booking/jxdm51:BookingSubject/nc30:RoleOfPerson/@s30:ref]/nc30:Activity/@s30:ref");
    String registeredSexOffender = XmlUtils.xPathStringSearch(personNode,
            "/br-doc:BookingReport/jxdm51:PersonCriminalHistorySummary[@s30:id='"
                    + personCriminalHistorySummaryRef + "']/jxdm51:RegisteredSexualOffenderIndicator");
    Boolean registeredSexOffenderBoolean = BooleanUtils.toBooleanObject(registeredSexOffender);
    String sexOffenderStatus = BooleanUtils.toString(registeredSexOffenderBoolean, "registered",
            "not registered", null);
    person.setSexOffenderStatusTypeId(
            descriptionCodeLookupService.retrieveCode(CodeTable.SexOffenderStatusType, sexOffenderStatus));

    String educationLevel = XmlUtils.xPathStringSearch(personNode, "nc30:PersonEducationLevelText");
    person.setEducationLevel(educationLevel);

    String occupation = XmlUtils.xPathStringSearch(personNode,
            "jxdm51:PersonAugmentation/nc30:EmployeeOccupationCategoryText");
    person.setOccupation(occupation);

    Boolean homelessIndicator = BooleanUtils
            .toBooleanObject(XmlUtils.xPathStringSearch(personNode, extPrefix + ":PersonHomelessIndicator"));
    String domicileStatusType = BooleanUtils.toString(homelessIndicator, "homeless", "not homeless", null);
    person.setDomicileStatusTypeId(
            descriptionCodeLookupService.retrieveCode(CodeTable.DomicileStatusType, domicileStatusType));

    Boolean personVeteranBenefitsEligibilityIndicator = BooleanUtils.toBooleanObject(
            XmlUtils.xPathStringSearch(personNode, extPrefix + ":PersonVeteranBenefitsEligibilityIndicator"));
    String programEligibilityType = BooleanUtils.toString(personVeteranBenefitsEligibilityIndicator,
            "Veteran Services", "none", null);
    person.setProgramEligibilityTypeId(descriptionCodeLookupService
            .retrieveCode(CodeTable.ProgramEligibilityType, programEligibilityType));

    Boolean inmateWorkReleaseIndicator = BooleanUtils.toBooleanObject(XmlUtils.xPathStringSearch(personNode,
            "preceding-sibling::jxdm51:Detention/" + extPrefix + ":InmateWorkReleaseIndicator"));
    String workReleaseStatusType = BooleanUtils.toString(inmateWorkReleaseIndicator, "assigned", "not assigned",
            null);
    person.setWorkReleaseStatusTypeId(
            descriptionCodeLookupService.retrieveCode(CodeTable.WorkReleaseStatusType, workReleaseStatusType));
    ;

    String militaryServiceStatusCode = XmlUtils.xPathStringSearch(personNode,
            "nc30:PersonMilitarySummary/ac-bkg-codes:MilitaryServiceStatusCode");
    Integer militaryServiceStatusTypeId = descriptionCodeLookupService
            .retrieveCode(CodeTable.MilitaryServiceStatusType, militaryServiceStatusCode);
    person.setMilitaryServiceStatusType(new KeyValue(militaryServiceStatusTypeId, militaryServiceStatusCode));
    Integer personId = analyticalDatastoreDAO.savePerson(person);

    return personId;
}