Skip to content

Commit

Permalink
UserLookup Properties Update (#422)
Browse files Browse the repository at this point in the history
* UserLookup Properties Update

* Adding condition for date check
  • Loading branch information
Sahil-tarento authored Jan 11, 2024
1 parent 54822a8 commit aaed9b1
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions src/main/java/org/sunbird/cbp/service/CbPlanServiceImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -742,6 +742,7 @@ private boolean updateCbPlanLookupInfo(CbPlan planDto, String orgId, UUID cbPlan
.collect(Collectors.toList());
cbPlanInfoRemoveAssignmentKey = assignmentKeyInfoList.stream()
.filter(key -> !planDto.getAssignmentTypeInfo().contains(key)).collect(Collectors.toList());
isUpdatedLookup = updateLookupInfoForProperties(cbPlanMap, planDto);
} else {
cbPlanInfoInsertAssignmentKey = planDto.getAssignmentTypeInfo();
}
Expand Down Expand Up @@ -772,6 +773,7 @@ private boolean updateCbPlanLookupInfo(CbPlan planDto, String orgId, UUID cbPlan

Map<String, Object> lookupInfoUpdated = new HashMap<>();
lookupInfoUpdated.put(Constants.CB_IS_ACTIVE, false);
lookupInfoUpdated.put(Constants.END_DATE, planDto.getEndDate());
Map<String, Object> resp = cassandraOperation.updateRecord(Constants.KEYSPACE_SUNBIRD,
Constants.TABLE_CB_PLAN_LOOKUP, lookupInfoUpdated, compositeKey);
if (resp.get(Constants.RESPONSE).equals(Constants.SUCCESS)) {
Expand Down Expand Up @@ -1068,4 +1070,28 @@ private boolean validateRequestCbplanPayload(String userId, Map<String, Object>
}
return true;
}

private boolean updateLookupInfoForProperties(List<Map<String, Object>> cbPlanMap, CbPlan planDto) {
boolean isUpdatedLookup = true;
for (Map<String, Object> cbLookupInfo : cbPlanMap) {
Date endDate = (Date)cbLookupInfo.get(Constants.END_DATE);
if (!planDto.getEndDate().equals(endDate)) {
Map<String, Object> compositeKey = new HashMap<>();
compositeKey.put(Constants.ORG_ID, planDto.getOrgId());
compositeKey.put(Constants.CB_PLAN_ID, planDto.getId());
compositeKey.put(Constants.CB_ASSIGNMENT_TYPE_INFO_KEY, cbLookupInfo.get(Constants.CB_ASSIGNMENT_TYPE_INFO_KEY));

Map<String, Object> lookupInfoUpdated = new HashMap<>();
lookupInfoUpdated.put(Constants.END_DATE, planDto.getEndDate());
Map<String, Object> resp = cassandraOperation.updateRecord(Constants.KEYSPACE_SUNBIRD,
Constants.TABLE_CB_PLAN_LOOKUP, lookupInfoUpdated, compositeKey);
if (resp.get(Constants.RESPONSE).equals(Constants.SUCCESS)) {
isUpdatedLookup = true;
} else {
isUpdatedLookup = false;
}
}
}
return isUpdatedLookup;
}
}

0 comments on commit aaed9b1

Please sign in to comment.