@Test public void testGetAssessmentDataMap2() throws JsonParseException, JsonMappingException, IOException { PowerMockito.mockStatic(QuestionPaperGeneratorUtil.class); PowerMockito.when(QuestionPaperGeneratorUtil.getMetadataFromNeo4j(Mockito.anyList())).thenReturn(null); PowerMockito.when(QuestionPaperGeneratorUtil.getExternalPropsData(Mockito.anyList())).thenReturn(null); String childDataString = "{\"do_11293645874324275213\":3,\"do_11293645447181107211\":1,\"do_11293645469885235212\":2}"; Map<String, Object> childData = mapper.readValue(childDataString, Map.class); Map<String, Object> assessmentMap = QuestionPaperGenerator.getAssessmentDataMap(childData); Assert.assertNull(assessmentMap); System.out.println(assessmentMap); }
public static Map<String, Object> getAssessmentDataMap(Map<String, Object> childData) throws JsonParseException, JsonMappingException, IOException { List<String> identifiers = new ArrayList<>(childData.keySet()); Map<String, Object> nodeMap = QuestionPaperGeneratorUtil.getMetadataFromNeo4j(identifiers); Map<String, Object> externalPropMap = QuestionPaperGeneratorUtil.getExternalPropsData(identifiers); if (MapUtils.isNotEmpty(nodeMap) && MapUtils.isNotEmpty(externalPropMap)) { Map<String, Object> assessmentMap = new HashMap<>(externalPropMap); for(String id : assessmentMap.keySet()) { String type = ((String)((Node)nodeMap.get(id)).getMetadata().get("type")); Map<String, Object> editorState = mapper.readValue((String)((Map<String, Object>) externalPropMap.get(id)).get("editorstate"), new TypeReference<Map<String, Object>>(){}); String answer = null; if(StringUtils.isNotBlank((String)((Node)nodeMap.get(id)).getMetadata().get("responseDeclaration"))) { Map<String, Object> answerMap = mapper.readValue((String)((Node)nodeMap.get(id)).getMetadata().get("responseDeclaration"), new TypeReference<Map<String, Object>>(){}); answer = (String) ((Map<String, Object>) ((Map<String, Object>) answerMap. getOrDefault("responseValue", new HashMap<String, Object>())). getOrDefault("correct_response", new HashMap<String, Object>())). getOrDefault("value", null); } if(StringUtils.equalsIgnoreCase(type, "mcq") && MapUtils.isNotEmpty(editorState)) { if(StringUtils.isNoneBlank(answer)) { ((Map<String, Object>)assessmentMap.get(id)).put(ANSWER, ((Map<String, Object>) ((Map<String, Object>) ((List<Map<String, Object>>)editorState.get("options")). get(Integer.parseInt(answer))). getOrDefault("value", new HashMap<String, Object>())). getOrDefault("body", "")); }else { ((Map<String, Object>)assessmentMap.get(id)).put(ANSWER, ""); } }else { ((Map<String, Object>)assessmentMap.get(id)).put(ANSWER, null != answer ? answer : ""); } ((Map<String, Object>)assessmentMap.get(id)).put(TYPE, type); ((Map<String, Object>)assessmentMap.get(id)).put(INDEX, childData.get(id)); } return assessmentMap; } TelemetryManager.error("Question Paper not generated because : typeMap and/or bodyMap is null."); return null; }
QuestionPaperGenerator { public static Map<String, Object> getAssessmentDataMap(Map<String, Object> childData) throws JsonParseException, JsonMappingException, IOException { List<String> identifiers = new ArrayList<>(childData.keySet()); Map<String, Object> nodeMap = QuestionPaperGeneratorUtil.getMetadataFromNeo4j(identifiers); Map<String, Object> externalPropMap = QuestionPaperGeneratorUtil.getExternalPropsData(identifiers); if (MapUtils.isNotEmpty(nodeMap) && MapUtils.isNotEmpty(externalPropMap)) { Map<String, Object> assessmentMap = new HashMap<>(externalPropMap); for(String id : assessmentMap.keySet()) { String type = ((String)((Node)nodeMap.get(id)).getMetadata().get("type")); Map<String, Object> editorState = mapper.readValue((String)((Map<String, Object>) externalPropMap.get(id)).get("editorstate"), new TypeReference<Map<String, Object>>(){}); String answer = null; if(StringUtils.isNotBlank((String)((Node)nodeMap.get(id)).getMetadata().get("responseDeclaration"))) { Map<String, Object> answerMap = mapper.readValue((String)((Node)nodeMap.get(id)).getMetadata().get("responseDeclaration"), new TypeReference<Map<String, Object>>(){}); answer = (String) ((Map<String, Object>) ((Map<String, Object>) answerMap. getOrDefault("responseValue", new HashMap<String, Object>())). getOrDefault("correct_response", new HashMap<String, Object>())). getOrDefault("value", null); } if(StringUtils.equalsIgnoreCase(type, "mcq") && MapUtils.isNotEmpty(editorState)) { if(StringUtils.isNoneBlank(answer)) { ((Map<String, Object>)assessmentMap.get(id)).put(ANSWER, ((Map<String, Object>) ((Map<String, Object>) ((List<Map<String, Object>>)editorState.get("options")). get(Integer.parseInt(answer))). getOrDefault("value", new HashMap<String, Object>())). getOrDefault("body", "")); }else { ((Map<String, Object>)assessmentMap.get(id)).put(ANSWER, ""); } }else { ((Map<String, Object>)assessmentMap.get(id)).put(ANSWER, null != answer ? answer : ""); } ((Map<String, Object>)assessmentMap.get(id)).put(TYPE, type); ((Map<String, Object>)assessmentMap.get(id)).put(INDEX, childData.get(id)); } return assessmentMap; } TelemetryManager.error("Question Paper not generated because : typeMap and/or bodyMap is null."); return null; } }
QuestionPaperGenerator { public static Map<String, Object> getAssessmentDataMap(Map<String, Object> childData) throws JsonParseException, JsonMappingException, IOException { List<String> identifiers = new ArrayList<>(childData.keySet()); Map<String, Object> nodeMap = QuestionPaperGeneratorUtil.getMetadataFromNeo4j(identifiers); Map<String, Object> externalPropMap = QuestionPaperGeneratorUtil.getExternalPropsData(identifiers); if (MapUtils.isNotEmpty(nodeMap) && MapUtils.isNotEmpty(externalPropMap)) { Map<String, Object> assessmentMap = new HashMap<>(externalPropMap); for(String id : assessmentMap.keySet()) { String type = ((String)((Node)nodeMap.get(id)).getMetadata().get("type")); Map<String, Object> editorState = mapper.readValue((String)((Map<String, Object>) externalPropMap.get(id)).get("editorstate"), new TypeReference<Map<String, Object>>(){}); String answer = null; if(StringUtils.isNotBlank((String)((Node)nodeMap.get(id)).getMetadata().get("responseDeclaration"))) { Map<String, Object> answerMap = mapper.readValue((String)((Node)nodeMap.get(id)).getMetadata().get("responseDeclaration"), new TypeReference<Map<String, Object>>(){}); answer = (String) ((Map<String, Object>) ((Map<String, Object>) answerMap. getOrDefault("responseValue", new HashMap<String, Object>())). getOrDefault("correct_response", new HashMap<String, Object>())). getOrDefault("value", null); } if(StringUtils.equalsIgnoreCase(type, "mcq") && MapUtils.isNotEmpty(editorState)) { if(StringUtils.isNoneBlank(answer)) { ((Map<String, Object>)assessmentMap.get(id)).put(ANSWER, ((Map<String, Object>) ((Map<String, Object>) ((List<Map<String, Object>>)editorState.get("options")). get(Integer.parseInt(answer))). getOrDefault("value", new HashMap<String, Object>())). getOrDefault("body", "")); }else { ((Map<String, Object>)assessmentMap.get(id)).put(ANSWER, ""); } }else { ((Map<String, Object>)assessmentMap.get(id)).put(ANSWER, null != answer ? answer : ""); } ((Map<String, Object>)assessmentMap.get(id)).put(TYPE, type); ((Map<String, Object>)assessmentMap.get(id)).put(INDEX, childData.get(id)); } return assessmentMap; } TelemetryManager.error("Question Paper not generated because : typeMap and/or bodyMap is null."); return null; }  }
QuestionPaperGenerator { public static Map<String, Object> getAssessmentDataMap(Map<String, Object> childData) throws JsonParseException, JsonMappingException, IOException { List<String> identifiers = new ArrayList<>(childData.keySet()); Map<String, Object> nodeMap = QuestionPaperGeneratorUtil.getMetadataFromNeo4j(identifiers); Map<String, Object> externalPropMap = QuestionPaperGeneratorUtil.getExternalPropsData(identifiers); if (MapUtils.isNotEmpty(nodeMap) && MapUtils.isNotEmpty(externalPropMap)) { Map<String, Object> assessmentMap = new HashMap<>(externalPropMap); for(String id : assessmentMap.keySet()) { String type = ((String)((Node)nodeMap.get(id)).getMetadata().get("type")); Map<String, Object> editorState = mapper.readValue((String)((Map<String, Object>) externalPropMap.get(id)).get("editorstate"), new TypeReference<Map<String, Object>>(){}); String answer = null; if(StringUtils.isNotBlank((String)((Node)nodeMap.get(id)).getMetadata().get("responseDeclaration"))) { Map<String, Object> answerMap = mapper.readValue((String)((Node)nodeMap.get(id)).getMetadata().get("responseDeclaration"), new TypeReference<Map<String, Object>>(){}); answer = (String) ((Map<String, Object>) ((Map<String, Object>) answerMap. getOrDefault("responseValue", new HashMap<String, Object>())). getOrDefault("correct_response", new HashMap<String, Object>())). getOrDefault("value", null); } if(StringUtils.equalsIgnoreCase(type, "mcq") && MapUtils.isNotEmpty(editorState)) { if(StringUtils.isNoneBlank(answer)) { ((Map<String, Object>)assessmentMap.get(id)).put(ANSWER, ((Map<String, Object>) ((Map<String, Object>) ((List<Map<String, Object>>)editorState.get("options")). get(Integer.parseInt(answer))). getOrDefault("value", new HashMap<String, Object>())). getOrDefault("body", "")); }else { ((Map<String, Object>)assessmentMap.get(id)).put(ANSWER, ""); } }else { ((Map<String, Object>)assessmentMap.get(id)).put(ANSWER, null != answer ? answer : ""); } ((Map<String, Object>)assessmentMap.get(id)).put(TYPE, type); ((Map<String, Object>)assessmentMap.get(id)).put(INDEX, childData.get(id)); } return assessmentMap; } TelemetryManager.error("Question Paper not generated because : typeMap and/or bodyMap is null."); return null; }  static File generateQuestionPaper(Node node); static Map<String, Object> fetchChildDetails(Node node); static Map<String, Object> getAssessmentDataMap(Map<String, Object> childData); static String getFileName(String prefix); }
QuestionPaperGenerator { public static Map<String, Object> getAssessmentDataMap(Map<String, Object> childData) throws JsonParseException, JsonMappingException, IOException { List<String> identifiers = new ArrayList<>(childData.keySet()); Map<String, Object> nodeMap = QuestionPaperGeneratorUtil.getMetadataFromNeo4j(identifiers); Map<String, Object> externalPropMap = QuestionPaperGeneratorUtil.getExternalPropsData(identifiers); if (MapUtils.isNotEmpty(nodeMap) && MapUtils.isNotEmpty(externalPropMap)) { Map<String, Object> assessmentMap = new HashMap<>(externalPropMap); for(String id : assessmentMap.keySet()) { String type = ((String)((Node)nodeMap.get(id)).getMetadata().get("type")); Map<String, Object> editorState = mapper.readValue((String)((Map<String, Object>) externalPropMap.get(id)).get("editorstate"), new TypeReference<Map<String, Object>>(){}); String answer = null; if(StringUtils.isNotBlank((String)((Node)nodeMap.get(id)).getMetadata().get("responseDeclaration"))) { Map<String, Object> answerMap = mapper.readValue((String)((Node)nodeMap.get(id)).getMetadata().get("responseDeclaration"), new TypeReference<Map<String, Object>>(){}); answer = (String) ((Map<String, Object>) ((Map<String, Object>) answerMap. getOrDefault("responseValue", new HashMap<String, Object>())). getOrDefault("correct_response", new HashMap<String, Object>())). getOrDefault("value", null); } if(StringUtils.equalsIgnoreCase(type, "mcq") && MapUtils.isNotEmpty(editorState)) { if(StringUtils.isNoneBlank(answer)) { ((Map<String, Object>)assessmentMap.get(id)).put(ANSWER, ((Map<String, Object>) ((Map<String, Object>) ((List<Map<String, Object>>)editorState.get("options")). get(Integer.parseInt(answer))). getOrDefault("value", new HashMap<String, Object>())). getOrDefault("body", "")); }else { ((Map<String, Object>)assessmentMap.get(id)).put(ANSWER, ""); } }else { ((Map<String, Object>)assessmentMap.get(id)).put(ANSWER, null != answer ? answer : ""); } ((Map<String, Object>)assessmentMap.get(id)).put(TYPE, type); ((Map<String, Object>)assessmentMap.get(id)).put(INDEX, childData.get(id)); } return assessmentMap; } TelemetryManager.error("Question Paper not generated because : typeMap and/or bodyMap is null."); return null; }  static File generateQuestionPaper(Node node); static Map<String, Object> fetchChildDetails(Node node); static Map<String, Object> getAssessmentDataMap(Map<String, Object> childData); static String getFileName(String prefix);  }