Skip to content

Commit

Permalink
4.8.15 dev v2 (#610)
Browse files Browse the repository at this point in the history
* KB-5130 | DEV| Assessment | BE | Enhancement in Consumption Logic for the QuestionWeightage Assessment Type (#586)

1. Enhancements in the assessment consumption logic.

* Fix for Save Assessment

* Fix for Save Assessment

* Fix for Save Assessment

* KB-5130 | DEV| Assessment | BE | Enhancement in Consumption Logic for the QuestionWeightage Assessment Type (#587)

1. Score calculation fix.

* Assessment SavePoint

* 4.8.15 assessment score calcln fix (#588)

* KB-5130 | DEV| Assessment | BE | Enhancement in Consumption Logic for the QuestionWeightage Assessment Type

1. Score calculation fix.

* KB-5130 | DEV| Assessment | BE | Enhancement in Consumption Logic for the QuestionWeightage Assessment Type

1. Score calculation issue fix.

* Assessment Defect Fix

* Practise Assessment Defect Fix

* DEV| Assessment | BE | Enhancement in Consumption Logic for the QuestionWeightage Assessment Type. (#591)

1. Section name is added.

* Assessment Configurations for V5 (#601)

Assessment Configurations for V5

* added code for user bulk upload using csv

* added code for user bulk upload using csv

* updated code based on code review comments

* 4.8.15 dev v2 (#608)

* added code for user bulk upload using csv

* added code for user bulk upload using csv

* updated code based on code review comments

* updated code based on code review comments

* updated code based on code review comments (#614)

* Modified validation message for employee Id (#613)

* Added exploreCourse update and delete APIs (#606)

* Added exploreCourse update and delete APIs

* Added exploreCourse update and delete APIs

* Changed method type to POST and delete API variable refactored

* Added code for competencyListing API

* Added code for competencyListing API

* Resolved conflict

* Resolved conflicts

* Resolved conflicts

* Resolved conflicts

* update the response (#617)

* update the response for profileImage (#618)

---------

Co-authored-by: tarentomaheshvakkund <[email protected]>
Co-authored-by: saipradeep_ravipati <[email protected]>
Co-authored-by: anil <[email protected]>
Co-authored-by: anilkumarkammalapalli <[email protected]>
Co-authored-by: SaipradeepR <[email protected]>
Co-authored-by: Haritest <[email protected]>
Co-authored-by: ravisaurav-tarento <[email protected]>
Co-authored-by: ruksana2808 <[email protected]>
Co-authored-by: Sahil-tarento <[email protected]>
  • Loading branch information
10 people authored Jun 21, 2024
1 parent 08e900d commit 1fa2796
Show file tree
Hide file tree
Showing 10 changed files with 524 additions and 12 deletions.
5 changes: 5 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,11 @@
<artifactId>jjwt</artifactId>
<version>0.9.1</version>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-csv</artifactId>
<version>1.9.0</version>
</dependency>
</dependencies>

<build>
Expand Down
3 changes: 3 additions & 0 deletions src/main/java/org/sunbird/common/util/Constants.java
Original file line number Diff line number Diff line change
Expand Up @@ -1088,6 +1088,9 @@ public class Constants {
public static final String SECTION_LEVEL_DEFINITION = "sectionLevelDefinition";

public static final String ASSESSMENT_HIERARCHY_SAVE_NOT_AVBL = "Assessment hierarchy save point not available, failed to process request";
public static final String SEQUENCE_NO = "seqno";
public static final String API_EXPLORE_COURSE_UPDATE = "api.explore.course.update";
public static final String API_EXPLORE_COURSE_DELETE = "api.explore.course.delete";

private Constants() {
throw new IllegalStateException("Utility class");
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
package org.sunbird.course.controller;

import java.util.Map;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;
import org.sunbird.common.model.SBApiResponse;
import org.sunbird.course.service.ExploreCourseService;
Expand Down Expand Up @@ -37,4 +42,16 @@ public ResponseEntity<SBApiResponse> getPublicCourseListV2() {
SBApiResponse response = courseService.getExploreCourseListV2();
return new ResponseEntity<>(response, response.getResponseCode());
}

@PostMapping("/course/v1/explore/upsert")
public ResponseEntity<SBApiResponse> upsertCourse(@RequestBody Map<String, Object> request) {
SBApiResponse response = courseService.upsertExploreCourse(request);
return new ResponseEntity<>(response, response.getResponseCode());
}

@DeleteMapping("/course/v1/explore/delete/{courseId}")
public ResponseEntity<SBApiResponse> deleteExploreCourse(@PathVariable String courseId) {
SBApiResponse response = courseService.deleteExploreCourse(courseId);
return new ResponseEntity<>(response, response.getResponseCode());
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package org.sunbird.course.service;

import java.util.Map;
import org.sunbird.common.model.SBApiResponse;

/**
Expand Down Expand Up @@ -32,4 +33,8 @@ public interface ExploreCourseService {
* @return - Course details in Sunbird API Response format.
*/
public SBApiResponse getExploreCourseListV2();

public SBApiResponse upsertExploreCourse(Map<String, Object> request);

public SBApiResponse deleteExploreCourse(String id);
}
132 changes: 132 additions & 0 deletions src/main/java/org/sunbird/course/service/ExploreCourseServiceImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.stereotype.Service;
import org.springframework.util.ObjectUtils;
import org.sunbird.cache.RedisCacheMgr;
import org.sunbird.cassandra.utils.CassandraOperation;
import org.sunbird.common.model.SBApiResponse;
Expand All @@ -20,6 +21,7 @@
import org.sunbird.common.util.Constants;
import org.sunbird.common.util.ProjectUtil;
import org.sunbird.core.exception.ApplicationLogicError;
import org.sunbird.staff.model.StaffInfo;

/**
* Implementation of ExploreCourseService
Expand Down Expand Up @@ -183,4 +185,134 @@ public SBApiResponse getExploreCourseListV2() {
}
return response;
}

@Override
public SBApiResponse upsertExploreCourse(Map<String, Object> requestObj) {
SBApiResponse response =
ProjectUtil.createDefaultResponse(Constants.API_EXPLORE_COURSE_UPDATE);
logger.info("ExploreCourseService::upsertExploreCourse:inside method");
Map<String, Object> masterData = (Map<String, Object>) requestObj.get(Constants.REQUEST);
String errMsg = validateUpsertRequest(masterData);
if (StringUtils.isNotBlank(errMsg)) {
response.getParams().setErrmsg(errMsg);
response.setResponseCode(HttpStatus.BAD_REQUEST);
return response;
}
try {
List<?> dataList = (List<?>) masterData.get(Constants.DATA);
Iterator<?> iterator = dataList.iterator();

while (iterator.hasNext()) {
Map<?, ?> itemMap = (Map) iterator.next();
Map<String, Object> request = new HashMap<>();
request.put(Constants.IDENTIFIER, itemMap.get(Constants.IDENTIFIER));

List<Map<String, Object>> listOfMasterData = cassandraOperation.getRecordsByProperties(
Constants.KEYSPACE_SUNBIRD, Constants.TABLE_EXPLORE_COURSE_LIST_V2, request,
new ArrayList<>());

if (CollectionUtils.isNotEmpty(listOfMasterData)) {
Map<String, Object> updateRequest = new HashMap<>();
updateRequest.put(Constants.SEQUENCE_NO, itemMap.get(Constants.SEQUENCE_NO));
Map<String, Object> updateResponse = cassandraOperation.updateRecord(
Constants.KEYSPACE_SUNBIRD, Constants.TABLE_EXPLORE_COURSE_LIST_V2, updateRequest,
request);

if (updateResponse != null && !Constants.SUCCESS.equalsIgnoreCase(
(String) updateResponse.get(Constants.RESPONSE))) {
errMsg = String.format("Failed to update details");
response.getParams().setErrmsg(errMsg);
response.setResponseCode(HttpStatus.BAD_REQUEST);
break;
} else {
response.getResult().put(Constants.STATUS, Constants.CREATED);
}
} else {
request.put(Constants.SEQUENCE_NO, itemMap.get(Constants.SEQUENCE_NO));
response = cassandraOperation.insertRecord(Constants.KEYSPACE_SUNBIRD,
Constants.TABLE_EXPLORE_COURSE_LIST_V2, request);
response.setResponseCode(HttpStatus.OK);
if (!Constants.SUCCESS.equalsIgnoreCase((String) response.get(Constants.RESPONSE))) {
errMsg = String.format("Failed to create position");
response.setResponseCode(HttpStatus.BAD_REQUEST);
response.getParams().setErrmsg(errMsg);
break;
} else {
response.getResult().put(Constants.STATUS, Constants.CREATED);
}
}
}
} catch (Exception e) {
errMsg = String.format("Exception occurred while performing upsert operation");
logger.error(errMsg, e);
}
if (StringUtils.isNotBlank(errMsg)) {
response.getParams().setStatus(Constants.FAILED);
response.getParams().setErrmsg(errMsg);
response.setResponseCode(HttpStatus.BAD_REQUEST);
}
return response;
}

@Override
public SBApiResponse deleteExploreCourse(String id) {
SBApiResponse response = ProjectUtil.createDefaultResponse(Constants.API_EXPLORE_COURSE_DELETE);
Map<String, Object> keyMap = new HashMap<>();
keyMap.put(Constants.IDENTIFIER, id);
try {
List<Map<String, Object>> existingDetails = cassandraOperation.getRecordsByProperties(
Constants.KEYSPACE_SUNBIRD,
Constants.TABLE_EXPLORE_COURSE_LIST_V2, keyMap, null);
if (!existingDetails.isEmpty()) {
cassandraOperation.deleteRecord(Constants.KEYSPACE_SUNBIRD,
Constants.TABLE_EXPLORE_COURSE_LIST_V2, keyMap);
response.getParams().setStatus(Constants.SUCCESSFUL);
response.getResult().put(Constants.STATUS, Constants.DELETED);
response.getResult().put(Constants.MESSAGE, "Deleted Explore Course for Id: " + id);
response.setResponseCode(HttpStatus.OK);
} else {
String errMsg = "Failed to find Course for OrgId: " + ", Id: " + id;
logger.error(errMsg);
response.getParams().setErrmsg(errMsg);
response.setResponseCode(HttpStatus.BAD_REQUEST);
}
} catch (Exception ex) {
String errMsg =
"Exception occurred while deleting the ExploredCourse. Exception: " + ex.getMessage();
logger.error(errMsg, ex);
response.getParams().setErrmsg(errMsg);
response.setResponseCode(HttpStatus.INTERNAL_SERVER_ERROR);
}
return response;
}

private String validateUpsertRequest(Map<String, Object> masterData) {
logger.info("ExploreCourseService::validateUpsertRequest:inside method");
StringBuilder strBuilder = new StringBuilder();
if (ObjectUtils.isEmpty(masterData)) {
strBuilder.append("Model object is empty.");
return strBuilder.toString();
}
// Check if the requestData contains the key "data"
if (!masterData.containsKey(Constants.DATA) || !(masterData.get(
Constants.DATA) instanceof List)) {
strBuilder.append("Data is missing or invalid.");
return strBuilder.toString();
}
List<?> dataList = (List<?>) masterData.get(Constants.DATA);
for (Object item : dataList) {
if (!(item instanceof Map)) {
strBuilder.append("Item in data list is not a valid map.");
return strBuilder.toString();
}
Map<?, ?> itemMap = (Map<?, ?>) item;
if (!itemMap.containsKey(Constants.IDENTIFIER)) {
strBuilder.append("Item is missing 'identifier'. ");
}
if (!itemMap.containsKey(Constants.SEQUENCE_NO)) {
strBuilder.append("Item is missing seqno. ");
}
}
return strBuilder.toString();
}
}
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
package org.sunbird.profile.controller;

import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.net.URLDecoder;
import java.util.HashMap;
import java.util.Map;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PatchMapping;
Expand All @@ -20,6 +23,9 @@
import org.sunbird.common.model.SBApiResponse;
import org.sunbird.common.util.Constants;
import org.sunbird.profile.service.ProfileService;
import org.sunbird.profile.service.UserBulkUploadService;

import javax.swing.plaf.PanelUI;

@RestController
public class ProfileController {
Expand Down Expand Up @@ -156,4 +162,16 @@ public ResponseEntity<?> profileUpdateV2(
SBApiResponse response = profileService.profileUpdateV2(request, userToken, authToken, rootOrgId);
return new ResponseEntity<>(response, response.getResponseCode());
}

@PostMapping("/user/v2/bulkupload")
public ResponseEntity<?> bulkUploadV2(@RequestParam(value = "file", required = true) MultipartFile multipartFile,
@RequestHeader(Constants.X_AUTH_USER_ORG_ID) String rootOrgId,
@RequestHeader(Constants.X_AUTH_USER_CHANNEL) String channel,
@RequestHeader(Constants.X_AUTH_USER_ID) String userId,
@RequestHeader(Constants.X_AUTH_TOKEN) String userAuthToken) throws UnsupportedEncodingException {
log.info(String.format("bulkupload channel name:%s,OrgId:%s",
URLDecoder.decode(channel, "UTF-8"), rootOrgId));
SBApiResponse uploadResponse = profileService.bulkUpload(multipartFile, rootOrgId, URLDecoder.decode(channel, "UTF-8"), userId, userAuthToken);
return new ResponseEntity<>(uploadResponse, uploadResponse.getResponseCode());
}
}
2 changes: 2 additions & 0 deletions src/main/java/org/sunbird/profile/service/ProfileService.java
Original file line number Diff line number Diff line change
Expand Up @@ -54,4 +54,6 @@ public interface ProfileService {
* @throws Exception if any error occurs during the profile update process.
*/
SBApiResponse profileUpdateV2(Map<String, Object> request, String userToken, String authToken, String rootOrgId) ;

SBApiResponse bulkUploadV2(MultipartFile mFile, String orgId, String orgName, String userId, String userAuthToken);
}
47 changes: 47 additions & 0 deletions src/main/java/org/sunbird/profile/service/ProfileServiceImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -2166,6 +2166,53 @@ private String validateExistingPhoneEmail(Map<String, Object> profileDetailsMap)
return "";
}

@Override
public SBApiResponse bulkUploadV2(MultipartFile mFile, String orgId, String channel, String userId, String userAuthToken) {
SBApiResponse response = ProjectUtil.createDefaultResponse(Constants.API_USER_BULK_UPLOAD);
try {
if (isFileExistForProcessingForMDO(orgId)) {
setErrorDataForMdo(response, "Failed to upload for another request as previous request is in processing state, please try after some time.");
return response;
}
SBApiResponse uploadResponse = storageService.uploadFile(mFile, serverConfig.getBulkUploadContainerName());
if (!HttpStatus.OK.equals(uploadResponse.getResponseCode())) {
setErrorData(response, String.format("Failed to upload file. Error: %s",
(String) uploadResponse.getParams().getErrmsg()));
return response;
}

Map<String, Object> uploadedFile = new HashMap<>();
uploadedFile.put(Constants.ROOT_ORG_ID, orgId);
uploadedFile.put(Constants.IDENTIFIER, UUID.randomUUID().toString());
uploadedFile.put(Constants.FILE_NAME, uploadResponse.getResult().get(Constants.NAME));
uploadedFile.put(Constants.FILE_PATH, uploadResponse.getResult().get(Constants.URL));
uploadedFile.put(Constants.DATE_CREATED_ON, new Timestamp(System.currentTimeMillis()));
uploadedFile.put(Constants.STATUS, Constants.INITIATED_CAPITAL);
uploadedFile.put(Constants.COMMENT, StringUtils.EMPTY);
uploadedFile.put(Constants.CREATED_BY, userId);

SBApiResponse insertResponse = cassandraOperation.insertRecord(Constants.DATABASE,
Constants.TABLE_USER_BULK_UPLOAD, uploadedFile);

if (!Constants.SUCCESS.equalsIgnoreCase((String) insertResponse.get(Constants.RESPONSE))) {
setErrorData(response, "Failed to update database with user bulk upload file details.");
return response;
}

response.getParams().setStatus(Constants.SUCCESSFUL);
response.setResponseCode(HttpStatus.OK);
response.getResult().putAll(uploadedFile);
uploadedFile.put(Constants.ORG_NAME, channel);
uploadedFile.put(Constants.X_AUTH_TOKEN, userAuthToken);
kafkaProducer.pushWithKey(serverConfig.getUserBulkUploadTopic(), uploadedFile, orgId);
sendBulkUploadNotification(orgId, channel, (String) uploadResponse.getResult().get(Constants.URL));
} catch (Exception e) {
setErrorData(response,
String.format("Failed to process user bulk upload request. Error: ", e.getMessage()));
}
return response;
}

}


Expand Down
Loading

0 comments on commit 1fa2796

Please sign in to comment.