Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /*
   * Copyright 2010-2013 Ning, Inc.
   *
   * Ning licenses this file to you under the Apache License, version 2.0
   * (the "License"); you may not use this file except in compliance with the
   * License.  You may obtain a copy of the License at:
   *
   *    http://www.apache.org/licenses/LICENSE-2.0
   *
  * Unless required by applicable law or agreed to in writing, software
  * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
  * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
  * License for the specific language governing permissions and limitations
  * under the License.
  */
 
 package com.ning.billing.subscription.api.timeline;
 
 import java.util.List;
 
 
 
 
 
     private final AddonUtils addonUtils;
     private final Clock clock;
     private final SubscriptionDao repairDao;
     private final CatalogService catalogService;
     private final List<SubscriptionBaseEventinitialEvents;
 
 
     public SubscriptionDataRepair(final SubscriptionBuilder builderfinal List<SubscriptionBaseEventinitialEventsfinal SubscriptionBaseApiService apiService,
                                   final SubscriptionDao daofinal Clock clockfinal AddonUtils addonUtilsfinal CatalogService catalogService,
                                   final InternalCallContextFactory internalCallContextFactory) {
         super(builderapiServiceclock);
         this. = dao;
         this. = addonUtils;
         this. = clock;
         this. = catalogService;
         this. = initialEvents;
         this. = internalCallContextFactory;
     }
 
 
 
     public SubscriptionDataRepair(final DefaultSubscriptionBase defaultSubscriptionBasefinal SubscriptionBaseApiService apiService,
                                   final SubscriptionDao daofinal Clock clockfinal AddonUtils addonUtilsfinal CatalogService catalogService,
                                   final InternalCallContextFactory internalCallContextFactory) {
         super(defaultSubscriptionBaseapiService , clock);
         this. = dao;
         this. = addonUtils;
         this. = clock;
         this. = catalogService;
         this. = defaultSubscriptionBase.getEvents();
         this. = internalCallContextFactory;
     }
 
         DateTime res = null;
         for (final SubscriptionBaseEvent cur : ) {
             if (cur.getActiveVersion() != getActiveVersion()) {
                 break;
             }
             if (cur.getType() == .) {
                 continue;
             }
             res = cur.getEffectiveDate();
         }
        return res;
    }
    public void addNewRepairEvent(final DefaultNewEvent inputfinal SubscriptionDataRepair baseSubscriptionfinal List<SubscriptionDataRepairaddonSubscriptionsfinal CallContext context)
            throws SubscriptionBaseRepairException {
        try {
            final PlanPhaseSpecifier spec = input.getPlanPhaseSpecifier();
            switch (input.getSubscriptionTransitionType()) {
                case :
                case :
                    recreate(specinput.getRequestedDate(), context);
                    checkAddonRights(baseSubscription);
                    break;
                case :
                    changePlanWithDate(spec.getProductName(), spec.getBillingPeriod(), spec.getPriceListName(), input.getRequestedDate(), context);
                    checkAddonRights(baseSubscription);
                    trickleDownBPEffectForAddon(addonSubscriptionsgetLastUserEventEffectiveDate(), context);
                    break;
                case :
                    cancelWithDate(input.getRequestedDate(), context);
                    trickleDownBPEffectForAddon(addonSubscriptionsgetLastUserEventEffectiveDate(), context);
                    break;
                case :
                    break;
                default:
                    throw new SubscriptionBaseRepairException(.input.getSubscriptionTransitionType(), );
            }
        } catch (SubscriptionBaseApiException e) {
            throw new SubscriptionBaseRepairException(e);
        } catch (CatalogApiException e) {
            throw new SubscriptionBaseRepairException(e);
        }
    }
    public void addFutureAddonCancellation(final List<SubscriptionDataRepairaddOnSubscriptionInRepairfinal CallContext context) {
        if (getCategory() != .) {
            return;
        }
        final SubscriptionBaseTransition pendingTransition = getPendingTransition();
        if (pendingTransition == null) {
            return;
        }
        final Product baseProduct = (pendingTransition.getTransitionType() == .) ? null :
                                    pendingTransition.getNextPlan().getProduct();
        addAddonCancellationIfRequired(addOnSubscriptionInRepairbaseProductpendingTransition.getEffectiveTransitionTime(), context);
    }
    private void trickleDownBPEffectForAddon(final List<SubscriptionDataRepairaddOnSubscriptionInRepairfinal DateTime effectiveDatefinal CallContext context)
            throws SubscriptionBaseApiException {
        if (getCategory() != .) {
            return;
        }
        final Product baseProduct = (getState() == .) ?
                                    null : getCurrentPlan().getProduct();
        addAddonCancellationIfRequired(addOnSubscriptionInRepairbaseProducteffectiveDatecontext);
    }
    private void addAddonCancellationIfRequired(final List<SubscriptionDataRepairaddOnSubscriptionInRepairfinal Product baseProduct,
                                                final DateTime effectiveDatefinal CallContext context) {
        final DateTime now = .getUTCNow();
        final Iterator<SubscriptionDataRepairit = addOnSubscriptionInRepair.iterator();
        while (it.hasNext()) {
            final SubscriptionDataRepair cur = it.next();
            if (cur.getState() == . ||
                cur.getCategory() != .) {
                continue;
            }
            final Plan addonCurrentPlan = cur.getCurrentPlan();
            if (baseProduct == null ||
                .isAddonIncluded(baseProductaddonCurrentPlan) ||
                !.isAddonAvailable(baseProductaddonCurrentPlan)) {
                final SubscriptionBaseEvent cancelEvent = new ApiEventCancel(new ApiEventBuilder()
                                                                                .setSubscriptionId(cur.getId())
                                                                                .setActiveVersion(cur.getActiveVersion())
                                                                                .setProcessedDate(now)
                                                                                .setEffectiveDate(effectiveDate)
                                                                                .setRequestedDate(now)
                                                                                .setFromDisk(true));
                .cancelSubscription(curcancelEvent.createInternalCallContext(cur.getId(), .context), 0);
            }
        }
    }
    private void checkAddonRights(final SubscriptionDataRepair baseSubscription)
            throws SubscriptionBaseApiExceptionCatalogApiException {
        if (getCategory() == .) {
            .checkAddonCreationRights(baseSubscriptiongetCurrentPlan());
        }
    }
    public List<SubscriptionBaseEventgetEvents() {
        return ;
    }
        return ;
    }
        return Collections2.filter(new Predicate<SubscriptionBaseEvent>() {
            @Override
            public boolean apply(final SubscriptionBaseEvent input) {
                return !.contains(input);
            }
        });
    }
New to GrepCode? Check out our FAQ X