package org.jabref.logic.importer;

import java.util.Optional;

import org.jabref.logic.importer.fetcher.ArXiv;
import org.jabref.logic.importer.fetcher.DoiFetcher;
import org.jabref.logic.importer.fetcher.IacrEprintFetcher;
import org.jabref.logic.importer.fetcher.IsbnFetcher;
import org.jabref.model.entry.BibEntry;
import org.jabref.model.entry.identifier.ArXivIdentifier;
import org.jabref.model.entry.identifier.DOI;
import org.jabref.model.entry.identifier.ISBN;
import org.jabref.model.entry.identifier.IacrEprint;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class CompositeIdFetcher {

    private final Logger LOGGER = LoggerFactory.getLogger(CompositeIdFetcher.class);

    private final ImportFormatPreferences importFormatPreferences;

    public CompositeIdFetcher(ImportFormatPreferences importFormatPreferences) {
        this.importFormatPreferences = importFormatPreferences;
    }

    public Optional<BibEntry> performSearchById(String identifier) {
        try {
            Optional<ArXivIdentifier> arXivIdentifier = ArXivIdentifier.parse(identifier);
            if (arXivIdentifier.isPresent()) {
                return new ArXiv(importFormatPreferences).performSearchById(arXivIdentifier.get().getNormalized());
            }
        } catch (FetcherException fetcherException) {
            LOGGER.debug(fetcherException.getMessage());
        }
        try {
            Optional<ISBN> isbn = ISBN.parse(identifier);
            if (isbn.isPresent()) {
                return new IsbnFetcher(importFormatPreferences).performSearchById(isbn.get().getNormalized());
            }
        } catch (FetcherException fetcherException) {
            LOGGER.debug(fetcherException.getMessage());
        }
        try {
            Optional<DOI> doi = DOI.parse(identifier);
            if (doi.isPresent()) {
                return new DoiFetcher(importFormatPreferences).performSearchById(doi.get().getNormalized());
            }
        } catch (FetcherException fetcherException) {
            LOGGER.debug(fetcherException.getMessage());
        }
        try {
            Optional<IacrEprint> iacrEprint = IacrEprint.parse(identifier);
            if (iacrEprint.isPresent()) {
                return new IacrEprintFetcher(importFormatPreferences).performSearchById(iacrEprint.get().getNormalized());
            }
        } catch (FetcherException fetcherException) {
            LOGGER.debug(fetcherException.getMessage());
        }

        return Optional.empty();

    }

    public String getName() {
        return "CompositeIdFetcher";
    }
}

@@ -521,185 +521,41 @@
 t;%0A%0A
-import org.slf4j.Logger;%0Aimport org.slf4j.LoggerFactory;%0A%0Apublic class CompositeIdFetcher %7B%0A%0A    private final Logger LOGGER = LoggerFactory.getLogger(CompositeIdFetcher.class);
+public class CompositeIdFetcher %7B
 %0A%0A  
@@ -1127,143 +1127,8 @@
   %7D%0A
-        %7D catch (FetcherException fetcherException) %7B%0A            LOGGER.debug(fetcherException.getMessage());%0A        %7D%0A        try %7B%0A
     
@@ -1346,143 +1346,8 @@
   %7D%0A
-        %7D catch (FetcherException fetcherException) %7B%0A            LOGGER.debug(fetcherException.getMessage());%0A        %7D%0A        try %7B%0A
     
@@ -1559,143 +1559,8 @@
   %7D%0A
-        %7D catch (FetcherException fetcherException) %7B%0A            LOGGER.debug(fetcherException.getMessage());%0A        %7D%0A        try %7B%0A
     
@@ -1880,21 +1880,8 @@
     
-LOGGER.debug(
 fetc
@@ -1897,21 +1897,25 @@
 ion.
-getMessag
+printStackTrac
 e()
-)
 ;%0A  

Revert "separately handle fetcherexceptions in CompositeIdFetcher"