Skip to content

Commit

Permalink
Merge branch 'refs/heads/master' into calendar-test
Browse files Browse the repository at this point in the history
  • Loading branch information
oliver-stoehr committed Apr 23, 2024
2 parents 3aabb14 + 9a1bcb1 commit 23757b1
Show file tree
Hide file tree
Showing 43 changed files with 759 additions and 223 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,6 @@ jobs:
mvn --version
- name: run build
run:
mvn clean install -B '-Pall-tests,flyway,checkstyle,spotbugs,!development' && xvfb-run --server-args="-screen 0 1600x1280x24" mvn clean install -B '-Pselenium,!development'
mvn clean install -B '-Pall-tests,flyway,checkstyle,!development' && xvfb-run --server-args="-screen 0 1600x1280x24" mvn clean install -B '-Pselenium,!development'


4 changes: 0 additions & 4 deletions Kitodo-API/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -82,10 +82,6 @@
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
</dependency>
<dependency>
<groupId>org.junit.vintage</groupId>
<artifactId>junit-vintage-engine</artifactId>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@

package org.kitodo.api.dataformat;

import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;

import java.util.List;
import java.util.stream.Collectors;

import org.junit.Test;
import org.junit.jupiter.api.Test;

public class DivisionTest {

Expand Down
2 changes: 1 addition & 1 deletion Kitodo-API/src/test/java/org/kitodo/config/ConfigTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
import static org.junit.jupiter.api.Assertions.assertNotNull;

import org.apache.commons.configuration.PropertiesConfiguration;
import org.junit.Test;
import org.junit.jupiter.api.Test;

public class ConfigTest {

Expand Down
35 changes: 17 additions & 18 deletions Kitodo-API/src/test/java/org/kitodo/config/KitodoConfigTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,19 +11,19 @@

package org.kitodo.config;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.mockStatic;
import static org.mockito.Mockito.when;

import java.util.NoSuchElementException;

import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import org.kitodo.config.enums.ParameterAPI;

public class KitodoConfigTest {
Expand All @@ -35,7 +35,7 @@ public class KitodoConfigTest {
*
* @throws Exception the exceptions thrown by method
*/
@BeforeClass
@BeforeAll
public static void init() {
NONE = mock(ParameterAPI.class);
doReturn(3).when(NONE).ordinal();
Expand All @@ -49,13 +49,13 @@ public static void init() {
@Test
public void shouldGetStringParameterWithoutDefault() {
String param = KitodoConfig.getParameter(ParameterAPI.DIR_XML_CONFIG);
assertEquals("Incorrect param!", "String", param);
assertEquals("String", param, "Incorrect param!");
}

@Test
public void shouldGetStringParameterWithDefault() {
String param = KitodoConfig.getParameter(ParameterAPI.DIR_XML_CONFIG, "test");
assertEquals("Incorrect param!", "String", param);
assertEquals("String", param, "Incorrect param!");
}

@Test
Expand All @@ -64,52 +64,51 @@ public void shouldGetStringParameterForNonexistentWithoutDefault() {
() -> KitodoConfig.getParameter(ParameterAPI.DIR_PROCESSES),
"Expected NoSuchElementException to be thrown, but it didn't");

assertEquals("No configuration found in kitodo_config.properties for key directory.metadata!",
thrown.getMessage());
assertEquals("No configuration found in kitodo_config.properties for key directory.metadata!", thrown.getMessage());
}

@Test
public void shouldGetStringParameterForNonexistentWithDefault() {
String param = KitodoConfig.getParameter(ParameterAPI.DIR_PROCESSES, "Default");
assertEquals("Incorrect param!", "Default", param);
assertEquals("Default", param, "Incorrect param!");
}

@Test
public void shouldGetBooleanParameter() {
assertTrue("Incorrect param!", KitodoConfig.getBooleanParameter(ParameterAPI.DIR_MODULES));
assertTrue(KitodoConfig.getBooleanParameter(ParameterAPI.DIR_MODULES), "Incorrect param!");
}

@Test
public void shouldGetBooleanParameterForNonexistentWithoutDefault() {
assertFalse("Incorrect param!", KitodoConfig.getBooleanParameter(ParameterAPI.DIR_PROCESSES));
assertFalse(KitodoConfig.getBooleanParameter(ParameterAPI.DIR_PROCESSES), "Incorrect param!");
}

@Test
public void shouldGetBooleanParameterForNonexistentWithDefault() {
assertTrue("Incorrect param!", KitodoConfig.getBooleanParameter(ParameterAPI.DIR_PROCESSES, true));
assertTrue(KitodoConfig.getBooleanParameter(ParameterAPI.DIR_PROCESSES, true), "Incorrect param!");
}

@Test
public void shouldGetIntParameterWithoutDefault() {
int param = KitodoConfig.getIntParameter(NONE);
assertEquals("Incorrect param for non existing enum without default value!", 0, param);
assertEquals(0, param, "Incorrect param for non existing enum without default value!");
}

@Test
public void shouldGetIntParameterWithDefault() {
int param = KitodoConfig.getIntParameter(NONE, 3);
assertEquals("Incorrect param for non existing enum with default value!", 3, param);
assertEquals(3, param, "Incorrect param for non existing enum with default value!");
}

@Test
public void shouldGetIntParameterForNonexistentWithoutDefault() {
int param = KitodoConfig.getIntParameter(ParameterAPI.DIR_PROCESSES);
assertEquals("Incorrect param!", 0, param);
assertEquals(0, param, "Incorrect param!");
}

@Test
public void shouldGetIntParameterForNonexistentWithDefault() {
int param = KitodoConfig.getIntParameter(ParameterAPI.DIR_PROCESSES, 3);
assertEquals("Incorrect param!", 3, param);
assertEquals(3, param, "Incorrect param!");
}
}
8 changes: 4 additions & 4 deletions Kitodo-API/src/test/java/org/kitodo/utils/MediaUtilTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@

package org.kitodo.utils;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;

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

public class MediaUtilTest {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import java.net.URI;
import java.nio.charset.StandardCharsets;
import java.util.Collection;
import java.util.Comparator;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.List;
Expand Down Expand Up @@ -254,8 +255,9 @@ DivType toDiv(Map<PhysicalDivision, String> physicalDivisionIDs, LinkedList<Pair
}
div.setORDERLABEL(super.getOrderlabel());
div.setTYPE(super.getType());
smLinkData.addAll(super.getViews().stream().map(View::getPhysicalDivision).map(physicalDivisionIDs::get)
.map(physicalDivisionId -> Pair.of(metsReferrerId, physicalDivisionId)).collect(Collectors.toList()));
smLinkData.addAll(super.getViews().stream().map(View::getPhysicalDivision)
.sorted(Comparator.comparing(PhysicalDivision::getOrder)).map(physicalDivisionIDs::get)
.map(physicalDivisionId -> Pair.of(metsReferrerId, physicalDivisionId)).collect(Collectors.toList()));

Optional<MdSecType> optionalDmdSec = createMdSec(super.getMetadata(), MdSec.DMD_SEC);
if (optionalDmdSec.isPresent()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -427,18 +427,19 @@ private DivType generatePhysicalStructMapRecursive(PhysicalDivision physicalDivi
*/
private StructLink createStructLink(LinkedList<Pair<String, String>> smLinkData) {
StructLink structLink = new StructLink();
structLink.getSmLinkOrSmLinkGrp().addAll(smLinkData.parallelStream().map(entry -> {
if (Objects.isNull(entry.getLeft())) {
throw new IllegalArgumentException("smLinkData.entry[?].left must not be null");
List<Object> content = structLink.getSmLinkOrSmLinkGrp();
for (Pair<String, String> link : smLinkData) {
if (Objects.isNull(link.getLeft())) {
throw new IllegalArgumentException("link.left must not be null");
}
if (Objects.isNull(entry.getRight())) {
throw new IllegalArgumentException("smLinkData.entry[?].right must not be null");
if (Objects.isNull(link.getRight())) {
throw new IllegalArgumentException("link.right must not be null");
}
SmLink smLink = new SmLink();
smLink.setFrom(entry.getLeft());
smLink.setTo(entry.getRight());
return smLink;
}).collect(Collectors.toList()));
smLink.setFrom(link.getLeft());
smLink.setTo(link.getRight());
content.add(smLink);
}
return structLink;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -341,7 +341,7 @@ private static ValidationResult checkForDetailsInTheMetadata(
.getSortedVisibleMetadata(containedMetadata, Collections.emptyList());
for (MetadataViewWithValuesInterface metadataViewWithValues : metadataViewsWithValues) {
Optional<MetadataViewInterface> optionalMetadataView = metadataViewWithValues.getMetadata();
if (!optionalMetadataView.isPresent()) {
if (optionalMetadataView.isEmpty()) {
continue;
}
MetadataViewInterface metadataView = optionalMetadataView.orElseThrow(IllegalStateException::new);
Expand Down Expand Up @@ -419,7 +419,7 @@ private static Map<MetadataViewInterface, Collection<Metadata>> squash(
Map<MetadataViewInterface, Collection<Metadata>> squashed = new HashMap<>();
for (MetadataViewWithValuesInterface metadataViewWithValues : metadataViewsWithValues) {
Optional<MetadataViewInterface> optionalMetadataView = metadataViewWithValues.getMetadata();
if (!optionalMetadataView.isPresent()) {
if (optionalMetadataView.isEmpty()) {
continue;
}
squashed.computeIfAbsent(optionalMetadataView.get(), each -> new ArrayList<>());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -757,7 +757,7 @@ public List<Pair<PhysicalDivision, LogicalDivision>> getSelectedMedia() {
* <p>Note: This method is called potentially thousands of times when rendering large galleries.</p>
*/
public boolean consecutivePagesSelected() {
if (selectedMedia.isEmpty()) {
if (Objects.isNull(selectedMedia) || selectedMedia.isEmpty()) {
return false;
}
int maxOrder = selectedMedia.stream().mapToInt(m -> m.getLeft().getOrder()).max().orElseThrow(NoSuchElementException::new);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ public void startMassImport() {
importSuccessMap = new HashMap<>();
PrimeFaces.current().ajax().update("massImportResultDialog");
try {
Map<String, Map<String, String>> presetMetadata = massImportService.prepareMetadata(metadataKeys, records);
Map<String, Map<String, List<String>>> presetMetadata = massImportService.prepareMetadata(metadataKeys, records);
importRecords(presetMetadata);
PrimeFaces.current().executeScript("PF('massImportResultDialog').show();");
PrimeFaces.current().ajax().update("massImportResultDialog");
Expand Down Expand Up @@ -181,10 +181,10 @@ public void prepare() {
*
* @param processMetadata Map containing record IDs as keys and preset metadata lists as values
*/
private void importRecords(Map<String, Map<String, String>> processMetadata) {
private void importRecords(Map<String, Map<String, List<String>>> processMetadata) {
ImportService importService = ServiceManager.getImportService();
PrimeFaces.current().ajax().update("massImportProgressDialog");
for (Map.Entry<String, Map<String, String>> entry : processMetadata.entrySet()) {
for (Map.Entry<String, Map<String, List<String>>> entry : processMetadata.entrySet()) {
try {
importService.importProcess(entry.getKey(), projectId, templateId, importConfiguration,
entry.getValue());
Expand Down
66 changes: 0 additions & 66 deletions Kitodo/src/main/java/org/kitodo/production/helper/FacesUtils.java

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ private static void addMultipleStructuresWithMetadataGroup(int number, String ty
for (int i = 0; i < number; i++) {
LogicalDivision newStructure = addLogicalDivision(type, workpiece, structure, position,
Collections.emptyList());
if (Objects.isNull(newStructure) || metadataKey.isEmpty() || metadataKey == null) {
if (Objects.isNull(newStructure) || metadataKey == null || metadataKey.isEmpty()) {
continue;
}
MetadataGroup metadataGroup = new MetadataGroup();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -261,9 +261,9 @@ private QueryBuilder buildQueryFromCondition(String condition, ObjectType object
}

private String replaceLegacyFilters(String filter) {
filter.replace("processproperty","property");
filter.replace("workpiece","property");
filter.replace("template","property");
filter = filter.replace("processproperty","property");
filter = filter.replace("workpiece","property");
filter = filter.replace("template","property");
return filter;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1174,7 +1174,7 @@ public static void processTempProcess(TempProcess tempProcess, RulesetManagement
* @return the importedProcess
*/
public Process importProcess(String ppn, int projectId, int templateId, ImportConfiguration importConfiguration,
Map<String, String> presetMetadata) throws ImportException {
Map<String, List<String>> presetMetadata) throws ImportException {
LinkedList<TempProcess> processList = new LinkedList<>();
TempProcess tempProcess;
Template template;
Expand Down Expand Up @@ -1257,14 +1257,16 @@ private static Collection<String> getFunctionalMetadata(Ruleset ruleset, Functio
return rulesetManagement.getFunctionalKeys(metadata);
}

private List<MetadataEntry> createMetadata(Map<String, String> presetMetadata) {
private List<MetadataEntry> createMetadata(Map<String, List<String>> presetMetadata) {
List<MetadataEntry> metadata = new LinkedList<>();
for (Map.Entry<String, String> presetMetadataEntry : presetMetadata.entrySet()) {
MetadataEntry metadataEntry = new MetadataEntry();
metadataEntry.setKey(presetMetadataEntry.getKey());
metadataEntry.setValue(presetMetadataEntry.getValue());
metadataEntry.setDomain(MdSec.DMD_SEC);
metadata.add(metadataEntry);
for (Map.Entry<String, List<String>> presetMetadataEntry : presetMetadata.entrySet()) {
for (String presetMetadataEntryValue : presetMetadataEntry.getValue()) {
MetadataEntry metadataEntry = new MetadataEntry();
metadataEntry.setKey(presetMetadataEntry.getKey());
metadataEntry.setValue(presetMetadataEntryValue);
metadataEntry.setDomain(MdSec.DMD_SEC);
metadata.add(metadataEntry);
}
}
return metadata;
}
Expand Down
Loading

0 comments on commit 23757b1

Please sign in to comment.