- *
- * 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.data.elasticsearch.api;
-
-import java.util.List;
-import java.util.Map;
-
-/**
- * Interface for serving types which are added to the index.
- *
- *
- * Note: MySQL -> Databases -> Tables -> Columns/Rows ElasticSearch -> Indices
- * -> Types -> Documents with Properties
- */
-public interface TypeInterface {
-
- Map createDocument(T baseIndexedBean);
-
- Map> createDocuments(List baseIndexedBeans);
-}
diff --git a/Kitodo-DataManagement/src/main/java/org/kitodo/data/elasticsearch/index/IndexRestClient.java b/Kitodo-DataManagement/src/main/java/org/kitodo/data/elasticsearch/index/IndexRestClient.java
deleted file mode 100644
index c6e0b7f2460..00000000000
--- a/Kitodo-DataManagement/src/main/java/org/kitodo/data/elasticsearch/index/IndexRestClient.java
+++ /dev/null
@@ -1,204 +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.data.elasticsearch.index;
-
-import java.io.IOException;
-import java.util.Map;
-import java.util.Objects;
-
-import javax.ws.rs.HttpMethod;
-
-import org.apache.http.HttpEntity;
-import org.apache.http.entity.ContentType;
-import org.apache.http.nio.entity.NStringEntity;
-import org.elasticsearch.action.bulk.BulkRequest;
-import org.elasticsearch.action.bulk.BulkResponse;
-import org.elasticsearch.action.delete.DeleteRequest;
-import org.elasticsearch.action.index.IndexRequest;
-import org.elasticsearch.action.index.IndexResponse;
-import org.elasticsearch.action.support.WriteRequest;
-import org.elasticsearch.client.Request;
-import org.elasticsearch.client.RequestOptions;
-import org.elasticsearch.client.Response;
-import org.elasticsearch.client.ResponseException;
-import org.kitodo.data.elasticsearch.KitodoRestClient;
-import org.kitodo.data.elasticsearch.exceptions.CustomResponseException;
-import org.kitodo.data.exceptions.DataException;
-
-/**
- * Implementation of ElasticSearch REST Client for index package.
- */
-public class IndexRestClient extends KitodoRestClient {
-
- /**
- * IndexRestClient singleton.
- */
- private static volatile IndexRestClient instance = null;
- private final Object lock = new Object();
-
- private IndexRestClient() {
- }
-
- /**
- * Return singleton variable of type IndexRestClient.
- *
- * @return unique instance of IndexRestClient
- */
- public static IndexRestClient getInstance() {
- IndexRestClient localReference = instance;
- if (Objects.isNull(localReference)) {
- synchronized (IndexRestClient.class) {
- localReference = instance;
- if (Objects.isNull(localReference)) {
- localReference = new IndexRestClient();
- localReference.initiateClient();
- instance = localReference;
- }
- }
- }
- return localReference;
- }
-
- /**
- * Add document to the index. This method will be used for add or update of
- * single document.
- *
- * @param type
- * for which request is performed
- * @param entity
- * with document which is going to be indexed
- * @param id
- * of document - equal to the id from table in database
- * @param forceRefresh
- * force index refresh - if true, time of execution is longer but
- * object is right after that available for display
- */
- public void addDocument(String type, Map entity, Integer id, boolean forceRefresh)
- throws IOException, CustomResponseException {
- IndexRequest indexRequest = new IndexRequest(this.indexBase + "_" + type).source(entity);
- indexRequest.id(String.valueOf(id));
- if (forceRefresh) {
- indexRequest.setRefreshPolicy(WriteRequest.RefreshPolicy.IMMEDIATE);
- }
-
- IndexResponse indexResponse = highLevelClient.index(indexRequest, RequestOptions.DEFAULT);
- processStatusCode(indexResponse.status());
- }
-
- /**
- * Add list of documents to the index. This method will be used for add whole
- * table to the index. It performs asynchronous request.
- *
- * @param type
- * for which request is performed
- * @param documentsToIndex
- * list of json documents to the index
- */
- void addTypeSync(String type, Map> documentsToIndex) throws CustomResponseException {
- BulkRequest bulkRequest = prepareBulkRequest(type, documentsToIndex);
-
- try {
- BulkResponse bulkResponse = highLevelClient.bulk(bulkRequest, RequestOptions.DEFAULT);
- if (bulkResponse.hasFailures()) {
- throw new CustomResponseException(bulkResponse.buildFailureMessage());
- }
- } catch (IOException e) {
- throw new CustomResponseException(e);
- }
- }
-
- /**
- * Add list of documents to the index. This method will be used for add whole
- * table to the index. It performs asynchronous request.
- *
- * @param type
- * for which request is performed
- * @param documentsToIndex
- * list of json documents to the index
- */
- void addTypeAsync(String type, Map> documentsToIndex) {
- BulkRequest bulkRequest = prepareBulkRequest(type, documentsToIndex);
-
- ResponseListener responseListener = new ResponseListener(type, documentsToIndex.size());
- highLevelClient.bulkAsync(bulkRequest, RequestOptions.DEFAULT, responseListener);
-
- synchronized (lock) {
- while (Objects.isNull(responseListener.getBulkResponse())) {
- try {
- lock.wait(1000);
- } catch (InterruptedException e) {
- Thread.currentThread().interrupt();
- break;
- }
- }
- }
- }
-
- /**
- * Delete document from type specific index.
- *
- * @param type
- * for which request is performed
- * @param id
- * of the document
- * @param forceRefresh
- * force index refresh - if true, time of execution is longer but
- * object is right after that available for display
- */
- void deleteDocument(String type, Integer id, boolean forceRefresh) throws CustomResponseException, DataException {
- DeleteRequest deleteRequest = new DeleteRequest(this.indexBase + "_" + type);
- deleteRequest.id(String.valueOf(id));
- if (forceRefresh) {
- deleteRequest.setRefreshPolicy(WriteRequest.RefreshPolicy.IMMEDIATE);
- }
-
- try {
- highLevelClient.delete(deleteRequest, RequestOptions.DEFAULT);
- } catch (ResponseException e) {
- handleResponseException(e);
- } catch (IOException e) {
- throw new DataException(e);
- }
- }
-
- /**
- * Enable sorting by text field.
- *
- * @param field
- * as String
- * @param mappingType
- * as String
- */
- public void enableSortingByTextField(String field, String mappingType) throws IOException, CustomResponseException {
- String query = "{\n \"properties\": {\n\"" + field + "\": {\n" + " \"type\": \"text\",\n"
- + " \"fielddata\": true,\n" + " \"fields\": {\n" + " \"raw\": {\n"
- + " \"type\": \"text\",\n" + " \"index\": false}\n" + " }\n" + " }}}";
- HttpEntity entity = new NStringEntity(query, ContentType.APPLICATION_JSON);
- Request request = new Request(HttpMethod.PUT,
- "/" + this.getIndexBase() + "_" + mappingType + "/_mappings");
- request.setEntity(entity);
- Response indexResponse = client.performRequest(request);
- processStatusCode(indexResponse.getStatusLine());
- }
-
- private BulkRequest prepareBulkRequest(String type, Map> documentsToIndex) {
- BulkRequest bulkRequest = new BulkRequest();
-
- for (Map.Entry> entry : documentsToIndex.entrySet()) {
- IndexRequest indexRequest = new IndexRequest(this.indexBase + "_" + type);
- indexRequest.id(String.valueOf(entry.getKey()));
- bulkRequest.add(indexRequest.source(entry.getValue()));
- }
-
- return bulkRequest;
- }
-}
diff --git a/Kitodo-DataManagement/src/main/java/org/kitodo/data/elasticsearch/index/Indexer.java b/Kitodo-DataManagement/src/main/java/org/kitodo/data/elasticsearch/index/Indexer.java
deleted file mode 100644
index 10d6f419e35..00000000000
--- a/Kitodo-DataManagement/src/main/java/org/kitodo/data/elasticsearch/index/Indexer.java
+++ /dev/null
@@ -1,149 +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.data.elasticsearch.index;
-
-import java.io.IOException;
-import java.util.List;
-import java.util.Map;
-
-import javax.ws.rs.HttpMethod;
-
-import org.kitodo.data.database.beans.BaseIndexedBean;
-import org.kitodo.data.elasticsearch.Index;
-import org.kitodo.data.elasticsearch.exceptions.CustomResponseException;
-import org.kitodo.data.elasticsearch.index.type.BaseType;
-import org.kitodo.data.exceptions.DataException;
-
-/**
- * Implementation of ElasticSearch Indexer for index package.
- */
-public class Indexer extends Index {
-
- private String method;
- private static final String INCORRECT_HTTP = "Incorrect HTTP method!";
-
- /**
- * Constructor for indexer with type names equal to table names.
- *
- * @param beanClass
- * as Class
- */
- public Indexer(Class> beanClass) {
- super(beanClass);
- }
-
- /**
- * Constructor for indexer with type names not equal to table names.
- *
- * @param type
- * as String
- */
- public Indexer(String type) {
- super(type);
- }
-
- /**
- * Perform request depending on given parameters of HTTP Method.
- *
- * @param baseIndexedBean
- * bean object which will be added or deleted from index
- * @param baseType
- * type on which will be called method createDocument()
- * @param forceRefresh
- * force index refresh - if true, time of execution is longer but
- * object is right after that available for display
- */
- @SuppressWarnings("unchecked")
- public void performSingleRequest(T baseIndexedBean, S baseType, boolean forceRefresh)
- throws CustomResponseException, DataException, IOException {
- IndexRestClient restClient = initiateRestClient();
-
- if (method.equals(HttpMethod.PUT)) {
- Map document = baseType.createDocument(baseIndexedBean);
- restClient.addDocument(this.type, document, baseIndexedBean.getId(), forceRefresh);
- } else if (method.equals(HttpMethod.DELETE)) {
- restClient.deleteDocument(this.type, baseIndexedBean.getId(), forceRefresh);
- } else {
- throw new CustomResponseException(INCORRECT_HTTP);
- }
-
- }
-
- /**
- * Perform delete request depending on given id of the bean.
- *
- * @param beanId
- * response from the server
- * @param forceRefresh
- * force index refresh - if true, time of execution is longer but
- * object is right after that available for display
- */
- public void performSingleRequest(Integer beanId, boolean forceRefresh) throws CustomResponseException, DataException {
- IndexRestClient restClient = initiateRestClient();
-
- if (method.equals(HttpMethod.DELETE)) {
- restClient.deleteDocument(this.type, beanId, forceRefresh);
- } else {
- throw new CustomResponseException(INCORRECT_HTTP);
- }
- }
-
- /**
- * This function is called directly by the administrator of the system.
- *
- * @param baseIndexedBeans
- * list of bean objects which will be added to index
- * @param baseType
- * type on which will be called method createDocument()
- */
- @SuppressWarnings("unchecked")
- public void performMultipleRequests(List baseIndexedBeans, S baseType, boolean async) throws CustomResponseException {
- IndexRestClient restClient = initiateRestClient();
-
- if (method.equals(HttpMethod.PUT)) {
- Map> documents = baseType.createDocuments(baseIndexedBeans);
- if (async) {
- restClient.addTypeAsync(this.type, documents);
- } else {
- restClient.addTypeSync(this.type, documents);
- }
- } else {
- throw new CustomResponseException(INCORRECT_HTTP);
- }
- }
-
- private IndexRestClient initiateRestClient() {
- IndexRestClient restClient = IndexRestClient.getInstance();
- restClient.setIndexBase(index);
- return restClient;
- }
-
- /**
- * Get type of method which will be used during performing request.
- *
- * @return method for request
- */
- public String getMethod() {
- return method;
- }
-
- /**
- * Set up type of method which will be used during performing request.
- *
- * @param method
- * Determines if we want to add (update) or delete document - true
- * add, false delete
- */
- public void setMethod(String method) {
- this.method = method;
- }
-}
diff --git a/Kitodo-DataManagement/src/main/java/org/kitodo/data/elasticsearch/index/ResponseListener.java b/Kitodo-DataManagement/src/main/java/org/kitodo/data/elasticsearch/index/ResponseListener.java
deleted file mode 100644
index a7f69fb3759..00000000000
--- a/Kitodo-DataManagement/src/main/java/org/kitodo/data/elasticsearch/index/ResponseListener.java
+++ /dev/null
@@ -1,63 +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.data.elasticsearch.index;
-
-import org.apache.logging.log4j.LogManager;
-import org.apache.logging.log4j.Logger;
-import org.elasticsearch.action.ActionListener;
-import org.elasticsearch.action.bulk.BulkResponse;
-
-public class ResponseListener implements ActionListener {
-
- private static final Logger logger = LogManager.getLogger(ResponseListener.class);
-
- private String type;
- private int batchSize;
- private BulkResponse bulkResponse = null;
-
- /**
- * Constructor with information about type and size of batch.
- *
- * @param type
- * as String
- * @param batchSize
- * as int
- */
- ResponseListener(String type, int batchSize) {
- this.type = type;
- this.batchSize = batchSize;
- }
-
- @Override
- public void onResponse(BulkResponse bulkResponse) {
- this.bulkResponse = bulkResponse;
- if (bulkResponse.hasFailures()) {
- logger.error(bulkResponse.buildFailureMessage());
- }
- }
-
- @Override
- public void onFailure(Exception e) {
- // TODO: add error handling
- logger.error("I got failure for type '{}' with size {}!", this.type, this.batchSize);
- logger.error(e.getMessage(), e);
- }
-
- /**
- * Get bulkResponse.
- *
- * @return value of bulkResponse
- */
- BulkResponse getBulkResponse() {
- return bulkResponse;
- }
-}
diff --git a/Kitodo-DataManagement/src/main/java/org/kitodo/data/elasticsearch/index/type/BaseType.java b/Kitodo-DataManagement/src/main/java/org/kitodo/data/elasticsearch/index/type/BaseType.java
deleted file mode 100644
index c50b4e139a0..00000000000
--- a/Kitodo-DataManagement/src/main/java/org/kitodo/data/elasticsearch/index/type/BaseType.java
+++ /dev/null
@@ -1,182 +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.data.elasticsearch.index.type;
-
-import java.text.DateFormat;
-import java.text.SimpleDateFormat;
-import java.util.ArrayList;
-import java.util.Date;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-import java.util.Objects;
-
-import org.kitodo.data.database.beans.BaseBean;
-import org.kitodo.data.database.beans.BaseIndexedBean;
-import org.kitodo.data.database.beans.BaseTemplateBean;
-import org.kitodo.data.database.beans.Batch;
-import org.kitodo.data.database.beans.Client;
-import org.kitodo.data.database.beans.Comment;
-import org.kitodo.data.database.beans.Filter;
-import org.kitodo.data.database.beans.Project;
-import org.kitodo.data.database.beans.Role;
-import org.kitodo.data.database.beans.Ruleset;
-import org.kitodo.data.database.beans.Task;
-import org.kitodo.data.database.beans.User;
-import org.kitodo.data.database.beans.Workflow;
-import org.kitodo.data.elasticsearch.api.TypeInterface;
-import org.kitodo.data.elasticsearch.index.type.enums.BatchTypeField;
-import org.kitodo.data.elasticsearch.index.type.enums.CommentTypeField;
-import org.kitodo.data.elasticsearch.index.type.enums.FilterTypeField;
-import org.kitodo.data.elasticsearch.index.type.enums.ProcessTypeField;
-import org.kitodo.data.elasticsearch.index.type.enums.ProjectTypeField;
-import org.kitodo.data.elasticsearch.index.type.enums.RoleTypeField;
-import org.kitodo.data.elasticsearch.index.type.enums.TaskTypeField;
-import org.kitodo.data.elasticsearch.index.type.enums.UserTypeField;
-
-/**
- * Abstract class for Type class.
- */
-public abstract class BaseType implements TypeInterface {
-
- @Override
- public Map createDocument(T baseIndexedBean) {
- return getJsonObject(baseIndexedBean);
- }
-
- @Override
- public Map> createDocuments(List baseIndexedBeans) {
- Map> documents = new HashMap<>();
- for (T bean : baseIndexedBeans) {
- documents.put(bean.getId(), createDocument(bean));
- }
- return documents;
- }
-
- abstract Map getJsonObject(T baseIndexedBean);
-
- /**
- * Method for adding relationship between bean objects.
- *
- * @param objects
- * list
- * @param addAdditionalProperties
- * true or false, if true also additional information are included,
- * type of information depends on the bean which is added as related
- * object
- * @return JSONArray
- */
- List addObjectRelation(List objects, boolean addAdditionalProperties) {
- List