org.broadleafcommerce.core.offer.service.workflow.RecordOfferUsageRollbackHandler Maven / Gradle / Ivy
/*
* #%L
* BroadleafCommerce Framework
* %%
* Copyright (C) 2009 - 2013 Broadleaf Commerce
* %%
* Licensed 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.
* #L%
*/
package org.broadleafcommerce.core.offer.service.workflow;
import java.util.List;
import java.util.Map;
import javax.annotation.Resource;
import org.broadleafcommerce.core.checkout.service.workflow.CheckoutSeed;
import org.broadleafcommerce.core.offer.domain.OfferAudit;
import org.broadleafcommerce.core.offer.service.OfferAuditService;
import org.broadleafcommerce.core.workflow.Activity;
import org.broadleafcommerce.core.workflow.ProcessContext;
import org.broadleafcommerce.core.workflow.state.RollbackFailureException;
import org.broadleafcommerce.core.workflow.state.RollbackHandler;
import org.springframework.stereotype.Component;
/**
* Rolls back audits that were saved in the database from {@link RecordOfferUsageActivity}.
*
* @author Phillip Verheyden (phillipuniverse)
* @see {@link RecordOfferUsageActivity}
*/
@Component("blRecordOfferUsageRollbackHandler")
public class RecordOfferUsageRollbackHandler implements RollbackHandler {
@Resource(name = "blOfferAuditService")
protected OfferAuditService offerAuditService;
@Override
public void rollbackState(Activity> activity, ProcessContext processContext, Map stateConfiguration) throws RollbackFailureException {
List audits = (List) stateConfiguration.get(RecordOfferUsageActivity.SAVED_AUDITS);
for (OfferAudit audit : audits) {
offerAuditService.delete(audit);
}
}
}