Skip to content

Commit

Permalink
#464 Fixed compile errors and removed usage of deprecated api
Browse files Browse the repository at this point in the history
  • Loading branch information
Possommi committed Aug 13, 2024
1 parent 0f9948a commit 1908b26
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 61 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ public static List<String> updateFunding(String url) {
String id = doc.get("id").toString();
String fundings = getFundings(publication).stream()
.map(MCRCategory::getId)
.map(MCRCategoryID::getID)
.map(MCRCategoryID::getId)
.map(n -> String.valueOf(n))
.collect(Collectors.joining(ThUniBibCommands.FUNDING_SEPARATOR_CHAR));

Expand Down Expand Up @@ -429,7 +429,7 @@ public static List<MCRUser> listVanishedLDAPUsers(String realm) {
return null;
}

List<MCRUser> users = MCRUserManager.listUsers(null, realm, null);
List<MCRUser> users = MCRUserManager.listUsers(null, realm, null, null);
if (users.size() == 0) {
LOGGER.info("No users found for realm '{}'", realm);
return users;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@
import org.mycore.mods.enrichment.MCREnrichmentResolver;
import org.mycore.services.queuedjob.MCRJob;
import org.mycore.services.queuedjob.MCRJobQueue;
import org.mycore.services.queuedjob.MCRJobQueueManager;
import org.mycore.solr.MCRSolrClientFactory;
import org.mycore.solr.MCRSolrUtils;
import org.xml.sax.InputSource;
Expand Down Expand Up @@ -118,7 +119,7 @@ public static void schedule(String q, String filter) {
job.setParameter("query", q);
job.setParameter("status", "imported");
job.setParameter("filter", filter);
MCRJobQueue.getInstance(ThUniBibImportJobAction.class).offer(job);
MCRJobQueueManager.getInstance().getJobQueue(ThUniBibImportJobAction.class).offer(job);
}

@MCRCommand(syntax = PICA_IMPORT_SYNTAX_WITH_KEY, help = "imports all objects for a specific query", order = 5)
Expand Down Expand Up @@ -457,7 +458,7 @@ private static List<String> getAllGNDsOfAffiliatedPersons(String affiliationGND)
}

private static MCRObjectID nextFreeID() {
return MCRObjectID.getNextFreeId(projectID, "mods");
return MCRMetadataManager.getMCRObjectIDGenerator().getNextFreeId(projectID, "mods");
}

private static MCRObject createOrUpdate(MCRMODSWrapper wrappedMCRobj, String import_status) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,5 @@
package de.uni_jena.thunibib.impex;

import java.net.ConnectException;
import java.net.SocketTimeoutException;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
import java.util.UUID;
import java.util.Vector;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.atomic.AtomicInteger;

import de.uni_jena.thunibib.ThUniBibMailer;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
Expand All @@ -26,20 +16,20 @@
import org.mycore.datamodel.metadata.MCRObject;
import org.mycore.services.queuedjob.MCRJob;
import org.mycore.services.queuedjob.MCRJobAction;
import org.mycore.services.queuedjob.MCRJobQueue;
import org.mycore.services.queuedjob.MCRJobStatus;

import static org.mycore.common.MCRConstants.XPATH_FACTORY;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
import java.util.concurrent.ExecutionException;

import static org.mycore.common.MCRConstants.*;

public class ThUniBibImportJobAction extends MCRJobAction {

protected static final Logger LOGGER = LogManager.getLogger(ThUniBibImportJobAction.class);
protected static final String SRU_CATALOG = MCRConfiguration2.getString("MCR.PICA2MODS.DATABASE").orElse("gvk");
protected static final int BATCH_SIZE = 10;

public ThUniBibImportJobAction() {
}

public ThUniBibImportJobAction(MCRJob job) {
super(job);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,10 @@
import org.mycore.mods.enrichment.MCREnrichmentResolver;
import org.mycore.oai.pmh.CannotDisseminateFormatException;
import org.mycore.oai.pmh.IdDoesNotExistException;
import org.mycore.solr.MCRSolrClientFactory;
import org.mycore.solr.search.MCRSolrSearchUtils;
import org.mycore.oai.pmh.harvester.Harvester;
import org.mycore.oai.pmh.harvester.HarvesterBuilder;
import org.mycore.solr.MCRSolrClientFactory;
import org.mycore.solr.search.MCRSolrSearchUtils;

import java.io.IOException;
import java.nio.charset.StandardCharsets;
Expand All @@ -41,7 +41,6 @@
import java.util.List;
import java.util.Optional;


@MCRCommandGroup(name = "experimental DBT import commands")
public class EnrichmentCommands extends MCRAbstractCommands {

Expand All @@ -53,43 +52,45 @@ public class EnrichmentCommands extends MCRAbstractCommands {
private static final Date EARLY_DATE = new Date(1);

@MCRCommand(syntax = "test import dbt with status {0}",
help = "test DBT import of mods from OAI, imported documents get status one of 'confirmed', " +
"'submitted', 'imported'",
order = 10
help = "test DBT import of mods from OAI, imported documents get status one of 'confirmed', " +
"'submitted', 'imported'",
order = 10
)
public static void testWithStatus(String import_status) {
final List<String> allowedStatus = Arrays.asList(new String[]{"confirmed", "submitted", "imported"});
if(allowedStatus.contains(import_status)) {
final List<String> allowedStatus = Arrays.asList(new String[] { "confirmed", "submitted", "imported" });
if (allowedStatus.contains(import_status)) {
testSub(import_status);
} else {
LOGGER.info("Status not allowed: {}, use one of {}", import_status, String.join(", ", allowedStatus));
}
}

@MCRCommand(syntax = "test import dbt",
help = "tests DBT import of mods from OAI",
order = 20)
help = "tests DBT import of mods from OAI",
order = 20)
public static void test() throws IdDoesNotExistException, CannotDisseminateFormatException {
testSub("imported");
}

@MCRCommand(syntax = "test single import dbt with status {0} and oai identifier {1}",
help = "test DBT import of single mods document from OAI, imported documents get status one of " +
"'confirmed', 'submitted', 'imported'; OAI Identifier typically has the following format: " +
"oai:www.db-thueringen.de:dbt_mods_00012345 (thueringen)",
order = 30
help = "test DBT import of single mods document from OAI, imported documents get status one of " +
"'confirmed', 'submitted', 'imported'; OAI Identifier typically has the following format: " +
"oai:www.db-thueringen.de:dbt_mods_00012345 (thueringen)",
order = 30
)
public static void testSingleWithStatus(String import_status, String oai_identifier) {
try {
Harvester harvester = HarvesterBuilder.createNewInstance("https://www.db-thueringen.de/servlets/OAIDataProvider");
Harvester harvester = HarvesterBuilder.createNewInstance(
"https://www.db-thueringen.de/servlets/OAIDataProvider");

OAIRecord oaiRecord = new OAIRecord(harvester.getRecord(oai_identifier, "mods"));
MCRMODSWrapper wrappedObj = createMinimalMods(oaiRecord);
new MCREnrichmentResolver().enrichPublication(wrappedObj.getMODS(), "import");
if(filterObject(wrappedObj)) {
if (filterObject(wrappedObj)) {
wrappedObj = mapToObject(wrappedObj);
createOrUpdate(wrappedObj, import_status);
LOGGER.info(new XMLOutputter(Format.getPrettyFormat()).outputString(wrappedObj.getMCRObject().createXML()));
LOGGER.info(
new XMLOutputter(Format.getPrettyFormat()).outputString(wrappedObj.getMCRObject().createXML()));
}
} catch (CannotDisseminateFormatException e) {
e.printStackTrace();
Expand All @@ -98,7 +99,6 @@ public static void testSingleWithStatus(String import_status, String oai_identif
}
}


private static MCRMODSWrapper createMinimalMods(OAIRecord oaiRecord) {
LOGGER.info("Start createMinimalMods");
String recordID = oaiRecord.getRecord().getHeader().getId();
Expand Down Expand Up @@ -127,29 +127,29 @@ public static void testSub(String import_status) {
Date lastHarvest = getLastHarvestDate();
final Date newHarvest = new Date();

if(lastHarvest.before(newHarvest)) {
if (lastHarvest.before(newHarvest)) {
final RecordTransformer recordTransformer = new RecordTransformer(
"https://www.db-thueringen.de/servlets/OAIDataProvider",
"mods",
"institute:1");
"https://www.db-thueringen.de/servlets/OAIDataProvider",
"mods",
"institute:1");

recordTransformer.getAll(lastHarvest, null)
.map(EnrichmentCommands::createMinimalMods)
.map(obj -> {
new MCREnrichmentResolver().enrichPublication(obj.getMODS(), "import");
return obj;
})
.filter(obj -> filterObject(obj))
.map(EnrichmentCommands::mapToObject)
.forEach(obj -> EnrichmentCommands.createOrUpdate(obj, import_status));
.map(EnrichmentCommands::createMinimalMods)
.map(obj -> {
new MCREnrichmentResolver().enrichPublication(obj.getMODS(), "import");
return obj;
})
.filter(obj -> filterObject(obj))
.map(EnrichmentCommands::mapToObject)
.forEach(obj -> EnrichmentCommands.createOrUpdate(obj, import_status));

saveLastHarvestDate(newHarvest);
}
}

private static boolean filterObject(MCRMODSWrapper wrappedMCRObj) {
boolean goesTroughFilter = true;
final List<String> filteredGenres = Arrays.asList(new String[]{"video", "audio", "picture", "broadcasting"});
final List<String> filteredGenres = Arrays.asList(new String[] { "video", "audio", "picture", "broadcasting" });

String mcrID = wrappedMCRObj.getMCRObject().getId().toString();
Element modsRootElement = wrappedMCRObj.getMODS();
Expand All @@ -158,11 +158,11 @@ private static boolean filterObject(MCRMODSWrapper wrappedMCRObj) {
LOGGER.info("Deciding whether to filter: {}", mcrID);

final XPathExpression<Element> xpath = XPathFactory.instance()
.compile("mods:genre",
Filters.element(), null, MCRConstants.MODS_NAMESPACE);
.compile("mods:genre",
Filters.element(), null, MCRConstants.MODS_NAMESPACE);
final Element genreElem = xpath.evaluateFirst(modsRootElement);

if(genreElem != null) {
if (genreElem != null) {
String genre = genreElem.getText();
LOGGER.info("Genre is: {}", genre);
if (filteredGenres.contains(genre)) {
Expand All @@ -182,7 +182,7 @@ private static void saveLastHarvestDate(Date lastHarvest) {
final String dateAsString = new SimpleDateFormat(RecordTransformer.OAI_SIMPLE_FORMAT).format(lastHarvest);
try {
Files.write(lastHarvestDateFilePath, dateAsString.getBytes(StandardCharsets.UTF_8),
StandardOpenOption.CREATE);
StandardOpenOption.CREATE);
} catch (IOException e) {
LOGGER.error("Error while writing lastHarvestDate", e);
}
Expand Down Expand Up @@ -219,12 +219,12 @@ private static Path getLastHarvestDateFilePath() {
private static MCRMODSWrapper mapToObject(MCRMODSWrapper wrappedMCRObj) {
final Element modsRoot = wrappedMCRObj.getMODS();
final XPathExpression<Element> xpath = XPathFactory.instance()
.compile("mods:identifier[@type='dbt']",
Filters.element(), null, MCRConstants.MODS_NAMESPACE);
.compile("mods:identifier[@type='dbt']",
Filters.element(), null, MCRConstants.MODS_NAMESPACE);
final Element dbtIdentifierElem = xpath.evaluateFirst(modsRoot);

String dbtIdentifier = "";
if(dbtIdentifierElem != null) {
if (dbtIdentifierElem != null) {
dbtIdentifier = dbtIdentifierElem.getText();
}

Expand All @@ -233,7 +233,7 @@ private static MCRMODSWrapper mapToObject(MCRMODSWrapper wrappedMCRObj) {
SolrDocument first = null;
try {
first = MCRSolrSearchUtils
.first(MCRSolrClientFactory.getMainSolrClient(), solrQuery);
.first(MCRSolrClientFactory.getMainSolrClient(), solrQuery);
} catch (SolrServerException | IOException e) {
e.printStackTrace();
}
Expand All @@ -253,7 +253,7 @@ private static MCRMODSWrapper mapToObject(MCRMODSWrapper wrappedMCRObj) {
}

private static MCRObjectID nextFreeID() {
return MCRObjectID.getNextFreeId(projectID, "mods");
return MCRMetadataManager.getMCRObjectIDGenerator().getNextFreeId(projectID, "mods");
}

private static void createOrUpdate(MCRMODSWrapper wrappedMCRobj, String import_status) {
Expand All @@ -264,7 +264,7 @@ private static void createOrUpdate(MCRMODSWrapper wrappedMCRobj, String import_s
setState(wrappedMCRobj, import_status);

final Optional<MCRObjectID> alreadyExists = Optional.of(object.getId())
.filter(MCRMetadataManager::exists);
.filter(MCRMetadataManager::exists);
if (!alreadyExists.isPresent()) {
LOGGER.info("Create object {}!", object.getId().toString());
MCRMetadataManager.create(object);
Expand Down

0 comments on commit 1908b26

Please sign in to comment.