GrrValidationDTO.java

package com.tradecloud.dto.goodsreceivedreceipt;

import lombok.Getter;
import lombok.Setter;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import static org.aspectj.runtime.internal.Conversions.longValue;

@Getter
@Setter
public class GrrValidationDTO {

    public static final String ORDER_ID_ALIAS = "order_id";
    public static final String SHIPMENT_ID_ALIAS = "shipment_id";
    public static final String ORDER_REFERENCE_ALIAS = "order_reference";
    public static final String GRN_REFERENCE_ALIAS = "grn_reference";
    public static final String SHIPMENT_REFERENCE_ALIAS = "shipment_reference";

    private Long orderId;
    private Long shipmentId;
    private String orderReference;
    private String shipmentReference;
    private String grnReference;
    private List<GrrItemValidationDTO> items = new ArrayList<>();

    public GrrValidationDTO(
            Object[] tuples,
            Map<String, Integer> aliasToIndexMap) {

        this.orderId = longValue(tuples[aliasToIndexMap.get(ORDER_ID_ALIAS)]);
        this.orderReference = (String) (tuples[aliasToIndexMap.get(ORDER_REFERENCE_ALIAS)]);
        this.grnReference = (String) (tuples[aliasToIndexMap.get(GRN_REFERENCE_ALIAS)]);

        Integer shipmentReferenceIndex = aliasToIndexMap.get(SHIPMENT_REFERENCE_ALIAS);
        if (shipmentReferenceIndex != null)
            this.shipmentReference = (String) (tuples[shipmentReferenceIndex]);

        Integer shipmentIdIndex = aliasToIndexMap.get(SHIPMENT_ID_ALIAS);
        if (shipmentIdIndex != null)
            this.shipmentId = longValue(tuples[shipmentIdIndex]);
    }
}