From 2f44cb8429d1c496059354c7c02766b093e79dfc Mon Sep 17 00:00:00 2001 From: Matthias Ronge Date: Wed, 13 Sep 2023 14:16:52 +0200 Subject: [PATCH 1/9] Remove indexing page and Index Must Be Updated Warning --- .../controller/SecurityAccessController.java | 9 --- .../kitodo/production/forms/IndexingForm.java | 9 +-- .../kitodo/production/forms/LoginForm.java | 18 +---- .../security/CustomLoginSuccessHandler.java | 25 +++---- .../services/index/IndexingService.java | 5 -- .../resources/messages/messages_de.properties | 7 -- .../resources/messages/messages_en.properties | 7 -- .../resources/messages/messages_es.properties | 7 -- .../includes/base/indexWarningDialog.xhtml | 67 ------------------- Kitodo/src/main/webapp/pages/checks.xhtml | 1 - Kitodo/src/main/webapp/pages/system.xhtml | 4 -- 11 files changed, 12 insertions(+), 147 deletions(-) delete mode 100644 Kitodo/src/main/webapp/WEB-INF/templates/includes/base/indexWarningDialog.xhtml diff --git a/Kitodo/src/main/java/org/kitodo/production/controller/SecurityAccessController.java b/Kitodo/src/main/java/org/kitodo/production/controller/SecurityAccessController.java index 72eb057e8e4..4973e266ff9 100644 --- a/Kitodo/src/main/java/org/kitodo/production/controller/SecurityAccessController.java +++ b/Kitodo/src/main/java/org/kitodo/production/controller/SecurityAccessController.java @@ -726,15 +726,6 @@ public boolean hasAuthorityToViewSystemPage() { || securityAccessService.hasAuthorityToViewMigrationPage(); } - /** - * Check if current user has authority to view index page. - * - * @return true if user has authority to 'viewIndex' page. - */ - public boolean hasAuthorityToViewIndexPage() { - return securityAccessService.hasAuthorityToViewIndexPage(); - } - /** * Check if current user has authority to view task manager page. * diff --git a/Kitodo/src/main/java/org/kitodo/production/forms/IndexingForm.java b/Kitodo/src/main/java/org/kitodo/production/forms/IndexingForm.java index 34e883ea90d..defe199704e 100644 --- a/Kitodo/src/main/java/org/kitodo/production/forms/IndexingForm.java +++ b/Kitodo/src/main/java/org/kitodo/production/forms/IndexingForm.java @@ -359,14 +359,7 @@ public ObjectType getNoneType() { * Update the view. */ public void updateView() { - try { - if (ServiceManager.getIndexingService().isIndexCorrupted()) { - Helper.setErrorMessage("indexOutOfDate"); - } - Ajax.update("@all"); - } catch (DataException | DAOException e) { - Helper.setErrorMessage(e.getMessage()); - } + Ajax.update("@all"); } /** diff --git a/Kitodo/src/main/java/org/kitodo/production/forms/LoginForm.java b/Kitodo/src/main/java/org/kitodo/production/forms/LoginForm.java index 32aab0b3fee..ec3494cc75f 100644 --- a/Kitodo/src/main/java/org/kitodo/production/forms/LoginForm.java +++ b/Kitodo/src/main/java/org/kitodo/production/forms/LoginForm.java @@ -99,21 +99,16 @@ public void performPostLoginChecks() throws DataException, DAOException, IOExcep ExternalContext context = FacesContext.getCurrentInstance().getExternalContext(); SessionClientController controller = new SessionClientController(); - PrimeFaces.current().executeScript("PF('indexWarningDialog').hide();"); if (ServiceManager.getSecurityAccessService().hasAuthorityToEditIndex()) { if (controller.getAvailableClientsOfCurrentUser().size() > 1 && Objects.isNull(controller.getCurrentSessionClient())) { controller.showClientSelectDialog(); - } else if (ServiceManager.getIndexingService().isIndexCorrupted()) { - context.redirect(INDEXING_PAGE + determineIndexingTab()); } else { redirect(context); } } else { - if (ServiceManager.getIndexingService().isIndexCorrupted()) { - PrimeFaces.current().executeScript("PF('indexWarningDialog').show();"); - } else if (controller.getAvailableClientsOfCurrentUser().size() > 1 + if (controller.getAvailableClientsOfCurrentUser().size() > 1 && Objects.isNull(controller.getCurrentSessionClient())) { controller.showClientSelectDialog(); } else { @@ -131,15 +126,4 @@ private void redirect(ExternalContext context) throws IOException { context.redirect(context.getRequestContextPath() + originalRequest); } } - - private int determineIndexingTab() { - int indexingTabIndex = 2; - if (!securityAccessService.hasAuthorityToViewTermsPage()) { - indexingTabIndex -= 1; - } - if (!securityAccessService.hasAuthorityToViewTaskManagerPage()) { - indexingTabIndex -= 1; - } - return indexingTabIndex; - } } diff --git a/Kitodo/src/main/java/org/kitodo/production/security/CustomLoginSuccessHandler.java b/Kitodo/src/main/java/org/kitodo/production/security/CustomLoginSuccessHandler.java index c8f8dfbf6e3..3e85052c03c 100644 --- a/Kitodo/src/main/java/org/kitodo/production/security/CustomLoginSuccessHandler.java +++ b/Kitodo/src/main/java/org/kitodo/production/security/CustomLoginSuccessHandler.java @@ -45,22 +45,17 @@ public class CustomLoginSuccessHandler implements AuthenticationSuccessHandler { public void onAuthenticationSuccess(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, Authentication authentication) throws IOException { - try { - SessionClientController controller = new SessionClientController(); - if (ServiceManager.getIndexingService().isIndexCorrupted() - || controller.getAvailableClientsOfCurrentUser().size() > 1) { - // redirect to empty landing page, where dialogs are displayed depending on both checks! - redirectStrategy.sendRedirect(httpServletRequest, httpServletResponse, EMPTY_LANDING_PAGE); - } else { - if (Objects.nonNull(httpServletRequest.getSession())) { - // calling showClientSelectDialog automatically sets the only one available client here - controller.showClientSelectDialog(); - redirectStrategy.sendRedirect(httpServletRequest, httpServletResponse, - getOriginalRequest(httpServletRequest.getSession().getAttribute(SAVED_REQUEST))); - } + SessionClientController controller = new SessionClientController(); + if (controller.getAvailableClientsOfCurrentUser().size() > 1) { + // redirect to empty landing page, where dialogs are displayed depending on both checks! + redirectStrategy.sendRedirect(httpServletRequest, httpServletResponse, EMPTY_LANDING_PAGE); + } else { + if (Objects.nonNull(httpServletRequest.getSession())) { + // calling showClientSelectDialog automatically sets the only one available client here + controller.showClientSelectDialog(); + redirectStrategy.sendRedirect(httpServletRequest, httpServletResponse, + getOriginalRequest(httpServletRequest.getSession().getAttribute(SAVED_REQUEST))); } - } catch (DataException | DAOException e) { - logger.error(e.getLocalizedMessage()); } } diff --git a/Kitodo/src/main/java/org/kitodo/production/services/index/IndexingService.java b/Kitodo/src/main/java/org/kitodo/production/services/index/IndexingService.java index 547614e0f51..134e83f8290 100644 --- a/Kitodo/src/main/java/org/kitodo/production/services/index/IndexingService.java +++ b/Kitodo/src/main/java/org/kitodo/production/services/index/IndexingService.java @@ -182,11 +182,6 @@ public Map getCountDatabaseObjects() { return countDatabaseObjects; } - public boolean isIndexCorrupted() throws DAOException, DataException { - updateCounts(); - return getTotalCount() != getAllIndexed(); - } - /** * Return the number of all objects processed during the current indexing * progress. diff --git a/Kitodo/src/main/resources/messages/messages_de.properties b/Kitodo/src/main/resources/messages/messages_de.properties index 90d592319a5..41552d09a55 100644 --- a/Kitodo/src/main/resources/messages/messages_de.properties +++ b/Kitodo/src/main/resources/messages/messages_de.properties @@ -651,7 +651,6 @@ imprint=Impressum imprintDefaultText=Das Impressum f\u00FCr dieses System wurde noch nicht hinterlegt. indexedEntries=Indexierte Eintr\u00E4ge indexing=Indexierung -indexOutOfDate=Der Index muss aktualisiert werden! insert=Einf\u00FCgen insertAsUncounted=Als unnummeriert einf\u00FCgen insertHere=hier einf\u00FCgen @@ -1093,12 +1092,6 @@ structuralElement=Strukturelement structureElementAdd=Strukturelement hinzuf\u00FCgen structureElementDelete=Strukturelement l\u00F6schen system=System -systemComeBackLaterMessage=Bitte versuchen Sie es sp\u00E4ter erneut! -systemErrorHeader=Systemfehler -systemErrorInformAdminMessage=Bitte informieren Sie einen Administrator! -systemErrorMessage=Es ist ein Fehler im System aufgetreten. -systemMaintenanceHeader=Systemwartung -systemMaintenanceMessage=Das System wird derzeit gewartet. table=Tabelle tableSize=Tabellengr\u00F6\u00DFe task=Aufgabe diff --git a/Kitodo/src/main/resources/messages/messages_en.properties b/Kitodo/src/main/resources/messages/messages_en.properties index a12c156c25f..2a8d58a3c7c 100644 --- a/Kitodo/src/main/resources/messages/messages_en.properties +++ b/Kitodo/src/main/resources/messages/messages_en.properties @@ -652,7 +652,6 @@ imprint=Imprint imprintDefaultText=Imprint information have not been configured for this system. indexedEntries=Indexed entries indexing=Indexing -indexOutOfDate=The search index needs to be updated! insert=Insert insertAsUncounted=Insert as uncounted insertHere=insert here @@ -1094,12 +1093,6 @@ structuralElement=Structural element structureElementAdd=Add docstruct structureElementDelete=Delete docstruct system=System -systemComeBackLaterMessage=Please try again later! -systemErrorHeader=System error -systemErrorInformAdminMessage=Please inform an administrator! -systemErrorMessage=A system error occurred. -systemMaintenanceHeader=System maintenance -systemMaintenanceMessage=The system is currently under maintenance. table=Table tableSize=Table size task=Task diff --git a/Kitodo/src/main/resources/messages/messages_es.properties b/Kitodo/src/main/resources/messages/messages_es.properties index 0effd29d4bc..bde18535888 100644 --- a/Kitodo/src/main/resources/messages/messages_es.properties +++ b/Kitodo/src/main/resources/messages/messages_es.properties @@ -645,7 +645,6 @@ imprint=Pie de imprenta imprintDefaultText=La huella de este sistema aún no se ha almacenado. indexedEntries=Entradas indexadas indexing=Indexación -indexOutOfDate=Hay que actualizar el índice. insert=Insertar insertAsUncounted=Insertar como no numerado insertHere=Insertar aquí @@ -1079,12 +1078,6 @@ structuralElement=Elemento de la estructura structureElementAdd=Añadir elemento estructural structureElementDelete=Borrar el elemento estructural system=Sistema -systemComeBackLaterMessage=Por favor, inténtelo más tarde. -systemErrorHeader=Error del sistema -systemErrorInformAdminMessage=Por favor, informe a un administrador. -systemErrorMessage=Se ha producido un error en el sistema. -systemMaintenanceHeader=Mantenimiento del sistema -systemMaintenanceMessage=El sistema se encuentra actualmente en fase de mantenimiento. table=Tabla tableSize=Tamaño de la tabla task=Tarea diff --git a/Kitodo/src/main/webapp/WEB-INF/templates/includes/base/indexWarningDialog.xhtml b/Kitodo/src/main/webapp/WEB-INF/templates/includes/base/indexWarningDialog.xhtml deleted file mode 100644 index ad3307d63db..00000000000 --- a/Kitodo/src/main/webapp/WEB-INF/templates/includes/base/indexWarningDialog.xhtml +++ /dev/null @@ -1,67 +0,0 @@ - - - - - - -

#{msgs.systemMaintenanceHeader}

-
- #{msgs.systemMaintenanceMessage}
- #{msgs.systemComeBackLaterMessage} -
-
- -

#{msgs.systemErrorHeader}

-
- #{msgs.systemErrorMessage}
- #{msgs.systemErrorInformAdminMessage} -
-
-
- - - - - - - - - - - -
-
diff --git a/Kitodo/src/main/webapp/pages/checks.xhtml b/Kitodo/src/main/webapp/pages/checks.xhtml index ad043f715cf..63b22e67e28 100644 --- a/Kitodo/src/main/webapp/pages/checks.xhtml +++ b/Kitodo/src/main/webapp/pages/checks.xhtml @@ -27,7 +27,6 @@ - diff --git a/Kitodo/src/main/webapp/pages/system.xhtml b/Kitodo/src/main/webapp/pages/system.xhtml index 6fbec921da8..c1633aa215e 100644 --- a/Kitodo/src/main/webapp/pages/system.xhtml +++ b/Kitodo/src/main/webapp/pages/system.xhtml @@ -43,10 +43,6 @@ rendered="#{SecurityAccessController.hasAuthorityToViewTermsPage()}"> - - - From d650dcdfe01d80b85dcb34e48c6a70996b7eb118 Mon Sep 17 00:00:00 2001 From: Matthias Ronge Date: Fri, 19 Jan 2024 08:55:24 +0100 Subject: [PATCH 2/9] Remove index warning test --- .../java/org/kitodo/selenium/LoginST.java | 44 ------------------- 1 file changed, 44 deletions(-) delete mode 100644 Kitodo/src/test/java/org/kitodo/selenium/LoginST.java diff --git a/Kitodo/src/test/java/org/kitodo/selenium/LoginST.java b/Kitodo/src/test/java/org/kitodo/selenium/LoginST.java deleted file mode 100644 index d3d27b7b836..00000000000 --- a/Kitodo/src/test/java/org/kitodo/selenium/LoginST.java +++ /dev/null @@ -1,44 +0,0 @@ -/* - * (c) Kitodo. Key to digital objects e. V. - * - * This file is part of the Kitodo project. - * - * It is licensed under GNU General Public License version 3 or later. - * - * For the full copyright and license information, please read the - * GPL3-License.txt file that was distributed with this source code. - */ - -package org.kitodo.selenium; - -import org.junit.Assert; -import org.junit.BeforeClass; -import org.junit.Test; -import org.kitodo.data.elasticsearch.exceptions.CustomResponseException; -import org.kitodo.data.exceptions.DataException; -import org.kitodo.production.services.ServiceManager; -import org.kitodo.selenium.testframework.BaseTestSelenium; -import org.kitodo.selenium.testframework.Browser; -import org.kitodo.selenium.testframework.Pages; - -public class LoginST extends BaseTestSelenium { - - @BeforeClass - public static void manipulateIndex() throws DataException, CustomResponseException { - // remove one process from index but not from DB to provoke index warning - ServiceManager.getProcessService().removeFromIndex(1, true); - } - - @Test - public void indexWarningTest() throws Exception { - // log into Kitodo with non-admin user to be redirected to 'checks' page - Pages.getLoginPage().goTo().performLogin(ServiceManager.getUserService().getById(2)); - Assert.assertEquals("http://localhost:8080/kitodo/pages/checks.jsf", Browser.getCurrentUrl()); - Pages.getPostLoginChecksPage().logout(); - - // log into kitodo with admin user to be redirected to 'system' page - Pages.getLoginPage().goTo().performLoginAsAdmin(); - Assert.assertEquals("http://localhost:8080/kitodo/pages/system.jsf?tabIndex=2", Browser.getCurrentUrl()); - Pages.getTopNavigation().logout(); - } -} From 67d5b84301872aed03563b839f8b61abe45bdbb1 Mon Sep 17 00:00:00 2001 From: Matthias Ronge Date: Mon, 22 Jan 2024 10:08:03 +0100 Subject: [PATCH 3/9] Fix tabbing for Selenium tests --- .../org/kitodo/selenium/testframework/enums/TabIndex.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Kitodo/src/test/java/org/kitodo/selenium/testframework/enums/TabIndex.java b/Kitodo/src/test/java/org/kitodo/selenium/testframework/enums/TabIndex.java index 86ac024519d..fdd677d071d 100644 --- a/Kitodo/src/test/java/org/kitodo/selenium/testframework/enums/TabIndex.java +++ b/Kitodo/src/test/java/org/kitodo/selenium/testframework/enums/TabIndex.java @@ -55,8 +55,8 @@ public enum TabIndex { // system page TASKMANAGER(0), - INDEXING(2), - MIGRATION(3), + INDEXING(null), + MIGRATION(2), // user configuration SETTINGS(0), @@ -67,9 +67,9 @@ public enum TabIndex { IMPORT_CONFIGURATION_MAPPING_FILES(1); - private final int index; + private final Integer index; - TabIndex(final int newIndex) { + TabIndex(final Integer newIndex) { index = newIndex; } From 51d19ed7e9bf4070dbb1e1e6c8c8cf110d5e4dc1 Mon Sep 17 00:00:00 2001 From: Matthias Ronge Date: Fri, 8 Mar 2024 10:12:30 +0100 Subject: [PATCH 4/9] Bring back indexing page --- .../controller/SecurityAccessController.java | 9 ++ .../kitodo/production/forms/IndexingForm.java | 136 +++++------------- .../kitodo/production/helper/IndexWorker.java | 2 +- .../production/helper/IndexWorkerStatus.java | 21 --- .../services/index/IndexManagmentThread.java | 6 +- .../services/index/IndexingService.java | 20 +-- Kitodo/src/main/webapp/pages/system.xhtml | 4 + .../testframework/enums/TabIndex.java | 8 +- 8 files changed, 56 insertions(+), 150 deletions(-) diff --git a/Kitodo/src/main/java/org/kitodo/production/controller/SecurityAccessController.java b/Kitodo/src/main/java/org/kitodo/production/controller/SecurityAccessController.java index 4973e266ff9..72eb057e8e4 100644 --- a/Kitodo/src/main/java/org/kitodo/production/controller/SecurityAccessController.java +++ b/Kitodo/src/main/java/org/kitodo/production/controller/SecurityAccessController.java @@ -726,6 +726,15 @@ public boolean hasAuthorityToViewSystemPage() { || securityAccessService.hasAuthorityToViewMigrationPage(); } + /** + * Check if current user has authority to view index page. + * + * @return true if user has authority to 'viewIndex' page. + */ + public boolean hasAuthorityToViewIndexPage() { + return securityAccessService.hasAuthorityToViewIndexPage(); + } + /** * Check if current user has authority to view task manager page. * diff --git a/Kitodo/src/main/java/org/kitodo/production/forms/IndexingForm.java b/Kitodo/src/main/java/org/kitodo/production/forms/IndexingForm.java index defe199704e..48a867696ef 100644 --- a/Kitodo/src/main/java/org/kitodo/production/forms/IndexingForm.java +++ b/Kitodo/src/main/java/org/kitodo/production/forms/IndexingForm.java @@ -11,8 +11,8 @@ package org.kitodo.production.forms; -import java.io.IOException; import java.time.LocalDateTime; +import java.util.Collections; import java.util.List; import java.util.Map; @@ -23,34 +23,29 @@ import javax.inject.Named; import javax.json.Json; import javax.json.JsonArray; -import javax.json.JsonArrayBuilder; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; -import org.kitodo.data.database.exceptions.DAOException; -import org.kitodo.data.elasticsearch.exceptions.CustomResponseException; -import org.kitodo.data.exceptions.DataException; import org.kitodo.production.enums.IndexStates; import org.kitodo.production.enums.ObjectType; import org.kitodo.production.helper.Helper; -import org.kitodo.production.services.ServiceManager; -import org.kitodo.production.services.index.IndexingService; import org.omnifaces.util.Ajax; @Named @ApplicationScoped public class IndexingForm { - private static final List objectTypes = ObjectType.getIndexableObjectTypes(); private static final Logger logger = LogManager.getLogger(IndexingForm.class); private static final String POLLING_CHANNEL_NAME = "togglePollingChannel"; - private String indexingStartedUser = ""; - private LocalDateTime indexingStartedTime = null; + private static final List OBJECT_TYPES = ObjectType.getIndexableObjectTypes(); @Inject @Push(channel = POLLING_CHANNEL_NAME) private PushContext pollingChannel; + private String indexingStartedUser = ""; + private LocalDateTime indexingStartedTime = null; + /** * Get user which started indexing. * @@ -65,11 +60,8 @@ public String getIndexingStartedUser() { * click. */ public void countDatabaseObjects() { - try { - ServiceManager.getIndexingService().countDatabaseObjects(); - } catch (DAOException e) { - Helper.setErrorMessage(e.getLocalizedMessage(), logger, e); - } + Exception e = new UnsupportedOperationException("currently not implemented"); + Helper.setErrorMessage(e.getLocalizedMessage(), logger, e); } /** @@ -87,7 +79,7 @@ public LocalDateTime getIndexingStartedTime() { * @return value of countDatabaseObjects */ public Map getCountDatabaseObjects() { - return ServiceManager.getIndexingService().getCountDatabaseObjects(); + return Collections.emptyMap(); } /** @@ -96,7 +88,7 @@ public Map getCountDatabaseObjects() { * @return long number of all items that can be written to the index */ public long getTotalCount() { - return ServiceManager.getIndexingService().getTotalCount(); + return 0; } /** @@ -108,12 +100,7 @@ public long getTotalCount() { * @return number of indexed objects */ public long getNumberOfIndexedObjects(ObjectType objectType) { - try { - return ServiceManager.getIndexingService().getNumberOfIndexedObjects(objectType); - } catch (DataException e) { - Helper.setErrorMessage(e.getLocalizedMessage(), logger, e); - return 0; - } + return 0; } /** @@ -123,12 +110,7 @@ public long getNumberOfIndexedObjects(ObjectType objectType) { * @return long number of all currently indexed objects */ public long getAllIndexed() { - try { - return ServiceManager.getIndexingService().getAllIndexed(); - } catch (DataException | ArithmeticException e) { - Helper.setErrorMessage(e.getLocalizedMessage(), logger, e); - return 0; - } + return 0; } /** @@ -138,13 +120,8 @@ public long getAllIndexed() { * type objects that get indexed */ public void callIndexing(ObjectType type) { - indexingStartedTime = LocalDateTime.now(); - indexingStartedUser = ServiceManager.getUserService().getAuthenticatedUser().getFullName(); - try { - ServiceManager.getIndexingService().startIndexing(pollingChannel, type); - } catch (IllegalStateException e) { - Helper.setErrorMessage(e.getLocalizedMessage(), logger, e); - } + Exception e = new UnsupportedOperationException("currently not implemented"); + Helper.setErrorMessage(e.getLocalizedMessage(), logger, e); } /** @@ -154,29 +131,24 @@ public void callIndexing(ObjectType type) { * type objects that get indexed */ public void callIndexingRemaining(ObjectType type) { - indexingStartedTime = LocalDateTime.now(); - indexingStartedUser = ServiceManager.getUserService().getAuthenticatedUser().getFullName(); - try { - ServiceManager.getIndexingService().startIndexingRemaining(pollingChannel, type); - } catch (IllegalStateException e) { - Helper.setErrorMessage(e.getLocalizedMessage(), logger, e); - } + Exception e = new UnsupportedOperationException("currently not implemented"); + Helper.setErrorMessage(e.getLocalizedMessage(), logger, e); } /** * Starts the process of indexing all objects to the ElasticSearch index. */ public void startAllIndexing() { - indexingStartedTime = LocalDateTime.now(); - indexingStartedUser = ServiceManager.getUserService().getAuthenticatedUser().getFullName(); - ServiceManager.getIndexingService().startAllIndexing(pollingChannel); + Exception e = new UnsupportedOperationException("currently not implemented"); + Helper.setErrorMessage(e.getLocalizedMessage(), logger, e); } /** * Starts the process of indexing all objects to the ElasticSearch index. */ public void startAllIndexingRemaining() { - ServiceManager.getIndexingService().startAllIndexingRemaining(pollingChannel); + Exception e = new UnsupportedOperationException("currently not implemented"); + Helper.setErrorMessage(e.getLocalizedMessage(), logger, e); } /** @@ -186,7 +158,7 @@ public void startAllIndexingRemaining() { * @return the overall progress of the indexing process */ public int getAllIndexingProgress() { - return (int) ((getAllIndexed() / (float) getTotalCount()) * 100); + return 0; } /** @@ -196,7 +168,7 @@ public int getAllIndexingProgress() { * progress or not */ public boolean indexingInProgress() { - return ServiceManager.getIndexingService().indexingInProgress(); + return false; } /** @@ -208,30 +180,16 @@ public boolean indexingInProgress() { * or not. */ public void createMapping(boolean updatePollingChannel) { - try { - if (updatePollingChannel) { - pollingChannel.send(IndexingService.MAPPING_STARTED_MESSAGE); - } - String mappingStateMessage = ServiceManager.getIndexingService().createMapping(); - if (updatePollingChannel) { - pollingChannel.send(mappingStateMessage); - } - } catch (IOException | CustomResponseException e) { - ServiceManager.getIndexingService().setIndexState(IndexStates.CREATING_MAPPING_FAILED); - if (updatePollingChannel) { - pollingChannel.send(IndexingService.MAPPING_FAILED_MESSAGE); - } - Helper.setErrorMessage(e.getLocalizedMessage(), logger, e); - } + Exception e = new UnsupportedOperationException("currently not implemented"); + Helper.setErrorMessage(e.getLocalizedMessage(), logger, e); } /** * Delete whole ElasticSearch index. */ public void deleteIndex() { - pollingChannel.send(IndexingService.DELETION_STARTED_MESSAGE); - String updateMessage = ServiceManager.getIndexingService().deleteIndex(); - pollingChannel.send(updateMessage); + Exception e = new UnsupportedOperationException("currently not implemented"); + Helper.setErrorMessage(e.getLocalizedMessage(), logger, e); } /** @@ -241,12 +199,7 @@ public void deleteIndex() { * @return String information about the server */ public String getServerInformation() { - try { - return ServiceManager.getIndexingService().getServerInformation(); - } catch (IOException e) { - Helper.setErrorMessage("elasticSearchNotRunning", logger, e); - return ""; - } + return ""; } /** @@ -258,12 +211,7 @@ public String getServerInformation() { * @return the progress of the current indexing process in percent */ public int getProgress(ObjectType currentType) { - try { - return ServiceManager.getIndexingService().getProgress(currentType, pollingChannel); - } catch (DataException e) { - Helper.setErrorMessage(e.getLocalizedMessage(), logger, e); - return 0; - } + return 0; } /** @@ -272,7 +220,7 @@ public int getProgress(ObjectType currentType) { * @return true if mapping is empty, otherwise false */ public boolean isMappingEmpty() { - return ServiceManager.getIndexingService().isMappingEmpty(); + return true; } /** @@ -281,11 +229,7 @@ public boolean isMappingEmpty() { * @return whether the Elastic Search index exists or not */ public boolean indexExists() { - try { - return ServiceManager.getIndexingService().indexExists(); - } catch (IOException | CustomResponseException ignored) { - return false; - } + return false; } /** @@ -296,7 +240,7 @@ public boolean indexExists() { * @return state of ES index */ public IndexStates getIndexState() { - return ServiceManager.getIndexingService().getIndexState(); + return IndexStates.NO_STATE; } /** @@ -308,7 +252,7 @@ public IndexStates getIndexState() { * @return indexing state of the given object type. */ public IndexStates getObjectIndexState(ObjectType objectType) { - return ServiceManager.getIndexingService().getObjectIndexState(objectType); + return IndexStates.NO_STATE; } /** @@ -320,7 +264,7 @@ public IndexStates getObjectIndexState(ObjectType objectType) { * @return static variable for global indexing state */ public IndexStates getAllObjectsIndexingState() { - return ServiceManager.getIndexingService().getAllObjectsIndexingState(); + return IndexStates.NO_STATE; } /** @@ -329,7 +273,7 @@ public IndexStates getAllObjectsIndexingState() { * @return array of object type values */ public ObjectType[] getObjectTypes() { - return objectTypes.toArray(new ObjectType[0]); + return OBJECT_TYPES.toArray(new ObjectType[0]); } /** @@ -337,13 +281,8 @@ public ObjectType[] getObjectTypes() { * * @return JSONArray containing objects type constants. */ - @SuppressWarnings("unused") public JsonArray getObjectTypesAsJson() { - JsonArrayBuilder objectsTypesJson = Json.createArrayBuilder(); - for (ObjectType objectType : objectTypes) { - objectsTypesJson.add(objectType.toString()); - } - return objectsTypesJson.build(); + return Json.createArrayBuilder().build(); } /** @@ -361,11 +300,4 @@ public ObjectType getNoneType() { public void updateView() { Ajax.update("@all"); } - - /** - * Cancel indexing upon user request. - */ - public void cancelIndexing() { - ServiceManager.getIndexingService().cancelIndexing(); - } } diff --git a/Kitodo/src/main/java/org/kitodo/production/helper/IndexWorker.java b/Kitodo/src/main/java/org/kitodo/production/helper/IndexWorker.java index a293e787550..92e2e2db9bc 100644 --- a/Kitodo/src/main/java/org/kitodo/production/helper/IndexWorker.java +++ b/Kitodo/src/main/java/org/kitodo/production/helper/IndexWorker.java @@ -55,7 +55,7 @@ public void run() { int maxBatch = indexWorkerStatus.getMaxBatch(); int nextBatch = indexWorkerStatus.getAndIncrementNextBatch(); - while (!indexWorkerStatus.hasFailed() && !indexWorkerStatus.isCanceled() && nextBatch < maxBatch) { + while (!indexWorkerStatus.hasFailed() && nextBatch < maxBatch) { // nextBatch is a valid batch that needs to be processed int attempt = 1; diff --git a/Kitodo/src/main/java/org/kitodo/production/helper/IndexWorkerStatus.java b/Kitodo/src/main/java/org/kitodo/production/helper/IndexWorkerStatus.java index a99b1567de7..b8d1c061343 100644 --- a/Kitodo/src/main/java/org/kitodo/production/helper/IndexWorkerStatus.java +++ b/Kitodo/src/main/java/org/kitodo/production/helper/IndexWorkerStatus.java @@ -34,11 +34,6 @@ public class IndexWorkerStatus { */ private final AtomicBoolean failed = new AtomicBoolean(false); - /** - * Whether the indexing process was canceled by a user. - */ - private final AtomicBoolean canceled = new AtomicBoolean(false); - /** * Initialize index worker status. * @@ -81,20 +76,4 @@ public boolean hasFailed() { public void markAsFailed() { this.failed.set(true); } - - /** - * Marks the index status as canceld by a user. - */ - public void markAsCanceled() { - this.canceled.set(true); - } - - /** - * Return whether indexing process was canceled by a user. - * - * @return true if canceled - */ - public boolean isCanceled() { - return this.canceled.get(); - } } diff --git a/Kitodo/src/main/java/org/kitodo/production/services/index/IndexManagmentThread.java b/Kitodo/src/main/java/org/kitodo/production/services/index/IndexManagmentThread.java index 2b9e38f9d1f..6828f573477 100644 --- a/Kitodo/src/main/java/org/kitodo/production/services/index/IndexManagmentThread.java +++ b/Kitodo/src/main/java/org/kitodo/production/services/index/IndexManagmentThread.java @@ -56,13 +56,13 @@ public void run() { if (Objects.isNull(this.objectType) || currentType.equals(objectType)) { try { IndexWorkerStatus status = indexingService.runIndexing(currentType, context, indexAllObjects); - if (Objects.nonNull(status) && (status.isCanceled() || status.hasFailed())) { - // stop indexing due to failure or cancel + if (Objects.nonNull(status) && (status.hasFailed())) { + // stop indexing due to failure break; } } catch (DataException | CustomResponseException | DAOException | RuntimeException e) { logger.error(e); - Helper.setErrorMessage(e.getLocalizedMessage(), IndexingService.getLogger(), e); + Helper.setErrorMessage(e.getLocalizedMessage(), logger, e); } } } diff --git a/Kitodo/src/main/java/org/kitodo/production/services/index/IndexingService.java b/Kitodo/src/main/java/org/kitodo/production/services/index/IndexingService.java index 134e83f8290..11a7d5a7ffa 100644 --- a/Kitodo/src/main/java/org/kitodo/production/services/index/IndexingService.java +++ b/Kitodo/src/main/java/org/kitodo/production/services/index/IndexingService.java @@ -350,7 +350,7 @@ private void waitWhileIndexing(ObjectType type, List> futures, PushCon while (true) { // check whether all jobs are done boolean done = true; - boolean failed = indexWorkerStatus.hasFailed() || indexWorkerStatus.isCanceled(); + boolean failed = indexWorkerStatus.hasFailed(); for (Future future : futures) { if (!future.isDone()) { done = false; @@ -638,22 +638,4 @@ void setIndexingAll(boolean indexing) { void resetCurrentIndexState() { currentIndexState = ObjectType.NONE; } - - /** - * Cancels indexing upon user request. - */ - public void cancelIndexing() { - if (Objects.nonNull(indexWorkerStatus)) { - indexWorkerStatus.markAsCanceled(); - } - } - - /** - * Get logger. - * - * @return value of logger - */ - public static Logger getLogger() { - return logger; - } } diff --git a/Kitodo/src/main/webapp/pages/system.xhtml b/Kitodo/src/main/webapp/pages/system.xhtml index c1633aa215e..6fbec921da8 100644 --- a/Kitodo/src/main/webapp/pages/system.xhtml +++ b/Kitodo/src/main/webapp/pages/system.xhtml @@ -43,6 +43,10 @@ rendered="#{SecurityAccessController.hasAuthorityToViewTermsPage()}"> + + + diff --git a/Kitodo/src/test/java/org/kitodo/selenium/testframework/enums/TabIndex.java b/Kitodo/src/test/java/org/kitodo/selenium/testframework/enums/TabIndex.java index fdd677d071d..86ac024519d 100644 --- a/Kitodo/src/test/java/org/kitodo/selenium/testframework/enums/TabIndex.java +++ b/Kitodo/src/test/java/org/kitodo/selenium/testframework/enums/TabIndex.java @@ -55,8 +55,8 @@ public enum TabIndex { // system page TASKMANAGER(0), - INDEXING(null), - MIGRATION(2), + INDEXING(2), + MIGRATION(3), // user configuration SETTINGS(0), @@ -67,9 +67,9 @@ public enum TabIndex { IMPORT_CONFIGURATION_MAPPING_FILES(1); - private final Integer index; + private final int index; - TabIndex(final Integer newIndex) { + TabIndex(final int newIndex) { index = newIndex; } From 777bbf918b2d070af3d5fd8fc26335f4444f380f Mon Sep 17 00:00:00 2001 From: Matthias Ronge Date: Mon, 11 Mar 2024 10:42:01 +0100 Subject: [PATCH 5/9] Revert "Bring back indexing page" This reverts commit 51d19ed7e9bf4070dbb1e1e6c8c8cf110d5e4dc1. --- .../controller/SecurityAccessController.java | 9 -- .../kitodo/production/forms/IndexingForm.java | 136 +++++++++++++----- .../kitodo/production/helper/IndexWorker.java | 2 +- .../production/helper/IndexWorkerStatus.java | 21 +++ .../services/index/IndexManagmentThread.java | 6 +- .../services/index/IndexingService.java | 20 ++- Kitodo/src/main/webapp/pages/system.xhtml | 4 - .../testframework/enums/TabIndex.java | 8 +- 8 files changed, 150 insertions(+), 56 deletions(-) diff --git a/Kitodo/src/main/java/org/kitodo/production/controller/SecurityAccessController.java b/Kitodo/src/main/java/org/kitodo/production/controller/SecurityAccessController.java index 72eb057e8e4..4973e266ff9 100644 --- a/Kitodo/src/main/java/org/kitodo/production/controller/SecurityAccessController.java +++ b/Kitodo/src/main/java/org/kitodo/production/controller/SecurityAccessController.java @@ -726,15 +726,6 @@ public boolean hasAuthorityToViewSystemPage() { || securityAccessService.hasAuthorityToViewMigrationPage(); } - /** - * Check if current user has authority to view index page. - * - * @return true if user has authority to 'viewIndex' page. - */ - public boolean hasAuthorityToViewIndexPage() { - return securityAccessService.hasAuthorityToViewIndexPage(); - } - /** * Check if current user has authority to view task manager page. * diff --git a/Kitodo/src/main/java/org/kitodo/production/forms/IndexingForm.java b/Kitodo/src/main/java/org/kitodo/production/forms/IndexingForm.java index 48a867696ef..defe199704e 100644 --- a/Kitodo/src/main/java/org/kitodo/production/forms/IndexingForm.java +++ b/Kitodo/src/main/java/org/kitodo/production/forms/IndexingForm.java @@ -11,8 +11,8 @@ package org.kitodo.production.forms; +import java.io.IOException; import java.time.LocalDateTime; -import java.util.Collections; import java.util.List; import java.util.Map; @@ -23,29 +23,34 @@ import javax.inject.Named; import javax.json.Json; import javax.json.JsonArray; +import javax.json.JsonArrayBuilder; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; +import org.kitodo.data.database.exceptions.DAOException; +import org.kitodo.data.elasticsearch.exceptions.CustomResponseException; +import org.kitodo.data.exceptions.DataException; import org.kitodo.production.enums.IndexStates; import org.kitodo.production.enums.ObjectType; import org.kitodo.production.helper.Helper; +import org.kitodo.production.services.ServiceManager; +import org.kitodo.production.services.index.IndexingService; import org.omnifaces.util.Ajax; @Named @ApplicationScoped public class IndexingForm { + private static final List objectTypes = ObjectType.getIndexableObjectTypes(); private static final Logger logger = LogManager.getLogger(IndexingForm.class); private static final String POLLING_CHANNEL_NAME = "togglePollingChannel"; - private static final List OBJECT_TYPES = ObjectType.getIndexableObjectTypes(); + private String indexingStartedUser = ""; + private LocalDateTime indexingStartedTime = null; @Inject @Push(channel = POLLING_CHANNEL_NAME) private PushContext pollingChannel; - private String indexingStartedUser = ""; - private LocalDateTime indexingStartedTime = null; - /** * Get user which started indexing. * @@ -60,8 +65,11 @@ public String getIndexingStartedUser() { * click. */ public void countDatabaseObjects() { - Exception e = new UnsupportedOperationException("currently not implemented"); - Helper.setErrorMessage(e.getLocalizedMessage(), logger, e); + try { + ServiceManager.getIndexingService().countDatabaseObjects(); + } catch (DAOException e) { + Helper.setErrorMessage(e.getLocalizedMessage(), logger, e); + } } /** @@ -79,7 +87,7 @@ public LocalDateTime getIndexingStartedTime() { * @return value of countDatabaseObjects */ public Map getCountDatabaseObjects() { - return Collections.emptyMap(); + return ServiceManager.getIndexingService().getCountDatabaseObjects(); } /** @@ -88,7 +96,7 @@ public Map getCountDatabaseObjects() { * @return long number of all items that can be written to the index */ public long getTotalCount() { - return 0; + return ServiceManager.getIndexingService().getTotalCount(); } /** @@ -100,7 +108,12 @@ public long getTotalCount() { * @return number of indexed objects */ public long getNumberOfIndexedObjects(ObjectType objectType) { - return 0; + try { + return ServiceManager.getIndexingService().getNumberOfIndexedObjects(objectType); + } catch (DataException e) { + Helper.setErrorMessage(e.getLocalizedMessage(), logger, e); + return 0; + } } /** @@ -110,7 +123,12 @@ public long getNumberOfIndexedObjects(ObjectType objectType) { * @return long number of all currently indexed objects */ public long getAllIndexed() { - return 0; + try { + return ServiceManager.getIndexingService().getAllIndexed(); + } catch (DataException | ArithmeticException e) { + Helper.setErrorMessage(e.getLocalizedMessage(), logger, e); + return 0; + } } /** @@ -120,8 +138,13 @@ public long getAllIndexed() { * type objects that get indexed */ public void callIndexing(ObjectType type) { - Exception e = new UnsupportedOperationException("currently not implemented"); - Helper.setErrorMessage(e.getLocalizedMessage(), logger, e); + indexingStartedTime = LocalDateTime.now(); + indexingStartedUser = ServiceManager.getUserService().getAuthenticatedUser().getFullName(); + try { + ServiceManager.getIndexingService().startIndexing(pollingChannel, type); + } catch (IllegalStateException e) { + Helper.setErrorMessage(e.getLocalizedMessage(), logger, e); + } } /** @@ -131,24 +154,29 @@ public void callIndexing(ObjectType type) { * type objects that get indexed */ public void callIndexingRemaining(ObjectType type) { - Exception e = new UnsupportedOperationException("currently not implemented"); - Helper.setErrorMessage(e.getLocalizedMessage(), logger, e); + indexingStartedTime = LocalDateTime.now(); + indexingStartedUser = ServiceManager.getUserService().getAuthenticatedUser().getFullName(); + try { + ServiceManager.getIndexingService().startIndexingRemaining(pollingChannel, type); + } catch (IllegalStateException e) { + Helper.setErrorMessage(e.getLocalizedMessage(), logger, e); + } } /** * Starts the process of indexing all objects to the ElasticSearch index. */ public void startAllIndexing() { - Exception e = new UnsupportedOperationException("currently not implemented"); - Helper.setErrorMessage(e.getLocalizedMessage(), logger, e); + indexingStartedTime = LocalDateTime.now(); + indexingStartedUser = ServiceManager.getUserService().getAuthenticatedUser().getFullName(); + ServiceManager.getIndexingService().startAllIndexing(pollingChannel); } /** * Starts the process of indexing all objects to the ElasticSearch index. */ public void startAllIndexingRemaining() { - Exception e = new UnsupportedOperationException("currently not implemented"); - Helper.setErrorMessage(e.getLocalizedMessage(), logger, e); + ServiceManager.getIndexingService().startAllIndexingRemaining(pollingChannel); } /** @@ -158,7 +186,7 @@ public void startAllIndexingRemaining() { * @return the overall progress of the indexing process */ public int getAllIndexingProgress() { - return 0; + return (int) ((getAllIndexed() / (float) getTotalCount()) * 100); } /** @@ -168,7 +196,7 @@ public int getAllIndexingProgress() { * progress or not */ public boolean indexingInProgress() { - return false; + return ServiceManager.getIndexingService().indexingInProgress(); } /** @@ -180,16 +208,30 @@ public boolean indexingInProgress() { * or not. */ public void createMapping(boolean updatePollingChannel) { - Exception e = new UnsupportedOperationException("currently not implemented"); - Helper.setErrorMessage(e.getLocalizedMessage(), logger, e); + try { + if (updatePollingChannel) { + pollingChannel.send(IndexingService.MAPPING_STARTED_MESSAGE); + } + String mappingStateMessage = ServiceManager.getIndexingService().createMapping(); + if (updatePollingChannel) { + pollingChannel.send(mappingStateMessage); + } + } catch (IOException | CustomResponseException e) { + ServiceManager.getIndexingService().setIndexState(IndexStates.CREATING_MAPPING_FAILED); + if (updatePollingChannel) { + pollingChannel.send(IndexingService.MAPPING_FAILED_MESSAGE); + } + Helper.setErrorMessage(e.getLocalizedMessage(), logger, e); + } } /** * Delete whole ElasticSearch index. */ public void deleteIndex() { - Exception e = new UnsupportedOperationException("currently not implemented"); - Helper.setErrorMessage(e.getLocalizedMessage(), logger, e); + pollingChannel.send(IndexingService.DELETION_STARTED_MESSAGE); + String updateMessage = ServiceManager.getIndexingService().deleteIndex(); + pollingChannel.send(updateMessage); } /** @@ -199,7 +241,12 @@ public void deleteIndex() { * @return String information about the server */ public String getServerInformation() { - return ""; + try { + return ServiceManager.getIndexingService().getServerInformation(); + } catch (IOException e) { + Helper.setErrorMessage("elasticSearchNotRunning", logger, e); + return ""; + } } /** @@ -211,7 +258,12 @@ public String getServerInformation() { * @return the progress of the current indexing process in percent */ public int getProgress(ObjectType currentType) { - return 0; + try { + return ServiceManager.getIndexingService().getProgress(currentType, pollingChannel); + } catch (DataException e) { + Helper.setErrorMessage(e.getLocalizedMessage(), logger, e); + return 0; + } } /** @@ -220,7 +272,7 @@ public int getProgress(ObjectType currentType) { * @return true if mapping is empty, otherwise false */ public boolean isMappingEmpty() { - return true; + return ServiceManager.getIndexingService().isMappingEmpty(); } /** @@ -229,7 +281,11 @@ public boolean isMappingEmpty() { * @return whether the Elastic Search index exists or not */ public boolean indexExists() { - return false; + try { + return ServiceManager.getIndexingService().indexExists(); + } catch (IOException | CustomResponseException ignored) { + return false; + } } /** @@ -240,7 +296,7 @@ public boolean indexExists() { * @return state of ES index */ public IndexStates getIndexState() { - return IndexStates.NO_STATE; + return ServiceManager.getIndexingService().getIndexState(); } /** @@ -252,7 +308,7 @@ public IndexStates getIndexState() { * @return indexing state of the given object type. */ public IndexStates getObjectIndexState(ObjectType objectType) { - return IndexStates.NO_STATE; + return ServiceManager.getIndexingService().getObjectIndexState(objectType); } /** @@ -264,7 +320,7 @@ public IndexStates getObjectIndexState(ObjectType objectType) { * @return static variable for global indexing state */ public IndexStates getAllObjectsIndexingState() { - return IndexStates.NO_STATE; + return ServiceManager.getIndexingService().getAllObjectsIndexingState(); } /** @@ -273,7 +329,7 @@ public IndexStates getAllObjectsIndexingState() { * @return array of object type values */ public ObjectType[] getObjectTypes() { - return OBJECT_TYPES.toArray(new ObjectType[0]); + return objectTypes.toArray(new ObjectType[0]); } /** @@ -281,8 +337,13 @@ public ObjectType[] getObjectTypes() { * * @return JSONArray containing objects type constants. */ + @SuppressWarnings("unused") public JsonArray getObjectTypesAsJson() { - return Json.createArrayBuilder().build(); + JsonArrayBuilder objectsTypesJson = Json.createArrayBuilder(); + for (ObjectType objectType : objectTypes) { + objectsTypesJson.add(objectType.toString()); + } + return objectsTypesJson.build(); } /** @@ -300,4 +361,11 @@ public ObjectType getNoneType() { public void updateView() { Ajax.update("@all"); } + + /** + * Cancel indexing upon user request. + */ + public void cancelIndexing() { + ServiceManager.getIndexingService().cancelIndexing(); + } } diff --git a/Kitodo/src/main/java/org/kitodo/production/helper/IndexWorker.java b/Kitodo/src/main/java/org/kitodo/production/helper/IndexWorker.java index 92e2e2db9bc..a293e787550 100644 --- a/Kitodo/src/main/java/org/kitodo/production/helper/IndexWorker.java +++ b/Kitodo/src/main/java/org/kitodo/production/helper/IndexWorker.java @@ -55,7 +55,7 @@ public void run() { int maxBatch = indexWorkerStatus.getMaxBatch(); int nextBatch = indexWorkerStatus.getAndIncrementNextBatch(); - while (!indexWorkerStatus.hasFailed() && nextBatch < maxBatch) { + while (!indexWorkerStatus.hasFailed() && !indexWorkerStatus.isCanceled() && nextBatch < maxBatch) { // nextBatch is a valid batch that needs to be processed int attempt = 1; diff --git a/Kitodo/src/main/java/org/kitodo/production/helper/IndexWorkerStatus.java b/Kitodo/src/main/java/org/kitodo/production/helper/IndexWorkerStatus.java index b8d1c061343..a99b1567de7 100644 --- a/Kitodo/src/main/java/org/kitodo/production/helper/IndexWorkerStatus.java +++ b/Kitodo/src/main/java/org/kitodo/production/helper/IndexWorkerStatus.java @@ -34,6 +34,11 @@ public class IndexWorkerStatus { */ private final AtomicBoolean failed = new AtomicBoolean(false); + /** + * Whether the indexing process was canceled by a user. + */ + private final AtomicBoolean canceled = new AtomicBoolean(false); + /** * Initialize index worker status. * @@ -76,4 +81,20 @@ public boolean hasFailed() { public void markAsFailed() { this.failed.set(true); } + + /** + * Marks the index status as canceld by a user. + */ + public void markAsCanceled() { + this.canceled.set(true); + } + + /** + * Return whether indexing process was canceled by a user. + * + * @return true if canceled + */ + public boolean isCanceled() { + return this.canceled.get(); + } } diff --git a/Kitodo/src/main/java/org/kitodo/production/services/index/IndexManagmentThread.java b/Kitodo/src/main/java/org/kitodo/production/services/index/IndexManagmentThread.java index 6828f573477..2b9e38f9d1f 100644 --- a/Kitodo/src/main/java/org/kitodo/production/services/index/IndexManagmentThread.java +++ b/Kitodo/src/main/java/org/kitodo/production/services/index/IndexManagmentThread.java @@ -56,13 +56,13 @@ public void run() { if (Objects.isNull(this.objectType) || currentType.equals(objectType)) { try { IndexWorkerStatus status = indexingService.runIndexing(currentType, context, indexAllObjects); - if (Objects.nonNull(status) && (status.hasFailed())) { - // stop indexing due to failure + if (Objects.nonNull(status) && (status.isCanceled() || status.hasFailed())) { + // stop indexing due to failure or cancel break; } } catch (DataException | CustomResponseException | DAOException | RuntimeException e) { logger.error(e); - Helper.setErrorMessage(e.getLocalizedMessage(), logger, e); + Helper.setErrorMessage(e.getLocalizedMessage(), IndexingService.getLogger(), e); } } } diff --git a/Kitodo/src/main/java/org/kitodo/production/services/index/IndexingService.java b/Kitodo/src/main/java/org/kitodo/production/services/index/IndexingService.java index 11a7d5a7ffa..134e83f8290 100644 --- a/Kitodo/src/main/java/org/kitodo/production/services/index/IndexingService.java +++ b/Kitodo/src/main/java/org/kitodo/production/services/index/IndexingService.java @@ -350,7 +350,7 @@ private void waitWhileIndexing(ObjectType type, List> futures, PushCon while (true) { // check whether all jobs are done boolean done = true; - boolean failed = indexWorkerStatus.hasFailed(); + boolean failed = indexWorkerStatus.hasFailed() || indexWorkerStatus.isCanceled(); for (Future future : futures) { if (!future.isDone()) { done = false; @@ -638,4 +638,22 @@ void setIndexingAll(boolean indexing) { void resetCurrentIndexState() { currentIndexState = ObjectType.NONE; } + + /** + * Cancels indexing upon user request. + */ + public void cancelIndexing() { + if (Objects.nonNull(indexWorkerStatus)) { + indexWorkerStatus.markAsCanceled(); + } + } + + /** + * Get logger. + * + * @return value of logger + */ + public static Logger getLogger() { + return logger; + } } diff --git a/Kitodo/src/main/webapp/pages/system.xhtml b/Kitodo/src/main/webapp/pages/system.xhtml index 6fbec921da8..c1633aa215e 100644 --- a/Kitodo/src/main/webapp/pages/system.xhtml +++ b/Kitodo/src/main/webapp/pages/system.xhtml @@ -43,10 +43,6 @@ rendered="#{SecurityAccessController.hasAuthorityToViewTermsPage()}"> - - - diff --git a/Kitodo/src/test/java/org/kitodo/selenium/testframework/enums/TabIndex.java b/Kitodo/src/test/java/org/kitodo/selenium/testframework/enums/TabIndex.java index 86ac024519d..fdd677d071d 100644 --- a/Kitodo/src/test/java/org/kitodo/selenium/testframework/enums/TabIndex.java +++ b/Kitodo/src/test/java/org/kitodo/selenium/testframework/enums/TabIndex.java @@ -55,8 +55,8 @@ public enum TabIndex { // system page TASKMANAGER(0), - INDEXING(2), - MIGRATION(3), + INDEXING(null), + MIGRATION(2), // user configuration SETTINGS(0), @@ -67,9 +67,9 @@ public enum TabIndex { IMPORT_CONFIGURATION_MAPPING_FILES(1); - private final int index; + private final Integer index; - TabIndex(final int newIndex) { + TabIndex(final Integer newIndex) { index = newIndex; } From ec11444f52a5652298be319f33610d9ee69228c9 Mon Sep 17 00:00:00 2001 From: Matthias Ronge Date: Mon, 11 Mar 2024 10:51:17 +0100 Subject: [PATCH 6/9] Revert "Fix tabbing for Selenium tests" This reverts commit 67d5b84301872aed03563b839f8b61abe45bdbb1. --- .../org/kitodo/selenium/testframework/enums/TabIndex.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Kitodo/src/test/java/org/kitodo/selenium/testframework/enums/TabIndex.java b/Kitodo/src/test/java/org/kitodo/selenium/testframework/enums/TabIndex.java index fdd677d071d..86ac024519d 100644 --- a/Kitodo/src/test/java/org/kitodo/selenium/testframework/enums/TabIndex.java +++ b/Kitodo/src/test/java/org/kitodo/selenium/testframework/enums/TabIndex.java @@ -55,8 +55,8 @@ public enum TabIndex { // system page TASKMANAGER(0), - INDEXING(null), - MIGRATION(2), + INDEXING(2), + MIGRATION(3), // user configuration SETTINGS(0), @@ -67,9 +67,9 @@ public enum TabIndex { IMPORT_CONFIGURATION_MAPPING_FILES(1); - private final Integer index; + private final int index; - TabIndex(final Integer newIndex) { + TabIndex(final int newIndex) { index = newIndex; } From 18f0b9ccbfb1e63f256b502e1bb51f4a8a7b11b7 Mon Sep 17 00:00:00 2001 From: Matthias Ronge Date: Mon, 11 Mar 2024 10:51:31 +0100 Subject: [PATCH 7/9] Revert "Remove indexing page and Index Must Be Updated Warning" This reverts commit 2f44cb8429d1c496059354c7c02766b093e79dfc. --- .../controller/SecurityAccessController.java | 9 +++ .../kitodo/production/forms/IndexingForm.java | 9 ++- .../kitodo/production/forms/LoginForm.java | 18 ++++- .../security/CustomLoginSuccessHandler.java | 25 ++++--- .../services/index/IndexingService.java | 5 ++ .../resources/messages/messages_de.properties | 7 ++ .../resources/messages/messages_en.properties | 7 ++ .../resources/messages/messages_es.properties | 7 ++ .../includes/base/indexWarningDialog.xhtml | 67 +++++++++++++++++++ Kitodo/src/main/webapp/pages/checks.xhtml | 1 + Kitodo/src/main/webapp/pages/system.xhtml | 4 ++ 11 files changed, 147 insertions(+), 12 deletions(-) create mode 100644 Kitodo/src/main/webapp/WEB-INF/templates/includes/base/indexWarningDialog.xhtml diff --git a/Kitodo/src/main/java/org/kitodo/production/controller/SecurityAccessController.java b/Kitodo/src/main/java/org/kitodo/production/controller/SecurityAccessController.java index 4973e266ff9..72eb057e8e4 100644 --- a/Kitodo/src/main/java/org/kitodo/production/controller/SecurityAccessController.java +++ b/Kitodo/src/main/java/org/kitodo/production/controller/SecurityAccessController.java @@ -726,6 +726,15 @@ public boolean hasAuthorityToViewSystemPage() { || securityAccessService.hasAuthorityToViewMigrationPage(); } + /** + * Check if current user has authority to view index page. + * + * @return true if user has authority to 'viewIndex' page. + */ + public boolean hasAuthorityToViewIndexPage() { + return securityAccessService.hasAuthorityToViewIndexPage(); + } + /** * Check if current user has authority to view task manager page. * diff --git a/Kitodo/src/main/java/org/kitodo/production/forms/IndexingForm.java b/Kitodo/src/main/java/org/kitodo/production/forms/IndexingForm.java index defe199704e..34e883ea90d 100644 --- a/Kitodo/src/main/java/org/kitodo/production/forms/IndexingForm.java +++ b/Kitodo/src/main/java/org/kitodo/production/forms/IndexingForm.java @@ -359,7 +359,14 @@ public ObjectType getNoneType() { * Update the view. */ public void updateView() { - Ajax.update("@all"); + try { + if (ServiceManager.getIndexingService().isIndexCorrupted()) { + Helper.setErrorMessage("indexOutOfDate"); + } + Ajax.update("@all"); + } catch (DataException | DAOException e) { + Helper.setErrorMessage(e.getMessage()); + } } /** diff --git a/Kitodo/src/main/java/org/kitodo/production/forms/LoginForm.java b/Kitodo/src/main/java/org/kitodo/production/forms/LoginForm.java index ec3494cc75f..32aab0b3fee 100644 --- a/Kitodo/src/main/java/org/kitodo/production/forms/LoginForm.java +++ b/Kitodo/src/main/java/org/kitodo/production/forms/LoginForm.java @@ -99,16 +99,21 @@ public void performPostLoginChecks() throws DataException, DAOException, IOExcep ExternalContext context = FacesContext.getCurrentInstance().getExternalContext(); SessionClientController controller = new SessionClientController(); + PrimeFaces.current().executeScript("PF('indexWarningDialog').hide();"); if (ServiceManager.getSecurityAccessService().hasAuthorityToEditIndex()) { if (controller.getAvailableClientsOfCurrentUser().size() > 1 && Objects.isNull(controller.getCurrentSessionClient())) { controller.showClientSelectDialog(); + } else if (ServiceManager.getIndexingService().isIndexCorrupted()) { + context.redirect(INDEXING_PAGE + determineIndexingTab()); } else { redirect(context); } } else { - if (controller.getAvailableClientsOfCurrentUser().size() > 1 + if (ServiceManager.getIndexingService().isIndexCorrupted()) { + PrimeFaces.current().executeScript("PF('indexWarningDialog').show();"); + } else if (controller.getAvailableClientsOfCurrentUser().size() > 1 && Objects.isNull(controller.getCurrentSessionClient())) { controller.showClientSelectDialog(); } else { @@ -126,4 +131,15 @@ private void redirect(ExternalContext context) throws IOException { context.redirect(context.getRequestContextPath() + originalRequest); } } + + private int determineIndexingTab() { + int indexingTabIndex = 2; + if (!securityAccessService.hasAuthorityToViewTermsPage()) { + indexingTabIndex -= 1; + } + if (!securityAccessService.hasAuthorityToViewTaskManagerPage()) { + indexingTabIndex -= 1; + } + return indexingTabIndex; + } } diff --git a/Kitodo/src/main/java/org/kitodo/production/security/CustomLoginSuccessHandler.java b/Kitodo/src/main/java/org/kitodo/production/security/CustomLoginSuccessHandler.java index 3e85052c03c..c8f8dfbf6e3 100644 --- a/Kitodo/src/main/java/org/kitodo/production/security/CustomLoginSuccessHandler.java +++ b/Kitodo/src/main/java/org/kitodo/production/security/CustomLoginSuccessHandler.java @@ -45,17 +45,22 @@ public class CustomLoginSuccessHandler implements AuthenticationSuccessHandler { public void onAuthenticationSuccess(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, Authentication authentication) throws IOException { - SessionClientController controller = new SessionClientController(); - if (controller.getAvailableClientsOfCurrentUser().size() > 1) { - // redirect to empty landing page, where dialogs are displayed depending on both checks! - redirectStrategy.sendRedirect(httpServletRequest, httpServletResponse, EMPTY_LANDING_PAGE); - } else { - if (Objects.nonNull(httpServletRequest.getSession())) { - // calling showClientSelectDialog automatically sets the only one available client here - controller.showClientSelectDialog(); - redirectStrategy.sendRedirect(httpServletRequest, httpServletResponse, - getOriginalRequest(httpServletRequest.getSession().getAttribute(SAVED_REQUEST))); + try { + SessionClientController controller = new SessionClientController(); + if (ServiceManager.getIndexingService().isIndexCorrupted() + || controller.getAvailableClientsOfCurrentUser().size() > 1) { + // redirect to empty landing page, where dialogs are displayed depending on both checks! + redirectStrategy.sendRedirect(httpServletRequest, httpServletResponse, EMPTY_LANDING_PAGE); + } else { + if (Objects.nonNull(httpServletRequest.getSession())) { + // calling showClientSelectDialog automatically sets the only one available client here + controller.showClientSelectDialog(); + redirectStrategy.sendRedirect(httpServletRequest, httpServletResponse, + getOriginalRequest(httpServletRequest.getSession().getAttribute(SAVED_REQUEST))); + } } + } catch (DataException | DAOException e) { + logger.error(e.getLocalizedMessage()); } } diff --git a/Kitodo/src/main/java/org/kitodo/production/services/index/IndexingService.java b/Kitodo/src/main/java/org/kitodo/production/services/index/IndexingService.java index 134e83f8290..547614e0f51 100644 --- a/Kitodo/src/main/java/org/kitodo/production/services/index/IndexingService.java +++ b/Kitodo/src/main/java/org/kitodo/production/services/index/IndexingService.java @@ -182,6 +182,11 @@ public Map getCountDatabaseObjects() { return countDatabaseObjects; } + public boolean isIndexCorrupted() throws DAOException, DataException { + updateCounts(); + return getTotalCount() != getAllIndexed(); + } + /** * Return the number of all objects processed during the current indexing * progress. diff --git a/Kitodo/src/main/resources/messages/messages_de.properties b/Kitodo/src/main/resources/messages/messages_de.properties index 41552d09a55..90d592319a5 100644 --- a/Kitodo/src/main/resources/messages/messages_de.properties +++ b/Kitodo/src/main/resources/messages/messages_de.properties @@ -651,6 +651,7 @@ imprint=Impressum imprintDefaultText=Das Impressum f\u00FCr dieses System wurde noch nicht hinterlegt. indexedEntries=Indexierte Eintr\u00E4ge indexing=Indexierung +indexOutOfDate=Der Index muss aktualisiert werden! insert=Einf\u00FCgen insertAsUncounted=Als unnummeriert einf\u00FCgen insertHere=hier einf\u00FCgen @@ -1092,6 +1093,12 @@ structuralElement=Strukturelement structureElementAdd=Strukturelement hinzuf\u00FCgen structureElementDelete=Strukturelement l\u00F6schen system=System +systemComeBackLaterMessage=Bitte versuchen Sie es sp\u00E4ter erneut! +systemErrorHeader=Systemfehler +systemErrorInformAdminMessage=Bitte informieren Sie einen Administrator! +systemErrorMessage=Es ist ein Fehler im System aufgetreten. +systemMaintenanceHeader=Systemwartung +systemMaintenanceMessage=Das System wird derzeit gewartet. table=Tabelle tableSize=Tabellengr\u00F6\u00DFe task=Aufgabe diff --git a/Kitodo/src/main/resources/messages/messages_en.properties b/Kitodo/src/main/resources/messages/messages_en.properties index 2a8d58a3c7c..a12c156c25f 100644 --- a/Kitodo/src/main/resources/messages/messages_en.properties +++ b/Kitodo/src/main/resources/messages/messages_en.properties @@ -652,6 +652,7 @@ imprint=Imprint imprintDefaultText=Imprint information have not been configured for this system. indexedEntries=Indexed entries indexing=Indexing +indexOutOfDate=The search index needs to be updated! insert=Insert insertAsUncounted=Insert as uncounted insertHere=insert here @@ -1093,6 +1094,12 @@ structuralElement=Structural element structureElementAdd=Add docstruct structureElementDelete=Delete docstruct system=System +systemComeBackLaterMessage=Please try again later! +systemErrorHeader=System error +systemErrorInformAdminMessage=Please inform an administrator! +systemErrorMessage=A system error occurred. +systemMaintenanceHeader=System maintenance +systemMaintenanceMessage=The system is currently under maintenance. table=Table tableSize=Table size task=Task diff --git a/Kitodo/src/main/resources/messages/messages_es.properties b/Kitodo/src/main/resources/messages/messages_es.properties index bde18535888..0effd29d4bc 100644 --- a/Kitodo/src/main/resources/messages/messages_es.properties +++ b/Kitodo/src/main/resources/messages/messages_es.properties @@ -645,6 +645,7 @@ imprint=Pie de imprenta imprintDefaultText=La huella de este sistema aún no se ha almacenado. indexedEntries=Entradas indexadas indexing=Indexación +indexOutOfDate=Hay que actualizar el índice. insert=Insertar insertAsUncounted=Insertar como no numerado insertHere=Insertar aquí @@ -1078,6 +1079,12 @@ structuralElement=Elemento de la estructura structureElementAdd=Añadir elemento estructural structureElementDelete=Borrar el elemento estructural system=Sistema +systemComeBackLaterMessage=Por favor, inténtelo más tarde. +systemErrorHeader=Error del sistema +systemErrorInformAdminMessage=Por favor, informe a un administrador. +systemErrorMessage=Se ha producido un error en el sistema. +systemMaintenanceHeader=Mantenimiento del sistema +systemMaintenanceMessage=El sistema se encuentra actualmente en fase de mantenimiento. table=Tabla tableSize=Tamaño de la tabla task=Tarea diff --git a/Kitodo/src/main/webapp/WEB-INF/templates/includes/base/indexWarningDialog.xhtml b/Kitodo/src/main/webapp/WEB-INF/templates/includes/base/indexWarningDialog.xhtml new file mode 100644 index 00000000000..ad3307d63db --- /dev/null +++ b/Kitodo/src/main/webapp/WEB-INF/templates/includes/base/indexWarningDialog.xhtml @@ -0,0 +1,67 @@ + + + + + + +

#{msgs.systemMaintenanceHeader}

+
+ #{msgs.systemMaintenanceMessage}
+ #{msgs.systemComeBackLaterMessage} +
+
+ +

#{msgs.systemErrorHeader}

+
+ #{msgs.systemErrorMessage}
+ #{msgs.systemErrorInformAdminMessage} +
+
+
+ + + + + + + + + + + +
+
diff --git a/Kitodo/src/main/webapp/pages/checks.xhtml b/Kitodo/src/main/webapp/pages/checks.xhtml index 63b22e67e28..ad043f715cf 100644 --- a/Kitodo/src/main/webapp/pages/checks.xhtml +++ b/Kitodo/src/main/webapp/pages/checks.xhtml @@ -27,6 +27,7 @@ + diff --git a/Kitodo/src/main/webapp/pages/system.xhtml b/Kitodo/src/main/webapp/pages/system.xhtml index c1633aa215e..6fbec921da8 100644 --- a/Kitodo/src/main/webapp/pages/system.xhtml +++ b/Kitodo/src/main/webapp/pages/system.xhtml @@ -43,6 +43,10 @@ rendered="#{SecurityAccessController.hasAuthorityToViewTermsPage()}">
+ + + From 8d662b609d1ed688c14c71fec9b5a818fec05f16 Mon Sep 17 00:00:00 2001 From: Matthias Ronge Date: Mon, 11 Mar 2024 11:00:03 +0100 Subject: [PATCH 8/9] Remove Index Must Be Updated Warning --- .../kitodo/production/forms/IndexingForm.java | 9 +-- .../kitodo/production/forms/LoginForm.java | 7 +- .../security/CustomLoginSuccessHandler.java | 24 ++----- .../services/index/IndexingService.java | 5 -- .../resources/messages/messages_de.properties | 7 -- .../resources/messages/messages_en.properties | 7 -- .../resources/messages/messages_es.properties | 7 -- .../includes/base/indexWarningDialog.xhtml | 67 ------------------- Kitodo/src/main/webapp/pages/checks.xhtml | 1 - 9 files changed, 8 insertions(+), 126 deletions(-) delete mode 100644 Kitodo/src/main/webapp/WEB-INF/templates/includes/base/indexWarningDialog.xhtml diff --git a/Kitodo/src/main/java/org/kitodo/production/forms/IndexingForm.java b/Kitodo/src/main/java/org/kitodo/production/forms/IndexingForm.java index 34e883ea90d..defe199704e 100644 --- a/Kitodo/src/main/java/org/kitodo/production/forms/IndexingForm.java +++ b/Kitodo/src/main/java/org/kitodo/production/forms/IndexingForm.java @@ -359,14 +359,7 @@ public ObjectType getNoneType() { * Update the view. */ public void updateView() { - try { - if (ServiceManager.getIndexingService().isIndexCorrupted()) { - Helper.setErrorMessage("indexOutOfDate"); - } - Ajax.update("@all"); - } catch (DataException | DAOException e) { - Helper.setErrorMessage(e.getMessage()); - } + Ajax.update("@all"); } /** diff --git a/Kitodo/src/main/java/org/kitodo/production/forms/LoginForm.java b/Kitodo/src/main/java/org/kitodo/production/forms/LoginForm.java index 32aab0b3fee..7d7b5fadb10 100644 --- a/Kitodo/src/main/java/org/kitodo/production/forms/LoginForm.java +++ b/Kitodo/src/main/java/org/kitodo/production/forms/LoginForm.java @@ -99,21 +99,16 @@ public void performPostLoginChecks() throws DataException, DAOException, IOExcep ExternalContext context = FacesContext.getCurrentInstance().getExternalContext(); SessionClientController controller = new SessionClientController(); - PrimeFaces.current().executeScript("PF('indexWarningDialog').hide();"); if (ServiceManager.getSecurityAccessService().hasAuthorityToEditIndex()) { if (controller.getAvailableClientsOfCurrentUser().size() > 1 && Objects.isNull(controller.getCurrentSessionClient())) { controller.showClientSelectDialog(); - } else if (ServiceManager.getIndexingService().isIndexCorrupted()) { - context.redirect(INDEXING_PAGE + determineIndexingTab()); } else { redirect(context); } } else { - if (ServiceManager.getIndexingService().isIndexCorrupted()) { - PrimeFaces.current().executeScript("PF('indexWarningDialog').show();"); - } else if (controller.getAvailableClientsOfCurrentUser().size() > 1 + if (controller.getAvailableClientsOfCurrentUser().size() > 1 && Objects.isNull(controller.getCurrentSessionClient())) { controller.showClientSelectDialog(); } else { diff --git a/Kitodo/src/main/java/org/kitodo/production/security/CustomLoginSuccessHandler.java b/Kitodo/src/main/java/org/kitodo/production/security/CustomLoginSuccessHandler.java index c8f8dfbf6e3..4d547b557ca 100644 --- a/Kitodo/src/main/java/org/kitodo/production/security/CustomLoginSuccessHandler.java +++ b/Kitodo/src/main/java/org/kitodo/production/security/CustomLoginSuccessHandler.java @@ -34,9 +34,7 @@ @Component public class CustomLoginSuccessHandler implements AuthenticationSuccessHandler { - private static final Logger logger = LogManager.getLogger(CustomLoginSuccessHandler.class); private static final String DESKTOP_LANDING_PAGE = "/pages/desktop.jsf"; - private static final String EMPTY_LANDING_PAGE = "/pages/checks.jsf"; private static final String SAVED_REQUEST = "SPRING_SECURITY_SAVED_REQUEST"; private static final String OMNIFACES_EVENT = "omnifaces.event"; private final RedirectStrategy redirectStrategy = new DefaultRedirectStrategy(); @@ -45,22 +43,12 @@ public class CustomLoginSuccessHandler implements AuthenticationSuccessHandler { public void onAuthenticationSuccess(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, Authentication authentication) throws IOException { - try { - SessionClientController controller = new SessionClientController(); - if (ServiceManager.getIndexingService().isIndexCorrupted() - || controller.getAvailableClientsOfCurrentUser().size() > 1) { - // redirect to empty landing page, where dialogs are displayed depending on both checks! - redirectStrategy.sendRedirect(httpServletRequest, httpServletResponse, EMPTY_LANDING_PAGE); - } else { - if (Objects.nonNull(httpServletRequest.getSession())) { - // calling showClientSelectDialog automatically sets the only one available client here - controller.showClientSelectDialog(); - redirectStrategy.sendRedirect(httpServletRequest, httpServletResponse, - getOriginalRequest(httpServletRequest.getSession().getAttribute(SAVED_REQUEST))); - } - } - } catch (DataException | DAOException e) { - logger.error(e.getLocalizedMessage()); + SessionClientController controller = new SessionClientController(); + if (Objects.nonNull(httpServletRequest.getSession())) { + // calling showClientSelectDialog automatically sets the only one available client here + controller.showClientSelectDialog(); + redirectStrategy.sendRedirect(httpServletRequest, httpServletResponse, + getOriginalRequest(httpServletRequest.getSession().getAttribute(SAVED_REQUEST))); } } diff --git a/Kitodo/src/main/java/org/kitodo/production/services/index/IndexingService.java b/Kitodo/src/main/java/org/kitodo/production/services/index/IndexingService.java index 547614e0f51..134e83f8290 100644 --- a/Kitodo/src/main/java/org/kitodo/production/services/index/IndexingService.java +++ b/Kitodo/src/main/java/org/kitodo/production/services/index/IndexingService.java @@ -182,11 +182,6 @@ public Map getCountDatabaseObjects() { return countDatabaseObjects; } - public boolean isIndexCorrupted() throws DAOException, DataException { - updateCounts(); - return getTotalCount() != getAllIndexed(); - } - /** * Return the number of all objects processed during the current indexing * progress. diff --git a/Kitodo/src/main/resources/messages/messages_de.properties b/Kitodo/src/main/resources/messages/messages_de.properties index 90d592319a5..41552d09a55 100644 --- a/Kitodo/src/main/resources/messages/messages_de.properties +++ b/Kitodo/src/main/resources/messages/messages_de.properties @@ -651,7 +651,6 @@ imprint=Impressum imprintDefaultText=Das Impressum f\u00FCr dieses System wurde noch nicht hinterlegt. indexedEntries=Indexierte Eintr\u00E4ge indexing=Indexierung -indexOutOfDate=Der Index muss aktualisiert werden! insert=Einf\u00FCgen insertAsUncounted=Als unnummeriert einf\u00FCgen insertHere=hier einf\u00FCgen @@ -1093,12 +1092,6 @@ structuralElement=Strukturelement structureElementAdd=Strukturelement hinzuf\u00FCgen structureElementDelete=Strukturelement l\u00F6schen system=System -systemComeBackLaterMessage=Bitte versuchen Sie es sp\u00E4ter erneut! -systemErrorHeader=Systemfehler -systemErrorInformAdminMessage=Bitte informieren Sie einen Administrator! -systemErrorMessage=Es ist ein Fehler im System aufgetreten. -systemMaintenanceHeader=Systemwartung -systemMaintenanceMessage=Das System wird derzeit gewartet. table=Tabelle tableSize=Tabellengr\u00F6\u00DFe task=Aufgabe diff --git a/Kitodo/src/main/resources/messages/messages_en.properties b/Kitodo/src/main/resources/messages/messages_en.properties index a12c156c25f..2a8d58a3c7c 100644 --- a/Kitodo/src/main/resources/messages/messages_en.properties +++ b/Kitodo/src/main/resources/messages/messages_en.properties @@ -652,7 +652,6 @@ imprint=Imprint imprintDefaultText=Imprint information have not been configured for this system. indexedEntries=Indexed entries indexing=Indexing -indexOutOfDate=The search index needs to be updated! insert=Insert insertAsUncounted=Insert as uncounted insertHere=insert here @@ -1094,12 +1093,6 @@ structuralElement=Structural element structureElementAdd=Add docstruct structureElementDelete=Delete docstruct system=System -systemComeBackLaterMessage=Please try again later! -systemErrorHeader=System error -systemErrorInformAdminMessage=Please inform an administrator! -systemErrorMessage=A system error occurred. -systemMaintenanceHeader=System maintenance -systemMaintenanceMessage=The system is currently under maintenance. table=Table tableSize=Table size task=Task diff --git a/Kitodo/src/main/resources/messages/messages_es.properties b/Kitodo/src/main/resources/messages/messages_es.properties index 0effd29d4bc..bde18535888 100644 --- a/Kitodo/src/main/resources/messages/messages_es.properties +++ b/Kitodo/src/main/resources/messages/messages_es.properties @@ -645,7 +645,6 @@ imprint=Pie de imprenta imprintDefaultText=La huella de este sistema aún no se ha almacenado. indexedEntries=Entradas indexadas indexing=Indexación -indexOutOfDate=Hay que actualizar el índice. insert=Insertar insertAsUncounted=Insertar como no numerado insertHere=Insertar aquí @@ -1079,12 +1078,6 @@ structuralElement=Elemento de la estructura structureElementAdd=Añadir elemento estructural structureElementDelete=Borrar el elemento estructural system=Sistema -systemComeBackLaterMessage=Por favor, inténtelo más tarde. -systemErrorHeader=Error del sistema -systemErrorInformAdminMessage=Por favor, informe a un administrador. -systemErrorMessage=Se ha producido un error en el sistema. -systemMaintenanceHeader=Mantenimiento del sistema -systemMaintenanceMessage=El sistema se encuentra actualmente en fase de mantenimiento. table=Tabla tableSize=Tamaño de la tabla task=Tarea diff --git a/Kitodo/src/main/webapp/WEB-INF/templates/includes/base/indexWarningDialog.xhtml b/Kitodo/src/main/webapp/WEB-INF/templates/includes/base/indexWarningDialog.xhtml deleted file mode 100644 index ad3307d63db..00000000000 --- a/Kitodo/src/main/webapp/WEB-INF/templates/includes/base/indexWarningDialog.xhtml +++ /dev/null @@ -1,67 +0,0 @@ - - - - - - -

#{msgs.systemMaintenanceHeader}

-
- #{msgs.systemMaintenanceMessage}
- #{msgs.systemComeBackLaterMessage} -
-
- -

#{msgs.systemErrorHeader}

-
- #{msgs.systemErrorMessage}
- #{msgs.systemErrorInformAdminMessage} -
-
-
- - - - - - - - - - - -
-
diff --git a/Kitodo/src/main/webapp/pages/checks.xhtml b/Kitodo/src/main/webapp/pages/checks.xhtml index ad043f715cf..63b22e67e28 100644 --- a/Kitodo/src/main/webapp/pages/checks.xhtml +++ b/Kitodo/src/main/webapp/pages/checks.xhtml @@ -27,7 +27,6 @@ - From 17bd18f3774ca3055fc0cb255c144cd1fbb75949 Mon Sep 17 00:00:00 2001 From: Matthias Ronge Date: Mon, 11 Mar 2024 11:15:48 +0100 Subject: [PATCH 9/9] Decommission indexing page --- .../kitodo/production/forms/IndexingForm.java | 109 ++++-------------- .../kitodo/production/forms/LoginForm.java | 22 ++-- .../security/CustomLoginSuccessHandler.java | 17 ++- .../production/forms/IndexingFormIT.java | 1 + 4 files changed, 42 insertions(+), 107 deletions(-) diff --git a/Kitodo/src/main/java/org/kitodo/production/forms/IndexingForm.java b/Kitodo/src/main/java/org/kitodo/production/forms/IndexingForm.java index defe199704e..082071e8073 100644 --- a/Kitodo/src/main/java/org/kitodo/production/forms/IndexingForm.java +++ b/Kitodo/src/main/java/org/kitodo/production/forms/IndexingForm.java @@ -11,8 +11,8 @@ package org.kitodo.production.forms; -import java.io.IOException; import java.time.LocalDateTime; +import java.util.Collections; import java.util.List; import java.util.Map; @@ -25,16 +25,8 @@ import javax.json.JsonArray; import javax.json.JsonArrayBuilder; -import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; -import org.kitodo.data.database.exceptions.DAOException; -import org.kitodo.data.elasticsearch.exceptions.CustomResponseException; -import org.kitodo.data.exceptions.DataException; import org.kitodo.production.enums.IndexStates; import org.kitodo.production.enums.ObjectType; -import org.kitodo.production.helper.Helper; -import org.kitodo.production.services.ServiceManager; -import org.kitodo.production.services.index.IndexingService; import org.omnifaces.util.Ajax; @Named @@ -42,7 +34,6 @@ public class IndexingForm { private static final List objectTypes = ObjectType.getIndexableObjectTypes(); - private static final Logger logger = LogManager.getLogger(IndexingForm.class); private static final String POLLING_CHANNEL_NAME = "togglePollingChannel"; private String indexingStartedUser = ""; private LocalDateTime indexingStartedTime = null; @@ -65,11 +56,7 @@ public String getIndexingStartedUser() { * click. */ public void countDatabaseObjects() { - try { - ServiceManager.getIndexingService().countDatabaseObjects(); - } catch (DAOException e) { - Helper.setErrorMessage(e.getLocalizedMessage(), logger, e); - } + throw new UnsupportedOperationException("currently not implemented"); } /** @@ -87,7 +74,7 @@ public LocalDateTime getIndexingStartedTime() { * @return value of countDatabaseObjects */ public Map getCountDatabaseObjects() { - return ServiceManager.getIndexingService().getCountDatabaseObjects(); + return Collections.emptyMap(); } /** @@ -96,7 +83,7 @@ public Map getCountDatabaseObjects() { * @return long number of all items that can be written to the index */ public long getTotalCount() { - return ServiceManager.getIndexingService().getTotalCount(); + return 0; } /** @@ -108,12 +95,7 @@ public long getTotalCount() { * @return number of indexed objects */ public long getNumberOfIndexedObjects(ObjectType objectType) { - try { - return ServiceManager.getIndexingService().getNumberOfIndexedObjects(objectType); - } catch (DataException e) { - Helper.setErrorMessage(e.getLocalizedMessage(), logger, e); - return 0; - } + return 0; } /** @@ -123,12 +105,7 @@ public long getNumberOfIndexedObjects(ObjectType objectType) { * @return long number of all currently indexed objects */ public long getAllIndexed() { - try { - return ServiceManager.getIndexingService().getAllIndexed(); - } catch (DataException | ArithmeticException e) { - Helper.setErrorMessage(e.getLocalizedMessage(), logger, e); - return 0; - } + return 0; } /** @@ -138,13 +115,7 @@ public long getAllIndexed() { * type objects that get indexed */ public void callIndexing(ObjectType type) { - indexingStartedTime = LocalDateTime.now(); - indexingStartedUser = ServiceManager.getUserService().getAuthenticatedUser().getFullName(); - try { - ServiceManager.getIndexingService().startIndexing(pollingChannel, type); - } catch (IllegalStateException e) { - Helper.setErrorMessage(e.getLocalizedMessage(), logger, e); - } + throw new UnsupportedOperationException("currently not implemented"); } /** @@ -154,29 +125,21 @@ public void callIndexing(ObjectType type) { * type objects that get indexed */ public void callIndexingRemaining(ObjectType type) { - indexingStartedTime = LocalDateTime.now(); - indexingStartedUser = ServiceManager.getUserService().getAuthenticatedUser().getFullName(); - try { - ServiceManager.getIndexingService().startIndexingRemaining(pollingChannel, type); - } catch (IllegalStateException e) { - Helper.setErrorMessage(e.getLocalizedMessage(), logger, e); - } + throw new UnsupportedOperationException("currently not implemented"); } /** * Starts the process of indexing all objects to the ElasticSearch index. */ public void startAllIndexing() { - indexingStartedTime = LocalDateTime.now(); - indexingStartedUser = ServiceManager.getUserService().getAuthenticatedUser().getFullName(); - ServiceManager.getIndexingService().startAllIndexing(pollingChannel); + throw new UnsupportedOperationException("currently not implemented"); } /** * Starts the process of indexing all objects to the ElasticSearch index. */ public void startAllIndexingRemaining() { - ServiceManager.getIndexingService().startAllIndexingRemaining(pollingChannel); + throw new UnsupportedOperationException("currently not implemented"); } /** @@ -196,7 +159,7 @@ public int getAllIndexingProgress() { * progress or not */ public boolean indexingInProgress() { - return ServiceManager.getIndexingService().indexingInProgress(); + return false; } /** @@ -208,30 +171,14 @@ public boolean indexingInProgress() { * or not. */ public void createMapping(boolean updatePollingChannel) { - try { - if (updatePollingChannel) { - pollingChannel.send(IndexingService.MAPPING_STARTED_MESSAGE); - } - String mappingStateMessage = ServiceManager.getIndexingService().createMapping(); - if (updatePollingChannel) { - pollingChannel.send(mappingStateMessage); - } - } catch (IOException | CustomResponseException e) { - ServiceManager.getIndexingService().setIndexState(IndexStates.CREATING_MAPPING_FAILED); - if (updatePollingChannel) { - pollingChannel.send(IndexingService.MAPPING_FAILED_MESSAGE); - } - Helper.setErrorMessage(e.getLocalizedMessage(), logger, e); - } + throw new UnsupportedOperationException("currently not implemented"); } /** * Delete whole ElasticSearch index. */ public void deleteIndex() { - pollingChannel.send(IndexingService.DELETION_STARTED_MESSAGE); - String updateMessage = ServiceManager.getIndexingService().deleteIndex(); - pollingChannel.send(updateMessage); + throw new UnsupportedOperationException("currently not implemented"); } /** @@ -241,12 +188,7 @@ public void deleteIndex() { * @return String information about the server */ public String getServerInformation() { - try { - return ServiceManager.getIndexingService().getServerInformation(); - } catch (IOException e) { - Helper.setErrorMessage("elasticSearchNotRunning", logger, e); - return ""; - } + return ""; } /** @@ -258,12 +200,7 @@ public String getServerInformation() { * @return the progress of the current indexing process in percent */ public int getProgress(ObjectType currentType) { - try { - return ServiceManager.getIndexingService().getProgress(currentType, pollingChannel); - } catch (DataException e) { - Helper.setErrorMessage(e.getLocalizedMessage(), logger, e); - return 0; - } + return 0; } /** @@ -272,7 +209,7 @@ public int getProgress(ObjectType currentType) { * @return true if mapping is empty, otherwise false */ public boolean isMappingEmpty() { - return ServiceManager.getIndexingService().isMappingEmpty(); + return false; } /** @@ -281,11 +218,7 @@ public boolean isMappingEmpty() { * @return whether the Elastic Search index exists or not */ public boolean indexExists() { - try { - return ServiceManager.getIndexingService().indexExists(); - } catch (IOException | CustomResponseException ignored) { - return false; - } + return false; } /** @@ -296,7 +229,7 @@ public boolean indexExists() { * @return state of ES index */ public IndexStates getIndexState() { - return ServiceManager.getIndexingService().getIndexState(); + return IndexStates.NO_STATE; } /** @@ -308,7 +241,7 @@ public IndexStates getIndexState() { * @return indexing state of the given object type. */ public IndexStates getObjectIndexState(ObjectType objectType) { - return ServiceManager.getIndexingService().getObjectIndexState(objectType); + return IndexStates.NO_STATE; } /** @@ -320,7 +253,7 @@ public IndexStates getObjectIndexState(ObjectType objectType) { * @return static variable for global indexing state */ public IndexStates getAllObjectsIndexingState() { - return ServiceManager.getIndexingService().getAllObjectsIndexingState(); + return IndexStates.NO_STATE; } /** @@ -366,6 +299,6 @@ public void updateView() { * Cancel indexing upon user request. */ public void cancelIndexing() { - ServiceManager.getIndexingService().cancelIndexing(); + throw new UnsupportedOperationException("currently not implemented"); } } diff --git a/Kitodo/src/main/java/org/kitodo/production/forms/LoginForm.java b/Kitodo/src/main/java/org/kitodo/production/forms/LoginForm.java index 7d7b5fadb10..6ad7026791b 100644 --- a/Kitodo/src/main/java/org/kitodo/production/forms/LoginForm.java +++ b/Kitodo/src/main/java/org/kitodo/production/forms/LoginForm.java @@ -20,6 +20,9 @@ import javax.faces.context.FacesContext; import javax.inject.Named; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; +import org.kitodo.data.database.beans.Client; import org.kitodo.data.database.beans.User; import org.kitodo.data.database.exceptions.DAOException; import org.kitodo.data.exceptions.DataException; @@ -32,9 +35,9 @@ @Named("LoginForm") @SessionScoped public class LoginForm implements Serializable { + private static final Logger logger = LogManager.getLogger(LoginForm.class); private User loggedUser; private boolean firstVisit = true; - private static final String INDEXING_PAGE = "system.jsf?tabIndex="; private static final String DESKTOP_VIEW = "desktop.jsf"; private final SecurityAccessService securityAccessService = ServiceManager.getSecurityAccessService(); @@ -100,20 +103,11 @@ public void performPostLoginChecks() throws DataException, DAOException, IOExcep ExternalContext context = FacesContext.getCurrentInstance().getExternalContext(); SessionClientController controller = new SessionClientController(); - if (ServiceManager.getSecurityAccessService().hasAuthorityToEditIndex()) { - if (controller.getAvailableClientsOfCurrentUser().size() > 1 - && Objects.isNull(controller.getCurrentSessionClient())) { - controller.showClientSelectDialog(); - } else { - redirect(context); - } + if (controller.getAvailableClientsOfCurrentUser().size() > 1 + && Objects.isNull(controller.getCurrentSessionClient())) { + controller.showClientSelectDialog(); } else { - if (controller.getAvailableClientsOfCurrentUser().size() > 1 - && Objects.isNull(controller.getCurrentSessionClient())) { - controller.showClientSelectDialog(); - } else { - redirect(context); - } + redirect(context); } } diff --git a/Kitodo/src/main/java/org/kitodo/production/security/CustomLoginSuccessHandler.java b/Kitodo/src/main/java/org/kitodo/production/security/CustomLoginSuccessHandler.java index 4d547b557ca..3e85052c03c 100644 --- a/Kitodo/src/main/java/org/kitodo/production/security/CustomLoginSuccessHandler.java +++ b/Kitodo/src/main/java/org/kitodo/production/security/CustomLoginSuccessHandler.java @@ -34,7 +34,9 @@ @Component public class CustomLoginSuccessHandler implements AuthenticationSuccessHandler { + private static final Logger logger = LogManager.getLogger(CustomLoginSuccessHandler.class); private static final String DESKTOP_LANDING_PAGE = "/pages/desktop.jsf"; + private static final String EMPTY_LANDING_PAGE = "/pages/checks.jsf"; private static final String SAVED_REQUEST = "SPRING_SECURITY_SAVED_REQUEST"; private static final String OMNIFACES_EVENT = "omnifaces.event"; private final RedirectStrategy redirectStrategy = new DefaultRedirectStrategy(); @@ -44,11 +46,16 @@ public void onAuthenticationSuccess(HttpServletRequest httpServletRequest, HttpS Authentication authentication) throws IOException { SessionClientController controller = new SessionClientController(); - if (Objects.nonNull(httpServletRequest.getSession())) { - // calling showClientSelectDialog automatically sets the only one available client here - controller.showClientSelectDialog(); - redirectStrategy.sendRedirect(httpServletRequest, httpServletResponse, - getOriginalRequest(httpServletRequest.getSession().getAttribute(SAVED_REQUEST))); + if (controller.getAvailableClientsOfCurrentUser().size() > 1) { + // redirect to empty landing page, where dialogs are displayed depending on both checks! + redirectStrategy.sendRedirect(httpServletRequest, httpServletResponse, EMPTY_LANDING_PAGE); + } else { + if (Objects.nonNull(httpServletRequest.getSession())) { + // calling showClientSelectDialog automatically sets the only one available client here + controller.showClientSelectDialog(); + redirectStrategy.sendRedirect(httpServletRequest, httpServletResponse, + getOriginalRequest(httpServletRequest.getSession().getAttribute(SAVED_REQUEST))); + } } } diff --git a/Kitodo/src/test/java/org/kitodo/production/forms/IndexingFormIT.java b/Kitodo/src/test/java/org/kitodo/production/forms/IndexingFormIT.java index 14fbec25d0c..ec142b5b1e6 100644 --- a/Kitodo/src/test/java/org/kitodo/production/forms/IndexingFormIT.java +++ b/Kitodo/src/test/java/org/kitodo/production/forms/IndexingFormIT.java @@ -55,6 +55,7 @@ public static void tearDown() throws Exception { } @Test + @Ignore("currently not implemented") public void shouldCreateMapping() { Assert.assertFalse(indexingForm.indexExists()); indexingForm.createMapping(false);