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

added userAddress field in the indexes #640

Merged
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ public interface Constants {
String USERNAME = "userName";
String NAME = "name";
String ROLE = "role";

String CITY = "city";
String INDIVIDUAL_ID = "individualId";
String ADDRESS_CODE = "addressLocalityCode";
String CHILDREN_PRESENTED_US = "childrenPresentedUS";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ public class HouseholdIndexV1 {
private String userName;
@JsonProperty("nameOfUser")
private String nameOfUser;
@JsonProperty("userAddress")
private String userAddress;
@JsonProperty("taskDates")
private String taskDates;
@JsonProperty("syncedDate")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,12 @@
public class PGRIndex {
@JsonProperty("service")
private Service service;
@JsonProperty("userName")
private String userName;
@JsonProperty("role")
private String role;
@JsonProperty("userAddress")
private String userAddress;
@JsonProperty("boundaryHierarchy")
private ObjectNode boundaryHierarchy;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ public class ProjectStaffIndexV1 {
private String projectId;
@JsonProperty("userName")
private String userName;
@JsonProperty("userAddress")
private String userAddress;
@JsonProperty("role")
private String role;
@JsonProperty("taskDates")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ public class ProjectTaskIndexV1 {
private String nameOfUser;
@JsonProperty("role")
private String role;
@JsonProperty("userCity")
private String userCity;
@JsonProperty("userAddress")
private String userAddress;
@JsonProperty("productVariant")
private String productVariant;
@JsonProperty("productName")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ public class ReferralIndexV1 {
private String userName;
@JsonProperty("role")
private String role;
@JsonProperty("userAddress")
private String userAddress;
@JsonProperty("age")
private Integer age;
@JsonProperty("boundaryHierarchy")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ public class ServiceIndexV1 {
private String userName;
@JsonProperty("role")
private String role;
@JsonProperty("userAddress")
private String userAddress;
@JsonProperty("boundaryHierarchy")
private ObjectNode boundaryHierarchy;
@JsonProperty("tenantId")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,9 @@ public class StockIndexV1 {
@JsonProperty("role")
private String role;

@JsonProperty("userAddress")
private String userAddress;

@JsonProperty("dateOfEntry")
private Long dateOfEntry;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ public HouseholdIndexV1 transform(Household household) {
.userName(userInfoMap.get(USERNAME))
.role(userInfoMap.get(ROLE))
.nameOfUser(userInfoMap.get(NAME))
.userAddress(userInfoMap.get(CITY))
.taskDates(commonUtils.getDateFromEpoch(household.getClientAuditDetails().getLastModifiedTime()))
.syncedDate(commonUtils.getDateFromEpoch(household.getAuditDetails().getLastModifiedTime()))
.geoPoint(commonUtils.getGeoPoint(household.getAddress()))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,20 +14,24 @@

import java.util.*;

import static org.egov.transformer.Constants.*;

@Slf4j
@Component
public class PGRTransformationService {

private final ProjectService projectService;
private final UserService userService;
private final TransformerProperties transformerProperties;
private final Producer producer;
private final CommonUtils commonUtils;
private static final HashMap<String, String> translations = null;


public PGRTransformationService(ProjectService projectService, TransformerProperties transformerProperties, Producer producer, CommonUtils commonUtils) {
public PGRTransformationService(ProjectService projectService, UserService userService, TransformerProperties transformerProperties, Producer producer, CommonUtils commonUtils) {

this.projectService = projectService;
this.userService = userService;
this.transformerProperties = transformerProperties;
this.producer = producer;
this.commonUtils = commonUtils;
Expand All @@ -52,17 +56,23 @@ private void transform(Service service, List<PGRIndex> pgrIndexList) {
if (localityCode.isPresent()) {
boundaryLabelToNameMap = projectService.getBoundaryLabelToNameMap(localityCode.get(), service.getTenantId());
}
//TODO change below logic to fetch default boundaryHierarchy using tenantId if we can't fetch projectTypeId

ObjectNode boundaryHierarchy = (ObjectNode) commonUtils.getBoundaryHierarchy(tenantId, null, boundaryLabelToNameMap);

Map<String, String> userInfoMap = userService.getUserInfo(tenantId, service.getAuditDetails().getCreatedBy());

service.setAddress(null); //explicitly setting it to null as it is not needed
service.setApplicationStatus(commonUtils.getMDMSTransformerLocalizations(service.getApplicationStatus(), tenantId));
service.setServiceCode(commonUtils.getMDMSTransformerLocalizations(service.getServiceCode(), tenantId));

PGRIndex pgrIndex = PGRIndex.builder()
.service(service)
.userName(userInfoMap.get(USERNAME))
.role(userInfoMap.get(ROLE))
.userAddress(userInfoMap.get(CITY))
.boundaryHierarchy(boundaryHierarchy)
.build();
service.setAddress(null); //explicitly setting it to null as it is not needed
service.setApplicationStatus(commonUtils.getMDMSTransformerLocalizations(service.getApplicationStatus(), tenantId));
service.setServiceCode(commonUtils.getMDMSTransformerLocalizations(service.getServiceCode(), tenantId));

pgrIndexList.add(pgrIndex);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,7 @@
import java.util.*;
import java.util.stream.Collectors;

import static org.egov.transformer.Constants.ROLE;
import static org.egov.transformer.Constants.USERNAME;
import static org.egov.transformer.Constants.*;

@Slf4j
public abstract class ProjectStaffTransformationService implements TransformationService<ProjectStaff> {
Expand Down Expand Up @@ -91,6 +90,7 @@ public List<ProjectStaffIndexV1> transform(ProjectStaff projectStaff) {
.userId(projectStaff.getUserId())
.userName(userInfoMap.get(USERNAME))
.role(userInfoMap.get(ROLE))
.userAddress(userInfoMap.get(CITY))
.taskDates(commonUtils.getProjectDatesList(project.getStartDate(), project.getEndDate()))
.createdTime(projectStaff.getAuditDetails().getCreatedTime())
.createdBy(projectStaff.getAuditDetails().getCreatedBy())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ private ProjectTaskIndexV1 transformTaskToProjectTaskIndex(TaskResource taskReso
.userName(userInfoMap.get(USERNAME))
.nameOfUser(userInfoMap.get(NAME))
.role(userInfoMap.get(ROLE))
.userCity(userInfoMap.get("city"))
.userAddress(userInfoMap.get(CITY))
.productVariant(taskResource.getProductVariantId())
.isDelivered(taskResource.getIsDelivered())
.quantity(taskResource.getQuantity())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ public ReferralIndexV1 transform(Referral referral) {
.tenantId(referral.getTenantId())
.userName(userInfoMap.get(USERNAME))
.role(userInfoMap.get(ROLE))
.userAddress(userInfoMap.get(CITY))
.facilityName(facilityName)
.age(individualDetails.containsKey(AGE) ? (Integer) individualDetails.get(AGE) : null)
.dateOfBirth(individualDetails.containsKey(DATE_OF_BIRTH) ? (Long) individualDetails.get(DATE_OF_BIRTH) : null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,7 @@
import java.util.stream.Collectors;
import java.util.stream.StreamSupport;

import static org.egov.transformer.Constants.ROLE;
import static org.egov.transformer.Constants.USERNAME;
import static org.egov.transformer.Constants.*;

@Slf4j
public abstract class ServiceTaskTransformationService implements TransformationService<Service> {
Expand Down Expand Up @@ -123,6 +122,7 @@ public List<ServiceIndexV1> transform(Service service) {
.checklistName(parts[1])
.userName(userInfoMap.get(USERNAME))
.role(userInfoMap.get(ROLE))
.userAddress(userInfoMap.get(CITY))
.createdTime(service.getAuditDetails().getCreatedTime())
.taskDates(commonUtils.getDateFromEpoch(service.getAuditDetails().getLastModifiedTime()))
.createdBy(service.getAuditDetails().getCreatedBy())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ public List<StockIndexV1> transform(Stock stock) {
.transactingFacilityId(stock.getTransactingPartyId())
.userName(userInfoMap.get(USERNAME))
.role(userInfoMap.get(ROLE))
.userAddress(userInfoMap.get(CITY))
.transactingFacilityName(transactingFacility != null ? transactingFacility.getName() : stock.getTransactingPartyId())
.facilityType(facilityType)
.transactingFacilityType(transactingFacilityType)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public Map<String, String> getUserInfo(String tenantId, String userId) {
userMap.put(NAME, null);
userMap.put(ROLE, null);
userMap.put(ID, null);
userMap.put("city", null);
userMap.put(CITY, null);
return userMap;
}
userName = users.get(0).getUserName();
Expand All @@ -72,7 +72,7 @@ public Map<String, String> getUserInfo(String tenantId, String userId) {
userMap.put(NAME, users.get(0).getName());
userMap.put(ROLE, role);
userMap.put(ID, String.valueOf(users.get(0).getId()));
userMap.put("city", users.get(0).getCorrespondenceAddress());
userMap.put(CITY, users.get(0).getCorrespondenceAddress());
userIdVsUserInfoCache.put(userId, userMap);
return userMap;
}
Expand All @@ -91,8 +91,12 @@ public List<UserSearchResponseContent> getUsers(String tenantId, String userId)
searchRequest,
UserSearchResponse.class
);
return Collections.singletonList(response.getUserSearchResponseContent().get(0));
// return response.getUserSearchResponseContent().get(0);
UserSearchResponseContent responseContent = response.getUserSearchResponseContent().get(0);
if (responseContent != null) {
return Collections.singletonList(responseContent);
} else {
return new ArrayList<>();
}
} catch (Exception e) {
log.error("Exception while searching users : {}", ExceptionUtils.getStackTrace(e));
}
Expand Down