@Override public void updateMetadataResources(MCRObject object, Deposit entry) throws SwordServerException { throw new SwordServerException("Operation is not supported!", new OperationNotSupportedException()); }
public void deleteObject(MCRObject object) throws SwordServerException { try { object .getStructure() .getDerivates() .stream() .map(MCRMetaLinkID::getXLinkHrefID) .forEach(id -> { try { MCRMetadataManager.deleteMCRDerivate(id); } catch (Exception e) { throw new MCRException(e); } }); MCRMetadataManager.delete(object); } catch (MCRActiveLinkException | MCRAccessException | MCRException e) { Throwable ex = e; if (e instanceof MCRException && Optional.ofNullable(e.getCause()).map(Object::getClass) .filter(MCRAccessException.class::isAssignableFrom).isPresent()) { //unwrapp ex = e.getCause(); } throw new SwordServerException("Error while deleting Object.", ex); } }
@Override public List<MCRObjectID> get(int from, int count) throws SwordServerException { final SolrQuery queryCopy = this.solrQuery.getCopy(); queryCopy.setStart(from); queryCopy.setRows(count); try { final QueryResponse queryResponse = MCRSolrClientFactory.getMainSolrClient().query(queryCopy); return queryResponse.getResults().stream() .map(r -> (String) r.getFieldValue("id")) .map(MCRObjectID::getInstance) .collect(Collectors.toList()); } catch (SolrServerException | IOException e) { throw new SwordServerException("Error while getting id list with MCRSword2SolrObjectIDSupplier and Query: " + this.solrQuery, e); } } }
deposit.getMd5()); } catch (IOException e) { throw new SwordServerException("Could not store deposit to temp files", e); throw new SwordServerException("Error while extracting ZIP.", e); throw new SwordServerException("Error while adding file " + ifsRootPath, e);
private Document convertDCToMods(Document dcDocument) throws SwordError, SwordServerException { final MCRContent mcrContent; try { mcrContent = XSL_DC_MODS_TRANSFORMER.transform(new MCRJDOMContent(dcDocument)); } catch (IOException e) { throw new SwordError(UriRegistry.ERROR_BAD_REQUEST, HttpServletResponse.SC_INTERNAL_SERVER_ERROR, "Error while transforming mods2dc!", e); } Document convertedDocument; try { convertedDocument = mcrContent.asXML(); } catch (JDOMException | IOException | SAXException e) { throw new SwordServerException("Error getting transform result of mods to dc transformation!", e); } return convertedDocument; }
} catch (DSpaceSwordException e) { log.error("caught exception:", e); throw new SwordServerException( "There was a problem determining the request type", e); } finally {
throw new SwordServerException("Error while deleting media resource!", e);
} catch (DSpaceSwordException e) { log.error("caught exception: ", e); throw new SwordServerException( "The DSpace SWORD interface experienced an error", e); } finally {
@Override public long getCount() throws SwordServerException { try { // make a copy to prevent multi threading issues final SolrQuery queryCopy = this.solrQuery.getCopy(); // only need the numFound queryCopy.setStart(0); queryCopy.setRows(0); final QueryResponse queryResponse = MCRSolrClientFactory.getMainSolrClient().query(queryCopy); return queryResponse.getResults().getNumFound(); } catch (SolrServerException | IOException e) { throw new SwordServerException( "Error while getting count with MCRSword2SolrObjectIDSupplier and Query: " + this.solrQuery, e); } }
} catch (DSpaceSwordException e) { log.error("caught exception:", e); throw new SwordServerException( "There was a problem depositing the item", e); } finally {
private MediaResource getBitstreamResource(Context context, Bitstream bitstream) throws SwordServerException, SwordAuthException { try { InputStream stream = bitstreamService.retrieve(context, bitstream); MediaResource mr = new MediaResource(stream, bitstream.getFormat(context).getMIMEType(), null, true); mr.setContentMD5(bitstream.getChecksum()); mr.setLastModified(this.getLastModified(context, bitstream)); return mr; } catch (IOException | SQLException e) { throw new SwordServerException(e); } catch (AuthorizeException e) { throw new SwordAuthException(e); } }
} catch (DSpaceSwordException e) { log.error("caught exception:", e); throw new SwordServerException( "There was a problem depositing the item", e); } finally {
} catch (DSpaceSwordException e) { log.error("caught exception:", e); throw new SwordServerException( "There was a problem depositing the item", e); } finally {
} catch (DSpaceSwordException e) { log.error("caught exception:", e); throw new SwordServerException( "There was a problem depositing the item", e); } finally {
} catch (DSpaceSwordException e) { log.error("caught exception:", e); throw new SwordServerException( "There was a problem depositing the item", e); } finally {
throw new SwordServerException( "There was a problem depositing the item", e); } catch (SQLException e) { throw new SwordServerException(e); } finally {
throw new SwordAuthException(); } catch (SQLException | DSpaceSwordException e) { throw new SwordServerException(e); } finally { if (sc != null) {
public Feed listCollectionContents(IRI colIRI, AuthCredentials authCredentials, SwordConfiguration swordConfig) throws SwordServerException, SwordError, SwordAuthException { SwordContext sc = null; try { SwordConfigurationDSpace config = (SwordConfigurationDSpace) swordConfig; sc = this.doAuth(authCredentials); Context context = sc.getContext(); SwordUrlManager urlManager = config.getUrlManager(context, config); Collection collection = urlManager .getCollection(context, colIRI.toString()); if (collection == null) { throw new SwordError(404); } List<Item> items = this.listItems(sc, collection, swordConfig); return this.itemListToFeed(sc, items, swordConfig); } catch (DSpaceSwordException e) { throw new SwordServerException(e); } finally { // this is a read operation only, so there's never any need to commit the context if (sc != null) { sc.abort(); } } }
@Override public void ingestResource(MCRObject object, Deposit entry) throws SwordServerException, SwordError { final MCRObjectID objectID = object.getId(); MCRObjectID createdDerivateID = null; boolean complete = false; try { final MCRDerivate derivate = MCRSwordUtil.createDerivate(objectID.toString()); createdDerivateID = derivate.getId(); mcrSwordMediaHandler.addResource(createdDerivateID.toString(), "/", entry); complete = true; } catch (IOException e) { throw new SwordServerException("Error while creating new derivate for object " + objectID.toString(), e); } catch (MCRAccessException e) { throw new SwordError(UriRegistry.ERROR_BAD_REQUEST, HttpServletResponse.SC_UNAUTHORIZED, e.getMessage()); } finally { if (createdDerivateID != null && !complete) { try { MCRMetadataManager.deleteMCRDerivate(createdDerivateID); } catch (MCRAccessException e1) { // derivate can be created but not deleted ?! LOGGER.error("Derivate could not be deleted(deposit was invalid)", e1); } } else if(complete) { setDefaultMainFile(createdDerivateID.toString()); } } }
@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()); } }