Skip to content

Commit

Permalink
Adapt to the guidelines of the community board
Browse files Browse the repository at this point in the history
  • Loading branch information
matthias-ronge committed Nov 26, 2024
1 parent f4c192b commit 87121c4
Show file tree
Hide file tree
Showing 13 changed files with 467 additions and 872 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.MappedSuperclass;
import javax.persistence.Transient;

import org.hibernate.Hibernate;
import org.hibernate.search.mapper.pojo.mapping.definition.annotation.GenericField;
Expand Down

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ public class Process extends BaseTemplateBean {
@JoinColumn(name = "docket_id", foreignKey = @ForeignKey(name = "FK_process_docket_id"))
private Docket docket;

@ManyToOne(fetch = FetchType.LAZY)
@ManyToOne
@JoinColumn(name = "project_id", foreignKey = @ForeignKey(name = "FK_process_project_id"))
private Project project;

Expand Down Expand Up @@ -1097,18 +1097,6 @@ public String getKeywordsForSearchingForTaskInformation() {
return initializeKeywords().getSearchTask();
}

/**
* When indexing, outputs the index keywords for searching for metadata.
*
* @return the index keywords for searching for metadata
*/
@Transient
@FullTextField(name = "searchMetadata")
@IndexingDependency(reindexOnUpdate = ReindexOnUpdate.NO)
public String getKeywordsForSearchingForMetadata() {
return initializeKeywords().getSearchMetadata();
}

private IndexingKeyworder initializeKeywords() {
if (this.indexingKeyworder == null) {
IndexingKeyworder indexingKeyworder = new IndexingKeyworder(this);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,18 +30,13 @@
import javax.persistence.Table;
import javax.persistence.Transient;

import org.hibernate.search.mapper.pojo.automaticindexing.ReindexOnUpdate;
import org.hibernate.search.mapper.pojo.mapping.definition.annotation.FullTextField;
import org.hibernate.search.mapper.pojo.mapping.definition.annotation.Indexed;
import org.hibernate.search.mapper.pojo.mapping.definition.annotation.IndexingDependency;
import org.kitodo.data.database.converter.TaskEditTypeConverter;
import org.kitodo.data.database.converter.TaskStatusConverter;
import org.kitodo.data.database.enums.TaskEditType;
import org.kitodo.data.database.enums.TaskStatus;
import org.kitodo.data.database.persistence.TaskDAO;

@Entity
@Indexed(index = "kitodo-task")
@Table(name = "task")
public class Task extends BaseBean {

Expand Down Expand Up @@ -160,9 +155,6 @@ public class Task extends BaseBean {
@Transient
private String editTypeTitle;

@Transient
private transient IndexingKeyworder indexingKeyworder;

/**
* Constructor.
*/
Expand Down Expand Up @@ -928,88 +920,4 @@ public List<Integer> getRoleIds() {
}
return getRoles().stream().map(Role::getId).collect(Collectors.toList());
}

/**
* When indexing, outputs the index keywords for free search.
*
* @return the index keywords for free search
*/
@Transient
@FullTextField(name = "search")
@IndexingDependency(reindexOnUpdate = ReindexOnUpdate.NO)
public String getKeywordsForFreeSearch() {
return initializeKeywords().getSearch();
}

/**
* When indexing, outputs the index keywords for searching in title.
*
* @return the index keywords for searching in title
*/
@Transient
@FullTextField(name = "searchTitle")
@IndexingDependency(reindexOnUpdate = ReindexOnUpdate.NO)
public String getKeywordsForSearchingInTitle() {
return initializeKeywords().getSearchTitle();
}

/**
* When indexing, outputs the index keywords for searching by project name.
*
* @return the index keywords for searching by project name
*/
@Transient
@FullTextField(name = "searchProject")
@IndexingDependency(reindexOnUpdate = ReindexOnUpdate.NO)
public String getKeywordsForSearchingByProjectName() {
return initializeKeywords().getSearchProject();
}

/**
* When indexing, outputs the index keywords for searching for assignment to
* batches.
*
* @return the index keywords for searching for assignment to batches
*/
@Transient
@FullTextField(name = "searchBatch")
@IndexingDependency(reindexOnUpdate = ReindexOnUpdate.NO)
public String getKeywordsForAssignmentToBatches() {
return initializeKeywords().getSearchBatch();
}

/**
* When indexing, outputs the index keywords for searching for task
* information.
*
* @return the index keywords for searching for task information
*/
@Transient
@FullTextField(name = "searchTask")
@IndexingDependency(reindexOnUpdate = ReindexOnUpdate.NO)
public String getKeywordsForSearchingForTaskInformation() {
return initializeKeywords().getSearchTask();
}

/**
* When indexing, outputs the index keywords for searching for metadata.
*
* @return the index keywords for searching for metadata
*/
@Transient
@FullTextField(name = "searchMetadata")
@IndexingDependency(reindexOnUpdate = ReindexOnUpdate.NO)
public String getKeywordsForSearchingForMetadata() {
return initializeKeywords().getSearchMetadata();
}

private IndexingKeyworder initializeKeywords() {
if (this.indexingKeyworder == null) {
IndexingKeyworder indexingKeyworder = new IndexingKeyworder(this);
this.indexingKeyworder = indexingKeyworder;
return indexingKeyworder;
} else {
return indexingKeyworder;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public enum ObjectType {
PROJECT("project", "projects", false, Project.class),
PROPERTY("property", "properties", false, Property.class),
RULESET("ruleset", "rulesets", false, Ruleset.class),
TASK("task", "tasks", true, Task.class),
TASK("task", "tasks", false, Task.class),
TEMPLATE("template", "template", false, Template.class),
USER("user", "users", false, User.class),
ROLE("role", "roles", false, Role.class),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import io.reactivex.annotations.CheckReturnValue;

import java.util.EnumMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Objects;
Expand Down Expand Up @@ -97,9 +98,13 @@ public BaseBeanService(S dao) {
* @return the data objects to be displayed
* @throws DAOException
* if processes cannot be loaded from search index
* @throws UnsupportedOperationException
* if the function is not offered by the implementing class
*/
public abstract List loadData(int offset, int limit, String sortField, SortOrder sortOrder, Map<?, String> filters)
throws DAOException;
public List<T> loadData(int offset, int limit, String sortField, SortOrder sortOrder, Map<?, String> filters)
throws DAOException {
throw new UnsupportedOperationException("optional operation");
}

/**
* Stores an object in the database.
Expand Down Expand Up @@ -194,10 +199,12 @@ public Long count(String query, Map<String, Object> parameters) throws DAOExcept
* @return the number of matching objects
* @throws DAOException
* that can be caused by Hibernate
* @throws DAOException
* that can be caused by ElasticSearch
* @throws UnsupportedOperationException
* if the function is not offered by the implementing class
*/
public abstract Long countResults(Map<?, String> filters) throws DAOException;
public Long countResults(Map<?, String> filters) throws DAOException {
throw new UnsupportedOperationException("optional operation");
}

/**
* Gets an object by its database record number.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@

import org.apache.commons.lang3.tuple.Pair;
import org.kitodo.data.database.beans.BaseBean;
import org.kitodo.data.database.beans.Process;
import org.kitodo.data.database.beans.Role;
import org.kitodo.production.enums.ProcessState;
import org.kitodo.production.services.ServiceManager;
Expand All @@ -35,6 +36,7 @@
*/
public class BeanQuery {
private static final Pattern EXPLICIT_ID_SEARCH = Pattern.compile("id:(\\d+)");
private final FilterService fileterService = ServiceManager.getFilterService();
private final IndexingService indexingService = ServiceManager.getIndexingService();
private final Class<? extends BaseBean> beanClass;
private final String className;
Expand Down Expand Up @@ -294,7 +296,8 @@ public void restrictToRoles(List<Role> roles) {
*/
public void restrictWithUserFilterString(String filterString) {
int userFilterCount = 0;
for (var groupFilter : UserSpecifiedFilterParser.parse(filterString).entrySet()) {
for (var groupFilter : fileterService.parse(filterString, beanClass.isAssignableFrom(Process.class))
.entrySet()) {
List<String> groupFilters = new ArrayList<>();
for (UserSpecifiedFilter searchFilter : groupFilter.getValue()) {
userFilterCount++;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
/*
* (c) Kitodo. Key to digital objects e. V. <[email protected]>
*
* 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.production.services.data;

import java.util.Map;
import java.util.Objects;

/**
* A part of the filter searching on the database for an ID or ID range.
*/
class DatabaseIdQueryPart extends DatabaseQueryPart {

private static final String SECOND_PARAMETER_EXTENSION = "upTo";

private Integer firstId;
private Integer upToId;

/**
* Constructor, creates a new DatabaseQueryPart.
*
* @param filterField
* field to search on
* @param firstId
* first or only ID
* @param upToId
* {@code null} or last ID
*/
DatabaseIdQueryPart(FilterField filterField, String firstId, String upToId, boolean operand) {
super(filterField, operand);
this.firstId = Integer.valueOf(firstId);
this.upToId = Objects.nonNull(upToId) ? Integer.valueOf(upToId) : null;
}

/**
* Returns the part HQL query. If the query contains the keyword "IN", it
* must be queried using JOIN, otherwise using WHERE.
*
* @param className
* "Task" for a query on the tasks table, else for a query on the
* process table.
* @param varName
* variable name to use in the query
* @param parameterName
* parameter name to use in the query
* @return the part HQL query
*/
@Override
String getDatabaseQuery(String className, String varName, String parameterName) {
String query = Objects.equals(className, "Task") ? filterField.getTaskIdQuery()
: filterField.getProcessIdQuery();
return varName + '.' + query + (upToId == null ? (operand ? " = :" : " != :") + parameterName
: (operand ? " BETWEEN :" : " NOT BETWEEN :") + parameterName + " AND :" + parameterName
+ SECOND_PARAMETER_EXTENSION);
}

/**
* Puts the parameters necessary for the query.
*
* @param parameterName
* parameter name used in the query
* @param parameters
* map to put the parameters into
*/
@Override
void addParameters(String parameterName, Map<String, Object> parameters) {
if (Objects.nonNull(filterField.getQueryObject())) {
parameters.put("queryObject", filterField.getQueryObject());
}
parameters.put(parameterName, firstId);
if (Objects.nonNull(upToId)) {
parameters.put(parameterName.concat(SECOND_PARAMETER_EXTENSION), upToId);
}
}

@Override
public String toString() {
return filterField + (upToId == null ? (operand ? " = " : " != ") + firstId
: (operand ? " BETWEEN " : " NOT BETWEEN ") + firstId + " AND " + upToId);
}
}
Loading

0 comments on commit 87121c4

Please sign in to comment.