Project

General

Profile

« Previous | Next » 

Revision 61343

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

View differences:

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

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

  
9
import com.google.common.collect.Lists;
10
import com.google.common.collect.Maps;
11
import org.junit.Assert;
12
import org.junit.Before;
13
import org.junit.Test;
14

  
15
import org.junit.runner.RunWith;
16
import org.mockito.runners.MockitoJUnitRunner;
17

  
18
import static org.mockito.Mockito.*;
19

  
20
/**
21
 * Created by Alessia Bardi on 26/05/2017.
22
 *
23
 * @author Alessia Bardi
24
 */
25
@RunWith(MockitoJUnitRunner.class)
26
public class OpenAIRESubmitterUtilsTest {
27

  
28
	private OpenAIRESubmitterUtils utils;
29

  
30
	final String fullProject = "info:eu-repo/grantAgreement/EC/FP7/244909/EU/Making Capabilities Work/WorkAble";
31
	final String minimalProject = "info:eu-repo/grantAgreement/EC/FP7/244909///WorkAble";
32
	final String onlyId = "info:eu-repo/grantAgreement/EC/FP7/244909/";
33
	final String onlyTitle = "info:eu-repo/grantAgreement/EC/FP7/244909/EU/Making Capabilities Work";
34
	final String escapedId = "info:eu-repo/grantAgreement/RCUK//NE%2FL003066%2F1/";
35

  
36

  
37
	@Before
38
	public void setup(){
39
		utils = mock(OpenAIRESubmitterUtils.class, withSettings().defaultAnswer(CALLS_REAL_METHODS));
40
		doReturn(Lists.newArrayList("dh-ch", "dariah", "bar", "x")).when(utils).translateZenodoCommunity("https://zenodo.org/communities/dimpo");
41
		doReturn(Lists.newArrayList()).when(utils).translateZenodoCommunity("https://zenodo.org/communities/dumbo");
42

  
43
	}
44

  
45
	@Test
46
	public void testCalculateProjectInfoEscaped() {
47
		final Map<String, String> project = utils.calculateProjectInfo(escapedId);
48
		print(project);
49
		Assert.assertEquals("NE/L003066/1", project.get("code"));
50
	}
51

  
52
	@Test
53
	public void testCalculateProjectInfoFull() {
54
		final Map<String, String> project = utils.calculateProjectInfo(fullProject);
55
		print(project);
56
		Assert.assertEquals(10, project.size());
57
		for(String k : project.keySet()){
58
			Assert.assertNotNull(project.get(k));
59
			Assert.assertNotSame("", project.get(k));
60
		}
61
	}
62

  
63
	@Test
64
	public void testCalculateProjectInfoOnlyId() {
65
		final Map<String, String> project = utils.calculateProjectInfo(onlyId);
66
		print(project);
67
		Assert.assertEquals("44909", project.get("code"));
68
	}
69

  
70
	@Test
71
	public void testCalculateProjectInfoMinimalAcro() {
72
		final Map<String, String> project = utils.calculateProjectInfo(minimalProject);
73
		print(project);
74
		Assert.assertEquals("44909", project.get("code"));
75
		Assert.assertEquals("WorkAble", project.get("acronym"));
76
	}
77

  
78
	@Test
79
	public void testCalculateProjectInfoOnlyTitle() {
80
		final Map<String, String> project = utils.calculateProjectInfo(onlyTitle);
81
		print(project);
82
		Assert.assertEquals("44909", project.get("code"));
83
		Assert.assertEquals("Making Capabilities Work", project.get("title"));
84
	}
85

  
86
	@Test
87
	public void testJerusalem(){
88
		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";
89
		final Map<String, String> project = utils.calculateProjectInfo(s);
90
		print(project);
91
		Assert.assertEquals("337895", project.get("code"));
92
		Assert.assertEquals("Opening Jerusalem Archives: For a connected History of ‘Citadinité’ in the Holy City (1840-1940)", project.get("title"));
93
		Assert.assertEquals("OPEN-JERUSALEM", project.get("acronym"));
94
	}
95

  
96
	private void print(final Map<String, String> map) {
97
		for (final Entry e : map.entrySet()) {
98
			System.out.println(e.getKey() + " = " + e.getValue());
99
		}
100
	}
101

  
102
	@Test
103
	public void testContext(){
104
		List<String> zenodoCommunities = new ArrayList<>();
105
		zenodoCommunities.add("https://zenodo.org/communities/dimpo");
106
		zenodoCommunities.add("https://zenodo.org/communities/dumbo");
107
		Map<String, String> labelMap = Maps.newHashMap();
108
		labelMap.put("dariah", "DARIAH" );
109
		labelMap.put("dh-ch", "DH-CH" );
110
		labelMap.put("foo", "FOO" );
111
		labelMap.put("bar", "" );
112

  
113
		List<OpenAIRESubmitterUtils.ContextInfo> tmp = utils.processContexts(zenodoCommunities, labelMap);
114
		Assert.assertEquals(2, tmp.size());
115

  
116
		Assert.assertTrue(tmp.get(0).getId().equals("dh-ch") || tmp.get(1).getId().equalsIgnoreCase("dh-ch"));
117
		Assert.assertTrue(tmp.get(0).getId().equals("dariah") || tmp.get(1).getId().equalsIgnoreCase("dariah"));
118
	}
119

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

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

  
22
import java.io.InputStreamReader;
23
import java.io.StringReader;
24
import java.util.ArrayList;
25
import java.util.Arrays;
26
import java.util.Properties;
27

  
28
import static org.mockito.Matchers.anyString;
29
import static org.mockito.Mockito.*;
30
import static org.mockito.Mockito.doReturn;
31

  
32
/**
33
 * Created by michele on 14/12/15.
34
 */
35
@RunWith(MockitoJUnitRunner.class)
36
public class ResultEntryToOafTest {
37

  
38
	private VelocityEngine ve;
39

  
40
	private final String community_api = "https://dev-openaire.d4science.org/openaire/community/";
41

  
42
	@Mock
43
	private ISLookUpService lookUpService;
44

  
45
	private ResultEntryToOaf toOaf;
46
	private OpenAIRESubmitterUtils utils;
47

  
48
	@Before
49
	public void setUp() throws Exception {
50

  
51
		utils = mock(OpenAIRESubmitterUtils.class, withSettings().defaultAnswer(CALLS_REAL_METHODS));
52
		doReturn(Lists.newArrayList("dh-ch", "dariah", "bar", "x")).when(utils).translateZenodoCommunity("https://zenodo.org/communities/dimpo");
53
		doReturn(Lists.newArrayList()).when(utils).translateZenodoCommunity("https://zenodo.org/communities/dumbo");
54
		doReturn(Lists.newArrayList("noLabel", "enermaps")).when(utils).translateZenodoCommunity("https://sandbox.zenodo.org/communities/oac-ni");
55
		doReturn(Lists.newArrayList("noLabel", "enermaps")).when(utils).translateZenodoCommunity("https://zenodo.org/communities/oac-ni");
56

  
57

  
58

  
59
		toOaf = new ResultEntryToOaf();
60
		toOaf.setUtils(utils);
61

  
62
		final Properties props = new Properties();
63
		props.setProperty("resource.loader", "class");
64
		props.setProperty("class.resource.loader.class", "org.apache.velocity.runtime.resource.loader.ClasspathResourceLoader");
65
		props.setProperty("runtime.log.logsystem.class", "org.apache.velocity.runtime.log.Log4JLogChute");
66
		ve = new VelocityEngine();
67
		ve.init(props);
68

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

  
96
		when(lookUpService.getResourceProfileByQuery(anyString())).thenAnswer(invocation -> "REPO NAME @@@ repo________");
97

  
98

  
99
	}
100

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

  
127
		final Document doc = new SAXReader().read(new StringReader(xml));
128

  
129
		final OutputFormat format = OutputFormat.createPrettyPrint();
130

  
131
		final XMLWriter writer = new XMLWriter(System.out, format);
132

  
133
		writer.write(doc);
134

  
135
		/* writer.close(); */
136

  
137
	}
138

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

  
164
		final Document doc = new SAXReader().read(new StringReader(xml));
165

  
166
		final OutputFormat format = OutputFormat.createPrettyPrint();
167

  
168
		final XMLWriter writer = new XMLWriter(System.out, format);
169

  
170
		writer.write(doc);
171

  
172
		/* writer.close(); */
173

  
174
	}
