Project

General

Profile

« Previous | Next » 

Revision 60579

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

View differences:

modules/dnet-directindex-api/tags/dnet-directindex-api-2.2.1/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-2.2.1/src/test/java/eu/dnetlib/msro/openaireplus/api/OpenAIRESubmitterUtilsTest.java
1
package eu.dnetlib.msro.openaireplus.api;
2

  
3
import java.util.ArrayList;
4
import java.util.List;
5
import java.util.Map;
6
import java.util.Map.Entry;
7

  
8
import org.junit.Assert;
9
import org.junit.Test;
10

  
11
import eu.dnetlib.openaire.directindex.api.OpenAIRESubmitterUtils;
12

  
13
/**
14
 * Created by Alessia Bardi on 26/05/2017.
15
 *
16
 * @author Alessia Bardi
17
 */
18
public class OpenAIRESubmitterUtilsTest {
19

  
20
	private OpenAIRESubmitterUtils utils = new OpenAIRESubmitterUtils(
21
			"http://beta.services.openaire.eu/openaire/community/"
22
	);
23

  
24
	final String fullProject = "info:eu-repo/grantAgreement/EC/FP7/244909/EU/Making Capabilities Work/WorkAble";
25
	final String minimalProject = "info:eu-repo/grantAgreement/EC/FP7/244909///WorkAble";
26
	final String onlyId = "info:eu-repo/grantAgreement/EC/FP7/244909/";
27
	final String onlyTitle = "info:eu-repo/grantAgreement/EC/FP7/244909/EU/Making Capabilities Work";
28
	final String escapedId = "info:eu-repo/grantAgreement/RCUK//NE%2FL003066%2F1/";
29

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

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

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

  
48
	@Test
49
	public void testCalculateProjectInfoMinimalAcro() {
50
		final Map<String, String> project = utils.calculateProjectInfo(minimalProject);
51
		print(project);
52
	}
53

  
54
	@Test
55
	public void testCalculateProjectInfoOnlyTitle() {
56
		final Map<String, String> project = utils.calculateProjectInfo(onlyTitle);
57
		print(project);
58
	}
59

  
60
	@Test
61
	public void testJerusalem(){
62
		String s = "info:eu-repo/grantAgreement/EC/FP7/337895/EU/Opening Jerusalem Archives: For a connected History of ‘Citadinité’ in the Holy City (1840-1940)/OPEN-JERUSALEM";
63
		final Map<String, String> project = utils.calculateProjectInfo(s);
64
		print(project);
65
	}
66

  
67
	private void print(final Map<String, String> map) {
68
		for (final Entry e : map.entrySet()) {
69
			System.out.println(e.getKey() + " = " + e.getValue());
70
		}
71
	}
72

  
73
	@Test
74
	public void testContext(){
75
		List<String> contexts = new ArrayList<>();
76
		contexts.add("https://zenodo.org/communities/dimpo");
77
		contexts.add("https://zenodo.org/communities/aoo_beopen");
78
		List<OpenAIRESubmitterUtils.ContextInfo> tmp = utils.processContexts(contexts);
79

  
80
		Assert.assertEquals(2, tmp.size());
81

  
82
		Assert.assertTrue(tmp.get(0).getId().equals("dh-ch") || tmp.get(1).getId().equalsIgnoreCase("dh-ch"));
83
		Assert.assertTrue(tmp.get(0).getId().equals("dariah") || tmp.get(1).getId().equalsIgnoreCase("dariah"));
84
	}
85
}
modules/dnet-directindex-api/tags/dnet-directindex-api-2.2.1/src/test/java/eu/dnetlib/msro/openaireplus/api/objects/ResultEntryTest.java
1
package eu.dnetlib.msro.openaireplus.api.objects;
2

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

  
20
import java.io.InputStreamReader;
21
import java.io.StringReader;
22
import java.util.ArrayList;
23
import java.util.Arrays;
24
import java.util.Properties;
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
	private final String community_api = "https://dev-openaire.d4science.org/openaire/community/";
38

  
39
	@Mock
40
	private ISLookUpService lookUpService;
41

  
42
	@Before
43
	public void setUp() throws Exception {
44

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

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

  
78
		when(lookUpService.getResourceProfileByQuery(anyString())).thenAnswer(invocation -> "REPO NAME @@@ repo________");
79
	}
80

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

  
107
		final Document doc = new SAXReader().read(new StringReader(xml));
108

  
109
		final OutputFormat format = OutputFormat.createPrettyPrint();
