Permalink
Browse files

jaxrs: Add some validation to not allow by default past effective dat…

…e when changing subscription BCD.

Behavior can be overriden by new query parameter forceNewBcdWithPastEffectiveDate=true
  • Loading branch information...
1 parent 9099bce commit ba72085d94211d3f620f522dd1beea7f888af02f @sbrossie sbrossie committed Jan 5, 2017
@@ -85,6 +85,7 @@
public static final String QUERY_SEARCH_OFFSET = "offset";
public static final String QUERY_SEARCH_LIMIT = "limit";
public static final String QUERY_ENTITLEMENT_EFFECTIVE_FROM_DT = "effectiveFromDate";
+ public static final String QUERY_FORCE_NEW_BCD_WITH_PAST_EFFECTIVE_DATE = "forceNewBcdWithPastEffectiveDate";
public static final String QUERY_ACCOUNT_WITH_BALANCE = "accountWithBalance";
public static final String QUERY_ACCOUNT_WITH_BALANCE_AND_CBA = "accountWithBalanceAndCBA";
@@ -710,20 +710,42 @@ public Response doResponseOk(final Response operationResponse) {
public Response updateSubscriptionBCD(final SubscriptionJson json,
@PathParam(ID_PARAM_NAME) final String id,
@QueryParam(QUERY_ENTITLEMENT_EFFECTIVE_FROM_DT) final String effectiveFromDateStr,
+ @QueryParam(QUERY_FORCE_NEW_BCD_WITH_PAST_EFFECTIVE_DATE) @DefaultValue("false") final Boolean forceNewBcdWithPastEffectiveDate,
@HeaderParam(HDR_CREATED_BY) final String createdBy,
@HeaderParam(HDR_REASON) final String reason,
@HeaderParam(HDR_COMMENT) final String comment,
@javax.ws.rs.core.Context final UriInfo uriInfo,
- @javax.ws.rs.core.Context final HttpServletRequest request) throws SubscriptionApiException, EntitlementApiException {
+ @javax.ws.rs.core.Context final HttpServletRequest request) throws SubscriptionApiException, EntitlementApiException, AccountApiException {
verifyNonNullOrEmpty(json, "SubscriptionJson body should be specified");
verifyNonNullOrEmpty(json.getBillCycleDayLocal(), "SubscriptionJson new BCD should be specified");
- final LocalDate effectiveFromDate = toLocalDate(effectiveFromDateStr);
+ LocalDate effectiveFromDate = toLocalDate(effectiveFromDateStr);
final CallContext callContext = context.createContext(createdBy, reason, comment, request);
+
final UUID subscriptionId = UUID.fromString(id);
final Entitlement entitlement = entitlementApi.getEntitlementForId(subscriptionId, callContext);
+ if (effectiveFromDateStr != null) {
+ final Account account = accountUserApi.getAccountById(entitlement.getAccountId(), callContext);
+ final LocalDate accountToday = new LocalDate(clock.getUTCNow(), account.getTimeZone());
+ int comp = effectiveFromDate.compareTo(accountToday);
+ switch (comp) {
+ case -1:
+ if (!forceNewBcdWithPastEffectiveDate) {
+ throw new IllegalArgumentException("Changing a subscription BCD in the past may have consequences on previous invoice generated. Use flag forceNewBcdWithPastEffectiveDate to force this behavior");
+ }
+ break;
+ case 0:
+ // Ensure system will use curremt time for the event so it happens immediately
+ effectiveFromDate = null;
+ break;
+ case 1:
+ // Future date, normal case where such effectiveFromDateStr is being passed
+ break;
+ }
+ }
+
entitlement.updateBCD(json.getBillCycleDayLocal(), effectiveFromDate, callContext);
return Response.status(Status.OK).build();
}

1 comment on commit ba72085

@pierre
Member
pierre commented on ba72085 Jan 5, 2017

👍

Please sign in to comment.