175

  
176
	@Test
177
	public void testAsORP() throws Exception {
178
		final ResultEntry pub = new ResultEntry();
179
		pub.setOriginalId("ORIG_ID_1234");
180
		pub.setTitle("TEST TITLE <test>");
181
		pub.getAuthors().add("Michele Artini");
182
		pub.getAuthors().add("Claudio Atzori");
183
		pub.getAuthors().add("Alessia Bardi");
184
		pub.setPublisher("Test publisher");
185
		pub.setDescription("DESCRIPTION & DESCRIPTION & DESCRIPTION & DESCRIPTION & DESCRIPTION & DESCRIPTION & DESCRIPTION ");
186
		pub.setLanguage("ita");
187
		pub.setLicenseCode("CLOSED");
188
		pub.setAccessRightCode("OPEN");
189
		pub.setResourceType("0020");
190
		pub.setType("other");
191
		pub.setUrl("http://test.it/a=1&b=2");
192
		pub.getPids().add(new PidEntry("doi", "10.000/xyz-123"));
193
		pub.getPids().add(new PidEntry("oai", "oai:1234"));
194
		pub.setCollectedFromId("test________::zenodo");
195
		pub.setHostedById("test________::UNKNOWN");
196
		pub.getLinksToProjects().add("info:eu-repo/grantAgreement/EC/FP7/283595/EU//OpenAIREplus");
197
		pub.getLinksToProjects().add("info:eu-repo/grantAgreement/EC/FP7/244909/EU/Making Capabilities Work/WorkAble");
198
		pub.getContexts().add("egi::classification::natsc::math::pure");
199
		pub.getContexts().add("egi::classification::natsc::math::stats");
200
		final String xml = toOaf.asOafRecord(pub,ve, lookUpService, "http://oaf/oaf.xsd",community_api);
201

  
202
		final Document doc = new SAXReader().read(new StringReader(xml));
203

  
204
		final OutputFormat format = OutputFormat.createPrettyPrint();
205

  
206
		final XMLWriter writer = new XMLWriter(System.out, format);
207

  
208
		writer.write(doc);
209

  
210
		/* writer.close(); */
211

  
212
	}
