Skip to content

Commit 5b60965

Browse files
authored
Merge pull request #5556 from effective-webwork/metadata-group
Change MetadataGroup.group variable to HashSet
2 parents ac5d52f + 05a6f92 commit 5b60965

File tree

9 files changed

+42
-43
lines changed

9 files changed

+42
-43
lines changed

Kitodo-API/src/main/java/org/kitodo/api/MetadataGroup.java

+9-10
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111

1212
package org.kitodo.api;
1313

14-
import java.util.Collection;
1514
import java.util.HashSet;
1615
import java.util.Objects;
1716
import java.util.stream.Collectors;
@@ -23,25 +22,25 @@ public class MetadataGroup extends Metadata {
2322
/**
2423
* The contents of the metadata group.
2524
*/
26-
private Collection<Metadata> group = new HashSet<>();
25+
private HashSet<Metadata> metadata = new HashSet<>();
2726

2827
/**
2928
* Get the grouped metadata.
3029
*
3130
* @return The grouped metadata
3231
*/
33-
public Collection<Metadata> getGroup() {
34-
return group;
32+
public HashSet<Metadata> getMetadata() {
33+
return metadata;
3534
}
3635

3736
/**
3837
* Set the grouped metadata.
3938
*
40-
* @param group
39+
* @param metadata
4140
* the grouped metadata
4241
*/
43-
public void setGroup(Collection<Metadata> group) {
44-
this.group = group;
42+
public void setMetadata(HashSet<Metadata> metadata) {
43+
this.metadata = metadata;
4544
}
4645

4746
@Override
@@ -63,22 +62,22 @@ public boolean equals(Object obj) {
6362
: MdSec.DMD_SEC)) {
6463
return false;
6564
}
66-
return Objects.equals(group, other.group);
65+
return Objects.equals(metadata, other.metadata);
6766
}
6867

6968
@Override
7069
public int hashCode() {
7170
final int prime = 31;
7271
int result = 1;
7372
result = prime * result + (Objects.nonNull(domain) ? domain : MdSec.DMD_SEC).hashCode();
74-
result = prime * result + ((group == null) ? 0 : group.hashCode());
73+
result = prime * result + ((metadata == null) ? 0 : metadata.hashCode());
7574
result = prime * result + ((key == null) ? 0 : key.hashCode());
7675
return result;
7776
}
7877

7978
@Override
8079
public String toString() {
8180
return (Objects.nonNull(domain) ? "(" + domain + ") " : "") + key + ": {"
82-
+ group.stream().map(String::valueOf).collect(Collectors.joining(", ")) + '}';
81+
+ metadata.stream().map(String::valueOf).collect(Collectors.joining(", ")) + '}';
8382
}
8483
}

