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); } }
/** * 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); } } }
MCRMetadataManager.update(deriv); } catch (MCRPersistenceException | MCRAccessException e) { LOGGER.error("Error while updating derivate {}", derivID, e);
@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); } } }
MCRMetadataManager.update(mcrBase); LOGGER.info("{}:{} is now under control of {}", objectID, trimAdditional, serviceID);
public void updateFlag(MCRObjectID id, String additional, MCRPI mcrpi) { MCRBase obj = MCRMetadataManager.retrieve(id); MCRObjectService service = obj.getService(); ArrayList<String> flags = service.getFlags(MCRPIService.PI_FLAG); Gson gson = getGson(); String stringFlag = flags.stream().filter(_stringFlag -> { MCRPI flag = gson.fromJson(_stringFlag, MCRPI.class); return flag.getAdditional().equals(additional) && flag.getIdentifier().equals(mcrpi.getIdentifier()); }).findAny().orElseThrow(() -> new MCRException(new MCRPersistentIdentifierException( "Could find flag to update (" + id + "," + additional + "," + mcrpi.getIdentifier() + ")"))); int flagIndex = service.getFlagIndex(stringFlag); service.removeFlag(flagIndex); addFlagToObject(obj, mcrpi); try { MCRMetadataManager.update(obj); } catch (Exception e) { throw new MCRException("Could not update flags of object " + id, e); } } }
mcrObject.getService().setDate(flagType, new Date()); try { MCRMetadataManager.update(mcrObject); } catch (MCRAccessException e) { throw new ExecutionException("Could not set " + flagType + " flag!", e);
@Override public MCRDNBURN register(MCRBase obj, String additional, boolean updateObject) throws MCRAccessException, MCRActiveLinkException, MCRPersistentIdentifierException { this.validateRegistration(obj, additional); MCRObjectDerivate derivate = ((MCRDerivate) obj).getDerivate(); MCRDNBURN newURN; if (additional.equals("")) { /* Multiple URN for entire Derivate... */ newURN = registerURNsDerivate(obj, additional, derivate); } else { /* Single URN to one File... */ newURN = registerSingleURN(obj, additional, derivate); } try { MCRMetadataManager.update(obj); } catch (Exception e) { throw new MCRPersistentIdentifierException("Error while updating derivate " + obj.getId(), e); } return newURN; }
MCRMetadataManager.update(der); Files.walkFileTree(derDir, MCRRecursiveDeleter.instance()); } catch (IOException | MCRPersistenceException | MCRAccessException e) {
MCRMetadataManager.update(updatedObject); return Response.status(Response.Status.NO_CONTENT).build(); } else {
LOGGER.info("Object doesn't have Identifier inscribed! Insert it.."); synchronizer.insertIdentifier(doi, mcrObject, ""); MCRMetadataManager.update(mcrObject);
MCRMetadataManager.update(derivate); return Response.status(Response.Status.NO_CONTENT).build();
@MCRCommand(syntax = "remove control {0} with pi service {1} with additional {2}", help = "This commands removes the " + "pi control from the object {0}(object id) with the serivce {1}(service id) and the additional {2}") public static void removeControlFromObject(String objectIDString, String serviceID, String additional) throws MCRAccessException, MCRActiveLinkException, MCRPersistentIdentifierException { MCRObjectID objectID = MCRObjectID.getInstance(objectIDString); MCRPI mcrpi = MCRPIManager.getInstance() .get(serviceID, objectIDString, additional != null ? additional.trim() : null); MCRPIManager.getInstance() .delete(mcrpi.getMycoreID(), mcrpi.getAdditional(), mcrpi.getType(), mcrpi.getService()); MCRBase base = MCRMetadataManager.retrieve(objectID); if (MCRPIService.removeFlagFromObject(base, mcrpi) == null) { throw new MCRPersistentIdentifierException("Could not delete Flag of object (flag not found)!"); } MCRMetadataManager.update(base); }
LOGGER.info("Saving: {}", childIdRef); try { MCRMetadataManager.update(child); } catch (MCRPersistenceException | MCRAccessException e) { throw new MCRPersistenceException("Error while updating inherited metadata", e); LOGGER.info("Saving: {}", recipientId); try { MCRMetadataManager.update(recipient); } catch (MCRPersistenceException | MCRAccessException e) { throw new MCRPersistenceException("Error while updating shared metadata", e);
@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()); } }