Skip to content

Commit af76551

Browse files
4.8.27.2 dev v2 (#27)
* Updated Table name * Added test Cases (#23) * ReadContentState API Added * Made changes according to review * Made changes according to review * Added fields validation * Added fields validation * ReadContentState API Added (#17) * ReadContentState API Added * Made changes according to review * Made changes according to review * Added fields validation * Added fields validation * Added contentStateUpdate API * Made changes according to the review * changed according to review * Added contentStateUpdate API (#18) * ReadContentState API Added * Made changes according to review * Made changes according to review * Added fields validation * Added fields validation * Added contentStateUpdate API * Made changes according to the review * changed according to review * Updated the contentUpdate API url * Updated the contentUpdate API url * Updated the contentUpdate API url * Updated the contentStateUpdate API url (#19) * ReadContentState API Added * Made changes according to review * Made changes according to review * Added fields validation * Added fields validation * Added contentStateUpdate API * Made changes according to the review * changed according to review * Updated the contentUpdate API url * Updated the contentUpdate API url * Updated the contentUpdate API url * Modified the API response for contentStateRead API * Modified contentStateRead API response (#20) * ReadContentState API Added * Made changes according to review * Made changes according to review * Added fields validation * Added fields validation * Added contentStateUpdate API * Made changes according to the review * changed according to review * Updated the contentUpdate API url * Updated the contentUpdate API url * Updated the contentUpdate API url * Modified the API response for contentStateRead API * Converting completion percentage to decimal * Converting completion percentage to decimal * Converting completion percentage to decimal (#21) * ReadContentState API Added * Made changes according to review * Made changes according to review * Added fields validation * Added fields validation * Added contentStateUpdate API * Made changes according to the review * changed according to review * Updated the contentUpdate API url * Updated the contentUpdate API url * Updated the contentUpdate API url * Modified the API response for contentStateRead API * Converting completion percentage to decimal * Converting completion percentage to decimal * optimized few classes * Enhancements in code and migration for string to integer for access settings * Added implementation assignedcourses API and improved code coverage * Updated application properties * Fixed issues in bitset convertion * Added test cases for new APIs --------- Co-authored-by: karthik-tarento <karthikeyan.rajendran@tarento.com> * Increased code coverage (#24) * ReadContentState API Added * Made changes according to review * Made changes according to review * Added fields validation * Added fields validation * ReadContentState API Added (#17) * ReadContentState API Added * Made changes according to review * Made changes according to review * Added fields validation * Added fields validation * Added contentStateUpdate API * Made changes according to the review * changed according to review * Added contentStateUpdate API (#18) * ReadContentState API Added * Made changes according to review * Made changes according to review * Added fields validation * Added fields validation * Added contentStateUpdate API * Made changes according to the review * changed according to review * Updated the contentUpdate API url * Updated the contentUpdate API url * Updated the contentUpdate API url * Updated the contentStateUpdate API url (#19) * ReadContentState API Added * Made changes according to review * Made changes according to review * Added fields validation * Added fields validation * Added contentStateUpdate API * Made changes according to the review * changed according to review * Updated the contentUpdate API url * Updated the contentUpdate API url * Updated the contentUpdate API url * Modified the API response for contentStateRead API * Modified contentStateRead API response (#20) * ReadContentState API Added * Made changes according to review * Made changes according to review * Added fields validation * Added fields validation * Added contentStateUpdate API * Made changes according to the review * changed according to review * Updated the contentUpdate API url * Updated the contentUpdate API url * Updated the contentUpdate API url * Modified the API response for contentStateRead API * Converting completion percentage to decimal * Converting completion percentage to decimal * Converting completion percentage to decimal (#21) * ReadContentState API Added * Made changes according to review * Made changes according to review * Added fields validation * Added fields validation * Added contentStateUpdate API * Made changes according to the review * changed according to review * Updated the contentUpdate API url * Updated the contentUpdate API url * Updated the contentUpdate API url * Modified the API response for contentStateRead API * Converting completion percentage to decimal * Converting completion percentage to decimal * optimized few classes * Enhancements in code and migration for string to integer for access settings * Added implementation assignedcourses API and improved code coverage * Updated application properties * Fixed issues in bitset convertion * Added test cases for new APIs * Increased code coverage --------- Co-authored-by: karthik-tarento <karthikeyan.rajendran@tarento.com> * Modified upsert API (#25) * Modified the testCase (#26) --------- Co-authored-by: Ruksana Semeir <111083125+ruksana2808@users.noreply.github.com>
1 parent aff1dcc commit af76551

File tree

7 files changed

+417
-34
lines changed

7 files changed

+417
-34
lines changed

src/main/java/com/igot/cb/service/AccessSettingMigrationServiceImpl.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -119,16 +119,16 @@ public boolean processAccessSettingRule(Map<String, Object> accessSettingMap) th
119119

120120
@SuppressWarnings("unchecked")
121121
protected boolean updateContextDataWithIdMap(String contextId, Map<String, Object> accessControl,
122-
Map<String, Object> accessControlIdMap) {
122+
Map<String, Object> accessControlIdMap) {
123123
List<Map<String, Object>> userGroupsList = (List<Map<String, Object>>) accessControl
124124
.get(Constants.USER_GROUPS);
125-
if (CollectionUtils.isEmpty(userGroupsList)) {
126-
log.error("User groups are missing in access control for contextId: {}", contextId);
127-
return false;
128-
}
129125
List<Map<String, Object>> userGroupIdMapList = new ArrayList<>();
130126
accessControlIdMap.put(Constants.USER_GROUPS, userGroupIdMapList);
131127
accessControlIdMap.put(Constants.VERSION, 1);
128+
if (CollectionUtils.isEmpty(userGroupsList)) {
129+
log.error("User groups are missing in access control for contextId: {}", contextId);
130+
return true;
131+
}
132132

133133
for (Map<String, Object> userGroup : userGroupsList) {
134134
String userGroupId = (String) userGroup.get(Constants.USER_GROUP_ID);

src/main/java/com/igot/cb/service/AccessSettingsServiceImpl.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ public ApiResponse upsert(Map<String, Object> userGroupDetails, String authToken
5757
accessRuleData.put(Constants.IS_ARCHIVED, false);
5858
if (accessSettingMigrationService.processAccessSettingRule(accessRuleData)) {
5959
cassandraOperation.insertRecord(Constants.KEYSPACE_SUNBIRD_COURSE,
60-
Constants.ACCESS_SETTINGS_RULES_TABLE, accessRuleData);
60+
Constants.ACCESS_SETTINGS_RULES_TABLE_V2, accessRuleData);
6161
response.getResult().put(Constants.MSG, Constants.CREATED_RULES);
6262
// Remove all other keys, and put a single object after message
6363
Map<String, Object> payload = new HashMap<>();
@@ -90,7 +90,7 @@ public ApiResponse read(String contentId) {
9090
fields.add(Constants.CONTEXT_DATA);
9191
fields.add(Constants.IS_ARCHIVED);
9292
List<Map<String, Object>> accessSettingRule = cassandraOperation.getRecordsByProperties(
93-
Constants.KEYSPACE_SUNBIRD_COURSE, Constants.ACCESS_SETTINGS_RULES_TABLE, propertyMap,
93+
Constants.KEYSPACE_SUNBIRD_COURSE, Constants.ACCESS_SETTINGS_RULES_TABLE_V2, propertyMap,
9494
fields, null);
9595
if (!accessSettingRule.isEmpty()) {
9696
Map<String, Object> record = accessSettingRule.get(0);
@@ -148,7 +148,7 @@ public ApiResponse delete(String contentId) {
148148
accessRuleData.put(Constants.CONTEXT_DATA, "");
149149
accessRuleData.put(Constants.IS_ARCHIVED, false);
150150
cassandraOperation.insertRecord(Constants.KEYSPACE_SUNBIRD_COURSE,
151-
Constants.ACCESS_SETTINGS_RULES_TABLE, accessRuleData);
151+
Constants.ACCESS_SETTINGS_RULES_TABLE_V2, accessRuleData);
152152
response.setResponseCode(HttpStatus.OK);
153153
response.getResult().put(Constants.MSG, "Access settings deleted successfully");
154154
return response;

src/main/java/com/igot/cb/util/KeyManager.java

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -68,14 +68,16 @@ public KeyData getPublicKey(String keyId) {
6868
*/
6969
public static PublicKey loadPublicKey(String key) throws Exception {
7070
// Remove header and footer from the key string
71-
String cleanedKey = key.replaceAll("(-+BEGIN PUBLIC KEY-+)", "")
72-
.replaceAll("(-+END PUBLIC KEY-+)", "")
73-
.replaceAll("[\\r\\n]+", "");
74-
// Decode Base64 content
75-
byte[] keyBytes = Base64.getDecoder().decode(cleanedKey);
76-
// Generate PublicKey object
77-
X509EncodedKeySpec spec = new X509EncodedKeySpec(keyBytes);
78-
KeyFactory keyFactory = KeyFactory.getInstance("RSA");
79-
return keyFactory.generatePublic(spec);
71+
String publicKey = new String(key.getBytes(), StandardCharsets.UTF_8);
72+
// Remove header and footer from the key string
73+
publicKey = publicKey.replaceAll("(-+BEGIN PUBLIC KEY-+)", "");
74+
publicKey = publicKey.replaceAll("(-+END PUBLIC KEY-+)", "");
75+
publicKey = publicKey.replaceAll("[\\r\\n]+", "");
76+
// Decode the key string from Base64
77+
byte[] keyBytes = Base64Util.decode(publicKey.getBytes("UTF-8"), Base64Util.DEFAULT);
78+
// Convert the key bytes to a PublicKey object
79+
X509EncodedKeySpec x509publicKey = new X509EncodedKeySpec(keyBytes);
80+
KeyFactory kf = KeyFactory.getInstance("RSA");
81+
return kf.generatePublic(x509publicKey);
8082
}
8183
}
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
package com.igot.cb.controller;
2+
3+
import static org.junit.jupiter.api.Assertions.assertEquals;
4+
import static org.mockito.Mockito.when;
5+
import static org.mockito.Mockito.verify;
6+
7+
import java.util.HashMap;
8+
import java.util.Map;
9+
10+
import com.igot.cb.model.ApiResponse;
11+
import com.igot.cb.service.ContentStateServiceImpl;
12+
import com.igot.cb.util.Constants;
13+
14+
import org.junit.jupiter.api.Test;
15+
import org.junit.jupiter.api.extension.ExtendWith;
16+
import org.mockito.InjectMocks;
17+
import org.mockito.Mock;
18+
import org.mockito.junit.jupiter.MockitoExtension;
19+
import org.springframework.http.HttpStatus;
20+
import org.springframework.http.ResponseEntity;
21+
22+
@ExtendWith(MockitoExtension.class)
23+
public class CourseControllerTest {
24+
25+
@Mock
26+
private ContentStateServiceImpl courseService;
27+
28+
@InjectMocks
29+
private CourseController courseController;
30+
31+
@Test
32+
void testReadContentState() {
33+
Map<String, Object> requestBody = new HashMap<>();
34+
String authToken = "Bearer test-token";
35+
ApiResponse mockResponse = new ApiResponse();
36+
mockResponse.setResponseCode(HttpStatus.OK);
37+
38+
when(courseService.readContentState(requestBody, authToken)).thenReturn(mockResponse);
39+
40+
ResponseEntity<Object> response = courseController.readContentState(requestBody, authToken);
41+
42+
assertEquals(HttpStatus.OK, response.getStatusCode());
43+
assertEquals(mockResponse, response.getBody());
44+
verify(courseService).readContentState(requestBody, authToken);
45+
}
46+
47+
@Test
48+
void testUpdateContentState() {
49+
Map<String, Object> requestBody = new HashMap<>();
50+
String authToken = "Bearer test-token";
51+
ApiResponse mockResponse = new ApiResponse();
52+
mockResponse.setResponseCode(HttpStatus.OK);
53+
54+
when(courseService.updateContentState(requestBody, authToken)).thenReturn(mockResponse);
55+
56+
ResponseEntity<Object> response = courseController.updateContentState(requestBody, authToken);
57+
58+
assertEquals(HttpStatus.OK, response.getStatusCode());
59+
assertEquals(mockResponse, response.getBody());
60+
verify(courseService).updateContentState(requestBody, authToken);
61+
}
62+
}

src/test/java/com/igot/cb/service/AccessSettingMigrationServiceImplTest.java

Lines changed: 50 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,7 @@
1616
import static org.mockito.Mockito.verify;
1717
import static org.mockito.Mockito.when;
1818

19-
import java.util.Collections;
20-
import java.util.HashMap;
21-
import java.util.List;
22-
import java.util.Map;
19+
import java.util.*;
2320

2421
import org.junit.jupiter.api.Test;
2522
import org.junit.jupiter.api.extension.ExtendWith;
@@ -147,24 +144,60 @@ void testMigrateAccessSettingRules_exception() {
147144
@Test
148145
void testUpdateContextDataWithIdMap_emptyUserGroups() throws Exception {
149146
String contextId = "ctx-empty-groups";
150-
151147
Map<String, Object> accessControl = new HashMap<>();
152-
accessControl.put(Constants.USER_GROUPS, List.of()); // empty list
148+
accessControl.put("version", 1);
149+
List<Map<String, Object>> userGroups = new ArrayList<>();
150+
151+
Map<String, Object> userGroup1 = new HashMap<>();
152+
userGroup1.put("userGroupId", "uuid1");
153+
userGroup1.put("userGroupName", "User Group 1");
154+
List<Map<String, Object>> criteriaList1 = new ArrayList<>();
155+
Map<String, Object> rule1 = new HashMap<>();
156+
rule1.put("ruleGroupKey", "rootOrgId");
157+
rule1.put("ruleGroupValue", new ArrayList<>());
158+
Map<String, Object> rule2 = new HashMap<>();
159+
rule2.put("userGroupKey", "designation");
160+
rule2.put("userGroupValue", java.util.Arrays.asList("Post Master", "Accountant"));
161+
criteriaList1.add(rule1);
162+
criteriaList1.add(rule2);
163+
userGroup1.put("userGroupCriteriaList", criteriaList1);
164+
userGroups.add(userGroup1);
165+
166+
// User Group 2
167+
Map<String, Object> userGroup2 = new HashMap<>();
168+
userGroup2.put("userGroupId", "uuid2");
169+
userGroup2.put("userGroupName", "User Group 2");
170+
List<Map<String, Object>> criteriaList2 = new ArrayList<>();
171+
Map<String, Object> rule3 = new HashMap<>();
172+
rule3.put("userGroupKey", "rootOrgId");
173+
rule3.put("userGroupValue", java.util.Arrays.asList("orgId3"));
174+
criteriaList2.add(rule3);
175+
userGroup2.put("userGroupCriteriaList", criteriaList2);
176+
userGroups.add(userGroup2);
177+
178+
// User Group 3
179+
Map<String, Object> userGroup3 = new HashMap<>();
180+
userGroup3.put("userGroupId", "uuid3");
181+
userGroup3.put("userGroupName", "User Group 3");
182+
List<Map<String, Object>> criteriaList3 = new ArrayList<>();
183+
Map<String, Object> rule4 = new HashMap<>();
184+
rule4.put("userGroupKey", "user");
185+
rule4.put("userGroupValue", java.util.Arrays.asList("userId1", "userId2"));
186+
criteriaList3.add(rule4);
187+
userGroup3.put("userGroupCriteriaList", criteriaList3);
188+
userGroups.add(userGroup3);
189+
190+
accessControl.put("userGroups", userGroups);
153191

154192
Map<String, Object> accessControlIdMap = new HashMap<>();
155-
156-
migrationService = new AccessSettingMigrationServiceImpl(cassandraOperation, contentService,
157-
idMapCacheMgr);
158-
159-
// Use reflection to test private method or move it to package-private for
160-
// easier testing
193+
migrationService = new AccessSettingMigrationServiceImpl(cassandraOperation, contentService, idMapCacheMgr);
161194
var method = AccessSettingMigrationServiceImpl.class.getDeclaredMethod(
162-
"updateContextDataWithIdMap", String.class, Map.class, Map.class);
195+
"updateContextDataWithIdMap", String.class, Map.class, Map.class);
163196
method.setAccessible(true);
164-
165-
method.invoke(migrationService, contextId, accessControl, accessControlIdMap);
166-
167-
assertTrue(accessControlIdMap.isEmpty());
197+
boolean result = (boolean) method.invoke(migrationService, contextId, accessControl, accessControlIdMap);
198+
assertFalse(result);
199+
assertTrue(accessControlIdMap.containsKey(Constants.USER_GROUPS));
200+
assertTrue(((List<?>) accessControlIdMap.get(Constants.USER_GROUPS)).isEmpty());
168201
}
169202

170203
@Test

0 commit comments

Comments
 (0)