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

com.sportradar.mts.sdk.api.impl.TicketCancelResponseImpl Maven / Gradle / Ivy

/*
 * Copyright (C) Sportradar AG. See LICENSE for full license governing this code
 */

package com.sportradar.mts.sdk.api.impl;

import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.google.common.base.Preconditions;
import com.sportradar.mts.sdk.api.ResponseReason;
import com.sportradar.mts.sdk.api.TicketCancelResponse;
import com.sportradar.mts.sdk.api.enums.TicketCancelAcceptance;
import com.sportradar.mts.sdk.api.utils.MtsTicketHelper;

import java.util.Date;
import java.util.Map;

/**
 * Implementation of TicketCancelResponse
 */
public class TicketCancelResponseImpl implements TicketCancelResponse {

    private final String ticketId;
    private final Date timestampUtc;
    private final String version;
    private final ResponseReason reason;
    private final TicketCancelAcceptance status;
    private final String signature;
    private final String correlationId;
    private final Map additionalInfo;
    private final String msgBody;

    @JsonCreator(mode = JsonCreator.Mode.PROPERTIES)
    public TicketCancelResponseImpl(@JsonProperty("ticketId") String ticketId,
                                    @JsonProperty("reason") ResponseReason reason,
                                    @JsonProperty("status") TicketCancelAcceptance status,
                                    @JsonProperty("signature") String signature,
                                    @JsonProperty("timestampUtc") Date timestampUtc,
                                    @JsonProperty("version") String version,
                                    @JsonProperty("correlationId") String correlationId,
                                    @JsonProperty("additionalInfo") Map additionalInfo,
                                    @JsonProperty("msgBody") String msgBody)
    {
        Preconditions.checkNotNull(ticketId, "ticketId cannot be null");
        Preconditions.checkArgument(MtsTicketHelper.validateTicketId(ticketId), "ticketId is not valid");
        Preconditions.checkNotNull(timestampUtc, "timestamp cannot be null");
        Preconditions.checkArgument(MtsTicketHelper.validateTimestamp(timestampUtc), "timestampUtc is not valid");
        Preconditions.checkNotNull(version, "version cannot be null");
        Preconditions.checkArgument(version.length() == 3, "version is not valid");
        Preconditions.checkNotNull(msgBody);

        this.ticketId = ticketId;
        this.reason = reason;
        this.status = status;
        this.signature = signature;
        this.timestampUtc = timestampUtc;
        this.version = version;
        this.correlationId = correlationId;
        this.additionalInfo = additionalInfo;
        this.msgBody = msgBody;
    }

    @Override
    public String getTicketId() {
        return ticketId;
    }

    @Override
    public Date getTimestampUtc() {
        return timestampUtc;
    }

    @Override
    public String getVersion() {
        return version;
    }

    @Override
    public TicketCancelAcceptance getStatus() {
        return status;
    }

    @Override
    public ResponseReason getReason() {
        return reason;
    }

    @Override
    public String getSignature() {
        return signature;
    }

    @Override
    public String getCorrelationId() { return correlationId; }

    @Override
    public Map getAdditionalInfo() {
        return additionalInfo;
    }

    /**
     * Returns the associated ticket in the required MTS JSON format
     *
     * @return the associated ticket in the required MTS JSON format
     */
    @Override
    public String getJsonValue() {
        return msgBody;
    }

    @Override
    public String toString() {
        return "TicketCancelResponseImpl{" +
                "ticketId='" + ticketId + '\'' +
                ", reason=" + reason +
                ", status=" + status +
                ", timestamp=" + timestampUtc +
                ", version='" + version + '\'' +
                ", correlationId='" + correlationId + '\'' +
                '}';
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy