Class BusinessObjectUtilsImpl
java.lang.Object
com.softslate.commerce.businessobjects.core.BusinessObjectUtilsImpl
- All Implemented Interfaces:
BusinessObjectUtils
A utility object containing various methods used by
BusinessProcessors in performing business logic.
Each BusinessProcessors is able to retrieve an instance of
BusinessObjectUtils by calling its utils method.
- Author:
- David Tobey
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionFrom a given OrderItem, returns a Map of each of the OrderItemAttributes under it, keyed by the attributeCode.booleandoesOrderItemHaveAttributeCode(OrderItem oi, String attributeCode) Tests to see if a given order item has an OrderItemAttribute under it with the given attributeCode.formatDateTime(Date dateTime) Formats a Date object into a string suitable for storage in the database.formatPrice(double rawPrice, String currencyCode, Locale locale) Formats a double into a string suitable for displaying the double as a price.formatPrice(Double rawPrice, String currencyCode, Locale locale) Formats a Double into a string suitable for displaying the double as a price, or a price representing 0 if the Double is null.getMapsFromBeans(Collection beans) Given a collection of bean objects returns a collection ofMaps describing each bean's properties.parse(InputStream xmlStream, boolean ignoreWhitespace) Returns a DOM Level2 document that represents the given document.parseDateTime(String dateTime) Parses a string (typically taken from a database query) into a Date object.Parses a section of XML and returns the first Element node foundparseResponseData(String response) Parses a query string of name value pairs into a Map.prepareRequestData(Map params, boolean urlEncode) Prepares a string, which may optionally be url-encoded, for use with an HTTP request, given a map of the request's parameters.roundForMoney(double value) Rounds money values in generalroundForMoney(Double value) Rounds money values in generalsendHTTPGet(String urlString, String postData, boolean followRedirect, Map requestProperties, String inputCharSet, Integer timeoutInSeconds) sendHTTPPost(String urlString, String postData, boolean followRedirect, Map requestProperties, String inputCharSet, Integer timeoutInSeconds) Sends an HTTP request using the POST method to a given URL.protected StringsendHTTPRequest(String urlString, String postData, boolean followRedirect, Map requestProperties, String inputCharSet, Integer timeoutInSeconds, String method) booleanstringArrayValuesGreaterThan(String[] paramValues, int value) Determines if at least one element in a string array is greater than a given value.
-
Field Details
-
log
static org.apache.commons.logging.Log log
-
-
Constructor Details
-
BusinessObjectUtilsImpl
public BusinessObjectUtilsImpl()
-
-
Method Details
-
formatDateTime
Description copied from interface:BusinessObjectUtilsFormats a Date object into a string suitable for storage in the database.- Specified by:
formatDateTimein interfaceBusinessObjectUtils- Returns:
- a String in the form of "yyyy-MM-dd HH:mm:ss:SSS" suitable for storage in the database.
-
parseDateTime
Description copied from interface:BusinessObjectUtilsParses a string (typically taken from a database query) into a Date object.- Specified by:
parseDateTimein interfaceBusinessObjectUtils- Returns:
- a String in the form of "yyyy-MM-dd HH:mm:ss:SSS" suitable for storage in the database.
-
formatPrice
Description copied from interface:BusinessObjectUtilsFormats a Double into a string suitable for displaying the double as a price, or a price representing 0 if the Double is null.- Specified by:
formatPricein interfaceBusinessObjectUtils- Returns:
- a String suitable for displaying the double as a price.
-
formatPrice
Description copied from interface:BusinessObjectUtilsFormats a double into a string suitable for displaying the double as a price.- Specified by:
formatPricein interfaceBusinessObjectUtils- Returns:
- a String suitable for displaying the double as a price.
-
prepareRequestData
Description copied from interface:BusinessObjectUtilsPrepares a string, which may optionally be url-encoded, for use with an HTTP request, given a map of the request's parameters.- Specified by:
prepareRequestDatain interfaceBusinessObjectUtils- Parameters:
params- A Map of key-value String pairs representing the parameters of the request.urlEncode- If true, the keys and values in the string will be url-encoded.- Returns:
- A String representing a valid URL-encoded query string.
- Throws:
Exception
-
sendHTTPPost
public String sendHTTPPost(String urlString, String postData, boolean followRedirect, Map requestProperties, String inputCharSet, Integer timeoutInSeconds) throws Exception Description copied from interface:BusinessObjectUtilsSends an HTTP request using the POST method to a given URL.- Specified by:
sendHTTPPostin interfaceBusinessObjectUtils- Parameters:
urlString- The URL to send the request to.postData- A String representing a valid URL-encoded query string.followRedirect- A boolean indicating whether redirects should be followed.requestProperties- Map that holds request properties to be sent in connection.inputCharSet- Character set of the response datatimeoutInSeconds- The timeout in seconds before an exception is thrown. If null there is no timeout.- Returns:
- A String representing the server's response, or the Location header if redirects are not to be followed.
- Throws:
Exception
-
sendHTTPGet
public String sendHTTPGet(String urlString, String postData, boolean followRedirect, Map requestProperties, String inputCharSet, Integer timeoutInSeconds) throws Exception - Specified by:
sendHTTPGetin interfaceBusinessObjectUtils- Throws:
Exception
-
sendHTTPRequest
protected String sendHTTPRequest(String urlString, String postData, boolean followRedirect, Map requestProperties, String inputCharSet, Integer timeoutInSeconds, String method) throws Exception - Throws:
Exception
-
getMapsFromBeans
Description copied from interface:BusinessObjectUtilsGiven a collection of bean objects returns a collection ofMaps describing each bean's properties.- Specified by:
getMapsFromBeansin interfaceBusinessObjectUtils- Returns:
- A
CollectionofMaps describing the beans.
-
parse
public Document parse(InputStream xmlStream, boolean ignoreWhitespace) throws ParserConfigurationException, SAXException, IOException Returns a DOM Level2 document that represents the given document.- Specified by:
parsein interfaceBusinessObjectUtils- Parameters:
xmlStream- An InputStream that is the source of the XML dataignoreWhitespace- This is passed through to the DocumentBuilder.- Throws:
ParserConfigurationExceptionSAXExceptionIOException
-
parsePartialDocument
public Node parsePartialDocument(String xml) throws ParserConfigurationException, SAXException, IOException Parses a section of XML and returns the first Element node found- Specified by:
parsePartialDocumentin interfaceBusinessObjectUtils- Parameters:
xml- The XML to be parsed in String form- Throws:
ParserConfigurationExceptionSAXExceptionIOException
-
parseResponseData
Description copied from interface:BusinessObjectUtilsParses a query string of name value pairs into a Map.- Specified by:
parseResponseDatain interfaceBusinessObjectUtils- Parameters:
response- A String key-value pairs in the form of a URL query string- Returns:
- A Map representing the query string.
- Throws:
Exception
-
stringArrayValuesGreaterThan
Description copied from interface:BusinessObjectUtilsDetermines if at least one element in a string array is greater than a given value.- Specified by:
stringArrayValuesGreaterThanin interfaceBusinessObjectUtils- Parameters:
paramValues- The string array being tested.value- The value for the string array's elements to be tested against.- Returns:
trueif at least one element in a string array is greater than a given value.falseif not.
-
roundForMoney
Description copied from interface:BusinessObjectUtilsRounds money values in general- Specified by:
roundForMoneyin interfaceBusinessObjectUtils- Parameters:
value- The value to be rounded.- Returns:
- The value after rounding
-
roundForMoney
Description copied from interface:BusinessObjectUtilsRounds money values in general- Specified by:
roundForMoneyin interfaceBusinessObjectUtils- Parameters:
value- The value to be rounded.- Returns:
- The value after rounding
-
buildOrderItemAttributeMap
Description copied from interface:BusinessObjectUtilsFrom a given OrderItem, returns a Map of each of the OrderItemAttributes under it, keyed by the attributeCode.- Specified by:
buildOrderItemAttributeMapin interfaceBusinessObjectUtils- Returns:
- A Map of OrderItemAttributes and their values.
-
doesOrderItemHaveAttributeCode
Description copied from interface:BusinessObjectUtilsTests to see if a given order item has an OrderItemAttribute under it with the given attributeCode.- Specified by:
doesOrderItemHaveAttributeCodein interfaceBusinessObjectUtils- Parameters:
oi- The order itemattributeCode- The attribute code- Returns:
- true, if the OrderItem has an OrderItemAttribute under it with the attributeCode.
-