diff --git a/src/main/java/com/databasepreservation/common/server/ViewerFactory.java b/src/main/java/com/databasepreservation/common/server/ViewerFactory.java index e322afa2..99b745e1 100644 --- a/src/main/java/com/databasepreservation/common/server/ViewerFactory.java +++ b/src/main/java/com/databasepreservation/common/server/ViewerFactory.java @@ -7,7 +7,20 @@ */ package com.databasepreservation.common.server; +import com.databasepreservation.common.client.ViewerConstants; +import com.databasepreservation.common.client.index.IndexResult; +import com.databasepreservation.common.client.index.filter.BasicSearchFilterParameter; +import com.databasepreservation.common.client.index.filter.Filter; +import com.databasepreservation.common.client.index.sort.Sorter; +import com.databasepreservation.common.client.models.structure.ViewerDatabase; +import com.databasepreservation.common.client.index.facets.Facets; +import com.databasepreservation.common.client.models.structure.ViewerDatabaseStatus; +import com.databasepreservation.common.client.models.structure.ViewerDatabaseValidationStatus; +import com.databasepreservation.common.server.index.utils.IterableDatabaseResult; import org.apache.solr.client.solrj.SolrClient; +import org.roda.core.data.exceptions.GenericException; +import org.roda.core.data.exceptions.RequestNotValidException; +import org.roda.core.data.v2.index.sublist.Sublist; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -15,6 +28,8 @@ import com.databasepreservation.common.server.index.DatabaseRowsSolrManager; import com.databasepreservation.common.server.index.factory.SolrClientFactory; +import java.util.ArrayList; + /** * @author Bruno Ferreira */ @@ -35,10 +50,25 @@ private static synchronized void instantiate() { solrManager = new DatabaseRowsSolrManager(solrClient); configurationManager = new ConfigurationManager(); activityLogStrategyFactory = new ActivityLogStrategyFactory(); + try { + checkIngestingDBs(); + } catch (GenericException | RequestNotValidException e) { + LOGGER.error("Error checking for ingesting databases in initialization: " + e.getMessage()); + } instantiated = true; } } + public static void checkIngestingDBs() throws RequestNotValidException, GenericException { + Filter ingestingFilter = new Filter(new BasicSearchFilterParameter(ViewerConstants.SOLR_DATABASES_STATUS, ViewerDatabaseStatus.INGESTING.toString())); + + IterableDatabaseResult dataBases = solrManager.findAll(ViewerDatabase.class, ingestingFilter, Sorter.NONE, new ArrayList<>()); + + for (ViewerDatabase db : dataBases) { + solrManager.markDatabaseCollection(db.getUuid(), ViewerDatabaseStatus.ERROR); + } + } + public static Integer getEnvInt(String name, Integer defaultValue) { Integer envInt; try {