110

  
111
		final XMLWriter writer = new XMLWriter(System.out, format);
112

  
113
		writer.write(doc);
114

  
115
		/* writer.close(); */
116

  
117
	}
118

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

  
144
		final Document doc = new SAXReader().read(new StringReader(xml));
145

  
146
		final OutputFormat format = OutputFormat.createPrettyPrint();
147

  
148
		final XMLWriter writer = new XMLWriter(System.out, format);
149

  
150
		writer.write(doc);
151

  
152
		/* writer.close(); */
153

  
154
	}
155

  
156
	@Test
157
	public void testAsORP() throws Exception {
158
		final ResultEntry pub = new ResultEntry();
159
		pub.setOriginalId("ORIG_ID_1234");
160
		pub.setTitle("TEST TITLE <test>");
161
		pub.getAuthors().add("Michele Artini");
162
		pub.getAuthors().add("Claudio Atzori");
163
		pub.getAuthors().add("Alessia Bardi");
164
		pub.setPublisher("Test publisher");
165
		pub.setDescription("DESCRIPTION & DESCRIPTION & DESCRIPTION & DESCRIPTION & DESCRIPTION & DESCRIPTION & DESCRIPTION ");
166
		pub.setLanguage("ita");
167
		pub.setLicenseCode("CLOSED");
168
		pub.setAccessRightCode("OPEN");
169
		pub.setResourceType("0020");
170
		pub.setType("other");
171
		pub.setUrl("http://test.it/a=1&b=2");
172
		pub.getPids().add(new PidEntry("doi", "10.000/xyz-123"));
173
		pub.getPids().add(new PidEntry("oai", "oai:1234"));
174
		pub.setCollectedFromId("test________::zenodo");
175
		pub.setHostedById("test________::UNKNOWN");
176
		pub.getLinksToProjects().add("info:eu-repo/grantAgreement/EC/FP7/283595/EU//OpenAIREplus");
177
		pub.getLinksToProjects().add("info:eu-repo/grantAgreement/EC/FP7/244909/EU/Making Capabilities Work/WorkAble");
178
		pub.getContexts().add("egi::classification::natsc::math::pure");
179
		pub.getContexts().add("egi::classification::natsc::math::stats");
180
		final String xml = pub.asOafRecord(ve, lookUpService, "http://oaf/oaf.xsd",community_api);
181

  
182
		final Document doc = new SAXReader().read(new StringReader(xml));
183

  
184
		final OutputFormat format = OutputFormat.createPrettyPrint();
185

  
186
		final XMLWriter writer = new XMLWriter(System.out, format);
187

  
188
		writer.write(doc);
189

  
190
		/* writer.close(); */
191

  
192
	}
193

  
194
	@Test
195
	public void testAsIndexRecord_json() throws Exception {
196
		testAsIndexRecord_json("test_record.json");
197

  
198
	}
199

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

  
203
		testAsIndexRecord_json("test_record_with_greek_chars.json");
204

  
205
	}
206

  
207
	@Test
208
	public void testAsIndexRecord_openaireId() throws Exception {
209

  
210
		testAsIndexRecord_json("test_record_openaireId.json");
211

  
212
	}
213

  
214
	@Test(expected = DirecIndexApiException.class)
215
	public void testAsIndexRecord_wrongOpenaireId() throws Exception {
216

  
217
		testAsIndexRecord_json("test_record_wrong_openaireId.json");
218

  
219
	}
220

  
221
	@Test
222
	public void testAsIndexRecord_json_zenodo() throws Exception {
223

  
224
		testAsIndexRecord_json("test_zenodo.json");
225

  
226
	}
227

  
228
	@Test
229
	public void testAsIndexRecord_json_zenodoWithAmpersand() throws Exception {
230

  
231
		testAsIndexRecord_json("test_zenodoAmpersandEverywhere.json");
232

  
233
	}
234

  
235
	@Test
236
	public void testAsIndexRecord_json_software() throws Exception {
237

  
238
		testAsIndexRecord_json("test_record_software.json");
239

  
240
	}
241

  
242
	@Test
243
	public void testAsIndexRecord_json_orp() throws Exception {
244

  
245
		testAsIndexRecord_json("test_record_orp.json");
246

  
247
	}
