Project

General

Profile

« Previous | Next » 

Revision 51020

refactoring using jaxb

View differences:

modules/dnet-isti/trunk/src/main/java/eu/dnetlib/xml/ISTIUtilityFunction.java
1
package eu.dnetlib.xml;
2

  
3
import java.util.Arrays;
4
import java.util.regex.Matcher;
5
import java.util.regex.Pattern;
6
import java.util.stream.Collectors;
7

  
8
import org.apache.commons.lang3.StringUtils;
9
import org.apache.commons.logging.Log;
10
import org.apache.commons.logging.LogFactory;
11

  
12
import eu.dnetlib.data.mdstore.plugins.objects.Project;
13

  
14
/**
15
 * Created by sandro on 12/6/16.
16
 */
17
public class ISTIUtilityFunction {
18

  
19
	private static final Log log = LogFactory.getLog(ISTIUtilityFunction.class);
20

  
21
	public static String cleanNames(final String s) {
22
		if (StringUtils.isBlank(s)) { return ""; }
23
		return cleanNames(s, StringUtils.countMatches(s, ",") > 1 ? "," : ";");
24
	}
25

  
26
	private static String cleanNames(final String s, final String sep) {
27
		return Arrays.stream(s.split(sep))
28
				.map(String::trim)
29
				.map(ISTIUtilityFunction::clean)
30
				.map(ISTIUtilityFunction::capitalize)
31
				.filter(StringUtils::isNotBlank)
32
				.collect(Collectors.joining("#"));
33
	}
34

  
35
	private static String clean(final String s) {
36
		return s.replaceAll("\\(.*\\)", "")
37
				.replaceAll("\\[.*\\]", "")
38
				.replaceAll("(?i)^et\\.? al(\\.|\\s)*$", "")
39
				.replaceAll("(?i)\\s*et\\.? al(\\.|\\s)*$", "")
40
				.replaceAll("\\d|\\*", "")
41
				.replaceAll("^(\\s|\\-|\\.)+", "")
42
				.replaceAll("\\,", "")
43
				.replaceAll("\\.", ". ")
44
				.trim();
45
	}
46

  
47
	public static String cleanDoi(final String doi) {
48
		final String x = doi.replaceAll("\\?", "")
49
				.replaceAll("\\s*\\/\\s*", "/")
50
				.replaceAll("\\s*\\-\\s*", "-")
51
				.trim()
52
				.replaceAll("\\s", "_");
53

  
54
		if (!x.equals(doi)) {
55
			log.info("Cleaning doi: " + doi + " -> " + x);
56
		}
57

  
58
		return x;
59
	}
60

  
61
	public static String capitalize(final String s) {
62
		return Arrays.stream(s.split(" "))
63
				.map(String::toLowerCase)
64
				.map(StringUtils::capitalize)
65
				.map(ISTIUtilityFunction::fixApostrophes)
66
				.collect(Collectors.joining(" "));
67
	}
68

  
69
	public static String fixApostrophes(final String s) {
70
		return s.replaceAll("'a", "'A").replaceAll("'e", "'E").replaceAll("'i", "'I").replaceAll("'o", "'O").replaceAll("'u", "'U")
71
				.replaceAll("a'", "à").replaceAll("e'", "è").replaceAll("i'", "ì").replaceAll("o'", "ò").replaceAll("u'", "ù");
72
	}
73

  
74
	public static boolean isValidProject(final String id) {
75
		return Project.isValid(id);
76
	}
77

  
78
	public static String calculatePersonName(final String s) {
79
		final Pattern pattern = Pattern.compile("info:cnr-pdr\\/author\\/(.+):(.+)\\/(.+)\\/(.+)");
80
		final Matcher matcher = pattern.matcher(s);
81
		return matcher.find() ? capitalize(String.format("%s %s", matcher.group(4), matcher.group(3))) : "";
82
	}
83

  
84
	// <xsl:for-each select="tokenize(istiFunction:cleanName(.), ';')">
85
	// <xsl:choose>
86
	// <xsl:when test="matches(normalize-space(.), ',(\s*[a-zA-Z]\.)+$')">
87
	// <creator>
88
	// <creatorName>
89
	// <xsl:value-of select="normalize-space(translate(.,',',' '))"/>
90
	// </creatorName>
91
	// </creator>
92
	// </xsl:when>
93
	//
94
	// <xsl:when test="matches(normalize-space(.), '(^[a-zA-Z\.]+,\s?[a-zA-Z\.\s]+$)|(^[a-zA-Z\.\s]+,\s?[a-zA-Z\.]+$)')">
95
	// <creator>
96
	// <creatorName>
97
	// <xsl:value-of select="normalize-space(translate(.,',',' '))"/>
98
	// </creatorName>
99
	// </creator>
100
	// </xsl:when>
101
	//
102
	// <xsl:otherwise>
103
	// <xsl:for-each select="tokenize(., ',')">
104
	// <creator>
105
	// <creatorName>
106
	// <xsl:value-of select="normalize-space(.)"/>
107
	// </creatorName>
108
	// </creator>
109
	// </xsl:for-each>
110
	// </xsl:otherwise>
111
	// </xsl:choose>
112
	// </xsl:for-each>
113
	//
114

  
115
}
modules/dnet-isti/trunk/src/main/resources/eu/dnetlib/bootstrap/profiles/MDFormatDSResources/datacite_mdformat.xml
1
<RESOURCE_PROFILE>
2
	<HEADER>
3
		<RESOURCE_IDENTIFIER
4
				value="98d4c3c4-4274-4250-89b5-434195b20ba8_TURGb3JtYXREU1Jlc291cmNlcy9NREZvcm1hdERTUmVzb3VyY2VUeXBl"/>
5
		<RESOURCE_TYPE value="MDFormatDSResourceType"/>
6
		<RESOURCE_KIND value="MDFormatDSResources"/>
7
		<RESOURCE_URI value=""/>
8
		<DATE_OF_CREATION value="2016-02-01T15:51:45+01:00"/>
9
	</HEADER>
10
	<BODY>
11
		<CONFIGURATION>
12
			<NAME>PMF</NAME>
13
			<DESCRIPTION>ISTI Portal Metadata Format</DESCRIPTION>
14
			<INTERPRETATION>final</INTERPRETATION>
15
			<SCHEMA uri=""/>
16
		</CONFIGURATION>
17
		<STATUS>
18
			<LAYOUTS>
19
				<LAYOUT name="index">
20
					<FIELDS>
21
						<FIELD indexable="true" name="objidentifier" result="false" stored="true" stat="false" tokenizable="false" xpath="//dri:objIdentifier"/>
22
						<FIELD indexable="true" name="creator" result="false" stored="true" stat="false" tokenizable="true" xpath="//*[local-name() = 'creator']/*[local-name()='creatorName']"/>
23
						<FIELD indexable="true" name="cnrcreator" result="false" stored="true" stat="false" tokenizable="true" xpath="//*[local-name() = 'person']/*[local-name()='personName']"/>
24
						<FIELD indexable="true" name="title" result="false" stored="true" stat="false" tokenizable="true" xpath="//*[local-name() = 'title']"/>
25
						<FIELD indexable="true" name="description" result="false" stored="true" stat="false" tokenizable="true" xpath="//*[local-name() = 'description']"/>
26
						<FIELD indexable="true" name="subject" result="false" stored="true" stat="false" tokenizable="false" xpath="//*[local-name() = 'subject']"/>
27
						<FIELD indexable="true" name="language" result="false" stored="true" stat="false" tokenizable="false" xpath="//*[local-name() = 'language']"/>
28
						<FIELD indexable="true" name="type" result="false" stored="true" stat="false" tokenizable="false" xpath="//*[local-name() = 'resourceType']"/>
