Skip to content

Commit c4f1694

Browse files
author
Rowan Drew
committed
Fixes #11
--README.md Updated retrieve org data section to contain more links to example files to retrieve products, categories, attributes, makers, models and maker model mappings --APIv1EndpointOrgRetrieveESDocument.java Added constants to allow category, maker, maker model, maker model mapping, and attributes to be retrieved. Modified call method to support pagination, and additional parameters with each data request. --APIv1ExampleRunnerRetrieveOrgESDDataAttributes.java Added class to show example of retrieving organisation attribute data from the platform's api. --APIv1ExampleRunnerRetrieveOrgESDDataCategories.java Added class to show example of retrieving organisation category data from the platform's api. --APIv1ExampleRunnerRetrieveOrgESDData.java Set correct comments in class. --APIv1ExampleRunnerRetrieveOrgESDDataMakerModelMappings.java Added class to show example of retrieving organisation maker model mapping data from the platform's api. --APIv1ExampleRunnerRetrieveOrgESDDataMakerModels.java Added class to show example of retrieving organisation maker model data from the platform's api. --APIv1ExampleRunnerRetrieveOrgESDDataMakers.java Added class to show example of retrieving organisation makers data from the platform's api.
1 parent 447a4ca commit c4f1694

8 files changed

+1593
-88
lines changed

README.md

Lines changed: 230 additions & 78 deletions
Large diffs are not rendered by default.

src/org/squizz/api/v1/endpoint/APIv1EndpointOrgRetrieveESDocument.java

Lines changed: 48 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package org.squizz.api.v1.endpoint;
22

