import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import java.io.IOException;
+import java.util.ArrayList;
import java.util.HashMap;
+import java.util.List;
import java.util.Map;
public class JsonGroupStore {
@JsonDeserialize(using = JsonGroupStore.GroupsDeserializer.class)
private Map<String, GroupInfo> groups = new HashMap<>();
- private static final ObjectMapper jsonProcessot = new ObjectMapper();
+ public static List<GroupInfo> groupsWithLegacyAvatarId = new ArrayList<>();
+
+ private static final ObjectMapper jsonProcessor = new ObjectMapper();
void updateGroup(GroupInfo group) {
groups.put(Base64.encodeBytes(group.groupId), group);
}
- GroupInfo getGroup(byte[] groupId) throws GroupNotFoundException {
+ GroupInfo getGroup(byte[] groupId) {
GroupInfo g = groups.get(Base64.encodeBytes(groupId));
- if (g == null) {
- throw new GroupNotFoundException(groupId);
- }
return g;
}
+ List<GroupInfo> getGroups() {
+ return new ArrayList<>(groups.values());
+ }
+
public static class MapToListSerializer extends JsonSerializer<Map<?, ?>> {
@Override
public void serialize(final Map<?, ?> value, final JsonGenerator jgen, final SerializerProvider provider) throws IOException {
Map<String, GroupInfo> groups = new HashMap<>();
JsonNode node = jsonParser.getCodec().readTree(jsonParser);
for (JsonNode n : node) {
- GroupInfo g = jsonProcessot.treeToValue(n, GroupInfo.class);
+ GroupInfo g = jsonProcessor.treeToValue(n, GroupInfo.class);
+ // Check if a legacy avatarId exists
+ if (g.getAvatarId() != 0) {
+ groupsWithLegacyAvatarId.add(g);
+ }
groups.put(Base64.encodeBytes(g.groupId), g);
}