-
Notifications
You must be signed in to change notification settings - Fork 3.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
TRUNK-4696: added specific exception classes for the Order Service
Modifying some Order Exception definitions to be more in line with the messages.properties. Fixing test to map to these new definitions.
- Loading branch information
1 parent
f5ef7a7
commit f7b79fd
Showing
3 changed files
with
229 additions
and
58 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 |
---|---|---|
@@ -0,0 +1,170 @@ | ||
/** | ||
* This Source Code Form is subject to the terms of the Mozilla Public License, | ||
* v. 2.0. If a copy of the MPL was not distributed with this file, You can | ||
* obtain one at http://mozilla.org/MPL/2.0/. OpenMRS is also distributed under | ||
* the terms of the Healthcare Disclaimer located at http://openmrs.org/license. | ||
* | ||
* Copyright (C) OpenMRS Inc. OpenMRS is a registered trademark and the OpenMRS | ||
* graphic logo is a trademark of OpenMRS Inc. | ||
*/ | ||
package org.openmrs.api; | ||
|
||
import static org.openmrs.Order.Action.DISCONTINUE; | ||
|
||
/** | ||
* Represents specific error conditions that are part of OrderService. | ||
* The specific error classes define only a default constructor if they are meant to be used with only a single error message. | ||
* In other cases, there should be static factory methods that can be used to create the error class with the specific error message needed. | ||
*/ | ||
public class OrderExceptions { | ||
|
||
public static final long serialVersionUID = 22121212L; | ||
|
||
/** | ||
* Thrown when the OrderAlreadyExists. | ||
*/ | ||
public static class CannotEditAlreadyExistingOrderException extends APIException { | ||
|
||
public static final long serialVersionUID = 22121213L; | ||
|
||
public CannotEditAlreadyExistingOrderException() { | ||
super("Order.cannot.edit.existing"); | ||
} | ||
} | ||
|
||
/** | ||
* Thrown when the Order has already been discontinued. | ||
*/ | ||
public static class CannotDiscontinueAlreadyDiscontinuedOrderException extends APIException { | ||
|
||
public static final long serialVersionUID = 22121214L; | ||
|
||
public CannotDiscontinueAlreadyDiscontinuedOrderException() { | ||
super("Order.stopped.cannot.discontinued"); | ||
} | ||
} | ||
|
||
/** | ||
* Thrown when trying to stop a retrospective discontinued order. | ||
*/ | ||
public static class CannotStopRetrospectiveDiscontinuedOrderException extends APIException { | ||
|
||
public static final long serialVersionUID = 22221215L; | ||
|
||
public CannotStopRetrospectiveDiscontinuedOrderException() { | ||
super("Order.retrospective.stopped.cannot.discontinued"); | ||
} | ||
} | ||
|
||
/** | ||
* Thrown with trying to discontinue an order with a specific action that cannot be discontinued. | ||
*/ | ||
public static class CannotDiscontinueOrderWithActionException extends APIException { | ||
|
||
public static final long serialVersionUID = 22121215L; | ||
|
||
public CannotDiscontinueOrderWithActionException() { | ||
super("Order.action.cannot.discontinued", new Object[] { DISCONTINUE }, null); | ||
} | ||
} | ||
|
||
/** | ||
* Thrown when an attempt to unvoid an order fails. | ||
*/ | ||
public static class CannotUnvoidOrderException extends APIException { | ||
|
||
public static final long serialVersionUID = 22121315L; | ||
|
||
public CannotUnvoidOrderException(String action) { | ||
super("Order.action.cannot.unvoid", new Object[] { action }); | ||
} | ||
} | ||
|
||
/** | ||
* Thrown when a previous order is required. | ||
*/ | ||
public static class PreviousOrderRequiredException extends APIException { | ||
|
||
public static final long serialVersionUID = 22121216L; | ||
|
||
public PreviousOrderRequiredException() { | ||
super("Order.previous.required"); | ||
} | ||
} | ||
|
||
/** | ||
* Thrown when trying to change unchangeable order properties. | ||
*/ | ||
public static class UnchangeableOrderPropertyException extends APIException { | ||
|
||
public static final long serialVersionUID = 22121217L; | ||
|
||
private UnchangeableOrderPropertyException(String message) { | ||
super(message); | ||
} | ||
|
||
public static UnchangeableOrderPropertyException withProperty(String property) { | ||
return new UnchangeableOrderPropertyException(String.format("Order.cannot.change.%s", property)); | ||
} | ||
} | ||
|
||
/** | ||
* Thrown when the new edited order contains modified properties that must be the same as previous order. | ||
*/ | ||
public static class EditedOrderDoesNotMatchPreviousException extends APIException { | ||
|
||
public static final long serialVersionUID = 22121218L; | ||
|
||
public EditedOrderDoesNotMatchPreviousException(String message) { | ||
super(message); | ||
} | ||
|
||
public EditedOrderDoesNotMatchPreviousException(String message, Object[] params) { | ||
super(message, params); | ||
} | ||
} | ||
|
||
/** | ||
* Thrown when the order is invalid. | ||
*/ | ||
public static class InvalidOrderException extends APIException { | ||
|
||
public static final long serialVersionUID = 22121219L; | ||
|
||
public InvalidOrderException(String message) { | ||
super(message); | ||
} | ||
} | ||
|
||
/** | ||
* Thrown when trying to edit an order property which is still in use. | ||
*/ | ||
public static class CannotEditOrderPropertyInUseException extends APIException { | ||
|
||
public static final long serialVersionUID = 22121220L; | ||
|
||
private CannotEditOrderPropertyInUseException(String message) { | ||
super(message); | ||
} | ||
|
||
public static CannotEditOrderPropertyInUseException withProperty(String property) { | ||
return new CannotEditOrderPropertyInUseException(String.format("Order.%s.cannot.edit", property)); | ||
} | ||
} | ||
|
||
/** | ||
* Thrown when trying to delete an order property that is still in use. | ||
*/ | ||
public static class CannotDeleteOrderPropertyInUseException extends APIException { | ||
|
||
public static final long serialVersionUID = 22121221L; | ||
|
||
private CannotDeleteOrderPropertyInUseException(String message) { | ||
super(message); | ||
} | ||
|
||
public static CannotDeleteOrderPropertyInUseException withProperty(String property) { | ||
return new CannotDeleteOrderPropertyInUseException(String.format("Order.%s.cannot.delete", property)); | ||
} | ||
} | ||
} |
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
Oops, something went wrong.