29
						<FIELD indexable="true" name="date" result="false" stored="true" stat="false" tokenizable="false" xpath="//*[local-name() = 'date']"/>
30
						<FIELD indexable="true" name="affiliation" result="false" stored="true" stat="false" tokenizable="false" xpath="//*[local-name() = 'affiliation']"/>
31
						<FIELD indexable="true" name="group" result="false" stored="true" stat="false" tokenizable="false" xpath="//*[local-name() = 'affiliation' and @type = 'Servizio']/@group"/>
32
						<FIELD indexable="true" name="laboratory" result="false" stored="true" stat="false" tokenizable="false" xpath="//*[local-name() = 'affiliation' and (@type = 'Laboratorio' or @type = 'Centro')]/@group"/>
33
						<FIELD indexable="true" name="creatorforbrowsing" result="false" stored="false" stat="false" tokenizable="false" xpath="//*[local-name() = 'creator']/*[local-name()='creatorName']"/>
34
						<FIELD indexable="true" name="cnrcreatorforbrowsing" result="false" stored="false" stat="false" tokenizable="false" xpath="//*[local-name() = 'person']/*[local-name()='personName']"/>
35
						<FIELD indexable="true" name="doi" result="false" stat="false" stored="true" tokenizable="false" xpath="//*[local-name() = 'alternateIdentifier' and @alternateIdentifierType='doi']"/>
36
						<FIELD indexable="true" name="url" result="false" stat="false" stored="true" tokenizable="false" xpath="//*[local-name() = 'alternateIdentifier' and @alternateIdentifierType='url']/concat(@licence, '||', @hostedBy, '||', text())"/>
37
						<FIELD indexable="true" name="rights" result="false" stat="false" stored="true" tokenizable="false" xpath="//*[local-name() = 'bestLicence']"/>
38
						<FIELD indexable="true" name="projectacronym" result="false" stat="false" stored="true" tokenizable="false" xpath="//*[local-name() = 'project']/*[local-name() = 'acronym']"/>
39
						<FIELD indexable="true" name="projectname" result="false" stat="false" stored="true" tokenizable="false" xpath="//*[local-name() = 'project']/concat(./*[local-name() = 'acronym'], ' - ',./*[local-name() = 'name'])"/>
40
						<FIELD indexable="true" name="projectopenaireid" result="false" stat="false" stored="true" tokenizable="false" xpath="//*[local-name() = 'project']/concat(./*[local-name() = 'acronym'], '||', ./*[local-name() = 'openaireId'])"/>
41
						<FIELD indexable="true" name="source" result="false" stored="true" stat="false" tokenizable="true" xpath="//*[local-name() = 'source']"/>
42
						<FIELD indexable="true" name="labgroupacronym" result="false" stored="true" stat="false" tokenizable="false" xpath="//*[local-name() = 'affiliation' and (@type = 'Laboratorio' or @type = 'Servizio' or @type = 'Centro')]/@groupAcronym"/>
43
						<FIELD indexable="true" name="publisher" result="false" stored="true" stat="false" tokenizable="false" xpath="//*[local-name() = 'publisher']"/>
44
					</FIELDS>
45
				</LAYOUT>
46
			</LAYOUTS>
47
		</STATUS>
48
	</BODY>
49
</RESOURCE_PROFILE>
modules/dnet-isti/trunk/src/test/java/eu/dnetlib/isti/transform/TransformTest.java
18 18
import org.junit.Ignore;
19 19
import org.junit.Test;
20 20

  
21
import eu.dnetlib.xml.ISTIUtilityFunction;
21
import eu.dnetlib.data.utils.XsltFunctions;
22 22

  
23 23
/**
24 24
 * Created by sandro on 9/30/16.
......
45 45

  
46 46
		// System.out.println("record = " + record);
47 47

  
48
		System.out.println("name :" + ISTIUtilityFunction.cleanNames("(eds.)"));
48
		System.out.println("name :" + XsltFunctions.cleanNames("(eds.)"));
49 49

  
50 50
	}
51 51

  
modules/dnet-isti/trunk/src/main/java/eu/dnetlib/msro/workflows/nodes/PimpaUpdateJobNode.java
11 11
import org.springframework.beans.factory.annotation.Autowired;
12 12

  
13 13
import eu.dnetlib.clients.pimpa.PimpaStubFactory;
14
import eu.dnetlib.data.db.Affiliation;
15 14
import eu.dnetlib.data.db.AffiliationsDao;
15
import eu.dnetlib.data.utils.IstiConstants;
16
import eu.dnetlib.data.utils.XsltFunctions;
16 17
import eu.dnetlib.msro.workflows.graph.Arc;
17 18
import eu.dnetlib.msro.workflows.procs.Env;
18
import eu.dnetlib.xml.ISTIUtilityFunction;
19 19

  
20 20
public class PimpaUpdateJobNode extends SimpleJobNode {
21 21

  
......
43 43
				.collect(Collectors.toSet());
44 44

  
45 45
		pimpa.getStub()
46
				.getDataRange(Affiliation.START_YEAR, Calendar.getInstance().get(Calendar.YEAR))
46
				.getDataRange(IstiConstants.PIMPA_START_YEAR, Calendar.getInstance().get(Calendar.YEAR))
47 47
				.getYears()
48 48
				.forEach(y -> {
49 49
					y.getPersons().getList().forEach(p -> {
......
81 81
		if (capitalizeFullnames) {
82 82
			log.info("Capitalizing person fullnames");
83 83
			dao.listPersons().forEach(p -> {
84
				dao.updatePerson(p.getId(), ISTIUtilityFunction.capitalize(p.getName()));
84
				dao.updatePerson(p.getId(), XsltFunctions.capitalize(p.getName()));
85 85
			});;
86 86
		}
87 87

  
modules/dnet-isti/trunk/src/main/java/eu/dnetlib/data/utils/XsltFunctions.java
1
package eu.dnetlib.data.utils;
2

  
3
import java.util.Arrays;
4
import java.util.regex.Matcher;
5
import java.util.regex.Pattern;
6
import java.util.stream.Collectors;
7

  
8
import org.apache.commons.lang3.StringUtils;
9
import org.apache.commons.logging.Log;
10
import org.apache.commons.logging.LogFactory;
11

  
12
import eu.dnetlib.data.mdstore.plugins.objects.Project;
13

  
14
/**
15
 * Created by sandro on 12/6/16.
16
 */
