All Downloads are FREE. Search and download functionalities are using the official Maven repository.

network.oxalis.as4.outbound.As4TransmissionResponse Maven / Gradle / Ivy

There is a newer version: 6.7.0
Show newest version
package network.oxalis.as4.outbound;

import network.oxalis.api.model.TransmissionIdentifier;
import network.oxalis.api.outbound.TransmissionRequest;
import network.oxalis.api.outbound.TransmissionResponse;
import network.oxalis.api.timestamp.Timestamp;
import network.oxalis.as4.lang.OxalisAs4TransmissionException;
import network.oxalis.vefa.peppol.common.model.*;

import java.util.ArrayList;
import java.util.Collections;
import java.util.Date;
import java.util.List;

public class As4TransmissionResponse implements TransmissionResponse {

    // Original transmission request is kept to allow easy access to immutable objects part of the request.
    private final TransmissionRequest transmissionRequest;
    private final TransmissionIdentifier transmissionIdentifier;
    private final Digest digest;
    private final Receipt receipt;
    private final List receipts;
    private final Date timestamp;
    private final OxalisAs4TransmissionException transmissionException;

    public As4TransmissionResponse(TransmissionIdentifier transmissionIdentifier,
                                   TransmissionRequest transmissionRequest, Digest digest,
                                   byte[] nativeEvidenceBytes, Timestamp timestamp, Date date) {
        this.transmissionIdentifier = transmissionIdentifier;
        this.transmissionRequest = transmissionRequest;
        this.digest = digest;
        this.receipt = Receipt.of("message/disposition-notification", nativeEvidenceBytes);
        this.timestamp = date;
        this.transmissionException = null;

        List receiptList = new ArrayList<>();
        receiptList.add(receipt);
        timestamp.getReceipt().ifPresent(receiptList::add);

        this.receipts = Collections.unmodifiableList(receiptList);
    }

    public As4TransmissionResponse(TransmissionIdentifier transmissionIdentifier, TransmissionRequest transmissionRequest, OxalisAs4TransmissionException transmissionException) {
        this.transmissionRequest = transmissionRequest;
        this.transmissionIdentifier = transmissionIdentifier;
        this.transmissionException = transmissionException;
        this.digest = null;
        this.receipt = null;
        this.receipts = null;
        this.timestamp = null;
    }

    @Override
    public Header getHeader() {
        return transmissionRequest.getHeader();
    }

    public TransmissionIdentifier getTransmissionIdentifier() {
        return transmissionIdentifier;
    }

    @Override
    public List getReceipts() {
        return receipts;
    }

    @Override
    public Endpoint getEndpoint() {
        return transmissionRequest.getEndpoint();
    }

    @Override
    public Receipt primaryReceipt() {
        return receipt;
    }

    @Override
    public Digest getDigest() {
        return digest;
    }

    @Override
    public TransportProtocol getTransportProtocol() {
        return TransportProtocol.AS4;
    }

    @Override
    public Date getTimestamp() {
        return timestamp;
    }

    public OxalisAs4TransmissionException getTransmissionException() {
        return transmissionException;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy