Skip to content

Commit

Permalink
Revert "Bring back indexing page"
Browse files Browse the repository at this point in the history
This reverts commit 51d19ed.
  • Loading branch information
matthias-ronge committed Mar 11, 2024
1 parent 51d19ed commit 777bbf9
Show file tree
Hide file tree
Showing 8 changed files with 150 additions and 56 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand Down
136 changes: 102 additions & 34 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 @@ -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<ObjectType> objectTypes = ObjectType.getIndexableObjectTypes();
private static final Logger logger = LogManager.getLogger(IndexingForm.class);
private static final String POLLING_CHANNEL_NAME = "togglePollingChannel";
private static final List<ObjectType> 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.
*
Expand All @@ -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);
}
}

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

/**
Expand All @@ -273,16 +329,21 @@ 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]);
}

/**
* Return object types as JSONArray.
*
* @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();
}

/**
Expand All @@ -300,4 +361,11 @@ public ObjectType getNoneType() {
public void updateView() {
Ajax.update("@all");
}

/**
* Cancel indexing upon user request.
*/
public void cancelIndexing() {
ServiceManager.getIndexingService().cancelIndexing();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand Down Expand Up @@ -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();
}
}
Loading

0 comments on commit 777bbf9

Please sign in to comment.