diff --git a/Kitodo-DataManagement/pom.xml b/Kitodo-DataManagement/pom.xml index 9ce50861139..d9e6a26760b 100644 --- a/Kitodo-DataManagement/pom.xml +++ b/Kitodo-DataManagement/pom.xml @@ -71,10 +71,6 @@ org.apache.myfaces.core myfaces-impl - - org.elasticsearch.client - elasticsearch-rest-high-level-client - org.glassfish javax.json @@ -125,10 +121,6 @@ org.junit.vintage junit-vintage-engine - - org.elasticsearch.plugin - transport-netty4-client - diff --git a/Kitodo-DataManagement/src/main/java/org/kitodo/data/elasticsearch/Index.java b/Kitodo-DataManagement/src/main/java/org/kitodo/data/elasticsearch/Index.java deleted file mode 100644 index 8c35d4ab548..00000000000 --- a/Kitodo-DataManagement/src/main/java/org/kitodo/data/elasticsearch/Index.java +++ /dev/null @@ -1,67 +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; - -import javax.persistence.Table; - -import org.kitodo.config.ConfigMain; - -/** - * Super class for Indexer and Searcher. - */ -public abstract class Index { - - protected String index; - protected String type; - - /** - * Constructor with type names equal to table names. - * - * @param beanClass - * as Class - */ - public Index(Class beanClass) { - Table table = beanClass.getAnnotation(Table.class); - this.index = ConfigMain.getParameter("elasticsearch.index", "kitodo"); - this.setType(table.name()); - } - - /** - * Constructor with type names not equal to table names. - * - * @param type - * as String - */ - public Index(String type) { - this.index = ConfigMain.getParameter("elasticsearch.index", "kitodo"); - this.setType(type); - } - - /** - * Getter for type. - * - * @return type name - */ - public String getType() { - return type; - } - - /** - * Setter for type. - * - * @param type - * - equal to the name of table in database, but not necessary - */ - public void setType(String type) { - this.type = type; - } -} diff --git a/Kitodo-DataManagement/src/main/java/org/kitodo/data/elasticsearch/KitodoRestClient.java b/Kitodo-DataManagement/src/main/java/org/kitodo/data/elasticsearch/KitodoRestClient.java deleted file mode 100644 index e0c82af9f20..00000000000 --- a/Kitodo-DataManagement/src/main/java/org/kitodo/data/elasticsearch/KitodoRestClient.java +++ /dev/null @@ -1,300 +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; - -import java.io.IOException; -import java.util.Arrays; -import java.util.Collections; -import java.util.List; - -import javax.ws.rs.HttpMethod; - -import org.apache.http.HttpEntity; -import org.apache.http.HttpHost; -import org.apache.http.StatusLine; -import org.apache.http.auth.AuthScope; -import org.apache.http.auth.UsernamePasswordCredentials; -import org.apache.http.client.CredentialsProvider; -import org.apache.http.entity.ContentType; -import org.apache.http.impl.client.BasicCredentialsProvider; -import org.apache.http.nio.entity.NStringEntity; -import org.apache.http.util.EntityUtils; -import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; -import org.elasticsearch.client.Request; -import org.elasticsearch.client.RequestOptions; -import org.elasticsearch.client.Requests; -import org.elasticsearch.client.Response; -import org.elasticsearch.client.ResponseException; -import org.elasticsearch.client.RestClient; -import org.elasticsearch.client.RestClientBuilder; -import org.elasticsearch.client.RestHighLevelClient; -import org.elasticsearch.client.core.MainResponse; -import org.elasticsearch.rest.RestStatus; -import org.kitodo.config.ConfigMain; -import org.kitodo.data.elasticsearch.api.RestClientInterface; -import org.kitodo.data.elasticsearch.exceptions.CustomResponseException; - -/** - * Implementation of ElasticSearch REST Client for Index Module. - */ -public abstract class KitodoRestClient implements RestClientInterface { - - private static final Logger logger = LogManager.getLogger(KitodoRestClient.class); - - protected String indexBase; - protected RestClient client; - protected RestHighLevelClient highLevelClient; - - public static final List MAPPING_TYPES = Arrays.asList("batch", "docket", "filter", "process", "project", - "property", "ruleset", "task", "template", "workflow"); - - /** - * Create REST client. - * - */ - protected void initiateClient() { - String host = ConfigMain.getParameter("elasticsearch.host", "localhost"); - int port = ConfigMain.getIntParameter("elasticsearch.port", 9200); - String protocol = ConfigMain.getParameter("elasticsearch.protocol", "http"); - String path = ConfigMain.getParameter("elasticsearch.path", "/"); - initiateClient(host, port, protocol, path); - } - - /** - * Create REST client with other without basic authentication. - * - * @param host - * default host is localhost - * @param port - * default port ist 9200 - * @param protocol - * default protocol is http - * @param path - * default path is / - */ - private void initiateClient(String host, Integer port, String protocol, String path) { - if (ConfigMain.getBooleanParameter("elasticsearch.useAuthentication")) { - initiateClientWithAuth(host, port, protocol, path); - } else { - RestClientBuilder builder = RestClient.builder(new HttpHost(host, port, protocol)); - - if (!path.isEmpty() && !path.equals("/")) { - builder.setPathPrefix(path); - } - - client = builder.build(); - highLevelClient = new RestHighLevelClient(builder); - } - } - - /** - * Create REST client with basic authentication. - * - * @param host - * default host is localhost - * @param port - * default port ist 9200 - * @param protocol - * default protocol is http - * @param path - * default path is / - */ - private void initiateClientWithAuth(String host, Integer port, String protocol, String path) { - String user = ConfigMain.getParameter("elasticsearch.user", "elastic"); - String password = ConfigMain.getParameter("elasticsearch.password", "changeme"); - - final CredentialsProvider credentialsProvider = new BasicCredentialsProvider(); - credentialsProvider.setCredentials(AuthScope.ANY, new UsernamePasswordCredentials(user, password)); - - RestClientBuilder builder = RestClient.builder(new HttpHost(host, port, protocol)).setHttpClientConfigCallback( - httpClientBuilder -> httpClientBuilder.setDefaultCredentialsProvider(credentialsProvider)); - - if (!path.isEmpty() && !path.equals("/")) { - builder.setPathPrefix(path); - } - client = builder.build(); - highLevelClient = new RestHighLevelClient(builder); - } - - /** - * Get information about client server. - * - * @return information about the server - */ - public String getServerInformation() throws IOException { - Request request = new Request(HttpMethod.GET, "/"); - request.addParameter("pretty", "true"); - Response response = performRequest(request); - return EntityUtils.toString(response.getEntity()); - } - - /** - * Get information about client server. - * - * @return information about the server - */ - public String getServerInfo() throws IOException { - MainResponse response = highLevelClient.info(RequestOptions.DEFAULT); - return response.toString(); - } - - /** - * Get mapping. - * - * @param mappingType - * the name of table in database as String - * @return mapping - */ - public String getMapping(String mappingType) throws IOException { - Request request = new Request(HttpMethod.GET, "/" + indexBase + "_" + mappingType + "/_mapping"); - request.addParameter("pretty", "true"); - Response response = performRequest(request); - return EntityUtils.toString(response.getEntity()); - } - - /** - * Create new indexes without mappings. - */ - public void createIndexes() throws IOException, CustomResponseException { - for (String mappingType : MAPPING_TYPES) { - createIndex(null, mappingType); - } - } - - /** - * Create new index with mapping. - * - * @param query - * contains mapping - * @param mappingType - * the name of table in database as String - * @return true or false - can be used for displaying information to user if - * success - */ - public boolean createIndex(String query, String mappingType) throws IOException, CustomResponseException { - if (query == null) { - query = "{\"settings\" : {\"index\" : {\"number_of_shards\" : 1,\"number_of_replicas\" : 0}}}"; - } - HttpEntity entity = new NStringEntity(query, ContentType.APPLICATION_JSON); - Request request = new Request(HttpMethod.PUT, "/" + indexBase + "_" + mappingType); - request.setEntity(entity); - Response indexResponse = performRequest(request); - int statusCode = processStatusCode(indexResponse.getStatusLine()); - return statusCode == 200 || statusCode == 201; - } - - /** - * Check if all indexes already exist. Needed for frontend. - * - * @return false if any index doesn't exist, true else - */ - public boolean typeIndexesExist() throws IOException, CustomResponseException { - for (String mappingType : MAPPING_TYPES) { - Response indexResponse = performRequest(new Request(HttpMethod.GET, "/" + indexBase + "_" + mappingType)); - int statusCode = processStatusCode(indexResponse.getStatusLine()); - if (statusCode != 200 && statusCode != 201) { - return false; - } - } - return true; - } - - /** - * Delete index of given mappingType. Currently, only used in test cases. - * @param mappingType mapping type - */ - public void deleteIndex(String mappingType) throws IOException { - performRequest(new Request(HttpMethod.DELETE, "/" + indexBase + "_" + mappingType)); - } - - /** - * Delete all indexes. Used for cleaning after tests! - */ - public void deleteAllIndexes() throws IOException { - for (String mappingType : MAPPING_TYPES) { - performRequest(new Request(HttpMethod.DELETE, "/" + indexBase + "_" + mappingType)); - } - } - - /** - * Getter for indexBase. - * The indexBase is the prefix of all indexes - equal to the name of database, default kitodo. - * - * @return indexBase name - */ - public String getIndexBase() { - return indexBase; - } - - /** - * Update refresh interval of search indices to 1 ms. - * - * @throws IOException when index cannot be reached - */ - public void setRefreshInterval() throws IOException { - this.highLevelClient.indices().putSettings(Requests.updateSettingsRequest() - .settings(Collections.singletonMap("refresh_interval", "1ms")), RequestOptions.DEFAULT); - } - - /** - * Setter for indexBase. The indexBase is the prefix of all indexes - * - * @param indexBase - * - equal to the name of database, default kitodo - */ - public void setIndexBase(String indexBase) { - this.indexBase = indexBase; - } - - protected void handleResponseException(ResponseException e) throws CustomResponseException { - if (e.getResponse().getStatusLine().getStatusCode() == 404) { - if (logger.isTraceEnabled()) { - logger.trace(e.getMessage(), e); - } else { - logger.debug(e.getMessage().replaceAll("\\p{Space}+", " ")); - } - } else { - throw new CustomResponseException(e); - } - } - - protected int processStatusCode(StatusLine statusLine) throws CustomResponseException { - int statusCode = statusLine.getStatusCode(); - processStatusCode(statusCode, statusLine); - return statusCode; - } - - protected int processStatusCode(RestStatus restStatus) throws CustomResponseException { - int statusCode = restStatus.getStatus(); - processStatusCode(statusCode, restStatus); - return statusCode; - } - - private void processStatusCode(int statusCode, Object restStatus) throws CustomResponseException { - if (statusCode >= 400 && statusCode <= 499) { - throw new CustomResponseException("Client error: " + restStatus.toString()); - } else if (statusCode >= 500 && statusCode <= 599) { - throw new CustomResponseException("Server error: " + restStatus.toString()); - } - } - - private Response performRequest(Request request) throws IOException { - Response response = client.performRequest(request); - if (logger.isDebugEnabled()) { - logger.debug(logger.isTraceEnabled() - ? response.toString() + System.lineSeparator() + EntityUtils.toString(response.getEntity()) - : response.toString()); - } - return response; - } -} diff --git a/Kitodo-DataManagement/src/main/java/org/kitodo/data/elasticsearch/api/RestClientInterface.java b/Kitodo-DataManagement/src/main/java/org/kitodo/data/elasticsearch/api/RestClientInterface.java deleted file mode 100644 index 1f42ae3f10c..00000000000 --- a/Kitodo-DataManagement/src/main/java/org/kitodo/data/elasticsearch/api/RestClientInterface.java +++ /dev/null @@ -1,22 +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.api; - -import java.io.IOException; - -/** - * Interface for REST clients. - */ -public interface RestClientInterface { - - String getServerInformation() throws IOException; -} diff --git a/Kitodo-DataManagement/src/main/java/org/kitodo/data/elasticsearch/api/TypeInterface.java b/Kitodo-DataManagement/src/main/java/org/kitodo/data/elasticsearch/api/TypeInterface.java deleted file mode 100644 index 1102ffcd070..00000000000 --- a/Kitodo-DataManagement/src/main/java/org/kitodo/data/elasticsearch/api/TypeInterface.java +++ /dev/null @@ -1,29 +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.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> jsonObjects = new ArrayList<>(); - for (F property : objects) { - Map jsonObject = new HashMap<>(); - jsonObject.put(BatchTypeField.ID.getKey(), property.getId()); - if (addAdditionalProperties) { - getAdditionalProperties(jsonObject, property); - } - jsonObjects.add(jsonObject); - } - return jsonObjects; - } - - /** - * Method for adding relationship between bean objects. - * - * @param objects - * list - * @return JSONArray - */ - List addObjectRelation(List objects) { - return addObjectRelation(objects, false); - } - - private void getAdditionalProperties(Map jsonObject, BaseBean property) { - if (property instanceof Batch) { - Batch batch = (Batch) property; - jsonObject.put(BatchTypeField.TITLE.getKey(), preventNull(batch.getTitle())); - } else if (property instanceof BaseTemplateBean) { - jsonObject.put(ProcessTypeField.TITLE.getKey(), preventNull(((BaseTemplateBean) property).getTitle())); - } else if (property instanceof Comment) { - jsonObject.put(CommentTypeField.MESSAGE.getKey(), preventNull(((Comment) property).getMessage())); - } else if (property instanceof Project) { - Project project = (Project) property; - jsonObject.put(ProjectTypeField.TITLE.getKey(), preventNull(project.getTitle())); - jsonObject.put(ProjectTypeField.ACTIVE.getKey(), project.isActive()); - if (Objects.nonNull(project.getClient())) { - jsonObject.put(ProjectTypeField.CLIENT_ID.getKey(), project.getClient().getId()); - } - } else if (property instanceof User) { - User user = (User) property; - jsonObject.put(UserTypeField.LOGIN.getKey(), preventNull(user.getLogin())); - jsonObject.put(UserTypeField.NAME.getKey(), preventNull(user.getName())); - jsonObject.put(UserTypeField.SURNAME.getKey(), preventNull(user.getSurname())); - } else if (property instanceof Role) { - jsonObject.put(RoleTypeField.TITLE.getKey(), preventNull(((Role) property).getTitle())); - } else if (property instanceof Task) { - jsonObject.put(TaskTypeField.TITLE.getKey(), preventNull(((Task) property).getTitle())); - } else if (property instanceof Filter) { - jsonObject.put(FilterTypeField.VALUE.getKey(), preventNull(((Filter) property).getValue())); - } - } - - /** - * Method used for formatting Date as JsonValue. It will help to change fast a - * way of Date formatting or expected String format. - * - * @param date - * as Date - * @return formatted date as JsonValue - String or NULL - */ - String getFormattedDate(Date date) { - if (Objects.nonNull(date)) { - DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); - return dateFormat.format(date); - } - return ""; - } - - int preventNull(Integer value) { - if (Objects.isNull(value)) { - return 0; - } - return value; - } - - String preventNull(String value) { - if (Objects.isNull(value)) { - return ""; - } - return value; - } - - int getId(BaseBean baseBean) { - if (Objects.nonNull(baseBean)) { - return baseBean.getId(); - } - return 0; - } - - String getTitle(BaseBean baseBean) { - if (baseBean instanceof BaseTemplateBean) { - return preventNull(((BaseTemplateBean) baseBean).getTitle()); - } else if (baseBean instanceof Project) { - return preventNull(((Project) baseBean).getTitle()); - } else if (baseBean instanceof Workflow) { - return preventNull(((Workflow) baseBean).getTitle()); - } else if (baseBean instanceof Client) { - return preventNull(((Client) baseBean).getName()); - } else if (baseBean instanceof Ruleset) { - return preventNull(((Ruleset) baseBean).getTitle()); - } - return ""; - } -} diff --git a/Kitodo-DataManagement/src/main/java/org/kitodo/data/elasticsearch/index/type/BatchType.java b/Kitodo-DataManagement/src/main/java/org/kitodo/data/elasticsearch/index/type/BatchType.java deleted file mode 100644 index bc7e34cef50..00000000000 --- a/Kitodo-DataManagement/src/main/java/org/kitodo/data/elasticsearch/index/type/BatchType.java +++ /dev/null @@ -1,32 +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.util.HashMap; -import java.util.Map; - -import org.kitodo.data.database.beans.Batch; -import org.kitodo.data.elasticsearch.index.type.enums.BatchTypeField; - -/** - * Implementation of Batch Type. - */ -public class BatchType extends BaseType { - - @Override - Map getJsonObject(Batch batch) { - Map jsonObject = new HashMap<>(); - jsonObject.put(BatchTypeField.TITLE.getKey(), preventNull(batch.getTitle())); - jsonObject.put(BatchTypeField.PROCESSES.getKey(), addObjectRelation(batch.getProcesses(), true)); - return jsonObject; - } -} diff --git a/Kitodo-DataManagement/src/main/java/org/kitodo/data/elasticsearch/index/type/DocketType.java b/Kitodo-DataManagement/src/main/java/org/kitodo/data/elasticsearch/index/type/DocketType.java deleted file mode 100644 index 313a804cde0..00000000000 --- a/Kitodo-DataManagement/src/main/java/org/kitodo/data/elasticsearch/index/type/DocketType.java +++ /dev/null @@ -1,35 +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.util.HashMap; -import java.util.Map; - -import org.kitodo.data.database.beans.Docket; -import org.kitodo.data.elasticsearch.index.type.enums.DocketTypeField; - -/** - * Implementation of Docket Type. - */ -public class DocketType extends BaseType { - - @Override - Map getJsonObject(Docket docket) { - Map jsonObject = new HashMap<>(); - jsonObject.put(DocketTypeField.TITLE.getKey(), preventNull(docket.getTitle())); - jsonObject.put(DocketTypeField.FILE.getKey(), preventNull(docket.getFile())); - jsonObject.put(DocketTypeField.ACTIVE.getKey(), docket.isActive()); - jsonObject.put(DocketTypeField.CLIENT_ID.getKey(), getId(docket.getClient())); - jsonObject.put(DocketTypeField.CLIENT_NAME.getKey(), getTitle(docket.getClient())); - return jsonObject; - } -} diff --git a/Kitodo-DataManagement/src/main/java/org/kitodo/data/elasticsearch/index/type/FilterType.java b/Kitodo-DataManagement/src/main/java/org/kitodo/data/elasticsearch/index/type/FilterType.java deleted file mode 100644 index 5db390cfc67..00000000000 --- a/Kitodo-DataManagement/src/main/java/org/kitodo/data/elasticsearch/index/type/FilterType.java +++ /dev/null @@ -1,32 +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.util.HashMap; -import java.util.Map; - -import org.kitodo.data.database.beans.Filter; -import org.kitodo.data.elasticsearch.index.type.enums.FilterTypeField; - -/** - * Type class for Filter bean. - */ -public class FilterType extends BaseType { - - @Override - Map getJsonObject(Filter filter) { - Map jsonObject = new HashMap<>(); - jsonObject.put(FilterTypeField.VALUE.getKey(), preventNull(filter.getValue())); - jsonObject.put(FilterTypeField.USER.getKey(), getId(filter.getUser())); - return jsonObject; - } -} diff --git a/Kitodo-DataManagement/src/main/java/org/kitodo/data/elasticsearch/index/type/ProcessType.java b/Kitodo-DataManagement/src/main/java/org/kitodo/data/elasticsearch/index/type/ProcessType.java deleted file mode 100644 index 69cdc014caf..00000000000 --- a/Kitodo-DataManagement/src/main/java/org/kitodo/data/elasticsearch/index/type/ProcessType.java +++ /dev/null @@ -1,157 +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.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.Objects; - -import org.kitodo.data.database.beans.Comment; -import org.kitodo.data.database.beans.Process; -import org.kitodo.data.database.beans.Property; -import org.kitodo.data.database.enums.TaskStatus; -import org.kitodo.data.elasticsearch.index.converter.ProcessConverter; -import org.kitodo.data.elasticsearch.index.type.enums.ProcessTypeField; - -/** - * Implementation of Process Type. - */ -public class ProcessType extends BaseType { - - private static final String TITLE_FIELD_KEY = "title"; - private static final String VALUE_FIELD_KEY = "value"; - - @Override - Map getJsonObject(Process process) { - String processBaseUri = process.getProcessBaseUri() != null ? process.getProcessBaseUri().getRawPath() : ""; - boolean projectActive = process.getProject() != null && process.getProject().isActive(); - int projectClientId = process.getProject() != null ? getId(process.getProject().getClient()) : 0; - int processParentId = Objects.nonNull(process.getParent()) ? process.getParent().getId() : 0; - - Map jsonObject = new HashMap<>(); - jsonObject.put(ProcessTypeField.ID.getKey(), preventNull(process.getId())); - jsonObject.put(ProcessTypeField.TITLE.getKey(), preventNull(process.getTitle())); - jsonObject.put(ProcessTypeField.CREATION_DATE.getKey(), getFormattedDate(process.getCreationDate())); - jsonObject.put(ProcessTypeField.WIKI_FIELD.getKey(), preventNull(process.getWikiField())); - jsonObject.put(ProcessTypeField.SORT_HELPER_ARTICLES.getKey(), process.getSortHelperArticles()); - jsonObject.put(ProcessTypeField.SORT_HELPER_DOCSTRUCTS.getKey(), process.getSortHelperDocstructs()); - jsonObject.put(ProcessTypeField.SORT_HELPER_STATUS.getKey(), preventNull(process.getSortHelperStatus())); - jsonObject.put(ProcessTypeField.SORT_HELPER_IMAGES.getKey(), process.getSortHelperImages()); - jsonObject.put(ProcessTypeField.SORT_HELPER_METADATA.getKey(), process.getSortHelperMetadata()); - jsonObject.put(ProcessTypeField.PROCESS_BASE_URI.getKey(), processBaseUri); - jsonObject.put(ProcessTypeField.TEMPLATE_ID.getKey(), getId(process.getTemplate())); - jsonObject.put(ProcessTypeField.TEMPLATE_TITLE.getKey(), getTitle(process.getTemplate())); - jsonObject.put(ProcessTypeField.PROJECT_ID.getKey(), getId(process.getProject())); - jsonObject.put(ProcessTypeField.PROJECT_TITLE.getKey(), getTitle(process.getProject())); - jsonObject.put(ProcessTypeField.PROJECT_ACTIVE.getKey(), projectActive); - jsonObject.put(ProcessTypeField.PROJECT_CLIENT_ID.getKey(), projectClientId); - jsonObject.put(ProcessTypeField.RULESET.getKey(), getId(process.getRuleset())); - jsonObject.put(ProcessTypeField.DOCKET.getKey(), getId(process.getDocket())); - jsonObject.put(ProcessTypeField.BATCHES.getKey(), addObjectRelation(process.getBatches(), true)); - jsonObject.put(ProcessTypeField.COMMENTS.getKey(), addObjectRelation(process.getComments())); - jsonObject.put(ProcessTypeField.COMMENTS_MESSAGE.getKey(), getProcessComments(process)); - jsonObject.put(ProcessTypeField.HAS_CHILDREN.getKey(), !process.getChildren().isEmpty()); - jsonObject.put(ProcessTypeField.PARENT_ID.getKey(), processParentId); - jsonObject.put(ProcessTypeField.TASKS.getKey(), addObjectRelation(process.getTasks(), true)); - jsonObject.put(ProcessTypeField.METADATA.getKey(), process.getMetadata()); - jsonObject.put(ProcessTypeField.NUMBER_OF_METADATA.getKey(), process.getNumberOfMetadata()); - jsonObject.put(ProcessTypeField.NUMBER_OF_IMAGES.getKey(), process.getNumberOfImages()); - jsonObject.put(ProcessTypeField.NUMBER_OF_STRUCTURES.getKey(), process.getNumberOfStructures()); - jsonObject.put(ProcessTypeField.PROPERTIES.getKey(), getProperties(process)); - jsonObject.put(ProcessTypeField.BASE_TYPE.getKey(), process.getBaseType()); - jsonObject.put(ProcessTypeField.IN_CHOICE_LIST_SHOWN.getKey(), process.getInChoiceListShown()); - jsonObject.put(ProcessTypeField.LAST_EDITING_USER.getKey(), ProcessConverter.getLastEditingUser(process)); - jsonObject.put( - ProcessTypeField.CORRECTION_COMMENT_STATUS.getKey(), - ProcessConverter.getCorrectionCommentStatus(process).getValue() - ); - convertLastProcessingTask(jsonObject, process); - convertProgressStatus(jsonObject, process); - - return jsonObject; - } - - /** - * Adds last processing task dates to json object for indexing. - * - * @param jsonObject the json object used for indexing - * @param process the process being index - */ - private void convertLastProcessingTask(Map jsonObject, Process process) { - jsonObject.put( - ProcessTypeField.PROCESSING_BEGIN_LAST_TASK.getKey(), - getFormattedDate(ProcessConverter.getLastProcessingBegin(process)) - ); - jsonObject.put( - ProcessTypeField.PROCESSING_END_LAST_TASK.getKey(), - getFormattedDate(ProcessConverter.getLastProcessingEnd(process)) - ); - } - - /** - * Adds progress status properties to json object for indexing. - * - * @param jsonObject the json object used for indexing - * @param process the process being index - */ - private void convertProgressStatus(Map jsonObject, Process process) { - // calculate and save process status - Map taskProgress = ProcessConverter.getTaskProgressPercentageOfProcess(process, true); - jsonObject.put(ProcessTypeField.PROGRESS_CLOSED.getKey(), taskProgress.get(TaskStatus.DONE)); - jsonObject.put(ProcessTypeField.PROGRESS_IN_PROCESSING.getKey(), taskProgress.get(TaskStatus.INWORK)); - jsonObject.put(ProcessTypeField.PROGRESS_OPEN.getKey(), taskProgress.get(TaskStatus.OPEN)); - jsonObject.put(ProcessTypeField.PROGRESS_LOCKED.getKey(), taskProgress.get(TaskStatus.LOCKED)); - jsonObject.put( - ProcessTypeField.PROGRESS_COMBINED.getKey(), - ProcessConverter.getCombinedProgressFromTaskPercentages(taskProgress) - ); - } - - private List> getProperties(Process process) { - List properties = process.getProperties(); - List> propertiesForIndex = new ArrayList<>(); - for (Property property : properties) { - HashMap propertyMap = new HashMap<>(); - propertyMap.put(TITLE_FIELD_KEY, property.getTitle()); - propertyMap.put(VALUE_FIELD_KEY, property.getValue()); - propertiesForIndex.add(propertyMap); - } - properties = process.getTemplates(); - for (Property property : properties) { - HashMap propertyMap = new HashMap<>(); - propertyMap.put(TITLE_FIELD_KEY, property.getTitle()); - propertyMap.put(VALUE_FIELD_KEY, property.getValue()); - propertiesForIndex.add(propertyMap); - } - properties = process.getWorkpieces(); - for (Property property : properties) { - HashMap propertyMap = new HashMap<>(); - propertyMap.put(TITLE_FIELD_KEY, property.getTitle()); - propertyMap.put(VALUE_FIELD_KEY, property.getValue()); - propertiesForIndex.add(propertyMap); - } - return propertiesForIndex; - } - - private String getProcessComments(Process process) { - String commentsMessages = ""; - List processComments = process.getComments(); - for (Comment comment : processComments) { - if (Objects.nonNull(comment) && Objects.nonNull(comment.getMessage())) { - commentsMessages = commentsMessages.concat(comment.getMessage() + "\n"); - } - } - return commentsMessages; - } -} diff --git a/Kitodo-DataManagement/src/main/java/org/kitodo/data/elasticsearch/index/type/ProjectType.java b/Kitodo-DataManagement/src/main/java/org/kitodo/data/elasticsearch/index/type/ProjectType.java deleted file mode 100644 index ed9003c954b..00000000000 --- a/Kitodo-DataManagement/src/main/java/org/kitodo/data/elasticsearch/index/type/ProjectType.java +++ /dev/null @@ -1,77 +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.util.ArrayList; -import java.util.Collections; -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; -import org.kitodo.data.database.beans.Folder; -import org.kitodo.data.database.beans.Project; -import org.kitodo.data.database.exceptions.DAOException; -import org.kitodo.data.database.persistence.ProjectDAO; -import org.kitodo.data.elasticsearch.index.type.enums.ProjectTypeField; - -/** - * Implementation of Project Type. - */ -public class ProjectType extends BaseType { - - private static final Logger logger = LogManager.getLogger(ProjectType.class); - - @Override - Map getJsonObject(Project project) { - List> folders = new ArrayList<>(); - List projectFolders = project.getFolders(); - for (Folder folder : projectFolders) { - Map folderObject = new HashMap<>(); - folderObject.put(ProjectTypeField.FOLDER_FILE_GROUP.getKey(), preventNull(folder.getFileGroup())); - folderObject.put(ProjectTypeField.FOLDER_URL_STRUCTURE.getKey(), preventNull(folder.getUrlStructure())); - folderObject.put(ProjectTypeField.FOLDER_MIME_TYPE.getKey(), preventNull(folder.getMimeType())); - folderObject.put(ProjectTypeField.FOLDER_PATH.getKey(), preventNull(folder.getPath())); - folders.add(folderObject); - } - - // query database for the amount of processes attached to a project - // instead of calling project.getProcesses(), which will load all processes into memory - Long processCount = 0L; - try { - ProjectDAO projectDAO = new ProjectDAO(); - processCount = projectDAO.count( - "SELECT COUNT(*) FROM Process WHERE project_id = :id", - Collections.singletonMap("id", project.getId()) - ); - } catch (DAOException e) { - logger.error("database access exception while transforming project to json for indexing.", e); - } - - Map jsonObject = new HashMap<>(); - jsonObject.put(ProjectTypeField.TITLE.getKey(), preventNull(project.getTitle())); - jsonObject.put(ProjectTypeField.START_DATE.getKey(), getFormattedDate(project.getStartDate())); - jsonObject.put(ProjectTypeField.END_DATE.getKey(), getFormattedDate(project.getEndDate())); - jsonObject.put(ProjectTypeField.NUMBER_OF_PAGES.getKey(), preventNull(project.getNumberOfPages())); - jsonObject.put(ProjectTypeField.NUMBER_OF_VOLUMES.getKey(), preventNull(project.getNumberOfVolumes())); - jsonObject.put(ProjectTypeField.METS_RIGTS_OWNER.getKey(), project.getMetsRightsOwner()); - jsonObject.put(ProjectTypeField.ACTIVE.getKey(), project.isActive()); - jsonObject.put(ProjectTypeField.HAS_PROCESSES.getKey(), processCount > 0); - jsonObject.put(ProjectTypeField.TEMPLATES.getKey(), addObjectRelation(project.getTemplates(), true)); - jsonObject.put(ProjectTypeField.USERS.getKey(), addObjectRelation(project.getUsers(), true)); - jsonObject.put(ProjectTypeField.CLIENT_ID.getKey(), getId(project.getClient())); - jsonObject.put(ProjectTypeField.CLIENT_NAME.getKey(), getTitle(project.getClient())); - jsonObject.put(ProjectTypeField.FOLDER.getKey(), folders); - return jsonObject; - } -} diff --git a/Kitodo-DataManagement/src/main/java/org/kitodo/data/elasticsearch/index/type/RulesetType.java b/Kitodo-DataManagement/src/main/java/org/kitodo/data/elasticsearch/index/type/RulesetType.java deleted file mode 100644 index 6f1573c066e..00000000000 --- a/Kitodo-DataManagement/src/main/java/org/kitodo/data/elasticsearch/index/type/RulesetType.java +++ /dev/null @@ -1,36 +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.util.HashMap; -import java.util.Map; - -import org.kitodo.data.database.beans.Ruleset; -import org.kitodo.data.elasticsearch.index.type.enums.RulesetTypeField; - -/** - * Implementation of Ruleset Type. - */ -public class RulesetType extends BaseType { - - @Override - Map getJsonObject(Ruleset ruleset) { - Map jsonObject = new HashMap<>(); - jsonObject.put(RulesetTypeField.TITLE.getKey(), preventNull(ruleset.getTitle())); - jsonObject.put(RulesetTypeField.FILE.getKey(), preventNull(ruleset.getFile())); - jsonObject.put(RulesetTypeField.ORDER_METADATA_BY_RULESET.getKey(), ruleset.isOrderMetadataByRuleset()); - jsonObject.put(RulesetTypeField.ACTIVE.getKey(), ruleset.isActive()); - jsonObject.put(RulesetTypeField.CLIENT_ID.getKey(), getId(ruleset.getClient())); - jsonObject.put(RulesetTypeField.CLIENT_NAME.getKey(), getTitle(ruleset.getClient())); - return jsonObject; - } -} diff --git a/Kitodo-DataManagement/src/main/java/org/kitodo/data/elasticsearch/index/type/TaskType.java b/Kitodo-DataManagement/src/main/java/org/kitodo/data/elasticsearch/index/type/TaskType.java deleted file mode 100644 index ad1b35fe3e4..00000000000 --- a/Kitodo-DataManagement/src/main/java/org/kitodo/data/elasticsearch/index/type/TaskType.java +++ /dev/null @@ -1,161 +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.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.Project; -import org.kitodo.data.database.beans.Task; -import org.kitodo.data.database.beans.User; -import org.kitodo.data.elasticsearch.index.converter.ProcessConverter; -import org.kitodo.data.elasticsearch.index.type.enums.TaskTypeField; - -/** - * Implementation of Task Type. - */ -public class TaskType extends BaseType { - - @Override - Map getJsonObject(Task task) { - int processingStatus = task.getProcessingStatus() != null ? task.getProcessingStatus().getValue() : 0; - int editType = task.getEditType() != null ? task.getEditType().getValue() : 0; - int processingUser = task.getProcessingUser() != null ? task.getProcessingUser().getId() : 0; - - Map jsonObject = new HashMap<>(); - jsonObject.put(TaskTypeField.TITLE.getKey(), preventNull(task.getTitle())); - jsonObject.put(TaskTypeField.ORDERING.getKey(), task.getOrdering()); - jsonObject.put(TaskTypeField.PROCESSING_STATUS.getKey(), processingStatus); - jsonObject.put(TaskTypeField.EDIT_TYPE.getKey(), editType); - jsonObject.put(TaskTypeField.PROCESSING_TIME.getKey(), getFormattedDate(task.getProcessingTime())); - jsonObject.put(TaskTypeField.PROCESSING_BEGIN.getKey(), getFormattedDate(task.getProcessingBegin())); - jsonObject.put(TaskTypeField.PROCESSING_END.getKey(), getFormattedDate(task.getProcessingEnd())); - jsonObject.put(TaskTypeField.HOME_DIRECTORY.getKey(), preventNull(String.valueOf(task.getHomeDirectory()))); - jsonObject.put(TaskTypeField.CORRECTION.getKey(), task.isCorrection()); - jsonObject.put(TaskTypeField.TYPE_METADATA.getKey(), task.isTypeMetadata()); - jsonObject.put(TaskTypeField.TYPE_AUTOMATIC.getKey(), task.isTypeAutomatic()); - jsonObject.put(TaskTypeField.TYPE_IMAGES_READ.getKey(), task.isTypeImagesRead()); - jsonObject.put(TaskTypeField.TYPE_IMAGES_WRITE.getKey(), task.isTypeImagesWrite()); - jsonObject.put(TaskTypeField.BATCH_STEP.getKey(), task.isBatchStep()); - jsonObject.put(TaskTypeField.PROCESSING_USER_ID.getKey(), processingUser); - if (processingUser > 0) { - User user = task.getProcessingUser(); - jsonObject.put(TaskTypeField.PROCESSING_USER_LOGIN.getKey(), user.getLogin()); - jsonObject.put(TaskTypeField.PROCESSING_USER_NAME.getKey(), user.getName()); - jsonObject.put(TaskTypeField.PROCESSING_USER_SURNAME.getKey(), user.getSurname()); - jsonObject.put(TaskTypeField.PROCESSING_USER_FULLNAME.getKey(), user.getFullName()); - } else { - jsonObject.put(TaskTypeField.PROCESSING_USER_LOGIN.getKey(),""); - jsonObject.put(TaskTypeField.PROCESSING_USER_NAME.getKey(), ""); - jsonObject.put(TaskTypeField.PROCESSING_USER_SURNAME.getKey(), ""); - jsonObject.put(TaskTypeField.PROCESSING_USER_FULLNAME.getKey(), ""); - } - jsonObject.put(TaskTypeField.PROCESS_ID.getKey(), getId(task.getProcess())); - jsonObject.put(TaskTypeField.PROCESS_TITLE.getKey(), getTitle(task.getProcess())); - jsonObject.put(TaskTypeField.PROCESS_CREATION_DATE.getKey(), getFormattedDate(getProcessCreationDate(task))); - jsonObject.put(TaskTypeField.CLIENT_ID.getKey(), getClientId(task)); - jsonObject.put(TaskTypeField.PROJECT_ID.getKey(), getProjectId(task)); - jsonObject.put(TaskTypeField.PROJECT_TITLE.getKey(), getProjectTitle(task)); - jsonObject.put(TaskTypeField.RELATED_PROJECT_IDS.getKey(), getRelatedProjectIds(task)); - jsonObject.put(TaskTypeField.TEMPLATE_ID.getKey(), getId(task.getTemplate())); - jsonObject.put(TaskTypeField.TEMPLATE_TITLE.getKey(), getTitle(task.getTemplate())); - jsonObject.put(TaskTypeField.ROLES.getKey(), addObjectRelation(task.getRoles())); - jsonObject.put( - TaskTypeField.CORRECTION_COMMENT_STATUS.getKey(), - ProcessConverter.getCorrectionCommentStatus(task.getProcess()).getValue() - ); - return jsonObject; - } - - /** - * Returns related project ids for a task. - * - *

This includes both the project id of the task's process, - * but also the project ids of the task's templates.

- * - *

Presumbly, this is used to be able to filter tasks based on the - * the projects the current user is allowed to see, see TaskService.

- * - * @param task the task - * @return the list of related project ids - */ - private List getRelatedProjectIds(Task task) { - ArrayList projectIds = new ArrayList<>(); - - if (Objects.nonNull(task.getProcess())) { - projectIds.add(getId(task.getProcess().getProject())); - return projectIds; - } - if (Objects.nonNull(task.getTemplate())) { - List projects = task.getTemplate().getProjects(); - for (Project project : projects) { - projectIds.add(getId(project)); - } - return projectIds; - } - return projectIds; - } - - /** - * Extracts the project id from a task if it has a process. - * - * @param task the task - * @return the project id or null - */ - private int getProjectId(Task task) { - if (Objects.nonNull(task.getProcess())) { - return getId(task.getProcess().getProject()); - } - return 0; - } - - /** - * Extracts process creation date from a task. - * - * @param task the task - * @return the process creation date or null - */ - private Date getProcessCreationDate(Task task) { - if (Objects.nonNull(task.getProcess())) { - return task.getProcess().getCreationDate(); - } - return null; - } - - /** - * Extracts the project title from a task if it has a process. - * - * @param task the task - * @return the project title or null - */ - private String getProjectTitle(Task task) { - if (Objects.nonNull(task.getProcess())) { - return getTitle(task.getProcess().getProject()); - } - return ""; - } - - private int getClientId(Task task) { - if (Objects.nonNull(task.getProcess()) && Objects.nonNull(task.getProcess().getProject())) { - return getId(task.getProcess().getProject().getClient()); - } - if (Objects.nonNull(task.getTemplate()) && Objects.nonNull(task.getTemplate().getClient())) { - return getId(task.getTemplate().getClient()); - } - return 0; - } - -} diff --git a/Kitodo-DataManagement/src/main/java/org/kitodo/data/elasticsearch/index/type/TemplateType.java b/Kitodo-DataManagement/src/main/java/org/kitodo/data/elasticsearch/index/type/TemplateType.java deleted file mode 100644 index 7a2dc62d660..00000000000 --- a/Kitodo-DataManagement/src/main/java/org/kitodo/data/elasticsearch/index/type/TemplateType.java +++ /dev/null @@ -1,45 +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.util.HashMap; -import java.util.Map; - -import org.kitodo.data.database.beans.Template; -import org.kitodo.data.elasticsearch.index.type.enums.ProjectTypeField; -import org.kitodo.data.elasticsearch.index.type.enums.TemplateTypeField; - -public class TemplateType extends BaseType