Project

General

Profile

« Previous | Next » 

Revision 63249

Added by Alessia Bardi 4 days ago

[maven-release-plugin] copy for tag dnet-directindex-api-4.0.2

View differences:

modules/dnet-directindex-api/tags/dnet-directindex-api-4.0.2/src/test/java/eu/dnetlib/openaire/directindex/objects/ResultEntryToOafTest.java
1
package eu.dnetlib.openaire.directindex.objects;
2

  
3
import static org.mockito.Matchers.anyString;
4
import static org.mockito.Mockito.CALLS_REAL_METHODS;
5
import static org.mockito.Mockito.doReturn;
6
import static org.mockito.Mockito.mock;
7
import static org.mockito.Mockito.when;
8
import static org.mockito.Mockito.withSettings;
9

  
10
import java.io.InputStreamReader;
11
import java.io.StringReader;
12
import java.util.ArrayList;
13
import java.util.Arrays;
14
import java.util.List;
15
import java.util.Properties;
16

  
17
import org.apache.commons.lang3.StringEscapeUtils;
18
import org.apache.velocity.app.VelocityEngine;
19
import org.dom4j.Document;
20
import org.dom4j.Node;
21
import org.dom4j.io.OutputFormat;
22
import org.dom4j.io.SAXReader;
23
import org.dom4j.io.XMLWriter;
24
import org.junit.Assert;
25
import org.junit.Before;
26
import org.junit.Test;
27
import org.junit.runner.RunWith;
28
import org.mockito.Mock;
29
import org.mockito.runners.MockitoJUnitRunner;
30

  
31
import com.google.common.collect.Lists;
32
import com.google.gson.Gson;
33

  
34
import eu.dnetlib.enabling.is.lookup.rmi.ISLookUpService;
35
import eu.dnetlib.openaire.directindex.api.DirecIndexApiException;
36
import eu.dnetlib.openaire.directindex.api.OpenAIRESubmitterUtils;
37

  
38
/**
39
 * Created by michele on 14/12/15.
40
 */