Kitodo-API/src/main/java/org/kitodo/api/dataformat/Division.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ public abstract class Division<T extends Division<T>> {
4747
/**
4848
* The metadata for this division.
4949
*/
50-
private Collection<Metadata> metadata = new HashSet<>();
50+
private HashSet<Metadata> metadata = new HashSet<>();
5151

5252
/**
5353
* Sequence number. The sequence number must be unique across all divisions.
@@ -165,7 +165,7 @@ public void setLabel(String label) {
165165
*
166166
* @return the metadata
167167
*/
168-
public Collection<Metadata> getMetadata() {
168+
public HashSet<Metadata> getMetadata() {
169169
return metadata;
170170
}
171171

Kitodo-DataFormat/src/main/java/org/kitodo/dataformat/access/MetadataGroupXmlElementAccess.java

+4-4
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ public MetadataGroupXmlElementAccess() {
3939

4040
/**
4141
* Constructor for a metadata entry group gained from METS.
42-
*
42+
*
4343
* @param domain
4444
* domain of the METS document where the metadata was read
4545
* @param xmlMetadataGroup
@@ -49,7 +49,7 @@ public MetadataGroupXmlElementAccess() {
4949
this();
5050
metadataGroup.setDomain(domain);
5151
metadataGroup.setKey(xmlMetadataGroup.getName());
52-
metadataGroup.getGroup()
52+
metadataGroup.getMetadata()
5353
.addAll(Stream.concat(
5454
xmlMetadataGroup.getMetadata().parallelStream()
5555
.map(kitodoMetadata -> new MetadataXmlElementAccess(null, kitodoMetadata)
@@ -70,13 +70,13 @@ MetadataGroup getMetadataGroup() {
7070

7171
/**
7272
* Generates a {@code <kitodo:metadataGroup>} XML element from this group.
73-
*
73+
*
7474
* @return a {@code <kitodo:metadataGroup>} XML element
7575
*/
7676
MetadataGroupType toXMLMetadataGroup() {
7777
MetadataGroupType xmlMetadataGroup = new MetadataGroupType();
7878
xmlMetadataGroup.setName(metadataGroup.getKey());
79-
for (org.kitodo.api.Metadata entry : metadataGroup.getGroup()) {
79+
for (org.kitodo.api.Metadata entry : metadataGroup.getMetadata()) {
8080
if (entry instanceof MetadataEntry) {
8181
xmlMetadataGroup.getMetadata().add(new MetadataXmlElementAccess((MetadataEntry) entry).toMetadata());
8282
} else if (entry instanceof MetadataGroup) {

Kitodo-DataFormat/src/test/java/org/kitodo/dataformat/access/MetsXmlElementAccessIT.java

+6-6
Original file line numberDiff line numberDiff line change
@@ -176,11 +176,11 @@ public void testSave() throws Exception {
176176
MetadataEntry firstName = new MetadataEntry();
177177
firstName.setKey("firstName");
178178
firstName.setValue("Alice");
179-
author.getGroup().add(firstName);
179+
author.getMetadata().add(firstName);
180180
MetadataEntry lastName = new MetadataEntry();
181181
lastName.setKey("firstName");
182182
lastName.setValue("Smith");
183-
author.getGroup().add(lastName);
183+
author.getMetadata().add(lastName);
184184
frontCover.getMetadata().add(author);
185185

186186
MetadataEntry imagesConverted = new MetadataEntry();
@@ -258,7 +258,7 @@ public void missingMetsHeaderCreationDateDidNotThrowNullPointerException() throw
258258

259259
@Test
260260
public void missingMetsFileForPointer() throws Exception {
261-
try {
261+
try {
262262
new MetsXmlElementAccess().read(new FileInputStream(new File("src/test/resources/meta_missing_file.xml")));
263263
} catch (IllegalArgumentException e) {
264264
assertEquals("Corrupt file: file id for <mets:fptr> not found for div PHYS_0001", e.getMessage());
@@ -267,7 +267,7 @@ public void missingMetsFileForPointer() throws Exception {
267267

268268
@Test
269269
public void duplicateMetsFileDefinition() throws Exception {
270-
try {
270+
try {
271271
new MetsXmlElementAccess().read(
272272
new FileInputStream(new File("src/test/resources/meta_duplicate_file.xml"))
273273
);
@@ -278,13 +278,13 @@ public void duplicateMetsFileDefinition() throws Exception {
278278

279279
@Test
280280
public void missingMetsFileGroupUse() throws Exception {
281-
try {
281+
try {
282282
new MetsXmlElementAccess().read(
283283
new FileInputStream(new File("src/test/resources/meta_missing_file_use.xml"))
284284
);
285285
} catch (IllegalArgumentException e) {
286286
assertEquals(
287-
"Corrupt file: file use for <mets:fptr> with id FILE_0001 not found in <mets:fileGrp>",
287+
"Corrupt file: file use for <mets:fptr> with id FILE_0001 not found in <mets:fileGrp>",
288288
e.getMessage()
289289
);
290290
};

Kitodo-Validation/src/main/java/org/kitodo/validation/metadata/MetadataValidation.java

+3-3
Original file line numberDiff line numberDiff line change
@@ -287,7 +287,7 @@ private static ValidationResult checkForMandatoryQuantitiesOfTheMetadataRecursiv
287287
for (Metadata metadata : metadataViewWithValues.getValue()) {
288288
if (metadata instanceof MetadataGroup) {
289289
ValidationResult validationResult = checkForMandatoryQuantitiesOfTheMetadataRecursive(
290-
((MetadataGroup) metadata).getGroup(),
290+
((MetadataGroup) metadata).getMetadata(),
291291
(ComplexMetadataViewInterface) metadataView, location + metadataView.getLabel() + " - ",
292292
translations);
293293
if (validationResult.getState().equals(State.ERROR)) {
@@ -327,7 +327,7 @@ private static ValidationResult checkForDetailsInTheMetadata(
327327
return checkForDetailsInTheMetadata( // start recursion
328328
containedMetadata, containingMetadataView, location, translations, new LinkedList<>());
329329
}
330-
330+
331331
private static ValidationResult checkForDetailsInTheMetadata(
332332
Collection<Metadata> containedMetadata, ComplexMetadataViewInterface containingMetadataView,
333333
String location, Map<String, String> translations, LinkedList<Map<MetadataEntry, Boolean>> surroundingMetadata) {
@@ -355,7 +355,7 @@ private static ValidationResult checkForDetailsInTheMetadata(
355355
} else if (metadata instanceof MetadataGroup
356356
&& metadataView instanceof ComplexMetadataViewInterface) {
357357
ValidationResult validationResult = checkForDetailsInTheMetadata( // recursive
358-
((MetadataGroup) metadata).getGroup(),
358+
((MetadataGroup) metadata).getMetadata(),
359359
(ComplexMetadataViewInterface) metadataView, location + metadataView.getLabel() + " - ",
360360
translations, surroundingMetadata);
361361
if (validationResult.getState().equals(State.ERROR)) {

Kitodo/src/main/java/org/kitodo/production/forms/createprocess/ProcessFieldedMetadata.java

+12-12
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ public class ProcessFieldedMetadata extends ProcessDetail implements Serializabl
8181
/**
8282
* The metadata object with the content of this panel.
8383
*/
84-
private final Collection<Metadata> metadata;
84+
private final HashSet<Metadata> metadata;
8585

8686
/**
8787
* The key of the metadata group displaying here.
@@ -105,7 +105,7 @@ public ProcessFieldedMetadata() {
105105
super(null, null);
106106
this.treeNode = new DefaultTreeNode();
107107
treeNode.setExpanded(true);
108-
this.metadata = Collections.emptyList();
108+
this.metadata = new HashSet<>();
109109
this.hiddenMetadata = Collections.emptyList();
110110
}
111111

@@ -191,7 +191,7 @@ private static void overwriteTreeNodes(List<TreeNode> source, List<TreeNode> tar
191191
* data of the group, may be empty but must be modifiable
192192
*/
193193
private ProcessFieldedMetadata(ProcessFieldedMetadata parent, ComplexMetadataViewInterface metadataView,
194-
Collection<Metadata> metadata) {
194+
HashSet<Metadata> metadata) {
195195
this(parent, null, metadataView, metadataView.getLabel(), metadataView.getId(), metadata);
196196
}
197197

@@ -208,7 +208,7 @@ private ProcessFieldedMetadata(ProcessFieldedMetadata parent, ComplexMetadataVie
208208
*/
209209
private ProcessFieldedMetadata(ProcessFieldedMetadata parent, Division<?> structure,
210210
ComplexMetadataViewInterface metadataView, String label, String metadataKey,
211-
Collection<Metadata> metadata) {
211+
HashSet<Metadata> metadata) {
212212
super(parent, label);
213213
this.division = structure;
214214
this.metadata = metadata;
@@ -217,12 +217,12 @@ private ProcessFieldedMetadata(ProcessFieldedMetadata parent, Division<?> struct
217217
}
218218

219219
private ProcessFieldedMetadata(ProcessFieldedMetadata parent, MetadataGroup group) {
220-
this(parent, null, null, group.getKey(), group.getKey(), group.getGroup());
220+
this(parent, null, null, group.getKey(), group.getKey(), group.getMetadata());
221221
}
222222

223223
private ProcessFieldedMetadata(ProcessFieldedMetadata template) {
224224
this(template.container, null, template.metadataView, template.label, template.metadataKey,
225-
new ArrayList<>(template.metadata));
225+
new HashSet<>(template.metadata));
226226
copy = true;
227227
hiddenMetadata = template.hiddenMetadata;
228228
treeNode = new DefaultTreeNode(this, template.getTreeNode().getParent());
@@ -330,17 +330,17 @@ private Collection<Metadata> addLabels(Collection<Metadata> metadata) {
330330
*/
331331
public void createMetadataGroupPanel(ComplexMetadataViewInterface complexMetadataView,
332332
Collection<Metadata> values) {
333-
Collection<Metadata> value;
333+
HashSet<Metadata> value;
334334

335335
switch (values.size()) {
336336
case 0:
337-
value = new ArrayList<>();
337+
value = new HashSet<>();
338338
break;
339339
case 1:
340340
Metadata nextMetadata = values.iterator().next();
341341
if (nextMetadata instanceof MetadataGroup) {
342342
MetadataGroup metadataGroup = (MetadataGroup) nextMetadata;
343-
value = metadataGroup.getGroup();
343+
value = metadataGroup.getMetadata();
344344
} else {
345345
throw new IllegalStateException("Got simple metadata entry with key \"" + nextMetadata.getKey()
346346
+ "\" which is declared as substructured key in the rule set.");
@@ -612,9 +612,9 @@ public Collection<Metadata> getMetadata(boolean skipEmpty) throws InvalidMetadat
612612
throw new IllegalStateException("never happening exception");
613613
}
614614
if (skipEmpty) {
615-
result.setGroup(metadata instanceof List ? metadata : new ArrayList<>(metadata));
615+
result.setMetadata(metadata instanceof List ? metadata : new HashSet<>(metadata));
616616
} else {
617-
result.setGroup(new ArrayList<>(DataEditorService.getExistingMetadataRows(treeNode.getChildren())));
617+
result.setMetadata(new HashSet<>(DataEditorService.getExistingMetadataRows(treeNode.getChildren())));
618618
}
619619
return Collections.singletonList(result);
620620
}
@@ -728,7 +728,7 @@ public void preserve() throws InvalidMetadataValueException, NoSuchMetadataField
728728
metadataGroup.setKey(metadataKey);
729729
Optional<Domain> optionalDomain = metadataView.getDomain();
730730
optionalDomain.ifPresent(domain -> metadataGroup.setDomain(DOMAIN_TO_MDSEC.get(domain)));
731-
metadataGroup.setGroup(metadata);
731+
metadataGroup.setMetadata(metadata);
732732
container.metadata.add(metadataGroup);
733733
copy = false;
734734
}

Kitodo/src/main/java/org/kitodo/production/helper/ProcessHelper.java

+4-4
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@
1212
package org.kitodo.production.helper;
1313

1414
import java.io.IOException;
15-
import java.util.ArrayList;
1615
import java.util.Collection;
16+
import java.util.HashSet;
1717
import java.util.List;
1818
import java.util.Locale;
1919
import java.util.Objects;
@@ -253,8 +253,8 @@ public static String getTitleDefinition(RulesetManagementInterface rulesetManage
253253
* domain of metadata
254254
* @return metadata from node list
255255
*/
256-
public static List<Metadata> convertMetadata(NodeList nodes, MdSec domain) {
257-
List<Metadata> allMetadata = new ArrayList<>();
256+
public static HashSet<Metadata> convertMetadata(NodeList nodes, MdSec domain) {
257+
HashSet<Metadata> allMetadata = new HashSet<>();
258258
if (Objects.nonNull(nodes)) {
259259
for (int index = 0; index < nodes.getLength(); index++) {
260260
Node node = nodes.item(index);
@@ -271,7 +271,7 @@ public static List<Metadata> convertMetadata(NodeList nodes, MdSec domain) {
271271
break;
272272
case "metadataGroup": {
273273
MetadataGroup group = new MetadataGroup();
274-
group.setGroup(convertMetadata(element.getChildNodes(), null));
274+
group.setMetadata(convertMetadata(element.getChildNodes(), null));
275275
metadata = group;
276276
break;
277277
}

Kitodo/src/main/java/org/kitodo/production/services/command/OverwriteDataScript.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ public void executeScript(LegacyMetsModsDigitalDocumentHelper metadataFile, Proc
3737
break;
3838
}
3939
if (metadatum instanceof MetadataGroup) {
40-
Collection<Metadata> group = ((MetadataGroup) metadatum).getGroup();
40+
Collection<Metadata> group = ((MetadataGroup) metadatum).getMetadata();
4141
if (metadatum.getKey().equals(metadataScript.getMetadataKey())) {
4242
// TODO: implement handling of metadataGroups
4343
}

Kitodo/src/main/java/org/kitodo/production/services/dataeditor/DataEditorService.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ public static String getTitleValue(LogicalDivision element, String metadataTitle
110110
metadata = metadata.stream()
111111
.filter(currentMetadata -> Objects.equals(currentMetadata.getKey(), metadataKey))
112112
.filter(MetadataGroup.class::isInstance).map(MetadataGroup.class::cast)
113-
.flatMap(metadataGroup -> metadataGroup.getGroup().stream())
113+
.flatMap(metadataGroup -> metadataGroup.getMetadata().stream())
114114
.collect(Collectors.toList());
115115
}
116116
Optional<String> metadataTitle = metadata.stream()

0 commit comments

Comments
 (0)