Project

General

Profile

« Previous | Next » 

Revision 59799

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

View differences:

modules/dnet-directindex-api/tags/dnet-directindex-api-2.1.18/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.1.18/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

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

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

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

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

  
53
	@Test
54
	public void testJerusalem(){
55
		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";
56
		final Map<String, String> project = utils.calculateProjectInfo(s);
57
		print(project);
58
	}
59

  
60
	private void print(final Map<String, String> map) {
61
		for (final Entry e : map.entrySet()) {
62
			System.out.println(e.getKey() + " = " + e.getValue());
63
		}
64
	}
65

  
66
	@Test
67
	public void testContext(){
68
		List<String> contexts = new ArrayList<>();
69
		contexts.add("https://zenodo.org/communities/dimpo");
70
		contexts.add("https://zenodo.org/communities/aoo_beopen");
71
		List<OpenAIRESubmitterUtils.ContextInfo> tmp = utils.processContexts(contexts);
72

  
73
		Assert.assertEquals(2, tmp.size());
74

  
75
		Assert.assertTrue(tmp.get(0).getId().equals("dh-ch") || tmp.get(1).getId().equalsIgnoreCase("dh-ch"));
76
		Assert.assertTrue(tmp.get(0).getId().equals("dariah") || tmp.get(1).getId().equalsIgnoreCase("dariah"));
77
	}
78
}
modules/dnet-directindex-api/tags/dnet-directindex-api-2.1.18/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
			} else {
73
				return new ArrayList<String>();
74
			}
75
		});
76

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

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

  
104
		final Document doc = new SAXReader().read(new StringReader(xml));
105

  
106
		final OutputFormat format = OutputFormat.createPrettyPrint();
107

  
108
		final XMLWriter writer = new XMLWriter(System.out, format);
109

  
110
		writer.write(doc);
111

  
112
		/* writer.close(); */
113

  
114
	}
115

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

  
141
		final Document doc = new SAXReader().read(new StringReader(xml));
142

  
143
		final OutputFormat format = OutputFormat.createPrettyPrint();
144

  
145
		final XMLWriter writer = new XMLWriter(System.out, format);
146

  
147
		writer.write(doc);
148

  
149
		/* writer.close(); */
150

  
151
	}
152

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

  
179
		final Document doc = new SAXReader().read(new StringReader(xml));
180

  
181
		final OutputFormat format = OutputFormat.createPrettyPrint();
182

  
183
		final XMLWriter writer = new XMLWriter(System.out, format);
184

  
185
		writer.write(doc);
186

  
187
		/* writer.close(); */
188

  
189
	}
190

  
191
	@Test
192
	public void testAsIndexRecord_json() throws Exception {
193
		testAsIndexRecord_json("test_record.json");
194

  
195
	}
196

  
197
	@Test
198
	public void testAsIndexRecord_json_with_greek_chars() throws Exception {
199

  
200
		testAsIndexRecord_json("test_record_with_greek_chars.json");
201

  
202
	}
203

  
204
	@Test
205
	public void testAsIndexRecord_openaireId() throws Exception {
206

  
207
		testAsIndexRecord_json("test_record_openaireId.json");
208

  
209
	}
210

  
211
	@Test(expected = DirecIndexApiException.class)
212
	public void testAsIndexRecord_wrongOpenaireId() throws Exception {
213

  
214
		testAsIndexRecord_json("test_record_wrong_openaireId.json");
215

  
216
	}
217

  
218
	@Test
219
	public void testAsIndexRecord_json_zenodo() throws Exception {
220

  
221
		testAsIndexRecord_json("test_zenodo.json");
222

  
223
	}
224

  
225
	@Test
226
	public void testAsIndexRecord_json_zenodoWithAmpersand() throws Exception {
227

  
228
		testAsIndexRecord_json("test_zenodoAmpersandEverywhere.json");
229

  
230
	}
231

  
232
	@Test
233
	public void testAsIndexRecord_json_software() throws Exception {
234

  
235
		testAsIndexRecord_json("test_record_software.json");
236

  
237
	}
238

  
239
	@Test
240
	public void testAsIndexRecord_json_orp() throws Exception {
241

  
242
		testAsIndexRecord_json("test_record_orp.json");
243

  
244
	}
245

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

  
250

  
251
		final String xml = pub.asOafRecord(ve, lookUpService, "http://oaf/oaf.xsd",community_api);
252
		//System.out.println(xml);
253

  
254
		final Document doc = new SAXReader().read(new StringReader(xml));
255

  
256
		final OutputFormat format = OutputFormat.createPrettyPrint();
257

  
258
		final XMLWriter writer = new XMLWriter(System.out, format);
259

  
260
		writer.write(doc);
