Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[hibernate search] Remove Index Must Be Updated warning and blank indexing page #5784

Merged
merged 9 commits into from
May 14, 2024
118 changes: 22 additions & 96 deletions Kitodo/src/main/java/org/kitodo/production/forms/IndexingForm.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -25,24 +25,15 @@
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<ObjectType> 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;
Expand All @@ -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");
}

/**
Expand All @@ -87,7 +74,7 @@ public LocalDateTime getIndexingStartedTime() {
* @return value of countDatabaseObjects
*/
public Map<ObjectType, Integer> getCountDatabaseObjects() {
return ServiceManager.getIndexingService().getCountDatabaseObjects();
return Collections.emptyMap();
}

/**
Expand All @@ -96,7 +83,7 @@ public Map<ObjectType, Integer> getCountDatabaseObjects() {
* @return long number of all items that can be written to the index
*/
public long getTotalCount() {
return ServiceManager.getIndexingService().getTotalCount();
return 0;
}

/**
Expand All @@ -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;
}

/**
Expand All @@ -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;
}

/**
Expand All @@ -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");
}

/**
Expand All @@ -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");
}

/**
Expand All @@ -196,7 +159,7 @@ public int getAllIndexingProgress() {
* progress or not
*/
public boolean indexingInProgress() {
return ServiceManager.getIndexingService().indexingInProgress();
return false;
}

/**
Expand All @@ -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");
}

/**
Expand All @@ -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 "";
}

/**
Expand All @@ -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;
}

/**
Expand All @@ -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;
}

/**
Expand All @@ -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;
}

/**
Expand All @@ -296,7 +229,7 @@ public boolean indexExists() {
* @return state of ES index
*/
public IndexStates getIndexState() {
return ServiceManager.getIndexingService().getIndexState();
return IndexStates.NO_STATE;
}

/**
Expand All @@ -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;
}

/**
Expand All @@ -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;
}

/**
Expand Down Expand Up @@ -359,20 +292,13 @@ 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");
}

/**
* Cancel indexing upon user request.
*/
public void cancelIndexing() {
ServiceManager.getIndexingService().cancelIndexing();
throw new UnsupportedOperationException("currently not implemented");
}
}
27 changes: 8 additions & 19 deletions Kitodo/src/main/java/org/kitodo/production/forms/LoginForm.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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();

Expand Down Expand Up @@ -99,26 +102,12 @@ 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);
}
if (controller.getAvailableClientsOfCurrentUser().size() > 1
&& Objects.isNull(controller.getCurrentSessionClient())) {
controller.showClientSelectDialog();
} else {
if (ServiceManager.getIndexingService().isIndexCorrupted()) {
PrimeFaces.current().executeScript("PF('indexWarningDialog').show();");
} else if (controller.getAvailableClientsOfCurrentUser().size() > 1
&& Objects.isNull(controller.getCurrentSessionClient())) {
controller.showClientSelectDialog();
} else {
redirect(context);
}
redirect(context);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -182,11 +182,6 @@ public Map<ObjectType, Integer> 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.
Expand Down
Loading