001/* 002 * The contents of this file are subject to the license and copyright 003 * detailed in the LICENSE and NOTICE files at the root of the source 004 * tree. 005 */ 006package org.fcrepo.kernel.impl.services; 007 008import java.util.stream.Stream; 009 010import javax.inject.Inject; 011 012import org.fcrepo.kernel.api.Transaction; 013import org.fcrepo.kernel.api.identifiers.FedoraId; 014import org.fcrepo.kernel.api.models.FedoraResource; 015import org.fcrepo.kernel.api.operations.DeleteResourceOperationFactory; 016import org.fcrepo.kernel.api.operations.ResourceOperation; 017import org.fcrepo.kernel.api.services.DeleteResourceService; 018import org.fcrepo.persistence.api.PersistentStorageSession; 019import org.fcrepo.persistence.api.exceptions.PersistentStorageException; 020 021import org.slf4j.Logger; 022import org.slf4j.LoggerFactory; 023import org.springframework.stereotype.Component; 024 025/** 026 * This class mediates delete operations between the kernel and persistent storage layers 027 * 028 * @author dbernstein 029 */ 030@Component 031public class DeleteResourceServiceImpl extends AbstractDeleteResourceService implements DeleteResourceService { 032 033 private final static Logger log = LoggerFactory.getLogger(DeleteResourceService.class); 034 035 @Inject 036 private DeleteResourceOperationFactory deleteResourceFactory; 037 038 @Override 039 protected Stream<String> getContained(final Transaction tx, final FedoraResource resource) { 040 return containmentIndex.getContains(tx, resource.getFedoraId()); 041 } 042 043 @Override 044 protected void doAction(final Transaction tx, final PersistentStorageSession pSession, 045 final FedoraId fedoraId, final String userPrincipal) 046 throws PersistentStorageException { 047 log.debug("starting delete of {}", fedoraId.getFullId()); 048 final ResourceOperation deleteOp = deleteResourceFactory.deleteBuilder(tx, fedoraId) 049 .userPrincipal(userPrincipal) 050 .build(); 051 052 lockArchivalGroupResource(tx, pSession, fedoraId); 053 tx.lockResource(fedoraId); 054 055 pSession.persist(deleteOp); 056 membershipService.resourceDeleted(tx, fedoraId); 057 containmentIndex.removeResource(tx, fedoraId); 058 referenceService.deleteAllReferences(tx, fedoraId); 059 searchIndex.removeFromIndex(tx, fedoraId); 060 recordEvent(tx, fedoraId, deleteOp); 061 log.debug("deleted {}", fedoraId.getFullId()); 062 } 063 064}