[kune-commits] r1637 - in trunk/src: main/java/cc/kune/gspace/client main/java/cc/kune/wave/server test/java/cc/kune/wave/server
Vicente J. Ruiz Jurado
vjrj_ at ourproject.org
Wed Dec 7 13:18:53 CET 2011
Author: vjrj_
Date: 2011-12-07 13:18:53 +0100 (Wed, 07 Dec 2011)
New Revision: 1637
Modified:
trunk/src/main/java/cc/kune/gspace/client/GSpaceArmorImpl.java
trunk/src/main/java/cc/kune/wave/server/KuneWaveServiceDefault.java
trunk/src/test/java/cc/kune/wave/server/KuneWaveServiceDefaultTest.java
Log:
CLOSED - # 177: List posts don't add participants correctly
http://kune.ourproject.org/issues/ticket/177
Modified: trunk/src/main/java/cc/kune/gspace/client/GSpaceArmorImpl.java
===================================================================
--- trunk/src/main/java/cc/kune/gspace/client/GSpaceArmorImpl.java 2011-12-06 19:55:44 UTC (rev 1636)
+++ trunk/src/main/java/cc/kune/gspace/client/GSpaceArmorImpl.java 2011-12-07 12:18:53 UTC (rev 1637)
@@ -127,7 +127,8 @@
@Override
public void clearBackImage() {
- DOM.setStyleAttribute(mainpanel.getElement(), CSS.A.BACKGROUND, "transparent");
+ final String bodyProp = "#FFFFFF";
+ DOM.setStyleAttribute(groupSpaceWrapper.getElement(), CSS.A.BACKGROUND, bodyProp);
}
@Override
Modified: trunk/src/main/java/cc/kune/wave/server/KuneWaveServiceDefault.java
===================================================================
--- trunk/src/main/java/cc/kune/wave/server/KuneWaveServiceDefault.java 2011-12-06 19:55:44 UTC (rev 1636)
+++ trunk/src/main/java/cc/kune/wave/server/KuneWaveServiceDefault.java 2011-12-07 12:18:53 UTC (rev 1637)
@@ -20,6 +20,7 @@
package cc.kune.wave.server;
import java.net.URL;
+import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
@@ -27,6 +28,7 @@
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;
+import java.util.TreeSet;
import javax.annotation.Nonnull;
@@ -70,6 +72,7 @@
import com.google.wave.api.OperationQueue;
import com.google.wave.api.OperationRequest;
import com.google.wave.api.OperationRequest.Parameter;
+import com.google.wave.api.Participants;
import com.google.wave.api.ProtocolVersion;
import com.google.wave.api.Range;
import com.google.wave.api.Wavelet;
@@ -186,27 +189,22 @@
public void addParticipants(final WaveRef waveName, final String author, final String userWhoAdds,
final String... newLocalParticipants) {
final Wavelet wavelet = fetchWave(waveName, author);
- final OperationQueue opQueue = new OperationQueue();
-
- for (final String newLocalParticipant : newLocalParticipants) {
- final String newPartWithDomain = participantUtils.of(newLocalParticipant).toString();
- boolean mustAdd = true;
- for (final String current : wavelet.getParticipants()) {
- if (current.equals(newPartWithDomain)) {
- // Current user is a participant already (issue #73)
- mustAdd = false;
- break;
- }
- }
- if (mustAdd) {
+ final Participants currentParticipants = wavelet.getParticipants();
+ // Removing duplicates
+ for (final String participant : toSet(newLocalParticipants)) {
+ final String newPartWithDomain = participantUtils.of(participant).toString();
+ if (!currentParticipants.contains(newPartWithDomain)) {
+ // FIXME This is very costly. Seems like only one participant per
+ // opQueue is added (try to
+ // fix this in WAVE)
+ final OperationQueue opQueue = new OperationQueue();
+ LOG.debug("Adding as participant: " + newPartWithDomain);
opQueue.addParticipantToWavelet(wavelet, newPartWithDomain);
+ final String whoAdd = wavelet.getParticipants().contains(participantUtils.of(userWhoAdds)) ? userWhoAdds
+ : author;
+ doOperation(whoAdd, opQueue, "add participant");
}
}
- if (opQueue.getPendingOperations().size() > 0) {
- final String whoAdd = wavelet.getParticipants().contains(participantUtils.of(userWhoAdds)) ? userWhoAdds
- : author;
- doOperation(whoAdd, opQueue, "add participant");
- }
}
@Override
@@ -307,38 +305,24 @@
return createWave(title, message, NO_WAVE_TO_COPY, gadgetUrl, participantsArray);
}
- // public void appendGadget(final WaveRef waveName, URL gadgetUrl, final
- // String author, boolean toRoot) {
- // final Wavelet wavelet = fetchWave(waveName, author);
- // final OperationQueue opQueue = new OperationQueue();
- // opQueue.
- // final Gadget gadget = new Gadget(gadgetUrl.toString());
- // Blip blip = toRoot? wavelet.getRootBlip():
- // opQueue.appendBlipToWavelet(wavelet, author);
- // blip.append(gadget);
- // }
-
@Override
- public void delParticipants(final WaveRef waveName, final String whoDel, final String... participants) {
+ public void delParticipants(final WaveRef waveName, final String whoDel,
+ final String... participantsToDel) {
final Wavelet wavelet = fetchWave(waveName, whoDel);
- final OperationQueue opQueue = new OperationQueue();
-
- for (final String participant : participants) {
+ final Participants currentParticipants = wavelet.getParticipants();
+ final Set<String> set = toSet(participantsToDel);
+ LOG.debug("Removing participants: " + set.toString());
+ for (final String participant : set) {
+ // FIXME Seems like only one participant per opQueue is added (try to fix
+ // this in WAVE)
final String partWithDomain = participantUtils.of(participant).toString();
- boolean mustDel = false;
- for (final String current : wavelet.getParticipants()) {
- if (current.equals(partWithDomain)) {
- mustDel = true;
- break;
- }
- }
- if (mustDel) {
+ if (currentParticipants.contains(partWithDomain)) {
+ final OperationQueue opQueue = new OperationQueue();
+ LOG.debug("Removing as participant: " + partWithDomain);
opQueue.removeParticipantFromWavelet(wavelet, partWithDomain);
+ doOperation(whoDel, opQueue, "del participant");
}
}
- if (opQueue.getPendingOperations().size() > 0) {
- doOperation(whoDel, opQueue, "add participant");
- }
}
private void doOperation(final String author, final OperationQueue opQueue, final String logComment) {
@@ -374,6 +358,17 @@
OperationUtil.submitDeltas(context, waveletProvider, listener);
}
+ // public void appendGadget(final WaveRef waveName, URL gadgetUrl, final
+ // String author, boolean toRoot) {
+ // final Wavelet wavelet = fetchWave(waveName, author);
+ // final OperationQueue opQueue = new OperationQueue();
+ // opQueue.
+ // final Gadget gadget = new Gadget(gadgetUrl.toString());
+ // Blip blip = toRoot? wavelet.getRootBlip():
+ // opQueue.appendBlipToWavelet(wavelet, author);
+ // blip.append(gadget);
+ // }
+
@Override
public Wavelet fetchWave(final WaveId waveId, final WaveletId waveletId, final String author) {
final OperationQueue opQueue = new OperationQueue();
@@ -389,6 +384,7 @@
onFailure(context.getResponse(reqId).getErrorMessage());
} else {
// Duplicate code from WaveService
+ assert response != null;
final WaveletData waveletData = (WaveletData) response.getData().get(ParamsProperty.WAVELET_DATA);
final Map<String, Blip> blips = new HashMap<String, Blip>();
final Map<String, BlipThread> threads = new HashMap<String, BlipThread>();
@@ -453,4 +449,10 @@
doOperation(author, opQueue, "set title");
}
+ private Set<String> toSet(final String[] array) {
+ final Set<String> set = new TreeSet<String>(Collections.reverseOrder());
+ set.addAll(Arrays.asList(array));
+ return set;
+ }
+
}
Modified: trunk/src/test/java/cc/kune/wave/server/KuneWaveServiceDefaultTest.java
===================================================================
--- trunk/src/test/java/cc/kune/wave/server/KuneWaveServiceDefaultTest.java 2011-12-06 19:55:44 UTC (rev 1636)
+++ trunk/src/test/java/cc/kune/wave/server/KuneWaveServiceDefaultTest.java 2011-12-07 12:18:53 UTC (rev 1637)
@@ -26,6 +26,10 @@
import java.io.IOException;
import java.net.URL;
+import java.util.Arrays;
+import java.util.Iterator;
+import java.util.Set;
+import java.util.TreeSet;
import org.junit.Before;
import org.junit.Test;
@@ -42,6 +46,7 @@
private static final String MESSAGE = "testing";
private static final String NEW_PARTICIPANT = "newparti";
+ private static final String NEW_PARTICIPANT2 = "newparti2";
private static final String RICHTEXT_MESSAGE = "<b>" + MESSAGE + "</b>";
private static final String TEST_GADGET = "http://wave-api.appspot.com/public/gadgets/areyouin/gadget.xml";
private static final String TITLE = "title";
@@ -52,26 +57,51 @@
ParticipantUtils participantUtils;
@Test
+ public void addAndDelParticipantTwice() throws IOException {
+ doLogin();
+ final WaveRef waveletName = createTestWave();
+ assertNotNull(waveletName);
+ manager.addParticipants(waveletName, getSiteAdminShortName(), getSiteAdminShortName(),
+ NEW_PARTICIPANT);
+ manager.addParticipants(waveletName, getSiteAdminShortName(), getSiteAdminShortName(),
+ NEW_PARTICIPANT, NEW_PARTICIPANT);
+ manager.addParticipants(waveletName, getSiteAdminShortName(), getSiteAdminShortName(),
+ NEW_PARTICIPANT, NEW_PARTICIPANT, NEW_PARTICIPANT);
+ final Wavelet fetchWavelet = manager.fetchWave(waveletName, getSiteAdminShortName());
+ assertNotNull(fetchWavelet);
+ assertEquals(2, fetchWavelet.getParticipants().size());
+ assertTrue(manager.isParticipant(fetchWavelet, NEW_PARTICIPANT));
+ assertTrue(manager.isParticipant(fetchWavelet, getSiteAdminShortName()));
+ // Del all
+ manager.delParticipants(waveletName, getSiteAdminShortName(), NEW_PARTICIPANT, NEW_PARTICIPANT,
+ getSiteAdminShortName(), getSiteAdminShortName());
+ }
+
+ @Test
public void addAndRemoveParticipant() throws IOException {
doLogin();
final String whoDels = getSiteAdminShortName();
final WaveRef waveletName = createTestWave();
assertNotNull(waveletName);
- manager.addParticipants(waveletName, getSiteAdminShortName(), whoDels, NEW_PARTICIPANT);
+ manager.addParticipants(waveletName, getSiteAdminShortName(), whoDels, NEW_PARTICIPANT,
+ NEW_PARTICIPANT2);
final Wavelet fetchWavelet = manager.fetchWave(waveletName, getSiteAdminShortName());
assertNotNull(fetchWavelet);
- assertEquals(2, fetchWavelet.getParticipants().size());
+ assertEquals(3, fetchWavelet.getParticipants().size());
assertTrue(manager.isParticipant(fetchWavelet, NEW_PARTICIPANT));
+ assertTrue(manager.isParticipant(fetchWavelet, NEW_PARTICIPANT2));
assertTrue(manager.isParticipant(fetchWavelet, getSiteAdminShortName()));
- manager.delParticipants(waveletName, whoDels, NEW_PARTICIPANT);
+ manager.delParticipants(waveletName, whoDels, NEW_PARTICIPANT, NEW_PARTICIPANT2);
final Wavelet fetchDelWavelet = manager.fetchWave(waveletName, getSiteAdminShortName());
assertNotNull(fetchDelWavelet);
assertEquals(1, fetchDelWavelet.getParticipants().size());
assertTrue(manager.isParticipant(fetchDelWavelet, getSiteAdminShortName()));
assertFalse(manager.isParticipant(fetchDelWavelet, NEW_PARTICIPANT));
- manager.addParticipants(waveletName, getSiteAdminShortName(), whoDels, NEW_PARTICIPANT);
- // Del all
- manager.delParticipants(waveletName, whoDels, getSiteAdminShortName(), NEW_PARTICIPANT);
+ assertFalse(manager.isParticipant(fetchDelWavelet, NEW_PARTICIPANT2));
+ manager.addParticipants(waveletName, getSiteAdminShortName(), getSiteAdminShortName(),
+ NEW_PARTICIPANT);
+ // Del all (the last, the whoDels...)
+ manager.delParticipants(waveletName, whoDels, NEW_PARTICIPANT, getSiteAdminShortName());
}
@Test
@@ -82,6 +112,17 @@
manager.addGadget(waveletName, getSiteAdminShortName(), new URL(TEST_GADGET));
}
+ @Test
+ public void addingToSetMaintainsOrder() throws IOException {
+ final String[] array = new String[] { NEW_PARTICIPANT, NEW_PARTICIPANT, NEW_PARTICIPANT2,
+ NEW_PARTICIPANT2 };
+ final Set<String> set = new TreeSet<String>(Arrays.asList(array));
+ assertTrue(set.size() == 2);
+ final Iterator<String> iterator = set.iterator();
+ assertTrue(iterator.next().equals(NEW_PARTICIPANT));
+ assertTrue(iterator.next().equals(NEW_PARTICIPANT2));
+ }
+
private void addParticipant(final String whoAdds) throws IOException {
doLogin();
final WaveRef waveletName = createTestWave();
@@ -95,24 +136,6 @@
}
@Test
- public void addParticipantTwice() throws IOException {
- doLogin();
- final WaveRef waveletName = createTestWave();
- assertNotNull(waveletName);
- manager.addParticipants(waveletName, getSiteAdminShortName(), getSiteAdminShortName(),
- NEW_PARTICIPANT);
- manager.addParticipants(waveletName, getSiteAdminShortName(), getSiteAdminShortName(),
- NEW_PARTICIPANT, NEW_PARTICIPANT);
- manager.addParticipants(waveletName, getSiteAdminShortName(), getSiteAdminShortName(),
- NEW_PARTICIPANT, NEW_PARTICIPANT, NEW_PARTICIPANT);
- final Wavelet fetchWavelet = manager.fetchWave(waveletName, getSiteAdminShortName());
- assertNotNull(fetchWavelet);
- assertEquals(2, fetchWavelet.getParticipants().size());
- assertTrue(manager.isParticipant(fetchWavelet, NEW_PARTICIPANT));
- assertTrue(manager.isParticipant(fetchWavelet, getSiteAdminShortName()));
- }
-
- @Test
public void authorAddParticipant() throws DefaultException, IOException {
final String whoAdds = getSiteAdminShortName();
addParticipant(whoAdds);
More information about the kune-commits
mailing list