mirror of
https://github.com/spring-projects/spring-petclinic.git
synced 2025-07-22 15:25:49 +00:00
solve bug of fechType
This commit is contained in:
parent
3d1868225a
commit
4732442672
58 changed files with 350 additions and 431 deletions
|
@ -11,13 +11,15 @@ public final class CommonAttribute {
|
|||
|
||||
public static final String ID = "id";
|
||||
|
||||
public static final String EMAIL = "email";
|
||||
|
||||
public static final String NAME = "name";
|
||||
|
||||
public static final String NEW = "new";
|
||||
|
||||
public static final String OWNER = "owner";
|
||||
|
||||
public static final String OWNER_ID = "ownerId";
|
||||
public static final String OWNER_ID = "id";
|
||||
|
||||
public static final String OWNER_LAST_NAME = "lastName";
|
||||
|
||||
|
@ -31,6 +33,8 @@ public final class CommonAttribute {
|
|||
|
||||
public static final String OWNER_PETS = "pets";
|
||||
|
||||
public static final String PASSWORD = "password";
|
||||
|
||||
public static final String PET = "pet";
|
||||
|
||||
public static final String SELECTIONS = "selections";
|
||||
|
|
|
@ -38,6 +38,8 @@ public class CommonParameter {
|
|||
|
||||
public static final int ROLE_MAX = 10;
|
||||
|
||||
public static final int PRIVILEGE_MAX = 10;
|
||||
|
||||
public static final int ZIP_MAX = 6;
|
||||
|
||||
public static final int ZIP_MIN = 5;
|
||||
|
|
|
@ -6,6 +6,7 @@ import org.springframework.context.annotation.Configuration;
|
|||
import org.springframework.context.annotation.PropertySource;
|
||||
|
||||
import org.springframework.core.env.Environment;
|
||||
import org.springframework.samples.petclinic.common.CommonEndPoint;
|
||||
import org.springframework.security.authentication.AuthenticationManager;
|
||||
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
|
||||
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
|
||||
|
@ -60,32 +61,31 @@ public class WebSecurityConfig extends WebSecurityConfigurerAdapter {
|
|||
http.authorizeRequests()
|
||||
.antMatchers("/").permitAll()
|
||||
.antMatchers("/login", "/logout", "/register","/confirm-account").permitAll()
|
||||
.antMatchers("/websocket/**", "/topic/**","/topic/public", "/app/**").permitAll()
|
||||
.antMatchers("/websocket/**", "/topic/**", "/app/**").permitAll()
|
||||
.antMatchers("/resources/**").permitAll()
|
||||
.antMatchers("/h2-console/**").permitAll()
|
||||
.antMatchers("/**").authenticated()
|
||||
.antMatchers("/edit/**").authenticated()
|
||||
.anyRequest().authenticated()
|
||||
.and()
|
||||
.formLogin()
|
||||
.loginPage("/login")
|
||||
.loginProcessingUrl("/login")
|
||||
.defaultSuccessUrl("/login/success", true)
|
||||
.loginPage(CommonEndPoint.LOGIN)
|
||||
.loginProcessingUrl(CommonEndPoint.LOGIN)
|
||||
.defaultSuccessUrl(CommonEndPoint.LOGIN_SUCCESS, true)
|
||||
.usernameParameter("email")
|
||||
.passwordParameter("password")
|
||||
.failureUrl("/login")
|
||||
.failureUrl(CommonEndPoint.LOGIN)
|
||||
.permitAll()
|
||||
.and()
|
||||
.logout()
|
||||
.logoutUrl("/logout")
|
||||
.logoutSuccessUrl("/logout/success")
|
||||
.logoutUrl(CommonEndPoint.LOGOUT)
|
||||
.logoutSuccessUrl(CommonEndPoint.LOGOUT_SUCCESS)
|
||||
.invalidateHttpSession(true)
|
||||
.permitAll()
|
||||
.and()
|
||||
.oauth2Login()
|
||||
.loginPage("/login")
|
||||
.defaultSuccessUrl("/oauth2/success", true)
|
||||
.failureUrl("/login")
|
||||
.loginPage(CommonEndPoint.LOGIN)
|
||||
.defaultSuccessUrl(CommonEndPoint.OAUTH2_SUCCESS, true)
|
||||
.failureUrl(CommonEndPoint.LOGIN)
|
||||
.clientRegistrationRepository(clientRegistrationRepository())
|
||||
.authorizedClientService(authorizedClientService())
|
||||
.and()
|
||||
|
|
|
@ -27,6 +27,7 @@ public class WebSocketConfig extends AbstractSecurityWebSocketMessageBrokerConfi
|
|||
* registry.setApplicationDestinationPrefixes("/app"); }
|
||||
*
|
||||
*/
|
||||
|
||||
@Override
|
||||
public void configureMessageBroker(MessageBrokerRegistry config) {
|
||||
config.enableSimpleBroker("/topic");
|
||||
|
|
|
@ -17,7 +17,8 @@ package org.springframework.samples.petclinic.controller;
|
|||
|
||||
import org.springframework.samples.petclinic.common.*;
|
||||
import org.springframework.samples.petclinic.controller.common.WebSocketSender;
|
||||
import org.springframework.samples.petclinic.dto.*;
|
||||
import org.springframework.samples.petclinic.dto.business.OwnerDTO;
|
||||
import org.springframework.samples.petclinic.dto.business.PetDTO;
|
||||
import org.springframework.samples.petclinic.service.business.OwnerService;
|
||||
import org.springframework.samples.petclinic.service.business.VisitService;
|
||||
import org.springframework.stereotype.Controller;
|
||||
|
|
|
@ -18,7 +18,9 @@ package org.springframework.samples.petclinic.controller;
|
|||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.samples.petclinic.common.*;
|
||||
import org.springframework.samples.petclinic.controller.common.WebSocketSender;
|
||||
import org.springframework.samples.petclinic.dto.*;
|
||||
import org.springframework.samples.petclinic.dto.business.OwnerDTO;
|
||||
import org.springframework.samples.petclinic.dto.business.PetDTO;
|
||||
import org.springframework.samples.petclinic.dto.business.PetTypeDTO;
|
||||
import org.springframework.samples.petclinic.service.business.OwnerService;
|
||||
import org.springframework.samples.petclinic.service.business.PetService;
|
||||
import org.springframework.samples.petclinic.service.business.PetTypeService;
|
||||
|
@ -40,7 +42,7 @@ import java.util.Collection;
|
|||
* @author Paul-Emmanuel DOS SANTOS FACAO
|
||||
*/
|
||||
@Controller
|
||||
@RequestMapping(CommonEndPoint.OWNERS_ID)
|
||||
@RequestMapping("/owners/{ownerId}")
|
||||
class PetController extends WebSocketSender {
|
||||
|
||||
private final OwnerService ownerService;
|
||||
|
@ -60,13 +62,12 @@ class PetController extends WebSocketSender {
|
|||
|
||||
@ModelAttribute("owner")
|
||||
public OwnerDTO findOwner(@PathVariable("ownerId") int ownerId) {
|
||||
OwnerDTO ownerDTO = ownerService.findById(ownerId);
|
||||
return ownerDTO;
|
||||
return ownerService.findById(ownerId);
|
||||
}
|
||||
|
||||
@InitBinder("owner")
|
||||
public void initOwnerBinder(WebDataBinder dataBinder) {
|
||||
// dataBinder.setDisallowedFields(CommonAttribute.OWNER_ID);
|
||||
dataBinder.setDisallowedFields(CommonAttribute.ID);
|
||||
}
|
||||
|
||||
@InitBinder("pet")
|
||||
|
@ -75,7 +76,7 @@ class PetController extends WebSocketSender {
|
|||
}
|
||||
|
||||
@GetMapping(CommonEndPoint.PETS_NEW)
|
||||
public String initCreationForm(@ModelAttribute(CommonAttribute.OWNER) OwnerDTO owner, ModelMap model) {
|
||||
public String initCreationForm(@ModelAttribute("owner") OwnerDTO owner, ModelMap model) {
|
||||
PetDTO pet = new PetDTO();
|
||||
owner.addPet(pet);
|
||||
model.put(CommonAttribute.PET, pet);
|
||||
|
@ -83,8 +84,8 @@ class PetController extends WebSocketSender {
|
|||
}
|
||||
|
||||
@PostMapping(CommonEndPoint.PETS_NEW)
|
||||
public String processCreationForm(@ModelAttribute(CommonAttribute.OWNER) OwnerDTO owner,
|
||||
@ModelAttribute(CommonAttribute.PET) @Valid PetDTO pet, BindingResult result, ModelMap model) {
|
||||
public String processCreationForm(@ModelAttribute("owner") OwnerDTO owner, @Valid PetDTO pet, BindingResult result,
|
||||
ModelMap model) {
|
||||
if (owner == null) {
|
||||
sendErrorMessage(CommonWebSocket.PET_CREATION_ERROR);
|
||||
result.rejectValue(CommonAttribute.OWNER, CommonError.NOT_FOUND_ARGS, CommonError.NOT_FOUND_MESSAGE);
|
||||
|
@ -109,16 +110,16 @@ class PetController extends WebSocketSender {
|
|||
}
|
||||
}
|
||||
|
||||
@GetMapping(CommonEndPoint.PETS_ID_EDIT)
|
||||
@GetMapping("/pets/{petId}/edit")
|
||||
public String initUpdateForm(@PathVariable("petId") int petId, ModelMap model) {
|
||||
PetDTO pet = this.petService.findById(petId);
|
||||
model.put(CommonAttribute.PET, pet);
|
||||
return CommonView.PET_CREATE_OR_UPDATE;
|
||||
}
|
||||
|
||||
@PostMapping(CommonEndPoint.PETS_ID_EDIT)
|
||||
public String processUpdateForm(@ModelAttribute(CommonAttribute.PET) @Valid PetDTO pet, BindingResult result,
|
||||
@ModelAttribute(CommonAttribute.OWNER) OwnerDTO owner, ModelMap model) {
|
||||
@PostMapping("/pets/{petId}/edit")
|
||||
public String processUpdateForm(@Valid PetDTO pet, BindingResult result, @ModelAttribute("owner") OwnerDTO owner,
|
||||
ModelMap model) {
|
||||
if (result.hasErrors()) {
|
||||
pet.setOwner(owner);
|
||||
model.put(CommonAttribute.PET, pet);
|
||||
|
|
|
@ -59,7 +59,7 @@ public class UserController extends WebSocketSender {
|
|||
|
||||
@InitBinder("user")
|
||||
public void setAllowedFields(WebDataBinder dataBinder) {
|
||||
dataBinder.setDisallowedFields(CommonAttribute.USER_ID,"roles");
|
||||
dataBinder.setDisallowedFields(CommonAttribute.USER_ID, "roles");
|
||||
}
|
||||
|
||||
Map<String, String> oauth2AuthenticationUrls = new HashMap<>();
|
||||
|
@ -91,7 +91,7 @@ public class UserController extends WebSocketSender {
|
|||
}
|
||||
|
||||
// set default role
|
||||
user.addRole("ROLE_USER");
|
||||
user.addRole(roleService.findByName("ROLE_USER"));
|
||||
|
||||
// encode password because we get clear password
|
||||
user.encode(user.getPassword());
|
||||
|
@ -108,8 +108,7 @@ public class UserController extends WebSocketSender {
|
|||
"Your attempt to create new account. To confirm your account, please click here : ",
|
||||
"http://localhost:8080/confirm-account?token=" + credential.getToken());
|
||||
|
||||
// TODO
|
||||
// emailService.sendMailAsynch(message, Locale.getDefault());
|
||||
emailService.sendMailAsynch(message, Locale.getDefault());
|
||||
|
||||
log.info(message.toString());
|
||||
|
||||
|
@ -132,11 +131,13 @@ public class UserController extends WebSocketSender {
|
|||
|
||||
if (type != ResolvableType.NONE && ClientRegistration.class.isAssignableFrom(type.resolveGenerics()[0])) {
|
||||
clientRegistrations = (Iterable<ClientRegistration>) clientRegistrationRepository;
|
||||
}
|
||||
|
||||
clientRegistrations.forEach(registration -> oauth2AuthenticationUrls.put(registration.getClientName(),
|
||||
"oauth2/authorization/" + registration.getRegistrationId()));
|
||||
model.put("urls", oauth2AuthenticationUrls);
|
||||
if (clientRegistrations != null) {
|
||||
clientRegistrations.forEach(registration -> oauth2AuthenticationUrls.put(registration.getClientName(),
|
||||
"oauth2/authorization/" + registration.getRegistrationId()));
|
||||
model.put("urls", oauth2AuthenticationUrls);
|
||||
}
|
||||
}
|
||||
|
||||
return CommonView.USER_LOGIN;
|
||||
}
|
||||
|
@ -174,7 +175,7 @@ public class UserController extends WebSocketSender {
|
|||
user.setFirstName(firstName);
|
||||
user.setLastName(lastName);
|
||||
user.setEnabled(true);
|
||||
user.addRole("ROLE_USER");
|
||||
user.addRole(roleService.findByName("ROLE_USER"));
|
||||
user = userService.save(user);
|
||||
}
|
||||
|
||||
|
@ -193,7 +194,7 @@ public class UserController extends WebSocketSender {
|
|||
SecurityContextHolder.clearContext();
|
||||
|
||||
}
|
||||
else if (credential.isVerified()) {
|
||||
else if (Boolean.TRUE.equals(credential.isVerified())) {
|
||||
securityService.autoLogin(credential.getEmail(), credential.getPassword());
|
||||
String message = String.format(CommonWebSocket.USER_LOGGED_IN, firstName, lastName);
|
||||
sendSuccessMessage(message);
|
||||
|
@ -293,7 +294,7 @@ public class UserController extends WebSocketSender {
|
|||
UserDTO operator = (UserDTO) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
|
||||
UserDTO user = userService.findById(userId);
|
||||
|
||||
if (user.equals(operator) || operator.getRoles().contains("ROLE_ADMIN")) {
|
||||
if (user.equals(operator) || operator.hasRole("ROLE_ADMIN")) {
|
||||
model.addAttribute(CommonAttribute.USER, user);
|
||||
model.addAttribute(CommonAttribute.USER_ID, user.getId());
|
||||
return CommonView.USER_CHANGE_PASSWORD;
|
||||
|
@ -329,7 +330,7 @@ public class UserController extends WebSocketSender {
|
|||
try {
|
||||
UserDTO operator = (UserDTO) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
|
||||
|
||||
if (user.equals(operator) || operator.getRoles().contains("ROLE_ADMIN")) {
|
||||
if (user.equals(operator) || operator.hasRole("ROLE_ADMIN")) {
|
||||
// encode password
|
||||
user.encode(newPassword);
|
||||
user = userService.save(user);
|
||||
|
|
|
@ -20,7 +20,7 @@ import org.springframework.samples.petclinic.common.CommonEndPoint;
|
|||
import org.springframework.samples.petclinic.common.CommonView;
|
||||
import org.springframework.samples.petclinic.common.CommonWebSocket;
|
||||
import org.springframework.samples.petclinic.controller.common.WebSocketSender;
|
||||
import org.springframework.samples.petclinic.dto.VetsDTO;
|
||||
import org.springframework.samples.petclinic.dto.business.VetsDTO;
|
||||
import org.springframework.samples.petclinic.service.business.VetService;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
|
|
|
@ -24,8 +24,8 @@ import org.springframework.samples.petclinic.common.CommonEndPoint;
|
|||
import org.springframework.samples.petclinic.common.CommonView;
|
||||
import org.springframework.samples.petclinic.common.CommonWebSocket;
|
||||
import org.springframework.samples.petclinic.controller.common.WebSocketSender;
|
||||
import org.springframework.samples.petclinic.dto.PetDTO;
|
||||
import org.springframework.samples.petclinic.dto.VisitDTO;
|
||||
import org.springframework.samples.petclinic.dto.business.PetDTO;
|
||||
import org.springframework.samples.petclinic.dto.business.VisitDTO;
|
||||
import org.springframework.samples.petclinic.service.business.PetService;
|
||||
import org.springframework.samples.petclinic.service.business.VisitService;
|
||||
import org.springframework.samples.petclinic.validator.VisitDTOValidator;
|
||||
|
|
|
@ -13,12 +13,13 @@
|
|||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.springframework.samples.petclinic.dto;
|
||||
package org.springframework.samples.petclinic.dto.business;
|
||||
|
||||
import org.springframework.beans.support.MutableSortDefinition;
|
||||
import org.springframework.beans.support.PropertyComparator;
|
||||
import org.springframework.core.style.ToStringCreator;
|
||||
import org.springframework.samples.petclinic.common.CommonAttribute;
|
||||
import org.springframework.samples.petclinic.dto.common.PersonDTO;
|
||||
|
||||
import javax.validation.constraints.Digits;
|
||||
import javax.validation.constraints.NotEmpty;
|
|
@ -13,11 +13,12 @@
|
|||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.springframework.samples.petclinic.dto;
|
||||
package org.springframework.samples.petclinic.dto.business;
|
||||
|
||||
import org.springframework.beans.support.MutableSortDefinition;
|
||||
import org.springframework.beans.support.PropertyComparator;
|
||||
import org.springframework.format.annotation.DateTimeFormat;
|
||||
import org.springframework.samples.petclinic.dto.common.NamedDTO;
|
||||
|
||||
import java.time.LocalDate;
|
||||
import java.util.*;
|
|
@ -1,4 +1,6 @@
|
|||
package org.springframework.samples.petclinic.dto;
|
||||
package org.springframework.samples.petclinic.dto.business;
|
||||
|
||||
import org.springframework.samples.petclinic.dto.common.NamedDTO;
|
||||
|
||||
/**
|
||||
* Simple Data Transfert Object representing PetType.
|
|
@ -1,4 +1,6 @@
|
|||
package org.springframework.samples.petclinic.dto;
|
||||
package org.springframework.samples.petclinic.dto.business;
|
||||
|
||||
import org.springframework.samples.petclinic.dto.common.NamedDTO;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
|
@ -13,10 +13,11 @@
|
|||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.springframework.samples.petclinic.dto;
|
||||
package org.springframework.samples.petclinic.dto.business;
|
||||
|
||||
import org.springframework.beans.support.MutableSortDefinition;
|
||||
import org.springframework.beans.support.PropertyComparator;
|
||||
import org.springframework.samples.petclinic.dto.common.PersonDTO;
|
||||
|
||||
import javax.xml.bind.annotation.XmlElement;
|
||||
import java.util.*;
|
|
@ -13,7 +13,7 @@
|
|||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.springframework.samples.petclinic.dto;
|
||||
package org.springframework.samples.petclinic.dto.business;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
|
@ -13,11 +13,12 @@
|
|||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.springframework.samples.petclinic.dto;
|
||||
package org.springframework.samples.petclinic.dto.business;
|
||||
|
||||
import org.springframework.format.annotation.DateTimeFormat;
|
||||
import org.springframework.samples.petclinic.dto.common.BaseDTO;
|
||||
|
||||
import javax.validation.constraints.NotEmpty;
|
||||
import javax.validation.constraints.NotNull;
|
||||
import java.time.LocalDate;
|
||||
|
||||
/**
|
|
@ -1,7 +1,5 @@
|
|||
package org.springframework.samples.petclinic.dto.common;
|
||||
|
||||
import org.springframework.samples.petclinic.dto.NamedDTO;
|
||||
|
||||
/**
|
||||
* Simple Data Transfert Object representing a Authorization Provider.
|
||||
*
|
||||
|
|
|
@ -13,7 +13,7 @@
|
|||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.springframework.samples.petclinic.dto;
|
||||
package org.springframework.samples.petclinic.dto.common;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
|
@ -2,7 +2,7 @@ package org.springframework.samples.petclinic.dto.common;
|
|||
|
||||
import org.springframework.samples.petclinic.common.CommonError;
|
||||
import org.springframework.samples.petclinic.common.CommonParameter;
|
||||
import org.springframework.samples.petclinic.dto.BaseDTO;
|
||||
|
||||
import javax.validation.constraints.NotNull;
|
||||
import javax.validation.constraints.Pattern;
|
||||
import javax.validation.constraints.Size;
|
||||
|
|
|
@ -13,7 +13,7 @@
|
|||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.springframework.samples.petclinic.dto;
|
||||
package org.springframework.samples.petclinic.dto.common;
|
||||
|
||||
/**
|
||||
* Simple Data Transfert Object with a name property to <code>BaseDTO</code>. Used as a
|
|
@ -13,7 +13,7 @@
|
|||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.springframework.samples.petclinic.dto;
|
||||
package org.springframework.samples.petclinic.dto.common;
|
||||
|
||||
import javax.validation.constraints.NotEmpty;
|
||||
|
|
@ -0,0 +1,26 @@
|
|||
package org.springframework.samples.petclinic.dto.common;
|
||||
|
||||
import lombok.Getter;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.Setter;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.Collection;
|
||||
|
||||
/**
|
||||
* Simple Data Transfert Object representing a Privileges.
|
||||
*
|
||||
* @author Paul-Emmanuel DOS SANTOS FACAO
|
||||
*/
|
||||
@Getter
|
||||
@Setter
|
||||
@NoArgsConstructor
|
||||
public class PrivilegeDTO implements Serializable {
|
||||
|
||||
private Integer id;
|
||||
|
||||
private String name;
|
||||
|
||||
private Collection<RoleDTO> roles;
|
||||
|
||||
}
|
|
@ -1,14 +1,35 @@
|
|||
package org.springframework.samples.petclinic.dto.common;
|
||||
|
||||
import org.springframework.samples.petclinic.dto.NamedDTO;
|
||||
import lombok.Getter;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.Setter;
|
||||
import org.springframework.samples.petclinic.common.CommonParameter;
|
||||
|
||||
import javax.validation.constraints.NotEmpty;
|
||||
import javax.validation.constraints.NotNull;
|
||||
import javax.validation.constraints.Size;
|
||||
import java.io.Serializable;
|
||||
import java.util.Collection;
|
||||
|
||||
/**
|
||||
* Simple Data Transfert Object representing a list of roles.
|
||||
*
|
||||
* @author Paul-Emmanuel DOS SANTOS FACAO
|
||||
*/
|
||||
public class RoleDTO extends NamedDTO implements Serializable {
|
||||
@Getter
|
||||
@Setter
|
||||
@NoArgsConstructor
|
||||
public class RoleDTO implements Serializable {
|
||||
|
||||
private Integer id;
|
||||
|
||||
@NotNull
|
||||
@NotEmpty
|
||||
@Size(max = CommonParameter.ROLE_MAX)
|
||||
private String name;
|
||||
|
||||
private Collection<UserDTO> users;
|
||||
|
||||
private Collection<PrivilegeDTO> privileges;
|
||||
|
||||
}
|
||||
|
|
|
@ -1,8 +1,9 @@
|
|||
package org.springframework.samples.petclinic.dto.common;
|
||||
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import org.springframework.samples.petclinic.common.CommonError;
|
||||
import org.springframework.samples.petclinic.common.CommonParameter;
|
||||
import org.springframework.samples.petclinic.dto.PersonDTO;
|
||||
import org.springframework.security.core.GrantedAuthority;
|
||||
import org.springframework.security.core.authority.SimpleGrantedAuthority;
|
||||
import org.springframework.security.core.userdetails.UserDetails;
|
||||
|
@ -14,6 +15,8 @@ import java.io.Serializable;
|
|||
|
||||
import java.util.*;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
public class UserDTO extends PersonDTO implements Serializable, UserDetails {
|
||||
|
||||
@Size(min = CommonParameter.EMAIL_MIN, max = CommonParameter.EMAIL_MAX, message = CommonError.FORMAT_BETWEEN
|
||||
|
@ -37,7 +40,7 @@ public class UserDTO extends PersonDTO implements Serializable, UserDetails {
|
|||
|
||||
private boolean credentialsNonExpired;
|
||||
|
||||
private List<String> roles;
|
||||
private Collection<RoleDTO> roles;
|
||||
|
||||
@Size(max = CommonParameter.PHONE_MAX, message = CommonError.FORMAT_LESS + CommonParameter.PHONE_MAX)
|
||||
// @Pattern(regexp = CommonParameter.PHONE_REGEXP, message = CommonError.PHONE_FORMAT)
|
||||
|
@ -75,150 +78,80 @@ public class UserDTO extends PersonDTO implements Serializable, UserDetails {
|
|||
return email;
|
||||
}
|
||||
|
||||
public String getEmail() {
|
||||
return email;
|
||||
}
|
||||
|
||||
public void setEmail(String email) {
|
||||
this.email = email;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getPassword() {
|
||||
return password;
|
||||
}
|
||||
|
||||
public void setPassword(String password) {
|
||||
this.password = password;
|
||||
}
|
||||
|
||||
public String getMatchingPassword() {
|
||||
return matchingPassword;
|
||||
}
|
||||
|
||||
public void setMatchingPassword(String matchingPassword) {
|
||||
this.matchingPassword = matchingPassword;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isEnabled() {
|
||||
return enabled;
|
||||
}
|
||||
|
||||
public void setEnabled(boolean enabled) {
|
||||
this.enabled = enabled;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isAccountNonExpired() {
|
||||
return accountNonExpired;
|
||||
}
|
||||
|
||||
public void setAccountNonExpired(boolean accountNonExpired) {
|
||||
this.accountNonExpired = accountNonExpired;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isAccountNonLocked() {
|
||||
return accountNonLocked;
|
||||
}
|
||||
|
||||
public void setAccountNonLocked(boolean accountNonLocked) {
|
||||
this.accountNonLocked = accountNonLocked;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isCredentialsNonExpired() {
|
||||
return credentialsNonExpired;
|
||||
}
|
||||
|
||||
public void setCredentialsNonExpired(boolean credentialsNonExpired) {
|
||||
this.credentialsNonExpired = credentialsNonExpired;
|
||||
public boolean hasRole(String roleName) {
|
||||
for (RoleDTO roleDTO : this.roles) {
|
||||
if (roleDTO.getName().equals(roleName))
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<? extends GrantedAuthority> getAuthorities() {
|
||||
Set<GrantedAuthority> grantedAuthorities = new HashSet<>();
|
||||
|
||||
this.roles.forEach(role -> grantedAuthorities.add(new SimpleGrantedAuthority(role)));
|
||||
|
||||
return grantedAuthorities;
|
||||
public boolean hasPrivilege(String privilegeName) {
|
||||
for (RoleDTO roleDTO : this.roles) {
|
||||
for (PrivilegeDTO privilegeDTO : roleDTO.getPrivileges()) {
|
||||
if (privilegeDTO.getName().equals(privilegeName))
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public List<String> getRoles() {
|
||||
return roles;
|
||||
}
|
||||
|
||||
public void setRoles(List<String> roles) {
|
||||
this.roles = roles;
|
||||
}
|
||||
|
||||
public void addRole(String role) {
|
||||
public void addRole(RoleDTO role) {
|
||||
if (this.roles == null) {
|
||||
this.roles = new ArrayList<>();
|
||||
this.roles = new HashSet<>();
|
||||
}
|
||||
|
||||
this.roles.add(role);
|
||||
}
|
||||
|
||||
public void removeRole(String role) {
|
||||
public void removeRole(RoleDTO role) {
|
||||
this.roles.remove(role);
|
||||
}
|
||||
|
||||
public String getTelephone() {
|
||||
return telephone;
|
||||
private List<GrantedAuthority> getGrantedAuthorities(List<String> privileges) {
|
||||
List<GrantedAuthority> authorities = new ArrayList<>();
|
||||
for (String privilege : privileges) {
|
||||
authorities.add(new SimpleGrantedAuthority(privilege));
|
||||
}
|
||||
return authorities;
|
||||
}
|
||||
|
||||
public void setTelephone(String telephone) {
|
||||
this.telephone = telephone;
|
||||
private List<String> getPrivileges(Collection<RoleDTO> roles) {
|
||||
|
||||
List<String> privileges = new ArrayList<>();
|
||||
List<PrivilegeDTO> collection = new ArrayList<>();
|
||||
for (RoleDTO role : roles) {
|
||||
collection.addAll(role.getPrivileges());
|
||||
}
|
||||
for (PrivilegeDTO item : collection) {
|
||||
privileges.add(item.getName());
|
||||
}
|
||||
return privileges;
|
||||
}
|
||||
|
||||
public String getStreet1() {
|
||||
return street1;
|
||||
}
|
||||
|
||||
public void setStreet1(String street1) {
|
||||
this.street1 = street1;
|
||||
}
|
||||
|
||||
public String getStreet2() {
|
||||
return street2;
|
||||
}
|
||||
|
||||
public void setStreet2(String street2) {
|
||||
this.street2 = street2;
|
||||
}
|
||||
|
||||
public String getStreet3() {
|
||||
return street3;
|
||||
}
|
||||
|
||||
public void setStreet3(String street3) {
|
||||
this.street3 = street3;
|
||||
}
|
||||
|
||||
public String getZipCode() {
|
||||
return zipCode;
|
||||
}
|
||||
|
||||
public void setZipCode(String zipCode) {
|
||||
this.zipCode = zipCode;
|
||||
}
|
||||
|
||||
public String getCity() {
|
||||
return city;
|
||||
}
|
||||
|
||||
public void setCity(String city) {
|
||||
this.city = city;
|
||||
}
|
||||
|
||||
public String getCountry() {
|
||||
return country;
|
||||
}
|
||||
|
||||
public void setCountry(String country) {
|
||||
this.country = country;
|
||||
@Override
|
||||
public Collection<? extends GrantedAuthority> getAuthorities() {
|
||||
return getGrantedAuthorities(getPrivileges(this.roles));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -20,7 +20,7 @@ import java.util.Collection;
|
|||
import java.util.Locale;
|
||||
|
||||
import org.springframework.format.Formatter;
|
||||
import org.springframework.samples.petclinic.dto.PetTypeDTO;
|
||||
import org.springframework.samples.petclinic.dto.business.PetTypeDTO;
|
||||
import org.springframework.samples.petclinic.service.business.PetService;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
|
|
|
@ -107,7 +107,7 @@ public class Owner extends Person {
|
|||
public void addPet(Pet pet) {
|
||||
|
||||
if (this.pets == null) {
|
||||
|
||||
this.pets = new HashSet<>();
|
||||
}
|
||||
try {
|
||||
if (!this.getPets().contains(pet)) {
|
||||
|
@ -152,7 +152,7 @@ public class Owner extends Person {
|
|||
|
||||
@Override
|
||||
public String toString() {
|
||||
return new ToStringCreator(this).append(CommonAttribute.OWNER_ID, this.getId())
|
||||
return new ToStringCreator(this).append(CommonAttribute.ID, this.getId())
|
||||
.append(CommonAttribute.NEW, this.isNew()).append(CommonAttribute.OWNER_LAST_NAME, this.getLastName())
|
||||
.append(CommonAttribute.OWNER_FIRST_NAME, this.getFirstName())
|
||||
.append(CommonAttribute.OWNER_ADDRESS, this.address).append(CommonAttribute.OWNER_CITY, this.city)
|
||||
|
|
|
@ -1,42 +1,35 @@
|
|||
package org.springframework.samples.petclinic.model.common;
|
||||
|
||||
import javax.persistence.*;
|
||||
import java.util.Set;
|
||||
import lombok.Getter;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.Setter;
|
||||
import org.springframework.samples.petclinic.common.CommonParameter;
|
||||
|
||||
import javax.persistence.*;
|
||||
import javax.validation.constraints.NotEmpty;
|
||||
import javax.validation.constraints.NotNull;
|
||||
import javax.validation.constraints.Size;
|
||||
import java.io.Serializable;
|
||||
import java.util.Collection;
|
||||
|
||||
@Entity
|
||||
public class Privilege {
|
||||
@Table(name = "privileges")
|
||||
@Getter
|
||||
@Setter
|
||||
@NoArgsConstructor
|
||||
public class Privilege implements Serializable {
|
||||
|
||||
@Id
|
||||
@GeneratedValue(strategy = GenerationType.AUTO)
|
||||
private Long id;
|
||||
private Integer id;
|
||||
|
||||
@NotNull
|
||||
@NotEmpty
|
||||
@Size(max = CommonParameter.PRIVILEGE_MAX)
|
||||
@Column(name = "name", length = CommonParameter.PRIVILEGE_MAX)
|
||||
private String name;
|
||||
|
||||
@ManyToMany(mappedBy = "privileges")
|
||||
private Set<Role> roles;
|
||||
@ManyToMany(mappedBy = "privileges", fetch = FetchType.EAGER)
|
||||
private Collection<Role> roles;
|
||||
|
||||
public Long getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(Long id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public Set<Role> getRoles() {
|
||||
return roles;
|
||||
}
|
||||
|
||||
public void setRoles(Set<Role> roles) {
|
||||
this.roles = roles;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,5 +1,10 @@
|
|||
package org.springframework.samples.petclinic.model.common;
|
||||
|
||||
import lombok.Getter;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.Setter;
|
||||
import org.hibernate.annotations.LazyCollection;
|
||||
import org.hibernate.annotations.LazyCollectionOption;
|
||||
import org.springframework.samples.petclinic.common.CommonParameter;
|
||||
|
||||
import javax.persistence.*;
|
||||
|
@ -7,10 +12,18 @@ import javax.validation.constraints.NotEmpty;
|
|||
import javax.validation.constraints.NotNull;
|
||||
import javax.validation.constraints.Size;
|
||||
import java.io.Serializable;
|
||||
import java.util.Set;
|
||||
import java.util.Collection;
|
||||
|
||||
@Entity(name = "Role")
|
||||
/**
|
||||
* Entity representing a Role.
|
||||
*
|
||||
* @author Paul-Emmanuel DOS SANTOS FACAO
|
||||
*/
|
||||
@Entity
|
||||
@Table(name = "roles")
|
||||
@Getter
|
||||
@Setter
|
||||
@NoArgsConstructor
|
||||
public class Role implements Serializable {
|
||||
|
||||
@Id
|
||||
|
@ -23,40 +36,14 @@ public class Role implements Serializable {
|
|||
@Column(name = "name", length = CommonParameter.ROLE_MAX)
|
||||
private String name;
|
||||
|
||||
@ManyToMany(mappedBy = "roles", fetch = FetchType.LAZY)
|
||||
private Set<User> users;
|
||||
@ManyToMany(mappedBy = "roles")
|
||||
@LazyCollection(LazyCollectionOption.FALSE)
|
||||
private Collection<User> users;
|
||||
|
||||
public Role(Integer id, @NotNull @NotEmpty @Size(max = CommonParameter.ROLE_MAX) String name) {
|
||||
this.id = id;
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public Role() {
|
||||
// empty constructor for creating empty role and add attribute after
|
||||
}
|
||||
|
||||
public Integer getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(Integer id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public Set<User> getUsers() {
|
||||
return users;
|
||||
}
|
||||
|
||||
public void setUsers(Set<User> users) {
|
||||
this.users = users;
|
||||
}
|
||||
@ManyToMany // (cascade = CascadeType.ALL, fetch = FetchType.EAGER)
|
||||
@LazyCollection(LazyCollectionOption.FALSE)
|
||||
@JoinTable(name = "roles_privileges", joinColumns = @JoinColumn(name = "role_id", referencedColumnName = "id"),
|
||||
inverseJoinColumns = @JoinColumn(name = "privilege_id", referencedColumnName = "id"))
|
||||
private Collection<Privilege> privileges;
|
||||
|
||||
}
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
package org.springframework.samples.petclinic.model.common;
|
||||
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import org.springframework.samples.petclinic.common.CommonError;
|
||||
import org.springframework.samples.petclinic.common.CommonParameter;
|
||||
import org.springframework.security.core.GrantedAuthority;
|
||||
|
@ -20,6 +22,8 @@ import java.util.*;
|
|||
*/
|
||||
@Entity
|
||||
@Table(name = "users")
|
||||
@Getter
|
||||
@Setter
|
||||
public class User extends Person implements Serializable, UserDetails {
|
||||
|
||||
@NotNull
|
||||
|
@ -50,10 +54,18 @@ public class User extends Person implements Serializable, UserDetails {
|
|||
@Column(name = "credential_unexpired")
|
||||
private boolean credentialsNonExpired;
|
||||
|
||||
/*
|
||||
* @ManyToMany(cascade = CascadeType.ALL, fetch = FetchType.EAGER)
|
||||
*
|
||||
* @JoinTable(name = "users_roles", joinColumns = @JoinColumn(name = "user_id",
|
||||
* referencedColumnName = "id"), inverseJoinColumns = @JoinColumn(name = "role_id",
|
||||
* referencedColumnName = "id")) private Set<Role> roles;
|
||||
*/
|
||||
|
||||
@ManyToMany(cascade = CascadeType.ALL, fetch = FetchType.EAGER)
|
||||
@JoinTable(name = "users_roles", joinColumns = @JoinColumn(name = "user_id", referencedColumnName = "id"),
|
||||
inverseJoinColumns = @JoinColumn(name = "role_id", referencedColumnName = "id"))
|
||||
private Set<Role> roles;
|
||||
private Collection<Role> roles;
|
||||
|
||||
@Size(max = CommonParameter.PHONE_MAX, message = CommonError.FORMAT_LESS + CommonParameter.PHONE_MAX)
|
||||
// @Pattern(regexp = CommonParameter.PHONE_REGEXP, message = CommonError.PHONE_FORMAT)
|
||||
|
@ -89,67 +101,26 @@ public class User extends Person implements Serializable, UserDetails {
|
|||
return email;
|
||||
}
|
||||
|
||||
public String getEmail() {
|
||||
return email;
|
||||
}
|
||||
|
||||
public void setEmail(String email) {
|
||||
this.email = email;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getPassword() {
|
||||
return password;
|
||||
}
|
||||
|
||||
public void setPassword(String password) {
|
||||
this.password = password;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isEnabled() {
|
||||
return enabled;
|
||||
}
|
||||
|
||||
public void setEnabled(boolean enabled) {
|
||||
this.enabled = enabled;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isAccountNonExpired() {
|
||||
return accountNonExpired;
|
||||
}
|
||||
|
||||
public void setAccountNonExpired(boolean accountNonExpired) {
|
||||
this.accountNonExpired = accountNonExpired;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isAccountNonLocked() {
|
||||
return accountNonLocked;
|
||||
}
|
||||
|
||||
public void setAccountNonLocked(boolean accountNonLocked) {
|
||||
this.accountNonLocked = accountNonLocked;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isCredentialsNonExpired() {
|
||||
return credentialsNonExpired;
|
||||
}
|
||||
|
||||
public void setCredentialsNonExpired(boolean credentialsNonExpired) {
|
||||
this.credentialsNonExpired = credentialsNonExpired;
|
||||
}
|
||||
|
||||
public Set<Role> getRoles() {
|
||||
return roles;
|
||||
}
|
||||
|
||||
public void setRoles(Set<Role> roles) {
|
||||
this.roles = roles;
|
||||
}
|
||||
|
||||
public void addRole(Role role) {
|
||||
if (this.roles == null) {
|
||||
this.roles = new HashSet<>();
|
||||
|
@ -165,69 +136,31 @@ public class User extends Person implements Serializable, UserDetails {
|
|||
}
|
||||
}
|
||||
|
||||
private List<GrantedAuthority> getGrantedAuthorities(List<String> privileges) {
|
||||
List<GrantedAuthority> authorities = new ArrayList<>();
|
||||
for (String privilege : privileges) {
|
||||
authorities.add(new SimpleGrantedAuthority(privilege));
|
||||
}
|
||||
return authorities;
|
||||
}
|
||||
|
||||
private List<String> getPrivileges(Collection<Role> roles) {
|
||||
|
||||
List<String> privileges = new ArrayList<>();
|
||||
List<Privilege> collection = new ArrayList<>();
|
||||
for (Role role : roles) {
|
||||
collection.addAll(role.getPrivileges());
|
||||
}
|
||||
for (Privilege item : collection) {
|
||||
privileges.add(item.getName());
|
||||
}
|
||||
return privileges;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<? extends GrantedAuthority> getAuthorities() {
|
||||
Set<GrantedAuthority> grantedAuthorities = new HashSet<>();
|
||||
|
||||
this.roles.forEach(role -> grantedAuthorities.add(new SimpleGrantedAuthority(role.getName())));
|
||||
|
||||
return grantedAuthorities;
|
||||
}
|
||||
|
||||
public String getTelephone() {
|
||||
return telephone;
|
||||
}
|
||||
|
||||
public void setTelephone(String telephone) {
|
||||
this.telephone = telephone;
|
||||
}
|
||||
|
||||
public String getStreet1() {
|
||||
return street1;
|
||||
}
|
||||
|
||||
public void setStreet1(String street1) {
|
||||
this.street1 = street1;
|
||||
}
|
||||
|
||||
public String getStreet2() {
|
||||
return street2;
|
||||
}
|
||||
|
||||
public void setStreet2(String street2) {
|
||||
this.street2 = street2;
|
||||
}
|
||||
|
||||
public String getStreet3() {
|
||||
return street3;
|
||||
}
|
||||
|
||||
public void setStreet3(String street3) {
|
||||
this.street3 = street3;
|
||||
}
|
||||
|
||||
public String getZipCode() {
|
||||
return zipCode;
|
||||
}
|
||||
|
||||
public void setZipCode(String zipCode) {
|
||||
this.zipCode = zipCode;
|
||||
}
|
||||
|
||||
public String getCity() {
|
||||
return city;
|
||||
}
|
||||
|
||||
public void setCity(String city) {
|
||||
this.city = city;
|
||||
}
|
||||
|
||||
public String getCountry() {
|
||||
return country;
|
||||
}
|
||||
|
||||
public void setCountry(String country) {
|
||||
this.country = country;
|
||||
return getGrantedAuthorities(getPrivileges(this.roles));
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1,7 +1,10 @@
|
|||
package org.springframework.samples.petclinic.repository;
|
||||
|
||||
import org.springframework.data.jpa.repository.Query;
|
||||
import org.springframework.data.repository.query.Param;
|
||||
import org.springframework.samples.petclinic.model.common.Role;
|
||||
import org.springframework.data.repository.Repository;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
|
@ -15,17 +18,21 @@ public interface RoleRepository extends Repository<Role, Integer> {
|
|||
|
||||
/**
|
||||
* Retrieve a {@link Role} from the data store by id.
|
||||
* @param roleId the id to search for
|
||||
* @param id the id to search for
|
||||
* @return the {@link Role} if found
|
||||
*/
|
||||
Role findById(Integer roleId);
|
||||
@Query("SELECT role FROM Role role join fetch role.privileges WHERE role.id =:id")
|
||||
@Transactional(readOnly = true)
|
||||
Role findById(@Param("id") Integer id);
|
||||
|
||||
/**
|
||||
* Retrieve a {@link Role} from the data store by id.
|
||||
* @param name the name to search for
|
||||
* @return the {@link Role} if found
|
||||
*/
|
||||
Role findByName(String name);
|
||||
@Query("SELECT role FROM Role role left join fetch role.users WHERE role.name =:name")
|
||||
@Transactional(readOnly = true)
|
||||
Role findByName(@Param("name") String name);
|
||||
|
||||
/**
|
||||
* Retrieve all {@link Role}s from the data store
|
||||
|
|
|
@ -1,7 +1,11 @@
|
|||
package org.springframework.samples.petclinic.repository;
|
||||
|
||||
import org.springframework.data.jpa.repository.Query;
|
||||
import org.springframework.data.repository.Repository;
|
||||
import org.springframework.data.repository.query.Param;
|
||||
import org.springframework.samples.petclinic.model.business.Owner;
|
||||
import org.springframework.samples.petclinic.model.common.User;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
@ -14,9 +18,23 @@ import java.util.List;
|
|||
*/
|
||||
public interface UserRepository extends Repository<User, Integer> {
|
||||
|
||||
User findById(Integer id);
|
||||
/**
|
||||
* Retrieve an {@link User} from the data store by email.
|
||||
* @param id the id to search for
|
||||
* @return the {@link User} if found
|
||||
*/
|
||||
@Query("SELECT user FROM User user left join fetch user.roles WHERE user.id =:id")
|
||||
@Transactional(readOnly = true)
|
||||
User findById(@Param("id") Integer id);
|
||||
|
||||
User findByEmail(String email);
|
||||
/**
|
||||
* Retrieve an {@link User} from the data store by email.
|
||||
* @param email the email to search for
|
||||
* @return the {@link User} if found
|
||||
*/
|
||||
@Query("SELECT user FROM User user left join fetch user.roles WHERE user.email =:email")
|
||||
@Transactional(readOnly = true)
|
||||
User findByEmail(@Param("email") String email);
|
||||
|
||||
Boolean existsByEmail(String email);
|
||||
|
||||
|
|
|
@ -2,14 +2,12 @@ package org.springframework.samples.petclinic.service.business;
|
|||
|
||||
import org.modelmapper.ModelMapper;
|
||||
import org.modelmapper.internal.util.Lists;
|
||||
import org.springframework.samples.petclinic.dto.OwnerDTO;
|
||||
import org.springframework.samples.petclinic.dto.PetDTO;
|
||||
import org.springframework.samples.petclinic.dto.business.OwnerDTO;
|
||||
import org.springframework.samples.petclinic.dto.business.PetDTO;
|
||||
import org.springframework.samples.petclinic.model.business.Owner;
|
||||
import org.springframework.samples.petclinic.model.business.Pet;
|
||||
import org.springframework.samples.petclinic.repository.OwnerRepository;
|
||||
import org.springframework.samples.petclinic.repository.PetRepository;
|
||||
import org.springframework.samples.petclinic.repository.PetTypeRepository;
|
||||
import org.springframework.samples.petclinic.repository.VisitRepository;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
@ -30,13 +28,9 @@ public class OwnerService implements BaseService<Owner, OwnerDTO> {
|
|||
|
||||
private final ModelMapper modelMapper = new ModelMapper();
|
||||
|
||||
private PetService petService;
|
||||
|
||||
public OwnerService(OwnerRepository ownerRepository, PetRepository petRepository,
|
||||
PetTypeRepository petTypeRepository, VisitRepository visitRepository) {
|
||||
public OwnerService(OwnerRepository ownerRepository, PetRepository petRepository) {
|
||||
this.ownerRepository = ownerRepository;
|
||||
this.petRepository = petRepository;
|
||||
petService = new PetService(petRepository, petTypeRepository, visitRepository);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -1,9 +1,9 @@
|
|||
package org.springframework.samples.petclinic.service.business;
|
||||
|
||||
import org.modelmapper.ModelMapper;
|
||||
import org.springframework.samples.petclinic.dto.OwnerDTO;
|
||||
import org.springframework.samples.petclinic.dto.PetDTO;
|
||||
import org.springframework.samples.petclinic.dto.PetTypeDTO;
|
||||
import org.springframework.samples.petclinic.dto.business.OwnerDTO;
|
||||
import org.springframework.samples.petclinic.dto.business.PetDTO;
|
||||
import org.springframework.samples.petclinic.dto.business.PetTypeDTO;
|
||||
import org.springframework.samples.petclinic.model.business.Owner;
|
||||
import org.springframework.samples.petclinic.model.business.Pet;
|
||||
import org.springframework.samples.petclinic.model.business.PetType;
|
||||
|
@ -27,8 +27,6 @@ public class PetService implements BaseService<Pet, PetDTO> {
|
|||
|
||||
private final PetTypeService petTypeService;
|
||||
|
||||
private final PetTypeRepository petTypeRepository;
|
||||
|
||||
private final VisitService visitService;
|
||||
|
||||
private final ModelMapper modelMapper = new ModelMapper();
|
||||
|
@ -36,7 +34,6 @@ public class PetService implements BaseService<Pet, PetDTO> {
|
|||
public PetService(PetRepository petRepository, PetTypeRepository petTypeRepository,
|
||||
VisitRepository visitRepository) {
|
||||
this.petRepository = petRepository;
|
||||
this.petTypeRepository = petTypeRepository;
|
||||
this.visitService = new VisitService(visitRepository);
|
||||
this.petTypeService = new PetTypeService(petTypeRepository);
|
||||
}
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
package org.springframework.samples.petclinic.service.business;
|
||||
|
||||
import org.modelmapper.ModelMapper;
|
||||
import org.springframework.samples.petclinic.dto.PetTypeDTO;
|
||||
import org.springframework.samples.petclinic.dto.business.PetTypeDTO;
|
||||
import org.springframework.samples.petclinic.model.business.PetType;
|
||||
import org.springframework.samples.petclinic.repository.PetTypeRepository;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
package org.springframework.samples.petclinic.service.business;
|
||||
|
||||
import org.modelmapper.ModelMapper;
|
||||
import org.springframework.samples.petclinic.dto.SpecialtyDTO;
|
||||
import org.springframework.samples.petclinic.dto.business.SpecialtyDTO;
|
||||
import org.springframework.samples.petclinic.model.business.Specialty;
|
||||
import org.springframework.samples.petclinic.repository.SpecialtyRepository;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
|
|
@ -2,8 +2,8 @@ package org.springframework.samples.petclinic.service.business;
|
|||
|
||||
import org.modelmapper.ModelMapper;
|
||||
import org.modelmapper.internal.util.Lists;
|
||||
import org.springframework.samples.petclinic.dto.SpecialtyDTO;
|
||||
import org.springframework.samples.petclinic.dto.VetDTO;
|
||||
import org.springframework.samples.petclinic.dto.business.SpecialtyDTO;
|
||||
import org.springframework.samples.petclinic.dto.business.VetDTO;
|
||||
import org.springframework.samples.petclinic.model.business.Specialty;
|
||||
import org.springframework.samples.petclinic.repository.SpecialtyRepository;
|
||||
import org.springframework.samples.petclinic.repository.VetRepository;
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
package org.springframework.samples.petclinic.service.business;
|
||||
|
||||
import org.modelmapper.ModelMapper;
|
||||
import org.springframework.samples.petclinic.dto.VisitDTO;
|
||||
import org.springframework.samples.petclinic.dto.business.VisitDTO;
|
||||
import org.springframework.samples.petclinic.model.business.Visit;
|
||||
import org.springframework.samples.petclinic.repository.VisitRepository;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
package org.springframework.samples.petclinic.service.common;
|
||||
|
||||
import org.modelmapper.ModelMapper;
|
||||
import org.springframework.samples.petclinic.dto.common.RoleDTO;
|
||||
import org.springframework.samples.petclinic.dto.common.UserDTO;
|
||||
import org.springframework.samples.petclinic.model.common.Role;
|
||||
import org.springframework.samples.petclinic.model.common.User;
|
||||
|
@ -40,16 +39,7 @@ public class UserService implements BaseService<User, UserDTO> {
|
|||
|
||||
User user = modelMapper.map(dto, User.class);
|
||||
user.setPassword(dto.getPassword());
|
||||
|
||||
if (dto.getRoles() != null) {
|
||||
Set<Role> roles = new HashSet<>();
|
||||
|
||||
for (String role : dto.getRoles()) {
|
||||
roles.add(roleRepository.findByName(role));
|
||||
}
|
||||
|
||||
user.setRoles(roles);
|
||||
}
|
||||
dto.getRoles().forEach(role -> user.addRole(modelMapper.map(role, Role.class)));
|
||||
|
||||
return user;
|
||||
}
|
||||
|
@ -64,16 +54,6 @@ public class UserService implements BaseService<User, UserDTO> {
|
|||
userDto.setPassword(entity.getPassword());
|
||||
userDto.setMatchingPassword(entity.getPassword());
|
||||
|
||||
if (entity.getRoles() != null) {
|
||||
List<String> roles = new ArrayList<>();
|
||||
|
||||
for (Role role : entity.getRoles()) {
|
||||
roles.add(role.getName());
|
||||
}
|
||||
|
||||
userDto.setRoles(roles);
|
||||
}
|
||||
|
||||
return userDto;
|
||||
}
|
||||
|
||||
|
|
|
@ -17,7 +17,7 @@ package org.springframework.samples.petclinic.validator;
|
|||
|
||||
import org.springframework.samples.petclinic.common.CommonAttribute;
|
||||
import org.springframework.samples.petclinic.common.CommonError;
|
||||
import org.springframework.samples.petclinic.dto.PetDTO;
|
||||
import org.springframework.samples.petclinic.dto.business.PetDTO;
|
||||
import org.springframework.util.StringUtils;
|
||||
import org.springframework.validation.Errors;
|
||||
import org.springframework.validation.Validator;
|
||||
|
|
|
@ -2,7 +2,7 @@ package org.springframework.samples.petclinic.validator;
|
|||
|
||||
import org.springframework.samples.petclinic.common.CommonAttribute;
|
||||
import org.springframework.samples.petclinic.common.CommonError;
|
||||
import org.springframework.samples.petclinic.dto.VisitDTO;
|
||||
import org.springframework.samples.petclinic.dto.business.VisitDTO;
|
||||
import org.springframework.validation.Errors;
|
||||
import org.springframework.validation.Validator;
|
||||
|
||||
|
|
|
@ -57,6 +57,12 @@ INSERT INTO roles (id, name) VALUES
|
|||
(2,'ROLE_STAFF'),
|
||||
(3,'ROLE_USER');
|
||||
|
||||
INSERT INTO privileges (id, name) VALUES
|
||||
(1,'CREATE'),
|
||||
(2,'READ'),
|
||||
(3,'UPDATE'),
|
||||
(4,'DELETE');
|
||||
|
||||
INSERT INTO users (id, first_name, last_name, email, password, enabled, telephone, street1, zip_code, city, country) VALUES
|
||||
(1, 'George', 'Franklin', 'georges.franklin@petclinic.com', '$2a$10$8KypNYtPopFo8Sk5jbKJ4.lCKeBhdApsrkmFfhwjB8nCls8qpzjZG', true, '6085551023', '110 W. Liberty St.',12354,'Madison','USA'),
|
||||
(2, 'Betty', 'Davis', 'betty.davis@petclinic.com', '$2a$10$InKx/fhX3CmLi8zKpHYx/.ETHUlZwvT1xn.Za/pp2JR0iEtYV9a9O', true, '6085551749','638 Cardinal Ave.', 6546, 'Sun Prairie', 'USA'),
|
||||
|
@ -67,6 +73,10 @@ INSERT INTO users_roles (user_id, role_id) VALUES
|
|||
(1,1),(1,2),(1,3),
|
||||
(2,3),(3,3);
|
||||
|
||||
INSERT INTO roles_privileges (role_id, privilege_id) values
|
||||
(1,1),(1,2),(1,3),(1,4),
|
||||
(2,1),(2,2),(2,3),
|
||||
(3,1),(3,2);
|
||||
|
||||
INSERT INTO auth_providers (id, name) VALUES
|
||||
(1,'local'),
|
||||
|
|
|
@ -71,6 +71,13 @@ CREATE TABLE roles (
|
|||
);
|
||||
CREATE INDEX roles_name ON roles (name);
|
||||
|
||||
DROP TABLE privileges IF EXISTS;
|
||||
CREATE TABLE privileges (
|
||||
id INTEGER IDENTITY PRIMARY KEY,
|
||||
name VARCHAR(20) NOT NULL
|
||||
);
|
||||
CREATE INDEX privileges_name ON privileges (name);
|
||||
|
||||
|
||||
DROP TABLE users IF EXISTS;
|
||||
CREATE TABLE users (
|
||||
|
@ -102,6 +109,13 @@ ALTER TABLE users_roles ADD CONSTRAINT fk_users_roles_user_id FOREIGN KEY (user_
|
|||
ALTER TABLE users_roles ADD CONSTRAINT fk_users_roles_role_id FOREIGN KEY (role_id) REFERENCES roles (id);
|
||||
CREATE INDEX users_roles_user_id ON users_roles (user_id);
|
||||
|
||||
DROP TABLE roles_privileges IF EXISTS;
|
||||
CREATE TABLE roles_privileges (
|
||||
role_id INTEGER NOT NULL,
|
||||
privilege_id INTEGER NOT NULL
|
||||
);
|
||||
|
||||
|
||||
DROP TABLE auth_providers IF EXISTS;
|
||||
CREATE TABLE auth_providers (
|
||||
id INTEGER IDENTITY PRIMARY KEY,
|
||||
|
|
|
@ -9,6 +9,7 @@
|
|||
</h2>
|
||||
<form th:object="${pet}" class="form-horizontal" method="post">
|
||||
<input type="hidden" name="id" th:value="*{id}" />
|
||||
|
||||
<div class="form-group has-feedback">
|
||||
<div class="form-group">
|
||||
<label class="col-sm-2 control-label">Owner</label>
|
||||
|
@ -35,4 +36,4 @@
|
|||
|
||||
</body>
|
||||
|
||||
</html>
|
||||
</html>
|
||||
|
|
|
@ -9,10 +9,10 @@ import org.springframework.boot.test.mock.mockito.MockBean;
|
|||
import org.springframework.samples.petclinic.common.CommonAttribute;
|
||||
import org.springframework.samples.petclinic.common.CommonEndPoint;
|
||||
import org.springframework.samples.petclinic.common.CommonView;
|
||||
import org.springframework.samples.petclinic.dto.OwnerDTO;
|
||||
import org.springframework.samples.petclinic.dto.PetDTO;
|
||||
import org.springframework.samples.petclinic.dto.PetTypeDTO;
|
||||
import org.springframework.samples.petclinic.dto.VisitDTO;
|
||||
import org.springframework.samples.petclinic.dto.business.OwnerDTO;
|
||||
import org.springframework.samples.petclinic.dto.business.PetDTO;
|
||||
import org.springframework.samples.petclinic.dto.business.PetTypeDTO;
|
||||
import org.springframework.samples.petclinic.dto.business.VisitDTO;
|
||||
import org.springframework.samples.petclinic.service.business.OwnerService;
|
||||
import org.springframework.samples.petclinic.service.common.UserDetailsServiceImpl;
|
||||
import org.springframework.security.test.context.support.WithMockUser;
|
||||
|
|
|
@ -30,29 +30,20 @@ import org.junit.jupiter.api.Test;
|
|||
import org.junit.runner.RunWith;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.boot.test.mock.mockito.MockBean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.messaging.simp.SimpMessagingTemplate;
|
||||
import org.springframework.samples.petclinic.common.CommonAttribute;
|
||||
import org.springframework.samples.petclinic.common.CommonEndPoint;
|
||||
import org.springframework.samples.petclinic.common.CommonError;
|
||||
import org.springframework.samples.petclinic.common.CommonView;
|
||||
import org.springframework.samples.petclinic.controller.common.WebSocketSender;
|
||||
import org.springframework.samples.petclinic.dto.OwnerDTO;
|
||||
import org.springframework.samples.petclinic.dto.PetDTO;
|
||||
import org.springframework.samples.petclinic.dto.PetTypeDTO;
|
||||
import org.springframework.samples.petclinic.dto.VisitDTO;
|
||||
import org.springframework.samples.petclinic.dto.business.OwnerDTO;
|
||||
import org.springframework.samples.petclinic.dto.business.PetDTO;
|
||||
import org.springframework.samples.petclinic.dto.business.PetTypeDTO;
|
||||
import org.springframework.samples.petclinic.dto.business.VisitDTO;
|
||||
import org.springframework.samples.petclinic.service.business.OwnerService;
|
||||
import org.springframework.samples.petclinic.service.business.VisitService;
|
||||
import org.springframework.samples.petclinic.service.common.UserDetailsServiceImpl;
|
||||
import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder;
|
||||
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
|
||||
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
|
||||
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
|
||||
import org.springframework.security.core.userdetails.UserDetailsService;
|
||||
import org.springframework.security.crypto.factory.PasswordEncoderFactories;
|
||||
import org.springframework.security.crypto.password.PasswordEncoder;
|
||||
import org.springframework.security.test.context.support.WithMockUser;
|
||||
import org.springframework.test.context.junit4.SpringRunner;
|
||||
import org.springframework.test.web.servlet.MockMvc;
|
||||
|
|
|
@ -9,8 +9,8 @@ import org.springframework.boot.test.mock.mockito.MockBean;
|
|||
import org.springframework.samples.petclinic.common.CommonAttribute;
|
||||
import org.springframework.samples.petclinic.common.CommonEndPoint;
|
||||
import org.springframework.samples.petclinic.common.CommonView;
|
||||
import org.springframework.samples.petclinic.dto.OwnerDTO;
|
||||
import org.springframework.samples.petclinic.dto.PetDTO;
|
||||
import org.springframework.samples.petclinic.dto.business.OwnerDTO;
|
||||
import org.springframework.samples.petclinic.dto.business.PetDTO;
|
||||
import org.springframework.samples.petclinic.repository.PetRepository;
|
||||
import org.springframework.samples.petclinic.service.business.OwnerService;
|
||||
import org.springframework.samples.petclinic.service.business.PetService;
|
||||
|
|
|
@ -39,9 +39,9 @@ import org.springframework.samples.petclinic.common.CommonAttribute;
|
|||
import org.springframework.samples.petclinic.common.CommonEndPoint;
|
||||
import org.springframework.samples.petclinic.common.CommonError;
|
||||
import org.springframework.samples.petclinic.common.CommonView;
|
||||
import org.springframework.samples.petclinic.dto.OwnerDTO;
|
||||
import org.springframework.samples.petclinic.dto.PetDTO;
|
||||
import org.springframework.samples.petclinic.dto.PetTypeDTO;
|
||||
import org.springframework.samples.petclinic.dto.business.OwnerDTO;
|
||||
import org.springframework.samples.petclinic.dto.business.PetDTO;
|
||||
import org.springframework.samples.petclinic.dto.business.PetTypeDTO;
|
||||
import org.springframework.samples.petclinic.formatter.PetTypeFormatter;
|
||||
import org.springframework.samples.petclinic.service.business.OwnerService;
|
||||
import org.springframework.samples.petclinic.service.business.PetService;
|
||||
|
|
|
@ -14,7 +14,7 @@ import org.springframework.boot.test.mock.mockito.MockBean;
|
|||
import org.springframework.samples.petclinic.common.CommonAttribute;
|
||||
import org.springframework.samples.petclinic.common.CommonEndPoint;
|
||||
import org.springframework.samples.petclinic.common.CommonView;
|
||||
import org.springframework.samples.petclinic.dto.VetsDTO;
|
||||
import org.springframework.samples.petclinic.dto.business.VetsDTO;
|
||||
import org.springframework.samples.petclinic.repository.VetRepository;
|
||||
import org.springframework.samples.petclinic.service.business.VetService;
|
||||
import org.springframework.samples.petclinic.service.common.UserDetailsServiceImpl;
|
||||
|
|
|
@ -37,9 +37,9 @@ import org.springframework.messaging.simp.SimpMessagingTemplate;
|
|||
import org.springframework.samples.petclinic.common.CommonAttribute;
|
||||
import org.springframework.samples.petclinic.common.CommonEndPoint;
|
||||
import org.springframework.samples.petclinic.common.CommonView;
|
||||
import org.springframework.samples.petclinic.dto.SpecialtyDTO;
|
||||
import org.springframework.samples.petclinic.dto.VetDTO;
|
||||
import org.springframework.samples.petclinic.dto.VetsDTO;
|
||||
import org.springframework.samples.petclinic.dto.business.SpecialtyDTO;
|
||||
import org.springframework.samples.petclinic.dto.business.VetDTO;
|
||||
import org.springframework.samples.petclinic.dto.business.VetsDTO;
|
||||
import org.springframework.samples.petclinic.service.business.VetService;
|
||||
import org.springframework.samples.petclinic.service.common.UserDetailsServiceImpl;
|
||||
import org.springframework.security.test.context.support.WithMockUser;
|
||||
|
|
|
@ -9,8 +9,8 @@ import org.springframework.boot.test.mock.mockito.MockBean;
|
|||
import org.springframework.samples.petclinic.common.CommonAttribute;
|
||||
import org.springframework.samples.petclinic.common.CommonEndPoint;
|
||||
import org.springframework.samples.petclinic.common.CommonView;
|
||||
import org.springframework.samples.petclinic.dto.PetDTO;
|
||||
import org.springframework.samples.petclinic.dto.VisitDTO;
|
||||
import org.springframework.samples.petclinic.dto.business.PetDTO;
|
||||
import org.springframework.samples.petclinic.dto.business.VisitDTO;
|
||||
import org.springframework.samples.petclinic.model.business.Visit;
|
||||
import org.springframework.samples.petclinic.repository.VisitRepository;
|
||||
import org.springframework.samples.petclinic.service.business.PetService;
|
||||
|
|
|
@ -36,9 +36,9 @@ import org.springframework.messaging.simp.SimpMessagingTemplate;
|
|||
import org.springframework.samples.petclinic.common.CommonAttribute;
|
||||
import org.springframework.samples.petclinic.common.CommonEndPoint;
|
||||
import org.springframework.samples.petclinic.common.CommonView;
|
||||
import org.springframework.samples.petclinic.dto.PetDTO;
|
||||
import org.springframework.samples.petclinic.dto.PetTypeDTO;
|
||||
import org.springframework.samples.petclinic.dto.VisitDTO;
|
||||
import org.springframework.samples.petclinic.dto.business.PetDTO;
|
||||
import org.springframework.samples.petclinic.dto.business.PetTypeDTO;
|
||||
import org.springframework.samples.petclinic.dto.business.VisitDTO;
|
||||
import org.springframework.samples.petclinic.model.business.Visit;
|
||||
import org.springframework.samples.petclinic.service.business.PetService;
|
||||
import org.springframework.samples.petclinic.service.business.VisitService;
|
||||
|
|
|
@ -22,7 +22,7 @@ import org.junit.jupiter.api.Test;
|
|||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.junit.jupiter.MockitoExtension;
|
||||
import org.springframework.samples.petclinic.dto.PetTypeDTO;
|
||||
import org.springframework.samples.petclinic.dto.business.PetTypeDTO;
|
||||
import org.springframework.samples.petclinic.formatter.PetTypeFormatter;
|
||||
import org.springframework.samples.petclinic.model.business.PetType;
|
||||
import org.springframework.samples.petclinic.service.business.PetService;
|
||||
|
|
|
@ -28,7 +28,7 @@ import org.junit.jupiter.api.Test;
|
|||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.junit.jupiter.MockitoExtension;
|
||||
import org.springframework.samples.petclinic.dto.PetTypeDTO;
|
||||
import org.springframework.samples.petclinic.dto.business.PetTypeDTO;
|
||||
import org.springframework.samples.petclinic.formatter.PetTypeFormatter;
|
||||
import org.springframework.samples.petclinic.model.business.PetType;
|
||||
import org.springframework.samples.petclinic.service.business.PetService;
|
||||
|
|
|
@ -9,9 +9,9 @@ import org.junit.runner.RunWith;
|
|||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest;
|
||||
import org.springframework.samples.petclinic.common.CommonAttribute;
|
||||
import org.springframework.samples.petclinic.dto.OwnerDTO;
|
||||
import org.springframework.samples.petclinic.dto.PetDTO;
|
||||
import org.springframework.samples.petclinic.dto.PetTypeDTO;
|
||||
import org.springframework.samples.petclinic.dto.business.OwnerDTO;
|
||||
import org.springframework.samples.petclinic.dto.business.PetDTO;
|
||||
import org.springframework.samples.petclinic.dto.business.PetTypeDTO;
|
||||
import org.springframework.samples.petclinic.model.business.Owner;
|
||||
import org.springframework.samples.petclinic.model.business.Pet;
|
||||
import org.springframework.samples.petclinic.model.business.PetType;
|
||||
|
@ -82,7 +82,7 @@ class OwnerServiceTest {
|
|||
@BeforeEach
|
||||
void beforeEach() {
|
||||
petService = new PetService(petRepository, petTypeRepository, visitRepository);
|
||||
ownerService = new OwnerService(ownerRepository, petRepository, petTypeRepository, visitRepository);
|
||||
ownerService = new OwnerService(ownerRepository, petRepository);
|
||||
PetTypeService petTypeService = new PetTypeService(petTypeRepository);
|
||||
Collection<PetTypeDTO> petTypeDTOS = petService.findPetTypes();
|
||||
PetTypeDTO petTypeDTO = petTypeDTOS.stream().findFirst().get();
|
||||
|
|
|
@ -5,9 +5,9 @@ import org.junit.jupiter.api.*;
|
|||
import org.junit.runner.RunWith;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest;
|
||||
import org.springframework.samples.petclinic.dto.OwnerDTO;
|
||||
import org.springframework.samples.petclinic.dto.PetDTO;
|
||||
import org.springframework.samples.petclinic.dto.PetTypeDTO;
|
||||
import org.springframework.samples.petclinic.dto.business.OwnerDTO;
|
||||
import org.springframework.samples.petclinic.dto.business.PetDTO;
|
||||
import org.springframework.samples.petclinic.dto.business.PetTypeDTO;
|
||||
import org.springframework.samples.petclinic.model.business.Owner;
|
||||
import org.springframework.samples.petclinic.model.business.Pet;
|
||||
import org.springframework.samples.petclinic.model.business.PetType;
|
||||
|
@ -68,7 +68,7 @@ class PetServiceTest {
|
|||
@BeforeEach
|
||||
void beforeEach() {
|
||||
this.petService = new PetService(petRepository, petTypeRepository, visitRepository);
|
||||
this.ownerService = new OwnerService(ownerRepository, petRepository, petTypeRepository, visitRepository);
|
||||
this.ownerService = new OwnerService(ownerRepository, petRepository);
|
||||
|
||||
PetTypeService petTypeService = new PetTypeService(petTypeRepository);
|
||||
Collection<PetTypeDTO> petTypeDTOS = petService.findPetTypes();
|
||||
|
|
|
@ -8,13 +8,11 @@ import org.junit.jupiter.api.Test;
|
|||
import org.junit.runner.RunWith;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest;
|
||||
import org.springframework.context.annotation.ComponentScan;
|
||||
import org.springframework.samples.petclinic.dto.VetDTO;
|
||||
import org.springframework.samples.petclinic.dto.business.VetDTO;
|
||||
import org.springframework.samples.petclinic.model.business.Vet;
|
||||
import org.springframework.samples.petclinic.repository.SpecialtyRepository;
|
||||
import org.springframework.samples.petclinic.repository.VetRepository;
|
||||
import org.springframework.samples.petclinic.service.business.VetService;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.test.context.junit4.SpringRunner;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
|
|
@ -6,8 +6,8 @@ import org.junit.jupiter.api.Tag;
|
|||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.samples.petclinic.common.CommonAttribute;
|
||||
import org.springframework.samples.petclinic.common.CommonError;
|
||||
import org.springframework.samples.petclinic.dto.PetDTO;
|
||||
import org.springframework.samples.petclinic.dto.PetTypeDTO;
|
||||
import org.springframework.samples.petclinic.dto.business.PetDTO;
|
||||
import org.springframework.samples.petclinic.dto.business.PetTypeDTO;
|
||||
import org.springframework.validation.BeanPropertyBindingResult;
|
||||
import org.springframework.validation.Errors;
|
||||
import org.springframework.validation.FieldError;
|
||||
|
|
|
@ -6,7 +6,7 @@ import org.junit.jupiter.api.Tag;
|
|||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.samples.petclinic.common.CommonAttribute;
|
||||
import org.springframework.samples.petclinic.common.CommonError;
|
||||
import org.springframework.samples.petclinic.dto.VisitDTO;
|
||||
import org.springframework.samples.petclinic.dto.business.VisitDTO;
|
||||
import org.springframework.validation.BeanPropertyBindingResult;
|
||||
import org.springframework.validation.Errors;
|
||||
import org.springframework.validation.FieldError;
|
||||
|
|
Loading…
Reference in a new issue