public Set<String> resolveParticipantIds(String anyID) {
   Set<String> idSet = new HashSet<String>();
   for (Participant p : resolveParticipants(anyID)) {
     idSet.add(p.getID());
   }
   return idSet;
 }
 public String resolveParticipantIdsAsXML(String anyID) {
   XNode node = new XNode("participantids");
   for (Participant p : resolveParticipants(anyID)) {
     node.addChild("id", p.getID());
   }
   return node.toString();
 }
 public Set<Participant> getOrgGroupMembers(OrgGroup o) {
   Set<Participant> result = new HashSet<Participant>();
   for (Participant p : participantMap.values()) {
     if (p.isOrgGroupMember(o)) result.add(p);
   }
   return result;
 }
  public String getParticipantsAsXML() {
    List<Participant> pList = sortFullParticipantListByName();

    StringBuilder xml = new StringBuilder("<participants>");
    for (Participant p : pList) xml.append(p.toXML());
    xml.append("</participants>");
    return xml.toString();
  }
 public Participant getParticipantFromUserID(String userID) {
   for (Participant p : getParticipants()) {
     if (p.getUserID().equals(userID)) {
       return p;
     }
   }
   return null;
 }
 // @return a csv listing of the full name of each participant
 public String getParticipantNames() {
   List<Participant> pList = sortFullParticipantListByName();
   StringBuilder csvList = new StringBuilder();
   for (Participant p : pList) {
     if (csvList.length() > 0) csvList.append(",");
     csvList.append(p.getFullName());
   }
   return csvList.toString();
 }
  private synchronized void disconnectResources(AbstractResourceAttribute attrib) {
    Set<AbstractResource> resources = attrib.getResources();

    // get ids to avoid ConcurrentModificationException
    List<String> ids = new ArrayList<String>();
    for (AbstractResource resource : resources) ids.add(resource.getID());

    for (String id : ids) {
      Participant p = getParticipant(id);
      if (attrib instanceof Role) p.removeRole((Role) attrib);
      else if (attrib instanceof Capability) p.removeCapability((Capability) attrib);
      else if (attrib instanceof Position) p.removePosition((Position) attrib);
      updateParticipant(p);
    }
  }
 /** ********************************* */
 public String addParticipant(Participant p) {
   if (isDataEditable(ResUnit.Participant)) {
     String newID = getDataSource(ResUnit.Participant).insert(p);
     if (!hasDefaultDataSource(ResUnit.Participant)) p.setID(newID);
     putParticipant(p); // add it to the data set
     return newID;
   } else return fail("External Participant dataset is read-only");
 }
 /** ********************************* */
 public synchronized boolean removeParticipant(Participant p) {
   boolean editable = isDataEditable(ResUnit.Participant);
   if (editable) {
     p.removeAttributeReferences();
     getDataSource(ResUnit.Participant).delete(p);
     delParticipant(p);
   }
   return editable;
 }
  /** Handles XEP-0337 "log" extensions. */
  private void handleLogRequest(LogPacketExtension log, String jid) {
    JitsiMeetConference conference = getConferenceForMucJid(jid);

    if (conference == null) {
      logger.debug("Room not found for JID: " + jid);
      return;
    }

    Participant participant = conference.findParticipantForRoomJid(jid);

    if (participant == null) {
      logger.info("Ignoring log request from an unknown JID: " + jid);
      return;
    }

    EventAdmin eventAdmin = FocusBundleActivator.getEventAdmin();

    if (eventAdmin == null) return;

    if (LogUtil.LOG_ID_PC_STATS.equals(log.getID())) {
      String content = LogUtil.getContent(log);

      if (content != null) {
        ColibriConference colibriConference = conference.getColibriConference();

        if (colibriConference != null) {
          Event event =
              EventFactory.peerConnectionStats(
                  colibriConference.getConferenceId(), participant.getEndpointId(), content);

          if (event != null) eventAdmin.sendEvent(event);
        } else {
          logger.warn("Unhandled log request" + " - no valid Colibri conference");
        }
      }
    } else if (logger.isInfoEnabled()) {
      logger.info("Ignoring log request with an unknown ID:" + log.getID());
    }
  }
 /**
  * Gets the immediate supervisor of a participant. If the participant holds multiple positions,
  * and therefore has multiple supervisors, one is returned as a random selection.
  *
  * @param p the participant to get the supervisor of
  * @return the Participant who is the supervisor of the pid passed, or null if there is no
  *     supervisor.
  */
 public Participant getImmediateSupervisor(Participant p) {
   if (p != null) {
     for (Position position : p.getPositions()) {
       Position superPosition = position.getReportsTo();
       if (superPosition != null) {
         Set<AbstractResource> resources = superPosition.getResources();
         if (!resources.isEmpty()) {
           return (Participant) resources.iterator().next();
         }
       }
     }
   }
   return null;
 }
 public Map<String, String> getParticipantIdentifiers(Identifier idType) {
   Map<String, String> idMap = new Hashtable<String, String>();
   for (Participant p : getParticipants()) {
     String nameValue;
     switch (idType) {
       case FullName:
         nameValue = p.getFullName();
         break;
       case ReverseFullName:
         nameValue = p.getLastName() + ", " + p.getFirstName();
         break;
       case LastName:
         nameValue = p.getLastName();
         break;
       default:
         nameValue = p.getUserID();
     }
     idMap.put(p.getID(), nameValue);
   }
   return idMap;
 }
 /** ********************************* */
 public void delParticipant(Participant p) {
   participantMap.remove(p.getID());
   setChangeStamp(ResUnit.Participant);
 }
 /** ********************************* */
 public void putParticipant(Participant p) {
   participantMap.put(p.getID(), p);
   setChangeStamp(ResUnit.Participant);
 }
 public void rollback() {
   for (Participant participant : participants) {
     participant.rollback();
   }
 }
 public Set<Capability> getParticipantCapabilities(String pid) {
   Participant p = participantMap.get(pid);
   return (p != null) ? p.getCapabilities() : null;
 }
 public Set<Position> getParticipantPositions(String pid) {
   Participant p = participantMap.get(pid);
   return (p != null) ? p.getPositions() : null;
 }
 public Set<Role> getParticipantRoles(String pid) {
   Participant p = participantMap.get(pid);
   return (p != null) ? p.getRoles() : null;
 }
 public boolean isKnownParticipant(Participant p) {
   return isKnownParticipant(p.getID());
 }
 private String participantSetToXML(Set<Participant> pSet, String header) {
   StringBuilder xml = new StringBuilder(header);
   for (Participant p : pSet) xml.append(p.toXML());
   xml.append("</participants>");
   return xml.toString();
 }
  /**
   * Handles presence stanzas
   *
   * @param presence
   */
  private void handlePresence(Presence presence) {
    // unavailable is sent when user leaves the room
    if (!presence.isAvailable()) {
      return;
    }

    String from = presence.getFrom();
    JitsiMeetConference conference = getConferenceForMucJid(from);

    if (conference == null) {
      if (logger.isDebugEnabled()) {
        logger.debug("Room not found for JID: " + from);
      }
      return;
    }

    ChatRoomMemberRole role = conference.getRoleForMucJid(from);

    if (role != null && role.compareTo(ChatRoomMemberRole.MODERATOR) < 0) {
      StartMutedPacketExtension ext =
          (StartMutedPacketExtension)
              presence.getExtension(
                  StartMutedPacketExtension.ELEMENT_NAME, StartMutedPacketExtension.NAMESPACE);

      if (ext != null) {
        boolean[] startMuted = {ext.getAudioMuted(), ext.getVideoMuted()};

        conference.setStartMuted(startMuted);
      }
    }

    Participant participant = conference.findParticipantForRoomJid(from);
    ColibriConference colibriConference = conference.getColibriConference();

    if (participant != null && colibriConference != null) {
      // Check if this conference is valid
      String conferenceId = colibriConference.getConferenceId();
      if (StringUtils.isNullOrEmpty(conferenceId)) {
        logger.error("Unable to send DisplayNameChanged event" + " - no conference id");
        return;
      }

      // Check for changes to the display name
      String oldDisplayName = participant.getDisplayName();
      String newDisplayName = null;
      for (PacketExtension pe : presence.getExtensions()) {
        if (pe instanceof Nick) {
          newDisplayName = ((Nick) pe).getName();
          break;
        }
      }

      if (!Objects.equals(oldDisplayName, newDisplayName)) {
        participant.setDisplayName(newDisplayName);

        EventAdmin eventAdmin = FocusBundleActivator.getEventAdmin();
        if (eventAdmin != null) {
          // Prevent NPE when adding to event hashtable
          if (newDisplayName == null) {
            newDisplayName = "";
          }
          eventAdmin.sendEvent(
              EventFactory.endpointDisplayNameChanged(
                  conferenceId, participant.getEndpointId(), newDisplayName));
        }
      }
    }
  }
  public void commit() {

    for (Participant participant : participants) {
      participant.commit();
    }
  }