Value of custom Date Picker Component in gridPro is always null - datepicker

I want to use a DatePicker as custom component in vaadin gridPro.
Since there are only checkbox, select and text natively supported as EditColumn, I tried it with custom.
final DatePicker component = new DatePicker();
this.medicationAdjustmentRules.addEditColumn(value -> (value.getValidUntil() != null ? value.getValidUntil().format(this.formatter) : null))
.custom(component, (medicationAdjustmentRule, newValue) -> medicationAdjustmentRule.setValidUntil(component.getValue() != null ? component.getValue() : newValue))
.setHeader("validUntil");
Both component.getValue() and newValue are always null.
What am I doing wrong?

I seem to be able to get a value out of both the component instance and from the ItemUpdater parameter. Here's a full example:
#Route(value = "gridpro", layout = MainLayout.class)
public class GridProView extends VerticalLayout {
public static class Person {
private String firstName;
private String lastName;
private LocalDate birthDate;
public String getFirstName() {
return firstName;
}
public void setFirstName(String firstName) {
this.firstName = firstName;
}
public String getLastName() {
return lastName;
}
public void setLastName(String lastName) {
this.lastName = lastName;
}
public LocalDate getBirthDate() {
return birthDate;
}
public void setBirthDate(LocalDate birthDate) {
this.birthDate = birthDate;
}
public Person(String firstName, String lastName, LocalDate birthDate) {
this.firstName = firstName;
this.lastName = lastName;
this.birthDate = birthDate;
}
}
public List<Person> getData() {
List<Person> persons = new ArrayList<>();
persons.add(new Person("Zach", "Quinto", LocalDate.of(2000, 5, 2)));
persons.add(new Person("Paula", "Boulon", LocalDate.of(1982, 11, 24)));
persons.add(new Person("Foo", "Bar", LocalDate.of(2020, 01, 01)));
return persons;
}
public GridProView() {
GridPro<Person> gridPro = new GridPro<>();
gridPro.addColumn(Person::getFirstName).setHeader("First name");
gridPro.addColumn(Person::getLastName).setHeader("Last name");
DatePicker component = new DatePicker();
gridPro.addEditColumn(Person::getBirthDate).custom(component,
(ItemUpdater<Person, LocalDate>) (person, newValue) -> {
System.out.println("Value in component: " + component.getValue());
System.out.println("newValue: " + newValue);
person.setBirthDate(newValue);
});
gridPro.setItems(getData());
add(gridPro);
}
}
This outputs something like:
Value in component: 2000-07-18
newValue: 2000-07-18
Value in component: 1981-11-24
newValue: 1981-11-24
Value in component: 2020-01-08
newValue: 2020-01-08

Related

Grid not updating after entity attributes are changed

