Skip to content

Commit

Permalink
Merge branch 'master' into dependabot/gradle/io.quarkus-quarkus-react…
Browse files Browse the repository at this point in the history
…ive-pg-client-3.19.0
  • Loading branch information
IliyanKostov9 authored Feb 25, 2025
2 parents 663deaf + bdebfda commit f53404b
Show file tree
Hide file tree
Showing 62 changed files with 204 additions and 407 deletions.
8 changes: 4 additions & 4 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ plugins {
id 'java'
id 'io.quarkus'
id "org.sonarqube" version "6.0.1.5171"
id "io.freefair.lombok" version "8.12.1"
id "io.freefair.lombok" version "8.12.2"
}

repositories {
Expand All @@ -19,7 +19,7 @@ dependencies {

// AWS
implementation 'io.quarkiverse.amazonservices:quarkus-amazon-s3:3.2.0'
implementation 'software.amazon.awssdk:aws-crt-client:2.30.21'
implementation 'software.amazon.awssdk:aws-crt-client:2.30.26'

// Elastisearch
implementation("io.quarkus:quarkus-elasticsearch-java-client")
Expand All @@ -34,7 +34,7 @@ dependencies {

implementation 'io.quarkus:quarkus-hibernate-validator'
implementation 'org.mapstruct:mapstruct:1.6.3'
implementation 'io.quarkus:quarkus-mailer:3.18.3'
implementation 'io.quarkus:quarkus-mailer:3.19.0'
implementation 'io.quarkus:quarkus-security-jpa'
implementation 'io.quarkus:quarkus-smallrye-openapi'
implementation 'org.jboss.logmanager:log4j2-jboss-logmanager'
Expand All @@ -56,7 +56,7 @@ dependencies {
testImplementation 'io.quarkus:quarkus-junit5'
testImplementation 'io.rest-assured:rest-assured'
testImplementation 'org.mockito:mockito-core:5.14.2'
testImplementation 'io.quarkus:quarkus-junit5-mockito:3.18.3'
testImplementation 'io.quarkus:quarkus-junit5-mockito:3.19.0'
}

group 'com.tuvarna'
Expand Down
21 changes: 17 additions & 4 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,25 @@
};

# NOTE: use devenv up to run the service
services.elasticsearch = {
enable = true;
cluster_name = "elasicsearch";
port = 9200;
services = {
postgres = {
enable = false;
initialDatabases.phd.name = {
name = "phd";
user = "phd";
pass = "phd";
listen_addresses = "127.0.0.1";
port = 5432;
};
};
elasticsearch = {
enable = true;
cluster_name = "elasicsearch";
port = 9200;
};
};


git-hooks.hooks = {
# Common
markdownlint.enable = true;
Expand Down
22 changes: 15 additions & 7 deletions src/main/java/com/tuvarna/phd/controller/AuthController.java
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package com.tuvarna.phd.controller;

import com.tuvarna.phd.entity.UserEntity;
import com.tuvarna.phd.service.AuthService;
import com.tuvarna.phd.dto.UnauthorizedUsersDTO;
import com.tuvarna.phd.entity.IUserEntity;
import com.tuvarna.phd.service.AuthService;
import io.smallrye.mutiny.tuples.Tuple2;
import jakarta.enterprise.context.RequestScoped;
import jakarta.inject.Inject;
Expand All @@ -12,6 +12,7 @@
import jakarta.ws.rs.Produces;
import jakarta.ws.rs.core.MediaType;
import jakarta.ws.rs.core.Response;
import org.eclipse.microprofile.jwt.JsonWebToken;
import org.eclipse.microprofile.openapi.annotations.Operation;
import org.eclipse.microprofile.openapi.annotations.enums.SecuritySchemeType;
import org.eclipse.microprofile.openapi.annotations.media.Content;
Expand All @@ -34,13 +35,13 @@
public final class AuthController extends BaseController {

private AuthService authService;
@Inject JsonWebToken jwt;
@Inject Logger LOG = Logger.getLogger(AuthController.class);

public AuthController(AuthService authService) {
this.authService = authService;
}


@POST
@Operation(
summary = "Verify the user is present in the database",
Expand All @@ -63,10 +64,17 @@ public AuthController(AuthService authService) {
schema = @Schema(implementation = UnauthorizedUsersDTO.class))),
})
@Path("/login")
public Response login(UnauthorizedUsersDTO userDTO) {
LOG.info("Received a request to login with user creds: " + userDTO);
public Response login() {
String oid = jwt.getClaim("oid");
String name = jwt.getClaim("name");
String email = jwt.getName();

LOG.info("Received a request to login with user oid: " + oid + " and email: " + email);

Tuple2<IUserEntity<?>, String> loggedUser = this.authService.login(oid, name, email);
IUserEntity<?> user = loggedUser.getItem1();
String group = loggedUser.getItem2();

Tuple2<UserEntity<?>, String> user = this.authService.login(userDTO);
return send("User logged in!", user.getItem1(), user.getItem2());
return send("User logged in!", user, group);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import com.tuvarna.phd.dto.CandidateStatusDTO;
import com.tuvarna.phd.dto.UnauthorizedUsersDTO;
import com.tuvarna.phd.entity.UnauthorizedUsers;
import com.tuvarna.phd.exception.CandidateException;
import com.tuvarna.phd.exception.HttpException;
import com.tuvarna.phd.service.DoctoralCenterService;
import com.tuvarna.phd.validator.CandidateValidator;
import jakarta.enterprise.context.RequestScoped;
Expand Down Expand Up @@ -86,7 +86,7 @@ public Response updateCandidateStatus(CandidateStatusDTO candidateDTO) {
this.doctoralCenterService.review(candidateDTO);
} catch (IOException exception) {
LOG.error("Error in reading mail template: " + exception);
throw new CandidateException("Error in sending email. Please try again later!");
throw new HttpException("Error in sending email. Please try again later!");
}

return send("Candidate status changed to: " + candidateDTO.getStatus());
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/com/tuvarna/phd/controller/PhdController.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.tuvarna.phd.controller;

import com.tuvarna.phd.dto.PhdDTO;
import com.tuvarna.phd.exception.PhdException;
import com.tuvarna.phd.exception.HttpException;
import com.tuvarna.phd.service.PhdService;
import jakarta.enterprise.context.RequestScoped;
import jakarta.inject.Inject;
Expand Down Expand Up @@ -63,7 +63,7 @@ public PhdController(PhdService phdService) {
schema = @Schema(implementation = PhdDTO.class))),
})
@Path("/login")
public Response login(PhdDTO pDto) throws PhdException {
public Response login(PhdDTO pDto) throws HttpException {
// LOG.info("Received a request to login from using Phd user creds: " + pDto);
// this.phdService.login(pDto);

Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/tuvarna/phd/entity/Candidate.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
@NoArgsConstructor
@AllArgsConstructor
@Table(name = "candidate")
public non-sealed class Candidate extends PanacheEntityBase implements UserEntity<Candidate> {
public non-sealed class Candidate extends PanacheEntityBase implements IUserEntity<Candidate> {

@Id
@SequenceGenerator(
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/tuvarna/phd/entity/Committee.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
@NoArgsConstructor
@AllArgsConstructor
@Table(name = "committee")
public non-sealed class Committee extends PanacheEntityBase implements UserEntity<Committee> {
public non-sealed class Committee extends PanacheEntityBase implements IUserEntity<Committee> {

@Id
@SequenceGenerator(
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/tuvarna/phd/entity/DoctoralCenter.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
// @UserDefinition
@Table(name = "doctoralcenter")
public non-sealed class DoctoralCenter extends PanacheEntityBase
implements UserEntity<DoctoralCenter> {
implements IUserEntity<DoctoralCenter> {

@Id
@SequenceGenerator(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import io.vertx.mutiny.sqlclient.Row;

public sealed interface UserEntity<T extends UserEntity<T>>
public sealed interface IUserEntity<T extends IUserEntity<T>>
permits Phd, Committee, DoctoralCenter, UnauthorizedUsers, Candidate, Supervisor {

T toEntity(Row row);
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/tuvarna/phd/entity/Phd.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
@NoArgsConstructor
@AllArgsConstructor
@Table(name = "phd")
public non-sealed class Phd extends PanacheEntityBase implements UserEntity<Phd> {
public non-sealed class Phd extends PanacheEntityBase implements IUserEntity<Phd> {

@Id
@SequenceGenerator(name = "phdSequence", sequenceName = "phd_id_seq", allocationSize = 1)
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/tuvarna/phd/entity/Supervisor.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
@NoArgsConstructor
@AllArgsConstructor
@Table(name = "supervisor")
public non-sealed class Supervisor extends PanacheEntityBase implements UserEntity<Supervisor> {
public non-sealed class Supervisor extends PanacheEntityBase implements IUserEntity<Supervisor> {

@Id
@SequenceGenerator(
Expand Down
9 changes: 8 additions & 1 deletion src/main/java/com/tuvarna/phd/entity/UnauthorizedUsers.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
@AllArgsConstructor
@Table(name = "unauthorizedusers")
public non-sealed class UnauthorizedUsers extends PanacheEntityBase
implements UserEntity<UnauthorizedUsers> {
implements IUserEntity<UnauthorizedUsers> {

@Id
@SequenceGenerator(
Expand All @@ -49,6 +49,13 @@ public non-sealed class UnauthorizedUsers extends PanacheEntityBase
@Column(nullable = false, unique = false)
private Boolean isAllowed = false;

public UnauthorizedUsers(String oid, String name, String email, Timestamp timestamp) {
this.oid = oid;
this.name = name;
this.email = email;
this.timestamp = timestamp;
}

@Override
public UnauthorizedUsers toEntity(Row row) {
return new UnauthorizedUsers();
Expand Down
12 changes: 0 additions & 12 deletions src/main/java/com/tuvarna/phd/exception/BlobException.java

This file was deleted.

12 changes: 0 additions & 12 deletions src/main/java/com/tuvarna/phd/exception/CandidateException.java

This file was deleted.

12 changes: 0 additions & 12 deletions src/main/java/com/tuvarna/phd/exception/CommitteeException.java

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
package com.tuvarna.phd.exception.handler;
package com.tuvarna.phd.exception;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.tuvarna.phd.controller.ControllerResponse;
import com.tuvarna.phd.exception.HttpException;
import io.quarkus.security.ForbiddenException;
import io.quarkus.security.UnauthorizedException;
import jakarta.annotation.Priority;
Expand All @@ -23,11 +22,7 @@ public class ControllerExceptionMapper implements ExceptionMapper<Exception> {
@Override
public Response toResponse(Exception exception) {
Response response = mapExceptionToResponse(exception);
log.error(
"Error with exception: "
+ exception.getClass()
+ " with message: "
+ exception.getMessage());
log.error("Exception: " + exception.getClass() + " with message: " + exception.getMessage());

return Response.fromResponse(response).type(MediaType.APPLICATION_JSON).build();
}
Expand Down
12 changes: 0 additions & 12 deletions src/main/java/com/tuvarna/phd/exception/CurriculumException.java

This file was deleted.

This file was deleted.

This file was deleted.

12 changes: 0 additions & 12 deletions src/main/java/com/tuvarna/phd/exception/FacultyException.java

This file was deleted.

12 changes: 0 additions & 12 deletions src/main/java/com/tuvarna/phd/exception/GradeException.java

This file was deleted.

26 changes: 7 additions & 19 deletions src/main/java/com/tuvarna/phd/exception/HttpException.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,28 +3,16 @@
import lombok.Getter;

@Getter
public abstract sealed class HttpException extends RuntimeException
permits BlobException,
SupervisorException,
SubjectException,
FacultyException,
ReportException,
GradeException,
CurriculumException,
CandidateException,
CommitteeException,
DoctoralCenterException,
DoctoralCenterRoleException,
IPBlockException,
LogException,
NotificationException,
PhdException,
S3ClientException,
UserException {
public class HttpException extends RuntimeException {
private final int status;

protected HttpException(String message, int status) {
public HttpException(String message, int status) {
super(message);
this.status = status;
}

public HttpException(String message) {
super(message);
this.status = 400;
}
}
Loading

0 comments on commit f53404b

Please sign in to comment.