diff --git a/src/main/java/esendex/sdk/java/model/domain/impl/ContactResponseAssembler.java b/src/main/java/esendex/sdk/java/model/domain/impl/ContactResponseAssembler.java index ade2540..9ba720a 100644 --- a/src/main/java/esendex/sdk/java/model/domain/impl/ContactResponseAssembler.java +++ b/src/main/java/esendex/sdk/java/model/domain/impl/ContactResponseAssembler.java @@ -20,6 +20,7 @@ public ContactResponse createResponse(ContactDto dto) { resp.setMobileNumber(dto.getPhoneNumber()); resp.setQuickName(dto.getQuickname()); + return resp; } diff --git a/src/main/java/esendex/sdk/java/model/transfer/Dto.java b/src/main/java/esendex/sdk/java/model/transfer/Dto.java index 31ca8f6..748ecb7 100644 --- a/src/main/java/esendex/sdk/java/model/transfer/Dto.java +++ b/src/main/java/esendex/sdk/java/model/transfer/Dto.java @@ -1,20 +1,31 @@ package esendex.sdk.java.model.transfer; +import com.thoughtworks.xstream.annotations.XStreamAlias; +import com.thoughtworks.xstream.annotations.XStreamAsAttribute; + /** * Base xml resource class. This is the superclass for all xml resources. - * When a Dto is the root xml entity then the xml namespace (xmlns) - * attribute will be set. Any Dto may have a URI attribute to provide + * When a Dto is the root xml entity then the xml namespace (xmlns) + * attribute will be set. Any Dto may have a URI attribute to provide * access to a more complete resource - * + * * @author Mike Whittaker */ public abstract class Dto { - + + @XStreamAlias("id") + @XStreamAsAttribute private String id; + + @XStreamAlias("uri") + @XStreamAsAttribute private String uri; + + @XStreamAlias("xmlns") + @XStreamAsAttribute private String xmlns; - + public Dto() { } @@ -57,7 +68,7 @@ public void setId(String id) { public void setUri(String uri) { this.uri = uri; } - + public void setXmlns(String xmlns) { this.xmlns = xmlns; } @@ -66,7 +77,7 @@ public void setXmlns(String xmlns) { * {@inheritDoc} */ @Override - public String toString() { + public String toString() { return "id: " + id + "\nuri: " + uri + "\nxmlns: " + xmlns; diff --git a/src/main/java/esendex/sdk/java/model/transfer/LinkDto.java b/src/main/java/esendex/sdk/java/model/transfer/LinkDto.java new file mode 100644 index 0000000..3ff3aab --- /dev/null +++ b/src/main/java/esendex/sdk/java/model/transfer/LinkDto.java @@ -0,0 +1,16 @@ +package esendex.sdk.java.model.transfer; + +import com.thoughtworks.xstream.annotations.XStreamAlias; +import com.thoughtworks.xstream.annotations.XStreamAsAttribute; + +@XStreamAlias("link") +public class LinkDto { + + @XStreamAlias("rel") + @XStreamAsAttribute + private String rel; + + @XStreamAlias("href") + @XStreamAsAttribute + private String href; +} diff --git a/src/main/java/esendex/sdk/java/model/transfer/contact/ContactCollectionDto.java b/src/main/java/esendex/sdk/java/model/transfer/contact/ContactCollectionDto.java index 0183bde..8418ea6 100644 --- a/src/main/java/esendex/sdk/java/model/transfer/contact/ContactCollectionDto.java +++ b/src/main/java/esendex/sdk/java/model/transfer/contact/ContactCollectionDto.java @@ -4,52 +4,35 @@ import java.util.ArrayList; import java.util.List; +import com.thoughtworks.xstream.annotations.XStreamImplicit; import esendex.sdk.java.model.transfer.PageableDto; import esendex.sdk.java.model.transfer.contact.ContactDto; -/** - * The response from certain services containing a collection of - * ContactResponse. - * @author Mike Whittaker - */ public class ContactCollectionDto extends PageableDto { - private List contacts; + @XStreamImplicit(itemFieldName = "contact") + private List contacts = new ArrayList(); - private Object readResolve() { - if (contacts == null) contacts = new ArrayList(); - return this; + @XStreamImplicit(itemFieldName = "link") + private List link = new ArrayList(); + + public ContactCollectionDto(List contacts) { + this.contacts = contacts; } - public ContactCollectionDto() { + public List getLink() { + return link; } - /** - * Creates a ContactCollectionDto populated with a List of - * ContactDtos. - * @param contacts the List of contacts - */ - public ContactCollectionDto(List contacts) { - this.contacts = contacts; + public void setLink(List link) { + this.link = link; } - /** - * Gets the contacts. - * @return the contacts - */ public List getContacts() { return contacts; } - public void setContacts(List contacts) { + public void setContacts(List contacts) { this.contacts = contacts; } - - /** - * {@inheritDoc} - */ - @Override - public String toString() { - return super.toString() + "\n" + contacts; - } } diff --git a/src/main/java/esendex/sdk/java/model/transfer/contact/ContactDto.java b/src/main/java/esendex/sdk/java/model/transfer/contact/ContactDto.java index 21c506c..e356072 100644 --- a/src/main/java/esendex/sdk/java/model/transfer/contact/ContactDto.java +++ b/src/main/java/esendex/sdk/java/model/transfer/contact/ContactDto.java @@ -1,128 +1,74 @@ package esendex.sdk.java.model.transfer.contact; +import com.thoughtworks.xstream.annotations.XStreamAlias; +import com.thoughtworks.xstream.annotations.XStreamImplicit; import com.thoughtworks.xstream.annotations.XStreamOmitField; import esendex.sdk.java.model.transfer.Dto; +import esendex.sdk.java.model.transfer.LinkDto; -/** - * Base class for contact requests and responses. This class directly holds the - * parsed xml data. Subclasses should merely allow selective access. - * @author Mike Whittaker - */ +import java.util.ArrayList; +import java.util.List; + +@XStreamAlias("contact") public class ContactDto extends Dto { + @XStreamAlias("firstname") private String firstname; + + @XStreamAlias("lastname") private String lastname; + + @XStreamAlias("quickname") private String quickname; + + @XStreamAlias("phonenumber") private String phonenumber; - private String accountreference; - @XStreamOmitField - private String link; + @XStreamAlias("accountreference") + private String accountreference; - public ContactDto() { - } + @XStreamImplicit(itemFieldName = "link") + private List link = new ArrayList(); - /** - * The first name of this Contact. This may not be returned if the property - * has not been set for the Contact. - * @return the contacts first name - */ public String getFirstname() { return firstname; } - /** - * The last name of this Contact. This may not be returned if - * the property has not been set for the Contact. - * @return the contacts last name - */ + public void setFirstname(String firstname) { + this.firstname = firstname; + } + public String getLastname() { return lastname; } - /** - * This is the human-friendly shortcut for the Contact and can be used as - * a Message recipient instead of a telephone number. Where firstname - * and lastname have been set when the Contact was created, it may be a - * concatenation of these two values. - * @return the contacts quickname - */ + public void setLastname(String lastname) { + this.lastname = lastname; + } + public String getQuickname() { return quickname; } - /** - * The telephone number associated with this Contact. - * @return the phone number - */ - public String getPhoneNumber() { - return phonenumber; + public void setQuickname(String quickname) { + this.quickname = quickname; } - /** - * The accountReference associated with this Contact. - * @return the Account Reference - */ - public String getAccountReference() {return accountreference; } - - /** - * Sets the firstname. - * @param firstname the first name to set - * @see #getFirstname() - */ - public void setFirstname(String firstname) { - this.firstname = firstname; + public String getPhoneNumber() { + return phonenumber; } - /** - * Sets the lastname. - * @param lastname the last name to set - * @see #getLastname() - */ - public void setLastname(String lastname) { - this.lastname = lastname; + public void setPhoneNumber(String phonenumber) { + this.phonenumber = phonenumber; } - /** - * Sets the quickname. - * @param quickname the quick name to set - * @see #getQuickname() - */ - public void setQuickname(String quickname) { - this.quickname = quickname; + public String getAccountReference() { + return accountreference; } - /** - * Sets the phonenumber. - * @param phonenumber the mobile number to set - * @see #getPhoneNumber() - */ - public void setPhoneNumber(String phonenumber) { - this.phonenumber = phonenumber; + public void setAccountReference(String accountreference) { + this.accountreference = accountreference; } - - /** - * Sets the type. - * @param accountReference the accountReference to set - * @see #getAccountReference() () - */ - public void setAccountReference(String accountReference) { - this.accountreference = accountReference; - } - - /** - * {@inheritDoc} - */ - @Override - public String toString() { - - return super.toString() + - "\nfirstname:" + firstname + - "\nlastname:" + lastname + - "\nquickname:" + quickname + - "\nmobilenumber:" + phonenumber + - "\naccountreference:" + accountreference; - } -} +} \ No newline at end of file diff --git a/src/main/java/esendex/sdk/java/model/transfer/contact/ContactResponseDto.java b/src/main/java/esendex/sdk/java/model/transfer/contact/ContactResponseDto.java index e247ffe..7affae0 100644 --- a/src/main/java/esendex/sdk/java/model/transfer/contact/ContactResponseDto.java +++ b/src/main/java/esendex/sdk/java/model/transfer/contact/ContactResponseDto.java @@ -1,12 +1,18 @@ package esendex.sdk.java.model.transfer.contact; - - import com.thoughtworks.xstream.annotations.XStreamAlias; +import esendex.sdk.java.model.transfer.Dto; @XStreamAlias("response") -public class ContactResponseDto { +public class ContactResponseDto extends Dto { @XStreamAlias("contact") - private NewContactDto contact;// = new ArrayList(); + private ContactDto contact; + + public ContactDto getContact() { + return contact; + } + public void setContact(ContactDto contact) { + this.contact = contact; + } } diff --git a/src/main/java/esendex/sdk/java/model/transfer/contact/NewContactDto.java b/src/main/java/esendex/sdk/java/model/transfer/contact/NewContactDto.java deleted file mode 100644 index 90ac052..0000000 --- a/src/main/java/esendex/sdk/java/model/transfer/contact/NewContactDto.java +++ /dev/null @@ -1,26 +0,0 @@ -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; -} diff --git a/src/main/java/esendex/sdk/java/parser/XmlParser.java b/src/main/java/esendex/sdk/java/parser/XmlParser.java index aeff372..a21c7ca 100644 --- a/src/main/java/esendex/sdk/java/parser/XmlParser.java +++ b/src/main/java/esendex/sdk/java/parser/XmlParser.java @@ -10,7 +10,7 @@ * @author Mike Whittaker */ public interface XmlParser { - + /** * Converts if possible, a String, that must be in XML format, to a Dto. * @param xml the character data to be converted @@ -18,7 +18,7 @@ public interface XmlParser { * @throws EsendexException if there is any problem reading or parseing the * XML. */ - Dto fromXml(String xml) throws EsendexException; + Object fromXml(String xml) throws EsendexException; /** * Converts a Dto Object to XML character data. diff --git a/src/main/java/esendex/sdk/java/parser/xstream/XStreamParser.java b/src/main/java/esendex/sdk/java/parser/xstream/XStreamParser.java index fc94a4d..78c0c1c 100644 --- a/src/main/java/esendex/sdk/java/parser/xstream/XStreamParser.java +++ b/src/main/java/esendex/sdk/java/parser/xstream/XStreamParser.java @@ -3,15 +3,14 @@ import java.io.StringWriter; +import esendex.sdk.java.model.transfer.LinkDto; +import esendex.sdk.java.model.transfer.contact.ContactCollectionDto; +import esendex.sdk.java.model.transfer.contact.ContactDto; 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; import com.thoughtworks.xstream.XStream; -import com.thoughtworks.xstream.converters.reflection.FieldDictionary; -import com.thoughtworks.xstream.converters.reflection.PureJavaReflectionProvider; -import com.thoughtworks.xstream.converters.reflection.SortableFieldKeySorter; import com.thoughtworks.xstream.io.StreamException; import com.thoughtworks.xstream.io.xml.CompactWriter; import com.thoughtworks.xstream.mapper.CannotResolveClassException; @@ -19,10 +18,7 @@ import esendex.sdk.java.EsendexException; import esendex.sdk.java.EsendexProperties; import esendex.sdk.java.model.transfer.Dto; -import esendex.sdk.java.model.transfer.FieldOrder; import esendex.sdk.java.model.transfer.PageableDto; -import esendex.sdk.java.model.transfer.contact.ContactCollectionDto; -import esendex.sdk.java.model.transfer.contact.ContactDto; import esendex.sdk.java.model.transfer.message.BodyDto; import esendex.sdk.java.model.transfer.message.MessageCollectionRequestDto; import esendex.sdk.java.model.transfer.message.MessageCollectionResponseDto; @@ -57,8 +53,6 @@ public XStreamParser() { xStream = createXStream(); - xStream.processAnnotations(NewContactDto.class); - xStream.processAnnotations(ContactResponseDto.class); // General aliases xStream.useAttributeFor(Dto.class, "id"); @@ -76,14 +70,13 @@ public XStreamParser() { xStream.alias("session", SessionDto.class); // Contacts - //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"); + xStream.processAnnotations(ContactDto.class); + xStream.processAnnotations(ContactResponseDto.class); + xStream.processAnnotations(LinkDto.class); // Message (request) xStream.alias("message", MessageRequestDto.class); @@ -123,9 +116,9 @@ private static XStream createXStream() { * {@inheritDoc} */ @Override - public Dto fromXml(String xml) throws EsendexException { + public Object fromXml(String xml) throws EsendexException { try { - return (Dto)xStream.fromXML(xml); + return xStream.fromXML(xml); } catch (ClassCastException ex) { throw new UnmappableException("Could not map to a Dto", ex); } catch (StreamException ex) { diff --git a/src/main/java/esendex/sdk/java/service/impl/ContactServiceImpl.java b/src/main/java/esendex/sdk/java/service/impl/ContactServiceImpl.java index 5b09477..d4f3e27 100644 --- a/src/main/java/esendex/sdk/java/service/impl/ContactServiceImpl.java +++ b/src/main/java/esendex/sdk/java/service/impl/ContactServiceImpl.java @@ -10,10 +10,10 @@ import esendex.sdk.java.model.domain.response.ContactResponse; import esendex.sdk.java.model.transfer.contact.ContactCollectionDto; import esendex.sdk.java.model.transfer.contact.ContactDto; +import esendex.sdk.java.model.transfer.contact.ContactResponseDto; import esendex.sdk.java.service.ContactService; import esendex.sdk.java.service.auth.Authenticator; import esendex.sdk.java.service.resource.contact.CreateContactResource; -import esendex.sdk.java.service.resource.contact.CreateContactsResource; import esendex.sdk.java.service.resource.contact.DeleteContactResource; import esendex.sdk.java.service.resource.contact.RetrieveContactResource; import esendex.sdk.java.service.resource.contact.RetrieveContactsResource; @@ -46,8 +46,8 @@ public ContactResponse createContact(ContactRequest contactRequest) throws Esend resource.setRequestObject(contactDto); resource.execute(); - ContactDto resp = resource.getResponseObject(); - return new ContactResponseAssembler().createResponse(resp); + ContactResponseDto resp = resource.getResponseObject(); + return new ContactResponseAssembler().createResponse(resp.getContact()); } /** diff --git a/src/main/java/esendex/sdk/java/service/resource/base/XmlRequester.java b/src/main/java/esendex/sdk/java/service/resource/base/XmlRequester.java index 8093cf2..9b4b83f 100644 --- a/src/main/java/esendex/sdk/java/service/resource/base/XmlRequester.java +++ b/src/main/java/esendex/sdk/java/service/resource/base/XmlRequester.java @@ -17,20 +17,20 @@ public class XmlRequester { private Log log = LogFactory.getLog(XmlRequester.class); private Q requestDto; private XmlParser parser; - + /** * Instantiates a new xml requester. * @param requestDto the request dto */ public XmlRequester(Q requestDto) { - if (requestDto == null) + if (requestDto == null) throw new NullPointerException("Argument must not be null"); - + log.info("Request class: " + requestDto.getClass().getSimpleName()); this.parser = XmlParserFactory.getInstance(); this.requestDto = requestDto; - } - + } + /** * Provide the request data that is required by the end point of this service. * @return the request data to submit diff --git a/src/main/java/esendex/sdk/java/service/resource/base/XmlRequesterResponderResource.java b/src/main/java/esendex/sdk/java/service/resource/base/XmlRequesterResponderResource.java index 6ddc00f..046ef8a 100644 --- a/src/main/java/esendex/sdk/java/service/resource/base/XmlRequesterResponderResource.java +++ b/src/main/java/esendex/sdk/java/service/resource/base/XmlRequesterResponderResource.java @@ -14,7 +14,7 @@ * @param the Dto type expected in the response * @author Mike Whittaker */ -public abstract class XmlRequesterResponderResource extends Resource { +public abstract class XmlRequesterResponderResource extends Resource { private XmlRequester requester; private XmlResponder responder; diff --git a/src/main/java/esendex/sdk/java/service/resource/base/XmlResponderResource.java b/src/main/java/esendex/sdk/java/service/resource/base/XmlResponderResource.java index d798df0..d32321b 100644 --- a/src/main/java/esendex/sdk/java/service/resource/base/XmlResponderResource.java +++ b/src/main/java/esendex/sdk/java/service/resource/base/XmlResponderResource.java @@ -12,7 +12,7 @@ * * @param the Dto type that is expected in response */ -public abstract class XmlResponderResource extends Resource { +public abstract class XmlResponderResource extends Resource { private XmlResponder responder; diff --git a/src/main/java/esendex/sdk/java/service/resource/contact/CreateContactResource.java b/src/main/java/esendex/sdk/java/service/resource/contact/CreateContactResource.java index dd4d97c..ba13bb1 100644 --- a/src/main/java/esendex/sdk/java/service/resource/contact/CreateContactResource.java +++ b/src/main/java/esendex/sdk/java/service/resource/contact/CreateContactResource.java @@ -4,6 +4,7 @@ import esendex.sdk.java.http.HttpRequestMethod; import esendex.sdk.java.model.transfer.contact.ContactCollectionDto; import esendex.sdk.java.model.transfer.contact.ContactDto; +import esendex.sdk.java.model.transfer.contact.ContactResponseDto; import esendex.sdk.java.service.auth.Authenticator; import esendex.sdk.java.service.resource.base.XmlRequesterResponderResource; @@ -12,7 +13,7 @@ * return a Contact response. * @author Mike Whittaker */ -public class CreateContactResource extends XmlRequesterResponderResource { +public class CreateContactResource extends XmlRequesterResponderResource { /** * Instantiates a new creates the contact resource. diff --git a/src/main/java/esendex/sdk/java/service/resource/contact/CreateContactsResource.java b/src/main/java/esendex/sdk/java/service/resource/contact/CreateContactsResource.java deleted file mode 100644 index a6e3787..0000000 --- a/src/main/java/esendex/sdk/java/service/resource/contact/CreateContactsResource.java +++ /dev/null @@ -1,42 +0,0 @@ - -package esendex.sdk.java.service.resource.contact; - -import esendex.sdk.java.http.HttpRequestMethod; -import esendex.sdk.java.model.transfer.contact.ContactCollectionDto; -import esendex.sdk.java.service.auth.Authenticator; -import esendex.sdk.java.service.resource.base.XmlRequesterResource; - -/** - * This operation allows the creation of multiple Contacts with one request POST - * to the Contacts resource. There is only an HTTP Status Code result from this - * operation. - * - * @author Mike Whittaker - */ -public class CreateContactsResource extends XmlRequesterResource { - - /** - * Instantiates a new creates the contacts resource. - * @param auth the authenticator - */ - public CreateContactsResource(Authenticator auth) { - super(auth, null, null, null, "2.0"); - } - - /** - * {@inheritDoc} - */ - @Override - protected String getEndpointChild() { - return "contacts"; - } - - /** - * {@inheritDoc} - */ - @Override - protected HttpRequestMethod getRequestMethod() { - return HttpRequestMethod.POST; - } - -} diff --git a/src/test/java/com/esendex/java/sdk/UnitTest.java b/src/test/java/com/esendex/java/sdk/UnitTest.java deleted file mode 100644 index 34c5e59..0000000 --- a/src/test/java/com/esendex/java/sdk/UnitTest.java +++ /dev/null @@ -1,30 +0,0 @@ -package com.esendex.java.sdk; - -import esendex.sdk.java.EsendexException; -import esendex.sdk.java.model.transfer.contact.ContactResponseDto; -import esendex.sdk.java.model.transfer.contact.NewContactDto; -import esendex.sdk.java.service.resource.base.XmlResponder; -import org.junit.Test; - -public class UnitTest { - - @Test - public void thenAstuff() throws EsendexException { - - String xml = "\n" + - "\n" + - " \n" + - " \n" + - " \n" + - " adasd111aaa1\n" + - " 44787134312\n" + - " EX0067551\n" + - " \n" + - " \n" + - " \n" + - ""; - - XmlResponder newContactDtoXmlResponder = new XmlResponder(xml); - - } -} diff --git a/src/test/java/com/esendex/java/sdk/integration/TestRunner.java b/src/test/java/com/esendex/java/sdk/integration/TestRunner.java deleted file mode 100644 index 1d1492d..0000000 --- a/src/test/java/com/esendex/java/sdk/integration/TestRunner.java +++ /dev/null @@ -1,17 +0,0 @@ -package com.esendex.java.sdk.integration; -import com.esendex.java.sdk.UnitTest; -import com.esendex.java.sdk.integration.contactsservice.ContactsServiceGetContactIT; -import com.esendex.java.sdk.integration.inboxservice.InboxServiceMarkIT; -import org.junit.runner.JUnitCore; -import org.junit.runner.Result; -import org.junit.runner.notification.Failure; - -public class TestRunner { - public static void main(String[] args) { - Result result = JUnitCore.runClasses(UnitTest.class); - for (Failure failure : result.getFailures()) { - System.out.println(failure.toString()); - } - System.out.println(result.wasSuccessful()); - } -} diff --git a/src/test/java/com/esendex/java/sdk/integration/contactsservice/ContactsServiceGetContactIT.java b/src/test/java/com/esendex/java/sdk/integration/contactsservice/ContactsServiceGetContactIT.java index 3943786..5ac8b32 100644 --- a/src/test/java/com/esendex/java/sdk/integration/contactsservice/ContactsServiceGetContactIT.java +++ b/src/test/java/com/esendex/java/sdk/integration/contactsservice/ContactsServiceGetContactIT.java @@ -25,8 +25,6 @@ public static void whenGettingContacts() throws EsendexException { ContactService contactService = getFactory().getContactService(); expectedContacts = contactService.getContacts(0, 5, ACCOUNT); - ContactResponse contactResponse = contactService.createContact(new ContactRequest("lol", "44876541224", "Esendex Exchange")); - actualContacts = new Vector(); for (ContactResponse expectedContact : expectedContacts) { String contactId = expectedContact.getId();