Task: Add CUBETIQ Fusion project with spring boot and vaadin fusion and updated the functions and classes

This commit is contained in:
Sambo Chea 2021-07-25 18:52:57 +07:00
parent 39035606c5
commit 64a6023b77
8 changed files with 30 additions and 40 deletions

View File

@ -12,9 +12,12 @@ import org.springframework.beans.factory.annotation.Autowired;
@Endpoint @Endpoint
@AnonymousAllowed @AnonymousAllowed
public class UserEndpoint { public class UserEndpoint {
private final AuthenticatedUser authenticatedUser;
@Autowired @Autowired
private AuthenticatedUser authenticatedUser; public UserEndpoint(AuthenticatedUser authenticatedUser) {
this.authenticatedUser = authenticatedUser;
}
public Optional<User> getAuthenticatedUser() { public Optional<User> getAuthenticatedUser() {
return authenticatedUser.get(); return authenticatedUser.get();

View File

@ -13,7 +13,6 @@ import javax.persistence.Lob;
@Entity @Entity
public class User extends AbstractEntity { public class User extends AbstractEntity {
@Nonnull @Nonnull
private String username; private String username;
@Nonnull @Nonnull

View File

@ -1,21 +1,16 @@
package com.cubetiqs.fusion.data.generator; package com.cubetiqs.fusion.data.generator;
import com.vaadin.flow.spring.annotation.SpringComponent;
import com.cubetiqs.fusion.data.service.UserRepository;
import com.cubetiqs.fusion.data.entity.User;
import java.util.Collections;
import org.springframework.security.crypto.password.PasswordEncoder;
import com.cubetiqs.fusion.data.Role; import com.cubetiqs.fusion.data.Role;
import com.cubetiqs.fusion.data.entity.User;
import java.time.LocalDateTime; import com.cubetiqs.fusion.data.service.UserRepository;
import com.vaadin.flow.spring.annotation.SpringComponent;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.springframework.boot.CommandLineRunner; import org.springframework.boot.CommandLineRunner;
import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Bean;
import org.vaadin.artur.exampledata.DataType; import org.springframework.security.crypto.password.PasswordEncoder;
import org.vaadin.artur.exampledata.ExampleDataGenerator;
import java.util.Collections;
@SpringComponent @SpringComponent
public class DataGenerator { public class DataGenerator {
@ -28,7 +23,6 @@ public class DataGenerator {
logger.info("Using existing database"); logger.info("Using existing database");
return; return;
} }
int seed = 123;
logger.info("Generating demo data"); logger.info("Generating demo data");

View File

@ -1,17 +1,8 @@
package com.cubetiqs.fusion.data.service; package com.cubetiqs.fusion.data.service;
import com.cubetiqs.fusion.data.entity.User; import com.cubetiqs.fusion.data.entity.User;
import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.jpa.repository.JpaRepository;
import com.vaadin.fusion.Nonnull;
import com.fasterxml.jackson.annotation.JsonIgnore;
import java.util.Set;
import javax.persistence.ElementCollection;
import javax.persistence.FetchType;
import com.cubetiqs.fusion.data.Role;
import javax.persistence.Lob;
public interface UserRepository extends JpaRepository<User, Integer> { public interface UserRepository extends JpaRepository<User, Integer> {
User findByUsername(String username); User findByUsername(String username);
} }

View File

@ -1,22 +1,13 @@
package com.cubetiqs.fusion.data.service; package com.cubetiqs.fusion.data.service;
import com.cubetiqs.fusion.data.entity.User; import com.cubetiqs.fusion.data.entity.User;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.vaadin.artur.helpers.CrudService; import org.vaadin.artur.helpers.CrudService;
import com.vaadin.fusion.Nonnull;
import com.fasterxml.jackson.annotation.JsonIgnore;
import java.util.Set;
import javax.persistence.ElementCollection;
import javax.persistence.FetchType;
import com.cubetiqs.fusion.data.Role;
import javax.persistence.Lob;
@Service @Service
public class UserService extends CrudService<User, Integer> { public class UserService extends CrudService<User, Integer> {
private final UserRepository repository;
private UserRepository repository;
public UserService(@Autowired UserRepository repository) { public UserService(@Autowired UserRepository repository) {
this.repository = repository; this.repository = repository;

View File

@ -16,9 +16,12 @@ import org.springframework.stereotype.Component;
@Component @Component
public class AuthenticatedUser { public class AuthenticatedUser {
private final UserRepository userRepository;
@Autowired @Autowired
private UserRepository userRepository; public AuthenticatedUser(UserRepository userRepository) {
this.userRepository = userRepository;
}
private UserDetails getAuthenticatedUser() { private UserDetails getAuthenticatedUser() {
SecurityContext context = SecurityContextHolder.getContext(); SecurityContext context = SecurityContextHolder.getContext();

View File

@ -16,9 +16,12 @@ import org.springframework.stereotype.Service;
@Service @Service
public class UserDetailsServiceImpl implements UserDetailsService { public class UserDetailsServiceImpl implements UserDetailsService {
private final UserRepository userRepository;
@Autowired @Autowired
private UserRepository userRepository; public UserDetailsServiceImpl(UserRepository userRepository) {
this.userRepository = userRepository;
}
@Override @Override
public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException { public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {
@ -34,7 +37,6 @@ public class UserDetailsServiceImpl implements UserDetailsService {
private static List<GrantedAuthority> getAuthorities(User user) { private static List<GrantedAuthority> getAuthorities(User user) {
return user.getRoles().stream().map(role -> new SimpleGrantedAuthority("ROLE_" + role.getRoleName())) return user.getRoles().stream().map(role -> new SimpleGrantedAuthority("ROLE_" + role.getRoleName()))
.collect(Collectors.toList()); .collect(Collectors.toList());
} }
} }

View File

@ -1,7 +1,14 @@
server.port=${PORT:8080} server:
logging.level.org.atmosphere = warn port: ${PORT:8080}
spring.mustache.check-template-location = false
logging:
level:
org.atmosphere: warn
spring:
mustache:
check-template-location: false
# To improve the performance during development. # To improve the performance during development.
# For more information https://vaadin.com/docs/flow/spring/tutorial-spring-configuration.html#special-configuration-parameters # For more information https://vaadin.com/docs/flow/spring/tutorial-spring-configuration.html#special-configuration-parameters
# vaadin.whitelisted-packages= org/vaadin/example # vaadin.whitelisted-packages= org/vaadin/example