Project

General

Profile

« Previous | Next » 

Revision 53793

branch for solr 7.5.0

View differences:

modules/dnet-directindex-api/branches/solr75/deploy.info
1
{"type_source": "SVN", "goal": "package -U source:jar", "url": "http://svn-public.driver.research-infrastructures.eu/driver/dnet45/modules/dnet-directindex-api/trunk/", "deploy_repository": "dnet45-snapshots", "version": "4", "mail": "sandro.labruzzo@isti.cnr.it,michele.artini@isti.cnr.it, claudio.atzori@isti.cnr.it, alessia.bardi@isti.cnr.it", "deploy_repository_url": "http://maven.research-infrastructures.eu/nexus/content/repositories/dnet45-snapshots", "name": "dnet-directindex-api"}
modules/dnet-directindex-api/branches/solr75/src/test/java/eu/dnetlib/msro/openaireplus/api/OpenAIRESubmitterUtilsTest.java
1
package eu.dnetlib.msro.openaireplus.api;
2

  
3
import java.util.Map;
4
import java.util.Map.Entry;
5

  
6
import org.junit.Test;
7

  
8
import eu.dnetlib.openaire.directindex.api.OpenAIRESubmitterUtils;
9

  
10
/**
11
 * Created by Alessia Bardi on 26/05/2017.
12
 *
13
 * @author Alessia Bardi
14
 */
15
public class OpenAIRESubmitterUtilsTest {
16

  
17
	private OpenAIRESubmitterUtils utils = new OpenAIRESubmitterUtils();
18

  
19
	final String fullProject = "info:eu-repo/grantAgreement/EC/FP7/244909/EU/Making Capabilities Work/WorkAble";
20
	final String minimalProject = "info:eu-repo/grantAgreement/EC/FP7/244909///WorkAble";
21
	final String onlyId = "info:eu-repo/grantAgreement/EC/FP7/244909/";
22
	final String onlyTitle = "info:eu-repo/grantAgreement/EC/FP7/244909/EU/Making Capabilities Work";
23

  
24
	@Test
25
	public void testCalculateProjectInfoFull() {
26
		final Map<String, String> project = utils.calculateProjectInfo(fullProject);
27
		print(project);
28
	}
29

  
30
	@Test
31
	public void testCalculateProjectInfoOnlyId() {
32
		final Map<String, String> project = utils.calculateProjectInfo(onlyId);
33
		print(project);
34
	}
35

  
36
	@Test
37
	public void testCalculateProjectInfoMinimalAcro() {
38
		final Map<String, String> project = utils.calculateProjectInfo(minimalProject);
39
		print(project);
40
	}
41

  
42
	@Test
43
	public void testCalculateProjectInfoOnlyTitle() {
44
		final Map<String, String> project = utils.calculateProjectInfo(onlyTitle);
45
		print(project);
46
	}
47

  
48
	private void print(final Map<String, String> map) {
49
		for (final Entry e : map.entrySet()) {
50
			System.out.println(e.getKey() + " = " + e.getValue());
51
		}
52
	}
53
}
modules/dnet-directindex-api/branches/solr75/src/test/java/eu/dnetlib/msro/openaireplus/api/objects/ResultEntryTest.java
1
package eu.dnetlib.msro.openaireplus.api.objects;
2

  
3
import java.io.InputStreamReader;
4
import java.io.StringReader;
5
import java.util.ArrayList;
6
import java.util.Arrays;
7
import java.util.Properties;
8

  
9
import com.google.gson.Gson;
10
import eu.dnetlib.enabling.is.lookup.rmi.ISLookUpService;
11
import eu.dnetlib.openaire.directindex.api.DirecIndexApiException;
12
import eu.dnetlib.openaire.directindex.objects.PidEntry;
13
import eu.dnetlib.openaire.directindex.objects.ResultEntry;
14
import org.apache.commons.lang3.StringEscapeUtils;
15
import org.apache.velocity.app.VelocityEngine;
16
import org.dom4j.Document;
17
import org.dom4j.io.OutputFormat;
18
import org.dom4j.io.SAXReader;
19
import org.dom4j.io.XMLWriter;
20
import org.junit.Before;
21
import org.junit.Test;
22
import org.junit.runner.RunWith;
23
import org.mockito.Mock;
24
import org.mockito.runners.MockitoJUnitRunner;
25

  
26
import static org.mockito.Matchers.anyString;
27
import static org.mockito.Mockito.when;
28

  
29
/**
30
 * Created by michele on 14/12/15.
31
 */