248

  
249
	private void testAsIndexRecord_json(final String filename) throws Exception {
250
		final ResultEntry pub =
251
				new Gson().fromJson(new InputStreamReader(getClass().getResourceAsStream(filename)), ResultEntry.class);
252

  
253

  
254
		final String xml = pub.asOafRecord(ve, lookUpService, "http://oaf/oaf.xsd",community_api);
255
		//System.out.println(xml);
256

  
257
		final Document doc = new SAXReader().read(new StringReader(xml));
258

  
259
		final OutputFormat format = OutputFormat.createPrettyPrint();
260

  
261
		final XMLWriter writer = new XMLWriter(System.out, format);
262

  
263
		writer.write(doc);
264

  
265
		/* writer.close(); */
266
	}
267

  
268
	@Test
269
	public void testAsIndexRecord_json_zenodocommunities()throws Exception{
270
		testAsIndexRecord_json("test_zenodo_community.json");
271
	}
272

  
273
	@Test
274
	public void testAsIndexRecordFromSandbox_json_zenodocommunities()throws Exception{
275
		testAsIndexRecord_json("test_zenodo_community2.json");
276
	}
277

  
278
	@Test
279
	public void testEscapeUnicode() {
280
		final String unicodeTxt =
281
				"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$";
282
		System.out.println(StringEscapeUtils.escapeXml11(unicodeTxt));
283
	}
284

  
285
}
modules/dnet-directindex-api/tags/dnet-directindex-api-2.2.1/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/tags/dnet-directindex-api-2.2.1/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/tags/dnet-directindex-api-2.2.1/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/tags/dnet-directindex-api-2.2.1/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/tags/dnet-directindex-api-2.2.1/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/tags/dnet-directindex-api-2.2.1/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/tags/dnet-directindex-api-2.2.1/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/tags/dnet-directindex-api-2.2.1/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/tags/dnet-directindex-api-2.2.1/src/test/resources/eu/dnetlib/msro/openaireplus/api/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-2.2.1/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/tags/dnet-directindex-api-2.2.1/src/test/resources/eu/dnetlib/msro/openaireplus/api/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"],
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-2.2.1/src/test/resources/eu/dnetlib/msro/openaireplus/api/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-2.2.1/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/tags/dnet-directindex-api-2.2.1/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/tags/dnet-directindex-api-2.2.1/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/tags/dnet-directindex-api-2.2.1/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/tags/dnet-directindex-api-2.2.1/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
import javax.annotation.Resource;
6

  
7
import com.google.gson.Gson;
8
import eu.dnetlib.common.rmi.DNetRestDocumentation;
9
import eu.dnetlib.data.index.CloudIndexClientException;
10
import eu.dnetlib.enabling.is.lookup.rmi.ISLookUpService;
11
import eu.dnetlib.enabling.locators.UniqueServiceLocator;
12
import eu.dnetlib.functionality.index.solr.feed.StreamingInputDocumentFactory;
13
import eu.dnetlib.miscutils.functional.UnaryFunction;
14
import eu.dnetlib.openaire.directindex.objects.ResultEntry;
15
import eu.dnetlib.openaire.directindex.utils.OafToIndexRecordFactory;
16
import org.apache.commons.lang.exception.ExceptionUtils;
17
import org.apache.commons.logging.Log;
18
import org.apache.commons.logging.LogFactory;
19
import org.apache.solr.client.solrj.impl.CloudSolrClient;
20
import org.apache.solr.common.SolrInputDocument;
21
import org.apache.velocity.app.VelocityEngine;
22
import org.springframework.beans.factory.annotation.Autowired;
23
import org.springframework.beans.factory.annotation.Value;
24
import org.springframework.http.HttpStatus;
25
import org.springframework.stereotype.Controller;
26
import org.springframework.web.bind.annotation.*;
27

  
28
/**
29
 * Created by michele on 11/11/15.
30
 */
31
@Controller
32
@DNetRestDocumentation
33
public class OpenaireResultSubmitter {
34

  
35
	private static final Log log = LogFactory.getLog(OpenaireResultSubmitter.class);
36

  
37
	@Value(value = "${openaire.api.community}")
38
	private String community_api;
39

  
40
	@Value(value = "oaf.schema.location")
41
	private String oafSchemaLocation;
42

  
43
	@Resource
44
	private UniqueServiceLocator serviceLocator;
45

  
46
	@Resource
47
	private OafToIndexRecordFactory oafToIndexRecordFactory;
48

  
49
	@Resource
50
	private RecentResultsQueue recentResultsQueue;
51

  
52
	@Resource(name = "openaireplusApisVelocityEngine")
53
	private VelocityEngine velocityEngine;
54

  
55
	@Resource(name = "indexClientManager")
56
	private IndexClientManager clientManager;
57

  
58
	@Resource(name = "resultSubmitterService")
59
	private ResultSubmitterService submitterService;
60

  
61
	@Autowired
62
	private IndexDSRetriever indexDSRetriever;
63

  
64
	@RequestMapping(value = { "/api/admin/autocommit/active" }, method = RequestMethod.GET)
65
	public @ResponseBody Boolean getAutocommit() throws DirecIndexApiException {
66
		return submitterService.isAutocommitactive();
67
	}
68

  
69
	@RequestMapping(value = { "/api/admin/autocommit/active" }, method = RequestMethod.POST)
70
	public @ResponseBody Boolean setAutocommit(@RequestParam(value = "active", required = true) final Boolean active) throws DirecIndexApiException {
71
		submitterService.setAutocommitactive(active);
72
		log.info(String.format("automatic commit, active '%s', frequency '%s'", submitterService.isAutocommitactive(), submitterService.getCommitfrquency()));
73
		return submitterService.isAutocommitactive();
74
	}
75

  
76
	@RequestMapping(value="/api/admin/evictCache", method=RequestMethod.GET)
77
	@ResponseStatus(value = HttpStatus.OK)
78
	public void evictCache(){
79
		indexDSRetriever.evictCache();
80
	}
81

  
82
	@Deprecated
83
	@RequestMapping(value = { "/api/publications/feedJson", "/api/results/feedJson" }, method = RequestMethod.POST)
84
	public @ResponseBody String feedObjectJson(@RequestParam(value = "json", required = true) final String json,
85
			@RequestParam(value = "commit", required = false, defaultValue = "true") final boolean commit) throws DirecIndexApiException {
86
		log.debug(json);
87
		final ResultEntry pub = new Gson().fromJson(json, ResultEntry.class);
88
		return feedObject(pub, commit);
89
	}
90

  
91

  
92
	@RequestMapping(value = { "/api/results/feedObject" }, method = RequestMethod.POST)
93
	public @ResponseBody String feedResult(@RequestBody final ResultEntry pub,
94
			@RequestParam(value = "commit", required = false, defaultValue = "true") final boolean commit)
95
			throws DirecIndexApiException {
96
		return feed(pub,commit);
97

  
98
	}
99

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

  
108

  
109
	@RequestMapping(value = "/api/result/{openaireId}", method = RequestMethod.DELETE)
110
	public @ResponseBody boolean deleteResultWithOpenaireId(
111
			@PathVariable(value = "openaireId") final String openaireId,
112
			@RequestParam(value = "commit", required = false, defaultValue = "true") final boolean commit) throws DirecIndexApiException {
113

  
114
		return deleteResult(openaireId);
115
	}
116

  
117
	@RequestMapping(value = "/api/results", method = RequestMethod.DELETE)
118
	public @ResponseBody boolean deleteResultWithOriginalId(
119
			@RequestParam(value = "originalId", required = true) final String originalId,
120
			@RequestParam(value = "collectedFromId", required = true) final String collectedFromId,
121
			@RequestParam(value = "commit", required = false, defaultValue = "true") final boolean commit) throws Exception {
122

  
123
		final String openaireId = ResultEntry.calculateOpenaireId(originalId, collectedFromId, serviceLocator.getService(ISLookUpService.class));
124
		return deleteResult(openaireId);
125
	}
126

  
127
	@Deprecated
128
	@RequestMapping(value = { "/api/publications/deleteObject", "/api/results/delete" }, method = RequestMethod.POST)
129
	public @ResponseBody boolean deleteResultPost(
130
			@RequestParam(value = "originalId", required = true) final String originalId,
131
			@RequestParam(value = "collectedFromId", required = true) final String collectedFromId,
132
			@RequestParam(value = "commit", required = false, defaultValue = "true") final boolean commit) throws Exception {
133

  
134
		final String openaireId = ResultEntry.calculateOpenaireId(originalId, collectedFromId, serviceLocator.getService(ISLookUpService.class));
135
		return deleteResult(openaireId);
136
	}
137

  
138
	@Deprecated
139
	private String feed(final ResultEntry pub, final boolean commit) throws DirecIndexApiException {
140
		return feed(pub);
141
	}
142

  
143
	private String feed(final ResultEntry pub) throws DirecIndexApiException {
144
		log.debug(pub);
145
		try {
146
			final IndexDsInfo info = indexDSRetriever.calculateCurrentIndexDsInfo();
147
			final String oafRecord = pub.asOafRecord(velocityEngine, serviceLocator.getService(ISLookUpService.class), oafSchemaLocation, community_api);
148
			final SolrInputDocument solrDocument = prepareSolrDocument(oafRecord, info.getIndexDsId(), oafToIndexRecordFactory.newTransformer(info.getFormat()));
149

  
150
			clientManager.getClient(info).add(solrDocument);
151
			recentResultsQueue.add(oafRecord);
152

  
153
			return pub.getOpenaireId();
154
		} catch (final Throwable e) {
155
			log.error("Error saving record", e);
156
			log.debug(pub.toString());
157
			throw new DirecIndexApiException("Error adding publication: " + e.getMessage(), e);
158
		}
159
	}
160

  
161
	private SolrInputDocument prepareSolrDocument(String record, String indexDsId, UnaryFunction<String, String> toIndexRecord) throws CloudIndexClientException {
162
		try {
163
			StreamingInputDocumentFactory documentFactory = new StreamingInputDocumentFactory();
164
			String version = (new SimpleDateFormat("yyyy-MM-dd'T'hh:mm:ss'Z'")).format(new Date());
165
			String indexRecord = (String)toIndexRecord.evaluate(record);
166
			if (log.isDebugEnabled()) {
167
				log.debug("***************************************\nSubmitting index record:\n" + indexRecord + "\n***************************************\n");
168
			}
169

  
170
			return documentFactory.parseDocument(version, indexRecord, indexDsId, "dnetResult");
171
		} catch (Throwable e) {
172
			throw new CloudIndexClientException("Error creating solr document", e);
173
		}
174
	}
175

  
176
	private boolean deleteResult(final String openaireId) throws DirecIndexApiException {
177
		try {
178
			IndexDsInfo info = indexDSRetriever.calculateCurrentIndexDsInfo();
179
			String query = String.format("objidentifier:\"%s\" OR resultdupid:\"%s\"", openaireId, openaireId);
180
			final CloudSolrClient client = clientManager.getClient(info);
181
			client.deleteByQuery(info.getColl(), query);
182
			log.info("Deleted result with id: " + openaireId + " from: " + info.getIndexBaseUrl());
183

  
184
			recentResultsQueue.remove(openaireId);
185
			return true;
186
		} catch (Throwable e) {
187
			throw new DirecIndexApiException("Error deleting publication: " + e.getMessage(), e);
188
		}
189
	}
190

  
191
	@ExceptionHandler(Exception.class)
192
	@ResponseStatus(value = HttpStatus.INTERNAL_SERVER_ERROR)
193
	public @ResponseBody ErrorMessage handleException(final Exception e) {
194
		log.error("Error in direct index API", e);
195
		return new ErrorMessage(e);
196
	}
197

  
198
	public class ErrorMessage {
199

  
200
		private final String message;
201
		private final String stacktrace;
202

  
203
		public ErrorMessage(final Exception e) {
204
			this(e.getMessage(), ExceptionUtils.getStackTrace(e));
205
		}
206

  
207
		public ErrorMessage(final String message, final String stacktrace) {
208
			this.message = message;
209
			this.stacktrace = stacktrace;
210
		}
211

  
212
		public String getMessage() {
213
			return this.message;
214
		}
215

  
216
		public String getStacktrace() {
217
			return this.stacktrace;
218
		}
219

  
220
	}
221

  
222
}
modules/dnet-directindex-api/tags/dnet-directindex-api-2.2.1/src/main/java/eu/dnetlib/openaire/directindex/api/IndexClientManager.java
1
package eu.dnetlib.openaire.directindex.api;
2

  
3
import eu.dnetlib.functionality.index.utils.ZkServers;
4
import org.apache.commons.logging.Log;
5
import org.apache.commons.logging.LogFactory;
6
import org.apache.solr.client.solrj.impl.CloudSolrClient;
7

  
8
public class IndexClientManager {
9

  
10
    private static final Log log = LogFactory.getLog(IndexClientManager.class);
11

  
12
    private CloudSolrClient client = null;
13

  
14
    public CloudSolrClient getClient(IndexDsInfo info) {
15

  
16
        if (client == null) {
17
            log.info(String.format("Initializing solr client (%s) with collection %s", info.getIndexBaseUrl(), info.getColl()));
18
            ZkServers zk = ZkServers.newInstance(info.getIndexBaseUrl());
19
            CloudSolrClient.Builder builder = new CloudSolrClient.Builder(zk.getHosts(), zk.getChroot()).withParallelUpdates(true);
20
            client = builder.build();
21
        }
22
        client.setDefaultCollection(info.getColl());
23
        return client;
24
    }
25

  
26
}
modules/dnet-directindex-api/tags/dnet-directindex-api-2.2.1/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.*;
5
import java.util.stream.Collectors;
6
import java.util.stream.Collectors;
7

  
8
import com.google.common.base.Function;
9
import com.google.common.collect.Lists;
10
import eu.dnetlib.miscutils.functional.hash.Hashing;
11
import eu.dnetlib.openaire.directindex.objects.ZenodoContextList;
12
import org.apache.commons.lang.StringUtils;
13
import org.springframework.web.client.RestClientException;
14
import org.springframework.web.client.RestTemplate;
15

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

  
21
	private static final org.apache.commons.logging.Log log = org.apache.commons.logging.LogFactory.getLog(OpenAIRESubmitterUtils.class);
