diff --git a/src/main/java/org/sunbird/assessment/service/AssessmentServiceImpl.java b/src/main/java/org/sunbird/assessment/service/AssessmentServiceImpl.java index dc462feaa..7bd34c107 100644 --- a/src/main/java/org/sunbird/assessment/service/AssessmentServiceImpl.java +++ b/src/main/java/org/sunbird/assessment/service/AssessmentServiceImpl.java @@ -108,11 +108,17 @@ public Map submitAssessment(String rootOrg, AssessmentSubmission if (Boolean.TRUE.equals(data.isAssessment()) && !"".equals(parentId)) { // get parent data for assessment try { - SunbirdApiResp contentHierarchy = contentService.getHeirarchyResponse(parentId); - if (contentHierarchy != null) { - persist.put("parentContentType", contentHierarchy.getResult().getContent().getContentType()); + Map contentResponse = contentService.searchLiveContent(parentId); + if (!ObjectUtils.isEmpty(contentResponse)) { + Map contentResult = (Map) contentResponse.get(Constants.RESULT); + if (0 < (Integer) contentResult.get(Constants.COUNT)) { + List> contentList = (List>) contentResult + .get(Constants.CONTENT); + Map content = contentList.get(0); + persist.put(Constants.PARENT_CONTENT_SEARCH, (String) content.get(Constants.CONTENT_TYPE_SEARCH)); + } } - } catch (Exception e) { + } catch (Exception e) { logger.error(e); } } else { diff --git a/src/main/java/org/sunbird/common/service/ContentServiceImpl.java b/src/main/java/org/sunbird/common/service/ContentServiceImpl.java index f0212c192..e0adbf0de 100644 --- a/src/main/java/org/sunbird/common/service/ContentServiceImpl.java +++ b/src/main/java/org/sunbird/common/service/ContentServiceImpl.java @@ -1,10 +1,6 @@ package org.sunbird.common.service; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.HashMap; -import java.util.List; -import java.util.Map; +import java.util.*; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; @@ -17,6 +13,8 @@ import com.fasterxml.jackson.databind.ObjectMapper; +import static java.util.Objects.nonNull; + @Service public class ContentServiceImpl implements ContentService { @@ -37,7 +35,7 @@ public SunbirdApiResp getHeirarchyResponse(String contentId) { .append("?hierarchyType=detail"); SunbirdApiResp response = mapper.convertValue(outboundRequestHandlerService.fetchResult(url.toString()), SunbirdApiResp.class); - if (response.getResponseCode().equalsIgnoreCase("Ok")) { + if (nonNull(response) && response.getResponseCode().equalsIgnoreCase("Ok")) { return response; } @@ -186,7 +184,7 @@ public Map searchLiveContent(String contentId) { Map contentRequestValue = new HashMap<>(); contentRequestValue.put(Constants.FILTERS, filters); contentRequestValue.put(Constants.FIELDS, - Arrays.asList(Constants.IDENTIFIER, Constants.NAME, Constants.PRIMARY_CATEGORY, Constants.BATCHES, Constants.LEAF_NODES_COUNT)); + Arrays.asList(Constants.IDENTIFIER, Constants.NAME, Constants.PRIMARY_CATEGORY, Constants.BATCHES, Constants.LEAF_NODES_COUNT, Constants.CONTENT_TYPE_SEARCH)); Map contentRequest = new HashMap<>(); contentRequest.put(Constants.REQUEST, contentRequestValue); response = outboundRequestHandlerService.fetchResultUsingPost( diff --git a/src/main/java/org/sunbird/common/util/Constants.java b/src/main/java/org/sunbird/common/util/Constants.java index 5edb34963..060a9ccbf 100644 --- a/src/main/java/org/sunbird/common/util/Constants.java +++ b/src/main/java/org/sunbird/common/util/Constants.java @@ -528,6 +528,7 @@ public class Constants { public static final String MIN = "min"; public static final String MAX = "max"; public static final String CONTENT_TYPE_SEARCH = "contentType"; + public static final String PARENT_CONTENT_SEARCH="parentContentType"; public static final String NEW_COURSES = "newcourses"; public static final String OVERVIEW_BATCH_KEY = "/overview?batchId="; public static final String LEAF_NODES_COUNT = "leafNodesCount"; diff --git a/src/main/java/org/sunbird/profile/service/ProfileServiceImpl.java b/src/main/java/org/sunbird/profile/service/ProfileServiceImpl.java index 51915d269..b1c3a5c8b 100644 --- a/src/main/java/org/sunbird/profile/service/ProfileServiceImpl.java +++ b/src/main/java/org/sunbird/profile/service/ProfileServiceImpl.java @@ -155,7 +155,8 @@ public SBApiResponse profileUpdate(Map request, String userToken response.getResult().put(Constants.RESPONSE, Constants.SUCCESS); response.getParams().setStatus(Constants.SUCCESS); } else { - if (Constants.CLIENT_ERROR.equalsIgnoreCase((String) updateResponse.get(Constants.RESPONSE_CODE))) { + if (updateResponse != null && Constants.CLIENT_ERROR + .equalsIgnoreCase((String) updateResponse.get(Constants.RESPONSE_CODE))) { response.setResponseCode(HttpStatus.BAD_REQUEST); } else { response.setResponseCode(HttpStatus.INTERNAL_SERVER_ERROR);