Skip to content

Commit

Permalink
Squashed commit of the following:
Browse files Browse the repository at this point in the history
commit 9f0cff0
Author: Zikani Nyirenda Mwase <zikaninyirenda@cgatechnologies.org.uk>
Date:   Wed Jul 20 17:00:39 2022 +0200

    chore: Add migrations to remove unnecessary tables n columns

commit 60cf74b
Author: Zikani Nyirenda Mwase <zikaninyirenda@cgatechnologies.org.uk>
Date:   Tue Jul 5 16:38:30 2022 +0200

    Transfers stuff

commit 9576aeb
Author: Zikani Nyirenda Mwase <zikaninyirenda@cgatechnologies.org.uk>
Date:   Wed Jun 29 09:58:51 2022 +0200

    fix: Update parameters view

commit 9d7f3f5
Author: Zikani Nyirenda Mwase <zikaninyirenda@cgatechnologies.org.uk>
Date:   Tue Jun 28 10:09:56 2022 +0200

    fix: Fix query use groupby

commit 8ca083d
Author: Zikani Nyirenda Mwase <zikaninyirenda@cgatechnologies.org.uk>
Date:   Tue Jun 28 09:43:45 2022 +0200

    feat: Add transfer parameters id to existing transfers parameters tables

commit 170ddd3
Author: Zikani Nyirenda Mwase <zikaninyirenda@cgatechnologies.org.uk>
Date:   Mon Jul 18 15:34:18 2022 +0200

    feat: Add Education Zone select box to Schools

    Users should now be able to select an education zone from existing educationz zones when creating/updating schools.

commit 0d1e0b0
Author: Zikani Nyirenda Mwase <zikaninyirenda@cgatechnologies.org.uk>
Date:   Mon Jul 18 12:28:55 2022 +0200

    feat: Move optional import parameters into a collapsible element;

commit 7be4f88
Author: Zikani Nyirenda Mwase <zikaninyirenda@cgatechnologies.org.uk>
Date:   Mon Jul 18 12:28:20 2022 +0200

    Update version to 1.6.1-SNAPSHOT
  • Loading branch information
zikani03 committed Jul 21, 2022
1 parent 0ab9d12 commit 5348bca
Show file tree
Hide file tree
Showing 38 changed files with 703 additions and 344 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<groupId>org.cga</groupId>
<artifactId>sctp</artifactId>
<packaging>pom</packaging>
<version>1.6.0</version>
<version>1.6.1-SNAPSHOT</version>

<parent>
<groupId>org.springframework.boot</groupId>
Expand Down
2 changes: 1 addition & 1 deletion sctp-api/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<artifactId>sctp</artifactId>
<groupId>org.cga</groupId>
<version>1.6.0</version>
<version>1.6.1-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>

Expand Down
2 changes: 1 addition & 1 deletion sctp-core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<artifactId>sctp</artifactId>
<groupId>org.cga</groupId>
<version>1.6.0</version>
<version>1.6.1-SNAPSHOT</version>
</parent>

<modelVersion>4.0.0</modelVersion>
Expand Down
13 changes: 7 additions & 6 deletions sctp-core/src/main/java/org/cga/sctp/schools/School.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@

package org.cga.sctp.schools;

import org.cga.sctp.schools.educationzone.EducationZone;
import org.cga.sctp.targeting.importation.converters.EducationLevelParameterValueConverter;
import org.cga.sctp.targeting.importation.parameters.EducationLevel;

