diff --git a/Kitodo-DataManagement/src/main/java/org/kitodo/data/database/beans/BaseBean.java b/Kitodo-DataManagement/src/main/java/org/kitodo/data/database/beans/BaseBean.java index b994453c647..22863227286 100644 --- a/Kitodo-DataManagement/src/main/java/org/kitodo/data/database/beans/BaseBean.java +++ b/Kitodo-DataManagement/src/main/java/org/kitodo/data/database/beans/BaseBean.java @@ -23,22 +23,25 @@ import org.hibernate.Hibernate; import org.kitodo.data.database.persistence.BaseDAO; +import org.kitodo.data.interfaces.DataInterface; /** * Base bean class. */ @MappedSuperclass -public abstract class BaseBean implements Serializable { +public abstract class BaseBean implements DataInterface, Serializable { @Id @Column(name = "id") @GeneratedValue(strategy = GenerationType.IDENTITY) protected Integer id; + @Override public Integer getId() { return id; } + @Override public void setId(Integer id) { this.id = id; } diff --git a/Kitodo-DataManagement/src/main/java/org/kitodo/data/database/beans/Batch.java b/Kitodo-DataManagement/src/main/java/org/kitodo/data/database/beans/Batch.java index c51d6f10f3d..931bdf09f1d 100644 --- a/Kitodo-DataManagement/src/main/java/org/kitodo/data/database/beans/Batch.java +++ b/Kitodo-DataManagement/src/main/java/org/kitodo/data/database/beans/Batch.java @@ -29,6 +29,8 @@ import org.kitodo.data.database.enums.BatchType; import org.kitodo.data.database.persistence.BatchDAO; +import org.kitodo.data.interfaces.BatchInterface; +import org.kitodo.data.interfaces.ProcessInterface; /** * A user-definable, unordered collection of processes whose batch-type tasks @@ -39,7 +41,7 @@ */ @Entity @Table(name = "batch") -public class Batch extends BaseIndexedBean { +public class Batch extends BaseIndexedBean implements BatchInterface { /** * The batch title. Using titles for batches is optional, the field may be @@ -105,22 +107,12 @@ public Batch(String title, Collection processes) { this.processes = new ArrayList<>(processes); } - /** - * Returns the batch title. Using titles for batches is optional, the field - * may be {@code null}. If so, the function returns null. - * - * @return the batch title - */ + @Override public String getTitle() { return title; } - /** - * Sets a batch title. - * - * @param title - * title of the batch - */ + @Override public void setTitle(String title) { this.title = title; } @@ -134,11 +126,7 @@ public BatchType getType() { return type; } - /** - * Return the processes that belong to the batch. - * - * @return the processes of the batch - */ + @Override public List getProcesses() { initialize(new BatchDAO(), this.processes); if (Objects.isNull(this.processes)) { @@ -147,18 +135,14 @@ public List getProcesses() { return this.processes; } - /** - * Sets the processes that belong to the batch. - * - * @param processes - * processes of the batch - */ - public void setProcesses(List processes) { + @Override + @SuppressWarnings("unchecked") + public void setProcesses(List processes) { if (this.processes == null) { - this.processes = processes; + this.processes = (List) processes; } else { this.processes.clear(); - this.processes.addAll(processes); + this.processes.addAll((List) processes); } } diff --git a/Kitodo-DataManagement/src/main/java/org/kitodo/data/database/beans/Client.java b/Kitodo-DataManagement/src/main/java/org/kitodo/data/database/beans/Client.java index 7711d56dc31..9d523cb2849 100644 --- a/Kitodo-DataManagement/src/main/java/org/kitodo/data/database/beans/Client.java +++ b/Kitodo-DataManagement/src/main/java/org/kitodo/data/database/beans/Client.java @@ -22,13 +22,17 @@ import javax.persistence.JoinColumn; import javax.persistence.JoinTable; import javax.persistence.ManyToMany; +import javax.persistence.OneToMany; import javax.persistence.Table; import org.kitodo.data.database.persistence.ClientDAO; +import org.kitodo.data.interfaces.ClientInterface; +import org.kitodo.data.interfaces.ProjectInterface; +import org.kitodo.data.interfaces.UserInterface; @Entity @Table(name = "client") -public class Client extends BaseBean { +public class Client extends BaseBean implements ClientInterface { @Column(name = "name") private String name; @@ -40,21 +44,18 @@ public class Client extends BaseBean { foreignKey = @ForeignKey(name = "FK_column_id"))}) private List listColumns; - /** - * Gets name. - * - * @return The name. - */ + @ManyToMany(mappedBy = "clients", cascade = CascadeType.PERSIST) + private List users; + + @OneToMany(mappedBy = "client", cascade = CascadeType.ALL, orphanRemoval = true) + private List projects; + + @Override public String getName() { return name; } - /** - * Sets name. - * - * @param name - * The name. - */ + @Override public void setName(String name) { this.name = name; } @@ -99,4 +100,26 @@ public List getListColumns() { public void setListColumns(List columns) { this.listColumns = columns; } + + @Override + public List getUsers() { + return users; + } + + @Override + @SuppressWarnings("unchecked") + public void setUsers(List users) { + this.users = (List) users; + } + + @Override + public List getProjects() { + return projects; + } + + @Override + @SuppressWarnings("unchecked") + public void setProjects(List projects) { + this.projects = (List) projects; + } } diff --git a/Kitodo-DataManagement/src/main/java/org/kitodo/data/database/beans/Docket.java b/Kitodo-DataManagement/src/main/java/org/kitodo/data/database/beans/Docket.java index 76950a7aed2..c934f03c8c3 100644 --- a/Kitodo-DataManagement/src/main/java/org/kitodo/data/database/beans/Docket.java +++ b/Kitodo-DataManagement/src/main/java/org/kitodo/data/database/beans/Docket.java @@ -20,9 +20,12 @@ import javax.persistence.ManyToOne; import javax.persistence.Table; +import org.kitodo.data.interfaces.ClientInterface; +import org.kitodo.data.interfaces.DocketInterface; + @Entity @Table(name = "docket") -public class Docket extends BaseIndexedBean { +public class Docket extends BaseIndexedBean implements DocketInterface { @Column(name = "title") private String title; @@ -37,18 +40,22 @@ public class Docket extends BaseIndexedBean { @JoinColumn(name = "client_id", foreignKey = @ForeignKey(name = "FK_docket_client_id")) private Client client; + @Override public String getTitle() { return title; } + @Override public void setTitle(String title) { this.title = title; } + @Override public String getFile() { return file; } + @Override public void setFile(String file) { this.file = file; } @@ -74,23 +81,14 @@ public void setActive(boolean active) { this.active = active; } - /** - * Get client. - * - * @return Client object - */ + @Override public Client getClient() { return this.client; } - /** - * Set client. - * - * @param client - * as Client object - */ - public void setClient(Client client) { - this.client = client; + @Override + public void setClient(ClientInterface client) { + this.client = (Client) client; } @Override diff --git a/Kitodo-DataManagement/src/main/java/org/kitodo/data/database/beans/Filter.java b/Kitodo-DataManagement/src/main/java/org/kitodo/data/database/beans/Filter.java index 120eaa1a4d1..9c38e18bb20 100644 --- a/Kitodo-DataManagement/src/main/java/org/kitodo/data/database/beans/Filter.java +++ b/Kitodo-DataManagement/src/main/java/org/kitodo/data/database/beans/Filter.java @@ -21,12 +21,14 @@ import javax.persistence.ManyToOne; import javax.persistence.Table; +import org.kitodo.data.interfaces.FilterInterface; + /** * Filter bean. */ @Entity @Table(name = "filter") -public class Filter extends BaseIndexedBean { +public class Filter extends BaseIndexedBean implements FilterInterface { @Column(name = "value", columnDefinition = "longtext") private String value; @@ -38,21 +40,12 @@ public class Filter extends BaseIndexedBean { @JoinColumn(name = "user_id", foreignKey = @ForeignKey(name = "FK_filter_user_id")) private User user; - /** - * Get filter value. - * - * @return filter value - */ + @Override public String getValue() { return value; } - /** - * Set filter value. - * - * @param value - * filter - */ + @Override public void setValue(String value) { this.value = value; } diff --git a/Kitodo-DataManagement/src/main/java/org/kitodo/data/database/beans/Process.java b/Kitodo-DataManagement/src/main/java/org/kitodo/data/database/beans/Process.java index a04e7800c43..6e2088a8af6 100644 --- a/Kitodo-DataManagement/src/main/java/org/kitodo/data/database/beans/Process.java +++ b/Kitodo-DataManagement/src/main/java/org/kitodo/data/database/beans/Process.java @@ -17,6 +17,7 @@ import java.util.List; import java.util.Map; import java.util.Objects; +import java.util.stream.Collectors; import javax.persistence.CascadeType; import javax.persistence.Column; @@ -31,11 +32,23 @@ import javax.persistence.Table; import javax.persistence.Transient; +import org.apache.commons.collections.CollectionUtils; +import org.kitodo.data.database.enums.TaskStatus; +import org.kitodo.data.database.persistence.HibernateUtil; import org.kitodo.data.database.persistence.ProcessDAO; +import org.kitodo.data.elasticsearch.index.converter.ProcessConverter; +import org.kitodo.data.interfaces.BatchInterface; +import org.kitodo.data.interfaces.DocketInterface; +import org.kitodo.data.interfaces.ProcessInterface; +import org.kitodo.data.interfaces.ProjectInterface; +import org.kitodo.data.interfaces.PropertyInterface; +import org.kitodo.data.interfaces.RulesetInterface; +import org.kitodo.data.interfaces.TaskInterface; +import org.kitodo.data.interfaces.UserInterface; @Entity @Table(name = "process") -public class Process extends BaseTemplateBean { +public class Process extends BaseTemplateBean implements ProcessInterface { @Column(name = "sortHelperImages") private Integer sortHelperImages; @@ -120,7 +133,7 @@ public class Process extends BaseTemplateBean { private String ocrdWorkflowId; @Transient - private User blockedUser; + private UserInterface blockedUser; @Transient private List> metadata; @@ -152,10 +165,9 @@ public Process() { } /** - * Get sorting helper for images. - * - * @return sorting helper as Integer, in case of null it returns 0 + * {@inheritDoc} In case of {@code null}, it returns 0. */ + @Override public Integer getSortHelperImages() { if (this.sortHelperImages == null) { this.sortHelperImages = 0; @@ -163,15 +175,15 @@ public Integer getSortHelperImages() { return this.sortHelperImages; } + @Override public void setSortHelperImages(Integer sortHelperImages) { this.sortHelperImages = sortHelperImages; } /** - * Get sorting helper for articles. - * - * @return sorting helper as Integer, in case of null it returns 0 + * {@inheritDoc} In case of {@code null}, it returns 0. */ + @Override public Integer getSortHelperArticles() { if (this.sortHelperArticles == null) { this.sortHelperArticles = 0; @@ -179,15 +191,15 @@ public Integer getSortHelperArticles() { return this.sortHelperArticles; } + @Override public void setSortHelperArticles(Integer sortHelperArticles) { this.sortHelperArticles = sortHelperArticles; } /** - * Get sorting helper for document structure. - * - * @return sorting helper as Integer, in case of null it returns 0 + * {@inheritDoc} In case of {@code null}, it returns 0. */ + @Override public Integer getSortHelperDocstructs() { if (this.sortHelperDocstructs == null) { this.sortHelperDocstructs = 0; @@ -195,15 +207,15 @@ public Integer getSortHelperDocstructs() { return this.sortHelperDocstructs; } + @Override public void setSortHelperDocstructs(Integer sortHelperDocstructs) { this.sortHelperDocstructs = sortHelperDocstructs; } /** - * Get sorting helper for metadata. - * - * @return sorting helper as Integer, in case of null it returns 0 + * {@inheritDoc} In case of {@code null}, it returns 0. */ + @Override public Integer getSortHelperMetadata() { if (this.sortHelperMetadata == null) { this.sortHelperMetadata = 0; @@ -211,41 +223,27 @@ public Integer getSortHelperMetadata() { return this.sortHelperMetadata; } + @Override public void setSortHelperMetadata(Integer sortHelperMetadata) { this.sortHelperMetadata = sortHelperMetadata; } - /** - * Get wikiField. - * - * @return value of wikiField - */ + @Override public String getWikiField() { return this.wikiField; } - /** - * Set wikiField. - * - * @param wikiField as java.lang.String - */ + @Override public void setWikiField(String wikiField) { this.wikiField = wikiField; } - /** - * Gets the process base URI. - */ + @Override public URI getProcessBaseUri() { return Objects.isNull(processBaseUri) ? null : URI.create(processBaseUri); } - /** - * Sets the process base URI. - * - * @param processBaseUri - * the given process base URI - */ + @Override public void setProcessBaseUri(URI processBaseUri) { this.processBaseUri = Objects.isNull(processBaseUri) ? null : processBaseUri.toString(); } @@ -262,34 +260,41 @@ public Integer getOrdering() { /** * Set ordering. * - * @param ordering as java.lang.Integer + * @param ordering + * as java.lang.Integer */ public void setOrdering(Integer ordering) { this.ordering = ordering; } + @Override public Project getProject() { return this.project; } - public void setProject(Project project) { - this.project = project; + @Override + public void setProject(ProjectInterface project) { + this.project = (Project) project; } + @Override public Ruleset getRuleset() { return this.ruleset; } - public void setRuleset(Ruleset ruleset) { - this.ruleset = ruleset; + @Override + public void setRuleset(RulesetInterface ruleset) { + this.ruleset = (Ruleset) ruleset; } + @Override public Docket getDocket() { return docket; } - public void setDocket(Docket docket) { - this.docket = docket; + @Override + public void setDocket(DocketInterface docket) { + this.docket = (Docket) docket; } /** @@ -304,7 +309,8 @@ public Template getTemplate() { /** * Set template. * - * @param template as Template object + * @param template + * as Template object */ public void setTemplate(Template template) { this.template = template; @@ -322,7 +328,8 @@ public Process getParent() { /** * Set parent. * - * @param parent as org.kitodo.data.database.beans.Process + * @param parent + * as org.kitodo.data.database.beans.Process */ public void setParent(Process parent) { this.parent = parent; @@ -344,17 +351,14 @@ public List getChildren() { /** * Set children. * - * @param children as List of Process objects + * @param children + * as List of Process objects */ public void setChildren(List children) { this.children = children; } - /** - * Get list of task. - * - * @return list of Task objects or empty list - */ + @Override public List getTasks() { initialize(new ProcessDAO(), this.tasks); if (Objects.isNull(this.tasks)) { @@ -363,8 +367,10 @@ public List getTasks() { return this.tasks; } - public void setTasks(List tasks) { - this.tasks = tasks; + @Override + @SuppressWarnings("unchecked") + public void setTasks(List tasks) { + this.tasks = (List) tasks; } /** @@ -414,11 +420,7 @@ public void setWorkpieces(List workpieces) { this.workpieces = workpieces; } - /** - * Get list of batches or empty list. - * - * @return list of batches or empty list - */ + @Override public List getBatches() { initialize(new ProcessDAO(), this.batches); if (Objects.isNull(this.batches)) { @@ -427,18 +429,17 @@ public List getBatches() { return this.batches; } - /** - * Set batches, if list is empty just set, if not first clear and next set. - * - * @param batches - * list + /* + * If list is empty just set, if not first clear and next set. */ - public void setBatches(List batches) { + @Override + @SuppressWarnings("unchecked") + public void setBatches(List batches) { if (this.batches == null) { - this.batches = batches; + this.batches = (List) batches; } else { this.batches.clear(); - this.batches.addAll(batches); + this.batches.addAll((List) batches); } } @@ -458,17 +459,14 @@ public List getComments() { /** * Set comments. * - * @param comments as List of Comment objects + * @param comments + * as List of Comment objects */ public void setComments(List comments) { this.comments = comments; } - /** - * Get list of properties. - * - * @return list of Property objects or empty list - */ + @Override public List getProperties() { initialize(new ProcessDAO(), this.properties); if (Objects.isNull(this.properties)) { @@ -477,8 +475,10 @@ public List getProperties() { return this.properties; } - public void setProperties(List properties) { - this.properties = properties; + @Override + @SuppressWarnings("unchecked") + public void setProperties(List properties) { + this.properties = (List) properties; } /** @@ -493,7 +493,8 @@ public boolean isExported() { /** * Set exported. * - * @param exported as boolean + * @param exported + * as boolean */ public void setExported(boolean exported) { this.exported = exported; @@ -511,45 +512,29 @@ public List> getMetadata() { /** * Set metadata. * - * @param metadata as Map + * @param metadata + * as Map */ public void setMetadata(List> metadata) { this.metadata = metadata; } - /** - * Get blocked user. - * - * @return User object if this user is blocked - */ - public User getBlockedUser() { + @Override + public UserInterface getBlockedUser() { return blockedUser; } - /** - * Set blocked user. - * - * @param blockedUser - * User object - */ - public void setBlockedUser(User blockedUser) { + @Override + public void setBlockedUser(UserInterface blockedUser) { this.blockedUser = blockedUser; } - /** - * Get baseType. - * - * @return value of baseType - */ + @Override public String getBaseType() { return baseType; } - /** - * Set baseType. - * - * @param baseType as java.lang.String - */ + @Override public void setBaseType(String baseType) { this.baseType = baseType; } @@ -566,7 +551,8 @@ public Boolean getInChoiceListShown() { /** * Set inChoiceListShown. * - * @param inChoiceListShown as java.lang.Boolean + * @param inChoiceListShown + * as java.lang.Boolean */ public void setInChoiceListShown(Boolean inChoiceListShown) { this.inChoiceListShown = inChoiceListShown; @@ -574,8 +560,9 @@ public void setInChoiceListShown(Boolean inChoiceListShown) { /** * Determines whether or not two processes are equal. Two instances of - * {@code Process} are equal if the values of their {@code Id}, {@code Title}, - * {@code OutputName} and {@code CreationDate} member fields are the same. + * {@code Process} are equal if the values of their {@code Id}, + * {@code Title}, {@code OutputName} and {@code CreationDate} member fields + * are the same. * * @param object * An object to be compared with this {@code Process}. @@ -601,56 +588,32 @@ public int hashCode() { return Objects.hash(this.getId()); } - /** - * Get amount of structure elements. - * - * @return Amount of structure elements - */ + @Override public Integer getNumberOfStructures() { return numberOfStructures; } - /** - * Get amount of meta data elements. - * - * @return Amount of meta data elements - */ + @Override public Integer getNumberOfMetadata() { return numberOfMetadata; } - /** - * Set amount of meta data elements. - * - * @param numberOfMetadata Integer value of amount of meta data elements - */ + @Override public void setNumberOfMetadata(Integer numberOfMetadata) { this.numberOfMetadata = numberOfMetadata; } - /** - * Get amount of images. - * - * @return Integer value of amount of images - */ + @Override public Integer getNumberOfImages() { return numberOfImages; } - /** - * Set amount of images. - * - * @param numberOfImages Integer value of amount of images - */ + @Override public void setNumberOfImages(Integer numberOfImages) { this.numberOfImages = numberOfImages; } - /** - * Set amount of structure elements. - * - * @param numberOfStructures Integer value of amount of structure elements - */ + @Override public void setNumberOfStructures(Integer numberOfStructures) { this.numberOfStructures = numberOfStructures; } @@ -668,9 +631,118 @@ public String getOcrdWorkflowId() { * Set the OCR-D workflow identifier. * * @param ocrdWorkflowId - * The identifier of the OCR-D workflow + * The identifier of the OCR-D workflow */ public void setOcrdWorkflowId(String ocrdWorkflowId) { this.ocrdWorkflowId = ocrdWorkflowId; } + + @Override + public Double getProgressClosed() { + if (CollectionUtils.isEmpty(tasks)) { + return 0.0; + } + return getProgressPercentageExact(TaskStatus.DONE); + } + + @Override + public Double getProgressInProcessing() { + if (CollectionUtils.isEmpty(tasks)) { + return 0.0; + } + return getProgressPercentageExact(TaskStatus.INWORK); + } + + @Override + public Double getProgressLocked() { + if (CollectionUtils.isEmpty(tasks)) { + return 100.0; + } + return getProgressPercentageExact(TaskStatus.LOCKED); + + } + + @Override + public Double getProgressOpen() { + if (CollectionUtils.isEmpty(tasks)) { + return 0.0; + } + return getProgressPercentageExact(TaskStatus.OPEN); + } + + private Double getProgressPercentageExact(TaskStatus status) { + Map taskProgress = ProcessConverter.getTaskProgressPercentageOfProcess(this, true); + return taskProgress.get(status); + } + + @Override + public String getProgressCombined() { + Map taskProgress = ProcessConverter.getTaskProgressPercentageOfProcess(this, true); + return ProcessConverter.getCombinedProgressFromTaskPercentages(taskProgress); + } + + @Override + public String getBatchID() { + return batches.stream().map(Batch::getTitle).collect(Collectors.joining(", ")); + } + + @Override + public Integer getParentID() { + return Objects.nonNull(parent) ? parent.getId() : null; + } + + @Override + public void setParentID(Integer parentID) { + this.parent = HibernateUtil.getSession().get(Process.class, parentID); + } + + @Override + public boolean hasChildren() { + return CollectionUtils.isNotEmpty(children); + } + + @Override + public void setHasChildren(boolean hasChildren) { + if (!hasChildren && Objects.nonNull(children)) { + children.forEach(child -> child.setParent(null)); + children.clear(); + } else if (hasChildren && CollectionUtils.isEmpty(children)) { + throw new UnsupportedOperationException("cannot insert child processes"); + } + } + + @Override + public String getLastEditingUser() { + return ProcessConverter.getLastEditingUser(this); + } + + @Override + public Date getProcessingBeginLastTask() { + return ProcessConverter.getLastProcessingBegin(this); + } + + @Override + public Date getProcessingEndLastTask() { + return ProcessConverter.getLastProcessingEnd(this); + } + + @Override + public Integer getCorrectionCommentStatus() { + return ProcessConverter.getCorrectionCommentStatus(this).getValue(); + } + + @Override + public boolean hasComments() { + return CollectionUtils.isNotEmpty(comments); + } + + @Override + public void setHasComments(boolean hasComments) { + if (!hasComments && Objects.nonNull(comments)) { + comments.forEach(comment -> comment.setProcess(null)); + comments.clear(); + } else if (hasComments && CollectionUtils.isEmpty(comments)) { + throw new UnsupportedOperationException("cannot insert comments"); + } + } } diff --git a/Kitodo-DataManagement/src/main/java/org/kitodo/data/database/beans/Project.java b/Kitodo-DataManagement/src/main/java/org/kitodo/data/database/beans/Project.java index 0561483b1cc..10e4050e1da 100644 --- a/Kitodo-DataManagement/src/main/java/org/kitodo/data/database/beans/Project.java +++ b/Kitodo-DataManagement/src/main/java/org/kitodo/data/database/beans/Project.java @@ -12,9 +12,13 @@ package org.kitodo.data.database.beans; import java.util.ArrayList; +import java.util.Collections; import java.util.Date; import java.util.List; +import java.util.Map; import java.util.Objects; +import java.util.function.Function; +import java.util.stream.Collectors; import javax.persistence.CascadeType; import javax.persistence.Column; @@ -28,12 +32,17 @@ import javax.persistence.OneToMany; import javax.persistence.Table; +import org.apache.commons.collections.CollectionUtils; import org.kitodo.data.database.enums.PreviewHoverMode; import org.kitodo.data.database.persistence.ProjectDAO; +import org.kitodo.data.interfaces.ClientInterface; +import org.kitodo.data.interfaces.ProjectInterface; +import org.kitodo.data.interfaces.TemplateInterface; +import org.kitodo.data.interfaces.UserInterface; @Entity @Table(name = "project") -public class Project extends BaseIndexedBean implements Comparable { +public class Project extends BaseIndexedBean implements ProjectInterface, Comparable { @Column(name = "title", nullable = false, unique = true) private String title; @@ -187,19 +196,17 @@ public Project() { this.dmsImportRootPath = ""; } + @Override public String getTitle() { return this.title; } + @Override public void setTitle(String title) { this.title = title; } - /** - * Returns the list of users of this project. - * - * @return the folders - */ + @Override public List getUsers() { initialize(new ProjectDAO(), this.users); if (Objects.isNull(this.users)) { @@ -208,8 +215,10 @@ public List getUsers() { return this.users; } - public void setUsers(List users) { - this.users = users; + @Override + @SuppressWarnings("unchecked") + public void setUsers(List users) { + this.users = (List) users; } /** @@ -283,10 +292,12 @@ public void setFolders(List folders) { this.folders = folders; } + @Override public String getMetsRightsOwner() { return this.metsRightsOwner; } + @Override public void setMetsRightsOwner(String metsRightsOwner) { this.metsRightsOwner = metsRightsOwner; } @@ -361,6 +372,7 @@ public String getMetsContentIDs() { * @return number of volumes for this project */ + @Override public Integer getNumberOfVolumes() { if (this.numberOfVolumes == null) { this.numberOfVolumes = 0; @@ -375,15 +387,12 @@ public Integer getNumberOfVolumes() { * for this project */ + @Override public void setNumberOfVolumes(Integer numberOfVolumes) { this.numberOfVolumes = numberOfVolumes; } - /** - * Get number of pages. - * - * @return number of pages - */ + @Override public Integer getNumberOfPages() { if (this.numberOfPages == null) { this.numberOfPages = 0; @@ -391,21 +400,12 @@ public Integer getNumberOfPages() { return this.numberOfPages; } - /** - * Set number of pages. - * - * @param numberOfPages - * the number of pages to set - */ + @Override public void setNumberOfPages(Integer numberOfPages) { this.numberOfPages = numberOfPages; } - /** - * Get start date. - * - * @return the start date - */ + @Override public Date getStartDate() { if (this.startDate == null) { this.startDate = new Date(); @@ -413,15 +413,12 @@ public Date getStartDate() { return this.startDate; } + @Override public void setStartDate(Date startDate) { this.startDate = startDate; } - /** - * Get end date. - * - * @return the end date - */ + @Override public Date getEndDate() { if (this.endDate == null) { this.endDate = new Date(); @@ -429,46 +426,29 @@ public Date getEndDate() { return this.endDate; } + @Override public void setEndDate(Date endDate) { this.endDate = endDate; } - /** - * Set if project is active. - * - * @param active - * whether project is active - */ + @Override public void setActive(boolean active) { this.active = active; } - /** - * Get if project is active. - * - * @return whether project is active - */ + @Override public boolean isActive() { return this.active; } - /** - * Gets client. - * - * @return The client. - */ + @Override public Client getClient() { return client; } - /** - * Sets client. - * - * @param client - * The client. - */ - public void setClient(Client client) { - this.client = client; + @Override + public void setClient(ClientInterface client) { + this.client = (Client) client; } /** @@ -721,4 +701,46 @@ public int hashCode() { return this.title == null ? 0 : this.title.hashCode(); } + @Override + public List getActiveTemplates() { + if (Objects.isNull(templates)) { + return null; + } + return templates.stream().filter(template -> template.isActive()).collect(Collectors.toList()); + } + + @SuppressWarnings("unchecked") + @Override + public void setActiveTemplates(List activeTemplates) { + if (Objects.isNull(activeTemplates)) { + activeTemplates = Collections.emptyList(); + } + Map activeTemplatesMap = activeTemplates.stream() + .collect(Collectors.toMap(TemplateInterface::getId, Function.identity())); + + if (Objects.isNull(this.templates) && CollectionUtils.isNotEmpty(activeTemplates)) { + this.templates = new ArrayList<>(); + } + for (Template assignedTemplate : this.templates) { + assignedTemplate.setActive(Objects.nonNull(activeTemplatesMap.remove(assignedTemplate.getId()))); + } + for (Template unassignedTemplate : ((Map) activeTemplatesMap).values()) { + unassignedTemplate.setActive(true); + this.templates.add(unassignedTemplate); + } + } + + @Override + public boolean hasProcesses() { + return CollectionUtils.isNotEmpty(processes); + } + + @Override + public void setHasProcesses(boolean hasProcesses) { + if (!hasProcesses && CollectionUtils.isNotEmpty(processes)) { + processes.clear(); + } else if (hasProcesses && CollectionUtils.isEmpty(processes)) { + throw new UnsupportedOperationException("cannot add processes"); + } + } } diff --git a/Kitodo-DataManagement/src/main/java/org/kitodo/data/database/beans/Property.java b/Kitodo-DataManagement/src/main/java/org/kitodo/data/database/beans/Property.java index 2863bd452d7..994eeec34e9 100644 --- a/Kitodo-DataManagement/src/main/java/org/kitodo/data/database/beans/Property.java +++ b/Kitodo-DataManagement/src/main/java/org/kitodo/data/database/beans/Property.java @@ -26,10 +26,11 @@ import org.kitodo.data.database.converter.PropertyTypeConverter; import org.kitodo.data.database.enums.PropertyType; import org.kitodo.data.database.persistence.PropertyDAO; +import org.kitodo.data.interfaces.PropertyInterface; @Entity @Table(name = "property") -public class Property extends BaseIndexedBean implements Comparable { +public class Property extends BaseIndexedBean implements PropertyInterface, Comparable { @Column(name = "title") private String title; @@ -68,40 +69,22 @@ public Property() { this.creationDate = new Date(); } - /** - * Get title. - * - * @return title as String - */ + @Override public String getTitle() { return this.title; } - /** - * Set title. - * - * @param title - * as String - */ + @Override public void setTitle(String title) { this.title = title; } - /** - * Get value. - * - * @return value as String - */ + @Override public String getValue() { return this.value; } - /** - * Set value. - * - * @param value - * as String - */ + @Override public void setValue(String value) { this.value = value; } @@ -147,21 +130,12 @@ public void setObligatory(Boolean obligatory) { this.obligatory = obligatory; } - /** - * Get creation date. - * - * @return creation date as Date - */ + @Override public Date getCreationDate() { return this.creationDate; } - /** - * Set creation date. - * - * @param creationDate - * as Date - */ + @Override public void setCreationDate(Date creationDate) { this.creationDate = creationDate; } @@ -264,6 +238,7 @@ public void setWorkpieces(List workpieces) { * object * @return int */ + @Override public int compareTo(Property property) { int titleMatch = this.getTitle().toLowerCase().compareTo(property.getTitle().toLowerCase()); int valueMatch = this.getValue().toLowerCase().compareTo(property.getValue().toLowerCase()); diff --git a/Kitodo-DataManagement/src/main/java/org/kitodo/data/database/beans/Role.java b/Kitodo-DataManagement/src/main/java/org/kitodo/data/database/beans/Role.java index 925fb74a811..911e2fe38a5 100644 --- a/Kitodo-DataManagement/src/main/java/org/kitodo/data/database/beans/Role.java +++ b/Kitodo-DataManagement/src/main/java/org/kitodo/data/database/beans/Role.java @@ -26,10 +26,13 @@ import javax.persistence.Table; import org.kitodo.data.database.persistence.RoleDAO; +import org.kitodo.data.interfaces.ClientInterface; +import org.kitodo.data.interfaces.RoleInterface; +import org.kitodo.data.interfaces.UserInterface; @Entity @Table(name = "role") -public class Role extends BaseBean implements Comparable { +public class Role extends BaseBean implements RoleInterface, Comparable { @Column(name = "title", nullable = false) private String title; @@ -60,11 +63,7 @@ public Role() { this.authorities = new ArrayList<>(); } - /** - * Gets title. - * - * @return The title. - */ + @Override public String getTitle() { if (this.title == null) { return ""; @@ -73,12 +72,7 @@ public String getTitle() { } } - /** - * Sets title. - * - * @param title - * The title. - */ + @Override public void setTitle(String title) { this.title = title; } @@ -106,11 +100,7 @@ public void setAuthorities(List authorities) { this.authorities = authorities; } - /** - * Gets users. - * - * @return The users. - */ + @Override public List getUsers() { initialize(new RoleDAO(), this.users); if (Objects.isNull(this.users)) { @@ -119,14 +109,10 @@ public List getUsers() { return this.users; } - /** - * Sets users. - * - * @param users - * The users. - */ - public void setUsers(List users) { - this.users = users; + @Override + @SuppressWarnings("unchecked") + public void setUsers(List users) { + this.users = (List) users; } /** @@ -152,23 +138,14 @@ public void setTasks(List tasks) { this.tasks = tasks; } - /** - * Get client. - * - * @return the client bean - */ + @Override public Client getClient() { return client; } - /** - * Set client. - * - * @param client - * bean - */ - public void setClient(Client client) { - this.client = client; + @Override + public void setClient(ClientInterface client) { + this.client = (Client) client; } @Override diff --git a/Kitodo-DataManagement/src/main/java/org/kitodo/data/database/beans/Ruleset.java b/Kitodo-DataManagement/src/main/java/org/kitodo/data/database/beans/Ruleset.java index 0de612f1e50..ec69122dfa5 100644 --- a/Kitodo-DataManagement/src/main/java/org/kitodo/data/database/beans/Ruleset.java +++ b/Kitodo-DataManagement/src/main/java/org/kitodo/data/database/beans/Ruleset.java @@ -20,9 +20,12 @@ import javax.persistence.ManyToOne; import javax.persistence.Table; +import org.kitodo.data.interfaces.ClientInterface; +import org.kitodo.data.interfaces.RulesetInterface; + @Entity @Table(name = "ruleset") -public class Ruleset extends BaseIndexedBean { +public class Ruleset extends BaseIndexedBean implements RulesetInterface { @Column(name = "title") private String title; @@ -40,27 +43,27 @@ public class Ruleset extends BaseIndexedBean { @JoinColumn(name = "client_id", foreignKey = @ForeignKey(name = "FK_ruleset_client_id")) private Client client; + @Override public String getTitle() { return this.title; } + @Override public void setTitle(String title) { this.title = title; } + @Override public String getFile() { return this.file; } + @Override public void setFile(String file) { this.file = file; } - /** - * Check if metadata should be ordered by ruleset. - * - * @return true or false - */ + @Override public boolean isOrderMetadataByRuleset() { if (this.orderMetadataByRuleset == null) { this.orderMetadataByRuleset = false; @@ -68,21 +71,12 @@ public boolean isOrderMetadataByRuleset() { return this.orderMetadataByRuleset; } - /** - * Set if metadata should be ordered by ruleset. - * - * @param orderMetadataByRuleset - * true or false - */ + @Override public void setOrderMetadataByRuleset(boolean orderMetadataByRuleset) { this.orderMetadataByRuleset = orderMetadataByRuleset; } - /** - * Check if ruleset is active. - * - * @return true or false - */ + @Override public Boolean isActive() { if (Objects.isNull(this.active)) { this.active = true; @@ -90,32 +84,19 @@ public Boolean isActive() { return this.active; } - /** - * Set ruleset as active. - * - * @param active as boolean - */ + @Override public void setActive(boolean active) { this.active = active; } - /** - * Get client. - * - * @return Client object - */ + @Override public Client getClient() { return this.client; } - /** - * Set client. - * - * @param client - * as Client object - */ - public void setClient(Client client) { - this.client = client; + @Override + public void setClient(ClientInterface client) { + this.client = (Client) client; } @Override diff --git a/Kitodo-DataManagement/src/main/java/org/kitodo/data/database/beans/Task.java b/Kitodo-DataManagement/src/main/java/org/kitodo/data/database/beans/Task.java index 8c5dd7d1f9d..b15420c4d68 100644 --- a/Kitodo-DataManagement/src/main/java/org/kitodo/data/database/beans/Task.java +++ b/Kitodo-DataManagement/src/main/java/org/kitodo/data/database/beans/Task.java @@ -35,10 +35,15 @@ import org.kitodo.data.database.enums.TaskEditType; import org.kitodo.data.database.enums.TaskStatus; import org.kitodo.data.database.persistence.TaskDAO; +import org.kitodo.data.interfaces.ProcessInterface; +import org.kitodo.data.interfaces.RoleInterface; +import org.kitodo.data.interfaces.TaskInterface; +import org.kitodo.data.interfaces.TemplateInterface; +import org.kitodo.data.interfaces.UserInterface; @Entity @Table(name = "task") -public class Task extends BaseIndexedBean { +public class Task extends BaseIndexedBean implements TaskInterface { @Column(name = "title") private String title; @@ -149,6 +154,12 @@ public class Task extends BaseIndexedBean { @Transient private String localizedTitle; + @Transient + private String processingStatusTitle; + + @Transient + private String editTypeTitle; + /** * Constructor. */ @@ -191,80 +202,72 @@ public Task(Task templateTask) { this.roles = new ArrayList<>(templateTask.getRoles()); } + @Override public String getTitle() { return this.title; } + @Override public void setTitle(String title) { this.title = title; } + @Override public Integer getOrdering() { return this.ordering; } + @Override public void setOrdering(Integer ordering) { this.ordering = ordering; } - /** - * Get editType as {@link TaskEditType}. - * - * @return current edit type - */ + @Override public TaskEditType getEditType() { return this.editType; } - /** - * Set editType to specific value from {@link TaskEditType}. - * - * @param inputType - * as {@link TaskEditType} - */ + @Override public void setEditType(TaskEditType inputType) { this.editType = inputType; } - /** - * Set processing status to specific value from {@link TaskStatus}. - * - * @param inputStatus - * as {@link TaskStatus} - */ + @Override public void setProcessingStatus(TaskStatus inputStatus) { this.processingStatus = inputStatus; } - /** - * Get processing status as {@link TaskStatus}. - * - * @return current processing status - */ + @Override public TaskStatus getProcessingStatus() { return this.processingStatus; } + @Override public Date getProcessingTime() { return this.processingTime; } + @Override public void setProcessingTime(Date processingTime) { this.processingTime = processingTime; } + @Override public Date getProcessingBegin() { return this.processingBegin; } + @Override public void setProcessingBegin(Date processingBegin) { this.processingBegin = processingBegin; } + @Override public Date getProcessingEnd() { return this.processingEnd; } + @Override public void setProcessingEnd(Date processingEnd) { this.processingEnd = processingEnd; } @@ -315,57 +318,44 @@ public void setLast(boolean last) { this.last = last; } - /** - * Get correction. - * - * @return value of correction - */ + @Override public boolean isCorrection() { return correction; } - /** - * Set correction. - * - * @param correction as boolean - */ + @Override public void setCorrection(boolean correction) { this.correction = correction; } + @Override public User getProcessingUser() { return this.processingUser; } - public void setProcessingUser(User processingUser) { - this.processingUser = processingUser; + @Override + public void setProcessingUser(UserInterface processingUser) { + this.processingUser = (User) processingUser; } + @Override public Process getProcess() { return this.process; } - public void setProcess(Process process) { - this.process = process; + @Override + public void setProcess(ProcessInterface process) { + this.process = (Process) process; } - /** - * Get template. - * - * @return value of template - */ + @Override public Template getTemplate() { return this.template; } - /** - * Set template. - * - * @param template - * as Template - */ - public void setTemplate(Template template) { - this.template = template; + @Override + public void setTemplate(TemplateInterface template) { + this.template = (Template) template; } /** @@ -420,25 +410,25 @@ public List getValidationFolders() { return validationFolders; } + @Override public boolean isTypeImagesRead() { return this.typeImagesRead; } + @Override public void setTypeImagesRead(boolean typeImagesRead) { this.typeImagesRead = typeImagesRead; } + @Override public boolean isTypeImagesWrite() { return this.typeImagesWrite; } /** - * Set task type images. If types is true, it also sets type images read to - * true. - * - * @param typeImagesWrite - * true or false + * {@inheritDoc} If true, the user is also given file system access. */ + @Override public void setTypeImagesWrite(boolean typeImagesWrite) { this.typeImagesWrite = typeImagesWrite; if (typeImagesWrite) { @@ -490,10 +480,12 @@ public void setTypeExportDMS(boolean typeExportDMS) { this.typeExportDMS = typeExportDMS; } + @Override public boolean isTypeMetadata() { return this.typeMetadata; } + @Override public void setTypeMetadata(boolean typeMetadata) { this.typeMetadata = typeMetadata; } @@ -506,10 +498,12 @@ public void setTypeAcceptClose(boolean typeAcceptClose) { this.typeAcceptClose = typeAcceptClose; } + @Override public boolean isTypeAutomatic() { return this.typeAutomatic; } + @Override public void setTypeAutomatic(boolean typeAutomatic) { this.typeAutomatic = typeAutomatic; } @@ -578,10 +572,12 @@ public void setWorkflowCondition(WorkflowCondition workflowCondition) { this.workflowCondition = workflowCondition; } + @Override public boolean isBatchStep() { return this.batchStep; } + @Override public void setBatchStep(boolean batchStep) { this.batchStep = batchStep; } @@ -604,21 +600,12 @@ public void setRepeatOnCorrection(boolean repeatOnCorrection) { this.repeatOnCorrection = repeatOnCorrection; } - /** - * Get localized title. - * - * @return localized title as String - */ + @Override public String getLocalizedTitle() { return this.localizedTitle; } - /** - * Set localized titles as String. - * - * @param localizedTitle - * as String - */ + @Override public void setLocalizedTitle(String localizedTitle) { this.localizedTitle = localizedTitle; } @@ -657,4 +644,32 @@ public boolean equals(Object object) { public int hashCode() { return Objects.hash(title, processingTime, processingBegin, processingEnd, process, template); } + + @Override + public String getProcessingStatusTitle() { + return processingStatusTitle; + } + + @Override + public void setProcessingStatusTitle(String processingStatusTitle) { + this.processingStatusTitle = processingStatusTitle; + } + + @Override + public String getEditTypeTitle() { + return editTypeTitle; + } + + @Override + public void setEditTypeTitle(String editTypeTitle) { + this.editTypeTitle = editTypeTitle; + } + + @Override + public List getRoleIds() { + if (Objects.isNull(roles)) { + return null; + } + return roles.stream().map(RoleInterface::getId).collect(Collectors.toList()); + } } diff --git a/Kitodo-DataManagement/src/main/java/org/kitodo/data/database/beans/Template.java b/Kitodo-DataManagement/src/main/java/org/kitodo/data/database/beans/Template.java index e26c256a697..9d09f20d9da 100644 --- a/Kitodo-DataManagement/src/main/java/org/kitodo/data/database/beans/Template.java +++ b/Kitodo-DataManagement/src/main/java/org/kitodo/data/database/beans/Template.java @@ -27,11 +27,18 @@ import javax.persistence.OneToMany; import javax.persistence.Table; +import org.apache.commons.collections.CollectionUtils; import org.kitodo.data.database.persistence.TemplateDAO; +import org.kitodo.data.interfaces.DocketInterface; +import org.kitodo.data.interfaces.ProjectInterface; +import org.kitodo.data.interfaces.RulesetInterface; +import org.kitodo.data.interfaces.TaskInterface; +import org.kitodo.data.interfaces.TemplateInterface; +import org.kitodo.data.interfaces.WorkflowInterface; @Entity @Table(name = "template") -public class Template extends BaseTemplateBean { +public class Template extends BaseTemplateBean implements TemplateInterface { @Column(name = "active") private Boolean active = true; @@ -77,11 +84,7 @@ public Template() { this.creationDate = new Date(); } - /** - * Check if template is active. - * - * @return true or false - */ + @Override public boolean isActive() { if (Objects.isNull(this.active)) { this.active = true; @@ -89,11 +92,7 @@ public boolean isActive() { return this.active; } - /** - * Set workflow as active. - * - * @param active as Boolean - */ + @Override public void setActive(boolean active) { this.active = active; } @@ -117,58 +116,34 @@ public void setClient(Client client) { this.client = client; } - /** - * Get docket. - * - * @return value of docket - */ + @Override public Docket getDocket() { return docket; } - /** - * Set docket. - * - * @param docket as Docket object - */ - public void setDocket(Docket docket) { - this.docket = docket; + @Override + public void setDocket(DocketInterface docket) { + this.docket = (Docket) docket; } - /** - * Get ruleset. - * - * @return value of ruleset - */ + @Override public Ruleset getRuleset() { return this.ruleset; } - /** - * Set ruleset. - * - * @param ruleset as Ruleset object - */ - public void setRuleset(Ruleset ruleset) { - this.ruleset = ruleset; + @Override + public void setRuleset(RulesetInterface ruleset) { + this.ruleset = (Ruleset) ruleset; } - /** - * Get workflow. - * - * @return value of workflow - */ + @Override public Workflow getWorkflow() { return workflow; } - /** - * Set workflow. - * - * @param workflow as Workflow object - */ - public void setWorkflow(Workflow workflow) { - this.workflow = workflow; + @Override + public void setWorkflow(WorkflowInterface workflow) { + this.workflow = (Workflow) workflow; } @@ -191,11 +166,7 @@ public void setOcrdWorkflowId(String ocrdWorkflowId) { this.ocrdWorkflowId = ocrdWorkflowId; } - /** - * Get projects list. - * - * @return list of projects - */ + @Override public List getProjects() { initialize(new TemplateDAO(), this.projects); if (Objects.isNull(this.projects)) { @@ -204,13 +175,10 @@ public List getProjects() { return this.projects; } - /** - * Set list of projects. - * - * @param projects as Project list - */ - public void setProjects(List projects) { - this.projects = projects; + @Override + @SuppressWarnings("unchecked") + public void setProjects(List projects) { + this.projects = (List) projects; } /** @@ -235,11 +203,7 @@ public void setProcesses(List processes) { this.processes = processes; } - /** - * Get list of task. - * - * @return list of Task objects or empty list - */ + @Override public List getTasks() { initialize(new TemplateDAO(), this.tasks); if (Objects.isNull(this.tasks)) { @@ -248,13 +212,10 @@ public List getTasks() { return this.tasks; } - /** - * Set tasks. - * - * @param tasks as list of task - */ - public void setTasks(List tasks) { - this.tasks = tasks; + @Override + @SuppressWarnings("unchecked") + public void setTasks(List tasks) { + this.tasks = (List) tasks; } /** @@ -284,4 +245,12 @@ public boolean equals(Object object) { public int hashCode() { return Objects.hash(client, docket, ruleset, workflow); } + + @Override + public boolean isCanBeUsedForProcess() { + if (Objects.isNull(tasks)) { + return false; + } + return tasks.stream().allMatch(task -> CollectionUtils.isNotEmpty(task.getRoles())); + } } diff --git a/Kitodo-DataManagement/src/main/java/org/kitodo/data/database/beans/User.java b/Kitodo-DataManagement/src/main/java/org/kitodo/data/database/beans/User.java index b9ab4ab7452..596e363ab33 100644 --- a/Kitodo-DataManagement/src/main/java/org/kitodo/data/database/beans/User.java +++ b/Kitodo-DataManagement/src/main/java/org/kitodo/data/database/beans/User.java @@ -27,10 +27,16 @@ import javax.persistence.Table; import org.kitodo.data.database.persistence.UserDAO; +import org.kitodo.data.interfaces.ClientInterface; +import org.kitodo.data.interfaces.FilterInterface; +import org.kitodo.data.interfaces.ProjectInterface; +import org.kitodo.data.interfaces.RoleInterface; +import org.kitodo.data.interfaces.TaskInterface; +import org.kitodo.data.interfaces.UserInterface; @Entity @Table(name = "user") -public class User extends BaseBean { +public class User extends BaseBean implements UserInterface { @Column(name = "name") private String name; @@ -181,26 +187,32 @@ public User(User user) { } } + @Override public String getLogin() { return this.login; } + @Override public void setLogin(String login) { this.login = login; } + @Override public String getName() { return this.name; } + @Override public void setName(String name) { this.name = name; } + @Override public String getSurname() { return this.surname; } + @Override public void setSurname(String surname) { this.surname = surname; } @@ -213,10 +225,12 @@ public void setPassword(String inputPassword) { this.password = inputPassword; } + @Override public boolean isActive() { return this.active; } + @Override public void setActive(boolean active) { this.active = active; } @@ -229,10 +243,12 @@ public void setDeleted(boolean deleted) { this.deleted = deleted; } + @Override public String getLocation() { return this.location; } + @Override public void setLocation(String location) { this.location = location; } @@ -287,11 +303,7 @@ public void setLdapGroup(LdapGroup ldapGroup) { this.ldapGroup = ldapGroup; } - /** - * Get roles. - * - * @return list of Role objects - */ + @Override public List getRoles() { initialize(new UserDAO(), this.roles); if (Objects.isNull(this.roles)) { @@ -300,21 +312,13 @@ public List getRoles() { return this.roles; } - /** - * Set roles. - * - * @param roles - * list of Role objects - */ - public void setRoles(List roles) { - this.roles = roles; + @Override + @SuppressWarnings("unchecked") + public void setRoles(List roles) { + this.roles = (List) roles; } - /** - * Get tasks processed by this user. - * - * @return tasks processed by this user - */ + @Override public List getProcessingTasks() { initialize(new UserDAO(), this.processingTasks); if (Objects.isNull(this.processingTasks)) { @@ -323,15 +327,13 @@ public List getProcessingTasks() { return this.processingTasks; } - public void setProcessingTasks(List processingTasks) { - this.processingTasks = processingTasks; + @Override + @SuppressWarnings("unchecked") + public void setProcessingTasks(List processingTasks) { + this.processingTasks = (List) processingTasks; } - /** - * Get projects to which user is assigned. - * - * @return projects to which user is assigned - */ + @Override public List getProjects() { initialize(new UserDAO(), this.projects); if (Objects.isNull(this.projects)) { @@ -340,15 +342,13 @@ public List getProjects() { return this.projects; } - public void setProjects(List projects) { - this.projects = projects; + @Override + @SuppressWarnings("unchecked") + public void setProjects(List projects) { + this.projects = (List) projects; } - /** - * Gets clients. - * - * @return The clients. - */ + @Override public List getClients() { initialize(new UserDAO(), this.clients); if (Objects.isNull(this.clients)) { @@ -357,14 +357,10 @@ public List getClients() { return this.clients; } - /** - * Sets clients. - * - * @param clients - * The clients. - */ - public void setClients(List clients) { - this.clients = clients; + @Override + @SuppressWarnings("unchecked") + public void setClients(List clients) { + this.clients = (List) clients; } public boolean isConfigProductionDateShow() { @@ -411,19 +407,17 @@ public void setLanguage(String language) { this.language = language; } + @Override public String getLdapLogin() { return this.ldapLogin; } + @Override public void setLdapLogin(String ldapLogin) { this.ldapLogin = ldapLogin; } - /** - * Get user filters. - * - * @return list of user filters - */ + @Override public List getFilters() { initialize(new UserDAO(), this.filters); if (Objects.isNull(this.filters)) { @@ -432,14 +426,10 @@ public List getFilters() { return this.filters; } - /** - * Set user filters. - * - * @param filters - * list of user filters - */ - public void setFilters(List filters) { - this.filters = filters; + @Override + @SuppressWarnings("unchecked") + public void setFilters(List filters) { + this.filters = (List) filters; } /** @@ -540,6 +530,7 @@ public void selfDestruct() { // Here will be methods which should be in UserService but are used by jsp // files + @Override public String getFullName() { return this.getSurname() + ", " + this.getName(); } diff --git a/Kitodo-DataManagement/src/main/java/org/kitodo/data/database/beans/Workflow.java b/Kitodo-DataManagement/src/main/java/org/kitodo/data/database/beans/Workflow.java index a1444fd4111..d6ffa2c424f 100644 --- a/Kitodo-DataManagement/src/main/java/org/kitodo/data/database/beans/Workflow.java +++ b/Kitodo-DataManagement/src/main/java/org/kitodo/data/database/beans/Workflow.java @@ -28,10 +28,11 @@ import org.kitodo.data.database.enums.WorkflowStatus; import org.kitodo.data.database.persistence.WorkflowDAO; +import org.kitodo.data.interfaces.WorkflowInterface; @Entity @Table(name = "workflow") -public class Workflow extends BaseIndexedBean { +public class Workflow extends BaseIndexedBean implements WorkflowInterface { @Column(name = "title") private String title; @@ -66,39 +67,22 @@ public Workflow(String title) { this.title = title; } - /** - * Get title. - * - * @return value of title - */ + @Override public String getTitle() { return title; } - /** - * Set title. - * - * @param title - * as String - */ + @Override public void setTitle(String title) { this.title = title; } - /** - * Get status of the workflow. - * - * @return value of status - */ + @Override public WorkflowStatus getStatus() { return status; } - /** - * Set status of the workflow. - * - * @param status as org.kitodo.data.database.beans.Workflow.Status - */ + @Override public void setStatus(WorkflowStatus status) { this.status = status; } diff --git a/Kitodo-DataManagement/src/main/java/org/kitodo/data/interfaces/BatchInterface.java b/Kitodo-DataManagement/src/main/java/org/kitodo/data/interfaces/BatchInterface.java index fc91f08d39e..42bf8c3bbb6 100644 --- a/Kitodo-DataManagement/src/main/java/org/kitodo/data/interfaces/BatchInterface.java +++ b/Kitodo-DataManagement/src/main/java/org/kitodo/data/interfaces/BatchInterface.java @@ -20,8 +20,8 @@ public interface BatchInterface extends DataInterface { /** - * Returns the title of the batch. If no textual title was assigned, the - * title returned is “Batch ‹i›” with its database ID. + * Returns the title of the batch. Using titles for batches is optional, the + * field may be {@code null}. If so, the function returns null. * * @return the title of the batch */ diff --git a/Kitodo-DataManagement/src/main/java/org/kitodo/data/interfaces/ProcessInterface.java b/Kitodo-DataManagement/src/main/java/org/kitodo/data/interfaces/ProcessInterface.java index 96ada669cdd..d5fed4d7cb7 100644 --- a/Kitodo-DataManagement/src/main/java/org/kitodo/data/interfaces/ProcessInterface.java +++ b/Kitodo-DataManagement/src/main/java/org/kitodo/data/interfaces/ProcessInterface.java @@ -238,8 +238,12 @@ default void setCreationTime(String creationDate) throws ParseException { * * @param progressClosed * the percentage of completed tasks + * @throws UnsupportedOperationException + * if setting is not supported */ - void setProgressClosed(Double progressClosed); + default void setProgressClosed(Double progressClosed) { + throw new UnsupportedOperationException("not supported"); + } /** * Returns the percentage of tasks in the process that are currently being @@ -264,8 +268,12 @@ default void setCreationTime(String creationDate) throws ParseException { * * @param progressInProcessing * percentage of tasks currently being processed + * @throws UnsupportedOperationException + * if setting is not supported */ - void setProgressInProcessing(Double progressInProcessing); + default void setProgressInProcessing(Double progressInProcessing) { + throw new UnsupportedOperationException("not supported"); + } /** * Returns the percentage of tasks in the process, that cannot yet be @@ -292,8 +300,12 @@ default void setCreationTime(String creationDate) throws ParseException { * * @param progressLocked * percentage of tasks waiting + * @throws UnsupportedOperationException + * if setting is not supported */ - void setProgressLocked(Double progressLocked); + default void setProgressLocked(Double progressLocked) { + throw new UnsupportedOperationException("not supported"); + } /** * Returns the contents of the wiki field as HTML. Wiki means that something @@ -337,8 +349,12 @@ default void setCreationTime(String creationDate) throws ParseException { * * @param progressOpen * percentage of startable tasks + * @throws UnsupportedOperationException + * if setting is not supported */ - void setProgressOpen(Double progressOpen); + default void setProgressOpen(Double progressOpen) { + throw new UnsupportedOperationException("not supported"); + } /** * Returns a coded overview of the progress of the process. The larger the @@ -366,8 +382,12 @@ default void setCreationTime(String creationDate) throws ParseException { * @param progressCombined * coded overview of the progress with pattern * ([01]\d{2}){4} + * @throws UnsupportedOperationException + * if setting is not supported */ - void setProgressCombined(String progressCombined); + default void setProgressCombined(String progressCombined) { + throw new UnsupportedOperationException("not supported"); + } /** * Returns a process identifier URI. Internally, this is the record number @@ -435,8 +455,12 @@ default void setProcessBase(String processBaseUri) { * @param batchID * human-readable information about which batches the process * belongs to + * @throws UnsupportedOperationException + * if setting is not supported */ - void setBatchID(String batchID); + default void setBatchID(String batchID) { + throw new UnsupportedOperationException("not supported"); + } /** * Returns the record number of the parent process, if any. Is {@code null} @@ -666,42 +690,56 @@ default void setProcessBase(String processBaseUri) { * * @param lastEditingUser * user name, comma-separated, last name first + * @throws UnsupportedOperationException + * if setting is not supported */ - void setLastEditingUser(String lastEditingUser); + default void setLastEditingUser(String lastEditingUser) { + throw new UnsupportedOperationException("not supported"); + } /** - * Returns the day on which a task of this process was last started. + * Returns time day on which a task of this process was last started. * - * @return day on which a task of this process was last started + * @return time on which a task of this process was last started */ Date getProcessingBeginLastTask(); /** - * Sets the day on which a task of this process was last started. This + * Sets the time on which a task of this process was last started. This * should only be set if the data comes from a third party; internally, it * is determined in the database. * * @param processingBeginLastTask - * the day on which a task of this process was last started + * the time on which a task of this process was last started + * @throws UnsupportedOperationException + * if setting is not supported */ - void setProcessingBeginLastTask(Date processingBeginLastTask); + default void setProcessingBeginLastTask(Date processingBeginLastTask) { + throw new UnsupportedOperationException("not supported"); + } /** - * Returns the day on which a task from this process was last completed. + * Returns the time on which a task from this process was last completed. * - * @return day on which a task from this process was last completed + * @return time on which a task from this process was last completed */ Date getProcessingEndLastTask(); /** - * Sets the day on which a task of this process was last completed. This + * Sets the time on which a task of this process was last completed. This * should only be set if the data comes from a third party; internally, it * is determined in the database. * * @param processingEndLastTask - * the day on which a task of this process was last completed + * the time on which a task of this process was last completed + * @throws UnsupportedOperationException + * if setting is not supported + * @throws UnsupportedOperationException + * if setting is not supported */ - void setProcessingEndLastTask(Date processingEndLastTask); + default void setProcessingEndLastTask(Date processingEndLastTask) { + throw new UnsupportedOperationException("not supported"); + } /** * Returns the error corrections processing state of the process. The value @@ -717,8 +755,12 @@ default void setProcessBase(String processBaseUri) { * * @param status * the error corrections processing state + * @throws UnsupportedOperationException + * if setting is not supported */ - void setCorrectionCommentStatus(Integer status); + default void setCorrectionCommentStatus(Integer status) { + throw new UnsupportedOperationException("not supported"); + } /** * Returns whether the process has any comments. diff --git a/Kitodo-DataManagement/src/main/java/org/kitodo/data/interfaces/TaskInterface.java b/Kitodo-DataManagement/src/main/java/org/kitodo/data/interfaces/TaskInterface.java index 80b56f773e0..d646ae709e4 100644 --- a/Kitodo-DataManagement/src/main/java/org/kitodo/data/interfaces/TaskInterface.java +++ b/Kitodo-DataManagement/src/main/java/org/kitodo/data/interfaces/TaskInterface.java @@ -118,7 +118,7 @@ public interface TaskInterface extends DataInterface { * Sets the translated processing status of the task at runtime. This is a * transient value that is not persisted. * - * @param processingStatus + * @param processingStatusTitle * translated processing status to set */ void setProcessingStatusTitle(String processingStatusTitle); @@ -164,10 +164,10 @@ public interface TaskInterface extends DataInterface { String getEditTypeTitle(); /** - * Sets the translated processing tipe of the task at runtime. This is a + * Sets the translated processing type of the task at runtime. This is a * transient value that is not persisted. * - * @param processingStatus + * @param editTypeTitle * translated processing type to set */ void setEditTypeTitle(String editTypeTitle); @@ -260,7 +260,7 @@ default String getProcessingBeginTime() { * Sets the time the task was accepted for processing. The string must be * parsable with {@link SimpleDateFormat}{@code ("yyyy-MM-dd HH:mm:ss")}. * - * @param processingTime + * @param processingBegin * time to set * @throws ParseException * if the time cannot be converted @@ -274,7 +274,7 @@ default void setProcessingBeginTime(String processingBegin) throws ParseExceptio /** * Sets the time the task was accepted for processing. * - * @param processingTime + * @param processingBegin * time to set */ void setProcessingBegin(Date processingBegin); @@ -303,7 +303,7 @@ default String getProcessingEndTime() { * Sets the time the task was completed. The string must be parsable with * {@link SimpleDateFormat}{@code ("yyyy-MM-dd HH:mm:ss")}. * - * @param processingTime + * @param processingEnd * time to set * @throws ParseException * if the time cannot be converted @@ -317,7 +317,7 @@ default void setProcessingEndTime(String processingEnd) throws ParseException { /** * Sets the time the task was completed. * - * @param processingTime + * @param processingEnd * time to set */ void setProcessingEnd(Date processingEnd); @@ -343,16 +343,25 @@ default void setProcessingEndTime(String processingEnd) throws ParseException { * Returns the project the process belongs to. * * @return the project the process belongs to + * @deprecated Use {@link #getProcess()}{@code .getProject()}. */ - ProjectInterface getProject(); + @Deprecated + default ProjectInterface getProject() { + return getProcess().getProject(); + } /** * Sets the project the process belongs to. * * @param project * project to set + * @deprecated Use + * {@link #getProcess()}{@code .setProject(ProjectInterface)}. */ - void setProject(ProjectInterface project); + @Deprecated + default void setProject(ProjectInterface project) { + getProcess().setProject(project); + } /** * Returns the production template this task belongs to. Can be {@code null} @@ -366,8 +375,8 @@ default void setProcessingEndTime(String processingEnd) throws ParseException { * Sets the production template this task belongs to. A task can only ever * be assigned to either a production template or a process. * - * @param process - * process this task belongs to + * @param template + * template this task belongs to */ void setTemplate(TemplateInterface template); @@ -388,8 +397,12 @@ default void setProcessingEndTime(String processingEnd) throws ParseException { * * @param roleIds * list of role IDs + * @throws UnsupportedOperationException + * if setting is not supported */ - void setRoleIds(List roleIds); + default void setRoleIds(List roleIds) { + throw new UnsupportedOperationException("not supported"); + } /** * Returns how many roles are allowed to take on this task. @@ -407,7 +420,7 @@ default int getRolesSize() { * depends on, whether there are role objects in the database linked to the * process. No additional roles can be added to the process here. * - * @param size + * @param rolesSize * how many users hold this role to set * @throws SecurityException * when trying to assign unspecified roles to this process @@ -525,13 +538,19 @@ default void setRolesSize(int rolesSize) { boolean isBatchStep(); /** - * Set information if batch is available for task - there is more than one - * task with the same title assigned to the batch.). + * Sets whether batch automation is possible for this task. The setter can + * be used when representing data from a third-party source. Internally it + * depends on whether the task's process is assigned to exactly one batch. + * Setting this to true cannot fix problems. * * @param batchAvailable * as boolean + * @throws UnsupportedOperationException + * if setting is not supported */ - void setBatchAvailable(boolean batchAvailable); + default void setBatchAvailable(boolean batchAvailable) { + throw new UnsupportedOperationException("not supported"); + } /** * Returns whether batch automation is possible for this task. For @@ -540,7 +559,10 @@ default void setRolesSize(int rolesSize) { * * @return whether batch automation is possible */ - boolean isBatchAvailable(); + default boolean isBatchAvailable() { + var batches = getProcess().getBatches(); + return Objects.nonNull(batches) && batches.size() == 1; + } /** * Sets whether batch automation is possible for this task. The setter can @@ -569,8 +591,13 @@ default void setRolesSize(int rolesSize) { * * @return the status regarding corrections * @see org.kitodo.data.database.enums.CorrectionComments + * @deprecated Use + * {@link #getProcess()}{@code .getCorrectionCommentStatus()}. */ - Integer getCorrectionCommentStatus(); + @Deprecated + default Integer getCorrectionCommentStatus() { + return getProcess().getCorrectionCommentStatus(); + } /** * Sets the status of the task regarding necessary corrections. Must be a @@ -579,7 +606,10 @@ default void setRolesSize(int rolesSize) { * @param status * the status regarding corrections * @see org.kitodo.data.database.enums.CorrectionComments + * @throws UnsupportedOperationException + * if setting is not supported */ - void setCorrectionCommentStatus(Integer status); - + default void setCorrectionCommentStatus(Integer status) { + throw new UnsupportedOperationException("not supported"); + } } diff --git a/Kitodo-DataManagement/src/main/java/org/kitodo/data/interfaces/UserInterface.java b/Kitodo-DataManagement/src/main/java/org/kitodo/data/interfaces/UserInterface.java index 70200e94be2..0795f9172e9 100644 --- a/Kitodo-DataManagement/src/main/java/org/kitodo/data/interfaces/UserInterface.java +++ b/Kitodo-DataManagement/src/main/java/org/kitodo/data/interfaces/UserInterface.java @@ -83,7 +83,16 @@ public interface UserInterface extends DataInterface { * @param fullName * full name to set */ - void setFullName(String fullName); + default void setFullName(String fullName) { + if (Objects.isNull(fullName)) { + setName(null); + setSurname(null); + } else { + String[] parts = fullName.split(", ", 2); + setName((parts.length == 2) ? parts[1] : ""); + setSurname(parts[0]); + } + } /** * Returns the user's location. Users from different locations collaborate @@ -186,7 +195,7 @@ default Integer getFiltersSize() { * whether there are filter objects in the database linked to the user. No * additional filters can be added to the process here. * - * @param size + * @param filtersSize * how many users hold this role to set * @throws UnsupportedOperationException * when trying to add unspecified filters to this user @@ -244,7 +253,7 @@ default int getRolesSize() { * whether there are role objects in the database linked to the user. No * additional roles can be added to the user here. * - * @param size + * @param rolesSize * number of roles to set * @throws SecurityException * when trying to assign unspecified roles to this user @@ -299,8 +308,8 @@ default int getClientsSize() { * whether there are role objects in the database linked to the user. No * additional roles can be added to the user here. * - * @param size - * number of roles to set + * @param clientsSize + * number of clients to set * @throws SecurityException * when trying to assign unspecified roles to this user * @throws IndexOutOfBoundsException @@ -354,8 +363,8 @@ default int getProjectsSize() { * whether there are role objects in the database linked to the user. No * additional roles can be added to the user here. * - * @param size - * number of roles to set + * @param projectsSize + * number of projects to set * @throws UnsupportedOperationException * when trying to assign unspecified projects to this user * @throws IndexOutOfBoundsException