2022-03-10 16:56:46 +01:00
|
|
|
// SPDX-FileCopyrightText: 2022 Paul Schaub <vanitasvitae@fsfe.org>
|
|
|
|
//
|
|
|
|
// SPDX-License-Identifier: Apache-2.0
|
|
|
|
|
2022-03-17 15:27:28 +01:00
|
|
|
package pgp.wkd.discovery;
|
2022-03-10 16:56:46 +01:00
|
|
|
|
|
|
|
import pgp.certificate_store.Certificate;
|
|
|
|
|
2022-03-17 15:27:28 +01:00
|
|
|
import javax.annotation.Nonnull;
|
2022-03-10 16:56:46 +01:00
|
|
|
import java.util.ArrayList;
|
|
|
|
import java.util.List;
|
|
|
|
|
2022-03-17 15:27:28 +01:00
|
|
|
public class DiscoveryResult {
|
2022-03-10 16:56:46 +01:00
|
|
|
|
2022-03-17 15:27:28 +01:00
|
|
|
private List<DiscoveryResponse> items;
|
2022-03-10 16:56:46 +01:00
|
|
|
|
2022-03-17 15:27:28 +01:00
|
|
|
public DiscoveryResult(@Nonnull List<DiscoveryResponse> items) {
|
2022-03-10 16:56:46 +01:00
|
|
|
this.items = items;
|
|
|
|
}
|
|
|
|
|
2022-03-17 15:27:28 +01:00
|
|
|
@Nonnull
|
2022-03-10 16:56:46 +01:00
|
|
|
public List<Certificate> getCertificates() {
|
|
|
|
List<Certificate> certificates = new ArrayList<>();
|
|
|
|
|
2022-03-17 15:27:28 +01:00
|
|
|
for (DiscoveryResponse item : items) {
|
2022-03-10 16:56:46 +01:00
|
|
|
if (item.isSuccessful()) {
|
|
|
|
certificates.addAll(item.getCertificates());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return certificates;
|
|
|
|
}
|
|
|
|
|
|
|
|
public boolean isSuccessful() {
|
2022-03-17 15:27:28 +01:00
|
|
|
for (DiscoveryResponse item : items) {
|
2022-03-10 16:56:46 +01:00
|
|
|
if (item.isSuccessful() && item.hasCertificates()) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2022-03-17 15:27:28 +01:00
|
|
|
@Nonnull
|
|
|
|
public List<DiscoveryResponse> getItems() {
|
2022-03-10 16:56:46 +01:00
|
|
|
return items;
|
|
|
|
}
|
|
|
|
|
2022-03-17 15:27:28 +01:00
|
|
|
@Nonnull
|
|
|
|
public List<DiscoveryResponse> getFailedItems() {
|
|
|
|
List<DiscoveryResponse> fails = new ArrayList<>();
|
|
|
|
for (DiscoveryResponse item : items) {
|
2022-03-10 16:56:46 +01:00
|
|
|
if (!item.isSuccessful()) {
|
|
|
|
fails.add(item);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return fails;
|
|
|
|
}
|
|
|
|
}
|