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 void throwObjectDoesNotExist(String objectIdString) throws SwordError { throw new SwordError(UriRegistry.ERROR_BAD_REQUEST, HttpServletResponse.SC_NOT_FOUND, "The object '" + objectIdString + "' does not exist!"); }
@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."); }
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."); } }
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 SwordError throwRegularSwordErrorWithoutStackTrace(String error) { if (error == null) { error = "UNKNOWN"; } SwordError swordError = new SwordError(error); StackTraceElement[] emptyStackTrace = new StackTraceElement[0]; swordError.setStackTrace(emptyStackTrace); return swordError; }
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!"); } }
/** * @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; }
@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"); } }
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"); } }
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; } }
public static SwordEntryIngester getEntryInstance(Context context, Deposit deposit, DSpaceObject dso) throws DSpaceSwordException, SwordError { SwordEntryIngester ingester = (SwordEntryIngester) CoreServiceFactory.getInstance().getPluginService() .getSinglePlugin(SwordEntryIngester.class); if (ingester == null) { throw new SwordError(UriRegistry.ERROR_CONTENT, "No ingester configured for handling SWORD entry documents"); } return ingester; } }
public static SwordEntryDisseminator getEntryInstance() throws DSpaceSwordException, SwordError { SwordEntryDisseminator disseminator = (SwordEntryDisseminator) CoreServiceFactory.getInstance() .getPluginService() .getSinglePlugin(SwordEntryDisseminator.class); if (disseminator == null) { throw new SwordError(DSpaceUriRegistry.REPOSITORY_ERROR, "No disseminator configured for handling sword entry documents"); } return disseminator; } }
/** * Get an instance of WorkflowManager * @return WorkflowManager * @throws DSpaceSwordException * @throws SwordError */ public static WorkflowManager getInstance() throws DSpaceSwordException, SwordError { WorkflowManager manager = (WorkflowManager) CoreServiceFactory.getInstance().getPluginService() .getSinglePlugin(WorkflowManager.class); if (manager == null) { throw new SwordError(DSpaceUriRegistry.REPOSITORY_ERROR, "No workflow manager configured"); } return manager; } }
protected Collection getDepositTarget(Context context, String depositUrl, SwordConfigurationDSpace config) throws DSpaceSwordException, SwordError { SwordUrlManager urlManager = config.getUrlManager(context, config); // get the target collection Collection collection = urlManager.getCollection(context, depositUrl); if (collection == null) { throw new SwordError(404); } this.verboseDescription .append("Performing deposit using deposit URL: " + depositUrl); this.verboseDescription .append("Location resolves to collection with handle: " + collection.getHandle() + " and name: " + collectionService.getName(collection)); return collection; } }
@Override public void updateMetadata(MCRObject object, Deposit entry, boolean replace) throws SwordServerException, SwordError { if (!replace) { throw new SwordServerException("Operation is not supported!", new OperationNotSupportedException()); } final Document document = buildDCDocument(entry.getSwordEntry().getDublinCore()); final Document newMetadata = convertDCToMods(document); object.getMetadata().setFromDOM(newMetadata.detachRootElement()); try { MCRMetadataManager.update(object); } catch (MCRAccessException e) { throw new SwordError(UriRegistry.ERROR_BAD_REQUEST, HttpServletResponse.SC_UNAUTHORIZED, e.getMessage()); } }