22
	private static final String ZENODO_COMMUNITY = "zenodo.org/communities/";
23
	private String community_api;
24
	public OpenAIRESubmitterUtils(String community_api){
25
		this.community_api = community_api;
26
	}
27

  
28
	public Map<String, String> calculateProjectInfo(final String link) {
29
		final Map<String, String> info = new HashMap<String, String>();
30
		final String[] arr = link.split("/");
31
		// info:eu-repo/grantAgreement/EC/FP7/244909/EU/Making Capabilities Work/WorkAble
32

  
33
		if (arr.length > 4) {
34
			final String acronym = arr.length > 7 ? arr[7] : "";
35
			final String title = arr.length > 6 ? StringUtils.isNotBlank(arr[6]) ? arr[6] : acronym : "";
36
			final String jurisdiction = arr.length > 5 ? arr[5] : "";
37
			final String funderId = calculateFunderId(arr[2], arr[3]);
38
			info.put("id", calculateProjectId(arr[2], arr[3], arr[4]));
39
			info.put("funderShortName", fixFunderShortName(arr[2]));
40
			info.put("fundingName", arr[3]);
41
			info.put("code", unescape(arr[4]));
42
			info.put("jurisdiction", jurisdiction);
43
			info.put("title", title);
44
			info.put("acronym", acronym);
45
			info.put("funderId", funderId);
46
			info.put("funderName", calculateFunderName(arr[2]));
47
			if(StringUtils.isNotBlank(arr[3])) info.put("fundingId", funderId + "::" + arr[3]);
48
		}
49
		return info;
50
	}
