/**
   * Associate the existing SCG to the report.
   *
   * @param request : request
   * @param reportQueueId : reportQueueId
   * @param participantIdToAssociate : participantIdToAssociate
   * @param specimenCollGrpId : specimenCollGrpId
   * @throws DAOException : DAOException
   * @throws BizLogicException : BizLogicException
   * @throws UserNotAuthorizedException : UserNotAuthorizedException
   */
  private void associateSCGWithReport(
      HttpServletRequest request,
      String reportQueueId,
      String participantIdToAssociate,
      String specimenCollGrpId)
      throws DAOException, BizLogicException, UserNotAuthorizedException {
    Long cprId = null;
    ReportLoaderQueue reportLoaderQueue = null;
    reportLoaderQueue = Utility.getReportQueueObject(reportQueueId);

    // Changing the status of the report in the queue to NEW
    reportLoaderQueue.setStatus(CaTIESConstants.NEW);

    // Associating the SCG
    if (specimenCollGrpId != null && !specimenCollGrpId.equals("")) {
      SpecimenCollectionGroup scg = null;
      final IFactory factory = AbstractFactoryConfig.getInstance().getBizLogicFactory();
      final ReportLoaderQueueBizLogic reportLoaderQueueBizLogic =
          (ReportLoaderQueueBizLogic) factory.getBizLogic(ReportLoaderQueue.class.getName());
      final Object object =
          reportLoaderQueueBizLogic.retrieve(
              SpecimenCollectionGroup.class.getName(), new Long(specimenCollGrpId));
      if (object != null) {
        scg = (SpecimenCollectionGroup) object;
      }
      cprId = scg.getCollectionProtocolRegistration().getId();
      reportLoaderQueue.setSpecimenCollectionGroup(scg);
    }

    // Retrieving participantID if it is null
    if (participantIdToAssociate == null || participantIdToAssociate.equals("")) {
      final DefaultBizLogic defaultBizLogic = new DefaultBizLogic();
      final Long partID =
          (Long)
              defaultBizLogic.retrieveAttribute(
                  CollectionProtocolRegistration.class.getName(),
                  cprId,
                  Constants.COLUMN_NAME_PARTICIPANT_ID);
      participantIdToAssociate = partID.toString();
    }

    // removing all participants from CATISSUE_REPORT_PARTICIP_REL other
    // than the selected participant
    final Collection participantColl = reportLoaderQueue.getParticipantCollection();
    final Iterator iter = participantColl.iterator();
    final Set tempColl = new HashSet();
    Participant participant = null;
    while (iter.hasNext()) {
      participant = (Participant) iter.next();
      if (participant.getId().toString().equals(participantIdToAssociate.trim())) {
        tempColl.add(participant);
      }
    }
    reportLoaderQueue.setParticipantCollection(tempColl);

    // Updating the report queue obj
    this.updateReportLoaderQueue(reportLoaderQueue, request);
  }
  /**
   * Ignore the new report and use the existing one.
   *
   * @param reportQueueId : reportQueueId
   * @throws DAOException : DAOException
   * @throws UserNotAuthorizedException : UserNotAuthorizedException
   * @throws BizLogicException : BizLogicException
   */
  protected void ignoreNewReport(String reportQueueId)
      throws DAOException, UserNotAuthorizedException, BizLogicException {
    // Long cprId = null;
    ReportLoaderQueue reportLoaderQueue = null;
    reportLoaderQueue = Utility.getReportQueueObject(reportQueueId);
    final IFactory factory = AbstractFactoryConfig.getInstance().getBizLogicFactory();
    final ReportLoaderQueueBizLogic reportLoaderQueueBizLogic =
        (ReportLoaderQueueBizLogic) factory.getBizLogic(ReportLoaderQueue.class.getName());

    // deleting the reportloaderQueue object
    reportLoaderQueueBizLogic.delete(reportLoaderQueue, 0);
  }
  /**
   * updating the reportloaderQueue obj.
   *
   * @param reportLoaderQueue : reportLoaderQueue
   * @param request : request
   */
  private void updateReportLoaderQueue(
      ReportLoaderQueue reportLoaderQueue, HttpServletRequest request) {

    try {
      final IFactory factory = AbstractFactoryConfig.getInstance().getBizLogicFactory();
      final ReportLoaderQueueBizLogic reportLoaderQueueBizLogic =
          (ReportLoaderQueueBizLogic) factory.getBizLogic(ReportLoaderQueue.class.getName());
      reportLoaderQueueBizLogic.update(
          reportLoaderQueue, reportLoaderQueue, 0, this.getSessionData(request));

    } catch (final Exception e) {
      this.logger.error("Error Updating ReportQueue" + e);
    }
  }