41
@RunWith(MockitoJUnitRunner.class)
42
public class ResultEntryToOafTest {
43

  
44
	private VelocityEngine ve;
45

  
46
	private final String community_api = "https://dev-openaire.d4science.org/openaire/community/";
47
	private final String dsm_api = "https://dev-openaire.d4science.org/openaire/ds/";
48

  
49
	@Mock
50
	private ISLookUpService lookUpService;
51

  
52
	private ResultEntryToOaf toOaf;
53
	private OpenAIRESubmitterUtils utils;
54

  
55
	@Before
56
	public void setUp() throws Exception {
57

  
58
		utils = mock(OpenAIRESubmitterUtils.class, withSettings().defaultAnswer(CALLS_REAL_METHODS));
59
		doReturn(Lists.newArrayList("dh-ch", "dariah", "bar", "x")).when(utils).translateZenodoCommunity("https://zenodo.org/communities/dimpo");
60
		doReturn(Lists.newArrayList()).when(utils).translateZenodoCommunity("https://zenodo.org/communities/dumbo");
61
		doReturn(Lists.newArrayList("noLabel", "enermaps")).when(utils).translateZenodoCommunity("https://sandbox.zenodo.org/communities/oac-ni");
62
		doReturn(Lists.newArrayList("noLabel", "enermaps")).when(utils).translateZenodoCommunity("https://zenodo.org/communities/oac-ni");
63
		doReturn(new DatasourceEntry("test________::XXX", "XXX", "xxxx________")).when(utils).findDatasource(anyString());
64
		doReturn(new DatasourceEntry("opendoar____::2659", "ZENODO", "od______2659")).when(utils).findDatasource("opendoar____::2659");
65

  
66
		toOaf = new ResultEntryToOaf(utils);
67

  
68
		final Properties props = new Properties();
69
		props.setProperty("resource.loader", "class");
70
		props.setProperty("class.resource.loader.class", "org.apache.velocity.runtime.resource.loader.ClasspathResourceLoader");
71
		props.setProperty("runtime.log.logsystem.class", "org.apache.velocity.runtime.log.Log4JLogChute");
72
		ve = new VelocityEngine();
73
		ve.init(props);
74

  
75
		when(lookUpService.quickSearchProfile(anyString())).thenAnswer(invocation -> {
76
			final String query = invocation.getArguments()[0].toString();
77
			if (query.contains("dnet:result_typologies")) {
78
				return Arrays.asList("publication @@@ publication", "dataset @@@ dataset", "software @@@ software", "other @@@ other");
79
			} else if (query.contains("dnet:access_modes")) {
80
				return Arrays.asList("OPEN @@@ Open Access");
81
			} else if (query.contains("dnet:publication_resource")) {
82
				return Arrays.asList("0001 @@@ Journal Article");
83
			} else if (query.contains("dnet:pid_types")) {
84
				return Arrays.asList("oai @@@ Open Archive Initiative", "doi @@@ Digital object identifier");
85
			} else if (query.contains("dnet:languages")) {
86
				return Arrays.asList("ita @@@ Italian");
87
			} else if (query.contains("ContextDSResourceType")) {
88
				return Arrays
89
					.asList("egi::classification::natsc::math::stats @@@ Statistics and Probability", "egi::classification::natsc::math::pure @@@ Pure Mathematics", "egi::classification::natsc::math @@@ Mathematics", "egi::classification::natsc @@@ Natural Sciences", "egi::classification @@@ EGI classification scheme", "egi @@@ EGI", "enermaps @@@ Energy Research", "enermaps::selection @@@ Selected by the H2020 EnerMaps project");
90
			} else {
91
				return new ArrayList<String>();
92
			}
93
		});
94

  
95
	}
96

  
97
	@Test
98
	public void testAsIndexRecord() throws Exception {
99
		final ResultEntry pub = new ResultEntry();
100
		pub.setOriginalId("oai:zenodo.org:5109933");
101
		pub.setTitle("TEST TITLE <test>");
102
		pub.getAuthors().add("Michele Artini");
103
		pub.getAuthors().add("Claudio Atzori");
104
		pub.getAuthors().add("Alessia Bardi");
105
		pub.setPublisher("Test publisher");
106
		pub.setDescription("DESCRIPTION & DESCRIPTION & DESCRIPTION & DESCRIPTION & DESCRIPTION & DESCRIPTION & DESCRIPTION ");
107
		pub.setLanguage("ita");
108
		pub.setLicenseCode("OPEN");
109
		pub.setResourceType("0001");
110
		pub.setUrl("http://test.it/a=1&b=2");
111
		pub.getPids().add(new PidEntry("doi", "10.5281/zenodo.7373707"));
112
		pub.getPids().add(new PidEntry("doi", "10.5281/zenodo.7373706"));
113
		pub.getPids().add(new PidEntry("oai", "oai:1234"));
114
		pub.setCollectedFromId("opendoar____::2659");
115
		pub.setHostedById("opendoar____::2659");
116
		pub.getLinksToProjects().add("info:eu-repo/grantAgreement/EC/FP7/283595/EU//OpenAIREplus");
117
		pub.getLinksToProjects().add("info:eu-repo/grantAgreement/RCUK//244%2F909/EU/Making Capabilities Work/WorkAble");
118
		pub.getContexts().add("egi::classification::natsc::math::pure");
119
		pub.getContexts().add("egi::classification::natsc::math::stats");
120
		pub.getContexts().add("enermaps");
121
		pub.getContexts().add("enermaps::selection");
122
		final String xml = toOaf.asOafRecord(pub, ve, lookUpService, "http://oaf/oaf.xsd");
123

  
124
		final Document doc = new SAXReader().read(new StringReader(xml));
125

  
126
		final Node resultNode = doc.selectSingleNode("//oaf:result");
127
		Assert.assertNotNull(resultNode);
128
		final Node origIdNode = resultNode.selectSingleNode("./originalId");
129
		Assert.assertNotNull(origIdNode);
130
		Assert.assertEquals("oai:zenodo.org:5109933", origIdNode.getText());
131
		final Node titleNode = resultNode.selectSingleNode("./title");
132
		Assert.assertNotNull(titleNode);
133
		Assert.assertNotNull(titleNode.getText());
134
		final List<Node> accessRightsNodes = resultNode.selectNodes(".//accessright/@classid");
135
		for (final Node aNode : accessRightsNodes) {
136
			Assert.assertEquals("OPEN", aNode.getStringValue());
137
		}
138
		final Node bestARNode = resultNode.selectSingleNode("./bestaccessright/@classid");
139
		Assert.assertEquals("OPEN", bestARNode.getStringValue());
140

  
141
		Assert.assertEquals("doi_________::023bff24ddf2083caec38db12aa0fa01", doc.selectSingleNode("//*[local-name()='objIdentifier']").getStringValue());
142
		// final OutputFormat format = OutputFormat.createPrettyPrint();
143
		// final XMLWriter writer = new XMLWriter(System.out, format);
144
		// writer.write(doc);
145

  
146
	}
147

  
148
	@Test
149
	public void testAsIndexRecordAccessRight() throws Exception {
150
		final ResultEntry pub = new ResultEntry();
151
		pub.setOriginalId("oai:zenodo.org:5109933");
152
		pub.setTitle("TEST TITLE <test>");
153
		pub.getAuthors().add("Michele Artini");
154
		pub.getAuthors().add("Claudio Atzori");
155
		pub.getAuthors().add("Alessia Bardi");
156
		pub.setPublisher("Test publisher");
157
		pub.setDescription("DESCRIPTION & DESCRIPTION & DESCRIPTION & DESCRIPTION & DESCRIPTION & DESCRIPTION & DESCRIPTION ");
158
		pub.setLanguage("ita");
159
		pub.setLicenseCode("CLOSED");
160
		pub.setAccessRightCode("OPEN");
161
		pub.setResourceType("0001");
162
		pub.setUrl("http://test.it/a=1&b=2");
163
		pub.getPids().add(new PidEntry("doi", "10.000/xyz-123"));
164
		pub.getPids().add(new PidEntry("oai", "oai:1234"));
165
		pub.setCollectedFromId("opendoar____::2659");
166
		pub.setHostedById("opendoar____::2659");
167
		pub.getLinksToProjects().add("info:eu-repo/grantAgreement/EC/FP7/283595/EU//OpenAIREplus");
168
		pub.getLinksToProjects().add("info:eu-repo/grantAgreement/EC/FP7/244909/EU/Making Capabilities Work/WorkAble");
169
		pub.getContexts().add("egi::classification::natsc::math::pure");
170
		pub.getContexts().add("egi::classification::natsc::math::stats");
171
		final String xml = toOaf.asOafRecord(pub, ve, lookUpService, "http://oaf/oaf.xsd");
172

  
173
		final Document doc = new SAXReader().read(new StringReader(xml));
174

  
175
		final Node resultNode = doc.selectSingleNode("//oaf:result");
176
		Assert.assertNotNull(resultNode);
177
		final Node origIdNode = resultNode.selectSingleNode("./originalId");
178
		Assert.assertNotNull(origIdNode);
179
		Assert.assertEquals("oai:zenodo.org:5109933", origIdNode.getText());
180
		final Node titleNode = resultNode.selectSingleNode("./title");
181
		Assert.assertNotNull(titleNode);
182
		Assert.assertNotNull(titleNode.getText());
183
		final List<Node> accessRightsNodes = resultNode.selectNodes(".//accessright/@classid");
184
		for (final Node aNode : accessRightsNodes) {
185
			Assert.assertEquals("OPEN", aNode.getStringValue());
186
		}
187
		final Node bestARNode = resultNode.selectSingleNode("./bestaccessright/@classid");
188
		Assert.assertEquals("OPEN", bestARNode.getStringValue());
189

  
190
		Assert.assertEquals("doi_________::6aab886fa2b3aba5a10f0136035e7e8d", doc.selectSingleNode("//*[local-name()='objIdentifier']").getStringValue());
191

  
192
		// final OutputFormat format = OutputFormat.createPrettyPrint();
193
		// final XMLWriter writer = new XMLWriter(System.out, format);
194
		// writer.write(doc);
195

  
196
	}
197

  
198
	@Test
199
	public void testAsORP() throws Exception {
200
		final ResultEntry pub = new ResultEntry();
201
		pub.setOriginalId("ORIG_ID_1234");
202
		pub.setTitle("TEST TITLE <test>");
203
		pub.getAuthors().add("Michele Artini");
204
		pub.getAuthors().add("Claudio Atzori");
205
		pub.getAuthors().add("Alessia Bardi");
206
		pub.setPublisher("Test publisher");
207
		pub.setDescription("DESCRIPTION & DESCRIPTION & DESCRIPTION & DESCRIPTION & DESCRIPTION & DESCRIPTION & DESCRIPTION ");
208
		pub.setLanguage("ita");
209
		pub.setLicenseCode("CLOSED");
210
		pub.setAccessRightCode("OPEN");
211
		pub.setResourceType("0020");
212
		pub.setType("other");
213
		pub.setUrl("http://test.it/a=1&b=2");
214
		pub.getPids().add(new PidEntry("doi", "10.000/xyz-123"));
215
		pub.getPids().add(new PidEntry("oai", "oai:1234"));
216
		pub.setCollectedFromId("test________::zenodo");
217
		pub.setHostedById("test________::UNKNOWN");
218
		pub.getLinksToProjects().add("info:eu-repo/grantAgreement/EC/FP7/283595/EU//OpenAIREplus");
219
		pub.getLinksToProjects().add("info:eu-repo/grantAgreement/EC/FP7/244909/EU/Making Capabilities Work/WorkAble");
220
		pub.getContexts().add("egi::classification::natsc::math::pure");
221
		pub.getContexts().add("egi::classification::natsc::math::stats");
222
		final String xml = toOaf.asOafRecord(pub, ve, lookUpService, "http://oaf/oaf.xsd");
223

  
224
		final Document doc = new SAXReader().read(new StringReader(xml));
225

  
226
		final Node resultNode = doc.selectSingleNode("//oaf:result");
227
		Assert.assertNotNull(resultNode);
228
		Assert.assertEquals("other", resultNode.selectSingleNode("./resulttype/@classid").getStringValue());
229
		final Node origIdNode = resultNode.selectSingleNode("./originalId");
230
		Assert.assertNotNull(origIdNode);
231
		Assert.assertEquals("ORIG_ID_1234", origIdNode.getText());
232
		final Node titleNode = resultNode.selectSingleNode("./title");
233
		Assert.assertNotNull(titleNode);
234
		Assert.assertNotNull(titleNode.getText());
235
		final List<Node> accessRightsNodes = resultNode.selectNodes(".//accessright/@classid");
236
		for (final Node aNode : accessRightsNodes) {
237
			Assert.assertEquals("OPEN", aNode.getStringValue());
238
		}
239
		final Node bestARNode = resultNode.selectSingleNode("./bestaccessright/@classid");
240
		Assert.assertEquals("OPEN", bestARNode.getStringValue());
241

  
242
		// final OutputFormat format = OutputFormat.createPrettyPrint();
243
		// final XMLWriter writer = new XMLWriter(System.out, format);
244
		// writer.write(doc);
245

  
246
	}
247

  
248
	@Test
249
	public void testAsIndexRecord_json() throws Exception {
250
		testAsIndexRecord_json("test_record.json");
251

  
252
	}
253

  
254
	@Test
255
	public void testAsIndexRecord_json_with_greek_chars() throws Exception {
256

  
257
		testAsIndexRecord_json("test_record_with_greek_chars.json");
258

  
259
	}
260

  
261
	@Test
262
	public void testAsIndexRecord_openaireId() throws Exception {
263

  
264
		testAsIndexRecord_json("test_record_openaireId.json");
265

  
266
	}
267

  
268
	@Test(expected = DirecIndexApiException.class)
269
	public void testAsIndexRecord_wrongOpenaireId() throws Exception {
270

  
271
		testAsIndexRecord_json("test_record_wrong_openaireId.json");
272

  
273
	}
274

  
275
	@Test
276
	public void testAsIndexRecord_json_zenodo() throws Exception {
277

  
278
		testAsIndexRecord_json("test_zenodo.json");
279

  
280
	}
281

  
282
	@Test
283
	public void testAsIndexRecord_json_zenodoWithAmpersand() throws Exception {
284

  
285
		testAsIndexRecord_json("test_zenodoAmpersandEverywhere.json");
286

  
287
	}
288

  
289
	@Test
290
	public void testAsIndexRecord_json_software() throws Exception {
291

  
292
		testAsIndexRecord_json("test_record_software.json");
293

  
294
	}
295

  
296
	@Test
297
	public void testAsIndexRecord_json_orp() throws Exception {
298

  
299
		testAsIndexRecord_json("test_record_orp.json");
300

  
301
	}
302

  
303
	private void testAsIndexRecord_json(final String filename) throws Exception {
304
		final ResultEntry pub =
305
			new Gson().fromJson(new InputStreamReader(getClass().getResourceAsStream(filename)), ResultEntry.class);
306

  
307
		final String xml = toOaf.asOafRecord(pub, ve, lookUpService, "http://oaf/oaf.xsd");
308
		// System.out.println(xml);
309

  
310
		final Document doc = new SAXReader().read(new StringReader(xml));
311

  
312
		final OutputFormat format = OutputFormat.createPrettyPrint();
313

  
314
		final XMLWriter writer = new XMLWriter(System.out, format);
315

  
316
		writer.write(doc);
317

  
318
		/* writer.close(); */
319
	}
320

  
321
	@Test
322
	public void testAsIndexRecord_json_zenodocommunities() throws Exception {
323
		testAsIndexRecord_json("test_zenodo_community.json");
324
	}
325

  
326
	@Test
327
	public void testAsIndexRecordFromSandbox_json_zenodocommunities() throws Exception {
328
		testAsIndexRecord_json("test_zenodo_community2.json");
329
	}
330

  
331
	@Test
332
	public void testAsIndexRecordFromZenodo_intelcomp() throws Exception {
333
		testAsIndexRecord_json("test_zenodo_dmp_intelcomp.json");
334
	}
335

  
336
	@Test
337
	public void testEscapeUnicode() {
338
		final String unicodeTxt =
339
			"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$";
340
		System.out.println(StringEscapeUtils.escapeXml11(unicodeTxt));
341
	}
342

  
343
	@Test
344
	public void testAsIndexRecordFromZenodo_doi() throws Exception {
345
		testAsIndexRecord_json("test_zenodo_doi.json");
346
	}
347

  
348
}
modules/dnet-directindex-api/tags/dnet-directindex-api-4.0.2/src/test/resources/eu/dnetlib/openaire/directindex/objects/test_zenodo_doi.json
1
{
2
  "originalId": "oai:zenodo.org:8282705",
3
  "title": "স্বাধীনতার পঁচাত্তর",
4
  "authors": [
5
    "মহম্মদ সেলিম"
6
  ],
7
  "publisher": "Zenodo",
8
  "description": "\u003cp\u003e\u0026nbsp;স্বাধীনতার পঁচাত্তর\u003c/p\u003e",
9
  "language": "ben",
10
  "pids": [
11
    {
12
      "type": "oai",
13
      "value": "oai:zenodo.org:8282705"
14
    },
15
    {
16
      "type": "doi",
17
      "value": "10.5281/zenodo.8282705"
18
    }
19
  ],
20
  "licenseCode": "OPEN",
21
  "type": "publication",
22
  "resourceType": "0001",
23
  "url": "https://zenodo.org/record/8282705",
24
  "collectedFromId": "opendoar____::2659",
25
  "hostedById": "opendoar____::2659",
26
  "contexts": [],
27
  "linksToProjects": []
28
}
modules/dnet-directindex-api/tags/dnet-directindex-api-4.0.2/src/test/resources/eu/dnetlib/openaire/directindex/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/tags/dnet-directindex-api-4.0.2/pom.xml
1
<?xml version="1.0" ?>
2
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
3
	<parent>
