MCRMetadataManager.getDerivateIds(parentObjId, 0, TimeUnit.SECONDS) .stream() .map(MCRObjectID::toString) MCRObject mcrObj = MCRMetadataManager.retrieveMCRObject(parentObjId); for (MCRMetaLinkID check : mcrObj.getStructure().getDerivates()) { if (derIDString.equals(check.getXLinkLabel()) || derIDString.equals(check.getXLinkTitle())) { 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)); return MCRMetadataManager.retrieveMCRDerivate(derID);
private MCRObject handleFeedEntry(SyndEntry entry, String projectID) throws MCRPersistenceException, MCRAccessException { String publicationID = getPublicationID(entry); if (publicationID == null) { return null; } if (isAlreadyStored(publicationID)) { LOGGER.info("publication with ID {} already existing, will not import.", publicationID); return null; } LOGGER.info("publication with ID {} does not exist yet, retrieving data...", publicationID); Element publicationXML = retrieveAndConvertPublication(publicationID); if (shouldIgnore(publicationXML)) { LOGGER.info("publication will be ignored, do not store."); return null; } MCRObject obj = buildMCRObject(publicationXML, projectID); MCRMetadataManager.create(obj); return obj; }
return; MCRDerivate derivate = MCRMetadataManager.retrieveMCRDerivate(derivateID); String urn = derivate.getDerivate().getURN(); if (urn == null) { MCRObject object = MCRMetadataManager.retrieveMCRObject(objectID); boolean objNeedsUpdate = setURN(object, urn); if (objNeedsUpdate) { LOGGER.info("Updating object {} ...", objectID); MCRMetadataManager.update(object); MCRMetadataManager.update(derivate);
private void releaseDocument(MCRObjectID objectID) { try { LOGGER.info("Release object {}", objectID); final MCRObject object = MCRMetadataManager.retrieveMCRObject(objectID); final MCRMODSWrapper modsWrapper = new MCRMODSWrapper(object); final String embargoXPATH = "mods:accessCondition[@type='embargo']"; Optional<Element> element = Optional.ofNullable(modsWrapper.getElement(embargoXPATH)); if (element.isPresent()) { element.get().setAttribute("type", "expiredEmbargo"); MCRMetadataManager.update(object); } } catch (MCRAccessException e) { LOGGER.error("Error while releasing embargo document!", e); } }
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); } }
@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(); } }
@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); }
/** * Returns the work originating from the given local object, if any. * This is done by comparing the ID and all mods:identifier elements given in the MyCoRe MODS object * with the identifiers given in the ORCID work. */ public Optional<MCRWork> findWork(MCRObjectID oid) { MCRObject obj = MCRMetadataManager.retrieveMCRObject(oid); return findWork(obj); }
if (MCRMetadataManager.exists(objectID)) { MCRObject obj = MCRMetadataManager.retrieveMCRObject(objectID); List<Map.Entry<String, URI>> newMediaList = registrationService.getMediaList(obj);
if (!MCRMetadataManager.exists(objectID)) { LOGGER.info("Could not find Object : {}", objectID); return; MCRObject mcrObject = MCRMetadataManager.retrieveMCRObject(objectID); MCRPIMetadataService<MCRDigitalObjectIdentifier> synchronizer = registrationService .getMetadataService(); LOGGER.info("Object doesn't have Identifier inscribed! Insert it.."); synchronizer.insertIdentifier(doi, mcrObject, ""); MCRMetadataManager.update(mcrObject);
MCRObject mcrObject = MCRMetadataManager.retrieveMCRObject(objectID); List<MCRObjectID> derivateIds = MCRMetadataManager.getDerivateIds(objectID, 10, TimeUnit.SECONDS); final String zipFileName = ppn + ".zip"; openZip(zipFileSystem -> { mcrObject.getService().setDate(flagType, new Date()); try { MCRMetadataManager.update(mcrObject); } catch (MCRAccessException e) { throw new ExecutionException("Could not set " + flagType + " flag!", e);
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; }
if (MCRMetadataManager.exists(derivateID)) { final MCRDerivate mcrDerivate = MCRMetadataManager.retrieveMCRDerivate(derivateID); try { MCRMetadataManager.delete(mcrDerivate); } catch (MCRAccessException e) { throw new SwordError(UriRegistry.ERROR_METHOD_NOT_ALLOWED, e);
/** * Builds a list with with right content types and media urls assigned of a specific Object * * @param obj the object * @return a list of entrys Media-Type, URL */ public List<Map.Entry<String, URI>> getMediaList(MCRObject obj) { List<Map.Entry<String, URI>> entryList = new ArrayList<>(); Optional<MCRObjectID> derivateIdOptional = MCRMetadataManager.getDerivateIds(obj.getId(), 1, TimeUnit.MINUTES) .stream().findFirst(); derivateIdOptional.ifPresent(derivateId -> { MCRDerivate derivate = MCRMetadataManager.retrieveMCRDerivate(derivateId); String mainDoc = derivate.getDerivate().getInternals().getMainDoc(); MCRPath mainDocumentPath = MCRPath.getPath(derivateId.toString(), mainDoc); try { String contentType = Optional.ofNullable(MCRContentTypes.probeContentType(mainDocumentPath)) .orElse("application/octet-stream"); entryList.add(new AbstractMap.SimpleEntry<>(contentType, new URI(this.registerURL + MCRXMLFunctions .encodeURIPath("/servlets/MCRFileNodeServlet/" + derivateId + "/" + mainDoc)))); } catch (IOException | URISyntaxException e) { LOGGER.error("Error while detecting the file to register!", e); } }); return entryList; }
@MCRCommand(syntax = "add pi flags to object {0}", help = "see add pi flags to all objects!") public static void addFlagToObject(String mycoreIDString) { MCRObjectID objectID = MCRObjectID.getInstance(mycoreIDString); MCRBase base = MCRMetadataManager.retrieve(objectID); final List<MCRPIRegistrationInfo> pi = MCRPIManager.getInstance().getRegistered(base); final boolean addedAFlag = pi.stream().filter(registrationInfo -> { if (!MCRPIService.hasFlag(base, registrationInfo.getAdditional(), registrationInfo)) { LOGGER.info("Add PI-Flag to " + mycoreIDString); MCRPIService.addFlagToObject(base, (MCRPI) registrationInfo); return true; } return false; }).count()>0; if(addedAFlag){ try { MCRMetadataManager.update(base); } catch (MCRAccessException e) { throw new MCRException(e); } } }
MCRObject mcrObj = MCRMetadataManager.retrieveMCRObject(mcrObjIDObj); MCRObjectID derID = null; if (overwriteOnExistingLabel) { .setInternals(new MCRMetaIFS("internal", UPLOAD_DIR.resolve(derID.toString()).toString())); MCRMetadataManager.create(mcrDerivate); MCRMetadataManager.addOrUpdateDerivateToObject(mcrObjIDObj, new MCRMetaLinkID("derobject", derID, null, label));
public static URL getDFGViewerURL(MCRPIRegistrationInfo urn) { URL url = null; try { MCRObjectID derivateId = MCRObjectID.getInstance(urn.getMycoreID()); MCRDerivate derivate = MCRMetadataManager.retrieveMCRDerivate(derivateId); String mainDoc = Optional.ofNullable(derivate.getDerivate()) .map(MCRObjectDerivate::getInternals) .map(MCRMetaIFS::getMainDoc) .orElseThrow(() -> new RuntimeException( "Could not get main doc for " + derivateId)); String spec = null; String baseURL = MCRFrontendUtil.getBaseURL(); String id = URLEncoder.encode(derivateId.toString(), "UTF-8"); if (mainDoc != null && mainDoc.length() > 0) { String mainDocEnc = URLEncoder.encode(mainDoc, "UTF-8"); spec = MessageFormat .format(baseURL + "servlets/MCRDFGLinkServlet?deriv={0}&file={1}", id, mainDocEnc); } else { spec = baseURL + "servlets/MCRDFGLinkServlet?deriv=" + id; } LOGGER.debug("Generated URL for urn {} is {}", urn.getIdentifier(), spec); url = new URL(spec); } catch (UnsupportedEncodingException | MalformedURLException e) { LOGGER.error("Could not create dfg viewer url", e); } return url; }
/** * Sets a main file if not present. * @param derivateID the id of the derivate */ private static void setDefaultMainFile(String derivateID) { MCRPath path = MCRPath.getPath(derivateID, "/"); try { MCRFileCollectingFileVisitor<Path> visitor = new MCRFileCollectingFileVisitor<>(); Files.walkFileTree(path, visitor); MCRDerivate derivate = MCRMetadataManager.retrieveMCRDerivate(MCRObjectID.getInstance(derivateID)); visitor.getPaths().stream() .map(MCRPath.class::cast) .filter(p -> !p.getOwnerRelativePath().endsWith(".xml")) .findFirst() .ifPresent(file -> { derivate.getDerivate().getInternals().setMainDoc(file.getOwnerRelativePath()); try { MCRMetadataManager.update(derivate); } catch (MCRPersistenceException | MCRAccessException e) { LOGGER.error("Could not set main file!", e); } }); } catch (IOException e) { LOGGER.error("Could not set main file!", e); } } }
@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(); }