001/* 002 * Licensed to DuraSpace under one or more contributor license agreements. 003 * See the NOTICE file distributed with this work for additional information 004 * regarding copyright ownership. 005 * 006 * DuraSpace licenses this file to you under the Apache License, 007 * Version 2.0 (the "License"); you may not use this file except in 008 * compliance with the License. You may obtain a copy of the License at 009 * 010 * http://www.apache.org/licenses/LICENSE-2.0 011 * 012 * Unless required by applicable law or agreed to in writing, software 013 * distributed under the License is distributed on an "AS IS" BASIS, 014 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 015 * See the License for the specific language governing permissions and 016 * limitations under the License. 017 */ 018package org.fcrepo.http.api; 019 020import com.google.common.annotations.VisibleForTesting; 021import org.fcrepo.kernel.api.models.FedoraResource; 022import org.fcrepo.kernel.api.exception.RepositoryRuntimeException; 023import org.slf4j.Logger; 024import org.springframework.context.annotation.Scope; 025 026import javax.jcr.RepositoryException; 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 @PathParam("path") protected String externalPath; 047 048 /** 049 * Default JAX-RS entry point 050 */ 051 public FedoraTombstones() { 052 super(); 053 } 054 055 /** 056 * Create a new FedoraNodes instance for a given path 057 * @param externalPath the external path 058 */ 059 @VisibleForTesting 060 public FedoraTombstones(final String externalPath) { 061 this.externalPath = externalPath; 062 } 063 064 065 /** 066 * Delete a tombstone resource (freeing the original resource to be reused) 067 * @return the free resource 068 */ 069 @DELETE 070 public Response delete() { 071 LOGGER.info("Delete tombstone: {}", resource()); 072 resource().delete(); 073 074 try { 075 session.save(); 076 } catch (RepositoryException e) { 077 throw new RepositoryRuntimeException(e); 078 } 079 080 return noContent().build(); 081 } 082 083 protected FedoraResource resource() { 084 return translator().convert(translator().toDomain(externalPath)); 085 } 086}