From 094e528949222ef54f76d114c510caa6bda480b4 Mon Sep 17 00:00:00 2001 From: Matthias Ronge Date: Thu, 11 Apr 2024 14:57:58 +0200 Subject: [PATCH] Fix type clashes --- .../kitodo/data/database/beans/Process.java | 18 ++-- .../kitodo/data/interfaces/DataInterface.java | 6 ++ .../data/interfaces/ProcessInterface.java | 35 +++++++- .../data/interfaces/ProjectInterface.java | 76 ++++++++++++++-- .../data/interfaces/PropertyInterface.java | 34 ++++++- .../kitodo/data/interfaces/RoleInterface.java | 4 + .../kitodo/data/interfaces/TaskInterface.java | 89 +++++++++++++++++-- .../data/interfaces/TemplateInterface.java | 2 + .../kitodo/data/interfaces/UserInterface.java | 18 ++++ .../data/interfaces/WorkflowInterface.java | 40 ++++++++- .../org/kitodo/production/dto/ProcessDTO.java | 15 +++- .../org/kitodo/production/dto/ProjectDTO.java | 41 ++++++++- .../kitodo/production/dto/PropertyDTO.java | 23 ++++- .../org/kitodo/production/dto/TaskDTO.java | 57 ++++++++++-- .../kitodo/production/dto/WorkflowDTO.java | 18 +++- .../services/data/ProcessService.java | 8 +- .../services/data/ProjectService.java | 9 +- .../production/services/data/TaskService.java | 11 ++- .../services/data/WorkflowService.java | 2 +- .../production/services/file/FileService.java | 6 +- .../services/data/ProcessServiceTest.java | 13 +-- 21 files changed, 462 insertions(+), 63 deletions(-) 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 dc69926aca4..a04e7800c43 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 @@ -126,13 +126,13 @@ public class Process extends BaseTemplateBean { private List> metadata; @Transient - private int numberOfMetadata; + private Integer numberOfMetadata; @Transient - private int numberOfImages; + private Integer numberOfImages; @Transient - private int numberOfStructures; + private Integer numberOfStructures; @Transient private String baseType; @@ -606,7 +606,7 @@ public int hashCode() { * * @return Amount of structure elements */ - public int getNumberOfStructures() { + public Integer getNumberOfStructures() { return numberOfStructures; } @@ -615,7 +615,7 @@ public int getNumberOfStructures() { * * @return Amount of meta data elements */ - public int getNumberOfMetadata() { + public Integer getNumberOfMetadata() { return numberOfMetadata; } @@ -624,7 +624,7 @@ public int getNumberOfMetadata() { * * @param numberOfMetadata Integer value of amount of meta data elements */ - public void setNumberOfMetadata(int numberOfMetadata) { + public void setNumberOfMetadata(Integer numberOfMetadata) { this.numberOfMetadata = numberOfMetadata; } @@ -633,7 +633,7 @@ public void setNumberOfMetadata(int numberOfMetadata) { * * @return Integer value of amount of images */ - public int getNumberOfImages() { + public Integer getNumberOfImages() { return numberOfImages; } @@ -642,7 +642,7 @@ public int getNumberOfImages() { * * @param numberOfImages Integer value of amount of images */ - public void setNumberOfImages(int numberOfImages) { + public void setNumberOfImages(Integer numberOfImages) { this.numberOfImages = numberOfImages; } @@ -651,7 +651,7 @@ public void setNumberOfImages(int numberOfImages) { * * @param numberOfStructures Integer value of amount of structure elements */ - public void setNumberOfStructures(int numberOfStructures) { + public void setNumberOfStructures(Integer numberOfStructures) { this.numberOfStructures = numberOfStructures; } diff --git a/Kitodo-DataManagement/src/main/java/org/kitodo/data/interfaces/DataInterface.java b/Kitodo-DataManagement/src/main/java/org/kitodo/data/interfaces/DataInterface.java index 483c43c9359..4f8c8b682f2 100644 --- a/Kitodo-DataManagement/src/main/java/org/kitodo/data/interfaces/DataInterface.java +++ b/Kitodo-DataManagement/src/main/java/org/kitodo/data/interfaces/DataInterface.java @@ -11,10 +11,16 @@ package org.kitodo.data.interfaces; +import java.text.DateFormat; +import java.text.SimpleDateFormat; + /** * Meta interface over the data interfaces of this interface. */ public interface DataInterface { + + static final DateFormat DATE_FORMAT = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); + /** * Returns the record number of the object in the database. Can be * {@code null} if the object has not yet been persisted. 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 e5c8d1c0343..10f32657274 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 @@ -11,10 +11,12 @@ package org.kitodo.data.interfaces; +import java.net.URI; import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.Date; import java.util.List; +import java.util.Objects; import org.kitodo.data.database.enums.CorrectionComments; @@ -346,8 +348,37 @@ public interface ProcessInterface extends DataInterface { * the application's processes directory on the file system. * * @return the union resource identifier of the process + * @deprecated Use {@link #getProcessBaseUri()}. */ - String getProcessBaseUri(); + @Deprecated + default String getProcessBase() { + URI processBaseUri = getProcessBaseUri(); + return Objects.isNull(processBaseUri) ? null : processBaseUri.toString(); + } + + /** + * Returns a process identifier URI. Internally, this is the record number + * of the process in the processes table of the database, but for external + * data it can also be another identifier that resolves to a directory in + * the application's processes directory on the file system. + * + * @return the union resource identifier of the process + */ + URI getProcessBaseUri(); + + /** + * Sets the union resource identifier of the process. This should only be + * set manually if the data comes from a third party source, otherwise, this + * is the process record number set by the database. + * + * @param processBaseUri + * the identification URI of the process + * @deprecated Use {@link #setProcessBaseUri(URI)}. + */ + @Deprecated + default void setProcessBase(String processBaseUri) { + setProcessBaseUri(Objects.isNull(processBaseUri) ? null : URI.create(processBaseUri)); + } /** * Sets the union resource identifier of the process. This should only be @@ -357,7 +388,7 @@ public interface ProcessInterface extends DataInterface { * @param processBaseUri * the identification URI of the process */ - void setProcessBaseUri(String processBaseUri); + void setProcessBaseUri(URI processBaseUri); /** * Returns all batches to which the process belongs. A comma-space-separated diff --git a/Kitodo-DataManagement/src/main/java/org/kitodo/data/interfaces/ProjectInterface.java b/Kitodo-DataManagement/src/main/java/org/kitodo/data/interfaces/ProjectInterface.java index 43bf73faf9d..c04f170c719 100644 --- a/Kitodo-DataManagement/src/main/java/org/kitodo/data/interfaces/ProjectInterface.java +++ b/Kitodo-DataManagement/src/main/java/org/kitodo/data/interfaces/ProjectInterface.java @@ -11,10 +11,11 @@ package org.kitodo.data.interfaces; -import java.util.List; +import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.Date; -import java.text.ParseException; +import java.util.List; +import java.util.Objects; /** * An interface to manage digitization projects. @@ -45,8 +46,23 @@ public interface ProjectInterface extends DataInterface { * {@link SimpleDateFormat}{@code ("yyyy-MM-dd HH:mm:ss")}. * * @return the start time + * @deprecated Use {@link #getStartDate()}. + */ + @Deprecated + default String getStartTime() { + Date startDate = getStartDate(); + return Objects.nonNull(startDate) ? DATE_FORMAT.format(startDate) : null; + } + + /** + * Returns the start time of the project. {@link Date} is a specific instant + * in time, with millisecond precision. It is a freely configurable value, + * not the date the project object was created in the database. This can be, + * for example, the start of the funding period. + * + * @return the start time */ - String getStartDate(); + Date getStartDate(); /** * Sets the start time of the project. The string must be parsable with @@ -56,8 +72,20 @@ public interface ProjectInterface extends DataInterface { * the start time * @throws ParseException * if the time cannot be converted + * @deprecated Use {@link #setStartDate(Date)}. */ - void setStartDate(String startDate); + @Deprecated + default void setStartTime(String startDate) throws ParseException { + setStartDate(Objects.nonNull(startDate) ? DATE_FORMAT.parse(startDate) : null); + } + + /** + * Sets the start time of the project. + * + * @param startDate + * the start time + */ + void setStartDate(Date startDate); /** * Returns the project end time. The value is a {@link Date} (a specific @@ -72,8 +100,39 @@ public interface ProjectInterface extends DataInterface { * {@link SimpleDateFormat}{@code ("yyyy-MM-dd HH:mm:ss")}. * * @return the end time + * @deprecated Use {@linkplain #getEndDate()}. */ - String getEndDate(); + @Deprecated + default String getEndTime() { + Date endDate = getEndDate(); + return Objects.nonNull(endDate) ? DATE_FORMAT.format(endDate) : null; + } + + /** + * Returns the project end time. {@link Date} is a specific instant in time, + * with millisecond precision. This is a freely configurable value, + * regardless of when the project was last actually worked on. For example, + * this can be the time at which the project must be completed in order to + * be billed. The timing can be used to monitor that the project is on time. + * + * @return the end time + */ + Date getEndDate(); + + /** + * Sets the project end time. The string must be parsable with + * {@link SimpleDateFormat}{@code ("yyyy-MM-dd HH:mm:ss")}. + * + * @param endDate + * the end time + * @throws ParseException + * if the time cannot be converted + * @deprecated Use {@link #setEndDate(Date)}. + */ + @Deprecated + default void setEndTime(String endDate) throws ParseException { + setEndDate(Objects.nonNull(endDate) ? DATE_FORMAT.parse(endDate) : null); + } /** * Sets the project end time. The string must be parsable with @@ -84,7 +143,7 @@ public interface ProjectInterface extends DataInterface { * @throws ParseException * if the time cannot be converted */ - void setEndDate(String endDate); + void setEndDate(Date endDate); /** * Returned the file format for exporting the project's business objects. In @@ -121,6 +180,7 @@ default void setFileFormatDmsExport(String fileFormatDmsExport) { * @deprecated The less suitable formats are no longer supported since * version 3. */ + @Deprecated default String getFileFormatInternal() { return ""; } @@ -132,7 +192,9 @@ default String getFileFormatInternal() { * unused * @deprecated Functionless today. */ - void setFileFormatInternal(String fileFormatInternal); + @Deprecated + default void setFileFormatInternal(String fileFormatInternal) { + } /** * Returns the name of the copyright holder of the business objects. These diff --git a/Kitodo-DataManagement/src/main/java/org/kitodo/data/interfaces/PropertyInterface.java b/Kitodo-DataManagement/src/main/java/org/kitodo/data/interfaces/PropertyInterface.java index a26fa81b6b5..62410c422fb 100644 --- a/Kitodo-DataManagement/src/main/java/org/kitodo/data/interfaces/PropertyInterface.java +++ b/Kitodo-DataManagement/src/main/java/org/kitodo/data/interfaces/PropertyInterface.java @@ -13,6 +13,8 @@ import java.text.ParseException; import java.text.SimpleDateFormat; +import java.util.Date; +import java.util.Objects; /** * An interface to manage process properties. Properties are key-value pairs @@ -55,8 +57,36 @@ public interface PropertyInterface extends DataInterface { * according to {@link SimpleDateFormat}{@code ("yyyy-MM-dd HH:mm:ss")}. * * @return the creation time + * @deprecated Use {@link #getCreationDate()}. */ - String getCreationDate(); + @Deprecated + default String getCreationTime() { + Date creationDate = getCreationDate(); + return Objects.nonNull(creationDate) ? DATE_FORMAT.format(creationDate) : null; + } + + /** + * Returns the creation time of the property. {@link Date} is a specific + * instant in time, with millisecond precision. + * + * @return the creation time + */ + Date getCreationDate(); + + /** + * Sets the creation time of the property. The string must be parsable with + * {@link SimpleDateFormat}{@code ("yyyy-MM-dd HH:mm:ss")}. + * + * @param creationDate + * creation time to set + * @throws ParseException + * if the time cannot be converted + * @deprecated Use {@link #setCreationDate(Date)}. + */ + @Deprecated + default void setCreationTime(String creationDate) throws ParseException { + setCreationDate(Objects.nonNull(creationDate) ? DATE_FORMAT.parse(creationDate) : null); + } /** * Sets the creation time of the property. The string must be parsable with @@ -67,5 +97,5 @@ public interface PropertyInterface extends DataInterface { * @throws ParseException * if the time cannot be converted */ - void setCreationDate(String creationDate); + void setCreationDate(Date creationDate); } diff --git a/Kitodo-DataManagement/src/main/java/org/kitodo/data/interfaces/RoleInterface.java b/Kitodo-DataManagement/src/main/java/org/kitodo/data/interfaces/RoleInterface.java index 7aaec2c35a0..21f897b9195 100644 --- a/Kitodo-DataManagement/src/main/java/org/kitodo/data/interfaces/RoleInterface.java +++ b/Kitodo-DataManagement/src/main/java/org/kitodo/data/interfaces/RoleInterface.java @@ -58,7 +58,9 @@ public interface RoleInterface extends DataInterface { * Returns how many users hold this role. * * @return how many users hold this role + * @deprecated Use {@link #getUsers()}{@code .size()}. */ + @Deprecated default Integer getUsersSize() { List users = getUsers(); return Objects.nonNull(users) ? users.size() : null; @@ -76,7 +78,9 @@ default Integer getUsersSize() { * when trying to assign this role to unspecified users * @throws IndexOutOfBoundsException * for an illegal endpoint index value + * @deprecated {@link #getUsers()} and edit them consciously. */ + @Deprecated default void setUsersSize(Integer size) { int newSize = Objects.nonNull(size) ? size : 0; List users = Optional.of(getUsers()).orElse(Collections.emptyList()); 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 811309bedc3..80b56f773e0 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 @@ -12,7 +12,9 @@ package org.kitodo.data.interfaces; import java.text.ParseException; +import java.text.SimpleDateFormat; import java.util.Collections; +import java.util.Date; import java.util.List; import java.util.Objects; import java.util.Optional; @@ -192,8 +194,22 @@ public interface TaskInterface extends DataInterface { * {@link SimpleDateFormat}{@code ("yyyy-MM-dd HH:mm:ss")}. * * @return the time the task status was last changed + * @deprecated Use {@link #getProcessingTime()}. */ - String getProcessingTime(); + @Deprecated + default String getProcessingMoment() { + Date processingTime = getProcessingTime(); + return Objects.nonNull(processingTime) ? DATE_FORMAT.format(processingTime) : null; + } + + /** + * Returns the time the task status was last changed. This references + * any activity on the task that involves a change in status. + * {@link Date} is a specific instant in time, with millisecond precision. + * + * @return the time the task status was last changed + */ + Date getProcessingTime(); /** * Sets the time the task status was last changed. The string must be @@ -203,8 +219,21 @@ public interface TaskInterface extends DataInterface { * time to set * @throws ParseException * if the time cannot be converted + * @deprecated Use {@link #setProcessingTime(Date)}. */ - void setProcessingTime(String processingTime); + @Deprecated + default void setProcessingMoment(String processingTime) throws ParseException { + setProcessingTime(Objects.nonNull(processingTime) ? DATE_FORMAT.parse(processingTime) : null); + } + + /** + * Sets the time the task status was last changed. The string must be + * parsable with {@link SimpleDateFormat}{@code ("yyyy-MM-dd HH:mm:ss")}. + * + * @param processingTime + * time to set + */ + void setProcessingTime(Date processingTime); /** * Returns the time when the task was accepted for processing. The string is @@ -212,8 +241,20 @@ public interface TaskInterface extends DataInterface { * {@link SimpleDateFormat}{@code ("yyyy-MM-dd HH:mm:ss")}. * * @return the time when the task was accepted for processing + * @deprecated Use {@link #getProcessingBegin()}. + */ + @Deprecated + default String getProcessingBeginTime() { + Date processingBegin = getProcessingBegin(); + return Objects.nonNull(processingBegin) ? DATE_FORMAT.format(processingBegin) : null; + } + + /** + * Returns the time when the task was accepted for processing. + * + * @return the time when the task was accepted for processing */ - String getProcessingBegin(); + Date getProcessingBegin(); /** * Sets the time the task was accepted for processing. The string must be @@ -223,16 +264,40 @@ public interface TaskInterface extends DataInterface { * time to set * @throws ParseException * if the time cannot be converted + * @deprecated Use {@link #setProcessingBegin(Date)}. */ - void setProcessingBegin(String processingBegin); + @Deprecated + default void setProcessingBeginTime(String processingBegin) throws ParseException { + setProcessingBegin(Objects.nonNull(processingBegin) ? DATE_FORMAT.parse(processingBegin) : null); + } + + /** + * Sets the time the task was accepted for processing. + * + * @param processingTime + * time to set + */ + void setProcessingBegin(Date processingBegin); /** * Returns the time when the task was completed. The string is formatted * according to {@link SimpleDateFormat}{@code ("yyyy-MM-dd HH:mm:ss")}. * * @return the time when the task was completed + * @deprecated Use {@link #getProcessingEnd()}. */ - String getProcessingEnd(); + @Deprecated + default String getProcessingEndTime() { + Date processingEnd = getProcessingEnd(); + return Objects.nonNull(processingEnd) ? DATE_FORMAT.format(processingEnd) : null; + } + + /** + * Returns the time when the task was completed. + * + * @return the time when the task was completed + */ + Date getProcessingEnd(); /** * Sets the time the task was completed. The string must be parsable with @@ -242,8 +307,20 @@ public interface TaskInterface extends DataInterface { * time to set * @throws ParseException * if the time cannot be converted + * @deprecated Use {@link #setProcessingEnd(Date)}. + */ + @Deprecated + default void setProcessingEndTime(String processingEnd) throws ParseException { + setProcessingEnd(Objects.nonNull(processingEnd) ? DATE_FORMAT.parse(processingEnd) : null); + } + + /** + * Sets the time the task was completed. + * + * @param processingTime + * time to set */ - void setProcessingEnd(String processingEnd); + void setProcessingEnd(Date processingEnd); /** * Returns the process this task belongs to. Can be {@code null} if the task diff --git a/Kitodo-DataManagement/src/main/java/org/kitodo/data/interfaces/TemplateInterface.java b/Kitodo-DataManagement/src/main/java/org/kitodo/data/interfaces/TemplateInterface.java index d153d6e5cd5..90aebce8d5d 100644 --- a/Kitodo-DataManagement/src/main/java/org/kitodo/data/interfaces/TemplateInterface.java +++ b/Kitodo-DataManagement/src/main/java/org/kitodo/data/interfaces/TemplateInterface.java @@ -157,7 +157,9 @@ public interface TemplateInterface extends DataInterface { * as boolean * @throws UnsupportedOperationException * when trying to set this on the database + * @deprecated Avoid creating invalid production templates. */ + @Deprecated default void setCanBeUsedForProcess(boolean canBeUsedForProcess) { throw new UnsupportedOperationException("not allowed"); } 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 21ea078a87b..70200e94be2 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 @@ -142,7 +142,9 @@ public interface UserInterface extends DataInterface { * as boolean * @throws UnsupportedOperationException * when trying to change this + * @deprecated Use servlet container user control. */ + @Deprecated default void setActive(boolean active) { if (active != isActive()) { throw new UnsupportedOperationException(active ? "cannot log user in" : "cannot log user out"); @@ -170,7 +172,9 @@ default void setActive(boolean active) { * Returns the number of saved search queries. * * @return the number of saved search queries + * @deprecated Use {@link #getFilters()}{@code .size()}. */ + @Deprecated default Integer getFiltersSize() { List queries = getFilters(); return Objects.nonNull(queries) ? queries.size() : null; @@ -188,7 +192,9 @@ default Integer getFiltersSize() { * when trying to add unspecified filters to this user * @throws IndexOutOfBoundsException * for an illegal endpoint index value + * @deprecated {@link #getFilters()} and edit them consciously. */ + @Deprecated default void setFiltersSize(Integer filtersSize) { if (Objects.isNull(filtersSize)) { setFilters(null); @@ -224,7 +230,9 @@ default void setFiltersSize(Integer filtersSize) { * Returns the number of roles the user has. * * @return the number of roles + * @deprecated Use {@link #getRoles()}{@code .size()}. */ + @Deprecated default int getRolesSize() { List roles = getRoles(); return Objects.nonNull(roles) ? roles.size() : 0; @@ -242,7 +250,9 @@ default int getRolesSize() { * when trying to assign unspecified roles to this user * @throws IndexOutOfBoundsException * for an illegal endpoint index value + * @deprecated {@link #getRoles()} and edit them consciously. */ + @Deprecated default void setRolesSize(Integer rolesSize) { int newSize = Objects.nonNull(rolesSize) ? rolesSize : 0; List users = Optional.of(getRoles()).orElse(Collections.emptyList()); @@ -275,7 +285,9 @@ default void setRolesSize(Integer rolesSize) { * Returns the number of clients the user interacts with. * * @return the number of clients + * @deprecated Use {@link #getClients()}{@code .size()}. */ + @Deprecated default int getClientsSize() { List clients = getClients(); return Objects.nonNull(clients) ? clients.size() : 0; @@ -293,7 +305,9 @@ default int getClientsSize() { * when trying to assign unspecified roles to this user * @throws IndexOutOfBoundsException * for an illegal endpoint index value + * @deprecated {@link #getClients()} and edit them consciously. */ + @Deprecated default void setClientsSize(Integer clientsSize) { int newSize = Objects.nonNull(clientsSize) ? clientsSize : 0; List users = Optional.of(getClients()).orElse(Collections.emptyList()); @@ -326,7 +340,9 @@ default void setClientsSize(Integer clientsSize) { * Returns the number of projects the user is working on. * * @return the number of projects + * @deprecated Use {@link #getProjects()}{@code .size()}. */ + @Deprecated default int getProjectsSize() { List projects = getProjects(); return Objects.nonNull(projects) ? projects.size() : 0; @@ -344,7 +360,9 @@ default int getProjectsSize() { * when trying to assign unspecified projects to this user * @throws IndexOutOfBoundsException * for an illegal endpoint index value + * @deprecated {@link #getProjects()} and edit them consciously. */ + @Deprecated default void setProjectsSize(Integer projectsSize) { int newSize = Objects.nonNull(projectsSize) ? projectsSize : 0; List users = Optional.of(getProjects()).orElse(Collections.emptyList()); diff --git a/Kitodo-DataManagement/src/main/java/org/kitodo/data/interfaces/WorkflowInterface.java b/Kitodo-DataManagement/src/main/java/org/kitodo/data/interfaces/WorkflowInterface.java index 6c2f620d0a4..89e00f9485d 100644 --- a/Kitodo-DataManagement/src/main/java/org/kitodo/data/interfaces/WorkflowInterface.java +++ b/Kitodo-DataManagement/src/main/java/org/kitodo/data/interfaces/WorkflowInterface.java @@ -11,6 +11,9 @@ package org.kitodo.data.interfaces; +import java.util.Objects; + +import org.apache.logging.log4j.util.Strings; import org.kitodo.data.database.enums.WorkflowStatus; public interface WorkflowInterface extends DataInterface { @@ -30,6 +33,27 @@ public interface WorkflowInterface extends DataInterface { */ void setTitle(String title); + /** + * Returns the stage of the workflow. Statuses: + * + *
+ *
DRAFT
+ *
the workflow is being created
+ *
ACTIVE
+ *
the workflow is in use
+ *
ARCHIVED
+ *
the workflow is no longer used
+ *
+ * + * @return the stage + * @deprecated Use {@link #getStatus()}. + */ + @Deprecated + default String getWorkflowStatus() { + WorkflowStatus status = getStatus(); + return Objects.nonNull(status) ? status.toString() : ""; + } + /** * Returns the stage of the workflow. Statuses: * @@ -44,7 +68,7 @@ public interface WorkflowInterface extends DataInterface { * * @return the stage */ - String getStatus(); + WorkflowStatus getStatus(); /** * Sets the stage of the workflow. One of {@link WorkflowStatus}. @@ -54,6 +78,18 @@ public interface WorkflowInterface extends DataInterface { * @throws IllegalArgumentException * if {@link WorkflowStatus} has no constant with the specified * name + * @deprecated Use {@link #setStatus(WorkflowStatus)}. + */ + @Deprecated + default void setWorkflowStatus(String status) { + setStatus(Strings.isNotEmpty(status) ? WorkflowStatus.valueOf(status) : null); + } + + /** + * Sets the stage of the workflow. + * + * @param status + * as String */ - void setStatus(String status); + void setStatus(WorkflowStatus status); } diff --git a/Kitodo/src/main/java/org/kitodo/production/dto/ProcessDTO.java b/Kitodo/src/main/java/org/kitodo/production/dto/ProcessDTO.java index d54f1116275..85db6ebbc76 100644 --- a/Kitodo/src/main/java/org/kitodo/production/dto/ProcessDTO.java +++ b/Kitodo/src/main/java/org/kitodo/production/dto/ProcessDTO.java @@ -11,6 +11,7 @@ package org.kitodo.production.dto; +import java.net.URI; import java.util.ArrayList; import java.util.Date; import java.util.List; @@ -257,20 +258,30 @@ public void setProgressCombined(String progressCombined) { * * @return process base URI as String. */ - public String getProcessBaseUri() { + public String getProcessBase() { return processBaseUri; } + @Override + public URI getProcessBaseUri() { + return Objects.isNull(processBaseUri) ? null : URI.create(processBaseUri); + } + /** * Set process base URI as String. * * @param processBaseUri * as String */ - public void setProcessBaseUri(String processBaseUri) { + public void setProcessBase(String processBaseUri) { this.processBaseUri = processBaseUri; } + @Override + public void setProcessBaseUri(URI processBaseUri) { + this.processBaseUri = Objects.isNull(processBaseUri) ? null : processBaseUri.toString(); + } + /** * Get batch id(label) as String. * diff --git a/Kitodo/src/main/java/org/kitodo/production/dto/ProjectDTO.java b/Kitodo/src/main/java/org/kitodo/production/dto/ProjectDTO.java index 530e923f6cb..3f56144b99e 100644 --- a/Kitodo/src/main/java/org/kitodo/production/dto/ProjectDTO.java +++ b/Kitodo/src/main/java/org/kitodo/production/dto/ProjectDTO.java @@ -11,9 +11,13 @@ package org.kitodo.production.dto; +import java.text.ParseException; import java.util.ArrayList; +import java.util.Date; import java.util.List; +import java.util.Objects; +import org.apache.logging.log4j.util.Strings; import org.kitodo.data.interfaces.ClientInterface; import org.kitodo.data.interfaces.ProjectInterface; import org.kitodo.data.interfaces.TemplateInterface; @@ -62,7 +66,7 @@ public void setTitle(String title) { * * @return start date as String */ - public String getStartDate() { + public String getStartTime() { return startDate; } @@ -72,7 +76,7 @@ public String getStartDate() { * @param startDate * as String */ - public void setStartDate(String startDate) { + public void setStartTime(String startDate) { this.startDate = startDate; } @@ -81,7 +85,7 @@ public void setStartDate(String startDate) { * * @return end date as String */ - public String getEndDate() { + public String getEndTime() { return endDate; } @@ -91,7 +95,7 @@ public String getEndDate() { * @param endDate * as String */ - public void setEndDate(String endDate) { + public void setEndTime(String endDate) { this.endDate = endDate; } @@ -282,4 +286,33 @@ public boolean hasProcesses() { public void setHasProcesses(boolean hasProcesses) { this.hasProcesses = hasProcesses; } + + @Override + public Date getStartDate() { + try { + return Strings.isNotEmpty(this.startDate) ? DATE_FORMAT.parse(this.startDate) : null; + } catch (ParseException e) { + throw new IllegalStateException(e.getMessage(), e); + } + } + + @Override + public void setStartDate(Date startDate) { + this.startDate = Objects.nonNull(startDate) ? DATE_FORMAT.format(startDate) : null; + } + + @Override + public Date getEndDate() { + try { + return Strings.isNotEmpty(this.endDate) ? DATE_FORMAT.parse(this.endDate) : null; + } catch (ParseException e) { + throw new IllegalStateException(e.getMessage(), e); + } + } + + @Override + public void setEndDate(Date endDate) { + this.endDate = Objects.nonNull(endDate) ? DATE_FORMAT.format(endDate) : null; + + } } diff --git a/Kitodo/src/main/java/org/kitodo/production/dto/PropertyDTO.java b/Kitodo/src/main/java/org/kitodo/production/dto/PropertyDTO.java index c5cd86eff05..45a5f845aed 100644 --- a/Kitodo/src/main/java/org/kitodo/production/dto/PropertyDTO.java +++ b/Kitodo/src/main/java/org/kitodo/production/dto/PropertyDTO.java @@ -11,6 +11,11 @@ package org.kitodo.production.dto; +import java.text.ParseException; +import java.util.Date; +import java.util.Objects; + +import org.apache.logging.log4j.util.Strings; import org.kitodo.data.interfaces.PropertyInterface; /** @@ -65,7 +70,7 @@ public void setValue(String value) { * * @return creation date as String. */ - public String getCreationDate() { + public String getCreationTime() { return creationDate; } @@ -75,7 +80,21 @@ public String getCreationDate() { * @param creationDate * as String */ - public void setCreationDate(String creationDate) { + public void setCreationTime(String creationDate) { this.creationDate = creationDate; } + + @Override + public Date getCreationDate() { + try { + return Strings.isNotEmpty(this.creationDate) ? DATE_FORMAT.parse(this.creationDate) : null; + } catch (ParseException e) { + throw new IllegalStateException(e.getMessage(), e); + } + } + + @Override + public void setCreationDate(Date creationDate) { + this.creationDate = Objects.nonNull(creationDate) ? DATE_FORMAT.format(creationDate) : null; + } } diff --git a/Kitodo/src/main/java/org/kitodo/production/dto/TaskDTO.java b/Kitodo/src/main/java/org/kitodo/production/dto/TaskDTO.java index bbf74549de0..63b74bea55a 100644 --- a/Kitodo/src/main/java/org/kitodo/production/dto/TaskDTO.java +++ b/Kitodo/src/main/java/org/kitodo/production/dto/TaskDTO.java @@ -11,9 +11,13 @@ package org.kitodo.production.dto; +import java.text.ParseException; import java.util.ArrayList; +import java.util.Date; import java.util.List; +import java.util.Objects; +import org.apache.logging.log4j.util.Strings; import org.kitodo.data.database.enums.TaskEditType; import org.kitodo.data.database.enums.TaskStatus; import org.kitodo.data.interfaces.ProcessInterface; @@ -210,7 +214,7 @@ public void setProcessingUser(UserInterface processingUser) { * * @return processing time as String */ - public String getProcessingTime() { + public String getProcessingMoment() { return processingTime; } @@ -220,7 +224,7 @@ public String getProcessingTime() { * @param processingTime * as String */ - public void setProcessingTime(String processingTime) { + public void setProcessingMoment(String processingTime) { this.processingTime = processingTime; } @@ -229,7 +233,7 @@ public void setProcessingTime(String processingTime) { * * @return processing begin time as String */ - public String getProcessingBegin() { + public String getProcessingBeginTime() { return processingBegin; } @@ -239,7 +243,7 @@ public String getProcessingBegin() { * @param processingBegin * as String */ - public void setProcessingBegin(String processingBegin) { + public void setProcessingBeginTime(String processingBegin) { this.processingBegin = processingBegin; } @@ -248,7 +252,7 @@ public void setProcessingBegin(String processingBegin) { * * @return processing end time as String */ - public String getProcessingEnd() { + public String getProcessingEndTime() { return processingEnd; } @@ -258,7 +262,7 @@ public String getProcessingEnd() { * @param processingEnd * as String */ - public void setProcessingEnd(String processingEnd) { + public void setProcessingEndTime(String processingEnd) { this.processingEnd = processingEnd; } @@ -509,4 +513,45 @@ public void setCorrectionCommentStatus(Integer status) { this.correctionCommentStatus = status; } + @Override + public Date getProcessingTime() { + try { + return Strings.isNotEmpty(this.processingTime) ? DATE_FORMAT.parse(this.processingTime) : null; + } catch (ParseException e) { + throw new IllegalStateException(e.getMessage(), e); + } + } + + @Override + public void setProcessingTime(Date processingTime) { + this.processingTime = Objects.nonNull(processingTime) ? DATE_FORMAT.format(processingTime) : null; + } + + @Override + public Date getProcessingBegin() { + try { + return Strings.isNotEmpty(this.processingBegin) ? DATE_FORMAT.parse(this.processingBegin) : null; + } catch (ParseException e) { + throw new IllegalStateException(e.getMessage(), e); + } + } + + @Override + public void setProcessingBegin(Date processingBegin) { + this.processingBegin = Objects.nonNull(processingBegin) ? DATE_FORMAT.format(processingBegin) : null; + } + + @Override + public Date getProcessingEnd() { + try { + return Strings.isNotEmpty(this.processingEnd) ? DATE_FORMAT.parse(this.processingEnd) : null; + } catch (ParseException e) { + throw new IllegalStateException(e.getMessage(), e); + } + } + + @Override + public void setProcessingEnd(Date processingEnd) { + this.processingEnd = Objects.nonNull(processingEnd) ? DATE_FORMAT.format(processingEnd) : null; + } } diff --git a/Kitodo/src/main/java/org/kitodo/production/dto/WorkflowDTO.java b/Kitodo/src/main/java/org/kitodo/production/dto/WorkflowDTO.java index fd14930dc2a..cf78e5ec02f 100644 --- a/Kitodo/src/main/java/org/kitodo/production/dto/WorkflowDTO.java +++ b/Kitodo/src/main/java/org/kitodo/production/dto/WorkflowDTO.java @@ -11,6 +11,10 @@ package org.kitodo.production.dto; +import java.util.Objects; + +import org.apache.logging.log4j.util.Strings; +import org.kitodo.data.database.enums.WorkflowStatus; import org.kitodo.data.interfaces.WorkflowInterface; public class WorkflowDTO extends BaseDTO implements WorkflowInterface { @@ -42,7 +46,7 @@ public void setTitle(String title) { * * @return value of status */ - public String getStatus() { + public String getWorkflowStatus() { return status.toLowerCase(); } @@ -52,7 +56,17 @@ public String getStatus() { * @param status * as String */ - public void setStatus(String status) { + public void setWorkflowStatus(String status) { this.status = status; } + + @Override + public WorkflowStatus getStatus() { + return Strings.isNotEmpty(status) ? WorkflowStatus.valueOf(status) : null; + } + + @Override + public void setStatus(WorkflowStatus status) { + this.status = Objects.nonNull(status) ? status.toString() : null; + } } diff --git a/Kitodo/src/main/java/org/kitodo/production/services/data/ProcessService.java b/Kitodo/src/main/java/org/kitodo/production/services/data/ProcessService.java index 1b1c1150d36..c0d03129fee 100644 --- a/Kitodo/src/main/java/org/kitodo/production/services/data/ProcessService.java +++ b/Kitodo/src/main/java/org/kitodo/production/services/data/ProcessService.java @@ -924,7 +924,7 @@ public ProcessInterface convertJSONObjectToInterface(Map jsonObj processInterface.setSortHelperImages(ProcessTypeField.SORT_HELPER_IMAGES.getIntValue(jsonObject)); processInterface.setSortHelperMetadata(ProcessTypeField.SORT_HELPER_METADATA.getIntValue(jsonObject)); processInterface.setSortHelperStatus(ProcessTypeField.SORT_HELPER_STATUS.getStringValue(jsonObject)); - processInterface.setProcessBaseUri(ProcessTypeField.PROCESS_BASE_URI.getStringValue(jsonObject)); + processInterface.setProcessBase(ProcessTypeField.PROCESS_BASE_URI.getStringValue(jsonObject)); processInterface.setHasChildren(ProcessTypeField.HAS_CHILDREN.getBooleanValue(jsonObject)); processInterface.setParentID(ProcessTypeField.PARENT_ID.getIntValue(jsonObject)); processInterface.setNumberOfImages(ProcessTypeField.NUMBER_OF_IMAGES.getIntValue(jsonObject)); @@ -1200,10 +1200,10 @@ public URI getProcessDataDirectory(Process process, boolean forIndexingAll) { * @return path */ public String getProcessDataDirectory(ProcessInterface processInterface) { - if (Objects.isNull(processInterface.getProcessBaseUri())) { - processInterface.setProcessBaseUri(fileService.getProcessBaseUriForExistingProcess(processInterface)); + if (Objects.isNull(processInterface.getProcessBase())) { + processInterface.setProcessBase(fileService.getProcessBaseUriForExistingProcess(processInterface)); } - return processInterface.getProcessBaseUri(); + return processInterface.getProcessBase(); } /** diff --git a/Kitodo/src/main/java/org/kitodo/production/services/data/ProjectService.java b/Kitodo/src/main/java/org/kitodo/production/services/data/ProjectService.java index 1356ed41968..f333f0e5a53 100644 --- a/Kitodo/src/main/java/org/kitodo/production/services/data/ProjectService.java +++ b/Kitodo/src/main/java/org/kitodo/production/services/data/ProjectService.java @@ -14,6 +14,7 @@ import static org.kitodo.constants.StringConstants.COMMA_DELIMITER; import java.io.IOException; +import java.text.ParseException; import java.util.ArrayList; import java.util.Collections; import java.util.HashMap; @@ -199,8 +200,12 @@ public ProjectInterface convertJSONObjectToInterface(Map jsonObj ProjectInterface projectInterface = DTOFactory.instance().newProject(); projectInterface.setId(getIdFromJSONObject(jsonObject)); projectInterface.setTitle(ProjectTypeField.TITLE.getStringValue(jsonObject)); - projectInterface.setStartDate(ProjectTypeField.START_DATE.getStringValue(jsonObject)); - projectInterface.setEndDate(ProjectTypeField.END_DATE.getStringValue(jsonObject)); + try { + projectInterface.setStartTime(ProjectTypeField.START_DATE.getStringValue(jsonObject)); + projectInterface.setEndTime(ProjectTypeField.END_DATE.getStringValue(jsonObject)); + } catch (ParseException e) { + throw new DataException(e); + } projectInterface.setMetsRightsOwner(ProjectTypeField.METS_RIGTS_OWNER.getStringValue(jsonObject)); projectInterface.setNumberOfPages(ProjectTypeField.NUMBER_OF_PAGES.getIntValue(jsonObject)); projectInterface.setNumberOfVolumes(ProjectTypeField.NUMBER_OF_VOLUMES.getIntValue(jsonObject)); diff --git a/Kitodo/src/main/java/org/kitodo/production/services/data/TaskService.java b/Kitodo/src/main/java/org/kitodo/production/services/data/TaskService.java index a3ea83e2903..6a27379bab2 100644 --- a/Kitodo/src/main/java/org/kitodo/production/services/data/TaskService.java +++ b/Kitodo/src/main/java/org/kitodo/production/services/data/TaskService.java @@ -13,6 +13,7 @@ import java.io.IOException; import java.text.MessageFormat; +import java.text.ParseException; import java.util.Arrays; import java.util.Collections; import java.util.Date; @@ -312,9 +313,13 @@ public TaskInterface convertJSONObjectToInterface(Map jsonObject int editType = TaskTypeField.EDIT_TYPE.getIntValue(jsonObject); taskInterface.setEditType(TaskEditType.getTypeFromValue(editType)); taskInterface.setEditTypeTitle(Helper.getTranslation(taskInterface.getEditType().getTitle())); - taskInterface.setProcessingTime(TaskTypeField.PROCESSING_TIME.getStringValue(jsonObject)); - taskInterface.setProcessingBegin(TaskTypeField.PROCESSING_BEGIN.getStringValue(jsonObject)); - taskInterface.setProcessingEnd(TaskTypeField.PROCESSING_END.getStringValue(jsonObject)); + try { + taskInterface.setProcessingMoment(TaskTypeField.PROCESSING_TIME.getStringValue(jsonObject)); + taskInterface.setProcessingBeginTime(TaskTypeField.PROCESSING_BEGIN.getStringValue(jsonObject)); + taskInterface.setProcessingEndTime(TaskTypeField.PROCESSING_END.getStringValue(jsonObject)); + } catch (ParseException e) { + throw new DataException(e); + } taskInterface.setCorrection(TaskTypeField.CORRECTION.getBooleanValue(jsonObject)); taskInterface.setTypeAutomatic(TaskTypeField.TYPE_AUTOMATIC.getBooleanValue(jsonObject)); taskInterface.setTypeMetadata(TaskTypeField.TYPE_METADATA.getBooleanValue(jsonObject)); diff --git a/Kitodo/src/main/java/org/kitodo/production/services/data/WorkflowService.java b/Kitodo/src/main/java/org/kitodo/production/services/data/WorkflowService.java index faa6a34a2c3..de8ea61b0b5 100644 --- a/Kitodo/src/main/java/org/kitodo/production/services/data/WorkflowService.java +++ b/Kitodo/src/main/java/org/kitodo/production/services/data/WorkflowService.java @@ -103,7 +103,7 @@ public WorkflowInterface convertJSONObjectToInterface(Map jsonOb WorkflowInterface workflowInterface = DTOFactory.instance().newWorkflow(); workflowInterface.setId(getIdFromJSONObject(jsonObject)); workflowInterface.setTitle(WorkflowTypeField.TITLE.getStringValue(jsonObject)); - workflowInterface.setStatus(WorkflowTypeField.STATUS.getStringValue(jsonObject)); + workflowInterface.setWorkflowStatus(WorkflowTypeField.STATUS.getStringValue(jsonObject)); return workflowInterface; } diff --git a/Kitodo/src/main/java/org/kitodo/production/services/file/FileService.java b/Kitodo/src/main/java/org/kitodo/production/services/file/FileService.java index 031636c4e0b..11d7ff1b032 100644 --- a/Kitodo/src/main/java/org/kitodo/production/services/file/FileService.java +++ b/Kitodo/src/main/java/org/kitodo/production/services/file/FileService.java @@ -906,11 +906,11 @@ public URI getProcessBaseUriForExistingProcess(Process process) { * @return the URI. */ public String getProcessBaseUriForExistingProcess(ProcessInterface processInterface) { - String processBaseUri = processInterface.getProcessBaseUri(); + String processBaseUri = processInterface.getProcessBase(); if (Objects.isNull(processBaseUri) && Objects.nonNull(processInterface.getId())) { - processInterface.setProcessBaseUri(fileManagementModule.createUriForExistingProcess(processInterface.getId().toString()).toString()); + processInterface.setProcessBase(fileManagementModule.createUriForExistingProcess(processInterface.getId().toString()).toString()); } - return processInterface.getProcessBaseUri(); + return processInterface.getProcessBase(); } /** diff --git a/Kitodo/src/test/java/org/kitodo/production/services/data/ProcessServiceTest.java b/Kitodo/src/test/java/org/kitodo/production/services/data/ProcessServiceTest.java index fa82b219251..f29b5ce6751 100644 --- a/Kitodo/src/test/java/org/kitodo/production/services/data/ProcessServiceTest.java +++ b/Kitodo/src/test/java/org/kitodo/production/services/data/ProcessServiceTest.java @@ -12,6 +12,7 @@ package org.kitodo.production.services.data; import java.net.URI; +import java.text.ParseException; import java.util.List; import org.junit.Assert; @@ -26,38 +27,38 @@ public class ProcessServiceTest { @Test - public void shouldGetSortedCorrectionSolutionMessages() { + public void shouldGetSortedCorrectionSolutionMessages() throws ParseException { final ProcessInterface processInterface = new ProcessDTO(); PropertyInterface firstPropertyInterface = new PropertyDTO(); firstPropertyInterface.setId(1); firstPropertyInterface.setTitle("Korrektur notwendig"); firstPropertyInterface.setValue("Fix it"); - firstPropertyInterface.setCreationDate(null); + firstPropertyInterface.setCreationTime(null); PropertyInterface secondPropertyInterface = new PropertyDTO(); secondPropertyInterface.setId(2); secondPropertyInterface.setTitle("Korrektur notwendig"); secondPropertyInterface.setValue("Fix it also"); - secondPropertyInterface.setCreationDate(null); + secondPropertyInterface.setCreationTime(null); PropertyInterface thirdPropertyInterface = new PropertyDTO(); thirdPropertyInterface.setId(3); thirdPropertyInterface.setTitle("Other title"); thirdPropertyInterface.setValue("Other value"); - thirdPropertyInterface.setCreationDate("2017-12-01"); + thirdPropertyInterface.setCreationTime("2017-12-01"); PropertyInterface fourthPropertyInterface = new PropertyDTO(); fourthPropertyInterface.setId(4); fourthPropertyInterface.setTitle("Korrektur durchgef\u00FChrt"); fourthPropertyInterface.setValue("Fixed second"); - fourthPropertyInterface.setCreationDate("2017-12-05"); + fourthPropertyInterface.setCreationTime("2017-12-05"); PropertyInterface fifthPropertyInterface = new PropertyDTO(); fifthPropertyInterface.setId(5); fifthPropertyInterface.setTitle("Korrektur durchgef\u00FChrt"); fifthPropertyInterface.setValue("Fixed first"); - fifthPropertyInterface.setCreationDate("2017-12-03"); + fifthPropertyInterface.setCreationTime("2017-12-03"); @SuppressWarnings("unchecked") List properties = (List) processInterface.getProperties();