4
		<groupId>eu.dnetlib</groupId>
5
		<artifactId>dnet45-parent</artifactId>
6
		<version>1.0.0</version>
7
		<relativePath />
8
	</parent>
9
	<modelVersion>4.0.0</modelVersion>
10
	<groupId>eu.dnetlib</groupId>
11
	<artifactId>dnet-directindex-api</artifactId>
12
	<packaging>jar</packaging>
13
	<version>4.0.2</version>
14
	<scm>
15
		<developerConnection>scm:svn:https://svn.driver.research-infrastructures.eu/driver/dnet45/modules/dnet-directindex-api/tags/dnet-directindex-api-4.0.2</developerConnection>
16
	</scm>
17
	<dependencies>
18
		<dependency>
19
			<groupId>eu.dnetlib</groupId>
20
			<artifactId>dnet-openaireplus-mapping-utils</artifactId>
21
			<version>[7.0.0,8.0.0)</version>
22
			<exclusions>
23
				<exclusion>
24
					<groupId>eu.dnetlib</groupId>
25
					<artifactId>dnet-hadoop-commons</artifactId>
26
				</exclusion>
27
			</exclusions>
28
		</dependency>
29
		<dependency>
30
			<groupId>eu.dnetlib</groupId>
31
			<artifactId>dnet-index-client</artifactId>