17
public class XsltFunctions {
18

  
19
	private static final Log log = LogFactory.getLog(XsltFunctions.class);
20

  
21
	public static String cleanNames(final String s) {
22
		if (StringUtils.isBlank(s)) { return ""; }
23
		return cleanNames(s, StringUtils.countMatches(s, ",") > 1 ? "," : ";");
24
	}
25

  
26
	private static String cleanNames(final String s, final String sep) {
27
		return Arrays.stream(s.split(sep))
28
				.map(String::trim)
29
				.map(XsltFunctions::clean)
30
				.map(XsltFunctions::capitalize)
31
				.filter(StringUtils::isNotBlank)
32
				.collect(Collectors.joining("#"));
33
	}
34

  
35
	private static String clean(final String s) {
36
		return s.replaceAll("\\(.*\\)", "")
37
				.replaceAll("\\[.*\\]", "")
38
				.replaceAll("(?i)^et\\.? al(\\.|\\s)*$", "")
39
				.replaceAll("(?i)\\s*et\\.? al(\\.|\\s)*$", "")
40
				.replaceAll("\\d|\\*", "")
41
				.replaceAll("^(\\s|\\-|\\.)+", "")
42
				.replaceAll("\\,", "")
43
				.replaceAll("\\.", ". ")
44
				.trim();
45
	}
46

  
47
	public static String cleanDoi(final String doi) {
48
		final String x = doi.replaceAll("\\?", "")
49
				.replaceAll("\\s*\\/\\s*", "/")
50
				.replaceAll("\\s*\\-\\s*", "-")
51
				.trim()
52
				.replaceAll("\\s", "_");
53

  
54
		if (!x.equals(doi)) {
55
			log.info("Cleaning doi: " + doi + " -> " + x);
56
		}
57

  
58
		return x;
59
	}
60

  
61
	public static String capitalize(final String s) {
62
		return Arrays.stream(s.split(" "))
63
				.map(String::toLowerCase)
64
				.map(StringUtils::capitalize)
65
				.map(XsltFunctions::fixApostrophes)
66
				.collect(Collectors.joining(" "));
67
	}
68

  
69
	public static String fixApostrophes(final String s) {
70
		return s.replaceAll("'a", "'A").replaceAll("'e", "'E").replaceAll("'i", "'I").replaceAll("'o", "'O").replaceAll("'u", "'U")
71
				.replaceAll("a'", "à").replaceAll("e'", "è").replaceAll("i'", "ì").replaceAll("o'", "ò").replaceAll("u'", "ù");
72
	}
73

  
74
	public static boolean isValidProject(final String id) {
75
		return Project.isValid(id);
76
	}
77

  
78
	public static String calculatePersonName(final String s) {
79
		final Pattern pattern = Pattern.compile("info:cnr-pdr\\/author\\/(.+):(.+)\\/(.+)\\/(.+)");
80
		final Matcher matcher = pattern.matcher(s);
81
		return matcher.find() ? capitalize(String.format("%s %s", matcher.group(4), matcher.group(3))) : "";
82
	}
83

  
84
	// <xsl:for-each select="tokenize(istiFunction:cleanName(.), ';')">
85
	// <xsl:choose>
86
	// <xsl:when test="matches(normalize-space(.), ',(\s*[a-zA-Z]\.)+$')">
87
	// <creator>
88
	// <creatorName>
89
	// <xsl:value-of select="normalize-space(translate(.,',',' '))"/>
90
	// </creatorName>
91
	// </creator>
92
	// </xsl:when>
93
	//
94
	// <xsl:when test="matches(normalize-space(.), '(^[a-zA-Z\.]+,\s?[a-zA-Z\.\s]+$)|(^[a-zA-Z\.\s]+,\s?[a-zA-Z\.]+$)')">
95
	// <creator>
96
	// <creatorName>
97
	// <xsl:value-of select="normalize-space(translate(.,',',' '))"/>
98
	// </creatorName>
99
	// </creator>
100
	// </xsl:when>
101
	//
102
	// <xsl:otherwise>
103
	// <xsl:for-each select="tokenize(., ',')">
104
	// <creator>
105
	// <creatorName>
106
	// <xsl:value-of select="normalize-space(.)"/>
107
	// </creatorName>
108
	// </creator>
109
	// </xsl:for-each>
110
	// </xsl:otherwise>
111
	// </xsl:choose>
112
	// </xsl:for-each>
113
	//
114

  
115
}
modules/dnet-isti/trunk/src/main/java/eu/dnetlib/data/utils/CsvConverter.java
1
package eu.dnetlib.data.utils;
2

  
3
public class CsvConverter {
4

  
5
	public static String asCsv(final String string) {
6
		// TODO Auto-generated method stub
7
		return null;
8
	}
9

  
10
}
modules/dnet-isti/trunk/src/main/java/eu/dnetlib/data/utils/BibTexConverter.java
1
package eu.dnetlib.data.utils;
2

  
3
import java.io.IOException;
4
import java.io.StringReader;
5
import java.io.StringWriter;
6
import java.io.Writer;
7
import java.util.List;
8
import java.util.stream.Collectors;
9

  
10
import org.apache.commons.lang3.StringUtils;
11
import org.apache.commons.logging.Log;
12
import org.apache.commons.logging.LogFactory;
13
import org.dom4j.Document;
14
import org.dom4j.DocumentException;
15
import org.dom4j.Node;
16
import org.dom4j.io.SAXReader;
17
import org.jbibtex.BibTeXDatabase;
18
import org.jbibtex.BibTeXEntry;
19
import org.jbibtex.BibTeXFormatter;
20
import org.jbibtex.Key;
21
import org.jbibtex.StringValue;
22
import org.jbibtex.StringValue.Style;
23

  
24
public class BibTexConverter {
25

  
26
	private static final Log log = LogFactory.getLog(BibTexConverter.class);
27

  
28
	public static String asBibTex(final String xml) {
29
		try {
30
			final Document doc = new SAXReader().read(new StringReader(xml));
31

  
32
			final BibTeXEntry dbEntry = new BibTeXEntry(
33
					findBibTexType(doc.valueOf("//*[local-name() = 'resourceType']")),
34
					new Key(doc.valueOf("//*[local-name() = 'identifier']")));
35

  
36
			addSimpleStringValue(dbEntry, BibTeXEntry.KEY_TITLE, doc, "//*[local-name() = 'title']");
37
			addMultipleStringValue(dbEntry, BibTeXEntry.KEY_AUTHOR, doc, "//*[local-name() = 'creator']");
38
			addSimpleStringValue(dbEntry, BibTeXEntry.KEY_YEAR, doc, "//*[local-name() = 'date']");
39

  
40
			final BibTeXFormatter formatter = new BibTeXFormatter();
41
			final Writer res = new StringWriter();
42
			final BibTeXDatabase db = new BibTeXDatabase();
43
			db.addObject(dbEntry);
44
			formatter.format(db, res);
45
			return res.toString();
46
		} catch (final DocumentException | IOException e) {
47
			log.warn("Error generating bibtex", e);
48
			return "";
49
		}
50
	}
51

  
52
	private static void addSimpleStringValue(final BibTeXEntry dbEntry, final Key key, final Document doc, final String xpath) {
53
		final String val = doc.valueOf(xpath).trim();
54
		if (StringUtils.isNotBlank(val)) {
55
			dbEntry.addField(key, new StringValue(val, Style.BRACED));
56
		}
57
	}
58

  
59
	@SuppressWarnings("unchecked")
60
	private static void addMultipleStringValue(final BibTeXEntry dbEntry, final Key key, final Document doc, final String xpath) {
61
		final String val = ((List<Node>) doc.selectNodes(xpath))
62
				.stream()
63
				.map(Node::getText)
64
				.map(String::trim)
65
				.filter(StringUtils::isNotEmpty)
66
				.collect(Collectors.joining(" and "));
67

  
68
		if (StringUtils.isNotBlank(val)) {
69
			dbEntry.addField(key, new StringValue(val, Style.BRACED));
70
		}
71
	}
72

  
73
	private static Key findBibTexType(final String resourceType) {
74
		switch (resourceType) {
75
		case "Conference object":
76
			return BibTeXEntry.TYPE_INPROCEEDINGS;
77
		case "Report":
78
			return BibTeXEntry.TYPE_TECHREPORT;
79
		case "Article":
80
			return BibTeXEntry.TYPE_ARTICLE;
81
		case "Other":
82
			return BibTeXEntry.TYPE_MISC;
83
		case "Part of book or chapter of book":
84
			return BibTeXEntry.TYPE_INBOOK;
85
		case "Book":
86
			return BibTeXEntry.TYPE_BOOK;
87
		case "Bachelor thesis":
88
			return BibTeXEntry.TYPE_MASTERSTHESIS;
89
		case "Doctoral thesis":
90
			return BibTeXEntry.TYPE_PHDTHESIS;
91
		case "Patent":
92
			return BibTeXEntry.TYPE_MISC;
93
		case "Master thesis":
94
			return BibTeXEntry.TYPE_MASTERSTHESIS;
95
		default:
96
			return BibTeXEntry.TYPE_MISC;
97
		}
98
	}
99
}
modules/dnet-isti/trunk/src/main/java/eu/dnetlib/data/utils/IstiConstants.java
1
package eu.dnetlib.data.utils;
2

  
3
public class IstiConstants {
4

  
5
	public static final int PIMPA_START_YEAR = 1985;
6
}
modules/dnet-isti/trunk/src/main/java/eu/dnetlib/data/db/Affiliation.java
2 2

  
3 3
public class Affiliation {
4 4

  
5
	public static final int START_YEAR = 1985;
6

  
7 5
	private String pid;
8 6
	private String gid;
9 7
	private int year;
modules/dnet-isti/trunk/src/main/java/eu/dnetlib/data/mdstore/plugins/EnrichDatasetsPlugin.java
2 2

  
3 3
import java.net.URI;
4 4
import java.net.URISyntaxException;
5
import java.util.HashMap;
5
import java.util.ArrayList;
6 6
import java.util.List;
7
import java.util.Map;
8 7

  
9 8
import org.apache.commons.lang3.StringUtils;
10
import org.apache.commons.logging.Log;
11
import org.apache.commons.logging.LogFactory;
12
import org.dom4j.Document;
13
import org.dom4j.Element;
14
import org.dom4j.Namespace;
15
import org.dom4j.QName;
16 9
import org.springframework.beans.factory.annotation.Value;
17 10

  
18 11
import com.google.gson.Gson;
19 12
import com.google.gson.reflect.TypeToken;
20 13

  
14
import eu.dnetlib.data.mdstore.plugins.objects.Dataset;
15
import eu.dnetlib.data.mdstore.plugins.objects.MdRecord;
21 16
import eu.dnetlib.data.mdstore.plugins.objects.dli.DliIdentifier;
22 17
import eu.dnetlib.data.mdstore.plugins.objects.dli.DliRelation;
23 18

  
24 19
public class EnrichDatasetsPlugin extends GenericDoiMdstorePlugin {
25 20

  
26
	private static final Log log = LogFactory.getLog(EnrichDatasetsPlugin.class);
21
	private static final Gson gson = new Gson();
27 22

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

  
36 31
	@Override
37
	protected boolean updateDocument(final Document doc, final String response) {
32
	protected void reconfigure() {}
38 33

  
39
		final Gson gson = new Gson();
34
	@Override
35
	protected boolean updateDocument(final MdRecord doc, final String response) {
36

  
37
		doc.getDatasets().clear();
38

  
39
		final List<Dataset> datasets = new ArrayList<>();
40

  
40 41
		final List<DliRelation> rels = gson.fromJson(response, new TypeToken<List<DliRelation>>() {}.getType());
41 42

  
42
		final Map<String, String> datasets = new HashMap<>();
43

  
44 43
		for (final DliRelation rel : rels) {
45 44
			final String title = rel.getTarget().getTitle();
46 45
			for (final DliIdentifier id : rel.getTarget().getIdentifiers()) {
47 46
				if (id.getSchema().equalsIgnoreCase("doi") && StringUtils.isNoneBlank(id.getIdentifier()) && StringUtils.isNotBlank(title)) {
48
					datasets.put(id.getIdentifier(), title);
47
					datasets.add(new Dataset(id.getIdentifier(), title));
49 48
				}
50 49
			}
51 50
		}
52 51

  
53
		if (datasets.isEmpty()) { return false; }
52
		if (datasets.isEmpty()) {
53
			return false;
54
		} else {
55
			doc.getDatasets().addAll(datasets);
56
			return true;
57
		}
58
	}
54 59

  
55
		final Element node = (Element) doc.selectSingleNode("//*[local-name() = 'datasets']");
56

  
57
		datasets.entrySet().forEach(e -> {
58
			final Element ds = node.addElement(new QName("dataset", new Namespace("isti", "http://www.isti.cnr.it/")));
59
			ds.addAttribute("doi", e.getKey());
60
			ds.addAttribute("url", "https://dx.doi.org/" + e.getKey());
61
			ds.setText(e.getValue());
62
			log.info("Found dataset: " + e.getKey() + " -> " + e.getValue());
63
		});
64

  
65
		return true;
66

  
67
	}
68 60
}
modules/dnet-isti/trunk/src/main/java/eu/dnetlib/data/mdstore/plugins/EnrichProjectsPlugin.java
1 1
package eu.dnetlib.data.mdstore.plugins;
2 2

  
3
import java.io.StringReader;
4 3
import java.net.URI;
5 4
import java.net.URISyntaxException;
6
import java.util.ArrayList;
7 5
import java.util.HashMap;
8 6
import java.util.List;
9 7
import java.util.Map;
8
import java.util.stream.Collectors;
10 9

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

  
20
import com.mongodb.BasicDBObject;
21
import com.mongodb.DBObject;
22
import com.mongodb.client.MongoCollection;
23

  
24
import eu.dnetlib.data.mdstore.modular.mongodb.MongoMDStore;
15
import eu.dnetlib.data.mdstore.plugins.objects.MdRecord;
25 16
import eu.dnetlib.data.mdstore.plugins.objects.Project;
26
import eu.dnetlib.rmi.data.MDStoreServiceException;
27 17

  
28
public class EnrichProjectsPlugin extends AbstractIstiMDStorePlugin {
18
public class EnrichProjectsPlugin extends MdRecordPlugin {
29 19

  
30 20
	private static final Log log = LogFactory.getLog(EnrichProjectsPlugin.class);
31 21

  
32 22
	@Value("${plugin.enrich.projects.openaire.url}")
33 23
	private String baseUrl;
34 24

  
25
	private Map<String, Project> mapProjects = new HashMap<>();
26

  
35 27
	@Override
36
	public void process(final MongoMDStore store, final Map<String, String> params) throws MDStoreServiceException {
37
		log.info("*****************************************");
38
		log.info("* ENRICH PROJECTS ...");
39
		log.info("*****************************************");
28
	protected void reconfigure() {
29
		log.info("Cleaning projects cache");
30
		mapProjects.clear();
31
	}
40 32

  
41
		final MongoCollection<DBObject> collPubs = store.getCollection();
33
	@Override
34
	protected boolean updateRecord(final MdRecord record) {
35
		log.debug("Found " + record.getProjects().size() + " projects");
42 36

  
43
		final Map<String, List<Project>> pubs = resolveProjects(collPubs);
37
		if (record.getProjects().isEmpty()) { return false; }
44 38

  
45
		// update the publications
46
		pubs.entrySet().forEach(e -> patchRecord(collPubs, e.getKey(), e.getValue()));
39
		final List<Project> list = record.getProjects()
40
				.stream()
41
				.map(Project::getInfoId)
42
				.filter(StringUtils::isNotBlank)
43
				.map(Project::newInstance)
44
				.map(this::findEnrichedProject)
45
				.collect(Collectors.toList());
47 46

  
48
		touch(store);
49
	}
47
		log.debug("Processed " + list.size() + " projects");
50 48

  
51
	private Map<String, List<Project>> resolveProjects(final MongoCollection<DBObject> collPubs) {
52
		final Map<String, List<Project>> pubs = new HashMap<>();
53
		final Map<String, Project> mapProjects = new HashMap<>();
54
		for (final DBObject obj : collPubs.find()) {
55
			final List<Project> projects = projectsFromPublication(obj, mapProjects);
56
			pubs.put(obj.get("id").toString(), projects);
57
		}
58
		return pubs;
59
	}
49
		if (list.isEmpty()) { return false; }
60 50

  
61
	private List<Project> projectsFromPublication(final DBObject obj, final Map<String, Project> mapProjects) {
62
		final List<Project> projects = new ArrayList<>();
63
		try {
64
			final Document doc = (new SAXReader()).read(new StringReader(obj.get("body").toString()));
65
			for (final Object o : doc.selectNodes("//*[local-name()='project']")) {
66
				final Element p = (Element) o;
67
				final String code = p.valueOf("./*[local-name() = 'code']").trim();
68
				final String infoId = p.valueOf("./*[local-name() = 'infoId']").trim();
51
		record.getProjects().clear();
52
		record.getProjects().addAll(list);
69 53

  
70
				if (StringUtils.isEmpty(code) && StringUtils.isNotEmpty(infoId)) {
71
					final Project simpleProject = Project.newInstance(infoId);
72
					if (simpleProject != null) {
73
						final String s = simpleProject.getFunder() + "/" + simpleProject.getProgram() + "/" + simpleProject.getCode();
74
						if (!mapProjects.containsKey(s)) {
75
							final Project project = resolveProject(s);
76
							mapProjects.put(s, project != null ? project : simpleProject);
77
						}
78
						projects.add(mapProjects.get(s));
79
					}
80
				}
81

  
82
			}
83
		} catch (final DocumentException e) {
84
			log.warn("Problem parsing a mdstore record");
85
		}
86

  
87
		return projects;
54
		return true;
88 55
	}
89 56

  
90
	private void patchRecord(final MongoCollection<DBObject> collPubs, final String id, final List<Project> projects) {
91
		log.debug("Adding to " + id + " " + projects.size() + " project(s)");
92

  
93
		try {
94
			final SAXReader reader = new SAXReader();
95
			final DBObject obj = collPubs.find(new BasicDBObject("id", id)).first();
96

  
97
			final Document doc = reader.read(new StringReader(obj.get("body").toString()));
98

  
99
			for (final Object o : doc.selectNodes("//*[local-name()='project']")) {
100
				final Element n = (Element) o;
101
				final String infoId = n.valueOf("./*[local-name()='infoId']");
102

  
103
				projects.stream()
104
						.filter(p -> (p != null) && p.match(infoId))
105
						.forEach(p -> {
106
							n.selectSingleNode("./*[local-name()='code']").setText(p.getCode());
107
							n.selectSingleNode("./*[local-name()='name']").setText(p.getName());
108
							n.selectSingleNode("./*[local-name()='acronym']").setText(p.getAcronym());
109
							n.selectSingleNode("./*[local-name()='funder']").setText(p.getFunder());
110
							n.selectSingleNode("./*[local-name()='program']").setText(p.getProgram());
111
							n.selectSingleNode("./*[local-name()='jurisdiction']").setText(p.getJurisdiction());
112
							n.selectSingleNode("./*[local-name()='openaireId']").setText(p.getOpenaireId());
113
						});
114
			}
115

  
116
			collPubs.updateOne(new BasicDBObject("id", id), new BasicDBObject("$set", new BasicDBObject("body", doc.asXML())));
117
		} catch (final DocumentException e) {
118
			log.warn("Error patching record: " + id);
57
	private Project findEnrichedProject(final Project simpleProject) {
58
		final String s = simpleProject.getFunder() + "/" + simpleProject.getProgram() + "/" + simpleProject.getCode();
59
		if (!mapProjects.containsKey(s)) {
60
			final Project project = resolveProject(s);
61
			mapProjects.put(s, project != null ? project : simpleProject);
119 62
		}
63
		return mapProjects.get(s);
120 64
	}
121 65

  
122 66
	private Project resolveProject(final String s) {
......
129 73
			throw new RuntimeException("Error resolving project: " + s, e);
130 74
		}
131 75
	}
76

  
132 77
}
modules/dnet-isti/trunk/src/main/java/eu/dnetlib/data/mdstore/plugins/GenericDoiMdstorePlugin.java
1 1
package eu.dnetlib.data.mdstore.plugins;
2 2

  
3
import java.io.StringReader;
4 3
import java.net.URI;
5 4
import java.net.URISyntaxException;
6 5
import java.security.KeyManagementException;
7 6
import java.security.KeyStoreException;
8 7
import java.security.NoSuchAlgorithmException;
9
import java.util.Map;
10 8
import java.util.concurrent.TimeUnit;
11 9

  
12 10
import org.apache.commons.logging.Log;
......
14 12
import org.apache.http.conn.ssl.SSLConnectionSocketFactory;
15 13
import org.apache.http.impl.client.HttpClientBuilder;
16 14
import org.apache.http.ssl.SSLContextBuilder;
17
import org.dom4j.Document;
18
import org.dom4j.DocumentException;
19
import org.dom4j.Node;
20
import org.dom4j.io.SAXReader;
21 15
import org.springframework.http.client.HttpComponentsClientHttpRequestFactory;
22 16
import org.springframework.web.client.RestTemplate;
23 17

  
24
import com.mongodb.BasicDBObject;
25
import com.mongodb.DBObject;
26
import com.mongodb.client.MongoCollection;
18
import eu.dnetlib.data.mdstore.plugins.objects.MdRecord;
27 19

  
28
import eu.dnetlib.data.mdstore.modular.mongodb.MongoMDStore;
29
import eu.dnetlib.rmi.data.MDStoreServiceException;
20
public abstract class GenericDoiMdstorePlugin extends MdRecordPlugin {
30 21

  
31
public abstract class GenericDoiMdstorePlugin extends AbstractIstiMDStorePlugin {
32

  
33 22
	private static final Log log = LogFactory.getLog(GenericDoiMdstorePlugin.class);
34 23

  
35 24
	private static final int MAX_NUMBER_OF_ATTEMPTS = 10;
......
57 46
			.build());
58 47

  
59 48
	@Override
60
	public void process(final MongoMDStore store, final Map<String, String> params) throws MDStoreServiceException {
61

  
62
		final MongoCollection<DBObject> collPubs = store.getCollection();
63

  
64
		int count = 0;
65

  
66
		for (final DBObject obj : collPubs.find()) {
67

  
68
			try {
69
				final String recordId = obj.get("id").toString();
70
				final Document doc = (new SAXReader()).read(new StringReader(obj.get("body").toString()));
71
				for (final Object o : doc.selectNodes("//*[local-name()='alternateIdentifier' and @alternateIdentifierType='doi']")) {
72
					final String doi = ((Node) o).getText().trim();
73

  
74
					log.debug("  Record " + recordId + " has doi " + doi);
75
					final String response = download(doi);
76
					if ((response != null) && updateDocument(doc, response)) {
77
						collPubs.updateOne(new BasicDBObject("id", recordId), new BasicDBObject("$set", new BasicDBObject("body", doc.asXML())));
78
						count++;
79
					}
80
				}
81
			} catch (final DocumentException e) {
82
				log.warn("Problem parsing a mdstore record");
83
			}
49
	protected final boolean updateRecord(final MdRecord record) {
50
		for (final String doi : record.getDois()) {
51
			log.debug("  Record " + record.getId() + " has doi " + doi);
52
			final String response = download(doi);
53
			if ((response != null) && updateDocument(record, response)) { return true; }
84 54
		}
85

  
86
		log.info("Number of patched records: " + count);
87

  
88
		touch(store);
55
		return false;
89 56
	}
90 57

  
91
	abstract protected boolean updateDocument(Document doc, String response);
58
	abstract protected boolean updateDocument(MdRecord doc, String response);
92 59

  
93 60
	abstract protected URI prepareURI(String doi) throws URISyntaxException;
94 61

  
......
116 83
			}
117 84
		}
118 85
	}
86

  
119 87
}
modules/dnet-isti/trunk/src/main/java/eu/dnetlib/data/mdstore/plugins/EnrichLabsPlugin.java
1 1
package eu.dnetlib.data.mdstore.plugins;
2 2

  
3
import java.io.StringReader;
3
import java.util.HashMap;
4 4
import java.util.Map;
5 5
import java.util.Set;
6 6
import java.util.regex.Matcher;
7 7
import java.util.regex.Pattern;
8 8
import java.util.stream.Collectors;
9 9

  
10
import org.apache.commons.lang3.math.NumberUtils;
11 10
import org.apache.commons.logging.Log;
12 11
import org.apache.commons.logging.LogFactory;
13
import org.dom4j.Document;
14
import org.dom4j.DocumentException;
15
import org.dom4j.Element;
16
import org.dom4j.Node;
17
import org.dom4j.QName;
18
import org.dom4j.io.SAXReader;
19 12
import org.springframework.beans.factory.annotation.Autowired;
20 13

  
21 14
import com.google.common.collect.Sets;
22
import com.mongodb.BasicDBObject;
23
import com.mongodb.DBObject;
24
import com.mongodb.client.MongoCollection;
25 15

  
26
import eu.dnetlib.data.db.Affiliation;
27 16
import eu.dnetlib.data.db.AffiliationsDao;
28 17
import eu.dnetlib.data.db.Group;
29 18
import eu.dnetlib.data.db.Person;
30
import eu.dnetlib.data.mdstore.modular.mongodb.MongoMDStore;
31
import eu.dnetlib.rmi.data.MDStoreServiceException;
32
import eu.dnetlib.xml.ISTIUtilityFunction;
19
import eu.dnetlib.data.mdstore.plugins.objects.Affiliation;
20
import eu.dnetlib.data.mdstore.plugins.objects.CnrPerson;
21
import eu.dnetlib.data.mdstore.plugins.objects.MdRecord;
22
import eu.dnetlib.data.utils.IstiConstants;
23
import eu.dnetlib.data.utils.XsltFunctions;
33 24

  
34
public class EnrichLabsPlugin extends AbstractIstiMDStorePlugin {
25
public class EnrichLabsPlugin extends MdRecordPlugin {
35 26

  
36 27
	private static final Log log = LogFactory.getLog(EnrichLabsPlugin.class);
37 28

  
......
40 31
	@Autowired
41 32
	private AffiliationsDao dao;
42 33

  
34
	private Map<String, Person> affiliations = new HashMap<>();
35

  
43 36
	@Override
44
	public void process(final MongoMDStore store, final Map<String, String> params) throws MDStoreServiceException {
45
		log.warn("********************************************");
46
		log.warn("* ENRICH LABS");
47
		log.warn("********************************************");
48

  
49
		// CODE -> year -> Lab
50
		final Map<String, Person> affiliations = dao.listPersonsWithAffiliations()
37
	protected void reconfigure() {
38
		affiliations = dao.listPersonsWithAffiliations()
51 39
				.stream()
52 40
				.collect(Collectors.toMap(Person::getId, a -> a));
41
	}
53 42

  
54
		final MongoCollection<DBObject> pubsCollection = store.getCollection();
43
	@Override
44
	protected boolean updateRecord(final MdRecord doc) {
45
		final int year = doc.getDate();
55 46

  
56
		for (final DBObject obj : pubsCollection.find()) {
57
			final String id = obj.get("id").toString();
58
			log.debug("**********************************************");
59
			log.debug("Record " + id);
47
		for (final CnrPerson cp : doc.getCnrPersons()) {
48
			cp.getAffiliations().clear();
60 49

  
61
			try {
62
				final Document doc = (new SAXReader()).read(new StringReader(obj.get("body").toString()));
50
			if (year >= IstiConstants.PIMPA_START_YEAR) {
51
				final String infoId = cp.getId();
52
				final Pattern pattern = Pattern.compile("info:cnr-pdr\\/author\\/(.+)\\/(.+)\\/(.+)");
53
				final Matcher matcher = pattern.matcher(infoId);
54
				if (matcher.find()) {
55
					final String code = matcher.group(1);
56
					final String fullname = XsltFunctions.capitalize(String.format("%s %s", matcher.group(3), matcher.group(2)));
63 57

  
64
				final int year = NumberUtils.toInt(doc.valueOf("//*[local-name()='date' and @dateType='Accepted']"), 0);
58
					final Person p = affiliations.get(code);
65 59

  
66
				if (year >= Affiliation.START_YEAR) {
67
					resetAffiliations(doc);
68

  
69
					for (final Object o : doc.selectNodes("//*[local-name()='person']")) {
70
						final Element node = (Element) o;
71
						final String infoId = node.valueOf("./*[local-name()='infoId']");
72
						final Pattern pattern = Pattern.compile("info:cnr-pdr\\/author\\/(.+)\\/(.+)\\/(.+)");
73
						final Matcher matcher = pattern.matcher(infoId);
74
						if (matcher.find()) {
75
							final String code = matcher.group(1);
76
							final String fullname = ISTIUtilityFunction.capitalize(String.format("%s %s", matcher.group(3), matcher.group(2)));
77

  
78
							final Person p = affiliations.get(code);
79

  
80
							if (p != null) {
81
								final Set<Group> groups = p.getAffiliations().get(year);
82
								if (groups != null) {
83
									node.selectSingleNode("./*[local-name() = 'personName']").setText(p.getName());
84
									for (final Group g : groups) {
85
										if (!g.getId().equals(UNKNOWN_GROUP.getId())) {
86
											final Element affNode = node.addElement(new QName("affiliation", node.getNamespace()));
87
											affNode.addAttribute("code", code);
88
											affNode.addAttribute("groupAcronym", g.getId());
89
											affNode.addAttribute("group", g.getName());
90
											affNode.addAttribute("type", g.getType());
91
										}
92
									}
93
								} else {
94
									log.info("Affiliation not found, infoId: " + infoId + ", year: " + year);
95
									dao.registerAffiliation(code, UNKNOWN_GROUP.getId(), year);
96
									p.getAffiliations().put(year, Sets.newHashSet(UNKNOWN_GROUP));
60
					if (p != null) {
61
						final Set<Group> groups = p.getAffiliations().get(year);
62
						if (groups != null) {
63
							cp.setName(p.getName());
64
							for (final Group g : groups) {
65
								if (!g.getId().equals(UNKNOWN_GROUP.getId())) {
66
									cp.getAffiliations().add(new Affiliation(code, g.getType(), g.getId(), g.getName()));
97 67
								}
98
							} else {
99
								log.info("Person not found, infoId: " + infoId + ", year: " + year);
100
								dao.registerPerson(code, fullname);
101
								dao.registerAffiliation(code, UNKNOWN_GROUP.getId(), year);
102

  
103
								final Person np = new Person(code, fullname);
104
								np.getAffiliations().put(year, Sets.newHashSet(UNKNOWN_GROUP));
105

  
106
								affiliations.put(code, np);
107 68
							}
108 69
						} else {
109
							log.warn("Invalid infoId: " + infoId);
70
							log.info("Affiliation not found, infoId: " + infoId + ", year: " + year);
71
							dao.registerAffiliation(code, UNKNOWN_GROUP.getId(), year);
72
							p.getAffiliations().put(year, Sets.newHashSet(UNKNOWN_GROUP));
110 73
						}
74
					} else {
75
						log.info("Person not found, infoId: " + infoId + ", year: " + year);
76
						dao.registerPerson(code, fullname);
77
						dao.registerAffiliation(code, UNKNOWN_GROUP.getId(), year);
78

  
79
						final Person np = new Person(code, fullname);
80
						np.getAffiliations().put(year, Sets.newHashSet(UNKNOWN_GROUP));
81

  
82
						affiliations.put(code, np);
111 83
					}
112

  
113
					pubsCollection.updateOne(new BasicDBObject("id", id), new BasicDBObject("$set", new BasicDBObject("body", doc.asXML())));
84
				} else {
85
					log.warn("Invalid infoId: " + infoId);
114 86
				}
115
			} catch (final DocumentException e) {
116
				log.warn("Problem parsing a mdstore record");
117 87
			}
118
		}
119
	}
120 88

  
121
	private void resetAffiliations(final Document doc) {
122
		for (final Object n : doc.selectNodes("//*[local-name() = 'person']/*[local-name() = 'affiliation']")) {
123
			((Node) n).detach();
124 89
		}
90
		return true;
125 91
	}
126 92

  
127 93
}
modules/dnet-isti/trunk/src/main/java/eu/dnetlib/data/mdstore/plugins/objects/MdRecord.java
1
package eu.dnetlib.data.mdstore.plugins.objects;
2

  
3
import java.util.LinkedHashSet;
4
import java.util.Set;
5
import java.util.TreeSet;
6

  
7
import javax.xml.bind.annotation.XmlAccessType;
8
import javax.xml.bind.annotation.XmlAccessorType;
9
import javax.xml.bind.annotation.XmlElement;
10
import javax.xml.bind.annotation.XmlElementWrapper;
11
import javax.xml.bind.annotation.XmlRootElement;
12

  
13
@XmlRootElement(name = "record")
14
@XmlAccessorType(XmlAccessType.FIELD)
15
public class MdRecord {
16

  
17
	@XmlElement(name = "identifier")
18
	private String id;
19

  
20
	@XmlElement(name = "title")
21
	private String title;
22

  
23
	@XmlElementWrapper(name = "creators")
24
	@XmlElement(name = "creator")
25
	private Set<String> creators = new LinkedHashSet<>();
26

  
27
	@XmlElement(name = "publisher")
28
	private String publisher;
29

  
30
	@XmlElementWrapper(name = "subjects")
31
	@XmlElement(name = "subject")
32
	private Set<String> subjects = new LinkedHashSet<>();
33

  
34
	@XmlElementWrapper(name = "contributors")
35
	@XmlElement(name = "contributor")
36
	private Set<String> contributors = new LinkedHashSet<>();
37

  
38
	@XmlElement(name = "date")
39
	private int date;
40

  
41
	@XmlElement(name = "language")
42
	private String language;
43

  
44
	@XmlElement(name = "type")
45
	private String type;
46

  
47
	@XmlElementWrapper(name = "urls")
48
	@XmlElement(name = "url")
49
	private Set<MyURL> urls = new TreeSet<>((u1, u2) -> {
50
		final String r1 = u1.getRights();
51
		final String r2 = u2.getRights();
52
		final int n1 = r1.equalsIgnoreCase("Open Access") ? 0 : r1.equalsIgnoreCase("Unknown") ? 2 : 1;
53
		final int n2 = r2.equalsIgnoreCase("Open Access") ? 0 : r2.equalsIgnoreCase("Unknown") ? 2 : 1;
54
		return Integer.compare(n1, n2);
55
	});
56

  
57
	@XmlElementWrapper(name = "dois")
58
	@XmlElement(name = "doi")
59
	private Set<String> dois = new LinkedHashSet<>();
60

  
61
	@XmlElement(name = "bestRights")
62
	private String bestRights;
63

  
64
	@XmlElement(name = "abstract")
65
	private String descriptionAbstract;
66

  
67
	@XmlElement(name = "source")
68
	private String source;
69

  
70
	@XmlElementWrapper(name = "projects")
71
	@XmlElement(name = "project")
72
	private Set<Project> projects = new TreeSet<>((p1, p2) -> p1.getName().compareTo(p2.getName()));
73

  
74
	@XmlElementWrapper(name = "cnrPersons")
75
	@XmlElement(name = "cnrPerson")
76
	private Set<CnrPerson> cnrPersons = new TreeSet<>((p1, p2) -> p1.getName().compareTo(p2.getName()));
77

  
78
	@XmlElementWrapper(name = "datasets")
79
	@XmlElement(name = "dataset")
80
	private Set<Dataset> datasets = new TreeSet<>((d1, d2) -> d1.getTitle().compareTo(d2.getTitle()));
81

  
82
	@XmlElementWrapper(name = "citations")
83
	@XmlElement(name = "citation")
84
	private Set<String> citations = new LinkedHashSet<>();
85

  
86
	public String getId() {
87
		return id;
88
	}
89

  
90
	public void setId(final String id) {
91
		this.id = id;
92
	}
93

  
94
	public String getTitle() {
95
		return title;
96
	}
97

  
98
	public void setTitle(final String title) {
99
		this.title = title;
100
	}
101

  
102
	public Set<String> getCreators() {
103
		return creators;
104
	}
105

  
106
	public void setCreators(final Set<String> creators) {
107
		this.creators = creators;
108
	}
109

  
110
	public String getPublisher() {
111
		return publisher;
112
	}
113

  
114
	public void setPublisher(final String publisher) {
115
		this.publisher = publisher;
116
	}
117

  
118
	public Set<String> getSubjects() {
119
		return subjects;
120
	}
121

  
122
	public void setSubjects(final Set<String> subjects) {
123
		this.subjects = subjects;
124
	}
125

  
126
	public Set<String> getContributors() {
127
		return contributors;
128
	}
129

  
130
	public void setContributors(final Set<String> contributors) {
131
		this.contributors = contributors;
132
	}
133

  
134
	public int getDate() {
135
		return date;
136
	}
137

  
138
	public void setDate(final int date) {
139
		this.date = date;
140
	}
141

  
142
	public String getLanguage() {
143
		return language;
144
	}
145

  
146
	public void setLanguage(final String language) {
147
		this.language = language;
148
	}
149

  
150
	public String getType() {
151
		return type;
152
	}
153

  
154
	public void setType(final String type) {
155
		this.type = type;
156
	}
157

  
158
	public Set<MyURL> getUrls() {
159
		return urls;
160
	}
161

  
162
	public void setUrls(final Set<MyURL> urls) {
163
		this.urls = urls;
164
	}
165

  
166
	public Set<String> getDois() {
167
		return dois;
168
	}
169

  
170
	public void setDois(final Set<String> dois) {
171
		this.dois = dois;
172
	}
173

  
174
	public String getBestRights() {
175
		return bestRights;
176
	}
177

  
178
	public void setBestRights(final String bestRights) {
179
		this.bestRights = bestRights;
180
	}
181

  
182
	public String getDescriptionAbstract() {
183
		return descriptionAbstract;
184
	}
185

  
186
	public void setDescriptionAbstract(final String descriptionAbstract) {
187
		this.descriptionAbstract = descriptionAbstract;
188
	}
189

  
190
	public String getSource() {
191
		return source;
192
	}
193

  
194
	public void setSource(final String source) {
195
		this.source = source;
196
	}
197

  
198
	public Set<Project> getProjects() {
199
		return projects;
200
	}
201

  
202
	public void setProjects(final Set<Project> projects) {
203
		this.projects = projects;
204
	}
205

  
206
	public Set<CnrPerson> getCnrPersons() {
207
		return cnrPersons;
208
	}
209

  
210
	public void setCnrPerson(final Set<CnrPerson> cnrPersons) {
211
		this.cnrPersons = cnrPersons;
212
	}
213

  
214
	public Set<Dataset> getDatasets() {
215
		return datasets;
216
	}
217

  
218
	public void setDatasets(final Set<Dataset> datasets) {
219
		this.datasets = datasets;
220
	}
221

  
222
	public Set<String> getCitations() {
223
		return citations;
224
	}
225

  
226
	public void setCitations(final Set<String> citations) {
227
		this.citations = citations;
228
	}
229

  
230
}
modules/dnet-isti/trunk/src/main/java/eu/dnetlib/data/mdstore/plugins/objects/MdRecordConvertUtils.java
1
package eu.dnetlib.data.mdstore.plugins.objects;
2

  
3
import java.io.StringReader;
4
import java.io.StringWriter;
5

  
6
import javax.xml.bind.JAXBContext;
7
import javax.xml.bind.JAXBException;
8
import javax.xml.bind.Marshaller;
9
import javax.xml.bind.Unmarshaller;
10

  
11
public class MdRecordConvertUtils {
12

  
13
	private static JAXBContext jaxbContext;
14
	private static Marshaller marshaller;
15
	private static Unmarshaller unmarshaller;
16

  
17
	public static MdRecord fromString(final String s) throws JAXBException {
18
		verifyInit();
19
		return (MdRecord) unmarshaller.unmarshal(new StringReader(s));
20

  
21
	}
22

  
23
	public static String toString(final MdRecord obj) throws JAXBException {
24
		final StringWriter sw = new StringWriter();
25
		marshaller.marshal(obj, sw);
26
		return sw.toString();
27
	}
28

  
29
	private static void verifyInit() throws JAXBException {
30
		if (jaxbContext == null) {
31
			jaxbContext = JAXBContext.newInstance(MdRecord.class);
32

  
33
			marshaller = jaxbContext.createMarshaller();
34
			unmarshaller = jaxbContext.createUnmarshaller();
35

  
36
			marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
37
		}
38
	}
39
}
modules/dnet-isti/trunk/src/main/java/eu/dnetlib/data/mdstore/plugins/objects/Dataset.java
1
package eu.dnetlib.data.mdstore.plugins.objects;
2

  
3
import javax.xml.bind.annotation.XmlAccessType;
4
import javax.xml.bind.annotation.XmlAccessorType;
5
import javax.xml.bind.annotation.XmlAttribute;
6
import javax.xml.bind.annotation.XmlValue;
7

  
8
@XmlAccessorType(XmlAccessType.FIELD)
9
public class Dataset {
10

  
11
	@XmlAttribute(name = "doi")
12
	private String doi;
13

  
14
	@XmlAttribute(name = "url")
15
	private String url;
16

  
17
	@XmlValue
18
	private String title;
19

  
20
	public Dataset() {}
21

  
22
	public Dataset(final String doi, final String title) {
23
		this.doi = doi;
24
		this.title = title;
25
		setUrl("https://dx.doi.org/" + doi);
26
	}
27

  
28
	public Dataset(final String doi, final String url, final String title) {
29
		this.doi = doi;
30
		this.url = url;
31
		this.title = title;
32
	}
33

  
34
	public String getDoi() {
35
		return doi;
36
	}
37

  
38
	public void setDoi(final String doi) {
39
		this.doi = doi;
40
	}
41

  
42
	public String getUrl() {
43
		return url;
44
	}
45

  
46
	public void setUrl(final String url) {
47
		this.url = url;
48
	}
49

  
50
	public String getTitle() {
51
		return title;
52
	}
53

  
54
	public void setTitle(final String title) {
55
		this.title = title;
56
	}
57

  
58
	@Override
59
	public int hashCode() {
60
		return doi.toLowerCase().hashCode();
61
	}
62

  
63
	@Override
64
	public boolean equals(final Object obj) {
65
		if (this == obj) { return true; }
66
		if (obj == null) { return false; }
67
		return (obj instanceof Dataset) && doi.equalsIgnoreCase(((Dataset) obj).getDoi());
68
	}
69

  
70
}
modules/dnet-isti/trunk/src/main/java/eu/dnetlib/data/mdstore/plugins/objects/Affiliation.java
1
package eu.dnetlib.data.mdstore.plugins.objects;
2

  
3
import javax.xml.bind.annotation.XmlAccessType;
4
import javax.xml.bind.annotation.XmlAccessorType;
5
import javax.xml.bind.annotation.XmlAttribute;
6

  
7
@XmlAccessorType(XmlAccessType.FIELD)
8
public class Affiliation {
9

  
10
	@XmlAttribute(name = "code")
11
	private String code;
12

  
13
	@XmlAttribute(name = "type")
14
	private String type;
15

  
16
	@XmlAttribute(name = "groupAcronym")
17
	private String groupAcronym;
18

  
19
	@XmlAttribute(name = "group")
20
	private String group;
21

  
22
	public Affiliation() {}
23

  
24
	public Affiliation(final String code, final String type, final String groupAcronym, final String group) {
25
		super();
26
		this.code = code;
27
		this.type = type;
28
		this.groupAcronym = groupAcronym;
29
		this.group = group;
30
	}
31

  
32
	public String getGroupAcronym() {
33
		return groupAcronym;
34
	}
35

  
36
	public void setGroupAcronym(final String groupAcronym) {
37
		this.groupAcronym = groupAcronym;
38
	}
39

  
40
	public String getGroup() {
41
		return group;
42
	}
43

  
44
	public void setGroup(final String group) {
45
		this.group = group;
46
	}
47

  
48
	public String getType() {
49
		return type;
50
	}
51

  
52
	public void setType(final String type) {
53
		this.type = type;
54
	}
55

  
56
	public String getCode() {
57
		return code;
58
	}
59

  
60
	public void setCode(final String code) {
61
		this.code = code;
62
	}
63

  
64
	@Override
65
	public int hashCode() {
66
		return groupAcronym == null ? 0 : groupAcronym.hashCode();
67

  
68
	}
69

  
70
	@Override
71
	public boolean equals(final Object obj) {
72
		if (this == obj) { return true; }
73
		if (obj == null) { return false; }
74
		if (getClass() != obj.getClass()) { return false; }
75
		final Affiliation other = (Affiliation) obj;
76
		if (groupAcronym == null) {
77
			if (other.groupAcronym != null) { return false; }
78
		} else if (!groupAcronym.equals(other.groupAcronym)) { return false; }
79
		return true;
80
	}
81

  
82
}
modules/dnet-isti/trunk/src/main/java/eu/dnetlib/data/mdstore/plugins/objects/Project.java
6 6
import java.util.regex.Matcher;
7 7
import java.util.regex.Pattern;
8 8

  
9
import javax.xml.bind.annotation.XmlAccessType;
10
import javax.xml.bind.annotation.XmlAccessorType;
11
import javax.xml.bind.annotation.XmlElement;
12

  
9 13
import org.apache.commons.lang3.StringUtils;
10 14
import org.apache.commons.logging.Log;
11 15
import org.apache.commons.logging.LogFactory;
......
16 20
import org.springframework.http.client.HttpComponentsClientHttpRequestFactory;
17 21
import org.springframework.web.client.RestTemplate;
18 22

  
23
@XmlAccessorType(XmlAccessType.FIELD)
19 24
public class Project {
20 25

  
26
	@XmlElement(name = "infoId")
27
	private String infoId;
28
	@XmlElement(name = "openaireId")
21 29
	private String openaireId;
30
	@XmlElement(name = "code")
22 31
	private String code;
32
	@XmlElement(name = "name")
23 33
	private String name;
34
	@XmlElement(name = "acronym")
24 35
	private String acronym;
36
	@XmlElement(name = "funder")
25 37
	private String funder;
38
	@XmlElement(name = "program")
26 39
	private String program;
40
	@XmlElement(name = "jurisdiction")
... This diff was truncated because it exceeds the maximum size that can be displayed.

Also available in: Unified diff