Search in sources :

Example 1 with Either

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;
            }
        });
    });
}
Also used : RpkiRepository(net.ripe.rpki.validator3.domain.RpkiRepository) Arrays(java.util.Arrays) CertificateRepositoryObject(net.ripe.rpki.commons.crypto.CertificateRepositoryObject) Transactional(javax.transaction.Transactional) RpkiRepositoryValidationRun(net.ripe.rpki.validator3.domain.RpkiRepositoryValidationRun) Hex(net.ripe.rpki.validator3.util.Hex) RpkiObject(net.ripe.rpki.validator3.domain.RpkiObject) Autowired(org.springframework.beans.factory.annotation.Autowired) Collectors(java.util.stream.Collectors) CertificateRepositoryObjectFactory(net.ripe.rpki.commons.crypto.util.CertificateRepositoryObjectFactory) ErrorCodes(net.ripe.rpki.validator3.domain.ErrorCodes) Slf4j(lombok.extern.slf4j.Slf4j) List(java.util.List) ByteArrayInputStream(java.io.ByteArrayInputStream) RpkiObjects(net.ripe.rpki.validator3.domain.RpkiObjects) Service(org.springframework.stereotype.Service) ValidationResult(net.ripe.rpki.commons.validation.ValidationResult) Optional(java.util.Optional) BigInteger(java.math.BigInteger) Sha256(net.ripe.rpki.validator3.util.Sha256) Either(fj.data.Either) Comparator(java.util.Comparator) ValidationCheck(net.ripe.rpki.validator3.domain.ValidationCheck) RpkiObject(net.ripe.rpki.validator3.domain.RpkiObject) ValidationResult(net.ripe.rpki.commons.validation.ValidationResult)

Aggregations

Either (fj.data.Either)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1 BigInteger (java.math.BigInteger)1 Arrays (java.util.Arrays)1 Comparator (java.util.Comparator)1 List (java.util.List)1 Optional (java.util.Optional)1 Collectors (java.util.stream.Collectors)1 Transactional (javax.transaction.Transactional)1 Slf4j (lombok.extern.slf4j.Slf4j)1 CertificateRepositoryObject (net.ripe.rpki.commons.crypto.CertificateRepositoryObject)1 CertificateRepositoryObjectFactory (net.ripe.rpki.commons.crypto.util.CertificateRepositoryObjectFactory)1 ValidationResult (net.ripe.rpki.commons.validation.ValidationResult)1 ErrorCodes (net.ripe.rpki.validator3.domain.ErrorCodes)1 RpkiObject (net.ripe.rpki.validator3.domain.RpkiObject)1 RpkiObjects (net.ripe.rpki.validator3.domain.RpkiObjects)1 RpkiRepository (net.ripe.rpki.validator3.domain.RpkiRepository)1 RpkiRepositoryValidationRun (net.ripe.rpki.validator3.domain.RpkiRepositoryValidationRun)1 ValidationCheck (net.ripe.rpki.validator3.domain.ValidationCheck)1 Hex (net.ripe.rpki.validator3.util.Hex)1