Project

General

Profile

« Previous | Next » 

Revision 54814

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

View differences:

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

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

  
6
import org.junit.Test;
7

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

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

  
17
	private OpenAIRESubmitterUtils utils = new OpenAIRESubmitterUtils();
18

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

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

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

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

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

  
48
	@Test
49
	public void testJerusalem(){
50
		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";
51
		final Map<String, String> project = utils.calculateProjectInfo(s);
52
		print(project);
53
	}
54

  
55
	private void print(final Map<String, String> map) {
56
		for (final Entry e : map.entrySet()) {
57
			System.out.println(e.getKey() + " = " + e.getValue());
58
		}
59
	}
60
}
modules/dnet-directindex-api/tags/dnet-directindex-api-1.1.11/src/test/java/eu/dnetlib/msro/openaireplus/api/objects/ResultEntryTest.java
1
package eu.dnetlib.msro.openaireplus.api.objects;
2

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

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

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

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

  
35
	private VelocityEngine ve;
36

  
37
	@Mock
38
	private ISLookUpService lookUpService;
39

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

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

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

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

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

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

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

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

  
108
		writer.write(doc);
109

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

  
112
	}
113

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

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

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

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

  
145
		writer.write(doc);
146

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

  
149
	}
150

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

  
177
		final Document doc = new SAXReader().read(new StringReader(xml));
178

  
179
		final OutputFormat format = OutputFormat.createPrettyPrint();
180

  
181
		final XMLWriter writer = new XMLWriter(System.out, format);
182

  
183
		writer.write(doc);
184

  
185
		/* writer.close(); */
186

  
187
	}
188

  
189

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

  
194
	}
195

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

  
199
		testAsIndexRecord_json("test_record_with_greek_chars.json");
200

  
201
	}
202

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

  
206
		testAsIndexRecord_json("test_record_openaireId.json");
207

  
208
	}
209

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

  
213
		testAsIndexRecord_json("test_record_wrong_openaireId.json");
214

  
215
	}
216

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

  
220
		testAsIndexRecord_json("test_zenodo.json");
221

  
222
	}
223

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

  
227
		testAsIndexRecord_json("test_zenodoAmpersandEverywhere.json");
228

  
229
	}
230

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

  
234
		testAsIndexRecord_json("test_record_software.json");
235

  
236
	}
237

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

  
241
		testAsIndexRecord_json("test_record_orp.json");
242

  
243
	}
244

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

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

  
252
		final Document doc = new SAXReader().read(new StringReader(xml));
253

  
254
		final OutputFormat format = OutputFormat.createPrettyPrint();
255

  
256
		final XMLWriter writer = new XMLWriter(System.out, format);
257

  
258
		writer.write(doc);
259

  
260
		/* writer.close(); */
261
	}
262

  
263
	@Test
264
	public void testAsIndexRecord_json_zenodoProblems()throws Exception{
265
		testAsIndexRecord_json("test_zenodo_problems.json");
266
	}
267

  
268
	@Test
269
	public void testEscapeUnicode() {
270
		final String unicodeTxt =
271
				"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$";
272
		System.out.println(StringEscapeUtils.escapeXml11(unicodeTxt));
273
	}
274

  
275
}
modules/dnet-directindex-api/tags/dnet-directindex-api-1.1.11/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-1.1.11/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-1.1.11/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-1.1.11/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-1.1.11/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-1.1.11/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-1.1.11/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-1.1.11/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-1.1.11/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-1.1.11/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-1.1.11/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-1.1.11/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-1.1.11/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-1.1.11/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-1.1.11/src/main/java/eu/dnetlib/openaire/directindex/api/OpenaireResultSubmitter.java
1
package eu.dnetlib.openaire.directindex.api;
2

  
3
import java.util.Map;
4
import javax.annotation.Resource;
5

  
6
import com.google.gson.Gson;
7
import eu.dnetlib.common.rmi.DNetRestDocumentation;
8
import eu.dnetlib.data.index.CloudIndexClient;
9
import eu.dnetlib.enabling.is.lookup.rmi.ISLookUpService;
10
import eu.dnetlib.enabling.locators.UniqueServiceLocator;
11
import eu.dnetlib.openaire.directindex.objects.ResultEntry;
12
import eu.dnetlib.openaire.directindex.utils.OafToIndexRecordFactory;
13
import org.apache.commons.lang.exception.ExceptionUtils;
14
import org.apache.commons.logging.Log;
15
import org.apache.commons.logging.LogFactory;
16
import org.apache.velocity.app.VelocityEngine;
17
import org.springframework.beans.factory.annotation.Autowired;
18
import org.springframework.beans.factory.annotation.Value;
19
import org.springframework.http.HttpStatus;
20
import org.springframework.stereotype.Controller;
21
import org.springframework.web.bind.annotation.*;
22

  
23
/**
24
 * Created by michele on 11/11/15.
25
 */
26
@Controller
27
@DNetRestDocumentation
28
public class OpenaireResultSubmitter {
29

  
30
	private static final Log log = LogFactory.getLog(OpenaireResultSubmitter.class);
31

  
32
	@Value(value = "oaf.schema.location")
33
	private String oafSchemaLocation;
34

  
35
	@Resource
36
	private UniqueServiceLocator serviceLocator;
37

  
38
	@Resource
39
	private OafToIndexRecordFactory oafToIndexRecordFactory;
40

  
41
	@Resource
42
	private RecentResultsQueue recentResultsQueue;
43

  
44
	@Resource(name = "openaireplusApisVelocityEngine")
45
	private VelocityEngine velocityEngine;
46

  
47
	@Resource(name = "resultSubmitterClientMap")
48
	private IndexClientMap clientMap;
49

  
50
	@Resource(name = "resultSubmitterService")
51
	private ResultSubmitterService submitterService;
52

  
53
	@Autowired
54
	private IndexDSRetriever indexDSRetriever;
55

  
56
	@RequestMapping(value = { "/api/admin/autocommit/active" }, method = RequestMethod.GET)
57
	public @ResponseBody Boolean getAutocommit() throws DirecIndexApiException {
58
		return submitterService.isAutocommitactive();
59
	}
60

  
61
	@RequestMapping(value = { "/api/admin/autocommit/active" }, method = RequestMethod.POST)
62
	public @ResponseBody Boolean setAutocommit(@RequestParam(value = "active", required = true) final Boolean active) throws DirecIndexApiException {
63
		submitterService.setAutocommitactive(active);
64
		log.info(String.format("automatic commit, active '%s', frequency '%s'", submitterService.isAutocommitactive(), submitterService.getCommitfrquency()));
65
		return submitterService.isAutocommitactive();
66
	}
67

  
68
	@RequestMapping(value="/api/admin/evictCache", method=RequestMethod.GET)
69
	@ResponseStatus(value = HttpStatus.OK)
70
	public void evictCache(){
71
		indexDSRetriever.evictCache();
72
	}
73

  
74
	@Deprecated
75
	@RequestMapping(value = { "/api/publications/feedJson", "/api/results/feedJson" }, method = RequestMethod.POST)
76
	public @ResponseBody String feedObjectJson(@RequestParam(value = "json", required = true) final String json,
77
			@RequestParam(value = "commit", required = false, defaultValue = "true") final boolean commit) throws DirecIndexApiException {
78
		final ResultEntry pub = new Gson().fromJson(json, ResultEntry.class);
79
		return feedObject(pub, commit);
80
	}
81

  
82

  
83
	@RequestMapping(value = { "/api/results/feedObject" }, method = RequestMethod.POST)
84
	public @ResponseBody String feedResult(@RequestBody final ResultEntry pub,
85
			@RequestParam(value = "commit", required = false, defaultValue = "true") final boolean commit)
86
			throws DirecIndexApiException {
87
		return feed(pub,commit);
88

  
89
	}
90

  
91
	@Deprecated
92
	@RequestMapping(value = { "/api/publications/feedObject" }, method = RequestMethod.POST)
93
	public @ResponseBody String feedObject(@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
	@RequestMapping(value = "/api/result/{openaireId}", method = RequestMethod.DELETE)
101
	public @ResponseBody boolean deleteResultWithOpenaireId(
102
			@PathVariable(value = "openaireId") final String openaireId,
103
			@RequestParam(value = "commit", required = false, defaultValue = "true") final boolean commit) throws DirecIndexApiException {
104

  
105
		return deleteResult(openaireId, commit);
106
	}
107

  
108
	@RequestMapping(value = "/api/results", method = RequestMethod.DELETE)
109
	public @ResponseBody boolean deleteResultWithOriginalId(
110
			@RequestParam(value = "originalId", required = true) final String originalId,
111
			@RequestParam(value = "collectedFromId", required = true) final String collectedFromId,
112
			@RequestParam(value = "commit", required = false, defaultValue = "true") final boolean commit) throws Exception {
113

  
114
		final String openaireId = ResultEntry.calculateOpenaireId(originalId, collectedFromId, serviceLocator.getService(ISLookUpService.class));
115
		return deleteResult(openaireId, commit);
116
	}
117

  
118
	@Deprecated
119
	@RequestMapping(value = { "/api/publications/deleteObject", "/api/results/delete" }, method = RequestMethod.POST)
120
	public @ResponseBody boolean deleteResultPost(
121
			@RequestParam(value = "originalId", required = true) final String originalId,
122
			@RequestParam(value = "collectedFromId", required = true) final String collectedFromId,
123
			@RequestParam(value = "commit", required = false, defaultValue = "true") final boolean commit) throws Exception {
124

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

  
129
	@Deprecated
130
	private String feed(final ResultEntry pub, final boolean commit) throws DirecIndexApiException {
131
		return feed(pub);
132
	}
133

  
134
	private String feed(final ResultEntry pub) throws DirecIndexApiException {
135
		try {
136
			final String oafRecord = pub.asOafRecord(velocityEngine, serviceLocator.getService(ISLookUpService.class), oafSchemaLocation);
137

  
138
			for(Map.Entry<IndexDsInfo, CloudIndexClient> e : clientMap.getClients().entrySet()) {
139
				final IndexDsInfo idx = e.getKey();
140
				final CloudIndexClient client = e.getValue();
141
				client.feed(oafRecord, idx.getIndexDsId(), oafToIndexRecordFactory.newTransformer(idx.getFormat()), false);
142
			}
143

  
144
			recentResultsQueue.add(oafRecord);
145

  
146
			return pub.getOpenaireId();
147
		} catch (final Throwable e) {
148
			log.error("Error saving record", e);
149
			log.debug(pub.toString());
150
			throw new DirecIndexApiException("Error adding publication: " + e.getMessage(), e);
151
		}
152
	}
153

  
154
	private boolean deleteResult(final String openaireId, final boolean commit) throws DirecIndexApiException {
155
		try {
156
			for(Map.Entry<IndexDsInfo, CloudIndexClient> e : clientMap.getClients().entrySet()) {
157
				final IndexDsInfo idx = e.getKey();
158
				final CloudIndexClient client = e.getValue();
159
				client.remove(openaireId, false);
160
				log.info("Deleted result with id: " + openaireId + " from: " + idx.getIndexBaseUrl());
161
			}
162

  
163
			recentResultsQueue.remove(openaireId);
164
			return true;
165
		} catch (Throwable e) {
166
			throw new DirecIndexApiException("Error deleting publication: " + e.getMessage(), e);
167
		}
168
	}
169

  
170
	@ExceptionHandler(Exception.class)
171
	@ResponseStatus(value = HttpStatus.INTERNAL_SERVER_ERROR)
172
	public @ResponseBody ErrorMessage handleException(final Exception e) {
173
		log.error("Error in direct index API", e);
174
		return new ErrorMessage(e);
175
	}
176

  
177
	public class ErrorMessage {
178

  
179
		private final String message;
180
		private final String stacktrace;
181

  
182
		public ErrorMessage(final Exception e) {
183
			this(e.getMessage(), ExceptionUtils.getStackTrace(e));
184
		}
185

  
186
		public ErrorMessage(final String message, final String stacktrace) {
187
			this.message = message;
188
			this.stacktrace = stacktrace;
189
		}
190

  
191
		public String getMessage() {
192
			return this.message;
193
		}
194

  
195
		public String getStacktrace() {
196
			return this.stacktrace;
197
		}
198

  
199
	}
200

  
201
}
modules/dnet-directindex-api/tags/dnet-directindex-api-1.1.11/src/main/java/eu/dnetlib/openaire/directindex/api/OpenAIRESubmitterUtils.java
1
package eu.dnetlib.openaire.directindex.api;
2

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

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

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

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

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

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

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

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

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

  
86

  
87
	protected String calculateFunderName(final String funderShortName) {
88

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

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

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

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

  
163
	}
164

  
165
	public class ContextInfo {
166

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

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

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

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

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

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

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

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

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

  
3
import java.io.IOException;
4
import java.util.List;
5
import java.util.Map;
6
import javax.annotation.Resource;
7

  
8
import com.google.common.collect.Maps;
9
import eu.dnetlib.data.index.CloudIndexClient;
10
import eu.dnetlib.data.index.CloudIndexClientException;
11
import eu.dnetlib.data.index.CloudIndexClientFactory;
12
import eu.dnetlib.enabling.is.lookup.rmi.ISLookUpException;
13
import eu.dnetlib.enabling.locators.UniqueServiceLocator;
14
import org.apache.commons.logging.Log;
15
import org.apache.commons.logging.LogFactory;
16
import org.springframework.beans.factory.annotation.Autowired;
17
import org.springframework.beans.factory.annotation.Value;
18
import org.springframework.core.io.ClassPathResource;
19

  
20
public class IndexClientMap {
21

  
22
    private static final Log log = LogFactory.getLog(IndexClientMap.class);
23

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

  
27
    @Value(value = "${openaire.api.directindex.findIndexDsInfo.xquery}")
28
    private ClassPathResource findIndexDsInfo;
29

  
30
    @Resource
31
    private UniqueServiceLocator serviceLocator;
32

  
33
    @Autowired
34
    private IndexDSRetriever indexDSRetriever;
35

  
36
    private Map<IndexDsInfo, CloudIndexClient> clients = Maps.newHashMap();
37

  
38
    public Map<IndexDsInfo, CloudIndexClient> getClients() throws DirecIndexApiException {
39
        try {
40
            final List<IndexDsInfo> idxList = indexDSRetriever.calculateCurrentIndexDsInfo();
41

  
42
            if (idxList == null || idxList.isEmpty()) {
43
                throw new DirecIndexApiException("cannot create index: no public Search Service found");
44
            }
45
            if (idxList.size() > 1) {
46
                log.warn("found more than 1 public search service");
47
            }
48

  
49
            for(IndexDsInfo i : idxList) {
50
                if (!clients.containsKey(i)) {
51
                    clients.put(i, CloudIndexClientFactory.newIndexClient(i.getIndexBaseUrl(), i.getColl(), false));
52
                }
53
            }
54
            return clients;
55

  
56
        } catch (IOException | ISLookUpException | CloudIndexClientException e) {
57
            throw new DirecIndexApiException(e);
58
        }
59
    }
60

  
61
}
modules/dnet-directindex-api/tags/dnet-directindex-api-1.1.11/src/main/java/eu/dnetlib/openaire/directindex/api/IndexDSRetriever.java
1
package eu.dnetlib.openaire.directindex.api;
2

  
3
import java.io.IOException;
4
import java.util.List;
5
import javax.annotation.Resource;
6

  
7
import com.google.common.collect.Lists;
8
import eu.dnetlib.enabling.is.lookup.rmi.ISLookUpException;
9
import eu.dnetlib.enabling.is.lookup.rmi.ISLookUpService;
10
import eu.dnetlib.enabling.locators.UniqueServiceLocator;
11
import org.apache.commons.io.IOUtils;
12
import org.apache.commons.logging.Log;
13
import org.apache.commons.logging.LogFactory;
14
import org.springframework.beans.factory.annotation.Value;
15
import org.springframework.cache.annotation.CacheEvict;
16
import org.springframework.cache.annotation.Cacheable;
17
import org.springframework.core.io.ClassPathResource;
18

  
19
public class IndexDSRetriever {
20

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

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

  
28
	@Resource
29
	private UniqueServiceLocator serviceLocator;
30

  
31
	@Cacheable("indexDsInfo")
32
	public List<IndexDsInfo> calculateCurrentIndexDsInfo() throws IOException, ISLookUpException {
33

  
34
		log.info("Not using cache");
35
		final List<IndexDsInfo> list = Lists.newArrayList();
36

  
37
		final String queryUrl = IOUtils.toString(findSolrIndexUrl.getInputStream());
38
		final String queryDs = IOUtils.toString(findIndexDsInfo.getInputStream());
39

  
40
		final ISLookUpService lu = serviceLocator.getService(ISLookUpService.class);
41
		final String indexBaseUrl = lu.getResourceProfileByQuery(queryUrl);
42

  
43
		final List<String> idxDs = lu.quickSearchProfile(queryDs);
44
		for (final String idx : idxDs) {
45
			final String[] arr = idx.split("@@@");
46
			list.add(new IndexDsInfo(indexBaseUrl, arr[0].trim(), arr[1].trim(), arr[2].trim()));
47
		}
48
		return list;
49
	}
50

  
51
	@CacheEvict(value="indexDsInfo", allEntries = true)
52
	public void evictCache(){
53
		log.info("Evicting indexDsInfo cache");
54
	}
55
}
modules/dnet-directindex-api/tags/dnet-directindex-api-1.1.11/src/main/java/eu/dnetlib/openaire/directindex/api/DirecIndexApiException.java
1
package eu.dnetlib.openaire.directindex.api;
2

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

  
5
public class DirecIndexApiException extends RMIException {
6

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

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

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

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

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

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

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

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

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

  
21
	private DB db;
22
	private String collection;
23

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

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

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

  
36
		return new Iterator<String>() {
37

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

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

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

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

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

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

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

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

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

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

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

  
97
	@Required
98
	public void setCollection(final String collection) {
99
		this.collection = collection;
100
	}
... This diff was truncated because it exceeds the maximum size that can be displayed.

Also available in: Unified diff