(CardRequest request)
| 695 | } |
| 696 | |
| 697 | private PaperCard tryGetCard(CardRequest request) { |
| 698 | // Before doing anything, check that a non-null request has been provided |
| 699 | if (request == null) |
| 700 | return null; |
| 701 | // 1. First off, try using all possible search parameters, to narrow down the actual cards looked for. |
| 702 | String reqEditionCode = request.edition; |
| 703 | if (reqEditionCode != null && !reqEditionCode.isEmpty()) { |
| 704 | // This get is robust even against expansion aliases (e.g. TE and TMP both valid for Tempest) - |
| 705 | // MOST of the extensions have two short codes, 141 out of 221 (so far) |
| 706 | // ALSO: Set Code are always UpperCase |
| 707 | CardEdition edition = editions.get(reqEditionCode.toUpperCase()); |
| 708 | |
| 709 | PaperCard cardFromSet = this.getCardFromSet(request.cardName, edition, request.artIndex, request.collectorNumber, request.isFoil); |
| 710 | if(cardFromSet != null && request.flags != null) |
| 711 | cardFromSet = cardFromSet.copyWithFlags(request.flags); |
| 712 | |
| 713 | if (cardFromSet != null) |
| 714 | return cardFromSet; |
| 715 | } |
| 716 | |
| 717 | // 2. Card lookup in edition with specified filter didn't work. |
| 718 | // So now check whether the cards exist in the DB first, |
| 719 | // and select pick the card based on current SetPreference policy as a fallback |
| 720 | Collection<PaperCard> cards = getAllCards(request.cardName); |
| 721 | if (cards.isEmpty()) // Never null being this a view in MultiMap |
| 722 | return null; |
| 723 | // Either No Edition has been specified OR as a fallback in case of any error! |
| 724 | // get card using the default card art preference |
| 725 | String cardRequest = CardRequest.compose(request.cardName, request.isFoil); |
| 726 | return getCardFromEditions(cardRequest, this.defaultCardArtPreference, request.artIndex); |
| 727 | } |
| 728 | |
| 729 | /* |
| 730 | * ========================================== |
no test coverage detected