diff --git a/api/src/main/java/ca/bc/gov/educ/api/institute/constants/v1/URL.java b/api/src/main/java/ca/bc/gov/educ/api/institute/constants/v1/URL.java index f74bd899..7abd9678 100644 --- a/api/src/main/java/ca/bc/gov/educ/api/institute/constants/v1/URL.java +++ b/api/src/main/java/ca/bc/gov/educ/api/institute/constants/v1/URL.java @@ -1,7 +1,6 @@ package ca.bc.gov.educ.api.institute.constants.v1; public final class URL { - public static final String SCHOOL_BY_ID = "/{schoolId}"; public static final String CATEGORY_CODES = "/category-codes"; public static final String GRADE_CODES = "/grade-codes"; public static final String FACILITY_TYPE_CODES = "/facility-codes"; @@ -12,12 +11,10 @@ public final class URL { public static final String AUTHORITY_GROUP_CODES = "/authority-group-codes"; public static final String AUTHORITY_TYPE_CODES = "/authority-type-codes"; public static final String DISTRICT_CONTACT_TYPE_CODES = "/district-contact-type-codes"; - public static final String SCHOOL_CONTACT_TYPE_CODES = "/school-contact-type-codes"; - public static final String AUTHORITY_CONTACT_TYPE_CODES = "/authority-contact-type-codes"; public static final String PROVINCE_CODES = "/province-codes"; - + public static final String FUNDING_GROUP_CODES = "/funding-group-codes"; public static final String COUNTRY_CODES = "/country-codes"; public static final String DISTRICT_REGION_CODES = "/district-region-codes"; public static final String DISTRICT_STATUS_CODES = "/district-status-codes"; @@ -29,4 +26,5 @@ private URL(){ public static final String BASE_URL_DISTRICT="/api/v1/institute/district"; public static final String BASE_URL_SCHOOL="/api/v1/institute/school"; public static final String BASE_URL_AUTHORITY="/api/v1/institute/authority"; + public static final String BASE_URL_SCHOOL_FUNDING="/api/v1/institute/schoolFundingGroup"; } diff --git a/api/src/main/java/ca/bc/gov/educ/api/institute/controller/v1/CodeTableAPIController.java b/api/src/main/java/ca/bc/gov/educ/api/institute/controller/v1/CodeTableAPIController.java index 36e3f4c9..997928c6 100644 --- a/api/src/main/java/ca/bc/gov/educ/api/institute/controller/v1/CodeTableAPIController.java +++ b/api/src/main/java/ca/bc/gov/educ/api/institute/controller/v1/CodeTableAPIController.java @@ -30,6 +30,11 @@ public List getAddressTypeCodes() { return getService().getAddressTypeCodesList().stream().map(mapper::toStructure).collect(Collectors.toList()); } + @Override + public List getIndependentSchoolFundingGroupCodes() { + return getService().getAllSchoolFundingGroupCodes().stream().map(mapper::toStructure).toList(); + } + @Override public List getProvinceCodes() { return getService().getProvinceCodesList().stream().map(mapper::toStructure).collect(Collectors.toList()); diff --git a/api/src/main/java/ca/bc/gov/educ/api/institute/controller/v1/IndependentSchoolFundingGroupController.java b/api/src/main/java/ca/bc/gov/educ/api/institute/controller/v1/IndependentSchoolFundingGroupController.java new file mode 100644 index 00000000..b4236d85 --- /dev/null +++ b/api/src/main/java/ca/bc/gov/educ/api/institute/controller/v1/IndependentSchoolFundingGroupController.java @@ -0,0 +1,113 @@ +package ca.bc.gov.educ.api.institute.controller.v1; + +import ca.bc.gov.educ.api.institute.endpoint.v1.IndependentSchoolFundingGroupEndpoint; +import ca.bc.gov.educ.api.institute.exception.EntityNotFoundException; +import ca.bc.gov.educ.api.institute.exception.InvalidPayloadException; +import ca.bc.gov.educ.api.institute.exception.errors.ApiError; +import ca.bc.gov.educ.api.institute.mapper.v1.IndependentSchoolFundingGroupMapper; +import ca.bc.gov.educ.api.institute.model.v1.IndependentSchoolFundingGroupEntity; +import ca.bc.gov.educ.api.institute.model.v1.IndependentSchoolFundingGroupHistoryEntity; +import ca.bc.gov.educ.api.institute.service.v1.IndependentSchoolFundingGroupService; +import ca.bc.gov.educ.api.institute.struct.v1.IndependentSchoolFundingGroup; +import ca.bc.gov.educ.api.institute.struct.v1.IndependentSchoolFundingGroupHistory; +import ca.bc.gov.educ.api.institute.util.RequestUtil; +import ca.bc.gov.educ.api.institute.util.ValidationUtil; +import ca.bc.gov.educ.api.institute.validator.IndependentSchoolFundingGroupPayloadValidator; +import com.fasterxml.jackson.core.JsonProcessingException; +import lombok.extern.slf4j.Slf4j; +import lombok.val; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.http.ResponseEntity; +import org.springframework.transaction.annotation.Transactional; +import org.springframework.validation.FieldError; +import org.springframework.web.bind.annotation.RestController; + +import java.time.LocalDateTime; +import java.util.ArrayList; +import java.util.List; +import java.util.Optional; +import java.util.UUID; +import java.util.function.Supplier; + +import static org.springframework.http.HttpStatus.BAD_REQUEST; + +@RestController +@Slf4j +public class IndependentSchoolFundingGroupController implements IndependentSchoolFundingGroupEndpoint { + + private static final IndependentSchoolFundingGroupMapper independentSchoolFundingGroupMapper = IndependentSchoolFundingGroupMapper.mapper; + private final IndependentSchoolFundingGroupPayloadValidator independentSchoolFundingGroupPayloadValidator; + private final IndependentSchoolFundingGroupService independentSchoolFundingGroupService; + + @Autowired + public IndependentSchoolFundingGroupController(IndependentSchoolFundingGroupPayloadValidator independentSchoolFundingGroupPayloadValidator, IndependentSchoolFundingGroupService independentSchoolFundingGroupService) { + this.independentSchoolFundingGroupPayloadValidator = independentSchoolFundingGroupPayloadValidator; + this.independentSchoolFundingGroupService = independentSchoolFundingGroupService; + } + + private void validatePayload(Supplier> validator) { + val validationResult = validator.get(); + if (!validationResult.isEmpty()) { + ApiError error = ApiError.builder().timestamp(LocalDateTime.now()).message("Payload contains invalid data.").status(BAD_REQUEST).build(); + error.addValidationErrors(validationResult); + throw new InvalidPayloadException(error); + } + } + + @Override + public IndependentSchoolFundingGroup getIndependentSchoolFundingGroup(UUID schoolFundingGroupID) { + Optional independentSchoolFundingGroup = this.independentSchoolFundingGroupService.getIndependentSchoolFundingGroup(schoolFundingGroupID); + + if (independentSchoolFundingGroup.isPresent()) { + return independentSchoolFundingGroupMapper.toStructure(independentSchoolFundingGroup.get()); + } else { + throw new EntityNotFoundException(); + } + } + + @Override + public List getIndependentSchoolFundingGroups(UUID schoolID) { + List independentSchoolFundingGroups = this.independentSchoolFundingGroupService.getIndependentSchoolFundingGroups(schoolID); + + List independentSchoolFundingGroupList = new ArrayList<>(); + for(IndependentSchoolFundingGroupEntity entity: independentSchoolFundingGroups){ + independentSchoolFundingGroupList.add(independentSchoolFundingGroupMapper.toStructure(entity)); + } + + return independentSchoolFundingGroupList; + } + + @Override + public List getIndependentSchoolFundingGroupHistory(UUID schoolID) { + List independentSchoolFundingGroups = this.independentSchoolFundingGroupService.getIndependentSchoolFundingGroupHistory(schoolID); + + List independentSchoolFundingGroupList = new ArrayList<>(); + for(IndependentSchoolFundingGroupHistoryEntity entity: independentSchoolFundingGroups){ + independentSchoolFundingGroupList.add(independentSchoolFundingGroupMapper.toStructure(entity)); + } + + return independentSchoolFundingGroupList; + } + + @Override + public IndependentSchoolFundingGroup createIndependentSchoolFundingGroup(IndependentSchoolFundingGroup fundingGroup) throws JsonProcessingException { + validatePayload(() -> this.independentSchoolFundingGroupPayloadValidator.validateCreatePayload(fundingGroup)); + RequestUtil.setAuditColumnsForCreate(fundingGroup); + + return independentSchoolFundingGroupMapper.toStructure(independentSchoolFundingGroupService.createIndependentSchoolFundingGroup(fundingGroup)); + } + + @Override + public IndependentSchoolFundingGroup updateIndependentSchoolFundingGroup(UUID schoolFundingGroupID, IndependentSchoolFundingGroup independentSchoolFundingGroup) { + ValidationUtil.validatePayload(() -> this.independentSchoolFundingGroupPayloadValidator.validatePayload(independentSchoolFundingGroup, false)); + RequestUtil.setAuditColumnsForUpdate(independentSchoolFundingGroup); + return independentSchoolFundingGroupMapper.toStructure(independentSchoolFundingGroupService.updateIndependentSchoolFundingGroup(independentSchoolFundingGroup)); + } + + @Override + @Transactional + public ResponseEntity deleteIndependentSchoolFundingGroup(UUID schoolFundingGroupID) { + this.independentSchoolFundingGroupService.deleteIndependentSchoolFundingGroup(schoolFundingGroupID); + return ResponseEntity.noContent().build(); + } +} diff --git a/api/src/main/java/ca/bc/gov/educ/api/institute/endpoint/v1/CodeTableAPIEndpoint.java b/api/src/main/java/ca/bc/gov/educ/api/institute/endpoint/v1/CodeTableAPIEndpoint.java index 1088f90c..e5715a76 100644 --- a/api/src/main/java/ca/bc/gov/educ/api/institute/endpoint/v1/CodeTableAPIEndpoint.java +++ b/api/src/main/java/ca/bc/gov/educ/api/institute/endpoint/v1/CodeTableAPIEndpoint.java @@ -38,6 +38,14 @@ public interface CodeTableAPIEndpoint { @Schema(name = "ProvinceCode", implementation = ProvinceCode.class) List getProvinceCodes(); + @PreAuthorize("hasAuthority('SCOPE_READ_COLLECTION_CODES')") + @GetMapping(URL.FUNDING_GROUP_CODES) + @ApiResponses(value = {@ApiResponse(responseCode = "200", description = "OK")}) + @Transactional(readOnly = true) + @Tag(name = "Collection Codes", description = "Endpoints to get collection codes.") + @Schema(name = "SchoolFundingGroupCodes", implementation = SchoolFundingGroupCode.class) + List getIndependentSchoolFundingGroupCodes(); + @PreAuthorize("hasAuthority('SCOPE_READ_INSTITUTE_CODES')") @GetMapping(URL.COUNTRY_CODES) @ApiResponses(value = {@ApiResponse(responseCode = "200", description = "OK")}) diff --git a/api/src/main/java/ca/bc/gov/educ/api/institute/endpoint/v1/IndependentSchoolFundingGroupEndpoint.java b/api/src/main/java/ca/bc/gov/educ/api/institute/endpoint/v1/IndependentSchoolFundingGroupEndpoint.java new file mode 100644 index 00000000..8a4e754d --- /dev/null +++ b/api/src/main/java/ca/bc/gov/educ/api/institute/endpoint/v1/IndependentSchoolFundingGroupEndpoint.java @@ -0,0 +1,73 @@ +package ca.bc.gov.educ.api.institute.endpoint.v1; + +import ca.bc.gov.educ.api.institute.constants.v1.URL; +import ca.bc.gov.educ.api.institute.struct.v1.IndependentSchoolFundingGroup; +import ca.bc.gov.educ.api.institute.struct.v1.IndependentSchoolFundingGroupHistory; +import com.fasterxml.jackson.core.JsonProcessingException; +import io.swagger.v3.oas.annotations.media.Schema; +import io.swagger.v3.oas.annotations.responses.ApiResponse; +import io.swagger.v3.oas.annotations.responses.ApiResponses; +import io.swagger.v3.oas.annotations.tags.Tag; +import org.springframework.http.ResponseEntity; +import org.springframework.security.access.prepost.PreAuthorize; +import org.springframework.transaction.annotation.Transactional; +import org.springframework.validation.annotation.Validated; +import org.springframework.web.bind.annotation.*; + +import java.util.List; +import java.util.UUID; + +import static org.springframework.http.HttpStatus.CREATED; +import static org.springframework.http.HttpStatus.NO_CONTENT; + +@RequestMapping(URL.BASE_URL_SCHOOL_FUNDING) +public interface IndependentSchoolFundingGroupEndpoint { + + @GetMapping("/{schoolFundingGroupID}") + @PreAuthorize("hasAuthority('SCOPE_READ_SCHOOL_FUNDING_GROUP')") + @ApiResponses(value = {@ApiResponse(responseCode = "200", description = "OK"), @ApiResponse(responseCode = "404", description = "NOT FOUND")}) + @Transactional(readOnly = true) + @Tag(name = "IndependentSchoolFundingGroup Entity", description = "Endpoints for independent school group funding entity.") + @Schema(name = "IndependentSchoolFundingGroup", implementation = IndependentSchoolFundingGroup.class) + IndependentSchoolFundingGroup getIndependentSchoolFundingGroup(@PathVariable("schoolFundingGroupID") UUID schoolFundingGroupID); + + @GetMapping("/search/{schoolID}") + @PreAuthorize("hasAuthority('SCOPE_READ_SCHOOL_FUNDING_GROUP')") + @ApiResponses(value = {@ApiResponse(responseCode = "200", description = "OK"), @ApiResponse(responseCode = "404", description = "NOT FOUND")}) + @Transactional(readOnly = true) + @Tag(name = "IndependentSchoolFundingGroup Entity", description = "Endpoints for independent school group funding entity.") + @Schema(name = "IndependentSchoolFundingGroup", implementation = IndependentSchoolFundingGroup.class) + List getIndependentSchoolFundingGroups(@PathVariable("schoolID") UUID schoolID); + + @GetMapping("/search/{schoolID}/history") + @PreAuthorize("hasAuthority('SCOPE_READ_SCHOOL_FUNDING_GROUP')") + @ApiResponses(value = {@ApiResponse(responseCode = "200", description = "OK"), @ApiResponse(responseCode = "404", description = "NOT FOUND")}) + @Transactional(readOnly = true) + @Tag(name = "IndependentSchoolFundingGroupHistory Entity", description = "Endpoints for independent school group funding history entities.") + @Schema(name = "IndependentSchoolFundingGroupHistory", implementation = IndependentSchoolFundingGroupHistory.class) + List getIndependentSchoolFundingGroupHistory(@PathVariable("schoolID") UUID schoolID); + + @PostMapping() + @PreAuthorize("hasAuthority('SCOPE_WRITE_SCHOOL_FUNDING_GROUP')") + @ApiResponses(value = {@ApiResponse(responseCode = "201", description = "CREATED"), @ApiResponse(responseCode = "400", description = "BAD REQUEST")}) + @Tag(name = "IndependentSchoolFundingGroup Entity", description = "Endpoints for independent school group funding entity.") + @Schema(name = "IndependentSchoolFundingGroup", implementation = IndependentSchoolFundingGroup.class) + @ResponseStatus(CREATED) + IndependentSchoolFundingGroup createIndependentSchoolFundingGroup(@Validated @RequestBody IndependentSchoolFundingGroup fundingGroup) throws JsonProcessingException; + + @PutMapping("/{schoolFundingGroupID}") + @PreAuthorize("hasAuthority('SCOPE_WRITE_SCHOOL_FUNDING_GROUP')") + @ApiResponses(value = {@ApiResponse(responseCode = "200", description = "OK"), @ApiResponse(responseCode = "400", description = "BAD REQUEST"), @ApiResponse(responseCode = "404", description = "NOT FOUND")}) + @Transactional + @Tag(name = "IndependentSchoolFundingGroup Entity", description = "Endpoints for independent school group funding entity.") + @Schema(name = "IndependentSchoolFundingGroup", implementation = IndependentSchoolFundingGroup.class) + IndependentSchoolFundingGroup updateIndependentSchoolFundingGroup(@PathVariable("schoolFundingGroupID") UUID schoolFundingGroupID, @Validated @RequestBody IndependentSchoolFundingGroup independentSchoolFundingGroup); + + @DeleteMapping("/{schoolFundingGroupID}") + @PreAuthorize("hasAuthority('SCOPE_DELETE_SCHOOL_FUNDING_GROUP')") + @ApiResponses(value = {@ApiResponse(responseCode = "204", description = "NO CONTENT"), @ApiResponse(responseCode = "404", description = "NOT FOUND")}) + @Tag(name = "IndependentSchoolFundingGroup Entity", description = "Endpoints for independent school group funding entity.") + @Schema(name = "IndependentSchoolFundingGroup", implementation = IndependentSchoolFundingGroup.class) + @ResponseStatus(NO_CONTENT) + ResponseEntity deleteIndependentSchoolFundingGroup(@PathVariable UUID schoolFundingGroupID); +} diff --git a/api/src/main/java/ca/bc/gov/educ/api/institute/mapper/v1/CodeTableMapper.java b/api/src/main/java/ca/bc/gov/educ/api/institute/mapper/v1/CodeTableMapper.java index 9f571d6c..42d346bd 100644 --- a/api/src/main/java/ca/bc/gov/educ/api/institute/mapper/v1/CodeTableMapper.java +++ b/api/src/main/java/ca/bc/gov/educ/api/institute/mapper/v1/CodeTableMapper.java @@ -5,7 +5,6 @@ import ca.bc.gov.educ.api.institute.model.v1.*; import ca.bc.gov.educ.api.institute.struct.v1.*; import org.mapstruct.Mapper; -import org.mapstruct.Mapping; import org.mapstruct.factory.Mappers; /** @@ -92,4 +91,6 @@ public interface CodeTableMapper { SchoolReportingRequirementCodeEntity toModel(SchoolReportingRequirementCode structure); SchoolReportingRequirementCode toStructure(SchoolReportingRequirementCodeEntity entity); + + SchoolFundingGroupCode toStructure(SchoolFundingGroupCodeEntity entity); } diff --git a/api/src/main/java/ca/bc/gov/educ/api/institute/mapper/v1/IndependentSchoolFundingGroupMapper.java b/api/src/main/java/ca/bc/gov/educ/api/institute/mapper/v1/IndependentSchoolFundingGroupMapper.java new file mode 100644 index 00000000..77f12e19 --- /dev/null +++ b/api/src/main/java/ca/bc/gov/educ/api/institute/mapper/v1/IndependentSchoolFundingGroupMapper.java @@ -0,0 +1,24 @@ +package ca.bc.gov.educ.api.institute.mapper.v1; + +import ca.bc.gov.educ.api.institute.mapper.LocalDateTimeMapper; +import ca.bc.gov.educ.api.institute.mapper.UUIDMapper; +import ca.bc.gov.educ.api.institute.model.v1.IndependentSchoolFundingGroupEntity; +import ca.bc.gov.educ.api.institute.model.v1.IndependentSchoolFundingGroupHistoryEntity; +import ca.bc.gov.educ.api.institute.struct.v1.IndependentSchoolFundingGroup; +import ca.bc.gov.educ.api.institute.struct.v1.IndependentSchoolFundingGroupHistory; +import org.mapstruct.Mapper; +import org.mapstruct.factory.Mappers; + +@Mapper(uses = {UUIDMapper.class, LocalDateTimeMapper.class}) +@SuppressWarnings("squid:S1214") +public interface IndependentSchoolFundingGroupMapper { + + IndependentSchoolFundingGroupMapper mapper = Mappers.getMapper(IndependentSchoolFundingGroupMapper.class); + + IndependentSchoolFundingGroupEntity toModel(IndependentSchoolFundingGroup structure); + + IndependentSchoolFundingGroup toStructure(IndependentSchoolFundingGroupEntity entity); + IndependentSchoolFundingGroupHistoryEntity toModel(IndependentSchoolFundingGroupHistory structure); + + IndependentSchoolFundingGroupHistory toStructure(IndependentSchoolFundingGroupHistoryEntity entity); +} diff --git a/api/src/main/java/ca/bc/gov/educ/api/institute/model/v1/IndependentSchoolFundingGroupEntity.java b/api/src/main/java/ca/bc/gov/educ/api/institute/model/v1/IndependentSchoolFundingGroupEntity.java new file mode 100644 index 00000000..bba10029 --- /dev/null +++ b/api/src/main/java/ca/bc/gov/educ/api/institute/model/v1/IndependentSchoolFundingGroupEntity.java @@ -0,0 +1,61 @@ +package ca.bc.gov.educ.api.institute.model.v1; + +import ca.bc.gov.educ.api.institute.util.UpperCase; +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import jakarta.persistence.*; +import jakarta.validation.constraints.PastOrPresent; +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; +import org.hibernate.annotations.DynamicUpdate; +import org.hibernate.annotations.GenericGenerator; +import org.hibernate.annotations.Parameter; + +import java.time.LocalDateTime; +import java.util.UUID; + +@Data +@NoArgsConstructor +@AllArgsConstructor +@DynamicUpdate +@Entity +@Builder +@Table(name = "INDEPENDENT_SCHOOL_FUNDING_GROUP") +@JsonIgnoreProperties(ignoreUnknown = true) +public class IndependentSchoolFundingGroupEntity { + + @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")}) + @Column(name = "SCHOOL_FUNDING_GROUP_ID", unique = true, updatable = false, columnDefinition = "BINARY(16)") + private UUID schoolFundingGroupID; + + @Basic + @Column(name = "SCHOOL_ID", columnDefinition = "BINARY(16)") + private UUID schoolID; + + @Column(name = "SCHOOL_GRADE_CODE", nullable = false, length = 10) + @UpperCase + private String schoolGradeCode; + + @Column(name = "SCHOOL_FUNDING_GROUP_CODE", nullable = false, length = 10) + @UpperCase + private String schoolFundingGroupCode; + + @Column(name = "CREATE_USER", updatable = false , length = 32) + private String createUser; + + @PastOrPresent + @Column(name = "CREATE_DATE", updatable = false) + private LocalDateTime createDate; + + @Column(name = "UPDATE_USER", length = 32) + private String updateUser; + + @PastOrPresent + @Column(name = "UPDATE_DATE") + private LocalDateTime updateDate; + +} diff --git a/api/src/main/java/ca/bc/gov/educ/api/institute/model/v1/IndependentSchoolFundingGroupHistoryEntity.java b/api/src/main/java/ca/bc/gov/educ/api/institute/model/v1/IndependentSchoolFundingGroupHistoryEntity.java new file mode 100644 index 00000000..3d746173 --- /dev/null +++ b/api/src/main/java/ca/bc/gov/educ/api/institute/model/v1/IndependentSchoolFundingGroupHistoryEntity.java @@ -0,0 +1,65 @@ +package ca.bc.gov.educ.api.institute.model.v1; + +import ca.bc.gov.educ.api.institute.util.UpperCase; +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import jakarta.persistence.*; +import jakarta.validation.constraints.PastOrPresent; +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; +import org.hibernate.annotations.DynamicUpdate; +import org.hibernate.annotations.GenericGenerator; +import org.hibernate.annotations.Parameter; + +import java.time.LocalDateTime; +import java.util.UUID; + +@Data +@NoArgsConstructor +@AllArgsConstructor +@DynamicUpdate +@Entity +@Builder +@Table(name = "INDEPENDENT_SCHOOL_FUNDING_GROUP_HISTORY") +@JsonIgnoreProperties(ignoreUnknown = true) +public class IndependentSchoolFundingGroupHistoryEntity { + + @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")}) + @Column(name = "SCHOOL_FUNDING_GROUP_HISTORY_ID", unique = true, updatable = false, columnDefinition = "BINARY(16)") + private UUID schoolFundingGroupHistoryID; + + @Basic + @Column(name = "SCHOOL_FUNDING_GROUP_ID", columnDefinition = "BINARY(16)") + private UUID schoolFundingGroupID; + + @Basic + @Column(name = "SCHOOL_ID", columnDefinition = "BINARY(16)") + private UUID schoolID; + + @Column(name = "SCHOOL_GRADE_CODE", nullable = false, length = 10) + @UpperCase + private String schoolGradeCode; + + @Column(name = "SCHOOL_FUNDING_GROUP_CODE", nullable = false, length = 10) + @UpperCase + private String schoolFundingGroupCode; + + @Column(name = "CREATE_USER", updatable = false , length = 32) + private String createUser; + + @PastOrPresent + @Column(name = "CREATE_DATE", updatable = false) + private LocalDateTime createDate; + + @Column(name = "UPDATE_USER", length = 32) + private String updateUser; + + @PastOrPresent + @Column(name = "UPDATE_DATE") + private LocalDateTime updateDate; + +} diff --git a/api/src/main/java/ca/bc/gov/educ/api/institute/model/v1/SchoolFundingGroupCodeEntity.java b/api/src/main/java/ca/bc/gov/educ/api/institute/model/v1/SchoolFundingGroupCodeEntity.java new file mode 100644 index 00000000..dd153c54 --- /dev/null +++ b/api/src/main/java/ca/bc/gov/educ/api/institute/model/v1/SchoolFundingGroupCodeEntity.java @@ -0,0 +1,53 @@ +package ca.bc.gov.educ.api.institute.model.v1; + +import jakarta.persistence.*; +import jakarta.validation.constraints.PastOrPresent; +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; +import org.hibernate.annotations.DynamicUpdate; + +import java.time.LocalDateTime; + +@Data +@NoArgsConstructor +@AllArgsConstructor +@Builder +@Entity +@DynamicUpdate +@Table(name = "SCHOOL_FUNDING_GROUP_CODE") +public class SchoolFundingGroupCodeEntity { + @Id + @Column(name = "school_funding_group_code", unique = true, updatable = false) + private String schoolFundingGroupCode; + @Basic + @Column(name = "label") + private String label; + @Basic + @Column(name = "description") + private String description; + @Basic + @Column(name = "legacy_code") + private String legacyCode; + @Basic + @Column(name = "display_order") + private Integer displayOrder; + @Basic + @Column(name = "effective_date") + private LocalDateTime effectiveDate; + @Basic + @Column(name = "expiry_date") + private LocalDateTime expiryDate; + @Column(name = "CREATE_USER", updatable = false) + private String createUser; + @PastOrPresent + @Column(name = "CREATE_DATE", updatable = false) + private LocalDateTime createDate; + @Column(name = "update_user") + private String updateUser; + @PastOrPresent + @Column(name = "update_date") + private LocalDateTime updateDate; + +} diff --git a/api/src/main/java/ca/bc/gov/educ/api/institute/repository/v1/IndependentSchoolFundingGroupHistoryRepository.java b/api/src/main/java/ca/bc/gov/educ/api/institute/repository/v1/IndependentSchoolFundingGroupHistoryRepository.java new file mode 100644 index 00000000..379a6ee6 --- /dev/null +++ b/api/src/main/java/ca/bc/gov/educ/api/institute/repository/v1/IndependentSchoolFundingGroupHistoryRepository.java @@ -0,0 +1,14 @@ +package ca.bc.gov.educ.api.institute.repository.v1; + +import ca.bc.gov.educ.api.institute.model.v1.IndependentSchoolFundingGroupHistoryEntity; +import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.stereotype.Repository; + +import java.util.List; +import java.util.UUID; + +@Repository +public interface IndependentSchoolFundingGroupHistoryRepository extends JpaRepository { + + List findAllBySchoolID(UUID schoolID); +} diff --git a/api/src/main/java/ca/bc/gov/educ/api/institute/repository/v1/IndependentSchoolFundingGroupRepository.java b/api/src/main/java/ca/bc/gov/educ/api/institute/repository/v1/IndependentSchoolFundingGroupRepository.java new file mode 100644 index 00000000..3f505542 --- /dev/null +++ b/api/src/main/java/ca/bc/gov/educ/api/institute/repository/v1/IndependentSchoolFundingGroupRepository.java @@ -0,0 +1,14 @@ +package ca.bc.gov.educ.api.institute.repository.v1; + +import ca.bc.gov.educ.api.institute.model.v1.IndependentSchoolFundingGroupEntity; +import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.stereotype.Repository; + +import java.util.List; +import java.util.UUID; + +@Repository +public interface IndependentSchoolFundingGroupRepository extends JpaRepository { + + List findAllBySchoolID(UUID schoolID); +} diff --git a/api/src/main/java/ca/bc/gov/educ/api/institute/repository/v1/SchoolFundingGroupCodeRepository.java b/api/src/main/java/ca/bc/gov/educ/api/institute/repository/v1/SchoolFundingGroupCodeRepository.java new file mode 100644 index 00000000..3b9669ae --- /dev/null +++ b/api/src/main/java/ca/bc/gov/educ/api/institute/repository/v1/SchoolFundingGroupCodeRepository.java @@ -0,0 +1,10 @@ +package ca.bc.gov.educ.api.institute.repository.v1; + +import ca.bc.gov.educ.api.institute.model.v1.SchoolFundingGroupCodeEntity; +import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.stereotype.Repository; + +@Repository +public interface SchoolFundingGroupCodeRepository extends JpaRepository { + +} diff --git a/api/src/main/java/ca/bc/gov/educ/api/institute/service/v1/CodeTableService.java b/api/src/main/java/ca/bc/gov/educ/api/institute/service/v1/CodeTableService.java index 9ed633f5..7478403f 100644 --- a/api/src/main/java/ca/bc/gov/educ/api/institute/service/v1/CodeTableService.java +++ b/api/src/main/java/ca/bc/gov/educ/api/institute/service/v1/CodeTableService.java @@ -42,6 +42,8 @@ public class CodeTableService { private final SchoolCategoryCodeRepository schoolCategoryCodeRepository; + private final SchoolFundingGroupCodeRepository schoolFundingGroupCodeRepository; + /** * Instantiates a new Code table service. * @@ -61,21 +63,22 @@ public class CodeTableService { */ @Autowired public CodeTableService( - AddressTypeCodeRepository addressTypeCodeRepository, - AuthorityTypeCodeRepository authorityTypeCodeRepository, - DistrictContactTypeCodeRepository districtContactTypeCodeRepository, - SchoolContactTypeCodeRepository schoolContactTypeCodeRepository, - AuthorityContactTypeCodeRepository authorityContactTypeCodeRepository, - DistrictRegionCodeRepository districtRegionCodeRepository, - DistrictStatusCodeRepository districtStatusCodeRepository, - FacilityTypeCodeRepository facilityTypeCodeRepository, - NeighborhoodLearningTypeCodeRepository neighborhoodLearningTypeCodeRepository, - ProvinceCodeRepository provinceCodeRepository, - CountryCodeRepository countryCodeRepository, - SchoolGradeCodeRepository schoolGradeCodeRepository, - SchoolOrganizationCodeRepository schoolOrganizationCodeRepository, - SchoolCategoryCodeRepository schoolCategoryCodeRepository, - SchoolReportingRequirementCodeRepository schoolReportingRequirementCodeRepository + AddressTypeCodeRepository addressTypeCodeRepository, + AuthorityTypeCodeRepository authorityTypeCodeRepository, + DistrictContactTypeCodeRepository districtContactTypeCodeRepository, + SchoolContactTypeCodeRepository schoolContactTypeCodeRepository, + AuthorityContactTypeCodeRepository authorityContactTypeCodeRepository, + DistrictRegionCodeRepository districtRegionCodeRepository, + DistrictStatusCodeRepository districtStatusCodeRepository, + FacilityTypeCodeRepository facilityTypeCodeRepository, + NeighborhoodLearningTypeCodeRepository neighborhoodLearningTypeCodeRepository, + ProvinceCodeRepository provinceCodeRepository, + CountryCodeRepository countryCodeRepository, + SchoolGradeCodeRepository schoolGradeCodeRepository, + SchoolOrganizationCodeRepository schoolOrganizationCodeRepository, + SchoolCategoryCodeRepository schoolCategoryCodeRepository, + SchoolReportingRequirementCodeRepository schoolReportingRequirementCodeRepository, + SchoolFundingGroupCodeRepository schoolFundingGroupCodeRepository ) { this.addressTypeCodeRepository = addressTypeCodeRepository; this.authorityTypeCodeRepository = authorityTypeCodeRepository; @@ -92,6 +95,7 @@ public CodeTableService( this.schoolOrganizationCodeRepository = schoolOrganizationCodeRepository; this.schoolReportingRequirementCodeRepository = schoolReportingRequirementCodeRepository; this.schoolCategoryCodeRepository = schoolCategoryCodeRepository; + this.schoolFundingGroupCodeRepository = schoolFundingGroupCodeRepository; } @Cacheable("addressTypeCodes") @@ -99,6 +103,11 @@ public List getAddressTypeCodesList() { return addressTypeCodeRepository.findAll(); } + @Cacheable("schoolFundingGroupCodes") + public List getAllSchoolFundingGroupCodes() { + return schoolFundingGroupCodeRepository.findAll(); + } + @Cacheable("authorityTypeCodes") public List getAuthorityTypeCodesList() { return authorityTypeCodeRepository.findAll(); diff --git a/api/src/main/java/ca/bc/gov/educ/api/institute/service/v1/IndependentSchoolFundingGroupService.java b/api/src/main/java/ca/bc/gov/educ/api/institute/service/v1/IndependentSchoolFundingGroupService.java new file mode 100644 index 00000000..04bc9398 --- /dev/null +++ b/api/src/main/java/ca/bc/gov/educ/api/institute/service/v1/IndependentSchoolFundingGroupService.java @@ -0,0 +1,101 @@ +package ca.bc.gov.educ.api.institute.service.v1; + +import ca.bc.gov.educ.api.institute.exception.EntityNotFoundException; +import ca.bc.gov.educ.api.institute.mapper.v1.IndependentSchoolFundingGroupMapper; +import ca.bc.gov.educ.api.institute.model.v1.IndependentSchoolFundingGroupEntity; +import ca.bc.gov.educ.api.institute.model.v1.IndependentSchoolFundingGroupHistoryEntity; +import ca.bc.gov.educ.api.institute.repository.v1.IndependentSchoolFundingGroupHistoryRepository; +import ca.bc.gov.educ.api.institute.repository.v1.IndependentSchoolFundingGroupRepository; +import ca.bc.gov.educ.api.institute.struct.v1.IndependentSchoolFundingGroup; +import ca.bc.gov.educ.api.institute.util.TransformUtil; +import lombok.AccessLevel; +import lombok.Getter; +import org.springframework.beans.BeanUtils; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Propagation; +import org.springframework.transaction.annotation.Transactional; + +import java.util.List; +import java.util.Optional; +import java.util.UUID; + +@Service +public class IndependentSchoolFundingGroupService { + + @Getter(AccessLevel.PRIVATE) + private final IndependentSchoolFundingGroupRepository independentSchoolFundingGroupRepository; + private final IndependentSchoolFundingGroupHistoryRepository independentSchoolFundingGroupHistoryRepository; + private static final IndependentSchoolFundingGroupMapper independentSchoolFundingGroupMapper = IndependentSchoolFundingGroupMapper.mapper; + + @Autowired + public IndependentSchoolFundingGroupService(IndependentSchoolFundingGroupRepository independentSchoolFundingGroupRepository, IndependentSchoolFundingGroupHistoryRepository independentSchoolFundingGroupHistoryRepository) { + this.independentSchoolFundingGroupRepository = independentSchoolFundingGroupRepository; + this.independentSchoolFundingGroupHistoryRepository = independentSchoolFundingGroupHistoryRepository; + } + + public Optional getIndependentSchoolFundingGroup(UUID schoolFundingGroupID) { + return independentSchoolFundingGroupRepository.findById(schoolFundingGroupID); + } + + public List getIndependentSchoolFundingGroups(UUID schoolID) { + return independentSchoolFundingGroupRepository.findAllBySchoolID(schoolID); + } + + public List getIndependentSchoolFundingGroupHistory(UUID schoolID) { + return independentSchoolFundingGroupHistoryRepository.findAllBySchoolID(schoolID); + } + + @Transactional(propagation = Propagation.REQUIRES_NEW) + public IndependentSchoolFundingGroupEntity createIndependentSchoolFundingGroup(IndependentSchoolFundingGroup independentSchoolFundingGroup) { + IndependentSchoolFundingGroupEntity independentSchoolFundingGroupEntity = IndependentSchoolFundingGroupMapper.mapper.toModel(independentSchoolFundingGroup); + TransformUtil.uppercaseFields(independentSchoolFundingGroupEntity); + + var savedEntity = independentSchoolFundingGroupRepository.save(independentSchoolFundingGroupEntity); + IndependentSchoolFundingGroupHistoryEntity historyEntity = getIndependentSchoolFundingGroupHistoryEntity(savedEntity); + independentSchoolFundingGroupHistoryRepository.save(historyEntity); + + return savedEntity; + } + + private static IndependentSchoolFundingGroupHistoryEntity getIndependentSchoolFundingGroupHistoryEntity(IndependentSchoolFundingGroupEntity savedEntity) { + IndependentSchoolFundingGroupHistoryEntity historyEntity = new IndependentSchoolFundingGroupHistoryEntity(); + historyEntity.setSchoolFundingGroupID(savedEntity.getSchoolFundingGroupID()); + historyEntity.setSchoolID(savedEntity.getSchoolID()); + historyEntity.setSchoolGradeCode(savedEntity.getSchoolGradeCode()); + historyEntity.setSchoolFundingGroupCode(savedEntity.getSchoolFundingGroupCode()); + historyEntity.setCreateUser(savedEntity.getCreateUser()); + historyEntity.setCreateDate(savedEntity.getCreateDate()); + historyEntity.setUpdateUser(savedEntity.getUpdateUser()); + historyEntity.setUpdateDate(savedEntity.getUpdateDate()); + return historyEntity; + } + + @Transactional(propagation = Propagation.REQUIRES_NEW) + public void deleteIndependentSchoolFundingGroup(UUID schoolFundingGroupID) { + Optional entityOptional = independentSchoolFundingGroupRepository.findById(schoolFundingGroupID); + IndependentSchoolFundingGroupEntity entity = entityOptional.orElseThrow(() -> new EntityNotFoundException(IndependentSchoolFundingGroupEntity.class, "schoolFundingGroupID", schoolFundingGroupID.toString())); + independentSchoolFundingGroupRepository.delete(entity); + } + + @Transactional(propagation = Propagation.REQUIRES_NEW) + public IndependentSchoolFundingGroupEntity updateIndependentSchoolFundingGroup(IndependentSchoolFundingGroup independentSchoolFundingGroup) { + Optional independentSchoolFundingGroupEntity = independentSchoolFundingGroupRepository.findById(UUID.fromString(independentSchoolFundingGroup.getSchoolFundingGroupID())); + + if(independentSchoolFundingGroupEntity.isEmpty()) { + throw new EntityNotFoundException(IndependentSchoolFundingGroupEntity.class, "IndependentSchoolFundingGroupEntity", independentSchoolFundingGroup.getSchoolFundingGroupID()); + } + + var curIndependentSchoolFundingGroupEntity = independentSchoolFundingGroupEntity.get(); + var incomingIndependentSchoolFundingGroupEntity = independentSchoolFundingGroupMapper.toModel(independentSchoolFundingGroup); + BeanUtils.copyProperties(incomingIndependentSchoolFundingGroupEntity, curIndependentSchoolFundingGroupEntity, "schoolFundingGroupID, schoolID, createUser, createDate"); + TransformUtil.uppercaseFields(curIndependentSchoolFundingGroupEntity); + + var savedEntity = independentSchoolFundingGroupRepository.save(curIndependentSchoolFundingGroupEntity); + IndependentSchoolFundingGroupHistoryEntity historyEntity = getIndependentSchoolFundingGroupHistoryEntity(savedEntity); + independentSchoolFundingGroupHistoryRepository.save(historyEntity); + + return savedEntity; + } + +} diff --git a/api/src/main/java/ca/bc/gov/educ/api/institute/struct/v1/IndependentSchoolFundingGroup.java b/api/src/main/java/ca/bc/gov/educ/api/institute/struct/v1/IndependentSchoolFundingGroup.java new file mode 100644 index 00000000..029fa515 --- /dev/null +++ b/api/src/main/java/ca/bc/gov/educ/api/institute/struct/v1/IndependentSchoolFundingGroup.java @@ -0,0 +1,31 @@ +package ca.bc.gov.educ.api.institute.struct.v1; + +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import jakarta.validation.constraints.NotNull; +import lombok.Data; +import lombok.EqualsAndHashCode; +import lombok.NoArgsConstructor; +import lombok.ToString; + +import java.io.Serializable; + +@Data +@NoArgsConstructor +@JsonIgnoreProperties(ignoreUnknown = true) +@EqualsAndHashCode(callSuper = true) +@ToString(callSuper = true) +@SuppressWarnings("squid:S1700") +public class IndependentSchoolFundingGroup extends BaseRequest implements Serializable { + private static final long serialVersionUID = 1L; + + private String schoolFundingGroupID; + + @NotNull(message = "schoolID cannot be null") + private String schoolID; + + @NotNull(message = "schoolGradeCode cannot be null") + private String schoolGradeCode; + + @NotNull(message = "schoolFundingGroupCode cannot be null") + private String schoolFundingGroupCode; +} diff --git a/api/src/main/java/ca/bc/gov/educ/api/institute/struct/v1/IndependentSchoolFundingGroupHistory.java b/api/src/main/java/ca/bc/gov/educ/api/institute/struct/v1/IndependentSchoolFundingGroupHistory.java new file mode 100644 index 00000000..6f9b3bf3 --- /dev/null +++ b/api/src/main/java/ca/bc/gov/educ/api/institute/struct/v1/IndependentSchoolFundingGroupHistory.java @@ -0,0 +1,33 @@ +package ca.bc.gov.educ.api.institute.struct.v1; + +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import jakarta.validation.constraints.NotNull; +import lombok.Data; +import lombok.EqualsAndHashCode; +import lombok.NoArgsConstructor; +import lombok.ToString; + +import java.io.Serializable; + +@Data +@NoArgsConstructor +@JsonIgnoreProperties(ignoreUnknown = true) +@EqualsAndHashCode(callSuper = true) +@ToString(callSuper = true) +@SuppressWarnings("squid:S1700") +public class IndependentSchoolFundingGroupHistory extends BaseRequest implements Serializable { + private static final long serialVersionUID = 1L; + + private String schoolFundingGroupHistoryID; + + private String schoolFundingGroupID; + + @NotNull(message = "schoolID cannot be null") + private String schoolID; + + @NotNull(message = "schoolGradeCode cannot be null") + private String schoolGradeCode; + + @NotNull(message = "schoolFundingGroupCode cannot be null") + private String schoolFundingGroupCode; +} diff --git a/api/src/main/java/ca/bc/gov/educ/api/institute/struct/v1/SchoolFundingGroupCode.java b/api/src/main/java/ca/bc/gov/educ/api/institute/struct/v1/SchoolFundingGroupCode.java new file mode 100644 index 00000000..32d11a3f --- /dev/null +++ b/api/src/main/java/ca/bc/gov/educ/api/institute/struct/v1/SchoolFundingGroupCode.java @@ -0,0 +1,30 @@ +package ca.bc.gov.educ.api.institute.struct.v1; + +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; + +import java.io.Serializable; + +@Data +@AllArgsConstructor +@NoArgsConstructor +@Builder +@SuppressWarnings("squid:S1700") +public class SchoolFundingGroupCode implements Serializable { + + private static final long serialVersionUID = 6118916290604876032L; + + private String schoolFundingGroupCode; + + private String label; + + private String description; + + private Integer displayOrder; + + private String effectiveDate; + + private String expiryDate; +} diff --git a/api/src/main/java/ca/bc/gov/educ/api/institute/util/ValidationUtil.java b/api/src/main/java/ca/bc/gov/educ/api/institute/util/ValidationUtil.java new file mode 100644 index 00000000..51801d93 --- /dev/null +++ b/api/src/main/java/ca/bc/gov/educ/api/institute/util/ValidationUtil.java @@ -0,0 +1,33 @@ +package ca.bc.gov.educ.api.institute.util; + + +import ca.bc.gov.educ.api.institute.exception.InvalidPayloadException; +import ca.bc.gov.educ.api.institute.exception.errors.ApiError; +import lombok.val; +import org.springframework.validation.FieldError; + +import java.time.LocalDateTime; +import java.util.List; +import java.util.function.Supplier; + +import static org.springframework.http.HttpStatus.BAD_REQUEST; + +public class ValidationUtil { + + private ValidationUtil(){ + + } + + public static FieldError createFieldError(String fieldName, Object rejectedValue, String message) { + return new FieldError("sdcSchoolCollection", fieldName, rejectedValue, false, null, null, message); + } + + public static void validatePayload(Supplier> validator) { + val validationResult = validator.get(); + if (!validationResult.isEmpty()) { + ApiError error = ApiError.builder().timestamp(LocalDateTime.now()).message("Payload contains invalid data.").status(BAD_REQUEST).build(); + error.addValidationErrors(validationResult); + throw new InvalidPayloadException(error); + } + } +} diff --git a/api/src/main/java/ca/bc/gov/educ/api/institute/validator/IndependentSchoolFundingGroupPayloadValidator.java b/api/src/main/java/ca/bc/gov/educ/api/institute/validator/IndependentSchoolFundingGroupPayloadValidator.java new file mode 100644 index 00000000..5c29f74b --- /dev/null +++ b/api/src/main/java/ca/bc/gov/educ/api/institute/validator/IndependentSchoolFundingGroupPayloadValidator.java @@ -0,0 +1,68 @@ +package ca.bc.gov.educ.api.institute.validator; + +import ca.bc.gov.educ.api.institute.model.v1.SchoolFundingGroupCodeEntity; +import ca.bc.gov.educ.api.institute.model.v1.SchoolGradeCodeEntity; +import ca.bc.gov.educ.api.institute.repository.v1.SchoolRepository; +import ca.bc.gov.educ.api.institute.service.v1.CodeTableService; +import ca.bc.gov.educ.api.institute.service.v1.IndependentSchoolFundingGroupService; +import ca.bc.gov.educ.api.institute.struct.v1.IndependentSchoolFundingGroup; +import ca.bc.gov.educ.api.institute.util.ValidationUtil; +import lombok.AccessLevel; +import lombok.Getter; +import org.apache.commons.lang3.StringUtils; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Component; +import org.springframework.validation.FieldError; + +import java.util.ArrayList; +import java.util.List; +import java.util.UUID; + +@Component +public class IndependentSchoolFundingGroupPayloadValidator { + + @Getter(AccessLevel.PRIVATE) + private final IndependentSchoolFundingGroupService independentSchoolFundingGroupService; + + @Getter(AccessLevel.PRIVATE) + private final CodeTableService codeTableService; + private final SchoolRepository schoolRepository; + + + @Autowired + public IndependentSchoolFundingGroupPayloadValidator(final IndependentSchoolFundingGroupService independentSchoolFundingGroupService, final CodeTableService codeTableService, SchoolRepository schoolRepository) { + this.independentSchoolFundingGroupService = independentSchoolFundingGroupService; + this.codeTableService = codeTableService; + this.schoolRepository = schoolRepository; + } + + public List validatePayload(IndependentSchoolFundingGroup independentSchoolFundingGroup, boolean isCreateOperation) { + final List apiValidationErrors = new ArrayList<>(); + if (isCreateOperation && independentSchoolFundingGroup.getSchoolFundingGroupID() != null) { + apiValidationErrors.add(ValidationUtil.createFieldError("schoolFundingGroupID", independentSchoolFundingGroup.getSchoolFundingGroupID(), "schoolFundingGroupID should be null for post operation.")); + } + if (independentSchoolFundingGroup.getSchoolID() != null && !schoolRepository.findById(UUID.fromString(independentSchoolFundingGroup.getSchoolID())).isPresent()) { + apiValidationErrors.add(ValidationUtil.createFieldError("schoolID", independentSchoolFundingGroup.getSchoolID(), "schoolID was not found")); + } + validateCollectionCodePayload(independentSchoolFundingGroup, apiValidationErrors); + + return apiValidationErrors; + } + + public List validateCreatePayload(IndependentSchoolFundingGroup independentSchoolFundingGroup) { + return validatePayload(independentSchoolFundingGroup, true); + } + + protected void validateCollectionCodePayload(IndependentSchoolFundingGroup independentSchoolFundingGroup, List apiValidationErrors) { + List schoolFundingGroupCodes = codeTableService.getAllSchoolFundingGroupCodes(); + if (StringUtils.isNotEmpty(independentSchoolFundingGroup.getSchoolFundingGroupCode()) && schoolFundingGroupCodes.stream().noneMatch(fundingGroupCode -> fundingGroupCode.getSchoolFundingGroupCode().equals(independentSchoolFundingGroup.getSchoolFundingGroupCode()))) { + apiValidationErrors.add(ValidationUtil.createFieldError("schoolFundingGroupCode", independentSchoolFundingGroup.getSchoolFundingGroupCode(), "Invalid School Funding Group Code.")); + } + + List schoolGradeCodes = codeTableService.getSchoolGradeCodesList(); + if (StringUtils.isNotEmpty(independentSchoolFundingGroup.getSchoolGradeCode()) && schoolGradeCodes.stream().noneMatch(gradeCode -> gradeCode.getSchoolGradeCode().equals(independentSchoolFundingGroup.getSchoolGradeCode()))) { + apiValidationErrors.add(ValidationUtil.createFieldError("schoolGradeCode", independentSchoolFundingGroup.getSchoolGradeCode(), "Invalid School Grade Code.")); + } + } + +} diff --git a/api/src/main/resources/db/migration/V1.0.23__INSTITUTE_API.sql b/api/src/main/resources/db/migration/V1.0.23__INSTITUTE_API.sql new file mode 100644 index 00000000..2cd0aaed --- /dev/null +++ b/api/src/main/resources/db/migration/V1.0.23__INSTITUTE_API.sql @@ -0,0 +1,98 @@ +CREATE TABLE INDEPENDENT_SCHOOL_FUNDING_GROUP +( + SCHOOL_FUNDING_GROUP_ID UUID NOT NULL, + SCHOOL_ID UUID NOT NULL, + SCHOOL_GRADE_CODE VARCHAR(10) NOT NULL, + SCHOOL_FUNDING_GROUP_CODE VARCHAR(10) NOT NULL, + CREATE_USER VARCHAR(100) NOT NULL, + CREATE_DATE TIMESTAMP DEFAULT CURRENT_TIMESTAMP NOT NULL, + UPDATE_USER VARCHAR(100) NOT NULL, + UPDATE_DATE TIMESTAMP DEFAULT CURRENT_TIMESTAMP NOT NULL, + CONSTRAINT SCHOOL_FUNDING_GROUP_ID_PK PRIMARY KEY (SCHOOL_FUNDING_GROUP_ID) +); + +CREATE TABLE INDEPENDENT_SCHOOL_FUNDING_GROUP_HISTORY +( + SCHOOL_FUNDING_GROUP_HISTORY_ID UUID NOT NULL, + SCHOOL_FUNDING_GROUP_ID UUID NOT NULL, + SCHOOL_ID UUID NOT NULL, + SCHOOL_GRADE_CODE VARCHAR(10) NOT NULL, + SCHOOL_FUNDING_GROUP_CODE VARCHAR(10) NOT NULL, + CREATE_USER VARCHAR(100) NOT NULL, + CREATE_DATE TIMESTAMP DEFAULT CURRENT_TIMESTAMP NOT NULL, + UPDATE_USER VARCHAR(100) NOT NULL, + UPDATE_DATE TIMESTAMP DEFAULT CURRENT_TIMESTAMP NOT NULL, + CONSTRAINT SCHOOL_FUNDING_GROUP_HISTORY_ID_PK PRIMARY KEY (SCHOOL_FUNDING_GROUP_HISTORY_ID) +); + +CREATE TABLE SCHOOL_FUNDING_GROUP_CODE +( + SCHOOL_FUNDING_GROUP_CODE VARCHAR(10) NOT NULL, + LABEL VARCHAR(30) NOT NULL, + DESCRIPTION VARCHAR(255) NOT NULL, + LEGACY_CODE VARCHAR(10), + DISPLAY_ORDER NUMERIC DEFAULT 1 NOT NULL, + EFFECTIVE_DATE TIMESTAMP NOT NULL, + EXPIRY_DATE TIMESTAMP NOT NULL, + CREATE_USER VARCHAR(32) NOT NULL, + CREATE_DATE TIMESTAMP DEFAULT CURRENT_TIMESTAMP NOT NULL, + UPDATE_USER VARCHAR(32) NOT NULL, + UPDATE_DATE TIMESTAMP DEFAULT CURRENT_TIMESTAMP NOT NULL, + CONSTRAINT SCHOOL_FUNDING_GROUP_CODE_PK PRIMARY KEY (SCHOOL_FUNDING_GROUP_CODE) +); + +ALTER TABLE INDEPENDENT_SCHOOL_FUNDING_GROUP + ADD CONSTRAINT FK_SCHOOL_FUNDING_FUNDING_CODE FOREIGN KEY (SCHOOL_FUNDING_GROUP_CODE) + REFERENCES SCHOOL_FUNDING_GROUP_CODE (SCHOOL_FUNDING_GROUP_CODE); + +ALTER TABLE INDEPENDENT_SCHOOL_FUNDING_GROUP + ADD CONSTRAINT FK_SCHOOL_FUNDING_GRADE_CODE FOREIGN KEY (SCHOOL_GRADE_CODE) + REFERENCES SCHOOL_GRADE_CODE (SCHOOL_GRADE_CODE); + +ALTER TABLE INDEPENDENT_SCHOOL_FUNDING_GROUP_HISTORY + ADD CONSTRAINT FK_SCHOOL_FUNDING_HISTORY_FUNDING_ID FOREIGN KEY (SCHOOL_FUNDING_GROUP_ID) + REFERENCES INDEPENDENT_SCHOOL_FUNDING_GROUP (SCHOOL_FUNDING_GROUP_ID); + +ALTER TABLE INDEPENDENT_SCHOOL_FUNDING_GROUP_HISTORY + ADD CONSTRAINT FK_SCHOOL_FUNDING_HISTORY_FUNDING_CODE FOREIGN KEY (SCHOOL_FUNDING_GROUP_CODE) + REFERENCES SCHOOL_FUNDING_GROUP_CODE (SCHOOL_FUNDING_GROUP_CODE); + +ALTER TABLE INDEPENDENT_SCHOOL_FUNDING_GROUP_HISTORY + ADD CONSTRAINT FK_SCHOOL_FUNDING_HISTORY_GRADE_CODE FOREIGN KEY (SCHOOL_GRADE_CODE) + REFERENCES SCHOOL_GRADE_CODE (SCHOOL_GRADE_CODE); + +INSERT INTO SCHOOL_FUNDING_GROUP_CODE (LEGACY_CODE, SCHOOL_FUNDING_GROUP_CODE, LABEL, DESCRIPTION, + DISPLAY_ORDER, EFFECTIVE_DATE, EXPIRY_DATE, CREATE_USER, + CREATE_DATE, UPDATE_USER, UPDATE_DATE) +VALUES ('01', 'GROUP1', 'Group 1', 'Group 1 Funding Group', 1, + to_date('2020-01-01 00:00:00', 'YYYY-MM-DD HH24:MI:SS'), + to_date('2099-12-31 00:00:00', 'YYYY-MM-DD HH24:MI:SS'), 'IDIR/MVILLENE', + to_date('2019-12-20 00:00:00', 'YYYY-MM-DD HH24:MI:SS'), 'IDIR/MVILLENE', + to_date('2019-12-20 00:00:00', 'YYYY-MM-DD HH24:MI:SS')); + +INSERT INTO SCHOOL_FUNDING_GROUP_CODE (LEGACY_CODE, SCHOOL_FUNDING_GROUP_CODE, LABEL, DESCRIPTION, + DISPLAY_ORDER, EFFECTIVE_DATE, EXPIRY_DATE, CREATE_USER, + CREATE_DATE, UPDATE_USER, UPDATE_DATE) +VALUES ('02', 'GROUP2', 'Group 2', 'Group 2 Funding Group', 2, + to_date('2020-01-01 00:00:00', 'YYYY-MM-DD HH24:MI:SS'), + to_date('2099-12-31 00:00:00', 'YYYY-MM-DD HH24:MI:SS'), 'IDIR/MVILLENE', + to_date('2019-12-20 00:00:00', 'YYYY-MM-DD HH24:MI:SS'), 'IDIR/MVILLENE', + to_date('2019-12-20 00:00:00', 'YYYY-MM-DD HH24:MI:SS')); + +INSERT INTO SCHOOL_FUNDING_GROUP_CODE (LEGACY_CODE, SCHOOL_FUNDING_GROUP_CODE, LABEL, DESCRIPTION, + DISPLAY_ORDER, EFFECTIVE_DATE, EXPIRY_DATE, CREATE_USER, + CREATE_DATE, UPDATE_USER, UPDATE_DATE) +VALUES ('03', 'GROUP3', 'Group 3', 'Group 3 Funding Group', 3, + to_date('2020-01-01 00:00:00', 'YYYY-MM-DD HH24:MI:SS'), + to_date('2099-12-31 00:00:00', 'YYYY-MM-DD HH24:MI:SS'), 'IDIR/MVILLENE', + to_date('2019-12-20 00:00:00', 'YYYY-MM-DD HH24:MI:SS'), 'IDIR/MVILLENE', + to_date('2019-12-20 00:00:00', 'YYYY-MM-DD HH24:MI:SS')); + +INSERT INTO SCHOOL_FUNDING_GROUP_CODE (LEGACY_CODE, SCHOOL_FUNDING_GROUP_CODE, LABEL, DESCRIPTION, + DISPLAY_ORDER, EFFECTIVE_DATE, EXPIRY_DATE, CREATE_USER, + CREATE_DATE, UPDATE_USER, UPDATE_DATE) +VALUES ('04', 'GROUP4', 'Group 4', 'Group 4 Funding Group', 4, + to_date('2020-01-01 00:00:00', 'YYYY-MM-DD HH24:MI:SS'), + to_date('2099-12-31 00:00:00', 'YYYY-MM-DD HH24:MI:SS'), 'IDIR/MVILLENE', + to_date('2019-12-20 00:00:00', 'YYYY-MM-DD HH24:MI:SS'), 'IDIR/MVILLENE', + to_date('2019-12-20 00:00:00', 'YYYY-MM-DD HH24:MI:SS')); diff --git a/api/src/main/resources/scripts/SPM_Migration_4 - Independent School Funding Groups.sql b/api/src/main/resources/scripts/SPM_Migration_4 - Independent School Funding Groups.sql new file mode 100644 index 00000000..2b392ba4 --- /dev/null +++ b/api/src/main/resources/scripts/SPM_Migration_4 - Independent School Funding Groups.sql @@ -0,0 +1,320 @@ +--UPDATE THE DATES LISTED "CHANGEME" to the current date + +ALTER SESSION SET NLS_TIMESTAMP_FORMAT = 'YYYY-MM-DD HH24:MI:SS.FF6'; +ALTER SESSION SET NLS_DATE_FORMAT = 'YYYY-MM-DD HH24:MI:SS'; + +CREATE TABLE SCHOOL_FUNDING_GROUP_CODE +( + SCHOOL_FUNDING_GROUP_CODE VARCHAR(10) NOT NULL, + LABEL VARCHAR(30) NOT NULL, + DESCRIPTION VARCHAR(255) NOT NULL, + LEGACY_CODE VARCHAR(10), + DISPLAY_ORDER NUMERIC DEFAULT 1 NOT NULL, + EFFECTIVE_DATE TIMESTAMP NOT NULL, + EXPIRY_DATE TIMESTAMP NOT NULL, + CREATE_USER VARCHAR(32) NOT NULL, + CREATE_DATE TIMESTAMP DEFAULT CURRENT_TIMESTAMP NOT NULL, + UPDATE_USER VARCHAR(32) NOT NULL, + UPDATE_DATE TIMESTAMP DEFAULT CURRENT_TIMESTAMP NOT NULL, + CONSTRAINT SCHOOL_FUNDING_GROUP_CODE_PK PRIMARY KEY (SCHOOL_FUNDING_GROUP_CODE) +); + +INSERT INTO SCHOOL_FUNDING_GROUP_CODE (LEGACY_CODE, SCHOOL_FUNDING_GROUP_CODE, LABEL, DESCRIPTION, + DISPLAY_ORDER, EFFECTIVE_DATE, EXPIRY_DATE, CREATE_USER, + CREATE_DATE, UPDATE_USER, UPDATE_DATE) +VALUES ('01', 'GROUP1', 'Group 1', 'Group 1 Funding Group', 1, + to_date('2020-01-01 00:00:00', 'YYYY-MM-DD HH24:MI:SS'), + to_date('2099-12-31 00:00:00', 'YYYY-MM-DD HH24:MI:SS'), 'IDIR/MVILLENE', + to_date('2019-12-20 00:00:00', 'YYYY-MM-DD HH24:MI:SS'), 'IDIR/MVILLENE', + to_date('2019-12-20 00:00:00', 'YYYY-MM-DD HH24:MI:SS')); + +INSERT INTO SCHOOL_FUNDING_GROUP_CODE (LEGACY_CODE, SCHOOL_FUNDING_GROUP_CODE, LABEL, DESCRIPTION, + DISPLAY_ORDER, EFFECTIVE_DATE, EXPIRY_DATE, CREATE_USER, + CREATE_DATE, UPDATE_USER, UPDATE_DATE) +VALUES ('02', 'GROUP2', 'Group 2', 'Group 2 Funding Group', 2, + to_date('2020-01-01 00:00:00', 'YYYY-MM-DD HH24:MI:SS'), + to_date('2099-12-31 00:00:00', 'YYYY-MM-DD HH24:MI:SS'), 'IDIR/MVILLENE', + to_date('2019-12-20 00:00:00', 'YYYY-MM-DD HH24:MI:SS'), 'IDIR/MVILLENE', + to_date('2019-12-20 00:00:00', 'YYYY-MM-DD HH24:MI:SS')); + +INSERT INTO SCHOOL_FUNDING_GROUP_CODE (LEGACY_CODE, SCHOOL_FUNDING_GROUP_CODE, LABEL, DESCRIPTION, + DISPLAY_ORDER, EFFECTIVE_DATE, EXPIRY_DATE, CREATE_USER, + CREATE_DATE, UPDATE_USER, UPDATE_DATE) +VALUES ('03', 'GROUP3', 'Group 3', 'Group 3 Funding Group', 3, + to_date('2020-01-01 00:00:00', 'YYYY-MM-DD HH24:MI:SS'), + to_date('2099-12-31 00:00:00', 'YYYY-MM-DD HH24:MI:SS'), 'IDIR/MVILLENE', + to_date('2019-12-20 00:00:00', 'YYYY-MM-DD HH24:MI:SS'), 'IDIR/MVILLENE', + to_date('2019-12-20 00:00:00', 'YYYY-MM-DD HH24:MI:SS')); + +INSERT INTO SCHOOL_FUNDING_GROUP_CODE (LEGACY_CODE, SCHOOL_FUNDING_GROUP_CODE, LABEL, DESCRIPTION, + DISPLAY_ORDER, EFFECTIVE_DATE, EXPIRY_DATE, CREATE_USER, + CREATE_DATE, UPDATE_USER, UPDATE_DATE) +VALUES ('04', 'GROUP4', 'Group 4', 'Group 4 Funding Group', 4, + to_date('2020-01-01 00:00:00', 'YYYY-MM-DD HH24:MI:SS'), + to_date('2099-12-31 00:00:00', 'YYYY-MM-DD HH24:MI:SS'), 'IDIR/MVILLENE', + to_date('2019-12-20 00:00:00', 'YYYY-MM-DD HH24:MI:SS'), 'IDIR/MVILLENE', + to_date('2019-12-20 00:00:00', 'YYYY-MM-DD HH24:MI:SS')); + +INSERT INTO SCHOOL_FUNDING_GROUP_CODE (LEGACY_CODE, SCHOOL_FUNDING_GROUP_CODE, LABEL, DESCRIPTION, + DISPLAY_ORDER, EFFECTIVE_DATE, EXPIRY_DATE, CREATE_USER, + CREATE_DATE, UPDATE_USER, UPDATE_DATE) +VALUES ('05', 'GROUP5', 'Group 5', 'Group 5 Funding Group', 5, + to_date('2020-01-01 00:00:00', 'YYYY-MM-DD HH24:MI:SS'), + to_date('2021-01-01 00:00:00', 'YYYY-MM-DD HH24:MI:SS'), 'IDIR/MVILLENE', + to_date('2019-12-20 00:00:00', 'YYYY-MM-DD HH24:MI:SS'), 'IDIR/MVILLENE', + to_date('2019-12-20 00:00:00', 'YYYY-MM-DD HH24:MI:SS')); + +INSERT INTO SCHOOL_FUNDING_GROUP_CODE (LEGACY_CODE, SCHOOL_FUNDING_GROUP_CODE, LABEL, DESCRIPTION, + DISPLAY_ORDER, EFFECTIVE_DATE, EXPIRY_DATE, CREATE_USER, + CREATE_DATE, UPDATE_USER, UPDATE_DATE) +VALUES ('06', 'GROUP6', 'Group 6', 'Group 6 Funding Group', 6, + to_date('2020-01-01 00:00:00', 'YYYY-MM-DD HH24:MI:SS'), + to_date('2021-01-01 00:00:00', 'YYYY-MM-DD HH24:MI:SS'), 'IDIR/MVILLENE', + to_date('2019-12-20 00:00:00', 'YYYY-MM-DD HH24:MI:SS'), 'IDIR/MVILLENE', + to_date('2019-12-20 00:00:00', 'YYYY-MM-DD HH24:MI:SS')); + +INSERT INTO SCHOOL_FUNDING_GROUP_CODE (LEGACY_CODE, SCHOOL_FUNDING_GROUP_CODE, LABEL, DESCRIPTION, + DISPLAY_ORDER, EFFECTIVE_DATE, EXPIRY_DATE, CREATE_USER, + CREATE_DATE, UPDATE_USER, UPDATE_DATE) +VALUES ('07', 'GROUP7', 'Group 7', 'Group 7 Funding Group', 7, + to_date('2020-01-01 00:00:00', 'YYYY-MM-DD HH24:MI:SS'), + to_date('2021-01-01 00:00:00', 'YYYY-MM-DD HH24:MI:SS'), 'IDIR/MVILLENE', + to_date('2019-12-20 00:00:00', 'YYYY-MM-DD HH24:MI:SS'), 'IDIR/MVILLENE', + to_date('2019-12-20 00:00:00', 'YYYY-MM-DD HH24:MI:SS')); + +CREATE TABLE INDEPENDENT_SCHOOL_FUNDING_GROUP +( + SCHOOL_FUNDING_GROUP_ID VARCHAR(255) NOT NULL, + SCHOOL_ID VARCHAR(255) NOT NULL, + SCHOOL_GRADE_CODE VARCHAR(10) NOT NULL, + SCHOOL_FUNDING_GROUP_CODE VARCHAR(10) NOT NULL, + CREATE_USER VARCHAR(32) NOT NULL, + CREATE_DATE TIMESTAMP DEFAULT CURRENT_TIMESTAMP NOT NULL, + UPDATE_USER VARCHAR(32) NOT NULL, + UPDATE_DATE TIMESTAMP DEFAULT CURRENT_TIMESTAMP NOT NULL, + CONSTRAINT SCHOOL_FUNDING_GROUP_ID_PK PRIMARY KEY (SCHOOL_FUNDING_GROUP_ID) +); + +INSERT INTO INDEPENDENT_SCHOOL_FUNDING_GROUP (SCHOOL_FUNDING_GROUP_ID, SCHOOL_ID, SCHOOL_GRADE_CODE, SCHOOL_FUNDING_GROUP_CODE, CREATE_USER, CREATE_DATE, UPDATE_USER, UPDATE_DATE) +SELECT + LOWER(REGEXP_REPLACE(dbms_crypto.randombytes(16), '(.{8})(.{4})(.{4})(.{4})(.{12})', '\1-\2-\3-\4-\5')) as SCHOOL_FUNDING_GROUP_ID, + (SELECT schl.SCHOOL_ID from SCHOOL schl WHERE fund_mast.SCHLNO = schl.SCHOOL_NUMBER AND fund_mast.DISTNO = (SELECT dist.DISTRICT_NUMBER from DISTRICT dist WHERE schl.DISTRICT_ID = dist.DISTRICT_ID)) as SCHOOL_ID, + (SELECT grade_code_tbl.SCHOOL_GRADE_CODE from SCHOOL_GRADE_CODE grade_code_tbl where grade_code_tbl.LEGACY_CODE = 'KH') as SCHOOL_GRADE_CODE, + (SELECT fund_code_tbl.SCHOOL_FUNDING_GROUP_CODE from SCHOOL_FUNDING_GROUP_CODE fund_code_tbl where fund_code_tbl.LEGACY_CODE = fund_mast.FUNDING_GROUP_CODE) as SCHOOL_FUNDING_GROUP_CODE, + 'SLD_MIGRATION' as CREATE_USER, + sysdate as CREATE_DATE, + 'SLD_MIGRATION' as UPDATE_USER, + sysdate as UPDATE_DATE +FROM SCHOOL_FUNDING_MASTER fund_mast, SCHOOL schl_table +WHERE fund_mast.FUNDING_GROUP_SUBCODE = '01' +AND fund_mast.SCHLNO = schl_table.SCHOOL_NUMBER AND fund_mast.DISTNO = (SELECT dist.DISTRICT_NUMBER from DISTRICT dist WHERE schl_table.DISTRICT_ID = dist.DISTRICT_ID); + +INSERT INTO INDEPENDENT_SCHOOL_FUNDING_GROUP (SCHOOL_FUNDING_GROUP_ID, SCHOOL_ID, SCHOOL_GRADE_CODE, SCHOOL_FUNDING_GROUP_CODE, CREATE_USER, CREATE_DATE, UPDATE_USER, UPDATE_DATE) +SELECT + LOWER(REGEXP_REPLACE(dbms_crypto.randombytes(16), '(.{8})(.{4})(.{4})(.{4})(.{12})', '\1-\2-\3-\4-\5')) as SCHOOL_FUNDING_GROUP_ID, + (SELECT schl.SCHOOL_ID from SCHOOL schl WHERE fund_mast.SCHLNO = schl.SCHOOL_NUMBER AND fund_mast.DISTNO = (SELECT dist.DISTRICT_NUMBER from DISTRICT dist WHERE schl.DISTRICT_ID = dist.DISTRICT_ID)) as SCHOOL_ID, + (SELECT grade_code_tbl.SCHOOL_GRADE_CODE from SCHOOL_GRADE_CODE grade_code_tbl where grade_code_tbl.LEGACY_CODE = 'KF') as SCHOOL_GRADE_CODE, + (SELECT fund_code_tbl.SCHOOL_FUNDING_GROUP_CODE from SCHOOL_FUNDING_GROUP_CODE fund_code_tbl where fund_code_tbl.LEGACY_CODE = fund_mast.FUNDING_GROUP_CODE) as SCHOOL_FUNDING_GROUP_CODE, + 'SLD_MIGRATION' as CREATE_USER, + sysdate as CREATE_DATE, + 'SLD_MIGRATION' as UPDATE_USER, + sysdate as UPDATE_DATE +FROM SCHOOL_FUNDING_MASTER fund_mast, SCHOOL schl_table +WHERE fund_mast.FUNDING_GROUP_SUBCODE = '01' +AND fund_mast.SCHLNO = schl_table.SCHOOL_NUMBER AND fund_mast.DISTNO = (SELECT dist.DISTRICT_NUMBER from DISTRICT dist WHERE schl_table.DISTRICT_ID = dist.DISTRICT_ID); + +INSERT INTO INDEPENDENT_SCHOOL_FUNDING_GROUP (SCHOOL_FUNDING_GROUP_ID, SCHOOL_ID, SCHOOL_GRADE_CODE, SCHOOL_FUNDING_GROUP_CODE, CREATE_USER, CREATE_DATE, UPDATE_USER, UPDATE_DATE) +SELECT + LOWER(REGEXP_REPLACE(dbms_crypto.randombytes(16), '(.{8})(.{4})(.{4})(.{4})(.{12})', '\1-\2-\3-\4-\5')) as SCHOOL_FUNDING_GROUP_ID, + (SELECT schl.SCHOOL_ID from SCHOOL schl WHERE fund_mast.SCHLNO = schl.SCHOOL_NUMBER AND fund_mast.DISTNO = (SELECT dist.DISTRICT_NUMBER from DISTRICT dist WHERE schl.DISTRICT_ID = dist.DISTRICT_ID)) as SCHOOL_ID, + (SELECT grade_code_tbl.SCHOOL_GRADE_CODE from SCHOOL_GRADE_CODE grade_code_tbl where grade_code_tbl.LEGACY_CODE = '01') as SCHOOL_GRADE_CODE, + (SELECT fund_code_tbl.SCHOOL_FUNDING_GROUP_CODE from SCHOOL_FUNDING_GROUP_CODE fund_code_tbl where fund_code_tbl.LEGACY_CODE = fund_mast.FUNDING_GROUP_CODE) as SCHOOL_FUNDING_GROUP_CODE, + 'SLD_MIGRATION' as CREATE_USER, + sysdate as CREATE_DATE, + 'SLD_MIGRATION' as UPDATE_USER, + sysdate as UPDATE_DATE +FROM SCHOOL_FUNDING_MASTER fund_mast, SCHOOL schl_table +WHERE fund_mast.FUNDING_GROUP_SUBCODE = '01' +AND fund_mast.SCHLNO = schl_table.SCHOOL_NUMBER AND fund_mast.DISTNO = (SELECT dist.DISTRICT_NUMBER from DISTRICT dist WHERE schl_table.DISTRICT_ID = dist.DISTRICT_ID); + +INSERT INTO INDEPENDENT_SCHOOL_FUNDING_GROUP (SCHOOL_FUNDING_GROUP_ID, SCHOOL_ID, SCHOOL_GRADE_CODE, SCHOOL_FUNDING_GROUP_CODE, CREATE_USER, CREATE_DATE, UPDATE_USER, UPDATE_DATE) +SELECT + LOWER(REGEXP_REPLACE(dbms_crypto.randombytes(16), '(.{8})(.{4})(.{4})(.{4})(.{12})', '\1-\2-\3-\4-\5')) as SCHOOL_FUNDING_GROUP_ID, + (SELECT schl.SCHOOL_ID from SCHOOL schl WHERE fund_mast.SCHLNO = schl.SCHOOL_NUMBER AND fund_mast.DISTNO = (SELECT dist.DISTRICT_NUMBER from DISTRICT dist WHERE schl.DISTRICT_ID = dist.DISTRICT_ID)) as SCHOOL_ID, + (SELECT grade_code_tbl.SCHOOL_GRADE_CODE from SCHOOL_GRADE_CODE grade_code_tbl where grade_code_tbl.LEGACY_CODE = '02') as SCHOOL_GRADE_CODE, + (SELECT fund_code_tbl.SCHOOL_FUNDING_GROUP_CODE from SCHOOL_FUNDING_GROUP_CODE fund_code_tbl where fund_code_tbl.LEGACY_CODE = fund_mast.FUNDING_GROUP_CODE) as SCHOOL_FUNDING_GROUP_CODE, + 'SLD_MIGRATION' as CREATE_USER, + sysdate as CREATE_DATE, + 'SLD_MIGRATION' as UPDATE_USER, + sysdate as UPDATE_DATE +FROM SCHOOL_FUNDING_MASTER fund_mast, SCHOOL schl_table +WHERE fund_mast.FUNDING_GROUP_SUBCODE = '01' +AND fund_mast.SCHLNO = schl_table.SCHOOL_NUMBER AND fund_mast.DISTNO = (SELECT dist.DISTRICT_NUMBER from DISTRICT dist WHERE schl_table.DISTRICT_ID = dist.DISTRICT_ID); + +INSERT INTO INDEPENDENT_SCHOOL_FUNDING_GROUP (SCHOOL_FUNDING_GROUP_ID, SCHOOL_ID, SCHOOL_GRADE_CODE, SCHOOL_FUNDING_GROUP_CODE, CREATE_USER, CREATE_DATE, UPDATE_USER, UPDATE_DATE) +SELECT + LOWER(REGEXP_REPLACE(dbms_crypto.randombytes(16), '(.{8})(.{4})(.{4})(.{4})(.{12})', '\1-\2-\3-\4-\5')) as SCHOOL_FUNDING_GROUP_ID, + (SELECT schl.SCHOOL_ID from SCHOOL schl WHERE fund_mast.SCHLNO = schl.SCHOOL_NUMBER AND fund_mast.DISTNO = (SELECT dist.DISTRICT_NUMBER from DISTRICT dist WHERE schl.DISTRICT_ID = dist.DISTRICT_ID)) as SCHOOL_ID, + (SELECT grade_code_tbl.SCHOOL_GRADE_CODE from SCHOOL_GRADE_CODE grade_code_tbl where grade_code_tbl.LEGACY_CODE = '03') as SCHOOL_GRADE_CODE, + (SELECT fund_code_tbl.SCHOOL_FUNDING_GROUP_CODE from SCHOOL_FUNDING_GROUP_CODE fund_code_tbl where fund_code_tbl.LEGACY_CODE = fund_mast.FUNDING_GROUP_CODE) as SCHOOL_FUNDING_GROUP_CODE, + 'SLD_MIGRATION' as CREATE_USER, + sysdate as CREATE_DATE, + 'SLD_MIGRATION' as UPDATE_USER, + sysdate as UPDATE_DATE +FROM SCHOOL_FUNDING_MASTER fund_mast, SCHOOL schl_table +WHERE fund_mast.FUNDING_GROUP_SUBCODE = '01' +AND fund_mast.SCHLNO = schl_table.SCHOOL_NUMBER AND fund_mast.DISTNO = (SELECT dist.DISTRICT_NUMBER from DISTRICT dist WHERE schl_table.DISTRICT_ID = dist.DISTRICT_ID); + +INSERT INTO INDEPENDENT_SCHOOL_FUNDING_GROUP (SCHOOL_FUNDING_GROUP_ID, SCHOOL_ID, SCHOOL_GRADE_CODE, SCHOOL_FUNDING_GROUP_CODE, CREATE_USER, CREATE_DATE, UPDATE_USER, UPDATE_DATE) +SELECT + LOWER(REGEXP_REPLACE(dbms_crypto.randombytes(16), '(.{8})(.{4})(.{4})(.{4})(.{12})', '\1-\2-\3-\4-\5')) as SCHOOL_FUNDING_GROUP_ID, + (SELECT schl.SCHOOL_ID from SCHOOL schl WHERE fund_mast.SCHLNO = schl.SCHOOL_NUMBER AND fund_mast.DISTNO = (SELECT dist.DISTRICT_NUMBER from DISTRICT dist WHERE schl.DISTRICT_ID = dist.DISTRICT_ID)) as SCHOOL_ID, + (SELECT grade_code_tbl.SCHOOL_GRADE_CODE from SCHOOL_GRADE_CODE grade_code_tbl where grade_code_tbl.LEGACY_CODE = '04') as SCHOOL_GRADE_CODE, + (SELECT fund_code_tbl.SCHOOL_FUNDING_GROUP_CODE from SCHOOL_FUNDING_GROUP_CODE fund_code_tbl where fund_code_tbl.LEGACY_CODE = fund_mast.FUNDING_GROUP_CODE) as SCHOOL_FUNDING_GROUP_CODE, + 'SLD_MIGRATION' as CREATE_USER, + sysdate as CREATE_DATE, + 'SLD_MIGRATION' as UPDATE_USER, + sysdate as UPDATE_DATE +FROM SCHOOL_FUNDING_MASTER fund_mast, SCHOOL schl_table +WHERE fund_mast.FUNDING_GROUP_SUBCODE = '04' +AND fund_mast.SCHLNO = schl_table.SCHOOL_NUMBER AND fund_mast.DISTNO = (SELECT dist.DISTRICT_NUMBER from DISTRICT dist WHERE schl_table.DISTRICT_ID = dist.DISTRICT_ID); + +INSERT INTO INDEPENDENT_SCHOOL_FUNDING_GROUP (SCHOOL_FUNDING_GROUP_ID, SCHOOL_ID, SCHOOL_GRADE_CODE, SCHOOL_FUNDING_GROUP_CODE, CREATE_USER, CREATE_DATE, UPDATE_USER, UPDATE_DATE) +SELECT + LOWER(REGEXP_REPLACE(dbms_crypto.randombytes(16), '(.{8})(.{4})(.{4})(.{4})(.{12})', '\1-\2-\3-\4-\5')) as SCHOOL_FUNDING_GROUP_ID, + (SELECT schl.SCHOOL_ID from SCHOOL schl WHERE fund_mast.SCHLNO = schl.SCHOOL_NUMBER AND fund_mast.DISTNO = (SELECT dist.DISTRICT_NUMBER from DISTRICT dist WHERE schl.DISTRICT_ID = dist.DISTRICT_ID)) as SCHOOL_ID, + (SELECT grade_code_tbl.SCHOOL_GRADE_CODE from SCHOOL_GRADE_CODE grade_code_tbl where grade_code_tbl.LEGACY_CODE = '05') as SCHOOL_GRADE_CODE, + (SELECT fund_code_tbl.SCHOOL_FUNDING_GROUP_CODE from SCHOOL_FUNDING_GROUP_CODE fund_code_tbl where fund_code_tbl.LEGACY_CODE = fund_mast.FUNDING_GROUP_CODE) as SCHOOL_FUNDING_GROUP_CODE, + 'SLD_MIGRATION' as CREATE_USER, + sysdate as CREATE_DATE, + 'SLD_MIGRATION' as UPDATE_USER, + sysdate as UPDATE_DATE +FROM SCHOOL_FUNDING_MASTER fund_mast, SCHOOL schl_table +WHERE fund_mast.FUNDING_GROUP_SUBCODE = '04' +AND fund_mast.SCHLNO = schl_table.SCHOOL_NUMBER AND fund_mast.DISTNO = (SELECT dist.DISTRICT_NUMBER from DISTRICT dist WHERE schl_table.DISTRICT_ID = dist.DISTRICT_ID); + +INSERT INTO INDEPENDENT_SCHOOL_FUNDING_GROUP (SCHOOL_FUNDING_GROUP_ID, SCHOOL_ID, SCHOOL_GRADE_CODE, SCHOOL_FUNDING_GROUP_CODE, CREATE_USER, CREATE_DATE, UPDATE_USER, UPDATE_DATE) +SELECT + LOWER(REGEXP_REPLACE(dbms_crypto.randombytes(16), '(.{8})(.{4})(.{4})(.{4})(.{12})', '\1-\2-\3-\4-\5')) as SCHOOL_FUNDING_GROUP_ID, + (SELECT schl.SCHOOL_ID from SCHOOL schl WHERE fund_mast.SCHLNO = schl.SCHOOL_NUMBER AND fund_mast.DISTNO = (SELECT dist.DISTRICT_NUMBER from DISTRICT dist WHERE schl.DISTRICT_ID = dist.DISTRICT_ID)) as SCHOOL_ID, + (SELECT grade_code_tbl.SCHOOL_GRADE_CODE from SCHOOL_GRADE_CODE grade_code_tbl where grade_code_tbl.LEGACY_CODE = '06') as SCHOOL_GRADE_CODE, + (SELECT fund_code_tbl.SCHOOL_FUNDING_GROUP_CODE from SCHOOL_FUNDING_GROUP_CODE fund_code_tbl where fund_code_tbl.LEGACY_CODE = fund_mast.FUNDING_GROUP_CODE) as SCHOOL_FUNDING_GROUP_CODE, + 'SLD_MIGRATION' as CREATE_USER, + sysdate as CREATE_DATE, + 'SLD_MIGRATION' as UPDATE_USER, + sysdate as UPDATE_DATE +FROM SCHOOL_FUNDING_MASTER fund_mast, SCHOOL schl_table +WHERE fund_mast.FUNDING_GROUP_SUBCODE = '04' +AND fund_mast.SCHLNO = schl_table.SCHOOL_NUMBER AND fund_mast.DISTNO = (SELECT dist.DISTRICT_NUMBER from DISTRICT dist WHERE schl_table.DISTRICT_ID = dist.DISTRICT_ID); + +INSERT INTO INDEPENDENT_SCHOOL_FUNDING_GROUP (SCHOOL_FUNDING_GROUP_ID, SCHOOL_ID, SCHOOL_GRADE_CODE, SCHOOL_FUNDING_GROUP_CODE, CREATE_USER, CREATE_DATE, UPDATE_USER, UPDATE_DATE) +SELECT + LOWER(REGEXP_REPLACE(dbms_crypto.randombytes(16), '(.{8})(.{4})(.{4})(.{4})(.{12})', '\1-\2-\3-\4-\5')) as SCHOOL_FUNDING_GROUP_ID, + (SELECT schl.SCHOOL_ID from SCHOOL schl WHERE fund_mast.SCHLNO = schl.SCHOOL_NUMBER AND fund_mast.DISTNO = (SELECT dist.DISTRICT_NUMBER from DISTRICT dist WHERE schl.DISTRICT_ID = dist.DISTRICT_ID)) as SCHOOL_ID, + (SELECT grade_code_tbl.SCHOOL_GRADE_CODE from SCHOOL_GRADE_CODE grade_code_tbl where grade_code_tbl.LEGACY_CODE = '07') as SCHOOL_GRADE_CODE, + (SELECT fund_code_tbl.SCHOOL_FUNDING_GROUP_CODE from SCHOOL_FUNDING_GROUP_CODE fund_code_tbl where fund_code_tbl.LEGACY_CODE = fund_mast.FUNDING_GROUP_CODE) as SCHOOL_FUNDING_GROUP_CODE, + 'SLD_MIGRATION' as CREATE_USER, + sysdate as CREATE_DATE, + 'SLD_MIGRATION' as UPDATE_USER, + sysdate as UPDATE_DATE +FROM SCHOOL_FUNDING_MASTER fund_mast, SCHOOL schl_table +WHERE fund_mast.FUNDING_GROUP_SUBCODE = '04' +AND fund_mast.SCHLNO = schl_table.SCHOOL_NUMBER AND fund_mast.DISTNO = (SELECT dist.DISTRICT_NUMBER from DISTRICT dist WHERE schl_table.DISTRICT_ID = dist.DISTRICT_ID); + +INSERT INTO INDEPENDENT_SCHOOL_FUNDING_GROUP (SCHOOL_FUNDING_GROUP_ID, SCHOOL_ID, SCHOOL_GRADE_CODE, SCHOOL_FUNDING_GROUP_CODE, CREATE_USER, CREATE_DATE, UPDATE_USER, UPDATE_DATE) +SELECT + LOWER(REGEXP_REPLACE(dbms_crypto.randombytes(16), '(.{8})(.{4})(.{4})(.{4})(.{12})', '\1-\2-\3-\4-\5')) as SCHOOL_FUNDING_GROUP_ID, + (SELECT schl.SCHOOL_ID from SCHOOL schl WHERE fund_mast.SCHLNO = schl.SCHOOL_NUMBER AND fund_mast.DISTNO = (SELECT dist.DISTRICT_NUMBER from DISTRICT dist WHERE schl.DISTRICT_ID = dist.DISTRICT_ID)) as SCHOOL_ID, + (SELECT grade_code_tbl.SCHOOL_GRADE_CODE from SCHOOL_GRADE_CODE grade_code_tbl where grade_code_tbl.LEGACY_CODE = 'EU') as SCHOOL_GRADE_CODE, + (SELECT fund_code_tbl.SCHOOL_FUNDING_GROUP_CODE from SCHOOL_FUNDING_GROUP_CODE fund_code_tbl where fund_code_tbl.LEGACY_CODE = fund_mast.FUNDING_GROUP_CODE) as SCHOOL_FUNDING_GROUP_CODE, + 'SLD_MIGRATION' as CREATE_USER, + sysdate as CREATE_DATE, + 'SLD_MIGRATION' as UPDATE_USER, + sysdate as UPDATE_DATE +FROM SCHOOL_FUNDING_MASTER fund_mast, SCHOOL schl_table +WHERE fund_mast.FUNDING_GROUP_SUBCODE = '04' +AND fund_mast.SCHLNO = schl_table.SCHOOL_NUMBER AND fund_mast.DISTNO = (SELECT dist.DISTRICT_NUMBER from DISTRICT dist WHERE schl_table.DISTRICT_ID = dist.DISTRICT_ID); + +INSERT INTO INDEPENDENT_SCHOOL_FUNDING_GROUP (SCHOOL_FUNDING_GROUP_ID, SCHOOL_ID, SCHOOL_GRADE_CODE, SCHOOL_FUNDING_GROUP_CODE, CREATE_USER, CREATE_DATE, UPDATE_USER, UPDATE_DATE) +SELECT + LOWER(REGEXP_REPLACE(dbms_crypto.randombytes(16), '(.{8})(.{4})(.{4})(.{4})(.{12})', '\1-\2-\3-\4-\5')) as SCHOOL_FUNDING_GROUP_ID, + (SELECT schl.SCHOOL_ID from SCHOOL schl WHERE fund_mast.SCHLNO = schl.SCHOOL_NUMBER AND fund_mast.DISTNO = (SELECT dist.DISTRICT_NUMBER from DISTRICT dist WHERE schl.DISTRICT_ID = dist.DISTRICT_ID)) as SCHOOL_ID, + (SELECT grade_code_tbl.SCHOOL_GRADE_CODE from SCHOOL_GRADE_CODE grade_code_tbl where grade_code_tbl.LEGACY_CODE = '08') as SCHOOL_GRADE_CODE, + (SELECT fund_code_tbl.SCHOOL_FUNDING_GROUP_CODE from SCHOOL_FUNDING_GROUP_CODE fund_code_tbl where fund_code_tbl.LEGACY_CODE = fund_mast.FUNDING_GROUP_CODE) as SCHOOL_FUNDING_GROUP_CODE, + 'SLD_MIGRATION' as CREATE_USER, + sysdate as CREATE_DATE, + 'SLD_MIGRATION' as UPDATE_USER, + sysdate as UPDATE_DATE +FROM SCHOOL_FUNDING_MASTER fund_mast, SCHOOL schl_table +WHERE fund_mast.FUNDING_GROUP_SUBCODE = '08' +AND fund_mast.SCHLNO = schl_table.SCHOOL_NUMBER AND fund_mast.DISTNO = (SELECT dist.DISTRICT_NUMBER from DISTRICT dist WHERE schl_table.DISTRICT_ID = dist.DISTRICT_ID); + +INSERT INTO INDEPENDENT_SCHOOL_FUNDING_GROUP (SCHOOL_FUNDING_GROUP_ID, SCHOOL_ID, SCHOOL_GRADE_CODE, SCHOOL_FUNDING_GROUP_CODE, CREATE_USER, CREATE_DATE, UPDATE_USER, UPDATE_DATE) +SELECT + LOWER(REGEXP_REPLACE(dbms_crypto.randombytes(16), '(.{8})(.{4})(.{4})(.{4})(.{12})', '\1-\2-\3-\4-\5')) as SCHOOL_FUNDING_GROUP_ID, + (SELECT schl.SCHOOL_ID from SCHOOL schl WHERE fund_mast.SCHLNO = schl.SCHOOL_NUMBER AND fund_mast.DISTNO = (SELECT dist.DISTRICT_NUMBER from DISTRICT dist WHERE schl.DISTRICT_ID = dist.DISTRICT_ID)) as SCHOOL_ID, + (SELECT grade_code_tbl.SCHOOL_GRADE_CODE from SCHOOL_GRADE_CODE grade_code_tbl where grade_code_tbl.LEGACY_CODE = '09') as SCHOOL_GRADE_CODE, + (SELECT fund_code_tbl.SCHOOL_FUNDING_GROUP_CODE from SCHOOL_FUNDING_GROUP_CODE fund_code_tbl where fund_code_tbl.LEGACY_CODE = fund_mast.FUNDING_GROUP_CODE) as SCHOOL_FUNDING_GROUP_CODE, + 'SLD_MIGRATION' as CREATE_USER, + sysdate as CREATE_DATE, + 'SLD_MIGRATION' as UPDATE_USER, + sysdate as UPDATE_DATE +FROM SCHOOL_FUNDING_MASTER fund_mast, SCHOOL schl_table +WHERE fund_mast.FUNDING_GROUP_SUBCODE = '08' +AND fund_mast.SCHLNO = schl_table.SCHOOL_NUMBER AND fund_mast.DISTNO = (SELECT dist.DISTRICT_NUMBER from DISTRICT dist WHERE schl_table.DISTRICT_ID = dist.DISTRICT_ID); + +INSERT INTO INDEPENDENT_SCHOOL_FUNDING_GROUP (SCHOOL_FUNDING_GROUP_ID, SCHOOL_ID, SCHOOL_GRADE_CODE, SCHOOL_FUNDING_GROUP_CODE, CREATE_USER, CREATE_DATE, UPDATE_USER, UPDATE_DATE) +SELECT + LOWER(REGEXP_REPLACE(dbms_crypto.randombytes(16), '(.{8})(.{4})(.{4})(.{4})(.{12})', '\1-\2-\3-\4-\5')) as SCHOOL_FUNDING_GROUP_ID, + (SELECT schl.SCHOOL_ID from SCHOOL schl WHERE fund_mast.SCHLNO = schl.SCHOOL_NUMBER AND fund_mast.DISTNO = (SELECT dist.DISTRICT_NUMBER from DISTRICT dist WHERE schl.DISTRICT_ID = dist.DISTRICT_ID)) as SCHOOL_ID, + (SELECT grade_code_tbl.SCHOOL_GRADE_CODE from SCHOOL_GRADE_CODE grade_code_tbl where grade_code_tbl.LEGACY_CODE = '10') as SCHOOL_GRADE_CODE, + (SELECT fund_code_tbl.SCHOOL_FUNDING_GROUP_CODE from SCHOOL_FUNDING_GROUP_CODE fund_code_tbl where fund_code_tbl.LEGACY_CODE = fund_mast.FUNDING_GROUP_CODE) as SCHOOL_FUNDING_GROUP_CODE, + 'SLD_MIGRATION' as CREATE_USER, + sysdate as CREATE_DATE, + 'SLD_MIGRATION' as UPDATE_USER, + sysdate as UPDATE_DATE +FROM SCHOOL_FUNDING_MASTER fund_mast, SCHOOL schl_table +WHERE fund_mast.FUNDING_GROUP_SUBCODE = '08' +AND fund_mast.SCHLNO = schl_table.SCHOOL_NUMBER AND fund_mast.DISTNO = (SELECT dist.DISTRICT_NUMBER from DISTRICT dist WHERE schl_table.DISTRICT_ID = dist.DISTRICT_ID); + +INSERT INTO INDEPENDENT_SCHOOL_FUNDING_GROUP (SCHOOL_FUNDING_GROUP_ID, SCHOOL_ID, SCHOOL_GRADE_CODE, SCHOOL_FUNDING_GROUP_CODE, CREATE_USER, CREATE_DATE, UPDATE_USER, UPDATE_DATE) +SELECT + LOWER(REGEXP_REPLACE(dbms_crypto.randombytes(16), '(.{8})(.{4})(.{4})(.{4})(.{12})', '\1-\2-\3-\4-\5')) as SCHOOL_FUNDING_GROUP_ID, + (SELECT schl.SCHOOL_ID from SCHOOL schl WHERE fund_mast.SCHLNO = schl.SCHOOL_NUMBER AND fund_mast.DISTNO = (SELECT dist.DISTRICT_NUMBER from DISTRICT dist WHERE schl.DISTRICT_ID = dist.DISTRICT_ID)) as SCHOOL_ID, + (SELECT grade_code_tbl.SCHOOL_GRADE_CODE from SCHOOL_GRADE_CODE grade_code_tbl where grade_code_tbl.LEGACY_CODE = 'SU') as SCHOOL_GRADE_CODE, + (SELECT fund_code_tbl.SCHOOL_FUNDING_GROUP_CODE from SCHOOL_FUNDING_GROUP_CODE fund_code_tbl where fund_code_tbl.LEGACY_CODE = fund_mast.FUNDING_GROUP_CODE) as SCHOOL_FUNDING_GROUP_CODE, + 'SLD_MIGRATION' as CREATE_USER, + sysdate as CREATE_DATE, + 'SLD_MIGRATION' as UPDATE_USER, + sysdate as UPDATE_DATE +FROM SCHOOL_FUNDING_MASTER fund_mast, SCHOOL schl_table +WHERE fund_mast.FUNDING_GROUP_SUBCODE = '08' +AND fund_mast.SCHLNO = schl_table.SCHOOL_NUMBER AND fund_mast.DISTNO = (SELECT dist.DISTRICT_NUMBER from DISTRICT dist WHERE schl_table.DISTRICT_ID = dist.DISTRICT_ID); + +INSERT INTO INDEPENDENT_SCHOOL_FUNDING_GROUP (SCHOOL_FUNDING_GROUP_ID, SCHOOL_ID, SCHOOL_GRADE_CODE, SCHOOL_FUNDING_GROUP_CODE, CREATE_USER, CREATE_DATE, UPDATE_USER, UPDATE_DATE) +SELECT + LOWER(REGEXP_REPLACE(dbms_crypto.randombytes(16), '(.{8})(.{4})(.{4})(.{4})(.{12})', '\1-\2-\3-\4-\5')) as SCHOOL_FUNDING_GROUP_ID, + (SELECT schl.SCHOOL_ID from SCHOOL schl WHERE fund_mast.SCHLNO = schl.SCHOOL_NUMBER AND fund_mast.DISTNO = (SELECT dist.DISTRICT_NUMBER from DISTRICT dist WHERE schl.DISTRICT_ID = dist.DISTRICT_ID)) as SCHOOL_ID, + (SELECT grade_code_tbl.SCHOOL_GRADE_CODE from SCHOOL_GRADE_CODE grade_code_tbl where grade_code_tbl.LEGACY_CODE = '11') as SCHOOL_GRADE_CODE, + (SELECT fund_code_tbl.SCHOOL_FUNDING_GROUP_CODE from SCHOOL_FUNDING_GROUP_CODE fund_code_tbl where fund_code_tbl.LEGACY_CODE = fund_mast.FUNDING_GROUP_CODE) as SCHOOL_FUNDING_GROUP_CODE, + 'SLD_MIGRATION' as CREATE_USER, + sysdate as CREATE_DATE, + 'SLD_MIGRATION' as UPDATE_USER, + sysdate as UPDATE_DATE +FROM SCHOOL_FUNDING_MASTER fund_mast, SCHOOL schl_table +WHERE fund_mast.FUNDING_GROUP_SUBCODE = '11' +AND fund_mast.SCHLNO = schl_table.SCHOOL_NUMBER AND fund_mast.DISTNO = (SELECT dist.DISTRICT_NUMBER from DISTRICT dist WHERE schl_table.DISTRICT_ID = dist.DISTRICT_ID); + +INSERT INTO INDEPENDENT_SCHOOL_FUNDING_GROUP (SCHOOL_FUNDING_GROUP_ID, SCHOOL_ID, SCHOOL_GRADE_CODE, SCHOOL_FUNDING_GROUP_CODE, CREATE_USER, CREATE_DATE, UPDATE_USER, UPDATE_DATE) +SELECT + LOWER(REGEXP_REPLACE(dbms_crypto.randombytes(16), '(.{8})(.{4})(.{4})(.{4})(.{12})', '\1-\2-\3-\4-\5')) as SCHOOL_FUNDING_GROUP_ID, + (SELECT schl.SCHOOL_ID from SCHOOL schl WHERE fund_mast.SCHLNO = schl.SCHOOL_NUMBER AND fund_mast.DISTNO = (SELECT dist.DISTRICT_NUMBER from DISTRICT dist WHERE schl.DISTRICT_ID = dist.DISTRICT_ID)) as SCHOOL_ID, + (SELECT grade_code_tbl.SCHOOL_GRADE_CODE from SCHOOL_GRADE_CODE grade_code_tbl where grade_code_tbl.LEGACY_CODE = '12') as SCHOOL_GRADE_CODE, + (SELECT fund_code_tbl.SCHOOL_FUNDING_GROUP_CODE from SCHOOL_FUNDING_GROUP_CODE fund_code_tbl where fund_code_tbl.LEGACY_CODE = fund_mast.FUNDING_GROUP_CODE) as SCHOOL_FUNDING_GROUP_CODE, + 'SLD_MIGRATION' as CREATE_USER, + sysdate as CREATE_DATE, + 'SLD_MIGRATION' as UPDATE_USER, + sysdate as UPDATE_DATE +FROM SCHOOL_FUNDING_MASTER fund_mast, SCHOOL schl_table +WHERE fund_mast.FUNDING_GROUP_SUBCODE = '11' +AND fund_mast.SCHLNO = schl_table.SCHOOL_NUMBER AND fund_mast.DISTNO = (SELECT dist.DISTRICT_NUMBER from DISTRICT dist WHERE schl_table.DISTRICT_ID = dist.DISTRICT_ID); diff --git a/api/src/test/java/ca/bc/gov/educ/api/institute/controller/v1/CodeTableControllerTest.java b/api/src/test/java/ca/bc/gov/educ/api/institute/controller/v1/CodeTableControllerTest.java index 1d5c1aba..4c4de2f4 100644 --- a/api/src/test/java/ca/bc/gov/educ/api/institute/controller/v1/CodeTableControllerTest.java +++ b/api/src/test/java/ca/bc/gov/educ/api/institute/controller/v1/CodeTableControllerTest.java @@ -198,7 +198,7 @@ private NeighborhoodLearningTypeCodeEntity createNeighborhoodLearningTypeCodeDat } private SchoolGradeCodeEntity createSchoolGradeCodeData() { - return SchoolGradeCodeEntity.builder().schoolGradeCode("01").description("First Grade") + return SchoolGradeCodeEntity.builder().schoolGradeCode("GRADE01").description("First Grade") .effectiveDate(LocalDateTime.now()).expiryDate(LocalDateTime.MAX).displayOrder(1).label("First").createDate(LocalDateTime.now()) .updateDate(LocalDateTime.now()).createUser("TEST").updateUser("TEST").build(); } @@ -272,7 +272,7 @@ public void testGetSchoolGradeCodes_ShouldReturnCodes() throws Exception { final GrantedAuthority grantedAuthority = () -> "SCOPE_READ_INSTITUTE_CODES"; final var mockAuthority = oidcLogin().authorities(grantedAuthority); this.mockMvc.perform(get(URL.BASE_URL + URL.GRADE_CODES).with(mockAuthority)).andDo(print()).andExpect(status().isOk()) - .andExpect(MockMvcResultMatchers.jsonPath("$[0].schoolGradeCode").value("01")); + .andExpect(MockMvcResultMatchers.jsonPath("$[0].schoolGradeCode").value("GRADE01")); } @Test diff --git a/api/src/test/java/ca/bc/gov/educ/api/institute/controller/v1/DistrictControllerTest.java b/api/src/test/java/ca/bc/gov/educ/api/institute/controller/v1/DistrictControllerTest.java index 487a41be..9392c048 100644 --- a/api/src/test/java/ca/bc/gov/educ/api/institute/controller/v1/DistrictControllerTest.java +++ b/api/src/test/java/ca/bc/gov/educ/api/institute/controller/v1/DistrictControllerTest.java @@ -92,6 +92,9 @@ public class DistrictControllerTest { @Autowired CountryCodeRepository countryCodeRepository; + @Autowired + SchoolRepository schoolRepository; + @BeforeEach public void setUp() { MockitoAnnotations.openMocks(this); @@ -115,6 +118,7 @@ public void after() { this.addressRepository.deleteAll(); this.districtContactRepository.deleteAll(); this.noteRepository.deleteAll(); + this.schoolRepository.deleteAll(); this.districtRepository.deleteAll(); this.districtHistoryRepository.deleteAll(); this.districtRegionCodeRepository.deleteAll(); diff --git a/api/src/test/java/ca/bc/gov/educ/api/institute/controller/v1/IndependentSchoolFundingGroupControllerTest.java b/api/src/test/java/ca/bc/gov/educ/api/institute/controller/v1/IndependentSchoolFundingGroupControllerTest.java new file mode 100644 index 00000000..ce4a82d5 --- /dev/null +++ b/api/src/test/java/ca/bc/gov/educ/api/institute/controller/v1/IndependentSchoolFundingGroupControllerTest.java @@ -0,0 +1,370 @@ +package ca.bc.gov.educ.api.institute.controller.v1; + +import ca.bc.gov.educ.api.institute.InstituteApiResourceApplication; +import ca.bc.gov.educ.api.institute.constants.v1.URL; +import ca.bc.gov.educ.api.institute.model.v1.*; +import ca.bc.gov.educ.api.institute.repository.v1.*; +import ca.bc.gov.educ.api.institute.struct.v1.IndependentSchoolFundingGroup; +import ca.bc.gov.educ.api.institute.struct.v1.IndependentSchoolFundingGroupHistory; +import com.fasterxml.jackson.core.type.TypeReference; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.SerializationFeature; +import com.fasterxml.jackson.databind.json.JsonMapper; +import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule; +import lombok.val; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.mockito.MockitoAnnotations; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.http.MediaType; +import org.springframework.security.core.GrantedAuthority; +import org.springframework.security.test.web.servlet.request.SecurityMockMvcRequestPostProcessors.OidcLoginRequestPostProcessor; +import org.springframework.test.context.ActiveProfiles; +import org.springframework.test.web.servlet.MockMvc; +import org.springframework.test.web.servlet.result.MockMvcResultMatchers; + +import java.time.LocalDateTime; +import java.util.List; +import java.util.UUID; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.hamcrest.Matchers.equalTo; +import static org.springframework.security.test.web.servlet.request.SecurityMockMvcRequestPostProcessors.oidcLogin; +import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.*; +import static org.springframework.test.web.servlet.result.MockMvcResultHandlers.print; +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; + +@SpringBootTest(classes = {InstituteApiResourceApplication.class}) +@ActiveProfiles("test") +@AutoConfigureMockMvc +class IndependentSchoolFundingGroupControllerTest { + + @Autowired + private MockMvc mockMvc; + @Autowired + IndependentSchoolFundingGroupController independentSchoolFundingGroupController; + @Autowired + IndependentSchoolFundingGroupRepository independentSchoolFundingGroupRepository; + @Autowired + SchoolFundingGroupCodeRepository schoolFundingGroupCodeRepository; + @Autowired + SchoolGradeCodeRepository schoolGradeCodeRepository; + @Autowired + DistrictTombstoneRepository districtTombstoneRepository; + @Autowired + SchoolRepository schoolRepository; + + @BeforeEach + public void setUp() { + MockitoAnnotations.openMocks(this); + } + + protected final static ObjectMapper objectMapper = JsonMapper.builder().addModule(new JavaTimeModule()).build(); + + @BeforeEach + public void before() { + SchoolFundingGroupCodeEntity group = new SchoolFundingGroupCodeEntity(); + group.setSchoolFundingGroupCode("GROUP1"); + group.setLabel("Group 1"); + group.setDescription("Group 1"); + group.setCreateDate(LocalDateTime.now()); + group.setCreateUser("ABC"); + schoolFundingGroupCodeRepository.save(group); + + SchoolGradeCodeEntity grade = new SchoolGradeCodeEntity(); + grade.setSchoolGradeCode("GRADE01"); + grade.setLabel("Grade 1"); + grade.setDescription("Grade 1"); + grade.setCreateDate(LocalDateTime.now()); + grade.setCreateUser("ABC"); + schoolGradeCodeRepository.save(grade); + + SchoolGradeCodeEntity grade2 = new SchoolGradeCodeEntity(); + grade2.setSchoolGradeCode("GRADE02"); + grade2.setLabel("Grade 2"); + grade2.setDescription("Grade 2"); + grade2.setCreateDate(LocalDateTime.now()); + grade2.setCreateUser("ABC"); + schoolGradeCodeRepository.save(grade2); + } + + @AfterEach + public void after() { + this.schoolFundingGroupCodeRepository.deleteAll(); + this.schoolGradeCodeRepository.deleteAll(); + } + + @Test + void testGetSchoolFundingGroup_WithWrongScope_ShouldReturnForbidden() throws Exception { + final GrantedAuthority grantedAuthority = () -> "WRONG_SCOPE"; + final OidcLoginRequestPostProcessor mockAuthority = oidcLogin().authorities(grantedAuthority); + this.mockMvc.perform(get(URL.BASE_URL_SCHOOL_FUNDING + "/" + UUID.randomUUID()).with(mockAuthority)) + .andDo(print()) + .andExpect(status().isForbidden()); + } + + @Test + void testGetSchoolFundingGroup_WithWrongID_ShouldReturnStatusNotFound() throws Exception { + final GrantedAuthority grantedAuthority = () -> "SCOPE_READ_SCHOOL_FUNDING_GROUP"; + final OidcLoginRequestPostProcessor mockAuthority = oidcLogin().authorities(grantedAuthority); + this.mockMvc.perform(get(URL.BASE_URL_SCHOOL_FUNDING + "/" + UUID.randomUUID()).with(mockAuthority)) + .andDo(print()).andExpect(status().isNotFound()); + } + + @Test + void testGetSchoolFundingGroupByID_ShouldReturnFundingGroup() throws Exception { + final GrantedAuthority grantedAuthority = () -> "SCOPE_READ_SCHOOL_FUNDING_GROUP"; + final OidcLoginRequestPostProcessor mockAuthority = oidcLogin().authorities(grantedAuthority); + + final var independentSchoolFundingGroupEntity = this.independentSchoolFundingGroupRepository.save(this.createMockIndependentSchoolFundingGroupEntity(UUID.randomUUID())); + + this.mockMvc.perform( + get(URL.BASE_URL_SCHOOL_FUNDING + "/" + independentSchoolFundingGroupEntity.getSchoolFundingGroupID()).with(mockAuthority)) + .andDo(print()).andExpect(status().isOk()).andExpect( + MockMvcResultMatchers.jsonPath("$.schoolFundingGroupID", + equalTo(independentSchoolFundingGroupEntity.getSchoolFundingGroupID().toString()))); + } + + @Test + void testGetSchoolFundingGroupByCreateUser_ShouldReturnFundingGroup() throws Exception { + final GrantedAuthority grantedAuthority = () -> "SCOPE_READ_SCHOOL_FUNDING_GROUP"; + final OidcLoginRequestPostProcessor mockAuthority = oidcLogin().authorities(grantedAuthority); + + final var independentSchoolFundingGroupEntity = this.independentSchoolFundingGroupRepository.save(this.createMockIndependentSchoolFundingGroupEntity(UUID.randomUUID())); + + var resultActions = this.mockMvc.perform( + get(URL.BASE_URL_SCHOOL_FUNDING + "/search/" + independentSchoolFundingGroupEntity.getSchoolID()).with(mockAuthority)) + .andDo(print()).andExpect(status().isOk()); + + val summary = objectMapper.readValue(resultActions.andReturn().getResponse().getContentAsByteArray(), new TypeReference() { + }); + + assertThat(summary).hasSize(1); + + var independentSchoolFundingGroupEntity1 = this.createMockIndependentSchoolFundingGroupEntity(independentSchoolFundingGroupEntity.getSchoolID()); + independentSchoolFundingGroupEntity1.setSchoolGradeCode("GRADE02"); + this.independentSchoolFundingGroupRepository.save(independentSchoolFundingGroupEntity1); + + var resultActions1 = this.mockMvc.perform( + get(URL.BASE_URL_SCHOOL_FUNDING + "/search/" + independentSchoolFundingGroupEntity.getSchoolID()).with(mockAuthority)) + .andDo(print()).andExpect(status().isOk()); + + val summary1 = objectMapper.readValue(resultActions1.andReturn().getResponse().getContentAsByteArray(), new TypeReference() { + }); + + assertThat(summary1).hasSize(2); + } + + @Test + void testUpdateSchoolFundingGroupByCreateUserWithHistory_ShouldReturnFundingGroup() throws Exception { + final GrantedAuthority grantedAuthority = () -> "SCOPE_READ_SCHOOL_FUNDING_GROUP"; + final OidcLoginRequestPostProcessor mockAuthority = oidcLogin().authorities(grantedAuthority); + + final var independentSchoolFundingGroupEntity = this.independentSchoolFundingGroupRepository.save(this.createMockIndependentSchoolFundingGroupEntity(UUID.randomUUID())); + + var resultActions = this.mockMvc.perform( + get(URL.BASE_URL_SCHOOL_FUNDING + "/search/" + independentSchoolFundingGroupEntity.getSchoolID()).with(mockAuthority)) + .andDo(print()).andExpect(status().isOk()); + + val summary = objectMapper.readValue(resultActions.andReturn().getResponse().getContentAsByteArray(), new TypeReference>() { + }); + + assertThat(summary).hasSize(1); + + final DistrictTombstoneEntity dist = this.districtTombstoneRepository.save(this.createDistrictData()); + var schoolEntity = this.createSchoolData(); + schoolEntity.setDistrictEntity(dist); + final SchoolEntity entity = this.schoolRepository.save(schoolEntity); + + independentSchoolFundingGroupEntity.setSchoolGradeCode("GRADE02"); + independentSchoolFundingGroupEntity.setSchoolID(entity.getSchoolId()); + independentSchoolFundingGroupEntity.setUpdateDate(null); + independentSchoolFundingGroupEntity.setUpdateUser(null); + independentSchoolFundingGroupEntity.setCreateDate(null); + independentSchoolFundingGroupEntity.setCreateUser(null); + + final GrantedAuthority grantedAuthority2 = () -> "SCOPE_WRITE_SCHOOL_FUNDING_GROUP"; + final OidcLoginRequestPostProcessor mockAuthority2 = oidcLogin().authorities(grantedAuthority2); + + var resultActions2 = this.mockMvc.perform(put(URL.BASE_URL_SCHOOL_FUNDING + "/" + independentSchoolFundingGroupEntity.getSchoolFundingGroupID()).contentType(MediaType.APPLICATION_JSON) + .accept(MediaType.APPLICATION_JSON).content(asJsonString(independentSchoolFundingGroupEntity)).with(mockAuthority2)) + .andDo(print()).andExpect(status().isOk()); + + val summary2 = objectMapper.readValue(resultActions2.andReturn().getResponse().getContentAsByteArray(), new TypeReference() { + }); + + assertThat(summary2).isNotNull(); + assertThat(summary2.getSchoolGradeCode()).isEqualTo("GRADE02"); + + final GrantedAuthority grantedAuthority3 = () -> "SCOPE_READ_SCHOOL_FUNDING_GROUP"; + final OidcLoginRequestPostProcessor mockAuthority3 = oidcLogin().authorities(grantedAuthority3); + + var resultActions3 = this.mockMvc.perform(get(URL.BASE_URL_SCHOOL_FUNDING + "/search/" + independentSchoolFundingGroupEntity.getSchoolID() + "/history").contentType(MediaType.APPLICATION_JSON) + .accept(MediaType.APPLICATION_JSON).content(asJsonString(independentSchoolFundingGroupEntity)).with(mockAuthority3)) + .andDo(print()).andExpect(status().isOk()); + + val summary3 = objectMapper.readValue(resultActions3.andReturn().getResponse().getContentAsByteArray(), new TypeReference>() { + }); + + assertThat(summary3).hasSize(1); + } + + @Test + void testCreateSchoolFundingGroup_GivenValidPayload_ShouldReturnStatusCreated() throws Exception { + final GrantedAuthority grantedAuthority = () -> "SCOPE_WRITE_SCHOOL_FUNDING_GROUP"; + final OidcLoginRequestPostProcessor mockAuthority = oidcLogin().authorities(grantedAuthority); + + final DistrictTombstoneEntity dist = this.districtTombstoneRepository.save(this.createDistrictData()); + var schoolEntity = this.createSchoolData(); + schoolEntity.setDistrictEntity(dist); + final SchoolEntity entity = this.schoolRepository.save(schoolEntity); + + final var independentSchoolFundingGroupEntity = this.createMockIndependentSchoolFundingGroupEntity(entity.getSchoolId()); + independentSchoolFundingGroupEntity.setCreateDate(null); + independentSchoolFundingGroupEntity.setUpdateDate(null); + + this.mockMvc.perform(post(URL.BASE_URL_SCHOOL_FUNDING).contentType(MediaType.APPLICATION_JSON) + .accept(MediaType.APPLICATION_JSON).content(asJsonString(independentSchoolFundingGroupEntity)).with(mockAuthority)) + .andDo(print()).andExpect(status().isCreated()); + } + + @Test + void testCreateSchoolFundingGroup_GivenInvalidPayload_ShouldReturnStatusBadRequest() throws Exception { + final GrantedAuthority grantedAuthority = () -> "SCOPE_WRITE_SCHOOL_FUNDING_GROUP"; + final OidcLoginRequestPostProcessor mockAuthority = oidcLogin().authorities(grantedAuthority); + + final DistrictTombstoneEntity dist = this.districtTombstoneRepository.save(this.createDistrictData()); + var schoolEntity = this.createSchoolData(); + schoolEntity.setDistrictEntity(dist); + final SchoolEntity entity = this.schoolRepository.save(schoolEntity); + + final var independentSchoolFundingGroupEntity = this.createMockIndependentSchoolFundingGroupEntity(entity.getSchoolId()); + independentSchoolFundingGroupEntity.setCreateDate(null); + independentSchoolFundingGroupEntity.setUpdateDate(null); + independentSchoolFundingGroupEntity.setSchoolFundingGroupID(UUID.randomUUID()); + + this.mockMvc.perform(post(URL.BASE_URL_SCHOOL_FUNDING).contentType(MediaType.APPLICATION_JSON) + .accept(MediaType.APPLICATION_JSON).content(asJsonString(independentSchoolFundingGroupEntity)).with(mockAuthority)) + .andDo(print()).andExpect(status().isBadRequest()); + } + + @Test + void testCreateSchoolFundingGroup_GivenInValidGrade_ShouldReturnStatusBadRequest() throws Exception { + final GrantedAuthority grantedAuthority = () -> "SCOPE_WRITE_SCHOOL_FUNDING_GROUP"; + final OidcLoginRequestPostProcessor mockAuthority = oidcLogin().authorities(grantedAuthority); + + final DistrictTombstoneEntity dist = this.districtTombstoneRepository.save(this.createDistrictData()); + var schoolEntity = this.createSchoolData(); + schoolEntity.setDistrictEntity(dist); + final SchoolEntity entity = this.schoolRepository.save(schoolEntity); + + final var independentSchoolFundingGroupEntity = this.createMockIndependentSchoolFundingGroupEntity(entity.getSchoolId()); + independentSchoolFundingGroupEntity.setCreateDate(null); + independentSchoolFundingGroupEntity.setUpdateDate(null); + independentSchoolFundingGroupEntity.setSchoolGradeCode("ABC"); + + this.mockMvc.perform(post(URL.BASE_URL_SCHOOL_FUNDING).contentType(MediaType.APPLICATION_JSON) + .accept(MediaType.APPLICATION_JSON).content(asJsonString(independentSchoolFundingGroupEntity)).with(mockAuthority)) + .andDo(print()).andExpect(status().isBadRequest()); + } + + @Test + void testCreateSchoolFundingGroup_GivenInValidFundingCode_ShouldReturnStatusBadRequest() throws Exception { + final GrantedAuthority grantedAuthority = () -> "SCOPE_WRITE_SCHOOL_FUNDING_GROUP"; + final OidcLoginRequestPostProcessor mockAuthority = oidcLogin().authorities(grantedAuthority); + + final DistrictTombstoneEntity dist = this.districtTombstoneRepository.save(this.createDistrictData()); + var schoolEntity = this.createSchoolData(); + schoolEntity.setDistrictEntity(dist); + final SchoolEntity entity = this.schoolRepository.save(schoolEntity); + + final var independentSchoolFundingGroupEntity = this.createMockIndependentSchoolFundingGroupEntity(entity.getSchoolId()); + independentSchoolFundingGroupEntity.setCreateDate(null); + independentSchoolFundingGroupEntity.setUpdateDate(null); + independentSchoolFundingGroupEntity.setSchoolFundingGroupCode("ABC"); + + this.mockMvc.perform(post(URL.BASE_URL_SCHOOL_FUNDING).contentType(MediaType.APPLICATION_JSON) + .accept(MediaType.APPLICATION_JSON).content(asJsonString(independentSchoolFundingGroupEntity)).with(mockAuthority)) + .andDo(print()).andExpect(status().isBadRequest()); + } + + @Test + void testCreateSchoolFundingGroup_GivenInValidSchoolID_ShouldReturnStatusBadRequest() throws Exception { + final GrantedAuthority grantedAuthority = () -> "SCOPE_WRITE_SCHOOL_FUNDING_GROUP"; + final OidcLoginRequestPostProcessor mockAuthority = oidcLogin().authorities(grantedAuthority); + + final var independentSchoolFundingGroupEntity = this.createMockIndependentSchoolFundingGroupEntity(UUID.randomUUID()); + independentSchoolFundingGroupEntity.setCreateDate(null); + independentSchoolFundingGroupEntity.setUpdateDate(null); + + this.mockMvc.perform(post(URL.BASE_URL_SCHOOL_FUNDING).contentType(MediaType.APPLICATION_JSON) + .accept(MediaType.APPLICATION_JSON).content(asJsonString(independentSchoolFundingGroupEntity)).with(mockAuthority)) + .andDo(print()).andExpect(status().isBadRequest()); + } + + @Test + void testDeleteCollection_GivenValidPayload_ShouldReturnNoContent() throws Exception { + final GrantedAuthority grantedAuthority = () -> "SCOPE_DELETE_SCHOOL_FUNDING_GROUP"; + final OidcLoginRequestPostProcessor mockAuthority = oidcLogin().authorities(grantedAuthority); + + final var independentSchoolFundingGroupEntity = this.independentSchoolFundingGroupRepository.save(this.createMockIndependentSchoolFundingGroupEntity(UUID.randomUUID())); + + this.mockMvc.perform( + delete(URL.BASE_URL_SCHOOL_FUNDING + "/" + independentSchoolFundingGroupEntity.getSchoolFundingGroupID().toString()).contentType( + MediaType.APPLICATION_JSON) + .with(mockAuthority)) + .andDo(print()).andExpect(status().isNoContent()); + + var independentSchoolFundingGroupRepositoryAll = this.independentSchoolFundingGroupRepository.findAll(); + assertThat(independentSchoolFundingGroupRepositoryAll).isEmpty(); + } + + public IndependentSchoolFundingGroupEntity createMockIndependentSchoolFundingGroupEntity(UUID schoolID){ + IndependentSchoolFundingGroupEntity independentSchoolFundingGroupEntity = new IndependentSchoolFundingGroupEntity(); + independentSchoolFundingGroupEntity.setSchoolID(schoolID); + independentSchoolFundingGroupEntity.setSchoolFundingGroupCode("GROUP1"); + independentSchoolFundingGroupEntity.setSchoolGradeCode("GRADE01"); + independentSchoolFundingGroupEntity.setCreateUser("ABC"); + independentSchoolFundingGroupEntity.setCreateDate(LocalDateTime.now()); + independentSchoolFundingGroupEntity.setUpdateUser("ABC"); + independentSchoolFundingGroupEntity.setUpdateDate(LocalDateTime.now()); + return independentSchoolFundingGroupEntity; + } + + private DistrictTombstoneEntity createDistrictData() { + return DistrictTombstoneEntity.builder().districtNumber("003").displayName("District Name").districtStatusCode("OPEN").districtRegionCode("KOOTENAYS") + .website("abc@sd99.edu").createDate(LocalDateTime.now()).updateDate(LocalDateTime.now()).createUser("TEST").updateUser("TEST").build(); + } + + private SchoolEntity createSchoolData() { + return SchoolEntity + .builder() + .schoolNumber("12345") + .displayName("School Name") + .openedDate(LocalDateTime.now().minusDays(1).withNano(0)) + .schoolCategoryCode("PUBLIC") + .schoolOrganizationCode("TWO_SEM") + .schoolReportingRequirementCode("REGULAR") + .facilityTypeCode("DISTONLINE") + .website("abc@sd99.edu") + .createDate(LocalDateTime.now().withNano(0)) + .updateDate(LocalDateTime.now().withNano(0)) + .createUser("TEST") + .updateUser("TEST") + .build(); + } + + public static String asJsonString(final Object obj) { + try { + ObjectMapper om = new ObjectMapper(); + om.registerModule(new JavaTimeModule()).configure(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS, false); + return om.writeValueAsString(obj); + } catch (final Exception e) { + throw new RuntimeException(e); + } + } + +} diff --git a/api/src/test/java/ca/bc/gov/educ/api/institute/controller/v1/SchoolControllerTest.java b/api/src/test/java/ca/bc/gov/educ/api/institute/controller/v1/SchoolControllerTest.java index 1915d1ff..0be71315 100644 --- a/api/src/test/java/ca/bc/gov/educ/api/institute/controller/v1/SchoolControllerTest.java +++ b/api/src/test/java/ca/bc/gov/educ/api/institute/controller/v1/SchoolControllerTest.java @@ -3,7 +3,6 @@ import ca.bc.gov.educ.api.institute.InstituteApiResourceApplication; import ca.bc.gov.educ.api.institute.constants.v1.URL; import ca.bc.gov.educ.api.institute.filter.FilterOperation; -import ca.bc.gov.educ.api.institute.mapper.v1.CodeTableMapper; import ca.bc.gov.educ.api.institute.mapper.v1.SchoolMapper; import ca.bc.gov.educ.api.institute.model.v1.*; import ca.bc.gov.educ.api.institute.repository.v1.*; @@ -55,8 +54,6 @@ @AutoConfigureMockMvc public class SchoolControllerTest { protected final static ObjectMapper objectMapper = new ObjectMapper(); - private static final CodeTableMapper mapper = CodeTableMapper.mapper; - private static final SchoolMapper schoolMapper = SchoolMapper.mapper; @Autowired private MockMvc mockMvc; diff --git a/api/target/classes/META-INF/spring.components b/api/target/classes/META-INF/spring.components index d06ca987..05517670 100644 --- a/api/target/classes/META-INF/spring.components +++ b/api/target/classes/META-INF/spring.components @@ -1,5 +1,4 @@ ca.bc.gov.educ.api.institute.InstituteApiResourceApplication=org.springframework.stereotype.Component,org.springframework.boot.SpringBootConfiguration -ca.bc.gov.educ.api.institute.InstituteApiResourceApplication$WebSecurityConfiguration=org.springframework.stereotype.Component ca.bc.gov.educ.api.institute.adapter.CustomRequestBodyAdviceAdapter=org.springframework.stereotype.Component ca.bc.gov.educ.api.institute.config.AsyncConfiguration=org.springframework.stereotype.Component ca.bc.gov.educ.api.institute.config.InstituteAPIMVCConfig=org.springframework.stereotype.Component @@ -7,6 +6,7 @@ ca.bc.gov.educ.api.institute.config.RequestResponseInterceptor=org.springframewo ca.bc.gov.educ.api.institute.controller.v1.CodeTableAPIController=org.springframework.stereotype.Component ca.bc.gov.educ.api.institute.controller.v1.DistrictAPIController=org.springframework.stereotype.Component ca.bc.gov.educ.api.institute.controller.v1.IndependentAuthorityAPIController=org.springframework.stereotype.Component +ca.bc.gov.educ.api.institute.controller.v1.IndependentSchoolFundingGroupController=org.springframework.stereotype.Component ca.bc.gov.educ.api.institute.controller.v1.SchoolAPIController=org.springframework.stereotype.Component ca.bc.gov.educ.api.institute.exception.RestExceptionHandler=org.springframework.stereotype.Component ca.bc.gov.educ.api.institute.filter.AuthorityFilterSpecs=org.springframework.stereotype.Component @@ -43,6 +43,8 @@ ca.bc.gov.educ.api.institute.model.v1.DistrictTombstoneEntity=jakarta.persistenc ca.bc.gov.educ.api.institute.model.v1.FacilityTypeCodeEntity=jakarta.persistence.Entity,jakarta.persistence.Table ca.bc.gov.educ.api.institute.model.v1.IndependentAuthorityEntity=jakarta.persistence.Entity,jakarta.persistence.Table ca.bc.gov.educ.api.institute.model.v1.IndependentAuthorityHistoryEntity=jakarta.persistence.Entity,jakarta.persistence.Table +ca.bc.gov.educ.api.institute.model.v1.IndependentSchoolFundingGroupEntity=jakarta.persistence.Entity,jakarta.persistence.Table +ca.bc.gov.educ.api.institute.model.v1.IndependentSchoolFundingGroupHistoryEntity=jakarta.persistence.Entity,jakarta.persistence.Table ca.bc.gov.educ.api.institute.model.v1.InstituteEvent=jakarta.persistence.Entity,jakarta.persistence.Table ca.bc.gov.educ.api.institute.model.v1.NeighborhoodLearningEntity=jakarta.persistence.Entity,jakarta.persistence.Table ca.bc.gov.educ.api.institute.model.v1.NeighborhoodLearningTypeCodeEntity=jakarta.persistence.Entity,jakarta.persistence.Table @@ -56,6 +58,7 @@ ca.bc.gov.educ.api.institute.model.v1.SchoolContactEntity=jakarta.persistence.En ca.bc.gov.educ.api.institute.model.v1.SchoolContactTombstoneEntity=jakarta.persistence.Entity,jakarta.persistence.Table ca.bc.gov.educ.api.institute.model.v1.SchoolContactTypeCodeEntity=jakarta.persistence.Entity,jakarta.persistence.Table ca.bc.gov.educ.api.institute.model.v1.SchoolEntity=jakarta.persistence.Entity,jakarta.persistence.Table +ca.bc.gov.educ.api.institute.model.v1.SchoolFundingGroupCodeEntity=jakarta.persistence.Entity,jakarta.persistence.Table ca.bc.gov.educ.api.institute.model.v1.SchoolGradeCodeEntity=jakarta.persistence.Entity,jakarta.persistence.Table ca.bc.gov.educ.api.institute.model.v1.SchoolGradeEntity=jakarta.persistence.Entity,jakarta.persistence.Table ca.bc.gov.educ.api.institute.model.v1.SchoolGradeSchoolHistoryEntity=jakarta.persistence.Entity,jakarta.persistence.Table @@ -83,6 +86,8 @@ ca.bc.gov.educ.api.institute.repository.v1.DistrictTombstoneRepository=org.sprin ca.bc.gov.educ.api.institute.repository.v1.FacilityTypeCodeRepository=org.springframework.stereotype.Component,org.springframework.data.repository.Repository ca.bc.gov.educ.api.institute.repository.v1.IndependentAuthorityHistoryRepository=org.springframework.stereotype.Component,org.springframework.data.repository.Repository ca.bc.gov.educ.api.institute.repository.v1.IndependentAuthorityRepository=org.springframework.stereotype.Component,org.springframework.data.repository.Repository +ca.bc.gov.educ.api.institute.repository.v1.IndependentSchoolFundingGroupHistoryRepository=org.springframework.stereotype.Component,org.springframework.data.repository.Repository +ca.bc.gov.educ.api.institute.repository.v1.IndependentSchoolFundingGroupRepository=org.springframework.stereotype.Component,org.springframework.data.repository.Repository ca.bc.gov.educ.api.institute.repository.v1.InstituteEventRepository=org.springframework.data.repository.Repository ca.bc.gov.educ.api.institute.repository.v1.NeighborhoodLearningRepository=org.springframework.stereotype.Component,org.springframework.data.repository.Repository ca.bc.gov.educ.api.institute.repository.v1.NeighborhoodLearningTypeCodeRepository=org.springframework.stereotype.Component,org.springframework.data.repository.Repository @@ -93,6 +98,7 @@ ca.bc.gov.educ.api.institute.repository.v1.SchoolCategoryCodeRepository=org.spri ca.bc.gov.educ.api.institute.repository.v1.SchoolContactRepository=org.springframework.stereotype.Component,org.springframework.data.repository.Repository ca.bc.gov.educ.api.institute.repository.v1.SchoolContactTombstoneRepository=org.springframework.stereotype.Component,org.springframework.data.repository.Repository ca.bc.gov.educ.api.institute.repository.v1.SchoolContactTypeCodeRepository=org.springframework.stereotype.Component,org.springframework.data.repository.Repository +ca.bc.gov.educ.api.institute.repository.v1.SchoolFundingGroupCodeRepository=org.springframework.stereotype.Component,org.springframework.data.repository.Repository ca.bc.gov.educ.api.institute.repository.v1.SchoolGradeCodeRepository=org.springframework.stereotype.Component,org.springframework.data.repository.Repository ca.bc.gov.educ.api.institute.repository.v1.SchoolGradeRepository=org.springframework.stereotype.Component,org.springframework.data.repository.Repository ca.bc.gov.educ.api.institute.repository.v1.SchoolHistoryRepository=org.springframework.stereotype.Component,org.springframework.data.repository.Repository @@ -112,6 +118,7 @@ ca.bc.gov.educ.api.institute.service.v1.EventHandlerDelegatorService=org.springf ca.bc.gov.educ.api.institute.service.v1.EventHandlerService=org.springframework.stereotype.Component ca.bc.gov.educ.api.institute.service.v1.IndependentAuthorityHistoryService=org.springframework.stereotype.Component ca.bc.gov.educ.api.institute.service.v1.IndependentAuthorityService=org.springframework.stereotype.Component +ca.bc.gov.educ.api.institute.service.v1.IndependentSchoolFundingGroupService=org.springframework.stereotype.Component ca.bc.gov.educ.api.institute.service.v1.JetStreamEventHandlerService=org.springframework.stereotype.Component ca.bc.gov.educ.api.institute.service.v1.SchoolContactSearchService=org.springframework.stereotype.Component ca.bc.gov.educ.api.institute.service.v1.SchoolHistorySearchService=org.springframework.stereotype.Component @@ -124,6 +131,7 @@ ca.bc.gov.educ.api.institute.validator.AuthorityContactPayloadValidator=org.spri ca.bc.gov.educ.api.institute.validator.DistrictContactPayloadValidator=org.springframework.stereotype.Component ca.bc.gov.educ.api.institute.validator.DistrictPayloadValidator=org.springframework.stereotype.Component ca.bc.gov.educ.api.institute.validator.IndependentAuthorityPayloadValidator=org.springframework.stereotype.Component +ca.bc.gov.educ.api.institute.validator.IndependentSchoolFundingGroupPayloadValidator=org.springframework.stereotype.Component ca.bc.gov.educ.api.institute.validator.NotePayloadValidator=org.springframework.stereotype.Component ca.bc.gov.educ.api.institute.validator.SchoolContactPayloadValidator=org.springframework.stereotype.Component ca.bc.gov.educ.api.institute.validator.SchoolPayloadValidator=org.springframework.stereotype.Component diff --git a/tools/config/update-configmap.sh b/tools/config/update-configmap.sh index 6005547d..c2586ad0 100644 --- a/tools/config/update-configmap.sh +++ b/tools/config/update-configmap.sh @@ -94,6 +94,27 @@ curl -sX POST "https://$SOAM_KC/auth/admin/realms/$SOAM_KC_REALM_ID/client-scope -H "Authorization: Bearer $TKN" \ -d "{\"description\": \"Delete scope for district address\",\"id\": \"DELETE_DISTRICT_ADDRESS\",\"name\": \"DELETE_DISTRICT_ADDRESS\",\"protocol\": \"openid-connect\",\"attributes\" : {\"include.in.token.scope\" : \"true\",\"display.on.consent.screen\" : \"false\"}}" +echo +echo Writing scope READ_SCHOOL_FUNDING_GROUP +curl -sX POST "https://$SOAM_KC/auth/admin/realms/$SOAM_KC_REALM_ID/client-scopes" \ + -H "Content-Type: application/json" \ + -H "Authorization: Bearer $TKN" \ + -d "{\"description\": \"Read Independent School Funding Group\",\"id\": \"READ_SCHOOL_FUNDING_GROUP\",\"name\": \"READ_SCHOOL_FUNDING_GROUP\",\"protocol\": \"openid-connect\",\"attributes\" : {\"include.in.token.scope\" : \"true\",\"display.on.consent.screen\" : \"false\"}}" + +echo +echo Writing scope WRITE_SCHOOL_FUNDING_GROUP +curl -sX POST "https://$SOAM_KC/auth/admin/realms/$SOAM_KC_REALM_ID/client-scopes" \ + -H "Content-Type: application/json" \ + -H "Authorization: Bearer $TKN" \ + -d "{\"description\": \"Write Independent School Funding Group\",\"id\": \"WRITE_SCHOOL_FUNDING_GROUP\",\"name\": \"WRITE_SCHOOL_FUNDING_GROUP\",\"protocol\": \"openid-connect\",\"attributes\" : {\"include.in.token.scope\" : \"true\",\"display.on.consent.screen\" : \"false\"}}" + +echo +echo Delete scope DELETE_SCHOOL_FUNDING_GROUP +curl -sX POST "https://$SOAM_KC/auth/admin/realms/$SOAM_KC_REALM_ID/client-scopes" \ + -H "Content-Type: application/json" \ + -H "Authorization: Bearer $TKN" \ + -d "{\"description\": \"Delete Independent School Funding Group\",\"id\": \"DELETE_SCHOOL_FUNDING_GROUP\",\"name\": \"DELETE_SCHOOL_FUNDING_GROUP\",\"protocol\": \"openid-connect\",\"attributes\" : {\"include.in.token.scope\" : \"true\",\"display.on.consent.screen\" : \"false\"}}" + echo echo Writing scope READ_DISTRICT_NOTE curl -sX POST "https://$SOAM_KC/auth/admin/realms/$SOAM_KC_REALM_ID/client-scopes" \