class CustodialHistoryMapper {

    public CustodialHistoryModel map(CustodialHistoryType custodialHistory) {
        if (custodialHistory == null) {
            return null;
        }
        CustodialHistoryModel custodialHistoryModel = new CustodialHistoryModel();
        List<String> collect = custodialHistory.getCustodialHistoryItem().stream()
            .map(TextType::getValue).collect(
                Collectors.toList());

        custodialHistoryModel.getCustodialHistoryItem().addAll(collect);

        DataObjectRefType dataObjectRefType = custodialHistory.getCustodialHistoryFile();
        if (dataObjectRefType != null) {
            DataObjectReference custodialHistoryFile = new DataObjectReference();
            if(dataObjectRefType.getDataObjectGroupReferenceId() != null){
                custodialHistoryFile.setDataObjectGroupReferenceId(dataObjectRefType.getDataObjectGroupReferenceId());
            }
            if(dataObjectRefType.getDataObjectReferenceId() != null){
                custodialHistoryFile.setDataObjectReferenceId(dataObjectRefType.getDataObjectReferenceId());
            }
            custodialHistoryModel.setCustodialHistoryFile(custodialHistoryFile);
        }

        return custodialHistoryModel;
    }

}