32
@RunWith(MockitoJUnitRunner.class)
33
public class ResultEntryTest {
34

  
35
	private VelocityEngine ve;
36

  
37
	@Mock
38
	private ISLookUpService lookUpService;
39

  
40
	@Before
41
	public void setUp() throws Exception {
42

  
43
		final Properties props = new Properties();
44
		props.setProperty("resource.loader", "class");
45
		props.setProperty("class.resource.loader.class", "org.apache.velocity.runtime.resource.loader.ClasspathResourceLoader");
46
		props.setProperty("runtime.log.logsystem.class", "org.apache.velocity.runtime.log.Log4JLogChute");
47
		ve = new VelocityEngine();
48
		ve.init(props);
49

  
50
		when(lookUpService.quickSearchProfile(anyString())).thenAnswer(invocation -> {
51
			final String query = invocation.getArguments()[0].toString();
52
			if (query.contains("dnet:result_typologies")) {
53
				return Arrays.asList("publication @@@ publication", "dataset @@@ dataset", "software @@@ software", "other @@@ other");
54
			} else if (query.contains("dnet:access_modes")) {
55
				return Arrays.asList("OPEN @@@ Open Access");
56
			} else if (query.contains("dnet:publication_resource")) {
57
				return Arrays.asList("0001 @@@ Journal Article");
58
			} else if (query.contains("dnet:pid_types")) {
59
				return Arrays.asList("oai @@@ Open Archive Initiative", "doi @@@ Digital object identifier");
60
			} else if (query.contains("dnet:languages")) {
61
				return Arrays.asList("ita @@@ Italian");
62
			} else if (query.contains("ContextDSResourceType")) {
63
				return Arrays.asList(
64
						"egi::classification::natsc::math::stats @@@ Statistics and Probability",
65
						"egi::classification::natsc::math::pure @@@ Pure Mathematics",
66
						"egi::classification::natsc::math @@@ Mathematics",
67
						"egi::classification::natsc @@@ Natural Sciences",
68
						"egi::classification @@@ EGI classification scheme",
69
						"egi @@@ EGI");
70
			} else {
71
				return new ArrayList<String>();
72
			}
73
		});
74

  
75
		when(lookUpService.getResourceProfileByQuery(anyString())).thenAnswer(invocation -> "REPO NAME @@@ repo________");
76
	}
77

  
78
	@Test
79
	public void testAsIndexRecord() throws Exception {
80
		final ResultEntry pub = new ResultEntry();
81
		pub.setOriginalId("ORIG_ID_1234");
82
		pub.setTitle("TEST TITLE <test>");
83
		pub.getAuthors().add("Michele Artini");
84
		pub.getAuthors().add("Claudio Atzori");
85
		pub.getAuthors().add("Alessia Bardi");
86
		pub.setPublisher("Test publisher");
87
		pub.setDescription("DESCRIPTION & DESCRIPTION & DESCRIPTION & DESCRIPTION & DESCRIPTION & DESCRIPTION & DESCRIPTION ");
88
		pub.setLanguage("ita");
89
		pub.setLicenseCode("OPEN");
90
		pub.setResourceType("0001");
91
		pub.setUrl("http://test.it/a=1&b=2");
92
		pub.getPids().add(new PidEntry("doi", "10.000/xyz-123"));
93
		pub.getPids().add(new PidEntry("oai", "oai:1234"));
94
		pub.setCollectedFromId("test________::zenodo");
95
		pub.setHostedById("test________::UNKNOWN");
96
		pub.getLinksToProjects().add("info:eu-repo/grantAgreement/EC/FP7/283595/EU//OpenAIREplus");
97
		pub.getLinksToProjects().add("info:eu-repo/grantAgreement/EC/FP7/244909/EU/Making Capabilities Work/WorkAble");
98
		pub.getContexts().add("egi::classification::natsc::math::pure");
99
		pub.getContexts().add("egi::classification::natsc::math::stats");
100
		final String xml = pub.asOafRecord(ve, lookUpService, "http://oaf/oaf.xsd");
101

  
102
		final Document doc = new SAXReader().read(new StringReader(xml));
103

  
104
		final OutputFormat format = OutputFormat.createPrettyPrint();
105

  
106
		final XMLWriter writer = new XMLWriter(System.out, format);
107

  
108
		writer.write(doc);
109

  
110
		/* writer.close(); */
111

  
112
	}
113

  
114
	@Test
115
	public void testAsIndexRecordAccessRight() throws Exception {
116
		final ResultEntry pub = new ResultEntry();
117
		pub.setOriginalId("ORIG_ID_1234");
118
		pub.setTitle("TEST TITLE <test>");
119
		pub.getAuthors().add("Michele Artini");
120
		pub.getAuthors().add("Claudio Atzori");
121
		pub.getAuthors().add("Alessia Bardi");
122
		pub.setPublisher("Test publisher");
123
		pub.setDescription("DESCRIPTION & DESCRIPTION & DESCRIPTION & DESCRIPTION & DESCRIPTION & DESCRIPTION & DESCRIPTION ");
124
		pub.setLanguage("ita");
125
		pub.setLicenseCode("CLOSED");
126
		pub.setAccessRightCode("OPEN");
127
		pub.setResourceType("0001");
128
		pub.setUrl("http://test.it/a=1&b=2");
129
		pub.getPids().add(new PidEntry("doi", "10.000/xyz-123"));
130
		pub.getPids().add(new PidEntry("oai", "oai:1234"));
131
		pub.setCollectedFromId("test________::zenodo");
132
		pub.setHostedById("test________::UNKNOWN");
133
		pub.getLinksToProjects().add("info:eu-repo/grantAgreement/EC/FP7/283595/EU//OpenAIREplus");
134
		pub.getLinksToProjects().add("info:eu-repo/grantAgreement/EC/FP7/244909/EU/Making Capabilities Work/WorkAble");
135
		pub.getContexts().add("egi::classification::natsc::math::pure");
136
		pub.getContexts().add("egi::classification::natsc::math::stats");
137
		final String xml = pub.asOafRecord(ve, lookUpService, "http://oaf/oaf.xsd");
138

  
139
		final Document doc = new SAXReader().read(new StringReader(xml));
140

  
141
		final OutputFormat format = OutputFormat.createPrettyPrint();
142

  
143
		final XMLWriter writer = new XMLWriter(System.out, format);
144

  
145
		writer.write(doc);
146

  
147
		/* writer.close(); */
148

  
149
	}
150

  
151

  
152
	@Test
153
	public void testAsIndexRecord_json() throws Exception {
154
		testAsIndexRecord_json("test_record.json");
155

  
156
	}
157

  
158
	@Test
159
	public void testAsIndexRecord_json_with_greek_chars() throws Exception {
160

  
161
		testAsIndexRecord_json("test_record_with_greek_chars.json");
162

  
163
	}
164

  
165
	@Test
166
	public void testAsIndexRecord_openaireId() throws Exception {
167

  
168
		testAsIndexRecord_json("test_record_openaireId.json");
169

  
170
	}
171

  
172
	@Test(expected = DirecIndexApiException.class)
173
	public void testAsIndexRecord_wrongOpenaireId() throws Exception {
174

  
175
		testAsIndexRecord_json("test_record_wrong_openaireId.json");
176

  
177
	}
178

  
179
	@Test
180
	public void testAsIndexRecord_json_zenodo() throws Exception {
181

  
182
		testAsIndexRecord_json("test_zenodo.json");
183

  
184
	}
185

  
186
	@Test
187
	public void testAsIndexRecord_json_zenodoWithAmpersand() throws Exception {
188

  
189
		testAsIndexRecord_json("test_zenodoAmpersandEverywhere.json");
190

  
191
	}
192

  
193
	@Test
194
	public void testAsIndexRecord_json_software() throws Exception {
195

  
196
		testAsIndexRecord_json("test_record_software.json");
197

  
198
	}
199

  
200
	@Test
201
	public void testAsIndexRecord_json_orp() throws Exception {
202

  
203
		testAsIndexRecord_json("test_record_orp.json");
204

  
205
	}
206

  
207
	private void testAsIndexRecord_json(final String filename) throws Exception {
208
		final ResultEntry pub =
209
				new Gson().fromJson(new InputStreamReader(getClass().getResourceAsStream(filename)), ResultEntry.class);
210

  
211
		final String xml = pub.asOafRecord(ve, lookUpService, "http://oaf/oaf.xsd");
212
		System.out.println(xml);
213

  
214
		final Document doc = new SAXReader().read(new StringReader(xml));
215

  
216
		final OutputFormat format = OutputFormat.createPrettyPrint();
217

  
218
		final XMLWriter writer = new XMLWriter(System.out, format);
219

  
220
		writer.write(doc);
221

  
222
		/* writer.close(); */
223
	}
224

  
225
	@Test
226
	public void testEscapeUnicode() {
227
		final String unicodeTxt =
228
				"i.e. closed curves of the form $t\ud835\udfc4 [0,2\u03c0] \u21a6 (\\cos t)u + (\\sin t)v$ for suitable orthogonal vectors $u$";
229
		System.out.println(StringEscapeUtils.escapeXml11(unicodeTxt));
230
	}
231

  
232
}
modules/dnet-directindex-api/branches/solr75/src/test/resources/eu/dnetlib/msro/openaireplus/api/objects/test_record_software.json
1
{
2
  "openaireId":"od_______278::d5b39693ac6c2197e8cf48008a982951",
3
  "originalId": "oai:rudar.ruc.dk:1800/24691",
4
  "type": "software",
5
  "title": "Software test",
6
  "authors": [
7
	"Sloan, Patrick Alexander Raaby",
8
	"Strange, Gustav Valdemar"
9
  ],
10
  "publisher": "",
11
  "description": "This is for testing software",
12
  "language": "eng",
13
  "pids": [],
14
  "licenseCode": "OPEN SOURCE",
15
  "resourceType": "0000",
16
  "url": "http://rudar.ruc.dk/handle/1800/24691",
17
  "collectedFromId": "opendoar____::278",
18
  "hostedById": "opendoar____::278",
19
  "linksToProjects": [],
20
  "contexts": []
21
}
modules/dnet-directindex-api/branches/solr75/src/test/resources/eu/dnetlib/msro/openaireplus/api/objects/test_record_wrong_openaireId.json
1
{
2
  "openaireId":"dedup_wf_001::ab42e811",
3
  "originalId": "ORIG_ID_TEST",
4
  "type": "publication",
5
  "title": "TEST TITLE",
6
  "authors": [
7
	"Michele Artini",
8
	"Claudio Atzori",
9
	"Alessia Bardi"
10
  ],
11
  "publisher": "Test publisher",
12
  "description": "DESCRIPTION DESCRIPTION DESCRIPTION DESCRIPTION DESCRIPTION DESCRIPTION",
13
  "language": "ita",
14
  "pids": [
15
	{
16
	  "type": "doi",
17
	  "value": "10.000/xyz-123"
18
	},
19
	{
20
	  "type": "oai",
21
	  "value": "oai:1234"
22
	}
23
  ],
24
  "licenseCode": "EMBARGO",
25
  "embargoEndDate": "2018-02-02",
26
  "resourceType": "0001",
27
  "url": "http://test.it/xyz",
28
  "collectedFromId": "opendoar____::2659",
29
  "hostedById": "opendoar____::2659",
30
  "linksToProjects": [
31
	"info:eu-repo/grantAgreement/EC/FP7/283595/EU//OpenAIREplus",
32
	"info:eu-repo/grantAgreement/EC/FP7/244909/EU/Making Capabilities Work/WorkAble"
33
  ],
34
  "contexts": [
35
	"egi::classification::natsc::math::pure",
36
	"egi::classification::natsc::math::stats"
37
  ]
38
}
modules/dnet-directindex-api/branches/solr75/src/test/resources/eu/dnetlib/msro/openaireplus/api/objects/test_record_openaireId.json
1
{
2
  "openaireId":"dedup_wf_001::ab42e8116f4ae3c4021fb7c643a8167a",
3
  "originalId": "ORIG_ID_TEST",
4
  "type": "publication",
5
  "title": "TEST TITLE",
6
  "authors": [
7
	"Michele Artini",
8
	"Claudio Atzori",
9
	"Alessia Bardi"
10
  ],
11
  "publisher": "Test publisher",
12
  "description": "DESCRIPTION DESCRIPTION DESCRIPTION DESCRIPTION DESCRIPTION DESCRIPTION",
13
  "language": "ita",
14
  "pids": [
15
	{
16
	  "type": "doi",
17
	  "value": "10.000/xyz-123"
18
	},
19
	{
20
	  "type": "oai",
21
	  "value": "oai:1234"
22
	}
23
  ],
24
  "accessRightCode": "EMBARGO",
25
  "licenseCode": "OPEN",
26
  "embargoEndDate": "2018-02-02",
27
  "resourceType": "0001",
28
  "url": "http://test.it/xyz",
29
  "collectedFromId": "opendoar____::2659",
30
  "hostedById": "opendoar____::2659",
31
  "linksToProjects": [
32
	"info:eu-repo/grantAgreement/EC/FP7/283595/EU//OpenAIREplus",
33
	"info:eu-repo/grantAgreement/EC/FP7/244909/EU/Making Capabilities Work/WorkAble"
34
  ],
35
  "contexts": [
36
	"egi::classification::natsc::math::pure",
37
	"egi::classification::natsc::math::stats"
38
  ]
39
}
modules/dnet-directindex-api/branches/solr75/src/test/resources/eu/dnetlib/msro/openaireplus/api/objects/test_record.json
1
{
2
  "originalId": "ORIG_ID_12345",
3
  "title": "TEST TITLE",
4
  "authors": [
5
	"Michele Artini",
6
	"Claudio Atzori",
7
	"Alessia Bardi"
8
  ],
9
  "publisher": "Test publisher",
10
  "description": "DESCRIPTION DESCRIPTION DESCRIPTION DESCRIPTION DESCRIPTION DESCRIPTION",
11
  "language": "ita",
12
  "pids": [
13
	{
14
	  "type": "doi",
15
	  "value": "10.000/xyz-123"
16
	},
17
	{
18
	  "type": "oai",
19
	  "value": "oai:1234"
20
	}
21
  ],
22
  "accessRightCode": "OPEN",
23
  "resourceType": "0001",
24
  "url": "http://test.it/xyz",
25
  "collectedFromId": "opendoar____::2659",
26
  "hostedById": "opendoar____::2367",
27
  "linksToProjects": [
28
	"info:eu-repo/grantAgreement/EC/FP7/283595/EU//OpenAIREplus",
29
	"info:eu-repo/grantAgreement/EC/FP7/244909/EU/Making Capabilities Work/WorkAble"
30
  ],
31
  "contexts": [
32
	"egi::classification::natsc::math::pure",
33
	"egi::classification::natsc::math::stats"
34
  ]
35
}
modules/dnet-directindex-api/branches/solr75/src/test/resources/eu/dnetlib/msro/openaireplus/api/objects/test_record_orp.json
1
{
2
  "openaireId":"od_______278::d5b39693ac6c2197e8cf48008a982951",
3
  "originalId": "oai:rudar.ruc.dk:1800/24691",
4
  "type": "other",
5
  "title": "Other test record",
6
  "authors": [
7
    "Sloan, Patrick Alexander Raaby",
8
    "Strange, Gustav Valdemar"
9
  ],
10
  "publisher": "",
11
  "description": "This is for testing software",
12
  "language": "eng",
13
  "pids": [],
14
  "licenseCode": "OPEN SOURCE",
15
  "resourceType": "0000",
16
  "url": "http://rudar.ruc.dk/handle/1800/24691",
17
  "collectedFromId": "opendoar____::278",
18
  "hostedById": "opendoar____::278",
19
  "linksToProjects": [],
20
  "contexts": []
21
}
modules/dnet-directindex-api/branches/solr75/src/test/resources/eu/dnetlib/msro/openaireplus/api/objects/test_zenodo.json
1
{
2
  "authors":[
3
	"Alouges, Fran\u00e7ois",
4
	"Di Fratta, Giovanni"
5
  ],
6
  "collectedFromId":"opendoar____::2659",
7
  "description":"The paper is about the parking 3-sphere swimmer ($\\text{sPr}_3$). This is a low-Reynolds number model swimmer composed of three balls of equal radii. The three balls can move along three horizontal axes (supported in the same plane) that mutually meet at the center of $\\text{sPr}_3$ with angles of $120^{\u2218}$ . The governing dynamical system is introduced and the implications of its geometric symmetries revealed. It is then shown that, in the first order range of small strokes, optimal periodic strokes are ellipses embedded in 3d space, i.e. closed curves of the form $t\ud835\udfc4 [0,2\u03c0] \u21a6 (\\cos t)u + (\\sin t)v$ for suitable orthogonal vectors $u$ and $v$ of $\u211d^3$. A simple analytic expression for the vectors $u$ and $v$ is derived. The results of the paper are used in a second article where the real physical dynamics of $\\text{sPr}_3$ is analyzed in the asymptotic range of very long arms. ; Comment: 17 pages, 4 figures",
8
  "hostedById":"opendoar____::2659",
9
  "licenseCode":"OPEN",
10
  "originalId":"oai:zenodo.org:996201",
11
  "pids":[
12
	{
13
	  "type":"oai",
14
	  "value":"oai:zenodo.org:996201"
15
	},
16
	{
17
	  "type":"doi",
18
	  "value":"10.5281/zenodo.996201"
19
	}
20
  ],
21
  "publisher":"Zenodo",
22
  "resourceType":"0020",
23
  "title":"Parking 3-sphere swimmer. I. Energy minimizing strokes",
24
  "type":"publication",
25
  "url":"https://zenodo.org/record/996201"
26
}
modules/dnet-directindex-api/branches/solr75/src/test/resources/eu/dnetlib/msro/openaireplus/api/objects/test_zenodoAmpersandEverywhere.json
1
{
2
  "authors": [
3
	"Conradt, Tobias",
4
	"& members of the ISIMIP project (original data provision), cf. Hempel et al. 2013, https://doi.org/10.5194/esd-4-219-2013"
5
  ],
6
  "collectedFromId": "re3data_____::r3d100010468",
7
  "description": "<p>ISIMIP-2a climate data cutout provided for Sardinia in the framework of SIM4NEXUS & X<\/p>",
8
  "hostedById": "re3data_____::r3d100010468",
9
  "licenseCode": "OPEN",
10
  "linksToProjects": ["info:eu-repo/grantAgreement/EC/H2020/689150//Sustainable Integrated Management FOR the NEXUS of water-land-food-energy-climate for a resource-efficient Europe & beyond/SIM4NEXUS"],
11
  "originalId": "10.5281/zenodo.1460665",
12
  "pids": [
13
	{
14
	  "type": "oai",
15
	  "value": "oai:zenodo.org:1460665"
16
	},
17
	{
18
	  "type": "doi",
19
	  "value": "10.5281/zenodo.1460665"
20
	}
21
  ],
22
  "publisher": "Zenodo & Zenodo",
23
  "resourceType": "0021",
24
  "title": "sardinia_tasmax_MIROC-ESM-CHEM_rcp4p5_2006-2099_daily.nc4 & the title has && in it",
25
  "type": "dataset",
26
  "url": "https://zenodo.org/record/1460665"
27
}
modules/dnet-directindex-api/branches/solr75/src/test/resources/eu/dnetlib/msro/openaireplus/api/objects/test_record_ariadne.json
1
{
2
  "openaireId":"od_______278::d5b39693ac6c2197e8cf48008a982950",
3
  "originalId": "oai:rudar.ruc.dk:1800/24690",
4
  "type": "publication",
5
  "title": "Autofiktion",
6
  "authors": [
7
	"Sloan, Patrick Alexander Raaby",
8
	"Strange, Gustav Valdemar",
9
	"Freund-Jensen, Sofie",
10
	"Canvin, Emilie Meistrup",
11
	"Faaborg, Ida Selvejer",
12
	"Kruse, Mikkel"
13
  ],
14
  "publisher": "",
15
  "description": "The following paper is a project on the autofictional book Færdig med Eddy Bellegueule by Édouard Louis (2015). The main focus is to ascertain how the novel is an expression of the author’s effort to connect social life and literature, and what part autofiction as a genre plays in this process. A textual analysis will describe the narrator’s position, and the aesthetic grip of the novel. Furthermore, we will analyze the central themes in Louis’ novel with theories by sociologist Pierre Bourdieu, gender theorist Judith Butler and postcolonial theorist Gayatri Spivak. This includes symbolic violence, gender roles, language and suppression. With use of classic literary theory and the more recent and specific theory on autofiction, the paper concludes, that Færdig med Eddy Bellegueule is based on non-fictional events, but presents these events through a fictionalization that raise the story into a literary work of art. The genre autofiction encircles a current tendency to blend non-fictional events and characters into literature, and Færdig med Eddy Bellegueule writes itself perfectly into this twilight zone between fact and fiction.",
16
  "language": "eng",
17
  "pids": [],
18
  "licenseCode": "OPEN",
19
  "resourceType": "0006",
20
  "url": "http://rudar.ruc.dk/handle/1800/24690",
21
  "collectedFromId": "opendoar____::278",
22
  "hostedById": "opendoar____::278",
23
  "linksToProjects": [],
24
  "contexts": []
25
}
modules/dnet-directindex-api/branches/solr75/src/test/resources/eu/dnetlib/msro/openaireplus/api/objects/submit_test_record.sh
1
#!/bin/bash
2

  
3
curl -H "Content-Type: application/json" --data @test_record.json "http://localhost:8280/app/mvc/api/publications/feedObject"
modules/dnet-directindex-api/branches/solr75/src/test/resources/eu/dnetlib/msro/openaireplus/api/objects/test_record_complete.json
1
{
2
  "originalId": "ORIG_ID_TEST",
3
  "type": "publication",
4
  "title": "TEST TITLE",
5
  "authors": [
6
	"Michele Artini",
7
	"Claudio Atzori",
8
	"Alessia Bardi"
9
  ],
10
  "publisher": "Test publisher",
11
  "description": "DESCRIPTION DESCRIPTION DESCRIPTION DESCRIPTION DESCRIPTION DESCRIPTION",
12
  "language": "ita",
13
  "pids": [
14
	{
15
	  "type": "doi",
16
	  "value": "10.000/xyz-123"
17
	},
18
	{
19
	  "type": "oai",
20
	  "value": "oai:1234"
21
	}
22
  ],
23
  "accessRightCode": "EMBARGO",
24
  "embargoEndDate": "2018-02-02",
25
  "resourceType": "0001",
26
  "url": "http://test.it/xyz",
27
  "collectedFromId": "opendoar____::2659",
28
  "hostedById": "opendoar____::2659",
29
  "linksToProjects": [
30
	"info:eu-repo/grantAgreement/EC/FP7/283595/EU//OpenAIREplus",
31
	"info:eu-repo/grantAgreement/EC/FP7/244909/EU/Making Capabilities Work/WorkAble"
32
  ],
33
  "contexts": [
34
	"egi::classification::natsc::math::pure",
35
	"egi::classification::natsc::math::stats"
36
  ]
37
}
modules/dnet-directindex-api/branches/solr75/src/test/resources/eu/dnetlib/msro/openaireplus/api/objects/test_record_with_greek_chars.json
1
{
2
  "originalId": "ORIG_ID_12345",
3
  "title": "TEST TITLE WITH Greek Characters",
4
  "authors": [
5
	"αβγδεζηθικλμ νξοπρσςτυφχψω",
6
	"ΑΒΓΔΕΖΗΘΙΚΛ ΜΝΞΟΠΡΣΤΥΦΧΨΩ"
7
  ],
8
  "publisher": "âââââââ",
9
  "description": "Αν περιμένατε να βρίσκεται εδώ μια σελίδα και δεν υπάρχει, η σελίδα μπορεί να μην εμφανίζεται λόγω καθυστέρησης στην ανανέωση της βάσης δεδομένων, ή μπορεί να έχει διαγραφεί. (Δείτε την γρήγορη διαγραφή σελίδων για πιθανούς λόγους). Μπορείτε να δοκιμάστε την λειτουργία εκκαθάρισης, και να ελέγξετε το αρχείο διαγραφών.",
10
  "language": "ell",
11
  "pids": [
12
	{
13
	  "type": "doi",
14
	  "value": "10.000/xyz-123-gr"
15
	}
16
  ],
17
  "licenseCode": "EMBARGO",
18
  "embargoEndDate": "2018-02-02",
19
  "resourceType": "0001",
20
  "url": "http://test.it/xyz",
21
  "collectedFromId": "opendoar____::2659",
22
  "hostedById": "opendoar____::2367",
23
  "linksToProjects": [
24
	"info:eu-repo/grantAgreement/EC/FP7/123456/EU//Test"
25
  ],
26
  "contexts": [
27
	"egi::classification::natsc::math::stats"
28
  ]
29
}
modules/dnet-directindex-api/branches/solr75/src/test/resources/log4j.properties
1
### Root Level ###
2
log4j.rootLogger=WARN, CONSOLE
3
### Configuration for the CONSOLE appender ###
4
log4j.appender.CONSOLE=org.apache.log4j.ConsoleAppender
5
log4j.appender.CONSOLE.layout=org.apache.log4j.PatternLayout
6
log4j.appender.CONSOLE.layout.ConversionPattern=[%-5p] %d %c - %m%n
7
org.apache.cxf.Logger=org.apache.cxf.common.logging.Log4jLogger
8
### Application Level ###
9
log4j.logger.eu.dnetlib=INFO
10
log4j.logger.eu.dnetlib.msro.openaireplus.workflows.nodes.contexts=DEBUG
modules/dnet-directindex-api/branches/solr75/src/main/java/eu/dnetlib/openaire/directindex/utils/OafToIndexRecordFactory.java
1
package eu.dnetlib.openaire.directindex.utils;
2

  
3
import java.io.IOException;
4
import java.io.StringReader;
5
import java.io.StringWriter;
6
import javax.annotation.Resource;
7
import javax.xml.transform.Transformer;
8
import javax.xml.transform.TransformerException;
9
import javax.xml.transform.TransformerFactory;
10
import javax.xml.transform.stream.StreamResult;
11
import javax.xml.transform.stream.StreamSource;
12

  
13
import eu.dnetlib.enabling.is.lookup.rmi.ISLookUpDocumentNotFoundException;
14
import eu.dnetlib.enabling.is.lookup.rmi.ISLookUpException;
15
import eu.dnetlib.enabling.is.lookup.rmi.ISLookUpService;
16
import eu.dnetlib.enabling.locators.UniqueServiceLocator;
17
import eu.dnetlib.miscutils.functional.xml.ApplyXslt;
18
import org.apache.commons.io.IOUtils;
19
import org.springframework.beans.factory.annotation.Required;
20
import org.springframework.core.io.ClassPathResource;
21

  
22
/**
23
 * Created by michele on 15/12/15.
24
 */
