-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
6aab5b0
commit 9794d26
Showing
168 changed files
with
7,359 additions
and
7,989 deletions.
There are no files selected for viewing
85 changes: 42 additions & 43 deletions
85
batch-index/src/main/java/no/unit/nva/indexingclient/AggregationsValidator.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,53 +1,52 @@ | ||
package no.unit.nva.indexingclient; | ||
|
||
import com.fasterxml.jackson.databind.JsonNode; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
public class AggregationsValidator { | ||
|
||
private static final String ENTITY_DESCRIPTION_POINTER = "/entityDescription"; | ||
private static final String REFERENCE_POINTER = "/entityDescription/reference"; | ||
private static final String PUBLICATION_CONTEXT_POINTER = | ||
"/entityDescription/reference/publicationContext"; | ||
private static final String PUBLICATION_INSTANCE_POINTER = | ||
"/entityDescription/reference/publicationInstance"; | ||
private static final String IDENTIFIER_POINTER = "/identifier"; | ||
private static final String DELIMITER = ", "; | ||
private static final String REPORT_TEMPLATE = "Document %s has missing fields %s"; | ||
private final List<String> report; | ||
private final JsonNode document; | ||
|
||
public AggregationsValidator(JsonNode document) { | ||
this.document = document; | ||
this.report = new ArrayList<>(); | ||
} | ||
|
||
private static boolean isNotValidNode(JsonNode node) { | ||
return !node.isObject(); | ||
} | ||
|
||
public String getReport() { | ||
return String.format( | ||
REPORT_TEMPLATE, | ||
document.at(IDENTIFIER_POINTER).textValue(), | ||
String.join(DELIMITER, report)); | ||
} | ||
|
||
public boolean isValid() { | ||
List.of( | ||
ENTITY_DESCRIPTION_POINTER, | ||
REFERENCE_POINTER, | ||
PUBLICATION_CONTEXT_POINTER, | ||
PUBLICATION_INSTANCE_POINTER) | ||
.forEach(this::validateNode); | ||
return report.isEmpty(); | ||
} | ||
|
||
private void validateNode(String value) { | ||
if (isNotValidNode(document.at(value))) { | ||
report.add(value); | ||
} | ||
private static final String ENTITY_DESCRIPTION_POINTER = "/entityDescription"; | ||
private static final String REFERENCE_POINTER = "/entityDescription/reference"; | ||
private static final String PUBLICATION_CONTEXT_POINTER = | ||
"/entityDescription/reference/publicationContext"; | ||
private static final String PUBLICATION_INSTANCE_POINTER = | ||
"/entityDescription/reference/publicationInstance"; | ||
private static final String IDENTIFIER_POINTER = "/identifier"; | ||
private static final String DELIMITER = ", "; | ||
private static final String REPORT_TEMPLATE = "Document %s has missing fields %s"; | ||
private final List<String> report; | ||
private final JsonNode document; | ||
|
||
public AggregationsValidator(JsonNode document) { | ||
this.document = document; | ||
this.report = new ArrayList<>(); | ||
} | ||
|
||
private static boolean isNotValidNode(JsonNode node) { | ||
return !node.isObject(); | ||
} | ||
|
||
public String getReport() { | ||
return String.format( | ||
REPORT_TEMPLATE, | ||
document.at(IDENTIFIER_POINTER).textValue(), | ||
String.join(DELIMITER, report)); | ||
} | ||
|
||
public boolean isValid() { | ||
List.of( | ||
ENTITY_DESCRIPTION_POINTER, | ||
REFERENCE_POINTER, | ||
PUBLICATION_CONTEXT_POINTER, | ||
PUBLICATION_INSTANCE_POINTER) | ||
.forEach(this::validateNode); | ||
return report.isEmpty(); | ||
} | ||
|
||
private void validateNode(String value) { | ||
if (isNotValidNode(document.at(value))) { | ||
report.add(value); | ||
} | ||
} | ||
} |
12 changes: 4 additions & 8 deletions
12
batch-index/src/main/java/no/unit/nva/indexingclient/BatchIndexer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.