Skip to content

Commit

Permalink
API changes for use case for removing and added again for cbPlan
Browse files Browse the repository at this point in the history
  • Loading branch information
Sahil-tarento committed Jan 22, 2024
1 parent c19bc01 commit 42c9826
Showing 1 changed file with 14 additions and 4 deletions.
18 changes: 14 additions & 4 deletions src/main/java/org/sunbird/cbp/service/CbPlanServiceImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -734,15 +734,21 @@ private boolean updateCbPlanLookupInfo(CbPlan planDto, String orgId, UUID cbPlan
List<Map<String, Object>> cbPlanMap = cassandraOperation.getRecordsByProperties(Constants.KEYSPACE_SUNBIRD,
Constants.TABLE_CB_PLAN_LOOKUP, cbPlanInfo, null);
List<String> cbPlanInfoInsertAssignmentKey = new ArrayList<>();
List<String> cbPlanInfoRemoveAssignmentKey = new ArrayList<>();
List<String> cbPlanInfoUpdateAssignmentKey = new ArrayList<>();
List<String> cbPlanInfoRequestUpdateAssignmentKey = new ArrayList<>();
if (CollectionUtils.isNotEmpty(cbPlanMap)) {
List<String> assignmentKeyInfoList = cbPlanMap.stream()
.map(c -> (String) c.get(Constants.CB_ASSIGNMENT_TYPE_INFO_KEY)).collect(Collectors.toList());
cbPlanInfoInsertAssignmentKey = planDto.getAssignmentTypeInfo().stream()
.filter(assignmentKeyInfo -> !assignmentKeyInfoList.contains(assignmentKeyInfo))
.collect(Collectors.toList());
cbPlanInfoRemoveAssignmentKey = assignmentKeyInfoList.stream()
cbPlanInfoUpdateAssignmentKey = assignmentKeyInfoList.stream()
.filter(key -> !planDto.getAssignmentTypeInfo().contains(key)).collect(Collectors.toList());
cbPlanInfoRequestUpdateAssignmentKey = cbPlanMap.stream().filter(key -> (planDto.getAssignmentTypeInfo().contains((String)key.get(Constants.CB_ASSIGNMENT_TYPE_INFO_KEY))
&& (Boolean)key.get(Constants.CB_IS_ACTIVE) == false))
.map(key -> (String) key.get(Constants.CB_ASSIGNMENT_TYPE_INFO_KEY))
.collect(Collectors.toList());
cbPlanInfoUpdateAssignmentKey.addAll(cbPlanInfoRequestUpdateAssignmentKey);
isUpdatedLookup = updateLookupInfoForProperties(cbPlanMap, planDto);
} else {
cbPlanInfoInsertAssignmentKey = planDto.getAssignmentTypeInfo();
Expand All @@ -766,14 +772,18 @@ private boolean updateCbPlanLookupInfo(CbPlan planDto, String orgId, UUID cbPlan
}
}

for (String assignmentTypeInfo : cbPlanInfoRemoveAssignmentKey) {
for (String assignmentTypeInfo : cbPlanInfoUpdateAssignmentKey) {
Map<String, Object> compositeKey = new HashMap<>();
compositeKey.put(Constants.ORG_ID, orgId);
compositeKey.put(Constants.CB_PLAN_ID, cbPlanId);
compositeKey.put(Constants.CB_ASSIGNMENT_TYPE_INFO_KEY, assignmentTypeInfo);

Map<String, Object> lookupInfoUpdated = new HashMap<>();
lookupInfoUpdated.put(Constants.CB_IS_ACTIVE, false);
if (CollectionUtils.isNotEmpty(cbPlanInfoRequestUpdateAssignmentKey) && cbPlanInfoRequestUpdateAssignmentKey.contains(assignmentTypeInfo)) {
lookupInfoUpdated.put(Constants.CB_IS_ACTIVE, true);
} else {
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);
Expand Down

0 comments on commit 42c9826

Please sign in to comment.