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.api.exception; 007 008import static java.time.ZoneOffset.UTC; 009import static java.time.format.DateTimeFormatter.ISO_INSTANT; 010 011import java.time.format.DateTimeFormatter; 012import java.util.Objects; 013 014import org.fcrepo.kernel.api.models.FedoraResource; 015 016/** 017 * Exception when a Tombstone {@link org.fcrepo.kernel.api.models.FedoraResource} 018 * is used where a real object is expected 019 * 020 * @author cabeer 021 * @since 10/16/14 022 */ 023public class TombstoneException extends RepositoryRuntimeException { 024 025 private static final long serialVersionUID = 1L; 026 027 private final String tombstoneUri; 028 029 private final String timemapUri; 030 031 private final FedoraResource fedoraResource; 032 033 private static DateTimeFormatter isoFormatter = ISO_INSTANT.withZone(UTC); 034 035 /** 036 * Construct a new tombstone exception for a resource 037 * @param resource the fedora resource 038 */ 039 public TombstoneException(final FedoraResource resource) { 040 this(resource, null, null); 041 } 042 043 /** 044 * Create a new tombstone exception with a URI to the tombstone resource 045 * @param resource the fedora resource 046 * @param tombstoneUri the uri to the tombstone resource for the Link header. 047 * @param timemapUri the uri to the resource's timemap for a Link header. 048 */ 049 public TombstoneException(final FedoraResource resource, final String tombstoneUri, final String timemapUri) { 050 super("Discovered tombstone resource at " + resource.getFedoraId().getFullIdPath() + 051 (Objects.nonNull(resource.getLastModifiedDate()) ? ", departed at: " + 052 isoFormatter.format(resource.getLastModifiedDate()) : "")); 053 this.tombstoneUri = tombstoneUri; 054 this.timemapUri = timemapUri; 055 this.fedoraResource = resource; 056 } 057 058 /** 059 * Get a URI to the tombstone resource 060 * @return the URI to the tombstone resource 061 */ 062 public String getTombstoneURI() { 063 return tombstoneUri; 064 } 065 066 /** 067 * @return the timemap URI 068 */ 069 public String getTimemapUri() { 070 return timemapUri; 071 } 072 073 /** 074 * @return the original resource of the tombstone. 075 */ 076 public FedoraResource getFedoraResource() { 077 return fedoraResource; 078 } 079}