Skip to content

Commit

Permalink
Add New Dtos
Browse files Browse the repository at this point in the history
  • Loading branch information
Jack Thorley authored and EsendexDev committed Dec 24, 2015
1 parent 145549b commit 2f71c26
Show file tree
Hide file tree
Showing 21 changed files with 133 additions and 106 deletions.
6 changes: 3 additions & 3 deletions src/main/java/esendex/sdk/java/http/HttpConnectorImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,9 @@ public HttpResponse connect(URL url,
HttpURLConnection uc = createHttpRequest(url, method, authenticator, data);

return executeHttpRequest(uc);

} catch (IOException ex) {

throw new HttpException("Failed connection to: " + url, ex);
}

Expand All @@ -55,7 +55,7 @@ private HttpResponse executeHttpRequest(HttpURLConnection uc) throws IOException
}

String response = null;
if (HttpURLConnection.HTTP_OK == respCode) {
if (HttpURLConnection.HTTP_OK == respCode || HttpURLConnection.HTTP_CREATED == respCode ) {

response = readHttpResponse(uc);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
package esendex.sdk.java.model.domain.impl;

import esendex.sdk.java.model.types.ContactType;

public class BaseContact {

private String id;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public ContactDto createRequest(ContactRequest c) {
dto.setFirstname(c.getFirstName());
dto.setLastname(c.getLastName());
dto.setQuickname(c.getQuickName());
dto.setMobilenumber(c.getMobileNumber());
dto.setPhoneNumber(c.getMobileNumber());
dto.setAccountReference(c.getAccountReference());

return dto;
Expand All @@ -34,11 +34,7 @@ public ContactCollectionDto createCollection(List<ContactRequest> contacts) {
return new ContactCollectionDto(list);
}

public ContactCollectionDto createCollection(ContactRequest contact) {

List<ContactDto> list = new ArrayList<ContactDto>();
list.add(createRequest(contact));
return new ContactCollectionDto(list);
public ContactDto createContactDto(ContactRequest contact) {
return createRequest(contact);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public ContactResponse createResponse(ContactDto dto) {
resp.setId(dto.getId());
resp.setAccountReference(dto.getAccountReference());
resp.setLastName(dto.getLastname());
resp.setMobileNumber(dto.getMobilenumber());
resp.setMobileNumber(dto.getPhoneNumber());
resp.setQuickName(dto.getQuickname());

return resp;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
package esendex.sdk.java.model.domain.request;

import esendex.sdk.java.model.domain.impl.BaseContact;
import esendex.sdk.java.model.types.ContactType;

/**
* A request object suitable for creating and updating a Contact resource.
Expand All @@ -24,6 +23,8 @@ public ContactRequest(String quickName, String mobileNumber, String accountRefer
setQuickName(quickName);
setMobileNumber(mobileNumber);
setAccountReference(accountReference);
setFirstName("");
setLastName("");
}

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@

package esendex.sdk.java.model.transfer.contact;

import com.thoughtworks.xstream.annotations.XStreamOmitField;
import esendex.sdk.java.model.transfer.Dto;
import esendex.sdk.java.model.types.ContactType;

import java.util.List;

// TODO: Auto-generated Javadoc
/**
* Base class for contact requests and responses. This class directly holds the
* parsed xml data. Subclasses should merely allow selective access.
Expand All @@ -20,6 +17,9 @@ public class ContactDto extends Dto {
private String phonenumber;
private String accountreference;

@XStreamOmitField
private String link;

public ContactDto() {
}

Expand Down Expand Up @@ -55,9 +55,9 @@ public String getQuickname() {

/**
* The telephone number associated with this Contact.
* @return the mobile number
* @return the phone number
*/
public String getMobilenumber() {
public String getPhoneNumber() {
return phonenumber;
}

Expand Down Expand Up @@ -95,12 +95,12 @@ public void setQuickname(String quickname) {
}

/**
* Sets the mobilenumber.
* @param mobilenumber the mobile number to set
* @see #getMobilenumber()
* Sets the phonenumber.
* @param phonenumber the mobile number to set
* @see #getPhoneNumber()
*/
public void setMobilenumber(String mobilenumber) {
this.phonenumber = mobilenumber;
public void setPhoneNumber(String phonenumber) {
this.phonenumber = phonenumber;
}

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package esendex.sdk.java.model.transfer.contact;


import com.thoughtworks.xstream.annotations.XStreamAlias;

@XStreamAlias("response")
public class ContactResponseDto {

@XStreamAlias("contact")
private NewContactDto contact;// = new ArrayList();

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package esendex.sdk.java.model.transfer.contact;

import com.thoughtworks.xstream.annotations.XStreamAlias;
import com.thoughtworks.xstream.annotations.XStreamOmitField;

@XStreamAlias("contact")
public class NewContactDto {

@XStreamAlias("firstname")
private String firstname;

@XStreamAlias("lastname")
private String lastname;

@XStreamAlias("quickname")
private String quickname;

@XStreamAlias("phonenumber")
private String phonenumber;

@XStreamAlias("accountreference")
private String accountreference;

@XStreamOmitField
private String link;
}
26 changes: 0 additions & 26 deletions src/main/java/esendex/sdk/java/model/types/ContactType.java

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,23 +1,22 @@

package esendex.sdk.java.model.types;
// TODO: Auto-generated Javadoc

/**
* Indicates whether the message header was Inbound (received) or Outbound
* (sent).
* @author Mike Whittaker
*/
public enum MessageDirection {

INBOUND ("Inbound"),
OUTBOUND ("Outbound");

private String representation;

private MessageDirection(String representation) {
this.representation = representation;
}

/**
* To string.
* @return the string {@inheritDoc}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@

package esendex.sdk.java.model.types;

// TODO: Auto-generated Javadoc
/**
* The Enum MessageLanguage.
*/
Expand All @@ -12,13 +11,13 @@ public enum MessageLanguage {
FR_FR ("fr-FR"),
ES_ES ("es-ES"),
DE_DE ("de-DE");

private String representation;

private MessageLanguage(String representation) {
this.representation = representation;
}

/**
* To string.
* @return the string {@inheritDoc}
Expand All @@ -27,6 +26,6 @@ private MessageLanguage(String representation) {
public String toString() {
return representation;
}


}
7 changes: 3 additions & 4 deletions src/main/java/esendex/sdk/java/model/types/MessageType.java
Original file line number Diff line number Diff line change
@@ -1,22 +1,21 @@

package esendex.sdk.java.model.types;

// TODO: Auto-generated Javadoc
/**
* The type of Message can be either SMS or Voice.
* @author Mike Whittaker
*/
public enum MessageType {

SMS ("SMS"),
VOICE ("Voice");

private String representation;

private MessageType(String representation) {
this.representation = representation;
}

/**
* To string.
* @return the string {@inheritDoc}
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/esendex/sdk/java/parser/XmlParserFactory.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@
import esendex.sdk.java.parser.xstream.XStreamParser;

/**
* Factory for creating and obtaining XmlParsers.
* Factory for creating and obtaining XmlParsers.
* The instances are cached.
* @author Mike Whittaker
*/
public class XmlParserFactory {

private static final XmlParser parser = new XStreamParser();

/**
Expand Down
24 changes: 16 additions & 8 deletions src/main/java/esendex/sdk/java/parser/xstream/XStreamParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@

import java.io.StringWriter;

import esendex.sdk.java.model.transfer.contact.ContactResponseDto;
import esendex.sdk.java.model.transfer.contact.NewContactDto;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

Expand Down Expand Up @@ -55,6 +57,9 @@ public XStreamParser() {

xStream = createXStream();

xStream.processAnnotations(NewContactDto.class);
xStream.processAnnotations(ContactResponseDto.class);

// General aliases
xStream.useAttributeFor(Dto.class, "id");
xStream.useAttributeFor(Dto.class, "uri");
Expand All @@ -71,13 +76,14 @@ public XStreamParser() {
xStream.alias("session", SessionDto.class);

// Contacts
xStream.alias("contact", ContactDto.class);
xStream.omitField(ContactDto.class, "groups");
xStream.omitField(ContactDto.class, "link");
//xStream.alias("contact", ContactDto.class);
//xStream.omitField(ContactDto.class, "groups");
//xStream.omitField(ContactDto.class, "link");
//xStream.omitField(ContactDto.class, "response");

xStream.alias("contacts", ContactCollectionDto.class);
xStream.addImplicitCollection(ContactCollectionDto.class, "contacts");
xStream.omitField(ContactCollectionDto.class, "link");
//xStream.alias("contacts", ContactCollectionDto.class);
//xStream.addImplicitCollection(ContactCollectionDto.class, "contacts");
//xStream.omitField(ContactCollectionDto.class, "link");

// Message (request)
xStream.alias("message", MessageRequestDto.class);
Expand All @@ -103,12 +109,14 @@ public XStreamParser() {

// configures the field order for the DTOs
private static XStream createXStream() {
SortableFieldKeySorter sorter = new SortableFieldKeySorter();
/* SortableFieldKeySorter sorter = new SortableFieldKeySorter();
for(FieldOrder fo : FieldOrder.getFieldOrders()) {
sorter.registerFieldOrder(
fo.getFieldOrderClass(), fo.getFieldOrder());
}
return new XStream(new PureJavaReflectionProvider(new FieldDictionary(sorter)));
return new XStream(new PureJavaReflectionProvider(new FieldDictionary(sorter)));*/

return new XStream();
}

/**
Expand Down
2 changes: 0 additions & 2 deletions src/main/java/esendex/sdk/java/service/ContactService.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@ public interface ContactService {

ContactResponse createContact(ContactRequest contactRequest) throws EsendexException;

boolean createContacts(List<ContactRequest> contactRequests) throws EsendexException;

/**
* @param id the id of the desired contact
*/
Expand Down
Loading

0 comments on commit 2f71c26

Please sign in to comment.