Skip to content

Commit

Permalink
Fix more type clashes
Browse files Browse the repository at this point in the history
  • Loading branch information
matthias-ronge committed Apr 11, 2024
1 parent 59b47a8 commit 580f8e1
Show file tree
Hide file tree
Showing 8 changed files with 112 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -49,20 +49,48 @@ public interface ProcessInterface extends DataInterface {
* Returns the time the process was created. The string is formatted
* according to {@link SimpleDateFormat}{@code ("yyyy-MM-dd HH:mm:ss")}.
*
* @return the time the process was created
* @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 time the process was created. {@link Date} is a specific
* instant in time, with millisecond precision.
*
* @return the creation time
*/
Date getCreationDate();

/**
* Sets the time the process was created. 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 time of process creation. The string must be parsable with
* Sets the time the process was created. The string must be parsable with
* {@link SimpleDateFormat}{@code ("yyyy-MM-dd HH:mm:ss")}.
*
* @param creationDate
* the time of process creation
* creation time to set
* @throws ParseException
* if the time cannot be converted
*/
void setCreationDate(String creationDate);
void setCreationDate(Date creationDate);

/**
* Returns the docket generation statement to use when creating a docket for
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@ default void setFileFormatInternal(String fileFormatInternal) {
*
* @return whether the project is active
*/
Boolean isActive();
boolean isActive();

/**
* Sets whether the project is active. Deactivated projects are hidden from
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,11 @@

package org.kitodo.data.interfaces;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
import java.util.Objects;

public interface TemplateInterface extends DataInterface {

Expand All @@ -31,19 +35,52 @@ public interface TemplateInterface extends DataInterface {
void setTitle(String title);

/**
* Returns the day the process template was created.
* Returns the time the process template was created. The string is
* formatted according to
* {@link SimpleDateFormat}{@code ("yyyy-MM-dd HH:mm:ss")}.
*
* @return the day the process template was created
* @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 time the process template was created. {@link Date} is a
* specific instant in time, with millisecond precision.
*
* @return the creation time
*/
Date getCreationDate();

/**
* Sets the time the process template was created. 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 day of process template creation.
* Sets the time the process template was created. The string must be
* parsable with {@link SimpleDateFormat}{@code ("yyyy-MM-dd HH:mm:ss")}.
*
* @param creationDate
* the day of process template creation
* creation time to set
* @throws ParseException
* if the time cannot be converted
*/
void setCreationDate(String creationDate);
void setCreationDate(Date creationDate);

/**
* Returns the docket generation statement to use when creating dockets for
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,21 @@

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.DocketInterface;
import org.kitodo.data.interfaces.RulesetInterface;
import org.kitodo.data.interfaces.TaskInterface;

public abstract class BaseTemplateDTO extends BaseDTO {

private String title;
private String creationDate;
protected String creationDate;
private DocketInterface docket;
private RulesetInterface ruleset;
private List<? extends TaskInterface> tasks = new ArrayList<>();
Expand Down Expand Up @@ -50,7 +54,7 @@ public void setTitle(String title) {
*
* @return creation date as String
*/
public String getCreationDate() {
public String getCreationTime() {
return creationDate;
}

Expand All @@ -60,7 +64,7 @@ public String getCreationDate() {
* @param creationDate
* as String
*/
public void setCreationDate(String creationDate) {
public void setCreationTime(String creationDate) {
this.creationDate = creationDate;
}

Expand Down Expand Up @@ -120,4 +124,16 @@ public List<? extends TaskInterface> getTasks() {
public void setTasks(List<? extends TaskInterface> tasks) {
this.tasks = tasks;
}

public Date getCreationDate() {
try {
return Strings.isNotEmpty(this.creationDate) ? DATE_FORMAT.parse(this.creationDate) : null;
} catch (ParseException e) {
throw new IllegalStateException(e.getMessage(), e);
}
}

public void setCreationDate(Date creationDate) {
this.creationDate = Objects.nonNull(creationDate) ? DATE_FORMAT.format(creationDate) : null;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -199,8 +199,8 @@ public void setNumberOfVolumes(Integer numberOfVolumes) {
*
* @return whether project is active or not
*/
public Boolean isActive() {
return this.active;
public boolean isActive() {
return Boolean.TRUE.equals(this.active);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ private void prepareRow(int rowCounter, HSSFSheet sheet, ProcessInterface proces
HSSFRow row = sheet.createRow(rowCounter);
row.createCell(0).setCellValue(processInterface.getTitle());
row.createCell(1).setCellValue(processInterface.getId());
row.createCell(2).setCellValue(processInterface.getCreationDate());
row.createCell(2).setCellValue(processInterface.getCreationTime());
row.createCell(3).setCellValue(processInterface.getNumberOfImages());
row.createCell(4).setCellValue(processInterface.getNumberOfStructures());
row.createCell(5).setCellValue(processInterface.getNumberOfMetadata());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import java.nio.file.Files;
import java.nio.file.Paths;
import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.time.Duration;
import java.time.LocalDateTime;
Expand Down Expand Up @@ -918,7 +919,11 @@ public ProcessInterface convertJSONObjectToInterface(Map<String, Object> jsonObj
processInterface.setId(getIdFromJSONObject(jsonObject));
processInterface.setTitle(ProcessTypeField.TITLE.getStringValue(jsonObject));
processInterface.setWikiField(ProcessTypeField.WIKI_FIELD.getStringValue(jsonObject));
processInterface.setCreationDate(ProcessTypeField.CREATION_DATE.getStringValue(jsonObject));
try {
processInterface.setCreationTime(ProcessTypeField.CREATION_DATE.getStringValue(jsonObject));
} catch (ParseException e) {
throw new DataException(e);
}
processInterface.setSortHelperArticles(ProcessTypeField.SORT_HELPER_ARTICLES.getIntValue(jsonObject));
processInterface.setSortHelperDocstructs(ProcessTypeField.SORT_HELPER_DOCSTRUCTS.getIntValue(jsonObject));
processInterface.setSortHelperImages(ProcessTypeField.SORT_HELPER_IMAGES.getIntValue(jsonObject));
Expand Down Expand Up @@ -2192,7 +2197,7 @@ public static String getPropertyValue(ProcessInterface process, String propertyN
* @return process age of given process
*/
public static String getProcessDuration(ProcessInterface process) {
String creationDateTimeString = process.getCreationDate();
String creationDateTimeString = process.getCreationTime();
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
LocalDateTime createLocalDate = LocalDateTime.parse(creationDateTimeString, formatter);
Duration duration = Duration.between(createLocalDate, LocalDateTime.now());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.text.ParseException;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.Date;
Expand Down Expand Up @@ -186,7 +187,11 @@ public TemplateInterface convertJSONObjectToInterface(Map<String, Object> jsonOb
templateInterface.setId(getIdFromJSONObject(jsonObject));
templateInterface.setTitle(TemplateTypeField.TITLE.getStringValue(jsonObject));
templateInterface.setActive(TemplateTypeField.ACTIVE.getBooleanValue(jsonObject));
templateInterface.setCreationDate(TemplateTypeField.CREATION_DATE.getStringValue(jsonObject));
try {
templateInterface.setCreationTime(TemplateTypeField.CREATION_DATE.getStringValue(jsonObject));
} catch (ParseException e) {
throw new DataException(e);
}
templateInterface.setDocket(
ServiceManager.getDocketService().findById(TemplateTypeField.DOCKET.getIntValue(jsonObject)));
templateInterface.setRuleset(
Expand Down

0 comments on commit 580f8e1

Please sign in to comment.