@Test public void should_return_empty_when_identity_is_missing() throws InvalidParseOperationException { Optional<PersonalCertificateModel> result = personalRepository.findPersonalCertificateByHash("invalid_dn"); assertThat(result).isEmpty(); }
public Optional<PersonalCertificateModel> findPersonalCertificateByHash(String hash) throws InvalidParseOperationException { FindIterable<Document> models = personnalCollection.find( and( eq(PersonalCertificateModel.TAG_HASH, hash), eq(PersonalCertificateModel.STATUS_TAG, CertificateStatus.VALID.name()))); Document first = models.first(); if (first == null) { return Optional.empty(); } return Optional.of(JsonHandler.getFromString(BsonHelper.stringify(first), PersonalCertificateModel.class)); }
PersonalRepository implements CertificateCRLCheckStateUpdater<PersonalCertificateModel> { public Optional<PersonalCertificateModel> findPersonalCertificateByHash(String hash) throws InvalidParseOperationException { FindIterable<Document> models = personnalCollection.find( and( eq(PersonalCertificateModel.TAG_HASH, hash), eq(PersonalCertificateModel.STATUS_TAG, CertificateStatus.VALID.name()))); Document first = models.first(); if (first == null) { return Optional.empty(); } return Optional.of(JsonHandler.getFromString(BsonHelper.stringify(first), PersonalCertificateModel.class)); } }
PersonalRepository implements CertificateCRLCheckStateUpdater<PersonalCertificateModel> { public Optional<PersonalCertificateModel> findPersonalCertificateByHash(String hash) throws InvalidParseOperationException { FindIterable<Document> models = personnalCollection.find( and( eq(PersonalCertificateModel.TAG_HASH, hash), eq(PersonalCertificateModel.STATUS_TAG, CertificateStatus.VALID.name()))); Document first = models.first(); if (first == null) { return Optional.empty(); } return Optional.of(JsonHandler.getFromString(BsonHelper.stringify(first), PersonalCertificateModel.class)); } @VisibleForTesting  PersonalRepository(MongoDbAccess mongoDbAccess, String collectionName);  PersonalRepository(MongoDbAccess mongoDbAccess); }
PersonalRepository implements CertificateCRLCheckStateUpdater<PersonalCertificateModel> { public Optional<PersonalCertificateModel> findPersonalCertificateByHash(String hash) throws InvalidParseOperationException { FindIterable<Document> models = personnalCollection.find( and( eq(PersonalCertificateModel.TAG_HASH, hash), eq(PersonalCertificateModel.STATUS_TAG, CertificateStatus.VALID.name()))); Document first = models.first(); if (first == null) { return Optional.empty(); } return Optional.of(JsonHandler.getFromString(BsonHelper.stringify(first), PersonalCertificateModel.class)); } @VisibleForTesting  PersonalRepository(MongoDbAccess mongoDbAccess, String collectionName);  PersonalRepository(MongoDbAccess mongoDbAccess); void createPersonalCertificate(PersonalCertificateModel personalCertificateModel); Optional<PersonalCertificateModel> findPersonalCertificateByHash(String hash); void deletePersonalCertificate(String hash); @Override FindIterable<Document> findCertificate(String issuerDN, CertificateStatus certificateStatus); @Override void updateCertificateState(List<String> certificatesToUpdate, CertificateStatus certificateStatus); @Override Class<PersonalCertificateModel> getEntityModelType(); }
PersonalRepository implements CertificateCRLCheckStateUpdater<PersonalCertificateModel> { public Optional<PersonalCertificateModel> findPersonalCertificateByHash(String hash) throws InvalidParseOperationException { FindIterable<Document> models = personnalCollection.find( and( eq(PersonalCertificateModel.TAG_HASH, hash), eq(PersonalCertificateModel.STATUS_TAG, CertificateStatus.VALID.name()))); Document first = models.first(); if (first == null) { return Optional.empty(); } return Optional.of(JsonHandler.getFromString(BsonHelper.stringify(first), PersonalCertificateModel.class)); } @VisibleForTesting  PersonalRepository(MongoDbAccess mongoDbAccess, String collectionName);  PersonalRepository(MongoDbAccess mongoDbAccess); void createPersonalCertificate(PersonalCertificateModel personalCertificateModel); Optional<PersonalCertificateModel> findPersonalCertificateByHash(String hash); void deletePersonalCertificate(String hash); @Override FindIterable<Document> findCertificate(String issuerDN, CertificateStatus certificateStatus); @Override void updateCertificateState(List<String> certificatesToUpdate, CertificateStatus certificateStatus); @Override Class<PersonalCertificateModel> getEntityModelType(); static final String PERSONAL_COLLECTION; }