25
public class OafToIndexRecordFactory {
26

  
27
	private ClassPathResource layoutToRecord;
28

  
29
	@Resource
30
	private UniqueServiceLocator serviceLocator;
31

  
32
	public ApplyXslt newTransformer(final String format) throws ISLookUpException, IOException, TransformerException {
33
		final TransformerFactory factory = TransformerFactory.newInstance();
34
		final Transformer layoutTransformer = factory.newTransformer(readLayoutToRecord());
35

  
36
		final StreamResult layoutToXsltXslt = new StreamResult(new StringWriter());
37

  
38
		layoutTransformer.setParameter("format", format);
39
		layoutTransformer.transform(new StreamSource(new StringReader(getLayoutSource(format))), layoutToXsltXslt);
40

  
41
		return new ApplyXslt(layoutToXsltXslt.getWriter().toString());
42
	}
43

  
44
	private StreamSource readLayoutToRecord() throws IOException {
45
		return new StreamSource(new StringReader(IOUtils.toString(layoutToRecord.getInputStream())));
46
	}
47

  
48
	private String getLayoutSource(final String format) throws ISLookUpDocumentNotFoundException, ISLookUpException {
49
		return serviceLocator.getService(ISLookUpService.class).getResourceProfileByQuery(
50
				"collection('/db/DRIVER/MDFormatDSResources/MDFormatDSResourceType')[.//NAME='" + format + "']//LAYOUT[@name='index']");
51
	}
52

  
53
	public ClassPathResource getLayoutToRecord() {
54
		return layoutToRecord;
55
	}
56

  
57
	@Required
58
	public void setLayoutToRecord(final ClassPathResource layoutToRecord) {
59
		this.layoutToRecord = layoutToRecord;
60
	}
61

  
62
}
modules/dnet-directindex-api/branches/solr75/src/main/java/eu/dnetlib/openaire/directindex/api/OpenaireResultSubmitter.java
1
package eu.dnetlib.openaire.directindex.api;
2

  
3
import java.io.IOException;
4
import java.util.List;
5

  
6
import javax.annotation.Resource;
7

  
8
import org.apache.commons.io.IOUtils;
9
import org.apache.commons.lang.exception.ExceptionUtils;
10
import org.apache.commons.logging.Log;
11
import org.apache.commons.logging.LogFactory;
12
import org.apache.velocity.app.VelocityEngine;
13
import org.springframework.beans.factory.annotation.Value;
14
import org.springframework.core.io.ClassPathResource;
15
import org.springframework.http.HttpStatus;
16
import org.springframework.stereotype.Controller;
17
import org.springframework.web.bind.annotation.ExceptionHandler;
18
import org.springframework.web.bind.annotation.PathVariable;
19
import org.springframework.web.bind.annotation.RequestBody;
20
import org.springframework.web.bind.annotation.RequestMapping;
21
import org.springframework.web.bind.annotation.RequestMethod;
22
import org.springframework.web.bind.annotation.RequestParam;
23
import org.springframework.web.bind.annotation.ResponseBody;
24
import org.springframework.web.bind.annotation.ResponseStatus;
25

  
26
import com.google.common.collect.Lists;
27
import com.google.gson.Gson;
28

  
29
import eu.dnetlib.common.rmi.DNetRestDocumentation;
30
import eu.dnetlib.data.index.CloudIndexClient;
31
import eu.dnetlib.data.index.CloudIndexClientFactory;
32
import eu.dnetlib.enabling.is.lookup.rmi.ISLookUpException;
33
import eu.dnetlib.enabling.is.lookup.rmi.ISLookUpService;
34
import eu.dnetlib.enabling.locators.UniqueServiceLocator;
35
import eu.dnetlib.openaire.directindex.objects.ResultEntry;
36
import eu.dnetlib.openaire.directindex.utils.OafToIndexRecordFactory;
37

  
38
/**
39
 * Created by michele on 11/11/15.
40
 */
