Project

General

Profile

« Previous | Next » 

Revision 38912

added new try catch

View differences:

modules/dnet-download-plugins/trunk/src/main/java/eu/dnetlib/download/plugin/EuropePMC.java
55 55
	@Override
56 56
	public DownloadItem retrieveUrl(final DownloadItem input) {
57 57

  
58
		String url = input.getOriginalUrl();
59
		if (url == null || url.trim().length() == 0) return input;
60
		@SuppressWarnings("unchecked")
61
		List<String> urls = new Gson().fromJson(url, ArrayList.class);
62
		log.debug(String.format("urls is %s", url));
63
		if (urls == null || urls.size() == 0) return input;
64
		input.setFileName(input.getIdItemMetadata());
65
		Boolean added = false;
66
		for (String s : urls) {
67
			if (s.startsWith("http")) {
68
				log.debug(String.format("found url starting with http replace original URL with %s", s));
69
				input.setOriginalUrl(s);
70
			} else if (s.startsWith("PMC")) {
71
				String correctUrl = s.replace("PMC", "");
72
				log.debug(String.format("found url starting with PMC %s", correctUrl));
73
				added = true;
74
				String path = PathRetreiver.getInstance(basePath).getPathForPMCID(Integer.parseInt(correctUrl));
75
				if (path != null) {
76
					input.setUrl("file://" + path);
77
				} else {
78
					input.setUrl(path);
58
		try {
59
			String url = input.getOriginalUrl();
60
			if (url == null || url.trim().length() == 0) return input;
61
			@SuppressWarnings("unchecked")
62
			List<String> urls = new Gson().fromJson(url, ArrayList.class);
63
			log.debug(String.format("urls is %s", url));
64
			if (urls == null || urls.size() == 0) return input;
65
			input.setFileName(input.getIdItemMetadata());
66
			Boolean added = false;
67
			for (String s : urls) {
68
				if (s.startsWith("http")) {
69
					log.debug(String.format("found url starting with http replace original URL with %s", s));
70
					input.setOriginalUrl(s);
71
				} else if (s.startsWith("PMC")) {
72
					String correctUrl = s.replace("PMC", "");
73
					log.debug(String.format("found url starting with PMC %s", correctUrl));
74
					added = true;
75
					String path = PathRetreiver.getInstance(basePath).getPathForPMCID(Integer.parseInt(correctUrl));
76
					if (path != null) {
77
						input.setUrl("file://" + path);
78
					} else {
79
						input.setUrl(path);
80
					}
81

  
79 82
				}
80

  
81 83
			}
84
			if (added == false) {
85
				input.setOriginalUrl(null);
86
				input.setUrl(null);
87
			}
88
			return input;
89
		} catch (Throwable e) {
90
			log.error("Exception on Download Plugin");
91
			log.error(e);
92
			return input;
82 93
		}
83
		if (added == false) {
84
			input.setOriginalUrl(null);
85
			input.setUrl(null);
86
		}
87
		return input;
88 94

  
89 95
	}
90 96

  

Also available in: Unified diff