Skip to content

Commit e236f1d

Browse files
authored
v0.5 - Refactoring Experience (#100)
* Updating to 0.4 * Updatng to v0.5 * Fixing parsing bug * Updating type safety * Cleaning up based upon comments * Updating typings * Updating for v0.5
1 parent 5badc89 commit e236f1d

File tree

66 files changed

+3838
-2181
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

66 files changed

+3838
-2181
lines changed

NotificationHubs/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
<modelVersion>4.0.0</modelVersion>
44
<groupId>com.windowsazure</groupId>
55
<artifactId>Notification-Hubs-java-sdk</artifactId>
6-
<version>0.4.2</version>
6+
<version>0.5.0</version>
77
<name>Windows Azure Notification Hubs Java SDK</name>
88
<url>https://github.com/Azure/azure-notificationhubs-java-backend</url>
99
<description>Azure Notification Hubs Java SDK for interacting with the data and management plane operations.</description>

NotificationHubs/src/com/windowsazure/messaging/AdmCredential.java

Lines changed: 34 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -8,41 +8,60 @@
88
import java.util.ArrayList;
99
import java.util.List;
1010

11+
/**
12+
* This class represents Amazon PNS credentials.
13+
*/
1114
public final class AdmCredential extends PnsCredential {
1215
private String clientId;
1316
private String clientSecret;
1417

18+
/**
19+
* Creates a new instance of the AdmCredential class.
20+
*/
1521
public AdmCredential() {
16-
this(null, null);
22+
super();
1723
}
1824

25+
/**
26+
* Creates a new instance of the AdmCredential class.
27+
* @param clientId The Amazon client ID.
28+
* @param clientSecret The Amazon client secret.
29+
*/
1930
public AdmCredential(String clientId, String clientSecret) {
2031
super();
2132
this.setClientId(clientId);
2233
this.setClientSecret(clientSecret);
2334
}
2435

25-
public String getClientId() {
26-
return clientId;
27-
}
36+
/**
37+
* Gets the Amazon client ID.
38+
* @return The Amazon client ID.
39+
*/
40+
public String getClientId() { return clientId; }
2841

29-
public void setClientId(String clientId) {
30-
this.clientId = clientId;
31-
}
42+
/**
43+
* Gets the Amazon client ID.
44+
* @param value THe Amazon client ID to set.
45+
*/
46+
public void setClientId(String value) { clientId = value; }
3247

33-
public String getClientSecret() {
34-
return clientSecret;
35-
}
48+
/**
49+
* Gets the Amazon client secret.
50+
* @return The Amazon client secret.
51+
*/
52+
public String getClientSecret() { return clientSecret; }
3653

37-
public void setClientSecret(String clientSecret) {
38-
this.clientSecret = clientSecret;
39-
}
54+
/**
55+
* Sets the Amazon client secret.
56+
* @param value The Amazon client secret to set.
57+
*/
58+
public void setClientSecret(String value) { clientSecret = value; }
4059

4160
@Override
4261
public List<SimpleEntry<String, String>> getProperties() {
4362
ArrayList<SimpleEntry<String, String>> result = new ArrayList<>();
44-
result.add(new SimpleEntry<>("ClientId", getClientId()));
45-
result.add(new SimpleEntry<>("ClientSecret", getClientSecret()));
63+
result.add(new SimpleEntry<>("ClientId", clientId));
64+
result.add(new SimpleEntry<>("ClientSecret", clientSecret));
4665
return result;
4766
}
4867

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
package com.windowsazure.messaging;
2+
3+
/**
4+
* This class represents an Amazon Device
5+
*/
6+
public class AdmInstallation extends Installation {
7+
8+
/**
9+
* Creates a new instance of the AdmInstallation class.
10+
*
11+
* @param installationId The ID for the installation.
12+
*/
13+
public AdmInstallation(String installationId) {
14+
super(installationId, NotificationPlatform.Adm, null, null);
15+
}
16+
17+
/**
18+
* Creates a new instance of the AdmInstallation class.
19+
*
20+
* @param installationId The ID for the installation.
21+
* @param tags The tags for the installation.
22+
*/
23+
public AdmInstallation(String installationId, String... tags) {
24+
super(installationId, NotificationPlatform.Adm, null, tags);
25+
}
26+
27+
/**
28+
* Creates a new instance of the AdmInstallation class.
29+
*
30+
* @param installationId The ID for the installation.
31+
*/
32+
public AdmInstallation(String installationId, String pushChannel) {
33+
super(installationId, NotificationPlatform.Adm, pushChannel, (String[]) null);
34+
}
35+
36+
/**
37+
* Creates a new instance of the AdmInstallation class.
38+
* @param installationId The ID for the installation.
39+
* @param pushChannel The device specific push channel for the installation.
40+
* @param tags The tags for the installation.
41+
*/
42+
public AdmInstallation(String installationId, String pushChannel, String... tags) {
43+
super(installationId, NotificationPlatform.Adm, pushChannel, tags);
44+
}
45+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
package com.windowsazure.messaging;
2+
3+
import org.apache.http.entity.ContentType;
4+
5+
/**
6+
* This class represents a notification to the Amazon PNS.
7+
*/
8+
public class AdmNotification extends Notification {
9+
10+
/**
11+
* Creates a new instance of the AdmNotification class.
12+
* @param body The JSON body for the Amazon PNS.
13+
*/
14+
public AdmNotification(String body) {
15+
this.body = body;
16+
this.contentType = ContentType.APPLICATION_JSON;
17+
18+
this.headers.put("ServiceBusNotification-Format", "adm");
19+
}
20+
}

NotificationHubs/src/com/windowsazure/messaging/AdmRegistration.java

Lines changed: 40 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -4,66 +4,79 @@
44

55
package com.windowsazure.messaging;
66

7+
import java.util.Objects;
8+
9+
/**
10+
* This class represents an Amazon device registration.
11+
*/
712
public class AdmRegistration extends Registration {
813
private static final String ADM_NATIVE_REGISTRATION1 = "<?xml version=\"1.0\" encoding=\"utf-8\"?><entry xmlns=\"http://www.w3.org/2005/Atom\"><content type=\"application/xml\"><AdmRegistrationDescription xmlns:i=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns=\"http://schemas.microsoft.com/netservices/2010/10/servicebus/connect\">";
914
private static final String ADM_NATIVE_REGISTRATION2 = "<AdmRegistrationId>";
1015
private static final String ADM_NATIVE_REGISTRATION3 = "</AdmRegistrationId></AdmRegistrationDescription></content></entry>";
1116

1217
protected String admRegistrationId;
1318

19+
/**
20+
* Creates a new instance of the AdmRegistration class.
21+
*/
1422
public AdmRegistration() {
1523
super();
1624
}
1725

26+
/**
27+
* Creates a new instance of the AdmRegistration class.
28+
* @param registrationId The Azure Notification Hubs registration ID for the device.
29+
* @param admRegistrationId The Amazon device registration ID.
30+
*/
1831
public AdmRegistration(String registrationId, String admRegistrationId) {
1932
super(registrationId);
2033
this.admRegistrationId = admRegistrationId;
2134
}
2235

36+
/**
37+
* Creates a new instance of the AdmRegistration class.
38+
* @param admRegistrationId The Amazon device registration ID.
39+
*/
2340
public AdmRegistration(String admRegistrationId) {
2441
super();
2542
this.admRegistrationId = admRegistrationId;
2643
}
2744

45+
/**
46+
* Gets the Amazon registration ID for the device.
47+
* @return The Amazon registration ID for the device.
48+
*/
2849
public String getAdmRegistrationId() {
2950
return admRegistrationId;
3051
}
3152

32-
public void setAdmRegistrationId(String admRegistrationId) {
33-
this.admRegistrationId = admRegistrationId;
53+
/**
54+
* Sets the Amazon registration ID for the device.
55+
* @param value The Amazon registration ID for the device to set.
56+
*/
57+
public void setAdmRegistrationId(String value) {
58+
admRegistrationId = value;
3459
}
3560

61+
/**
62+
* Gets the PNS handle for getting devices by channel.
63+
* @return The PNS handle for getting devices by channel.
64+
*/
3665
@Override
37-
public String getPnsHandle() {
38-
return admRegistrationId;
39-
}
66+
public String getPnsHandle() { return admRegistrationId; }
4067

4168
@Override
42-
public int hashCode() {
43-
final int prime = 31;
44-
int result = super.hashCode();
45-
result = prime
46-
* result
47-
+ ((admRegistrationId == null) ? 0 : admRegistrationId
48-
.hashCode());
49-
return result;
69+
public boolean equals(Object o) {
70+
if (this == o) return true;
71+
if (o == null || getClass() != o.getClass()) return false;
72+
if (!super.equals(o)) return false;
73+
AdmRegistration that = (AdmRegistration) o;
74+
return Objects.equals(getAdmRegistrationId(), that.getAdmRegistrationId());
5075
}
5176

5277
@Override
53-
public boolean equals(Object obj) {
54-
if (this == obj)
55-
return true;
56-
if (!super.equals(obj))
57-
return false;
58-
if (getClass() != obj.getClass())
59-
return false;
60-
AdmRegistration other = (AdmRegistration) obj;
61-
if (admRegistrationId == null) {
62-
if (other.admRegistrationId != null)
63-
return false;
64-
} else if (!admRegistrationId.equals(other.admRegistrationId))
65-
return false;
66-
return true;
78+
public int hashCode() {
79+
return Objects.hash(super.hashCode(), getAdmRegistrationId());
6780
}
6881

6982
@Override

NotificationHubs/src/com/windowsazure/messaging/AdmTemplateRegistration.java

Lines changed: 36 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,36 +4,62 @@
44

55
package com.windowsazure.messaging;
66

7-
public class AdmTemplateRegistration extends AdmRegistration {
7+
/**
8+
* This class represents an Amazon device template registration.
9+
*/
10+
public class AdmTemplateRegistration extends AdmRegistration implements TemplateRegistration {
811
private static final String ADM_TEMPLATE_REGISTRATION1 = "<?xml version=\"1.0\" encoding=\"utf-8\"?><entry xmlns=\"http://www.w3.org/2005/Atom\"><content type=\"application/xml\"><AdmTemplateRegistrationDescription xmlns:i=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns=\"http://schemas.microsoft.com/netservices/2010/10/servicebus/connect\">";
912
private static final String ADM_TEMPLATE_REGISTRATION2 = "<AdmRegistrationId>";
1013
private static final String ADM_TEMPLATE_REGISTRATION3 = "</AdmRegistrationId><BodyTemplate><![CDATA[";
1114
private static final String ADM_TEMPLATE_REGISTRATION4 = "]]></BodyTemplate></AdmTemplateRegistrationDescription></content></entry>";
1215

1316
private String bodyTemplate;
1417

18+
/**
19+
* Creates a new instance of the AdmTemplateRegistration class.
20+
*/
1521
public AdmTemplateRegistration() {
1622
super();
1723
}
1824

19-
public AdmTemplateRegistration(String registrationId,
20-
String admRegistrationId, String bodyTemplate) {
25+
/**
26+
* Creates a new instance of the AdmTemplateRegistration class.
27+
* @param registrationId The Azure Notification Hubs registration ID.
28+
* @param admRegistrationId The Amazon device registration ID.
29+
* @param bodyTemplate The template body.
30+
*/
31+
public AdmTemplateRegistration(
32+
String registrationId,
33+
String admRegistrationId,
34+
String bodyTemplate
35+
) {
2136
super(registrationId, admRegistrationId);
2237
this.bodyTemplate = bodyTemplate;
2338
}
2439

40+
/**
41+
* Creates a new instance of the AdmTemplateRegistration class.
42+
* @param admRegistrationId The Amazon device registration ID.
43+
* @param bodyTemplate The template body.
44+
*/
2545
public AdmTemplateRegistration(String admRegistrationId, String bodyTemplate) {
2646
super(admRegistrationId);
2747
this.bodyTemplate = bodyTemplate;
2848
}
2949

30-
public String getBodyTemplate() {
31-
return bodyTemplate;
32-
}
50+
/**
51+
* Gets the registration template body.
52+
* @return The registration template body.
53+
*/
54+
@Override
55+
public String getBodyTemplate() { return bodyTemplate; }
3356

34-
public void setBodyTemplate(String bodyTemplate) {
35-
this.bodyTemplate = bodyTemplate;
36-
}
57+
/**
58+
* Sets the registration template body.
59+
* @param value The registration template body to set.
60+
*/
61+
@Override
62+
public void setBodyTemplate(String value) { this.bodyTemplate = value; }
3763

3864
@Override
3965
public int hashCode() {
@@ -66,7 +92,7 @@ public String getXml() {
6692
return ADM_TEMPLATE_REGISTRATION1 +
6793
getTagsXml() +
6894
ADM_TEMPLATE_REGISTRATION2 +
69-
admRegistrationId +
95+
getAdmRegistrationId() +
7096
ADM_TEMPLATE_REGISTRATION3 +
7197
bodyTemplate +
7298
ADM_TEMPLATE_REGISTRATION4;

0 commit comments

Comments
 (0)