41
@Controller
42
@DNetRestDocumentation
43
public class OpenaireResultSubmitter {
44

  
45
	private static final Log log = LogFactory.getLog(OpenaireResultSubmitter.class);
46

  
47
	public class IndexDsInfo {
48

  
49
		private final String indexBaseUrl;
50
		private final String indexDsId;
51
		private final String format;
52
		private final String coll;
53

  
54
		public IndexDsInfo(final String indexBaseUrl, final String indexDsId, final String format, final String coll) {
55
			this.indexBaseUrl = indexBaseUrl;
56
			this.indexDsId = indexDsId;
57
			this.format = format;
58
			this.coll = coll;
59
		}
60

  
61
		public String getIndexBaseUrl() {
62
			return indexBaseUrl;
63
		}
64

  
65
		public String getIndexDsId() {
66
			return indexDsId;
67
		}
68

  
69
		public String getFormat() {
70
			return format;
71
		}
72

  
73
		public String getColl() {
74
			return coll;
75
		}
76

  
77
	}
78

  
79
	@Value(value = "oaf.schema.location")
80
	private String oafSchemaLocation;
81

  
82
	@Resource
83
	private UniqueServiceLocator serviceLocator;
84

  
85
	@Resource
86
	private OafToIndexRecordFactory oafToIndexRecordFactory;
87

  
88
	@Resource
89
	private RecentResultsQueue recentResultsQueue;
90

  
91
	@Resource(name = "openaireplusApisVelocityEngine")
92
	private VelocityEngine velocityEngine;
93

  
94
	@Value(value = "${openaire.api.directindex.findSolrIndexUrl.xquery}")
95
	private ClassPathResource findSolrIndexUrl;
96

  
97
	@Value(value = "${openaire.api.directindex.findIndexDsInfo.xquery}")
98
	private ClassPathResource findIndexDsInfo;
99

  
100
	@Deprecated
101
	@RequestMapping(value = { "/api/publications/feedJson", "/api/results/feedJson" }, method = RequestMethod.POST)
102
	public @ResponseBody String feedObjectJson(@RequestParam(value = "json", required = true) final String json,
103
			@RequestParam(value = "commit", required = false, defaultValue = "true") final boolean commit) throws DirecIndexApiException {
104
		final ResultEntry pub = new Gson().fromJson(json, ResultEntry.class);
105
		return feedObject(pub, commit);
106
	}
107

  
108
	@RequestMapping(value = { "/api/results/feedObject" }, method = RequestMethod.POST)
109
	public @ResponseBody String feedResult(@RequestBody final ResultEntry pub,
110
			@RequestParam(value = "commit", required = false, defaultValue = "true") final boolean commit)
111
			throws DirecIndexApiException {
112
		return feed(pub, commit);
113
	}
114

  
115
	@Deprecated
116
	@RequestMapping(value = { "/api/publications/feedObject" }, method = RequestMethod.POST)
117
	public @ResponseBody String feedObject(@RequestBody final ResultEntry pub,
118
			@RequestParam(value = "commit", required = false, defaultValue = "true") final boolean commit)
119
			throws DirecIndexApiException {
120
		return feed(pub, commit);
121
	}
122

  
123

  
124
	@RequestMapping(value = "/api/result/{openaireId}", method = RequestMethod.DELETE)
125
	public @ResponseBody boolean deleteResultWithOpenaireId(
126
			@PathVariable(value = "openaireId") final String openaireId,
127
			@RequestParam(value = "commit", required = false, defaultValue = "true") final boolean commit) throws DirecIndexApiException {
128

  
129
		return deleteResult(openaireId, commit);
130
	}
131

  
132
	@RequestMapping(value = "/api/results", method = RequestMethod.DELETE)
133
	public @ResponseBody boolean deleteResultWithOriginalId(
134
			@RequestParam(value = "originalId", required = true) final String originalId,
135
			@RequestParam(value = "collectedFromId", required = true) final String collectedFromId,
136
			@RequestParam(value = "commit", required = false, defaultValue = "true") final boolean commit) throws Exception {
137

  
138
		final String openaireId = ResultEntry.calculateOpenaireId(originalId, collectedFromId, serviceLocator.getService(ISLookUpService.class));
139
		return deleteResult(openaireId, commit);
140
	}
141

  
142
	@Deprecated
143
	@RequestMapping(value = { "/api/publications/deleteObject", "/api/results/delete" }, method = RequestMethod.POST)
144
	public @ResponseBody boolean deleteResultPost(
145
			@RequestParam(value = "originalId", required = true) final String originalId,
146
			@RequestParam(value = "collectedFromId", required = true) final String collectedFromId,
147
			@RequestParam(value = "commit", required = false, defaultValue = "true") final boolean commit) throws Exception {
148

  
149
		final String openaireId = ResultEntry.calculateOpenaireId(originalId, collectedFromId, serviceLocator.getService(ISLookUpService.class));
150
		return deleteResult(openaireId, commit);
151
	}
152

  
153
	private String feed(final ResultEntry pub, final boolean commit) throws DirecIndexApiException {
154
		final List<IndexDsInfo> idxList;
155
		try {
156
			idxList = calculateCurrentIndexDsInfo();
157
			if (idxList == null
158
					|| idxList.isEmpty()) { throw new DirecIndexApiException("Cannot add result: " + pub.getAnyId() + " : No public Search Service found"); }
159
			if (idxList.size() > 1) {
160
				log.warn("Found more than 1 public search service");
161
			}
162
			final String oafRecord = pub.asOafRecord(velocityEngine, serviceLocator.getService(ISLookUpService.class), oafSchemaLocation);
163

  
164
			for (final IndexDsInfo idx : idxList) {
165
				CloudIndexClient idxClient = null;
166
				try {
167
					idxClient = CloudIndexClientFactory.newIndexClient(idx.getIndexBaseUrl(), idx.getColl(), false);
168
					idxClient.feed(oafRecord, idx.getIndexDsId(), oafToIndexRecordFactory.newTransformer(idx.getFormat()), commit);
169
				} catch (final Throwable e) {
170
					throw new DirecIndexApiException("Error adding publication: " + e.getMessage(), e);
171
				} finally {
172
					if (idxClient != null) {
173
						idxClient.close();
174
					}
175
				}
176
			}
177
			recentResultsQueue.add(oafRecord);
178
			return pub.getOpenaireId();
179
		} catch (final Throwable e) {
180
			log.error("Error saving record", e);
181
			log.debug(pub.toString());
182
			throw new DirecIndexApiException("Error adding publication: " + e.getMessage(), e);
183
		}
184
	}
185

  
186

  
187
	private boolean deleteResult(final String openaireId, final boolean commit) throws DirecIndexApiException {
188

  
189
		final List<IndexDsInfo> idxList;
190
		try {
191
			idxList = calculateCurrentIndexDsInfo();
192

  
193
			if (idxList == null
194
					|| idxList.isEmpty()) { throw new DirecIndexApiException("Cannot delete result: " + openaireId + " : No public Search Service found"); }
195
			if (idxList.size() > 1) {
196
				log.warn("Found more than 1 public search service");
197
			}
198

  
199
			// final String objId = ResultEntry.calculateOpenaireId(originalId, collectedFromId,
200
			// serviceLocator.getService(ISLookUpService.class));
201

  
202
			for (final IndexDsInfo idx : idxList) {
203
				CloudIndexClient idxClient = null;
204
				try {
205
					idxClient = CloudIndexClientFactory.newIndexClient(idx.getIndexBaseUrl(), idx.getColl(), false);
206
					idxClient.remove(openaireId, commit);
207
					log.info("Deleted result with id: " + openaireId + " from: " + idx.getIndexBaseUrl());
208
				} catch (final Throwable e) {
209
					throw new DirecIndexApiException("Error deleting publication: " + e.getMessage(), e);
210
				} finally {
211
					if (idxClient != null) {
212
						idxClient.close();
213
					}
214
				}
215
			}
216
			recentResultsQueue.remove(openaireId);
217
			return true;
218
		} catch (IOException | ISLookUpException e) {
219
			throw new DirecIndexApiException("Error deleting publication: " + e.getMessage(), e);
220
		}
221
	}
222

  
223
	@ExceptionHandler(Exception.class)
224
	@ResponseStatus(value = HttpStatus.INTERNAL_SERVER_ERROR)
225
	public @ResponseBody ErrorMessage handleException(final Exception e) {
226
		log.error("Error in direct index API", e);
227
		return new ErrorMessage(e);
228
	}
229

  
230
	private List<IndexDsInfo> calculateCurrentIndexDsInfo() throws IOException, ISLookUpException {
231
		final List<IndexDsInfo> list = Lists.newArrayList();
232

  
233
		final String queryUrl = IOUtils.toString(findSolrIndexUrl.getInputStream());
234
		final String queryDs = IOUtils.toString(findIndexDsInfo.getInputStream());
235

  
236
		final ISLookUpService lu = serviceLocator.getService(ISLookUpService.class);
237
		final String indexBaseUrl = lu.getResourceProfileByQuery(queryUrl);
238

  
239
		final List<String> idxDs = lu.quickSearchProfile(queryDs);
240
		for (final String idx : idxDs) {
241
			final String[] arr = idx.split("@@@");
242
			list.add(new IndexDsInfo(indexBaseUrl, arr[0].trim(), arr[1].trim(), arr[2].trim()));
243
		}
244
		return list;
245
	}
246

  
247
	public class ErrorMessage {
248

  
249
		private final String message;
250
		private final String stacktrace;
251

  
252
		public ErrorMessage(final Exception e) {
253
			this(e.getMessage(), ExceptionUtils.getStackTrace(e));
254
		}
255

  
256
		public ErrorMessage(final String message, final String stacktrace) {
257
			this.message = message;
258
			this.stacktrace = stacktrace;
259
		}
260

  
261
		public String getMessage() {
262
			return this.message;
263
		}
264

  
265
		public String getStacktrace() {
266
			return this.stacktrace;
267
		}
268

  
269
	}
270

  
271
}
modules/dnet-directindex-api/branches/solr75/src/main/java/eu/dnetlib/openaire/directindex/api/OpenAIRESubmitterUtils.java
1
package eu.dnetlib.openaire.directindex.api;
2

  
3
import java.io.StringWriter;
4
import java.util.ArrayList;
5
import java.util.HashMap;
6
import java.util.List;
7
import java.util.Map;
8

  
9
import com.google.common.base.Function;
10
import com.google.common.collect.Lists;
11
import eu.dnetlib.miscutils.functional.hash.Hashing;
12
import org.apache.commons.lang.StringUtils;
13

  
14
/**
15
 * Created by michele on 15/01/16.
16
 */
