public static boolean hasFlag(MCRObjectID id, String additional, MCRPIRegistrationInfo mcrpi) { MCRBase obj = MCRMetadataManager.retrieve(id); return hasFlag(obj, additional, mcrpi); }
public static MCRObject getMcrObjectForDerivateID(String requestDerivateID) { final MCRObjectID objectID = MCRObjectID.getInstance(MCRXMLFunctions.getMCRObjectID(requestDerivateID)); return (MCRObject) MCRMetadataManager.retrieve(objectID); }
@MCRCommand(syntax = "add pi flags to all objects", help = "Should only be used if you used mycore-pi pre 2016 lts!") public static List<String> addFlagsToObjects() { return MCRPIManager.getInstance().getList().stream() .filter(registrationInfo -> { String mycoreID = registrationInfo.getMycoreID(); MCRObjectID objectID = MCRObjectID.getInstance(mycoreID); MCRBase base = MCRMetadataManager.retrieve(objectID); return !MCRPIService.hasFlag(base, registrationInfo.getAdditional(), registrationInfo); }) .map(MCRPIRegistrationInfo::getMycoreID) .distinct() .map(id -> "add pi flags to object " + id) .collect(Collectors.toList()); }
MCRBase object = MCRMetadataManager.retrieve(mycoreIDObject); try { identifier = registrationService.register(object, additional, true);
MCRBase mcrBase = MCRMetadataManager.retrieve(objectID); Optional<MCRPersistentIdentifier> identifier;
@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); } } }
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); } } }
public DepositReceipt addObject(Deposit deposit) throws SwordError, SwordServerException { final MCRSwordCollectionProvider collection = MCRSword .getCollection(this.lifecycleConfiguration.getCollection()); final MCRObjectID idOfIngested = collection.getIngester().ingestMetadata(deposit); final MCRObject createdObject = (MCRObject) MCRMetadataManager.retrieve(idOfIngested); return collection.getMetadataProvider().provideMetadata(createdObject); }
public DepositReceipt addObjectWithDerivate(String objectIdString, Deposit deposit) throws SwordError, SwordServerException { final MCRSwordCollectionProvider collection = MCRSword .getCollection(this.lifecycleConfiguration.getCollection()); final MCRObjectID idOfIngested = collection.getIngester().ingestMetadataResources(deposit); final MCRObject createdObject = (MCRObject) MCRMetadataManager.retrieve(idOfIngested); return collection.getMetadataProvider().provideMetadata(createdObject); }
@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); }
@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); }
@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); }
Element e = new Element("list"); MCRBase obj = MCRMetadataManager.retrieve(MCRObjectID.getInstance(objectID)); MCRPIServiceManager.getInstance().getServiceList() .stream()
@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); }
@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); } } }