Skip to content

Commit

Permalink
Changes to eliniate session status and normalization changes on asses…
Browse files Browse the repository at this point in the history
…sment_student
  • Loading branch information
sumathi-thirumani committed Oct 12, 2024
1 parent ee50230 commit a1489dd
Show file tree
Hide file tree
Showing 31 changed files with 499 additions and 240 deletions.
6 changes: 5 additions & 1 deletion api/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
<maven.compiler.source>${java.version}</maven.compiler.source>
<maven.compiler.target>${java.version}</maven.compiler.target>
<org.mapstruct.version>1.6.2</org.mapstruct.version>
<shedlock.version>4.20.0</shedlock.version>
<shedlock.version>5.16.0</shedlock.version>
<springdoc.version>1.6.9</springdoc.version>
<nats.version>2.11.0</nats.version>
<postgresql.version>42.7.3</postgresql.version>
Expand Down Expand Up @@ -87,6 +87,10 @@
<groupId>org.flywaydb</groupId>
<artifactId>flyway-core</artifactId>
</dependency>
<dependency>
<groupId>org.flywaydb</groupId>
<artifactId>flyway-database-postgresql</artifactId>
</dependency>
<dependency>
<groupId>org.postgresql</groupId>
<artifactId>postgresql</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,14 @@ public class AssessmentStudentController implements AssessmentStudentEndpoint {
private final AssessmentStudentService studentService;
private final AssessmentStudentValidator validator;
private final AssessmentStudentSearchService searchService;
private final AssessmentStudentMapper mapper;

private static final AssessmentStudentMapper mapper = AssessmentStudentMapper.mapper;
@Autowired
public AssessmentStudentController(AssessmentStudentService assessmentStudentService, AssessmentStudentValidator validator, AssessmentStudentSearchService searchService) {
public AssessmentStudentController(AssessmentStudentService assessmentStudentService, AssessmentStudentValidator validator, AssessmentStudentSearchService searchService, AssessmentStudentMapper mapper) {
this.studentService = assessmentStudentService;
this.validator = validator;
this.searchService = searchService;
this.mapper = mapper;
}

@Override
Expand All @@ -43,14 +44,14 @@ public AssessmentStudent readStudent(UUID assessmentStudentID) {

@Override
public AssessmentStudent updateStudent(AssessmentStudent assessmentStudent, UUID assessmentStudentID) {
ValidationUtil.validatePayload(() -> validator.validatePayload(assessmentStudent, false));
ValidationUtil.validatePayload(() -> validator.validatePayload(mapper.mapAssessment(assessmentStudent), false));
RequestUtil.setAuditColumnsForUpdate(assessmentStudent);
return mapper.toStructure(studentService.updateStudent(mapper.toModel(assessmentStudent)));
}

@Override
public AssessmentStudent createStudent(AssessmentStudent assessmentStudent) {
ValidationUtil.validatePayload(() -> validator.validatePayload(assessmentStudent, true));
ValidationUtil.validatePayload(() -> validator.validatePayload(mapper.mapAssessment(assessmentStudent), true));
RequestUtil.setAuditColumnsForCreate(assessmentStudent);
return mapper.toStructure(studentService.createStudent(mapper.toModel(assessmentStudent)));
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package ca.bc.gov.educ.eas.api.controller.v1;

import ca.bc.gov.educ.eas.api.endpoint.v1.SessionEndpoint;
import ca.bc.gov.educ.eas.api.mappers.SessionMapper;
import ca.bc.gov.educ.eas.api.mappers.v1.SessionMapper;
import ca.bc.gov.educ.eas.api.model.v1.SessionEntity;
import ca.bc.gov.educ.eas.api.service.v1.SessionService;
import ca.bc.gov.educ.eas.api.struct.v1.Session;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
package ca.bc.gov.educ.eas.api.endpoint.v1;

import ca.bc.gov.educ.eas.api.constants.v1.URL;
import ca.bc.gov.educ.eas.api.struct.OnCreate;
import ca.bc.gov.educ.eas.api.struct.OnUpdate;
import ca.bc.gov.educ.eas.api.struct.v1.AssessmentStudent;
import io.swagger.v3.oas.annotations.responses.ApiResponse;
import io.swagger.v3.oas.annotations.responses.ApiResponses;
import jakarta.validation.groups.Default;
import org.springframework.data.domain.Page;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.transaction.annotation.Transactional;
Expand All @@ -16,28 +19,28 @@
@RequestMapping(URL.BASE_URL_STUDENT)
public interface AssessmentStudentEndpoint {

@GetMapping("/{assessmentStudentID}")
@PreAuthorize("hasAuthority('SCOPE_READ_EAS_STUDENT')")
@ApiResponses(value = {@ApiResponse(responseCode = "200", description = "OK"), @ApiResponse(responseCode = "404", description = "NOT FOUND"), @ApiResponse(responseCode = "500", description = "INTERNAL SERVER ERROR.")})
AssessmentStudent readStudent(@PathVariable UUID assessmentStudentID);

@PutMapping("/{assessmentStudentID}")
@PreAuthorize("hasAuthority('SCOPE_WRITE_EAS_STUDENT')")
@ApiResponses(value = {@ApiResponse(responseCode = "200", description = "OK"), @ApiResponse(responseCode = "404", description = "NOT FOUND"), @ApiResponse(responseCode = "400", description = "BAD REQUEST"), @ApiResponse(responseCode = "500", description = "INTERNAL SERVER ERROR.")})
AssessmentStudent updateStudent(@Validated @RequestBody AssessmentStudent assessmentStudent, @PathVariable UUID assessmentStudentID);

@PostMapping
@PreAuthorize("hasAuthority('SCOPE_WRITE_EAS_STUDENT')")
@ApiResponses(value = {@ApiResponse(responseCode = "200", description = "OK"), @ApiResponse(responseCode = "404", description = "NOT FOUND"), @ApiResponse(responseCode = "400", description = "BAD REQUEST"), @ApiResponse(responseCode = "500", description = "INTERNAL SERVER ERROR.")})
AssessmentStudent createStudent(@Validated @RequestBody AssessmentStudent assessmentStudent);

@GetMapping(URL.PAGINATED)
@PreAuthorize("hasAuthority('SCOPE_READ_EAS_STUDENT')")
@Transactional(readOnly = true)
@ApiResponses(value = {@ApiResponse(responseCode = "200", description = "OK"), @ApiResponse(responseCode = "400", description = "BAD REQUEST"), @ApiResponse(responseCode = "500", description = "INTERNAL SERVER ERROR.")})
CompletableFuture<Page<AssessmentStudent>> findAll(@RequestParam(name = "pageNumber", defaultValue = "0") Integer pageNumber,
@RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize,
@RequestParam(name = "sort", defaultValue = "") String sortCriteriaJson,
@RequestParam(name = "searchCriteriaList", required = false) String searchCriteriaListJson);
@GetMapping("/{assessmentStudentID}")
@PreAuthorize("hasAuthority('SCOPE_READ_EAS_STUDENT')")
@ApiResponses(value = {@ApiResponse(responseCode = "200", description = "OK"), @ApiResponse(responseCode = "404", description = "NOT FOUND"), @ApiResponse(responseCode = "500", description = "INTERNAL SERVER ERROR.")})
AssessmentStudent readStudent(@PathVariable UUID assessmentStudentID);

@PutMapping("/{assessmentStudentID}")
@PreAuthorize("hasAuthority('SCOPE_WRITE_EAS_STUDENT')")
@ApiResponses(value = {@ApiResponse(responseCode = "200", description = "OK"), @ApiResponse(responseCode = "404", description = "NOT FOUND"), @ApiResponse(responseCode = "400", description = "BAD REQUEST"), @ApiResponse(responseCode = "500", description = "INTERNAL SERVER ERROR.")})
AssessmentStudent updateStudent(@Validated({Default.class, OnUpdate.class}) @RequestBody AssessmentStudent assessmentStudent, @PathVariable UUID assessmentStudentID);

@PostMapping
@PreAuthorize("hasAuthority('SCOPE_WRITE_EAS_STUDENT')")
@ApiResponses(value = {@ApiResponse(responseCode = "200", description = "OK"), @ApiResponse(responseCode = "404", description = "NOT FOUND"), @ApiResponse(responseCode = "400", description = "BAD REQUEST"), @ApiResponse(responseCode = "500", description = "INTERNAL SERVER ERROR.")})
AssessmentStudent createStudent(@Validated({Default.class, OnCreate.class}) @RequestBody AssessmentStudent assessmentStudent);

@GetMapping(URL.PAGINATED)
@PreAuthorize("hasAuthority('SCOPE_READ_EAS_STUDENT')")
@Transactional(readOnly = true)
@ApiResponses(value = {@ApiResponse(responseCode = "200", description = "OK"), @ApiResponse(responseCode = "400", description = "BAD REQUEST"), @ApiResponse(responseCode = "500", description = "INTERNAL SERVER ERROR.")})
CompletableFuture<Page<AssessmentStudent>> findAll(@RequestParam(name = "pageNumber", defaultValue = "0") Integer pageNumber,
@RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize,
@RequestParam(name = "sort", defaultValue = "") String sortCriteriaJson,
@RequestParam(name = "searchCriteriaList", required = false) String searchCriteriaListJson);

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package ca.bc.gov.educ.eas.api.mappers.v1;

import ca.bc.gov.educ.eas.api.mappers.LocalDateTimeMapper;
import ca.bc.gov.educ.eas.api.mappers.UUIDMapper;
import ca.bc.gov.educ.eas.api.model.v1.AssessmentEntity;
import ca.bc.gov.educ.eas.api.struct.v1.Assessment;
import org.mapstruct.Mapper;
import org.mapstruct.Mapping;
import org.mapstruct.factory.Mappers;

@Mapper(uses = {UUIDMapper.class, LocalDateTimeMapper.class})
public interface AssessmentMapper {

AssessmentMapper mapper = Mappers.getMapper(AssessmentMapper.class);

@Mapping(target = "session.sessionID", source = "sessionEntity.sessionID")
Assessment toStructure(AssessmentEntity entity);

@Mapping(target = "sessionEntity.sessionID", source = "session.sessionID")
AssessmentEntity toEntity(Assessment session);

}
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,32 @@
import ca.bc.gov.educ.eas.api.mappers.UUIDMapper;
import ca.bc.gov.educ.eas.api.model.v1.AssessmentStudentEntity;
import ca.bc.gov.educ.eas.api.struct.v1.AssessmentStudent;
import ca.bc.gov.educ.eas.api.util.TransformUtil;
import org.mapstruct.AfterMapping;
import org.mapstruct.Mapper;
import org.mapstruct.Mapping;
import org.mapstruct.MappingTarget;
import org.mapstruct.factory.Mappers;

@Mapper(uses = {UUIDMapper.class, LocalDateTimeMapper.class})
public interface AssessmentStudentMapper {

AssessmentStudentMapper mapper = Mappers.getMapper(AssessmentStudentMapper.class);
AssessmentStudentMapper mapper = Mappers.getMapper(AssessmentStudentMapper.class);

@Mapping(target = "sessionID", source = "sessionEntity.sessionID")
AssessmentStudent toStructure(AssessmentStudentEntity entity);
@Mapping(target = "assessmentID", source = "assessmentEntity.assessmentID")
@Mapping(target = "sessionID", source = "assessmentEntity.sessionEntity.sessionID")
@Mapping(target = "assessmentTypeCode", source = "assessmentEntity.assessmentTypeCode")
AssessmentStudent toStructure(AssessmentStudentEntity entity);

@Mapping(target = "sessionEntity.sessionID", source = "sessionID")
AssessmentStudentEntity toModel(AssessmentStudent assessmentStudent);
AssessmentStudent mapAssessment(AssessmentStudent assessmentStudent);

@Mapping(target = "assessmentEntity.assessmentID", source = "assessmentID")
@Mapping(target = "assessmentEntity.sessionEntity.sessionID", source = "sessionID")
@Mapping(target = "assessmentEntity.assessmentTypeCode", source = "assessmentTypeCode")
AssessmentStudentEntity toModel(AssessmentStudent assessmentStudent);

@AfterMapping
default void transformToUpperCase(AssessmentStudentEntity assessmentStudentEntity, @MappingTarget AssessmentStudent.AssessmentStudentBuilder assessmentStudent) {
TransformUtil.uppercaseFields(assessmentStudentEntity);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
package ca.bc.gov.educ.eas.api.mappers.v1;

import ca.bc.gov.educ.eas.api.model.v1.AssessmentEntity;
import ca.bc.gov.educ.eas.api.model.v1.AssessmentStudentEntity;
import ca.bc.gov.educ.eas.api.repository.v1.AssessmentRepository;
import ca.bc.gov.educ.eas.api.struct.v1.AssessmentStudent;
import io.micrometer.common.util.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.Optional;
import java.util.UUID;

@Component
public class AssessmentStudentSessionMapper implements AssessmentStudentMapper {

private final AssessmentRepository assessmentRepository;

@Autowired
public AssessmentStudentSessionMapper(AssessmentRepository assessmentRepository) {
this.assessmentRepository = assessmentRepository;
}

@Override
public AssessmentStudent toStructure(AssessmentStudentEntity entity) {
return mapper.toStructure(entity);
}

@Override
public AssessmentStudent mapAssessment(AssessmentStudent assessmentStudent) {
Optional<AssessmentEntity> assessmentEntity;
if (StringUtils.isNotEmpty(assessmentStudent.getAssessmentID())) {
assessmentEntity = assessmentRepository.findById(UUID.fromString(assessmentStudent.getAssessmentID()));
} else {
assessmentEntity = assessmentRepository.findBySessionIdAndAssessmentType(UUID.fromString(assessmentStudent.getSessionID()), assessmentStudent.getAssessmentTypeCode());
}
if (assessmentEntity.isPresent()) {
assessmentStudent.setAssessmentID(assessmentEntity.get().getAssessmentID().toString());
} else {
assessmentStudent.setAssessmentID(null);
}
return assessmentStudent;
}

@Override
public AssessmentStudentEntity toModel(AssessmentStudent assessmentStudent) {
return mapper.toModel(assessmentStudent);
}

}
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package ca.bc.gov.educ.eas.api.mappers;
package ca.bc.gov.educ.eas.api.mappers.v1;

import ca.bc.gov.educ.eas.api.mappers.LocalDateTimeMapper;
import ca.bc.gov.educ.eas.api.mappers.UUIDMapper;
import ca.bc.gov.educ.eas.api.model.v1.SessionEntity;
import ca.bc.gov.educ.eas.api.struct.v1.Session;
import org.mapstruct.BeanMapping;
Expand All @@ -8,28 +10,14 @@
import org.mapstruct.NullValuePropertyMappingStrategy;
import org.mapstruct.factory.Mappers;

/**
* Mapper for converting between SessionEntity and Session DTO.
*/
@Mapper(uses = {UUIDMapper.class, LocalDateTimeMapper.class})
public interface SessionMapper {

SessionMapper mapper = Mappers.getMapper(SessionMapper.class);

/**
* Conversion from Session Entity to DTO.
* @param entity SessionEntity
* @return Session
*/
@Mapping(source = "courseSession", target = "courseSession")
@Mapping(source = "statusCode", target = "status")
Session toStructure(SessionEntity entity);

/**
* Conversion from Session DTO to Entity.
* @param session Session
* @return SessionEntity
*/
@BeanMapping(nullValuePropertyMappingStrategy = NullValuePropertyMappingStrategy.IGNORE)
SessionEntity toEntity(Session session);

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
package ca.bc.gov.educ.eas.api.model.v1;

import jakarta.persistence.*;
import jakarta.validation.constraints.PastOrPresent;
import lombok.*;
import org.hibernate.annotations.DynamicUpdate;
import org.hibernate.annotations.UuidGenerator;

import java.time.LocalDateTime;
import java.util.UUID;

@Data
@NoArgsConstructor
@AllArgsConstructor
@DynamicUpdate
@Entity
@Builder
@Table(name = "ASSESSMENT")
public class AssessmentEntity {

@Id
@GeneratedValue(generator = "UUID")
@UuidGenerator
@Column(name = "ASSESSMENT_ID", unique = true, updatable = false, columnDefinition = "BINARY(16)")
private UUID assessmentID;

@ToString.Exclude
@EqualsAndHashCode.Exclude
@ManyToOne(optional = false, targetEntity = SessionEntity.class)
@JoinColumn(name = "SESSION_ID", referencedColumnName = "SESSION_ID", updatable = false)
SessionEntity sessionEntity;

@Column(name = "ASSESSMENT_TYPE_CODE", nullable = false, length = 10)
private String assessmentTypeCode;

@Column(name = "CREATE_USER", updatable = false, length = 100)
private String createUser;

@PastOrPresent
@Column(name = "CREATE_DATE", updatable = false)
private LocalDateTime createDate;

@Column(name = "UPDATE_USER", nullable = false, length = 100)
private String updateUser;

@PastOrPresent
@Column(name = "UPDATE_DATE", nullable = false)
private LocalDateTime updateDate;
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@
import jakarta.validation.constraints.PastOrPresent;
import lombok.*;
import org.hibernate.annotations.DynamicUpdate;
import org.hibernate.annotations.GenericGenerator;
import org.hibernate.annotations.Parameter;
import org.hibernate.annotations.UuidGenerator;

import java.time.LocalDateTime;
import java.util.UUID;
Expand All @@ -23,19 +22,15 @@ public class AssessmentStudentEntity {

@Id
@GeneratedValue(generator = "UUID")
@GenericGenerator(name = "UUID", strategy = "org.hibernate.id.UUIDGenerator", parameters = {
@Parameter(name = "uuid_gen_strategy_class", value = "org.hibernate.id.uuid.CustomVersionOneStrategy")})
@UuidGenerator
@Column(name = "ASSESSMENT_STUDENT_ID", unique = true, updatable = false, columnDefinition = "BINARY(16)")
private UUID assessmentStudentID;

@ToString.Exclude
@EqualsAndHashCode.Exclude
@ManyToOne(optional = false, targetEntity = SessionEntity.class)
@JoinColumn(name = "SESSION_ID", referencedColumnName = "SESSION_ID", updatable = false)
SessionEntity sessionEntity;

@Column(name = "ASSESSMENT_TYPE_CODE", nullable = false, length = 10)
private String assessmentTypeCode;
@ManyToOne(optional = false, targetEntity = AssessmentEntity.class)
@JoinColumn(name = "ASSESSMENT_ID", referencedColumnName = "ASSESSMENT_ID", updatable = false)
AssessmentEntity assessmentEntity;

@Column(name = "SCHOOL_ID", nullable = false, columnDefinition = "BINARY(16)")
private UUID schoolID;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import lombok.Data;
import lombok.NoArgsConstructor;
import org.hibernate.annotations.DynamicUpdate;
import org.hibernate.annotations.GenericGenerator;
import org.hibernate.annotations.UuidGenerator;

import java.time.LocalDateTime;
import java.util.UUID;
Expand All @@ -28,8 +28,7 @@ public class EasSagaEntity {

@Id
@GeneratedValue(generator = "UUID")
@GenericGenerator(name = "UUID", strategy = "org.hibernate.id.UUIDGenerator", parameters = {
@org.hibernate.annotations.Parameter(name = "uuid_gen_strategy_class", value = "org.hibernate.id.uuid.CustomVersionOneStrategy")})
@UuidGenerator
@Column(name = "SAGA_ID", unique = true, updatable = false, columnDefinition = "BINARY(16)")
UUID sagaId;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import jakarta.validation.constraints.Size;
import lombok.*;
import org.hibernate.annotations.DynamicUpdate;
import org.hibernate.annotations.GenericGenerator;
import org.hibernate.annotations.UuidGenerator;

import java.time.LocalDateTime;
import java.util.UUID;
Expand All @@ -29,8 +29,7 @@ public class SagaEventStatesEntity {
*/
@Id
@GeneratedValue(generator = "UUID")
@GenericGenerator(name = "UUID", strategy = "org.hibernate.id.UUIDGenerator", parameters = {
@org.hibernate.annotations.Parameter(name = "uuid_gen_strategy_class", value = "org.hibernate.id.uuid.CustomVersionOneStrategy")})
@UuidGenerator
@Column(name = "SAGA_EVENT_ID", unique = true, updatable = false, columnDefinition = "BINARY(16)")
UUID sagaEventId;

Expand Down
Loading

0 comments on commit a1489dd

Please sign in to comment.