private ParticipantId computeCreator(WaveViewData wave) { for (ObservableWaveletData wavelet : wave.getWavelets()) { if (IdUtil.isConversationRootWaveletId(wavelet.getWaveletId())) { return wavelet.getCreator(); } } // If not found creator - compare with UNKNOWN_CREATOR; return UNKNOWN_CREATOR; }
/** * Verifies whether the wavelet matches the filter criteria. * * @param wavelet the wavelet. * @param user the logged in user. * @param withList the list of participants to be used in 'with' filter. * @param creatorList the list of participants to be used in 'creator' filter. * @param isAllQuery true if the search results should include shared for this domain waves. */ private boolean matches( ObservableWaveletData wavelet, ParticipantId user, ParticipantId sharedDomainParticipantId, List<ParticipantId> withList, List<ParticipantId> creatorList, boolean isAllQuery) throws WaveletStateException { // If it is user data wavelet for the user - return true. if (IdUtil.isUserDataWavelet(wavelet.getWaveletId()) && wavelet.getCreator().equals(user)) { return true; } // Filter by creator. This is the fastest check so we perform it first. for (ParticipantId creator : creatorList) { if (!creator.equals(wavelet.getCreator())) { // Skip. return false; } } // The wavelet should have logged in user as participant for 'in:inbox' // query. if (!isAllQuery && !wavelet.getParticipants().contains(user)) { return false; } // Or if it is an 'all' query - then either logged in user or shared domain // participant should be present in the wave. if (isAllQuery && !WaveletDataUtil.checkAccessPermission(wavelet, user, sharedDomainParticipantId)) { return false; } // If not returned 'false' above - then logged in user is either // explicit or implicit participant and therefore has access permission. // Now filter by 'with'. for (ParticipantId otherUser : withList) { if (!wavelet.getParticipants().contains(otherUser)) { // Skip. return false; } } return true; }
/** Opens a mux, binding its operation channels with operation-supporting wavelets. */ public static void openAndBind( WaveletOperationalizer operationalizer, WaveViewImpl<OpBasedWavelet> wave, WaveDocuments<? extends CcDocument> docRegistry, OperationChannelMultiplexer mux, IdFilter filter, Command whenOpened) { StaticChannelBinder staticBinder = new StaticChannelBinder(operationalizer, docRegistry); LiveChannelBinder liveBinder = new LiveChannelBinder(staticBinder, operationalizer, wave, mux, whenOpened); final Collection<KnownWavelet> remoteWavelets = CollectionUtils.createQueue(); final Collection<ObservableWaveletData> localWavelets = CollectionUtils.createQueue(); for (ObservableWaveletData wavelet : operationalizer.getWavelets()) { // Version 0 wavelets must be wavelets that the client has created in this // session. They are not to be included in the known-wavelet collection, // because the server does not know about them. if (wavelet.getVersion() > 0) { remoteWavelets.add( new KnownWavelet(wavelet, wavelet.getHashedVersion(), Accessibility.READ_WRITE)); } else { localWavelets.add(wavelet); } } // Start listening to wave events and channel events. wave.addListener(liveBinder); // This binder only starts getting events once open() has been called, since // that is what sets this binder as a mux listener. Since wavelet-to-channel // binding occurs through event callbacks, this listener setting must occur // before trying to bind localWavelets. mux.open(liveBinder, filter, remoteWavelets); for (ObservableWaveletData local : localWavelets) { mux.createOperationChannel(local.getWaveletId(), local.getCreator()); } }