261

  
262
		/* writer.close(); */
263
	}
264

  
265
	@Test
266
	public void testAsIndexRecord_json_zenodocommunities()throws Exception{
267
		testAsIndexRecord_json("test_zenodo_community.json");
268
	}
269

  
270
	@Test
271
	public void testAsIndexRecordFromSandbox_json_zenodocommunities()throws Exception{
272
		testAsIndexRecord_json("test_zenodo_community2.json");
273
	}
274

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

  
282
}
modules/dnet-directindex-api/tags/dnet-directindex-api-2.1.18/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.1.18/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.1.18/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.1.18/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.1.18/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.1.18/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.1.18/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.1.18/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.1.18/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.1.18/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.1.18/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.1.18/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.1.18/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.1.18/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.1.18/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.1.18/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.1.18/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 java.util.Map;
6
import javax.annotation.Resource;
7

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

  
32
/**
33
 * Created by michele on 11/11/15.
34
 */
35
@Controller
36
@DNetRestDocumentation
37
public class OpenaireResultSubmitter {
38

  
39
	private static final Log log = LogFactory.getLog(OpenaireResultSubmitter.class);
40

  
41
	@Value(value = "${openaire.api.community}")
42
	private String community_api;
43

  
44
	@Value(value = "oaf.schema.location")
45
	private String oafSchemaLocation;
46

  
47
	@Resource
48
	private UniqueServiceLocator serviceLocator;
49

  
50
	@Resource
51
	private OafToIndexRecordFactory oafToIndexRecordFactory;
52

  
53
	@Resource
54
	private RecentResultsQueue recentResultsQueue;
55

  
56
	@Resource(name = "openaireplusApisVelocityEngine")
57
	private VelocityEngine velocityEngine;
58

  
59
	@Resource(name = "indexClientManager")
60
	private IndexClientManager clientManager;
61

  
62
	@Resource(name = "resultSubmitterService")
63
	private ResultSubmitterService submitterService;
64

  
65
	@Autowired
66
	private IndexDSRetriever indexDSRetriever;
67

  
68
	@RequestMapping(value = { "/api/admin/autocommit/active" }, method = RequestMethod.GET)
69
	public @ResponseBody Boolean getAutocommit() throws DirecIndexApiException {
70
		return submitterService.isAutocommitactive();
71
	}
72

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

  
80
	@RequestMapping(value="/api/admin/evictCache", method=RequestMethod.GET)
81
	@ResponseStatus(value = HttpStatus.OK)
82
	public void evictCache(){
83
		indexDSRetriever.evictCache();
84
	}
85

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

  
94

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

  
101
	}
102

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

  
111

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

  
117
		return deleteResult(openaireId);
118
	}
119

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

  
126
		final String openaireId = ResultEntry.calculateOpenaireId(originalId, collectedFromId, serviceLocator.getService(ISLookUpService.class));
127
		return deleteResult(openaireId);
128
	}
129

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

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

  
141
	@Deprecated
142
	private String feed(final ResultEntry pub, final boolean commit) throws DirecIndexApiException {
143
		return feed(pub);
144
	}
145

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

  
152
			clientManager.getClient(info).add(solrDocument);
153
			recentResultsQueue.add(oafRecord);
154

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

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

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

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

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

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

  
200
	public class ErrorMessage {
201

  
202
		private final String message;
203
		private final String stacktrace;
204

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

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

  
214
		public String getMessage() {
215
			return this.message;
216
		}
217

  
218
		public String getStacktrace() {
219
			return this.stacktrace;
220
		}
221

  
222
	}
223

  
224
}
modules/dnet-directindex-api/tags/dnet-directindex-api-2.1.18/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.1.18/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", arr[2]);
40
			info.put("fundingName", arr[3]);
41
			info.put("code", 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
			info.put("fundingId", funderId + "::" + arr[3]);
48
		}
49
		return info;
50
	}
51

  
52
	protected String calculateFunderPrefix(final String funderShortName, final String funding){
53
		switch(funderShortName.toLowerCase()){
54
		case "conicyt":
55
			return "conicytf____::";
56
		case "dfg":
57
			return "dfgf________::";
58
		case "ec":
59
			if (funding.equalsIgnoreCase("fp7")) {
60
				return "corda_______::";
61
			} else {
62
				return "corda__h2020::";
63
			}
64
		case "eea":
65
			return "euenvagency_::";
66
		case "hrzz":
67
		case "mzos":
68
			return "irb_hr______::";
69
		case "tara":
70
			return "taraexp_____::";
71
		case "tubitak":
72
			return "tubitakf____::";
73
			case "rcuk":
74
				return "ukri________";
75
		default:
76
			String prefix = funderShortName.toLowerCase();
77
			//ensure we have 12 chars
78
			while(prefix.length() < 12) prefix += "_";
79
			return prefix +"::";
80
		}
81
	}
