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

created cache for user and staff roles #622

Merged
merged 5 commits into from
Jan 30, 2024
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 @@ -47,6 +47,8 @@ public interface Constants {
String AGE = "age";
String DATE_OF_BIRTH = "dateOfBirth";
String GENDER = "gender";
String USERNAME = "userName";
String ROLE = "role";
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,9 @@
import java.util.Map;
import java.util.stream.Collectors;

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

@Component
@Slf4j
public class HouseholdService {
Expand Down Expand Up @@ -100,11 +103,12 @@ public HouseholdIndexV1 transform(Household household) {
boundaryLabelToNameMap = null;
}
ObjectNode boundaryHierarchy = (ObjectNode) commonUtils.getBoundaryHierarchy(household.getTenantId(), projectTypeId, boundaryLabelToNameMap);
List<User> users = userService.getUsers(household.getTenantId(), household.getAuditDetails().getCreatedBy());
Map<String, String> userInfoMap = userService.getUserInfo(household.getTenantId(), household.getAuditDetails().getCreatedBy());

return HouseholdIndexV1.builder()
.household(household)
.userName(userService.getUserName(users, userId))
.role(userService.getStaffRole(household.getTenantId(), users))
.userName(userInfoMap.get(USERNAME))
.role(userInfoMap.get(ROLE))
.geoPoint(commonUtils.getGeoPoint(household.getAddress()))
.boundaryHierarchy(boundaryHierarchy)
.build();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@
import java.util.*;
import java.util.stream.Collectors;

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

@Slf4j
public abstract class ProjectStaffTransformationService implements TransformationService<ProjectStaff> {
protected final ProjectStaffIndexV1Transformer transformer;
Expand Down Expand Up @@ -63,29 +66,31 @@ static class ProjectStaffIndexV1Transformer implements
private final UserService userService;

private final CommonUtils commonUtils;

@Autowired
ProjectStaffIndexV1Transformer(ProjectService projectService, UserService userService, CommonUtils commonUtils) {
this.projectService = projectService;
this.userService = userService;
this.commonUtils = commonUtils;
}

@Override
public List<ProjectStaffIndexV1> transform(ProjectStaff projectStaff) {
String tenantId = projectStaff.getTenantId();
String projectId = projectStaff.getProjectId();
Project project = projectService.getProject(projectId,tenantId);
Project project = projectService.getProject(projectId, tenantId);
String projectTypeId = project.getProjectTypeId();
Map<String, String> boundaryLabelToNameMap = projectService
.getBoundaryLabelToNameMapByProjectId(projectStaff.getProjectId(), projectStaff.getTenantId());
log.info("boundary labels {}", boundaryLabelToNameMap.toString());
List<User> users = userService.getUsers(projectStaff.getTenantId(), projectStaff.getUserId());
Map<String, String> userInfoMap = userService.getUserInfo(projectStaff.getTenantId(), projectStaff.getUserId());
List<ProjectStaffIndexV1> projectStaffIndexV1List = new ArrayList<>();
ProjectStaffIndexV1 projectStaffIndexV1 = ProjectStaffIndexV1.builder()
.id(projectStaff.getId())
.projectId(projectId)
.userId(projectStaff.getUserId())
.userName(userService.getUserName(users,projectStaff.getUserId()))
.role(userService.getStaffRole(projectStaff.getTenantId(),users))
.userName(userInfoMap.get(USERNAME))
.role(userInfoMap.get(ROLE))
.createdTime(projectStaff.getAuditDetails().getCreatedTime())
.createdBy(projectStaff.getAuditDetails().getCreatedBy())
.lastModifiedBy(projectStaff.getAuditDetails().getLastModifiedBy())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ public List<ProjectTaskIndexV1> transform(Task task) {
boundaryLabelToNameMap = projectService
.getBoundaryLabelToNameMapByProjectId(task.getProjectId(), tenantId);
}
Project project = projectService.getProject(task.getProjectId(),tenantId);
Project project = projectService.getProject(task.getProjectId(), tenantId);
String projectTypeId = project.getProjectTypeId();
log.info("boundary labels {}", boundaryLabelToNameMap.toString());
Map<String, String> finalBoundaryLabelToNameMap = boundaryLabelToNameMap;
Expand All @@ -119,29 +119,30 @@ public List<ProjectTaskIndexV1> transform(Task task) {
}
final ProjectBeneficiary finalProjectBeneficiary = projectBeneficiary;

List<User> users = userService.getUsers(task.getTenantId(), task.getAuditDetails().getCreatedBy());
String projectBeneficiaryType = projectService.getProjectBeneficiaryType(task.getTenantId(), projectTypeId);

ObjectNode boundaryHierarchy = (ObjectNode) commonUtils.getBoundaryHierarchy(tenantId, projectTypeId, finalBoundaryLabelToNameMap);

Task constructedTask = constructTaskResourceIfNull(task);

return constructedTask.getResources().stream().map(r ->
transformTaskToProjectTaskIndex(r, task, boundaryHierarchy, tenantId, users, finalProjectBeneficiary, projectBeneficiaryType)
transformTaskToProjectTaskIndex(r, task, boundaryHierarchy, tenantId, finalProjectBeneficiary, projectBeneficiaryType)
).collect(Collectors.toList());
}

private ProjectTaskIndexV1 transformTaskToProjectTaskIndex(TaskResource taskResource, Task task, ObjectNode boundaryHierarchy, String tenantId, List<User> users,
private ProjectTaskIndexV1 transformTaskToProjectTaskIndex(TaskResource taskResource, Task task, ObjectNode boundaryHierarchy, String tenantId,
ProjectBeneficiary finalProjectBeneficiary, String projectBeneficiaryType) {
Map<String, String> userInfoMap = userService.getUserInfo(task.getTenantId(), task.getAuditDetails().getCreatedBy());

ProjectTaskIndexV1 projectTaskIndexV1 = ProjectTaskIndexV1.builder()
.id(taskResource.getId())
.taskId(task.getId())
.clientReferenceId(taskResource.getClientReferenceId())
.tenantId(tenantId)
.taskType("DELIVERY")
.projectId(task.getProjectId())
.userName(userService.getUserName(users, task.getAuditDetails().getCreatedBy()))
.role(userService.getStaffRole(task.getTenantId(), users))
.userName(userInfoMap.get(USERNAME))
.role(userInfoMap.get(ROLE))
.productVariant(taskResource.getProductVariantId())
.isDelivered(taskResource.getIsDelivered())
.quantity(taskResource.getQuantity())
Expand All @@ -162,7 +163,7 @@ private ProjectTaskIndexV1 transformTaskToProjectTaskIndex(TaskResource taskReso
.boundaryHierarchy(boundaryHierarchy)
.build();

List<String> variantList= new ArrayList<>(Collections.singleton(taskResource.getProductVariantId()));
List<String> variantList = new ArrayList<>(Collections.singleton(taskResource.getProductVariantId()));
String productName = String.join(COMMA, productService.getProductVariantNames(variantList, tenantId));
projectTaskIndexV1.setProductName(productName);

Expand Down Expand Up @@ -223,6 +224,7 @@ private void addAdditionalDetails(AdditionalFields additionalFields, ObjectNode
}
});
}

private Task constructTaskResourceIfNull(Task task) {
if (task.getResources() == null || task.getResources().isEmpty()) {
TaskResource taskResource = new TaskResource();
Expand Down Expand Up @@ -254,6 +256,7 @@ private Task constructTaskResourceIfNull(Task task) {
}
return task;
}

private String getFieldStringValue(List<Field> fields, String key) {
Optional<Field> field = fields.stream()
.filter(field1 -> key.equalsIgnoreCase(field1.getKey()))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,6 @@ public void transform(List<Referral> payloadList) {
}

public ReferralIndexV1 transform(Referral referral) {
List<User> users = userService.getUsers(referral.getTenantId(), referral.getAuditDetails().getCreatedBy());
String tenantId = referral.getTenantId();
ProjectBeneficiary projectBeneficiary = getProjectBeneficiary(referral, tenantId);
Map<String, Object> individualDetails = new HashMap<>();
Expand All @@ -93,11 +92,12 @@ public ReferralIndexV1 transform(Referral referral) {

Map<String, String> finalBoundaryLabelToNameMap = boundaryLabelToNameMap;
ObjectNode boundaryHierarchy = (ObjectNode) commonUtils.getBoundaryHierarchy(tenantId, projectTypeId, finalBoundaryLabelToNameMap);
Map<String, String> userInfoMap = userService.getUserInfo(tenantId, referral.getAuditDetails().getCreatedBy());
ReferralIndexV1 referralIndexV1 = ReferralIndexV1.builder()
.referral(referral)
.tenantId(referral.getTenantId())
.userName(userService.getUserName(users, referral.getAuditDetails().getCreatedBy()))
.role(userService.getStaffRole(referral.getTenantId(), users))
.userName(userInfoMap.get(USERNAME))
.role(userInfoMap.get(ROLE))
.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,6 +23,9 @@
import java.util.stream.Collectors;
import java.util.stream.StreamSupport;

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

@Slf4j
public abstract class ServiceTaskTransformationService implements TransformationService<Service> {

Expand All @@ -32,6 +35,7 @@ public abstract class ServiceTaskTransformationService implements Transformation

protected final TransformerProperties properties;
protected final CommonUtils commonUtils;

@Autowired
protected ServiceTaskTransformationService(ServiceTaskTransformationService.ServiceTaskIndexV1Transformer transformer,
Producer producer, TransformerProperties properties, CommonUtils commonUtils) {
Expand Down Expand Up @@ -71,6 +75,7 @@ static class ServiceTaskIndexV1Transformer implements
private UserService userService;

private final ObjectMapper objectMapper;

@Autowired
ServiceTaskIndexV1Transformer(ProjectService projectService, TransformerProperties properties, ServiceDefinitionService serviceDefinitionService, CommonUtils commonUtils, UserService userService, ObjectMapper objectMapper) {

Expand All @@ -96,7 +101,7 @@ public List<ServiceIndexV1> transform(Service service) {
projectId = projectService.getProjectByName(projectName, service.getTenantId()).getId();
}
Map<String, String> boundaryLabelToNameMap = new HashMap<>();
Project project = projectService.getProject(projectId,tenantId);
Project project = projectService.getProject(projectId, tenantId);
String projectTypeId = project.getProjectTypeId();
if (service.getAdditionalDetails() != null) {
boundaryLabelToNameMap = projectService
Expand All @@ -106,8 +111,8 @@ public List<ServiceIndexV1> transform(Service service) {
}
log.info("boundary labels {}", boundaryLabelToNameMap.toString());
ObjectNode boundaryHierarchy = (ObjectNode) commonUtils.getBoundaryHierarchy(tenantId, projectTypeId, boundaryLabelToNameMap);
List<User> users = userService.getUsers(service.getTenantId(), service.getAuditDetails().getCreatedBy());
String syncedTimeStamp = commonUtils.getTimeStampFromEpoch(service.getAuditDetails().getCreatedTime());
Map<String, String> userInfoMap = userService.getUserInfo(service.getTenantId(), service.getAuditDetails().getCreatedBy());

ServiceIndexV1 serviceIndexV1 = ServiceIndexV1.builder()
.id(service.getId())
Expand All @@ -116,8 +121,8 @@ public List<ServiceIndexV1> transform(Service service) {
.serviceDefinitionId(service.getServiceDefId())
.supervisorLevel(supervisorLevel)
.checklistName(parts[1])
.userName(userService.getUserName(users,service.getAuditDetails().getCreatedBy()))
.role(userService.getStaffRole(service.getTenantId(),users))
.userName(userInfoMap.get(USERNAME))
.role(userInfoMap.get(ROLE))
.createdTime(service.getAuditDetails().getCreatedTime())
.createdBy(service.getAuditDetails().getCreatedBy())
.tenantId(service.getTenantId())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@
import java.util.stream.Collectors;
import java.util.stream.StreamSupport;

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

@Slf4j
@Component
public class ServiceTransformationService {
Expand Down Expand Up @@ -80,13 +83,13 @@ private void transform(Service service, List<ServiceIndexV2> serviceIndexV2List)
}
log.info("boundary labels {}", boundaryLabelToNameMap.toString());
ObjectNode boundaryHierarchy = (ObjectNode) commonUtils.getBoundaryHierarchy(tenantId, projectTypeId, boundaryLabelToNameMap);
List<User> users = userService.getUsers(service.getTenantId(), service.getAuditDetails().getCreatedBy());
String syncedTimeStamp = commonUtils.getTimeStampFromEpoch(service.getAuditDetails().getCreatedTime());

// populate them from env
String checkListToFilter = transformerProperties.getCheckListName().trim();
List<AttributeValue> attributeValueList = service.getAttributes();
Map<String, Map<String, String>> attributeCodeToQuestionAgeGroup = new HashMap<>();
Map<String, String> userInfoMap = userService.getUserInfo(service.getTenantId(), service.getAuditDetails().getCreatedBy());
getAttributeCodeMappings(attributeCodeToQuestionAgeGroup);
if (checkListName.trim().equals(checkListToFilter)) {
String finalProjectId = projectId;
Expand All @@ -99,8 +102,8 @@ private void transform(Service service, List<ServiceIndexV2> serviceIndexV2List)
.ageGroup(key)
.tenantId(tenantId)
.projectId(finalProjectId)
.userName(userService.getUserName(users, service.getAuditDetails().getCreatedBy()))
.role(userService.getStaffRole(service.getTenantId(), users))
.userName(userInfoMap.get(USERNAME))
.role(userInfoMap.get(ROLE))
.createdTime(service.getAuditDetails().getCreatedTime())
.syncedTime(service.getAuditDetails().getCreatedTime())
.createdBy(service.getAuditDetails().getCreatedBy())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ static class StockIndexV1Transformer implements
private final CommonUtils commonUtils;
private final UserService userService;
private final ProductService productService;

StockIndexV1Transformer(ProjectService projectService, FacilityService facilityService,
CommonUtils commonUtils, UserService userService, ProductService productService) {
this.projectService = projectService;
Expand All @@ -86,11 +87,11 @@ public List<StockIndexV1> transform(Stock stock) {
Map<String, String> boundaryLabelToNameMap = new HashMap<>();
String tenantId = stock.getTenantId();
String projectId = stock.getReferenceId();
Project project = projectService.getProject(projectId,tenantId);
Project project = projectService.getProject(projectId, tenantId);
String projectTypeId = project.getProjectTypeId();
Facility facility = facilityService.findFacilityById(stock.getFacilityId(), stock.getTenantId());
Facility transactingFacility = facilityService.findFacilityById(stock.getTransactingPartyId(), stock.getTenantId());
if (facility != null && facility.getAddress() != null && facility.getAddress().getLocality() != null
if (facility != null && facility.getAddress() != null && facility.getAddress().getLocality() != null
&& facility.getAddress().getLocality().getCode() != null) {
boundaryLabelToNameMap = projectService
.getBoundaryLabelToNameMap(facility.getAddress().getLocality().getCode(), stock.getTenantId());
Expand All @@ -101,20 +102,20 @@ public List<StockIndexV1> transform(Stock stock) {
}
}
ObjectNode boundaryHierarchy = (ObjectNode) commonUtils.getBoundaryHierarchy(tenantId, projectTypeId, boundaryLabelToNameMap);
String facilityLevel = facility != null ? getFacilityLevel(facility): null;
String facilityLevel = facility != null ? getFacilityLevel(facility) : null;
String transactingFacilityLevel = transactingFacility != null ? getFacilityLevel(transactingFacility) : null;
Long facilityTarget = facility != null ? getFacilityTarget(facility): null;
Long facilityTarget = facility != null ? getFacilityTarget(facility) : null;

String facilityType = WAREHOUSE;
String transactingFacilityType = WAREHOUSE;

facilityType = facility != null ? getType(facilityType, facility): facilityType;
facilityType = facility != null ? getType(facilityType, facility) : facilityType;
transactingFacilityType = transactingFacility != null ? getType(transactingFacilityType, transactingFacility) : transactingFacilityType;

List<User> users = userService.getUsers(stock.getTenantId(), stock.getAuditDetails().getCreatedBy());
String syncedTimeStamp = commonUtils.getTimeStampFromEpoch(stock.getAuditDetails().getCreatedTime());
List<String> variantList= new ArrayList<>(Collections.singleton(stock.getProductVariantId()));
List<String> variantList = new ArrayList<>(Collections.singleton(stock.getProductVariantId()));
String productName = String.join(COMMA, productService.getProductVariantNames(variantList, tenantId));
Map<String, String> userInfoMap = userService.getUserInfo(stock.getTenantId(), stock.getAuditDetails().getCreatedBy());

StockIndexV1 stockIndexV1 = StockIndexV1.builder()
.id(stock.getId())
Expand All @@ -125,8 +126,8 @@ public List<StockIndexV1> transform(Stock stock) {
.facilityId(stock.getFacilityId())
.facilityName(facility != null ? facility.getName() : stock.getFacilityId())
.transactingFacilityId(stock.getTransactingPartyId())
.userName(userService.getUserName(users, stock.getAuditDetails().getCreatedBy()))
.role(userService.getStaffRole(stock.getTenantId(), users))
.userName(userInfoMap.get(USERNAME))
.role(userInfoMap.get(ROLE))
.transactingFacilityName(transactingFacility != null ? transactingFacility.getName() : stock.getTransactingPartyId())
.facilityType(facilityType)
.transactingFacilityType(transactingFacilityType)
Expand Down
Loading