33
/**
4-
* Copyright (C) 2017 Squizz PTY LTD
4+
* Copyright (C) 2019 Squizz PTY LTD
55
* This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
66
* This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
77
* You should have received a copy of the GNU General Public License along with this program. If not, see http://www.gnu.org/licenses/.
@@ -29,8 +29,13 @@
2929
public class APIv1EndpointOrgRetrieveESDocument
3030
{
3131
public static final int RETRIEVE_TYPE_ID_PRODUCTS = 3;
32-
public static final int RETRIEVE_TYPE_ID_PRICING = 37;
32+
public static final int RETRIEVE_TYPE_ID_CATEGORIES = 8;
3333
public static final int RETRIEVE_TYPE_ID_PRODUCT_STOCK = 10;
34+
public static final int RETRIEVE_TYPE_ID_ATTRIBUTES = 11;
35+
public static final int RETRIEVE_TYPE_ID_PRICING = 37;
36+
public static final int RETRIEVE_TYPE_ID_MAKERS = 44;
37+
public static final int RETRIEVE_TYPE_ID_MAKER_MODELS = 45;
38+
public static final int RETRIEVE_TYPE_ID_MAKER_MODEL_MAPPINGS = 46;
3439

3540
/**
3641
* Calls the platform's API endpoint and gets organisation data in a Ecommerce Standards Document of a specified type
@@ -39,9 +44,12 @@ public class APIv1EndpointOrgRetrieveESDocument
3944
* @param retrieveTypeID ID of the type of data to retrieve
4045
* @param supplierOrgID unique ID of the supplier organisation in the SQUIZZ.com platform to obtain data from
4146
* @param customerAccountCode code of the supplier organisation's customer account. Customer account only needs to be set if the supplier organisation has assigned multiple accounts to the organisation logged into the API session (customer org) and account specific data is being obtained
47+
* @param recordsMaxAmount maximum number of records to obtain from the platform
48+
* @param recordsStartIndex index containing the position of records to start obtaining from the server
49+
* @param requestParameters set additional parameters to in the request URL. Ensure parameter values are URI encoded
4250
* @return response from calling the API endpoint
4351
*/
44-
public static APIv1EndpointResponseESD call(APIv1OrgSession apiOrgSession, int endpointTimeoutMilliseconds, int retrieveTypeID, String supplierOrgID, String customerAccountCode)
52+
public static APIv1EndpointResponseESD call(APIv1OrgSession apiOrgSession, int endpointTimeoutMilliseconds, int retrieveTypeID, String supplierOrgID, String customerAccountCode, int recordsMaxAmount, int recordsStartIndex, String requestParameters)
4553
{
4654
ArrayList<Pair<String, String>> requestHeaders = new ArrayList<>();
4755
APIv1EndpointResponseESD endpointResponse = new APIv1EndpointResponseESD();
@@ -50,7 +58,14 @@ public static APIv1EndpointResponseESD call(APIv1OrgSession apiOrgSession, int e
5058

5159
try{
5260
//set endpoint parameters
53-
String endpointParams = "data_type_id="+retrieveTypeID + "&supplier_org_id=" + URLEncoder.encode(supplierOrgID, StandardCharsets.UTF_8.name()) + "&customer_account_code="+URLEncoder.encode(customerAccountCode, StandardCharsets.UTF_8.name());
61+
String endpointParams =
62+
"data_type_id="+retrieveTypeID +
63+
"&supplier_org_id=" +
64+
URLEncoder.encode(supplierOrgID, StandardCharsets.UTF_8.name()) +
65+
"&customer_account_code="+URLEncoder.encode(customerAccountCode, StandardCharsets.UTF_8.name())+
66+
"&records_max_amount="+recordsMaxAmount+
67+
"&records_start_index="+recordsStartIndex+
68+
(requestParameters!= null && !requestParameters.isEmpty()? "&"+requestParameters: "");
5469

5570
//create JSON deserializer to interpret the response from the endpoint
5671
ObjectMapper jsonMapper = new ObjectMapper();
@@ -66,6 +81,21 @@ public static APIv1EndpointResponseESD call(APIv1OrgSession apiOrgSession, int e
6681
break;
6782
case RETRIEVE_TYPE_ID_PRODUCT_STOCK:
6883
endpointJSONReader = jsonMapper.readerFor(ESDocumentStockQuantity.class);
84+
break;
85+
case RETRIEVE_TYPE_ID_CATEGORIES:
86+
endpointJSONReader = jsonMapper.readerFor(ESDocumentCategory.class);
87+
break;
88+
case RETRIEVE_TYPE_ID_ATTRIBUTES:
89+
endpointJSONReader = jsonMapper.readerFor(ESDocumentAttribute.class);
90+
break;
91+
case RETRIEVE_TYPE_ID_MAKERS:
92+
endpointJSONReader = jsonMapper.readerFor(ESDocumentMaker.class);
93+
break;
94+
case RETRIEVE_TYPE_ID_MAKER_MODELS:
95+
endpointJSONReader = jsonMapper.readerFor(ESDocumentMakerModel.class);
96+
break;
97+
case RETRIEVE_TYPE_ID_MAKER_MODEL_MAPPINGS:
98+
endpointJSONReader = jsonMapper.readerFor(ESDocumentMakerModelMapping.class);
6999
break;
70100
default:
71101
callEndpoint = false;
@@ -99,4 +129,18 @@ public static APIv1EndpointResponseESD call(APIv1OrgSession apiOrgSession, int e
99129

100130
return endpointResponse;
101131
}
132+
133+
/**
134+
* Calls the platform's API endpoint and gets organisation data in a Ecommerce Standards Document of a specified type
135+
* @param apiOrgSession existing organisation API session
136+
* @param endpointTimeoutMilliseconds amount of milliseconds to wait after calling the the API before giving up, set a positive number
137+
* @param retrieveTypeID ID of the type of data to retrieve
138+
* @param supplierOrgID unique ID of the supplier organisation in the SQUIZZ.com platform to obtain data from
139+
* @param customerAccountCode code of the supplier organisation's customer account. Customer account only needs to be set if the supplier organisation has assigned multiple accounts to the organisation logged into the API session (customer org) and account specific data is being obtained
140+
* @return response from calling the API endpoint
141+
*/
142+
public static APIv1EndpointResponseESD call(APIv1OrgSession apiOrgSession, int endpointTimeoutMilliseconds, int retrieveTypeID, String supplierOrgID, String customerAccountCode)
143+
{
144+
return call(apiOrgSession, endpointTimeoutMilliseconds, retrieveTypeID, supplierOrgID, customerAccountCode, 5000, 0, "");
145+
}
102146
}

test/org/squizz/api/v1/example/APIv1ExampleRunnerRetrieveOrgESDData.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
2-
* Copyright (C) 2017 Squizz PTY LTD
2+
* Copyright (C) 2019 Squizz PTY LTD
33
* This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
44
* This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
55
* You should have received a copy of the GNU General Public License along with this program. If not, see http://www.gnu.org/licenses/.
@@ -75,16 +75,16 @@ public static void main(String[] args)
7575
System.out.println("FAIL - API session failed to be created. Reason: " + endpointResponse.result_message + " Error Code: " + endpointResponse.result_code);
7676
}
7777

78-
//import organisation data if the API was successfully created
78+
//retrieve organisation data if the API was successfully created
7979
if(apiOrgSession.sessionExists())
8080
{
8181
//after 60 seconds give up on waiting for a response from the API when creating the notification
8282
int timeoutMilliseconds = 60000;
8383

84-
//call the platform's API to import in the organisation's data, which for this example is product pricing
84+
//call the platform's API to retrieve the organisation's data, which for this example is product pricing
8585
APIv1EndpointResponseESD endpointResponseESD = APIv1EndpointOrgRetrieveESDocument.call(apiOrgSession, timeoutMilliseconds, recordType, supplierOrgID, customerAccountCode);
8686

87-
//check that the data successfully imported
87+
//check that the data successfully retrieved
8888
if(endpointResponseESD.result.equals(APIv1EndpointResponse.ENDPOINT_RESULT_SUCCESS)){
8989
System.out.println("SUCCESS - organisation data successfully obtained from the platform");
9090
DecimalFormat decimalFormat = new DecimalFormat("#.####");
@@ -133,7 +133,7 @@ public static void main(String[] args)
133133
int i=0;
134134
for(ESDRecordProduct productRecord: esDocumentProduct.dataRecords)
135135
{
136-
//output details of the price record
136+
//output details of the product record
137137
System.out.println(APIv1OrgTestRunner.CONSOLE_LINE);
138138
System.out.println("Product Record #: " + i);
139139
System.out.println(" Key Product ID: " + productRecord.keyProductID);
@@ -176,7 +176,7 @@ public static void main(String[] args)
176176
int i=0;
177177
for(ESDRecordStockQuantity stockQuantityRecord: esDocumentStockQuantity.dataRecords)
178178
{
179-
//output details of the price record
179+
//output details of the product stock record
180180
System.out.println(APIv1OrgTestRunner.CONSOLE_LINE);
181181
System.out.println("Product Record #: " + i);
182182
System.out.println(" Key Product ID: " + stockQuantityRecord.keyProductID);

0 commit comments

Comments
 (0)