213

  
214
	@Test
215
	public void testAsIndexRecord_json() throws Exception {
216
		testAsIndexRecord_json("test_record.json");
217

  
218
	}
219

  
220
	@Test
221
	public void testAsIndexRecord_json_with_greek_chars() throws Exception {
222

  
223
		testAsIndexRecord_json("test_record_with_greek_chars.json");
224

  
225
	}
226

  
227
	@Test
228
	public void testAsIndexRecord_openaireId() throws Exception {
229

  
230
		testAsIndexRecord_json("test_record_openaireId.json");
231

  
232
	}
233

  
234
	@Test(expected = DirecIndexApiException.class)
235
	public void testAsIndexRecord_wrongOpenaireId() throws Exception {
236

  
237
		testAsIndexRecord_json("test_record_wrong_openaireId.json");
238

  
239
	}
240

  
241
	@Test
242
	public void testAsIndexRecord_json_zenodo() throws Exception {
243

  
244
		testAsIndexRecord_json("test_zenodo.json");
245

  
246
	}
247

  
248
	@Test
249
	public void testAsIndexRecord_json_zenodoWithAmpersand() throws Exception {
250

  
251
		testAsIndexRecord_json("test_zenodoAmpersandEverywhere.json");
252

  
253
	}
254

  
255
	@Test
256
	public void testAsIndexRecord_json_software() throws Exception {
257

  
258
		testAsIndexRecord_json("test_record_software.json");
259

  
260
	}
261

  
262
	@Test
263
	public void testAsIndexRecord_json_orp() throws Exception {
264

  
265
		testAsIndexRecord_json("test_record_orp.json");
266

  
267
	}
268

  
269
	private void testAsIndexRecord_json(final String filename) throws Exception {
270
		final ResultEntry pub =
271
				new Gson().fromJson(new InputStreamReader(getClass().getResourceAsStream(filename)), ResultEntry.class);
272

  
273

  
274
		final String xml = toOaf.asOafRecord(pub,ve, lookUpService, "http://oaf/oaf.xsd",community_api);
275
		//System.out.println(xml);
276

  
277
		final Document doc = new SAXReader().read(new StringReader(xml));
278

  
279
		final OutputFormat format = OutputFormat.createPrettyPrint();
280

  
281
		final XMLWriter writer = new XMLWriter(System.out, format);
282

  
283
		writer.write(doc);
284

  
285
		/* writer.close(); */
286
	}
