Skip to content

Commit

Permalink
adde nullable method
Browse files Browse the repository at this point in the history
  • Loading branch information
paullatzelsperger committed May 13, 2024
1 parent 54e9dbc commit cd42a65
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import java.util.stream.Collectors;

import static org.eclipse.edc.spi.result.Result.success;
import static org.eclipse.edc.spi.result.Result.successNullable;

/**
* Service to check if a particular {@link VerifiableCredential} is "valid", where "validity" is defined as not revoked and not suspended.
Expand Down Expand Up @@ -62,7 +63,7 @@ public Result<Void> checkValidity(VerifiableCredential credential) {
@Override
public Result<String> getStatusPurpose(VerifiableCredential credential) {
if (credential.getCredentialStatus().isEmpty()) {
return success();
return successNullable(null);
}
var res = credential.getCredentialStatus().stream()
.map(StatusListStatus::parse)
Expand All @@ -80,7 +81,7 @@ public Result<String> getStatusPurpose(VerifiableCredential credential) {
.map(AbstractResult::getContent).toList();

// get(0) is OK, because there should only be 1 credentialStatus
return list.isEmpty() ? success() : success(list.get(0));
return list.isEmpty() ? successNullable(null) : success(list.get(0));

}

Expand Down Expand Up @@ -120,7 +121,7 @@ private Result<String> getStatusInternal(StatusListStatus status) {
if (bitString.get(index)) {
return success(purpose);
}
return success();
return successNullable(null);
}

private VerifiableCredential downloadStatusListCredential(String credentialUrl) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,18 @@ private Result(T content, Failure failure) {
super(content, failure);
}

public static <T> Result<T> success() {
public static Result<Void> success() {
return new Result<>(null, null);
}

public static <T> Result<T> success(@NotNull T content) {
return new Result<>(content, null);
}

public static <T> Result<T> successNullable(@Nullable T content) {
return new Result<>(content, null);
}

public static <T> Result<T> failure(String failure) {
return new Result<>(null, new Failure(List.of(failure)));
}
Expand Down

0 comments on commit cd42a65

Please sign in to comment.