32
			<version>[3.0.2,4.0.0)</version>
33
		</dependency>
34
		<dependency>
35
			<groupId>junit</groupId>
36
			<artifactId>junit</artifactId>
37
			<version>${junit.version}</version>
38
			<scope>test</scope>
39
		</dependency>
40
		<dependency>
41
			<groupId>io.springfox</groupId>
42
			<artifactId>springfox-swagger2</artifactId>
43
			<version>${springfox-version}</version>
44
		</dependency>
45
		<dependency>
46
			<groupId>org.mockito</groupId>
47
			<artifactId>mockito-core</artifactId>
48
			<version>1.9.5</version>
49
		</dependency>
50
		<dependency>
51
			<groupId>org.apache.velocity</groupId>
52
			<artifactId>velocity</artifactId>
53
			<version>1.7</version>
54
			<exclusions>
55
				<exclusion>
56
					<artifactId>antlr</artifactId>
57
					<groupId>antlr</groupId>
58
				</exclusion>
59
			</exclusions>
60
		</dependency>
61
		<dependency>
62
			<groupId>org.apache.velocity</groupId>
63
			<artifactId>velocity-tools</artifactId>
64
			<version>2.0</version>
65
			<exclusions>
66
				<exclusion>
67
					<artifactId>antlr</artifactId>
68
					<groupId>antlr</groupId>
69
				</exclusion>
70
			</exclusions>
71
		</dependency>
72
		<dependency>
73
			<groupId>org.springframework</groupId>
74
			<artifactId>spring-context-support</artifactId>
75
			<version>${spring.version}</version>
76
		</dependency>
77
		<dependency>
78
			<groupId>com.fasterxml.jackson.core</groupId>
79
			<artifactId>jackson-annotations</artifactId>
80
			<version>2.9.4</version>
81
		</dependency>
82
    </dependencies>
83

  
84
	<properties>
85
		<springfox-version>2.5.0</springfox-version>
86
	</properties>
87
</project>
modules/dnet-directindex-api/tags/dnet-directindex-api-4.0.2/src/test/resources/eu/dnetlib/openaire/directindex/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/tags/dnet-directindex-api-4.0.2/src/test/resources/eu/dnetlib/openaire/directindex/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/tags/dnet-directindex-api-4.0.2/src/test/resources/eu/dnetlib/openaire/directindex/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/tags/dnet-directindex-api-4.0.2/src/test/resources/eu/dnetlib/openaire/directindex/objects/test_zenodo_community.json
1
{"authors": ["Dag Haug", "Marius J\xf8hndal"],
2
  "collectedFromId": "re3data_____::r3d100010468",
3
  "contexts": ["https://sandbox.zenodo.org/communities/oac-ni","pippo", "egi"],
4
  "description": "<p>Official releases of the PROIEL treebank of ancient Indo-European languages</p>",
5
  "hostedById": "re3data_____::r3d100010468",
6
  "licenseCode": "OPEN",
7
  "originalId": "10.5281/zenodo.11003",
8
  "pids": [{"type": "oai", "value": "oai:zenodo.org:11003"},
9
  {"type": "doi", "value": "10.5281/zenodo.11003"}],
10
  "publisher": "Zenodo",
11
  "resourceType": "0021",
12
  "title": "proiel-treebank: 20140723 version",
13
  "type": "dataset",
14
  "url": "https://zenodo.org/record/11003"}
modules/dnet-directindex-api/tags/dnet-directindex-api-4.0.2/src/test/resources/eu/dnetlib/openaire/directindex/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/tags/dnet-directindex-api-4.0.2/src/main/java/eu/dnetlib/openaire/directindex/api/OpenaireResultSubmitter.java
1
package eu.dnetlib.openaire.directindex.api;
2

  
3
import java.text.SimpleDateFormat;
4
import java.util.Date;
5

  
6
import javax.annotation.PostConstruct;
7
import javax.annotation.Resource;
8

  
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.solr.client.solrj.impl.CloudSolrClient;
13
import org.apache.solr.common.SolrInputDocument;
14
import org.apache.velocity.app.VelocityEngine;
15
import org.springframework.beans.factory.annotation.Autowired;
16
import org.springframework.beans.factory.annotation.Value;
17
import org.springframework.http.HttpStatus;
18
import org.springframework.stereotype.Controller;
19
import org.springframework.web.bind.annotation.ExceptionHandler;
20
import org.springframework.web.bind.annotation.PathVariable;
21
import org.springframework.web.bind.annotation.RequestBody;
22
import org.springframework.web.bind.annotation.RequestMapping;
23
import org.springframework.web.bind.annotation.RequestMethod;
24
import org.springframework.web.bind.annotation.RequestParam;
25
import org.springframework.web.bind.annotation.ResponseBody;
26
import org.springframework.web.bind.annotation.ResponseStatus;
27

  
28
import com.google.gson.Gson;
29

  
30
import eu.dnetlib.common.rmi.DNetRestDocumentation;
31
import eu.dnetlib.enabling.is.lookup.rmi.ISLookUpService;
32
import eu.dnetlib.enabling.locators.UniqueServiceLocator;
33
import eu.dnetlib.functionality.index.solr.feed.StreamingInputDocumentFactory;
34
import eu.dnetlib.miscutils.functional.UnaryFunction;
35
import eu.dnetlib.openaire.directindex.objects.ResultEntry;
36
import eu.dnetlib.openaire.directindex.objects.ResultEntryToOaf;
37
import eu.dnetlib.openaire.directindex.utils.OafToIndexRecordFactory;
38

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

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

  
48
	@Value(value = "${openaire.api.community}")
49
	private String community_api;
50

  
51
	@Value(value = "${openaire.api.dsm}")
52
	private String dsm_api;
53

  
54
	@Value(value = "oaf.schema.location")
55
	private String oafSchemaLocation;
56

  
57
	@Resource
58
	private UniqueServiceLocator serviceLocator;
59

  
60
	@Resource
61
	private OafToIndexRecordFactory oafToIndexRecordFactory;
62

  
63
	@Resource
64
	private RecentResultsQueue recentResultsQueue;
65

  
66
	@Resource(name = "openaireplusApisVelocityEngine")
67
	private VelocityEngine velocityEngine;
68

  
69
	@Resource(name = "indexClientManager")
70
	private IndexClientManager clientManager;
71

  
72
	@Resource(name = "resultSubmitterService")
73
	private ResultSubmitterService submitterService;
74

  
75
	@Autowired
