Author: scottbw
Date: Fri Feb 14 15:08:03 2014
New Revision: 1568334
URL: http://svn.apache.org/r1568334
Log:
Applied fixes to SPI implementations to make sure they pass all the unit tests;
this mostly involved adding null and empty string guards
Modified:
wookie/trunk/wookie-services/wookie-redis/src/main/java/org/apache/wookie/services/redis/RedisSharedContextService.java
wookie/trunk/wookie-services/wookie-spi/src/main/java/org/apache/wookie/services/impl/DefaultPreferencesService.java
wookie/trunk/wookie-services/wookie-spi/src/main/java/org/apache/wookie/services/impl/DefaultSharedContextService.java
Modified:
wookie/trunk/wookie-services/wookie-redis/src/main/java/org/apache/wookie/services/redis/RedisSharedContextService.java
URL:
http://svn.apache.org/viewvc/wookie/trunk/wookie-services/wookie-redis/src/main/java/org/apache/wookie/services/redis/RedisSharedContextService.java?rev=1568334&r1=1568333&r2=1568334&view=diff
==============================================================================
---
wookie/trunk/wookie-services/wookie-redis/src/main/java/org/apache/wookie/services/redis/RedisSharedContextService.java
(original)
+++
wookie/trunk/wookie-services/wookie-redis/src/main/java/org/apache/wookie/services/redis/RedisSharedContextService.java
Fri Feb 14 15:08:03 2014
@@ -331,10 +331,14 @@ public class RedisSharedContextService i
String key = getParticipantKey(apiKey, widgetId, contextId,
participant.getParticipantId());
//
- // If there is no existing tuple, add the key to the list of
keys for this token
+ // If there is no existing tuple, add the key to the list of
keys for this token, otherwise
+ // we return false as there is no overwriting of participants
//
if (this.getParticipant(apiKey, widgetId, contextId,
participant.getParticipantId()) == null){
jedis.lpush(this.getContextKey(apiKey, widgetId,
contextId), key);
+ } else {
+ pool.returnResource(jedis);
+ return false;
}
//
Modified:
wookie/trunk/wookie-services/wookie-spi/src/main/java/org/apache/wookie/services/impl/DefaultPreferencesService.java
URL:
http://svn.apache.org/viewvc/wookie/trunk/wookie-services/wookie-spi/src/main/java/org/apache/wookie/services/impl/DefaultPreferencesService.java?rev=1568334&r1=1568333&r2=1568334&view=diff
==============================================================================
---
wookie/trunk/wookie-services/wookie-spi/src/main/java/org/apache/wookie/services/impl/DefaultPreferencesService.java
(original)
+++
wookie/trunk/wookie-services/wookie-spi/src/main/java/org/apache/wookie/services/impl/DefaultPreferencesService.java
Fri Feb 14 15:08:03 2014
@@ -51,12 +51,14 @@ public class DefaultPreferencesService i
@Override
public void setPreference(String token, IPreference preference) {
- HashMap<String, IPreference> widgetpreferences =
preferences.get(token);
- if (widgetpreferences == null){
- widgetpreferences = new HashMap<String, IPreference>();
- this.preferences.put(token, widgetpreferences);
+ if (preference != null){
+ HashMap<String, IPreference> widgetpreferences =
preferences.get(token);
+ if (widgetpreferences == null){
+ widgetpreferences = new HashMap<String,
IPreference>();
+ this.preferences.put(token, widgetpreferences);
+ }
+ widgetpreferences.put(preference.getName(), preference);
}
- widgetpreferences.put(preference.getName(), preference);
}
@Override
@@ -77,11 +79,18 @@ public class DefaultPreferencesService i
@Override
public void setPreferences(String token, Collection<IPreference>
preferences) {
- HashMap<String, IPreference> widgetpreferences = new
HashMap<String, IPreference>();
- for (IPreference preference: preferences){
- widgetpreferences.put(preference.getName(), preference);
- }
- this.preferences.put(token, widgetpreferences);
+ //
+ // Setting to null is the same as clearing the preferences
+ //
+ if (preferences == null){
+ this.removePreferences(token);
+ } else {
+ HashMap<String, IPreference> widgetpreferences = new
HashMap<String, IPreference>();
+ for (IPreference preference: preferences){
+ widgetpreferences.put(preference.getName(),
preference);
+ }
+ this.preferences.put(token, widgetpreferences);
+ }
}
@Override
Modified:
wookie/trunk/wookie-services/wookie-spi/src/main/java/org/apache/wookie/services/impl/DefaultSharedContextService.java
URL:
http://svn.apache.org/viewvc/wookie/trunk/wookie-services/wookie-spi/src/main/java/org/apache/wookie/services/impl/DefaultSharedContextService.java?rev=1568334&r1=1568333&r2=1568334&view=diff
==============================================================================
---
wookie/trunk/wookie-services/wookie-spi/src/main/java/org/apache/wookie/services/impl/DefaultSharedContextService.java
(original)
+++
wookie/trunk/wookie-services/wookie-spi/src/main/java/org/apache/wookie/services/impl/DefaultSharedContextService.java
Fri Feb 14 15:08:03 2014
@@ -127,10 +127,25 @@ public class DefaultSharedContextService
String contextId, String key, String value, boolean
append) {
HashMap<String, ISharedData> sharedData =
getSharedContextFromTree(apiKey,contextId, widgetId).getSharedData();
boolean existing = true;
+
+
+ //
+ // If the value is null, and we're not set to append, this is
+ // actually the same as "remove"
+ //
+ if (value == null){
+ return this.removeSharedData(apiKey, widgetId,
contextId, key);
+ }
+
if (!sharedData.containsKey(key)) existing = false;
+
+ //
+ // if it already exists, and the instruction is to append,
prepend the
+ // existing value to the new value to set
+ //
if (append && existing) value = sharedData.get(key).getDvalue()
+ value;
sharedData.put(key, new DefaultSharedDataImpl(key,value));
- return existing;
+ return true;
}
@Override
@@ -154,7 +169,16 @@ public class DefaultSharedContextService
String role) {
HashMap<String, IParticipant> participants =
getSharedContextFromTree(apiKey,contextId, widgetId).getParticipants();
+ //
+ // Already exists
+ //
if (participants.containsKey(participantId)) return false;
+
+ //
+ // No id
+ //
+ if (participantId == null || participantId.trim().length() ==
0) return false;
+
participants.put(participantId, new
DefaultParticipantImpl(participantId,participantDisplayName,
participantThumbnailUrl, role));
return true;
}
@@ -162,8 +186,10 @@ public class DefaultSharedContextService
@Override
public void removeParticipant(String apiKey, String widgetId,
String contextId, IParticipant participant) {
- HashMap<String, IParticipant> participants =
getSharedContextFromTree(apiKey,contextId, widgetId).getParticipants();
- participants.remove(participant.getParticipantId());
+ if (participant != null){
+ HashMap<String, IParticipant> participants =
getSharedContextFromTree(apiKey,contextId, widgetId).getParticipants();
+ participants.remove(participant.getParticipantId());
+ }
}
@Override