use of fj.data.Either in project rpki-validator-3 by RIPE-NCC.
the class RrdpService method storeSnapshot.
void storeSnapshot(final Snapshot snapshot, final RpkiRepositoryValidationRun validationRun) {
snapshot.asMap().forEach((objUri, value) -> {
byte[] content = value.content;
rpkiObjectRepository.findBySha256(Sha256.hash(content)).map(existing -> {
existing.addLocation(objUri);
return existing;
}).orElseGet(() -> {
final Either<ValidationResult, RpkiObject> maybeRpkiObject = createRpkiObject(objUri, content);
if (maybeRpkiObject.isLeft()) {
validationRun.addChecks(maybeRpkiObject.left().value());
return null;
} else {
RpkiObject object = maybeRpkiObject.right().value();
rpkiObjectRepository.add(object);
validationRun.addRpkiObject(object);
log.debug("added to database {}", object);
return object;
}
});
});
}
Aggregations