76
	private IndexDSRetriever indexDSRetriever;
77

  
78
	private OpenAIRESubmitterUtils utils;
79

  
80
	@PostConstruct
81
	public void init() {
82
		utils = new OpenAIRESubmitterUtils(community_api, dsm_api);
83
	}
84

  
85
	@RequestMapping(value = {
86
		"/api/admin/autocommit/active"
87
	}, method = RequestMethod.GET)
88
	public @ResponseBody Boolean getAutocommit() throws DirecIndexApiException {
89
		return submitterService.isAutocommitactive();
90
	}
91

  
92
	@RequestMapping(value = {
93
		"/api/admin/autocommit/active"
94
	}, method = RequestMethod.POST)
95
	public @ResponseBody Boolean setAutocommit(@RequestParam(value = "active", required = true) final Boolean active) throws DirecIndexApiException {
96
		submitterService.setAutocommitactive(active);
97
		log.info(String.format("automatic commit, active '%s', frequency '%s'", submitterService.isAutocommitactive(), submitterService.getCommitfrquency()));
98
		return submitterService.isAutocommitactive();
99
	}
100

  
101
	@RequestMapping(value = "/api/admin/evictCache", method = RequestMethod.GET)
102
	@ResponseStatus(value = HttpStatus.OK)
103
	public void evictCache() {
104
		indexDSRetriever.evictCache();
105
	}
106

  
107
	@Deprecated
108
	@RequestMapping(value = {
109
		"/api/publications/feedJson", "/api/results/feedJson"
110
	}, method = RequestMethod.POST)
111
	public @ResponseBody String feedObjectJson(@RequestParam(value = "json", required = true) final String json,
112
		@RequestParam(value = "commit", required = false, defaultValue = "true") final boolean commit) throws DirecIndexApiException {
113
		log.debug(json);
114
		final ResultEntry pub = new Gson().fromJson(json, ResultEntry.class);
115
		return feedObject(pub, commit);
116
	}
117

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

  
126
	}
127

  
128
	@Deprecated
129
	@RequestMapping(value = {
130
		"/api/publications/feedObject"
131
	}, method = RequestMethod.POST)
132
	public @ResponseBody String feedObject(@RequestBody final ResultEntry pub,
133
		@RequestParam(value = "commit", required = false, defaultValue = "true") final boolean commit)
134
		throws DirecIndexApiException {
135
		return feed(pub, commit);
136
	}
137

  
138
	@RequestMapping(value = "/api/result/{openaireId}", method = RequestMethod.DELETE)
139
	public @ResponseBody boolean deleteResultWithOpenaireId(
140
		@PathVariable(value = "openaireId") final String openaireId,
141
		@RequestParam(value = "commit", required = false, defaultValue = "true") final boolean commit) throws DirecIndexApiException {
142

  
143
		return deleteResult(openaireId);
144
	}
145

  
146
	@RequestMapping(value = "/api/results", method = RequestMethod.DELETE)
147
	public @ResponseBody boolean deleteResultWithOriginalId(
148
		@RequestParam(value = "originalId", required = true) final String originalId,
149
		@RequestParam(value = "collectedFromId", required = true) final String collectedFromId,
150
		@RequestParam(value = "commit", required = false, defaultValue = "true") final boolean commit) throws Exception {
151

  
152
		final String openaireId = ResultEntryToOaf.calculateOpenaireId(originalId, collectedFromId, utils);
153
		return deleteResult(openaireId);
154
	}
155

  
156
	@Deprecated
157
	@RequestMapping(value = {
158
		"/api/publications/deleteObject", "/api/results/delete"
159
	}, method = RequestMethod.POST)
160
	public @ResponseBody boolean deleteResultPost(
161
		@RequestParam(value = "originalId", required = true) final String originalId,
162
		@RequestParam(value = "collectedFromId", required = true) final String collectedFromId,
163
		@RequestParam(value = "commit", required = false, defaultValue = "true") final boolean commit) throws Exception {
164

  
165
		final String openaireId = ResultEntryToOaf.calculateOpenaireId(originalId, collectedFromId, utils);
166

  
167
		return deleteResult(openaireId);
168
	}
169

  
170
	@Deprecated
171
	private String feed(final ResultEntry pub, final boolean commit) throws DirecIndexApiException {
172
		return feed(pub);
173
	}
174

  
175
	private String feed(final ResultEntry pub) throws DirecIndexApiException {
176
		log.debug(pub);
177
		try {
178
			final ResultEntryToOaf toOaf = new ResultEntryToOaf(utils);
179
			final IndexDsInfo info = indexDSRetriever.calculateCurrentIndexDsInfo();
180
			final String oafRecord = toOaf.asOafRecord(pub, velocityEngine, serviceLocator.getService(ISLookUpService.class), oafSchemaLocation);
181
			final SolrInputDocument solrDocument =
182
				prepareSolrDocument(oafRecord, info.getIndexDsId(), oafToIndexRecordFactory.newTransformer(info.getFormat()));
183

  
184
			clientManager.getClient(info).add(solrDocument);
185
			recentResultsQueue.add(oafRecord);
186

  
187
			return pub.getOpenaireId();
188
		} catch (final Throwable e) {
189
			log.error("Error saving record", e);
190
			log.debug(pub.toString());
191
			throw new DirecIndexApiException("Error adding publication: " + e.getMessage(), e);
192
		}
193
	}
194

  
195
	private SolrInputDocument prepareSolrDocument(final String record, final String indexDsId, final UnaryFunction<String, String> toIndexRecord) throws DirecIndexApiException {
196
		try {
197
			final StreamingInputDocumentFactory documentFactory = new StreamingInputDocumentFactory();
198
			final String version = new SimpleDateFormat("yyyy-MM-dd'T'hh:mm:ss'Z'").format(new Date());
199
			final String indexRecord = toIndexRecord.evaluate(record);
200
			if (log.isDebugEnabled()) {
201
				log.debug("***************************************\nSubmitting index record:\n" + indexRecord + "\n***************************************\n");
202
			}
203

  
204
			return documentFactory.parseDocument(version, indexRecord, "dnetResult");
205
		} catch (final Throwable e) {
206
			throw new DirecIndexApiException("Error creating solr document", e);
207
		}
208
	}
209

  
210
	private boolean deleteResult(final String openaireId) throws DirecIndexApiException {
211
		try {
212
			final IndexDsInfo info = indexDSRetriever.calculateCurrentIndexDsInfo();
213
			final String query = String.format("objidentifier:\"%s\" OR resultdupid:\"%s\"", openaireId, openaireId);
214
			final CloudSolrClient client = clientManager.getClient(info);
215
			client.deleteByQuery(info.getColl(), query);
216
			log.info("Deleted result with id: " + openaireId + " from: " + info.getIndexBaseUrl());
217

  
218
			recentResultsQueue.remove(openaireId);
219
			return true;
220
		} catch (final Throwable e) {
221
			throw new DirecIndexApiException("Error deleting publication: " + e.getMessage(), e);
222
		}
223
	}
