use of org.mycore.datamodel.ifs2.MCRVersionedMetadata in project mycore by MyCoRe-Org.
the class MCRMetadataHistoryCommands method buildDerivateHistory.
private static Stream<MCRMetaHistoryItem> buildDerivateHistory(MCRObjectID derId) {
try {
List<MCRMetadataVersion> versions = Collections.emptyList();
MCRMetadataStore store = MCRXMLMetadataManager.instance().getStore(derId);
if (store instanceof MCRVersioningMetadataStore) {
MCRVersionedMetadata versionedMetadata = ((MCRVersioningMetadataStore) store).retrieve(derId.getNumberAsInteger());
versions = versionedMetadata.listVersions();
}
if (versions.isEmpty()) {
return buildSimpleDerivateHistory(derId);
} else {
return buildDerivateHistory(derId, versions);
}
} catch (IOException e) {
LogManager.getLogger().error("Error while getting history of {}", derId);
return Stream.empty();
}
}
use of org.mycore.datamodel.ifs2.MCRVersionedMetadata in project mycore by MyCoRe-Org.
the class MCRXMLMetadataManagerTest method retrieve.
@Test
public void retrieve() throws JDOMException, IOException, SAXException {
assertEquals("Stored document ID do not match:", MyCoRe_document_00000001.id.toString(), SAX_BUILDER.build(new ByteArrayInputStream(MyCoRe_document_00000001.blob)).getRootElement().getAttributeValue("id"));
getStore().create(MyCoRe_document_00000001.id, new MCRByteContent(MyCoRe_document_00000001.blob, MCR_document_00000001.lastModified.getTime()), MyCoRe_document_00000001.lastModified);
MCRVersionedMetadata data = getStore().getVersionedMetaData(MyCoRe_document_00000001.id);
assertFalse(data.isDeleted());
assertFalse(data.isDeletedInRepository());
Document doc = getStore().retrieveXML(MyCoRe_document_00000001.id);
assertEquals("Stored document ID do not match:", MyCoRe_document_00000001.id.toString(), doc.getRootElement().getAttributeValue("id"));
try {
doc = getStore().retrieveXML(MCR_document_00000001.id);
if (doc != null) {
fail("Requested " + MCR_document_00000001.id + ", retrieved wrong document:\n" + new XMLOutputter(Format.getPrettyFormat()).outputString(doc));
}
} catch (Exception e) {
// this is ok
}
}
use of org.mycore.datamodel.ifs2.MCRVersionedMetadata in project mycore by MyCoRe-Org.
the class MCRMigrationCommands method addServFlags.
@MCRCommand(syntax = "migrate author servflags for {0}", help = "Create missing servflags for createdby and modifiedby for object {0}. (MCR-786)", order = 10)
public static void addServFlags(String id) throws IOException, MCRPersistenceException, MCRActiveLinkException, MCRAccessException {
MCRObjectID objectID = MCRObjectID.getInstance(id);
MCRBase obj = MCRMetadataManager.retrieve(objectID);
MCRObjectService service = obj.getService();
if (!service.isFlagTypeSet(MCRObjectService.FLAG_TYPE_CREATEDBY)) {
// the egg
MCRVersionedMetadata versionedMetadata = MCRXMLMetadataManager.instance().getVersionedMetaData(objectID);
String createUser = null, modifyUser = null;
if (versionedMetadata == null) {
LOGGER.warn("Cannot restore author servflags as there are no versions available. Setting to current user.");
createUser = MCRSessionMgr.getCurrentSession().getUserInformation().getUserID();
modifyUser = createUser;
} else {
List<MCRMetadataVersion> versions = versionedMetadata.listVersions();
MCRMetadataVersion firstVersion = versions.get(0);
for (MCRMetadataVersion version : versions) {
if (version.getType() == 'A') {
// get last 'added'
firstVersion = version;
}
}
MCRMetadataVersion lastVersion = versions.get(versions.size() - 1);
createUser = firstVersion.getUser();
modifyUser = lastVersion.getUser();
}
service.addFlag(MCRObjectService.FLAG_TYPE_CREATEDBY, createUser);
LOGGER.info("{}, created by: {}", objectID, createUser);
if (!service.isFlagTypeSet(MCRObjectService.FLAG_TYPE_MODIFIEDBY)) {
// the chicken
// have to restore also modifiedby from version history.
LOGGER.info("{}, modified by: {}", objectID, modifyUser);
service.addFlag(MCRObjectService.FLAG_TYPE_CREATEDBY, modifyUser);
}
obj.setImportMode(true);
if (obj instanceof MCRDerivate) {
MCRMetadataManager.updateMCRDerivateXML((MCRDerivate) obj);
} else {
MCRMetadataManager.update((MCRObject) obj);
}
}
}
use of org.mycore.datamodel.ifs2.MCRVersionedMetadata in project mycore by MyCoRe-Org.
the class MCRMetadataHistoryCommands method buildObjectHistory.
private static Stream<MCRMetaHistoryItem> buildObjectHistory(MCRObjectID objId) {
try {
List<MCRMetadataVersion> versions = Collections.emptyList();
MCRMetadataStore store = MCRXMLMetadataManager.instance().getStore(objId);
if (store instanceof MCRVersioningMetadataStore) {
MCRVersionedMetadata versionedMetadata = ((MCRVersioningMetadataStore) store).retrieve(objId.getNumberAsInteger());
versions = versionedMetadata.listVersions();
}
if (versions.isEmpty()) {
return buildSimpleObjectHistory(objId);
} else {
return buildObjectHistory(objId, versions);
}
} catch (IOException e) {
LogManager.getLogger().error("Error while getting history of {}", objId);
return Stream.empty();
}
}
use of org.mycore.datamodel.ifs2.MCRVersionedMetadata in project mycore by MyCoRe-Org.
the class MCRXMLMetadataManager method getVersionedMetaData.
public MCRVersionedMetadata getVersionedMetaData(MCRObjectID id) throws IOException {
if (id == null) {
return null;
}
MCRMetadataStore metadataStore = getStore(id);
if (!(metadataStore instanceof MCRVersioningMetadataStore)) {
return null;
}
MCRVersioningMetadataStore verStore = (MCRVersioningMetadataStore) metadataStore;
return verStore.retrieve(id.getNumberAsInteger());
}
Aggregations