51

  
52
	//TODO: remove me when Zenodo ingests the good UKRI projects
53
	protected String fixFunderShortName(final String funderShortName){
54
		switch(funderShortName){
55
			case "RCUK":
56
				return "UKRI";
57
			default:
58
				return funderShortName;
59
		}
60
	}
61

  
62
	protected String calculateFunderPrefix(final String funderShortName, final String funding){
63
		switch(funderShortName.toLowerCase()){
64
		case "conicyt":
65
			return "conicytf____::";
66
		case "dfg":
67
			return "dfgf________::";
68
		case "ec":
69
			if (funding.equalsIgnoreCase("fp7")) {
70
				return "corda_______::";
71
			} else {
72
				return "corda__h2020::";
73
			}
74
		case "eea":
75
			return "euenvagency_::";
76
		case "hrzz":
77
		case "mzos":
78
			return "irb_hr______::";
79
		case "tara":
80
			return "taraexp_____::";
81
		case "tubitak":
82
			return "tubitakf____::";
83
			case "rcuk":
84
				return "ukri________::";
85
		default:
86
			String prefix = funderShortName.toLowerCase();
87
			//ensure we have 12 chars
88
			while(prefix.length() < 12) prefix += "_";
89
			return prefix +"::";
90
		}
91
	}
92

  
93
	protected String calculateProjectId(final String funderShortName, final String funding, final String code) {
94
		final String suffix = Hashing.md5(unescape(code));
95
		//final String suffix = Hashing.md5(code);
96
		final String funderPrefix = calculateFunderPrefix(funderShortName, funding);
97
		return funderPrefix + suffix;
98
	}
99

  
100
	private String unescape(String code) {
101
		return StringUtils.replaceChars(code, "%2F", "/");
102
	}
103

  
104
	protected String calculateFunderId(final String funderShortName, final String funding) {
105
		switch (funderShortName.toLowerCase()) {
106
		case "ec":
107
			return "ec__________::EC";
108
		default:
109
			String fixedFunderShortName = fixFunderShortName(funderShortName);
110
			String prefix = calculateFunderPrefix(fixedFunderShortName, funding);
111
			return prefix + fixedFunderShortName.toUpperCase();
112
		}
113
	}
