Skip to content
This repository has been archived by the owner on Apr 17, 2023. It is now read-only.

AGPUSH-419 #31

Merged
merged 5 commits into from Nov 6, 2013
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
14 changes: 7 additions & 7 deletions src/main/java/org/jboss/aerogear/unifiedpush/SenderClient.java
Expand Up @@ -61,11 +61,11 @@ protected String buildUrl() {

@Override
public void send(UnifiedMessage unifiedMessage, MessageResponseCallback callback) {
final Map<String, Object> selectedPayloadObject = prepareMessage(unifiedMessage);
final Map<String, Object> payloadObject = prepareMessage(unifiedMessage);
// transform to JSONString:
String payload = transformJSON(selectedPayloadObject);
String jsonString = toJSONString(payloadObject);
// fire!
submitPayload(buildUrl(), payload, unifiedMessage.getPushApplicationId(), unifiedMessage.getMasterSecret(), callback);
submitPayload(buildUrl(), jsonString, unifiedMessage.getPushApplicationId(), unifiedMessage.getMasterSecret(), callback);
}

@Override
Expand All @@ -87,8 +87,8 @@ private Map<String, Object> prepareMessage(UnifiedMessage unifiedMessage) {
payloadObject.put("alias", unifiedMessage.getAliases());
}

if (!isEmpty(unifiedMessage.getCategory())) {
payloadObject.put("category", unifiedMessage.getCategory());
if (!isEmpty(unifiedMessage.getCategories())) {
payloadObject.put("categories", unifiedMessage.getCategories());
}

if (!isEmpty(unifiedMessage.getDeviceType())) {
Expand Down Expand Up @@ -209,9 +209,9 @@ private boolean isRedirect(int statusCode) {
}

/**
* A simple utility to tranform an {@link Object} into a json {@link String}
* A simple utility to transforms an {@link Object} into a json {@link String}
*/
private String transformJSON(Object value) {
private String toJSONString(Object value) {
ObjectMapper om = new ObjectMapper();
String stringPayload = null;
try {
Expand Down
Expand Up @@ -17,10 +17,7 @@

package org.jboss.aerogear.unifiedpush.message;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.*;

/**
* A UnifiedMessage represents a message in the format expected from the Unified Push Server.
Expand All @@ -39,6 +36,7 @@
* .sound("default")
* .variants(Arrays.asList("c3f0a94f-48de-4b77-a08e-68114460857e")) //e.g. HR_Premium
* .aliases(Arrays.asList("mike", "john"))
* .categories(Arrays.asList("sport","world cup"))
* .deviceType(Arrays.asList("iPad","AndroidTablet"))
* .build();
* }
Expand All @@ -56,7 +54,7 @@ public class UnifiedMessage {

private Map<String, Object> attributes;

private String category;
private Set<String> categories;

private List<String> deviceType;

Expand All @@ -71,7 +69,7 @@ public static class Builder {

private String masterSecret;

private String category;
private Set<String> categories = new HashSet<String>();

private String simplePush;

Expand Down Expand Up @@ -133,13 +131,24 @@ public Builder variants(List<String> variants) {
}

/**
* A category is a semantical tag.
* A list of categories. A Category is a semantical tag.
*
* @param category a semantical tag
* @param set of categories
* @return the current {@link Builder} instance
*/
public Builder category(String category) {
this.category = category;
public Builder categories(Set categories) {
this.categories = categories;
return this;
}

/**
* A list of categories. A Category is a semantical tag.
*
* @param a list of categories
* @return the current {@link Builder} instance
*/
public Builder categories(String... categories) {
this.categories = new HashSet<String>(Arrays.asList(categories));
return this;
}

Expand Down Expand Up @@ -258,7 +267,7 @@ private UnifiedMessage(Builder builder) {
this.attributes = builder.attributes;
this.aliases = builder.aliases;
this.variants = builder.variants;
this.category = builder.category;
this.categories = builder.categories;
this.deviceType = builder.deviceType;
this.pushApplicationId = builder.pushApplicationId;
this.masterSecret = builder.masterSecret;
Expand Down Expand Up @@ -313,12 +322,12 @@ public Map<String, Object> getAttributes() {
}

/**
* Get a category, a semantical tag.
* Get a category list, a category is a semantical tag.
*
* @return the category
* @return the category list
*/
public String getCategory() {
return category;
public Set getCategories() {
return categories;
}

/**
Expand Down
Expand Up @@ -19,6 +19,8 @@
import org.junit.Test;

import java.util.ArrayList;
import java.util.HashSet;
import java.util.Set;
import java.util.List;

import static org.junit.Assert.assertEquals;
Expand Down Expand Up @@ -73,6 +75,14 @@ public void simpleSelectiveMessageWithDevicesTest() {
assertEquals(1, unifiedMessage.getDeviceType().size());
}

@Test
public void simpleSelectiveMessageWithCategoriesTest() {
UnifiedMessage unifiedMessage = new UnifiedMessage.Builder()
.categories("sports","world cup")
.build();
assertEquals(2, unifiedMessage.getCategories().size());
}

@Test
public void simplePushVersionMessageTest() {
UnifiedMessage unifiedMessage = new UnifiedMessage.Builder()
Expand Down