private MCRObjectID checkID(String objectID) { if (objectID == null || objectID.isEmpty() || !MCRObjectID.isValid(objectID)) { throw new WebApplicationException(Status.NOT_FOUND); } MCRObjectID oid = MCRObjectID.getInstance(objectID); if (!MCRMetadataManager.exists(oid)) { throw new WebApplicationException(Status.NOT_FOUND); } return oid; }
/** * Checks for a given derivate id whether all files in that derivate are tiled. * * @return true if all files in belonging to the derivate are tiled, false otherwise */ public static boolean isCompletelyTiled(String derivateId) { if (!MCRMetadataManager.exists(MCRObjectID.getInstance(derivateId))) { return false; } EntityManager em = MCREntityManagerProvider.getCurrentEntityManager(); TypedQuery<Number> namedQuery = em .createNamedQuery("MCRTileJob.countByStateListByDerivate", Number.class) .setParameter("derivateId", derivateId) .setParameter("states", MCRJobState.notCompleteStates().stream().map(MCRJobState::toChar).collect( Collectors.toSet())); return namedQuery.getSingleResult().intValue() == 0; }
protected String formatURI(String uri, String id, String metadataPrefix) { MCRObjectID mcrID = MCRObjectID.isValid(id) ? MCRObjectID.getInstance(id) : null; boolean exists; String objectType; if (mcrID != null) { exists = MCRMetadataManager.exists(mcrID); objectType = mcrID.getTypeId(); } else { MCRFilesystemNode node = MCRFilesystemNode.getNode(id); exists = node != null; objectType = "data_file"; } return uri.replace("{id}", id).replace("{format}", metadataPrefix).replace("{objectType}", objectType).replace( ":{flag}", !exists ? ":deletedMcrObject" : ""); }
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!"); } }
@DELETE @Operation(summary = "Deletes MCRDerivate {" + PARAM_DERID + "}", tags = MCRRestUtils.TAG_MYCORE_DERIVATE, responses = { @ApiResponse(responseCode = "204", description = "MCRDerivate successfully deleted"), }) @MCRRequireTransaction @Path("/{" + PARAM_DERID + "}") public Response deleteDerivate( @Parameter(example = "mir_derivate_00004711") @PathParam(PARAM_DERID) MCRObjectID derid) { if (!MCRMetadataManager.exists(derid)) { throw new NotFoundException(); } try { MCRMetadataManager.deleteMCRDerivate(derid); return Response.noContent().build(); } catch (MCRAccessException e) { throw new ForbiddenException(); } }
if (MCRMetadataManager.exists(objectID)) { MCRObject obj = MCRMetadataManager.retrieveMCRObject(objectID); List<Map.Entry<String, URI>> newMediaList = registrationService.getMediaList(obj);
/** * Adds a new "work" to the remote ORCID profile. * The publication data is taken from the MODS stored in the MyCoRe object with the given ID. */ public MCRWork addWorkFrom(MCRObjectID objectID) throws IOException, JDOMException, SAXException { if (!MCRMetadataManager.exists(objectID)) { throw new MCRORCIDException("can not create work, object " + objectID + " does not exist locally"); } MCRWork work = orcid.getPublisher().createWorkFrom(objectID); this.addWork(work); return work; }
@DELETE @Path("/{" + PARAM_MCRID + "}") @Operation(summary = "Deletes MCRObject {" + PARAM_MCRID + "}", tags = MCRRestUtils.TAG_MYCORE_OBJECT, responses = { @ApiResponse(responseCode = "204", description = "MCRObject successfully deleted"), @ApiResponse(responseCode = "409", description = "MCRObject could not be deleted as it is referenced.", content = @Content(schema = @Schema( description = "Map<String, <Collection<String>> of source (key) to targets (value)", implementation = Map.class))), }) @MCRRequireTransaction public Response deleteObject(@PathParam(PARAM_MCRID) MCRObjectID id) { //check preconditions if (!MCRMetadataManager.exists(id)) { throw new NotFoundException(); } try { MCRMetadataManager.deleteMCRObject(id); } catch (MCRActiveLinkException e) { Map<String, Collection<String>> activeLinks = e.getActiveLinks(); return Response.status(Response.Status.CONFLICT).entity(activeLinks).build(); } catch (MCRAccessException e) { throw new ForbiddenException(); //usually handled before } return Response.noContent().build(); }
/** * If this work's source is this MyCoRe application, * updates the work in the remote ORCID profile from the local MyCoRe object */ public void update() throws IOException, SAXException, JDOMException { if (!source.isThisApplication()) { throw new MCRORCIDException("can not update that work, is not from us"); } if (!MCRMetadataManager.exists(objectID)) { throw new MCRORCIDException("can not update that work, object " + objectID + " does not exist locally"); } orcid.getPublisher().update(this); }
if (!MCRMetadataManager.exists(derID)) { throw new MCRRestAPIException(Response.Status.NOT_FOUND, new MCRRestAPIError(MCRRestAPIError.CODE_NOT_FOUND, "There is no derivate with the id '" + matchedDerID + "'.", null));
LOGGER.info("Checking DOI: {}", doi.asString()); MCRObjectID objectID = getObjectID(uri); if (MCRMetadataManager.exists(objectID)) { if (!registrationService.isRegistered(objectID, "")) { LOGGER.info("DOI is not registered in MyCoRe. Add to Database: {}", doi.asString());
if (MCRMetadataManager.exists(id)) { MCRMetadataManager.update(updatedObject); return Response.status(Response.Status.NO_CONTENT).build();
@Override public DepositReceipt getEntry(String editIRI, Map<String, String> map, AuthCredentials authCredentials, SwordConfiguration swordConfiguration) throws SwordServerException, SwordError, SwordAuthException { IRI iri = new IRI(editIRI); String collection = MCRSwordUtil.ParseLinkUtil.EditIRI.getCollectionFromEditIRI(iri); String objectIdString = MCRSwordUtil.ParseLinkUtil.EditIRI.getObjectFromEditIRI(iri); final MCRSwordCollectionProvider collectionProvider = MCRSword.getCollection(collection); LOGGER.info(MessageFormat.format("REQUEST: Get entry {0} from {1} !", objectIdString, collection)); collectionProvider.getAuthHandler().authentication(authCredentials); MCRObjectID objectId = MCRObjectID.getInstance(objectIdString); if (!MCRMetadataManager.exists(objectId)) { throwObjectDoesNotExist(objectIdString); } MCRBase retrievedMCRBase = MCRMetadataManager.retrieve(objectId); checkIsObject(retrievedMCRBase); final Optional<Map<String, String>> accept = Optional.of(map); return collectionProvider.getContainerHandler().getMetadata(collection, (MCRObject) retrievedMCRBase, accept); }
if (!MCRMetadataManager.exists(objectID)) { LOGGER.info("Could not find Object : {}", objectID); return;
@Override public DepositReceipt addResources(String editIRI, Deposit deposit, AuthCredentials authCredentials, SwordConfiguration swordConfiguration) throws SwordError, SwordServerException, SwordAuthException { IRI iri = new IRI(editIRI); String collection = MCRSwordUtil.ParseLinkUtil.EditIRI.getCollectionFromEditIRI(iri); String objectIdString = MCRSwordUtil.ParseLinkUtil.EditIRI.getObjectFromEditIRI(iri); final MCRSwordCollectionProvider collectionProvider = MCRSword.getCollection(collection); LOGGER.info(MessageFormat.format("REQUEST: add resources {0} from {1} !", objectIdString, collection)); collectionProvider.getAuthHandler().authentication(authCredentials); MCRObjectID objectId = MCRObjectID.getInstance(objectIdString); if (!MCRMetadataManager.exists(objectId)) { throwObjectDoesNotExist(objectIdString); } MCRBase retrievedMCRBase = MCRMetadataManager.retrieve(objectId); return collectionProvider.getContainerHandler().addResources((MCRObject) retrievedMCRBase, deposit); }
if (MCRMetadataManager.exists(derivateID)) { final MCRDerivate mcrDerivate = MCRMetadataManager.retrieveMCRDerivate(derivateID); try {
@Override public DepositReceipt replaceMetadataAndMediaResource(String editIRI, Deposit deposit, AuthCredentials authCredentials, SwordConfiguration swordConfiguration) throws SwordError, SwordServerException, SwordAuthException { IRI iri = new IRI(editIRI); String collection = MCRSwordUtil.ParseLinkUtil.EditIRI.getCollectionFromEditIRI(iri); String objectIdString = MCRSwordUtil.ParseLinkUtil.EditIRI.getObjectFromEditIRI(iri); final MCRSwordCollectionProvider collectionProvider = MCRSword.getCollection(collection); LOGGER.info(MessageFormat.format("REQUEST: Replace metadata and resource of {0} from {1} !", objectIdString, collection)); collectionProvider.getAuthHandler().authentication(authCredentials); MCRObjectID objectId = MCRObjectID.getInstance(objectIdString); if (!MCRMetadataManager.exists(objectId)) { throwObjectDoesNotExist(objectIdString); } MCRBase retrievedMCRBase = MCRMetadataManager.retrieve(objectId); return collectionProvider.getContainerHandler().replaceMetadataAndResources((MCRObject) retrievedMCRBase, deposit); }
@Override public void deleteContainer(String editIRI, AuthCredentials authCredentials, SwordConfiguration swordConfiguration) throws SwordError, SwordServerException, SwordAuthException { IRI iri = new IRI(editIRI); String collection = MCRSwordUtil.ParseLinkUtil.EditIRI.getCollectionFromEditIRI(iri); String objectIdString = MCRSwordUtil.ParseLinkUtil.EditIRI.getObjectFromEditIRI(iri); final MCRSwordCollectionProvider collectionProvider = MCRSword.getCollection(collection); LOGGER.info(MessageFormat.format("REQUEST: Delete {0} from {1}", objectIdString, collection)); collectionProvider.getAuthHandler().authentication(authCredentials); MCRObjectID objectId = MCRObjectID.getInstance(objectIdString); if (!MCRMetadataManager.exists(objectId)) { throwObjectDoesNotExist(objectIdString); } final MCRBase object = MCRMetadataManager.retrieve(objectId); checkIsObject(object); collectionProvider.getContainerHandler().deleteObject((MCRObject) object); }
@Override public DepositReceipt replaceMetadata(String editIRI, Deposit deposit, AuthCredentials authCredentials, SwordConfiguration swordConfiguration) throws SwordError, SwordServerException, SwordAuthException { IRI iri = new IRI(editIRI); String collection = MCRSwordUtil.ParseLinkUtil.EditIRI.getCollectionFromEditIRI(iri); String objectIdString = MCRSwordUtil.ParseLinkUtil.EditIRI.getObjectFromEditIRI(iri); final MCRSwordCollectionProvider collectionProvider = MCRSword.getCollection(collection); LOGGER.info(MessageFormat.format("REQUEST: Replace metadata of {0} from {1} !", objectIdString, collection)); collectionProvider.getAuthHandler().authentication(authCredentials); MCRObjectID objectId = MCRObjectID.getInstance(objectIdString); if (!MCRMetadataManager.exists(objectId)) { throwObjectDoesNotExist(objectIdString); } MCRBase retrievedMCRBase = MCRMetadataManager.retrieve(objectId); checkIsObject(retrievedMCRBase); return collectionProvider.getContainerHandler().replaceMetadata((MCRObject) retrievedMCRBase, deposit); }
@Override protected void handleObjectUpdated(final MCREvent evt, final MCRObject obj) { if (!MCRMODSWrapper.isSupported(obj)) { return; } handleObjectCreated(evt, obj); //may have to reindex children, if they inherit any information for (MCRMetaLinkID childLinkID : obj.getStructure().getChildren()) { MCRObjectID childID = childLinkID.getXLinkHrefID(); if (MCRMetadataManager.exists(childID)) { MCREvent childEvent = new MCREvent(childID.getTypeId(), MCREvent.INDEX_EVENT); childEvent.put("object", MCRMetadataManager.retrieve(childID)); MCREventManager.instance().handleEvent(childEvent); } } }