Orgnize theese word files

Description

take ch 1 to 5 from ticket reservation file And take ch 6 to 8 and the appendix a from the second file

Don't use plagiarized sources. Get Your Custom Assignment on
Orgnize theese word files
From as Little as $13/Page

Trnasfere it and orgnize it to the Senior Project II – New Template V-0.1.docx file


Unformatted Attachment Preview

Appendix A: Source Code.
FileName
Code.
Bot.java
package sa.edu.seu.ticketrs.bot;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
import java.util.List;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;
import org.springframework.util.ResourceUtils;
import jakarta.xml.bind.JAXBContext;
import jakarta.xml.bind.JAXBContextFactory;
@Component
@Scope(“singleton”)
public class Bot {
private Logger logger = LoggerFactory.getLogger(Bot.class);
private Map answers;
public Bot() {
answers = new HashMap();
this.logger.info(“Bot is ready to chat”);
this.loadAnswers();
}
private void loadAnswers() {
try {
JAXBContext ctx = JAXBContext.newInstance(BotConfig.class);
var um = ctx.createUnmarshaller();
BotConfig config = (BotConfig)
um.unmarshal(ResourceUtils.getFile(“classpath:data.xml”));
var states = config.getStates();
if(states != null && states.size() > 0)
{
for (State state : states) {
var keywords = state.getKeywords();
if (keywords != null && keywords.size() > 0) {
for (String keyword : keywords) {
this.answers.put(keyword, state.getMessage());
this.logger.info(“Keyword: ” + keyword + ” —> loaded”);
}
} else {
this.answers.put(“-1”, state.getMessage());
}
}
this.logger.info(“Bot answers loaded”);
}
} catch (Exception ex) {
this.logger.error(ex.getMessage(), ex);
}
}
// send user message to the bot and get the response
public String getAnswer(String message) {
this.logger.info(“Answering message: ” + message);
String response = “N/A”;
if (this.answers.containsKey(message)) {
return this.answers.get(message);
} else {
response = getMessage(message);
}
return response;
}
public String getMessage(String keyword) {
String unknown = “Sorry can not understand you!”;
if (keyword == null || this.answers == null || this.answers.keySet().size() == 0)
{
return unknown;
}
keyword = keyword.toLowerCase();
for (String k : this.answers.keySet()) {
if (k.toLowerCase().trim().contains(keyword)) {
return this.answers.get(k);
}
}
return unknown;
}
}
BotConfig.java
package sa.edu.seu.ticketrs.bot;
import java.util.List;
import jakarta.xml.bind.annotation.XmlAccessType;
import jakarta.xml.bind.annotation.XmlAccessorType;
import jakarta.xml.bind.annotation.XmlElement;
import jakarta.xml.bind.annotation.XmlRootElement;
@XmlRootElement(name = “Config”)
@XmlAccessorType(XmlAccessType.FIELD)
public class BotConfig {
@XmlElement(name=”State”)
private List states;
public List getStates() {
return states;
}
public void setStates(List states) {
this.states = states;
}
}
ChatMessage.java
package sa.edu.seu.ticketrs.bot;
public class ChatMessage {
private String text;
public String getText() {
return text;
}
public void setText(String text) {
this.text = text;
}
}
State.java
package sa.edu.seu.ticketrs.bot;
import java.util.ArrayList;
import java.util.List;
import jakarta.xml.bind.annotation.XmlAccessType;
import jakarta.xml.bind.annotation.XmlAccessorType;
import jakarta.xml.bind.annotation.XmlAttribute;
import jakarta.xml.bind.annotation.XmlElement;
import jakarta.xml.bind.annotation.XmlRootElement;
@XmlRootElement
@XmlAccessorType(XmlAccessType.FIELD)
public class State {
@XmlAttribute
private String id = “”;
@XmlElement(name=”message”)
private String message;
@XmlElement(name=”keyword”)
private List keywords;
// default constructor, constructs State object
public State() {
}
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public String getMessage() {
return message;
}
public void setMessage(String message) {
this.message = message;
}
public List getKeywords() {
return keywords;
}
public void setKeywords(ArrayList keywords) {
this.keywords = keywords;
}
}
Event.java
package sa.edu.seu.ticketrs.domain;
import java.io.Serializable;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.LocalTime;
import java.util.Collections;
import java.util.Set;
import java.util.TreeSet;
import org.springframework.format.annotation.DateTimeFormat;
import jakarta.persistence.Entity;
import jakarta.persistence.FetchType;
import jakarta.persistence.Table;
import jakarta.persistence.Transient;
import jakarta.persistence.Id;
import jakarta.persistence.OneToMany;
import jakarta.persistence.Column;
import jakarta.persistence.GeneratedValue;
@Entity
@Table(name=”events”)
public class Event implements Serializable {
@Id //pk
@Column(name=”event_id”)
@GeneratedValue
private int id; // id
@Column(name=”event_name”, length = 200)
private String name;
@DateTimeFormat(pattern = “yyyy-MM-dd”)
@Column(name=”event_date”)
private LocalDate date;
@DateTimeFormat(pattern = “HH:mm”)
@Column(name = “event_time”)
private LocalTime time;
@Column(name=”location”, length = 100)
private String location;
@Transient
private String distanceFromUser;
@OneToMany(mappedBy = “event”)
private Set tickets;
@OneToMany(mappedBy = “event”, fetch = FetchType.EAGER)
private Set ticketClasses;
public Event() {
this.date = LocalDate.now();
this.time = LocalTime.now();
}
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public LocalDate getDate() {
return date;
}
public void setDate(LocalDate date) {
this.date = date;
}
public LocalTime getTime() {
return time;
}
public void setTime(LocalTime time) {
this.time = time;
}
public String getLocation() {
return location;
}
public void setLocation(String location) {
this.location = location;
}
public Set getTickets() {
return tickets;
}
public void setTickets(Set tickets) {
this.tickets = tickets;
}
public Set getTicketClasses() {
if (this.ticketClasses != null) {
return new TreeSet(this.ticketClasses);
}
return ticketClasses;
}
public void setTicketClasses(Set ticketClasses) {
this.ticketClasses = ticketClasses;
}
public boolean isExpired() {
LocalDateTime cd = LocalDateTime.of(this.date, this.time);
var expired = LocalDateTime.now().isAfter(cd);
return expired;
}
public String getDistanceFromUser() {
return distanceFromUser;
}
public void setDistanceFromUser(String distanceFromUser) {
this.distanceFromUser = distanceFromUser;
}
}
Ticket.java
package sa.edu.seu.ticketrs.domain;
import java.io.ByteArrayOutputStream;
import java.io.Serializable;
import jakarta.persistence.Column;
import jakarta.persistence.Entity;
import jakarta.persistence.FetchType;
import jakarta.persistence.GeneratedValue;
import jakarta.persistence.Id;
import jakarta.persistence.JoinColumn;
import jakarta.persistence.ManyToOne;
import jakarta.persistence.Table;
import jakarta.persistence.Transient;
import sa.edu.seu.ticketrs.models.SeatModel;
import java.math.BigDecimal;
import java.util.Base64;
import com.google.zxing.BarcodeFormat;
import com.google.zxing.client.j2se.MatrixToImageWriter;
import com.google.zxing.common.BitMatrix;
import com.google.zxing.qrcode.QRCodeWriter;
@Entity
@Table(name=”tickets”)
public class Ticket implements Serializable{
@Id
@GeneratedValue
@Column(name=”ticket_id”)
private int id;
@Column(name=”event_id”)
private int eventId;
@ManyToOne
@JoinColumn(name=”event_id”, insertable = false,updatable = false)
private Event event;
@Column(name=”user_id”)
private int userId;
@ManyToOne
@JoinColumn(name=”user_id”, insertable = false, updatable = false)
private User user;
@Column(name=”status”)
private TicketStatus status;
@Column(name=”price”)
private BigDecimal price = new BigDecimal(0);//default 0;
@Column(name=”class_id”)
private int ticketClassId;
@ManyToOne(fetch = FetchType.EAGER)
@JoinColumn(name=”class_id”, insertable = false,updatable = false)
private TicketClass ticketClass;
@Column(name=”seat”)
private Integer seat;
@Transient
private String qrCode;
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public int getEventId() {
return eventId;
}
public void setEventId(int eventId) {
this.eventId = eventId;
}
public Event getEvent() {
return event;
}
public void setEvent(Event event) {
this.event = event;
}
public int getUserId() {
return userId;
}
public void setUserId(int userId) {
this.userId = userId;
}
public User getUser() {
return user;
}
public void setUser(User user) {
this.user = user;
}
public TicketStatus getStatus() {
return status;
}
public void setStatus(TicketStatus status) {
this.status = status;
}
public BigDecimal getPrice() {
return price;
}
public void setPrice(BigDecimal price) {
this.price = price;
}
public int getTicketClassId() {
return ticketClassId;
}
public void setTicketClassId(int ticketClassId) {
this.ticketClassId = ticketClassId;
}
public TicketClass getTicketClass() {
return ticketClass;
}
public void setTicketClass(TicketClass ticketClass) {
this.ticketClass = ticketClass;
}
public Integer getSeat() {
return seat;
}
public void setSeat(Integer seat) {
this.seat = seat;
}
//text –> processing –> image.
public String toString() {
return “***Ticket***n#: ” + id
+ “nEvent: ” + event.getName()
+ “nUser: ” + user.getEmail()
+ “nPrice: ” + price
+ “nClass: ” + ticketClass.getName()
+ “nSeat: ” + seat;
}
public String getQrCode() {
try{
this.qrCode = generateQRCodeImage(this);
}catch(Exception e){
e.printStackTrace();
qrCode = “”;
}
return qrCode;
}
public void setQrCode(String qrCode) {
this.qrCode = qrCode;
}
private String generateQRCodeImage(Ticket ticket) throws Exception {
//QR //
QRCodeWriter barcodeWriter = new QRCodeWriter();
BitMatrix bitMatrix = barcodeWriter.encode(ticket.toString(),
BarcodeFormat.QR_CODE, 250, 250);
//000000010101010 –> pixel
//000000101010101
ByteArrayOutputStream baos = new ByteArrayOutputStream();
MatrixToImageWriter.writeToStream(bitMatrix, “jpg”, baos);
//return MatrixToImageWriter.toBufferedImage(bitMatrix);
String src = “data:image/jpg;base64, ” +
Base64.getEncoder().encodeToString(baos.toByteArray());
return src;
}
}
TicketClass.java
package sa.edu.seu.ticketrs.domain;
import java.io.Serializable;
import java.math.BigDecimal;
import jakarta.persistence.Column;
import jakarta.persistence.Entity;
import jakarta.persistence.FetchType;
import jakarta.persistence.GeneratedValue;
import jakarta.persistence.Id;
import jakarta.persistence.JoinColumn;
import jakarta.persistence.ManyToOne;
import jakarta.persistence.Table;
@Entity
@Table(name=”ticket_classes”)
public class TicketClass implements Serializable, Comparable {
@Id
@GeneratedValue
@Column(name=”class_id”)
private int id;
@Column(name=”class_name”, length = 100)
private String name;
@Column(name=”price”)
private BigDecimal price;//price
@Column(name = “number_of_tickets”)
private Integer numberOfTickets;
@Column(name=”event_id”)
private int eventId;
@ManyToOne(fetch = FetchType.EAGER)
@JoinColumn(name=”event_id”,insertable = false, updatable = false)
private Event event;
@Column(name=”sold_tickets”)
private Integer soldTickets;
@Column(name=”available_tickets”)
private Integer availableTickets;
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public BigDecimal getPrice() {
return price;
}
public void setPrice(BigDecimal price) {
this.price = price;
}
public Integer getNumberOfTickets() {
return numberOfTickets;
}
public void setNumberOfTickets(Integer numberOfTickets) {
this.numberOfTickets = numberOfTickets;
}
public int getEventId() {
return eventId;
}
public void setEventId(int eventId) {
this.eventId = eventId;
}
public Event getEvent() {
return event;
}
public void setEvent(Event event) {
this.event = event;
}
public Integer getSoldTickets() {
return soldTickets;
}
public void setSoldTickets(Integer soldTickets) {
this.soldTickets = soldTickets;
}
public Integer getAvailableTickets() {
return availableTickets;
}
public void setAvailableTickets(Integer availableTickets) {
this.availableTickets = availableTickets;
}
@Override
public boolean equals(Object obj) {
if(obj instanceof TicketClass){
TicketClass ticketClass = (TicketClass) obj;
return ticketClass.getId() == this.getId();
}
return false;
}
@Override
public int compareTo(TicketClass other) {
if(other == null)
return 1;
if (this.name == null)
return -1;
return this.name.compareTo(other.name);
}
}
TicketStatus.java
package sa.edu.seu.ticketrs.domain;
public enum TicketStatus {
Available,
Reserved,
Purchased
}
User.java
package sa.edu.seu.ticketrs.domain;
import java.io.Serializable;
import jakarta.persistence.Column;
import jakarta.persistence.Entity;
import jakarta.persistence.FetchType;
import jakarta.persistence.GeneratedValue;
import jakarta.persistence.Id;
import jakarta.persistence.JoinColumn;
import jakarta.persistence.ManyToOne;
import jakarta.persistence.Table;
@Entity
@Table(name=”users”)
public class User implements Serializable {
@Id
@GeneratedValue
@Column(name=”user_id”)
private int id;//0 –>
@Column(name=”first_name”,length = 50)
private String firstName;
@Column(name=”last_name”,length = 50)
private String lastName;
@Column(name=”user_email”, length = 50, unique = true)
private String email;
@Column(name=”user_pass”, length = 200)
private String password;
@Column(name=”pass_salt”, length = 500)
private String passwordSalt;
@Column(name=”user_role”)
private int userRoleId;
@ManyToOne(fetch = FetchType.EAGER)
@JoinColumn(name=”user_role”, insertable = false,updatable = false)
private UserRole userRole;
@Column(name=”location”, length = 100)
private String location;
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
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 getPasswordSalt() {
return passwordSalt;
}
public void setPasswordSalt(String passwordSalt) {
this.passwordSalt = passwordSalt;
}
public int getUserRoleId() {
return userRoleId;
}
public void setUserRoleId(int userRoleId) {
this.userRoleId = userRoleId;
}
public UserRole getUserRole() {
return userRole;
}
public void setUserRole(UserRole userRole) {
this.userRole = userRole;
}
public String getLocation() {
return location;
}
public void setLocation(String location) {
this.location = location;
}
}
UserRole..java
package sa.edu.seu.ticketrs.domain;
import java.io.Serializable;
import jakarta.persistence.Column;
import jakarta.persistence.Entity;
import jakarta.persistence.GeneratedValue;
import jakarta.persistence.Id;
import jakarta.persistence.Table;
@Entity
@Table(name=”user_roles”)
public class UserRole implements Serializable {
@Id
@GeneratedValue
@Column(name=”role_id”)
private int id;
@Column(name=”role_name”,unique = true)
private String name;
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
}
EventModel.java
package sa.edu.seu.ticketrs.models;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.LocalTime;
import sa.edu.seu.ticketrs.domain.Event;
public class EventModel {
private int id;
private String name;
private LocalDate date;
private LocalTime time;
private String location;
public EventModel(int id, String name, LocalDate date, LocalTime time, String
location) {
this.id = id;
this.name = name;
this.date = date;
this.time = time;
this.location = location;
}
public EventModel() {
}
public EventModel(Event event) {
this.id = event.getId();
this.name = event.getName();
this.date = event.getDate();
this.time = event.getTime();
this.location = event.getLocation();
}
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public LocalDate getDate() {
return date;
}
public void setDate(LocalDate date) {
this.date = date;
}
public LocalTime getTime() {
return time;
}
public void setTime(LocalTime time) {
this.time = time;
}
public String getLocation() {
return location;
}
public void setLocation(String location) {
this.location = location;
}
public boolean isExpired() {
LocalDateTime cd = LocalDateTime.of(this.date, this.time);
var expired = LocalDateTime.now().isAfter(cd);
return expired;
}
}
MyTicketModel.jav package sa.edu.seu.ticketrs.models;
a
import java.util.List;
import sa.edu.seu.ticketrs.domain.Ticket;
public class MyTicketModel {
private Integer eventId;
private String eventName;
private String date;
private String time;
private List tickets;
public MyTicketModel() {
}
public Integer getEventId() {
return eventId;
}
public void setEventId(Integer eventId) {
this.eventId = eventId;
}
public String getEventName() {
return eventName;
}
public void setEventName(String eventName) {
this.eventName = eventName;
}
public String getDate() {
return date;
}
public void setDate(String date) {
this.date = date;
}
public String getTime() {
return time;
}
public void setTime(String time) {
this.time = time;
}
public List getTickets() {
return tickets;
}
public void setTickets(List tickets) {
this.tickets = tickets;
}
}
SeatModel.java
package sa.edu.seu.ticketrs.models;
public class SeatModel {
private int classId;
private int eventId;
private int number;
private boolean available;
private int quantity;
public SeatModel() {
}
public SeatModel(int classId, int eventId, int number, boolean available) {
this.classId = classId;
this.eventId = eventId;
this.number = number;
this.available = available;
}
public int getClassId() {
return this.classId;
}
public void setClassId(int classId) {
this.classId = classId;
}
public int getEventId() {
return this.eventId;
}
public void setEventId(int eventId) {
this.eventId = eventId;
}
public int getNumber() {
return this.number;
}
public void setNumber(int seatNumber) {
this.number = seatNumber;
}
public boolean isAvailable() {
return this.available;
}
public void setAvailable(boolean available) {
this.available = available;
}
public int getQuantity() {
return this.quantity;
}
public void setQuantity(int quantity) {
this.quantity = quantity;
}
}
TicketClassModel.j package sa.edu.seu.ticketrs.models;
ava
import sa.edu.seu.ticketrs.domain.TicketClass;
public class TicketClassModel {
private int id;
private String name;
private double price;
private int eventId;
private String event;
private Integer capacity;
private Integer availableTickets;
private Integer soldTickets;
public TicketClassModel(int id, String name, double price, int eventId, String
event,
Integer capacity,
Integer availableTickets, Integer soldTickets) {
this.id = id;
this.name = name;
this.price = price;
this.eventId = eventId;
this.event = event;
this.capacity = capacity;
this.availableTickets = availableTickets;
this.soldTickets = soldTickets;
}
public TicketClassModel(TicketClass clx) {
this.id = clx.getId();
this.name = clx.getName();
this.price = clx.getPrice() != null ? clx.getPrice().doubleValue() : 0.0;
this.eventId = clx.getEvent().getId();
this.event = clx.getEvent().getName();
this.capacity = clx.getNumberOfTickets();
this.availableTickets = clx.getAvailableTickets();
this.soldTickets = clx.getSoldTickets();
}
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public double getPrice() {
return price;
}
public void setPrice(double price) {
this.price = price;
}
public int getEventId() {
return eventId;
}
public void setEventId(int eventId) {
this.eventId = eventId;
}
public String getEvent() {
return event;
}
public void setEvent(String event) {
this.event = event;
}
public Integer getCapacity() {
return capacity;
}
public void setCapacity(Integer capacity) {
this.capacity = capacity;
}
public Integer getAvailableTickets() {
return availableTickets;
}
public void setAvailableTickets(Integer availableTickets) {
this.availableTickets = availableTickets;
}
public Integer getSoldTickets() {
return soldTickets;
}
public void setSoldTickets(Integer soldTickets) {
this.soldTickets = soldTickets;
}
}
UserProfileModel.j package sa.edu.seu.ticketrs.models;
ava
public class UserProfileModel {
private String email;
private String oldPassword;
private String newPassword;
private String location;
public String getEmail() {
return email;
}
public void setEmail(String email) {
this.email = email;
}
public String getOldPassword() {
return oldPassword;
}
public void setOldPassword(String oldPassword) {
this.oldPassword = oldPassword;
}
public String getNewPassword() {
return newPassword;
}
public void setNewPassword(String newPassword) {
this.newPassword = newPassword;
}
public String getLocation() {
return location;
}
public void setLocation(String location) {
this.location = location;
}
}
EventRepository.ja package sa.edu.seu.ticketrs.repo;
va
import org.springframework.data.jpa.repository.JpaRepository;
import sa.edu.seu.ticketrs.domain.Event;
//
public interface EventRepository extends JpaRepository {
}
TicketClassReposit package sa.edu.seu.ticketrs.repo;
ory.java
import java.util.List;
import org.springframework.data.jpa.repository.JpaRepository;
import sa.edu.seu.ticketrs.domain.TicketClass;
public interface TicketClassRepository extends
JpaRepository {
List findAllByEventId(Integer eventId);
}
TicketRepository.ja package sa.edu.seu.ticketrs.repo;
va
import java.util.List;
import org.springframework.data.jpa.repository.JpaRepository;
import sa.edu.seu.ticketrs.domain.Ticket;
public interface TicketRepository extends JpaRepository {
public long countByEventIdAndTicketClassId(Integer eventId, Integer
ticketClassId);
List findAllByUserId(Integer userId);
List findAllByTicketClassId(Integer ticketClassId);
}
UserRepository.jav package sa.edu.seu.ticketrs.repo;
a
import java.util.Optional;
import org.springframework.data.jpa.repository.JpaRepository;
import sa.edu.seu.ticketrs.domain.User;
public interface UserRepository extends JpaRepository {
public Optional findOneByEmail(String email);
}
UserRoleRepositor package sa.edu.seu.ticketrs.repo;
y.java
import java.util.Optional;
import org.springframework.data.jpa.repository.JpaRepository;
import sa.edu.seu.ticketrs.domain.UserRole;
public interface UserRoleRepository extends
JpaRepository {
public Optional findOneByName(String role);
}
TicketRsSecurityCo package sa.edu.seu.ticketrs.security;
nfiguration.java
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import
org.springframework.security.config.annotation.web.builders.HttpSecurity;
import
org.springframework.security.config.annotation.web.configuration.EnableWe
bSecurity;
import org.springframework.security.web.SecurityFilterChain;
import sa.edu.seu.ticketrs.service.UserService;
@Configuration
@EnableWebSecurity
public class TicketRsSecurityConfiguration {
@Autowired
private UserService authProviderService;
@Bean
public SecurityFilterChain securityFilterChain(HttpSecurity http) throws
Exception {
http
.authorizeHttpRequests(rs ->
rs.requestMatchers(“/”, “/home”,”welcome”,
“/register”,”/css/**”,
“/js/**”, “/images/**”,”/chat/**”).permitAll()
.requestMatchers(“/events/**”).hasAuthority(
UserRoleNames.ADMIN)
.requestMatchers(“/ticketclasses/**”).hasAuthority(
UserRoleNames.ADMIN)
.anyRequest().authenticated()
)
.formLogin((form) -> form
.loginPage(“/login”)
.defaultSuccessUrl(“/”,true)
.permitAll());
http.logout(
x ->
x.permitAll().logoutUrl(“/logout”)
.invalidateHttpSession(true)
.deleteCookies(“JSESSIONID”)
.logoutSuccessUrl(“/”)
);
//csrf –> cross site request frogery ..
http.csrf(x -> x.disable());
http.authenticationProvider(this.authProviderService);//username, password
return http.build();
}
}
UserRoleNames.ja package sa.edu.seu.ticketrs.security;
va
public interface UserRoleNames {
public static final String ADMIN = “ADMIN”;
public static final String USER = “USER”;
}
DistanceCalculator package sa.edu.seu.ticketrs.service;
Service.java
import org.springframework.stereotype.Service;
@Service
public class DistanceCalculatorService {
public double calculateDistance(double lat1, double lon1, double lat2,
double lon2) {
double R = 6371e3; // metres
double φ1 = Math.toRadians(lat1);
double φ2 = Math.toRadians(lat2);
double Δφ = Math.toRadians(lat2 – lat1);
double Δλ = Math.toRadians(lon2 – lon1);
double a = Math.sin(Δφ / 2) * Math.sin(Δφ / 2)
+ Math.cos(φ1) * Math.cos(φ2)
* Math.sin(Δλ / 2) * Math.sin(Δλ / 2);
double c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1 – a));
return R * c;
}
public double calculateDistanceInKiloMeters(double lat1, double lon1,
double lat2, double lon2) {
return calculateDistance(lat1, lon1, lat2, lon2) / 1000;
}
public double[] getLngLat(String location) {
if(location == null)
{
return new double[]{0, 0};
}
var parts = location.split(“,”);
if(parts.length != 2) {
return new double[]{0, 0};
}
var lat = Double.parseDouble(parts[0]);
var lng = Double.parseDouble(parts[1]);
return new double[] { lat, lng };
}
}
EventService.java
package sa.edu.seu.ticketrs.service;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.List;
import java.util.Optional;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import sa.edu.seu.ticketrs.domain.Event;
import sa.edu.seu.ticketrs.repo.EventRepository;
import sa.edu.seu.ticketrs.web.SearchEventModel;
// –> database
// –> dal ( data access layer.) ( repository )
// –> service ( business logic)
// –> controller ( )
// –> view ()
@Service
public class EventService {
@Autowired
private EventRepository repo;
@Autowired
private UserService userService;
@Autowired
private DistanceCalculatorService distanceCalculatorService;
// list of events.
public List getAllEvents() {
var found = this.repo.findAll();
this.updateDistance(found);
return found;
}
public List getActiveEvents() {
var found = this.repo.findAll();
if (found == null) {
return new ArrayList();
}
var now = LocalDateTime.now();
var collected = found.stream().filter(x -> {
var cd = LocalDateTime.of(x.getDate(), x.getTime());
return now.isBefore(cd) || now.isEqual(cd);
}).toList();
this.updateDistance(collected);
return collected;
}
public Optional findById(Integer id) {
return this.repo.findById(id);
}
public Event save(Event entity) {
return this.repo.save(entity);
}
public void deleteById(Integer id) {
this.repo.deleteById(id);
}
// j
public List search(SearchEventModel searchEventModel) {
var found = this.repo.findAll();
if (found == null) {
return new ArrayList();
}
if (searchEventModel.getName() == null) {
searchEventModel.setName(“”); /// string.contains(e)
}
if (searchEventModel.isAllDates()) {
var search = found.stream()
.filter(x ->
x.getName().toLowerCase().contains(searchEventModel.getName().toLowerCa
se())).toList();
this.updateDistance(search);
return search;
}
var search = found.stream().filter(x -> {
var cd = LocalDateTime.of(x.getDate(), x.getTime());
return cd.toLocalDate().isEqual(searchEventModel.getDate())
&&
x.getName().toLowerCase().contains(searchEventModel.getName().toLowerCa
se());
}).toList();
this.updateDistance(search);
return search;
}
private void updateDistance(List events) {
var user = this.userService.getCurrentUser();
if (user == null || user.getLocation() == null || user.getLocation().isBlank()) {
return;
}
var userLocation = user.getLocation();
for (var event : events) {
var eventLocation = event.getLocation();
if (eventLocation == null || eventLocation.isBlank()) {
event.setDistanceFromUser(“N/A”);
continue;
}
double[] userLngLat =
this.distanceCalculatorService.getLngLat(userLocation);
double[] locLngLat =
this.distanceCalculatorService.getLngLat(eventLocation);
var distance = this.distanceCalculatorService.calculateDistanceInKiloMeters(
userLngLat[1], userLngLat[0], locLngLat[1], locLngLat[0]);
event.setDistanceFromUser(String.format(“%.2f KM”,distance));
}
}
}
TicketClassService.j package sa.edu.seu.ticketrs.service;
ava
import java.util.List;
import java.util.Optional;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import sa.edu.seu.ticketrs.domain.TicketClass;
import sa.edu.seu.ticketrs.repo.TicketClassRepository;
@Service
public class TicketClassService {
@Autowired
private TicketClassRepository repo;
public TicketClass save(TicketClass entity) {
if(entity.getId()
Purchase answer to see full
attachment