17
public class OpenAIRESubmitterUtils {
18

  
19
	private static final org.apache.commons.logging.Log log = org.apache.commons.logging.LogFactory.getLog(OpenAIRESubmitterUtils.class);
20

  
21
	public Map<String, String> calculateProjectInfo(final String link) {
22
		final Map<String, String> info = new HashMap<String, String>();
23
		final String[] arr = link.split("/");
24
		// info:eu-repo/grantAgreement/EC/FP7/244909/EU/Making Capabilities Work/WorkAble
25

  
26
		if (arr.length > 4) {
27
			final String acronym = arr.length > 7 ? arr[7] : "";
28
			final String title = arr.length > 6 ? StringUtils.isNotBlank(arr[6]) ? arr[6] : acronym : "";
29
			final String jurisdiction = arr.length > 5 ? arr[5] : "";
30
			final String funderId = calculateFunderId(arr[2], arr[3]);
31
			info.put("id", calculateProjectId(arr[2], arr[3], arr[4]));
32
			info.put("funderShortName", arr[2]);
33
			info.put("fundingName", arr[3]);
34
			info.put("code", arr[4]);
35
			info.put("jurisdiction", jurisdiction);
36
			info.put("title", title);
37
			info.put("acronym", acronym);
38
			info.put("funderId", funderId);
39
			info.put("funderName", calculateFunderName(arr[2]));
40
			info.put("fundingId", funderId + "::" + arr[3]);
41
		}
42
		return info;
43
	}
44

  
45
	protected String calculateFunderPrefix(final String funderShortName, final String funding){
46
		switch(funderShortName.toLowerCase()){
47
		case "conicyt":
48
			return "conicytf____::";
49
		case "ec":
50
			if (funding.equalsIgnoreCase("fp7")) {
51
				return "corda_______::";
52
			} else {
53
				return "corda__h2020::";
54
			}
55
		case "hrzz":
56
		case "mzos":
57
			return "irb_hr______::";
58
		case "tara":
59
			return "taraexp_____::";
60
		case "tubitak":
61
			return "tubitakf____::";
62
		default:
63
			String prefix = funderShortName.toLowerCase();
64
			//ensure we have 12 chars
65
			while(prefix.length() < 12) prefix += "_";
66
			return prefix +"::";
67
		}
68
	}
69

  
70
	protected String calculateProjectId(final String funderShortName, final String funding, final String code) {
71
		final String suffix = Hashing.md5(code);
72
		final String funderPrefix = calculateFunderPrefix(funderShortName, funding);
73
		return funderPrefix + suffix;
74
	}
75

  
76
	protected String calculateFunderId(final String funderShortName, final String funding) {
77
		switch (funderShortName.toLowerCase()) {
78
		case "ec":
79
			return "ec__________::EC";
80
		default:
81
			String prefix = calculateFunderPrefix(funderShortName, funding);
82
			return prefix + funderShortName.toUpperCase();
83
		}
84
	}
85

  
86

  
87
	protected String calculateFunderName(final String funderShortName) {
88

  
89
		switch (funderShortName.toLowerCase()) {
90
		case "aff":
91
		case "aka":
92
			return "Academy of Finland";
93
		case "arc":
94
			return "Australian Research Council (ARC)";
95
		case "conicyt":
96
			return "Comisión Nacional de Investigación Científica y Tecnológica";
97
		case "ec":
98
			return "European Commission";
99
		case "fct":
100
			return "Fundação para a Ciência e a Tecnologia, I.P.";
101
		case "fwf":
102
			return "Austrian Science Fund (FWF)";
103
		case "hrzz":
104
			return "Croatian Science Foundation (CSF)";
105
		case "mestd":
106
			return "Ministry of Education, Science and Technological Development of Republic of Serbia";
107
		case "miur":
108
			return "Ministero dell'Istruzione dell'Università e della Ricerca";
109
		case "mzos":
110
			return "Ministry of Science, Education and Sports of the Republic of Croatia (MSES)";
111
		case "nhmrc":
112
			return "National Health and Medical Research Council (NHMRC)";
113
		case "nih":
114
			return "National Institutes of Health";
115
		case "nsf":
116
			return "National Science Foundation";
117
		case "nwo":
118
			return "Netherlands Organisation for Scientific Research (NWO)";
119
		case "rcuk":
120
			return "Research Council UK";
121
		case "sfi":
122
			return "Science Foundation Ireland";
123
		case "sgov":
124
			return "Gobierno de España";
125
		case "snsf":
126
			return "Swiss National Science Foundation";
127
		case "tara":
128
			return "Tara Expeditions Foundation";
129
		case "tubitak":
130
			return "Türkiye Bilimsel ve Teknolojik Araştırma Kurumu";
131
		case "wt":
132
			return "Wellcome Trust";
133
		default:
134
			log.error("Funder short name '"+funderShortName+"' not managed");
135
			return "";
136
		}
137
	}
138

  
139
	public List<ContextInfo> processContexts(final List<String> list) {
140
		return Lists.newArrayList(Lists.transform(list, new Function<String, ContextInfo>() {
141

  
142
			@Override
143
			public ContextInfo apply(final String s) {
144
				return createContextInfo(s.split("::"), 0);
145
			}
146

  
147
			private ContextInfo createContextInfo(final String[] arr, final int pos) {
148
				final StringWriter id = new StringWriter();
149
				id.write(arr[0]);
150
				for (int i = 0; i < pos; i++) {
151
					id.write("::");
152
					id.write(arr[i + 1]);
153
				}
154
				final String elem = (pos == 0) ? "context" : (pos == 1) ? "category" : "concept";
155
				final ContextInfo info = new ContextInfo(elem, id.toString());
156
				if ((pos + 1) < arr.length) {
157
					info.getChildren().add(createContextInfo(arr, pos + 1));
158
				}
159
				return info;
160
			}
161
		}));
162

  
163
	}
164

  
165
	public class ContextInfo {
166

  
167
		private String elem;
168
		private String id;
169
		private List<ContextInfo> children = new ArrayList<ContextInfo>();
170

  
171
		public ContextInfo(final String elem,
172
				final String id) {
173
			this.elem = elem;
174
			this.id = id;
175
		}
176

  
177
		public String getElem() {
178
			return elem;
179
		}
180

  
181
		public void setElem(final String elem) {
182
			this.elem = elem;
183
		}
184

  
185
		public String getId() {
186
			return id;
187
		}
188

  
189
		public void setId(final String id) {
190
			this.id = id;
191
		}
192

  
193
		public List<ContextInfo> getChildren() {
194
			return children;
195
		}
196

  
197
		public void setChildren(final List<ContextInfo> children) {
198
			this.children = children;
199
		}
200

  
201
		public boolean isRoot() {
202
			return elem.equals("context");
203
		}
204
	}
205
}
modules/dnet-directindex-api/branches/solr75/src/main/java/eu/dnetlib/openaire/directindex/api/DirecIndexApiException.java
1
package eu.dnetlib.openaire.directindex.api;
2

  
3
import eu.dnetlib.common.rmi.RMIException;
4

  
5
public class DirecIndexApiException extends RMIException {
6

  
7
	/**
8
	 *
9
	 */
10
	private static final long serialVersionUID = -3888037031334809448L;
11

  
12
	public DirecIndexApiException(final String string) {
13
		super(string);
14
	}
15

  
16
	public DirecIndexApiException(final String string, final Throwable exception) {
17
		super(string, exception);
18
	}
19

  
20
	public DirecIndexApiException(final Throwable exception) {
21
		super(exception);
22
	}
23

  
24
}
modules/dnet-directindex-api/branches/solr75/src/main/java/eu/dnetlib/openaire/directindex/api/RecentResultsQueue.java
1
package eu.dnetlib.openaire.directindex.api;
2

  
3
import java.io.StringReader;
4
import java.util.Iterator;
5
import java.util.List;
6

  
7
import com.mongodb.*;
8
import eu.dnetlib.miscutils.datetime.DateUtils;
9
import org.apache.commons.logging.Log;
10
import org.apache.commons.logging.LogFactory;
11
import org.dom4j.io.SAXReader;
12
import org.springframework.beans.factory.annotation.Required;
13

  
14
/**
15
 * Created by michele on 11/11/15.
16
 */
