Search in sources :

Example 1 with Controller

use of jakarta.mvc.Controller in project org.openntf.xsp.jakartaee by OpenNTF.

the class NoSQLExample method createPerson.

@Path("create")
@POST
@Consumes(MediaType.APPLICATION_FORM_URLENCODED)
@Controller
public String createPerson(@FormParam("firstName") String firstName, @FormParam("lastName") String lastName, @FormParam("birthday") String birthday, @FormParam("favoriteTime") String favoriteTime, @FormParam("added") String added) {
    Person person = new Person();
    person.setFirstName(firstName);
    person.setLastName(lastName);
    if (StringUtil.isNotEmpty(birthday)) {
        LocalDate bd = LocalDate.from(DateTimeFormatter.ISO_LOCAL_DATE.parse(birthday));
        person.setBirthday(bd);
    } else {
        person.setBirthday(null);
    }
    if (StringUtil.isNotEmpty(favoriteTime)) {
        LocalTime bd = LocalTime.from(DateTimeFormatter.ISO_LOCAL_TIME.parse(favoriteTime));
        person.setFavoriteTime(bd);
    } else {
        person.setFavoriteTime(null);
    }
    if (StringUtil.isNotEmpty(added)) {
        LocalDateTime dt = LocalDateTime.from(DateTimeFormatter.ISO_LOCAL_DATE_TIME.parse(added));
        Instant bd = dt.toInstant(ZoneOffset.UTC);
        person.setAdded(bd);
    } else {
        person.setAdded(null);
    }
    personRepository.save(person);
    return "redirect:nosql/list";
}
Also used : LocalDateTime(java.time.LocalDateTime) LocalTime(java.time.LocalTime) Instant(java.time.Instant) Person(model.Person) LocalDate(java.time.LocalDate) Path(jakarta.ws.rs.Path) POST(jakarta.ws.rs.POST) Consumes(jakarta.ws.rs.Consumes) Controller(jakarta.mvc.Controller)

Example 2 with Controller

use of jakarta.mvc.Controller in project org.openntf.xsp.jakartaee by OpenNTF.

the class NoSQLExample method update.

@Path("{id}/update")
@PATCH
@Controller
@Consumes(MediaType.APPLICATION_FORM_URLENCODED)
public String update(@PathParam("id") String id, @FormParam("firstName") String firstName, @FormParam("lastName") String lastName, @FormParam("birthday") String birthday, @FormParam("favoriteTime") String favoriteTime, @FormParam("added") String added) {
    Person person = personRepository.findById(id).get();
    person.setFirstName(firstName);
    person.setLastName(lastName);
    if (StringUtil.isNotEmpty(birthday)) {
        LocalDate bd = LocalDate.from(DateTimeFormatter.ISO_LOCAL_DATE.parse(birthday));
        person.setBirthday(bd);
    } else {
        person.setBirthday(null);
    }
    if (StringUtil.isNotEmpty(favoriteTime)) {
        LocalTime bd = LocalTime.from(DateTimeFormatter.ISO_LOCAL_TIME.parse(favoriteTime));
        person.setFavoriteTime(bd);
    } else {
        person.setFavoriteTime(null);
    }
    if (StringUtil.isNotEmpty(added)) {
        LocalDateTime dt = LocalDateTime.from(DateTimeFormatter.ISO_LOCAL_DATE_TIME.parse(added));
        Instant bd = dt.toInstant(ZoneOffset.UTC);
        person.setAdded(bd);
    } else {
        person.setAdded(null);
    }
    personRepository.save(person);
    return "redirect:nosql/list";
}
Also used : LocalDateTime(java.time.LocalDateTime) LocalTime(java.time.LocalTime) Instant(java.time.Instant) Person(model.Person) LocalDate(java.time.LocalDate) Path(jakarta.ws.rs.Path) Consumes(jakarta.ws.rs.Consumes) Controller(jakarta.mvc.Controller) PATCH(jakarta.ws.rs.PATCH)

Aggregations

Controller (jakarta.mvc.Controller)2 Consumes (jakarta.ws.rs.Consumes)2 Path (jakarta.ws.rs.Path)2 Instant (java.time.Instant)2 LocalDate (java.time.LocalDate)2 LocalDateTime (java.time.LocalDateTime)2 LocalTime (java.time.LocalTime)2 Person (model.Person)2 PATCH (jakarta.ws.rs.PATCH)1 POST (jakarta.ws.rs.POST)1