Skip to content

Commit

Permalink
Decommission indexing page -- test
Browse files Browse the repository at this point in the history
  • Loading branch information
matthias-ronge committed Mar 11, 2024
1 parent 8d662b6 commit da5d343
Show file tree
Hide file tree
Showing 2 changed files with 87 additions and 83 deletions.
169 changes: 86 additions & 83 deletions Kitodo/src/main/java/org/kitodo/production/forms/IndexingForm.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

import java.io.IOException;
import java.time.LocalDateTime;
import java.util.Collections;
import java.util.List;
import java.util.Map;

Expand All @@ -28,13 +29,9 @@
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
Expand Down Expand Up @@ -65,11 +62,11 @@ public String getIndexingStartedUser() {
* click.
*/
public void countDatabaseObjects() {
try {
ServiceManager.getIndexingService().countDatabaseObjects();
} catch (DAOException e) {
Helper.setErrorMessage(e.getLocalizedMessage(), logger, e);
}
// try {
// ServiceManager.getIndexingService().countDatabaseObjects();
// } catch (DAOException e) {
// Helper.setErrorMessage(e.getLocalizedMessage(), logger, e);
// }
}

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

/**
Expand All @@ -96,7 +94,8 @@ 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 ServiceManager.getIndexingService().getTotalCount();
return 0;
}

/**
Expand All @@ -108,12 +107,13 @@ 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;
}
// try {
// return ServiceManager.getIndexingService().getNumberOfIndexedObjects(objectType);
// } catch (DataException e) {
// Helper.setErrorMessage(e.getLocalizedMessage(), logger, e);
// return 0;
// }
return 0;
}

/**
Expand All @@ -123,12 +123,13 @@ 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;
}
// try {
// return ServiceManager.getIndexingService().getAllIndexed();
// } catch (DataException | ArithmeticException e) {
// Helper.setErrorMessage(e.getLocalizedMessage(), logger, e);
// return 0;
// }
return 0;
}

/**
Expand All @@ -138,13 +139,13 @@ 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);
}
// 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 @@ -154,29 +155,29 @@ 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);
}
// 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() {
indexingStartedTime = LocalDateTime.now();
indexingStartedUser = ServiceManager.getUserService().getAuthenticatedUser().getFullName();
ServiceManager.getIndexingService().startAllIndexing(pollingChannel);
// 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() {
ServiceManager.getIndexingService().startAllIndexingRemaining(pollingChannel);
// ServiceManager.getIndexingService().startAllIndexingRemaining(pollingChannel);
}

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

/**
Expand All @@ -208,30 +210,30 @@ 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);
}
// 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() {
pollingChannel.send(IndexingService.DELETION_STARTED_MESSAGE);
String updateMessage = ServiceManager.getIndexingService().deleteIndex();
pollingChannel.send(updateMessage);
// pollingChannel.send(IndexingService.DELETION_STARTED_MESSAGE);
// String updateMessage = ServiceManager.getIndexingService().deleteIndex();
// pollingChannel.send(updateMessage);
}

/**
Expand All @@ -241,12 +243,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,21 +255,23 @@ 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;
}
// try {
// return ServiceManager.getIndexingService().getProgress(currentType, pollingChannel);
// } catch (DataException e) {
// Helper.setErrorMessage(e.getLocalizedMessage(), logger, e);
// return 0;
// }
return 0;
}

/**
* Check if current mapping is empty.
*
* @return true if mapping is empty, otherwise false
*/
public boolean isMappingEmpty() {
return ServiceManager.getIndexingService().isMappingEmpty();
public Boolean isMappingEmpty() {
// return ServiceManager.getIndexingService().isMappingEmpty();
return null;
}

/**
Expand All @@ -281,11 +280,12 @@ 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;
}
// try {
// return ServiceManager.getIndexingService().indexExists();
// } catch (IOException | CustomResponseException ignored) {
// return false;
// }
return false;
}

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

/**
Expand All @@ -308,7 +309,8 @@ public IndexStates getIndexState() {
* @return indexing state of the given object type.
*/
public IndexStates getObjectIndexState(ObjectType objectType) {
return ServiceManager.getIndexingService().getObjectIndexState(objectType);
// return ServiceManager.getIndexingService().getObjectIndexState(objectType);
return IndexStates.NO_STATE;
}

/**
Expand All @@ -320,7 +322,8 @@ public IndexStates getObjectIndexState(ObjectType objectType) {
* @return static variable for global indexing state
*/
public IndexStates getAllObjectsIndexingState() {
return ServiceManager.getIndexingService().getAllObjectsIndexingState();
// return ServiceManager.getIndexingService().getAllObjectsIndexingState();
return IndexStates.NO_STATE;
}

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

0 comments on commit da5d343

Please sign in to comment.