287

  
288
	@Test
289
	public void testAsIndexRecord_json_zenodocommunities()throws Exception{
290
		testAsIndexRecord_json("test_zenodo_community.json");
291
	}
292

  
293
	@Test
294
	public void testAsIndexRecordFromSandbox_json_zenodocommunities()throws Exception{
295
		testAsIndexRecord_json("test_zenodo_community2.json");
296
	}
297

  
298
	@Test
299
	public void testEscapeUnicode() {
300
		final String unicodeTxt =
301
				"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$";
302
		System.out.println(StringEscapeUtils.escapeXml11(unicodeTxt));
303
	}
304

  
305
}
modules/dnet-directindex-api/tags/dnet-directindex-api-2.3.0/src/test/resources/eu/dnetlib/openaire/directindex/objects/test_record_software.json
1
{
2
  "openaireId":"od_______278::d5b39693ac6c2197e8cf48008a982951",
3
  "originalId": "oai:rudar.ruc.dk:1800/24691",
4
  "type": "software",
5
  "title": "Software test",
6
  "authors": [
7
	"Sloan, Patrick Alexander Raaby",
8
	"Strange, Gustav Valdemar"
9
  ],
10
  "publisher": "",
11
  "description": "This is for testing software",
12
  "language": "eng",
13
  "pids": [],
14
  "licenseCode": "OPEN SOURCE",
15
  "resourceType": "0000",
16
  "url": "http://rudar.ruc.dk/handle/1800/24691",
17
  "collectedFromId": "opendoar____::278",
18
  "hostedById": "opendoar____::278",
19
  "linksToProjects": [],
20
  "contexts": []
21
}
modules/dnet-directindex-api/tags/dnet-directindex-api-2.3.0/src/test/resources/eu/dnetlib/openaire/directindex/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.3.0/src/test/resources/eu/dnetlib/openaire/directindex/objects/test_record_openaireId.json
1
{
2
  "openaireId":"dedup_wf_001::ab42e8116f4ae3c4021fb7c643a8167a",
3
  "originalId": "ORIG_ID_TEST",
4
  "type": "publication",
5
  "title": "TEST TITLE",
6
  "authors": [
7
	"Michele Artini",
8
	"Claudio Atzori",
9
	"Alessia Bardi"
10
  ],
11
  "publisher": "Test publisher",
12
  "description": "DESCRIPTION DESCRIPTION DESCRIPTION DESCRIPTION DESCRIPTION DESCRIPTION",
13
  "language": "ita",
14
  "pids": [
15
	{
16
	  "type": "doi",
17
	  "value": "10.000/xyz-123"
18
	},
19
	{
20
	  "type": "oai",
21
	  "value": "oai:1234"
22
	}
23
  ],
24
  "accessRightCode": "EMBARGO",
25
  "licenseCode": "OPEN",
26
  "embargoEndDate": "2018-02-02",
27
  "resourceType": "0001",
28
  "url": "http://test.it/xyz",
29
  "collectedFromId": "opendoar____::2659",
30
  "hostedById": "opendoar____::2659",
31
  "linksToProjects": [
32
	"info:eu-repo/grantAgreement/EC/FP7/283595/EU//OpenAIREplus",
33
	"info:eu-repo/grantAgreement/EC/FP7/244909/EU/Making Capabilities Work/WorkAble"
34
  ],
35
  "contexts": [
36
	"egi::classification::natsc::math::pure",
37
	"egi::classification::natsc::math::stats"
38
  ]
39
}
modules/dnet-directindex-api/tags/dnet-directindex-api-2.3.0/src/test/resources/eu/dnetlib/openaire/directindex/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.3.0/src/test/resources/eu/dnetlib/openaire/directindex/objects/test_record_orp.json
1
{
2
  "openaireId":"od_______278::d5b39693ac6c2197e8cf48008a982951",
3
  "originalId": "oai:rudar.ruc.dk:1800/24691",
4
  "type": "other",
5
  "title": "Other test record",
6
  "authors": [
7
    "Sloan, Patrick Alexander Raaby",
8
    "Strange, Gustav Valdemar"
9
  ],
10
  "publisher": "",
11
  "description": "This is for testing software",
12
  "language": "eng",
13
  "pids": [],
14
  "licenseCode": "OPEN SOURCE",
15
  "resourceType": "0000",
16
  "url": "http://rudar.ruc.dk/handle/1800/24691",
17
  "collectedFromId": "opendoar____::278",
18
  "hostedById": "opendoar____::278",
19
  "linksToProjects": [],
20
  "contexts": []
21
}
modules/dnet-directindex-api/tags/dnet-directindex-api-2.3.0/src/test/resources/eu/dnetlib/openaire/directindex/objects/test_zenodo.json
1
{
2
  "authors":[
3
	"Alouges, Fran\u00e7ois",
4
	"Di Fratta, Giovanni"
5
  ],
6
  "collectedFromId":"opendoar____::2659",
7
  "description":"The paper is about the parking 3-sphere swimmer ($\\text{sPr}_3$). This is a low-Reynolds number model swimmer composed of three balls of equal radii. The three balls can move along three horizontal axes (supported in the same plane) that mutually meet at the center of $\\text{sPr}_3$ with angles of $120^{\u2218}$ . The governing dynamical system is introduced and the implications of its geometric symmetries revealed. It is then shown that, in the first order range of small strokes, optimal periodic strokes are ellipses embedded in 3d space, i.e. closed curves of the form $t\ud835\udfc4 [0,2\u03c0] \u21a6 (\\cos t)u + (\\sin t)v$ for suitable orthogonal vectors $u$ and $v$ of $\u211d^3$. A simple analytic expression for the vectors $u$ and $v$ is derived. The results of the paper are used in a second article where the real physical dynamics of $\\text{sPr}_3$ is analyzed in the asymptotic range of very long arms. ; Comment: 17 pages, 4 figures",
8
  "hostedById":"opendoar____::2659",
9
  "licenseCode":"OPEN",
10
  "originalId":"oai:zenodo.org:996201",
11
  "pids":[
12
	{
13
	  "type":"oai",
14
	  "value":"oai:zenodo.org:996201"
15
	},
16
	{
17
	  "type":"doi",
18
	  "value":"10.5281/zenodo.996201"
19
	}
20
  ],
21
  "publisher":"Zenodo",
22
  "resourceType":"0020",
23
  "title":"Parking 3-sphere swimmer. I. Energy minimizing strokes",
24
  "type":"publication",
25
  "url":"https://zenodo.org/record/996201"
26
}
modules/dnet-directindex-api/tags/dnet-directindex-api-2.3.0/src/test/resources/eu/dnetlib/openaire/directindex/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.3.0/src/test/resources/eu/dnetlib/openaire/directindex/objects/test_record_ariadne.json
1
{
2
  "openaireId":"od_______278::d5b39693ac6c2197e8cf48008a982950",
3
  "originalId": "oai:rudar.ruc.dk:1800/24690",
4
  "type": "publication",
5
  "title": "Autofiktion",
6
  "authors": [
7
	"Sloan, Patrick Alexander Raaby",
8
	"Strange, Gustav Valdemar",
9
	"Freund-Jensen, Sofie",
10
	"Canvin, Emilie Meistrup",
11
	"Faaborg, Ida Selvejer",
12
	"Kruse, Mikkel"
13
  ],
14
  "publisher": "",
15
  "description": "The following paper is a project on the autofictional book Færdig med Eddy Bellegueule by Édouard Louis (2015). The main focus is to ascertain how the novel is an expression of the author’s effort to connect social life and literature, and what part autofiction as a genre plays in this process. A textual analysis will describe the narrator’s position, and the aesthetic grip of the novel. Furthermore, we will analyze the central themes in Louis’ novel with theories by sociologist Pierre Bourdieu, gender theorist Judith Butler and postcolonial theorist Gayatri Spivak. This includes symbolic violence, gender roles, language and suppression. With use of classic literary theory and the more recent and specific theory on autofiction, the paper concludes, that Færdig med Eddy Bellegueule is based on non-fictional events, but presents these events through a fictionalization that raise the story into a literary work of art. The genre autofiction encircles a current tendency to blend non-fictional events and characters into literature, and Færdig med Eddy Bellegueule writes itself perfectly into this twilight zone between fact and fiction.",
16
  "language": "eng",
17
  "pids": [],
18
  "licenseCode": "OPEN",
19
  "resourceType": "0006",
20
  "url": "http://rudar.ruc.dk/handle/1800/24690",
21
  "collectedFromId": "opendoar____::278",
22
  "hostedById": "opendoar____::278",
23
  "linksToProjects": [],
24
  "contexts": []
25
}
modules/dnet-directindex-api/tags/dnet-directindex-api-2.3.0/src/test/resources/eu/dnetlib/openaire/directindex/objects/test_zenodo_problems.json
1
{
2
  "authors": ["Milanese, Alessio", "Mende, Daniel", "Zeller, Georg", "Sunagawa, Shinichi"],
3
  "collectedFromId": "re3data_____::r3d100010468",
4
  "description": "<p>We simulated ten human gut metagenomic samples to assess the taxonomic quantification accuracy of the mOTUs tool (<a href=\"http: \// motu-tool.org \/\">link</a>). In this directory you can find the metagenomic samples, the gold standard (used to produce them) and the profiles obtained with four metagenomic profiler tools.</p>\\n\\n<p>Check README.txt for more information.</p>",
5
  "hostedById": "re3data_____::r3d100010468",
6
  "licenseCode": "OPEN",
7
  "originalId": "10.5281/zenodo.1473645",
8
  "pids": [
9
    {"type": "oai", "value": "oai:zenodo.org:1473645"},
10
    {"type": "doi", "value": "10.5281/zenodo.1473645"}
11
  ],
12
  "publisher": "Zenodo",
13
  "resourceType": "0021",
14
  "title": "Simulated Human gut metagenomic samples to benchmark mOTUs v2",
15
  "type": "dataset",
16
  "url": "https://zenodo.org/record/1473645",
17
  "version": "2"
18
}
modules/dnet-directindex-api/tags/dnet-directindex-api-2.3.0/src/test/resources/eu/dnetlib/openaire/directindex/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.3.0/src/test/resources/eu/dnetlib/openaire/directindex/objects/test_zenodo_community.json
1
{"authors": ["Dag Haug", "Marius J\xf8hndal"],
2
  "collectedFromId": "re3data_____::r3d100010468",
3
  "contexts": ["https://sandbox.zenodo.org/communities/oac-ni","pippo", "egi"],
4
  "description": "<p>Official releases of the PROIEL treebank of ancient Indo-European languages</p>",
5
  "hostedById": "re3data_____::r3d100010468",
6
  "licenseCode": "OPEN",
7
  "originalId": "10.5281/zenodo.11003",
8
  "pids": [{"type": "oai", "value": "oai:zenodo.org:11003"},
9
  {"type": "doi", "value": "10.5281/zenodo.11003"}],
10
  "publisher": "Zenodo",
11
  "resourceType": "0021",
12
  "title": "proiel-treebank: 20140723 version",
13
  "type": "dataset",
14
  "url": "https://zenodo.org/record/11003"}
