/**
   * Method that search the PlatformComponentProfiles tha mach with the parameters
   *
   * @param platformComponentType
   * @param networkServiceType
   * @param communicationCloudClientIdentity
   * @return List<PlatformComponentProfile>
   */
  private List<PlatformComponentProfile> searchProfileByCommunicationCloudClientIdentity(
      PlatformComponentType platformComponentType,
      NetworkServiceType networkServiceType,
      String communicationCloudClientIdentity) {

    /*
     * Prepare the list
     */
    List<PlatformComponentProfile> temporalList = null;
    List<PlatformComponentProfile> finalFilteredList = new ArrayList<>();

    /*
     * Switch between platform component type
     */
    switch (platformComponentType) {
      case COMMUNICATION_CLOUD_SERVER:
        temporalList =
            new ArrayList<>(
                wsCommunicationCloudServer.getRegisteredCommunicationsCloudServerCache().values());
        break;

      case COMMUNICATION_CLOUD_CLIENT:
        temporalList =
            new ArrayList<>(
                wsCommunicationCloudServer.getRegisteredCommunicationsCloudClientCache().values());
        break;

      case NETWORK_SERVICE:
        temporalList =
            new ArrayList<>(
                wsCommunicationCloudServer
                    .getRegisteredNetworkServicesCache()
                    .get(networkServiceType));
        break;

        // Others
      default:
        temporalList =
            wsCommunicationCloudServer
                .getRegisteredOtherPlatformComponentProfileCache()
                .get(platformComponentType);
        break;
    }

    /*
     * Find the component that match with the CommunicationCloudClientIdentity
     */
    for (PlatformComponentProfile platformComponentProfile : temporalList) {

      if (platformComponentProfile
          .getCommunicationCloudClientIdentity()
          .equals(communicationCloudClientIdentity)) {
        finalFilteredList.add(platformComponentProfile);
      }
    }

    return finalFilteredList;
  }
  /**
   * Filter the PlatformComponentProfiles that match with the discoveryQueryParameters that get from
   * other component
   *
   * @param discoveryQueryParameters
   * @param clientIdentityPublicKey
   * @return List<PlatformComponentProfile>
   */
  private List<PlatformComponentProfile> applyDiscoveryQueryParametersFromOtherComponent(
      DiscoveryQueryParameters discoveryQueryParameters, String clientIdentityPublicKey) {

    System.out.println(
        "ComponentRegisteredListWebService - applyDiscoveryQueryParametersFromOtherComponent    = ");

    List<PlatformComponentProfile> filteredListFromOtherComponentType = new ArrayList<>();

    /*
     * Get the list from the cache that match with the other componet
     */
    List<PlatformComponentProfile> otherComponentList =
        (List<PlatformComponentProfile>)
            new ArrayList<>(
                    searchProfile(
                        discoveryQueryParameters.getFromOtherPlatformComponentType(),
                        discoveryQueryParameters.getFromOtherNetworkServiceType(),
                        discoveryQueryParameters.getIdentityPublicKey()))
                .clone();
    System.out.println(
        "ComponentRegisteredListWebService - otherComponentList  = " + otherComponentList.size());

    /*
     * Find the other component that match with the identity
     */
    for (PlatformComponentProfile platformComponentProfile : otherComponentList) {

      if (discoveryQueryParameters.getIdentityPublicKey() != null
          && discoveryQueryParameters.getIdentityPublicKey() != "") {
        List<PlatformComponentProfile> newList =
            searchProfileByCommunicationCloudClientIdentity(
                discoveryQueryParameters.getPlatformComponentType(),
                discoveryQueryParameters.getNetworkServiceType(),
                platformComponentProfile.getCommunicationCloudClientIdentity());
        filteredListFromOtherComponentType.addAll(newList);
      }
    }

    /*
     * Remove the requester from the list
     */
    Iterator<PlatformComponentProfile> iterator = filteredListFromOtherComponentType.iterator();
    while (iterator.hasNext()) {

      PlatformComponentProfile platformComponentProfileRegistered = iterator.next();
      if (platformComponentProfileRegistered
          .getCommunicationCloudClientIdentity()
          .equals(clientIdentityPublicKey)) {
        System.out.println(
            "ComponentRegisteredListWebService - removing ="
                + platformComponentProfileRegistered.getName());
        iterator.remove();
      }
    }

    System.out.println(
        "ComponentRegisteredListWebService - filteredListFromOtherComponentType  = "
            + filteredListFromOtherComponentType.size());

    return filteredListFromOtherComponentType;
  }
  /**
   * Return the primary list from the cache filtered by the platformComponentType or
   * networkServiceType
   *
   * @param platformComponentType
   * @param networkServiceType
   * @return List<PlatformComponentProfile>
   */
  public List<PlatformComponentProfile> getPrimaryFilteredListFromCache(
      PlatformComponentType platformComponentType,
      NetworkServiceType networkServiceType,
      String clientIdentityPublicKey) {

    /*
     * Get the list
     */
    List<PlatformComponentProfile> list = new ArrayList<>();

    /*
     * Switch between platform component type
     */
    switch (platformComponentType) {
      case COMMUNICATION_CLOUD_SERVER:
        if (!wsCommunicationCloudServer.getRegisteredCommunicationsCloudServerCache().isEmpty()) {
          list =
              (List<PlatformComponentProfile>)
                  new ArrayList<>(
                          wsCommunicationCloudServer
                              .getRegisteredCommunicationsCloudServerCache()
                              .values())
                      .clone();
        }
        break;

      case COMMUNICATION_CLOUD_CLIENT:
        if (!wsCommunicationCloudServer.getRegisteredCommunicationsCloudClientCache().isEmpty()) {
          list =
              (List<PlatformComponentProfile>)
                  new ArrayList<>(
                          wsCommunicationCloudServer
                              .getRegisteredCommunicationsCloudClientCache()
                              .values())
                      .clone();
        }
        break;

      case NETWORK_SERVICE:
        if (wsCommunicationCloudServer
                .getRegisteredNetworkServicesCache()
                .containsKey(networkServiceType)
            && !wsCommunicationCloudServer
                .getRegisteredNetworkServicesCache()
                .get(networkServiceType)
                .isEmpty()) {
          list =
              (List<PlatformComponentProfile>)
                  new ArrayList<>(
                          wsCommunicationCloudServer
                              .getRegisteredNetworkServicesCache()
                              .get(networkServiceType))
                      .clone();
        }
        break;

        // Others
      default:
        if (wsCommunicationCloudServer
                .getRegisteredOtherPlatformComponentProfileCache()
                .containsKey(platformComponentType)
            && !wsCommunicationCloudServer
                .getRegisteredOtherPlatformComponentProfileCache()
                .get(platformComponentType)
                .isEmpty()) {
          list =
              (List<PlatformComponentProfile>)
                  new ArrayList<>(
                          wsCommunicationCloudServer
                              .getRegisteredOtherPlatformComponentProfileCache()
                              .get(platformComponentType))
                      .clone();
        }
        break;
    }

    /*
     * Remove the requester from the list
     */
    Iterator<PlatformComponentProfile> iterator = list.iterator();
    while (iterator.hasNext()) {

      PlatformComponentProfile platformComponentProfileRegistered = iterator.next();
      if (platformComponentProfileRegistered
          .getCommunicationCloudClientIdentity()
          .equals(clientIdentityPublicKey)) {
        System.out.println(
            "ComponentRegisteredListWebService - removing ="
                + platformComponentProfileRegistered.getName());
        iterator.remove();
      }
    }

    return list;
  }