Skip to content

Commit

Permalink
Merge branch 'kitodo:master' into filter-select
Browse files Browse the repository at this point in the history
  • Loading branch information
markusweigelt authored Dec 5, 2023
2 parents f682269 + b8aec9c commit 79d8355
Show file tree
Hide file tree
Showing 108 changed files with 2,397 additions and 385 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,9 @@ public interface CommandInterface {
/**
* Runs a given command.
*
* @param id
* The id, to identify the command and it's results.
* @param command
* The command as a String.
* @return A commandResult, which contains id and result messages.
*/
CommandResult runCommand(Integer id, String command);
CommandResult runCommand(String command);
}
22 changes: 3 additions & 19 deletions Kitodo-API/src/main/java/org/kitodo/api/command/CommandResult.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,6 @@

public class CommandResult {

/** The id of the command. */
private Integer id;

/** The command as a String. */
private String command;

Expand All @@ -31,31 +28,19 @@ public class CommandResult {
/**
* Constructor.
*
* @param id
* The id.
* @param command
* The command.
* @param successful
* If command was successful.
* @param messages
* The resultMessages
*/
public CommandResult(Integer id, String command, boolean successful, List<String> messages) {
this.id = id;
public CommandResult(String command, boolean successful, List<String> messages) {
this.command = command;
this.successful = successful;
this.messages = messages;
}

/**
* Gets the id.
*
* @return The id.
*/
public Integer getId() {
return id;
}

/**
* Gets the command.
*
Expand Down Expand Up @@ -99,8 +84,7 @@ public boolean equals(Object object) {
if (object instanceof CommandResult) {
CommandResult that = (CommandResult) object;

return this.id.equals(that.id)
&& this.successful == that.successful
return this.successful == that.successful
&& this.command.equals(that.command)
&& this.messages.equals(that.messages);
}
Expand All @@ -109,6 +93,6 @@ public boolean equals(Object object) {

@Override
public int hashCode() {
return Objects.hash(id, successful, command, messages);
return Objects.hash(successful, command, messages);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
package org.kitodo.api.dataformat;

import java.util.ArrayList;
import java.util.Collections;
import java.util.Arrays;
import java.util.Comparator;
import java.util.GregorianCalendar;
import java.util.List;
Expand Down Expand Up @@ -180,15 +180,16 @@ public List<LogicalDivision> getAllLogicalDivisions() {

/**
* Returns all child physical divisions of the physical division of the workpiece with
* type "page" sorted by their {@code order} as a flat list. The root media
* type "page" or "track" sorted by their {@code order} as a flat list. The root media
* unit is not contained. The list isn’t backed by the physical divisions, which
* means that insertions and deletions in the list would not change the
* physical divisions. Therefore, a list that cannot be modified is returned.
*
* @return all physical divisions with type "page", sorted by their {@code order}
* @return all physical divisions with type "page" or "track", sorted by their {@code order}
*/
public List<PhysicalDivision> getAllPhysicalDivisionChildrenFilteredByTypePageAndSorted() {
return getAllPhysicalDivisionChildrenFilteredByTypes(Collections.singletonList(PhysicalDivision.TYPE_PAGE));
public List<PhysicalDivision> getAllPhysicalDivisionChildrenSortedFilteredByPageAndTrack() {
return getAllPhysicalDivisionChildrenFilteredByTypes(
Arrays.asList(PhysicalDivision.TYPE_PAGE, PhysicalDivision.TYPE_TRACK));
}

/**
Expand Down
22 changes: 11 additions & 11 deletions Kitodo-API/src/main/java/org/kitodo/api/docket/DocketData.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ public class DocketData {
/** The creation Date of the process. */
private String creationDate;

/** A comment. */
private String comment;
/** The comments. */
private List<String> comments = new ArrayList<>();

/** The template properties. */
private List<Property> templateProperties;
Expand Down Expand Up @@ -185,22 +185,22 @@ public void setCreationDate(String creationDate) {
}

/**
* Gets the comment.
* Gets the comments.
*
* @return The comment.
* @return The comments.
*/
public String getComment() {
return comment;
public List<String> getComments() {
return comments;
}

/**
* Sets the comment.
* Sets the comments.
*
* @param comment
* The comment.
* @param comments
* The comments.
*/
public void setComment(String comment) {
this.comment = comment;
public void setComments(List<String> comments) {
this.comments = comments;
}

/**
Expand Down
94 changes: 94 additions & 0 deletions Kitodo-API/src/main/java/org/kitodo/utils/MediaUtil.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
/*
* (c) Kitodo. Key to digital objects e. V. <[email protected]>
*
* This file is part of the Kitodo project.
*
* It is licensed under GNU General Public License version 3 or later.
*
* For the full copyright and license information, please read the
* GPL3-License.txt file that was distributed with this source code.
*/

package org.kitodo.utils;

import java.util.Objects;

import org.kitodo.api.dataformat.PhysicalDivision;

public class MediaUtil {

public static final String MIME_TYPE_AUDIO_PREFIX = "audio";
public static final String MIME_TYPE_IMAGE_PREFIX = "image";
public static final String MIME_TYPE_VIDEO_PREFIX = "video";

/**
* Private constructor to hide the implicit public one.
*/
private MediaUtil() {

}

/**
* Check if mime type starts with {@link org.kitodo.utils.MediaUtil#MIME_TYPE_AUDIO_PREFIX} or
* {@link org.kitodo.utils.MediaUtil#MIME_TYPE_VIDEO_PREFIX}.
*
* @param mimeType
* The mime type to check
* @return True if mime type starts with {@link org.kitodo.utils.MediaUtil#MIME_TYPE_AUDIO_PREFIX} or
* {@link org.kitodo.utils.MediaUtil#MIME_TYPE_VIDEO_PREFIX}.
*/
public static boolean isAudioOrVideo(String mimeType) {
return isAudio(mimeType) || isVideo(mimeType);
}

/**
* Check if mime type starts with {@link org.kitodo.utils.MediaUtil#MIME_TYPE_AUDIO_PREFIX}.
*
* @param mimeType
* The mime type to check
* @return True if mime type starts with {@link org.kitodo.utils.MediaUtil#MIME_TYPE_AUDIO_PREFIX}
*/
public static boolean isAudio(String mimeType) {
return Objects.nonNull(mimeType) && mimeType.startsWith(MIME_TYPE_AUDIO_PREFIX);
}

/**
* Check if mime type starts with {@link org.kitodo.utils.MediaUtil#MIME_TYPE_IMAGE_PREFIX}.
*
* @param mimeType
* The mime type to check
* @return True if mime type starts with {@link org.kitodo.utils.MediaUtil#MIME_TYPE_IMAGE_PREFIX}
*/
public static boolean isImage(String mimeType) {
return Objects.nonNull(mimeType) && mimeType.startsWith(MIME_TYPE_IMAGE_PREFIX);
}

/**
* Check if mime type starts with {@link org.kitodo.utils.MediaUtil#MIME_TYPE_VIDEO_PREFIX}.
*
* @param mimeType
* The mime type to check
* @return True if mime type starts with {@link org.kitodo.utils.MediaUtil#MIME_TYPE_VIDEO_PREFIX}
*/
public static boolean isVideo(String mimeType) {
return Objects.nonNull(mimeType) && mimeType.startsWith(MIME_TYPE_VIDEO_PREFIX);
}

/**
* Get the type of {@link org.kitodo.api.dataformat.PhysicalDivision} by mime type.
*
* @param mimeType
* The mime type to get the physical division type for
* @return The type of the {@link org.kitodo.api.dataformat.PhysicalDivision}
*/
public static String getPhysicalDivisionTypeOfMimeType(String mimeType) {
if (isImage(mimeType)) {
return PhysicalDivision.TYPE_PAGE;
}
if (isAudioOrVideo(mimeType)) {
return PhysicalDivision.TYPE_TRACK;
}
return PhysicalDivision.TYPE_OTHER;
}

}
52 changes: 52 additions & 0 deletions Kitodo-API/src/test/java/org/kitodo/utils/MediaUtilTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
/*
* (c) Kitodo. Key to digital objects e. V. <[email protected]>
*
* This file is part of the Kitodo project.
*
* It is licensed under GNU General Public License version 3 or later.
*
* For the full copyright and license information, please read the
* GPL3-License.txt file that was distributed with this source code.
*/

package org.kitodo.utils;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;

import org.junit.Test;
import org.kitodo.api.dataformat.PhysicalDivision;

public class MediaUtilTest {

/**
* Test detection of mime type.
*/
@Test
public void testMimeTypeDetection() {
assertTrue(MediaUtil.isAudio("audio/mp3"));
assertFalse(MediaUtil.isVideo("image/jpeg"));

assertTrue(MediaUtil.isImage("image/jpeg"));
assertFalse(MediaUtil.isImage("video/mp4"));

assertTrue(MediaUtil.isVideo("video/mp4"));
assertFalse(MediaUtil.isVideo("image/jpeg"));

assertTrue(MediaUtil.isAudioOrVideo("audio/mp3"));
assertTrue(MediaUtil.isAudioOrVideo("video/mp4"));
assertFalse(MediaUtil.isAudioOrVideo("image/jpeg"));
}

/**
* Test getting the type of the {@link org.kitodo.api.dataformat.PhysicalDivision}.
*/
@Test
public void testGettingPhysicalDivisionTypeByMimeType() {
assertEquals(PhysicalDivision.TYPE_PAGE, MediaUtil.getPhysicalDivisionTypeOfMimeType("image/jpeg"));
assertEquals(PhysicalDivision.TYPE_TRACK, MediaUtil.getPhysicalDivisionTypeOfMimeType("audio/mp3"));
assertEquals(PhysicalDivision.TYPE_TRACK, MediaUtil.getPhysicalDivisionTypeOfMimeType("video/mp4"));
assertEquals(PhysicalDivision.TYPE_OTHER, MediaUtil.getPhysicalDivisionTypeOfMimeType("application/pdf"));
}
}
16 changes: 7 additions & 9 deletions Kitodo-Command/src/main/java/org/kitodo/command/Command.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,12 @@ public class Command implements CommandInterface {
/**
* Method executes a script.
*
* @param id
* The id, to identify the command and it's results.
* @param command
* The command as a String.
* @return The command result.
*/
@Override
public CommandResult runCommand(Integer id, String command) {
public CommandResult runCommand(String command) {
CommandResult commandResult;
Process process;
String[] callSequence = command.split("[\\r\\n\\s]+");
Expand All @@ -53,26 +51,26 @@ public CommandResult runCommand(Integer id, String command) {

outputMessage.addAll(errorMessage);

commandResult = new CommandResult(id, command, errCode == 0, outputMessage);
commandResult = new CommandResult(command, errCode == 0, outputMessage);
if (commandResult.isSuccessful()) {
logger.info("Execution of Command {} {} was successful!: {}", commandResult.getId(),
logger.info("Execution of Command {} was successful!: {}",
commandResult.getCommand(), commandResult.getMessages());
} else {
logger.error("Execution of Command {} {} failed!: {}", commandResult.getId(),
logger.error("Execution of Command {} failed!: {}",
commandResult.getCommand(), commandResult.getMessages());
}
}
} catch (InterruptedException e) {
commandResult = new CommandResult(id, command, false, Collections.singletonList(e.getMessage()));
commandResult = new CommandResult(command, false, Collections.singletonList(e.getMessage()));
logger.error("Execution of Command Thread was interrupted!");
Thread.currentThread().interrupt();
return commandResult;
} catch (IOException e) {
List<String> errorMessages = new ArrayList<>();
errorMessages.add(e.getCause().toString());
errorMessages.add(e.getMessage());
commandResult = new CommandResult(id, command, false, errorMessages);
logger.error("Execution of Command {} {} failed!: {}", commandResult.getId(), commandResult.getCommand(),
commandResult = new CommandResult(command, false, errorMessages);
logger.error("Execution of Command {} failed!: {}", commandResult.getCommand(),
commandResult.getMessages());
return commandResult;
}
Expand Down
Loading

0 comments on commit 79d8355

Please sign in to comment.