Skip to content

Commit

Permalink
Merge pull request 'release_1.1.3' (#6) from release_1.1.3 into master
Browse files Browse the repository at this point in the history
  • Loading branch information
Dominick Leppich committed Sep 10, 2024
2 parents e0edeba + 0148f03 commit ab87956
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 21 deletions.
4 changes: 2 additions & 2 deletions module-core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
</parent>
<groupId>io.goobi.vocabulary</groupId>
<artifactId>vocabulary-server-core</artifactId>
<version>1.1.2</version>
<version>1.1.3</version>
<name>Vocabulary-Server-Core</name>
<description>Spring Boot based RESTful web service for vocabulary management</description>
<packaging>jar</packaging>
Expand All @@ -26,7 +26,7 @@
<dependency>
<groupId>io.goobi.vocabulary</groupId>
<artifactId>vocabulary-server-exchange</artifactId>
<version>1.1.2</version>
<version>1.1.3</version>
<scope>compile</scope>
</dependency>

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package io.goobi.vocabulary.service.io;

import io.goobi.vocabulary.exception.VocabularyException;
import io.goobi.vocabulary.exchange.FieldInstance;
import io.goobi.vocabulary.exchange.FieldValue;
import io.goobi.vocabulary.exchange.TranslationInstance;
Expand Down Expand Up @@ -53,22 +54,21 @@ public List<VocabularyRecord> fromTabularData(VocabularyEntity vocabulary, List<
List<String> header = data.get(0);
parseHeader(header);
validateHeader();
List<Throwable> importErrors = new LinkedList<>();
List<VocabularyException> importErrors = new LinkedList<>();

// parse all records and create a queue
List<VocabularyRecord> result = new LinkedList<>();
for (int i = 1; i < data.size(); i++) {
try {
result.add(parseRecord(data.get(i)));
} catch (IllegalArgumentException e) {
} catch (VocabularyException e) {
importErrors.add(e);
}
}

if (!importErrors.isEmpty()) {
// TODO: Use VocabularyException
throw new IllegalArgumentException("Error(s) during tabular data parsing:\n\t"
+ importErrors.stream().map(Throwable::getMessage).collect(Collectors.joining("\n\t")));
throw new VocabularyException(VocabularyException.ErrorCode.RecordImportParsingIssues, importErrors, null,
params -> "Errors during record parsing");
}

return result;
Expand Down Expand Up @@ -113,31 +113,31 @@ private void validateHeader() {
.map(l -> new FieldInformation(name, l));
})
.collect(Collectors.toSet()));
Set<FieldInformation> presentFields = fields.stream().collect(Collectors.toSet());
Set<FieldInformation> presentFields = new HashSet<>(fields);
if (!definedFields.equals(presentFields)) {
Set<FieldInformation> undefined = presentFields.stream()
.filter(f -> !definedFields.contains(f))
.collect(Collectors.toSet());
Set<FieldInformation> missing = definedFields.stream()
.filter(f -> !presentFields.contains(f))
.collect(Collectors.toSet());
String error = "Given fields do not match vocabulary schema:";
if (!undefined.isEmpty()) {
error += "\n\tUndefined fields: " + undefined.stream().map(FieldInformation::toString).collect(Collectors.joining(", "));
}
if (!missing.isEmpty()) {
error += "\n\tMissing fields: " + missing.stream().map(FieldInformation::toString).collect(Collectors.joining(", "));
}
// TODO: Use VocabularyException
throw new IllegalArgumentException(error);
throw new VocabularyException(VocabularyException.ErrorCode.RecordImportHeaderIssues, null, Map.of(
"undefinedFields", undefined.stream().map(FieldInformation::toString).collect(Collectors.joining(",")),
"missingFields", missing.stream().map(FieldInformation::toString).collect(Collectors.joining(","))
),
params -> "Given fields do not match vocabulary schema, undefined fields \"" + params.get("undefinedFields") + "\", missing fields \"" + params.get("missingFields") + "\"");
}
}

private VocabularyRecord parseRecord(List<String> rec) {
VocabularyRecord resultRecord = new VocabularyRecord();

if (rec.size() != fields.size()) {
throw new IllegalArgumentException("Malformed tabular data, number of fields does not match header");
throw new VocabularyException(VocabularyException.ErrorCode.RecordImportFieldCountIssue, null, Map.of(
"expectedSize", String.valueOf(fields.size()),
"realSize", String.valueOf(rec.size())
),
params -> "Malformed tabular data, number of fields does not match header. Header size \"" + params.get("expectedSize") + "\", data row size \"" + params.get("realSize") + "\"");
}

Map<String, FieldInstance> fieldMap = new HashMap<>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,6 @@ private void performRecordImport(List<VocabularyRecord> insertionQueue) {
}
}
if (!importErrors.isEmpty()) {
// TODO: Use VocabularyException
throw new VocabularyException(RecordImport, importErrors, null,
params -> "Error(s) during tabular import:\n\t" + importErrors.stream().map(Throwable::getMessage).collect(Collectors.joining("\n\t")));
}
Expand Down
2 changes: 1 addition & 1 deletion module-exchange/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>io.goobi.vocabulary</groupId>
<artifactId>vocabulary-server-exchange</artifactId>
<version>1.1.2</version>
<version>1.1.3</version>
<name>Vocabulary Exchange</name>
<description>Vocabulary data exchange classes</description>
<packaging>jar</packaging>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@ public enum ErrorCode {
RecordValidationChildrenReferencesNotAllowed,
RecordValidationSingleRootElementVocabularyAlreadyContainsRecord,
RecordImport,
RecordImportHeaderIssues,
RecordImportParsingIssues,
RecordImportFieldCountIssue,
RecordImportUnsupportedExcelCellType,
FieldInstanceIssues,
FieldInstanceIsEmpty,
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>io.goobi.vocabulary</groupId>
<artifactId>vocabulary-server</artifactId>
<version>1.1.2</version>
<version>1.1.3</version>
<name>Vocabulary-Server</name>
<packaging>pom</packaging>
<description>RESTful webservice for vocabulary management</description>
Expand Down

0 comments on commit ab87956

Please sign in to comment.