In my project, I have "Events" and "Users". Users sign up for events. Anyways the Events entity has a "participants" attribute which is an int that is the total capacity of the event, that is supposed to decrement every time a User signs up for the Event. Each Event also has an ArrayList attribute called "registrants" that is supposed to contain all the current User entities that have signed up for the Event.
My issue is that when a User signs up for an Event, this capacity attribute "participants" does not decrease at all like it is supposed to, which I suspect means the ArrayList "registrants" is also not be updated with the User that signs up. I re-check the EventManagementView after using a User to sign up for an event to see if the capacity is ever dropped from its initial set value, but it never is. Here's all the code that is directly used with this issue:
Events.java class for Events entity:
package ymca.tracker.application.data.entity;
import java.time.LocalDate;
import java.time.LocalTime;
import java.util.ArrayList;
import java.util.List;
import javax.persistence.ElementCollection;
import javax.persistence.Embeddable;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.OneToMany;
import ymca.tracker.application.data.AbstractEntity;
#Embeddable
#Entity
public class Events extends AbstractEntity{
private String name;
private java.time.LocalDate startDate;
private java.time.LocalDate endDate;
private java.time.LocalTime startTime;
private java.time.LocalTime endTime;
private String recurring;
// The capacity attribute I was referring to above
public int participants;
private String nonMemberPrice;
private String memberPrice;
private String location;
private String description;
// Registrants ArrayList that is supposed to hold all the User entities that sign up for an event
#ElementCollection
#OneToMany(fetch = FetchType.EAGER)
public List<User> registrants = new ArrayList<User>();
public Events() {
}
public Events(String name, LocalDate startDate, LocalDate endDate, LocalTime startTime, LocalTime endTime,
String recurring, int participants, String nonMemberPrice, String memberPrice, String location,
String description, ArrayList<User> registrants) {
this.name = name;
this.startDate = startDate;
this.endDate = endDate;
this.startTime = startTime;
this.endTime = endTime;
this.recurring = recurring;
this.participants = participants;
this.nonMemberPrice = nonMemberPrice;
this.memberPrice = memberPrice;
this.location = location;
this.description = description;
this.registrants = registrants;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public java.time.LocalDate getStartDate() {
return startDate;
}
public void setStartDate(java.time.LocalDate startDate) {
this.startDate = startDate;
}
public java.time.LocalDate getEndDate() {
return endDate;
}
public void setEndDate(java.time.LocalDate endDate) {
this.endDate = endDate;
}
public java.time.LocalTime getStartTime() {
return startTime;
}
public void setStartTime(java.time.LocalTime startTime) {
this.startTime = startTime;
}
public java.time.LocalTime getEndTime() {
return endTime;
}
public void setEndTime(java.time.LocalTime endTime) {
this.endTime = endTime;
}
public String getRecurring() {
return recurring;
}
public void setRecurring(String recurring) {
this.recurring = recurring;
}
public int getParticipants() {
return participants;
}
public void setParticipants(int participants) {
this.participants = participants;
}
// This method is called (only with value 1 for now) to decrease participants count
public void decreaseCapacity(int numToDecreaseBy) {
this.participants = this.participants - numToDecreaseBy;
}
public String getMemberPrice() {
return memberPrice;
}
public void setMemberPrice(String memberPrice) {
this.memberPrice = memberPrice;
}
public String getNonMemberPrice() {
return nonMemberPrice;
}
public void setNonMemberPrice(String nonMemberPrice) {
this.nonMemberPrice = nonMemberPrice;
}
public String getLocation() {
return location;
}
public void setLocation(String location) {
this.location = location;
}
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
public List<User> getRegistrants() {
return registrants;
}
public void setGuests(ArrayList<User> registrants) {
this.registrants = registrants;
}
// This method is called to add a User to the registrants ArrayList
public void addRegistrant(User user) {
this.registrants.add(user);
}
public void removeRegistrant(User user) {
this.registrants.remove(user);
}
}
User.java class for User entity:
package ymca.tracker.application.data.entity;
import javax.persistence.Embeddable;
import javax.persistence.Entity;
import org.apache.commons.codec.digest.DigestUtils;
import org.apache.commons.lang3.RandomStringUtils;
import ymca.tracker.application.data.AbstractEntity;
#Embeddable
#Entity
public class User extends AbstractEntity {
private boolean familyAccount;
private String firstName;
private String lastName;
private String username;
private String password;
private String passwordSalt;
private String passwordHash;
private ymca.tracker.application.data.entity.Role role;
public User() {
}
public User(boolean familyAccount, String firstName, String lastName,
String username, String password, ymca.tracker.application.data.entity.Role role) {
this.familyAccount = familyAccount;
this.firstName = firstName;
this.lastName = lastName;
this.username = username;
this.role = role;
this.password = password;
this.passwordSalt = RandomStringUtils.random(32);
this.passwordHash = DigestUtils.sha1Hex(password + passwordSalt);
}
public boolean checkPassword(String password) {
return DigestUtils.sha1Hex(password + passwordSalt).equals(passwordHash);
}
public boolean getFamilyAccount() {
return familyAccount;
}
public void setFamilyAccount(boolean familyAccount) {
this.familyAccount = familyAccount;
}
public String getFirstName() {
return firstName;
}
public void setFirstName(String firstName) {
this.firstName = firstName;
}
public String getLastName() {
return lastName;
}
public void setLastName(String lastName) {
this.lastName = lastName;
}
public String getUsername() {
return username;
}
public void setUsername(String username) {
this.username = username;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
public String getPasswordSalt() {
return passwordSalt;
}
public void setPasswordSalt(String passwordSalt) {
this.passwordSalt = passwordSalt;
}
public String getPasswordHash() {
return passwordHash;
}
public void setPasswordHash(String passwordHash) {
this.passwordHash = passwordHash;
}
public ymca.tracker.application.data.entity.Role getRole() {
return role;
}
public void setRole(ymca.tracker.application.data.entity.Role role) {
this.role = role;
}
}
My Staff/Admin account uses this EventManagementView below to initially create the event:
package ymca.tracker.application.views.eventmanagement;
import com.vaadin.flow.component.Component;
import com.vaadin.flow.component.HasStyle;
import com.vaadin.flow.component.UI;
import com.vaadin.flow.component.button.Button;
import com.vaadin.flow.component.button.ButtonVariant;
import com.vaadin.flow.component.datepicker.DatePicker;
import com.vaadin.flow.component.dependency.Uses;
import com.vaadin.flow.component.formlayout.FormLayout;
import com.vaadin.flow.component.grid.Grid;
import com.vaadin.flow.component.grid.GridVariant;
import com.vaadin.flow.component.html.Div;
import com.vaadin.flow.component.icon.Icon;
import com.vaadin.flow.component.notification.Notification;
import com.vaadin.flow.component.orderedlayout.HorizontalLayout;
import com.vaadin.flow.component.splitlayout.SplitLayout;
import com.vaadin.flow.component.textfield.IntegerField;
import com.vaadin.flow.component.textfield.TextField;
import com.vaadin.flow.component.timepicker.TimePicker;
import com.vaadin.flow.data.binder.BeanValidationBinder;
import com.vaadin.flow.data.binder.ValidationException;
import com.vaadin.flow.router.BeforeEnterEvent;
import com.vaadin.flow.router.BeforeEnterObserver;
import com.vaadin.flow.router.PageTitle;
import com.vaadin.flow.router.Route;
import com.vaadin.flow.spring.data.VaadinSpringDataHelpers;
import java.time.Duration;
import java.util.ArrayList;
import java.util.List;
import java.util.Optional;
import java.util.UUID;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.PageRequest;
import ymca.tracker.application.data.entity.Events;
import ymca.tracker.application.data.entity.User;
import ymca.tracker.application.data.service.EventsService;
#PageTitle("Event Management")
#Route(value = "event-management")
#Uses(Icon.class)
public class EventManagementView extends Div implements BeforeEnterObserver {
private final String EVENTS_ID = "eventsID";
private final String EVENTS_EDIT_ROUTE_TEMPLATE = "event-management/%s/edit";
private Grid<Events> grid = new Grid<>(Events.class, false);
private TextField name;
private DatePicker startDate;
private DatePicker endDate;
private TimePicker startTime;
private TimePicker endTime;
private TextField recurring;
private IntegerField participants;
private TextField nonMemberPrice;
private TextField memberPrice;
private TextField location;
private TextField description;
private Button delete = new Button("Delete");
private Button cancel = new Button("Cancel");
private Button save = new Button("Save");
private BeanValidationBinder<Events> binder;
private Events events;
private EventsService eventsService;
public EventManagementView(#Autowired EventsService eventsService) {
this.eventsService = eventsService;
addClassNames("event-management-view", "flex", "flex-col", "h-full");
// Create UI
SplitLayout splitLayout = new SplitLayout();
splitLayout.setSizeFull();
createGridLayout(splitLayout);
createEditorLayout(splitLayout);
add(splitLayout);
// Configure Grid
grid.addColumn("name").setAutoWidth(true);
grid.addColumn("startDate").setAutoWidth(true);
grid.addColumn("endDate").setAutoWidth(true);
grid.addColumn("startTime").setAutoWidth(true);
grid.addColumn("endTime").setAutoWidth(true);
grid.addColumn("recurring").setAutoWidth(true);
grid.addColumn("participants").setAutoWidth(true);
grid.addColumn("nonMemberPrice").setAutoWidth(true);
grid.addColumn("memberPrice").setAutoWidth(true);
grid.addColumn("location").setAutoWidth(true);
grid.addColumn("description").setAutoWidth(true);
grid.setItems(query -> eventsService.list(
PageRequest.of(query.getPage(), query.getPageSize(), VaadinSpringDataHelpers.toSpringDataSort(query)))
.stream());
grid.addThemeVariants(GridVariant.LUMO_NO_BORDER);
grid.setHeightFull();
// when a row is selected or deselected, populate form
grid.asSingleSelect().addValueChangeListener(event -> {
if (event.getValue() != null) {
UI.getCurrent().navigate(String.format(EVENTS_EDIT_ROUTE_TEMPLATE, event.getValue().getId()));
} else {
clearForm();
UI.getCurrent().navigate(EventManagementView.class);
}
});
// Configure Form
binder = new BeanValidationBinder<>(Events.class);
// Bind fields. This is where you'd define e.g. validation rules
binder.bindInstanceFields(this);
delete.addClickListener(e -> {
binder.removeBean();
eventsService.delete(this.events.getId());
eventsService.update(this.events);
clearForm();
refreshGrid();
Notification.show("Event deleted");
UI.getCurrent().navigate(EventManagementView.class);
});
cancel.addClickListener(e -> {
clearForm();
refreshGrid();
});
save.addClickListener(e -> {
try {
if (this.events == null) {
this.events = new Events();
}
/*
Since the ArrayList isn't set by the grid editor, I hardcoded an
empty ArrayList to go with the new Event here
*/
ArrayList<User> registrants = new ArrayList<User>();
this.events.setGuests(registrants);
binder.writeBean(this.events);
eventsService.update(this.events);
clearForm();
refreshGrid();
Notification.show("Event details saved.");
UI.getCurrent().navigate(EventManagementView.class);
} catch (ValidationException validationException) {
Notification.show("An exception happened while trying to save the event details.");
}
});
}
#Override
public void beforeEnter(BeforeEnterEvent event) {
Optional<UUID> eventsId = event.getRouteParameters().get(EVENTS_ID).map(UUID::fromString);
if (eventsId.isPresent()) {
Optional<Events> eventsFromBackend = eventsService.get(eventsId.get());
if (eventsFromBackend.isPresent()) {
populateForm(eventsFromBackend.get());
} else {
Notification.show(
String.format("The requested event was not found, ID = %s", eventsId.get()), 3000,
Notification.Position.BOTTOM_START);
// when a row is selected but the data is no longer available,
// refresh grid
refreshGrid();
event.forwardTo(EventManagementView.class);
}
}
}
private void createEditorLayout(SplitLayout splitLayout) {
Div editorLayoutDiv = new Div();
editorLayoutDiv.setClassName("flex flex-col");
editorLayoutDiv.setWidth("400px");
Div editorDiv = new Div();
editorDiv.setClassName("p-l flex-grow");
editorLayoutDiv.add(editorDiv);
FormLayout formLayout = new FormLayout();
name = new TextField("Event Name");
startDate = new DatePicker("Start Date");
endDate = new DatePicker("End Date");
startTime = new TimePicker("Start Time");
startTime.setStep(Duration.ofMinutes(10));
endTime = new TimePicker("End Time");
endTime.setStep(Duration.ofMinutes(10));
recurring = new TextField("Recurring Event?");
participants = new IntegerField("Number of Participants");
nonMemberPrice = new TextField("Non-Member Price");
memberPrice = new TextField("Member Price");
location = new TextField("Location");
description = new TextField("Description");
Component[] fields = new Component[]{name, startDate, endDate, startTime, endTime, recurring, participants, nonMemberPrice, memberPrice, location, description};
for (Component field : fields) {
((HasStyle) field).addClassName("full-width");
}
formLayout.add(fields);
editorDiv.add(formLayout);
createButtonLayout(editorLayoutDiv);
splitLayout.addToSecondary(editorLayoutDiv);
}
private void createButtonLayout(Div editorLayoutDiv) {
HorizontalLayout buttonLayout = new HorizontalLayout();
buttonLayout.setClassName("w-full flex-wrap bg-contrast-5 py-s px-l");
buttonLayout.setSpacing(true);
cancel.addThemeVariants(ButtonVariant.LUMO_TERTIARY);
save.addThemeVariants(ButtonVariant.LUMO_PRIMARY);
delete.addThemeVariants(ButtonVariant.LUMO_ERROR);
buttonLayout.add(save, cancel, delete);
editorLayoutDiv.add(buttonLayout);
}
private void createGridLayout(SplitLayout splitLayout) {
Div wrapper = new Div();
wrapper.setId("grid-wrapper");
wrapper.setWidthFull();
splitLayout.addToPrimary(wrapper);
wrapper.add(grid);
}
private void refreshGrid() {
grid.select(null);
grid.getLazyDataView().refreshAll();
}
private void clearForm() {
populateForm(null);
}
private void populateForm(Events value) {
this.events = value;
binder.readBean(this.events);
}
}
The portion of code that handles event sign up for a User (If you'd prefer to see the whole class for this view instead of just this method please let me know):
private VerticalLayout createSignUpFormLayout(Dialog signUpForm) {
signUpForm.getElement().setAttribute("aria-label", "Registration Form");
TextField firstName = new TextField("First Name");
TextField lastName = new TextField("Last Name");
H2 headline = new H2("Registration Form");
headline.getStyle().set("margin-top", "0");
Button cancel = new Button("Cancel", e -> signUpForm.close());
Button submit = new Button("Submit", e -> {
if(fillChecker(firstName.getValue(), lastName.getValue()) == true) {
String fn = firstName.getValue();
String ln = lastName.getValue();
User guest = new User(false, fn, ln,
"null", "null", Role.GUEST);
Set<Events> selected = grid.getSelectedItems();
Events[] curEvent = selected.toArray(new Events[1]);
Events selectedEvent = curEvent[0];
if(selectedEvent == null) {
Notification.show("No Event Selected!", 5000, Position.TOP_CENTER);
} else {
userRepository.save(guest); // Saves guest sign-up info to user repository
selectedEvent.addRegistrant(guest);; // Adds guest sign-up info to events guest list
selectedEvent.decreaseCapacity(1); // Decrease events participants count by 1
signUpForm.close();
Notification.show("Registered 1 Guest", 5000, Position.TOP_CENTER);
}
} else {
Notification.show("Please complete the form to register", 5000, Position.TOP_CENTER);
}
});

JPA Repository save method creates new instance instead of merging

In my project there are events that users sign up for. When a user signs up for an event, the events capacity decreases by 1 and the users name is added to a String attribute for the event. After these changes are made to the event in my code, I call eventsRepository.save(event), which I thought just merges the newly updated event, but for some reason my database is just creating a whole new event with a new ID with the new values.
Here are some pictures of the issue:
The event data before a user signs up (UUID in repository included)
The event data after a user signs up
Code for a User:
import javax.persistence.Embeddable;
import javax.persistence.Entity;
import org.apache.commons.codec.digest.DigestUtils;
import org.apache.commons.lang3.RandomStringUtils;
import ymca.tracker.application.data.AbstractEntity;
#Embeddable
#Entity
public class User extends AbstractEntity {
private boolean familyAccount;
private String firstName;
private String lastName;
private String username;
private String password;
private String passwordSalt;
private String passwordHash;
private ymca.tracker.application.data.entity.Role role;
public User() {
}
public User(boolean familyAccount, String firstName, String lastName,
String username, String password, ymca.tracker.application.data.entity.Role role) {
this.familyAccount = familyAccount;
this.firstName = firstName;
this.lastName = lastName;
this.username = username;
this.role = role;
this.password = password;
this.passwordSalt = RandomStringUtils.random(32);
this.passwordHash = DigestUtils.sha1Hex(password + passwordSalt);
}
public boolean checkPassword(String password) {
return DigestUtils.sha1Hex(password + passwordSalt).equals(passwordHash);
}
public boolean getFamilyAccount() {
return familyAccount;
}
public void setFamilyAccount(boolean familyAccount) {
this.familyAccount = familyAccount;
}
public String getFirstName() {
return firstName;
}
public void setFirstName(String firstName) {
this.firstName = firstName;
}
public String getLastName() {
return lastName;
}
public void setLastName(String lastName) {
this.lastName = lastName;
}
public String getUsername() {
return username;
}
public void setUsername(String username) {
this.username = username;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
public String getPasswordSalt() {
return passwordSalt;
}
public void setPasswordSalt(String passwordSalt) {
this.passwordSalt = passwordSalt;
}
public String getPasswordHash() {
return passwordHash;
}
public void setPasswordHash(String passwordHash) {
this.passwordHash = passwordHash;
}
public ymca.tracker.application.data.entity.Role getRole() {
return role;
}
public void setRole(ymca.tracker.application.data.entity.Role role) {
this.role = role;
}
}
Code for an Events:
import java.time.LocalDate;
import java.time.LocalTime;
import java.util.ArrayList;
import java.util.List;
import javax.persistence.ElementCollection;
import javax.persistence.Embeddable;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.OneToMany;
import ymca.tracker.application.data.AbstractEntity;
#Embeddable
#Entity
public class Events extends AbstractEntity {
private String name;
private java.time.LocalDate startDate;
private java.time.LocalDate endDate;
private java.time.LocalTime startTime;
private java.time.LocalTime endTime;
private String recurring;
private int participants;
private String nonMemberPrice;
private String memberPrice;
private String location;
private String description;
private String users;
// Not currently used
#ElementCollection
#OneToMany(fetch = FetchType.LAZY)
private List<User> registrants = new ArrayList<User>();
public Events() {
}
public Events(String name, LocalDate startDate, LocalDate endDate, LocalTime startTime, LocalTime endTime,
String recurring, int participants, String nonMemberPrice, String memberPrice, String location,
String description, String users, List<User> registrants) {
this.name = name;
this.startDate = startDate;
this.endDate = endDate;
this.startTime = startTime;
this.endTime = endTime;
this.recurring = recurring;
this.participants = participants;
this.nonMemberPrice = nonMemberPrice;
this.memberPrice = memberPrice;
this.location = location;
this.description = description;
this.users = " ";
this.registrants = registrants;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public java.time.LocalDate getStartDate() {
return startDate;
}
public void setStartDate(java.time.LocalDate startDate) {
this.startDate = startDate;
}
public java.time.LocalDate getEndDate() {
return endDate;
}
public void setEndDate(java.time.LocalDate endDate) {
this.endDate = endDate;
}
public java.time.LocalTime getStartTime() {
return startTime;
}
public void setStartTime(java.time.LocalTime startTime) {
this.startTime = startTime;
}
public java.time.LocalTime getEndTime() {
return endTime;
}
public void setEndTime(java.time.LocalTime endTime) {
this.endTime = endTime;
}
public String getRecurring() {
return recurring;
}
public void setRecurring(String recurring) {
this.recurring = recurring;
}
public int getParticipants() {
return participants;
}
public void setParticipants(int participants) {
this.participants = participants;
}
public void decreaseCapacity(int numToDecreaseBy) {
this.participants = this.participants - numToDecreaseBy;
}
public String getMemberPrice() {
return memberPrice;
}
public void setMemberPrice(String memberPrice) {
this.memberPrice = memberPrice;
}
public String getNonMemberPrice() {
return nonMemberPrice;
}
public void setNonMemberPrice(String nonMemberPrice) {
this.nonMemberPrice = nonMemberPrice;
}
public String getLocation() {
return location;
}
public void setLocation(String location) {
this.location = location;
}
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
public String getUsers() {
return users;
}
public void setUsers(String users) {
this.users = users;
}
public void addUser(String user) {
this.users = this.users + user + "\n";
}
public List<User> getRegistrants() {
return registrants;
}
public void setGuests(ArrayList<User> registrants) {
this.registrants = registrants;
}
public void addRegistrant(User user) {
this.registrants.add(user);
}
public void removeRegistrant(User user) {
this.registrants.remove(user);
}
public boolean checkRegistrant(User user) {
return this.registrants.contains(user);
}
}
Code for Guest Users to sign up located in this View (save call is marked with comment) (updated with id column code):
import com.vaadin.flow.component.button.Button;
import com.vaadin.flow.component.button.ButtonVariant;
import com.vaadin.flow.component.dialog.Dialog;
import com.vaadin.flow.component.grid.Grid;
import com.vaadin.flow.component.grid.Grid.SelectionMode;
import com.vaadin.flow.component.grid.GridVariant;
import com.vaadin.flow.component.grid.dataview.GridListDataView;
import com.vaadin.flow.component.html.Div;
import com.vaadin.flow.component.html.H2;
import com.vaadin.flow.component.notification.Notification;
import com.vaadin.flow.component.notification.Notification.Position;
import com.vaadin.flow.component.orderedlayout.HorizontalLayout;
import com.vaadin.flow.component.orderedlayout.VerticalLayout;
import com.vaadin.flow.component.orderedlayout.FlexComponent.Alignment;
import com.vaadin.flow.component.textfield.TextField;
import com.vaadin.flow.router.PageTitle;
import com.vaadin.flow.router.Route;
import java.util.ArrayList;
import java.util.List;
import java.util.Set;
import java.util.UUID;
import ymca.tracker.application.data.entity.Events;
import ymca.tracker.application.data.entity.Role;
import ymca.tracker.application.data.entity.User;
import ymca.tracker.application.data.service.EventsRepository;
import ymca.tracker.application.data.service.EventsService;
import ymca.tracker.application.data.service.UserRepository;
import ymca.tracker.application.views.MainLayout;
#PageTitle("Guest Events")
#Route(value = "guest-events", layout = MainLayout.class)
public class GuestEventsView extends Div {
private EventsService eventsService;
private EventsRepository eventsRepository;
private UserRepository userRepository;
private Grid<Events> grid;
private GridListDataView<Events> gridListDataView;
private Grid.Column<Events> idColumn;
private Grid.Column<Events> signUpColumn;
private Grid.Column<Events> nameColumn;
private Grid.Column<Events> startDateColumn;
private Grid.Column<Events> endDateColumn;
private Grid.Column<Events> startTimeColumn;
private Grid.Column<Events> endTimeColumn;
private Grid.Column<Events> recurringColumn;
private Grid.Column<Events> participantsColumn;
private Grid.Column<Events> priceColumn;
private Grid.Column<Events> locationColumn;
private Grid.Column<Events> descriptionColumn;
public GuestEventsView(EventsService eventsService, EventsRepository eventsRepository, UserRepository userRepository) {
this.eventsService = eventsService;
this.eventsRepository = eventsRepository;
this.userRepository = userRepository;
addClassName("guest-events-view");
setSizeFull();
Button signUpButton = createSignUpButton();
add(signUpButton);
createGrid();
add(grid);
}
private void createGrid() {
createGridComponent();
addColumnsToGrid();
}
private void createGridComponent() {
grid = new Grid<>();
grid.setSelectionMode(SelectionMode.SINGLE);
grid.addThemeVariants(GridVariant.LUMO_NO_BORDER, GridVariant.LUMO_COLUMN_BORDERS);
grid.setHeight("100%");
List<Events> events = getEvents();
gridListDataView = grid.setItems(events);
}
private void addColumnsToGrid() {
createIdColumn();
createNameColumn();
createStartDateColumn();
createEndDateColumn();
createStartTimeColumn();
createEndTimeColumn();
createRecurringColumn();
createParticipantsColumn();
createPriceColumn();
createLocationColumn();
createDescriptionColumn();
}
private Button createSignUpButton() {
// Create the Dialog object which will be the signUpForm
Dialog signUpForm = new Dialog();
// Create the layout for the signUpForm, passing in the Dialog and selected Event
VerticalLayout signUpFormLayout = createSignUpFormLayout(signUpForm);
// Add the created layout to the signUpForm
signUpForm.add(signUpFormLayout);
// Only the signUpForm can be interacted with when it appears on the screen
signUpForm.setModal(true);
Button signUpButton = new Button("Sign Up");
signUpButton.addClickListener(e -> signUpForm.open());
return signUpButton;
}
private VerticalLayout createSignUpFormLayout(Dialog signUpForm) {
signUpForm.getElement().setAttribute("aria-label", "Registration Form");
TextField firstName = new TextField("First Name");
TextField lastName = new TextField("Last Name");
H2 headline = new H2("Registration Form");
headline.getStyle().set("margin-top", "0");
Button cancel = new Button("Cancel", e -> signUpForm.close());
Button submit = new Button("Submit", e -> {
if(fillChecker(firstName.getValue(), lastName.getValue()) == true) {
String fn = firstName.getValue();
String ln = lastName.getValue();
User guest = new User(false, fn, ln,
"null", "null", Role.GUEST);
Set<Events> selected = grid.getSelectedItems();
Events[] curEvent = selected.toArray(new Events[1]);
Events selectedEvent = curEvent[0];
if(selectedEvent == null) {
Notification.show("No Event Selected!", 5000, Position.TOP_CENTER);
} else {
userRepository.save(guest); // Saves guest sign-up info to user repository
selectedEvent.addUser(fn + " " + ln);
selectedEvent.decreaseCapacity(1); // Decrease events participants count by 1
// ISSUE HERE
// Currently saves new version of event instead of merging
UUID toDelete = selectedEvent.getId();
eventsRepository.save(selectedEvent);
eventsRepository.deleteById(toDelete);
signUpForm.close();
Notification.show("Registered 1 Guest", 5000, Position.TOP_CENTER);
}
} else {
Notification.show("Please complete the form to register", 5000, Position.TOP_CENTER);
}
});
submit.addThemeVariants(ButtonVariant.LUMO_PRIMARY);
HorizontalLayout buttonLayout = new HorizontalLayout(cancel, submit);
buttonLayout.setAlignItems(Alignment.END);
buttonLayout.getStyle().set("margin-top", "var(--lumo-space-m");
VerticalLayout signUpFormLayout = new VerticalLayout(headline, firstName, lastName, buttonLayout);
signUpFormLayout.setPadding(false);
signUpFormLayout.setSpacing(false);
signUpFormLayout.setAlignItems(Alignment.STRETCH);
signUpFormLayout.getStyle().set("width", "18rem").set("max-width", "100%");
return signUpFormLayout;
}
private boolean fillChecker(String firstName, String lastName) {
if(firstName.equals("") || lastName.equals("")) {
return false;
}
return true;
}
private void createIdColumn() {
idColumn = grid.addColumn(Events::getId, "id").setHeader("ID").setAutoWidth(true);
}
private void createNameColumn() {
nameColumn = grid.addColumn(Events::getName, "name").setHeader("Name").setAutoWidth(true);
}
private void createStartDateColumn() {
startDateColumn = grid.addColumn(Events::getStartDate, "startDate").setHeader("Start Date").setAutoWidth(true);
}
private void createEndDateColumn() {
startDateColumn = grid.addColumn(Events::getEndDate, "endDate").setHeader("End Date").setAutoWidth(true);
}
private void createStartTimeColumn() {
startTimeColumn = grid.addColumn(Events::getStartTime, "startTime").setHeader("Start Time").setAutoWidth(true);
}
private void createEndTimeColumn() {
startDateColumn = grid.addColumn(Events::getEndTime, "endTime").setHeader("End Time").setAutoWidth(true);
}
private void createRecurringColumn() {
recurringColumn = grid.addColumn(Events::getRecurring, "recurring").setHeader("Recurring?").setAutoWidth(true);
}
private void createParticipantsColumn() {
participantsColumn = grid.addColumn(Events::getParticipants, "participants").setHeader("Capacity").setAutoWidth(true);
}
private void createPriceColumn() {
priceColumn = grid.addColumn(Events::getNonMemberPrice, "price").setHeader("Price").setAutoWidth(true);
}
private void createLocationColumn() {
locationColumn = grid.addColumn(Events::getLocation, "location").setHeader("Location").setAutoWidth(true);
}
private void createDescriptionColumn() {
descriptionColumn = grid.addColumn(Events::getDescription, "description").setHeader("Description").setAutoWidth(true);
}
private List<Events> getEvents() {
List<Events> list = eventsService.findAllEvents();
List<Events> toReturn = new ArrayList<Events>();
Events e;
int size = list.size();
for(int i = 0; i < size; i++) {
Events temp = list.get(i);
e = createEvents(temp.getName(), temp.getStartDate(), temp.getEndDate(), temp.getStartTime(), temp.getEndTime(),
temp.getRecurring(), temp.getParticipants(), temp.getNonMemberPrice(), temp.getLocation(), temp.getDescription());
toReturn.add(e);
}
return toReturn;
}
private Events createEvents(String name, java.time.LocalDate startDate, java.time.LocalDate endDate,
java.time.LocalTime startTime, java.time.LocalTime endTime, String recurring, int participants,
String price, String location, String description) {
Events e = new Events();
e.setName(name);
e.setStartDate(startDate);
e.setEndDate(endDate);
e.setStartTime(startTime);
e.setEndTime(endTime);
e.setRecurring(recurring);
e.setParticipants(participants);
e.setNonMemberPrice(price);
e.setLocation(location);
e.setDescription(description);
return e;
}
};
Here is my AbstractEntity class:
import java.util.UUID;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.MappedSuperclass;
#MappedSuperclass
public abstract class AbstractEntity {
#Id
#GeneratedValue
private UUID id;
public UUID getId() {
return id;
}
public void setId(UUID id) {
this.id = id;
}
#Override
public int hashCode() {
if (id != null) {
return id.hashCode();
}
return super.hashCode();
}
#Override
public boolean equals(Object obj) {
if (!(obj instanceof AbstractEntity)) {
return false; // null or other class
}
AbstractEntity other = (AbstractEntity) obj;
if (id != null) {
return id.equals(other.id);
}
return super.equals(other);
}
}
Results of adding an Id Column to the sign up grid:
What does AbstractEntity contain? I'm guessing that your are missing the #Id annotation on your unique identifier for events, or that it is not mapped and goes missing before the entity is saved to the database. Without the id JPA has no way of knowing that this is an updated entity instead of a new one.
Debug the code and check that the entity contains the right ID at this line:
eventsRepository.save(selectedEvent)

save data to the database using spring boot

when I post the data using the postman, the server replies with error code 500. the NetBeans terminal show:(java.sql.SQLIntegrityConstraintViolationException: Column 'email' cannot be null)
bellow my entityclass:
#Entity(name="user")
public class UserEntity {
#Id
#GeneratedValue
private long id;
#Column(nullable = true)
private String userId;
#Column(nullable = true)
private String FirstName;
#Column(nullable = true)
private String LastName;
#Column(nullable = true)
private String Email;
#Column(nullable = true)
private String Password;
#Column(nullable = true)
private String encryptedPassword;
#Column()
private String emailVerificationToken;
#Column()
private Boolean emailVerificationStatus=false;
public long getId() {
return id;
}
public void setId(long id) {
this.id = id;
}
public String getUserId() {
return userId;
}
public void setUserId(String userId) {
this.userId = userId;
}
public String getFirstName() {
return FirstName;
}
public void setFirstName(String FirstName) {
this.FirstName = FirstName;
}
public String getLastName() {
return LastName;
}
public void setLastName(String LastName) {
this.LastName = LastName;
}
public String getEmail() {
return Email;
}
public void setEmail(String Email) {
this.Email = Email;
}
public String getPassword() {
return Password;
}
public void setPassword(String Password) {
this.Password = Password;
}
public String getEncryptedPassword() {
return encryptedPassword;
}
public void setEncryptedPassword(String encryptedPassword) {
this.encryptedPassword = encryptedPassword;
}
public String getEmailVerificationToken() {
return emailVerificationToken;
}
public void setEmailVerificationToken(String emailVerificationToken) {
this.emailVerificationToken = emailVerificationToken;
}
public Boolean getEmailVerificationStatus() {
return emailVerificationStatus;
}
public void setEmailVerificationStatus(Boolean emailVerificationStatus) {
this.emailVerificationStatus = emailVerificationStatus;
}
}
bellow is my service implementation class:
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package com.example.mobile.demo.impl;
import com.example.mobile.demo.DTo.UserDto;
import com.example.mobile.demo.Entity.UserEntity;
import com.example.mobile.demo.repository.UserRepository;
import com.example.mobile.demo.service.UserService;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
/**
*
* #author iphone
*/
#Service
public class UserserviceImpl implements UserService{
#Autowired
UserRepository userRepository;//it is in the data layer so we need the repository to save in the database
#Override
public UserDto createuser(UserDto user) {
UserEntity userentity=new UserEntity();
BeanUtils.copyProperties(user, userentity);
System.out.println("the properties has been copied to the entity");
userentity.setEncryptedPassword("test");
userentity.setUserId("testID");
System.out.println("encryptef passwird and user id has been set");
UserEntity stotedValue=userRepository.save(userentity);
UserDto returnValue=new UserDto();
BeanUtils.copyProperties(stotedValue, returnValue);
return returnValue;
}
}
my model class:
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package com.example.mobile.demo.modoel;
/**
*
* #author iphone
*/
public class Model {
private String FirstName;
private String LastName;
private String Email;
private String Password;
public String getFirstName() {
return FirstName;
}
public void setFistName(String FirstName) {
this.FirstName = FirstName;
}
public String getLastName() {
return LastName;
}
public void setLastName(String LastName) {
this.LastName = LastName;
}
public String getEmail() {
return Email;
}
public void setEmail(String Email) {
this.Email = Email;
}
public String getPassword() {
return Password;
}
public void setPassword(String password) {
this.Password = password;
}
}
bellow is what Iam sending in the post request in the postman:
{
"FirstName":"jack",
"LastName":"testjack",
"Password":"124",
"Email":"emailTest#gmail.com"
}
The issue is in json to java Model mapping.
You need to rename your Model.java properties in this way:
Email -> email
FirstName -> firstName
Or add #JsonProperty("name"):
#JsonProperty("email")
private String Email;
Don't forget json changes, if you choose properties renaming:
{
"firstName":"jack",
"lastName":"testjack",
"password":"124",
"email":"emailTest#gmail.com"
}

JPA: How to map one entity's property value to collection property of another entity

I have two entities, naming Sport and Image.
As the title above, how can I map the value of property, sportId at Sport to the #ManyToOne collection property at Image? For instance, I want the value of sportId (eg. 1) to be displayed at collection property field of sportId at Image. How can I achieve this?
Sport.java
#Views({#View(members= "title; date; estimatedCost; attendance; remark; images"),
#View(name="NoImagesCollection", members= "sportId; title; date; estimatedCost; attendance; remark")})
#Entity
public class Sport {
//******************************FORM ID******************************//
#Id
#Hidden
#GeneratedValue(strategy = GenerationType.AUTO)
#Column(name="SPORT_ID", length=10, unique = true, nullable = false, updatable = false)
private int sportId;
#NoCreate
#NoModify
#OneToMany(fetch = FetchType.LAZY,cascade=CascadeType.ALL,mappedBy="sports")
private Collection<Image> images;
//******************************TITLE******************************//
#Column(name="SPORT_TITLE", precision=2000)
#Required
private String title;
//******************************DATE START******************************//
// #Stereotype("DATE")
#Column(name="SPORT_DATE")
#Required
private Date date;
//******************************ESTIMATED COST******************************//
#Hidden
#Stereotype("MONEY")
#Column(name="SPORT_EST_COST")
#Required
private BigDecimal estimatedCost; // Include the import java.math.* BigDecimal is typically used for money
//******************************ESTIMATED ATTENDEES******************************//
#Hidden
#Column(name="SPORT_ATTENDANCE", length=10)
#Required
private int attendance;
//******************************REMARK******************************//
#Hidden
#Editor("TextAreaNoFrame")
#Stereotype("MEMO")
#Column(name="SPORT_REMARK", precision=2000)
private String remark;
//******************************ENTERED DATE******************************//
#Hidden
#Column(name="ENTERED_DATE")
#Temporal(TemporalType.TIMESTAMP)
private Date enteredDate;
#PrePersist
private void setCreateDate() {
enteredDate = new Date();
}
//******************************MODIFIED DATE******************************//
#Hidden
#Column(name="MODIFIED_DATE")
#Temporal(TemporalType.TIMESTAMP)
private Date modifiedDate;
#PostUpdate
private void updateModifyDate() {
modifiedDate = new Date();
}
//******************************GETTERS AND SETTERS FOR ALL PROPERTIES******************************//
public int getSportId() {
return sportId;
}
public void setSportId(int sportId) {
this.sportId = sportId;
}
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
public Date getDate() {
return date;
}
public void setDate(Date date) {
this.date = date;
}
public BigDecimal getEstimatedCost() {
return estimatedCost;
}
public void setEstimatedCost(BigDecimal estimatedCost) {
this.estimatedCost = estimatedCost;
}
public int getAttendance() {
return attendance;
}
public void setAttendance(int attendance) {
this.attendance = attendance;
}
public String getRemark() {
return remark;
}
public void setRemark(String remark) {
this.remark = remark;
}
public Date getEnteredDate() {
return enteredDate;
}
public void setEnteredDate(Date enteredDate) {
this.enteredDate = enteredDate;
}
public Date getModifiedDate() {
return modifiedDate;
}
public void setModifiedDate(Date modifiedDate) {
this.modifiedDate = modifiedDate;
}
public Collection<Image> getImages() {
return images;
}
public void setImages(Collection<Image> images) {
this.images = images;
}
}
Image.java
#View(members="sports; image")
#Entity
public class Image {
#Id
#Hidden
#GeneratedValue(strategy = GenerationType.AUTO)
#Column(name="IMG_ID", unique = true, nullable = false, updatable = false)
private int imgId;
#Required
#Column(name="IMG_IMAGE")
#Stereotype("PHOTO")
private byte [] image;
#ReferenceView("NoImagesCollection")
#Required
#NoFrame
#ManyToOne(optional=true)
#JoinColumn(name="IMG_SPORT_ID", nullable = false)
private Sport sports;
#Hidden
#Column(name="ENTERED_DATE")
#Temporal(TemporalType.TIMESTAMP)
private Date penteredDate;
#PrePersist
private void setCreateDate() {
penteredDate = new Date();
}
#Hidden
#Column(name="MODIFIED_DATE")
#Temporal(TemporalType.TIMESTAMP)
private Date pmodifiedDate;
#PostUpdate
private void updateModifyDate() {
pmodifiedDate = new Date();
}
public int getImgId() {
return imgId;
}
public void setImgId(int imgId) {
this.imgId = imgId;
}
public byte[] getImage() {
return image;
}
public void setImage(byte[] image) {
this.image = image;
}
public Sport getSports() {
return sports;
}
public void setSports(Sport sports) {
this.sports = sports;
}
public Date getPenteredDate() {
return penteredDate;
}
public void setPenteredDate(Date penteredDate) {
this.penteredDate = penteredDate;
}
public Date getPmodifiedDate() {
return pmodifiedDate;
}
public void setPmodifiedDate(Date pmodifiedDate) {
this.pmodifiedDate = pmodifiedDate;
}
}
ListSportImagesAction.java
public class ListSportImagesAction extends TabBaseAction implements IForwardAction {
private int row;
#Inject
private Tab tab;
public void execute() throws Exception {
Map sportKey = (Map) tab.getTableModel().getObjectAt(row);
int sportId = ((Integer) sportKey.get("sportId")).intValue();
Tab imageTab = (Tab)getContext().get("CkSurvey", getForwardURI(), "xava_tab");
imageTab.setBaseCondition("${sport.sportId} = " + sportId);
System.out.println("id================="+sportId);
}
public int getRow() {
return row;
}
public void setRow(int row) {
this.row = row;
}
public Tab getTab() {
return tab;
}
public void setTab(Tab tab) {
this.tab = tab;
}
#Override
public String getForwardURI() {
return "/m/Image";
}
#Override
public boolean inNewWindow() {
return true;
}
}
Any guidance provided will be appreciated.
--Edited--
I have added the code for the action that map the value. I fail to display the value at the property field, although it is displayed at Eclipse's console.

Rest Client: Javax.ws.rs

i'm starting with Rest and don't have no idea how to implement it properly. I got an exercise: i must implement a Rest-Client with the RestClient-API from javax.ws.rs standard library and i tried by using the code below, but i'm getting a null pointer exception. But the resource are there and when i try directly from the browser (http://localhost:8080/sep/rest/customers/112). Now my question how can i do it properly. Some constraints, i must use XML (not JSON) for the Data-support.
Hier my client-code:
public Response createCustomer(Customer customer){
log.info("Starting: Rest Create a Customer with Name: " + Customer.class.getName());
this.customerWebTarget = this.client.target(URL);
Response response = this.customerWebTarget.request().
buildPost(Entity.entity(customer, MediaType.APPLICATION_XML)).invoke();
log.info("Ending: Rest Create a Customer with Name: " + response.getEntity().getClass().getName());
return response;
}
CustomerResource-Code:
#Path("customers")
public class CustomerResource implements IAllowedMethods<Customer> {
private static final long serialVersionUID = -6367055402693237329L;
private Logger logger = Logger.getLogger(CustomerResource.class.getName());
#Inject
private CustomerService service;
public CustomerResource() {
logger.info("create of instance " + this.getClass().getName());
}
#Override
#GET
#Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
public Response get() {
List<Customer> list = service.loadAll(Customer.FINDALL, Customer.class);
if (list != null && !list.isEmpty()) {
ResponseCustomerList responseList = new ResponseCustomerList();
responseList.setList(list);
return Response.ok(responseList).build();
}
return Response.status(Status.NOT_FOUND).build();
}
.
.
.
Customer Code:
import de.ostfalia.sep.adapter.XMLIntegerAdapter;
#XmlRootElement
#XmlAccessorType(XmlAccessType.FIELD)
public class Customer implements Serializable {
private static final long serialVersionUID = 80668466040239995L;
#XmlID
#XmlJavaTypeAdapter(XMLIntegerAdapter.class)
private Integer customerNumber;
private String customerName;
private String contactLastName;
private String contactFirstName;
private String phone;
private String addressLine1;
private String addressLine2;
private String city;
private String state;
private String postalCode;
private String country;
#XmlIDREF
private Employee salesRepEmployee;
private BigDecimal creditLimit;
private Set<Payment> payments;
private Set<Order> orders;
public Customer() {
}
public Customer(Integer customernumber) {
this.customerNumber = customernumber;
}
public Customer(Integer customerNumber, String customerName, String contactLastName, String contactFirstName,
String phone, String addressLine1, String city, String country) {
this.customerNumber = customerNumber;
this.customerName = customerName;
this.contactLastName = contactLastName;
this.contactFirstName = contactFirstName;
this.phone = phone;
this.addressLine1 = addressLine1;
this.city = city;
this.country = country;
}
public Integer getCustomerNumber() {
return customerNumber;
}
public void setCustomerNumber(Integer customerNumber) {
this.customerNumber = customerNumber;
}
public String getCustomerName() {
return customerName;
}
public void setCustomerName(String customerName) {
this.customerName = customerName;
}
public String getContactLastName() {
return contactLastName;
}
public void setContactLastName(String contactLastName) {
this.contactLastName = contactLastName;
}
public String getContactFirstName() {
return contactFirstName;
}
public void setContactFirstName(String contactFirstName) {
this.contactFirstName = contactFirstName;
}
public String getPhone() {
return phone;
}
public void setPhone(String phone) {
this.phone = phone;
}
public String getAddressLine1() {
return addressLine1;
}
public void setAddressLine1(String addressLine1) {
this.addressLine1 = addressLine1;
}
public String getAddressLine2() {
return addressLine2;
}
public void setAddressLine2(String addressLine2) {
this.addressLine2 = addressLine2;
}
public String getCity() {
return city;
}
public void setCity(String city) {
this.city = city;
}
public String getState() {
return state;
}
public void setState(String state) {
this.state = state;
}
public String getPostalCode() {
return postalCode;
}
public void setPostalCode(String postalCode) {
this.postalCode = postalCode;
}
public String getCountry() {
return country;
}
public void setCountry(String country) {
this.country = country;
}
public Employee getSalesRepEmployee() {
return salesRepEmployee;
}
public void setSalesRepEmployee(Employee salesRepEmployee) {
this.salesRepEmployee = salesRepEmployee;
}
public BigDecimal getCreditLimit() {
return creditLimit;
}
public void setCreditLimit(BigDecimal creditLimit) {
this.creditLimit = creditLimit;
}
#Override
public int hashCode() {
int hash = 0;
hash += (customerNumber != null ? customerNumber.hashCode() : 0);
return hash;
}
#Override
public boolean equals(Object object) {
// TODO: Warning - this method won't work in the case the id fields are
// not set
if (!(object instanceof Customer)) {
return false;
}
Customer other = (Customer) object;
if ((this.customerNumber == null && other.customerNumber != null)
|| (this.customerNumber != null && !this.customerNumber.equals(other.customerNumber))) {
return false;
}
return true;
}
#Override
public String toString() {
return customerNumber.toString();
}
public Set<Payment> getPayments() {
return payments;
}
public void setPayments(Set<Payment> payments) {
this.payments = payments;
}
public Set<Order> getOrders() {
return orders;
}
public void setOrders(Set<Order> orders) {
this.orders = orders;
}
}
Instead of response.getEntity(), use response.readEntity(String.class) to get the data as a String. If you want to deserialize it to a POJO, then just pass that class to the readEntity.
Also you should make sure to check the status code (response.getStatus()) to make sure it's a success status.