From 42c982691bcc95f0f6a6737eecf57197a6772b2c Mon Sep 17 00:00:00 2001 From: sahilchaudhary Date: Mon, 22 Jan 2024 15:45:05 +0530 Subject: [PATCH] API changes for use case for removing and added again for cbPlan --- .../sunbird/cbp/service/CbPlanServiceImpl.java | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/src/main/java/org/sunbird/cbp/service/CbPlanServiceImpl.java b/src/main/java/org/sunbird/cbp/service/CbPlanServiceImpl.java index 3699edf36..fd3a81cb6 100644 --- a/src/main/java/org/sunbird/cbp/service/CbPlanServiceImpl.java +++ b/src/main/java/org/sunbird/cbp/service/CbPlanServiceImpl.java @@ -734,15 +734,21 @@ private boolean updateCbPlanLookupInfo(CbPlan planDto, String orgId, UUID cbPlan List> cbPlanMap = cassandraOperation.getRecordsByProperties(Constants.KEYSPACE_SUNBIRD, Constants.TABLE_CB_PLAN_LOOKUP, cbPlanInfo, null); List cbPlanInfoInsertAssignmentKey = new ArrayList<>(); - List cbPlanInfoRemoveAssignmentKey = new ArrayList<>(); + List cbPlanInfoUpdateAssignmentKey = new ArrayList<>(); + List cbPlanInfoRequestUpdateAssignmentKey = new ArrayList<>(); if (CollectionUtils.isNotEmpty(cbPlanMap)) { List 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(); @@ -766,14 +772,18 @@ private boolean updateCbPlanLookupInfo(CbPlan planDto, String orgId, UUID cbPlan } } - for (String assignmentTypeInfo : cbPlanInfoRemoveAssignmentKey) { + for (String assignmentTypeInfo : cbPlanInfoUpdateAssignmentKey) { Map 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 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 resp = cassandraOperation.updateRecord(Constants.KEYSPACE_SUNBIRD, Constants.TABLE_CB_PLAN_LOOKUP, lookupInfoUpdated, compositeKey);