use of org.mycore.datamodel.ifs2.MCRMetadataStore in project mycore by MyCoRe-Org.
the class MCRMetadataHistoryCommands method buildHistory.
@MCRCommand(syntax = "build metadata history of base {0}", help = "build metadata history of all objects with base id {0}")
public static List<String> buildHistory(String baseId) {
MCRMetadataStore store = MCRXMLMetadataManager.instance().getStore(baseId);
if (store instanceof MCRVersioningMetadataStore) {
LogManager.getLogger().info("Verify SVN history of {}", baseId);
((MCRVersioningMetadataStore) store).verify();
}
ExecutorService executorService = Executors.newWorkStealingPool();
MCRSession currentSession = MCRSessionMgr.getCurrentSession();
int maxId = store.getHighestStoredID();
AtomicInteger completed = new AtomicInteger(maxId);
IntStream.rangeClosed(1, maxId).parallel().mapToObj(i -> MCRObjectID.formatID(baseId, i)).map(MCRObjectID::getInstance).map(id -> new MCRTransactionableCallable<>(Executors.callable(() -> {
EntityManager em = MCREntityManagerProvider.getCurrentEntityManager();
getHistoryItems(id).sequential().forEach(em::persist);
completed.decrementAndGet();
}), currentSession)).forEach(executorService::submit);
executorService.shutdown();
boolean waitToFinish = true;
while (!executorService.isTerminated() && waitToFinish) {
LogManager.getLogger().info("Waiting for history of {} objects/derivates.", completed.get());
try {
executorService.awaitTermination(10, TimeUnit.SECONDS);
} catch (InterruptedException e) {
waitToFinish = false;
}
}
return Collections.emptyList();
}
use of org.mycore.datamodel.ifs2.MCRMetadataStore 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.MCRMetadataStore 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());
}
use of org.mycore.datamodel.ifs2.MCRMetadataStore in project mycore by MyCoRe-Org.
the class MCRXMLMetadataManager method listIDsForBase.
/**
* Lists all MCRObjectIDs stored for the given base, which is {project}_{type}
*
* @param base the MCRObjectID base, e.g. DocPortal_document
*/
public List<String> listIDsForBase(String base) {
MCRMetadataStore store = getStore(base);
List<String> list = new ArrayList<>();
Iterator<Integer> it = store.listIDs(MCRStore.ASCENDING);
String[] idParts = MCRObjectID.getIDParts(base);
while (it.hasNext()) {
list.add(MCRObjectID.formatID(idParts[0], idParts[1], it.next()));
}
return list;
}
Aggregations