224

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

  
232
	public class ErrorMessage {
233

  
234
		private final String message;
235
		private final String stacktrace;
236

  
237
		public ErrorMessage(final Exception e) {
238
			this(e.getMessage(), ExceptionUtils.getStackTrace(e));
239
		}
240

  
241
		public ErrorMessage(final String message, final String stacktrace) {
242
			this.message = message;
243
			this.stacktrace = stacktrace;
244
		}
245

  
246
		public String getMessage() {
247
			return this.message;
248
		}
249

  
250
		public String getStacktrace() {
251
			return this.stacktrace;
252
		}
253

  
254
	}
255

  
256
}
modules/dnet-directindex-api/tags/dnet-directindex-api-4.0.2/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/tags/dnet-directindex-api-4.0.2/src/test/resources/eu/dnetlib/openaire/directindex/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/tags/dnet-directindex-api-4.0.2/src/test/resources/eu/dnetlib/openaire/directindex/objects/test_zenodo_problems.json
1
{
2
  "authors": ["Milanese, Alessio", "Mende, Daniel", "Zeller, Georg", "Sunagawa, Shinichi"],
3
  "collectedFromId": "re3data_____::r3d100010468",
4
  "description": "<p>We simulated ten human gut metagenomic samples to assess the taxonomic quantification accuracy of the mOTUs tool (<a href=\"http: \// motu-tool.org \/\">link</a>). In this directory you can find the metagenomic samples, the gold standard (used to produce them) and the profiles obtained with four metagenomic profiler tools.</p>\\n\\n<p>Check README.txt for more information.</p>",
5
  "hostedById": "re3data_____::r3d100010468",
6
  "licenseCode": "OPEN",
7
  "originalId": "10.5281/zenodo.1473645",
8
  "pids": [
9
    {"type": "oai", "value": "oai:zenodo.org:1473645"},
10
    {"type": "doi", "value": "10.5281/zenodo.1473645"}
11
  ],
12
  "publisher": "Zenodo",
13
  "resourceType": "0021",
14
  "title": "Simulated Human gut metagenomic samples to benchmark mOTUs v2",
15
  "type": "dataset",
16
  "url": "https://zenodo.org/record/1473645",
17
  "version": "2"
18
}
modules/dnet-directindex-api/tags/dnet-directindex-api-4.0.2/src/test/resources/eu/dnetlib/openaire/directindex/objects/test_zenodo_community2.json
1
{"authors":["test"],
2
  "collectedFromId":"re3data_____::r3d100010468",
3
  "contexts":["https://zenodo.org/communities/oac-ni"],
4
  "description":"<p>test</p>",
5
  "hostedById":"re3data_____::r3d100010468",
6
  "licenseCode":"OPEN",
7
  "originalId":"oai:zenodo.org:315784",
8
  "pids":[{"type":"oai","value":"oai:zenodo.org:315784"},
9
    {"type":"doi","value":"10.5072/zenodo.315784"}],"resourceType":"0020","title":"test","type":"other","url":"https://zenodo.org/record/315784"}
modules/dnet-directindex-api/tags/dnet-directindex-api-4.0.2/src/test/resources/eu/dnetlib/openaire/directindex/utils/openaireLayoutToRecordStylesheet.xsl
1
<xsl:stylesheet version="1.0"
2
                xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:nxsl="http://www.w3.org/1999/XSL/TransformXX">
3

  
4
	<xsl:output omit-xml-declaration="yes" method="xml"/>
5
	<xsl:namespace-alias stylesheet-prefix="nxsl" result-prefix="xsl"/>
6

  
7
	<xsl:param name="format"/>
8

  
9
	<xsl:template match="/">
10
		<xsl:apply-templates select="//LAYOUT"/>
11
	</xsl:template>
12

  
13
	<xsl:template match="LAYOUT">
14
		<nxsl:stylesheet version="1.0"
15
		                 xmlns:dnet="eu.dnetlib.miscutils.functional.xml.DnetXsltFunctions"
16
		                 xmlns:dri="http://www.driver-repository.eu/namespace/dri"
17
		                 exclude-result-prefixes="dnet">
18

  
19
			<nxsl:output version="1.0" omit-xml-declaration="yes"
20
			             method="xml"/>
21

  
22
			<nxsl:variable name="format">
23
				<xsl:value-of select="$format"/>
24
			</nxsl:variable>
25

  
26
			<nxsl:template match="/">
27
				<indexRecord>
28
					<indexRecordIdentifier>
29
						<nxsl:value-of select="//dri:objIdentifier"/>
30
					</indexRecordIdentifier>
31
					<targetFields>
32
						<nxsl:if test="count(//*[local-name()='metadata']/*) &gt; 0">
33
							<xsl:apply-templates select="FIELDS/FIELD[@indexable='true']"/>
34
						</nxsl:if>
35
					</targetFields>
36
					<dnetResult>
37
						<nxsl:copy-of select="/*[local-name()='record']/*[local-name()='result']/*[local-name()='header']"/>
38
						<metadata>
39
							<xsl:apply-templates select="FIELDS/FIELD"
40
							                     mode="result"/>
41
						</metadata>
42
					</dnetResult>
43
				</indexRecord>
44
			</nxsl:template>
45
		</nxsl:stylesheet>
46
	</xsl:template>
47

  
48
	<xsl:template match="FIELD[@indexable='true']">
49
		<xsl:choose>
50
			<xsl:when test="@constant">
51
				<xsl:element name="{@name}">
52
					<xsl:value-of select="@constant"/>
53
				</xsl:element>
54
			</xsl:when>
55
			<xsl:when test="@value and not(@xpath)">
56
				<xsl:choose>
57
					<xsl:when test="contains(@type, 'date')">
58
						<nxsl:variable name="{@name}" select="dnet:normalizeDate(normalize-space({normalize-space(@value)}), false())"/>
59
						<nxsl:if test="string-length(${@name}) &gt; 0">
60
							<nxsl:element name="{@name}">
61
								<nxsl:value-of select="${@name}"/>
62
							</nxsl:element>
63
						</nxsl:if>
64
					</xsl:when>
65
					<xsl:otherwise>
66
						<nxsl:element name="{@name}">
67
							<nxsl:value-of select="{@value}"/>
68
						</nxsl:element>
69
					</xsl:otherwise>
70
				</xsl:choose>
71
			</xsl:when>
72
			<xsl:otherwise>
73
				<xsl:variable name="value">
74
					<xsl:choose>
75
						<xsl:when test="@value">
76
							<xsl:value-of select="@value"/>
77
						</xsl:when>
78
						<xsl:otherwise>
79
							.
80
						</xsl:otherwise>
81
					</xsl:choose>
82
				</xsl:variable>
83
				<nxsl:for-each select="{@xpath}">
84
					<xsl:element name="{@name}">
85
						<xsl:choose>
86
							<xsl:when test="@tokenizable='false'">
87
								<nxsl:value-of select="normalize-space({normalize-space($value)})"/>
88
							</xsl:when>
89
							<xsl:otherwise>
