From 61841555fdf5f58d931bbca841b9cab2da1b197c Mon Sep 17 00:00:00 2001 From: Diptee Warudkar Date: Tue, 1 Mar 2016 15:02:45 +0100 Subject: [PATCH 01/24] Adding model classes for Address Adding service class for Address TODO common Abstract Class --- .../zalando/api/nativecart/model/Address.java | 107 +++++++ .../nativecart/model/AddressCheckRequest.java | 8 + .../model/AddressCheckResponse.java | 38 +++ .../zalando/api/nativecart/model/Base.java | 12 + .../model/CreateAddressRequest.java | 13 + .../model/CreateAddressResponse.java | 9 + .../nativecart/model/GetAddressResponse.java | 9 + .../model/GetAddressesResponse.java | 22 ++ .../model/UpdateAddressRequest.java | 12 + .../model/UpdateAddressResponse.java | 10 + .../nativecart/service/AbstractService.java | 287 ++++++++++++++++++ .../nativecart/service/AddressService.java | 76 +++++ .../nativecart/service/IAddressService.java | 46 +++ 13 files changed, 649 insertions(+) create mode 100644 src/main/java/io/sprucehill/zalando/api/nativecart/model/Address.java create mode 100644 src/main/java/io/sprucehill/zalando/api/nativecart/model/AddressCheckRequest.java create mode 100644 src/main/java/io/sprucehill/zalando/api/nativecart/model/AddressCheckResponse.java create mode 100644 src/main/java/io/sprucehill/zalando/api/nativecart/model/Base.java create mode 100644 src/main/java/io/sprucehill/zalando/api/nativecart/model/CreateAddressRequest.java create mode 100644 src/main/java/io/sprucehill/zalando/api/nativecart/model/CreateAddressResponse.java create mode 100644 src/main/java/io/sprucehill/zalando/api/nativecart/model/GetAddressResponse.java create mode 100644 src/main/java/io/sprucehill/zalando/api/nativecart/model/GetAddressesResponse.java create mode 100644 src/main/java/io/sprucehill/zalando/api/nativecart/model/UpdateAddressRequest.java create mode 100644 src/main/java/io/sprucehill/zalando/api/nativecart/model/UpdateAddressResponse.java create mode 100644 src/main/java/io/sprucehill/zalando/api/nativecart/service/AbstractService.java create mode 100644 src/main/java/io/sprucehill/zalando/api/nativecart/service/AddressService.java create mode 100644 src/main/java/io/sprucehill/zalando/api/nativecart/service/IAddressService.java diff --git a/src/main/java/io/sprucehill/zalando/api/nativecart/model/Address.java b/src/main/java/io/sprucehill/zalando/api/nativecart/model/Address.java new file mode 100644 index 0000000..63a8b43 --- /dev/null +++ b/src/main/java/io/sprucehill/zalando/api/nativecart/model/Address.java @@ -0,0 +1,107 @@ +package io.sprucehill.zalando.api.nativecart.model; + +import com.fasterxml.jackson.annotation.JsonProperty; + +/** + * + * @author dipteewarudkar + * + */ +public abstract class Address extends Base { + + @JsonProperty + private String id; + @JsonProperty + private String customer_number; + @JsonProperty + private String gender; + @JsonProperty + private String first_name; + @JsonProperty + private String last_name; + @JsonProperty + private String street; + @JsonProperty + private String additional; + @JsonProperty + private String zip; + @JsonProperty + private String city; + @JsonProperty + private String country_code; + @JsonProperty + private Boolean pack_station; + @JsonProperty + private Boolean default_billing; + @JsonProperty + private Boolean default_shipping; + + public Address(){} + + public Address(String id, String customer_number, String gender, String first_name, String last_name, String street,String additional, String zip, String city, String country_code, Boolean pack_station,Boolean default_billing, Boolean default_shipping) { + this.id=id; + this.customer_number=customer_number; + this.gender=gender; + this.first_name=first_name; + this.last_name=last_name; + this.street=street; + this.additional=additional; + this.city=city; + this.country_code=country_code; + this.pack_station=pack_station; + this.default_billing=default_billing; + this.default_shipping=default_shipping; + } + + public String getId() { + return id; + } + + public String getCustomer_number() { + return customer_number; + } + + public String getGender() { + return gender; + } + + public String getFirst_name() { + return first_name; + } + + public String getLast_name() { + return last_name; + } + + public String getStreet() { + return street; + } + + public String getAdditional() { + return additional; + } + + public String getZip() { + return zip; + } + + public String getCity() { + return city; + } + + public String getCountry_code() { + return country_code; + } + + public Boolean getPack_station() { + return pack_station; + } + + public Boolean getDefault_billing() { + return default_billing; + } + + public Boolean getDefault_shipping() { + return default_shipping; + } +} diff --git a/src/main/java/io/sprucehill/zalando/api/nativecart/model/AddressCheckRequest.java b/src/main/java/io/sprucehill/zalando/api/nativecart/model/AddressCheckRequest.java new file mode 100644 index 0000000..2bc192f --- /dev/null +++ b/src/main/java/io/sprucehill/zalando/api/nativecart/model/AddressCheckRequest.java @@ -0,0 +1,8 @@ +package io.sprucehill.zalando.api.nativecart.model; + +public class AddressCheckRequest extends Address{ + + public AddressCheckRequest(String gender,String first_name,String last_name,String street,String additional,String zip,String city,String country_code,Boolean pack_station,Boolean default_billing,Boolean default_shipping){ + super(null,null,gender,first_name,last_name,street,additional,zip,city,country_code,pack_station,default_billing,default_shipping); + } +} diff --git a/src/main/java/io/sprucehill/zalando/api/nativecart/model/AddressCheckResponse.java b/src/main/java/io/sprucehill/zalando/api/nativecart/model/AddressCheckResponse.java new file mode 100644 index 0000000..b565e7f --- /dev/null +++ b/src/main/java/io/sprucehill/zalando/api/nativecart/model/AddressCheckResponse.java @@ -0,0 +1,38 @@ +package io.sprucehill.zalando.api.nativecart.model; + +/** + * + * @author dipteewarudkar + * + */ +public class AddressCheckResponse extends Base { + private String status; + private Boolean blacklisted; + Address address; + Address normalized_address; + + public String getStatus() { + return status; + } + public void setStatus(String status) { + this.status = status; + } + public Boolean getBlacklisted() { + return blacklisted; + } + public void setBlacklisted(Boolean blacklisted) { + this.blacklisted = blacklisted; + } + public Address getAddress() { + return address; + } + public void setAddress(Address address) { + this.address = address; + } + public Address getNormalized_address() { + return normalized_address; + } + public void setNormalized_address(Address normalized_address) { + this.normalized_address = normalized_address; + } +} diff --git a/src/main/java/io/sprucehill/zalando/api/nativecart/model/Base.java b/src/main/java/io/sprucehill/zalando/api/nativecart/model/Base.java new file mode 100644 index 0000000..b9358a1 --- /dev/null +++ b/src/main/java/io/sprucehill/zalando/api/nativecart/model/Base.java @@ -0,0 +1,12 @@ +package io.sprucehill.zalando.api.nativecart.model; + +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonInclude; + +/** + * @author Michael Duergner + */ +@JsonIgnoreProperties(ignoreUnknown = true) +@JsonInclude(value = JsonInclude.Include.NON_NULL) +public abstract class Base { +} diff --git a/src/main/java/io/sprucehill/zalando/api/nativecart/model/CreateAddressRequest.java b/src/main/java/io/sprucehill/zalando/api/nativecart/model/CreateAddressRequest.java new file mode 100644 index 0000000..786f0eb --- /dev/null +++ b/src/main/java/io/sprucehill/zalando/api/nativecart/model/CreateAddressRequest.java @@ -0,0 +1,13 @@ +package io.sprucehill.zalando.api.nativecart.model; + +/** + * + * @author dipteewarudkar + * + */ +public class CreateAddressRequest extends Address{ + + public CreateAddressRequest(String gender,String first_name,String last_name,String street,String additional,String zip,String city,String country_code,Boolean pack_station,Boolean default_billing,Boolean default_shipping){ + super(null,null,gender,first_name,last_name,street,additional,zip,city,country_code,pack_station,default_billing,default_shipping); + } +} \ No newline at end of file diff --git a/src/main/java/io/sprucehill/zalando/api/nativecart/model/CreateAddressResponse.java b/src/main/java/io/sprucehill/zalando/api/nativecart/model/CreateAddressResponse.java new file mode 100644 index 0000000..0eecb13 --- /dev/null +++ b/src/main/java/io/sprucehill/zalando/api/nativecart/model/CreateAddressResponse.java @@ -0,0 +1,9 @@ +package io.sprucehill.zalando.api.nativecart.model; + +/** + * + * @author dipteewarudkar + * + */ +public class CreateAddressResponse extends Address{ +} diff --git a/src/main/java/io/sprucehill/zalando/api/nativecart/model/GetAddressResponse.java b/src/main/java/io/sprucehill/zalando/api/nativecart/model/GetAddressResponse.java new file mode 100644 index 0000000..5e91d6b --- /dev/null +++ b/src/main/java/io/sprucehill/zalando/api/nativecart/model/GetAddressResponse.java @@ -0,0 +1,9 @@ +package io.sprucehill.zalando.api.nativecart.model; + +/** + * + * @author dipteewarudkar + * + */ +public class GetAddressResponse extends Address { +} diff --git a/src/main/java/io/sprucehill/zalando/api/nativecart/model/GetAddressesResponse.java b/src/main/java/io/sprucehill/zalando/api/nativecart/model/GetAddressesResponse.java new file mode 100644 index 0000000..054fce9 --- /dev/null +++ b/src/main/java/io/sprucehill/zalando/api/nativecart/model/GetAddressesResponse.java @@ -0,0 +1,22 @@ +package io.sprucehill.zalando.api.nativecart.model; + +import java.util.List; + +/** + * + * @author dipteewarudkar + * + */ +public class GetAddressesResponse extends Base { + + List addresses; + + public List getAddresses() { + return addresses; + } + + public void setAddresses(List addresses) { + this.addresses = addresses; + } + +} diff --git a/src/main/java/io/sprucehill/zalando/api/nativecart/model/UpdateAddressRequest.java b/src/main/java/io/sprucehill/zalando/api/nativecart/model/UpdateAddressRequest.java new file mode 100644 index 0000000..85939bf --- /dev/null +++ b/src/main/java/io/sprucehill/zalando/api/nativecart/model/UpdateAddressRequest.java @@ -0,0 +1,12 @@ +package io.sprucehill.zalando.api.nativecart.model; + +/** + * + * @author dipteewarudkar + * + */ +public class UpdateAddressRequest extends Address { + public UpdateAddressRequest(String gender,String first_name,String last_name,String street,String additional,String zip,String city,String country_code,Boolean pack_station,Boolean default_billing,Boolean default_shipping){ + super(null,null,gender,first_name,last_name,street,additional,zip,city,country_code,pack_station,default_billing,default_shipping); + } +} \ No newline at end of file diff --git a/src/main/java/io/sprucehill/zalando/api/nativecart/model/UpdateAddressResponse.java b/src/main/java/io/sprucehill/zalando/api/nativecart/model/UpdateAddressResponse.java new file mode 100644 index 0000000..219bfa2 --- /dev/null +++ b/src/main/java/io/sprucehill/zalando/api/nativecart/model/UpdateAddressResponse.java @@ -0,0 +1,10 @@ +package io.sprucehill.zalando.api.nativecart.model; + +/** + * + * @author dipteewarudkar + * + */ +public class UpdateAddressResponse extends Base{ + +} diff --git a/src/main/java/io/sprucehill/zalando/api/nativecart/service/AbstractService.java b/src/main/java/io/sprucehill/zalando/api/nativecart/service/AbstractService.java new file mode 100644 index 0000000..08850dd --- /dev/null +++ b/src/main/java/io/sprucehill/zalando/api/nativecart/service/AbstractService.java @@ -0,0 +1,287 @@ +package io.sprucehill.zalando.api.nativecart.service; + +import com.fasterxml.jackson.core.type.TypeReference; +import com.fasterxml.jackson.databind.ObjectMapper; +import io.sprucehill.zalando.api.exception.NotFoundException; +import io.sprucehill.zalando.api.model.Domain; +import org.apache.http.HttpHeaders; +import org.apache.http.HttpResponse; +import org.apache.http.client.HttpClient; +import org.apache.http.client.methods.*; +import org.apache.http.client.utils.URIBuilder; +import org.apache.http.impl.client.HttpClientBuilder; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import javax.annotation.PostConstruct; +import java.io.IOException; +import java.net.URI; +import java.net.URISyntaxException; + +/** + * @author Michael Duergner + */ +public abstract class AbstractService { + + String apiBase = "https://api.zalando.com"; + + String scheme; + + String host; + + Integer port; + + String pathPrefix; + + protected Domain defaultDomain; + + protected Logger logger = LoggerFactory.getLogger(getClass()); + + protected HttpClient httpClient; + + protected ObjectMapper objectMapper; + + /** + * Set a different API base + * + * @param apiBase The API base to use; defaults to 'https://api.zalando.com' + */ + public void setApiBase(String apiBase) { + this.apiBase = apiBase; + } + + /** + * Set the default domain to use; this is a mandatory setter to be called + * + * @param defaultDomain The default shop domain to use + */ + public void setDefaultDomain(Domain defaultDomain) { + this.defaultDomain = defaultDomain; + } + + /** + * Set a custom HttpClient to use; the bean will create a default HttpClient on its postConstruct method if no HttpClient has been set previously. + * You might want to set your custom HttpClient as the default implementation does not use any pooling or threading implementation. + * + * @param httpClient The HttpClient to use. + */ + public void setHttpClient(HttpClient httpClient) { + this.httpClient = httpClient; + } + + /** + * Set a custom ObjectMapper to use; the bean will create a default ObjectMapper on its postConstruct method if no ObjectMapper has been set previously. + * + * @param objectMapper The ObjectMapper to use. + */ + public void setObjectMapper(ObjectMapper objectMapper) { + this.objectMapper = objectMapper; + } + + /** + * Call this method on postConstruct for any subclasses as it takes care to initialize the bean + */ + @PostConstruct + public void postConstruct() { + if (null == httpClient) { + httpClient = HttpClientBuilder.create().build(); + } + if (null == objectMapper) { + objectMapper = new ObjectMapper(); + } + if (null == defaultDomain) { + throw new RuntimeException("'defaultDomain' must be set!"); + } + if (null == apiBase) { + throw new RuntimeException("'apiBase' must be set!"); + } + try { + URI uri = new URI(apiBase); + scheme = uri.getScheme(); + host = uri.getHost(); + port = uri.getPort(); + pathPrefix = uri.getPath(); + if (("https".equalsIgnoreCase(scheme) && 443 == port) || ("http".equalsIgnoreCase(scheme) && 80 == port)) { + port = null; + } + if ("/".equalsIgnoreCase(pathPrefix)) { + pathPrefix = null; + } + else if (pathPrefix.endsWith("/")) { + pathPrefix = pathPrefix.substring(0,pathPrefix.length()-1); + } + } + catch (URISyntaxException e) { + throw new RuntimeException("'apiBase' is invalid"); + } + } + + /** + * Create and initialize a GET request for the specified path + * + * @param path The path of the GET request + * @return A HttpGet object for the specified path + */ + HttpGet getRequest(String path) { + return enrich(new HttpGet(normalizePath(path))); + } + + /** + * Create an initialize a GET request for the specified URIBuilder + * + * @param uriBuilder The URIBuilder to work upon + * @return A HttGet object for the specified URIBuilder's URI + * @throws URISyntaxException Throw if URI cannot be built from the supplied URIBuilder + */ + HttpGet getRequest(URIBuilder uriBuilder) throws URISyntaxException { + return enrich(new HttpGet(normalize(uriBuilder))); + } + + /** + * Create and initialize a POST request for the specified path + * + * @param path The path of the POST request + * @return A HttpGet object for the specified path + */ + HttpPost postRequest(String path) { + return enrich(new HttpPost(normalizePath(path))); + } + + /** + * Create and initialize a PUT request for the specified path + * + * @param path The path of the PUT request + * @return A HttpGet object for the specified path + */ + HttpPut putRequest(String path) { + return enrich(new HttpPut(normalizePath(path))); + } + + /** + * Create and initialize a DELETE request for the specified path + * + * @param path The path of the DELETE request + * @return A HttpGet object for the specified path + */ + HttpDelete deleteRequest(String path) { + return enrich(new HttpDelete(normalizePath(path))); + } + + /** + * Helper method to normalize a supplied path; + * the current implementation only append a '/' if none is present and prefix with API Base + * + * @param path The path to normalize + * @return The normalized path + */ + protected String normalizePath(String path) { + if (!path.startsWith("/")) { + path = "/" + path; + } + return apiBase + path; + } + + /** + * Helper method to normalize a supplied path; + * the current implementation will set scheme, host, port and prefix with pathPrefix if present + * + * @param uriBuilder The URIBuilder to work upon + * @return A normalized path with defaults set if necessary + * @throws URISyntaxException Throw if the URL cannot be built + */ + protected String normalize(URIBuilder uriBuilder) throws URISyntaxException { + if (null == uriBuilder.getHost() || null == uriBuilder.getScheme()) { + uriBuilder.setHost(host); + uriBuilder.setScheme(scheme); + if (null != port) { + uriBuilder.setPort(port); + } + if (null != pathPrefix) { + uriBuilder.setPath(pathPrefix + uriBuilder.getPath()); + } + } + return uriBuilder.build().toString(); + } + + /** + * Enrich a HttpRequest with some default stuff; + * the current implementation does nothing here + * + * @param request The request to enrich + * @param Generic method to handle different types of HttpRequests + * @return The supplied HttpRequest object + */ + protected T enrich(T request) { + return request; + } + + /** + * Execute a HttpRequest and handle common response states. + * + * @param request The HttpRequest to execute + * @param typeReference The type of the expected response + * @param Generic method to request different response data + * @return The response data for the request + * @throws NotFoundException This exception is thrown when a 404 status code is encountered on the response + */ + protected T execute(HttpRequestBase request, TypeReference typeReference) { + try { + if (null == request.getHeaders(HttpHeaders.ACCEPT_LANGUAGE)) { + request.addHeader(HttpHeaders.ACCEPT_LANGUAGE,defaultDomain.getLocale()); + } + HttpResponse httpResponse = httpClient.execute(request); + if (200 == httpResponse.getStatusLine().getStatusCode()) { + return objectMapper.readValue(httpResponse.getEntity().getContent(),typeReference); + } + else { + throw new RuntimeException("StatusCode: "+httpResponse.getStatusLine().getStatusCode() + ", Reason: " + httpResponse.getStatusLine().getReasonPhrase()); + } + } + catch (IOException e) { + logger.error(e.getMessage(), e); + throw new RuntimeException(e); + } + finally { + if (null != request && !request.isAborted()) { + request.abort(); + } + } + } + + protected static abstract class Init> { + + protected S service; + + protected Init(S service) { + this.service = service; + } + + public B withHttpClient(HttpClient httpClient) { + service.setHttpClient(httpClient); + return self(); + } + + public B withObjectMapper(ObjectMapper objectMapper) { + service.setObjectMapper(objectMapper); + return self(); + } + + public B withApiBase(String apiBase) { + service.setApiBase(apiBase); + return self(); + } + + public B withDefaultDomain(Domain defaultDomain) { + service.setDefaultDomain(defaultDomain); + return self(); + } + + protected void onBuild() { + service.postConstruct(); + } + + protected abstract B self(); + + public abstract I build(); + } +} diff --git a/src/main/java/io/sprucehill/zalando/api/nativecart/service/AddressService.java b/src/main/java/io/sprucehill/zalando/api/nativecart/service/AddressService.java new file mode 100644 index 0000000..19e6480 --- /dev/null +++ b/src/main/java/io/sprucehill/zalando/api/nativecart/service/AddressService.java @@ -0,0 +1,76 @@ +package io.sprucehill.zalando.api.nativecart.service; + +import java.io.UnsupportedEncodingException; +import javax.annotation.PostConstruct; +import org.apache.http.client.methods.HttpGet; +import org.apache.http.client.methods.HttpPost; +import org.apache.http.entity.StringEntity; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.core.type.TypeReference; +import io.sprucehill.zalando.api.nativecart.model.AddressCheckRequest; +import io.sprucehill.zalando.api.nativecart.model.AddressCheckResponse; +import io.sprucehill.zalando.api.nativecart.model.CreateAddressRequest; +import io.sprucehill.zalando.api.nativecart.model.CreateAddressResponse; +import io.sprucehill.zalando.api.nativecart.model.GetAddressResponse; +import io.sprucehill.zalando.api.nativecart.model.GetAddressesResponse; +import io.sprucehill.zalando.api.nativecart.model.UpdateAddressRequest; +import io.sprucehill.zalando.api.nativecart.model.UpdateAddressResponse; + +/** + * + * @author dipteewarudkar + * + */ +public class AddressService extends AbstractService implements IAddressService{ + + @PostConstruct + @Override + public void postConstruct() { + super.postConstruct(); + } + + @Override + public GetAddressesResponse read(String customer_number) { + HttpGet request = getRequest("/customers/" + customer_number +"/addresses"); + return execute(request, new TypeReference() {}); + } + + @Override + public GetAddressResponse read(String customer_number, String address_id) { + HttpGet request = getRequest("/customers/" + customer_number +"/addresses/"+address_id); + return execute(request, new TypeReference() {}); + } + + @Override + public UpdateAddressResponse update(String customer_number, String address_id, UpdateAddressRequest updateAddressRequest) { + HttpPost request = postRequest("/customers/" + customer_number +"/addresses"); + + try { + request.setEntity(new StringEntity(objectMapper.writeValueAsString(updateAddressRequest))); + } catch (UnsupportedEncodingException e) { + e.printStackTrace(); + } catch (JsonProcessingException e) { + e.printStackTrace(); + } + return execute(request, new TypeReference() {}); + } + + @Override + public CreateAddressResponse create(String customer_number, CreateAddressRequest createAddressRequest) { + HttpGet request = getRequest("/customers/" + customer_number+"/addresses"); + return execute(request, new TypeReference() {}); + } + + @Override + public AddressCheckResponse checkAddress(AddressCheckRequest checkAddressRequest) { + HttpPost request = postRequest("/addresses"); + try { + request.setEntity(new StringEntity(objectMapper.writeValueAsString(checkAddressRequest))); + } catch (UnsupportedEncodingException e) { + e.printStackTrace(); + } catch (JsonProcessingException e) { + e.printStackTrace(); + } + return execute(request, new TypeReference() {}); + } +} diff --git a/src/main/java/io/sprucehill/zalando/api/nativecart/service/IAddressService.java b/src/main/java/io/sprucehill/zalando/api/nativecart/service/IAddressService.java new file mode 100644 index 0000000..878693f --- /dev/null +++ b/src/main/java/io/sprucehill/zalando/api/nativecart/service/IAddressService.java @@ -0,0 +1,46 @@ +package io.sprucehill.zalando.api.nativecart.service; + +import io.sprucehill.zalando.api.nativecart.model.AddressCheckRequest; +import io.sprucehill.zalando.api.nativecart.model.AddressCheckResponse; +import io.sprucehill.zalando.api.nativecart.model.CreateAddressRequest; +import io.sprucehill.zalando.api.nativecart.model.CreateAddressResponse; +import io.sprucehill.zalando.api.nativecart.model.GetAddressResponse; +import io.sprucehill.zalando.api.nativecart.model.GetAddressesResponse; +import io.sprucehill.zalando.api.nativecart.model.UpdateAddressRequest; +import io.sprucehill.zalando.api.nativecart.model.UpdateAddressResponse; + +public interface IAddressService { + AddressCheckResponse checkAddress(AddressCheckRequest checkAddressRequest); + + /** + * + * @param customer_number + * @return + */ + GetAddressesResponse read(String customer_number) ; + + /** + * + * @param customer_number + * @param address_id + * @return + */ + GetAddressResponse read(String customer_number,String address_id) ; + + /** + * + * @param customer_number + * @param address_id + * @param request + * @return + */ + UpdateAddressResponse update(String customer_number,String address_id,UpdateAddressRequest request); + + /** + * + * @param customer_number + * @param createAddressRequest + * @return + */ + CreateAddressResponse create(String customer_number,CreateAddressRequest createAddressRequest); +} From c7751efcbeebdcdbfa960032d14733801537fe95 Mon Sep 17 00:00:00 2001 From: Diptee Warudkar Date: Wed, 2 Mar 2016 10:30:04 +0100 Subject: [PATCH 02/24] Fixing GetAddressesResponse structure --- .../zalando/api/nativecart/model/GetAddressesResponse.java | 6 +++--- .../zalando/api/nativecart/model/UpdateAddressResponse.java | 2 +- .../zalando/api/nativecart/service/IAddressService.java | 5 +++++ 3 files changed, 9 insertions(+), 4 deletions(-) diff --git a/src/main/java/io/sprucehill/zalando/api/nativecart/model/GetAddressesResponse.java b/src/main/java/io/sprucehill/zalando/api/nativecart/model/GetAddressesResponse.java index 054fce9..cb5ddb1 100644 --- a/src/main/java/io/sprucehill/zalando/api/nativecart/model/GetAddressesResponse.java +++ b/src/main/java/io/sprucehill/zalando/api/nativecart/model/GetAddressesResponse.java @@ -9,13 +9,13 @@ */ public class GetAddressesResponse extends Base { - List addresses; + List addresses; - public List getAddresses() { + public List getAddresses() { return addresses; } - public void setAddresses(List addresses) { + public void setAddresses(List addresses) { this.addresses = addresses; } diff --git a/src/main/java/io/sprucehill/zalando/api/nativecart/model/UpdateAddressResponse.java b/src/main/java/io/sprucehill/zalando/api/nativecart/model/UpdateAddressResponse.java index 219bfa2..865fdc5 100644 --- a/src/main/java/io/sprucehill/zalando/api/nativecart/model/UpdateAddressResponse.java +++ b/src/main/java/io/sprucehill/zalando/api/nativecart/model/UpdateAddressResponse.java @@ -5,6 +5,6 @@ * @author dipteewarudkar * */ -public class UpdateAddressResponse extends Base{ +public class UpdateAddressResponse extends Address{ } diff --git a/src/main/java/io/sprucehill/zalando/api/nativecart/service/IAddressService.java b/src/main/java/io/sprucehill/zalando/api/nativecart/service/IAddressService.java index 878693f..42e5270 100644 --- a/src/main/java/io/sprucehill/zalando/api/nativecart/service/IAddressService.java +++ b/src/main/java/io/sprucehill/zalando/api/nativecart/service/IAddressService.java @@ -9,6 +9,11 @@ import io.sprucehill.zalando.api.nativecart.model.UpdateAddressRequest; import io.sprucehill.zalando.api.nativecart.model.UpdateAddressResponse; +/** + * + * @author dipteewarudkar + * + */ public interface IAddressService { AddressCheckResponse checkAddress(AddressCheckRequest checkAddressRequest); From e9810242e767e6808be40ee7dedff394fb16db59 Mon Sep 17 00:00:00 2001 From: Diptee Warudkar Date: Wed, 2 Mar 2016 10:41:59 +0100 Subject: [PATCH 03/24] Fixing build warnings --- .../nativecart/service/IAddressService.java | 29 +++++++++++-------- 1 file changed, 17 insertions(+), 12 deletions(-) diff --git a/src/main/java/io/sprucehill/zalando/api/nativecart/service/IAddressService.java b/src/main/java/io/sprucehill/zalando/api/nativecart/service/IAddressService.java index 42e5270..02d1c70 100644 --- a/src/main/java/io/sprucehill/zalando/api/nativecart/service/IAddressService.java +++ b/src/main/java/io/sprucehill/zalando/api/nativecart/service/IAddressService.java @@ -15,37 +15,42 @@ * */ public interface IAddressService { + /** + * + * @param checkAddressRequest The address object to be checked + * @return The address object with normalized address + */ AddressCheckResponse checkAddress(AddressCheckRequest checkAddressRequest); /** * - * @param customer_number - * @return + * @param customer_number The customer unique id + * @return The list of user addresses */ GetAddressesResponse read(String customer_number) ; /** * - * @param customer_number - * @param address_id - * @return + * @param customer_number The customer unique id + * @param address_id The ID of the address to read + * @return The address with the requested ID for the specified customer */ GetAddressResponse read(String customer_number,String address_id) ; /** * - * @param customer_number - * @param address_id - * @param request - * @return + * @param customer_number The customer unique id + * @param address_id The ID of the address to update + * @param request The address object to update + * @return The updated address object */ UpdateAddressResponse update(String customer_number,String address_id,UpdateAddressRequest request); /** * - * @param customer_number - * @param createAddressRequest - * @return + * @param customer_number The customer unique id + * @param createAddressRequest The address object to create + * @return Newly created address object */ CreateAddressResponse create(String customer_number,CreateAddressRequest createAddressRequest); } From d76ea5e7f0ef2955fdc115b8d38c850c6b4ca95d Mon Sep 17 00:00:00 2001 From: Diptee Warudkar Date: Wed, 2 Mar 2016 12:11:05 +0100 Subject: [PATCH 04/24] Fixing update address to http PUT request --- .../zalando/api/nativecart/service/AddressService.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/main/java/io/sprucehill/zalando/api/nativecart/service/AddressService.java b/src/main/java/io/sprucehill/zalando/api/nativecart/service/AddressService.java index 19e6480..29297d5 100644 --- a/src/main/java/io/sprucehill/zalando/api/nativecart/service/AddressService.java +++ b/src/main/java/io/sprucehill/zalando/api/nativecart/service/AddressService.java @@ -4,6 +4,7 @@ import javax.annotation.PostConstruct; import org.apache.http.client.methods.HttpGet; import org.apache.http.client.methods.HttpPost; +import org.apache.http.client.methods.HttpPut; import org.apache.http.entity.StringEntity; import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.core.type.TypeReference; @@ -43,7 +44,7 @@ public GetAddressResponse read(String customer_number, String address_id) { @Override public UpdateAddressResponse update(String customer_number, String address_id, UpdateAddressRequest updateAddressRequest) { - HttpPost request = postRequest("/customers/" + customer_number +"/addresses"); + HttpPut request = putRequest("/customers/" + customer_number +"/addresses"); try { request.setEntity(new StringEntity(objectMapper.writeValueAsString(updateAddressRequest))); From d0b45de83e0aa6d74974101a90203dbfad882955 Mon Sep 17 00:00:00 2001 From: Diptee Warudkar Date: Wed, 2 Mar 2016 13:21:36 +0100 Subject: [PATCH 05/24] Adding wrapper for zalando Api for Cart checkout order customer --- .../zalando/api/nativecart/model/Cart.java | 68 ++++++++++++++++ .../api/nativecart/model/Checkout.java | 70 ++++++++++++++++ .../nativecart/model/CreateCartRequest.java | 15 ++++ .../nativecart/model/CreateCartResponse.java | 11 +++ .../model/CreateCheckoutRequest.java | 14 ++++ .../model/CreateCheckoutResponse.java | 5 ++ .../nativecart/model/CreateOrderRequest.java | 18 +++++ .../nativecart/model/CreateOrderResponse.java | 10 +++ .../api/nativecart/model/Delivery.java | 28 +++++++ .../api/nativecart/model/GetCartResponse.java | 63 +++++++++++++++ .../nativecart/model/GetCheckoutResponse.java | 10 +++ .../nativecart/model/GetCustomerResponse.java | 38 +++++++++ .../zalando/api/nativecart/model/Items.java | 28 +++++++ .../zalando/api/nativecart/model/Money.java | 30 +++++++ .../zalando/api/nativecart/model/Order.java | 81 +++++++++++++++++++ .../zalando/api/nativecart/model/Payment.java | 50 ++++++++++++ .../model/UpdateCartItemsRequest.java | 15 ++++ .../model/UpdateCartItemsResponse.java | 10 +++ .../model/UpdateCheckoutRequest.java | 14 ++++ .../model/UpdateCheckoutRespone.java | 5 ++ .../nativecart/service/AbstractService.java | 2 - .../api/nativecart/service/CartService.java | 62 ++++++++++++++ .../nativecart/service/CheckoutService.java | 57 +++++++++++++ .../nativecart/service/CustomerService.java | 19 +++++ .../api/nativecart/service/ICartService.java | 40 +++++++++ .../nativecart/service/ICheckoutService.java | 41 ++++++++++ .../nativecart/service/ICustomerService.java | 18 +++++ .../api/nativecart/service/IOrderService.java | 21 +++++ .../api/nativecart/service/OrderService.java | 31 +++++++ 29 files changed, 872 insertions(+), 2 deletions(-) create mode 100644 src/main/java/io/sprucehill/zalando/api/nativecart/model/Cart.java create mode 100644 src/main/java/io/sprucehill/zalando/api/nativecart/model/Checkout.java create mode 100644 src/main/java/io/sprucehill/zalando/api/nativecart/model/CreateCartRequest.java create mode 100644 src/main/java/io/sprucehill/zalando/api/nativecart/model/CreateCartResponse.java create mode 100644 src/main/java/io/sprucehill/zalando/api/nativecart/model/CreateCheckoutRequest.java create mode 100644 src/main/java/io/sprucehill/zalando/api/nativecart/model/CreateCheckoutResponse.java create mode 100644 src/main/java/io/sprucehill/zalando/api/nativecart/model/CreateOrderRequest.java create mode 100644 src/main/java/io/sprucehill/zalando/api/nativecart/model/CreateOrderResponse.java create mode 100644 src/main/java/io/sprucehill/zalando/api/nativecart/model/Delivery.java create mode 100644 src/main/java/io/sprucehill/zalando/api/nativecart/model/GetCartResponse.java create mode 100644 src/main/java/io/sprucehill/zalando/api/nativecart/model/GetCheckoutResponse.java create mode 100644 src/main/java/io/sprucehill/zalando/api/nativecart/model/GetCustomerResponse.java create mode 100644 src/main/java/io/sprucehill/zalando/api/nativecart/model/Items.java create mode 100644 src/main/java/io/sprucehill/zalando/api/nativecart/model/Money.java create mode 100644 src/main/java/io/sprucehill/zalando/api/nativecart/model/Order.java create mode 100644 src/main/java/io/sprucehill/zalando/api/nativecart/model/Payment.java create mode 100644 src/main/java/io/sprucehill/zalando/api/nativecart/model/UpdateCartItemsRequest.java create mode 100644 src/main/java/io/sprucehill/zalando/api/nativecart/model/UpdateCartItemsResponse.java create mode 100644 src/main/java/io/sprucehill/zalando/api/nativecart/model/UpdateCheckoutRequest.java create mode 100644 src/main/java/io/sprucehill/zalando/api/nativecart/model/UpdateCheckoutRespone.java create mode 100644 src/main/java/io/sprucehill/zalando/api/nativecart/service/CartService.java create mode 100644 src/main/java/io/sprucehill/zalando/api/nativecart/service/CheckoutService.java create mode 100644 src/main/java/io/sprucehill/zalando/api/nativecart/service/CustomerService.java create mode 100644 src/main/java/io/sprucehill/zalando/api/nativecart/service/ICartService.java create mode 100644 src/main/java/io/sprucehill/zalando/api/nativecart/service/ICheckoutService.java create mode 100644 src/main/java/io/sprucehill/zalando/api/nativecart/service/ICustomerService.java create mode 100644 src/main/java/io/sprucehill/zalando/api/nativecart/service/IOrderService.java create mode 100644 src/main/java/io/sprucehill/zalando/api/nativecart/service/OrderService.java diff --git a/src/main/java/io/sprucehill/zalando/api/nativecart/model/Cart.java b/src/main/java/io/sprucehill/zalando/api/nativecart/model/Cart.java new file mode 100644 index 0000000..3130321 --- /dev/null +++ b/src/main/java/io/sprucehill/zalando/api/nativecart/model/Cart.java @@ -0,0 +1,68 @@ +package io.sprucehill.zalando.api.nativecart.model; + +import java.util.ArrayList; +import java.util.List; + +import com.fasterxml.jackson.annotation.JsonProperty; + +public abstract class Cart extends Base{ + @JsonProperty + private String id ; + @JsonProperty + private String appDomainId ; + @JsonProperty + private List items = new ArrayList(); + @JsonProperty + private List itemsOutOfStock = new ArrayList(); + @JsonProperty + private Delivery delivery ; + @JsonProperty + private Money grossTotal ; + @JsonProperty + private Money taxTotal ; + @JsonProperty + private String cartUrl; + + public Cart(){} + + public Cart(String id,String appDomainId ,List items,List itemsOutOfStock,Delivery delivery, + Money grossTotal,Money taxTotal,String cartUrl){ + this.id =id; + this.appDomainId=appDomainId; + this.items =items; + this.itemsOutOfStock =itemsOutOfStock; + this.delivery =delivery; + this.grossTotal =grossTotal; + this.taxTotal= taxTotal; + this.cartUrl=cartUrl; + + } + + public String getId() { + return id; + } + public String getAppDomainId() { + return appDomainId; + } + public List getItems() { + return items; + } + public List getItemsOutOfStock() { + return itemsOutOfStock; + } + public Delivery getDelivery() { + return delivery; + } + public Money getGrossTotal() { + return grossTotal; + } + public Money getTaxTotal() { + return taxTotal; + } + public String getCartUrl() { + return cartUrl; + } + + + +} diff --git a/src/main/java/io/sprucehill/zalando/api/nativecart/model/Checkout.java b/src/main/java/io/sprucehill/zalando/api/nativecart/model/Checkout.java new file mode 100644 index 0000000..78b01b9 --- /dev/null +++ b/src/main/java/io/sprucehill/zalando/api/nativecart/model/Checkout.java @@ -0,0 +1,70 @@ +package io.sprucehill.zalando.api.nativecart.model; + +import java.util.HashMap; +import java.util.Map; + +import com.fasterxml.jackson.annotation.JsonProperty; + +/** + * + * @author dipteewarudkar + * + */ +public abstract class Checkout extends Base{ + @JsonProperty + private String id; + @JsonProperty + private String customer_number; + @JsonProperty + private String cart_id; + @JsonProperty + private String billing_address_id; + @JsonProperty + private String shipping_address_id; + @JsonProperty + private Delivery delivery; + @JsonProperty + private Payment payment; + + public Checkout(){} + + public Checkout(String id,String customer_number,String cart_id, String billing_address_id,String shipping_address_id,Delivery delivery,Payment payment){ + this.id=id; + this.customer_number=customer_number; + this.cart_id=cart_id; + this.billing_address_id=billing_address_id; + this.shipping_address_id=shipping_address_id; + this.delivery=delivery; + this.payment=payment; + } + + + + public String getId() { + return id; + } + + public String getCustomer_number() { + return customer_number; + } + + public String getCart_id() { + return cart_id; + } + + public String getBilling_address_id() { + return billing_address_id; + } + + public String getShipping_address_id() { + return shipping_address_id; + } + + public Delivery getDelivery() { + return delivery; + } + + public Payment getPayment() { + return payment; + } +} diff --git a/src/main/java/io/sprucehill/zalando/api/nativecart/model/CreateCartRequest.java b/src/main/java/io/sprucehill/zalando/api/nativecart/model/CreateCartRequest.java new file mode 100644 index 0000000..f0c10ad --- /dev/null +++ b/src/main/java/io/sprucehill/zalando/api/nativecart/model/CreateCartRequest.java @@ -0,0 +1,15 @@ +package io.sprucehill.zalando.api.nativecart.model; + +import java.util.List; + +/** + * + * @author dipteewarudkar + * + */ +public class CreateCartRequest extends Cart{ + + public CreateCartRequest(String appDomainId,List items){ + super(null,appDomainId,items,null,null,null,null,null); + } +} diff --git a/src/main/java/io/sprucehill/zalando/api/nativecart/model/CreateCartResponse.java b/src/main/java/io/sprucehill/zalando/api/nativecart/model/CreateCartResponse.java new file mode 100644 index 0000000..256ddc5 --- /dev/null +++ b/src/main/java/io/sprucehill/zalando/api/nativecart/model/CreateCartResponse.java @@ -0,0 +1,11 @@ +package io.sprucehill.zalando.api.nativecart.model; + + +/** + * + * @author dipteewarudkar + * + */ +public class CreateCartResponse extends Cart { + +} diff --git a/src/main/java/io/sprucehill/zalando/api/nativecart/model/CreateCheckoutRequest.java b/src/main/java/io/sprucehill/zalando/api/nativecart/model/CreateCheckoutRequest.java new file mode 100644 index 0000000..9b97d1f --- /dev/null +++ b/src/main/java/io/sprucehill/zalando/api/nativecart/model/CreateCheckoutRequest.java @@ -0,0 +1,14 @@ +package io.sprucehill.zalando.api.nativecart.model; + +/** + * + * @author dipteewarudkar + * + */ +public class CreateCheckoutRequest extends Checkout { + public CreateCheckoutRequest(String cart_id,String billing_address_id,String shipping_address_id,Payment payment){ + super(null,null,cart_id,billing_address_id,shipping_address_id,null,payment); + } + +} + diff --git a/src/main/java/io/sprucehill/zalando/api/nativecart/model/CreateCheckoutResponse.java b/src/main/java/io/sprucehill/zalando/api/nativecart/model/CreateCheckoutResponse.java new file mode 100644 index 0000000..480278a --- /dev/null +++ b/src/main/java/io/sprucehill/zalando/api/nativecart/model/CreateCheckoutResponse.java @@ -0,0 +1,5 @@ +package io.sprucehill.zalando.api.nativecart.model; + +public class CreateCheckoutResponse extends Checkout{ + +} diff --git a/src/main/java/io/sprucehill/zalando/api/nativecart/model/CreateOrderRequest.java b/src/main/java/io/sprucehill/zalando/api/nativecart/model/CreateOrderRequest.java new file mode 100644 index 0000000..f7e9fbc --- /dev/null +++ b/src/main/java/io/sprucehill/zalando/api/nativecart/model/CreateOrderRequest.java @@ -0,0 +1,18 @@ +package io.sprucehill.zalando.api.nativecart.model; + +import com.fasterxml.jackson.annotation.JsonProperty; + +public class CreateOrderRequest extends Base{ + + @JsonProperty + private String checkout_id; + + public String getCheckout_id() { + return checkout_id; + } + + public void setCheckout_id(String checkout_id) { + this.checkout_id = checkout_id; + } + +} diff --git a/src/main/java/io/sprucehill/zalando/api/nativecart/model/CreateOrderResponse.java b/src/main/java/io/sprucehill/zalando/api/nativecart/model/CreateOrderResponse.java new file mode 100644 index 0000000..3f0b1b0 --- /dev/null +++ b/src/main/java/io/sprucehill/zalando/api/nativecart/model/CreateOrderResponse.java @@ -0,0 +1,10 @@ +package io.sprucehill.zalando.api.nativecart.model; + +/** + * + * @author dipteewarudkar + * + */ +public class CreateOrderResponse extends Order{ + +} diff --git a/src/main/java/io/sprucehill/zalando/api/nativecart/model/Delivery.java b/src/main/java/io/sprucehill/zalando/api/nativecart/model/Delivery.java new file mode 100644 index 0000000..1f12b5f --- /dev/null +++ b/src/main/java/io/sprucehill/zalando/api/nativecart/model/Delivery.java @@ -0,0 +1,28 @@ +package io.sprucehill.zalando.api.nativecart.model; + +import com.fasterxml.jackson.annotation.JsonProperty; + +/** + * + * @author dipteewarudkar + * + */ +public class Delivery extends Base{ + @JsonProperty + private String earliest; + @JsonProperty + private String latest; + public String getEarliest() { + return earliest; + } + public void setEarliest(String earliest) { + this.earliest = earliest; + } + public String getLatest() { + return latest; + } + public void setLatest(String latest) { + this.latest = latest; + } + +} diff --git a/src/main/java/io/sprucehill/zalando/api/nativecart/model/GetCartResponse.java b/src/main/java/io/sprucehill/zalando/api/nativecart/model/GetCartResponse.java new file mode 100644 index 0000000..3e74f12 --- /dev/null +++ b/src/main/java/io/sprucehill/zalando/api/nativecart/model/GetCartResponse.java @@ -0,0 +1,63 @@ +package io.sprucehill.zalando.api.nativecart.model; + +import java.util.ArrayList; +import java.util.List; + +public class GetCartResponse extends Base{ + private String id = null; + private String appDomainId = null; + private List items = new ArrayList(); + private List itemsOutOfStock = new ArrayList(); + private Delivery delivery = null; + private Money grossTotal = null; + private Money taxTotal = null; + private String cartUrl = null; + public String getId() { + return id; + } + public void setId(String id) { + this.id = id; + } + public String getAppDomainId() { + return appDomainId; + } + public void setAppDomainId(String appDomainId) { + this.appDomainId = appDomainId; + } + public List getItems() { + return items; + } + public void setItems(List items) { + this.items = items; + } + public List getItemsOutOfStock() { + return itemsOutOfStock; + } + public void setItemsOutOfStock(List itemsOutOfStock) { + this.itemsOutOfStock = itemsOutOfStock; + } + public Delivery getDelivery() { + return delivery; + } + public void setDelivery(Delivery delivery) { + this.delivery = delivery; + } + public Money getGrossTotal() { + return grossTotal; + } + public void setGrossTotal(Money grossTotal) { + this.grossTotal = grossTotal; + } + public Money getTaxTotal() { + return taxTotal; + } + public void setTaxTotal(Money taxTotal) { + this.taxTotal = taxTotal; + } + public String getCartUrl() { + return cartUrl; + } + public void setCartUrl(String cartUrl) { + this.cartUrl = cartUrl; + } +} diff --git a/src/main/java/io/sprucehill/zalando/api/nativecart/model/GetCheckoutResponse.java b/src/main/java/io/sprucehill/zalando/api/nativecart/model/GetCheckoutResponse.java new file mode 100644 index 0000000..31ca4af --- /dev/null +++ b/src/main/java/io/sprucehill/zalando/api/nativecart/model/GetCheckoutResponse.java @@ -0,0 +1,10 @@ +package io.sprucehill.zalando.api.nativecart.model; + +/** + * + * @author dipteewarudkar + * + */ +public class GetCheckoutResponse extends Checkout{ + +} diff --git a/src/main/java/io/sprucehill/zalando/api/nativecart/model/GetCustomerResponse.java b/src/main/java/io/sprucehill/zalando/api/nativecart/model/GetCustomerResponse.java new file mode 100644 index 0000000..0614e09 --- /dev/null +++ b/src/main/java/io/sprucehill/zalando/api/nativecart/model/GetCustomerResponse.java @@ -0,0 +1,38 @@ +package io.sprucehill.zalando.api.nativecart.model; + +import com.fasterxml.jackson.annotation.JsonProperty; + +/** + * + * @author dipteewarudkar + * + */ +public class GetCustomerResponse extends Base { + + @JsonProperty + private String customer_number; + @JsonProperty + private String gender; + @JsonProperty + private String first_name; + @JsonProperty + private String last_name; + @JsonProperty + private String email; + + public String getCustomer_number() { + return customer_number; + } + public String getGender() { + return gender; + } + public String getFirst_name() { + return first_name; + } + public String getLast_name() { + return last_name; + } + public String getEmail() { + return email; + } +} diff --git a/src/main/java/io/sprucehill/zalando/api/nativecart/model/Items.java b/src/main/java/io/sprucehill/zalando/api/nativecart/model/Items.java new file mode 100644 index 0000000..0da7a0e --- /dev/null +++ b/src/main/java/io/sprucehill/zalando/api/nativecart/model/Items.java @@ -0,0 +1,28 @@ +package io.sprucehill.zalando.api.nativecart.model; + +import com.fasterxml.jackson.annotation.JsonProperty; + +/** + * + * @author dipteewarudkar + * + */ +public class Items extends Base{ + @JsonProperty + private String sku; + @JsonProperty + private Integer quantity; + public Integer getQuantity() { + return quantity; + } + public void setQuantity(Integer quantity) { + this.quantity = quantity; + } + public String getSku() { + return sku; + } + public void setSku(String sku) { + this.sku = sku; + } + +} diff --git a/src/main/java/io/sprucehill/zalando/api/nativecart/model/Money.java b/src/main/java/io/sprucehill/zalando/api/nativecart/model/Money.java new file mode 100644 index 0000000..af8ad6c --- /dev/null +++ b/src/main/java/io/sprucehill/zalando/api/nativecart/model/Money.java @@ -0,0 +1,30 @@ +package io.sprucehill.zalando.api.nativecart.model; + +import java.math.BigInteger; + +import com.fasterxml.jackson.annotation.JsonProperty; + +/** + * + * @author dipteewarudkar + * + */ +public class Money extends Base{ + @JsonProperty + private BigInteger amount; + @JsonProperty + private String currency; + public String getCurrency() { + return currency; + } + public void setCurrency(String currency) { + this.currency = currency; + } + public BigInteger getAmount() { + return amount; + } + public void setAmount(BigInteger amount) { + this.amount = amount; + } + +} diff --git a/src/main/java/io/sprucehill/zalando/api/nativecart/model/Order.java b/src/main/java/io/sprucehill/zalando/api/nativecart/model/Order.java new file mode 100644 index 0000000..f0d0f51 --- /dev/null +++ b/src/main/java/io/sprucehill/zalando/api/nativecart/model/Order.java @@ -0,0 +1,81 @@ +package io.sprucehill.zalando.api.nativecart.model; + +import com.fasterxml.jackson.annotation.JsonProperty; + +/** + * + * @author dipteewarudkar + * + */ +public abstract class Order extends Base{ + @JsonProperty + private String order_number; + @JsonProperty + private String customer_number; + @JsonProperty + private Address billing_address ; + @JsonProperty + private Address shipping_address; + @JsonProperty + private Delivery delivery; + @JsonProperty + private Money gross_total; + @JsonProperty + private Money tax_total; + @JsonProperty + private String created; + @JsonProperty + private String detail_url; + @JsonProperty + private String external_payment_url; + + public Order(){} + + public Order(String order_number,String customer_number,Address billing_address,Address shipping_address,Delivery delivery, + Money gross_total,Money tax_total,String created,String detail_url,String external_payment_url){ + this.order_number=order_number; + this.customer_number=customer_number; + this.billing_address=billing_address; + this.shipping_address=shipping_address; + this.delivery=delivery; + this.gross_total=gross_total; + this.tax_total=tax_total; + this.created=created; + this.detail_url=detail_url; + this.external_payment_url=external_payment_url; + } + + + public String getOrder_number() { + return order_number; + } + public String getCustomer_number() { + return customer_number; + } + public Address getBilling_address() { + return billing_address; + } + public Address getShipping_address() { + return shipping_address; + } + public Delivery getDelivery() { + return delivery; + } + public Money getGross_total() { + return gross_total; + } + public Money getTax_total() { + return tax_total; + } + public String getCreated() { + return created; + } + public String getDetail_url() { + return detail_url; + } + public String getExternal_payment_url() { + return external_payment_url; + } + + +} diff --git a/src/main/java/io/sprucehill/zalando/api/nativecart/model/Payment.java b/src/main/java/io/sprucehill/zalando/api/nativecart/model/Payment.java new file mode 100644 index 0000000..1ed26fd --- /dev/null +++ b/src/main/java/io/sprucehill/zalando/api/nativecart/model/Payment.java @@ -0,0 +1,50 @@ +package io.sprucehill.zalando.api.nativecart.model; + +import java.util.HashMap; +import java.util.Map; + +import com.fasterxml.jackson.annotation.JsonProperty; + +/** + * + * @author dipteewarudkar + * + */ +public class Payment extends Base{ + @JsonProperty + private String callback_url; + @JsonProperty + private Map templateParameters = new HashMap(); + @JsonProperty + private String selection_page_url; + @JsonProperty + private Selected selected; + + public String getCallback_url() { + return callback_url; + } + public Map getTemplateParameters() { + return templateParameters; + } + public String getSelection_page_url() { + return selection_page_url; + } + public Selected getSelected() { + return selected; + } + + public static class Selected extends Base { + @JsonProperty + private String method; + @JsonProperty + private Map metadata = new HashMap(); + public String getMethod() { + return method; + } + public Map getMetadata() { + return metadata; + } + } + +} + diff --git a/src/main/java/io/sprucehill/zalando/api/nativecart/model/UpdateCartItemsRequest.java b/src/main/java/io/sprucehill/zalando/api/nativecart/model/UpdateCartItemsRequest.java new file mode 100644 index 0000000..a92099e --- /dev/null +++ b/src/main/java/io/sprucehill/zalando/api/nativecart/model/UpdateCartItemsRequest.java @@ -0,0 +1,15 @@ +package io.sprucehill.zalando.api.nativecart.model; + +import java.util.List; + +/** + * + * @author dipteewarudkar + * + */ +public class UpdateCartItemsRequest extends Cart{ + + public UpdateCartItemsRequest(List items){ + super(null,null,items,null,null,null,null,null); + } +} diff --git a/src/main/java/io/sprucehill/zalando/api/nativecart/model/UpdateCartItemsResponse.java b/src/main/java/io/sprucehill/zalando/api/nativecart/model/UpdateCartItemsResponse.java new file mode 100644 index 0000000..d8a43ea --- /dev/null +++ b/src/main/java/io/sprucehill/zalando/api/nativecart/model/UpdateCartItemsResponse.java @@ -0,0 +1,10 @@ +package io.sprucehill.zalando.api.nativecart.model; + +/** + * + * @author dipteewarudkar + * + */ +public class UpdateCartItemsResponse extends Cart { + +} diff --git a/src/main/java/io/sprucehill/zalando/api/nativecart/model/UpdateCheckoutRequest.java b/src/main/java/io/sprucehill/zalando/api/nativecart/model/UpdateCheckoutRequest.java new file mode 100644 index 0000000..9acf687 --- /dev/null +++ b/src/main/java/io/sprucehill/zalando/api/nativecart/model/UpdateCheckoutRequest.java @@ -0,0 +1,14 @@ +package io.sprucehill.zalando.api.nativecart.model; + +/** + * + * @author dipteewarudkar + * + */ +public class UpdateCheckoutRequest extends Checkout{ + + public UpdateCheckoutRequest(String billing_address_id,String shipping_address_id,Payment payment){ + super(null,null,null,billing_address_id,shipping_address_id,null,payment); + } + +} diff --git a/src/main/java/io/sprucehill/zalando/api/nativecart/model/UpdateCheckoutRespone.java b/src/main/java/io/sprucehill/zalando/api/nativecart/model/UpdateCheckoutRespone.java new file mode 100644 index 0000000..cc3e52f --- /dev/null +++ b/src/main/java/io/sprucehill/zalando/api/nativecart/model/UpdateCheckoutRespone.java @@ -0,0 +1,5 @@ +package io.sprucehill.zalando.api.nativecart.model; + +public class UpdateCheckoutRespone extends Checkout { + +} diff --git a/src/main/java/io/sprucehill/zalando/api/nativecart/service/AbstractService.java b/src/main/java/io/sprucehill/zalando/api/nativecart/service/AbstractService.java index 08850dd..724647d 100644 --- a/src/main/java/io/sprucehill/zalando/api/nativecart/service/AbstractService.java +++ b/src/main/java/io/sprucehill/zalando/api/nativecart/service/AbstractService.java @@ -2,7 +2,6 @@ import com.fasterxml.jackson.core.type.TypeReference; import com.fasterxml.jackson.databind.ObjectMapper; -import io.sprucehill.zalando.api.exception.NotFoundException; import io.sprucehill.zalando.api.model.Domain; import org.apache.http.HttpHeaders; import org.apache.http.HttpResponse; @@ -222,7 +221,6 @@ protected T enrich(T request) { * @param typeReference The type of the expected response * @param Generic method to request different response data * @return The response data for the request - * @throws NotFoundException This exception is thrown when a 404 status code is encountered on the response */ protected T execute(HttpRequestBase request, TypeReference typeReference) { try { diff --git a/src/main/java/io/sprucehill/zalando/api/nativecart/service/CartService.java b/src/main/java/io/sprucehill/zalando/api/nativecart/service/CartService.java new file mode 100644 index 0000000..863663d --- /dev/null +++ b/src/main/java/io/sprucehill/zalando/api/nativecart/service/CartService.java @@ -0,0 +1,62 @@ +package io.sprucehill.zalando.api.nativecart.service; + +import java.io.UnsupportedEncodingException; + +import org.apache.http.HttpHeaders; +import org.apache.http.client.methods.HttpGet; +import org.apache.http.client.methods.HttpPost; +import org.apache.http.client.methods.HttpPut; +import org.apache.http.entity.StringEntity; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.core.type.TypeReference; +import io.sprucehill.zalando.api.nativecart.model.CreateCartRequest; +import io.sprucehill.zalando.api.nativecart.model.CreateCartResponse; +import io.sprucehill.zalando.api.nativecart.model.GetCartResponse; +import io.sprucehill.zalando.api.nativecart.model.UpdateCartItemsRequest; + +/** + * + * @author dipteewarudkar + * + */ +public class CartService extends AbstractService implements ICartService{ + + @Override + public CreateCartResponse create(String access_token, CreateCartRequest createCartRequest) { + HttpPost request = postRequest("/carts"); + + try { + request.addHeader(HttpHeaders.AUTHORIZATION,"Bearer "+access_token); + request.setEntity(new StringEntity(objectMapper.writeValueAsString(createCartRequest))); + } catch (UnsupportedEncodingException e) { + e.printStackTrace(); + } catch (JsonProcessingException e) { + e.printStackTrace(); + } + return execute(request, new TypeReference() {}); + } + + + @Override + public GetCartResponse read(String access_token, String cart_id) { + HttpGet request = getRequest("/carts/" + cart_id); + request.addHeader(HttpHeaders.AUTHORIZATION,"Bearer "+access_token); + return execute(request, new TypeReference() {}); + } + + + @Override + public UpdateCartItemsRequest update(String access_token, String cart_id,UpdateCartItemsRequest updateCartRequest) { + HttpPut request = putRequest("/carts/"+cart_id); + + try { + request.addHeader(HttpHeaders.AUTHORIZATION,"Bearer "+access_token); + request.setEntity(new StringEntity(objectMapper.writeValueAsString(updateCartRequest))); + } catch (UnsupportedEncodingException e) { + e.printStackTrace(); + } catch (JsonProcessingException e) { + e.printStackTrace(); + } + return execute(request, new TypeReference() {}); + } +} diff --git a/src/main/java/io/sprucehill/zalando/api/nativecart/service/CheckoutService.java b/src/main/java/io/sprucehill/zalando/api/nativecart/service/CheckoutService.java new file mode 100644 index 0000000..4c363cc --- /dev/null +++ b/src/main/java/io/sprucehill/zalando/api/nativecart/service/CheckoutService.java @@ -0,0 +1,57 @@ +package io.sprucehill.zalando.api.nativecart.service; + +import java.io.UnsupportedEncodingException; +import org.apache.http.client.methods.HttpGet; +import org.apache.http.client.methods.HttpPost; +import org.apache.http.client.methods.HttpPut; +import org.apache.http.entity.StringEntity; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.core.type.TypeReference; +import io.sprucehill.zalando.api.nativecart.model.CreateCheckoutRequest; +import io.sprucehill.zalando.api.nativecart.model.CreateCheckoutResponse; +import io.sprucehill.zalando.api.nativecart.model.GetCheckoutResponse; +import io.sprucehill.zalando.api.nativecart.model.UpdateCheckoutRequest; +import io.sprucehill.zalando.api.nativecart.model.UpdateCheckoutRespone; + +/** + * + * @author dipteewarudkar + * + */ +public class CheckoutService extends AbstractService implements ICheckoutService{ + + @Override + public GetCheckoutResponse read(String customer_number, String checkout_id) { + HttpGet request = getRequest("/customer/"+customer_number+"/checkouts/"+checkout_id); + return execute(request, new TypeReference() {}); + } + + @Override + public CreateCheckoutResponse create(String customer_number, CreateCheckoutRequest createcheckoutRequest) { + HttpPost request = postRequest("/customer/"+customer_number+"/checkouts"); + + try { + request.setEntity(new StringEntity(objectMapper.writeValueAsString(createcheckoutRequest))); + } catch (UnsupportedEncodingException e) { + e.printStackTrace(); + } catch (JsonProcessingException e) { + e.printStackTrace(); + } + return execute(request, new TypeReference() {}); + } + + @Override + public UpdateCheckoutRespone update(String customer_number, String checkout_id,UpdateCheckoutRequest updateCheckoutRequest) { + HttpPut request = putRequest("/customer/"+customer_number+"/checkouts/"+checkout_id); + + try { + request.setEntity(new StringEntity(objectMapper.writeValueAsString(updateCheckoutRequest))); + } catch (UnsupportedEncodingException e) { + e.printStackTrace(); + } catch (JsonProcessingException e) { + e.printStackTrace(); + } + return execute(request, new TypeReference() {}); + } + +} diff --git a/src/main/java/io/sprucehill/zalando/api/nativecart/service/CustomerService.java b/src/main/java/io/sprucehill/zalando/api/nativecart/service/CustomerService.java new file mode 100644 index 0000000..6c05699 --- /dev/null +++ b/src/main/java/io/sprucehill/zalando/api/nativecart/service/CustomerService.java @@ -0,0 +1,19 @@ +package io.sprucehill.zalando.api.nativecart.service; + +import org.apache.http.client.methods.HttpGet; +import com.fasterxml.jackson.core.type.TypeReference; +import io.sprucehill.zalando.api.nativecart.model.GetCustomerResponse; + +/** + * + * @author dipteewarudkar + * + */ +public class CustomerService extends AbstractService implements ICustomerService{ + + @Override + public GetCustomerResponse read(String customer_number) { + HttpGet request = getRequest("/customers/" + customer_number); + return execute(request, new TypeReference() {}); + } +} diff --git a/src/main/java/io/sprucehill/zalando/api/nativecart/service/ICartService.java b/src/main/java/io/sprucehill/zalando/api/nativecart/service/ICartService.java new file mode 100644 index 0000000..0b78146 --- /dev/null +++ b/src/main/java/io/sprucehill/zalando/api/nativecart/service/ICartService.java @@ -0,0 +1,40 @@ +package io.sprucehill.zalando.api.nativecart.service; + +import io.sprucehill.zalando.api.nativecart.model.CreateCartRequest; +import io.sprucehill.zalando.api.nativecart.model.CreateCartResponse; +import io.sprucehill.zalando.api.nativecart.model.GetCartResponse; +import io.sprucehill.zalando.api.nativecart.model.UpdateCartItemsRequest; + +/** + * + * @author dipteewarudkar + * + */ +public interface ICartService { + + /** + * + * @param access_token access token for performing create cart operation + * @param createCartRequest The Cart object to be created + * @return Newly created cart object + */ + CreateCartResponse create(String access_token,CreateCartRequest createCartRequest); + + /** + * + * @param access_token access token for performing create cart operation + * @param cart_id The ID of the cart to read + * @return The cart with the requested ID for the specified access_token + */ + GetCartResponse read(String access_token,String cart_id); + + /** + * + * @param access_token + * @param cart_id + * @param updateCartRequest + * @return + */ + UpdateCartItemsRequest update(String access_token,String cart_id,UpdateCartItemsRequest updateCartRequest ); + +} diff --git a/src/main/java/io/sprucehill/zalando/api/nativecart/service/ICheckoutService.java b/src/main/java/io/sprucehill/zalando/api/nativecart/service/ICheckoutService.java new file mode 100644 index 0000000..08bee42 --- /dev/null +++ b/src/main/java/io/sprucehill/zalando/api/nativecart/service/ICheckoutService.java @@ -0,0 +1,41 @@ +package io.sprucehill.zalando.api.nativecart.service; + +import io.sprucehill.zalando.api.nativecart.model.CreateCheckoutRequest; +import io.sprucehill.zalando.api.nativecart.model.CreateCheckoutResponse; +import io.sprucehill.zalando.api.nativecart.model.GetCheckoutResponse; +import io.sprucehill.zalando.api.nativecart.model.UpdateCheckoutRequest; +import io.sprucehill.zalando.api.nativecart.model.UpdateCheckoutRespone; + +/** + * + * @author dipteewarudkar + * + */ +public interface ICheckoutService { + + /** + * + * @param customer_number The customer unique id + * @param checkout_id The ID of the checkout to read + * @return The checkout object with the requested ID for the specified customer + */ + GetCheckoutResponse read(String customer_number,String checkout_id); + + /** + * + * @param customer_number The customer unique id + * @param CreatecheckoutRequest The checkout object to be created + * @return The newly created checkout object + */ + CreateCheckoutResponse create(String customer_number,CreateCheckoutRequest CreatecheckoutRequest); + + /** + * + * @param customer_number The customer unique id + * @param checkout_id The ID of the address to update + * @param updateCheckoutRequest The checkout object to be updated + * @return The updated checkout object + */ + UpdateCheckoutRespone update(String customer_number,String checkout_id,UpdateCheckoutRequest updateCheckoutRequest); + +} diff --git a/src/main/java/io/sprucehill/zalando/api/nativecart/service/ICustomerService.java b/src/main/java/io/sprucehill/zalando/api/nativecart/service/ICustomerService.java new file mode 100644 index 0000000..ac23158 --- /dev/null +++ b/src/main/java/io/sprucehill/zalando/api/nativecart/service/ICustomerService.java @@ -0,0 +1,18 @@ +package io.sprucehill.zalando.api.nativecart.service; + +import io.sprucehill.zalando.api.nativecart.model.GetCustomerResponse; + +/** + * + * @author dipteewarudkar + * + */ +public interface ICustomerService { + + /** + * + * @param customer_number The customer unique id + * @return Details of the customer with specified customer_number + */ + GetCustomerResponse read(String customer_number); +} diff --git a/src/main/java/io/sprucehill/zalando/api/nativecart/service/IOrderService.java b/src/main/java/io/sprucehill/zalando/api/nativecart/service/IOrderService.java new file mode 100644 index 0000000..a7de587 --- /dev/null +++ b/src/main/java/io/sprucehill/zalando/api/nativecart/service/IOrderService.java @@ -0,0 +1,21 @@ +package io.sprucehill.zalando.api.nativecart.service; + +import io.sprucehill.zalando.api.nativecart.model.CreateOrderRequest; +import io.sprucehill.zalando.api.nativecart.model.CreateOrderResponse; + +/** + * + * @author dipteewarudkar + * + */ +public interface IOrderService { + + /** + * + * @param customer_number The unique id of the customer + * @param createOrderRequest The order object to be created + * @return The newly create order object + */ + CreateOrderResponse create(String customer_number,CreateOrderRequest createOrderRequest); + +} diff --git a/src/main/java/io/sprucehill/zalando/api/nativecart/service/OrderService.java b/src/main/java/io/sprucehill/zalando/api/nativecart/service/OrderService.java new file mode 100644 index 0000000..8df6174 --- /dev/null +++ b/src/main/java/io/sprucehill/zalando/api/nativecart/service/OrderService.java @@ -0,0 +1,31 @@ +package io.sprucehill.zalando.api.nativecart.service; + +import java.io.UnsupportedEncodingException; +import org.apache.http.client.methods.HttpPost; +import org.apache.http.entity.StringEntity; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.core.type.TypeReference; +import io.sprucehill.zalando.api.nativecart.model.CreateOrderRequest; +import io.sprucehill.zalando.api.nativecart.model.CreateOrderResponse; + +/** + * + * @author dipteewarudkar + * + */ +public class OrderService extends AbstractService implements IOrderService{ + + @Override + public CreateOrderResponse create(String customer_number, CreateOrderRequest createOrderRequest) { + HttpPost request = postRequest("/addresses"); + try { + request.setEntity(new StringEntity(objectMapper.writeValueAsString(createOrderRequest))); + } catch (UnsupportedEncodingException e) { + e.printStackTrace(); + } catch (JsonProcessingException e) { + e.printStackTrace(); + } + return execute(request, new TypeReference() {}); + } + +} From ac1bc49306545cedfea3cd154a69dc60684b185f Mon Sep 17 00:00:00 2001 From: Diptee Warudkar Date: Wed, 2 Mar 2016 17:45:29 +0100 Subject: [PATCH 06/24] Fixing : Formatting problems Naming issues Removing repeated objects TODO AbstractService/postContructs -> Will keep this in hold till we have a running version to test these APIs. --- .gitignore | 3 +- .../zalando/api/nativecart/model/Address.java | 87 +++++++------ .../nativecart/model/AddressCheckRequest.java | 8 -- .../model/AddressCheckResponse.java | 30 ++++- .../zalando/api/nativecart/model/Base.java | 12 -- .../zalando/api/nativecart/model/Cart.java | 40 ++++-- .../api/nativecart/model/Checkout.java | 59 ++++----- .../model/CreateAddressRequest.java | 13 -- .../model/CreateAddressResponse.java | 9 -- .../nativecart/model/CreateCartRequest.java | 15 --- .../nativecart/model/CreateCartResponse.java | 11 -- .../model/CreateCheckoutRequest.java | 14 --- .../model/CreateCheckoutResponse.java | 5 - .../nativecart/model/CreateOrderRequest.java | 21 ++-- .../nativecart/model/CreateOrderResponse.java | 10 -- ...GetCustomerResponse.java => Customer.java} | 27 ++-- .../api/nativecart/model/Delivery.java | 10 +- .../nativecart/model/GetAddressResponse.java | 9 -- .../model/GetAddressesResponse.java | 22 ---- .../api/nativecart/model/GetCartResponse.java | 63 ---------- .../nativecart/model/GetCheckoutResponse.java | 10 -- .../zalando/api/nativecart/model/Items.java | 10 +- .../zalando/api/nativecart/model/Money.java | 9 +- .../zalando/api/nativecart/model/Order.java | 115 ++++++++++-------- .../zalando/api/nativecart/model/Payment.java | 32 +++-- .../model/UpdateAddressRequest.java | 12 -- .../model/UpdateAddressResponse.java | 10 -- .../model/UpdateCartItemsRequest.java | 15 --- .../model/UpdateCartItemsResponse.java | 10 -- .../model/UpdateCheckoutRequest.java | 14 --- .../model/UpdateCheckoutRespone.java | 5 - .../nativecart/service/AddressService.java | 59 ++++----- .../api/nativecart/service/CartService.java | 38 +++--- .../nativecart/service/CheckoutService.java | 40 +++--- .../nativecart/service/CustomerService.java | 8 +- .../nativecart/service/IAddressService.java | 18 +-- .../api/nativecart/service/ICartService.java | 12 +- .../nativecart/service/ICheckoutService.java | 12 +- .../nativecart/service/ICustomerService.java | 4 +- .../api/nativecart/service/IOrderService.java | 5 +- .../api/nativecart/service/OrderService.java | 20 ++- 41 files changed, 357 insertions(+), 569 deletions(-) delete mode 100644 src/main/java/io/sprucehill/zalando/api/nativecart/model/AddressCheckRequest.java delete mode 100644 src/main/java/io/sprucehill/zalando/api/nativecart/model/Base.java delete mode 100644 src/main/java/io/sprucehill/zalando/api/nativecart/model/CreateAddressRequest.java delete mode 100644 src/main/java/io/sprucehill/zalando/api/nativecart/model/CreateAddressResponse.java delete mode 100644 src/main/java/io/sprucehill/zalando/api/nativecart/model/CreateCartRequest.java delete mode 100644 src/main/java/io/sprucehill/zalando/api/nativecart/model/CreateCartResponse.java delete mode 100644 src/main/java/io/sprucehill/zalando/api/nativecart/model/CreateCheckoutRequest.java delete mode 100644 src/main/java/io/sprucehill/zalando/api/nativecart/model/CreateCheckoutResponse.java delete mode 100644 src/main/java/io/sprucehill/zalando/api/nativecart/model/CreateOrderResponse.java rename src/main/java/io/sprucehill/zalando/api/nativecart/model/{GetCustomerResponse.java => Customer.java} (58%) delete mode 100644 src/main/java/io/sprucehill/zalando/api/nativecart/model/GetAddressResponse.java delete mode 100644 src/main/java/io/sprucehill/zalando/api/nativecart/model/GetAddressesResponse.java delete mode 100644 src/main/java/io/sprucehill/zalando/api/nativecart/model/GetCartResponse.java delete mode 100644 src/main/java/io/sprucehill/zalando/api/nativecart/model/GetCheckoutResponse.java delete mode 100644 src/main/java/io/sprucehill/zalando/api/nativecart/model/UpdateAddressRequest.java delete mode 100644 src/main/java/io/sprucehill/zalando/api/nativecart/model/UpdateAddressResponse.java delete mode 100644 src/main/java/io/sprucehill/zalando/api/nativecart/model/UpdateCartItemsRequest.java delete mode 100644 src/main/java/io/sprucehill/zalando/api/nativecart/model/UpdateCartItemsResponse.java delete mode 100644 src/main/java/io/sprucehill/zalando/api/nativecart/model/UpdateCheckoutRequest.java delete mode 100644 src/main/java/io/sprucehill/zalando/api/nativecart/model/UpdateCheckoutRespone.java diff --git a/.gitignore b/.gitignore index 8499fc5..16baa22 100644 --- a/.gitignore +++ b/.gitignore @@ -6,4 +6,5 @@ gradle.properties *.iws .classpath .settings -.project \ No newline at end of file +.project +/bin/ diff --git a/src/main/java/io/sprucehill/zalando/api/nativecart/model/Address.java b/src/main/java/io/sprucehill/zalando/api/nativecart/model/Address.java index 63a8b43..b528961 100644 --- a/src/main/java/io/sprucehill/zalando/api/nativecart/model/Address.java +++ b/src/main/java/io/sprucehill/zalando/api/nativecart/model/Address.java @@ -1,76 +1,89 @@ package io.sprucehill.zalando.api.nativecart.model; import com.fasterxml.jackson.annotation.JsonProperty; +import io.sprucehill.zalando.api.model.Base; /** * * @author dipteewarudkar * */ -public abstract class Address extends Base { +public class Address extends Base { @JsonProperty private String id; - @JsonProperty - private String customer_number; + + @JsonProperty(value="customer_number") + private String customerNumber; + @JsonProperty private String gender; - @JsonProperty - private String first_name; - @JsonProperty - private String last_name; + + @JsonProperty(value="first_name") + private String firstName; + + @JsonProperty(value="last_name") + private String lastName; + @JsonProperty private String street; + @JsonProperty private String additional; + @JsonProperty private String zip; + @JsonProperty - private String city; - @JsonProperty - private String country_code; - @JsonProperty - private Boolean pack_station; - @JsonProperty - private Boolean default_billing; - @JsonProperty - private Boolean default_shipping; + private String city; + + @JsonProperty(value="country_code") + private String countryCode; + + @JsonProperty(value="pack_station") + private Boolean packStation; + + @JsonProperty(value="default_billing") + private Boolean defaultBilling; + + @JsonProperty(value="default_shipping") + private Boolean defaultShipping; public Address(){} public Address(String id, String customer_number, String gender, String first_name, String last_name, String street,String additional, String zip, String city, String country_code, Boolean pack_station,Boolean default_billing, Boolean default_shipping) { this.id=id; - this.customer_number=customer_number; + this.customerNumber=customer_number; this.gender=gender; - this.first_name=first_name; - this.last_name=last_name; + this.firstName=first_name; + this.lastName=last_name; this.street=street; this.additional=additional; this.city=city; - this.country_code=country_code; - this.pack_station=pack_station; - this.default_billing=default_billing; - this.default_shipping=default_shipping; + this.countryCode=country_code; + this.packStation=pack_station; + this.defaultBilling=default_billing; + this.defaultShipping=default_shipping; } public String getId() { return id; } - public String getCustomer_number() { - return customer_number; + public String getCustomerNumber() { + return customerNumber; } public String getGender() { return gender; } - public String getFirst_name() { - return first_name; + public String getFirstName() { + return firstName; } - public String getLast_name() { - return last_name; + public String getLastName() { + return lastName; } public String getStreet() { @@ -89,19 +102,19 @@ public String getCity() { return city; } - public String getCountry_code() { - return country_code; + public String getCountryCode() { + return countryCode; } - public Boolean getPack_station() { - return pack_station; + public Boolean getPackStation() { + return packStation; } - public Boolean getDefault_billing() { - return default_billing; + public Boolean getDefaultBilling() { + return defaultBilling; } - public Boolean getDefault_shipping() { - return default_shipping; + public Boolean getDefaultShipping() { + return defaultShipping; } } diff --git a/src/main/java/io/sprucehill/zalando/api/nativecart/model/AddressCheckRequest.java b/src/main/java/io/sprucehill/zalando/api/nativecart/model/AddressCheckRequest.java deleted file mode 100644 index 2bc192f..0000000 --- a/src/main/java/io/sprucehill/zalando/api/nativecart/model/AddressCheckRequest.java +++ /dev/null @@ -1,8 +0,0 @@ -package io.sprucehill.zalando.api.nativecart.model; - -public class AddressCheckRequest extends Address{ - - public AddressCheckRequest(String gender,String first_name,String last_name,String street,String additional,String zip,String city,String country_code,Boolean pack_station,Boolean default_billing,Boolean default_shipping){ - super(null,null,gender,first_name,last_name,street,additional,zip,city,country_code,pack_station,default_billing,default_shipping); - } -} diff --git a/src/main/java/io/sprucehill/zalando/api/nativecart/model/AddressCheckResponse.java b/src/main/java/io/sprucehill/zalando/api/nativecart/model/AddressCheckResponse.java index b565e7f..64499ee 100644 --- a/src/main/java/io/sprucehill/zalando/api/nativecart/model/AddressCheckResponse.java +++ b/src/main/java/io/sprucehill/zalando/api/nativecart/model/AddressCheckResponse.java @@ -1,38 +1,56 @@ package io.sprucehill.zalando.api.nativecart.model; +import com.fasterxml.jackson.annotation.JsonProperty; +import io.sprucehill.zalando.api.model.Base; + /** * * @author dipteewarudkar * */ public class AddressCheckResponse extends Base { + + @JsonProperty private String status; + + @JsonProperty private Boolean blacklisted; - Address address; - Address normalized_address; + + @JsonProperty + private Address address; + + @JsonProperty(value="normalized_address") + private Address normalizedAddress; public String getStatus() { return status; } + public void setStatus(String status) { this.status = status; } + public Boolean getBlacklisted() { return blacklisted; } + public void setBlacklisted(Boolean blacklisted) { this.blacklisted = blacklisted; } + public Address getAddress() { return address; } + public void setAddress(Address address) { this.address = address; } - public Address getNormalized_address() { - return normalized_address; + + public Address getNormalizedAddress() { + return normalizedAddress; } - public void setNormalized_address(Address normalized_address) { - this.normalized_address = normalized_address; + + public void setNormalizedAddress(Address normalizedAddress) { + this.normalizedAddress = normalizedAddress; } } diff --git a/src/main/java/io/sprucehill/zalando/api/nativecart/model/Base.java b/src/main/java/io/sprucehill/zalando/api/nativecart/model/Base.java deleted file mode 100644 index b9358a1..0000000 --- a/src/main/java/io/sprucehill/zalando/api/nativecart/model/Base.java +++ /dev/null @@ -1,12 +0,0 @@ -package io.sprucehill.zalando.api.nativecart.model; - -import com.fasterxml.jackson.annotation.JsonIgnoreProperties; -import com.fasterxml.jackson.annotation.JsonInclude; - -/** - * @author Michael Duergner - */ -@JsonIgnoreProperties(ignoreUnknown = true) -@JsonInclude(value = JsonInclude.Include.NON_NULL) -public abstract class Base { -} diff --git a/src/main/java/io/sprucehill/zalando/api/nativecart/model/Cart.java b/src/main/java/io/sprucehill/zalando/api/nativecart/model/Cart.java index 3130321..9a9346f 100644 --- a/src/main/java/io/sprucehill/zalando/api/nativecart/model/Cart.java +++ b/src/main/java/io/sprucehill/zalando/api/nativecart/model/Cart.java @@ -2,28 +2,41 @@ import java.util.ArrayList; import java.util.List; - import com.fasterxml.jackson.annotation.JsonProperty; +import io.sprucehill.zalando.api.model.Base; -public abstract class Cart extends Base{ +/** + * + * @author dipteewarudkar + * + */ +public abstract class Cart extends Base { + @JsonProperty - private String id ; + private String id; + @JsonProperty - private String appDomainId ; + private String appDomainId; + @JsonProperty private List items = new ArrayList(); + @JsonProperty private List itemsOutOfStock = new ArrayList(); + @JsonProperty - private Delivery delivery ; + private Delivery delivery; + @JsonProperty - private Money grossTotal ; + private Money grossTotal; + @JsonProperty - private Money taxTotal ; + private Money taxTotal; + @JsonProperty private String cartUrl; - public Cart(){} + public Cart() {} public Cart(String id,String appDomainId ,List items,List itemsOutOfStock,Delivery delivery, Money grossTotal,Money taxTotal,String cartUrl){ @@ -35,34 +48,37 @@ public Cart(String id,String appDomainId ,List items,List itemsOu this.grossTotal =grossTotal; this.taxTotal= taxTotal; this.cartUrl=cartUrl; - } public String getId() { return id; } + public String getAppDomainId() { return appDomainId; } + public List getItems() { return items; } + public List getItemsOutOfStock() { return itemsOutOfStock; } + public Delivery getDelivery() { return delivery; } + public Money getGrossTotal() { return grossTotal; } + public Money getTaxTotal() { return taxTotal; } + public String getCartUrl() { return cartUrl; } - - - } diff --git a/src/main/java/io/sprucehill/zalando/api/nativecart/model/Checkout.java b/src/main/java/io/sprucehill/zalando/api/nativecart/model/Checkout.java index 78b01b9..44ee641 100644 --- a/src/main/java/io/sprucehill/zalando/api/nativecart/model/Checkout.java +++ b/src/main/java/io/sprucehill/zalando/api/nativecart/model/Checkout.java @@ -1,63 +1,66 @@ package io.sprucehill.zalando.api.nativecart.model; -import java.util.HashMap; -import java.util.Map; - import com.fasterxml.jackson.annotation.JsonProperty; +import io.sprucehill.zalando.api.model.Base; /** * * @author dipteewarudkar * */ -public abstract class Checkout extends Base{ +public abstract class Checkout extends Base { + @JsonProperty private String id; - @JsonProperty - private String customer_number; - @JsonProperty - private String cart_id; - @JsonProperty - private String billing_address_id; - @JsonProperty - private String shipping_address_id; + + @JsonProperty(value="customer_number") + private String customerNumber; + + @JsonProperty(value="cart_id") + private String cartId; + + @JsonProperty(value="billing_address_id") + private String billingAddressId; + + @JsonProperty(value="billing_address_id") + private String shippingAddressId; + @JsonProperty private Delivery delivery; + @JsonProperty private Payment payment; - public Checkout(){} + public Checkout() {} - public Checkout(String id,String customer_number,String cart_id, String billing_address_id,String shipping_address_id,Delivery delivery,Payment payment){ + public Checkout(String id,String customerNumber,String cartId, String billingAddressId,String shippingAddressId,Delivery delivery,Payment payment){ this.id=id; - this.customer_number=customer_number; - this.cart_id=cart_id; - this.billing_address_id=billing_address_id; - this.shipping_address_id=shipping_address_id; + this.customerNumber=customerNumber; + this.cartId=cartId; + this.billingAddressId=billingAddressId; + this.shippingAddressId=shippingAddressId; this.delivery=delivery; this.payment=payment; } - - public String getId() { return id; } - public String getCustomer_number() { - return customer_number; + public String getCustomerNumber() { + return customerNumber; } - public String getCart_id() { - return cart_id; + public String getCartId() { + return cartId; } - public String getBilling_address_id() { - return billing_address_id; + public String getBillingAddressId() { + return billingAddressId; } - public String getShipping_address_id() { - return shipping_address_id; + public String getShippingAddressId() { + return shippingAddressId; } public Delivery getDelivery() { diff --git a/src/main/java/io/sprucehill/zalando/api/nativecart/model/CreateAddressRequest.java b/src/main/java/io/sprucehill/zalando/api/nativecart/model/CreateAddressRequest.java deleted file mode 100644 index 786f0eb..0000000 --- a/src/main/java/io/sprucehill/zalando/api/nativecart/model/CreateAddressRequest.java +++ /dev/null @@ -1,13 +0,0 @@ -package io.sprucehill.zalando.api.nativecart.model; - -/** - * - * @author dipteewarudkar - * - */ -public class CreateAddressRequest extends Address{ - - public CreateAddressRequest(String gender,String first_name,String last_name,String street,String additional,String zip,String city,String country_code,Boolean pack_station,Boolean default_billing,Boolean default_shipping){ - super(null,null,gender,first_name,last_name,street,additional,zip,city,country_code,pack_station,default_billing,default_shipping); - } -} \ No newline at end of file diff --git a/src/main/java/io/sprucehill/zalando/api/nativecart/model/CreateAddressResponse.java b/src/main/java/io/sprucehill/zalando/api/nativecart/model/CreateAddressResponse.java deleted file mode 100644 index 0eecb13..0000000 --- a/src/main/java/io/sprucehill/zalando/api/nativecart/model/CreateAddressResponse.java +++ /dev/null @@ -1,9 +0,0 @@ -package io.sprucehill.zalando.api.nativecart.model; - -/** - * - * @author dipteewarudkar - * - */ -public class CreateAddressResponse extends Address{ -} diff --git a/src/main/java/io/sprucehill/zalando/api/nativecart/model/CreateCartRequest.java b/src/main/java/io/sprucehill/zalando/api/nativecart/model/CreateCartRequest.java deleted file mode 100644 index f0c10ad..0000000 --- a/src/main/java/io/sprucehill/zalando/api/nativecart/model/CreateCartRequest.java +++ /dev/null @@ -1,15 +0,0 @@ -package io.sprucehill.zalando.api.nativecart.model; - -import java.util.List; - -/** - * - * @author dipteewarudkar - * - */ -public class CreateCartRequest extends Cart{ - - public CreateCartRequest(String appDomainId,List items){ - super(null,appDomainId,items,null,null,null,null,null); - } -} diff --git a/src/main/java/io/sprucehill/zalando/api/nativecart/model/CreateCartResponse.java b/src/main/java/io/sprucehill/zalando/api/nativecart/model/CreateCartResponse.java deleted file mode 100644 index 256ddc5..0000000 --- a/src/main/java/io/sprucehill/zalando/api/nativecart/model/CreateCartResponse.java +++ /dev/null @@ -1,11 +0,0 @@ -package io.sprucehill.zalando.api.nativecart.model; - - -/** - * - * @author dipteewarudkar - * - */ -public class CreateCartResponse extends Cart { - -} diff --git a/src/main/java/io/sprucehill/zalando/api/nativecart/model/CreateCheckoutRequest.java b/src/main/java/io/sprucehill/zalando/api/nativecart/model/CreateCheckoutRequest.java deleted file mode 100644 index 9b97d1f..0000000 --- a/src/main/java/io/sprucehill/zalando/api/nativecart/model/CreateCheckoutRequest.java +++ /dev/null @@ -1,14 +0,0 @@ -package io.sprucehill.zalando.api.nativecart.model; - -/** - * - * @author dipteewarudkar - * - */ -public class CreateCheckoutRequest extends Checkout { - public CreateCheckoutRequest(String cart_id,String billing_address_id,String shipping_address_id,Payment payment){ - super(null,null,cart_id,billing_address_id,shipping_address_id,null,payment); - } - -} - diff --git a/src/main/java/io/sprucehill/zalando/api/nativecart/model/CreateCheckoutResponse.java b/src/main/java/io/sprucehill/zalando/api/nativecart/model/CreateCheckoutResponse.java deleted file mode 100644 index 480278a..0000000 --- a/src/main/java/io/sprucehill/zalando/api/nativecart/model/CreateCheckoutResponse.java +++ /dev/null @@ -1,5 +0,0 @@ -package io.sprucehill.zalando.api.nativecart.model; - -public class CreateCheckoutResponse extends Checkout{ - -} diff --git a/src/main/java/io/sprucehill/zalando/api/nativecart/model/CreateOrderRequest.java b/src/main/java/io/sprucehill/zalando/api/nativecart/model/CreateOrderRequest.java index f7e9fbc..523686c 100644 --- a/src/main/java/io/sprucehill/zalando/api/nativecart/model/CreateOrderRequest.java +++ b/src/main/java/io/sprucehill/zalando/api/nativecart/model/CreateOrderRequest.java @@ -1,18 +1,23 @@ package io.sprucehill.zalando.api.nativecart.model; import com.fasterxml.jackson.annotation.JsonProperty; +import io.sprucehill.zalando.api.model.Base; -public class CreateOrderRequest extends Base{ +/** + * + * @author dipteewarudkar + * + */ +public class CreateOrderRequest extends Base { @JsonProperty - private String checkout_id; + private String checkoutId; - public String getCheckout_id() { - return checkout_id; + public String getCheckoutId() { + return checkoutId; } - - public void setCheckout_id(String checkout_id) { - this.checkout_id = checkout_id; + + public void setCheckoutId(String checkoutId) { + this.checkoutId = checkoutId; } - } diff --git a/src/main/java/io/sprucehill/zalando/api/nativecart/model/CreateOrderResponse.java b/src/main/java/io/sprucehill/zalando/api/nativecart/model/CreateOrderResponse.java deleted file mode 100644 index 3f0b1b0..0000000 --- a/src/main/java/io/sprucehill/zalando/api/nativecart/model/CreateOrderResponse.java +++ /dev/null @@ -1,10 +0,0 @@ -package io.sprucehill.zalando.api.nativecart.model; - -/** - * - * @author dipteewarudkar - * - */ -public class CreateOrderResponse extends Order{ - -} diff --git a/src/main/java/io/sprucehill/zalando/api/nativecart/model/GetCustomerResponse.java b/src/main/java/io/sprucehill/zalando/api/nativecart/model/Customer.java similarity index 58% rename from src/main/java/io/sprucehill/zalando/api/nativecart/model/GetCustomerResponse.java rename to src/main/java/io/sprucehill/zalando/api/nativecart/model/Customer.java index 0614e09..ec09bd5 100644 --- a/src/main/java/io/sprucehill/zalando/api/nativecart/model/GetCustomerResponse.java +++ b/src/main/java/io/sprucehill/zalando/api/nativecart/model/Customer.java @@ -1,37 +1,46 @@ package io.sprucehill.zalando.api.nativecart.model; import com.fasterxml.jackson.annotation.JsonProperty; +import io.sprucehill.zalando.api.model.Base; /** * * @author dipteewarudkar * */ -public class GetCustomerResponse extends Base { +public class Customer extends Base { @JsonProperty private String customer_number; + @JsonProperty private String gender; - @JsonProperty - private String first_name; - @JsonProperty - private String last_name; + + @JsonProperty(value="first_name") + private String firstName; + + @JsonProperty(value="last_name") + private String lastName; + @JsonProperty private String email; public String getCustomer_number() { return customer_number; } + public String getGender() { return gender; } - public String getFirst_name() { - return first_name; + + public String getFirstName() { + return firstName; } - public String getLast_name() { - return last_name; + + public String getLastName() { + return lastName; } + public String getEmail() { return email; } diff --git a/src/main/java/io/sprucehill/zalando/api/nativecart/model/Delivery.java b/src/main/java/io/sprucehill/zalando/api/nativecart/model/Delivery.java index 1f12b5f..aade376 100644 --- a/src/main/java/io/sprucehill/zalando/api/nativecart/model/Delivery.java +++ b/src/main/java/io/sprucehill/zalando/api/nativecart/model/Delivery.java @@ -1,28 +1,34 @@ package io.sprucehill.zalando.api.nativecart.model; import com.fasterxml.jackson.annotation.JsonProperty; +import io.sprucehill.zalando.api.model.Base; /** * * @author dipteewarudkar * */ -public class Delivery extends Base{ +public class Delivery extends Base { + @JsonProperty private String earliest; + @JsonProperty private String latest; + public String getEarliest() { return earliest; } + public void setEarliest(String earliest) { this.earliest = earliest; } + public String getLatest() { return latest; } + public void setLatest(String latest) { this.latest = latest; } - } diff --git a/src/main/java/io/sprucehill/zalando/api/nativecart/model/GetAddressResponse.java b/src/main/java/io/sprucehill/zalando/api/nativecart/model/GetAddressResponse.java deleted file mode 100644 index 5e91d6b..0000000 --- a/src/main/java/io/sprucehill/zalando/api/nativecart/model/GetAddressResponse.java +++ /dev/null @@ -1,9 +0,0 @@ -package io.sprucehill.zalando.api.nativecart.model; - -/** - * - * @author dipteewarudkar - * - */ -public class GetAddressResponse extends Address { -} diff --git a/src/main/java/io/sprucehill/zalando/api/nativecart/model/GetAddressesResponse.java b/src/main/java/io/sprucehill/zalando/api/nativecart/model/GetAddressesResponse.java deleted file mode 100644 index cb5ddb1..0000000 --- a/src/main/java/io/sprucehill/zalando/api/nativecart/model/GetAddressesResponse.java +++ /dev/null @@ -1,22 +0,0 @@ -package io.sprucehill.zalando.api.nativecart.model; - -import java.util.List; - -/** - * - * @author dipteewarudkar - * - */ -public class GetAddressesResponse extends Base { - - List addresses; - - public List getAddresses() { - return addresses; - } - - public void setAddresses(List addresses) { - this.addresses = addresses; - } - -} diff --git a/src/main/java/io/sprucehill/zalando/api/nativecart/model/GetCartResponse.java b/src/main/java/io/sprucehill/zalando/api/nativecart/model/GetCartResponse.java deleted file mode 100644 index 3e74f12..0000000 --- a/src/main/java/io/sprucehill/zalando/api/nativecart/model/GetCartResponse.java +++ /dev/null @@ -1,63 +0,0 @@ -package io.sprucehill.zalando.api.nativecart.model; - -import java.util.ArrayList; -import java.util.List; - -public class GetCartResponse extends Base{ - private String id = null; - private String appDomainId = null; - private List items = new ArrayList(); - private List itemsOutOfStock = new ArrayList(); - private Delivery delivery = null; - private Money grossTotal = null; - private Money taxTotal = null; - private String cartUrl = null; - public String getId() { - return id; - } - public void setId(String id) { - this.id = id; - } - public String getAppDomainId() { - return appDomainId; - } - public void setAppDomainId(String appDomainId) { - this.appDomainId = appDomainId; - } - public List getItems() { - return items; - } - public void setItems(List items) { - this.items = items; - } - public List getItemsOutOfStock() { - return itemsOutOfStock; - } - public void setItemsOutOfStock(List itemsOutOfStock) { - this.itemsOutOfStock = itemsOutOfStock; - } - public Delivery getDelivery() { - return delivery; - } - public void setDelivery(Delivery delivery) { - this.delivery = delivery; - } - public Money getGrossTotal() { - return grossTotal; - } - public void setGrossTotal(Money grossTotal) { - this.grossTotal = grossTotal; - } - public Money getTaxTotal() { - return taxTotal; - } - public void setTaxTotal(Money taxTotal) { - this.taxTotal = taxTotal; - } - public String getCartUrl() { - return cartUrl; - } - public void setCartUrl(String cartUrl) { - this.cartUrl = cartUrl; - } -} diff --git a/src/main/java/io/sprucehill/zalando/api/nativecart/model/GetCheckoutResponse.java b/src/main/java/io/sprucehill/zalando/api/nativecart/model/GetCheckoutResponse.java deleted file mode 100644 index 31ca4af..0000000 --- a/src/main/java/io/sprucehill/zalando/api/nativecart/model/GetCheckoutResponse.java +++ /dev/null @@ -1,10 +0,0 @@ -package io.sprucehill.zalando.api.nativecart.model; - -/** - * - * @author dipteewarudkar - * - */ -public class GetCheckoutResponse extends Checkout{ - -} diff --git a/src/main/java/io/sprucehill/zalando/api/nativecart/model/Items.java b/src/main/java/io/sprucehill/zalando/api/nativecart/model/Items.java index 0da7a0e..b1cb90f 100644 --- a/src/main/java/io/sprucehill/zalando/api/nativecart/model/Items.java +++ b/src/main/java/io/sprucehill/zalando/api/nativecart/model/Items.java @@ -1,28 +1,34 @@ package io.sprucehill.zalando.api.nativecart.model; import com.fasterxml.jackson.annotation.JsonProperty; +import io.sprucehill.zalando.api.model.Base; /** * * @author dipteewarudkar * */ -public class Items extends Base{ +public class Items extends Base { + @JsonProperty private String sku; + @JsonProperty private Integer quantity; + public Integer getQuantity() { return quantity; } + public void setQuantity(Integer quantity) { this.quantity = quantity; } + public String getSku() { return sku; } + public void setSku(String sku) { this.sku = sku; } - } diff --git a/src/main/java/io/sprucehill/zalando/api/nativecart/model/Money.java b/src/main/java/io/sprucehill/zalando/api/nativecart/model/Money.java index af8ad6c..dad8f6b 100644 --- a/src/main/java/io/sprucehill/zalando/api/nativecart/model/Money.java +++ b/src/main/java/io/sprucehill/zalando/api/nativecart/model/Money.java @@ -1,8 +1,8 @@ package io.sprucehill.zalando.api.nativecart.model; import java.math.BigInteger; - import com.fasterxml.jackson.annotation.JsonProperty; +import io.sprucehill.zalando.api.model.Base; /** * @@ -10,21 +10,26 @@ * */ public class Money extends Base{ + @JsonProperty private BigInteger amount; + @JsonProperty private String currency; + public String getCurrency() { return currency; } + public void setCurrency(String currency) { this.currency = currency; } + public BigInteger getAmount() { return amount; } + public void setAmount(BigInteger amount) { this.amount = amount; } - } diff --git a/src/main/java/io/sprucehill/zalando/api/nativecart/model/Order.java b/src/main/java/io/sprucehill/zalando/api/nativecart/model/Order.java index f0d0f51..8780362 100644 --- a/src/main/java/io/sprucehill/zalando/api/nativecart/model/Order.java +++ b/src/main/java/io/sprucehill/zalando/api/nativecart/model/Order.java @@ -1,81 +1,98 @@ package io.sprucehill.zalando.api.nativecart.model; import com.fasterxml.jackson.annotation.JsonProperty; +import io.sprucehill.zalando.api.model.Base; /** * * @author dipteewarudkar * */ -public abstract class Order extends Base{ - @JsonProperty - private String order_number; - @JsonProperty - private String customer_number; - @JsonProperty - private Address billing_address ; - @JsonProperty - private Address shipping_address; +public class Order extends Base { + + @JsonProperty(value="order_number") + private String orderNumber; + + @JsonProperty(value="customer_number") + private String customerNumber; + + @JsonProperty(value="billing_address") + private Address billingAddress ; + + @JsonProperty(value="shipping_address") + private Address shippingAddress; + @JsonProperty private Delivery delivery; - @JsonProperty - private Money gross_total; - @JsonProperty - private Money tax_total; + + @JsonProperty(value="gross_total") + private Money grossTotal; + + @JsonProperty(value="tax_total") + private Money taxTotal; + @JsonProperty private String created; - @JsonProperty - private String detail_url; - @JsonProperty - private String external_payment_url; - + + @JsonProperty(value="detail_url") + private String detailUrl; + + @JsonProperty(value="external_payment_url") + private String externalPaymentUrl; + public Order(){} - - public Order(String order_number,String customer_number,Address billing_address,Address shipping_address,Delivery delivery, - Money gross_total,Money tax_total,String created,String detail_url,String external_payment_url){ - this.order_number=order_number; - this.customer_number=customer_number; - this.billing_address=billing_address; - this.shipping_address=shipping_address; + + public Order(String orderNumber,String customerNumber,Address billingAddress,Address shippingAddress,Delivery delivery, + Money grossTotal,Money taxTotal,String created,String detailUrl,String externalPaymentUrl){ + this.orderNumber=orderNumber; + this.customerNumber=customerNumber; + this.billingAddress=billingAddress; + this.shippingAddress=shippingAddress; this.delivery=delivery; - this.gross_total=gross_total; - this.tax_total=tax_total; + this.grossTotal=grossTotal; + this.taxTotal=taxTotal; this.created=created; - this.detail_url=detail_url; - this.external_payment_url=external_payment_url; + this.detailUrl=detailUrl; + this.externalPaymentUrl=externalPaymentUrl; } - - - public String getOrder_number() { - return order_number; + + public String getOrderNumber() { + return orderNumber; } - public String getCustomer_number() { - return customer_number; + + public String getCustomerNumber() { + return customerNumber; } - public Address getBilling_address() { - return billing_address; + + public Address getBillingAddress() { + return billingAddress; } - public Address getShipping_address() { - return shipping_address; + + public Address getShippingAddress() { + return shippingAddress; } + public Delivery getDelivery() { return delivery; } - public Money getGross_total() { - return gross_total; + + public Money getGrossTotal() { + return grossTotal; } - public Money getTax_total() { - return tax_total; + + public Money getTaxTotal() { + return taxTotal; } + public String getCreated() { return created; } - public String getDetail_url() { - return detail_url; + + public String getDetailUrl() { + return detailUrl; } - public String getExternal_payment_url() { - return external_payment_url; - } - + public String getExternalPaymentUrl() { + return externalPaymentUrl; + } } diff --git a/src/main/java/io/sprucehill/zalando/api/nativecart/model/Payment.java b/src/main/java/io/sprucehill/zalando/api/nativecart/model/Payment.java index 1ed26fd..68f8260 100644 --- a/src/main/java/io/sprucehill/zalando/api/nativecart/model/Payment.java +++ b/src/main/java/io/sprucehill/zalando/api/nativecart/model/Payment.java @@ -2,49 +2,59 @@ import java.util.HashMap; import java.util.Map; - import com.fasterxml.jackson.annotation.JsonProperty; +import io.sprucehill.zalando.api.model.Base; /** * * @author dipteewarudkar * */ -public class Payment extends Base{ - @JsonProperty - private String callback_url; +public class Payment extends Base { + + @JsonProperty(value="callback_url") + private String callbackUrl; + @JsonProperty private Map templateParameters = new HashMap(); - @JsonProperty - private String selection_page_url; + + @JsonProperty(value="selection_page_url") + private String selectionPageUrl; + @JsonProperty private Selected selected; - public String getCallback_url() { - return callback_url; + public String getCallbackUrl() { + return callbackUrl; } + public Map getTemplateParameters() { return templateParameters; } - public String getSelection_page_url() { - return selection_page_url; + + public String getSelectionPageUrl() { + return selectionPageUrl; } + public Selected getSelected() { return selected; } public static class Selected extends Base { + @JsonProperty private String method; + @JsonProperty private Map metadata = new HashMap(); + public String getMethod() { return method; } + public Map getMetadata() { return metadata; } } - } diff --git a/src/main/java/io/sprucehill/zalando/api/nativecart/model/UpdateAddressRequest.java b/src/main/java/io/sprucehill/zalando/api/nativecart/model/UpdateAddressRequest.java deleted file mode 100644 index 85939bf..0000000 --- a/src/main/java/io/sprucehill/zalando/api/nativecart/model/UpdateAddressRequest.java +++ /dev/null @@ -1,12 +0,0 @@ -package io.sprucehill.zalando.api.nativecart.model; - -/** - * - * @author dipteewarudkar - * - */ -public class UpdateAddressRequest extends Address { - public UpdateAddressRequest(String gender,String first_name,String last_name,String street,String additional,String zip,String city,String country_code,Boolean pack_station,Boolean default_billing,Boolean default_shipping){ - super(null,null,gender,first_name,last_name,street,additional,zip,city,country_code,pack_station,default_billing,default_shipping); - } -} \ No newline at end of file diff --git a/src/main/java/io/sprucehill/zalando/api/nativecart/model/UpdateAddressResponse.java b/src/main/java/io/sprucehill/zalando/api/nativecart/model/UpdateAddressResponse.java deleted file mode 100644 index 865fdc5..0000000 --- a/src/main/java/io/sprucehill/zalando/api/nativecart/model/UpdateAddressResponse.java +++ /dev/null @@ -1,10 +0,0 @@ -package io.sprucehill.zalando.api.nativecart.model; - -/** - * - * @author dipteewarudkar - * - */ -public class UpdateAddressResponse extends Address{ - -} diff --git a/src/main/java/io/sprucehill/zalando/api/nativecart/model/UpdateCartItemsRequest.java b/src/main/java/io/sprucehill/zalando/api/nativecart/model/UpdateCartItemsRequest.java deleted file mode 100644 index a92099e..0000000 --- a/src/main/java/io/sprucehill/zalando/api/nativecart/model/UpdateCartItemsRequest.java +++ /dev/null @@ -1,15 +0,0 @@ -package io.sprucehill.zalando.api.nativecart.model; - -import java.util.List; - -/** - * - * @author dipteewarudkar - * - */ -public class UpdateCartItemsRequest extends Cart{ - - public UpdateCartItemsRequest(List items){ - super(null,null,items,null,null,null,null,null); - } -} diff --git a/src/main/java/io/sprucehill/zalando/api/nativecart/model/UpdateCartItemsResponse.java b/src/main/java/io/sprucehill/zalando/api/nativecart/model/UpdateCartItemsResponse.java deleted file mode 100644 index d8a43ea..0000000 --- a/src/main/java/io/sprucehill/zalando/api/nativecart/model/UpdateCartItemsResponse.java +++ /dev/null @@ -1,10 +0,0 @@ -package io.sprucehill.zalando.api.nativecart.model; - -/** - * - * @author dipteewarudkar - * - */ -public class UpdateCartItemsResponse extends Cart { - -} diff --git a/src/main/java/io/sprucehill/zalando/api/nativecart/model/UpdateCheckoutRequest.java b/src/main/java/io/sprucehill/zalando/api/nativecart/model/UpdateCheckoutRequest.java deleted file mode 100644 index 9acf687..0000000 --- a/src/main/java/io/sprucehill/zalando/api/nativecart/model/UpdateCheckoutRequest.java +++ /dev/null @@ -1,14 +0,0 @@ -package io.sprucehill.zalando.api.nativecart.model; - -/** - * - * @author dipteewarudkar - * - */ -public class UpdateCheckoutRequest extends Checkout{ - - public UpdateCheckoutRequest(String billing_address_id,String shipping_address_id,Payment payment){ - super(null,null,null,billing_address_id,shipping_address_id,null,payment); - } - -} diff --git a/src/main/java/io/sprucehill/zalando/api/nativecart/model/UpdateCheckoutRespone.java b/src/main/java/io/sprucehill/zalando/api/nativecart/model/UpdateCheckoutRespone.java deleted file mode 100644 index cc3e52f..0000000 --- a/src/main/java/io/sprucehill/zalando/api/nativecart/model/UpdateCheckoutRespone.java +++ /dev/null @@ -1,5 +0,0 @@ -package io.sprucehill.zalando.api.nativecart.model; - -public class UpdateCheckoutRespone extends Checkout { - -} diff --git a/src/main/java/io/sprucehill/zalando/api/nativecart/service/AddressService.java b/src/main/java/io/sprucehill/zalando/api/nativecart/service/AddressService.java index 29297d5..2b96f38 100644 --- a/src/main/java/io/sprucehill/zalando/api/nativecart/service/AddressService.java +++ b/src/main/java/io/sprucehill/zalando/api/nativecart/service/AddressService.java @@ -1,76 +1,59 @@ package io.sprucehill.zalando.api.nativecart.service; -import java.io.UnsupportedEncodingException; -import javax.annotation.PostConstruct; import org.apache.http.client.methods.HttpGet; import org.apache.http.client.methods.HttpPost; import org.apache.http.client.methods.HttpPut; import org.apache.http.entity.StringEntity; -import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.core.type.TypeReference; -import io.sprucehill.zalando.api.nativecart.model.AddressCheckRequest; +import io.sprucehill.zalando.api.nativecart.model.Address; import io.sprucehill.zalando.api.nativecart.model.AddressCheckResponse; -import io.sprucehill.zalando.api.nativecart.model.CreateAddressRequest; -import io.sprucehill.zalando.api.nativecart.model.CreateAddressResponse; -import io.sprucehill.zalando.api.nativecart.model.GetAddressResponse; -import io.sprucehill.zalando.api.nativecart.model.GetAddressesResponse; -import io.sprucehill.zalando.api.nativecart.model.UpdateAddressRequest; -import io.sprucehill.zalando.api.nativecart.model.UpdateAddressResponse; /** * * @author dipteewarudkar * */ -public class AddressService extends AbstractService implements IAddressService{ +public class AddressService extends AbstractService implements IAddressService { - @PostConstruct @Override - public void postConstruct() { - super.postConstruct(); + public Address read(String customerNumber) { + HttpGet request = getRequest("/customers/" + customerNumber +"/addresses"); + return execute(request, new TypeReference
() {}); } @Override - public GetAddressesResponse read(String customer_number) { - HttpGet request = getRequest("/customers/" + customer_number +"/addresses"); - return execute(request, new TypeReference() {}); + public Address read(String customerNumber, String addressId) { + HttpGet request = getRequest("/customers/" + customerNumber +"/addresses/"+addressId); + return execute(request, new TypeReference
() {}); } @Override - public GetAddressResponse read(String customer_number, String address_id) { - HttpGet request = getRequest("/customers/" + customer_number +"/addresses/"+address_id); - return execute(request, new TypeReference() {}); - } - - @Override - public UpdateAddressResponse update(String customer_number, String address_id, UpdateAddressRequest updateAddressRequest) { - HttpPut request = putRequest("/customers/" + customer_number +"/addresses"); + public Address update(String customerNumber, String addressId, Address updateAddressRequest) { + HttpPut request = putRequest("/customers/" + customerNumber +"/addresses/"+addressId); try { request.setEntity(new StringEntity(objectMapper.writeValueAsString(updateAddressRequest))); - } catch (UnsupportedEncodingException e) { - e.printStackTrace(); - } catch (JsonProcessingException e) { - e.printStackTrace(); + }catch(Throwable t) { + logger.warn(t.getMessage()); + throw new RuntimeException(t); } - return execute(request, new TypeReference() {}); + return execute(request, new TypeReference
() {}); } @Override - public CreateAddressResponse create(String customer_number, CreateAddressRequest createAddressRequest) { - HttpGet request = getRequest("/customers/" + customer_number+"/addresses"); - return execute(request, new TypeReference() {}); + public Address create(String customerNumber, Address createAddressRequest) { + HttpGet request = getRequest("/customers/" + customerNumber+"/addresses"); + return execute(request, new TypeReference
() {}); } @Override - public AddressCheckResponse checkAddress(AddressCheckRequest checkAddressRequest) { + public AddressCheckResponse checkAddress(Address checkAddressRequest) { HttpPost request = postRequest("/addresses"); try { request.setEntity(new StringEntity(objectMapper.writeValueAsString(checkAddressRequest))); - } catch (UnsupportedEncodingException e) { - e.printStackTrace(); - } catch (JsonProcessingException e) { - e.printStackTrace(); + }catch(Throwable t) { + logger.warn(t.getMessage()); + throw new RuntimeException(t); } return execute(request, new TypeReference() {}); } diff --git a/src/main/java/io/sprucehill/zalando/api/nativecart/service/CartService.java b/src/main/java/io/sprucehill/zalando/api/nativecart/service/CartService.java index 863663d..f24d7ad 100644 --- a/src/main/java/io/sprucehill/zalando/api/nativecart/service/CartService.java +++ b/src/main/java/io/sprucehill/zalando/api/nativecart/service/CartService.java @@ -1,62 +1,52 @@ package io.sprucehill.zalando.api.nativecart.service; -import java.io.UnsupportedEncodingException; - import org.apache.http.HttpHeaders; import org.apache.http.client.methods.HttpGet; import org.apache.http.client.methods.HttpPost; import org.apache.http.client.methods.HttpPut; import org.apache.http.entity.StringEntity; -import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.core.type.TypeReference; -import io.sprucehill.zalando.api.nativecart.model.CreateCartRequest; -import io.sprucehill.zalando.api.nativecart.model.CreateCartResponse; -import io.sprucehill.zalando.api.nativecart.model.GetCartResponse; -import io.sprucehill.zalando.api.nativecart.model.UpdateCartItemsRequest; +import io.sprucehill.zalando.api.nativecart.model.Cart; /** * * @author dipteewarudkar * */ -public class CartService extends AbstractService implements ICartService{ +public class CartService extends AbstractService implements ICartService { @Override - public CreateCartResponse create(String access_token, CreateCartRequest createCartRequest) { + public Cart create(String access_token, Cart createCartRequest) { HttpPost request = postRequest("/carts"); try { request.addHeader(HttpHeaders.AUTHORIZATION,"Bearer "+access_token); request.setEntity(new StringEntity(objectMapper.writeValueAsString(createCartRequest))); - } catch (UnsupportedEncodingException e) { - e.printStackTrace(); - } catch (JsonProcessingException e) { - e.printStackTrace(); + }catch(Throwable t) { + logger.warn(t.getMessage()); + throw new RuntimeException(t); } - return execute(request, new TypeReference() {}); + return execute(request, new TypeReference() {}); } - @Override - public GetCartResponse read(String access_token, String cart_id) { + public Cart read(String access_token, String cart_id) { HttpGet request = getRequest("/carts/" + cart_id); request.addHeader(HttpHeaders.AUTHORIZATION,"Bearer "+access_token); - return execute(request, new TypeReference() {}); + return execute(request, new TypeReference() {}); } - @Override - public UpdateCartItemsRequest update(String access_token, String cart_id,UpdateCartItemsRequest updateCartRequest) { + public Cart update(String access_token, String cart_id,Cart updateCartRequest) { HttpPut request = putRequest("/carts/"+cart_id); try { request.addHeader(HttpHeaders.AUTHORIZATION,"Bearer "+access_token); request.setEntity(new StringEntity(objectMapper.writeValueAsString(updateCartRequest))); - } catch (UnsupportedEncodingException e) { - e.printStackTrace(); - } catch (JsonProcessingException e) { - e.printStackTrace(); + }catch(Throwable t) { + logger.warn(t.getMessage()); + throw new RuntimeException(t); } - return execute(request, new TypeReference() {}); + return execute(request, new TypeReference() {}); } } diff --git a/src/main/java/io/sprucehill/zalando/api/nativecart/service/CheckoutService.java b/src/main/java/io/sprucehill/zalando/api/nativecart/service/CheckoutService.java index 4c363cc..ea982b6 100644 --- a/src/main/java/io/sprucehill/zalando/api/nativecart/service/CheckoutService.java +++ b/src/main/java/io/sprucehill/zalando/api/nativecart/service/CheckoutService.java @@ -1,17 +1,11 @@ package io.sprucehill.zalando.api.nativecart.service; -import java.io.UnsupportedEncodingException; import org.apache.http.client.methods.HttpGet; import org.apache.http.client.methods.HttpPost; import org.apache.http.client.methods.HttpPut; import org.apache.http.entity.StringEntity; -import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.core.type.TypeReference; -import io.sprucehill.zalando.api.nativecart.model.CreateCheckoutRequest; -import io.sprucehill.zalando.api.nativecart.model.CreateCheckoutResponse; -import io.sprucehill.zalando.api.nativecart.model.GetCheckoutResponse; -import io.sprucehill.zalando.api.nativecart.model.UpdateCheckoutRequest; -import io.sprucehill.zalando.api.nativecart.model.UpdateCheckoutRespone; +import io.sprucehill.zalando.api.nativecart.model.Checkout; /** * @@ -21,37 +15,35 @@ public class CheckoutService extends AbstractService implements ICheckoutService{ @Override - public GetCheckoutResponse read(String customer_number, String checkout_id) { - HttpGet request = getRequest("/customer/"+customer_number+"/checkouts/"+checkout_id); - return execute(request, new TypeReference() {}); + public Checkout read(String customerNumber, String checkout_id) { + HttpGet request = getRequest("/customer/"+customerNumber+"/checkouts/"+checkout_id); + return execute(request, new TypeReference() {}); } @Override - public CreateCheckoutResponse create(String customer_number, CreateCheckoutRequest createcheckoutRequest) { - HttpPost request = postRequest("/customer/"+customer_number+"/checkouts"); + public Checkout create(String customerNumber, Checkout createcheckoutRequest) { + HttpPost request = postRequest("/customer/"+customerNumber+"/checkouts"); try { request.setEntity(new StringEntity(objectMapper.writeValueAsString(createcheckoutRequest))); - } catch (UnsupportedEncodingException e) { - e.printStackTrace(); - } catch (JsonProcessingException e) { - e.printStackTrace(); + }catch (Throwable t) { + logger.warn(t.getMessage()); + throw new RuntimeException(t); } - return execute(request, new TypeReference() {}); + return execute(request, new TypeReference() {}); } @Override - public UpdateCheckoutRespone update(String customer_number, String checkout_id,UpdateCheckoutRequest updateCheckoutRequest) { - HttpPut request = putRequest("/customer/"+customer_number+"/checkouts/"+checkout_id); + public Checkout update(String customerNumber, String checkoutId,Checkout updateCheckoutRequest) { + HttpPut request = putRequest("/customer/"+customerNumber+"/checkouts/"+checkoutId); try { request.setEntity(new StringEntity(objectMapper.writeValueAsString(updateCheckoutRequest))); - } catch (UnsupportedEncodingException e) { - e.printStackTrace(); - } catch (JsonProcessingException e) { - e.printStackTrace(); + }catch (Throwable t) { + logger.warn(t.getMessage()); + throw new RuntimeException(t); } - return execute(request, new TypeReference() {}); + return execute(request, new TypeReference() {}); } } diff --git a/src/main/java/io/sprucehill/zalando/api/nativecart/service/CustomerService.java b/src/main/java/io/sprucehill/zalando/api/nativecart/service/CustomerService.java index 6c05699..f4497a4 100644 --- a/src/main/java/io/sprucehill/zalando/api/nativecart/service/CustomerService.java +++ b/src/main/java/io/sprucehill/zalando/api/nativecart/service/CustomerService.java @@ -2,7 +2,7 @@ import org.apache.http.client.methods.HttpGet; import com.fasterxml.jackson.core.type.TypeReference; -import io.sprucehill.zalando.api.nativecart.model.GetCustomerResponse; +import io.sprucehill.zalando.api.nativecart.model.Customer; /** * @@ -12,8 +12,8 @@ public class CustomerService extends AbstractService implements ICustomerService{ @Override - public GetCustomerResponse read(String customer_number) { - HttpGet request = getRequest("/customers/" + customer_number); - return execute(request, new TypeReference() {}); + public Customer read(String customerNumber) { + HttpGet request = getRequest("/customers/" + customerNumber); + return execute(request, new TypeReference() {}); } } diff --git a/src/main/java/io/sprucehill/zalando/api/nativecart/service/IAddressService.java b/src/main/java/io/sprucehill/zalando/api/nativecart/service/IAddressService.java index 02d1c70..52752c6 100644 --- a/src/main/java/io/sprucehill/zalando/api/nativecart/service/IAddressService.java +++ b/src/main/java/io/sprucehill/zalando/api/nativecart/service/IAddressService.java @@ -1,13 +1,7 @@ package io.sprucehill.zalando.api.nativecart.service; -import io.sprucehill.zalando.api.nativecart.model.AddressCheckRequest; +import io.sprucehill.zalando.api.nativecart.model.Address; import io.sprucehill.zalando.api.nativecart.model.AddressCheckResponse; -import io.sprucehill.zalando.api.nativecart.model.CreateAddressRequest; -import io.sprucehill.zalando.api.nativecart.model.CreateAddressResponse; -import io.sprucehill.zalando.api.nativecart.model.GetAddressResponse; -import io.sprucehill.zalando.api.nativecart.model.GetAddressesResponse; -import io.sprucehill.zalando.api.nativecart.model.UpdateAddressRequest; -import io.sprucehill.zalando.api.nativecart.model.UpdateAddressResponse; /** * @@ -20,14 +14,14 @@ public interface IAddressService { * @param checkAddressRequest The address object to be checked * @return The address object with normalized address */ - AddressCheckResponse checkAddress(AddressCheckRequest checkAddressRequest); + AddressCheckResponse checkAddress(Address checkAddressRequest); /** * * @param customer_number The customer unique id * @return The list of user addresses */ - GetAddressesResponse read(String customer_number) ; + Address read(String customerNumber) ; /** * @@ -35,7 +29,7 @@ public interface IAddressService { * @param address_id The ID of the address to read * @return The address with the requested ID for the specified customer */ - GetAddressResponse read(String customer_number,String address_id) ; + Address read(String customerNumber,String addressId) ; /** * @@ -44,7 +38,7 @@ public interface IAddressService { * @param request The address object to update * @return The updated address object */ - UpdateAddressResponse update(String customer_number,String address_id,UpdateAddressRequest request); + Address update(String customerNumber,String addressId,Address request); /** * @@ -52,5 +46,5 @@ public interface IAddressService { * @param createAddressRequest The address object to create * @return Newly created address object */ - CreateAddressResponse create(String customer_number,CreateAddressRequest createAddressRequest); + Address create(String customerNumber,Address createAddressRequest); } diff --git a/src/main/java/io/sprucehill/zalando/api/nativecart/service/ICartService.java b/src/main/java/io/sprucehill/zalando/api/nativecart/service/ICartService.java index 0b78146..34f84c2 100644 --- a/src/main/java/io/sprucehill/zalando/api/nativecart/service/ICartService.java +++ b/src/main/java/io/sprucehill/zalando/api/nativecart/service/ICartService.java @@ -1,9 +1,6 @@ package io.sprucehill.zalando.api.nativecart.service; -import io.sprucehill.zalando.api.nativecart.model.CreateCartRequest; -import io.sprucehill.zalando.api.nativecart.model.CreateCartResponse; -import io.sprucehill.zalando.api.nativecart.model.GetCartResponse; -import io.sprucehill.zalando.api.nativecart.model.UpdateCartItemsRequest; +import io.sprucehill.zalando.api.nativecart.model.Cart; /** * @@ -18,7 +15,7 @@ public interface ICartService { * @param createCartRequest The Cart object to be created * @return Newly created cart object */ - CreateCartResponse create(String access_token,CreateCartRequest createCartRequest); + Cart create(String accessToken,Cart createCartRequest); /** * @@ -26,7 +23,7 @@ public interface ICartService { * @param cart_id The ID of the cart to read * @return The cart with the requested ID for the specified access_token */ - GetCartResponse read(String access_token,String cart_id); + Cart read(String accessToken,String cartId); /** * @@ -35,6 +32,5 @@ public interface ICartService { * @param updateCartRequest * @return */ - UpdateCartItemsRequest update(String access_token,String cart_id,UpdateCartItemsRequest updateCartRequest ); - + Cart update(String accessToken,String cartId,Cart updateCartRequest); } diff --git a/src/main/java/io/sprucehill/zalando/api/nativecart/service/ICheckoutService.java b/src/main/java/io/sprucehill/zalando/api/nativecart/service/ICheckoutService.java index 08bee42..9cb4e22 100644 --- a/src/main/java/io/sprucehill/zalando/api/nativecart/service/ICheckoutService.java +++ b/src/main/java/io/sprucehill/zalando/api/nativecart/service/ICheckoutService.java @@ -1,10 +1,6 @@ package io.sprucehill.zalando.api.nativecart.service; -import io.sprucehill.zalando.api.nativecart.model.CreateCheckoutRequest; -import io.sprucehill.zalando.api.nativecart.model.CreateCheckoutResponse; -import io.sprucehill.zalando.api.nativecart.model.GetCheckoutResponse; -import io.sprucehill.zalando.api.nativecart.model.UpdateCheckoutRequest; -import io.sprucehill.zalando.api.nativecart.model.UpdateCheckoutRespone; +import io.sprucehill.zalando.api.nativecart.model.Checkout; /** * @@ -19,7 +15,7 @@ public interface ICheckoutService { * @param checkout_id The ID of the checkout to read * @return The checkout object with the requested ID for the specified customer */ - GetCheckoutResponse read(String customer_number,String checkout_id); + Checkout read(String customerNumber,String checkoutId); /** * @@ -27,7 +23,7 @@ public interface ICheckoutService { * @param CreatecheckoutRequest The checkout object to be created * @return The newly created checkout object */ - CreateCheckoutResponse create(String customer_number,CreateCheckoutRequest CreatecheckoutRequest); + Checkout create(String customerNumber,Checkout CreatecheckoutRequest); /** * @@ -36,6 +32,6 @@ public interface ICheckoutService { * @param updateCheckoutRequest The checkout object to be updated * @return The updated checkout object */ - UpdateCheckoutRespone update(String customer_number,String checkout_id,UpdateCheckoutRequest updateCheckoutRequest); + Checkout update(String customerNumber,String checkoutId,Checkout updateCheckoutRequest); } diff --git a/src/main/java/io/sprucehill/zalando/api/nativecart/service/ICustomerService.java b/src/main/java/io/sprucehill/zalando/api/nativecart/service/ICustomerService.java index ac23158..0406b52 100644 --- a/src/main/java/io/sprucehill/zalando/api/nativecart/service/ICustomerService.java +++ b/src/main/java/io/sprucehill/zalando/api/nativecart/service/ICustomerService.java @@ -1,6 +1,6 @@ package io.sprucehill.zalando.api.nativecart.service; -import io.sprucehill.zalando.api.nativecart.model.GetCustomerResponse; +import io.sprucehill.zalando.api.nativecart.model.Customer; /** * @@ -14,5 +14,5 @@ public interface ICustomerService { * @param customer_number The customer unique id * @return Details of the customer with specified customer_number */ - GetCustomerResponse read(String customer_number); + Customer read(String customerNumber); } diff --git a/src/main/java/io/sprucehill/zalando/api/nativecart/service/IOrderService.java b/src/main/java/io/sprucehill/zalando/api/nativecart/service/IOrderService.java index a7de587..b3b1d0c 100644 --- a/src/main/java/io/sprucehill/zalando/api/nativecart/service/IOrderService.java +++ b/src/main/java/io/sprucehill/zalando/api/nativecart/service/IOrderService.java @@ -1,7 +1,7 @@ package io.sprucehill.zalando.api.nativecart.service; import io.sprucehill.zalando.api.nativecart.model.CreateOrderRequest; -import io.sprucehill.zalando.api.nativecart.model.CreateOrderResponse; +import io.sprucehill.zalando.api.nativecart.model.Order; /** * @@ -16,6 +16,5 @@ public interface IOrderService { * @param createOrderRequest The order object to be created * @return The newly create order object */ - CreateOrderResponse create(String customer_number,CreateOrderRequest createOrderRequest); - + Order create(String customerNumber,CreateOrderRequest createOrderRequest); } diff --git a/src/main/java/io/sprucehill/zalando/api/nativecart/service/OrderService.java b/src/main/java/io/sprucehill/zalando/api/nativecart/service/OrderService.java index 8df6174..56efb0b 100644 --- a/src/main/java/io/sprucehill/zalando/api/nativecart/service/OrderService.java +++ b/src/main/java/io/sprucehill/zalando/api/nativecart/service/OrderService.java @@ -1,31 +1,27 @@ package io.sprucehill.zalando.api.nativecart.service; -import java.io.UnsupportedEncodingException; import org.apache.http.client.methods.HttpPost; import org.apache.http.entity.StringEntity; -import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.core.type.TypeReference; import io.sprucehill.zalando.api.nativecart.model.CreateOrderRequest; -import io.sprucehill.zalando.api.nativecart.model.CreateOrderResponse; +import io.sprucehill.zalando.api.nativecart.model.Order; /** * * @author dipteewarudkar * */ -public class OrderService extends AbstractService implements IOrderService{ +public class OrderService extends AbstractService implements IOrderService { @Override - public CreateOrderResponse create(String customer_number, CreateOrderRequest createOrderRequest) { - HttpPost request = postRequest("/addresses"); + public Order create(String customerNumber, CreateOrderRequest createOrderRequest) { + HttpPost request = postRequest("/customer/" + customerNumber +"/orders"); try { request.setEntity(new StringEntity(objectMapper.writeValueAsString(createOrderRequest))); - } catch (UnsupportedEncodingException e) { - e.printStackTrace(); - } catch (JsonProcessingException e) { - e.printStackTrace(); + }catch(Throwable t) { + logger.warn(t.getMessage()); + throw new RuntimeException(t); } - return execute(request, new TypeReference() {}); + return execute(request, new TypeReference() {}); } - } From 54433f66c6ebeb530192a650de797aaa2affc2bf Mon Sep 17 00:00:00 2001 From: Diptee Warudkar Date: Wed, 2 Mar 2016 17:46:12 +0100 Subject: [PATCH 07/24] Formatting fixes --- .../zalando/api/nativecart/service/CheckoutService.java | 2 +- .../zalando/api/nativecart/service/CustomerService.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/io/sprucehill/zalando/api/nativecart/service/CheckoutService.java b/src/main/java/io/sprucehill/zalando/api/nativecart/service/CheckoutService.java index ea982b6..eb04f89 100644 --- a/src/main/java/io/sprucehill/zalando/api/nativecart/service/CheckoutService.java +++ b/src/main/java/io/sprucehill/zalando/api/nativecart/service/CheckoutService.java @@ -12,7 +12,7 @@ * @author dipteewarudkar * */ -public class CheckoutService extends AbstractService implements ICheckoutService{ +public class CheckoutService extends AbstractService implements ICheckoutService { @Override public Checkout read(String customerNumber, String checkout_id) { diff --git a/src/main/java/io/sprucehill/zalando/api/nativecart/service/CustomerService.java b/src/main/java/io/sprucehill/zalando/api/nativecart/service/CustomerService.java index f4497a4..8093a7b 100644 --- a/src/main/java/io/sprucehill/zalando/api/nativecart/service/CustomerService.java +++ b/src/main/java/io/sprucehill/zalando/api/nativecart/service/CustomerService.java @@ -9,7 +9,7 @@ * @author dipteewarudkar * */ -public class CustomerService extends AbstractService implements ICustomerService{ +public class CustomerService extends AbstractService implements ICustomerService { @Override public Customer read(String customerNumber) { From db78cb1f5cb4ebf1df6c127635a5acb03696a9f2 Mon Sep 17 00:00:00 2001 From: Diptee Warudkar Date: Wed, 2 Mar 2016 18:36:01 +0100 Subject: [PATCH 08/24] Changing response of read(customer_no) in addressService to List
--- .../zalando/api/nativecart/service/AddressService.java | 6 ++++-- .../zalando/api/nativecart/service/IAddressService.java | 4 +++- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/src/main/java/io/sprucehill/zalando/api/nativecart/service/AddressService.java b/src/main/java/io/sprucehill/zalando/api/nativecart/service/AddressService.java index 2b96f38..c677be9 100644 --- a/src/main/java/io/sprucehill/zalando/api/nativecart/service/AddressService.java +++ b/src/main/java/io/sprucehill/zalando/api/nativecart/service/AddressService.java @@ -1,5 +1,7 @@ package io.sprucehill.zalando.api.nativecart.service; +import java.util.List; + import org.apache.http.client.methods.HttpGet; import org.apache.http.client.methods.HttpPost; import org.apache.http.client.methods.HttpPut; @@ -16,9 +18,9 @@ public class AddressService extends AbstractService implements IAddressService { @Override - public Address read(String customerNumber) { + public List
read(String customerNumber) { HttpGet request = getRequest("/customers/" + customerNumber +"/addresses"); - return execute(request, new TypeReference
() {}); + return execute(request, new TypeReference>() {}); } @Override diff --git a/src/main/java/io/sprucehill/zalando/api/nativecart/service/IAddressService.java b/src/main/java/io/sprucehill/zalando/api/nativecart/service/IAddressService.java index 52752c6..11967f4 100644 --- a/src/main/java/io/sprucehill/zalando/api/nativecart/service/IAddressService.java +++ b/src/main/java/io/sprucehill/zalando/api/nativecart/service/IAddressService.java @@ -1,5 +1,7 @@ package io.sprucehill.zalando.api.nativecart.service; +import java.util.List; + import io.sprucehill.zalando.api.nativecart.model.Address; import io.sprucehill.zalando.api.nativecart.model.AddressCheckResponse; @@ -21,7 +23,7 @@ public interface IAddressService { * @param customer_number The customer unique id * @return The list of user addresses */ - Address read(String customerNumber) ; + List
read(String customerNumber) ; /** * From 687364b3302ae42235521824609c233e8732c39d Mon Sep 17 00:00:00 2001 From: Diptee Warudkar Date: Wed, 2 Mar 2016 20:50:21 +0100 Subject: [PATCH 09/24] Fixing build javadoc errors --- .../api/nativecart/service/IAddressService.java | 10 +++++----- .../zalando/api/nativecart/service/ICartService.java | 10 +++++----- .../api/nativecart/service/ICheckoutService.java | 10 +++++----- .../api/nativecart/service/ICustomerService.java | 2 +- .../zalando/api/nativecart/service/IOrderService.java | 2 +- 5 files changed, 17 insertions(+), 17 deletions(-) diff --git a/src/main/java/io/sprucehill/zalando/api/nativecart/service/IAddressService.java b/src/main/java/io/sprucehill/zalando/api/nativecart/service/IAddressService.java index 11967f4..e9db20b 100644 --- a/src/main/java/io/sprucehill/zalando/api/nativecart/service/IAddressService.java +++ b/src/main/java/io/sprucehill/zalando/api/nativecart/service/IAddressService.java @@ -20,22 +20,22 @@ public interface IAddressService { /** * - * @param customer_number The customer unique id + * @param customerNumber The customer unique id * @return The list of user addresses */ List
read(String customerNumber) ; /** * - * @param customer_number The customer unique id - * @param address_id The ID of the address to read + * @param customerNumber The customer unique id + * @param addressId The ID of the address to read * @return The address with the requested ID for the specified customer */ Address read(String customerNumber,String addressId) ; /** * - * @param customer_number The customer unique id + * @param customerNumber The customer unique id * @param address_id The ID of the address to update * @param request The address object to update * @return The updated address object @@ -44,7 +44,7 @@ public interface IAddressService { /** * - * @param customer_number The customer unique id + * @param customerNumber The customer unique id * @param createAddressRequest The address object to create * @return Newly created address object */ diff --git a/src/main/java/io/sprucehill/zalando/api/nativecart/service/ICartService.java b/src/main/java/io/sprucehill/zalando/api/nativecart/service/ICartService.java index 34f84c2..6ee3dfc 100644 --- a/src/main/java/io/sprucehill/zalando/api/nativecart/service/ICartService.java +++ b/src/main/java/io/sprucehill/zalando/api/nativecart/service/ICartService.java @@ -11,7 +11,7 @@ public interface ICartService { /** * - * @param access_token access token for performing create cart operation + * @param accessToken access token for performing create cart operation * @param createCartRequest The Cart object to be created * @return Newly created cart object */ @@ -19,16 +19,16 @@ public interface ICartService { /** * - * @param access_token access token for performing create cart operation - * @param cart_id The ID of the cart to read + * @param accessToken access token for performing create cart operation + * @param cartId The ID of the cart to read * @return The cart with the requested ID for the specified access_token */ Cart read(String accessToken,String cartId); /** * - * @param access_token - * @param cart_id + * @param accessToken + * @param cartId * @param updateCartRequest * @return */ diff --git a/src/main/java/io/sprucehill/zalando/api/nativecart/service/ICheckoutService.java b/src/main/java/io/sprucehill/zalando/api/nativecart/service/ICheckoutService.java index 9cb4e22..463787c 100644 --- a/src/main/java/io/sprucehill/zalando/api/nativecart/service/ICheckoutService.java +++ b/src/main/java/io/sprucehill/zalando/api/nativecart/service/ICheckoutService.java @@ -11,15 +11,15 @@ public interface ICheckoutService { /** * - * @param customer_number The customer unique id - * @param checkout_id The ID of the checkout to read + * @param customerNumber The customer unique id + * @param checkoutId The ID of the checkout to read * @return The checkout object with the requested ID for the specified customer */ Checkout read(String customerNumber,String checkoutId); /** * - * @param customer_number The customer unique id + * @param customerNumber The customer unique id * @param CreatecheckoutRequest The checkout object to be created * @return The newly created checkout object */ @@ -27,8 +27,8 @@ public interface ICheckoutService { /** * - * @param customer_number The customer unique id - * @param checkout_id The ID of the address to update + * @param customerNumber The customer unique id + * @param checkoutId The ID of the address to update * @param updateCheckoutRequest The checkout object to be updated * @return The updated checkout object */ diff --git a/src/main/java/io/sprucehill/zalando/api/nativecart/service/ICustomerService.java b/src/main/java/io/sprucehill/zalando/api/nativecart/service/ICustomerService.java index 0406b52..553b6b5 100644 --- a/src/main/java/io/sprucehill/zalando/api/nativecart/service/ICustomerService.java +++ b/src/main/java/io/sprucehill/zalando/api/nativecart/service/ICustomerService.java @@ -11,7 +11,7 @@ public interface ICustomerService { /** * - * @param customer_number The customer unique id + * @param customerNumber The customer unique id * @return Details of the customer with specified customer_number */ Customer read(String customerNumber); diff --git a/src/main/java/io/sprucehill/zalando/api/nativecart/service/IOrderService.java b/src/main/java/io/sprucehill/zalando/api/nativecart/service/IOrderService.java index b3b1d0c..c10044a 100644 --- a/src/main/java/io/sprucehill/zalando/api/nativecart/service/IOrderService.java +++ b/src/main/java/io/sprucehill/zalando/api/nativecart/service/IOrderService.java @@ -12,7 +12,7 @@ public interface IOrderService { /** * - * @param customer_number The unique id of the customer + * @param customerNumber The unique id of the customer * @param createOrderRequest The order object to be created * @return The newly create order object */ From ec24c2e26cbc039e1996caefe7d228fc2f4f9166 Mon Sep 17 00:00:00 2001 From: Diptee Warudkar Date: Wed, 2 Mar 2016 20:54:28 +0100 Subject: [PATCH 10/24] Fixing some more javadoc build error --- .../zalando/api/nativecart/service/IAddressService.java | 2 +- .../zalando/api/nativecart/service/ICartService.java | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/main/java/io/sprucehill/zalando/api/nativecart/service/IAddressService.java b/src/main/java/io/sprucehill/zalando/api/nativecart/service/IAddressService.java index e9db20b..65a6e7f 100644 --- a/src/main/java/io/sprucehill/zalando/api/nativecart/service/IAddressService.java +++ b/src/main/java/io/sprucehill/zalando/api/nativecart/service/IAddressService.java @@ -36,7 +36,7 @@ public interface IAddressService { /** * * @param customerNumber The customer unique id - * @param address_id The ID of the address to update + * @param addressId The ID of the address to update * @param request The address object to update * @return The updated address object */ diff --git a/src/main/java/io/sprucehill/zalando/api/nativecart/service/ICartService.java b/src/main/java/io/sprucehill/zalando/api/nativecart/service/ICartService.java index 6ee3dfc..c1a6c1f 100644 --- a/src/main/java/io/sprucehill/zalando/api/nativecart/service/ICartService.java +++ b/src/main/java/io/sprucehill/zalando/api/nativecart/service/ICartService.java @@ -21,15 +21,15 @@ public interface ICartService { * * @param accessToken access token for performing create cart operation * @param cartId The ID of the cart to read - * @return The cart with the requested ID for the specified access_token + * @return The cart with the requested ID for the specified accessToken */ Cart read(String accessToken,String cartId); /** * - * @param accessToken - * @param cartId - * @param updateCartRequest + * @param accessToken access token for performing update cart operation + * @param cartId The ID of the cart to update + * @param updateCartRequest Cart object to be updated * @return */ Cart update(String accessToken,String cartId,Cart updateCartRequest); From ac317e4568883a57fde4f321190f64be942eb7ab Mon Sep 17 00:00:00 2001 From: Diptee Warudkar Date: Thu, 3 Mar 2016 10:46:51 +0100 Subject: [PATCH 11/24] 1)Changing Currency to enum 2)Fixing naming bug. --- .../zalando/api/nativecart/model/Customer.java | 8 ++++---- .../sprucehill/zalando/api/nativecart/model/Money.java | 10 +++++++--- 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/src/main/java/io/sprucehill/zalando/api/nativecart/model/Customer.java b/src/main/java/io/sprucehill/zalando/api/nativecart/model/Customer.java index ec09bd5..8d35770 100644 --- a/src/main/java/io/sprucehill/zalando/api/nativecart/model/Customer.java +++ b/src/main/java/io/sprucehill/zalando/api/nativecart/model/Customer.java @@ -10,8 +10,8 @@ */ public class Customer extends Base { - @JsonProperty - private String customer_number; + @JsonProperty(value="customer_number") + private String customerNumber; @JsonProperty private String gender; @@ -25,8 +25,8 @@ public class Customer extends Base { @JsonProperty private String email; - public String getCustomer_number() { - return customer_number; + public String getCustomerNumber() { + return customerNumber; } public String getGender() { diff --git a/src/main/java/io/sprucehill/zalando/api/nativecart/model/Money.java b/src/main/java/io/sprucehill/zalando/api/nativecart/model/Money.java index dad8f6b..77ac03a 100644 --- a/src/main/java/io/sprucehill/zalando/api/nativecart/model/Money.java +++ b/src/main/java/io/sprucehill/zalando/api/nativecart/model/Money.java @@ -11,17 +11,21 @@ */ public class Money extends Base{ + public enum Currency { + EUR,DKK,GBP,CHF,NOK,SEK,PLN + } + @JsonProperty private BigInteger amount; @JsonProperty - private String currency; + private Currency currency; - public String getCurrency() { + public Currency getCurrency() { return currency; } - public void setCurrency(String currency) { + public void setCurrency(Currency currency) { this.currency = currency; } From 3a5c64f21b48adabbc999f77d77d9434b5b81b87 Mon Sep 17 00:00:00 2001 From: Diptee Warudkar Date: Thu, 3 Mar 2016 17:09:28 +0100 Subject: [PATCH 12/24] Adding service for getting access token and some other small changes --- .../zalando/api/nativecart/model/Cart.java | 2 +- .../zalando/api/nativecart/model/Items.java | 7 +++++++ .../nativecart/service/AccessTokenService.java | 15 +++++++++++++++ .../nativecart/service/IAccessTokenService.java | 15 +++++++++++++++ 4 files changed, 38 insertions(+), 1 deletion(-) create mode 100644 src/main/java/io/sprucehill/zalando/api/nativecart/service/AccessTokenService.java create mode 100644 src/main/java/io/sprucehill/zalando/api/nativecart/service/IAccessTokenService.java diff --git a/src/main/java/io/sprucehill/zalando/api/nativecart/model/Cart.java b/src/main/java/io/sprucehill/zalando/api/nativecart/model/Cart.java index 9a9346f..f914c1d 100644 --- a/src/main/java/io/sprucehill/zalando/api/nativecart/model/Cart.java +++ b/src/main/java/io/sprucehill/zalando/api/nativecart/model/Cart.java @@ -10,7 +10,7 @@ * @author dipteewarudkar * */ -public abstract class Cart extends Base { +public class Cart extends Base { @JsonProperty private String id; diff --git a/src/main/java/io/sprucehill/zalando/api/nativecart/model/Items.java b/src/main/java/io/sprucehill/zalando/api/nativecart/model/Items.java index b1cb90f..8f9f4c7 100644 --- a/src/main/java/io/sprucehill/zalando/api/nativecart/model/Items.java +++ b/src/main/java/io/sprucehill/zalando/api/nativecart/model/Items.java @@ -16,6 +16,13 @@ public class Items extends Base { @JsonProperty private Integer quantity; + public Items(){} + + public Items(String sku,Integer quantity){ + this.sku = sku; + this.quantity = quantity; + } + public Integer getQuantity() { return quantity; } diff --git a/src/main/java/io/sprucehill/zalando/api/nativecart/service/AccessTokenService.java b/src/main/java/io/sprucehill/zalando/api/nativecart/service/AccessTokenService.java new file mode 100644 index 0000000..ccdb3a4 --- /dev/null +++ b/src/main/java/io/sprucehill/zalando/api/nativecart/service/AccessTokenService.java @@ -0,0 +1,15 @@ +package io.sprucehill.zalando.api.nativecart.service; + +/** + * + * @author dipteewarudkar + * + */ +public class AccessTokenService extends AbstractService implements IAccessTokenService { + + @Override + public String read() { + // TODO Auto-generated method stub + return null; + } +} diff --git a/src/main/java/io/sprucehill/zalando/api/nativecart/service/IAccessTokenService.java b/src/main/java/io/sprucehill/zalando/api/nativecart/service/IAccessTokenService.java new file mode 100644 index 0000000..6c78bfb --- /dev/null +++ b/src/main/java/io/sprucehill/zalando/api/nativecart/service/IAccessTokenService.java @@ -0,0 +1,15 @@ +package io.sprucehill.zalando.api.nativecart.service; + +/** + * + * @author dipteewarudkar + * + */ +public interface IAccessTokenService { + + /** + * + * @return access token + */ + String read(); +} From bbf107cb8afa3a9f26907161b50e346882ff56eb Mon Sep 17 00:00:00 2001 From: Diptee Warudkar Date: Fri, 4 Mar 2016 16:27:00 +0100 Subject: [PATCH 13/24] Some changes to removing CreateOrderRequest and using the common Order class. Adding token property on Payment Some Camel case fixes --- .../api/nativecart/model/Checkout.java | 10 +++++++- .../nativecart/model/CreateOrderRequest.java | 23 ------------------- .../zalando/api/nativecart/model/Order.java | 7 ++++++ .../zalando/api/nativecart/model/Payment.java | 15 ++++++++++++ .../api/nativecart/service/CartService.java | 4 ++-- .../api/nativecart/service/IOrderService.java | 3 +-- .../api/nativecart/service/OrderService.java | 3 +-- 7 files changed, 35 insertions(+), 30 deletions(-) delete mode 100644 src/main/java/io/sprucehill/zalando/api/nativecart/model/CreateOrderRequest.java diff --git a/src/main/java/io/sprucehill/zalando/api/nativecart/model/Checkout.java b/src/main/java/io/sprucehill/zalando/api/nativecart/model/Checkout.java index 44ee641..73823c8 100644 --- a/src/main/java/io/sprucehill/zalando/api/nativecart/model/Checkout.java +++ b/src/main/java/io/sprucehill/zalando/api/nativecart/model/Checkout.java @@ -8,7 +8,7 @@ * @author dipteewarudkar * */ -public abstract class Checkout extends Base { +public class Checkout extends Base { @JsonProperty private String id; @@ -62,6 +62,14 @@ public String getBillingAddressId() { public String getShippingAddressId() { return shippingAddressId; } + + public void setBillingAddressId(String billingAddressId) { + this.billingAddressId = billingAddressId; + } + + public void setShippingAddressId(String shippingAddressId) { + this.shippingAddressId = shippingAddressId; + } public Delivery getDelivery() { return delivery; diff --git a/src/main/java/io/sprucehill/zalando/api/nativecart/model/CreateOrderRequest.java b/src/main/java/io/sprucehill/zalando/api/nativecart/model/CreateOrderRequest.java deleted file mode 100644 index 523686c..0000000 --- a/src/main/java/io/sprucehill/zalando/api/nativecart/model/CreateOrderRequest.java +++ /dev/null @@ -1,23 +0,0 @@ -package io.sprucehill.zalando.api.nativecart.model; - -import com.fasterxml.jackson.annotation.JsonProperty; -import io.sprucehill.zalando.api.model.Base; - -/** - * - * @author dipteewarudkar - * - */ -public class CreateOrderRequest extends Base { - - @JsonProperty - private String checkoutId; - - public String getCheckoutId() { - return checkoutId; - } - - public void setCheckoutId(String checkoutId) { - this.checkoutId = checkoutId; - } -} diff --git a/src/main/java/io/sprucehill/zalando/api/nativecart/model/Order.java b/src/main/java/io/sprucehill/zalando/api/nativecart/model/Order.java index 8780362..c05eb02 100644 --- a/src/main/java/io/sprucehill/zalando/api/nativecart/model/Order.java +++ b/src/main/java/io/sprucehill/zalando/api/nativecart/model/Order.java @@ -10,6 +10,9 @@ */ public class Order extends Base { + @JsonProperty(value="checkout_id") + private String checkoutId; + @JsonProperty(value="order_number") private String orderNumber; @@ -95,4 +98,8 @@ public String getDetailUrl() { public String getExternalPaymentUrl() { return externalPaymentUrl; } + + public void setCheckoutId(String checkoutId) { + this.checkoutId = checkoutId; + } } diff --git a/src/main/java/io/sprucehill/zalando/api/nativecart/model/Payment.java b/src/main/java/io/sprucehill/zalando/api/nativecart/model/Payment.java index 68f8260..0aa95ff 100644 --- a/src/main/java/io/sprucehill/zalando/api/nativecart/model/Payment.java +++ b/src/main/java/io/sprucehill/zalando/api/nativecart/model/Payment.java @@ -23,11 +23,26 @@ public class Payment extends Base { @JsonProperty private Selected selected; + + @JsonProperty + private String token; + + public String getToken() { + return token; + } + + public void setToken(String token) { + this.token = token; + } public String getCallbackUrl() { return callbackUrl; } + public void setCallbackUrl(String callbackUrl) { + this.callbackUrl = callbackUrl; + } + public Map getTemplateParameters() { return templateParameters; } diff --git a/src/main/java/io/sprucehill/zalando/api/nativecart/service/CartService.java b/src/main/java/io/sprucehill/zalando/api/nativecart/service/CartService.java index f24d7ad..a1227d7 100644 --- a/src/main/java/io/sprucehill/zalando/api/nativecart/service/CartService.java +++ b/src/main/java/io/sprucehill/zalando/api/nativecart/service/CartService.java @@ -16,11 +16,11 @@ public class CartService extends AbstractService implements ICartService { @Override - public Cart create(String access_token, Cart createCartRequest) { + public Cart create(String accessToken, Cart createCartRequest) { HttpPost request = postRequest("/carts"); try { - request.addHeader(HttpHeaders.AUTHORIZATION,"Bearer "+access_token); + request.addHeader(HttpHeaders.AUTHORIZATION,"Bearer "+accessToken); request.setEntity(new StringEntity(objectMapper.writeValueAsString(createCartRequest))); }catch(Throwable t) { logger.warn(t.getMessage()); diff --git a/src/main/java/io/sprucehill/zalando/api/nativecart/service/IOrderService.java b/src/main/java/io/sprucehill/zalando/api/nativecart/service/IOrderService.java index c10044a..40a8e9f 100644 --- a/src/main/java/io/sprucehill/zalando/api/nativecart/service/IOrderService.java +++ b/src/main/java/io/sprucehill/zalando/api/nativecart/service/IOrderService.java @@ -1,6 +1,5 @@ package io.sprucehill.zalando.api.nativecart.service; -import io.sprucehill.zalando.api.nativecart.model.CreateOrderRequest; import io.sprucehill.zalando.api.nativecart.model.Order; /** @@ -16,5 +15,5 @@ public interface IOrderService { * @param createOrderRequest The order object to be created * @return The newly create order object */ - Order create(String customerNumber,CreateOrderRequest createOrderRequest); + Order create(String customerNumber,Order createOrderRequest); } diff --git a/src/main/java/io/sprucehill/zalando/api/nativecart/service/OrderService.java b/src/main/java/io/sprucehill/zalando/api/nativecart/service/OrderService.java index 56efb0b..894c1cd 100644 --- a/src/main/java/io/sprucehill/zalando/api/nativecart/service/OrderService.java +++ b/src/main/java/io/sprucehill/zalando/api/nativecart/service/OrderService.java @@ -3,7 +3,6 @@ import org.apache.http.client.methods.HttpPost; import org.apache.http.entity.StringEntity; import com.fasterxml.jackson.core.type.TypeReference; -import io.sprucehill.zalando.api.nativecart.model.CreateOrderRequest; import io.sprucehill.zalando.api.nativecart.model.Order; /** @@ -14,7 +13,7 @@ public class OrderService extends AbstractService implements IOrderService { @Override - public Order create(String customerNumber, CreateOrderRequest createOrderRequest) { + public Order create(String customerNumber, Order createOrderRequest) { HttpPost request = postRequest("/customer/" + customerNumber +"/orders"); try { request.setEntity(new StringEntity(objectMapper.writeValueAsString(createOrderRequest))); From 8ec5e8c2bbedc1243e9e1495dc9cb9f55abc55b0 Mon Sep 17 00:00:00 2001 From: Diptee Warudkar Date: Mon, 7 Mar 2016 14:15:00 +0100 Subject: [PATCH 14/24] Using Abstract Service from internal package and handling Exceptions --- .../zalando/api/nativecart/model/Address.java | 16 +- .../api/nativecart/model/Delivery.java | 17 +- .../zalando/api/nativecart/model/Order.java | 2 + .../nativecart/service/AbstractService.java | 285 ------------------ .../service/AccessTokenService.java | 10 +- .../nativecart/service/AddressService.java | 13 +- .../api/nativecart/service/CartService.java | 7 +- .../nativecart/service/CheckoutService.java | 7 +- .../nativecart/service/CustomerService.java | 3 +- .../service/IAccessTokenService.java | 2 +- .../nativecart/service/IAddressService.java | 11 +- .../api/nativecart/service/ICartService.java | 6 +- .../nativecart/service/ICheckoutService.java | 6 +- .../nativecart/service/ICustomerService.java | 2 +- .../api/nativecart/service/IOrderService.java | 2 +- .../api/nativecart/service/OrderService.java | 3 +- .../zalando/api/service/AbstractService.java | 8 +- 17 files changed, 66 insertions(+), 334 deletions(-) delete mode 100644 src/main/java/io/sprucehill/zalando/api/nativecart/service/AbstractService.java diff --git a/src/main/java/io/sprucehill/zalando/api/nativecart/model/Address.java b/src/main/java/io/sprucehill/zalando/api/nativecart/model/Address.java index b528961..101339e 100644 --- a/src/main/java/io/sprucehill/zalando/api/nativecart/model/Address.java +++ b/src/main/java/io/sprucehill/zalando/api/nativecart/model/Address.java @@ -51,19 +51,19 @@ public class Address extends Base { public Address(){} - public Address(String id, String customer_number, String gender, String first_name, String last_name, String street,String additional, String zip, String city, String country_code, Boolean pack_station,Boolean default_billing, Boolean default_shipping) { + public Address(String id, String customerNumber, String gender, String firstName, String lastName, String street,String additional, String zip, String city, String countryCode, Boolean packStation,Boolean defaultBilling, Boolean defaultShipping) { this.id=id; - this.customerNumber=customer_number; + this.customerNumber=customerNumber; this.gender=gender; - this.firstName=first_name; - this.lastName=last_name; + this.firstName=firstName; + this.lastName=lastName; this.street=street; this.additional=additional; this.city=city; - this.countryCode=country_code; - this.packStation=pack_station; - this.defaultBilling=default_billing; - this.defaultShipping=default_shipping; + this.countryCode=countryCode; + this.packStation=packStation; + this.defaultBilling=defaultBilling; + this.defaultShipping=defaultShipping; } public String getId() { diff --git a/src/main/java/io/sprucehill/zalando/api/nativecart/model/Delivery.java b/src/main/java/io/sprucehill/zalando/api/nativecart/model/Delivery.java index aade376..b0727e5 100644 --- a/src/main/java/io/sprucehill/zalando/api/nativecart/model/Delivery.java +++ b/src/main/java/io/sprucehill/zalando/api/nativecart/model/Delivery.java @@ -1,5 +1,8 @@ package io.sprucehill.zalando.api.nativecart.model; +import java.util.Date; + +import com.fasterxml.jackson.annotation.JsonFormat; import com.fasterxml.jackson.annotation.JsonProperty; import io.sprucehill.zalando.api.model.Base; @@ -11,24 +14,26 @@ public class Delivery extends Base { @JsonProperty - private String earliest; + @JsonFormat(pattern="yyyy-MM-dd") + private Date earliest; @JsonProperty - private String latest; + @JsonFormat(pattern="yyyy-MM-dd") + private Date latest; - public String getEarliest() { + public Date getEarliest() { return earliest; } - public void setEarliest(String earliest) { + public void setEarliest(Date earliest) { this.earliest = earliest; } - public String getLatest() { + public Date getLatest() { return latest; } - public void setLatest(String latest) { + public void setLatest(Date latest) { this.latest = latest; } } diff --git a/src/main/java/io/sprucehill/zalando/api/nativecart/model/Order.java b/src/main/java/io/sprucehill/zalando/api/nativecart/model/Order.java index c05eb02..e090a6f 100644 --- a/src/main/java/io/sprucehill/zalando/api/nativecart/model/Order.java +++ b/src/main/java/io/sprucehill/zalando/api/nativecart/model/Order.java @@ -1,5 +1,6 @@ package io.sprucehill.zalando.api.nativecart.model; +import com.fasterxml.jackson.annotation.JsonFormat; import com.fasterxml.jackson.annotation.JsonProperty; import io.sprucehill.zalando.api.model.Base; @@ -35,6 +36,7 @@ public class Order extends Base { private Money taxTotal; @JsonProperty + @JsonFormat(pattern = "yyyy-MM-dd") private String created; @JsonProperty(value="detail_url") diff --git a/src/main/java/io/sprucehill/zalando/api/nativecart/service/AbstractService.java b/src/main/java/io/sprucehill/zalando/api/nativecart/service/AbstractService.java deleted file mode 100644 index 724647d..0000000 --- a/src/main/java/io/sprucehill/zalando/api/nativecart/service/AbstractService.java +++ /dev/null @@ -1,285 +0,0 @@ -package io.sprucehill.zalando.api.nativecart.service; - -import com.fasterxml.jackson.core.type.TypeReference; -import com.fasterxml.jackson.databind.ObjectMapper; -import io.sprucehill.zalando.api.model.Domain; -import org.apache.http.HttpHeaders; -import org.apache.http.HttpResponse; -import org.apache.http.client.HttpClient; -import org.apache.http.client.methods.*; -import org.apache.http.client.utils.URIBuilder; -import org.apache.http.impl.client.HttpClientBuilder; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import javax.annotation.PostConstruct; -import java.io.IOException; -import java.net.URI; -import java.net.URISyntaxException; - -/** - * @author Michael Duergner - */ -public abstract class AbstractService { - - String apiBase = "https://api.zalando.com"; - - String scheme; - - String host; - - Integer port; - - String pathPrefix; - - protected Domain defaultDomain; - - protected Logger logger = LoggerFactory.getLogger(getClass()); - - protected HttpClient httpClient; - - protected ObjectMapper objectMapper; - - /** - * Set a different API base - * - * @param apiBase The API base to use; defaults to 'https://api.zalando.com' - */ - public void setApiBase(String apiBase) { - this.apiBase = apiBase; - } - - /** - * Set the default domain to use; this is a mandatory setter to be called - * - * @param defaultDomain The default shop domain to use - */ - public void setDefaultDomain(Domain defaultDomain) { - this.defaultDomain = defaultDomain; - } - - /** - * Set a custom HttpClient to use; the bean will create a default HttpClient on its postConstruct method if no HttpClient has been set previously. - * You might want to set your custom HttpClient as the default implementation does not use any pooling or threading implementation. - * - * @param httpClient The HttpClient to use. - */ - public void setHttpClient(HttpClient httpClient) { - this.httpClient = httpClient; - } - - /** - * Set a custom ObjectMapper to use; the bean will create a default ObjectMapper on its postConstruct method if no ObjectMapper has been set previously. - * - * @param objectMapper The ObjectMapper to use. - */ - public void setObjectMapper(ObjectMapper objectMapper) { - this.objectMapper = objectMapper; - } - - /** - * Call this method on postConstruct for any subclasses as it takes care to initialize the bean - */ - @PostConstruct - public void postConstruct() { - if (null == httpClient) { - httpClient = HttpClientBuilder.create().build(); - } - if (null == objectMapper) { - objectMapper = new ObjectMapper(); - } - if (null == defaultDomain) { - throw new RuntimeException("'defaultDomain' must be set!"); - } - if (null == apiBase) { - throw new RuntimeException("'apiBase' must be set!"); - } - try { - URI uri = new URI(apiBase); - scheme = uri.getScheme(); - host = uri.getHost(); - port = uri.getPort(); - pathPrefix = uri.getPath(); - if (("https".equalsIgnoreCase(scheme) && 443 == port) || ("http".equalsIgnoreCase(scheme) && 80 == port)) { - port = null; - } - if ("/".equalsIgnoreCase(pathPrefix)) { - pathPrefix = null; - } - else if (pathPrefix.endsWith("/")) { - pathPrefix = pathPrefix.substring(0,pathPrefix.length()-1); - } - } - catch (URISyntaxException e) { - throw new RuntimeException("'apiBase' is invalid"); - } - } - - /** - * Create and initialize a GET request for the specified path - * - * @param path The path of the GET request - * @return A HttpGet object for the specified path - */ - HttpGet getRequest(String path) { - return enrich(new HttpGet(normalizePath(path))); - } - - /** - * Create an initialize a GET request for the specified URIBuilder - * - * @param uriBuilder The URIBuilder to work upon - * @return A HttGet object for the specified URIBuilder's URI - * @throws URISyntaxException Throw if URI cannot be built from the supplied URIBuilder - */ - HttpGet getRequest(URIBuilder uriBuilder) throws URISyntaxException { - return enrich(new HttpGet(normalize(uriBuilder))); - } - - /** - * Create and initialize a POST request for the specified path - * - * @param path The path of the POST request - * @return A HttpGet object for the specified path - */ - HttpPost postRequest(String path) { - return enrich(new HttpPost(normalizePath(path))); - } - - /** - * Create and initialize a PUT request for the specified path - * - * @param path The path of the PUT request - * @return A HttpGet object for the specified path - */ - HttpPut putRequest(String path) { - return enrich(new HttpPut(normalizePath(path))); - } - - /** - * Create and initialize a DELETE request for the specified path - * - * @param path The path of the DELETE request - * @return A HttpGet object for the specified path - */ - HttpDelete deleteRequest(String path) { - return enrich(new HttpDelete(normalizePath(path))); - } - - /** - * Helper method to normalize a supplied path; - * the current implementation only append a '/' if none is present and prefix with API Base - * - * @param path The path to normalize - * @return The normalized path - */ - protected String normalizePath(String path) { - if (!path.startsWith("/")) { - path = "/" + path; - } - return apiBase + path; - } - - /** - * Helper method to normalize a supplied path; - * the current implementation will set scheme, host, port and prefix with pathPrefix if present - * - * @param uriBuilder The URIBuilder to work upon - * @return A normalized path with defaults set if necessary - * @throws URISyntaxException Throw if the URL cannot be built - */ - protected String normalize(URIBuilder uriBuilder) throws URISyntaxException { - if (null == uriBuilder.getHost() || null == uriBuilder.getScheme()) { - uriBuilder.setHost(host); - uriBuilder.setScheme(scheme); - if (null != port) { - uriBuilder.setPort(port); - } - if (null != pathPrefix) { - uriBuilder.setPath(pathPrefix + uriBuilder.getPath()); - } - } - return uriBuilder.build().toString(); - } - - /** - * Enrich a HttpRequest with some default stuff; - * the current implementation does nothing here - * - * @param request The request to enrich - * @param Generic method to handle different types of HttpRequests - * @return The supplied HttpRequest object - */ - protected T enrich(T request) { - return request; - } - - /** - * Execute a HttpRequest and handle common response states. - * - * @param request The HttpRequest to execute - * @param typeReference The type of the expected response - * @param Generic method to request different response data - * @return The response data for the request - */ - protected T execute(HttpRequestBase request, TypeReference typeReference) { - try { - if (null == request.getHeaders(HttpHeaders.ACCEPT_LANGUAGE)) { - request.addHeader(HttpHeaders.ACCEPT_LANGUAGE,defaultDomain.getLocale()); - } - HttpResponse httpResponse = httpClient.execute(request); - if (200 == httpResponse.getStatusLine().getStatusCode()) { - return objectMapper.readValue(httpResponse.getEntity().getContent(),typeReference); - } - else { - throw new RuntimeException("StatusCode: "+httpResponse.getStatusLine().getStatusCode() + ", Reason: " + httpResponse.getStatusLine().getReasonPhrase()); - } - } - catch (IOException e) { - logger.error(e.getMessage(), e); - throw new RuntimeException(e); - } - finally { - if (null != request && !request.isAborted()) { - request.abort(); - } - } - } - - protected static abstract class Init> { - - protected S service; - - protected Init(S service) { - this.service = service; - } - - public B withHttpClient(HttpClient httpClient) { - service.setHttpClient(httpClient); - return self(); - } - - public B withObjectMapper(ObjectMapper objectMapper) { - service.setObjectMapper(objectMapper); - return self(); - } - - public B withApiBase(String apiBase) { - service.setApiBase(apiBase); - return self(); - } - - public B withDefaultDomain(Domain defaultDomain) { - service.setDefaultDomain(defaultDomain); - return self(); - } - - protected void onBuild() { - service.postConstruct(); - } - - protected abstract B self(); - - public abstract I build(); - } -} diff --git a/src/main/java/io/sprucehill/zalando/api/nativecart/service/AccessTokenService.java b/src/main/java/io/sprucehill/zalando/api/nativecart/service/AccessTokenService.java index ccdb3a4..3f62e24 100644 --- a/src/main/java/io/sprucehill/zalando/api/nativecart/service/AccessTokenService.java +++ b/src/main/java/io/sprucehill/zalando/api/nativecart/service/AccessTokenService.java @@ -1,5 +1,9 @@ package io.sprucehill.zalando.api.nativecart.service; +import org.apache.http.client.methods.HttpGet; +import com.fasterxml.jackson.core.type.TypeReference; +import io.sprucehill.zalando.api.service.AbstractService; + /** * * @author dipteewarudkar @@ -8,8 +12,8 @@ public class AccessTokenService extends AbstractService implements IAccessTokenService { @Override - public String read() { - // TODO Auto-generated method stub - return null; + public String read() throws Exception { + HttpGet request = getRequest("https://token.services.auth.zalando.com/oauth2/access_token?realm=/external-services"); + return execute(request, new TypeReference() {}); } } diff --git a/src/main/java/io/sprucehill/zalando/api/nativecart/service/AddressService.java b/src/main/java/io/sprucehill/zalando/api/nativecart/service/AddressService.java index c677be9..749a8d6 100644 --- a/src/main/java/io/sprucehill/zalando/api/nativecart/service/AddressService.java +++ b/src/main/java/io/sprucehill/zalando/api/nativecart/service/AddressService.java @@ -7,8 +7,11 @@ import org.apache.http.client.methods.HttpPut; import org.apache.http.entity.StringEntity; import com.fasterxml.jackson.core.type.TypeReference; + +import io.sprucehill.zalando.api.exception.NotFoundException; import io.sprucehill.zalando.api.nativecart.model.Address; import io.sprucehill.zalando.api.nativecart.model.AddressCheckResponse; +import io.sprucehill.zalando.api.service.AbstractService; /** * @@ -18,19 +21,19 @@ public class AddressService extends AbstractService implements IAddressService { @Override - public List
read(String customerNumber) { + public List
read(String customerNumber) throws Exception { HttpGet request = getRequest("/customers/" + customerNumber +"/addresses"); return execute(request, new TypeReference>() {}); } @Override - public Address read(String customerNumber, String addressId) { + public Address read(String customerNumber, String addressId) throws Exception { HttpGet request = getRequest("/customers/" + customerNumber +"/addresses/"+addressId); return execute(request, new TypeReference
() {}); } @Override - public Address update(String customerNumber, String addressId, Address updateAddressRequest) { + public Address update(String customerNumber, String addressId, Address updateAddressRequest) throws Exception { HttpPut request = putRequest("/customers/" + customerNumber +"/addresses/"+addressId); try { @@ -43,13 +46,13 @@ public Address update(String customerNumber, String addressId, Address updateAdd } @Override - public Address create(String customerNumber, Address createAddressRequest) { + public Address create(String customerNumber, Address createAddressRequest) throws Exception { HttpGet request = getRequest("/customers/" + customerNumber+"/addresses"); return execute(request, new TypeReference
() {}); } @Override - public AddressCheckResponse checkAddress(Address checkAddressRequest) { + public AddressCheckResponse checkAddress(Address checkAddressRequest) throws Exception { HttpPost request = postRequest("/addresses"); try { request.setEntity(new StringEntity(objectMapper.writeValueAsString(checkAddressRequest))); diff --git a/src/main/java/io/sprucehill/zalando/api/nativecart/service/CartService.java b/src/main/java/io/sprucehill/zalando/api/nativecart/service/CartService.java index a1227d7..7dc1137 100644 --- a/src/main/java/io/sprucehill/zalando/api/nativecart/service/CartService.java +++ b/src/main/java/io/sprucehill/zalando/api/nativecart/service/CartService.java @@ -7,6 +7,7 @@ import org.apache.http.entity.StringEntity; import com.fasterxml.jackson.core.type.TypeReference; import io.sprucehill.zalando.api.nativecart.model.Cart; +import io.sprucehill.zalando.api.service.AbstractService; /** * @@ -16,7 +17,7 @@ public class CartService extends AbstractService implements ICartService { @Override - public Cart create(String accessToken, Cart createCartRequest) { + public Cart create(String accessToken, Cart createCartRequest) throws Exception { HttpPost request = postRequest("/carts"); try { @@ -30,14 +31,14 @@ public Cart create(String accessToken, Cart createCartRequest) { } @Override - public Cart read(String access_token, String cart_id) { + public Cart read(String access_token, String cart_id) throws Exception { HttpGet request = getRequest("/carts/" + cart_id); request.addHeader(HttpHeaders.AUTHORIZATION,"Bearer "+access_token); return execute(request, new TypeReference() {}); } @Override - public Cart update(String access_token, String cart_id,Cart updateCartRequest) { + public Cart update(String access_token, String cart_id,Cart updateCartRequest) throws Exception { HttpPut request = putRequest("/carts/"+cart_id); try { diff --git a/src/main/java/io/sprucehill/zalando/api/nativecart/service/CheckoutService.java b/src/main/java/io/sprucehill/zalando/api/nativecart/service/CheckoutService.java index eb04f89..c93c604 100644 --- a/src/main/java/io/sprucehill/zalando/api/nativecart/service/CheckoutService.java +++ b/src/main/java/io/sprucehill/zalando/api/nativecart/service/CheckoutService.java @@ -6,6 +6,7 @@ import org.apache.http.entity.StringEntity; import com.fasterxml.jackson.core.type.TypeReference; import io.sprucehill.zalando.api.nativecart.model.Checkout; +import io.sprucehill.zalando.api.service.AbstractService; /** * @@ -15,13 +16,13 @@ public class CheckoutService extends AbstractService implements ICheckoutService { @Override - public Checkout read(String customerNumber, String checkout_id) { + public Checkout read(String customerNumber, String checkout_id) throws Exception { HttpGet request = getRequest("/customer/"+customerNumber+"/checkouts/"+checkout_id); return execute(request, new TypeReference() {}); } @Override - public Checkout create(String customerNumber, Checkout createcheckoutRequest) { + public Checkout create(String customerNumber, Checkout createcheckoutRequest) throws Exception { HttpPost request = postRequest("/customer/"+customerNumber+"/checkouts"); try { @@ -34,7 +35,7 @@ public Checkout create(String customerNumber, Checkout createcheckoutRequest) { } @Override - public Checkout update(String customerNumber, String checkoutId,Checkout updateCheckoutRequest) { + public Checkout update(String customerNumber, String checkoutId,Checkout updateCheckoutRequest) throws Exception { HttpPut request = putRequest("/customer/"+customerNumber+"/checkouts/"+checkoutId); try { diff --git a/src/main/java/io/sprucehill/zalando/api/nativecart/service/CustomerService.java b/src/main/java/io/sprucehill/zalando/api/nativecart/service/CustomerService.java index 8093a7b..4e16639 100644 --- a/src/main/java/io/sprucehill/zalando/api/nativecart/service/CustomerService.java +++ b/src/main/java/io/sprucehill/zalando/api/nativecart/service/CustomerService.java @@ -3,6 +3,7 @@ import org.apache.http.client.methods.HttpGet; import com.fasterxml.jackson.core.type.TypeReference; import io.sprucehill.zalando.api.nativecart.model.Customer; +import io.sprucehill.zalando.api.service.AbstractService; /** * @@ -12,7 +13,7 @@ public class CustomerService extends AbstractService implements ICustomerService { @Override - public Customer read(String customerNumber) { + public Customer read(String customerNumber) throws Exception { HttpGet request = getRequest("/customers/" + customerNumber); return execute(request, new TypeReference() {}); } diff --git a/src/main/java/io/sprucehill/zalando/api/nativecart/service/IAccessTokenService.java b/src/main/java/io/sprucehill/zalando/api/nativecart/service/IAccessTokenService.java index 6c78bfb..ea5fdcd 100644 --- a/src/main/java/io/sprucehill/zalando/api/nativecart/service/IAccessTokenService.java +++ b/src/main/java/io/sprucehill/zalando/api/nativecart/service/IAccessTokenService.java @@ -11,5 +11,5 @@ public interface IAccessTokenService { * * @return access token */ - String read(); + String read() throws Exception; } diff --git a/src/main/java/io/sprucehill/zalando/api/nativecart/service/IAddressService.java b/src/main/java/io/sprucehill/zalando/api/nativecart/service/IAddressService.java index 65a6e7f..9bb2df3 100644 --- a/src/main/java/io/sprucehill/zalando/api/nativecart/service/IAddressService.java +++ b/src/main/java/io/sprucehill/zalando/api/nativecart/service/IAddressService.java @@ -1,7 +1,6 @@ package io.sprucehill.zalando.api.nativecart.service; import java.util.List; - import io.sprucehill.zalando.api.nativecart.model.Address; import io.sprucehill.zalando.api.nativecart.model.AddressCheckResponse; @@ -16,14 +15,14 @@ public interface IAddressService { * @param checkAddressRequest The address object to be checked * @return The address object with normalized address */ - AddressCheckResponse checkAddress(Address checkAddressRequest); + AddressCheckResponse checkAddress(Address checkAddressRequest) throws Exception; /** * * @param customerNumber The customer unique id * @return The list of user addresses */ - List
read(String customerNumber) ; + List
read(String customerNumber) throws Exception ; /** * @@ -31,7 +30,7 @@ public interface IAddressService { * @param addressId The ID of the address to read * @return The address with the requested ID for the specified customer */ - Address read(String customerNumber,String addressId) ; + Address read(String customerNumber,String addressId) throws Exception; /** * @@ -40,7 +39,7 @@ public interface IAddressService { * @param request The address object to update * @return The updated address object */ - Address update(String customerNumber,String addressId,Address request); + Address update(String customerNumber,String addressId,Address request) throws Exception; /** * @@ -48,5 +47,5 @@ public interface IAddressService { * @param createAddressRequest The address object to create * @return Newly created address object */ - Address create(String customerNumber,Address createAddressRequest); + Address create(String customerNumber,Address createAddressRequest) throws Exception; } diff --git a/src/main/java/io/sprucehill/zalando/api/nativecart/service/ICartService.java b/src/main/java/io/sprucehill/zalando/api/nativecart/service/ICartService.java index c1a6c1f..71cf791 100644 --- a/src/main/java/io/sprucehill/zalando/api/nativecart/service/ICartService.java +++ b/src/main/java/io/sprucehill/zalando/api/nativecart/service/ICartService.java @@ -15,7 +15,7 @@ public interface ICartService { * @param createCartRequest The Cart object to be created * @return Newly created cart object */ - Cart create(String accessToken,Cart createCartRequest); + Cart create(String accessToken,Cart createCartRequest) throws Exception; /** * @@ -23,7 +23,7 @@ public interface ICartService { * @param cartId The ID of the cart to read * @return The cart with the requested ID for the specified accessToken */ - Cart read(String accessToken,String cartId); + Cart read(String accessToken,String cartId) throws Exception; /** * @@ -32,5 +32,5 @@ public interface ICartService { * @param updateCartRequest Cart object to be updated * @return */ - Cart update(String accessToken,String cartId,Cart updateCartRequest); + Cart update(String accessToken,String cartId,Cart updateCartRequest) throws Exception; } diff --git a/src/main/java/io/sprucehill/zalando/api/nativecart/service/ICheckoutService.java b/src/main/java/io/sprucehill/zalando/api/nativecart/service/ICheckoutService.java index 463787c..e93729f 100644 --- a/src/main/java/io/sprucehill/zalando/api/nativecart/service/ICheckoutService.java +++ b/src/main/java/io/sprucehill/zalando/api/nativecart/service/ICheckoutService.java @@ -15,7 +15,7 @@ public interface ICheckoutService { * @param checkoutId The ID of the checkout to read * @return The checkout object with the requested ID for the specified customer */ - Checkout read(String customerNumber,String checkoutId); + Checkout read(String customerNumber,String checkoutId) throws Exception; /** * @@ -23,7 +23,7 @@ public interface ICheckoutService { * @param CreatecheckoutRequest The checkout object to be created * @return The newly created checkout object */ - Checkout create(String customerNumber,Checkout CreatecheckoutRequest); + Checkout create(String customerNumber,Checkout CreatecheckoutRequest) throws Exception; /** * @@ -32,6 +32,6 @@ public interface ICheckoutService { * @param updateCheckoutRequest The checkout object to be updated * @return The updated checkout object */ - Checkout update(String customerNumber,String checkoutId,Checkout updateCheckoutRequest); + Checkout update(String customerNumber,String checkoutId,Checkout updateCheckoutRequest) throws Exception; } diff --git a/src/main/java/io/sprucehill/zalando/api/nativecart/service/ICustomerService.java b/src/main/java/io/sprucehill/zalando/api/nativecart/service/ICustomerService.java index 553b6b5..25e1e44 100644 --- a/src/main/java/io/sprucehill/zalando/api/nativecart/service/ICustomerService.java +++ b/src/main/java/io/sprucehill/zalando/api/nativecart/service/ICustomerService.java @@ -14,5 +14,5 @@ public interface ICustomerService { * @param customerNumber The customer unique id * @return Details of the customer with specified customer_number */ - Customer read(String customerNumber); + Customer read(String customerNumber) throws Exception; } diff --git a/src/main/java/io/sprucehill/zalando/api/nativecart/service/IOrderService.java b/src/main/java/io/sprucehill/zalando/api/nativecart/service/IOrderService.java index 40a8e9f..07a40b5 100644 --- a/src/main/java/io/sprucehill/zalando/api/nativecart/service/IOrderService.java +++ b/src/main/java/io/sprucehill/zalando/api/nativecart/service/IOrderService.java @@ -15,5 +15,5 @@ public interface IOrderService { * @param createOrderRequest The order object to be created * @return The newly create order object */ - Order create(String customerNumber,Order createOrderRequest); + Order create(String customerNumber,Order createOrderRequest) throws Exception; } diff --git a/src/main/java/io/sprucehill/zalando/api/nativecart/service/OrderService.java b/src/main/java/io/sprucehill/zalando/api/nativecart/service/OrderService.java index 894c1cd..0038a6f 100644 --- a/src/main/java/io/sprucehill/zalando/api/nativecart/service/OrderService.java +++ b/src/main/java/io/sprucehill/zalando/api/nativecart/service/OrderService.java @@ -4,6 +4,7 @@ import org.apache.http.entity.StringEntity; import com.fasterxml.jackson.core.type.TypeReference; import io.sprucehill.zalando.api.nativecart.model.Order; +import io.sprucehill.zalando.api.service.AbstractService; /** * @@ -13,7 +14,7 @@ public class OrderService extends AbstractService implements IOrderService { @Override - public Order create(String customerNumber, Order createOrderRequest) { + public Order create(String customerNumber, Order createOrderRequest) throws Exception { HttpPost request = postRequest("/customer/" + customerNumber +"/orders"); try { request.setEntity(new StringEntity(objectMapper.writeValueAsString(createOrderRequest))); diff --git a/src/main/java/io/sprucehill/zalando/api/service/AbstractService.java b/src/main/java/io/sprucehill/zalando/api/service/AbstractService.java index 9f33cbd..4772df9 100644 --- a/src/main/java/io/sprucehill/zalando/api/service/AbstractService.java +++ b/src/main/java/io/sprucehill/zalando/api/service/AbstractService.java @@ -122,7 +122,7 @@ else if (pathPrefix.endsWith("/")) { * @param path The path of the GET request * @return A HttpGet object for the specified path */ - HttpGet getRequest(String path) { + protected HttpGet getRequest(String path) { return enrich(new HttpGet(normalizePath(path))); } @@ -143,7 +143,7 @@ HttpGet getRequest(URIBuilder uriBuilder) throws URISyntaxException { * @param path The path of the POST request * @return A HttpGet object for the specified path */ - HttpPost postRequest(String path) { + protected HttpPost postRequest(String path) { return enrich(new HttpPost(normalizePath(path))); } @@ -153,7 +153,7 @@ HttpPost postRequest(String path) { * @param path The path of the PUT request * @return A HttpGet object for the specified path */ - HttpPut putRequest(String path) { + protected HttpPut putRequest(String path) { return enrich(new HttpPut(normalizePath(path))); } @@ -222,7 +222,7 @@ protected T enrich(T request) { * @param typeReference The type of the expected response * @param Generic method to request different response data * @return The response data for the request - * @throws NotFoundException This exception is thrown when a 404 status code is encountered on the response + * @throws ZalandoException This exception is thrown when a status other then 200 is encountered */ protected T execute(HttpRequestBase request, TypeReference typeReference) throws NotFoundException { try { From c1065e9af5bf59de3e58df77819019e3c4c3effd Mon Sep 17 00:00:00 2001 From: Diptee Warudkar Date: Fri, 11 Mar 2016 18:05:39 +0100 Subject: [PATCH 15/24] Some changes needed while integrating with live zalando Apis --- .../zalando/api/nativecart/model/Cart.java | 2 +- .../api/nativecart/model/TokenInfo.java | 46 +++++++++++++++++++ .../service/AccessTokenService.java | 8 ++++ .../nativecart/service/AddressService.java | 20 +++++--- .../api/nativecart/service/CartService.java | 3 ++ .../service/IAccessTokenService.java | 10 ++++ .../nativecart/service/IAddressService.java | 10 ++-- 7 files changed, 86 insertions(+), 13 deletions(-) create mode 100644 src/main/java/io/sprucehill/zalando/api/nativecart/model/TokenInfo.java diff --git a/src/main/java/io/sprucehill/zalando/api/nativecart/model/Cart.java b/src/main/java/io/sprucehill/zalando/api/nativecart/model/Cart.java index f914c1d..371e4bc 100644 --- a/src/main/java/io/sprucehill/zalando/api/nativecart/model/Cart.java +++ b/src/main/java/io/sprucehill/zalando/api/nativecart/model/Cart.java @@ -15,7 +15,7 @@ public class Cart extends Base { @JsonProperty private String id; - @JsonProperty + @JsonProperty(value="app_domain_id") private String appDomainId; @JsonProperty diff --git a/src/main/java/io/sprucehill/zalando/api/nativecart/model/TokenInfo.java b/src/main/java/io/sprucehill/zalando/api/nativecart/model/TokenInfo.java new file mode 100644 index 0000000..ccd3cfb --- /dev/null +++ b/src/main/java/io/sprucehill/zalando/api/nativecart/model/TokenInfo.java @@ -0,0 +1,46 @@ +package io.sprucehill.zalando.api.nativecart.model; + +import com.fasterxml.jackson.annotation.JsonProperty; +import io.sprucehill.zalando.api.model.Base; + +/** + * + * @author dipteewarudkar + * + */ +public class TokenInfo extends Base{ + + @JsonProperty(value="token_type") + public String tokenType; + + @JsonProperty(value="access_token") + public String accessToken; + + @JsonProperty(value="uid") + public String customerNumber; + + public String getTokenType() { + return tokenType; + } + + public void setTokenType(String tokenType) { + this.tokenType = tokenType; + } + + public String getAccessToken() { + return accessToken; + } + + public void setAccessToken(String accessToken) { + this.accessToken = accessToken; + } + + public String getCustomerNumber() { + return customerNumber; + } + + public void setCustomerNumber(String customerNumber) { + this.customerNumber = customerNumber; + } +} + diff --git a/src/main/java/io/sprucehill/zalando/api/nativecart/service/AccessTokenService.java b/src/main/java/io/sprucehill/zalando/api/nativecart/service/AccessTokenService.java index 3f62e24..8c1801c 100644 --- a/src/main/java/io/sprucehill/zalando/api/nativecart/service/AccessTokenService.java +++ b/src/main/java/io/sprucehill/zalando/api/nativecart/service/AccessTokenService.java @@ -2,6 +2,8 @@ import org.apache.http.client.methods.HttpGet; import com.fasterxml.jackson.core.type.TypeReference; + +import io.sprucehill.zalando.api.nativecart.model.TokenInfo; import io.sprucehill.zalando.api.service.AbstractService; /** @@ -16,4 +18,10 @@ public String read() throws Exception { HttpGet request = getRequest("https://token.services.auth.zalando.com/oauth2/access_token?realm=/external-services"); return execute(request, new TypeReference() {}); } + + @Override + public TokenInfo read(String accessToken) throws Exception { + HttpGet request = new HttpGet("https://atlas-openam-staging.dc.zalan.do/openam/oauth2/tokeninfo?access_token="+accessToken); + return execute(request, new TypeReference() {}); + } } diff --git a/src/main/java/io/sprucehill/zalando/api/nativecart/service/AddressService.java b/src/main/java/io/sprucehill/zalando/api/nativecart/service/AddressService.java index 749a8d6..8b105ba 100644 --- a/src/main/java/io/sprucehill/zalando/api/nativecart/service/AddressService.java +++ b/src/main/java/io/sprucehill/zalando/api/nativecart/service/AddressService.java @@ -7,8 +7,6 @@ import org.apache.http.client.methods.HttpPut; import org.apache.http.entity.StringEntity; import com.fasterxml.jackson.core.type.TypeReference; - -import io.sprucehill.zalando.api.exception.NotFoundException; import io.sprucehill.zalando.api.nativecart.model.Address; import io.sprucehill.zalando.api.nativecart.model.AddressCheckResponse; import io.sprucehill.zalando.api.service.AbstractService; @@ -21,22 +19,26 @@ public class AddressService extends AbstractService implements IAddressService { @Override - public List
read(String customerNumber) throws Exception { + public List
read(String accessToken,String customerNumber) throws Exception { HttpGet request = getRequest("/customers/" + customerNumber +"/addresses"); + request.setHeader("Authorization","Bearer "+accessToken); return execute(request, new TypeReference>() {}); } @Override - public Address read(String customerNumber, String addressId) throws Exception { + public Address read(String accessToken,String customerNumber, String addressId) throws Exception { HttpGet request = getRequest("/customers/" + customerNumber +"/addresses/"+addressId); + request.setHeader("Authorization","Bearer "+accessToken); return execute(request, new TypeReference
() {}); } @Override - public Address update(String customerNumber, String addressId, Address updateAddressRequest) throws Exception { + public Address update(String accessToken,String customerNumber, String addressId, Address updateAddressRequest) throws Exception { HttpPut request = putRequest("/customers/" + customerNumber +"/addresses/"+addressId); try { + request.setHeader("Authorization","Bearer "+accessToken); + request.addHeader("Content-Type","application/x.zalando.customer.address.update+json"); request.setEntity(new StringEntity(objectMapper.writeValueAsString(updateAddressRequest))); }catch(Throwable t) { logger.warn(t.getMessage()); @@ -46,15 +48,19 @@ public Address update(String customerNumber, String addressId, Address updateAdd } @Override - public Address create(String customerNumber, Address createAddressRequest) throws Exception { + public Address create(String accessToken,String customerNumber, Address createAddressRequest) throws Exception { HttpGet request = getRequest("/customers/" + customerNumber+"/addresses"); + request.setHeader("Authorization","Bearer "+accessToken); + request.addHeader("Content-Type","application/x.zalando.customer.address.create+json"); return execute(request, new TypeReference
() {}); } @Override - public AddressCheckResponse checkAddress(Address checkAddressRequest) throws Exception { + public AddressCheckResponse checkAddress(String accessToken,Address checkAddressRequest) throws Exception { HttpPost request = postRequest("/addresses"); try { + request.setHeader("Authorization","Bearer "+accessToken); + request.addHeader("Content-Type","application/x.zalando.address-check.create+json"); request.setEntity(new StringEntity(objectMapper.writeValueAsString(checkAddressRequest))); }catch(Throwable t) { logger.warn(t.getMessage()); diff --git a/src/main/java/io/sprucehill/zalando/api/nativecart/service/CartService.java b/src/main/java/io/sprucehill/zalando/api/nativecart/service/CartService.java index 7dc1137..0d852a3 100644 --- a/src/main/java/io/sprucehill/zalando/api/nativecart/service/CartService.java +++ b/src/main/java/io/sprucehill/zalando/api/nativecart/service/CartService.java @@ -22,6 +22,7 @@ public Cart create(String accessToken, Cart createCartRequest) throws Exception try { request.addHeader(HttpHeaders.AUTHORIZATION,"Bearer "+accessToken); + request.addHeader("Content-Type","application/x.zalando.cart.create+json"); request.setEntity(new StringEntity(objectMapper.writeValueAsString(createCartRequest))); }catch(Throwable t) { logger.warn(t.getMessage()); @@ -33,6 +34,7 @@ public Cart create(String accessToken, Cart createCartRequest) throws Exception @Override public Cart read(String access_token, String cart_id) throws Exception { HttpGet request = getRequest("/carts/" + cart_id); + request.addHeader("Content-Type","application/x.zalando.cart+json"); request.addHeader(HttpHeaders.AUTHORIZATION,"Bearer "+access_token); return execute(request, new TypeReference() {}); } @@ -43,6 +45,7 @@ public Cart update(String access_token, String cart_id,Cart updateCartRequest) t try { request.addHeader(HttpHeaders.AUTHORIZATION,"Bearer "+access_token); + request.addHeader("Content-Type","application/x.zalando.cart.update+json"); request.setEntity(new StringEntity(objectMapper.writeValueAsString(updateCartRequest))); }catch(Throwable t) { logger.warn(t.getMessage()); diff --git a/src/main/java/io/sprucehill/zalando/api/nativecart/service/IAccessTokenService.java b/src/main/java/io/sprucehill/zalando/api/nativecart/service/IAccessTokenService.java index ea5fdcd..e1f322c 100644 --- a/src/main/java/io/sprucehill/zalando/api/nativecart/service/IAccessTokenService.java +++ b/src/main/java/io/sprucehill/zalando/api/nativecart/service/IAccessTokenService.java @@ -1,5 +1,7 @@ package io.sprucehill.zalando.api.nativecart.service; +import io.sprucehill.zalando.api.nativecart.model.TokenInfo; + /** * * @author dipteewarudkar @@ -12,4 +14,12 @@ public interface IAccessTokenService { * @return access token */ String read() throws Exception; + + /** + * + * @param accessToken + * @return + * @throws Exception + */ + TokenInfo read(String accessToken) throws Exception; } diff --git a/src/main/java/io/sprucehill/zalando/api/nativecart/service/IAddressService.java b/src/main/java/io/sprucehill/zalando/api/nativecart/service/IAddressService.java index 9bb2df3..7fc2648 100644 --- a/src/main/java/io/sprucehill/zalando/api/nativecart/service/IAddressService.java +++ b/src/main/java/io/sprucehill/zalando/api/nativecart/service/IAddressService.java @@ -15,14 +15,14 @@ public interface IAddressService { * @param checkAddressRequest The address object to be checked * @return The address object with normalized address */ - AddressCheckResponse checkAddress(Address checkAddressRequest) throws Exception; + AddressCheckResponse checkAddress(String accessToken,Address checkAddressRequest) throws Exception; /** * * @param customerNumber The customer unique id * @return The list of user addresses */ - List
read(String customerNumber) throws Exception ; + List
read(String accessToken,String customerNumber) throws Exception ; /** * @@ -30,7 +30,7 @@ public interface IAddressService { * @param addressId The ID of the address to read * @return The address with the requested ID for the specified customer */ - Address read(String customerNumber,String addressId) throws Exception; + Address read(String accessToken,String customerNumber,String addressId) throws Exception; /** * @@ -39,7 +39,7 @@ public interface IAddressService { * @param request The address object to update * @return The updated address object */ - Address update(String customerNumber,String addressId,Address request) throws Exception; + Address update(String accessToken,String customerNumber,String addressId,Address request) throws Exception; /** * @@ -47,5 +47,5 @@ public interface IAddressService { * @param createAddressRequest The address object to create * @return Newly created address object */ - Address create(String customerNumber,Address createAddressRequest) throws Exception; + Address create(String accessToken,String customerNumber,Address createAddressRequest) throws Exception; } From 137c1566357f31f75f7600edcca2e8f1a1a9978f Mon Sep 17 00:00:00 2001 From: Diptee Warudkar Date: Thu, 17 Mar 2016 11:28:20 +0100 Subject: [PATCH 16/24] =?UTF-8?q?Changing=20StringEntity=20to=20ByteEntity?= =?UTF-8?q?=20to=20save=20special=20characters=20such=20as=20(=C3=BC)=20wh?= =?UTF-8?q?en=20posting=20data?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Adding "problem" class to get details of the exceptions Changing the api path for adding updating cart Passing accessToken to get customer details Adding clientId and clientCredentials in abstractservice --- .../zalando/api/nativecart/model/Address.java | 1 + .../nativecart/model/AddressCheckRequest.java | 24 + .../zalando/api/nativecart/model/Cart.java | 4 +- .../zalando/api/nativecart/model/Problem.java | 50 ++ .../service/AccessTokenService.java | 18 +- .../nativecart/service/AddressService.java | 14 +- .../api/nativecart/service/CartService.java | 10 +- .../nativecart/service/CustomerService.java | 3 +- .../service/IAccessTokenService.java | 15 +- .../nativecart/service/IAddressService.java | 3 +- .../nativecart/service/ICustomerService.java | 2 +- .../zalando/api/service/AbstractService.java | 569 ++++++++++-------- 12 files changed, 427 insertions(+), 286 deletions(-) create mode 100644 src/main/java/io/sprucehill/zalando/api/nativecart/model/AddressCheckRequest.java create mode 100644 src/main/java/io/sprucehill/zalando/api/nativecart/model/Problem.java diff --git a/src/main/java/io/sprucehill/zalando/api/nativecart/model/Address.java b/src/main/java/io/sprucehill/zalando/api/nativecart/model/Address.java index 101339e..7793fde 100644 --- a/src/main/java/io/sprucehill/zalando/api/nativecart/model/Address.java +++ b/src/main/java/io/sprucehill/zalando/api/nativecart/model/Address.java @@ -64,6 +64,7 @@ public Address(String id, String customerNumber, String gender, String firstName this.packStation=packStation; this.defaultBilling=defaultBilling; this.defaultShipping=defaultShipping; + this.zip = zip; } public String getId() { diff --git a/src/main/java/io/sprucehill/zalando/api/nativecart/model/AddressCheckRequest.java b/src/main/java/io/sprucehill/zalando/api/nativecart/model/AddressCheckRequest.java new file mode 100644 index 0000000..ae03497 --- /dev/null +++ b/src/main/java/io/sprucehill/zalando/api/nativecart/model/AddressCheckRequest.java @@ -0,0 +1,24 @@ +package io.sprucehill.zalando.api.nativecart.model; + +import com.fasterxml.jackson.annotation.JsonProperty; + +import io.sprucehill.zalando.api.model.Base; + +/** + * + * @author dipteewarudkar + * + */ +public class AddressCheckRequest extends Base { + + @JsonProperty + private Address address; + + public Address getAddress() { + return address; + } + + public void setAddress(Address address) { + this.address = address; + } +} diff --git a/src/main/java/io/sprucehill/zalando/api/nativecart/model/Cart.java b/src/main/java/io/sprucehill/zalando/api/nativecart/model/Cart.java index 371e4bc..77a947f 100644 --- a/src/main/java/io/sprucehill/zalando/api/nativecart/model/Cart.java +++ b/src/main/java/io/sprucehill/zalando/api/nativecart/model/Cart.java @@ -21,7 +21,7 @@ public class Cart extends Base { @JsonProperty private List items = new ArrayList(); - @JsonProperty + @JsonProperty(value="items_out_of_stock") private List itemsOutOfStock = new ArrayList(); @JsonProperty @@ -33,7 +33,7 @@ public class Cart extends Base { @JsonProperty private Money taxTotal; - @JsonProperty + @JsonProperty(value="cart_url") private String cartUrl; public Cart() {} diff --git a/src/main/java/io/sprucehill/zalando/api/nativecart/model/Problem.java b/src/main/java/io/sprucehill/zalando/api/nativecart/model/Problem.java new file mode 100644 index 0000000..8fd0caf --- /dev/null +++ b/src/main/java/io/sprucehill/zalando/api/nativecart/model/Problem.java @@ -0,0 +1,50 @@ +package io.sprucehill.zalando.api.nativecart.model; + +import io.sprucehill.zalando.api.model.Base; + +/** + * + * @author dipteewarudkar + * + */ +public class Problem extends Base{ + + private String type; + private String title; + private String status; + private String detail; + private String instance; + public String getType() { + return type; + } + public void setType(String type) { + this.type = type; + } + public String getTitle() { + return title; + } + public void setTitle(String title) { + this.title = title; + } + public String getStatus() { + return status; + } + public void setStatus(String status) { + this.status = status; + } + public String getDetail() { + return detail; + } + public void setDetail(String detail) { + this.detail = detail; + } + public String getInstance() { + return instance; + } + public void setInstance(String instance) { + this.instance = instance; + } + + + +} diff --git a/src/main/java/io/sprucehill/zalando/api/nativecart/service/AccessTokenService.java b/src/main/java/io/sprucehill/zalando/api/nativecart/service/AccessTokenService.java index 8c1801c..80cc2de 100644 --- a/src/main/java/io/sprucehill/zalando/api/nativecart/service/AccessTokenService.java +++ b/src/main/java/io/sprucehill/zalando/api/nativecart/service/AccessTokenService.java @@ -1,6 +1,8 @@ package io.sprucehill.zalando.api.nativecart.service; import org.apache.http.client.methods.HttpGet; +import org.apache.http.client.methods.HttpPost; + import com.fasterxml.jackson.core.type.TypeReference; import io.sprucehill.zalando.api.nativecart.model.TokenInfo; @@ -14,14 +16,22 @@ public class AccessTokenService extends AbstractService implements IAccessTokenService { @Override - public String read() throws Exception { - HttpGet request = getRequest("https://token.services.auth.zalando.com/oauth2/access_token?realm=/external-services"); - return execute(request, new TypeReference() {}); + public TokenInfo read() throws Exception { + HttpPost request = postRequest("/access_token?realm=%2Fcustomers&grant_type=client_credentials&client_id="+clientId+"&client_secret="+clientCredential); + request.setHeader("Content-Type","application/x-www-form-urlencoded"); + return execute(request, new TypeReference() {}); + } + + @Override + public TokenInfo readFromAuthorizationCode(String authCode,String redirectUrl) throws Exception { + HttpPost request = postRequest("/access_token?realm=%2Fcustomers&grant_type=authorization_code&client_id="+clientId+"&client_secret="+clientCredential+"&code="+authCode+"&redirect_uri="+redirectUrl); + request.setHeader("Content-Type","application/x-www-form-urlencoded"); + return execute(request, new TypeReference() {}); } @Override public TokenInfo read(String accessToken) throws Exception { - HttpGet request = new HttpGet("https://atlas-openam-staging.dc.zalan.do/openam/oauth2/tokeninfo?access_token="+accessToken); + HttpGet request = getRequest("/tokeninfo?access_token="+accessToken); return execute(request, new TypeReference() {}); } } diff --git a/src/main/java/io/sprucehill/zalando/api/nativecart/service/AddressService.java b/src/main/java/io/sprucehill/zalando/api/nativecart/service/AddressService.java index 8b105ba..95898c1 100644 --- a/src/main/java/io/sprucehill/zalando/api/nativecart/service/AddressService.java +++ b/src/main/java/io/sprucehill/zalando/api/nativecart/service/AddressService.java @@ -5,9 +5,10 @@ import org.apache.http.client.methods.HttpGet; import org.apache.http.client.methods.HttpPost; import org.apache.http.client.methods.HttpPut; -import org.apache.http.entity.StringEntity; +import org.apache.http.entity.ByteArrayEntity; import com.fasterxml.jackson.core.type.TypeReference; import io.sprucehill.zalando.api.nativecart.model.Address; +import io.sprucehill.zalando.api.nativecart.model.AddressCheckRequest; import io.sprucehill.zalando.api.nativecart.model.AddressCheckResponse; import io.sprucehill.zalando.api.service.AbstractService; @@ -39,7 +40,7 @@ public Address update(String accessToken,String customerNumber, String addressId try { request.setHeader("Authorization","Bearer "+accessToken); request.addHeader("Content-Type","application/x.zalando.customer.address.update+json"); - request.setEntity(new StringEntity(objectMapper.writeValueAsString(updateAddressRequest))); + request.setEntity(new ByteArrayEntity(objectMapper.writeValueAsBytes(updateAddressRequest))); }catch(Throwable t) { logger.warn(t.getMessage()); throw new RuntimeException(t); @@ -49,19 +50,20 @@ public Address update(String accessToken,String customerNumber, String addressId @Override public Address create(String accessToken,String customerNumber, Address createAddressRequest) throws Exception { - HttpGet request = getRequest("/customers/" + customerNumber+"/addresses"); + HttpPost request = postRequest("/customers/" + customerNumber+"/addresses"); request.setHeader("Authorization","Bearer "+accessToken); request.addHeader("Content-Type","application/x.zalando.customer.address.create+json"); + request.setEntity(new ByteArrayEntity(objectMapper.writeValueAsBytes(createAddressRequest))); return execute(request, new TypeReference
() {}); } @Override - public AddressCheckResponse checkAddress(String accessToken,Address checkAddressRequest) throws Exception { - HttpPost request = postRequest("/addresses"); + public AddressCheckResponse checkAddress(String accessToken,AddressCheckRequest checkAddressRequest) throws Exception { + HttpPost request = postRequest("/address-checks"); try { request.setHeader("Authorization","Bearer "+accessToken); request.addHeader("Content-Type","application/x.zalando.address-check.create+json"); - request.setEntity(new StringEntity(objectMapper.writeValueAsString(checkAddressRequest))); + request.setEntity(new ByteArrayEntity(objectMapper.writeValueAsBytes(checkAddressRequest))); }catch(Throwable t) { logger.warn(t.getMessage()); throw new RuntimeException(t); diff --git a/src/main/java/io/sprucehill/zalando/api/nativecart/service/CartService.java b/src/main/java/io/sprucehill/zalando/api/nativecart/service/CartService.java index 0d852a3..8dfda32 100644 --- a/src/main/java/io/sprucehill/zalando/api/nativecart/service/CartService.java +++ b/src/main/java/io/sprucehill/zalando/api/nativecart/service/CartService.java @@ -21,6 +21,7 @@ public Cart create(String accessToken, Cart createCartRequest) throws Exception HttpPost request = postRequest("/carts"); try { + request.addHeader(HttpHeaders.AUTHORIZATION,"Bearer "+accessToken); request.addHeader("Content-Type","application/x.zalando.cart.create+json"); request.setEntity(new StringEntity(objectMapper.writeValueAsString(createCartRequest))); @@ -41,16 +42,17 @@ public Cart read(String access_token, String cart_id) throws Exception { @Override public Cart update(String access_token, String cart_id,Cart updateCartRequest) throws Exception { - HttpPut request = putRequest("/carts/"+cart_id); + HttpPut request = putRequest("/carts/"+cart_id+"/items"); try { request.addHeader(HttpHeaders.AUTHORIZATION,"Bearer "+access_token); - request.addHeader("Content-Type","application/x.zalando.cart.update+json"); - request.setEntity(new StringEntity(objectMapper.writeValueAsString(updateCartRequest))); + request.addHeader("Content-Type","application/x.zalando.cart.items.update+json"); + request.setEntity(new StringEntity(objectMapper.writeValueAsString(updateCartRequest.getItems()))); + return execute(request, new TypeReference() {}); + }catch(Throwable t) { logger.warn(t.getMessage()); throw new RuntimeException(t); } - return execute(request, new TypeReference() {}); } } diff --git a/src/main/java/io/sprucehill/zalando/api/nativecart/service/CustomerService.java b/src/main/java/io/sprucehill/zalando/api/nativecart/service/CustomerService.java index 4e16639..56d8b49 100644 --- a/src/main/java/io/sprucehill/zalando/api/nativecart/service/CustomerService.java +++ b/src/main/java/io/sprucehill/zalando/api/nativecart/service/CustomerService.java @@ -13,8 +13,9 @@ public class CustomerService extends AbstractService implements ICustomerService { @Override - public Customer read(String customerNumber) throws Exception { + public Customer read(String accessToken ,String customerNumber) throws Exception { HttpGet request = getRequest("/customers/" + customerNumber); + request.addHeader("Authorization","Bearer "+accessToken); return execute(request, new TypeReference() {}); } } diff --git a/src/main/java/io/sprucehill/zalando/api/nativecart/service/IAccessTokenService.java b/src/main/java/io/sprucehill/zalando/api/nativecart/service/IAccessTokenService.java index e1f322c..f052978 100644 --- a/src/main/java/io/sprucehill/zalando/api/nativecart/service/IAccessTokenService.java +++ b/src/main/java/io/sprucehill/zalando/api/nativecart/service/IAccessTokenService.java @@ -11,15 +11,24 @@ public interface IAccessTokenService { /** * - * @return access token + * @return Access token */ - String read() throws Exception; + TokenInfo read() throws Exception; /** * * @param accessToken - * @return + * @return Token details for the given accessToken * @throws Exception */ TokenInfo read(String accessToken) throws Exception; + + /** + * + * @param authCode authorization code + * @param redirectUrl The redirect url to receive callnack + * @return Token details for the given authorization code + * @throws Exception + */ + TokenInfo readFromAuthorizationCode(String authCode, String redirectUrl) throws Exception; } diff --git a/src/main/java/io/sprucehill/zalando/api/nativecart/service/IAddressService.java b/src/main/java/io/sprucehill/zalando/api/nativecart/service/IAddressService.java index 7fc2648..6b5a84b 100644 --- a/src/main/java/io/sprucehill/zalando/api/nativecart/service/IAddressService.java +++ b/src/main/java/io/sprucehill/zalando/api/nativecart/service/IAddressService.java @@ -2,6 +2,7 @@ import java.util.List; import io.sprucehill.zalando.api.nativecart.model.Address; +import io.sprucehill.zalando.api.nativecart.model.AddressCheckRequest; import io.sprucehill.zalando.api.nativecart.model.AddressCheckResponse; /** @@ -15,7 +16,7 @@ public interface IAddressService { * @param checkAddressRequest The address object to be checked * @return The address object with normalized address */ - AddressCheckResponse checkAddress(String accessToken,Address checkAddressRequest) throws Exception; + AddressCheckResponse checkAddress(String accessToken,AddressCheckRequest checkAddressRequest) throws Exception; /** * diff --git a/src/main/java/io/sprucehill/zalando/api/nativecart/service/ICustomerService.java b/src/main/java/io/sprucehill/zalando/api/nativecart/service/ICustomerService.java index 25e1e44..d51576d 100644 --- a/src/main/java/io/sprucehill/zalando/api/nativecart/service/ICustomerService.java +++ b/src/main/java/io/sprucehill/zalando/api/nativecart/service/ICustomerService.java @@ -14,5 +14,5 @@ public interface ICustomerService { * @param customerNumber The customer unique id * @return Details of the customer with specified customer_number */ - Customer read(String customerNumber) throws Exception; + Customer read(String accessToken,String customerNumber) throws Exception; } diff --git a/src/main/java/io/sprucehill/zalando/api/service/AbstractService.java b/src/main/java/io/sprucehill/zalando/api/service/AbstractService.java index 4772df9..26864d4 100644 --- a/src/main/java/io/sprucehill/zalando/api/service/AbstractService.java +++ b/src/main/java/io/sprucehill/zalando/api/service/AbstractService.java @@ -4,6 +4,8 @@ import com.fasterxml.jackson.databind.ObjectMapper; import io.sprucehill.zalando.api.exception.NotFoundException; import io.sprucehill.zalando.api.model.Domain; +import io.sprucehill.zalando.api.nativecart.model.Problem; + import org.apache.http.HttpHeaders; import org.apache.http.HttpResponse; import org.apache.http.client.HttpClient; @@ -23,268 +25,307 @@ */ public abstract class AbstractService { - String apiBase = "https://api.zalando.com"; - - String scheme; - - String host; - - Integer port; - - String pathPrefix; - - protected Domain defaultDomain; - - protected Logger logger = LoggerFactory.getLogger(getClass()); - - protected HttpClient httpClient; - - protected ObjectMapper objectMapper; - - /** - * Set a different API base - * - * @param apiBase The API base to use; defaults to 'https://api.zalando.com' - */ - public void setApiBase(String apiBase) { - this.apiBase = apiBase; - } - - /** - * Set the default domain to use; this is a mandatory setter to be called - * - * @param defaultDomain The default shop domain to use - */ - public void setDefaultDomain(Domain defaultDomain) { - this.defaultDomain = defaultDomain; - } - - /** - * Set a custom HttpClient to use; the bean will create a default HttpClient on its postConstruct method if no HttpClient has been set previously. - * You might want to set your custom HttpClient as the default implementation does not use any pooling or threading implementation. - * - * @param httpClient The HttpClient to use. - */ - public void setHttpClient(HttpClient httpClient) { - this.httpClient = httpClient; - } - - /** - * Set a custom ObjectMapper to use; the bean will create a default ObjectMapper on its postConstruct method if no ObjectMapper has been set previously. - * - * @param objectMapper The ObjectMapper to use. - */ - public void setObjectMapper(ObjectMapper objectMapper) { - this.objectMapper = objectMapper; - } - - /** - * Call this method on postConstruct for any subclasses as it takes care to initialize the bean - */ - @PostConstruct - public void postConstruct() { - if (null == httpClient) { - httpClient = HttpClientBuilder.create().build(); - } - if (null == objectMapper) { - objectMapper = new ObjectMapper(); - } - if (null == defaultDomain) { - throw new RuntimeException("'defaultDomain' must be set!"); - } - if (null == apiBase) { - throw new RuntimeException("'apiBase' must be set!"); - } - try { - URI uri = new URI(apiBase); - scheme = uri.getScheme(); - host = uri.getHost(); - port = uri.getPort(); - pathPrefix = uri.getPath(); - if (("https".equalsIgnoreCase(scheme) && 443 == port) || ("http".equalsIgnoreCase(scheme) && 80 == port)) { - port = null; - } - if ("/".equalsIgnoreCase(pathPrefix)) { - pathPrefix = null; - } - else if (pathPrefix.endsWith("/")) { - pathPrefix = pathPrefix.substring(0,pathPrefix.length()-1); - } - } - catch (URISyntaxException e) { - throw new RuntimeException("'apiBase' is invalid"); - } - } - - /** - * Create and initialize a GET request for the specified path - * - * @param path The path of the GET request - * @return A HttpGet object for the specified path - */ - protected HttpGet getRequest(String path) { - return enrich(new HttpGet(normalizePath(path))); - } - - /** - * Create an initialize a GET request for the specified URIBuilder - * - * @param uriBuilder The URIBuilder to work upon - * @return A HttGet object for the specified URIBuilder's URI - * @throws URISyntaxException Throw if URI cannot be built from the supplied URIBuilder - */ - HttpGet getRequest(URIBuilder uriBuilder) throws URISyntaxException { - return enrich(new HttpGet(normalize(uriBuilder))); - } - - /** - * Create and initialize a POST request for the specified path - * - * @param path The path of the POST request - * @return A HttpGet object for the specified path - */ - protected HttpPost postRequest(String path) { - return enrich(new HttpPost(normalizePath(path))); - } - - /** - * Create and initialize a PUT request for the specified path - * - * @param path The path of the PUT request - * @return A HttpGet object for the specified path - */ - protected HttpPut putRequest(String path) { - return enrich(new HttpPut(normalizePath(path))); - } - - /** - * Create and initialize a DELETE request for the specified path - * - * @param path The path of the DELETE request - * @return A HttpGet object for the specified path - */ - HttpDelete deleteRequest(String path) { - return enrich(new HttpDelete(normalizePath(path))); - } - - /** - * Helper method to normalize a supplied path; - * the current implementation only append a '/' if none is present and prefix with API Base - * - * @param path The path to normalize - * @return The normalized path - */ - protected String normalizePath(String path) { - if (!path.startsWith("/")) { - path = "/" + path; - } - return apiBase + path; - } - - /** - * Helper method to normalize a supplied path; - * the current implementation will set scheme, host, port and prefix with pathPrefix if present - * - * @param uriBuilder The URIBuilder to work upon - * @return A normalized path with defaults set if necessary - * @throws URISyntaxException Throw if the URL cannot be built - */ - protected String normalize(URIBuilder uriBuilder) throws URISyntaxException { - if (null == uriBuilder.getHost() || null == uriBuilder.getScheme()) { - uriBuilder.setHost(host); - uriBuilder.setScheme(scheme); - if (null != port) { - uriBuilder.setPort(port); - } - if (null != pathPrefix) { - uriBuilder.setPath(pathPrefix + uriBuilder.getPath()); - } - } - return uriBuilder.build().toString(); - } - - /** - * Enrich a HttpRequest with some default stuff; - * the current implementation does nothing here - * - * @param request The request to enrich - * @param Generic method to handle different types of HttpRequests - * @return The supplied HttpRequest object - */ - protected T enrich(T request) { - return request; - } - - /** - * Execute a HttpRequest and handle common response states. - * - * @param request The HttpRequest to execute - * @param typeReference The type of the expected response - * @param Generic method to request different response data - * @return The response data for the request - * @throws ZalandoException This exception is thrown when a status other then 200 is encountered - */ - protected T execute(HttpRequestBase request, TypeReference typeReference) throws NotFoundException { - try { - if (null == request.getHeaders(HttpHeaders.ACCEPT_LANGUAGE)) { - request.addHeader(HttpHeaders.ACCEPT_LANGUAGE,defaultDomain.getLocale()); - } - HttpResponse httpResponse = httpClient.execute(request); - if (200 == httpResponse.getStatusLine().getStatusCode()) { - return objectMapper.readValue(httpResponse.getEntity().getContent(),typeReference); - } - if (404 == httpResponse.getStatusLine().getStatusCode()) { - throw new NotFoundException(httpResponse.getStatusLine().getReasonPhrase()); - } - else { - throw new RuntimeException("StatusCode: "+httpResponse.getStatusLine().getStatusCode() + ", Reason: " + httpResponse.getStatusLine().getReasonPhrase()); - } - } - catch (IOException e) { - logger.error(e.getMessage(), e); - throw new RuntimeException(e); - } - finally { - if (null != request && !request.isAborted()) { - request.abort(); - } - } - } - - protected static abstract class Init> { - - protected S service; - - protected Init(S service) { - this.service = service; - } - - public B withHttpClient(HttpClient httpClient) { - service.setHttpClient(httpClient); - return self(); - } - - public B withObjectMapper(ObjectMapper objectMapper) { - service.setObjectMapper(objectMapper); - return self(); - } - - public B withApiBase(String apiBase) { - service.setApiBase(apiBase); - return self(); - } - - public B withDefaultDomain(Domain defaultDomain) { - service.setDefaultDomain(defaultDomain); - return self(); - } - - protected void onBuild() { - service.postConstruct(); - } - - protected abstract B self(); - - public abstract I build(); - } + String apiBase = "https://api.zalando.com"; + + String scheme; + + String host; + + Integer port; + + String pathPrefix; + + protected Domain defaultDomain; + + protected Logger logger = LoggerFactory.getLogger(getClass()); + + protected HttpClient httpClient; + + protected ObjectMapper objectMapper; + + protected String clientId; + + protected String clientCredential; + + /** + * Set a client Id + * + * @param clientId The clientId of the app + */ + public void setClientId(String clientId) { + this.clientId = clientId; + } + + /** + * Set a client clientCredentials + * + * @param clientCredentials The client secret of the app + */ + public void setClientCredential(String clientCredential) { + this.clientCredential = clientCredential; + } + + /** + * Set a different API base + * + * @param apiBase The API base to use; defaults to 'https://api.zalando.com' + */ + public void setApiBase(String apiBase) { + this.apiBase = apiBase; + } + + /** + * Set the default domain to use; this is a mandatory setter to be called + * + * @param defaultDomain The default shop domain to use + */ + public void setDefaultDomain(Domain defaultDomain) { + this.defaultDomain = defaultDomain; + } + + /** + * Set a custom HttpClient to use; the bean will create a default HttpClient on its postConstruct method if no HttpClient has been set previously. + * You might want to set your custom HttpClient as the default implementation does not use any pooling or threading implementation. + * + * @param httpClient The HttpClient to use. + */ + public void setHttpClient(HttpClient httpClient) { + this.httpClient = httpClient; + } + + /** + * Set a custom ObjectMapper to use; the bean will create a default ObjectMapper on its postConstruct method if no ObjectMapper has been set previously. + * + * @param objectMapper The ObjectMapper to use. + */ + public void setObjectMapper(ObjectMapper objectMapper) { + this.objectMapper = objectMapper; + } + + /** + * Call this method on postConstruct for any subclasses as it takes care to initialize the bean + */ + @PostConstruct + public void postConstruct() { + if (null == httpClient) { + httpClient = HttpClientBuilder.create().build(); + } + if (null == objectMapper) { + objectMapper = new ObjectMapper(); + } + if (null == defaultDomain) { + throw new RuntimeException("'defaultDomain' must be set!"); + } + if (null == apiBase) { + throw new RuntimeException("'apiBase' must be set!"); + } + try { + URI uri = new URI(apiBase); + scheme = uri.getScheme(); + host = uri.getHost(); + port = uri.getPort(); + pathPrefix = uri.getPath(); + if (("https".equalsIgnoreCase(scheme) && 443 == port) || ("http".equalsIgnoreCase(scheme) && 80 == port)) { + port = null; + } + if ("/".equalsIgnoreCase(pathPrefix)) { + pathPrefix = null; + } + else if (pathPrefix.endsWith("/")) { + pathPrefix = pathPrefix.substring(0,pathPrefix.length()-1); + } + } + catch (URISyntaxException e) { + throw new RuntimeException("'apiBase' is invalid"); + } + } + + /** + * Create and initialize a GET request for the specified path + * + * @param path The path of the GET request + * @return A HttpGet object for the specified path + */ + protected HttpGet getRequest(String path) { + return enrich(new HttpGet(normalizePath(path))); + } + + /** + * Create an initialize a GET request for the specified URIBuilder + * + * @param uriBuilder The URIBuilder to work upon + * @return A HttGet object for the specified URIBuilder's URI + * @throws URISyntaxException Throw if URI cannot be built from the supplied URIBuilder + */ + HttpGet getRequest(URIBuilder uriBuilder) throws URISyntaxException { + return enrich(new HttpGet(normalize(uriBuilder))); + } + + /** + * Create and initialize a POST request for the specified path + * + * @param path The path of the POST request + * @return A HttpGet object for the specified path + */ + protected HttpPost postRequest(String path) { + return enrich(new HttpPost(normalizePath(path))); + } + + /** + * Create and initialize a PUT request for the specified path + * + * @param path The path of the PUT request + * @return A HttpGet object for the specified path + */ + protected HttpPut putRequest(String path) { + return enrich(new HttpPut(normalizePath(path))); + } + + /** + * Create and initialize a DELETE request for the specified path + * + * @param path The path of the DELETE request + * @return A HttpGet object for the specified path + */ + HttpDelete deleteRequest(String path) { + return enrich(new HttpDelete(normalizePath(path))); + } + + /** + * Helper method to normalize a supplied path; + * the current implementation only append a '/' if none is present and prefix with API Base + * + * @param path The path to normalize + * @return The normalized path + */ + protected String normalizePath(String path) { + if (!path.startsWith("/")) { + path = "/" + path; + } + return apiBase + path; + } + + /** + * Helper method to normalize a supplied path; + * the current implementation will set scheme, host, port and prefix with pathPrefix if present + * + * @param uriBuilder The URIBuilder to work upon + * @return A normalized path with defaults set if necessary + * @throws URISyntaxException Throw if the URL cannot be built + */ + protected String normalize(URIBuilder uriBuilder) throws URISyntaxException { + if (null == uriBuilder.getHost() || null == uriBuilder.getScheme()) { + uriBuilder.setHost(host); + uriBuilder.setScheme(scheme); + if (null != port) { + uriBuilder.setPort(port); + } + if (null != pathPrefix) { + uriBuilder.setPath(pathPrefix + uriBuilder.getPath()); + } + } + return uriBuilder.build().toString(); + } + + /** + * Enrich a HttpRequest with some default stuff; + * the current implementation does nothing here + * + * @param request The request to enrich + * @param Generic method to handle different types of HttpRequests + * @return The supplied HttpRequest object + */ + protected T enrich(T request) { + return request; + } + + /** + * Execute a HttpRequest and handle common response states. + * + * @param request The HttpRequest to execute + * @param typeReference The type of the expected response + * @param Generic method to request different response data + * @return The response data for the request + * @throws ZalandoException This exception is thrown when a status other then 200 is encountered + */ + protected T execute(HttpRequestBase request, TypeReference typeReference) throws NotFoundException { + try { + if (null == request.getHeaders(HttpHeaders.ACCEPT_LANGUAGE)) { + request.addHeader(HttpHeaders.ACCEPT_LANGUAGE,defaultDomain.getLocale()); + } + HttpResponse httpResponse = httpClient.execute(request); + if (200 == httpResponse.getStatusLine().getStatusCode()) { + return objectMapper.readValue(httpResponse.getEntity().getContent(),typeReference); + } + + if (404 == httpResponse.getStatusLine().getStatusCode()) { + throw new NotFoundException(httpResponse.getStatusLine().getReasonPhrase()); + } + else { + try{ + Problem problem = objectMapper.readValue(httpResponse.getEntity().getContent(),Problem.class); + throw new RuntimeException("StatusCode: "+problem.getStatus() + ", Reason: " + problem.getDetail()); + }catch(Exception e){ + throw new RuntimeException("StatusCode: "+httpResponse.getStatusLine().getStatusCode() + ", Reason: " + httpResponse.getStatusLine().getReasonPhrase()); + } + + } + } + catch (IOException e) { + logger.error(e.getMessage(), e); + throw new RuntimeException(e); + } + finally { + if (null != request && !request.isAborted()) { + request.abort(); + } + } + } + + protected static abstract class Init> { + + protected S service; + + protected Init(S service) { + this.service = service; + } + + public B withHttpClient(HttpClient httpClient) { + service.setHttpClient(httpClient); + return self(); + } + + public B withObjectMapper(ObjectMapper objectMapper) { + service.setObjectMapper(objectMapper); + return self(); + } + + public B withApiBase(String apiBase) { + service.setApiBase(apiBase); + return self(); + } + + public B withDefaultDomain(Domain defaultDomain) { + service.setDefaultDomain(defaultDomain); + return self(); + } + + public B withClientId(String clientId) { + service.setClientId(clientId);; + return self(); + } + + public B withClientCredential(String clientCredential) { + service.setClientCredential(clientCredential);; + return self(); + } + + protected void onBuild() { + service.postConstruct(); + } + + protected abstract B self(); + + public abstract I build(); + } } From 29aeff2c34d9e6db53232bd5db40e9a6bbad99b8 Mon Sep 17 00:00:00 2001 From: Diptee Warudkar Date: Thu, 17 Mar 2016 11:41:09 +0100 Subject: [PATCH 17/24] Fixing javadoc build errors --- .../zalando/api/nativecart/service/IAccessTokenService.java | 6 ++++-- .../zalando/api/nativecart/service/IAddressService.java | 5 +++++ .../zalando/api/nativecart/service/ICartService.java | 5 ++++- .../zalando/api/nativecart/service/ICheckoutService.java | 4 +++- .../zalando/api/nativecart/service/ICustomerService.java | 1 + .../zalando/api/nativecart/service/IOrderService.java | 1 + 6 files changed, 18 insertions(+), 4 deletions(-) diff --git a/src/main/java/io/sprucehill/zalando/api/nativecart/service/IAccessTokenService.java b/src/main/java/io/sprucehill/zalando/api/nativecart/service/IAccessTokenService.java index f052978..6469b70 100644 --- a/src/main/java/io/sprucehill/zalando/api/nativecart/service/IAccessTokenService.java +++ b/src/main/java/io/sprucehill/zalando/api/nativecart/service/IAccessTokenService.java @@ -1,5 +1,6 @@ package io.sprucehill.zalando.api.nativecart.service; +import io.sprucehill.zalando.api.exception.NotFoundException; import io.sprucehill.zalando.api.nativecart.model.TokenInfo; /** @@ -12,6 +13,7 @@ public interface IAccessTokenService { /** * * @return Access token + * @throws Exception Any Exception that is thrown while doing the operation */ TokenInfo read() throws Exception; @@ -19,7 +21,7 @@ public interface IAccessTokenService { * * @param accessToken * @return Token details for the given accessToken - * @throws Exception + * @throws Exception Any Exception that is thrown while doing the operation */ TokenInfo read(String accessToken) throws Exception; @@ -28,7 +30,7 @@ public interface IAccessTokenService { * @param authCode authorization code * @param redirectUrl The redirect url to receive callnack * @return Token details for the given authorization code - * @throws Exception + * @throws Exception Any Exception that is thrown while doing the operation */ TokenInfo readFromAuthorizationCode(String authCode, String redirectUrl) throws Exception; } diff --git a/src/main/java/io/sprucehill/zalando/api/nativecart/service/IAddressService.java b/src/main/java/io/sprucehill/zalando/api/nativecart/service/IAddressService.java index 6b5a84b..8a3063c 100644 --- a/src/main/java/io/sprucehill/zalando/api/nativecart/service/IAddressService.java +++ b/src/main/java/io/sprucehill/zalando/api/nativecart/service/IAddressService.java @@ -15,6 +15,7 @@ public interface IAddressService { * * @param checkAddressRequest The address object to be checked * @return The address object with normalized address + * @throws Exception Any Exception that is thrown while doing the operation */ AddressCheckResponse checkAddress(String accessToken,AddressCheckRequest checkAddressRequest) throws Exception; @@ -22,6 +23,7 @@ public interface IAddressService { * * @param customerNumber The customer unique id * @return The list of user addresses + * @throws Exception Any Exception that is thrown while doing the operation */ List
read(String accessToken,String customerNumber) throws Exception ; @@ -30,6 +32,7 @@ public interface IAddressService { * @param customerNumber The customer unique id * @param addressId The ID of the address to read * @return The address with the requested ID for the specified customer + * @throws Exception Any Exception that is thrown while doing the operation */ Address read(String accessToken,String customerNumber,String addressId) throws Exception; @@ -39,6 +42,7 @@ public interface IAddressService { * @param addressId The ID of the address to update * @param request The address object to update * @return The updated address object + * @throws Exception Any Exception that is thrown while doing the operation */ Address update(String accessToken,String customerNumber,String addressId,Address request) throws Exception; @@ -47,6 +51,7 @@ public interface IAddressService { * @param customerNumber The customer unique id * @param createAddressRequest The address object to create * @return Newly created address object + * @throws Exception Any Exception that is thrown while doing the operation */ Address create(String accessToken,String customerNumber,Address createAddressRequest) throws Exception; } diff --git a/src/main/java/io/sprucehill/zalando/api/nativecart/service/ICartService.java b/src/main/java/io/sprucehill/zalando/api/nativecart/service/ICartService.java index 71cf791..02e83c7 100644 --- a/src/main/java/io/sprucehill/zalando/api/nativecart/service/ICartService.java +++ b/src/main/java/io/sprucehill/zalando/api/nativecart/service/ICartService.java @@ -14,6 +14,7 @@ public interface ICartService { * @param accessToken access token for performing create cart operation * @param createCartRequest The Cart object to be created * @return Newly created cart object + * @throws Exception Any Exception that is thrown while doing the operation */ Cart create(String accessToken,Cart createCartRequest) throws Exception; @@ -22,6 +23,7 @@ public interface ICartService { * @param accessToken access token for performing create cart operation * @param cartId The ID of the cart to read * @return The cart with the requested ID for the specified accessToken + * @throws Exception Any Exception that is thrown while doing the operation */ Cart read(String accessToken,String cartId) throws Exception; @@ -30,7 +32,8 @@ public interface ICartService { * @param accessToken access token for performing update cart operation * @param cartId The ID of the cart to update * @param updateCartRequest Cart object to be updated - * @return + * @return The updated Cart object + * @throws Exception Any Exception that is thrown while doing the operation */ Cart update(String accessToken,String cartId,Cart updateCartRequest) throws Exception; } diff --git a/src/main/java/io/sprucehill/zalando/api/nativecart/service/ICheckoutService.java b/src/main/java/io/sprucehill/zalando/api/nativecart/service/ICheckoutService.java index e93729f..e0f2c04 100644 --- a/src/main/java/io/sprucehill/zalando/api/nativecart/service/ICheckoutService.java +++ b/src/main/java/io/sprucehill/zalando/api/nativecart/service/ICheckoutService.java @@ -14,6 +14,7 @@ public interface ICheckoutService { * @param customerNumber The customer unique id * @param checkoutId The ID of the checkout to read * @return The checkout object with the requested ID for the specified customer + * @throws Exception Any Exception that is thrown while doing the operation */ Checkout read(String customerNumber,String checkoutId) throws Exception; @@ -22,6 +23,7 @@ public interface ICheckoutService { * @param customerNumber The customer unique id * @param CreatecheckoutRequest The checkout object to be created * @return The newly created checkout object + * @throws Exception Any Exception that is thrown while doing the operation */ Checkout create(String customerNumber,Checkout CreatecheckoutRequest) throws Exception; @@ -31,7 +33,7 @@ public interface ICheckoutService { * @param checkoutId The ID of the address to update * @param updateCheckoutRequest The checkout object to be updated * @return The updated checkout object + * @throws Exception Any Exception that is thrown while doing the operation */ Checkout update(String customerNumber,String checkoutId,Checkout updateCheckoutRequest) throws Exception; - } diff --git a/src/main/java/io/sprucehill/zalando/api/nativecart/service/ICustomerService.java b/src/main/java/io/sprucehill/zalando/api/nativecart/service/ICustomerService.java index d51576d..d333039 100644 --- a/src/main/java/io/sprucehill/zalando/api/nativecart/service/ICustomerService.java +++ b/src/main/java/io/sprucehill/zalando/api/nativecart/service/ICustomerService.java @@ -13,6 +13,7 @@ public interface ICustomerService { * * @param customerNumber The customer unique id * @return Details of the customer with specified customer_number + * @throws Exception Any Exception that is thrown while doing the operation */ Customer read(String accessToken,String customerNumber) throws Exception; } diff --git a/src/main/java/io/sprucehill/zalando/api/nativecart/service/IOrderService.java b/src/main/java/io/sprucehill/zalando/api/nativecart/service/IOrderService.java index 07a40b5..fe94d81 100644 --- a/src/main/java/io/sprucehill/zalando/api/nativecart/service/IOrderService.java +++ b/src/main/java/io/sprucehill/zalando/api/nativecart/service/IOrderService.java @@ -14,6 +14,7 @@ public interface IOrderService { * @param customerNumber The unique id of the customer * @param createOrderRequest The order object to be created * @return The newly create order object + * @throws Exception Any Exception that is thrown while doing the operation */ Order create(String customerNumber,Order createOrderRequest) throws Exception; } From 64bbfc26d8e9d5decc2b19583b296abb9c789fbc Mon Sep 17 00:00:00 2001 From: Diptee Warudkar Date: Thu, 17 Mar 2016 11:49:46 +0100 Subject: [PATCH 18/24] Fixing some more javadoc build errors --- .../zalando/api/nativecart/service/IAccessTokenService.java | 2 +- .../zalando/api/nativecart/service/IAddressService.java | 5 +++++ .../zalando/api/nativecart/service/ICustomerService.java | 1 + .../io/sprucehill/zalando/api/service/AbstractService.java | 6 +++--- 4 files changed, 10 insertions(+), 4 deletions(-) diff --git a/src/main/java/io/sprucehill/zalando/api/nativecart/service/IAccessTokenService.java b/src/main/java/io/sprucehill/zalando/api/nativecart/service/IAccessTokenService.java index 6469b70..2c29820 100644 --- a/src/main/java/io/sprucehill/zalando/api/nativecart/service/IAccessTokenService.java +++ b/src/main/java/io/sprucehill/zalando/api/nativecart/service/IAccessTokenService.java @@ -19,7 +19,7 @@ public interface IAccessTokenService { /** * - * @param accessToken + * @param accessToken The access token for authorization * @return Token details for the given accessToken * @throws Exception Any Exception that is thrown while doing the operation */ diff --git a/src/main/java/io/sprucehill/zalando/api/nativecart/service/IAddressService.java b/src/main/java/io/sprucehill/zalando/api/nativecart/service/IAddressService.java index 8a3063c..53765b4 100644 --- a/src/main/java/io/sprucehill/zalando/api/nativecart/service/IAddressService.java +++ b/src/main/java/io/sprucehill/zalando/api/nativecart/service/IAddressService.java @@ -13,6 +13,7 @@ public interface IAddressService { /** * + * @param accessToken The access token for authorization * @param checkAddressRequest The address object to be checked * @return The address object with normalized address * @throws Exception Any Exception that is thrown while doing the operation @@ -21,6 +22,7 @@ public interface IAddressService { /** * + * @param accessToken The access token for authorization * @param customerNumber The customer unique id * @return The list of user addresses * @throws Exception Any Exception that is thrown while doing the operation @@ -29,6 +31,7 @@ public interface IAddressService { /** * + * @param accessToken The access token for authorization * @param customerNumber The customer unique id * @param addressId The ID of the address to read * @return The address with the requested ID for the specified customer @@ -38,6 +41,7 @@ public interface IAddressService { /** * + * @param accessToken The access token for authorization * @param customerNumber The customer unique id * @param addressId The ID of the address to update * @param request The address object to update @@ -48,6 +52,7 @@ public interface IAddressService { /** * + * @param accessToken The access token for authorization * @param customerNumber The customer unique id * @param createAddressRequest The address object to create * @return Newly created address object diff --git a/src/main/java/io/sprucehill/zalando/api/nativecart/service/ICustomerService.java b/src/main/java/io/sprucehill/zalando/api/nativecart/service/ICustomerService.java index d333039..4d2d596 100644 --- a/src/main/java/io/sprucehill/zalando/api/nativecart/service/ICustomerService.java +++ b/src/main/java/io/sprucehill/zalando/api/nativecart/service/ICustomerService.java @@ -11,6 +11,7 @@ public interface ICustomerService { /** * + * @param accessToken The access token for authorization * @param customerNumber The customer unique id * @return Details of the customer with specified customer_number * @throws Exception Any Exception that is thrown while doing the operation diff --git a/src/main/java/io/sprucehill/zalando/api/service/AbstractService.java b/src/main/java/io/sprucehill/zalando/api/service/AbstractService.java index 26864d4..3b6c608 100644 --- a/src/main/java/io/sprucehill/zalando/api/service/AbstractService.java +++ b/src/main/java/io/sprucehill/zalando/api/service/AbstractService.java @@ -57,9 +57,9 @@ public void setClientId(String clientId) { } /** - * Set a client clientCredentials + * Set a client clientCredential * - * @param clientCredentials The client secret of the app + * @param clientCredential The client secret of the app */ public void setClientCredential(String clientCredential) { this.clientCredential = clientCredential; @@ -246,7 +246,7 @@ protected T enrich(T request) { * @param typeReference The type of the expected response * @param Generic method to request different response data * @return The response data for the request - * @throws ZalandoException This exception is thrown when a status other then 200 is encountered + * @throws NotFoundException This exception is thrown when a resource is not found */ protected T execute(HttpRequestBase request, TypeReference typeReference) throws NotFoundException { try { From 818e8985a699dc28559c97ddf095ba2781351fd8 Mon Sep 17 00:00:00 2001 From: Diptee Warudkar Date: Thu, 17 Mar 2016 11:55:10 +0100 Subject: [PATCH 19/24] Changing StringEntity to ByteArrayEntity --- .../zalando/api/nativecart/service/CartService.java | 6 +++--- .../zalando/api/nativecart/service/CheckoutService.java | 6 +++--- .../zalando/api/nativecart/service/OrderService.java | 4 ++-- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/main/java/io/sprucehill/zalando/api/nativecart/service/CartService.java b/src/main/java/io/sprucehill/zalando/api/nativecart/service/CartService.java index 8dfda32..49e336d 100644 --- a/src/main/java/io/sprucehill/zalando/api/nativecart/service/CartService.java +++ b/src/main/java/io/sprucehill/zalando/api/nativecart/service/CartService.java @@ -4,7 +4,7 @@ import org.apache.http.client.methods.HttpGet; import org.apache.http.client.methods.HttpPost; import org.apache.http.client.methods.HttpPut; -import org.apache.http.entity.StringEntity; +import org.apache.http.entity.ByteArrayEntity; import com.fasterxml.jackson.core.type.TypeReference; import io.sprucehill.zalando.api.nativecart.model.Cart; import io.sprucehill.zalando.api.service.AbstractService; @@ -24,7 +24,7 @@ public Cart create(String accessToken, Cart createCartRequest) throws Exception request.addHeader(HttpHeaders.AUTHORIZATION,"Bearer "+accessToken); request.addHeader("Content-Type","application/x.zalando.cart.create+json"); - request.setEntity(new StringEntity(objectMapper.writeValueAsString(createCartRequest))); + request.setEntity(new ByteArrayEntity(objectMapper.writeValueAsBytes(createCartRequest))); }catch(Throwable t) { logger.warn(t.getMessage()); throw new RuntimeException(t); @@ -47,7 +47,7 @@ public Cart update(String access_token, String cart_id,Cart updateCartRequest) t try { request.addHeader(HttpHeaders.AUTHORIZATION,"Bearer "+access_token); request.addHeader("Content-Type","application/x.zalando.cart.items.update+json"); - request.setEntity(new StringEntity(objectMapper.writeValueAsString(updateCartRequest.getItems()))); + request.setEntity(new ByteArrayEntity(objectMapper.writeValueAsBytes(updateCartRequest.getItems()))); return execute(request, new TypeReference() {}); }catch(Throwable t) { diff --git a/src/main/java/io/sprucehill/zalando/api/nativecart/service/CheckoutService.java b/src/main/java/io/sprucehill/zalando/api/nativecart/service/CheckoutService.java index c93c604..6b39f18 100644 --- a/src/main/java/io/sprucehill/zalando/api/nativecart/service/CheckoutService.java +++ b/src/main/java/io/sprucehill/zalando/api/nativecart/service/CheckoutService.java @@ -3,7 +3,7 @@ import org.apache.http.client.methods.HttpGet; import org.apache.http.client.methods.HttpPost; import org.apache.http.client.methods.HttpPut; -import org.apache.http.entity.StringEntity; +import org.apache.http.entity.ByteArrayEntity; import com.fasterxml.jackson.core.type.TypeReference; import io.sprucehill.zalando.api.nativecart.model.Checkout; import io.sprucehill.zalando.api.service.AbstractService; @@ -26,7 +26,7 @@ public Checkout create(String customerNumber, Checkout createcheckoutRequest) th HttpPost request = postRequest("/customer/"+customerNumber+"/checkouts"); try { - request.setEntity(new StringEntity(objectMapper.writeValueAsString(createcheckoutRequest))); + request.setEntity(new ByteArrayEntity(objectMapper.writeValueAsBytes(createcheckoutRequest))); }catch (Throwable t) { logger.warn(t.getMessage()); throw new RuntimeException(t); @@ -39,7 +39,7 @@ public Checkout update(String customerNumber, String checkoutId,Checkout updateC HttpPut request = putRequest("/customer/"+customerNumber+"/checkouts/"+checkoutId); try { - request.setEntity(new StringEntity(objectMapper.writeValueAsString(updateCheckoutRequest))); + request.setEntity(new ByteArrayEntity(objectMapper.writeValueAsBytes(updateCheckoutRequest))); }catch (Throwable t) { logger.warn(t.getMessage()); throw new RuntimeException(t); diff --git a/src/main/java/io/sprucehill/zalando/api/nativecart/service/OrderService.java b/src/main/java/io/sprucehill/zalando/api/nativecart/service/OrderService.java index 0038a6f..94bf560 100644 --- a/src/main/java/io/sprucehill/zalando/api/nativecart/service/OrderService.java +++ b/src/main/java/io/sprucehill/zalando/api/nativecart/service/OrderService.java @@ -1,7 +1,7 @@ package io.sprucehill.zalando.api.nativecart.service; import org.apache.http.client.methods.HttpPost; -import org.apache.http.entity.StringEntity; +import org.apache.http.entity.ByteArrayEntity; import com.fasterxml.jackson.core.type.TypeReference; import io.sprucehill.zalando.api.nativecart.model.Order; import io.sprucehill.zalando.api.service.AbstractService; @@ -17,7 +17,7 @@ public class OrderService extends AbstractService implements IOrderService { public Order create(String customerNumber, Order createOrderRequest) throws Exception { HttpPost request = postRequest("/customer/" + customerNumber +"/orders"); try { - request.setEntity(new StringEntity(objectMapper.writeValueAsString(createOrderRequest))); + request.setEntity(new ByteArrayEntity(objectMapper.writeValueAsBytes(createOrderRequest))); }catch(Throwable t) { logger.warn(t.getMessage()); throw new RuntimeException(t); From f4d33daf16ba22b1d6d77ce46ec04dd51066c1e2 Mon Sep 17 00:00:00 2001 From: Diptee Warudkar Date: Thu, 17 Mar 2016 16:25:30 +0100 Subject: [PATCH 20/24] Implemented Review comments 1) Changed magic numbers to HttpHeaders 2)Added authorization on checkout and order services --- .../service/AccessTokenService.java | 31 +++++++++++++++++-- .../nativecart/service/AddressService.java | 17 +++++----- .../api/nativecart/service/CartService.java | 7 ++--- .../nativecart/service/CheckoutService.java | 17 +++++++--- .../nativecart/service/CustomerService.java | 3 +- .../nativecart/service/ICheckoutService.java | 9 ++++-- .../api/nativecart/service/IOrderService.java | 3 +- .../api/nativecart/service/OrderService.java | 5 ++- 8 files changed, 66 insertions(+), 26 deletions(-) diff --git a/src/main/java/io/sprucehill/zalando/api/nativecart/service/AccessTokenService.java b/src/main/java/io/sprucehill/zalando/api/nativecart/service/AccessTokenService.java index 80cc2de..c17fe27 100644 --- a/src/main/java/io/sprucehill/zalando/api/nativecart/service/AccessTokenService.java +++ b/src/main/java/io/sprucehill/zalando/api/nativecart/service/AccessTokenService.java @@ -1,7 +1,14 @@ package io.sprucehill.zalando.api.nativecart.service; +import java.util.ArrayList; +import java.util.List; + +import org.apache.http.HttpHeaders; +import org.apache.http.NameValuePair; +import org.apache.http.client.entity.UrlEncodedFormEntity; import org.apache.http.client.methods.HttpGet; import org.apache.http.client.methods.HttpPost; +import org.apache.http.message.BasicNameValuePair; import com.fasterxml.jackson.core.type.TypeReference; @@ -17,15 +24,33 @@ public class AccessTokenService extends AbstractService implements IAccessTokenS @Override public TokenInfo read() throws Exception { - HttpPost request = postRequest("/access_token?realm=%2Fcustomers&grant_type=client_credentials&client_id="+clientId+"&client_secret="+clientCredential); - request.setHeader("Content-Type","application/x-www-form-urlencoded"); + HttpPost request = postRequest("/access_token"); + request.setHeader(HttpHeaders.CONTENT_TYPE,"application/x-www-form-urlencoded"); + + List params = new ArrayList(); + params.add(new BasicNameValuePair("realm","%2Fcustomers")); + params.add(new BasicNameValuePair("grant_type","client_credentials")); + params.add(new BasicNameValuePair("client_id",clientId)); + params.add(new BasicNameValuePair("client_secret",clientCredential)); + + request.setEntity(new UrlEncodedFormEntity(params)); + return execute(request, new TypeReference() {}); } @Override public TokenInfo readFromAuthorizationCode(String authCode,String redirectUrl) throws Exception { HttpPost request = postRequest("/access_token?realm=%2Fcustomers&grant_type=authorization_code&client_id="+clientId+"&client_secret="+clientCredential+"&code="+authCode+"&redirect_uri="+redirectUrl); - request.setHeader("Content-Type","application/x-www-form-urlencoded"); + request.setHeader(HttpHeaders.CONTENT_TYPE,"application/x-www-form-urlencoded"); + + List params = new ArrayList(); + params.add(new BasicNameValuePair("realm","%2Fcustomers")); + params.add(new BasicNameValuePair("grant_type","authorization_code")); + params.add(new BasicNameValuePair("client_id",clientId)); + params.add(new BasicNameValuePair("client_secret",clientCredential)); + + request.setEntity(new UrlEncodedFormEntity(params)); + return execute(request, new TypeReference() {}); } diff --git a/src/main/java/io/sprucehill/zalando/api/nativecart/service/AddressService.java b/src/main/java/io/sprucehill/zalando/api/nativecart/service/AddressService.java index 95898c1..bec483d 100644 --- a/src/main/java/io/sprucehill/zalando/api/nativecart/service/AddressService.java +++ b/src/main/java/io/sprucehill/zalando/api/nativecart/service/AddressService.java @@ -2,6 +2,7 @@ import java.util.List; +import org.apache.http.HttpHeaders; import org.apache.http.client.methods.HttpGet; import org.apache.http.client.methods.HttpPost; import org.apache.http.client.methods.HttpPut; @@ -22,14 +23,14 @@ public class AddressService extends AbstractService implements IAddressService { @Override public List
read(String accessToken,String customerNumber) throws Exception { HttpGet request = getRequest("/customers/" + customerNumber +"/addresses"); - request.setHeader("Authorization","Bearer "+accessToken); + request.setHeader(HttpHeaders.AUTHORIZATION,"Bearer "+accessToken); return execute(request, new TypeReference>() {}); } @Override public Address read(String accessToken,String customerNumber, String addressId) throws Exception { HttpGet request = getRequest("/customers/" + customerNumber +"/addresses/"+addressId); - request.setHeader("Authorization","Bearer "+accessToken); + request.setHeader(HttpHeaders.AUTHORIZATION,"Bearer "+accessToken); return execute(request, new TypeReference
() {}); } @@ -38,8 +39,8 @@ public Address update(String accessToken,String customerNumber, String addressId HttpPut request = putRequest("/customers/" + customerNumber +"/addresses/"+addressId); try { - request.setHeader("Authorization","Bearer "+accessToken); - request.addHeader("Content-Type","application/x.zalando.customer.address.update+json"); + request.setHeader(HttpHeaders.AUTHORIZATION,"Bearer "+accessToken); + request.addHeader(HttpHeaders.CONTENT_TYPE,"application/x.zalando.customer.address.update+json"); request.setEntity(new ByteArrayEntity(objectMapper.writeValueAsBytes(updateAddressRequest))); }catch(Throwable t) { logger.warn(t.getMessage()); @@ -51,8 +52,8 @@ public Address update(String accessToken,String customerNumber, String addressId @Override public Address create(String accessToken,String customerNumber, Address createAddressRequest) throws Exception { HttpPost request = postRequest("/customers/" + customerNumber+"/addresses"); - request.setHeader("Authorization","Bearer "+accessToken); - request.addHeader("Content-Type","application/x.zalando.customer.address.create+json"); + request.setHeader(HttpHeaders.AUTHORIZATION,"Bearer "+accessToken); + request.addHeader(HttpHeaders.CONTENT_TYPE,"application/x.zalando.customer.address.create+json"); request.setEntity(new ByteArrayEntity(objectMapper.writeValueAsBytes(createAddressRequest))); return execute(request, new TypeReference
() {}); } @@ -61,8 +62,8 @@ public Address create(String accessToken,String customerNumber, Address createAd public AddressCheckResponse checkAddress(String accessToken,AddressCheckRequest checkAddressRequest) throws Exception { HttpPost request = postRequest("/address-checks"); try { - request.setHeader("Authorization","Bearer "+accessToken); - request.addHeader("Content-Type","application/x.zalando.address-check.create+json"); + request.setHeader(HttpHeaders.AUTHORIZATION,"Bearer "+accessToken); + request.addHeader(HttpHeaders.CONTENT_TYPE,"application/x.zalando.address-check.create+json"); request.setEntity(new ByteArrayEntity(objectMapper.writeValueAsBytes(checkAddressRequest))); }catch(Throwable t) { logger.warn(t.getMessage()); diff --git a/src/main/java/io/sprucehill/zalando/api/nativecart/service/CartService.java b/src/main/java/io/sprucehill/zalando/api/nativecart/service/CartService.java index 49e336d..d229af1 100644 --- a/src/main/java/io/sprucehill/zalando/api/nativecart/service/CartService.java +++ b/src/main/java/io/sprucehill/zalando/api/nativecart/service/CartService.java @@ -21,9 +21,8 @@ public Cart create(String accessToken, Cart createCartRequest) throws Exception HttpPost request = postRequest("/carts"); try { - request.addHeader(HttpHeaders.AUTHORIZATION,"Bearer "+accessToken); - request.addHeader("Content-Type","application/x.zalando.cart.create+json"); + request.addHeader(HttpHeaders.CONTENT_TYPE,"application/x.zalando.cart.create+json"); request.setEntity(new ByteArrayEntity(objectMapper.writeValueAsBytes(createCartRequest))); }catch(Throwable t) { logger.warn(t.getMessage()); @@ -35,7 +34,7 @@ public Cart create(String accessToken, Cart createCartRequest) throws Exception @Override public Cart read(String access_token, String cart_id) throws Exception { HttpGet request = getRequest("/carts/" + cart_id); - request.addHeader("Content-Type","application/x.zalando.cart+json"); + request.addHeader(HttpHeaders.CONTENT_TYPE,"application/x.zalando.cart+json"); request.addHeader(HttpHeaders.AUTHORIZATION,"Bearer "+access_token); return execute(request, new TypeReference() {}); } @@ -46,7 +45,7 @@ public Cart update(String access_token, String cart_id,Cart updateCartRequest) t try { request.addHeader(HttpHeaders.AUTHORIZATION,"Bearer "+access_token); - request.addHeader("Content-Type","application/x.zalando.cart.items.update+json"); + request.addHeader(HttpHeaders.CONTENT_TYPE,"application/x.zalando.cart.items.update+json"); request.setEntity(new ByteArrayEntity(objectMapper.writeValueAsBytes(updateCartRequest.getItems()))); return execute(request, new TypeReference() {}); diff --git a/src/main/java/io/sprucehill/zalando/api/nativecart/service/CheckoutService.java b/src/main/java/io/sprucehill/zalando/api/nativecart/service/CheckoutService.java index 6b39f18..7643974 100644 --- a/src/main/java/io/sprucehill/zalando/api/nativecart/service/CheckoutService.java +++ b/src/main/java/io/sprucehill/zalando/api/nativecart/service/CheckoutService.java @@ -1,5 +1,6 @@ package io.sprucehill.zalando.api.nativecart.service; +import org.apache.http.HttpHeaders; import org.apache.http.client.methods.HttpGet; import org.apache.http.client.methods.HttpPost; import org.apache.http.client.methods.HttpPut; @@ -16,15 +17,19 @@ public class CheckoutService extends AbstractService implements ICheckoutService { @Override - public Checkout read(String customerNumber, String checkout_id) throws Exception { + public Checkout read(String accessToken,String customerNumber, String checkout_id) throws Exception { HttpGet request = getRequest("/customer/"+customerNumber+"/checkouts/"+checkout_id); + request.addHeader(HttpHeaders.AUTHORIZATION,"Bearer "+accessToken); + request.addHeader(HttpHeaders.CONTENT_TYPE,"application/x.zalando.customer.checkout.create+json"); return execute(request, new TypeReference() {}); } @Override - public Checkout create(String customerNumber, Checkout createcheckoutRequest) throws Exception { + public Checkout create(String accessToken,String customerNumber, Checkout createcheckoutRequest) throws Exception { HttpPost request = postRequest("/customer/"+customerNumber+"/checkouts"); - + request.addHeader(HttpHeaders.AUTHORIZATION,"Bearer "+accessToken); + request.addHeader(HttpHeaders.CONTENT_TYPE,"application/x.zalando.customer.checkout+json"); + try { request.setEntity(new ByteArrayEntity(objectMapper.writeValueAsBytes(createcheckoutRequest))); }catch (Throwable t) { @@ -35,9 +40,11 @@ public Checkout create(String customerNumber, Checkout createcheckoutRequest) th } @Override - public Checkout update(String customerNumber, String checkoutId,Checkout updateCheckoutRequest) throws Exception { + public Checkout update(String accessToken,String customerNumber, String checkoutId,Checkout updateCheckoutRequest) throws Exception { HttpPut request = putRequest("/customer/"+customerNumber+"/checkouts/"+checkoutId); - + request.addHeader(HttpHeaders.AUTHORIZATION,"Bearer "+accessToken); + request.addHeader(HttpHeaders.CONTENT_TYPE,"application/x.zalando.customer.checkout.update+json"); + try { request.setEntity(new ByteArrayEntity(objectMapper.writeValueAsBytes(updateCheckoutRequest))); }catch (Throwable t) { diff --git a/src/main/java/io/sprucehill/zalando/api/nativecart/service/CustomerService.java b/src/main/java/io/sprucehill/zalando/api/nativecart/service/CustomerService.java index 56d8b49..593442f 100644 --- a/src/main/java/io/sprucehill/zalando/api/nativecart/service/CustomerService.java +++ b/src/main/java/io/sprucehill/zalando/api/nativecart/service/CustomerService.java @@ -1,5 +1,6 @@ package io.sprucehill.zalando.api.nativecart.service; +import org.apache.http.HttpHeaders; import org.apache.http.client.methods.HttpGet; import com.fasterxml.jackson.core.type.TypeReference; import io.sprucehill.zalando.api.nativecart.model.Customer; @@ -15,7 +16,7 @@ public class CustomerService extends AbstractService implements ICustomerService @Override public Customer read(String accessToken ,String customerNumber) throws Exception { HttpGet request = getRequest("/customers/" + customerNumber); - request.addHeader("Authorization","Bearer "+accessToken); + request.addHeader(HttpHeaders.AUTHORIZATION,"Bearer "+accessToken); return execute(request, new TypeReference() {}); } } diff --git a/src/main/java/io/sprucehill/zalando/api/nativecart/service/ICheckoutService.java b/src/main/java/io/sprucehill/zalando/api/nativecart/service/ICheckoutService.java index e0f2c04..c724f5b 100644 --- a/src/main/java/io/sprucehill/zalando/api/nativecart/service/ICheckoutService.java +++ b/src/main/java/io/sprucehill/zalando/api/nativecart/service/ICheckoutService.java @@ -11,29 +11,32 @@ public interface ICheckoutService { /** * + * @param accessToken The access token for authorization * @param customerNumber The customer unique id * @param checkoutId The ID of the checkout to read * @return The checkout object with the requested ID for the specified customer * @throws Exception Any Exception that is thrown while doing the operation */ - Checkout read(String customerNumber,String checkoutId) throws Exception; + Checkout read(String accessToken,String customerNumber,String checkoutId) throws Exception; /** * + * @param accessToken The access token for authorization * @param customerNumber The customer unique id * @param CreatecheckoutRequest The checkout object to be created * @return The newly created checkout object * @throws Exception Any Exception that is thrown while doing the operation */ - Checkout create(String customerNumber,Checkout CreatecheckoutRequest) throws Exception; + Checkout create(String accessToken,String customerNumber,Checkout CreatecheckoutRequest) throws Exception; /** * + * @param accessToken The access token for authorization * @param customerNumber The customer unique id * @param checkoutId The ID of the address to update * @param updateCheckoutRequest The checkout object to be updated * @return The updated checkout object * @throws Exception Any Exception that is thrown while doing the operation */ - Checkout update(String customerNumber,String checkoutId,Checkout updateCheckoutRequest) throws Exception; + Checkout update(String accessToken,String customerNumber,String checkoutId,Checkout updateCheckoutRequest) throws Exception; } diff --git a/src/main/java/io/sprucehill/zalando/api/nativecart/service/IOrderService.java b/src/main/java/io/sprucehill/zalando/api/nativecart/service/IOrderService.java index fe94d81..e9e240a 100644 --- a/src/main/java/io/sprucehill/zalando/api/nativecart/service/IOrderService.java +++ b/src/main/java/io/sprucehill/zalando/api/nativecart/service/IOrderService.java @@ -11,10 +11,11 @@ public interface IOrderService { /** * + * @param accessToken The access token for authorization * @param customerNumber The unique id of the customer * @param createOrderRequest The order object to be created * @return The newly create order object * @throws Exception Any Exception that is thrown while doing the operation */ - Order create(String customerNumber,Order createOrderRequest) throws Exception; + Order create(String accessToken,String customerNumber,Order createOrderRequest) throws Exception; } diff --git a/src/main/java/io/sprucehill/zalando/api/nativecart/service/OrderService.java b/src/main/java/io/sprucehill/zalando/api/nativecart/service/OrderService.java index 94bf560..459f775 100644 --- a/src/main/java/io/sprucehill/zalando/api/nativecart/service/OrderService.java +++ b/src/main/java/io/sprucehill/zalando/api/nativecart/service/OrderService.java @@ -1,5 +1,6 @@ package io.sprucehill.zalando.api.nativecart.service; +import org.apache.http.HttpHeaders; import org.apache.http.client.methods.HttpPost; import org.apache.http.entity.ByteArrayEntity; import com.fasterxml.jackson.core.type.TypeReference; @@ -14,8 +15,10 @@ public class OrderService extends AbstractService implements IOrderService { @Override - public Order create(String customerNumber, Order createOrderRequest) throws Exception { + public Order create(String accessToken,String customerNumber, Order createOrderRequest) throws Exception { HttpPost request = postRequest("/customer/" + customerNumber +"/orders"); + request.addHeader(HttpHeaders.AUTHORIZATION,"Bearer "+accessToken); + request.addHeader(HttpHeaders.CONTENT_TYPE,"application/x.zalando.customer.order.create+json"); try { request.setEntity(new ByteArrayEntity(objectMapper.writeValueAsBytes(createOrderRequest))); }catch(Throwable t) { From 44c5cceda01a4d3ebaecbfccf6c2f5f7f0937f94 Mon Sep 17 00:00:00 2001 From: Diptee Warudkar Date: Thu, 17 Mar 2016 18:50:26 +0100 Subject: [PATCH 21/24] Implementing review comments , removing content-type setting and adding /customers instead of encoded value --- .../api/nativecart/service/AccessTokenService.java | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/main/java/io/sprucehill/zalando/api/nativecart/service/AccessTokenService.java b/src/main/java/io/sprucehill/zalando/api/nativecart/service/AccessTokenService.java index c17fe27..e841ce8 100644 --- a/src/main/java/io/sprucehill/zalando/api/nativecart/service/AccessTokenService.java +++ b/src/main/java/io/sprucehill/zalando/api/nativecart/service/AccessTokenService.java @@ -25,10 +25,9 @@ public class AccessTokenService extends AbstractService implements IAccessTokenS @Override public TokenInfo read() throws Exception { HttpPost request = postRequest("/access_token"); - request.setHeader(HttpHeaders.CONTENT_TYPE,"application/x-www-form-urlencoded"); List params = new ArrayList(); - params.add(new BasicNameValuePair("realm","%2Fcustomers")); + params.add(new BasicNameValuePair("realm","/customers")); params.add(new BasicNameValuePair("grant_type","client_credentials")); params.add(new BasicNameValuePair("client_id",clientId)); params.add(new BasicNameValuePair("client_secret",clientCredential)); @@ -40,14 +39,15 @@ public TokenInfo read() throws Exception { @Override public TokenInfo readFromAuthorizationCode(String authCode,String redirectUrl) throws Exception { - HttpPost request = postRequest("/access_token?realm=%2Fcustomers&grant_type=authorization_code&client_id="+clientId+"&client_secret="+clientCredential+"&code="+authCode+"&redirect_uri="+redirectUrl); - request.setHeader(HttpHeaders.CONTENT_TYPE,"application/x-www-form-urlencoded"); + HttpPost request = postRequest("/access_token"); List params = new ArrayList(); - params.add(new BasicNameValuePair("realm","%2Fcustomers")); + params.add(new BasicNameValuePair("realm","/customers")); params.add(new BasicNameValuePair("grant_type","authorization_code")); params.add(new BasicNameValuePair("client_id",clientId)); params.add(new BasicNameValuePair("client_secret",clientCredential)); + params.add(new BasicNameValuePair("code",authCode)); + params.add(new BasicNameValuePair("redirect_uri",redirectUrl)); request.setEntity(new UrlEncodedFormEntity(params)); From 9cd8e0e1f66c3a77256449526cacf71177183d43 Mon Sep 17 00:00:00 2001 From: Diptee Warudkar Date: Tue, 5 Apr 2016 09:51:13 +0200 Subject: [PATCH 22/24] Some bug fix came up while integration. - Changing app_domain_id to sales channel. - Linking corrrect property to shipping address id in checkout object - Updating the api url for checkout and order --- .../zalando/api/nativecart/model/Cart.java | 2 +- .../zalando/api/nativecart/model/Checkout.java | 2 +- .../zalando/api/nativecart/service/CartService.java | 3 +-- .../api/nativecart/service/CheckoutService.java | 13 ++++++------- .../api/nativecart/service/OrderService.java | 2 +- 5 files changed, 10 insertions(+), 12 deletions(-) diff --git a/src/main/java/io/sprucehill/zalando/api/nativecart/model/Cart.java b/src/main/java/io/sprucehill/zalando/api/nativecart/model/Cart.java index 77a947f..ce84a64 100644 --- a/src/main/java/io/sprucehill/zalando/api/nativecart/model/Cart.java +++ b/src/main/java/io/sprucehill/zalando/api/nativecart/model/Cart.java @@ -15,7 +15,7 @@ public class Cart extends Base { @JsonProperty private String id; - @JsonProperty(value="app_domain_id") + @JsonProperty(value="sales_channel") private String appDomainId; @JsonProperty diff --git a/src/main/java/io/sprucehill/zalando/api/nativecart/model/Checkout.java b/src/main/java/io/sprucehill/zalando/api/nativecart/model/Checkout.java index 73823c8..40cfabf 100644 --- a/src/main/java/io/sprucehill/zalando/api/nativecart/model/Checkout.java +++ b/src/main/java/io/sprucehill/zalando/api/nativecart/model/Checkout.java @@ -22,7 +22,7 @@ public class Checkout extends Base { @JsonProperty(value="billing_address_id") private String billingAddressId; - @JsonProperty(value="billing_address_id") + @JsonProperty(value="shipping_address_id") private String shippingAddressId; @JsonProperty diff --git a/src/main/java/io/sprucehill/zalando/api/nativecart/service/CartService.java b/src/main/java/io/sprucehill/zalando/api/nativecart/service/CartService.java index d229af1..601698a 100644 --- a/src/main/java/io/sprucehill/zalando/api/nativecart/service/CartService.java +++ b/src/main/java/io/sprucehill/zalando/api/nativecart/service/CartService.java @@ -24,11 +24,11 @@ public Cart create(String accessToken, Cart createCartRequest) throws Exception request.addHeader(HttpHeaders.AUTHORIZATION,"Bearer "+accessToken); request.addHeader(HttpHeaders.CONTENT_TYPE,"application/x.zalando.cart.create+json"); request.setEntity(new ByteArrayEntity(objectMapper.writeValueAsBytes(createCartRequest))); + return execute(request, new TypeReference() {}); }catch(Throwable t) { logger.warn(t.getMessage()); throw new RuntimeException(t); } - return execute(request, new TypeReference() {}); } @Override @@ -48,7 +48,6 @@ public Cart update(String access_token, String cart_id,Cart updateCartRequest) t request.addHeader(HttpHeaders.CONTENT_TYPE,"application/x.zalando.cart.items.update+json"); request.setEntity(new ByteArrayEntity(objectMapper.writeValueAsBytes(updateCartRequest.getItems()))); return execute(request, new TypeReference() {}); - }catch(Throwable t) { logger.warn(t.getMessage()); throw new RuntimeException(t); diff --git a/src/main/java/io/sprucehill/zalando/api/nativecart/service/CheckoutService.java b/src/main/java/io/sprucehill/zalando/api/nativecart/service/CheckoutService.java index 7643974..08e7c44 100644 --- a/src/main/java/io/sprucehill/zalando/api/nativecart/service/CheckoutService.java +++ b/src/main/java/io/sprucehill/zalando/api/nativecart/service/CheckoutService.java @@ -18,7 +18,7 @@ public class CheckoutService extends AbstractService implements ICheckoutService @Override public Checkout read(String accessToken,String customerNumber, String checkout_id) throws Exception { - HttpGet request = getRequest("/customer/"+customerNumber+"/checkouts/"+checkout_id); + HttpGet request = getRequest("/customers/"+customerNumber+"/checkouts/"+checkout_id); request.addHeader(HttpHeaders.AUTHORIZATION,"Bearer "+accessToken); request.addHeader(HttpHeaders.CONTENT_TYPE,"application/x.zalando.customer.checkout.create+json"); return execute(request, new TypeReference() {}); @@ -26,32 +26,31 @@ public Checkout read(String accessToken,String customerNumber, String checkout_i @Override public Checkout create(String accessToken,String customerNumber, Checkout createcheckoutRequest) throws Exception { - HttpPost request = postRequest("/customer/"+customerNumber+"/checkouts"); + HttpPost request = postRequest("/customers/"+customerNumber+"/checkouts"); request.addHeader(HttpHeaders.AUTHORIZATION,"Bearer "+accessToken); - request.addHeader(HttpHeaders.CONTENT_TYPE,"application/x.zalando.customer.checkout+json"); + request.addHeader(HttpHeaders.CONTENT_TYPE,"application/x.zalando.customer.checkout.create+json"); try { request.setEntity(new ByteArrayEntity(objectMapper.writeValueAsBytes(createcheckoutRequest))); + return execute(request, new TypeReference() {}); }catch (Throwable t) { logger.warn(t.getMessage()); throw new RuntimeException(t); } - return execute(request, new TypeReference() {}); } @Override public Checkout update(String accessToken,String customerNumber, String checkoutId,Checkout updateCheckoutRequest) throws Exception { - HttpPut request = putRequest("/customer/"+customerNumber+"/checkouts/"+checkoutId); + HttpPut request = putRequest("/customers/"+customerNumber+"/checkouts/"+checkoutId); request.addHeader(HttpHeaders.AUTHORIZATION,"Bearer "+accessToken); request.addHeader(HttpHeaders.CONTENT_TYPE,"application/x.zalando.customer.checkout.update+json"); try { request.setEntity(new ByteArrayEntity(objectMapper.writeValueAsBytes(updateCheckoutRequest))); + return execute(request, new TypeReference() {}); }catch (Throwable t) { logger.warn(t.getMessage()); throw new RuntimeException(t); } - return execute(request, new TypeReference() {}); } - } diff --git a/src/main/java/io/sprucehill/zalando/api/nativecart/service/OrderService.java b/src/main/java/io/sprucehill/zalando/api/nativecart/service/OrderService.java index 459f775..e9ad12b 100644 --- a/src/main/java/io/sprucehill/zalando/api/nativecart/service/OrderService.java +++ b/src/main/java/io/sprucehill/zalando/api/nativecart/service/OrderService.java @@ -16,7 +16,7 @@ public class OrderService extends AbstractService implements IOrderService { @Override public Order create(String accessToken,String customerNumber, Order createOrderRequest) throws Exception { - HttpPost request = postRequest("/customer/" + customerNumber +"/orders"); + HttpPost request = postRequest("/customers/" + customerNumber +"/orders"); request.addHeader(HttpHeaders.AUTHORIZATION,"Bearer "+accessToken); request.addHeader(HttpHeaders.CONTENT_TYPE,"application/x.zalando.customer.order.create+json"); try { From 8c94a6d48717da0a97aa826404ae687a8eb3fe70 Mon Sep 17 00:00:00 2001 From: Diptee Warudkar Date: Wed, 27 Apr 2016 13:45:54 +0200 Subject: [PATCH 23/24] Removing /customers/customer_number/ from urls --- .../zalando/api/nativecart/service/AddressService.java | 8 ++++---- .../zalando/api/nativecart/service/CheckoutService.java | 6 +++--- .../zalando/api/nativecart/service/CustomerService.java | 2 +- .../zalando/api/nativecart/service/OrderService.java | 2 +- 4 files changed, 9 insertions(+), 9 deletions(-) diff --git a/src/main/java/io/sprucehill/zalando/api/nativecart/service/AddressService.java b/src/main/java/io/sprucehill/zalando/api/nativecart/service/AddressService.java index bec483d..b284d82 100644 --- a/src/main/java/io/sprucehill/zalando/api/nativecart/service/AddressService.java +++ b/src/main/java/io/sprucehill/zalando/api/nativecart/service/AddressService.java @@ -22,21 +22,21 @@ public class AddressService extends AbstractService implements IAddressService { @Override public List
read(String accessToken,String customerNumber) throws Exception { - HttpGet request = getRequest("/customers/" + customerNumber +"/addresses"); + HttpGet request = getRequest("/addresses"); request.setHeader(HttpHeaders.AUTHORIZATION,"Bearer "+accessToken); return execute(request, new TypeReference>() {}); } @Override public Address read(String accessToken,String customerNumber, String addressId) throws Exception { - HttpGet request = getRequest("/customers/" + customerNumber +"/addresses/"+addressId); + HttpGet request = getRequest("/addresses/"+addressId); request.setHeader(HttpHeaders.AUTHORIZATION,"Bearer "+accessToken); return execute(request, new TypeReference
() {}); } @Override public Address update(String accessToken,String customerNumber, String addressId, Address updateAddressRequest) throws Exception { - HttpPut request = putRequest("/customers/" + customerNumber +"/addresses/"+addressId); + HttpPut request = putRequest("/addresses/"+addressId); try { request.setHeader(HttpHeaders.AUTHORIZATION,"Bearer "+accessToken); @@ -51,7 +51,7 @@ public Address update(String accessToken,String customerNumber, String addressId @Override public Address create(String accessToken,String customerNumber, Address createAddressRequest) throws Exception { - HttpPost request = postRequest("/customers/" + customerNumber+"/addresses"); + HttpPost request = postRequest("/addresses"); request.setHeader(HttpHeaders.AUTHORIZATION,"Bearer "+accessToken); request.addHeader(HttpHeaders.CONTENT_TYPE,"application/x.zalando.customer.address.create+json"); request.setEntity(new ByteArrayEntity(objectMapper.writeValueAsBytes(createAddressRequest))); diff --git a/src/main/java/io/sprucehill/zalando/api/nativecart/service/CheckoutService.java b/src/main/java/io/sprucehill/zalando/api/nativecart/service/CheckoutService.java index 08e7c44..acbbdae 100644 --- a/src/main/java/io/sprucehill/zalando/api/nativecart/service/CheckoutService.java +++ b/src/main/java/io/sprucehill/zalando/api/nativecart/service/CheckoutService.java @@ -18,7 +18,7 @@ public class CheckoutService extends AbstractService implements ICheckoutService @Override public Checkout read(String accessToken,String customerNumber, String checkout_id) throws Exception { - HttpGet request = getRequest("/customers/"+customerNumber+"/checkouts/"+checkout_id); + HttpGet request = getRequest("/checkouts/"+checkout_id); request.addHeader(HttpHeaders.AUTHORIZATION,"Bearer "+accessToken); request.addHeader(HttpHeaders.CONTENT_TYPE,"application/x.zalando.customer.checkout.create+json"); return execute(request, new TypeReference() {}); @@ -26,7 +26,7 @@ public Checkout read(String accessToken,String customerNumber, String checkout_i @Override public Checkout create(String accessToken,String customerNumber, Checkout createcheckoutRequest) throws Exception { - HttpPost request = postRequest("/customers/"+customerNumber+"/checkouts"); + HttpPost request = postRequest("/checkouts"); request.addHeader(HttpHeaders.AUTHORIZATION,"Bearer "+accessToken); request.addHeader(HttpHeaders.CONTENT_TYPE,"application/x.zalando.customer.checkout.create+json"); @@ -41,7 +41,7 @@ public Checkout create(String accessToken,String customerNumber, Checkout create @Override public Checkout update(String accessToken,String customerNumber, String checkoutId,Checkout updateCheckoutRequest) throws Exception { - HttpPut request = putRequest("/customers/"+customerNumber+"/checkouts/"+checkoutId); + HttpPut request = putRequest("/checkouts/"+checkoutId); request.addHeader(HttpHeaders.AUTHORIZATION,"Bearer "+accessToken); request.addHeader(HttpHeaders.CONTENT_TYPE,"application/x.zalando.customer.checkout.update+json"); diff --git a/src/main/java/io/sprucehill/zalando/api/nativecart/service/CustomerService.java b/src/main/java/io/sprucehill/zalando/api/nativecart/service/CustomerService.java index 593442f..0235207 100644 --- a/src/main/java/io/sprucehill/zalando/api/nativecart/service/CustomerService.java +++ b/src/main/java/io/sprucehill/zalando/api/nativecart/service/CustomerService.java @@ -15,7 +15,7 @@ public class CustomerService extends AbstractService implements ICustomerService @Override public Customer read(String accessToken ,String customerNumber) throws Exception { - HttpGet request = getRequest("/customers/" + customerNumber); + HttpGet request = getRequest("/customer"); request.addHeader(HttpHeaders.AUTHORIZATION,"Bearer "+accessToken); return execute(request, new TypeReference() {}); } diff --git a/src/main/java/io/sprucehill/zalando/api/nativecart/service/OrderService.java b/src/main/java/io/sprucehill/zalando/api/nativecart/service/OrderService.java index e9ad12b..9df61a2 100644 --- a/src/main/java/io/sprucehill/zalando/api/nativecart/service/OrderService.java +++ b/src/main/java/io/sprucehill/zalando/api/nativecart/service/OrderService.java @@ -16,7 +16,7 @@ public class OrderService extends AbstractService implements IOrderService { @Override public Order create(String accessToken,String customerNumber, Order createOrderRequest) throws Exception { - HttpPost request = postRequest("/customers/" + customerNumber +"/orders"); + HttpPost request = postRequest("/orders"); request.addHeader(HttpHeaders.AUTHORIZATION,"Bearer "+accessToken); request.addHeader(HttpHeaders.CONTENT_TYPE,"application/x.zalando.customer.order.create+json"); try { From ed7383f92d24e2118551a7df4a0a6d0c612b9021 Mon Sep 17 00:00:00 2001 From: duergner Date: Fri, 29 Apr 2016 08:18:29 +0200 Subject: [PATCH 24/24] Should bump the version to correct snapshot one --- build.gradle | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/build.gradle b/build.gradle index 8c44ba0..98ec8b2 100644 --- a/build.gradle +++ b/build.gradle @@ -24,7 +24,7 @@ apply plugin: 'signing' group = 'io.sprucehill' archivesBaseName = 'zalando-java-api-wrapper' -version = '0.5.0' +version = '0.6.0-SNAPSHOT' description = 'A Java API client for the Zalando REST API' processResources { @@ -76,7 +76,7 @@ uploadArchives { } snapshotRepository(url: "https://oss.sonatype.org/content/repositories/snapshots/") { - authentication(userName: hasProperty('ossrhUsername')?ossrhUsername:'', password: hasProperty('ossrhPassword')?ossrhPassword:'') + authentication(userName: this.hasProperty('ossrhUsername')?ossrhUsername:'', password: this.hasProperty('ossrhPassword')?ossrhPassword:'') } pom.project {