/**
   * Update the common fields in the UnManagedVolume to reflect RP characteristics Is this volume
   * SOURCE, TARGET, or JOURNAL? What's the RP Copy Name of this volume? (what copy does it belong
   * to?)
   *
   * @param unManagedProtectionSet
   * @param unManagedVolume
   * @param personalityType
   * @param volume
   * @param dbClient
   */
  private void updateCommonRPProperties(
      UnManagedProtectionSet unManagedProtectionSet,
      UnManagedVolume unManagedVolume,
      String personalityType,
      GetVolumeResponse volume,
      DbClient dbClient) {
    StringSet rpCopyName = new StringSet();
    rpCopyName.add(volume.getRpCopyName());

    StringSet rpInternalSiteName = new StringSet();
    rpInternalSiteName.add(volume.getInternalSiteName());

    if (volume.isProductionStandby()) {
      unManagedVolume.putVolumeInfo(
          SupportedVolumeInformation.RP_STANDBY_COPY_NAME.toString(), rpCopyName);

      unManagedVolume.putVolumeInfo(
          SupportedVolumeInformation.RP_STANDBY_INTERNAL_SITENAME.toString(), rpInternalSiteName);

      // If this volume is flagged as production standby it indicates that this RP CG is
      // MetroPoint. Set the IS_MP flag on UnManagedProtectionSet to TRUE. This only needs
      // to be done once.
      String metroPoint =
          unManagedProtectionSet
              .getCGCharacteristics()
              .get(UnManagedProtectionSet.SupportedCGCharacteristics.IS_MP.name());
      if (metroPoint == null || metroPoint.isEmpty() || !Boolean.parseBoolean(metroPoint)) {
        // Set the flag to true if it hasn't already been set
        unManagedProtectionSet
            .getCGCharacteristics()
            .put(
                UnManagedProtectionSet.SupportedCGCharacteristics.IS_MP.name(),
                Boolean.TRUE.toString());
      }
    } else {
      unManagedVolume.putVolumeInfo(SupportedVolumeInformation.RP_COPY_NAME.toString(), rpCopyName);

      unManagedVolume.putVolumeInfo(
          SupportedVolumeInformation.RP_INTERNAL_SITENAME.toString(), rpInternalSiteName);
    }

    StringSet personality = new StringSet();
    personality.add(personalityType);
    unManagedVolume.putVolumeInfo(
        SupportedVolumeInformation.RP_PERSONALITY.toString(), personality);

    StringSet rpProtectionSystemId = new StringSet();
    rpProtectionSystemId.add(unManagedProtectionSet.getProtectionSystemUri().toString());
    unManagedVolume.putVolumeInfo(
        SupportedVolumeInformation.RP_PROTECTIONSYSTEM.toString(), rpProtectionSystemId);

    // Filter in RP source vpools, filter out everything else (if source)
    // Filter out certain vpools if target/journal

    filterProtectedVpools(dbClient, unManagedVolume, personality.iterator().next());
  }
  /**
   * Clean up the existing unmanaged protection set and its associated unmanaged volumes so that it
   * gets updated with latest info during rediscovery
   *
   * @param unManagedProtectionSet unmanaged protection set
   * @param unManagedVolumesToUpdateByWwn unmanaged volumes to update
   * @param dbClient db client
   */
  private void cleanUpUnManagedResources(
      UnManagedProtectionSet unManagedProtectionSet,
      Map<String, UnManagedVolume> unManagedVolumesToUpdateByWwn,
      DbClient dbClient) {
    // Clean up the volume wwns, managed volume and unmanaged volume lists of the unmanaged
    // protection set
    unManagedProtectionSet.getManagedVolumeIds().clear();
    unManagedProtectionSet.getVolumeWwns().clear();
    List<URI> unManagedVolsUris =
        new ArrayList<URI>(
            Collections2.transform(
                unManagedProtectionSet.getUnManagedVolumeIds(),
                CommonTransformerFunctions.FCTN_STRING_TO_URI));
    Iterator<UnManagedVolume> unManagedVolsOfProtectionSetIter =
        dbClient.queryIterativeObjects(UnManagedVolume.class, unManagedVolsUris);
    while (unManagedVolsOfProtectionSetIter.hasNext()) {
      UnManagedVolume rpUnManagedVolume = unManagedVolsOfProtectionSetIter.next();
      // Clear the RP related fields in the UnManagedVolume
      StringSet rpPersonality =
          rpUnManagedVolume
              .getVolumeInformation()
              .get(SupportedVolumeInformation.RP_PERSONALITY.toString());
      StringSet rpCopyName =
          rpUnManagedVolume
              .getVolumeInformation()
              .get(SupportedVolumeInformation.RP_COPY_NAME.toString());
      StringSet rpInternalSiteName =
          rpUnManagedVolume
              .getVolumeInformation()
              .get(SupportedVolumeInformation.RP_INTERNAL_SITENAME.toString());
      StringSet rpProtectionSystem =
          rpUnManagedVolume
              .getVolumeInformation()
              .get(SupportedVolumeInformation.RP_PROTECTIONSYSTEM.toString());
      StringSet rpSourceVol =
          rpUnManagedVolume
              .getVolumeInformation()
              .get(SupportedVolumeInformation.RP_UNMANAGED_SOURCE_VOLUME.toString());
      StringSet rpTargetVols =
          rpUnManagedVolume
              .getVolumeInformation()
              .get(SupportedVolumeInformation.RP_UNMANAGED_TARGET_VOLUMES.toString());
      StringSet rpAccessState =
          rpUnManagedVolume
              .getVolumeInformation()
              .get(SupportedVolumeInformation.RP_ACCESS_STATE.toString());

      if (rpPersonality != null) {
        rpPersonality.clear();
      }
      if (rpCopyName != null) {
        rpCopyName.clear();
      }
      if (rpInternalSiteName != null) {
        rpInternalSiteName.clear();
      }
      if (rpProtectionSystem != null) {
        rpProtectionSystem.clear();
      }
      if (rpSourceVol != null) {
        rpSourceVol.clear();
      }
      if (rpTargetVols != null) {
        rpTargetVols.clear();
      }
      if (rpAccessState != null) {
        rpAccessState.clear();
      }
      unManagedVolumesToUpdateByWwn.put(rpUnManagedVolume.getWwn(), rpUnManagedVolume);
    }

    unManagedProtectionSet.getUnManagedVolumeIds().clear();
  }