Project

General

Profile

« Previous | Next » 

Revision 55101

counters

View differences:

modules/dnet-isti/trunk/src/main/java/eu/dnetlib/data/mdstore/plugins/Counter.java
1
package eu.dnetlib.data.mdstore.plugins;
2

  
3
public class Counter {
4

  
5
	private int before = 0;
6
	private int after = 0;
7

  
8
	public int getBefore() {
9
		return before;
10
	}
11

  
12
	public void setBefore(final int before) {
13
		this.before = before;
14
	}
15

  
16
	public int getAfter() {
17
		return after;
18
	}
19

  
20
	public void setAfter(final int after) {
21
		this.after = after;
22
	}
23

  
24
	public void incrementBefore(final int n) {
25
		before += n;
26
	}
27

  
28
	public void incrementAfter(final int n) {
29
		after += n;
30
	}
31

  
32
	@Override
33
	public String toString() {
34
		return "before = " + before + ", after = " + after + " , difference = " + (after - before);
35
	}
36

  
37
	public void reset() {
38
		setBefore(0);
39
		setAfter(0);
40
	}
41

  
42
}
modules/dnet-isti/trunk/src/main/java/eu/dnetlib/data/mdstore/plugins/EnrichDatasetsPlugin.java
7 7
import java.util.Map;
8 8

  
9 9
import org.apache.commons.lang3.StringUtils;
10
import org.apache.commons.logging.Log;
11
import org.apache.commons.logging.LogFactory;
10 12
import org.springframework.beans.factory.annotation.Value;
11 13

  
12 14
import com.google.gson.Gson;
......
19 21

  
20 22
public class EnrichDatasetsPlugin extends GenericDoiMdstorePlugin {
21 23

  
24
	private static final Log log = LogFactory.getLog(EnrichDatasetsPlugin.class);
25

  
22 26
	private static final Gson gson = new Gson();
23 27

  
24 28
	@Value("${plugin.enrich.dataset.dli.url}")
25 29
	private String baseUrl;
26 30

  
31
	private Counter enrichDatasetsCounter = new Counter();
32

  
27 33
	@Override
28 34
	protected URI prepareURI(final String doi) throws URISyntaxException {
29 35
		return new URI(String.format(baseUrl, doi));
30 36
	}
31 37

  
32 38
	@Override
33
	protected void reconfigure(final Map<String, String> params) {}
39
	protected void reconfigure(final Map<String, String> params) {
40
		enrichDatasetsCounter.reset();
41
	}
34 42

  
35 43
	@Override
36
	protected void resetConfiguration() {}
44
	protected void resetConfiguration() {
45
		log.info("***** Openaire Enrichment - datasets  : " + enrichDatasetsCounter);
46
		enrichDatasetsCounter.reset();
47
	}
37 48

  
38 49
	@Override
39 50
	protected boolean updateDocument(final MdRecord doc, final String response) {
......
57 68
			return false;
58 69
		} else {
59 70
			doc.getDatasets().addAll(datasets);
71
			enrichDatasetsCounter.incrementAfter(doc.getDatasets().size());
60 72
			return true;
61 73
		}
62 74
	}
modules/dnet-isti/trunk/src/main/java/eu/dnetlib/data/mdstore/plugins/EnrichOpenairePlugin.java
3 3
import java.io.StringReader;
4 4
import java.net.URI;
5 5
import java.net.URISyntaxException;
6
import java.util.HashMap;
6 7
import java.util.List;
7 8
import java.util.Map;
8 9
import java.util.Set;
......
28 29
	@Value("${plugin.enrich.publications.openaire.url}")
29 30
	private String baseUrl;
30 31

  
32
	private Map<String, Counter> counters = new HashMap<>();
33

  
31 34
	@Override
32 35
	protected URI prepareURI(final String doi) throws URISyntaxException {
33 36
		return new URI(String.format(baseUrl, doi));
34 37
	}
35 38

  
36 39
	@Override
37
	protected void reconfigure(final Map<String, String> params) {}
40
	protected void reconfigure(final Map<String, String> params) {
41
		counters.clear();
42
		counters.put("subjects", new Counter());
43
		counters.put("citations", new Counter());
44
		counters.put("urls", new Counter());
45
		counters.put("projects", new Counter());
46
	}
38 47

  
39 48
	@Override
40
	protected void resetConfiguration() {}
49
	protected void resetConfiguration() {
50
		log.info("***** Openaire Enrichment - subjects  : " + counters.get("subjects"));
51
		log.info("***** Openaire Enrichment - citations : " + counters.get("citations"));
52
		log.info("***** Openaire Enrichment - urls      : " + counters.get("urls"));
53
		log.info("***** Openaire Enrichment - projects  : " + counters.get("projects"));
54
		counters.clear();
55
	}
41 56

  
42 57
	@Override
43 58
	protected boolean updateDocument(final MdRecord doc, final String response) {
59
		counters.get("subjects").incrementBefore(doc.getSubjects().size());
60
		counters.get("citations").incrementBefore(doc.getCitations().size());
61
		counters.get("urls").incrementBefore(doc.getUrls().size());
62
		counters.get("projects").incrementBefore(doc.getProjects().size());
44 63

  
45 64
		try {
46 65
			final Document docRes = (new SAXReader()).read(new StringReader(response));
......
54 73
				updateUrls(doc, n);
55 74
				updateProjects(doc, n);
56 75
				updateBestRights(doc);
76

  
57 77
				return true;
58 78
			} else if (results.size() == 1) {
59 79
				log.warn("Too many responses");
60 80
			}
61

  
62 81
		} catch (final DocumentException e) {
63 82
			log.warn("Invalid response", e);
83
		} finally {
84
			counters.get("subjects").incrementAfter(doc.getSubjects().size());
85
			counters.get("citations").incrementAfter(doc.getCitations().size());
86
			counters.get("urls").incrementAfter(doc.getUrls().size());
87
			counters.get("projects").incrementAfter(doc.getProjects().size());
64 88
		}
65 89

  
66 90
		return false;

Also available in: Unified diff