public static void checkIsObject(MCRBase retrievedMCRBase) throws SwordError { if (retrievedMCRBase instanceof MCRDerivate) { throw new SwordError(UriRegistry.ERROR_METHOD_NOT_ALLOWED, HttpServletResponse.SC_BAD_REQUEST, "You cannot directly change Metadata of a Derivate!"); } }
public static SwordError throwSpecialSwordErrorWithoutStackTrace(String SwordUriRegistryError, String error) { if (SwordUriRegistryError == null) { SwordUriRegistryError = UriRegistry.ERROR_BAD_REQUEST; } if (error == null) { error = "UNKNOWN"; } SwordError swordError = new SwordError(SwordUriRegistryError, error); StackTraceElement[] emptyStackTrace = new StackTraceElement[0]; swordError.setStackTrace(emptyStackTrace); return swordError; }
public static void throwObjectDoesNotExist(String objectIdString) throws SwordError { throw new SwordError(UriRegistry.ERROR_BAD_REQUEST, HttpServletResponse.SC_NOT_FOUND, "The object '" + objectIdString + "' does not exist!"); }
public static SwordError throwRegularSwordErrorWithoutStackTrace(String error) { if (error == null) { error = "UNKNOWN"; } SwordError swordError = new SwordError(error); StackTraceElement[] emptyStackTrace = new StackTraceElement[0]; swordError.setStackTrace(emptyStackTrace); return swordError; }
@Override public DepositReceipt replaceMediaResource(String uri, Deposit deposit, AuthCredentials authCredentials, SwordConfiguration swordConfiguration) throws SwordError, SwordServerException, SwordAuthException { /** * @todo: Perhaps create a new version of a dataset here? * * "The server MUST effectively replace all the existing content in the * item, although implementations may choose to provide versioning or * some other mechanism for retaining the overwritten content." -- * http://swordapp.github.io/SWORDv2-Profile/SWORDProfile.html#protocoloperations_editingcontent_binary * * Also, if you enable this method, think about the SwordError currently * being returned by replaceOrAddFiles with shouldReplace set to true * and an empty zip uploaded. If no files are unzipped the user will see * a error about this but the files will still be deleted! */ throw new SwordError(UriRegistry.ERROR_BAD_REQUEST, "Replacing the files of a dataset is not supported. Please delete and add files separately instead."); }
/** * @todo get rid of this method */ private SwordError returnEarly(String error) { SwordError swordError = new SwordError(error); StackTraceElement[] emptyStackTrace = new StackTraceElement[0]; swordError.setStackTrace(emptyStackTrace); return swordError; }
protected static void checkFile(MCRPath path) throws SwordError { if (!Files.exists(path)) { throw new SwordError(UriRegistry.ERROR_BAD_REQUEST, HttpServletResponse.SC_NOT_FOUND, "The requested file '" + path + "' does not exists."); } }
protected static void checkObject(String objectID) throws SwordError { if (objectID == null) { throw new SwordError(UriRegistry.ERROR_BAD_REQUEST, HttpServletResponse.SC_BAD_REQUEST, "Could not extract ObjectID from IRI."); } if (!MCRMetadataManager.exists(MCRObjectID.getInstance(objectID))) { throw new SwordError(UriRegistry.ERROR_BAD_REQUEST, HttpServletResponse.SC_NOT_FOUND, "The requested object " + objectID + " does not exist!"); } }
public void replaceMediaResource(String derivateId, String requestFilePath, Deposit deposit) throws SwordError, SwordServerException { if (!MCRAccessManager.checkPermission(derivateId, MCRAccessManager.PERMISSION_WRITE)) { throw new SwordError(UriRegistry.ERROR_METHOD_NOT_ALLOWED, "You dont have the right to write to the derivate!"); } MCRPath path = MCRPath.getPath(derivateId, requestFilePath); if (!Files.exists(path)) { throw new SwordError(UriRegistry.ERROR_BAD_REQUEST, HttpServletResponse.SC_NOT_FOUND, "Cannot replace a not existing file."); } final boolean pathIsDirectory = Files.isDirectory(path); if (pathIsDirectory) { throw new SwordError(UriRegistry.ERROR_BAD_REQUEST, HttpServletResponse.SC_METHOD_NOT_ALLOWED, "replaceMediaResource is not supported with directories"); } // TODO: replace file }
@Override public boolean isStatementRequest(String uri, Map<String, String> map, AuthCredentials authCredentials, SwordConfiguration swordConfiguration) throws SwordError, SwordServerException, SwordAuthException { urlManager.processUrl(uri); String servlet = urlManager.getServlet(); if (servlet != null) { return servlet.equals("statement"); } else { throw new SwordError(UriRegistry.ERROR_BAD_REQUEST, "Unable to determine requested IRI from URL: " + uri); } }
public void modifyState(Context context, Item item) throws SwordError, DSpaceSwordException { WorkflowTools wft = new WorkflowTools(); if (item.isArchived() || item.isWithdrawn()) { throw new SwordError(UriRegistry.ERROR_METHOD_NOT_ALLOWED, "The item has already been archived, and can no longer be modified"); } if (wft.isItemInWorkflow(context, item)) { throw new SwordError(UriRegistry.ERROR_METHOD_NOT_ALLOWED, "The item has already been injected into the review workflow, and can no longer be " + "modified"); } }
public void deleteItem(Context context, Item item) throws SwordError, DSpaceSwordException { WorkflowTools wft = new WorkflowTools(); if (item.isArchived() || item.isWithdrawn()) { throw new SwordError(UriRegistry.ERROR_METHOD_NOT_ALLOWED, "The item has already been archived, and can no longer be modified"); } if (wft.isItemInWorkflow(context, item)) { throw new SwordError(UriRegistry.ERROR_METHOD_NOT_ALLOWED, "The item has already been injected into the review workflow, and can no longer be " + "modified"); } }
String baseUrl = this.getBaseCollectionUrl(); if (baseUrl.length() == location.length()) { throw new SwordError(DSpaceUriRegistry.BAD_URL, "The deposit URL is incomplete"); throw new SwordError(DSpaceUriRegistry.BAD_URL, "The deposit URL is incomplete"); throw new SwordError(DSpaceUriRegistry.BAD_URL, "The deposit URL does not resolve to a valid collection");
public void replaceResourceContent(Context context, Item item) throws SwordError, DSpaceSwordException { WorkflowTools wft = new WorkflowTools(); if (item.isArchived() || item.isWithdrawn()) { throw new SwordError(UriRegistry.ERROR_METHOD_NOT_ALLOWED, "The item has already been archived, and can no longer be modified"); } if (wft.isItemInWorkflow(context, item)) { throw new SwordError(UriRegistry.ERROR_METHOD_NOT_ALLOWED, "The item has already been injected into the review workflow, and can no longer be " + "modified"); } }
public void deleteMediaResource(Context context, Item item) throws SwordError, DSpaceSwordException { WorkflowTools wft = new WorkflowTools(); if (item.isArchived() || item.isWithdrawn()) { throw new SwordError(UriRegistry.ERROR_METHOD_NOT_ALLOWED, "The item has already been archived, and can no longer be modified"); } if (wft.isItemInWorkflow(context, item)) { throw new SwordError(UriRegistry.ERROR_METHOD_NOT_ALLOWED, "The item has already been injected into the review workflow, and can no longer be " + "modified"); } }
public void addResourceContent(Context context, Item item) throws SwordError, DSpaceSwordException { WorkflowTools wft = new WorkflowTools(); if (item.isArchived() || item.isWithdrawn()) { throw new SwordError(UriRegistry.ERROR_METHOD_NOT_ALLOWED, "The item has already been archived, and can no longer be modified"); } if (wft.isItemInWorkflow(context, item)) { throw new SwordError(UriRegistry.ERROR_METHOD_NOT_ALLOWED, "The item has already been injected into the review workflow, and can no longer be " + "modified"); } }
public Bitstream getBitstream(Context context, String location) throws DSpaceSwordException, SwordError { try { String baseUrl = this.getSwordBaseUrl(); String emBaseUrl = baseUrl + "/edit-media/bitstream/"; if (!location.startsWith(emBaseUrl)) { throw new SwordError(DSpaceUriRegistry.BAD_URL, "The bitstream URL is invalid"); } String bitstreamParts = location.substring(emBaseUrl.length()); // the bitstream id is the part up to the first "/" int firstSlash = bitstreamParts.indexOf("/"); String bid = bitstreamParts.substring(0, firstSlash); Bitstream bitstream = bitstreamService.findByIdOrLegacyId(context, bid); return bitstream; } catch (SQLException e) { // log.error("Caught exception:", e); throw new DSpaceSwordException( "There was a problem resolving the collection", e); } }
u = new URI(url); } catch (URISyntaxException ex) { throw new SwordError(UriRegistry.ERROR_BAD_REQUEST, "unable to part URL");
cBaseUrl = sBaseUrl; } else { throw new SwordError(DSpaceUriRegistry.BAD_URL, "The item URL is invalid");
private Item getDSpaceTarget(Context context, String editUrl, SwordConfigurationDSpace config) throws DSpaceSwordException, SwordError { SwordUrlManager urlManager = config.getUrlManager(context, config); // get the target collection Item item = urlManager.getItem(context, editUrl); if (item == null) { throw new SwordError(404); } this.verboseDescription.append( "Performing replace using edit-media URL: " + editUrl); this.verboseDescription.append( "Location resolves to item with handle: " + item.getHandle()); return item; } }