114

  
115

  
116
	protected String calculateFunderName(final String funderShortName) {
117

  
118
		switch (funderShortName.toLowerCase()) {
119
		case "aff":
120
		case "aka":
121
			return "Academy of Finland";
122
		case "anr":
123
			return "French National Research Agency (ANR)";
124
		case "arc":
125
			return "Australian Research Council (ARC)";
126
		case "cihr":
127
			return "Canadian Institutes of Health Research";
128
		case "conicyt":
129
			return "Comisión Nacional de Investigación Científica y Tecnológica";
130
		case "dfg":
131
			return "Deutsche Forschungsgemeinschaft";
132
		case "ec":
133
			return "European Commission";
134
		case "eea":
135
			return "European Environment Agency";
136
		case "fct":
137
			return "Fundação para a Ciência e a Tecnologia, I.P.";
138
		case "fwf":
139
			return "Austrian Science Fund (FWF)";
140
		case "gsrt":
141
			return "General Secretariat of Research and Technology (GSRT)";
142
		case "hrzz":
143
			return "Croatian Science Foundation (CSF)";
144
		case "innoviris":
145
			return "INNOVIRIS";
146
		case "mestd":
147
			return "Ministry of Education, Science and Technological Development of Republic of Serbia";
148
		case "miur":
149
			return "Ministero dell'Istruzione dell'Università e della Ricerca";
150
		case "mzos":
151
			return "Ministry of Science, Education and Sports of the Republic of Croatia (MSES)";
152
		case "nhmrc":
153
			return "National Health and Medical Research Council (NHMRC)";
154
		case "nih":
155
			return "National Institutes of Health";
156
		case "nsf":
157
			return "National Science Foundation";
158
		case "nserc":
159
			return "Natural Sciences and Engineering Research Council of Canada";
160
		case "nwo":
161
			return "Netherlands Organisation for Scientific Research (NWO)";
162
		case "rcuk":
163
			case "ukri":
164
			return "UK Research and Innovation";
165
		case "rif":
166
		case "rpf":
167
			return "Research and Innovation Foundation";
168
		case "rsf":
169
			return "Russian Science Foundation";
170
		case "sfi":
171
			return "Science Foundation Ireland";
172
		case "sgov":
173
			return "Gobierno de España";
174
		case "snsf":
175
			return "Swiss National Science Foundation";
176
		case "sshrc":
177
			return "Social Sciences and Humanities Research Council";
178
		case "tara":
179
			return "Tara Expeditions Foundation";
180
		case "tubitak":
181
			return "Türkiye Bilimsel ve Teknolojik Araştırma Kurumu";
182
		case "wt":
183
			return "Wellcome Trust";
184
		default:
185
			log.error("Funder short name '"+funderShortName+"' not managed");
186
			return "";
187
		}
188
	}
189

  
190
	private List<String> filterContexts(List<String> contexts){
191

  
192
		List<String> zenodoContexts
193
				= contexts.stream()
194
				.map(c -> {
195
					if(c.contains(ZENODO_COMMUNITY))
196
						return c.substring(c.lastIndexOf("/")+1);
197
					return null;
198
				}).collect(Collectors.toList());
199

  
200
		if (zenodoContexts.size()>0){
201
			contexts = contexts.stream().filter(c -> !c.contains(ZENODO_COMMUNITY)).collect(Collectors.toList());
202
			RestTemplate rt = new RestTemplate();
203
			Set<String> zenodoOpenAIRE = new HashSet<>();
204
			for (String context: zenodoContexts){
205
				//String ct = context.substring(context.lastIndexOf("/")+1);
206
				try{
207
					zenodoOpenAIRE.addAll(rt.getForObject(community_api +context+"/openairecommunities", ZenodoContextList.class).getOpenAirecommunitylist());
208
				}catch(RestClientException rce){
209
					log.error("Unable to get object for " + community_api +context+"/openairecommunities");
210
				}
211

  
212

  
213
			}
214
			contexts.addAll(zenodoOpenAIRE);
215
		}
216

  
217
		return contexts;
218

  
219
	}
