Changeset 950fa0d for src/main/java


Ignore:
Timestamp:
05/24/23 23:18:47 (18 months ago)
Author:
Gjoko Kostadinov <gjoko.kostadinov@…>
Branches:
master
Children:
77205be
Parents:
8bcd64c
Message:

Periodic update

Location:
src/main/java/edu/gjoko/schedlr
Files:
6 added
12 edited
1 moved

Legend:

Unmodified
Added
Removed
  • src/main/java/edu/gjoko/schedlr/config/AppFilter.java

    r8bcd64c r950fa0d  
    1010import org.springframework.web.filter.GenericFilterBean;
    1111
    12 import javax.servlet.FilterChain;
    13 import javax.servlet.ServletException;
    14 import javax.servlet.ServletRequest;
    15 import javax.servlet.ServletResponse;
     12import javax.servlet.*;
    1613import javax.servlet.http.HttpServletRequest;
    1714import javax.servlet.http.HttpServletResponse;
     
    7572                            break;
    7673                    }
    77                     if(page != null && !page.trim().isEmpty()) {
     74                    if(page != null && !page.trim().isEmpty() && !DispatcherType.ERROR.equals(servletRequest.getDispatcherType())) {
    7875                        servletRequest.getRequestDispatcher(page).forward(servletRequest, servletResponse);
    7976                        return;
  • src/main/java/edu/gjoko/schedlr/config/AppSecurityConfig.java

    r8bcd64c r950fa0d  
    1010import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
    1111import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
    12 import org.springframework.security.config.core.GrantedAuthorityDefaults;
    1312import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
    14 import org.springframework.security.web.access.AccessDeniedHandler;
    1513import org.springframework.security.web.authentication.AuthenticationFailureHandler;
    1614import org.springframework.security.web.authentication.AuthenticationSuccessHandler;
     15import org.springframework.security.web.authentication.logout.HeaderWriterLogoutHandler;
     16import org.springframework.security.web.authentication.logout.SecurityContextLogoutHandler;
    1717import org.springframework.security.web.authentication.www.BasicAuthenticationFilter;
     18import org.springframework.security.web.header.writers.ClearSiteDataHeaderWriter;
     19
     20import static org.springframework.security.web.header.writers.ClearSiteDataHeaderWriter.Directive.*;
    1821
    1922@Configuration
     
    2124@AllArgsConstructor
    2225public class AppSecurityConfig extends WebSecurityConfigurerAdapter {
     26
     27    private static final ClearSiteDataHeaderWriter.Directive[] SOURCE =
     28            {CACHE, COOKIES, STORAGE, EXECUTION_CONTEXTS};
    2329
    2430    private final PostgresUserDetailsService userDetailsService;
     
    5561                .defaultSuccessUrl("/homepage")
    5662                .and()
     63                .logout(logout -> logout
     64                        .logoutUrl("/logout")
     65                        .logoutSuccessUrl("/login")
     66                        .addLogoutHandler(new SecurityContextLogoutHandler())
     67                        .addLogoutHandler(new HeaderWriterLogoutHandler(new ClearSiteDataHeaderWriter(SOURCE))))
    5768                .authorizeRequests()
    5869                .antMatchers("/login").permitAll()
     70                .antMatchers("/logout").permitAll()
    5971                .antMatchers("/register_customer").permitAll()
    6072                .antMatchers("/register_business").permitAll()
    6173                .antMatchers("/api/nomenclatures/*").permitAll()
     74                .antMatchers("/api/user/me").permitAll()
    6275                .antMatchers("/api/business").permitAll()
     76                .antMatchers("/api/appointment").permitAll()
    6377                .antMatchers("/homepage").permitAll()
    6478                .antMatchers("/css/**").permitAll()
  • src/main/java/edu/gjoko/schedlr/controllers/rest/BusinessController.java

    r8bcd64c r950fa0d  
    22
    33import edu.gjoko.schedlr.entity.Business;
     4import edu.gjoko.schedlr.entity.BusinessType;
    45import edu.gjoko.schedlr.services.BusinessService;
    56import lombok.AllArgsConstructor;
    6 import org.springframework.security.core.Authentication;
    7 import org.springframework.security.core.context.SecurityContextHolder;
    87import org.springframework.web.bind.annotation.*;
    98
     
    3837        return businessService.findByOwner(businessOwnerId);
    3938    }
     39
     40    @GetMapping(path = "/{businessTypeId}")
     41    public List<Business> getBusinessesByBusinessType(@PathVariable("businessTypeId") Long id) {
     42        BusinessType businessType = new BusinessType();
     43        businessType.setId(id);
     44        return businessService.findByBusinessTypeAndActiveStatus(businessType);
     45    }
    4046}
  • src/main/java/edu/gjoko/schedlr/controllers/rest/NomenclatureController.java

    r8bcd64c r950fa0d  
    22
    33import edu.gjoko.schedlr.entity.BusinessType;
    4 import edu.gjoko.schedlr.repositories.BusinessTypeRepository;
    54import edu.gjoko.schedlr.services.NomenclaturesService;
    65import lombok.AllArgsConstructor;
     
    1413@RequestMapping("api/nomenclatures")
    1514@AllArgsConstructor
    16 public class NomenclaturesController {
     15public class NomenclatureController {
    1716
    1817    private final NomenclaturesService nomenclaturesService;
  • src/main/java/edu/gjoko/schedlr/entity/Appointment.java

    r8bcd64c r950fa0d  
    2424    private Long id;
    2525
    26     @Column(name = "start_type")
     26    @Column(name = "start_time")
    2727    private LocalDateTime startTime;
    2828
     
    3030    private LocalDateTime endTime;
    3131
    32     @Column(name = "price")
    33     private Float price;
     32    @OneToOne
     33    @JoinColumn(name = "customer_id", referencedColumnName = "id")
     34    private Stakeholder customer;
     35
     36    @ManyToOne
     37    @JoinColumn(name = "business_id")
     38    private Business business;
     39
     40    @ManyToOne
     41    @JoinColumn(name = "service_id")
     42    private Service service;
    3443
    3544    @Column(name = "created")
  • src/main/java/edu/gjoko/schedlr/entity/Business.java

    r8bcd64c r950fa0d  
    3737    private BusinessType businessType;
    3838
    39     @ManyToOne(cascade = CascadeType.PERSIST)
     39    @ManyToOne()
    4040    @JoinColumn(name = "owner_id", referencedColumnName = "id", nullable = false)
    4141    @JsonProperty("owner")
  • src/main/java/edu/gjoko/schedlr/entity/Service.java

    r8bcd64c r950fa0d  
    3333    private Integer price;
    3434
    35     @OneToOne(cascade = CascadeType.MERGE)
     35    @OneToOne(cascade = CascadeType.PERSIST)
    3636    @JoinColumn(name = "service_type_id", referencedColumnName = "id")
    3737    private ServiceType serviceType;
    3838
    3939    @ManyToOne
    40     @JoinColumn(name = "business_fk")
     40    @JoinColumn(name = "business_id")
    4141    @JsonBackReference
    4242    private Business business;
  • src/main/java/edu/gjoko/schedlr/entity/ServiceType.java

    r8bcd64c r950fa0d  
    3030    private String name;
    3131
    32 
    3332    @ManyToOne
    3433    @JoinColumn(name = "business_type_id")
  • src/main/java/edu/gjoko/schedlr/entity/Stakeholder.java

    r8bcd64c r950fa0d  
    4343
    4444    @Column(name = "password")
    45     @JsonIgnore
    4645    private String password;
    4746
  • src/main/java/edu/gjoko/schedlr/repositories/BusinessRepository.java

    r8bcd64c r950fa0d  
    33import edu.gjoko.schedlr.entity.Business;
    44import edu.gjoko.schedlr.entity.BusinessStatus;
     5import edu.gjoko.schedlr.entity.BusinessType;
    56import edu.gjoko.schedlr.entity.Stakeholder;
     7import org.hibernate.Session;
    68import org.springframework.data.jpa.repository.JpaRepository;
    79import org.springframework.stereotype.Repository;
     
    1214public interface BusinessRepository extends JpaRepository<Business, Long> {
    1315
    14     List<Business> findBusinessesByBusinessStatus(BusinessStatus status);
     16    Business findBusinessByOwner(Stakeholder owner);
    1517
    16     Business findBusinessByOwner(Stakeholder owner);
     18    List<Business> findBusinessesByBusinessTypeAndBusinessStatus(BusinessType businessType, BusinessStatus businessStatus);
    1719}
  • src/main/java/edu/gjoko/schedlr/services/BusinessService.java

    r8bcd64c r950fa0d  
    11package edu.gjoko.schedlr.services;
    22
    3 import edu.gjoko.schedlr.entity.Business;
    4 import edu.gjoko.schedlr.entity.ServiceType;
    5 import edu.gjoko.schedlr.entity.Stakeholder;
    6 import edu.gjoko.schedlr.entity.StakeholderType;
     3import edu.gjoko.schedlr.entity.*;
    74import edu.gjoko.schedlr.repositories.BusinessRepository;
     5import edu.gjoko.schedlr.repositories.ServiceRepository;
    86import edu.gjoko.schedlr.repositories.ServiceTypeRepository;
     7import edu.gjoko.schedlr.repositories.StakeholderRepository;
    98import lombok.AllArgsConstructor;
    109import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
     
    1312import java.util.List;
    1413
     14import static edu.gjoko.schedlr.entity.BusinessStatus.ACTIVE;
    1515import static edu.gjoko.schedlr.entity.BusinessStatus.NEW;
    1616
     
    2121    private final BusinessRepository businessRepository;
    2222    private final ServiceTypeRepository serviceTypeRepository;
     23    private final ServiceRepository serviceRepository;
     24
     25    private final StakeholderRepository stakeholderRepository;
    2326    private BCryptPasswordEncoder bCryptPasswordEncoder;
    2427
     
    5154                .stream()
    5255                .forEach(business -> {
     56                    stakeholderRepository.save(business.getOwner());
     57                    serviceRepository.saveAll(business.getServices());
    5358                    businessRepository.save(business);
    5459                });
     
    6065        return businessRepository.findBusinessByOwner(owner);
    6166    }
     67
     68    public List<Business> findByBusinessTypeAndActiveStatus(BusinessType businessType) {
     69        return businessRepository.findBusinessesByBusinessTypeAndBusinessStatus(businessType, ACTIVE);
     70    }
    6271}
  • src/main/java/edu/gjoko/schedlr/services/PostgresUserDetailsService.java

    r8bcd64c r950fa0d  
    88import edu.gjoko.schedlr.repositories.StakeholderRepository;
    99import lombok.RequiredArgsConstructor;
    10 import org.springframework.security.access.AccessDeniedException;
    1110import org.springframework.security.core.GrantedAuthority;
    1211import org.springframework.security.core.authority.SimpleGrantedAuthority;
     
    1514import org.springframework.security.core.userdetails.UserDetailsService;
    1615import org.springframework.security.core.userdetails.UsernameNotFoundException;
    17 import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
    1816import org.springframework.stereotype.Service;
    1917
     
    2624
    2725    private final StakeholderRepository stakeholderRepository;
    28     private final BCryptPasswordEncoder bCryptPasswordEncoder;
    29 
    3026    private final BusinessRepository businessRepository;
    3127
     
    3329    public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {
    3430        Stakeholder user = stakeholderRepository.findStakeholderByUsername(username);
    35         if(user == null) {
     31        if (user == null) {
    3632            throw new UsernameNotFoundException("Non existing user");
    3733        }
    3834
    39         if(user.getStakeholderType() == StakeholderType.BUSINESS_OWNER) {
     35        if (user.getStakeholderType() == StakeholderType.BUSINESS_OWNER) {
    4036            Business business = businessRepository.findBusinessByOwner(user);
    4137            if (business.getBusinessStatus() != BusinessStatus.ACTIVE) {
  • src/main/java/edu/gjoko/schedlr/services/StakeholderService.java

    r8bcd64c r950fa0d  
    2424        return stakeholderRepository.save(stakeholder);
    2525    }
     26
     27    public Stakeholder findById(Long id) {
     28        return stakeholderRepository.findById(id).get();
     29    }
    2630}
Note: See TracChangeset for help on using the changeset viewer.