Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -143,12 +143,12 @@
<artifactId>testcontainers-postgresql</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.awspring.cloud</groupId>
<artifactId>spring-cloud-aws-starter-s3</artifactId>
<version>4.0.0</version>
<scope>compile</scope>
</dependency>
<!-- <dependency>-->
<!-- <groupId>io.awspring.cloud</groupId>-->
<!-- <artifactId>spring-cloud-aws-starter-s3</artifactId>-->
<!-- <version>4.0.0</version>-->
<!-- <scope>compile</scope>-->
<!-- </dependency>-->
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package org.example.visacasemanagementsystem.log;
package org.example.visacasemanagementsystem.audit;

public enum LogEvent {
public enum AuditEventType {
CREATED,
ASSIGNED,
UPDATED,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package org.example.visacasemanagementsystem.audit.dto;

import org.example.visacasemanagementsystem.audit.AuditEventType;

import java.time.LocalDateTime;

public record AuditDTO(
Long id,
LocalDateTime timeStamp,
Long userId,
Long visaCaseId,
AuditEventType auditEventType,
String description) {
}
Original file line number Diff line number Diff line change
@@ -1,27 +1,31 @@
package org.example.visacasemanagementsystem.log.entity;
package org.example.visacasemanagementsystem.audit.entity;

import jakarta.persistence.*;
import jakarta.validation.constraints.NotNull;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import lombok.ToString;
import org.example.visacasemanagementsystem.log.LogEvent;
import org.example.visacasemanagementsystem.audit.AuditEventType;
import org.springframework.data.annotation.CreatedDate;
import org.springframework.data.jpa.domain.support.AuditingEntityListener;

import java.time.LocalDateTime;
import java.util.Objects;

@Entity
@Getter
@Setter
@NoArgsConstructor
public class Log {
@EntityListeners(AuditingEntityListener.class)
public class AuditLog {

@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(nullable = false)
@Column(name = "audit_id", nullable = false)
private Long id;

@NotNull
@CreatedDate
private LocalDateTime timeStamp;

@NotNull
Expand All @@ -32,14 +36,14 @@ public class Log {

@NotNull
@Enumerated(EnumType.STRING)
private LogEvent logEvent;
private AuditEventType auditEventType;

private String description; // Beskrivning av händelse

@Override
public boolean equals(Object o) {
if (!(o instanceof Log log)) return false;
return Objects.equals(id, log.id);
if (!(o instanceof AuditLog auditLog)) return false;
return Objects.equals(id, auditLog.id);
}

@Override
Expand All @@ -49,12 +53,12 @@ public int hashCode() {

@Override
public String toString() {
return "Log{" +
return "AuditLog{" +
"id=" + id +
", timeStamp=" + timeStamp +
", userId=" + userId +
", visaCaseId=" + visaCaseId +
", logEvent=" + logEvent +
", auditEventType=" + auditEventType +
", description='" + description + '\'' +
'}';
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package org.example.visacasemanagementsystem.audit.mapper;

import org.example.visacasemanagementsystem.audit.AuditEventType;
import org.example.visacasemanagementsystem.audit.dto.AuditDTO;
import org.example.visacasemanagementsystem.audit.entity.AuditLog;
import org.springframework.stereotype.Component;

import java.time.LocalDateTime;

@Component
public class AuditMapper {

// För visning (Entity --> DTO)
public AuditDTO toDTO(AuditLog auditLog){
if (auditLog == null) return null;

return new AuditDTO(
auditLog.getId(),
auditLog.getTimeStamp(),
auditLog.getUserId(),
auditLog.getVisaCaseId(),
auditLog.getAuditEventType(),
auditLog.getDescription()
);
}


// Service-klassen sköter skapandet av denna log
public AuditLog toEntity(Long userId, Long visaCaseId, AuditEventType auditEventType, String description){
AuditLog auditLog = new AuditLog();
auditLog.setUserId(userId);
auditLog.setVisaCaseId(visaCaseId);
auditLog.setAuditEventType(auditEventType);
auditLog.setDescription(description);
return auditLog;

}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package org.example.visacasemanagementsystem.audit.repository;

import org.example.visacasemanagementsystem.audit.entity.AuditLog;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository;

@Repository
public interface AuditRepository extends JpaRepository<AuditLog, Long> {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package org.example.visacasemanagementsystem.audit.service;

import org.example.visacasemanagementsystem.audit.AuditEventType;
import org.example.visacasemanagementsystem.audit.entity.AuditLog;
import org.example.visacasemanagementsystem.audit.mapper.AuditMapper;
import org.example.visacasemanagementsystem.audit.repository.AuditRepository;
import org.springframework.stereotype.Service;

@Service
public class AuditService {

private final AuditRepository auditRepository;
private final AuditMapper auditMapper;

public AuditService(AuditRepository auditRepository, AuditMapper auditMapper) {
this.auditRepository = auditRepository;
this.auditMapper = auditMapper;
}

public void createAuditLog(Long userId, Long visaCaseId, AuditEventType auditEventType, String description) {
AuditLog auditLog = auditMapper.toEntity(userId, visaCaseId, auditEventType, description);
auditRepository.save(auditLog);
}

}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package org.example.visacasemanagementsystem.visa.dto;
package org.example.visacasemanagementsystem.comment.dto;

import java.time.LocalDateTime;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package org.example.visacasemanagementsystem.visa.dto;
package org.example.visacasemanagementsystem.comment.dto;

import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.NotNull;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
package org.example.visacasemanagementsystem.visa.entity;
package org.example.visacasemanagementsystem.comment.entity;

import jakarta.persistence.*;
import jakarta.validation.constraints.NotBlank;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import org.example.visacasemanagementsystem.user.entity.User;
import org.example.visacasemanagementsystem.visa.entity.Visa;
import org.springframework.data.annotation.CreatedDate;
import org.springframework.data.jpa.domain.support.AuditingEntityListener;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package org.example.visacasemanagementsystem.visa.mapper;
package org.example.visacasemanagementsystem.comment.mapper;

import org.example.visacasemanagementsystem.visa.dto.CommentDTO;
import org.example.visacasemanagementsystem.visa.dto.CreateCommentDTO;
import org.example.visacasemanagementsystem.visa.entity.Comment;
import org.example.visacasemanagementsystem.comment.dto.CommentDTO;
import org.example.visacasemanagementsystem.comment.dto.CreateCommentDTO;
import org.example.visacasemanagementsystem.comment.entity.Comment;
import org.springframework.stereotype.Component;

@Component
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package org.example.visacasemanagementsystem.exception;

import jakarta.persistence.EntityNotFoundException;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.ResponseStatus;

@ControllerAdvice
public class GlobalExceptionHandler {

@ResponseStatus(value = HttpStatus.FORBIDDEN)
@ExceptionHandler(UnauthorizedException.class)
@ResponseBody
public String handleUnauthorizedException(UnauthorizedException exception) {
return "Access Denied: " + exception.getMessage();
}

@ResponseStatus(value = HttpStatus.NOT_FOUND)
@ExceptionHandler(EntityNotFoundException.class)
@ResponseBody
public String handleNotFoundException(EntityNotFoundException exception) {
return exception.getMessage();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package org.example.visacasemanagementsystem.exception;

public class UnauthorizedException extends RuntimeException {
public UnauthorizedException(String message) {
super(message);
}
}

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import org.example.visacasemanagementsystem.user.UserAuthorization;

public record CreateUserDTO(
@NotBlank(message = "User name must be specified") String username,
@NotBlank(message = "Full name must be specified") String fullName,
@NotBlank(message = "Email must be specified") String email,
@NotBlank String password,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@

public record UpdateUserDTO(
@NotNull Long id,
@NotBlank(message = "User name must be specified") String username,
@NotBlank(message = "Full name must be specified") String fullName,
@NotBlank(message = "Email must be specified") String email,
@NotNull(message = "Authorization level must be selected") UserAuthorization userAuthorization) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

public record UserDTO(
Long id,
String username,
String fullName,
String email,
UserAuthorization userAuthorization) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,14 @@
@Getter
@Setter
@NoArgsConstructor
@Table(name = "users")
public class User {

@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(nullable = false, updatable = false)
private Long id;

@NotBlank
@Column(nullable = false, unique = true)
private String username;

@NotBlank
@Column(nullable = false)
private String fullName;
Expand Down Expand Up @@ -56,7 +53,6 @@ public int hashCode() {
public String toString() {
return "User{" +
"id=" + id +
", username='" + username + '\'' +
", fullName='" + fullName + '\'' +
", role=" + userAuthorization +
'}';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ public UserDTO toDTO(User user){

return new UserDTO(
user.getId(),
user.getUsername(),
user.getFullName(),
user.getEmail(),
user.getUserAuthorization()
Expand All @@ -27,7 +26,6 @@ public User toEntity(CreateUserDTO dto){
if (dto == null) return null;

User user = new User();
user.setUsername(dto.username());
user.setFullName(dto.fullName());
user.setEmail(dto.email());
user.setUserAuthorization(dto.userAuthorization());
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package org.example.visacasemanagementsystem.user.repository;

import org.example.visacasemanagementsystem.user.entity.User;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository;

import java.util.Optional;

@Repository
public interface UserRepository extends JpaRepository<User, Long> {

Optional<User> findByEmail(String email);

}
Loading