90
								<nxsl:value-of select="{normalize-space($value)}"/>
91
							</xsl:otherwise>
92
						</xsl:choose>
93
					</xsl:element>
94
				</nxsl:for-each>
95
			</xsl:otherwise>
96
		</xsl:choose>
97
	</xsl:template>
98

  
99

  
100
	<xsl:template match="FIELD" mode="result">
101
		<xsl:if test="@result='true'">
102
			<nxsl:copy-of select="{@xpath}"/>
103
		</xsl:if>
104
	</xsl:template>
105

  
106
	<xsl:template match="FIELD" mode="header">
107
		<xsl:if test="@header='true'">
108
			<nxsl:copy-of select="{@xpath}"/>
109
		</xsl:if>
110
	</xsl:template>
111

  
112
</xsl:stylesheet>
modules/dnet-directindex-api/tags/dnet-directindex-api-4.0.2/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
11
log4j.logger.eu.dnetlib.openaire.directindex.api=DEBUG
modules/dnet-directindex-api/tags/dnet-directindex-api-4.0.2/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.Collection;
6
import java.util.HashMap;
7
import java.util.HashSet;
8
import java.util.List;
9
import java.util.Map;
10
import java.util.stream.Collectors;
11

  
12
import org.apache.commons.lang.StringUtils;
13
import org.springframework.web.client.RestClientException;
14
import org.springframework.web.client.RestTemplate;
15

  
16
import com.google.common.collect.Sets;
17

  
18
import eu.dnetlib.miscutils.functional.hash.Hashing;
19
import eu.dnetlib.openaire.directindex.objects.DatasourceEntry;
20
import eu.dnetlib.openaire.directindex.objects.DsmSearchRequest;
21
import eu.dnetlib.openaire.directindex.objects.DsmSearchResponse;
22
import eu.dnetlib.openaire.directindex.objects.ZenodoContextList;
23

  
24
/**
25
 * Created by michele on 15/01/16.
26
 */
