Skip to content

Commit

Permalink
Workaround for an unexpected NPE (#830)
Browse files Browse the repository at this point in the history
* Workaround for a case where the negotiation can be null
  • Loading branch information
ununhexium authored Mar 20, 2024
1 parent 6f67c88 commit c002935
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 16 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ please see [changelog_updates.md](docs/dev/changelog_updates.md).

#### Patch Changes

- Add a fix for a null pointer exception in the transfer history API.
- Add e2e test for double encoding of query parameters

### Deployment Migration Notes
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
import java.util.Comparator;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.function.BinaryOperator;
import java.util.function.Function;

Expand All @@ -59,6 +60,7 @@ public class TransferHistoryPageApiService {
public List<TransferHistoryEntry> getTransferHistoryEntries() {

var negotiationsById = getAllContractNegotiations().stream()
.filter(negotiation -> negotiation != null)
.filter(negotiation -> negotiation.getContractAgreement() != null)
.collect(toMap(
it -> it.getContractAgreement().getId(),
Expand All @@ -76,26 +78,33 @@ public List<TransferHistoryEntry> getTransferHistoryEntries() {
var transferProcesses = getAllTransferProcesses();

return transferProcesses.stream().map(process -> {
var agreement = agreementsById.get(process.getDataRequest().getContractId());
var negotiation = negotiationsById.get(process.getDataRequest().getContractId());
var agreement = Optional.ofNullable(agreementsById.get(process.getDataRequest().getContractId()));
var negotiation = Optional.ofNullable(negotiationsById.get(process.getDataRequest().getContractId()));
var asset = assetLookup(assetsById, process);
var direction = ContractAgreementDirection.fromType(negotiation.getType());
var direction = negotiation.map(ContractNegotiation::getType).map(ContractAgreementDirection::fromType);
var transferHistoryEntry = new TransferHistoryEntry();
transferHistoryEntry.setAssetId(asset.getId());
if (direction == ContractAgreementDirection.CONSUMING) {
transferHistoryEntry.setAssetName(asset.getId());
} else {
transferHistoryEntry.setAssetName(
StringUtils.isBlank((String) asset.getProperties().get(Prop.Dcterms.TITLE))
? asset.getId()
: asset.getProperties().get(Prop.Dcterms.TITLE).toString()
);

if (direction.isPresent()) {
if (direction.get() == ContractAgreementDirection.CONSUMING) {
transferHistoryEntry.setAssetName(asset.getId());
} else {
transferHistoryEntry.setAssetName(
StringUtils.isBlank((String) asset.getProperties().get(Prop.Dcterms.TITLE))
? asset.getId()
: asset.getProperties().get(Prop.Dcterms.TITLE).toString()
);
}
}
transferHistoryEntry.setContractAgreementId(agreement.getId());
transferHistoryEntry.setCounterPartyConnectorEndpoint(negotiation.getCounterPartyAddress());
transferHistoryEntry.setCounterPartyParticipantId(negotiation.getCounterPartyId());
transferHistoryEntry.setCreatedDate(utcMillisToOffsetDateTime(negotiation.getCreatedAt()));
transferHistoryEntry.setDirection(direction);

agreement.ifPresent(it -> transferHistoryEntry.setContractAgreementId(it.getId()));
negotiation.ifPresent( it -> {
transferHistoryEntry.setCounterPartyConnectorEndpoint(it.getCounterPartyAddress());
transferHistoryEntry.setCounterPartyParticipantId(it.getCounterPartyId());
transferHistoryEntry.setCreatedDate(utcMillisToOffsetDateTime(it.getCreatedAt()));
});
direction.ifPresent(transferHistoryEntry::setDirection);

transferHistoryEntry.setErrorMessage(process.getErrorDetail());
transferHistoryEntry.setLastUpdatedDate(utcMillisToOffsetDateTime(process.getUpdatedAt()));
transferHistoryEntry.setState(transferProcessStateService.buildTransferProcessState(process.getState()));
Expand Down

0 comments on commit c002935

Please sign in to comment.