Skip to content

Commit

Permalink
Renamed OrderContext.addAttribute to setAttribute and added some debu…
Browse files Browse the repository at this point in the history
…gging lines when getting the order number generator - TRUNK-4270
  • Loading branch information
wluyima committed Mar 12, 2014
1 parent 5ad6a65 commit b738e2f
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 11 deletions.
2 changes: 1 addition & 1 deletion api/src/main/java/org/openmrs/api/OrderContext.java
Expand Up @@ -95,7 +95,7 @@ public Object getAttribute(String attributeName) {
* @param attributeName the attribute name
* @param attributeValue the attribute value
*/
public void addAttribute(String attributeName, Object attributeValue) {
public void setAttribute(String attributeName, Object attributeValue) {
getContextAttributes().put(attributeName, attributeValue);
}

Expand Down
Expand Up @@ -177,23 +177,20 @@ public Long getNextOrderNumberSeedSequenceValue() {
OpenmrsConstants.GP_NEXT_ORDER_NUMBER_SEED, LockOptions.UPGRADE);

if (globalProperty == null) {
throw new APIException("Missing global property named: "
+ OpenmrsConstants.GP_NEXT_ORDER_NUMBER_SEED);
throw new APIException("Missing global property named: " + OpenmrsConstants.GP_NEXT_ORDER_NUMBER_SEED);
}

String gpTextValue = globalProperty.getPropertyValue();
if (StringUtils.isBlank(gpTextValue)) {
throw new APIException("Invalid value for global property named: "
+ OpenmrsConstants.GP_NEXT_ORDER_NUMBER_SEED);
throw new APIException("Invalid value for global property named: " + OpenmrsConstants.GP_NEXT_ORDER_NUMBER_SEED);
}

Long gpNumericValue = null;
try {
gpNumericValue = Long.parseLong(gpTextValue);
}
catch (NumberFormatException ex) {
throw new APIException("Invalid value for global property named: "
+ OpenmrsConstants.GP_NEXT_ORDER_NUMBER_SEED);
throw new APIException("Invalid value for global property named: " + OpenmrsConstants.GP_NEXT_ORDER_NUMBER_SEED);
}

globalProperty.setPropertyValue(String.valueOf(gpNumericValue + 1));
Expand Down
3 changes: 2 additions & 1 deletion api/src/main/java/org/openmrs/api/impl/OrderServiceImpl.java
Expand Up @@ -14,7 +14,6 @@
package org.openmrs.api.impl;

import java.lang.reflect.Field;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
Expand Down Expand Up @@ -126,8 +125,10 @@ private OrderNumberGenerator getOrderNumberGenerator() {
OpenmrsConstants.GP_ORDER_NUMBER_GENERATOR_BEAN_ID);
if (StringUtils.hasText(generatorBeanId)) {
orderNumberGenerator = Context.getRegisteredComponent(generatorBeanId, OrderNumberGenerator.class);
log.info("Successfully set the configured order number generator");
} else {
orderNumberGenerator = this;
log.info("Setting default order number generator");
}
}

Expand Down
3 changes: 1 addition & 2 deletions api/src/main/java/org/openmrs/util/OpenmrsConstants.java
Expand Up @@ -1442,8 +1442,7 @@ public static final List<GlobalProperty> CORE_GLOBAL_PROPERTIES() {
props.add(new GlobalProperty(GLOBAL_PROPERTY_USER_REQUIRE_EMAIL_AS_USERNAME, "false",
"Indicates whether a username must be a valid e-mail or not.", BooleanDatatype.class, null));

props.add(new GlobalProperty(GP_NEXT_ORDER_NUMBER_SEED, "1",
"The next order number available for assignment"));
props.add(new GlobalProperty(GP_NEXT_ORDER_NUMBER_SEED, "1", "The next order number available for assignment"));

props.add(new GlobalProperty(GP_ORDER_NUMBER_GENERATOR_BEAN_ID, "",
"Specifies spring bean id of the order generator to use when assigning order numbers"));
Expand Down
2 changes: 1 addition & 1 deletion api/src/test/java/org/openmrs/api/OrderServiceTest.java
Expand Up @@ -1181,7 +1181,7 @@ public void saveOrder_shouldSetOrderNumberSpecifiedInTheContextIfSpecified() thr
order.setStartDate(new Date());
OrderContext orderCtxt = new OrderContext();
final String expectedOrderNumber = "Testing";
orderCtxt.addAttribute(TimestampOrderNumberGenerator.NEXT_ORDER_NUMBER, expectedOrderNumber);
orderCtxt.setAttribute(TimestampOrderNumberGenerator.NEXT_ORDER_NUMBER, expectedOrderNumber);
order = orderService.saveOrder(order, orderCtxt);
assertEquals(expectedOrderNumber, order.getOrderNumber());
}
Expand Down

0 comments on commit b738e2f

Please sign in to comment.