Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Downsync for cfl view #1291

Open
wants to merge 20 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion health-services/libraries/health-services-models/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>org.egov.common</groupId>
<artifactId>health-services-models</artifactId>
<version>1.0.23-SNAPSHOT</version>
<version>1.0.23-dev-SNAPSHOT</version>
<properties>
<java.version>17</java.version>
<maven.compiler.source>${java.version}</maven.compiler.source>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package org.egov.common.models.household;

import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;

@JsonIgnoreProperties(ignoreUnknown = true)
public enum HouseHoldType {

FAMILY("FAMILY"),

COMMUNITY("COMMUNITY"),

OTHER("OTHER");

private String value;

HouseHoldType(String value) {
this.value = value;
}

@JsonCreator
public static HouseHoldType fromValue(String text) {
for (HouseHoldType b : HouseHoldType.values()) {
if (String.valueOf(b.value).equalsIgnoreCase(text)) {
return b;
}
}
return null;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,16 @@ public class Household extends EgovOfflineModel {

@JsonProperty("memberCount")
@NotNull
@Range(min = 0, max = 1000)
// @Range(min = 0, max = 1000)
private Integer memberCount = null;

@JsonProperty("address")
@Valid
private Address address = null;

@JsonProperty("householdType")
private HouseHoldType householdType = null;

//TODO remove
@JsonProperty("isDeleted")
private Boolean isDeleted = Boolean.FALSE;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ public class HouseholdSearch extends EgovOfflineSearchModel {
@JsonProperty("boundaryCode")
private String localityCode = null;

@JsonProperty("householdType")
private String householdType = null;

@Exclude
@JsonProperty("latitude")
@DecimalMin("-90")
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package org.egov.common.models.referralmanagement.beneficiarydownsync;

import com.fasterxml.jackson.annotation.JsonProperty;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.egov.common.models.household.Household;

import java.util.List;
import java.util.Map;

@Data
@NoArgsConstructor
@AllArgsConstructor
@Builder
public class DownsyncCLFHousehold {

@JsonProperty("HouseholdCountMap")
List<HouseholdMemberMap> householdMemberCountMap;

@JsonProperty("DownsyncCriteria")
DownsyncCriteria downsyncCriteria;

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package org.egov.common.models.referralmanagement.beneficiarydownsync;

import com.fasterxml.jackson.annotation.JsonProperty;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.egov.common.contract.response.ResponseInfo;

import java.util.List;

@Data
@NoArgsConstructor
@AllArgsConstructor
@Builder
public class DownsyncCLFHouseholdResponse {


@JsonProperty("ResponseInfo")
private ResponseInfo responseInfo;

@JsonProperty("Households")
private DownsyncCLFHousehold Households;

}
Original file line number Diff line number Diff line change
Expand Up @@ -35,5 +35,7 @@ public class DownsyncCriteria {
private Integer limit = 50;

private Long totalCount;

private String householdId;
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package org.egov.common.models.referralmanagement.beneficiarydownsync;

import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.egov.common.models.household.Household;

@Data
@NoArgsConstructor
@AllArgsConstructor
@Builder
public class HouseholdMemberMap {

private Household household;

private Integer numberOfMembers;


}
2 changes: 1 addition & 1 deletion health-services/referralmanagement/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -132,4 +132,4 @@
<url>https://nexus-repo.digit.org/nexus/content/repositories/snapshots/</url>
</repository>
</repositories>
</project>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
package org.egov.referralmanagement.repository;

import org.egov.common.ds.Tuple;
import org.egov.common.models.household.Household;
import org.egov.referralmanagement.repository.rowmapper.HouseholdRowMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate;
import org.springframework.stereotype.Repository;
import org.springframework.util.StringUtils;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Repository
public class HouseholdRepository {

@Autowired
private NamedParameterJdbcTemplate namedParameterJdbcTemplate;

@Autowired
private HouseholdRowMapper householdRowMapper;


public Tuple<Long, List<Household>> findByViewCLF(String localityCode, Integer limit, Integer offset, String tenantId, Long lastModifiedTime, String householdId) {
String query = null;
Map<String, Object> paramsMap = new HashMap<>();
Long totalCount = null;

query = "select * from household_address_clf_mv where localitycode=:localitycode ";
if (StringUtils.hasLength(householdId)) {
query = query + " and id=:id";
paramsMap.put("id", householdId);
} else {
paramsMap.put("start", offset);
paramsMap.put("end", offset+limit);
query = query + " and rank between :start and :end ";

Map<String, Object> paramsMapCount = new HashMap<>();
paramsMapCount.put("localitycode", localityCode);
paramsMapCount.put("lastModifiedTime", lastModifiedTime);
Integer maxRank = namedParameterJdbcTemplate.queryForObject("select max(rank) from household_address_clf_mv where localitycode=:localitycode and lastModifiedTime>=:lastModifiedTime", paramsMapCount, Integer.class);
totalCount = maxRank == null ? 0L : Long.valueOf(maxRank);
}
paramsMap.put("localitycode", localityCode);
return new Tuple<>(totalCount, this.namedParameterJdbcTemplate.query(query, paramsMap, householdRowMapper));

}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
package org.egov.referralmanagement.repository.rowmapper;

import java.sql.ResultSet;
import java.sql.SQLException;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.egov.common.contract.models.AuditDetails;
import org.egov.common.models.core.AdditionalFields;
import org.egov.common.models.household.Address;
import org.egov.common.models.household.AddressType;
import org.egov.common.models.core.Boundary;
import org.egov.common.models.household.HouseHoldType;
import org.egov.common.models.household.Household;
import org.springframework.jdbc.core.RowMapper;
import org.springframework.stereotype.Component;

@Component
public class HouseholdRowMapper implements RowMapper<Household> {
private final ObjectMapper objectMapper = new ObjectMapper();

@Override
public Household mapRow(ResultSet resultSet, int i) throws SQLException {
try {
AuditDetails auditDetails = AuditDetails.builder()
.createdBy(resultSet.getString("createdBy"))
.createdTime(resultSet.getLong("createdTime"))
.lastModifiedBy(resultSet.getString("lastModifiedBy"))
.lastModifiedTime(resultSet.getLong("lastModifiedTime"))
.build();
AuditDetails clientAuditDetails = AuditDetails.builder()
.createdTime(resultSet.getLong("clientCreatedTime"))
.createdBy(resultSet.getString("clientCreatedBy"))
.lastModifiedTime(resultSet.getLong("clientLastModifiedTime"))
.lastModifiedBy(resultSet.getString("clientLastModifiedBy"))
.build();
Household household = Household.builder()
.id(resultSet.getString("id"))
.rowVersion(resultSet.getInt("rowVersion"))
.isDeleted(resultSet.getBoolean("isDeleted"))
.householdType(HouseHoldType.fromValue(resultSet.getString("householdType")))
.tenantId(resultSet.getString("tenantId"))
.memberCount(resultSet.getInt("numberOfMembers"))
.clientReferenceId(resultSet.getString("clientReferenceId"))
.auditDetails(auditDetails)
.clientAuditDetails(clientAuditDetails)
.additionalFields(resultSet.getString("additionalDetails") == null ? null : objectMapper.readValue(resultSet
.getString("additionalDetails"), AdditionalFields.class))
.address(Address.builder()
.id(resultSet.getString("aid"))
.clientReferenceId(resultSet.getString("aclientreferenceid"))
.tenantId(resultSet.getString("atenantid"))
.doorNo(resultSet.getString("doorNo"))
.latitude(resultSet.getDouble("latitude"))
.longitude(resultSet.getDouble("longitude"))
.locationAccuracy(resultSet.getDouble("locationAccuracy"))
.type(AddressType.fromValue(resultSet.getString("type")))
.addressLine1(resultSet.getString("addressLine1"))
.addressLine2(resultSet.getString("addressLine2"))
.landmark(resultSet.getString("landmark"))
.city(resultSet.getString("city"))
.pincode(resultSet.getString("pinCode"))
.buildingName(resultSet.getString("buildingName"))
.street(resultSet.getString("street"))
.locality(resultSet.getString("localityCode") != null ?
Boundary.builder().code(resultSet.getString("localityCode")).build() : null)
.build())
.build();
if (household.getAddress().getId() == null) {
household.setAddress(null);
}
return household;
} catch (JsonProcessingException e) {
throw new SQLException(e);
}

}
}
Loading
Loading