Example #1
0
  /** @param project */
  private void createInitialFindingsFromInterviews(Project project) {
    List<InterviewSummary> interviewSummaryList = project.getInterviewSummaries();

    for (InterviewSummary interviewSummary : CollectionUtil.safe(interviewSummaryList)) {
      for (InterviewDtl interviewDtl : interviewSummary.getInterviewDtls()) {
        if (RoadmapConstants.VALUE_YES_CHAR.equals(interviewDtl.getFindingsFlag())) {
          Finding finding = new Finding();
          finding.setFindingsText(interviewDtl.getResponseText());
          FindingsCategory findingsCategory =
              getEntityManager()
                  .find(
                      FindingsCategory.class,
                      interviewDtl
                          .getQuestionGroupMapping()
                          .getQuestionGroup()
                          .getQuestionGroupId());
          findingsCategory.addFinding(finding);

          project.addFinding(finding);

          getEntityManager().persist(finding);
        }
      }
    }

    getEntityManager().flush();
  }
Example #2
0
  /**
   * @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("&amp;", "&"));
          findings.setProject(project);
          getEntityManager().persist(findings);
        }
        findings.setFindingsText(
            (findingsVO.getFindingsText() == null)
                ? RoadmapConstants.EMPTY_STRING
                : findingsVO.getFindingsText().replace("&amp;", "&"));
        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;
  }