Skip to content

Commit

Permalink
fixed some maintenance issues; refs #20082
Browse files Browse the repository at this point in the history
  • Loading branch information
Keelhaul committed Jan 23, 2025
1 parent df14520 commit beff4db
Show file tree
Hide file tree
Showing 13 changed files with 76 additions and 72 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ public List<String> addToIndex(Path denkxwebFile, Map<String, Boolean> reindexSe
logger.info("Created media folder {}", newMediaFolder.toAbsolutePath());
}
}

// Use existing folders for those missing in the hotfolder
checkReindexSettings(dataFolders, reindexSettings);

Expand Down Expand Up @@ -342,23 +342,20 @@ private static void setSimpleData(IndexObject indexObj) {
Element structNode = indexObj.getRootStructNode();

// Set type
{
String value = structNode.getAttributeValue("type");
if (StringUtils.isNotEmpty(value)) {
indexObj.setType(MetadataConfigurationManager.mapDocStrct(value).trim());
} else {
indexObj.setType("monument");
}
logger.trace("TYPE: {}", indexObj.getType());
String type = structNode.getAttributeValue("type");
if (StringUtils.isNotEmpty(type)) {
indexObj.setType(MetadataConfigurationManager.mapDocStrct(type).trim());
} else {
indexObj.setType("monument");
}
logger.trace("TYPE: {}", indexObj.getType());

// Set label
{
String value = structNode.getAttributeValue("LABEL");
if (value != null) {
indexObj.setLabel(value);
}
String label = structNode.getAttributeValue("LABEL");
if (label != null) {
indexObj.setLabel(label);
}

logger.trace("LABEL: {}", indexObj.getLabel());
}

Expand All @@ -368,11 +365,10 @@ private static void setSimpleData(IndexObject indexObj) {
* @param dataFolders
* @param pageCountStart
* @param downloadExternalImages
* @throws FatalIndexerException
* @should generate pages correctly
*/
public void generatePageDocuments(ISolrWriteStrategy writeStrategy, Map<String, Path> dataFolders, int pageCountStart,
boolean downloadExternalImages) throws FatalIndexerException {
boolean downloadExternalImages) {
String xpath = "//denkxweb:images/denkxweb:image";
List<Element> eleImageList = xp.evaluateToElements(xpath, null);
if (eleImageList == null || eleImageList.isEmpty()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -529,15 +529,14 @@ private static List<LuceneField> mapPagesToDocstruct(IndexObject indexObj, ISolr
* @param dataRepository a {@link io.goobi.viewer.indexer.model.datarepository.DataRepository} object.
* @param pi a {@link java.lang.String} object.
* @param pageCountStart a int.
* @throws io.goobi.viewer.indexer.exceptions.FatalIndexerException
* @should create documents for all mapped pages
* @should set correct ORDER values
* @should skip unmapped pages
* @should switch to DEFAULT file group correctly
* @should maintain page order after parallel processing
*/
public void generatePageDocuments(final ISolrWriteStrategy writeStrategy, final Map<String, Path> dataFolders,
final DataRepository dataRepository, final String pi, int pageCountStart) throws FatalIndexerException {
final DataRepository dataRepository, final String pi, int pageCountStart) {
// Get all physical elements
String xpath = "/record/dc:relation";
List<Element> eleImageList = xp.evaluateToElements(xpath, null);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -610,11 +610,10 @@ List<SolrInputDocument> generateUserGeneratedContentDocsForPage(SolrInputDocumen
* @param groupIds
* @param order
* @return Generated {@link SolrInputDocument}
* @throws FatalIndexerException
* @should throw IllegalArgumentException if eleContent null
*/
SolrInputDocument generateUserGeneratedContentDocForPage(Element eleContent, SolrInputDocument pageDoc, String pi,
String anchorPi, Map<String, String> groupIds, int order) throws FatalIndexerException {
String anchorPi, Map<String, String> groupIds, int order) {
if (eleContent == null) {
throw new IllegalArgumentException("eleContent may not be null");
}
Expand Down Expand Up @@ -852,12 +851,11 @@ List<SolrInputDocument> generateUserCommentDocsForPage(SolrInputDocument pageDoc
* @param anchorPi
* @param groupIds
* @return List<SolrInputDocument>
* @throws FatalIndexerException
* @should return empty list if dataFolder null
* @should create docs correctly
*/
List<SolrInputDocument> generateAnnotationDocs(Map<Integer, SolrInputDocument> pageDocs, Path dataFolder, String pi, String anchorPi,
Map<String, String> groupIds) throws FatalIndexerException {
Map<String, String> groupIds) {
if (dataFolder == null || !Files.isDirectory(dataFolder)) {
logger.info("Annotation folder is empty.");
return Collections.emptyList();
Expand Down Expand Up @@ -1012,7 +1010,7 @@ public SolrInputDocument readAnnotation(Path path, String iddoc, String pi, Stri
protected void writeUserGeneratedContents(ISolrWriteStrategy writeStrategy, Map<String, Path> dataFolders, IndexObject indexObj)
throws FatalIndexerException {
// Collect page docs for annotation<->page mapping
Map<Integer, SolrInputDocument> pageDocs = new HashMap<>(writeStrategy.getPageDocsSize());
Map<Integer, SolrInputDocument> pageDocs = HashMap.newHashMap(writeStrategy.getPageDocsSize());

// Add used-generated content docs from legacy crowdsourcing
for (int i : writeStrategy.getPageOrderNumbers()) {
Expand Down Expand Up @@ -1231,10 +1229,9 @@ public static ImageReader getOpenJpegReader() {
* @param pi Record identifier
* @param writeStrategy
* @return Number of added group docs
* @throws FatalIndexerException
* @should add grouped metadata docs from given page to writeStrategy correctly
*/
public int addGroupedMetadataDocsForPage(PhysicalElement page, String pi, ISolrWriteStrategy writeStrategy) throws FatalIndexerException {
public int addGroupedMetadataDocsForPage(PhysicalElement page, String pi, ISolrWriteStrategy writeStrategy) {
if (page == null) {
throw new IllegalArgumentException("page may not be null");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -574,10 +574,9 @@ protected static List<LuceneField> mapPagesToDocstruct(IndexObject indexObj, ISo
* @param imageXPaths a {@link java.util.List} object.
* @param downloadExternalImages a boolean.
* @param useOldImageFolderIfAvailable
* @throws io.goobi.viewer.indexer.exceptions.FatalIndexerException
*/
public void generatePageDocuments(ISolrWriteStrategy writeStrategy, Map<String, Path> dataFolders, int pageCountStart,
List<String> imageXPaths, boolean downloadExternalImages, boolean useOldImageFolderIfAvailable) throws FatalIndexerException {
List<String> imageXPaths, boolean downloadExternalImages, boolean useOldImageFolderIfAvailable) {
String xpath = "/lido:lido/lido:administrativeMetadata/lido:resourceWrap/lido:resourceSet";
List<Element> resourceSetList = xp.evaluateToElements(xpath, null);
if (resourceSetList == null || resourceSetList.isEmpty()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1161,7 +1161,7 @@ PhysicalElement generatePageDocument(Element eleStructMapPhysical, String iddoc,
return null;
}
}
logger.trace("generatePageDocument: {} (IDDOC {}) processed by thread {}", id, iddoc, Thread.currentThread().getId());
logger.trace("generatePageDocument: {} (IDDOC {}) processed by thread {}", id, iddoc, Thread.currentThread().threadId());
// Check whether this physical element is mapped to any logical element, skip if not
StringBuilder sbXPath = new StringBuilder(70);
sbXPath.append("/mets:mets/mets:structLink/mets:smLink[@xlink:to=\"").append(id).append("\"]");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ SolrInputDocument index(Path sourceFile) throws IOException, FatalIndexerExcepti

/**
* @param solrDateString
* @return
* @return a boolean
* @throws IOException
* @throws SolrServerException
*/
Expand All @@ -131,10 +131,9 @@ private static boolean statisticsExists(String solrDateString) throws SolrServer

/**
* @param stats
* @return
* @throws FatalIndexerException
* @return {@link IndexObject}
*/
private static IndexObject createIndexObject(DailyUsageStatistics stats) throws FatalIndexerException {
private static IndexObject createIndexObject(DailyUsageStatistics stats) {
IndexObject indexObj = new IndexObject(getNextIddoc());
indexObj.addToLucene(SolrConstants.IDDOC, indexObj.getIddoc());
indexObj.addToLucene(SolrConstants.GROUPFIELD, indexObj.getIddoc());
Expand Down Expand Up @@ -183,7 +182,7 @@ public boolean removeFromIndex(Path sourceFile) throws FatalIndexerException {
/**
*
* @param sourceFile
* @return
* @return {@link String}
*/
private static String getStatisticsDate(Path sourceFile) {
String dateString = sourceFile.getFileName().toString().replaceAll("statistics-usage-([\\d-]+).\\w+", "$1");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@
import java.io.IOException;
import java.io.InputStream;
import java.io.StringWriter;
import java.net.URL;
import java.net.URI;
import java.net.URISyntaxException;
import java.nio.charset.StandardCharsets;
import java.time.LocalDateTime;
import java.util.regex.Matcher;
Expand Down Expand Up @@ -83,12 +84,12 @@ private static String getManifestStringFromJar() {
String manifestPath = classPath.substring(0, classPath.lastIndexOf("/io/goobi")) + "/META-INF/MANIFEST.MF";
logger.trace(manifestPath);

try (InputStream inputStream = new URL(manifestPath).openStream()) {
try (InputStream inputStream = new URI(manifestPath).toURL().openStream()) {
StringWriter writer = new StringWriter();
IOUtils.copy(inputStream, writer, StandardCharsets.UTF_8);
String manifestString = writer.toString();
value = manifestString;
} catch (IOException e) {
} catch (IOException | URISyntaxException e) {
return null;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
package io.goobi.viewer.indexer;

import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.nio.file.DirectoryStream;
import java.nio.file.FileAlreadyExistsException;
import java.nio.file.Files;
Expand Down Expand Up @@ -720,15 +719,14 @@ private void finalizeChildDocstruct(IndexObject indexObj, Map<String, Path> data
* @param pi
* @param pageCountStart a int.
* @throws InterruptedException
* @throws io.goobi.viewer.indexer.exceptions.FatalIndexerException
* @should create documents for all mapped pages
* @should set correct ORDER values
* @should skip unmapped pages
* @should switch to DEFAULT file group correctly
* @should maintain page order after parallel processing
*/
public void generatePageDocuments(final ISolrWriteStrategy writeStrategy, final Map<String, Path> dataFolders, final String pi,
int pageCountStart) throws InterruptedException, FatalIndexerException {
int pageCountStart) throws InterruptedException {
// Get all physical elements
List<Element> eleListImages = xp.evaluateToElements("worldviews/resource/images/image", null);
logger.info("Generating {} page documents (count starts at {})...", eleListImages.size(), pageCountStart);
Expand Down Expand Up @@ -785,7 +783,7 @@ PhysicalElement generatePageDocument(Element eleImage, String iddoc, String pi,
}

int useOrder = order != null ? order : Integer.parseInt(eleImage.getChildText("sequence"));
logger.trace("generatePageDocument: {} (IDDOC {}) processed by thread {}", useOrder, iddoc, Thread.currentThread().getId());
logger.trace("generatePageDocument: {} (IDDOC {}) processed by thread {}", useOrder, iddoc, Thread.currentThread().threadId());

// Create object for this page
PhysicalElement ret = createPhysicalElement(order, iddoc, "PHYS_" + MetadataHelper.FORMAT_FOUR_DIGITS.get().format(useOrder));
Expand Down Expand Up @@ -847,9 +845,8 @@ PhysicalElement generatePageDocument(Element eleImage, String iddoc, String pi,
* @param indexObj {@link IndexObject}
* @param hotfolder
* @param dataRepository
* @throws UnsupportedEncodingException
*/
static void copyAndReIndexAnchor(IndexObject indexObj, Hotfolder hotfolder, DataRepository dataRepository) throws UnsupportedEncodingException {
static void copyAndReIndexAnchor(IndexObject indexObj, Hotfolder hotfolder, DataRepository dataRepository) {
logger.debug("copyAndReIndexAnchor: {}", indexObj.getPi());
if (indexObj.getParent() != null) {
String piParent = indexObj.getParent().getPi();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
package io.goobi.viewer.indexer.helper;

import java.net.MalformedURLException;
import java.net.URI;
import java.net.URISyntaxException;
import java.net.URL;
import java.util.ArrayList;
import java.util.Arrays;
Expand Down Expand Up @@ -667,12 +669,13 @@ public List<String> getProxyWhitelist() {
* <p>isHostProxyWhitelisted.</p>
*
* @param url
* @return a boolean
* @throws MalformedURLException
* @throws URISyntaxException
* @should return true if host whitelisted
* @return a boolean
*/
public boolean isHostProxyWhitelisted(String url) throws MalformedURLException {
URL urlAsURL = new URL(url);
public boolean isHostProxyWhitelisted(String url) throws MalformedURLException, URISyntaxException {
URL urlAsURL = new URI(url).toURL();
return getProxyWhitelist().contains(urlAsURL.getHost());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URISyntaxException;
import java.nio.file.DirectoryStream;
import java.nio.file.Files;
import java.nio.file.Path;
Expand Down Expand Up @@ -509,7 +510,7 @@ private static List<LuceneField> retrieveAuthorityData(final String authorityUrl
proxyUrl = SolrIndexerDaemon.getInstance().getConfiguration().getProxyUrl();
proxyPort = SolrIndexerDaemon.getInstance().getConfiguration().getProxyPort();
}
} catch (MalformedURLException e) {
} catch (MalformedURLException | URISyntaxException e) {
logger.error(e.getMessage());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -872,7 +872,7 @@ public Set<String> checkDuplicateFieldValues(List<String> fields, List<String> v
return Collections.emptySet();
}

Set<String> ret = new HashSet<>(found.size());
Set<String> ret = HashSet.newHashSet(found.size());
for (SolrDocument doc : found) {
if (doc.containsKey(SolrConstants.PI_TOPSTRUCT)) {
ret.add((String) doc.getFieldValue(SolrConstants.PI_TOPSTRUCT));
Expand Down
Loading

0 comments on commit beff4db

Please sign in to comment.