use of org.mycore.datamodel.metadata.MCRBase in project mycore by MyCoRe-Org.
the class MCRPIRegistrationService method updateFlag.
public void updateFlag(MCRObjectID id, String additional, MCRPI mcrpi) {
MCRBase obj = MCRMetadataManager.retrieve(id);
MCRObjectService service = obj.getService();
ArrayList<String> flags = service.getFlags(MCRPIRegistrationService.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);
}
}
use of org.mycore.datamodel.metadata.MCRBase in project mycore by MyCoRe-Org.
the class MCRPICommands method addFlagsToObjects.
@MCRCommand(syntax = "add PI Flags to objects", help = "Should only be used if you used mycore-pi pre 2016 lts!")
public static void addFlagsToObjects() {
MCRPersistentIdentifierManager.getInstance().getList().forEach(registrationInfo -> {
if (registrationInfo.getMcrRevision() <= 35726) {
String mycoreID = registrationInfo.getMycoreID();
MCRObjectID objectID = MCRObjectID.getInstance(mycoreID);
MCRBase base = MCRMetadataManager.retrieve(objectID);
LOGGER.info("Add PI-Flag to {}", mycoreID);
MCRPIRegistrationService.addFlagToObject(base, (MCRPI) registrationInfo);
try {
MCRMetadataManager.update(base);
} catch (Exception e) {
throw new MCRException(e);
}
}
});
}
use of org.mycore.datamodel.metadata.MCRBase in project mycore by MyCoRe-Org.
the class MCRURNObjectXPathMetadataManager method insertIdentifier.
@Override
public void insertIdentifier(MCRDNBURN identifier, MCRBase obj, String additional) throws MCRPersistentIdentifierException {
String xpath = getProperties().get("Xpath");
Document xml = obj.createXML();
MCRNodeBuilder nb = new MCRNodeBuilder();
try {
nb.buildElement(xpath, identifier.asString(), xml);
MCRBase object = new MCRObject(xml);
MCRMetadataManager.update(object);
} catch (Exception e) {
throw new MCRException("Error while inscribing URN to " + obj.getId(), e);
}
}
Aggregations