compare the logic of method getResponse2 with getResponse. both use different approaches…
- User
compare the logic of method getResponse2 with getResponse. both use different approaches but I want to know the processing logic is same. 'public String getResponse2(Map<String, Object> storyMap, Map<String, Object> featureMap, String testsDefects, String genAIResponse) { // Process testsDefects using JSONObject JSONObject testsDefectsJson = new JSONObject(testsDefects);
Set<String> storiesWithoutGroomingIds = new HashSet<>(); Set<String> storiesWithoutDevelopment = new HashSet<>(); Set<String> storiesWithoutPlanning = new HashSet<>(); // Extract collections directly from the maps List<String> storiesWithoutGroomingIdsList = (List<String>) storyMap.get("storiesWithoutGroomingIds"); List<String> storiesWithoutPlanningList = (List<String>) storyMap.get("storiesWithoutPlanning"); List<String> storiesWithoutDevelopmentList = (List<String>) storyMap.get("storiesWithoutDevelopment"); List<String> storiesWithoutTestsList = getJSONArrayAsList(testsDefectsJson.getJSONArray("storiesWithoutTestsList")); List<String> storiesWithOpenDefectList = getJSONArrayAsList(testsDefectsJson.getJSONArray("storiesWithOpenDefectList")); List<String> storiesWithoutTestsCompleted = getJSONArrayAsList(testsDefectsJson.getJSONArray("storiesWithoutTestsCompleted")); // Merge sets storiesWithoutGroomingIds.addAll(storiesWithoutGroomingIdsList); storiesWithoutGroomingIds.addAll(storiesWithoutTestsList); storiesWithoutPlanning.addAll(storiesWithoutPlanningList); storiesWithoutPlanning.removeAll(storiesWithoutGroomingIds); storiesWithoutDevelopment.addAll(storiesWithoutDevelopmentList); storiesWithoutDevelopment.addAll(storiesWithOpenDefectList); storiesWithoutDevelopment.addAll(storiesWithoutTestsCompleted); // Remove duplicate items storiesWithoutDevelopment.removeAll(storiesWithoutGroomingIds); storiesWithoutDevelopment.removeAll(storiesWithoutPlanning); // Calculate counts int totalCountStoriesWithoutGrooming = storiesWithoutGroomingIds.size(); int totalStoriesWithoutPlanning = storiesWithoutPlanning.size(); int totalStoriesWithoutDevelopment = storiesWithoutDevelopment.size(); int totalCountOfFeaturesWithoutGrooming = (int) featureMap.get("totalCountOfFeaturesWithoutGrooming"); int totalCountOfFeaturesWithoutPlanning = (int) featureMap.get("totalCountOfFeaturesWithoutPlanning"); int totalCountOfFeaturesWithoutDevelopmentDone = (int) featureMap.get("totalCountOfFeaturesWithoutDevelopmentDone"); int totalFeaturesCount = (int) featureMap.get("total"); int totalStoriesCount = (int) storyMap.get("total"); int totalStoriesWithGroomingCompleted = totalStoriesCount - totalCountStoriesWithoutGrooming; int totalFeaturesWithGroomingCompleted = totalFeaturesCount - totalCountOfFeaturesWithoutGrooming; int totalStoriesWithPlanningCompleted = totalStoriesCount - totalStoriesWithoutPlanning - totalCountStoriesWithoutGrooming; int totalFeaturesWithPlanningCompleted = totalFeaturesCount - totalCountOfFeaturesWithoutPlanning - totalCountOfFeaturesWithoutGrooming; int totalStoriesWithDevelopmentDone = totalStoriesCount - totalStoriesWithoutDevelopment - totalStoriesWithoutPlanning - totalCountStoriesWithoutGrooming; int totalCountOfFeaturesWithDevelopmentDone = totalFeaturesCount - totalCountOfFeaturesWithoutDevelopmentDone - totalCountOfFeaturesWithoutPlanning - totalCountOfFeaturesWithoutGrooming; // Calculate percentages double groomingCompletionPercentage = ((double) (totalFeaturesWithGroomingCompleted + totalStoriesWithGroomingCompleted) / (totalFeaturesCount + totalStoriesCount)) * 100; double planningCompletionPercentage = ((double) (totalFeaturesWithPlanningCompleted + totalStoriesWithPlanningCompleted) / (totalFeaturesCount + totalStoriesCount)) * 100; double developmentCompletionPercentage = ((double) (totalCountOfFeaturesWithDevelopmentDone + totalStoriesWithDevelopmentDone) / (totalFeaturesCount + totalStoriesCount)) * 100; // To add story and features sub data in scope Map<String, Object> scopeFeatures = new HashMap<>(); scopeFeatures.put("featureWithoutAcceptanceCriteriaList", featureMap.get("AcceptanceCriteriaNotDefined")); scopeFeatures.put("featureWithoutDescriptionList", featureMap.get("DescriptionNotDefined")); scopeFeatures.put("featureWithoutTitleList", featureMap.get("featureWithoutTitleList")); scopeFeatures.put("featureWithoutStoriesList", featureMap.get("featureListWithoutStories")); Map<String, Object> scopeStories = new HashMap<>(); scopeStories.put("storyWithoutTitleList", storyMap.get("storiesWithoutTitleIds")); scopeStories.put("storyWithoutAcceptanceCriteriaList", storyMap.get("AcceptanceCriteriaNotDefined")); scopeStories.put("storyWithoutDescriptionList", storyMap.get("DescriptionNotDefined")); // To add story and features sub data in planning Map<String, Object> planningFeatures = new HashMap<>(); planningFeatures.put("delayedFeaturesList", featureMap.get("delayedFeaturesList")); planningFeatures.put("featureWithoutTeamList", featureMap.get("TeamNotDefined")); planningFeatures.put("featureWithoutOwnerList", featureMap.get("OwnerNotDefined")); planningFeatures.put("featurePIEndDateAfterODRTargetDateList", featureMap.get("featurePIEndDateAfterODRTargetDate")); planningFeatures.put("featureWithoutPIEndDateList", featureMap.get("featureWithoutPIEndDateList")); planningFeatures.put("featureWithoutPINameList", featureMap.get("PINameNotDefined")); Map<String, Object> planningStories = new HashMap<>(); planningStories.put("storyWithoutEstimationList", storyMap.get("EstimationNotDone")); planningStories.put("storyWithoutTeamList", storyMap.get("TeamNotDefined")); planningStories.put("storyWithoutOwnerList", storyMap.get("OwnerNotDefined")); planningStories.put("storyWithoutIterationList", storyMap.get("IterationNameNotDefined")); planningStories.put("storyWithoutTasksList", storyMap.get("TasksBreakdownNotDefined")); planningStories.put("storiesWhichHasTasksWithoutEstimationList", storyMap.get("storiesWhichHasTasksWithoutEstimation")); planningStories.put("storiesIterationEndDateAfterODRTargetDateList", storyMap.get("storiesIterationEndDateAfterODRTargetDate")); planningStories.put("storiesPastIterationEndDateList", storyMap.get("storiesPastIterationEndDate")); // To add story and features sub data in development Map<String, Object> developmentFeatures = new HashMap<>(); developmentFeatures.put("featureWithoutDoneStatusList", featureMap.get("featureWithoutDoneStatusList")); Map<String, Object> developmentStories = new HashMap<>(); developmentStories.put("storiesWithoutTasksDoneList", storyMap.get("storiesWithoutTasksDone")); developmentStories.put("storiesNotDoneList", storyMap.get("storiesNotDoneList")); // Build the response using Java Collections Map<String, Object> response = new HashMap<>(); Map<String, Object> scope = new HashMap<>(); scope.put("totalFeaturesWithGroomingCompleted", totalFeaturesWithGroomingCompleted); scope.put("totalStoriesWithGroomingCompleted", totalStoriesWithGroomingCompleted); scope.put("storiesWithoutGroomingIds", new ArrayList<>(storiesWithoutGroomingIds)); scope.put("featuresWithoutGroomingList", featureMap.get("featuresWithoutGroomingList")); scope.put("percentage", groomingCompletionPercentage); scope.put("stories",scopeStories); scope.put("features",scopeFeatures); Map<String, Object> planning = new HashMap<>(); planning.put("totalStoriesWithPlanningCompleted", totalStoriesWithPlanningCompleted); planning.put("totalFeaturesWithPlanningCompleted", totalFeaturesWithPlanningCompleted); planning.put("storiesWithoutPlanning", new ArrayList<>(storiesWithoutPlanning)); planning.put("featuresWithoutPlanning", featureMap.get("featuresWithoutPlanning")); planning.put("percentage", planningCompletionPercentage); planning.put("features", planningFeatures); planning.put("stories", planningStories); Map<String, Object> development = new HashMap<>(); development.put("totalStoriesWithDevelopmentDone", totalStoriesWithDevelopmentDone); development.put("totalCountOfFeaturesWithDevelopmentDone", totalCountOfFeaturesWithDevelopmentDone); development.put("storiesWithoutDevelopment", new ArrayList<>(storiesWithoutDevelopment)); development.put("featuresWithoutDevelopmentDone", featureMap.get("featuresWithoutDevelopmentDone")); development.put("percentage", developmentCompletionPercentage); development.put("features", developmentFeatures); development.put("stories", developmentStories); response.put("scope", scope); response.put("planning", planning); response.put("development", development); response.put("totalFeaturesCount", totalFeaturesCount); response.put("totalStoriesCount", totalStoriesCount); if (genAIResponse != null && !genAIResponse.isBlank()) { response.put("AIRecommendations", genAIResponse); } return new JSONObject(response).toString(); }', 'private String getResponse(Map<String, Object> storyMap, Map<String, Object> featureMap, String testsDefects, String genAIResponse) throws JsonProcessingException { ObjectMapper mapper = new ObjectMapper(); String stories = mapper.writeValueAsString(storyMap); String features = mapper.writeValueAsString(featureMap); // Parse JSON strings into JSON objects JSONObject storiesJson = new JSONObject(stories); JSONObject featuresJson = new JSONObject(features); JSONObject testsDefectsJson = new JSONObject(testsDefects); // Initialize variables to store merged data Set<String> storiesWithoutGroomingIds = new HashSet<>(); Set<String> storiesWithoutDevelopment = new HashSet<>(); Set<String> storiesWithoutPlanning = new HashSet<>(); // Merge storiesWithoutGroomingIds with storiesWithoutTestsList without duplicates JSONArray storiesWithoutGroomingIdsArray = storiesJson.getJSONArray("storiesWithoutGroomingIds"); JSONArray storiesWithoutTestsList = testsDefectsJson.getJSONArray("storiesWithoutTestsList"); JSONArray storiesWithoutPlanningList =storiesJson.getJSONArray("storiesWithoutPlanning"); for (int i = 0; i < storiesWithoutGroomingIdsArray.length(); i++) { storiesWithoutGroomingIds.add(storiesWithoutGroomingIdsArray.getString(i)); } for (int i = 0; i < storiesWithoutTestsList.length(); i++) { storiesWithoutGroomingIds.add(storiesWithoutTestsList.getString(i)); } for (int i = 0; i < storiesWithoutPlanningList.length(); i++) { storiesWithoutPlanning.add(storiesWithoutPlanningList.getString(i)); } // Merge storiesWithoutDevelopment with storiesWithOpenDefectCount and storiesWithoutTestsCompleted JSONArray storiesWithoutDevelopmentArray = storiesJson.getJSONArray("storiesWithoutDevelopment"); JSONArray storiesWithOpenDefectList = testsDefectsJson.getJSONArray("storiesWithOpenDefectList"); JSONArray storiesWithoutTestsCompleted = testsDefectsJson.getJSONArray("storiesWithoutTestsCompleted"); for (int i = 0; i < storiesWithoutDevelopmentArray.length(); i++) { storiesWithoutDevelopment.add(storiesWithoutDevelopmentArray.getString(i)); } for (int i = 0; i < storiesWithOpenDefectList.length(); i++) { storiesWithoutDevelopment.add(storiesWithOpenDefectList.getString(i)); } for (int i = 0; i < storiesWithoutTestsCompleted.length(); i++) { storiesWithoutDevelopment.add(storiesWithoutTestsCompleted.getString(i)); } storiesWithoutDevelopment.removeAll(storiesWithoutGroomingIds); storiesWithoutDevelopment.removeAll(storiesWithoutPlanning); // Update counts int totalCountStoriesWithoutGrooming = storiesWithoutGroomingIds.size(); int totalStoriesWithoutPlanning = storiesWithoutPlanning.size(); int totalStoriesWithoutDevelopment = storiesWithoutDevelopment.size(); //calculate percentages int totalFeaturesCount = featuresJson.getInt("total"); int totalStoriesCount = storiesJson.getInt("total"); int totalStoriesWithGroomingCompleted = totalStoriesCount-totalCountStoriesWithoutGrooming; int totalFeaturesWithGroomingCompleted = totalFeaturesCount-featuresJson.getInt("totalCountOfFeaturesWithoutGrooming"); int totalStoriesWithPlanningCompleted = totalStoriesCount-totalStoriesWithoutPlanning-totalCountStoriesWithoutGrooming; int totalFeaturesWithPlanningCompleted = totalFeaturesCount-featuresJson.getInt("totalCountOfFeaturesWithoutPlanning")-featuresJson.getInt("totalCountOfFeaturesWithoutGrooming"); int totalStoriesWithDevelopmentDone = totalStoriesCount-totalStoriesWithoutDevelopment-totalStoriesWithoutPlanning-totalCountStoriesWithoutGrooming; int totalCountOfFeaturesWithDevelopmentDone = totalFeaturesCount-featuresJson.getInt("totalCountOfFeaturesWithoutDevelopmentDone")-featuresJson.getInt("totalCountOfFeaturesWithoutPlanning")-featuresJson.getInt("totalCountOfFeaturesWithoutGrooming"); double groomingCompletionPercentage = ((double)(totalFeaturesWithGroomingCompleted + totalStoriesWithGroomingCompleted) / (totalFeaturesCount + totalStoriesCount)) * 100; double planningCompletionPercentage = ((double)(totalFeaturesWithPlanningCompleted + totalStoriesWithPlanningCompleted) / (totalFeaturesCount + totalStoriesCount)) * 100; double developmentCompletionPercentage = ((double)(totalCountOfFeaturesWithDevelopmentDone + totalStoriesWithDevelopmentDone) / (totalFeaturesCount + totalStoriesCount)) * 100; // Create response JSON JSONObject response = new JSONObject(); JSONObject scope = new JSONObject(); scope.put("totalFeaturesWithGroomingCompleted", totalFeaturesWithGroomingCompleted); scope.put("totalStoriesWithGroomingCompleted", totalStoriesWithGroomingCompleted); scope.put("storiesWithoutGroomingIds", new JSONArray(storiesWithoutGroomingIds)); scope.put("featuresWithoutGroomingList", featuresJson.getJSONArray("featuresWithoutGroomingList")); scope.put("percentage",groomingCompletionPercentage); JSONObject scopeFeatures = new JSONObject(); scopeFeatures.put("featureWithoutAcceptanceCriteriaList", featuresJson.getJSONArray("AcceptanceCriteriaNotDefined")); scopeFeatures.put("featureWithoutDescriptionList", featuresJson.getJSONArray("DescriptionNotDefined")); scopeFeatures.put("featureWithoutTitleList", featuresJson.getJSONArray("featureWithoutTitleList")); scopeFeatures.put("featureWithoutStoriesList", featuresJson.getJSONArray("featureListWithoutStories")); JSONObject scopeStories = new JSONObject(); scopeStories.put("storyWithoutTitleList", storiesJson.getJSONArray("storiesWithoutTitleIds")); scopeStories.put("storyWithoutAcceptanceCriteriaList", storiesJson.getJSONArray("AcceptanceCriteriaNotDefined")); scopeStories.put("storyWithoutDescriptionList", storiesJson.getJSONArray("DescriptionNotDefined")); scope.put("features", scopeFeatures); scope.put("stories", scopeStories); response.put("scope", scope); JSONObject planning = new JSONObject(); planning.put("totalStoriesWithPlanningCompleted", totalStoriesWithPlanningCompleted); planning.put("totalFeaturesWithPlanningCompleted", totalFeaturesWithPlanningCompleted); planning.put("storiesWithoutPlanning", storiesJson.getJSONArray("storiesWithoutPlanning")); planning.put("featuresWithoutPlanning", featuresJson.getJSONArray("featuresWithoutPlanning")); JSONObject planningFeatures = new JSONObject(); planningFeatures.put("delayedFeaturesList", featuresJson.getJSONArray("delayedFeaturesList")); planningFeatures.put("featureWithoutTeamList", featuresJson.getJSONArray("TeamNotDefined")); planningFeatures.put("featureWithoutOwnerList", featuresJson.getJSONArray("OwnerNotDefined")); planningFeatures.put("featurePIEndDateAfterODRTargetDateList", featuresJson.getJSONArray("featurePIEndDateAfterODRTargetDate")); planningFeatures.put("featureWithoutPIEndDateList", featuresJson.getJSONArray("featureWithoutPIEndDateList")); planningFeatures.put("featureWithoutPINameList", featuresJson.getJSONArray("PINameNotDefined")); JSONObject planningStories = new JSONObject(); planningStories.put("storyWithoutEstimationList", storiesJson.getJSONArray("EstimationNotDone")); planningStories.put("storyWithoutTeamList", storiesJson.getJSONArray("TeamNotDefined")); planningStories.put("storyWithoutOwnerList", storiesJson.getJSONArray("OwnerNotDefined")); planningStories.put("storyWithoutIterationList", storiesJson.getJSONArray("IterationNameNotDefined")); planningStories.put("storyWithoutTasksList", storiesJson.getJSONArray("TasksBreakdownNotDefined")); planningStories.put("storiesWhichHasTasksWithoutEstimationList", storiesJson.getJSONArray("storiesWhichHasTasksWithoutEstimation")); planningStories.put("storiesIterationEndDateAfterODRTargetDateList", storiesJson.getJSONArray("storiesIterationEndDateAfterODRTargetDate")); planningStories.put("storiesPastIterationEndDateList", storiesJson.getJSONArray("storiesPastIterationEndDate")); planning.put("percentage",planningCompletionPercentage); planning.put("features", planningFeatures); planning.put("stories", planningStories); response.put("planning", planning); JSONObject development = new JSONObject(); development.put("totalStoriesWithDevelopmentDone", totalStoriesWithDevelopmentDone); development.put("totalCountOfFeaturesWithDevelopmentDone", totalCountOfFeaturesWithDevelopmentDone); development.put("storiesWithoutDevelopment", new JSONArray(storiesWithoutDevelopment)); development.put("featuresWithoutDevelopmentDone", featuresJson.getJSONArray("featuresWithoutDevelopmentDone")); JSONObject developmentFeatures = new JSONObject(); developmentFeatures.put("featureWithoutDoneStatusList", featuresJson.getJSONArray("featureWithoutDoneStatusList")); JSONObject developmentStories = new JSONObject(); developmentStories.put("storiesWithoutTasksDoneList", storiesJson.getJSONArray("storiesWithoutTasksDone")); developmentStories.put("storiesNotDoneList", storiesJson.getJSONArray("storiesNotDoneList")); development.put("percentage",developmentCompletionPercentage); development.put("features", developmentFeatures); development.put("stories", developmentStories); response.put("development", development); response.put("totalFeaturesCount", totalFeaturesCount); response.put("totalStoriesCount", totalStoriesCount); if (genAIResponse!=null && !genAIResponse.isBlank()){ response.put("AIRecommendations", genAIResponse); } return response.toString(); }' - Assistant