use of org.mycore.datamodel.metadata.MCRBase in project mycore by MyCoRe-Org.
the class MCRPURLJobRegistrationService method update.
@Override
protected void update(MCRPersistentUniformResourceLocator purl, MCRBase obj, String additional) throws MCRPersistentIdentifierException {
if (!hasRegistrationStarted(obj.getId(), additional)) {
Predicate<MCRBase> registrationCondition = getRegistrationCondition(obj.getId().getTypeId());
if (registrationCondition.test(obj)) {
this.updateStartRegistrationDate(obj.getId(), "", new Date());
startRegisterJob(obj, purl);
}
} else {
if (isRegistered(obj.getId(), "")) {
startUpdateJob(obj, purl);
}
}
}
use of org.mycore.datamodel.metadata.MCRBase in project mycore by MyCoRe-Org.
the class MCRPICommands method removeControlFromObject.
@MCRCommand(syntax = "remove control {0} with 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 = MCRPersistentIdentifierManager.getInstance().get(serviceID, objectIDString, additional != null ? additional.trim() : null);
MCRPersistentIdentifierManager.getInstance().delete(mcrpi.getMycoreID(), mcrpi.getAdditional(), mcrpi.getType(), mcrpi.getService());
MCRBase base = MCRMetadataManager.retrieve(objectID);
if (MCRPIRegistrationService.removeFlagFromObject(base, mcrpi) == null) {
throw new MCRPersistentIdentifierException("Could not delete Flag of object (flag not found)!");
}
MCRMetadataManager.update(base);
}
use of org.mycore.datamodel.metadata.MCRBase in project mycore by MyCoRe-Org.
the class MCRPICommands method controlObjectWithServiceAndAdditional.
@MCRCommand(syntax = "try to control {0} with service {1} with additional {2}", help = "This command tries to" + " read a pi from the object {0} with the MetadataManager from the specified service {1}." + " If the service configuration is right then the pi is under control of MyCoRe.")
public static void controlObjectWithServiceAndAdditional(String objectIDString, String serviceID, final String additional) throws MCRAccessException, MCRActiveLinkException, IOException {
String trimAdditional = additional.trim();
MCRPIRegistrationService<MCRPersistentIdentifier> service = MCRPIRegistrationServiceManager.getInstance().getRegistrationService(serviceID);
MCRPersistentIdentifierMetadataManager<MCRPersistentIdentifier> metadataManager = service.getMetadataManager();
MCRObjectID objectID = MCRObjectID.getInstance(objectIDString);
MCRBase mcrBase = MCRMetadataManager.retrieve(objectID);
Optional<MCRPersistentIdentifier> identifier;
try {
identifier = metadataManager.getIdentifier(mcrBase, trimAdditional);
} catch (MCRPersistentIdentifierException e) {
LOGGER.info("Could not detect any identifier with service {}", serviceID, e);
return;
}
if (!identifier.isPresent()) {
LOGGER.info("Could not detect any identifier with service {}", serviceID);
return;
}
MCRPersistentIdentifier persistentIdentifier = identifier.get();
if (service.isRegistered(objectID, trimAdditional)) {
LOGGER.info("Already present in Database: {}", serviceID);
return;
}
MCRPI mcrpi = service.insertIdentifierToDatabase(mcrBase, trimAdditional, persistentIdentifier);
MCRPIRegistrationService.addFlagToObject(mcrBase, mcrpi);
MCRMetadataManager.update(mcrBase);
LOGGER.info("{}:{} is now under control of {}", objectID, trimAdditional, serviceID);
}
use of org.mycore.datamodel.metadata.MCRBase in project mycore by MyCoRe-Org.
the class MCRIdentifierXSLUtils method getPIServiceInformation.
/**
* Gets all available services which are configured.
* e.g.
* <ul>
* <li><service id="service1" inscribed="false" permission="true" type="urn" /></li>
* <li><service id="service2" inscribed="true" permission="false" type="doi" /></li>
* </ul>
*
* @param objectID the object
* @return a Nodelist
* @throws JDOMException
*/
public static NodeList getPIServiceInformation(String objectID) throws JDOMException {
Element e = new Element("list");
MCRBase obj = MCRMetadataManager.retrieve(MCRObjectID.getInstance(objectID));
MCRConfiguration.instance().getPropertiesMap("MCR.PI.Registration.").keySet().stream().map(s -> s.substring("MCR.PI.Registration.".length())).filter(id -> !id.contains(".")).map((serviceID) -> MCRPIRegistrationServiceManager.getInstance().getRegistrationService(serviceID)).map((rs -> {
Element service = new Element("service");
service.setAttribute("id", rs.getRegistrationServiceID());
// Check if the inscriber of this service can read a PI
try {
if (rs.getMetadataManager().getIdentifier(obj, "").isPresent()) {
service.setAttribute("inscribed", "true");
} else {
service.setAttribute("inscribed", "false");
}
} catch (MCRPersistentIdentifierException e1) {
LOGGER.warn("Error happened while try to read PI from object: {}", objectID, e1);
service.setAttribute("inscribed", "false");
}
// rights
String permission = "register-" + rs.getRegistrationServiceID();
Boolean canRegister = MCRAccessManager.checkPermission(objectID, "writedb") && MCRAccessManager.checkPermission(obj.getId(), permission);
service.setAttribute("permission", canRegister.toString().toLowerCase(Locale.ROOT));
// add the type
service.setAttribute("type", rs.getType());
return service;
})).forEach(e::addContent);
return new DOMOutputter().output(e).getElementsByTagName("service");
}
use of org.mycore.datamodel.metadata.MCRBase in project mycore by MyCoRe-Org.
the class MCRSwordContainerManager method replaceMetadataAndMediaResource.
@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);
}
Aggregations