modules/dnet-directindex-api/tags/dnet-directindex-api-2.3.0/src/test/resources/eu/dnetlib/openaire/directindex/objects/test_zenodo_community2.json
1
{"authors":["test"],
2
  "collectedFromId":"re3data_____::r3d100010468",
3
  "contexts":["https://zenodo.org/communities/oac-ni"],
4
  "description":"<p>test</p>",
5
  "hostedById":"re3data_____::r3d100010468",
6
  "licenseCode":"OPEN",
7
  "originalId":"oai:zenodo.org:315784",
8
  "pids":[{"type":"oai","value":"oai:zenodo.org:315784"},
9
    {"type":"doi","value":"10.5072/zenodo.315784"}],"resourceType":"0020","title":"test","type":"other","url":"https://zenodo.org/record/315784"}
modules/dnet-directindex-api/tags/dnet-directindex-api-2.3.0/src/test/resources/eu/dnetlib/openaire/directindex/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.3.0/src/test/resources/eu/dnetlib/openaire/directindex/objects/test_record_with_greek_chars.json
1
{
2
  "originalId": "ORIG_ID_12345",
3
  "title": "TEST TITLE WITH Greek Characters",
4
  "authors": [
5
	"αβγδεζηθικλμ νξοπρσςτυφχψω",
6
	"ΑΒΓΔΕΖΗΘΙΚΛ ΜΝΞΟΠΡΣΤΥΦΧΨΩ"
7
  ],
8
  "publisher": "âââââââ",
9
  "description": "Αν περιμένατε να βρίσκεται εδώ μια σελίδα και δεν υπάρχει, η σελίδα μπορεί να μην εμφανίζεται λόγω καθυστέρησης στην ανανέωση της βάσης δεδομένων, ή μπορεί να έχει διαγραφεί. (Δείτε την γρήγορη διαγραφή σελίδων για πιθανούς λόγους). Μπορείτε να δοκιμάστε την λειτουργία εκκαθάρισης, και να ελέγξετε το αρχείο διαγραφών.",
10
  "language": "ell",
11
  "pids": [
12
	{
13
	  "type": "doi",
14
	  "value": "10.000/xyz-123-gr"
15
	}
16
  ],
17
  "licenseCode": "EMBARGO",
18
  "embargoEndDate": "2018-02-02",
19
  "resourceType": "0001",
20
  "url": "http://test.it/xyz",
21
  "collectedFromId": "opendoar____::2659",
22
  "hostedById": "opendoar____::2367",
23
  "linksToProjects": [
24
	"info:eu-repo/grantAgreement/EC/FP7/123456/EU//Test"
25
  ],
26
  "contexts": [
27
	"egi::classification::natsc::math::stats"
28
  ]
29
}
modules/dnet-directindex-api/tags/dnet-directindex-api-2.3.0/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.3.0/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.3.0/src/main/java/eu/dnetlib/openaire/directindex/api/OpenaireResultSubmitter.java
1
package eu.dnetlib.openaire.directindex.api;
2

  
3
import java.text.SimpleDateFormat;
4
import java.util.Date;
5
import javax.annotation.Resource;
6

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

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

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

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

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

  
44
	@Resource
