/** * @param requestVO * @return */ @Transactional(propagation = Propagation.REQUIRED) public FindingsResponseVO retrieveFindings(FindingsRequestVO requestVO) { FindingsResponseVO responseVO = new FindingsResponseVO(); Project project = getEntityManager().find(Project.class, Long.parseLong(requestVO.getProjectId())); if (project.getFindings() == null || project.getFindings().isEmpty()) { createInitialFindingsFromInterviews(project); } List<FindingsVO> findingsVOList = new ArrayList<FindingsVO>(); for (Finding finding : CollectionUtil.safe(project.getFindings())) { FindingsVO findingsVO = new FindingsVO(); findingsVO.setFindingsId(String.valueOf(finding.getFindingsId())); findingsVO.setFindingsText(finding.getFindingsText()); findingsVO.setImportance(finding.getImportance()); findingsVO.setFindingsCategoryId( String.valueOf(finding.getFindingsCategory().getFindingsCategoryId())); findingsVOList.add(findingsVO); } this.includeInputParams(findingsVOList); List<OpportunityVO> opportunityVOList = new ArrayList<OpportunityVO>(); for (Opportunity opportunity : CollectionUtil.safe(project.getOpportunities())) { OpportunityVO opportunityVO = new OpportunityVO(); opportunityVO.setOpportunityId(String.valueOf(opportunity.getOpportunityId())); opportunityVO.setOpportunityText(opportunity.getOpportunityText()); opportunityVO.setOpportunityCategoryId( String.valueOf(opportunity.getOpportunityCategory().getOpportunityCategoryId())); opportunityVOList.add(opportunityVO); } responseVO.setProjectId(Long.parseLong(requestVO.getProjectId())); responseVO.setFindingsList(addFindingsGridSelection(findingsVOList)); responseVO.setOpportunityList(addOpportunityGridSelection(opportunityVOList)); responseVO.setCompletedSteps( ProjectRoadmapProgressUtil.getCompletedSteps(getEntityManager(), requestVO.getProjectId())); return responseVO; }
/** * @param requestVO * @return */ @Transactional(propagation = Propagation.REQUIRED) public int saveFindings(FindingsRequestVO requestVO) { Project project = getEntityManager().find(Project.class, Long.parseLong(requestVO.getProjectId())); // FINDINGS List<Finding> findingsList = new ArrayList<Finding>(); for (FindingsVO findingsVO : CollectionUtil.safe(requestVO.getFindingsList())) { Finding findings = null; if (DataValidator.isNotEmpty(findingsVO.getFindingsCategoryId()) || DataValidator.isNotEmpty(findingsVO.getFindingsText())) { if (!DataValidator.isNewRecord(findingsVO.getFindingsId())) { findings = getEntityManager().find(Finding.class, Long.parseLong(findingsVO.getFindingsId())); } else { findings = new Finding(); if (findingsVO.getFindingsCategoryId() != null) { if (NumberUtils.isNumber(findingsVO.getFindingsCategoryId())) { findings.setFindingsCategory( getEntityManager() .find( FindingsCategory.class, Long.parseLong(findingsVO.getFindingsCategoryId()))); } else { FindingsCategory findingsCategory = new FindingsCategory(); findingsCategory.setFindingsCategoryDesc(findingsVO.getFindingsCategoryId()); findingsCategory.setFindingsCategoryName(findingsVO.getFindingsCategoryId()); getEntityManager().persist(findingsCategory); findings.setFindingsCategory(findingsCategory); } } findings.setFindingsText( (findingsVO.getFindingsText() == null) ? RoadmapConstants.EMPTY_STRING : findingsVO.getFindingsText().replace("&", "&")); findings.setProject(project); getEntityManager().persist(findings); } findings.setFindingsText( (findingsVO.getFindingsText() == null) ? RoadmapConstants.EMPTY_STRING : findingsVO.getFindingsText().replace("&", "&")); findings.setImportance(findingsVO.getImportance()); if (!DataValidator.isNewRecord(findingsVO.getFindingsCategoryId()) && NumberUtils.isNumber(findingsVO.getFindingsCategoryId())) { FindingsCategory findingsCategory = getEntityManager() .find(FindingsCategory.class, Long.parseLong(findingsVO.getFindingsCategoryId())); findings.setFindingsCategory(findingsCategory); } findingsList.add(findings); } } // OPPORTUNITY List<Opportunity> opportunityList = new ArrayList<Opportunity>(); for (OpportunityVO opportunityVO : CollectionUtil.safe(requestVO.getOpportunityList())) { Opportunity opportunity = null; if (DataValidator.isNotEmpty(opportunityVO.getOpportunityCategoryId()) || DataValidator.isNotEmpty(opportunityVO.getOpportunityText())) { if (!DataValidator.isNewRecord(opportunityVO.getOpportunityId())) { opportunity = getEntityManager() .find(Opportunity.class, Long.parseLong(opportunityVO.getOpportunityId())); } else { opportunity = new Opportunity(); if (opportunityVO.getOpportunityCategoryId() != null) { if (NumberUtils.isNumber(opportunityVO.getOpportunityCategoryId()) && isValidId(opportunityVO.getOpportunityCategoryId())) { opportunity.setOpportunityCategory( getEntityManager() .find( OpportunityCategory.class, Long.parseLong(opportunityVO.getOpportunityCategoryId()))); } else { OpportunityCategory opportunityCategory = new OpportunityCategory(); opportunityCategory.setOpportunityCategoryDesc( opportunityVO.getOpportunityCategoryId()); opportunityCategory.setOpportunityCategoryName( opportunityVO.getOpportunityCategoryId()); getEntityManager().persist(opportunityCategory); getEntityManager().flush(); opportunity.setOpportunityCategory(opportunityCategory); } } opportunity.setOpportunityText(opportunityVO.getOpportunityText()); opportunity.setProject(project); getEntityManager().persist(opportunity); } opportunity.setOpportunityText(opportunityVO.getOpportunityText()); if (!DataValidator.isNewRecord(opportunityVO.getOpportunityCategoryId()) && NumberUtils.isNumber(opportunityVO.getOpportunityCategoryId()) && isValidId(opportunityVO.getOpportunityCategoryId())) { OpportunityCategory opportunityCategory = getEntityManager() .find( OpportunityCategory.class, Long.parseLong(opportunityVO.getOpportunityCategoryId())); opportunity.setOpportunityCategory(opportunityCategory); } opportunityList.add(opportunity); } } List<Finding> projectFindingsListForRemoval = (List<Finding>) CollectionUtils.removeAll(CollectionUtil.safe(project.getFindings()), findingsList); for (Finding findingForRemoval : projectFindingsListForRemoval) { getEntityManager().remove(findingForRemoval); getEntityManager().flush(); project.removeFinding(findingForRemoval); } List<Opportunity> projectOpportunityListForRemoval = (List<Opportunity>) CollectionUtils.removeAll( CollectionUtil.safe(project.getOpportunities()), opportunityList); for (Opportunity opportunityForRemoval : projectOpportunityListForRemoval) { getEntityManager().remove(opportunityForRemoval); getEntityManager().flush(); project.removeOpportunity(opportunityForRemoval); } return RoadmapConstants.SAVE_SUCCESS; }