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 demo #1317

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 @@ -84,4 +84,4 @@
<url>https://nexus-repo.digit.org/nexus/content/repositories/snapshots/</url>
</repository>
</repositories>
</project>
</project>
4 changes: 2 additions & 2 deletions health-services/referralmanagement/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
<dependency>
<groupId>org.egov.common</groupId>
<artifactId>health-services-models</artifactId>
<version>1.0.23-dev-SNAPSHOT</version>
<version>1.0.25-dev-SNAPSHOT</version>
<scope>compile</scope>
</dependency>
<dependency>
Expand Down 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,76 @@
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.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"))
.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