45
	private UniqueServiceLocator serviceLocator;
46

  
47
	@Resource
48
	private OafToIndexRecordFactory oafToIndexRecordFactory;
49

  
50
	@Resource
51
	private RecentResultsQueue recentResultsQueue;
52

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

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

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

  
62
	@Autowired
63
	private IndexDSRetriever indexDSRetriever;
64

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

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

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

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

  
92

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

  
99
	}
100

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

  
109

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

  
115
		return deleteResult(openaireId);
116
	}
117

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

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

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

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

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

  
144
	private String feed(final ResultEntry pub) throws DirecIndexApiException {
145
		log.debug(pub);
146
		try {
147
			ResultEntryToOaf toOaf = new ResultEntryToOaf();
148
			final IndexDsInfo info = indexDSRetriever.calculateCurrentIndexDsInfo();
149
			final String oafRecord = toOaf.asOafRecord(pub, 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 = 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.3.0/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.3.0/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
import java.util.stream.Stream;
8

  
9
import com.google.common.base.Function;
10
import com.google.common.collect.Lists;
11
import com.google.common.collect.Sets;
12
import eu.dnetlib.enabling.is.lookup.rmi.ISLookUpException;
13
import eu.dnetlib.enabling.is.lookup.rmi.ISLookUpService;
14
import eu.dnetlib.miscutils.functional.hash.Hashing;
15
import eu.dnetlib.openaire.directindex.objects.DatasourceEntry;
16
import eu.dnetlib.openaire.directindex.objects.ZenodoContextList;
17
import org.apache.commons.lang.StringUtils;
18
import org.springframework.web.client.RestClientException;
19
import org.springframework.web.client.RestTemplate;
20

  
21
/**
22
 * Created by michele on 15/01/16.
23
 */
24
public class OpenAIRESubmitterUtils {
25

  
26
    private static final org.apache.commons.logging.Log log = org.apache.commons.logging.LogFactory.getLog(OpenAIRESubmitterUtils.class);
27
    private static final String ZENODO_COMMUNITY = "zenodo.org/communities/";
28
    private String community_api;
29

  
30
    public OpenAIRESubmitterUtils(String community_api) {
31
        this.community_api = community_api;
32
    }
33

  
34
    public Map<String, String> calculateProjectInfo(final String link) {
35
        final Map<String, String> info = new HashMap<String, String>();
36
        final String[] arr = link.split("/");
37
        // info:eu-repo/grantAgreement/EC/FP7/244909/EU/Making Capabilities Work/WorkAble
38

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

  
58
    //TODO: remove me when Zenodo ingests the good UKRI projects
59
    protected String fixFunderShortName(final String funderShortName) {
60
        switch (funderShortName) {
61
            case "RCUK":
62
                return "UKRI";
63
            default:
64
                return funderShortName;
65
        }
66
    }
67

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

  
99
    protected String calculateProjectId(final String funderShortName, final String funding, final String code) {
100
        final String suffix = Hashing.md5(unescape(code));
101
        //final String suffix = Hashing.md5(code);
102
        final String funderPrefix = calculateFunderPrefix(funderShortName, funding);
103
        return funderPrefix + suffix;
104
    }
105

  
106
    private String unescape(String code) {
107
        return StringUtils.replaceChars(code, "%2F", "/");
108
    }
109

  
110
    protected String calculateFunderId(final String funderShortName, final String funding) {
111
        switch (funderShortName.toLowerCase()) {
112
            case "ec":
113
                return "ec__________::EC";
114
            default:
115
                String fixedFunderShortName = fixFunderShortName(funderShortName);
116
                String prefix = calculateFunderPrefix(fixedFunderShortName, funding);
117
                return prefix + fixedFunderShortName.toUpperCase();
118
        }
119
    }
120

  
121

  
122
    protected String calculateFunderName(final String funderShortName) {
123

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

  
196
    public Collection<String> translateZenodoCommunity(final String community) {
197
        if (community.contains(ZENODO_COMMUNITY)) {
198
            String context = community.substring(community.lastIndexOf("/") + 1);
199
            RestTemplate rt = new RestTemplate();
200
            try {
201
                return new HashSet<>(rt.getForObject(community_api + context + "/openairecommunities", ZenodoContextList.class)
202
                        .getOpenAirecommunitylist());
203
            } catch (RestClientException rce) {
204
                log.error("Unable to get object for " + community_api + context + "/openairecommunities");
205
                return new HashSet<>();
206
            }
207
        } else return Sets.newHashSet(community);
208
    }
209

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

  
226
    public List<ContextInfo> processContexts(final List<String> zenodoCommunities, final Map<String, String> labelMap) {
227
        return zenodoCommunities.stream().map(c -> translateZenodoCommunity(c))
228
                .flatMap(coll -> coll.stream())
229
                .map(ctx -> createContextInfo(ctx.split("::"), 0,  labelMap))
230
                .filter(info -> StringUtils.isNotBlank(info.getLabel()))
231
                .collect(Collectors.toList());
232
    }
233

  
234

  
235

  
236
    public class ContextInfo {
237

  
238
        private String elem;
239
        private String id;
240
        private String label;
241
        private List<ContextInfo> children = new ArrayList<ContextInfo>();
242

  
243
        public ContextInfo(final String elem,
244
                           final String id, final String label) {
245
            this.elem = elem;
246
            this.id = id;
247
            this.label = label;
248
        }
249

  
250
        public String getElem() {
251
            return elem;
252
        }
253

  
254
        public void setElem(final String elem) {
255
            this.elem = elem;
256
        }
257

  
258
        public String getId() {
259
            return id;
260
        }
261

  
262
        public void setId(final String id) {
263
            this.id = id;
264
        }
265

  
266
        public List<ContextInfo> getChildren() {
267
            return children;
268
        }
269

  
270
        public void setChildren(final List<ContextInfo> children) {
271
            this.children = children;
272
        }
273

  
274
        public boolean isRoot() {
275
            return elem.equals("context");
276
        }
277

  
278
        public String getLabel() {
279
            return label;
280
        }
281

  
282
        public void setLabel(String label) {
283
            this.label = label;
284
        }
285
    }
286
}
... This diff was truncated because it exceeds the maximum size that can be displayed.

Also available in: Unified diff