Project

General

Profile

« Previous | Next » 

Revision 49380

Openaire plugin

View differences:

modules/dnet-isti/trunk/src/main/java/eu/dnetlib/xml/ISTIUtilityFunction.java
4 4
import java.util.stream.Collectors;
5 5

  
6 6
import org.apache.commons.lang3.StringUtils;
7
import org.apache.commons.logging.Log;
8
import org.apache.commons.logging.LogFactory;
7 9

  
8 10
import eu.dnetlib.data.mdstore.plugins.objects.Project;
9 11

  
......
12 14
 */
13 15
public class ISTIUtilityFunction {
14 16

  
17
	private static final Log log = LogFactory.getLog(ISTIUtilityFunction.class);
18

  
15 19
	public static String cleanNames(final String s) {
16 20
		if (StringUtils.isBlank(s)) { return ""; }
17 21
		return cleanNames(s, StringUtils.countMatches(s, ",") > 1 ? "," : ";");
......
46 50
				.replaceAll("\\s", "_");
47 51

  
48 52
		if (!x.equals(doi)) {
49
			System.out.println("AAAAAAAAAAAAAAAAAA " + doi + " -> " + x);
53
			log.info("Cleaning doi: " + doi + " -> " + x);
50 54
		}
51 55

  
52 56
		return x;
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.LinkedHashMap;
7
import java.util.LinkedHashSet;
6 8
import java.util.List;
9
import java.util.Map;
10
import java.util.Map.Entry;
11
import java.util.Set;
7 12

  
13
import org.apache.commons.lang3.StringUtils;
8 14
import org.apache.commons.logging.Log;
9 15
import org.apache.commons.logging.LogFactory;
10 16
import org.dom4j.Document;
11 17
import org.dom4j.DocumentException;
18
import org.dom4j.Element;
12 19
import org.dom4j.Node;
20
import org.dom4j.QName;
13 21
import org.dom4j.io.SAXReader;
14 22
import org.springframework.beans.factory.annotation.Value;
15 23

  
......
35 43

  
36 44
			if (results.size() == 1) {
37 45
				final Node n = (Node) results.get(0);
38
				System.out.println("------------");
39
				System.out.println("TITLE 1: " + doc.valueOf("//*[local-name() = 'title']"));
40
				System.out.println("TITLE 2: " + docRes.valueOf("//*[local-name() = 'title' and @classid='main title']"));
41

  
42
				for (final Object oid : n.selectNodes(".//originalId")) {
43
					System.out.println(" - " + ((Node) oid).getText());
44
				}
46
				updateRights(doc, n);
47
				updateSubjects(doc, n);
48
				updateCitations(doc, n);
49
				updateUrls(doc, n);
45 50
				return true;
46 51
			} else if (results.size() == 1) {
47 52
				log.warn("Too many responses");
......
54 59
		return false;
55 60

  
56 61
	}
62

  
63
	private void updateRights(final Document doc, final Node n) {
64
		final Element rightsList = (Element) doc.selectSingleNode("//*[local-name() = 'rightsList']");
65
		final Set<String> rights = new LinkedHashSet<>();
66
		for (final Object o : rightsList.selectNodes("./*[local-name() = 'rights']")) {
67
			rights.add(((Node) o).getText());
68
			((Node) o).detach();
69
		}
70

  
71
		final String bestLicence = n.valueOf("./bestlicense/@classname");
72
		if (StringUtils.isNotBlank(bestLicence)) {
73
			rights.add(bestLicence);
74
		}
75

  
76
		for (final Object o : n.selectNodes(".//instance")) {
77
			rights.add(((Node) o).valueOf("./licence/@classname").trim());
78
		}
79

  
80
		for (final String r : rights) {
81
			rightsList.addElement(new QName("rights", rightsList.getNamespace())).setText(r);
82
		}
83
	}
84

  
85
	private void updateSubjects(final Document doc, final Node n) {
86
		final Element subjectsList = (Element) doc.selectSingleNode("//*[local-name() = 'subjects']");
87
		final Set<String> subjects = new LinkedHashSet<>();
88
		for (final Object o : subjectsList.selectNodes("./*[local-name() = 'subject']")) {
89
			subjects.add(((Node) o).getText());
90
			((Node) o).detach();
91
		}
92

  
93
		for (final Object o : n.selectNodes(".//subject[@classid='keyword']")) {
94
			subjects.add(((Node) o).getText().trim());
95
		}
96

  
97
		for (final String r : subjects) {
98
			subjectsList.addElement(new QName("subject", subjectsList.getNamespace())).setText(r);
99
		}
100
	}
101

  
102
	private void updateCitations(final Document doc, final Node n) {
103
		final Element citations = (Element) doc.selectSingleNode("//*[local-name() = 'citations']");
104

  
105
		for (final Object o : n.selectNodes(".//citations/citation/rawText")) {
106
			citations.addElement(new QName("citation", citations.getNamespace())).setText(((Node) o).getText());
107
		}
108
	}
109

  
110
	private void updateUrls(final Document doc, final Node n) {
111
		final Element urlList = (Element) doc.selectSingleNode("//*[local-name() = 'alternateIdentifiers']");
112
		final Map<String, String> urls = new LinkedHashMap<>();
113
		for (final Object o : urlList.selectNodes("./*[local-name() = 'alternateIdentifier' and @alternateIdentifierType='url']")) {
114
			urls.put(((Node) o).getText().trim(), "unknown");
115
			((Node) o).detach();
116
		}
117

  
118
		for (final Object oin : n.selectNodes(".//instance")) {
119
			final String licence = ((Element) oin).valueOf("./licence/@classname").trim();
120
			for (final Object ourl : ((Element) oin).selectNodes("./webresource/url")) {
121
				urls.put(((Node) ourl).getText().trim(), licence);
122
			}
123
		}
124

  
125
		for (final Entry<String, String> e : urls.entrySet()) {
126
			final Element aid = urlList.addElement(new QName("alternateIdentifier", urlList.getNamespace()));
127
			aid.addAttribute("alternateIdentifierType", "url");
128
			aid.addAttribute("licence", e.getValue());
129
			aid.setText(e.getKey());
130
		}
131
	}
57 132
}
modules/dnet-isti/trunk/src/main/resources/eu/dnetlib/bootstrap/profiles/TransformationRuleDSResources/people2dataciteTransform.xml
161 161
                    		</isti:person>
162 162
                    	</xsl:for-each>
163 163
                    </isti:persons>
164
                    
165
                    <isti:citations />
166
                    
164 167

  
165 168
                </resource>
166 169

  

Also available in: Unified diff