@Rule @Test(expected = ServerException.class) public void testPublish8() throws Exception{ List<String> itemsetsList = Arrays.asList("do_11292667205373132811"); ControllerUtil controllerUtil = PowerMockito.mock(ControllerUtil.class); ItemsetPublishManager itemsetPublishManager = new ItemsetPublishManager(controllerUtil); String itemSetNodeString = "{\"identifier\":\"do_11292667205373132811\",\"objectType\":\"ItemSet\",\"owner\":\"Ilimi\",\"lastStatusChangedOn\":\"2020-01-02T16:31:37.174+0530\",\"code\":\"akshara.grade5.ws1.test\",\"previewUrl\":\"https: Map<String, Object> itemSetNodeMap = mapper.readValue(itemSetNodeString, Map.class); DefinitionDTO itemSetDefinition = new ControllerUtil().getDefinition("domain", "ItemSet"); Node itemSetNode = ConvertToGraphNode.convertToGraphNode(itemSetNodeMap, itemSetDefinition, null); itemSetNode.getOutRelations().forEach(x -> x.setEndNodeObjectType("AssessmentItem")); PowerMockito.when(controllerUtil.getNode(Mockito.anyString(), Mockito.anyString())).thenReturn(itemSetNode); String itemNodeString1 = "{\"identifier\":\"test.mcq_test_mcq_101\",\"objectType\":\"AssessmentItem\",\"type\":\"mcq\",\"name\":\"Mmcq Question 2\",\"status\":\"Draft\"}"; String itemNodeString2 = "{\"identifier\":\"test.mcq_test_mcq_102\",\"objectType\":\"AssessmentItem\",\"type\":\"mcq\",\"name\":\"Mmcq Question 2\",\"status\":\"Retired\"}"; Map<String, Object> itemNodeMap1 = mapper.readValue(itemNodeString1, Map.class); Map<String, Object> itemNodeMap2 = mapper.readValue(itemNodeString2, Map.class); DefinitionDTO itemDefinition = new ControllerUtil().getDefinition("domain", "AssessmentItem"); Node itemNode1 = ConvertToGraphNode.convertToGraphNode(itemNodeMap1, itemDefinition, null); Node itemNode2 = ConvertToGraphNode.convertToGraphNode(itemNodeMap2, itemDefinition, null); Response getDataNodesResponse = new Response(); getDataNodesResponse.getResult().put("node_list", Arrays.asList(itemNode1, itemNode2)); PowerMockito.when(controllerUtil.getDataNodes(Mockito.anyString(), Mockito.anyList())).thenReturn(getDataNodesResponse); Response updateNodesResponse = new Response(); PowerMockito.when(controllerUtil.updateNodes(Mockito.anyList(), Mockito.anyMap())).thenReturn(updateNodesResponse); PowerMockito.mockStatic(QuestionPaperGenerator.class); PowerMockito.when(QuestionPaperGenerator.generateQuestionPaper(Mockito.any())).thenReturn(new File("/tmp/previewUrl.html")); PowerMockito.mockStatic(ItemsetPublishManagerUtil.class); PowerMockito.when(ItemsetPublishManagerUtil.uploadFileToCloud(Mockito.any(), Mockito.anyString())).thenReturn("previewUrl.html"); Response updateNodeResponse = new Response(); updateNodeResponse.setResponseCode(ResponseCode.SERVER_ERROR); PowerMockito.when(controllerUtil.updateNode(Mockito.any())).thenReturn(updateNodeResponse); String url = itemsetPublishManager.publish(itemsetsList); }
public String publish(List<String> itemSetIdetifiers) throws Exception { if (CollectionUtils.isNotEmpty(itemSetIdetifiers)) { Node itemSet = controllerUtil.getNode(TAXONOMY_ID, itemSetIdetifiers.get(0)); List<Relation> outRelations = itemSet.getOutRelations(); if(CollectionUtils.isEmpty(outRelations)) return null; List<String> assessmentItemIds = outRelations.stream().filter(r -> StringUtils.equalsIgnoreCase(r.getEndNodeObjectType(), "AssessmentItem")).map(x -> x.getEndNodeId()).collect(Collectors.toList()); Response response = null; if(CollectionUtils.isNotEmpty(assessmentItemIds)) { response = controllerUtil.getDataNodes(TAXONOMY_ID, assessmentItemIds); if(response.getResponseCode() != ResponseCode.OK) { TelemetryManager.error("Fetching Itemset linked question failed for :: " + itemSet.getIdentifier()); throw new ServerException(AssessmentErrorCodes.ERR_ASSESSMENT_BULK_READ.name(), "AssessmentItem linked to ItemSet: " + itemSet + " couldn't be fetched."); } List<Node> assessmentItems = (List<Node>)response.getResult().get("node_list"); List<Node> assessmentItemAcceptedPublish = assessmentItems.stream().filter(q -> assessmentItemAcceptedStatus.contains(q.getMetadata().get("status"))).collect(Collectors.toList()); List<String> assessmentItemNotAcceptedPublish = assessmentItems.stream().filter(q -> !assessmentItemAcceptedStatus.contains(q.getMetadata().get("status"))).map(x -> x.getIdentifier()).collect(Collectors.toList()); if(CollectionUtils.isNotEmpty(assessmentItemAcceptedPublish)) { Map<String, Object> metadata = new HashMap<>();metadata.put("status", "Live"); response = controllerUtil.updateNodes(assessmentItemAcceptedPublish, metadata); if(response.getResponseCode() != ResponseCode.OK) { TelemetryManager.error("AssessmentItem update failed for ItemSet: " + itemSet.getIdentifier()); throw new ServerException(AssessmentErrorCodes.ERR_ASSESSMENT_BULK_UPDATE.name(), "AssessmentItem linked to ItemSet: " + itemSet + " couldn't be updated."); } } if(CollectionUtils.isNotEmpty(assessmentItemNotAcceptedPublish)) { List<Relation> outRelationForPublish = itemSet.getOutRelations().stream().filter(x -> !assessmentItemNotAcceptedPublish.contains(x.getEndNodeId())).collect(Collectors.toList()); itemSet.setOutRelations(outRelationForPublish); } File previewFile = QuestionPaperGenerator.generateQuestionPaper(itemSet); if(null == previewFile) { TelemetryManager.error("Itemset questionPeper generated null file :: " + itemSetIdetifiers.get(0)); throw new ServerException(AssessmentErrorCodes.ERR_QUESTIONPAPER_FILE_GENERATE.name(), "Question paper for identifier: " + itemSet + "couldn't be generated."); } if (null != previewFile) { String previewUrl = ItemsetPublishManagerUtil.uploadFileToCloud(previewFile, itemSet.getIdentifier()); if(null == previewUrl) { TelemetryManager.error("QuestionPeper - upload file - failed for Itemset :: " + itemSetIdetifiers.get(0)); throw new ServerException(AssessmentErrorCodes.ERR_QUESTIONPAPER_UPLOAD_FAILED.name(), "QuestionPaper upload failed for identifier: " + itemSet + "."); } itemSet.getMetadata().put("previewUrl", previewUrl); itemSet.getMetadata().put("status", "Live"); response = controllerUtil.updateNode(itemSet); if(previewFile.exists()) previewFile.delete(); if (response.getResponseCode() != ResponseCode.OK) { TelemetryManager.error("Itemset publish operation failed for :: " + itemSet.getIdentifier() + " ::::: " + response.getParams() + " ::::: " + response.getResponseCode() + " ::::::: " + response.getResult()); throw new ServerException(AssessmentErrorCodes.ERR_ASSESSMENT_UPDATE.name(), "AssessmentItem with identifier: " + itemSet + "couldn't be updated"); } return previewUrl; } } } TelemetryManager.error("Itemset List is empty :: " + itemSetIdetifiers); return null; }
ItemsetPublishManager { public String publish(List<String> itemSetIdetifiers) throws Exception { if (CollectionUtils.isNotEmpty(itemSetIdetifiers)) { Node itemSet = controllerUtil.getNode(TAXONOMY_ID, itemSetIdetifiers.get(0)); List<Relation> outRelations = itemSet.getOutRelations(); if(CollectionUtils.isEmpty(outRelations)) return null; List<String> assessmentItemIds = outRelations.stream().filter(r -> StringUtils.equalsIgnoreCase(r.getEndNodeObjectType(), "AssessmentItem")).map(x -> x.getEndNodeId()).collect(Collectors.toList()); Response response = null; if(CollectionUtils.isNotEmpty(assessmentItemIds)) { response = controllerUtil.getDataNodes(TAXONOMY_ID, assessmentItemIds); if(response.getResponseCode() != ResponseCode.OK) { TelemetryManager.error("Fetching Itemset linked question failed for :: " + itemSet.getIdentifier()); throw new ServerException(AssessmentErrorCodes.ERR_ASSESSMENT_BULK_READ.name(), "AssessmentItem linked to ItemSet: " + itemSet + " couldn't be fetched."); } List<Node> assessmentItems = (List<Node>)response.getResult().get("node_list"); List<Node> assessmentItemAcceptedPublish = assessmentItems.stream().filter(q -> assessmentItemAcceptedStatus.contains(q.getMetadata().get("status"))).collect(Collectors.toList()); List<String> assessmentItemNotAcceptedPublish = assessmentItems.stream().filter(q -> !assessmentItemAcceptedStatus.contains(q.getMetadata().get("status"))).map(x -> x.getIdentifier()).collect(Collectors.toList()); if(CollectionUtils.isNotEmpty(assessmentItemAcceptedPublish)) { Map<String, Object> metadata = new HashMap<>();metadata.put("status", "Live"); response = controllerUtil.updateNodes(assessmentItemAcceptedPublish, metadata); if(response.getResponseCode() != ResponseCode.OK) { TelemetryManager.error("AssessmentItem update failed for ItemSet: " + itemSet.getIdentifier()); throw new ServerException(AssessmentErrorCodes.ERR_ASSESSMENT_BULK_UPDATE.name(), "AssessmentItem linked to ItemSet: " + itemSet + " couldn't be updated."); } } if(CollectionUtils.isNotEmpty(assessmentItemNotAcceptedPublish)) { List<Relation> outRelationForPublish = itemSet.getOutRelations().stream().filter(x -> !assessmentItemNotAcceptedPublish.contains(x.getEndNodeId())).collect(Collectors.toList()); itemSet.setOutRelations(outRelationForPublish); } File previewFile = QuestionPaperGenerator.generateQuestionPaper(itemSet); if(null == previewFile) { TelemetryManager.error("Itemset questionPeper generated null file :: " + itemSetIdetifiers.get(0)); throw new ServerException(AssessmentErrorCodes.ERR_QUESTIONPAPER_FILE_GENERATE.name(), "Question paper for identifier: " + itemSet + "couldn't be generated."); } if (null != previewFile) { String previewUrl = ItemsetPublishManagerUtil.uploadFileToCloud(previewFile, itemSet.getIdentifier()); if(null == previewUrl) { TelemetryManager.error("QuestionPeper - upload file - failed for Itemset :: " + itemSetIdetifiers.get(0)); throw new ServerException(AssessmentErrorCodes.ERR_QUESTIONPAPER_UPLOAD_FAILED.name(), "QuestionPaper upload failed for identifier: " + itemSet + "."); } itemSet.getMetadata().put("previewUrl", previewUrl); itemSet.getMetadata().put("status", "Live"); response = controllerUtil.updateNode(itemSet); if(previewFile.exists()) previewFile.delete(); if (response.getResponseCode() != ResponseCode.OK) { TelemetryManager.error("Itemset publish operation failed for :: " + itemSet.getIdentifier() + " ::::: " + response.getParams() + " ::::: " + response.getResponseCode() + " ::::::: " + response.getResult()); throw new ServerException(AssessmentErrorCodes.ERR_ASSESSMENT_UPDATE.name(), "AssessmentItem with identifier: " + itemSet + "couldn't be updated"); } return previewUrl; } } } TelemetryManager.error("Itemset List is empty :: " + itemSetIdetifiers); return null; } }
ItemsetPublishManager { public String publish(List<String> itemSetIdetifiers) throws Exception { if (CollectionUtils.isNotEmpty(itemSetIdetifiers)) { Node itemSet = controllerUtil.getNode(TAXONOMY_ID, itemSetIdetifiers.get(0)); List<Relation> outRelations = itemSet.getOutRelations(); if(CollectionUtils.isEmpty(outRelations)) return null; List<String> assessmentItemIds = outRelations.stream().filter(r -> StringUtils.equalsIgnoreCase(r.getEndNodeObjectType(), "AssessmentItem")).map(x -> x.getEndNodeId()).collect(Collectors.toList()); Response response = null; if(CollectionUtils.isNotEmpty(assessmentItemIds)) { response = controllerUtil.getDataNodes(TAXONOMY_ID, assessmentItemIds); if(response.getResponseCode() != ResponseCode.OK) { TelemetryManager.error("Fetching Itemset linked question failed for :: " + itemSet.getIdentifier()); throw new ServerException(AssessmentErrorCodes.ERR_ASSESSMENT_BULK_READ.name(), "AssessmentItem linked to ItemSet: " + itemSet + " couldn't be fetched."); } List<Node> assessmentItems = (List<Node>)response.getResult().get("node_list"); List<Node> assessmentItemAcceptedPublish = assessmentItems.stream().filter(q -> assessmentItemAcceptedStatus.contains(q.getMetadata().get("status"))).collect(Collectors.toList()); List<String> assessmentItemNotAcceptedPublish = assessmentItems.stream().filter(q -> !assessmentItemAcceptedStatus.contains(q.getMetadata().get("status"))).map(x -> x.getIdentifier()).collect(Collectors.toList()); if(CollectionUtils.isNotEmpty(assessmentItemAcceptedPublish)) { Map<String, Object> metadata = new HashMap<>();metadata.put("status", "Live"); response = controllerUtil.updateNodes(assessmentItemAcceptedPublish, metadata); if(response.getResponseCode() != ResponseCode.OK) { TelemetryManager.error("AssessmentItem update failed for ItemSet: " + itemSet.getIdentifier()); throw new ServerException(AssessmentErrorCodes.ERR_ASSESSMENT_BULK_UPDATE.name(), "AssessmentItem linked to ItemSet: " + itemSet + " couldn't be updated."); } } if(CollectionUtils.isNotEmpty(assessmentItemNotAcceptedPublish)) { List<Relation> outRelationForPublish = itemSet.getOutRelations().stream().filter(x -> !assessmentItemNotAcceptedPublish.contains(x.getEndNodeId())).collect(Collectors.toList()); itemSet.setOutRelations(outRelationForPublish); } File previewFile = QuestionPaperGenerator.generateQuestionPaper(itemSet); if(null == previewFile) { TelemetryManager.error("Itemset questionPeper generated null file :: " + itemSetIdetifiers.get(0)); throw new ServerException(AssessmentErrorCodes.ERR_QUESTIONPAPER_FILE_GENERATE.name(), "Question paper for identifier: " + itemSet + "couldn't be generated."); } if (null != previewFile) { String previewUrl = ItemsetPublishManagerUtil.uploadFileToCloud(previewFile, itemSet.getIdentifier()); if(null == previewUrl) { TelemetryManager.error("QuestionPeper - upload file - failed for Itemset :: " + itemSetIdetifiers.get(0)); throw new ServerException(AssessmentErrorCodes.ERR_QUESTIONPAPER_UPLOAD_FAILED.name(), "QuestionPaper upload failed for identifier: " + itemSet + "."); } itemSet.getMetadata().put("previewUrl", previewUrl); itemSet.getMetadata().put("status", "Live"); response = controllerUtil.updateNode(itemSet); if(previewFile.exists()) previewFile.delete(); if (response.getResponseCode() != ResponseCode.OK) { TelemetryManager.error("Itemset publish operation failed for :: " + itemSet.getIdentifier() + " ::::: " + response.getParams() + " ::::: " + response.getResponseCode() + " ::::::: " + response.getResult()); throw new ServerException(AssessmentErrorCodes.ERR_ASSESSMENT_UPDATE.name(), "AssessmentItem with identifier: " + itemSet + "couldn't be updated"); } return previewUrl; } } } TelemetryManager.error("Itemset List is empty :: " + itemSetIdetifiers); return null; } ItemsetPublishManager(ControllerUtil controllerUtil); }
ItemsetPublishManager { public String publish(List<String> itemSetIdetifiers) throws Exception { if (CollectionUtils.isNotEmpty(itemSetIdetifiers)) { Node itemSet = controllerUtil.getNode(TAXONOMY_ID, itemSetIdetifiers.get(0)); List<Relation> outRelations = itemSet.getOutRelations(); if(CollectionUtils.isEmpty(outRelations)) return null; List<String> assessmentItemIds = outRelations.stream().filter(r -> StringUtils.equalsIgnoreCase(r.getEndNodeObjectType(), "AssessmentItem")).map(x -> x.getEndNodeId()).collect(Collectors.toList()); Response response = null; if(CollectionUtils.isNotEmpty(assessmentItemIds)) { response = controllerUtil.getDataNodes(TAXONOMY_ID, assessmentItemIds); if(response.getResponseCode() != ResponseCode.OK) { TelemetryManager.error("Fetching Itemset linked question failed for :: " + itemSet.getIdentifier()); throw new ServerException(AssessmentErrorCodes.ERR_ASSESSMENT_BULK_READ.name(), "AssessmentItem linked to ItemSet: " + itemSet + " couldn't be fetched."); } List<Node> assessmentItems = (List<Node>)response.getResult().get("node_list"); List<Node> assessmentItemAcceptedPublish = assessmentItems.stream().filter(q -> assessmentItemAcceptedStatus.contains(q.getMetadata().get("status"))).collect(Collectors.toList()); List<String> assessmentItemNotAcceptedPublish = assessmentItems.stream().filter(q -> !assessmentItemAcceptedStatus.contains(q.getMetadata().get("status"))).map(x -> x.getIdentifier()).collect(Collectors.toList()); if(CollectionUtils.isNotEmpty(assessmentItemAcceptedPublish)) { Map<String, Object> metadata = new HashMap<>();metadata.put("status", "Live"); response = controllerUtil.updateNodes(assessmentItemAcceptedPublish, metadata); if(response.getResponseCode() != ResponseCode.OK) { TelemetryManager.error("AssessmentItem update failed for ItemSet: " + itemSet.getIdentifier()); throw new ServerException(AssessmentErrorCodes.ERR_ASSESSMENT_BULK_UPDATE.name(), "AssessmentItem linked to ItemSet: " + itemSet + " couldn't be updated."); } } if(CollectionUtils.isNotEmpty(assessmentItemNotAcceptedPublish)) { List<Relation> outRelationForPublish = itemSet.getOutRelations().stream().filter(x -> !assessmentItemNotAcceptedPublish.contains(x.getEndNodeId())).collect(Collectors.toList()); itemSet.setOutRelations(outRelationForPublish); } File previewFile = QuestionPaperGenerator.generateQuestionPaper(itemSet); if(null == previewFile) { TelemetryManager.error("Itemset questionPeper generated null file :: " + itemSetIdetifiers.get(0)); throw new ServerException(AssessmentErrorCodes.ERR_QUESTIONPAPER_FILE_GENERATE.name(), "Question paper for identifier: " + itemSet + "couldn't be generated."); } if (null != previewFile) { String previewUrl = ItemsetPublishManagerUtil.uploadFileToCloud(previewFile, itemSet.getIdentifier()); if(null == previewUrl) { TelemetryManager.error("QuestionPeper - upload file - failed for Itemset :: " + itemSetIdetifiers.get(0)); throw new ServerException(AssessmentErrorCodes.ERR_QUESTIONPAPER_UPLOAD_FAILED.name(), "QuestionPaper upload failed for identifier: " + itemSet + "."); } itemSet.getMetadata().put("previewUrl", previewUrl); itemSet.getMetadata().put("status", "Live"); response = controllerUtil.updateNode(itemSet); if(previewFile.exists()) previewFile.delete(); if (response.getResponseCode() != ResponseCode.OK) { TelemetryManager.error("Itemset publish operation failed for :: " + itemSet.getIdentifier() + " ::::: " + response.getParams() + " ::::: " + response.getResponseCode() + " ::::::: " + response.getResult()); throw new ServerException(AssessmentErrorCodes.ERR_ASSESSMENT_UPDATE.name(), "AssessmentItem with identifier: " + itemSet + "couldn't be updated"); } return previewUrl; } } } TelemetryManager.error("Itemset List is empty :: " + itemSetIdetifiers); return null; } ItemsetPublishManager(ControllerUtil controllerUtil); String publish(List<String> itemSetIdetifiers); }
ItemsetPublishManager { public String publish(List<String> itemSetIdetifiers) throws Exception { if (CollectionUtils.isNotEmpty(itemSetIdetifiers)) { Node itemSet = controllerUtil.getNode(TAXONOMY_ID, itemSetIdetifiers.get(0)); List<Relation> outRelations = itemSet.getOutRelations(); if(CollectionUtils.isEmpty(outRelations)) return null; List<String> assessmentItemIds = outRelations.stream().filter(r -> StringUtils.equalsIgnoreCase(r.getEndNodeObjectType(), "AssessmentItem")).map(x -> x.getEndNodeId()).collect(Collectors.toList()); Response response = null; if(CollectionUtils.isNotEmpty(assessmentItemIds)) { response = controllerUtil.getDataNodes(TAXONOMY_ID, assessmentItemIds); if(response.getResponseCode() != ResponseCode.OK) { TelemetryManager.error("Fetching Itemset linked question failed for :: " + itemSet.getIdentifier()); throw new ServerException(AssessmentErrorCodes.ERR_ASSESSMENT_BULK_READ.name(), "AssessmentItem linked to ItemSet: " + itemSet + " couldn't be fetched."); } List<Node> assessmentItems = (List<Node>)response.getResult().get("node_list"); List<Node> assessmentItemAcceptedPublish = assessmentItems.stream().filter(q -> assessmentItemAcceptedStatus.contains(q.getMetadata().get("status"))).collect(Collectors.toList()); List<String> assessmentItemNotAcceptedPublish = assessmentItems.stream().filter(q -> !assessmentItemAcceptedStatus.contains(q.getMetadata().get("status"))).map(x -> x.getIdentifier()).collect(Collectors.toList()); if(CollectionUtils.isNotEmpty(assessmentItemAcceptedPublish)) { Map<String, Object> metadata = new HashMap<>();metadata.put("status", "Live"); response = controllerUtil.updateNodes(assessmentItemAcceptedPublish, metadata); if(response.getResponseCode() != ResponseCode.OK) { TelemetryManager.error("AssessmentItem update failed for ItemSet: " + itemSet.getIdentifier()); throw new ServerException(AssessmentErrorCodes.ERR_ASSESSMENT_BULK_UPDATE.name(), "AssessmentItem linked to ItemSet: " + itemSet + " couldn't be updated."); } } if(CollectionUtils.isNotEmpty(assessmentItemNotAcceptedPublish)) { List<Relation> outRelationForPublish = itemSet.getOutRelations().stream().filter(x -> !assessmentItemNotAcceptedPublish.contains(x.getEndNodeId())).collect(Collectors.toList()); itemSet.setOutRelations(outRelationForPublish); } File previewFile = QuestionPaperGenerator.generateQuestionPaper(itemSet); if(null == previewFile) { TelemetryManager.error("Itemset questionPeper generated null file :: " + itemSetIdetifiers.get(0)); throw new ServerException(AssessmentErrorCodes.ERR_QUESTIONPAPER_FILE_GENERATE.name(), "Question paper for identifier: " + itemSet + "couldn't be generated."); } if (null != previewFile) { String previewUrl = ItemsetPublishManagerUtil.uploadFileToCloud(previewFile, itemSet.getIdentifier()); if(null == previewUrl) { TelemetryManager.error("QuestionPeper - upload file - failed for Itemset :: " + itemSetIdetifiers.get(0)); throw new ServerException(AssessmentErrorCodes.ERR_QUESTIONPAPER_UPLOAD_FAILED.name(), "QuestionPaper upload failed for identifier: " + itemSet + "."); } itemSet.getMetadata().put("previewUrl", previewUrl); itemSet.getMetadata().put("status", "Live"); response = controllerUtil.updateNode(itemSet); if(previewFile.exists()) previewFile.delete(); if (response.getResponseCode() != ResponseCode.OK) { TelemetryManager.error("Itemset publish operation failed for :: " + itemSet.getIdentifier() + " ::::: " + response.getParams() + " ::::: " + response.getResponseCode() + " ::::::: " + response.getResult()); throw new ServerException(AssessmentErrorCodes.ERR_ASSESSMENT_UPDATE.name(), "AssessmentItem with identifier: " + itemSet + "couldn't be updated"); } return previewUrl; } } } TelemetryManager.error("Itemset List is empty :: " + itemSetIdetifiers); return null; } ItemsetPublishManager(ControllerUtil controllerUtil); String publish(List<String> itemSetIdetifiers);  }