use of org.mycore.datamodel.metadata.MCRObject in project mycore by MyCoRe-Org.
the class MCRTransferPackagePacker method build.
/**
* Builds the transfer package and returns it.
*
* @return the transfer package
* @throws MCRAccessException
*/
private MCRTransferPackage build() throws MCRAccessException {
MCRObject source = getSource();
MCRTransferPackage transferPackage = new MCRTransferPackage(source);
transferPackage.build();
return transferPackage;
}
use of org.mycore.datamodel.metadata.MCRObject in project mycore by MyCoRe-Org.
the class MCRTransferPackageUtil method importObjectCLI.
/**
* Same as {@link #importObject(Path, String)} but returns a list of derivates which
* should be imported afterwards.
*
* @param targetDirectory
* the directory where the *.tar was unpacked
* @param objectId
* object id to import
* @throws JDOMException
* coulnd't parse the import order xml
* @throws IOException
* when an I/O error prevents a document from being fully parsed
* @throws MCRActiveLinkException
* if object is created (no real update), see {@link MCRMetadataManager#create(MCRObject)}
* @throws MCRAccessException
* if write permission is missing or see {@link MCRMetadataManager#create(MCRObject)}
*/
public static List<String> importObjectCLI(Path targetDirectory, String objectId) throws JDOMException, IOException, MCRActiveLinkException, MCRAccessException {
SAXBuilder sax = new SAXBuilder();
Path targetXML = targetDirectory.resolve(CONTENT_DIRECTORY).resolve(objectId + ".xml");
if (LOGGER.isDebugEnabled()) {
LOGGER.debug(MessageFormat.format("Importing {0}", targetXML.toAbsolutePath().toString()));
}
Document objXML = sax.build(targetXML.toFile());
MCRObject mcr = new MCRObject(objXML);
mcr.setImportMode(true);
List<String> derivates = new LinkedList<>();
// one must copy the ids before updating the mcr objects
for (MCRMetaLinkID id : mcr.getStructure().getDerivates()) {
derivates.add(id.getXLinkHref());
}
// delete children & derivate -> will be added later
mcr.getStructure().clearChildren();
mcr.getStructure().clearDerivates();
// update
MCRMetadataManager.update(mcr);
// return list of derivates
return derivates;
}
use of org.mycore.datamodel.metadata.MCRObject in project mycore by MyCoRe-Org.
the class MCRDOICommands method synchronizeDatabase.
@MCRCommand(syntax = "repair registered dois {0}", help = "Contacts the Registration Service and inserts all registered DOIs to the Database. It also updates all media files. The Service ID{0} is the id from the configuration.", order = 10)
public static void synchronizeDatabase(String serviceID) {
MCRDOIRegistrationService registrationService = new MCRDOIRegistrationService(serviceID);
try {
MCRDataciteClient dataciteClient = registrationService.getDataciteClient();
List<MCRDigitalObjectIdentifier> doiList = dataciteClient.getDOIList();
doiList.stream().filter(doi -> {
boolean isTestDOI = doi.getPrefix().equals(MCRDigitalObjectIdentifier.TEST_DOI_PREFIX);
return !isTestDOI || registrationService.usesTestPrefix();
}).forEach(doi -> {
try {
URI uri = dataciteClient.resolveDOI(doi);
if (uri.toString().startsWith(registrationService.getRegisterURL())) {
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());
MCRPI databaseEntry = new MCRPI(doi.asString(), registrationService.getType(), objectID.toString(), "", serviceID, new Date());
MCRHIBConnection.instance().getSession().save(databaseEntry);
}
// Update main files
MCRObject obj = MCRMetadataManager.retrieveMCRObject(objectID);
List<Map.Entry<String, URI>> entryList = registrationService.getMediaList(obj);
dataciteClient.setMediaList(doi, entryList);
} else {
LOGGER.info("Could not find Object : {}", objectID);
}
} else {
LOGGER.info("DOI/URL is not from this application: {}/{}", doi.asString(), uri);
}
} catch (MCRPersistentIdentifierException e) {
LOGGER.error("Error occurred for DOI: {}", doi, e);
}
});
} catch (MCRPersistentIdentifierException e) {
LOGGER.error("Error while receiving DOI list from Registration-Service!", e);
}
}
use of org.mycore.datamodel.metadata.MCRObject in project mycore by MyCoRe-Org.
the class MCRPersistentIdentifierEventHandler method handleObjectRepaired.
@Override
protected void handleObjectRepaired(MCREvent evt, MCRObject obj) {
/* Add PIs to DB if they are not there */
MCRPersistentIdentifierManager.getInstance().getRegistered(obj).forEach(pi -> MCRPersistentIdentifierManager.getInstance().delete(pi.getMycoreID(), pi.getAdditional(), pi.getType(), pi.getService()));
Gson gson = new Gson();
obj.getService().getFlags(MCRPIRegistrationService.PI_FLAG).stream().map(piFlag -> gson.fromJson(piFlag, MCRPI.class)).filter(entry -> !MCRPersistentIdentifierManager.getInstance().exist(entry)).forEach(entry -> {
// TODO: disabled for MCR-1393
// entry.setMcrRevision(MCRCoreVersion.getRevision());
entry.setMcrVersion(MCRCoreVersion.getVersion());
entry.setMycoreID(obj.getId().toString());
LOGGER.info("Add PI : {} with service {} to database!", entry.getIdentifier(), entry.getService());
MCRHIBConnection.instance().getSession().save(entry);
});
handleObjectUpdated(evt, obj);
}
use of org.mycore.datamodel.metadata.MCRObject in project mycore by MyCoRe-Org.
the class MCRDOIRegistrationService method registerJob.
@Override
public void registerJob(Map<String, String> parameters) throws MCRPersistentIdentifierException {
MCRDigitalObjectIdentifier doi = getDOIFromJob(parameters);
String idString = parameters.get(CONTEXT_OBJ);
MCRObjectID objectID = MCRObjectID.getInstance(idString);
this.validateJobUserRights(objectID);
MCRObject object = MCRMetadataManager.retrieveMCRObject(objectID);
MCRObject mcrBase = MCRMetadataManager.retrieveMCRObject(objectID);
Document dataciteDocument = transformToDatacite(doi, mcrBase);
MCRDataciteClient dataciteClient = getDataciteClient();
dataciteClient.storeMetadata(dataciteDocument);
URI registeredURI;
try {
registeredURI = getRegisteredURI(object);
dataciteClient.mintDOI(doi, registeredURI);
} catch (URISyntaxException e) {
throw new MCRException("Base-URL seems to be invalid!", e);
}
List<Map.Entry<String, URI>> entryList = getMediaList((MCRObject) object);
dataciteClient.setMediaList(doi, entryList);
this.updateRegistrationDate(objectID, "", new Date());
}
Aggregations