Package com.portal.common
Class CurrencyRateManager
java.lang.Object
com.portal.common.InfranetCachedData
com.portal.common.CurrencyRateManager
-
Nested Class Summary
Nested classes/interfaces inherited from class com.portal.common.InfranetCachedData
InfranetCachedData.InstanceBuilder
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final int
static final int
Currency mode determines which operator to use for currency exchange rates.static final int
static final long
This value signifies that the end time for a currency rate is infinite.Fields inherited from class com.portal.common.InfranetCachedData
m_Connection
-
Constructor Summary
ConstructorsModifierConstructorDescriptionprotected
CurrencyRateManager
(PortalContext connection) Construct a rate manager object. -
Method Summary
Modifier and TypeMethodDescriptionconvertCurrency
(int srcCurrencyID, int destCurrencyID, Date transactionTime, BigDecimal amount) Convert an amount from one currency to another based on a point in time.static CurrencyRateManager
getInstance
(PortalContext connection) Get the one and only instance of this class.static CurrencyRateManager
getInstance
(PortalContext connection, boolean rebuild) Get the one and only instance of this class.static boolean
Determine if tTestTime is equal to tBaseTime.static boolean
Determine if testTime is greater than baseTime.static boolean
Determine if testTime is greater than or equal to baseTime.static boolean
Determine if testTime is less than baseTime.static boolean
Determine if testTime is less than or equal to baseTime.static boolean
isTimeWithinRange
(Date testTime, Date startTime, Date endTime) Determine if tTestTime is between startTime and endTime.protected boolean
isTriangulationRequired
(int srcCurrencyID, int destCurrencyID) Test to see if this is a case where we must do triangulation for rate conversion of an amount from one currency to another.protected ExchangeRate
loadCurrencyRate
(int srcCurrencyID, int destCurrencyID, Date transactionDate) Try to load the currency rate for the specified source and destination currencies and transaction time.protected ExchangeRate
lookupRate
(int srcCurrencyID, int destCurrencyID, Date transTime) Find the rate for the specified source currency, destination currency, and transaction time.Methods inherited from class com.portal.common.InfranetCachedData
buildKey, buildKeySimple, createDataManagers, getInstanceImpl, getInstanceImplSimple
-
Field Details
-
CURRENCY_OPERATOR_MULTIPLY
public static final int CURRENCY_OPERATOR_MULTIPLYCurrency mode determines which operator to use for currency exchange rates. This is necessary because it is illegal with the EURO and EMU currencies to multiply by the inverse rates.- See Also:
-
CURRENCY_OPERATOR_DIVIDE
public static final int CURRENCY_OPERATOR_DIVIDE- See Also:
-
CURRENCY_OPERATOR_NONE
public static final int CURRENCY_OPERATOR_NONE- See Also:
-
TIME_NEVER
public static final long TIME_NEVERThis value signifies that the end time for a currency rate is infinite.- See Also:
-
-
Constructor Details
-
CurrencyRateManager
Construct a rate manager object. This class is primarily used to convert currency values from one currency to another based on a point in time.- Parameters:
connection
- An active connection to Portal.
-
-
Method Details
-
getInstance
Get the one and only instance of this class. If the instance has not been created then create one.- Parameters:
connection
- An active connection to Portal.- Returns:
- The one and only instance of this class.
-
getInstance
Get the one and only instance of this class. If the instance has not been created then create one.- Parameters:
connection
- An active connection to Portal.rebuild
- If this flag is TRUE then the reference to the existing instance will be set to null and a new instance will be created. This will cause the data to be refreshed.- Returns:
- The one and only instance of this class.
-
convertCurrency
public BigDecimal convertCurrency(int srcCurrencyID, int destCurrencyID, Date transactionTime, BigDecimal amount) throws CurrencyRateException Convert an amount from one currency to another based on a point in time. If the required rate information is not in the cache then it will be read from Portal.- Parameters:
srcCurrencyID
- The ID of the currency to convert from.destCurrencyID
- The ID of the currency to convert to.transactionTime
- The point in time that the amount was "realized" (time of billing, time of the adjustment was made, etc.)amount
- The amount to convert.- Throws:
CurrencyRateException
- is thrown if the specified rate was not found, corrupt data, etc.
-
isTriangulationRequired
protected boolean isTriangulationRequired(int srcCurrencyID, int destCurrencyID) Test to see if this is a case where we must do triangulation for rate conversion of an amount from one currency to another. Note: At present this means that the source and destination are both EMU currencies. This definition will need to be expanded in the future- Parameters:
srcCurrencyID
- The ID of the currency to convert from.destCurrencyID
- The ID of the currency to convert to.- Returns:
- false if Triangulation is NOT needed for the conversion and true if Triangulation is NEEDED for the conversion.
-
isTimeLT
Determine if testTime is less than baseTime. This method is very useful for changing the way we compare times throughout the code base, especially when the time_t format will change over in 2039 (time_t measures the time in seconds from 1/1/1970 to 1/1/2039)- Parameters:
testTime
- Time to test against tBaseTimebaseTime
- Basis for test- Returns:
- Return true if testTime is less than baseTime or baseTime is equal to CurrencyRateManager.TIME_NEVER, otherwise return false.
-
isTimeLTE
Determine if testTime is less than or equal to baseTime. This method is very useful for changing the way we compare times throughout the code base, especially when the time_t format will change over in 2039 (time_t measures the time in seconds from 1/1/1970 to 1/1/2039)- Parameters:
testTime
- Time to test against tBaseTimebaseTime
- Basis for test- Returns:
- Return true if testTime is less than or equal to baseTime or baseTime is equal to CurrencyRateManager.TIME_NEVER, otherwise return false.
-
isTimeGT
Determine if testTime is greater than baseTime. This method is very useful for changing the way we compare times throughout the code base, especially when the time_t format will change over in 2039 (time_t measures the time in seconds from 1/1/1970 to 1/1/2039)- Parameters:
testTime
- Time to test against tBaseTimebaseTime
- Basis for test- Returns:
- Return true if testTime is greater than baseTime and baseTime does not equal CurrencyRateManager.TIME_NEVER, otherwise return false.
-
isTimeGTE
Determine if testTime is greater than or equal to baseTime. This method is very useful for changing the way we compare times throughout the code base, especially when the time_t format will change over in 2039 (time_t measures the time in seconds from 1/1/1970 to 1/1/2039)- Parameters:
testTime
- Time to test against tBaseTimebaseTime
- Basis for test- Returns:
- Return true if testTime is greater than or equal to baseTime and baseTime does not equal CurrencyRateManager.TIME_NEVER, otherwise return false.
-
isTimeEQ
Determine if tTestTime is equal to tBaseTime. This method is very useful for changing the way we compare times throughout the code base, especially when the time_t format will change over in 2039 (time_t measures the time in seconds from 1/1/1970 to 1/1/2039)- Parameters:
testTime
- Time to test against tBaseTimebaseTime
- Basis for test- Returns:
- Return true if testTime is equal to baseTime, otherwise return false.
-
isTimeWithinRange
Determine if tTestTime is between startTime and endTime. This method is very useful for changing the way we compare times throughout the code base, especially when the time_t format will change over in 2039 (time_t measures the time in seconds from 1/1/1970 to 1/1/2039)- Parameters:
testTime
- Time to test against the time range.startTime
- The start of the time range.endTime
- The end of the time range.- Returns:
- Return true if testTime is within the time range specified by startTime and endTime, otherwise return false.
-
loadCurrencyRate
protected ExchangeRate loadCurrencyRate(int srcCurrencyID, int destCurrencyID, Date transactionDate) throws CurrencyRateException Try to load the currency rate for the specified source and destination currencies and transaction time. After loading the rate create and return a currency rate object.- Parameters:
srcCurrencyID
- The ID of the currency to convert from.destCurrencyID
- The ID of the currency to convert to.transactionDate
- The point time the transaction was made.- Throws:
CurrencyRateException
- is thrown if the specified rate was not found, corrupt data, etc.
-
lookupRate
protected ExchangeRate lookupRate(int srcCurrencyID, int destCurrencyID, Date transTime) throws CurrencyRateException Find the rate for the specified source currency, destination currency, and transaction time. If the rate is not in "cache" then load it from memory and add it to the "cache".- Parameters:
srcCurrencyID
- The ID of the currency to convert from.destCurrencyID
- The ID of the currency to convert to.transTime
- The point in time that the amount was "realized" (time of billing, time of the adjustment was made, etc.)- Returns:
- Return the matching rate object. An exception will be thrown if an error is encountered.
- Throws:
CurrencyRateException
- is thrown if the specified rate was not found, corrupt data, etc.
-