82

  
83
	protected String calculateProjectId(final String funderShortName, final String funding, final String code) {
84
		final String suffix = Hashing.md5(code);
85
		final String funderPrefix = calculateFunderPrefix(funderShortName, funding);
86
		return funderPrefix + suffix;
87
	}
88

  
89
	protected String calculateFunderId(final String funderShortName, final String funding) {
90
		switch (funderShortName.toLowerCase()) {
91
		case "ec":
92
			return "ec__________::EC";
93
		default:
94
			String prefix = calculateFunderPrefix(funderShortName, funding);
95
			return prefix + funderShortName.toUpperCase();
96
		}
97
	}
98

  
99

  
100
	protected String calculateFunderName(final String funderShortName) {
101

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

  
174
	private List<String> filterContexts(List<String> contexts){
175

  
176
		List<String> zenodoContexts
177
				= contexts.stream()
178
				.map(c -> {
179
					if(c.contains(ZENODO_COMMUNITY))
180
						return c.substring(c.lastIndexOf("/")+1);
181
					return null;
182
				}).collect(Collectors.toList());
183

  
184
		if (zenodoContexts.size()>0){
185
			contexts = contexts.stream().filter(c -> !c.contains(ZENODO_COMMUNITY)).collect(Collectors.toList());
186
			RestTemplate rt = new RestTemplate();
187
			Set<String> zenodoOpenAIRE = new HashSet<>();
188
			for (String context: zenodoContexts){
189
				//String ct = context.substring(context.lastIndexOf("/")+1);
190
				try{
191
					zenodoOpenAIRE.addAll(rt.getForObject(community_api +context+"/openairecommunities", ZenodoContextList.class).getOpenAirecommunitylist());
192
				}catch(RestClientException rce){
193
					log.error("Unable to get object for " + community_api +context+"/openairecommunities");
194
				}
195

  
196

  
197
			}
198
			contexts.addAll(zenodoOpenAIRE);
199
		}
200

  
201
		return contexts;
202

  
203
	}
204
	public List<ContextInfo> processContexts(final List<String> list) {
205
		//filterContexts(list);
206
		return Lists.newArrayList(Lists.transform(filterContexts(list), new Function<String, ContextInfo>() {
207

  
208
			@Override
209
			public ContextInfo apply(final String s) {
210
				return createContextInfo(s.split("::"), 0);
211
			}
212

  
213
			private ContextInfo createContextInfo(final String[] arr, final int pos) {
214
				final StringWriter id = new StringWriter();
215
				id.write(arr[0]);
216
				for (int i = 0; i < pos; i++) {
217
					id.write("::");
218
					id.write(arr[i + 1]);
219
				}
220
				final String elem = (pos == 0) ? "context" : (pos == 1) ? "category" : "concept";
221
				final ContextInfo info = new ContextInfo(elem, id.toString());
222
				if ((pos + 1) < arr.length) {
223
					info.getChildren().add(createContextInfo(arr, pos + 1));
224
				}
225
				return info;
226
			}
227
		}));
228

  
229
	}
230

  
231
	public class ContextInfo {
232

  
233
		private String elem;
234
		private String id;
235
		private List<ContextInfo> children = new ArrayList<ContextInfo>();
236

  
237
		public ContextInfo(final String elem,
238
				final String id) {
239
			this.elem = elem;
240
			this.id = id;
241
		}
242

  
243
		public String getElem() {
244
			return elem;
245
		}
246

  
247
		public void setElem(final String elem) {
248
			this.elem = elem;
249
		}
250

  
251
		public String getId() {
252
			return id;
253
		}
254

  
255
		public void setId(final String id) {
256
			this.id = id;
257
		}
258

  
259
		public List<ContextInfo> getChildren() {
260
			return children;
261
		}
262

  
263
		public void setChildren(final List<ContextInfo> children) {
264
			this.children = children;
265
		}
266

  
267
		public boolean isRoot() {
268
			return elem.equals("context");
269
		}
270
	}
271
}
modules/dnet-directindex-api/tags/dnet-directindex-api-2.1.18/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");
53
	}
54
}
modules/dnet-directindex-api/tags/dnet-directindex-api-2.1.18/src/main/java/eu/dnetlib/openaire/directindex/api/DirecIndexApiException.java
1
package eu.dnetlib.openaire.directindex.api;
2

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

  
5
public class DirecIndexApiException extends RMIException {
6

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

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

  
16
	public DirecIndexApiException(final String string, final Throwable exception) {
... This diff was truncated because it exceeds the maximum size that can be displayed.

Also available in: Unified diff