27
public class OpenAIRESubmitterUtils {
28

  
29
	private static final org.apache.commons.logging.Log log = org.apache.commons.logging.LogFactory.getLog(OpenAIRESubmitterUtils.class);
30
	private static final String ZENODO_COMMUNITY = "zenodo.org/communities/";
31
	private final String community_api;
32
	private final String dsm_api;
33

  
34
	public OpenAIRESubmitterUtils(final String community_api, final String dsm_api) {
35
		this.community_api = community_api;
36
		this.dsm_api = dsm_api;
37
	}
38

  
39
	public DatasourceEntry findDatasource(final String dsId) {
40
		final RestTemplate rt = new RestTemplate();
41
		final String url = dsm_api + "/searchdetails/0/1?requestSortBy=id&order=ASCENDING";
42
		try {
43
			final DsmSearchResponse res = rt.postForObject(url, new DsmSearchRequest(dsId), DsmSearchResponse.class);
44
			return res.getDatasourceInfo()
45
				.stream()
46
				.map(ds -> new DatasourceEntry(ds.getId(), ds.getOfficialname(), ds.getNamespaceprefix()))
47
				.findFirst()
48
				.orElse(null);
49
		} catch (final RestClientException rce) {
50
			log.error("Unable to get object for " + url);
51
			return null;
52
		}
53
	}
54

  
55
	public Map<String, String> calculateProjectInfo(final String link) {
56
		final Map<String, String> info = new HashMap<>();
57
		final String[] arr = link.split("/");
58
		// info:eu-repo/grantAgreement/EC/FP7/244909/EU/Making Capabilities Work/WorkAble
59

  
60
		if (arr.length > 4) {
61
			final String acronym = arr.length > 7 ? arr[7] : "";
62
			final String title = arr.length > 6 ? StringUtils.isNotBlank(arr[6]) ? arr[6] : acronym : "";
63
			final String jurisdiction = arr.length > 5 ? arr[5] : "";
64
			final String funderId = calculateFunderId(arr[2], arr[3]);
65
			final String funderShortName = fixFunderShortName(arr[2]);
66
			final String fundingName = fixFundingName(funderShortName, arr[3]);
67
			info.put("id", calculateProjectId(arr[2], arr[3], arr[4]));
68
			info.put("funderShortName", fixFunderShortName(arr[2]));
69
			info.put("fundingName", fundingName);
70
			info.put("code", unescape(arr[4]));
71
			info.put("jurisdiction", jurisdiction);
72
			info.put("title", title);
73
			info.put("acronym", acronym);
74
			info.put("funderId", funderId);
75
			info.put("funderName", calculateFunderName(arr[2]));
76
			if (StringUtils.isNotBlank(arr[3])) {
77
				info.put("fundingId", funderId + "::" + fundingName);
78
			}
79
		}
80
		return info;
81
	}
82

  
83
	// TODO: remove me when Zenodo ingests the good UKRI projects
84
	protected String fixFunderShortName(final String funderShortName) {
85
		switch (funderShortName) {
86
		case "RCUK":
87
			return "UKRI";
88
		default:
89
			return funderShortName;
90
		}
91
	}
92

  
93
	protected String calculateFunderPrefix(final String funderShortName, final String funding) {
94
		switch (funderShortName.toLowerCase()) {
95
		case "chist-era":
96
			return "chistera____::";
97
		case "conicyt":
98
			return "conicytf____::";
99
		case "dfg":
100
			return "dfgf________::";
101
		case "ec":
102
			switch (funding.toLowerCase()) {
103
			case "fp7":
104
				return "corda_______::";
105
			case "h2020":
106
				return "corda__h2020::";
107
			default:
108
				return "corda_____he::";
109
			}
110
		case "eea":
111
			return "euenvagency_::";
112
		case "hrzz":
113
		case "mzos":
114
			return "irb_hr______::";
115
		case "tara":
116
			return "taraexp_____::";
117
		case "tubitak":
118
			return "tubitakf____::";
119
		case "rcuk":
120
			return "ukri________::";
121
		default:
122
			String prefix = funderShortName.toLowerCase();
123
			// ensure we have 12 chars
124
			while (prefix.length() < 12) {
125
				prefix += "_";
126
			}
127
			return prefix + "::";
128
		}
129
	}
130

  
131
	protected String calculateProjectId(final String funderShortName, final String funding, final String code) {
132
		final String suffix = Hashing.md5(unescape(code));
133
		final String funderPrefix = calculateFunderPrefix(funderShortName, funding);
134
		return funderPrefix + suffix;
135
	}
136

  
137
	private String unescape(final String code) {
138
		return code.replace("%2F", "/");
139
	}
140

  
141
	protected String calculateFunderId(final String funderShortName, final String funding) {
142
		switch (funderShortName.toLowerCase()) {
143
		case "ec":
144
			return "ec__________::EC";
145
		default:
146
			final String fixedFunderShortName = fixFunderShortName(funderShortName);
147
			final String prefix = calculateFunderPrefix(fixedFunderShortName, funding);
148
			return prefix + fixedFunderShortName.toUpperCase();
149
		}
150
	}
151

  
152
	protected String calculateFunderName(final String funderShortName) {
153

  
154
		switch (funderShortName.toLowerCase()) {
155
		case "aff":
156
		case "aka":
157
			return "Academy of Finland";
158
		case "anr":
159
			return "French National Research Agency (ANR)";
160
		case "arc":
161
			return "Australian Research Council (ARC)";
162
		case "asap":
163
			return "Aligning Science Across Parkinson's";
164
		case "chist-era":
165
			return "CHIST-ERA";
166
		case "cihr":
167
			return "Canadian Institutes of Health Research";
168
		case "conicyt":
169
			return "Comisión Nacional de Investigación Científica y Tecnológica";
170
		case "dfg":
171
			return "Deutsche Forschungsgemeinschaft";
172
		case "ec":
173
			return "European Commission";
174
		case "eea":
175
			return "European Environment Agency";
176
		case "fct":
177
			return "Fundação para a Ciência e a Tecnologia, I.P.";
178
		case "fwf":
179
			return "Austrian Science Fund (FWF)";
180
		case "gsrt":
181
			return "General Secretariat of Research and Technology (GSRT)";
182
		case "hrzz":
183
			return "Croatian Science Foundation (CSF)";
184
		case "innoviris":
185
			return "INNOVIRIS";
186
		case "mestd":
187
			return "Ministry of Education, Science and Technological Development of Republic of Serbia";
188
		case "miur":
189
			return "Ministero dell'Istruzione dell'Università e della Ricerca";
190
		case "mzos":
191
			return "Ministry of Science, Education and Sports of the Republic of Croatia (MSES)";
192
		case "nhmrc":
193
			return "National Health and Medical Research Council (NHMRC)";
194
		case "nih":
195
			return "National Institutes of Health";
196
		case "nsf":
197
			return "National Science Foundation";
198
		case "nserc":
199
			return "Natural Sciences and Engineering Research Council of Canada";
200
		case "nwo":
201
			return "Netherlands Organisation for Scientific Research (NWO)";
202
		case "rcuk":
203
		case "ukri":
204
			return "UK Research and Innovation";
205
		case "rif":
206
		case "rpf":
207
			return "Research and Innovation Foundation";
208
		case "rsf":
209
			return "Russian Science Foundation";
210
		case "sfi":
211
			return "Science Foundation Ireland";
212
		case "sgov":
213
			return "Gobierno de España";
214
		case "snsf":
215
			return "Swiss National Science Foundation";
216
		case "sshrc":
217
			return "Social Sciences and Humanities Research Council";
218
		case "tara":
219
			return "Tara Expeditions Foundation";
220
		case "tubitak":
221
			return "Türkiye Bilimsel ve Teknolojik Araştırma Kurumu";
222
		case "wt":
223
			return "Wellcome Trust";
224
		default:
225
			log.error("Funder short name '" + funderShortName + "' not managed");
226
			return "";
227
		}
228
	}
229

  
230
	protected String fixFundingName(final String funderShortName, final String fundingName) {
231
		switch (funderShortName) {
232
		case "EC":
233
			if (fundingName.toLowerCase().startsWith("horizon 2020")) { return "H2020"; }
234
			if (fundingName.toLowerCase().startsWith("horizon europe")) { return "HE"; }
235
		default:
236
			return fundingName;
237
		}
238
	}
239

  
240
	public Collection<String> translateZenodoCommunity(final String community) {
241
		if (community.contains(ZENODO_COMMUNITY)) {
242
			final String context = community.substring(community.lastIndexOf("/") + 1);
243
			final RestTemplate rt = new RestTemplate();
244
			try {
245
				return new HashSet<>(rt.getForObject(community_api + context + "/openairecommunities", ZenodoContextList.class)
246
					.getOpenAirecommunitylist());
247
			} catch (final RestClientException rce) {
248
				log.error("Unable to get object for " + community_api + context + "/openairecommunities");
249
				log.error(rce.getMessage());
250
				return new HashSet<>();
251
			}
252
		} else {
253
			return Sets.newHashSet(community);
254
		}
255
	}
256

  
257
	private ContextInfo createContextInfo(final String[] arr, final int pos, final Map<String, String> labelMap) {
258
		final StringWriter id = new StringWriter();
259
		id.write(arr[0]);
260
		for (int i = 0; i < pos; i++) {
261
			id.write("::");
262
			id.write(arr[i + 1]);
263
		}
264
		final String label = labelMap.get(id.toString());
265
		final String elem = pos == 0 ? "context" : pos == 1 ? "category" : "concept";
266
		final ContextInfo info = new ContextInfo(elem, id.toString(), label);
267
		if (pos + 1 < arr.length) {
268
			info.getChildren().add(createContextInfo(arr, pos + 1, labelMap));
269
		}
270
		return info;
271
	}
272

  
273
	public List<ContextInfo> processContexts(final List<String> zenodoCommunities, final Map<String, String> labelMap) {
274
		return zenodoCommunities.stream()
275
			.map(c -> translateZenodoCommunity(c))
276
			.flatMap(coll -> coll.stream())
277
			.map(ctx -> createContextInfo(ctx.split("::"), 0, labelMap))
278
			.filter(info -> StringUtils.isNotBlank(info.getLabel()))
279
			.collect(Collectors.toList());
280
	}
281

  
282
	public class ContextInfo {
283

  
284
		private String elem;
285
		private String id;
286
		private String label;
287
		private List<ContextInfo> children = new ArrayList<>();
288

  
289
		public ContextInfo(final String elem,
290
			final String id, final String label) {
291
			this.elem = elem;
292
			this.id = id;
293
			this.label = label;
294
		}
295

  
296
		public String getElem() {
297
			return elem;
298
		}
299

  
300
		public void setElem(final String elem) {
301
			this.elem = elem;
302
		}
303

  
304
		public String getId() {
305
			return id;
306
		}
307

  
308
		public void setId(final String id) {
309
			this.id = id;
310
		}
311

  
312
		public List<ContextInfo> getChildren() {
313
			return children;
314
		}
315

  
316
		public void setChildren(final List<ContextInfo> children) {
317
			this.children = children;
318
		}
319

  
320
		public boolean isRoot() {
321
			return elem.equals("context");
322
		}
323

  
324
		public String getLabel() {
325
			return label;
326
		}
327

  
328
		public void setLabel(final String label) {
329
			this.label = label;
330
		}
331
	}
332

  
333
}
modules/dnet-directindex-api/tags/dnet-directindex-api-4.0.2/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 com.mongodb.client.model.IndexOptions;
9
import eu.dnetlib.miscutils.datetime.DateUtils;
10
import org.apache.commons.logging.Log;
11
import org.apache.commons.logging.LogFactory;
12
import org.dom4j.io.SAXReader;
13
import org.springframework.beans.factory.annotation.Required;
14

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

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

  
22
	private DB db;
23
	private String collection;
... This diff was truncated because it exceeds the maximum size that can be displayed.

Also available in: Unified diff