220
	public List<ContextInfo> processContexts(final List<String> list) {
221
		//filterContexts(list);
222
		return Lists.newArrayList(Lists.transform(filterContexts(list), new Function<String, ContextInfo>() {
223

  
224
			@Override
225
			public ContextInfo apply(final String s) {
226
				return createContextInfo(s.split("::"), 0);
227
			}
228

  
229
			private ContextInfo createContextInfo(final String[] arr, final int pos) {
230
				final StringWriter id = new StringWriter();
231
				id.write(arr[0]);
232
				for (int i = 0; i < pos; i++) {
233
					id.write("::");
234
					id.write(arr[i + 1]);
235
				}
236
				final String elem = (pos == 0) ? "context" : (pos == 1) ? "category" : "concept";
237
				final ContextInfo info = new ContextInfo(elem, id.toString());
238
				if ((pos + 1) < arr.length) {
239
					info.getChildren().add(createContextInfo(arr, pos + 1));
240
				}
241
				return info;
242
			}
243
		}));
244

  
245
	}
246

  
247
	public class ContextInfo {
248

  
249
		private String elem;
250
		private String id;
251
		private List<ContextInfo> children = new ArrayList<ContextInfo>();
252

  
253
		public ContextInfo(final String elem,
254
				final String id) {
255
			this.elem = elem;
256
			this.id = id;
257
		}
258

  
259
		public String getElem() {
260
			return elem;
261
		}
262

  
263
		public void setElem(final String elem) {
264
			this.elem = elem;
265
		}
266

  
267
		public String getId() {
268
			return id;
269
		}
270

  
271
		public void setId(final String id) {
272
			this.id = id;
273
		}
274

  
275
		public List<ContextInfo> getChildren() {
276
			return children;
277
		}
278

  
279
		public void setChildren(final List<ContextInfo> children) {
280
			this.children = children;
281
		}
282

  
283
		public boolean isRoot() {
284
			return elem.equals("context");
285
		}
286
	}
287
}
modules/dnet-directindex-api/tags/dnet-directindex-api-2.2.1/src/main/java/eu/dnetlib/openaire/directindex/api/IndexDSRetriever.java
1
package eu.dnetlib.openaire.directindex.api;
2

  
3
import eu.dnetlib.enabling.is.lookup.rmi.ISLookUpException;
4
import eu.dnetlib.enabling.is.lookup.rmi.ISLookUpService;
5
import eu.dnetlib.enabling.locators.UniqueServiceLocator;
6
import org.apache.commons.io.IOUtils;
7
import org.apache.commons.logging.Log;
8
import org.apache.commons.logging.LogFactory;
9
import org.springframework.beans.factory.annotation.Value;
10
import org.springframework.cache.annotation.CacheEvict;
11
import org.springframework.cache.annotation.Cacheable;
12
import org.springframework.core.io.ClassPathResource;
13

  
14
import javax.annotation.Resource;
15
import java.io.IOException;
16

  
17
public class IndexDSRetriever {
18

  
19
	private static final Log log = LogFactory.getLog(IndexDSRetriever.class);
20
	@Value(value = "${openaire.api.directindex.findSolrIndexUrl.xquery}")
21
	private ClassPathResource findSolrIndexUrl;
22

  
23
	@Value(value = "${openaire.api.directindex.findIndexDsInfo.xquery}")
24
	private ClassPathResource findIndexDsInfo;
25

  
26
	@Resource
27
	private UniqueServiceLocator serviceLocator;
28

  
29
	@Cacheable("indexDsInfo")
30
	public IndexDsInfo calculateCurrentIndexDsInfo() throws IOException, ISLookUpException {
31

  
32
		log.info("Not using cache");
33

  
34
		final String queryUrl = IOUtils.toString(findSolrIndexUrl.getInputStream());
35
		final String queryDs = IOUtils.toString(findIndexDsInfo.getInputStream());
36

  
37
		final ISLookUpService lu = serviceLocator.getService(ISLookUpService.class);
38
		final String indexBaseUrl = lu.getResourceProfileByQuery(queryUrl);
39

  
40
		final String idxDs = lu.getResourceProfileByQuery(queryDs);
41

  
42
		if (idxDs.isEmpty()) {
43
			throw new IllegalStateException(queryDs + "\n\nreturned no results, check IS profiles");
44
		}
45

  
46
		final String[] arr = idxDs.split("@@@");
47
		return new IndexDsInfo(indexBaseUrl, arr[0].trim(), arr[1].trim(), arr[2].trim());
48
	}
49

  
50
	@CacheEvict(value="indexDsInfo", allEntries = true)
51
	public void evictCache(){
52
		log.info("Evicting indexDsInfo cache");
... This diff was truncated because it exceeds the maximum size that can be displayed.

Also available in: Unified diff