Expand All @@ -55,8 +56,8 @@ public class School {
@Convert(converter = EducationLevelParameterValueConverter.class)
private EducationLevel educationLevel;

@Column
private long educationZone;
@Column(name="education_zone")
private Long educationZoneId;

@Column
private String contactName;
Expand Down Expand Up @@ -105,12 +106,12 @@ public void setEducationLevel(EducationLevel educationLevel) {
this.educationLevel = educationLevel;
}

public long getEducationZone() {
return educationZone;
public Long getEducationZoneId() {
return educationZoneId;
}

public void setEducationZone(long educationZone) {
this.educationZone = educationZone;
public void setEducationZoneId(Long educationZone) {
this.educationZoneId = educationZone;
}

public String getContactName() {
Expand Down
12 changes: 12 additions & 0 deletions sctp-core/src/main/java/org/cga/sctp/schools/SchoolService.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@

package org.cga.sctp.schools;

import org.cga.sctp.schools.educationzone.EducationZone;
import org.cga.sctp.schools.educationzone.EducationZoneRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

Expand All @@ -44,6 +46,9 @@ public class SchoolService {
@Autowired
SchoolRepository schoolRepository;

@Autowired
EducationZoneRepository educationZoneRepository;

public SchoolRepository getSchoolRepository() {
return schoolRepository;
}
Expand All @@ -57,6 +62,13 @@ public Optional<School> findById(Long id) {
}

public School save(School school) {
if (educationZoneRepository.findById(school.getEducationZoneId()).isEmpty()) {
throw new IllegalArgumentException("Invalid School Education Zone");
}
return schoolRepository.save(school);
}

public List<EducationZone> findAllActiveEducationZones() {
return educationZoneRepository.findAll();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -90,10 +90,10 @@ public static void updateAssetsLiveliHoodAndValidationErrors(UbrHouseholdImport

// Default to Other if none matched
boolean other = record.getSurvivesOnBegging()
| record.getSurvivesOnGanyu()
| record.getSurvivesOnPettyTrading()
| record.getSurvivesOnAgriculture()
| record.getSurvivesOnOther();
|| record.getSurvivesOnGanyu()
|| record.getSurvivesOnPettyTrading()
|| record.getSurvivesOnAgriculture()
|| record.getSurvivesOnOther();
if (!other) {
record.setSurvivesOnOther(true);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,10 @@
import org.cga.sctp.location.Location;
import org.cga.sctp.targeting.CbtStatus;
import org.cga.sctp.transfers.accounts.BeneficiaryAccountService;
import org.cga.sctp.transfers.agencies.TransferAgenciesRepository;
import org.cga.sctp.transfers.accounts.TransferAccountNumberList;
import org.cga.sctp.transfers.agencies.TransferAgenciesRepository;
import org.cga.sctp.transfers.periods.TransferPeriod;
import org.cga.sctp.transfers.periods.TransferPeriodRepository;
import org.cga.sctp.transfers.reconciliation.TransferReconciliationRequest;
import org.cga.sctp.user.User;
import org.slf4j.Logger;
Expand All @@ -58,6 +59,9 @@
public class TransferServiceImpl implements TransferService {
private static final Logger LOGGER = LoggerFactory.getLogger(TransferServiceImpl.class);

@Autowired
private TransferPeriodRepository transferPeriodRepository;

@Autowired
private TransfersRepository transfersRepository;

Expand Down Expand Up @@ -95,10 +99,16 @@ public TransferSession initiateTransfers(Location location, TransferSession tran
if (getTranferSessionRepository().save(transferSession) == null) {
throw new IllegalArgumentException("transferSession must be valid to initiate transfers");
}
// transfersRepository.initiateTransfersInDistrict(transferSession.getProgramId(), location.getId(), transferSession.getId(), userId);
Optional<TransferPeriod> transferPeriod = transferPeriodRepository.findFirstByProgramIdAndDistrictIdAndIsOpen(transferSession.getProgramId(), location.getId());
if (transferPeriod.isEmpty()) {
throw new UnsupportedOperationException("Cannot initiate transfers without an open Transfer Period for the program in the given location");
}

transfersRepository.initiateTransfersForEnrolledHouseholds(
// transferSession.getProgramId(),
transferSession.getEnrollmentSessionId(),
transferSession.getId(),
transferPeriod.get().getId(),
location.getId(),
userId
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ public interface TransferSessionRepository extends JpaRepository<TransferSession
FROM locations AS district
LEFT OUTER JOIN transfer_periods tp ON tp.district_id = district.id
WHERE district.location_type = 'SUBNATIONAL1'
GROUP BY districtId
ORDER BY district.name, tp.end_date
""")
List<DistrictTransferSummaryView> fetchDistrictSummary();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,11 +91,12 @@ public interface TransfersRepository extends JpaRepository<Transfer, Long> {
// of TransferPeriods and other things kept changing. So once the design is solidified, we can move this monster
// to it's own stored procedure.
// @Query(nativeQuery = true, value = "CALL initiateTransfersForEnrolledHouseholdsInDistrict(:enrollmentSessionId, :transferSessionId, :userId)")

// @Query(nativeQuery = true, value = "CALL initiateTransfersForEnrolledHouseholdsInDistrict(:enrollmentSessionId, :transferSessionId, :userId)")
@Modifying
@Query(nativeQuery = true, value ="""
@Query(nativeQuery = true, value ="""
INSERT INTO transfers (
transfer_session_id,
transfer_period_id,
program_id,
household_id,
receiver_id,
Expand Down Expand Up @@ -133,6 +134,7 @@ INSERT INTO transfers (
modified_at
)
SELECT
:transferPeriodId,
ts.id as transfer_session_id,
ts.program_id AS program_id,
h.household_id,
Expand Down Expand Up @@ -180,9 +182,10 @@ INSERT INTO transfers (
LEFT JOIN enrollment_sessions es ON es.id = :enrollmentSessionId
LEFT JOIN transfers_sessions ts ON ts.id = :transferSessionId
WHERE l.id = :districtId AND he.status = 5 ;-- CbtStatus '5' is Enrolled
""")
""")
void initiateTransfersForEnrolledHouseholds(@Param("enrollmentSessionId") Long enrollmentSessionId,
@Param("transferSessionId") Long transferSessionId,
@Param("transferPeriodId") Long transferPeriodId,
@Param("districtId") Long districtId,
@Param("userId") Long userId);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
import org.cga.sctp.targeting.importation.parameters.EducationLevel;

import javax.persistence.*;
import javax.validation.constraints.NotNull;
import java.time.LocalDateTime;

@Entity
Expand All @@ -44,6 +45,10 @@ public class EducationTransferParameter {
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;

@NotNull(message = "Transfer Parameter cannot be null")
@Column
private Long transferParameterId;

@Column
@Enumerated(EnumType.STRING)
private EducationLevel educationLevel;
Expand All @@ -68,6 +73,14 @@ public void setId(Long id) {
this.id = id;
}

public Long getTransferParameterId() {
return transferParameterId;
}

public void setTransferParameterId(Long transferParameterId) {
this.transferParameterId = transferParameterId;
}

public EducationLevel getEducationLevel() {
return educationLevel;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,11 @@
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;

import java.util.List;
import java.util.Optional;

public interface EducationTransferParameterRepository extends JpaRepository<EducationTransferParameter, Long> {
EducationTransferParameter findDistinctByEducationLevel(EducationLevel educationLevel);

List<EducationTransferParameter> findByTransferParameterId(Long transferParameterId);
}
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@ public class HouseholdTransferParameter {
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;

@Column
private Long transferParameterId;

@Column
private int numberOfMembers;

Expand Down Expand Up @@ -69,6 +72,14 @@ public void setId(Long id) {
this.id = id;
}

public Long getTransferParameterId() {
return transferParameterId;
}

public void setTransferParameterId(Long transferParameterId) {
this.transferParameterId = transferParameterId;
}

public int getNumberOfMembers() {
return numberOfMembers;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,5 +34,8 @@

import org.springframework.data.jpa.repository.JpaRepository;

import java.util.List;

public interface HouseholdTransferParametersRepository extends JpaRepository<HouseholdTransferParameter, Long> {
List<HouseholdTransferParameter> findByTransferParameterId(Long transferParameterId);
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,13 @@
package org.cga.sctp.transfers.parameters;

import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public interface TransferParametersRepository extends JpaRepository<TransferParameter, Long> {
@Query("FROM TransferParameter t where t.active = true")
List<TransferParameter> findAllActive();
}
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,16 @@
import org.springframework.data.repository.query.Param;

import java.util.List;
import java.util.Optional;

public interface TransferPeriodRepository extends JpaRepository<TransferPeriod, Long> {

@Query("SELECT COUNT(id) FROM TransferPeriod WHERE programId = :programId AND districtId = :districtId AND closed = false")
int countAllOpenInProgramAndDistrict(@Param("programId") long programId, @Param("districtId") long districtId);

@Query("FROM TransferPeriod WHERE programId = :programId AND districtId = :districtId AND closed = false")
Optional<TransferPeriod> findFirstByProgramIdAndDistrictIdAndIsOpen(@Param("programId") long programId, @Param("districtId") long districtId);

@Query
List<TransferPeriod> findAllByDistrictId(Long districtId);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ALTER TABLE transfer_education_parameters ADD transfer_parameter_id BIGINT(19) NOT NULL AFTER id;
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ALTER TABLE transfer_households_parameters ADD transfer_parameter_id BIGINT(19) NOT NULL AFTER id;
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
-- This migration removes unused tables in the schema.
-- The following will be dropped: education_zone, delivery_agencies

DROP TABLE education_zone;

DROP TABLE delivery_agencies;
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ALTER TABLE transfer_periods DROP COLUMN ta_id;
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ALTER TABLE transfers DROP COLUMN enrollment_session_id;
2 changes: 1 addition & 1 deletion sctp-mis/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<artifactId>sctp</artifactId>
<groupId>org.cga</groupId>
<version>1.6.0</version>
<version>1.6.1-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
import org.cga.sctp.program.Program;
import org.cga.sctp.program.ProgramUser;
import org.cga.sctp.program.ProgramUserCandidate;
import org.cga.sctp.schools.educationzone.EducationZone;
import org.cga.sctp.security.permission.UserRole;
import org.cga.sctp.targeting.criteria.CriteriaFilterObject;
import org.cga.sctp.targeting.criteria.CriteriaFilterTemplate;
Expand All @@ -47,6 +48,7 @@
import org.cga.sctp.transfers.agencies.TransferAgency;
import org.cga.sctp.transfers.agencies.TransferMethod;
import org.cga.sctp.transfers.parameters.HouseholdParameterCondition;
import org.cga.sctp.transfers.parameters.TransferParameter;
import org.cga.sctp.user.AccessLevel;
import org.cga.sctp.user.Permission;
import org.cga.sctp.user.SystemRole;
Expand Down Expand Up @@ -151,4 +153,14 @@ public SelectOptionEntry educationLevelSelectOption() {
public SelectOptionEntry transferMethodSelectOption() {
return new SelectOptionEntry(TransferMethod.class, "name()", "name()");
}

@Bean
public SelectOptionEntry educationZones() {
return new SelectOptionEntry(EducationZone.class, "getId()", "getName()");
}

@Bean
public SelectOptionEntry transferParameterOption() {
return new SelectOptionEntry(TransferParameter.class, "getId()", "getTitle()");
}
}
Loading

0 comments on commit 5348bca

Please sign in to comment.