17
public class RecentResultsQueue implements Iterable<String> {
18

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

  
21
	private DB db;
22
	private String collection;
23

  
24
	public void init() {
25
		if (!db.collectionExists(collection)) {
26
			log.info(String.format("creating collection %s", collection));
27
			db.createCollection(collection, new BasicDBObject());
28
		}
29
	}
30

  
31
	@Override
32
	public Iterator<String> iterator() {
33

  
34
		final DBCursor cursor = db.getCollection(collection).find();
35

  
36
		return new Iterator<String>() {
37

  
38
			@Override
39
			public boolean hasNext() {
40
				return cursor.hasNext();
41
			}
42

  
43
			@Override
44
			public String next() {
45
				final DBObject obj = cursor.next();
46
				return ((obj != null) && obj.containsField("record")) ? obj.get("record").toString() : "";
47
			}
48

  
49
			@Override
50
			public void remove() {
51
				throw new RuntimeException("NOT IMPLEMENTED");
52
			}
53
		};
54
	}
55

  
56
	synchronized public void add(final String oaf) throws Exception {
57
		final String id = (new SAXReader()).read(new StringReader(oaf)).valueOf("//*[local-name() = 'objIdentifier']");
58

  
59
		log.info("Saving record " + id + " in db: " + db.getName() + ", coll: " + collection);
60

  
61
		final DBCollection coll = db.getCollection(collection);
62
		final DBObject obj = BasicDBObjectBuilder.start()
63
				.append("id", id)
64
				.append("record", oaf)
65
				.append("date", DateUtils.now())
66
				.get();
67
		coll.update(new BasicDBObject("id", id), obj, true, false);
68
	}
69

  
70
	public void remove(final List<String> list) {
71
		final DBCollection coll = db.getCollection(collection);
72
		for (final String id : list) {
73
			coll.remove(new BasicDBObject("id", id));
74
		}
75
	}
76

  
77
	public void remove(final String... ids) {
78
		final DBCollection coll = db.getCollection(collection);
79
		for (final String id : ids) {
80
			coll.remove(new BasicDBObject("id", id));
81
		}
82
	}
83

  
84
	public DB getDb() {
85
		return db;
86
	}
87

  
88
	@Required
89
	public void setDb(final DB db) {
90
		this.db = db;
91
	}
92

  
93
	public String getCollection() {
94
		return collection;
95
	}
96

  
97
	@Required
98
	public void setCollection(final String collection) {
99
		this.collection = collection;
100
	}
101
}
modules/dnet-directindex-api/branches/solr75/src/main/java/eu/dnetlib/openaire/directindex/objects/ResultEntry.java
1
package eu.dnetlib.openaire.directindex.objects;
2

  
3
import java.text.SimpleDateFormat;
4
import java.util.ArrayList;
5
import java.util.Date;
6
import java.util.HashMap;
7
import java.util.List;
8
import java.util.Map;
9
import java.util.concurrent.TimeUnit;
10

  
11
import org.apache.commons.lang.StringUtils;
12
import org.apache.commons.logging.Log;
13
import org.apache.commons.logging.LogFactory;
14
import org.apache.velocity.app.VelocityEngine;
15
import org.springframework.ui.velocity.VelocityEngineUtils;
16

  
17
import com.google.gson.Gson;
18

  
19
import eu.dnetlib.enabling.is.lookup.rmi.ISLookUpException;
20
import eu.dnetlib.enabling.is.lookup.rmi.ISLookUpService;
21
import eu.dnetlib.miscutils.datetime.DateUtils;
22
import eu.dnetlib.miscutils.functional.hash.Hashing;
23
import eu.dnetlib.miscutils.functional.string.EscapeXml;
24
import eu.dnetlib.openaire.directindex.api.DirecIndexApiException;
25
import eu.dnetlib.openaire.directindex.api.OpenAIRESubmitterUtils;
26
import io.swagger.annotations.ApiModelProperty;
27

  
28
/**
29
 * Created by michele on 02/12/15.
30
 */
