Compare commits
11 Commits
7b303df1ea
...
main
| Author | SHA1 | Date | |
|---|---|---|---|
| f5c0930494 | |||
| a06b3cadd1 | |||
| 93ab8196fa | |||
| ebf79fa15d | |||
| 3fbd77ca13 | |||
| 6f9349b13c | |||
| dea9c2eb27 | |||
| 9f24b94aaa | |||
| 4a786e506c | |||
| c696d61091 | |||
| 79473e4cfc |
@@ -1,6 +1,15 @@
|
|||||||
package nl.veenm.jobfindr.domain;
|
package nl.veenm.jobfindr.domain;
|
||||||
|
|
||||||
|
import jakarta.persistence.Entity;
|
||||||
|
import jakarta.persistence.GeneratedValue;
|
||||||
|
import jakarta.persistence.GenerationType;
|
||||||
|
import jakarta.persistence.Id;
|
||||||
|
|
||||||
|
@Entity
|
||||||
public class Event {
|
public class Event {
|
||||||
|
@Id
|
||||||
|
@GeneratedValue(strategy = GenerationType.AUTO)
|
||||||
|
private Long id;
|
||||||
private String timestamp;
|
private String timestamp;
|
||||||
private String className;
|
private String className;
|
||||||
private String methodName;
|
private String methodName;
|
||||||
@@ -25,6 +34,10 @@ public class Event {
|
|||||||
this.error = error;
|
this.error = error;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Event() {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
public String getTimestamp() {
|
public String getTimestamp() {
|
||||||
return timestamp;
|
return timestamp;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,12 @@
|
|||||||
|
package nl.veenm.jobfindr.repository;
|
||||||
|
|
||||||
|
import io.quarkus.hibernate.orm.panache.PanacheRepository;
|
||||||
|
import jakarta.enterprise.context.ApplicationScoped;
|
||||||
|
import nl.veenm.jobfindr.domain.Event;
|
||||||
|
import nl.veenm.jobfindr.domain.VacatureDetail;
|
||||||
|
|
||||||
|
@ApplicationScoped
|
||||||
|
public class EventRepository implements PanacheRepository<Event> {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
@@ -4,10 +4,6 @@ import io.quarkus.hibernate.orm.panache.PanacheRepository;
|
|||||||
import jakarta.enterprise.context.ApplicationScoped;
|
import jakarta.enterprise.context.ApplicationScoped;
|
||||||
import nl.veenm.jobfindr.domain.VacatureDetail;
|
import nl.veenm.jobfindr.domain.VacatureDetail;
|
||||||
|
|
||||||
import java.time.LocalDate;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
|
|
||||||
@ApplicationScoped
|
@ApplicationScoped
|
||||||
public class VacatureDetailRepository implements PanacheRepository<VacatureDetail> {
|
public class VacatureDetailRepository implements PanacheRepository<VacatureDetail> {
|
||||||
|
|
||||||
|
|||||||
@@ -17,7 +17,6 @@ import java.time.format.DateTimeFormatter;
|
|||||||
import java.time.format.DateTimeParseException;
|
import java.time.format.DateTimeParseException;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.stream.Collectors;
|
|
||||||
|
|
||||||
@ApplicationScoped
|
@ApplicationScoped
|
||||||
public class VacatureService {
|
public class VacatureService {
|
||||||
@@ -38,7 +37,7 @@ public class VacatureService {
|
|||||||
|
|
||||||
private static final Logger logger = Logger.getLogger(VacatureService.class);
|
private static final Logger logger = Logger.getLogger(VacatureService.class);
|
||||||
|
|
||||||
private final String className = this.getClass().getName();
|
private final String className = this.getClass().getSimpleName();
|
||||||
|
|
||||||
public List<Vacature> getServices() throws IOException {
|
public List<Vacature> getServices() throws IOException {
|
||||||
eventService.logInfo(VacatureService.class.getName(), "getServices", "getServices aangeroepen");
|
eventService.logInfo(VacatureService.class.getName(), "getServices", "getServices aangeroepen");
|
||||||
@@ -53,7 +52,6 @@ public class VacatureService {
|
|||||||
logger.info("Checking for new vacatures");
|
logger.info("Checking for new vacatures");
|
||||||
eventService.logInfo(className, "checkAndSendNewVacatures", "Checking for new vacatures");
|
eventService.logInfo(className, "checkAndSendNewVacatures", "Checking for new vacatures");
|
||||||
LocalDate today = LocalDate.now();
|
LocalDate today = LocalDate.now();
|
||||||
LocalDate yesterday = today.minusDays(1);
|
|
||||||
|
|
||||||
// Scrape de nieuwste vacatures
|
// Scrape de nieuwste vacatures
|
||||||
String url = "https://www.meesterbaan.nl/vacatures/50-km?trefwoord=duits&locatie=Apeldoorn";
|
String url = "https://www.meesterbaan.nl/vacatures/50-km?trefwoord=duits&locatie=Apeldoorn";
|
||||||
@@ -71,26 +69,28 @@ public class VacatureService {
|
|||||||
});
|
});
|
||||||
|
|
||||||
// Haal de vacatures van gisteren op
|
// Haal de vacatures van gisteren op
|
||||||
List<Vacature> yesterdayVacatures = vacatureRepository.findByDate(yesterday);
|
List<Vacature> yesterdayVacatures = vacatureRepository.findAll().stream().toList();
|
||||||
|
|
||||||
// Filter nieuwe vacatures
|
System.out.println(todayVacatures.size());
|
||||||
List<Vacature> newVacatures = todayVacatures.stream()
|
System.out.println(yesterdayVacatures.size());
|
||||||
.filter(vacature -> yesterdayVacatures.stream()
|
|
||||||
.noneMatch(yv -> yv.getTitel().equals(vacature.getTitel()) && yv.getUrl().equals(vacature.getUrl())))
|
|
||||||
.collect(Collectors.toList());
|
todayVacatures.removeIf(a -> yesterdayVacatures.stream().anyMatch(b -> b.getUrl().equals(a.getUrl())));
|
||||||
|
|
||||||
|
System.out.println(todayVacatures.size());
|
||||||
|
|
||||||
// Alleen nieuwe vacatures opslaan en versturen
|
// Alleen nieuwe vacatures opslaan en versturen
|
||||||
if (!newVacatures.isEmpty()) {
|
if (!todayVacatures.isEmpty()) {
|
||||||
// Sla de nieuwe vacatures op
|
// Sla de nieuwe vacatures op
|
||||||
newVacatures.forEach(vacature -> {
|
todayVacatures.forEach(vacature -> {
|
||||||
vacature.setDatum(today);
|
vacature.setDatum(today);
|
||||||
vacatureDetailRepository.persist(vacature.getDetail());
|
vacatureDetailRepository.persist(vacature.getDetail());
|
||||||
vacatureRepository.persist(vacature);
|
vacatureRepository.persist(vacature);
|
||||||
});
|
});
|
||||||
|
|
||||||
// Verstuur een e-mail
|
// Verstuur een e-mail
|
||||||
emailService.stuurVacatureEmail("danthefranken@gmail.com", newVacatures);
|
emailService.stuurVacatureEmail("danthefranken@gmail.com", todayVacatures);
|
||||||
emailService.stuurVacatureEmail("vanveenmel11@gmail.com", newVacatures);
|
emailService.stuurVacatureEmail("vanveenmel11@gmail.com", todayVacatures);
|
||||||
logger.info("Nieuwe vacatures verstuurd en opgeslagen.");
|
logger.info("Nieuwe vacatures verstuurd en opgeslagen.");
|
||||||
eventService.logSucces(className, "checkAndSendNewVacatures", "Nieuwe vacatures verstuurd en opgeslagen.");
|
eventService.logSucces(className, "checkAndSendNewVacatures", "Nieuwe vacatures verstuurd en opgeslagen.");
|
||||||
} else {
|
} else {
|
||||||
@@ -107,6 +107,7 @@ public class VacatureService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public List<Vacature> getAllVacatures() {
|
public List<Vacature> getAllVacatures() {
|
||||||
|
eventService.logInfo(className, "getAllVacatures", "fetching all vacatures");
|
||||||
return vacatureRepository.listAll();
|
return vacatureRepository.listAll();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,8 +1,11 @@
|
|||||||
package nl.veenm.jobfindr.util;
|
package nl.veenm.jobfindr.util;
|
||||||
|
|
||||||
|
import io.quarkus.scheduler.Scheduled;
|
||||||
import jakarta.enterprise.context.ApplicationScoped;
|
import jakarta.enterprise.context.ApplicationScoped;
|
||||||
import jakarta.inject.Inject;
|
import jakarta.inject.Inject;
|
||||||
|
import jakarta.transaction.Transactional;
|
||||||
import nl.veenm.jobfindr.domain.Event;
|
import nl.veenm.jobfindr.domain.Event;
|
||||||
|
import nl.veenm.jobfindr.repository.EventRepository;
|
||||||
|
|
||||||
import java.time.Instant;
|
import java.time.Instant;
|
||||||
|
|
||||||
@@ -10,8 +13,9 @@ import java.time.Instant;
|
|||||||
public class EventService {
|
public class EventService {
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
EventWebSocket eventWebSocket;
|
EventRepository eventRepository;
|
||||||
|
|
||||||
|
@Transactional
|
||||||
public void logInfo(String className, String methodName, String message) {
|
public void logInfo(String className, String methodName, String message) {
|
||||||
// Maak een nieuw event
|
// Maak een nieuw event
|
||||||
Event event = new Event(
|
Event event = new Event(
|
||||||
@@ -23,10 +27,10 @@ public class EventService {
|
|||||||
// Bericht
|
// Bericht
|
||||||
);
|
);
|
||||||
|
|
||||||
// Verstuur het event via WebSocket
|
saveEvent(event);
|
||||||
eventWebSocket.sendEvent(event);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Transactional
|
||||||
public void logSucces(String className, String methodName, String message) {
|
public void logSucces(String className, String methodName, String message) {
|
||||||
// Maak een nieuw event
|
// Maak een nieuw event
|
||||||
Event event = new Event(
|
Event event = new Event(
|
||||||
@@ -38,9 +42,10 @@ public class EventService {
|
|||||||
// Bericht
|
// Bericht
|
||||||
);
|
);
|
||||||
|
|
||||||
// Verstuur het event via WebSocket
|
saveEvent(event);
|
||||||
eventWebSocket.sendEvent(event);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Transactional
|
||||||
public void logError(String className, String methodName, String message, Exception e) {
|
public void logError(String className, String methodName, String message, Exception e) {
|
||||||
// Maak een nieuw event
|
// Maak een nieuw event
|
||||||
Event event = new Event(
|
Event event = new Event(
|
||||||
@@ -53,7 +58,18 @@ public class EventService {
|
|||||||
// Bericht
|
// Bericht
|
||||||
);
|
);
|
||||||
|
|
||||||
// Verstuur het event via WebSocket
|
saveEvent(event);
|
||||||
eventWebSocket.sendEvent(event);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void saveEvent(Event event) {
|
||||||
|
eventRepository.persist(event);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Scheduled(cron = "0 00 00 ? * 1#1")
|
||||||
|
@Transactional
|
||||||
|
public void cleanEvents() {
|
||||||
|
eventRepository.deleteAll();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,48 +0,0 @@
|
|||||||
package nl.veenm.jobfindr.util;
|
|
||||||
|
|
||||||
import jakarta.websocket.OnOpen;
|
|
||||||
import jakarta.websocket.Session;
|
|
||||||
import jakarta.websocket.server.ServerEndpoint;
|
|
||||||
import nl.veenm.jobfindr.domain.Event;
|
|
||||||
import org.jboss.logging.Logger;
|
|
||||||
|
|
||||||
import jakarta.enterprise.context.ApplicationScoped;
|
|
||||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.util.Set;
|
|
||||||
import java.util.concurrent.ConcurrentHashMap;
|
|
||||||
|
|
||||||
@ServerEndpoint("/events")
|
|
||||||
@ApplicationScoped
|
|
||||||
public class EventWebSocket {
|
|
||||||
|
|
||||||
private static final Logger logger = Logger.getLogger(EventWebSocket.class);
|
|
||||||
private final Set<Session> sessions = ConcurrentHashMap.newKeySet();
|
|
||||||
private final ObjectMapper objectMapper = new ObjectMapper(); // Om objecten naar JSON te serialiseren
|
|
||||||
|
|
||||||
@OnOpen
|
|
||||||
public void onOpen(Session session) {
|
|
||||||
logger.info("event websocket opened: " + session.getId());
|
|
||||||
sessions.add(session);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void sendEvent(Event event) {
|
|
||||||
String jsonEvent;
|
|
||||||
try {
|
|
||||||
jsonEvent = objectMapper.writeValueAsString(event); // Event naar JSON converteren
|
|
||||||
} catch (IOException e) {
|
|
||||||
logger.error(e);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
for (Session session : sessions) {
|
|
||||||
if (session.isOpen()) {
|
|
||||||
try {
|
|
||||||
session.getBasicRemote().sendText(jsonEvent);
|
|
||||||
} catch (IOException e) {
|
|
||||||
logger.error(e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -12,8 +12,10 @@ quarkus.datasource.jdbc.url=jdbc:postgresql://${DB_HOST}:${DB_PORT}/vacaturesdb
|
|||||||
quarkus.datasource.username=${DB_USERNAME}
|
quarkus.datasource.username=${DB_USERNAME}
|
||||||
quarkus.datasource.password=${DB_PASSWORD}
|
quarkus.datasource.password=${DB_PASSWORD}
|
||||||
quarkus.hibernate-orm.database.generation=update
|
quarkus.hibernate-orm.database.generation=update
|
||||||
quarkus.hibernate-orm.log.sql=true
|
|
||||||
quarkus.hibernate-orm.sql-load-script=no-file
|
quarkus.hibernate-orm.sql-load-script=no-file
|
||||||
|
quarkus.hibernate-orm.log.highlight-sql=false
|
||||||
|
quarkus.hibernate-orm.log.sql=false
|
||||||
|
|
||||||
|
|
||||||
# CORS configuratie
|
# CORS configuratie
|
||||||
quarkus.http.cors=true
|
quarkus.http.cors=true
|
||||||
|
|||||||
Reference in New Issue
Block a user