Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Responding to review comments for: The API should assign order numbers
to new orders - TRUNK-4163
- Loading branch information
Showing
1 changed file
with
29 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -59,6 +59,10 @@ public class OrderServiceImpl extends BaseOpenmrsService implements OrderService | |
|
||
protected OrderDAO dao; | ||
|
||
private static final String ORDER_NUMBER_PREFIX = "ORD-"; | ||
|
||
private static final String ORDER_NUMBER_START_VALUE = "1"; | ||
|
||
public OrderServiceImpl() { | ||
} | ||
|
||
|
@@ -471,16 +475,35 @@ public synchronized String getNewOrderNumber() { | |
GlobalProperty globalProperty = Context.getAdministrationService().getGlobalPropertyObject( | ||
OpenmrsConstants.GLOBAL_PROPERTY_NEXT_ORDER_NUMBER); | ||
if (globalProperty == null) { | ||
globalProperty = new GlobalProperty(OpenmrsConstants.GLOBAL_PROPERTY_NEXT_ORDER_NUMBER, "1", | ||
"The next order number available for assignment"); | ||
globalProperty = new GlobalProperty(OpenmrsConstants.GLOBAL_PROPERTY_NEXT_ORDER_NUMBER, | ||
ORDER_NUMBER_START_VALUE, "The next order number available for assignment"); | ||
} | ||
|
||
String gpTextValue = globalProperty.getPropertyValue(); | ||
if (!StringUtils.hasText(gpTextValue)) { | ||
gpTextValue = ORDER_NUMBER_START_VALUE; | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong. |
||
} | ||
|
||
Long gpNumericValue = null; | ||
try { | ||
gpNumericValue = Long.parseLong(gpTextValue); | ||
} | ||
catch (NumberFormatException ex) { | ||
gpNumericValue = 1l; | ||
gpTextValue = ORDER_NUMBER_START_VALUE; | ||
This comment has been minimized.
Sorry, something went wrong.
wluyima
Member
|
||
} | ||
|
||
String orderNumber = "ORD-" + globalProperty.getValue(); | ||
String orderNumber = ORDER_NUMBER_PREFIX + gpTextValue; | ||
|
||
globalProperty.setPropertyValue(String.valueOf(gpNumericValue + 1)); | ||
|
||
globalProperty.setPropertyValue(String.valueOf(Long.parseLong(globalProperty.getPropertyValue()) + 1)); | ||
Context.addProxyPrivilege(PrivilegeConstants.MANAGE_GLOBAL_PROPERTIES); | ||
Context.getAdministrationService().saveGlobalProperty(globalProperty); | ||
Context.removeProxyPrivilege(PrivilegeConstants.MANAGE_GLOBAL_PROPERTIES); | ||
try { | ||
Context.getAdministrationService().saveGlobalProperty(globalProperty); | ||
} | ||
finally { | ||
Context.removeProxyPrivilege(PrivilegeConstants.MANAGE_GLOBAL_PROPERTIES); | ||
} | ||
|
||
return orderNumber; | ||
} | ||
|
Wouldn't it be better to fail out loud here because if say a user cleared it or a module or some form of bug(i have seen a similar bug that clears global properties) , it would mean you will end up getting back already assigned values. I assumed when instantiating the GP the very first time ever you set it to 1 meaning it should never go back to 1.