31
public class ResultEntry {
32

  
33
	private String openaireId;
34
	private String originalId;
35
	private String title;
36
	private List<String> authors = new ArrayList<>();
37
	private String publisher;
38
	private String description;
39
	private String language;
40
	private List<PidEntry> pids = new ArrayList<>();
41
	/**
42
	 * @Deprecated: use accessRightCode
43
	 */
44
	@Deprecated
45
	private String licenseCode;
46
	private String accessRightCode;
47
	private String embargoEndDate;
48
	/**
49
	 * One of publication, dataset, software, other. Default value is publication.
50
	 */
51
	private String type = "publication";
52
	private String resourceType;
53
	private String url;
54
	private String collectedFromId;
55
	private String hostedById;
56

  
57
	// String according to the EGI context profile, example: egi::classification::natsc::math
58
	private List<String> contexts = new ArrayList<>();
59

  
60
	// String according to openaire guidelines:
61
	// info:eu-repo/grantAgreement/Funder/FundingProgram/ProjectID/[Jurisdiction]/[ProjectName]/[ProjectAcronym]
62
	private List<String> linksToProjects = new ArrayList<>();
63

  
64
	private static long last_cache_update = 0;
65
	private static final Map<String, Map<String, String>> cached_vocabularies = new HashMap<>();
66
	private static final Map<String, DatasourceEntry> cached_datasources = new HashMap<>();
67
	private static final Map<String, String> cached_contexts = new HashMap<>();
68

  
69
	private static final Log log = LogFactory.getLog(ResultEntry.class);
70

  
71
	public ResultEntry() {}
72

  
73
	public String getOpenaireId() {
74
		return openaireId;
75
	}
76

  
77
	public void setOpenaireId(final String openaireId) {
78
		this.openaireId = openaireId;
79
	}
80

  
81
	public String getOriginalId() {
82
		return originalId;
83
	}
84

  
85
	public void setOriginalId(final String originalId) {
86
		this.originalId = originalId;
87
	}
88

  
89
	@ApiModelProperty(required = true)
90
	public String getTitle() {
91
		return title;
92
	}
93

  
94
	public void setTitle(final String title) {
95
		this.title = title;
96
	}
97

  
98
	public List<String> getAuthors() {
99
		return authors;
100
	}
101

  
102
	public void setAuthors(final List<String> authors) {
103
		this.authors = authors;
104
	}
105

  
106
	public String getPublisher() {
107
		return publisher;
108
	}
109

  
110
	public void setPublisher(final String publisher) {
111
		this.publisher = publisher;
112
	}
113

  
114
	public String getDescription() {
115
		return description;
116
	}
117

  
118
	public void setDescription(final String description) {
119
		this.description = description;
120
	}
121

  
122
	@ApiModelProperty(value = "ISO Alpha-3 code. E.g. 'eng', 'ita'")
123
	public String getLanguage() {
124
		return language;
125
	}
... This diff was truncated because it exceeds the maximum size that can be displayed.

Also available in: Unified diff