001/** 002 * Copyright 2015 DuraSpace, Inc. 003 * 004 * Licensed under the Apache License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * http://www.apache.org/licenses/LICENSE-2.0 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 */ 016package org.fcrepo.http.api; 017 018import com.google.common.annotations.VisibleForTesting; 019import org.fcrepo.kernel.models.FedoraResource; 020import org.fcrepo.kernel.exception.RepositoryRuntimeException; 021import org.slf4j.Logger; 022import org.springframework.context.annotation.Scope; 023 024import javax.inject.Inject; 025import javax.jcr.RepositoryException; 026import javax.jcr.Session; 027import javax.ws.rs.DELETE; 028import javax.ws.rs.Path; 029import javax.ws.rs.PathParam; 030import javax.ws.rs.core.Response; 031 032import static javax.ws.rs.core.Response.noContent; 033import static org.slf4j.LoggerFactory.getLogger; 034 035/** 036 * CRUD operations on Fedora tombstones 037 * 038 * @author cbeer 039 */ 040@Scope("request") 041@Path("/{path: .*}/fcr:tombstone") 042public class FedoraTombstones extends FedoraBaseResource { 043 044 private static final Logger LOGGER = getLogger(FedoraTombstones.class); 045 046 @Inject 047 protected Session session; 048 049 @PathParam("path") protected String externalPath; 050 051 /** 052 * Default JAX-RS entry point 053 */ 054 public FedoraTombstones() { 055 super(); 056 } 057 058 /** 059 * Create a new FedoraNodes instance for a given path 060 * @param externalPath the external path 061 */ 062 @VisibleForTesting 063 public FedoraTombstones(final String externalPath) { 064 this.externalPath = externalPath; 065 } 066 067 068 /** 069 * Delete a tombstone resource (freeing the original resource to be reused) 070 * @return the free resource 071 */ 072 @DELETE 073 public Response delete() { 074 LOGGER.info("Delete tombstone: {}", resource()); 075 resource().delete(); 076 077 try { 078 session.save(); 079 } catch (RepositoryException e) { 080 throw new RepositoryRuntimeException(e); 081 } 082 083 return noContent().build(); 084 } 085 086 protected FedoraResource resource() { 087 return translator().convert(translator().toDomain(externalPath)); 088 } 089 090 091 @Override 092 protected Session session() { 093 return session; 094 } 095 096}