Project

General

Profile

« Previous | Next » 

Revision 62821

Added by Alessia Bardi over 1 year ago

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

View differences:

modules/dnet-directindex-api/tags/dnet-directindex-api-4.0.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-4.0.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-4.0.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-4.0.0/pom.xml
1
<?xml version="1.0" ?>
2
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
3
	<parent>
4
		<groupId>eu.dnetlib</groupId>
5
		<artifactId>dnet45-parent</artifactId>
6
		<version>1.0.0</version>
7
		<relativePath />
8
	</parent>
9
	<modelVersion>4.0.0</modelVersion>
10
	<groupId>eu.dnetlib</groupId>
11
	<artifactId>dnet-directindex-api</artifactId>
12
	<packaging>jar</packaging>
13
	<version>4.0.0</version>
14

  
15
	<scm>
16
		<developerConnection>scm:svn:https://svn.driver.research-infrastructures.eu/driver/dnet45/modules/dnet-directindex-api/tags/dnet-directindex-api-4.0.0</developerConnection>
17
	</scm>
18
	<dependencies>
19
		<dependency>
20
			<groupId>eu.dnetlib</groupId>
21
			<artifactId>dnet-openaireplus-mapping-utils</artifactId>
22
			<version>[7.0.0,8.0.0)</version>
23
			<exclusions>
24
				<exclusion>
25
					<groupId>eu.dnetlib</groupId>
26
					<artifactId>dnet-hadoop-commons</artifactId>
27
				</exclusion>
28
			</exclusions>
29
		</dependency>
30
		<dependency>
31
			<groupId>eu.dnetlib</groupId>
32
			<artifactId>dnet-index-client</artifactId>
33
			<version>[3.0.0,4.0.0)</version>
34
		</dependency>
35
		<dependency>
36
			<groupId>junit</groupId>
37
			<artifactId>junit</artifactId>
38
			<version>${junit.version}</version>
39
			<scope>test</scope>
40
		</dependency>
41
		<dependency>
42
			<groupId>io.springfox</groupId>
43
			<artifactId>springfox-swagger2</artifactId>
44
			<version>${springfox-version}</version>
45
		</dependency>
46
		<dependency>
47
			<groupId>org.mockito</groupId>
48
			<artifactId>mockito-core</artifactId>
49
			<version>1.9.5</version>
50
		</dependency>
51
		<dependency>
52
			<groupId>org.apache.velocity</groupId>
53
			<artifactId>velocity</artifactId>
54
			<version>1.7</version>
55
			<exclusions>
56
				<exclusion>
57
					<artifactId>antlr</artifactId>
58
					<groupId>antlr</groupId>
59
				</exclusion>
60
			</exclusions>
61
		</dependency>
62
		<dependency>
63
			<groupId>org.apache.velocity</groupId>
64
			<artifactId>velocity-tools</artifactId>
65
			<version>2.0</version>
66
			<exclusions>
67
				<exclusion>
68
					<artifactId>antlr</artifactId>
69
					<groupId>antlr</groupId>
70
				</exclusion>
71
			</exclusions>
72
		</dependency>
73
		<dependency>
74
			<groupId>org.springframework</groupId>
75
			<artifactId>spring-context-support</artifactId>
76
			<version>${spring.version}</version>
77
		</dependency>
78
		<dependency>
79
			<groupId>com.fasterxml.jackson.core</groupId>
80
			<artifactId>jackson-annotations</artifactId>
81
			<version>2.9.4</version>
82
		</dependency>
83
    </dependencies>
84

  
85
	<properties>
86
		<springfox-version>2.5.0</springfox-version>
87
	</properties>
88
</project>
modules/dnet-directindex-api/tags/dnet-directindex-api-4.0.0/src/test/java/eu/dnetlib/openaire/directindex/api/OpenAIRESubmitterUtilsTest.java
1
package eu.dnetlib.openaire.directindex.api;
2

  
3
import static org.mockito.Mockito.CALLS_REAL_METHODS;
4
import static org.mockito.Mockito.doReturn;
5
import static org.mockito.Mockito.mock;
6
import static org.mockito.Mockito.withSettings;
7

  
8
import java.util.ArrayList;
9
import java.util.List;
10
import java.util.Map;
11
import java.util.Map.Entry;
12

  
13
import org.junit.Assert;
14
import org.junit.Before;
15
import org.junit.Ignore;
16
import org.junit.Test;
17
import org.junit.runner.RunWith;
18
import org.mockito.runners.MockitoJUnitRunner;
19

  
20
import com.google.common.collect.Lists;
21
import com.google.common.collect.Maps;
22
import com.google.gson.Gson;
23

  
24
import eu.dnetlib.openaire.directindex.objects.DatasourceEntry;
25

  
26
/**
27
 * Created by Alessia Bardi on 26/05/2017.
28
 *
29
 * @author Alessia Bardi
30
 */
31
@RunWith(MockitoJUnitRunner.class)
32
public class OpenAIRESubmitterUtilsTest {
33

  
34
	private OpenAIRESubmitterUtils utils;
35

  
36
	final String fullProject = "info:eu-repo/grantAgreement/EC/FP7/244909/EU/Making Capabilities Work/WorkAble";
37
	final String minimalProject = "info:eu-repo/grantAgreement/EC/FP7/244909///WorkAble";
38
	final String onlyId = "info:eu-repo/grantAgreement/EC/FP7/244909/";
39
	final String onlyTitle = "info:eu-repo/grantAgreement/EC/FP7/244909/EU/Making Capabilities Work";
40
	final String escapedId = "info:eu-repo/grantAgreement/RCUK//NE%2FL003066%2F1/";
41
	final String heProjectFromZenodo =
42
		"info:eu-repo/grantAgreement/EC/Horizon Europe Framework Programme - HORIZON-CSA\\HORIZON Action Grant Budget-Based/101058527/";
43
	final String chistera = "info:eu-repo/grantAgreement/CHIST-ERA//CHIST-ERA-19-XAI-002/";
44

  
45
	final String intelcomp = "info:eu-repo/grantAgreement/EC/H2020/101004870//A Competitive Intelligence Cloud%2FHPC Platform for AI-based STI Policy Making/IntelComp";
46

  
47
	@Before
48
	public void setup() {
49
		utils = mock(OpenAIRESubmitterUtils.class, withSettings().defaultAnswer(CALLS_REAL_METHODS));
50
		doReturn(Lists.newArrayList("dh-ch", "dariah", "bar", "x")).when(utils).translateZenodoCommunity("https://zenodo.org/communities/dimpo");
51
		doReturn(Lists.newArrayList()).when(utils).translateZenodoCommunity("https://zenodo.org/communities/dumbo");
52

  
53
	}
54

  
55
	@Test
56
	public void testCalculateProjectInfoCHISTERA() {
57
		final Map<String, String> project = utils.calculateProjectInfo(chistera);
58
		print(project);
59
		Assert.assertEquals("CHIST-ERA-19-XAI-002", project.get("code"));
60
		Assert.assertEquals("chistera____::289ec73ce0e9ece89a0cbdf74c445cd8", project.get("id"));
61

  
62
	}
63

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

  
70
	}
71

  
72
	@Test
73
	public void testCalculateProjectInfoZenodoHE() {
74
		final Map<String, String> project = utils.calculateProjectInfo(heProjectFromZenodo);
75
		print(project);
76
		Assert.assertEquals("101058527", project.get("code"));
77
		Assert.assertEquals("corda_____he::eab43774d3762e87f5e66030c6e01d2b", project.get("id"));
78
	}
79

  
80
	@Test
81
	public void testCalculateProjectInfoZenodoIntelComp() {
82
		final Map<String, String> project = utils.calculateProjectInfo(intelcomp);
83
		print(project);
84
		Assert.assertEquals("101004870", project.get("code"));
85
		Assert.assertEquals("corda__h2020::8264fd9d5f5d59b1b76fc618f3a8af24", project.get("id"));
86
		Assert.assertEquals("IntelComp", project.get("acronym"));
87

  
88
	}
89

  
90
	@Test
91
	public void testCalculateProjectInfoEscaped() {
92
		final Map<String, String> project = utils.calculateProjectInfo(escapedId);
93
		print(project);
94
		Assert.assertEquals("NE/L003066/1", project.get("code"));
95
	}
96

  
97
	@Test
98
	public void testCalculateProjectInfoFull() {
99
		final Map<String, String> project = utils.calculateProjectInfo(fullProject);
100
		print(project);
101
		Assert.assertEquals(10, project.size());
102
		for (final String k : project.keySet()) {
103
			Assert.assertNotNull(project.get(k));
104
			Assert.assertNotSame("", project.get(k));
105
		}
106
	}
107

  
108
	@Test
109
	public void testCalculateProjectInfoOnlyId() {
110
		final Map<String, String> project = utils.calculateProjectInfo(onlyId);
111
		print(project);
112
		Assert.assertEquals("244909", project.get("code"));
113
	}
114

  
115
	@Test
116
	public void testCalculateProjectInfoMinimalAcro() {
117
		final Map<String, String> project = utils.calculateProjectInfo(minimalProject);
118
		print(project);
119
		Assert.assertEquals("244909", project.get("code"));
120
		Assert.assertEquals("WorkAble", project.get("acronym"));
121
	}
122

  
123
	@Test
124
	public void testCalculateProjectInfoOnlyTitle() {
125
		final Map<String, String> project = utils.calculateProjectInfo(onlyTitle);
126
		print(project);
127
		Assert.assertEquals("244909", project.get("code"));
128
		Assert.assertEquals("Making Capabilities Work", project.get("title"));
129
	}
130

  
131
	@Test
132
	public void testJerusalem() {
133
		final String s =
134
			"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";
135
		final Map<String, String> project = utils.calculateProjectInfo(s);
136
		print(project);
137
		Assert.assertEquals("337895", project.get("code"));
138
		Assert.assertEquals("Opening Jerusalem Archives: For a connected History of ‘Citadinité’ in the Holy City (1840-1940)", project.get("title"));
139
		Assert.assertEquals("OPEN-JERUSALEM", project.get("acronym"));
140
	}
141

  
142
	private void print(final Map<String, String> map) {
143
		for (final Entry e : map.entrySet()) {
144
			System.out.println(e.getKey() + " = " + e.getValue());
145
		}
146
	}
147

  
148
	@Test
149
	public void testContext() {
150
		final List<String> zenodoCommunities = new ArrayList<>();
151
		zenodoCommunities.add("https://zenodo.org/communities/dimpo");
152
		zenodoCommunities.add("https://zenodo.org/communities/dumbo");
153
		final Map<String, String> labelMap = Maps.newHashMap();
154
		labelMap.put("dariah", "DARIAH");
155
		labelMap.put("dh-ch", "DH-CH");
156
		labelMap.put("foo", "FOO");
157
		labelMap.put("bar", "");
158

  
159
		final List<OpenAIRESubmitterUtils.ContextInfo> tmp = utils.processContexts(zenodoCommunities, labelMap);
160
		Assert.assertEquals(2, tmp.size());
161

  
162
		Assert.assertTrue(tmp.get(0).getId().equals("dh-ch") || tmp.get(1).getId().equalsIgnoreCase("dh-ch"));
163
		Assert.assertTrue(tmp.get(0).getId().equals("dariah") || tmp.get(1).getId().equalsIgnoreCase("dariah"));
164
	}
165

  
166
	@Test
167
	public void testWrongH2020() {
168
		final String link = "info:eu-repo/grantAgreement/EC/Horizon 2020 Framework Programme - Research and Innovation action/881825/";
169
		final Map<String, String> info = utils.calculateProjectInfo(link);
170
		System.out.println(info);
171
		Assert.assertEquals("H2020", info.get("fundingName"));
172
	}
173

  
174
	@Test
175
	@Ignore
176
	public void testFindDatasource_01() {
177
		final OpenAIRESubmitterUtils utils = new OpenAIRESubmitterUtils("", "https://services.openaire.eu/openaire/ds/");
178
		final DatasourceEntry res = utils.findDatasource("opendoar____::1112");
179
		System.err.println(new Gson().toJson(res));
180
	}
181

  
182
	@Test
183
	@Ignore
184
	public void testFindDatasourceCrossref() {
185
		final OpenAIRESubmitterUtils utils = new OpenAIRESubmitterUtils("", "https://services.openaire.eu/openaire/ds/");
186
		final DatasourceEntry res = utils.findDatasource("openaire____::crossref");
187
		System.err.println(new Gson().toJson(res));
188
	}
189

  
190
}
modules/dnet-directindex-api/tags/dnet-directindex-api-4.0.0/src/test/resources/eu/dnetlib/openaire/directindex/objects/test_zenodo_dmp_intelcomp.json
1
{
2
  "linksToProjects": [
3
    "info:eu-repo/grantAgreement/EC/H2020/101004870//A Competitive Intelligence Cloud%2FHPC Platform for AI-based STI Policy Making/IntelComp"
4
  ],
5
  "description": "<p>IntelComp sets out to build an innovative Cloud Platform that...",
6
  "publisher": "Zenodo",
7
  "contexts": [
8
    "https://zenodo.org/communities/argos",
9
    "https://zenodo.org/communities/intelcomp"
10
  ],
11
  "collectedFromId": "opendoar____::2659",
12
  "hostedById": "opendoar____::2659",
13
  "originalId": "oai:zenodo.org:5109933",
14
  "resourceType": "0045",
15
  "version": "1",
16
  "licenseCode": "OPEN",
17
  "authors": [
18
    "Elli Papadopoulou"
19
  ],
20
  "url": "https://zenodo.org/record/5109933",
21
  "title": "Data Management Plan for IntelComp. D8.2.",
22
  "pids": [
23
    {
24
      "type": "oai",
25
      "value": "oai:zenodo.org:5109933"
26
    },
27
    {
28
      "type": "doi",
29
      "value": "10.5281/zenodo.5109933"
30
    }
31
  ],
32
  "type": "publication"
33
}
modules/dnet-directindex-api/tags/dnet-directindex-api-4.0.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-4.0.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-4.0.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-4.0.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-4.0.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-4.0.0/src/test/resources/eu/dnetlib/openaire/directindex/utils/openaireLayoutToRecordStylesheet.xsl
1
<xsl:stylesheet version="1.0"
2
                xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:nxsl="http://www.w3.org/1999/XSL/TransformXX">
3

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

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

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

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

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

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

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

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

  
99

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

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

  
112
</xsl:stylesheet>
modules/dnet-directindex-api/tags/dnet-directindex-api-4.0.0/src/main/java/eu/dnetlib/openaire/directindex/objects/ResultEntryToOaf.java
1
package eu.dnetlib.openaire.directindex.objects;
2

  
3
import java.text.SimpleDateFormat;
4
import java.util.Date;
5
import java.util.HashMap;
6
import java.util.List;
7
import java.util.Map;
8
import java.util.concurrent.TimeUnit;
9

  
10
import org.apache.commons.lang.StringUtils;
11
import org.apache.commons.logging.Log;
12
import org.apache.commons.logging.LogFactory;
13
import org.apache.velocity.app.VelocityEngine;
14
import org.springframework.ui.velocity.VelocityEngineUtils;
15

  
16
import eu.dnetlib.enabling.is.lookup.rmi.ISLookUpException;
17
import eu.dnetlib.enabling.is.lookup.rmi.ISLookUpService;
18
import eu.dnetlib.miscutils.datetime.DateUtils;
19
import eu.dnetlib.miscutils.functional.hash.Hashing;
20
import eu.dnetlib.miscutils.functional.string.EscapeXml;
21
import eu.dnetlib.openaire.directindex.api.DirecIndexApiException;
22
import eu.dnetlib.openaire.directindex.api.OpenAIRESubmitterUtils;
23

  
24
public class ResultEntryToOaf {
25

  
26
	private static final Log log = LogFactory.getLog(ResultEntryToOaf.class);
27

  
28
	private static long last_cache_update = 0;
29
	private static final Map<String, Map<String, String>> cached_vocabularies = new HashMap<>();
30
	private static final Map<String, DatasourceEntry> cached_datasources = new HashMap<>();
31
	private static final Map<String, String> cached_contexts = new HashMap<>();
32

  
33
	private static final String ZENODO_ID="opendoar____::2659";
34

  
35
	private OpenAIRESubmitterUtils utils;
36

  
37
	public ResultEntryToOaf(final OpenAIRESubmitterUtils utils) {
38
		this.utils = utils;
39
	}
40

  
41
	public String asOafRecord(final ResultEntry entry,
42
		final VelocityEngine ve,
43
		final ISLookUpService lookupService,
44
		final String oafSchemaLocation) throws Exception {
45

  
46
		if (StringUtils.isBlank(entry.getOriginalId())
47
			&& StringUtils
48
				.isBlank(entry.getOpenaireId())) {
49
			throw new DirecIndexApiException("One of the following fields is required: originalId or openaireId");
50
		}
51
		if (StringUtils.isBlank(entry.getTitle())) { throw new DirecIndexApiException("A required field is missing: title"); }
52
		if (StringUtils.isBlank(entry.getUrl())) { throw new DirecIndexApiException("A required field is missing: url"); }
53
		if (StringUtils.isBlank(entry.getLicenseCode()) && StringUtils.isBlank(entry.getAccessRightCode())) {
54
			throw new DirecIndexApiException("A required field is missing: accessRightCode");
55
		}
56
		if (StringUtils.isBlank(entry.getResourceType())) { throw new DirecIndexApiException("A required field is missing: resourceType"); }
57
		if (StringUtils.isBlank(entry.getCollectedFromId())) { throw new DirecIndexApiException("A required field is missing: collectedFromId"); }
58
		if (StringUtils.isBlank(entry.getType())) { throw new DirecIndexApiException("A required field is missing: type"); }
59

  
60
		final DatasourceEntry collectedFromEntry = getDatasourceInfo(entry.getCollectedFromId(), utils);
61
		final DatasourceEntry hostedByEntry = getDatasourceInfo(entry.getHostedById(), utils);
62

  
63
		if (StringUtils.isBlank(entry.getOpenaireId())) {
64
			if(entry.getCollectedFromId().equals(ZENODO_ID)){
65
				String doi = entry.getPids().stream().filter(e -> e.getType().equalsIgnoreCase("doi")).findFirst().get().getValue();
66
				entry.setOpenaireId(calculateOpenaireId(doi, collectedFromEntry));
67
			}
68
			else entry.setOpenaireId(calculateOpenaireId(entry.getOriginalId(), collectedFromEntry));
69
		}
70

  
71
		if (!entry.getOpenaireId()
72
			.matches("^\\w{12}::\\w{32}$")) {
73
			throw new DirecIndexApiException(
74
				"Invalid openaireId: " + entry.getOpenaireId() + " - regex ^\\w{12}::\\w{32}$ not matched");
75
		}
76

  
77
		final List<OpenAIRESubmitterUtils.ContextInfo> contextInfos = utils.processContexts(entry.getContexts(), getContexts(lookupService));
78

  
79
		final Map<String, Object> model = new HashMap<>();
80
		model.put("esc", new EscapeXml());
81
		model.put("util", utils);
82
		model.put("pub", entry);
83
		model.put("objIdentifier", entry.getOpenaireId());
84
		model.put("oafSchemaLocation", oafSchemaLocation);
85
		model.put("resultTypes", getVocabulary("dnet:result_typologies", lookupService));
86
		model.put("rights", getVocabulary("dnet:access_modes", lookupService));
87
		model.put("resourceTypes", getVocabulary("dnet:publication_resource", lookupService));
88
		model.put("pidTypes", getVocabulary("dnet:pid_types", lookupService));
89
		model.put("languages", getVocabulary("dnet:languages", lookupService));
90
		model.put("contexts", getContexts(lookupService));
91
		model.put("contextInfo", contextInfos);
92
		model.put("dateOfCollection", new SimpleDateFormat("yyyy-MM-dd\'T\'hh:mm:ss\'Z\'").format(new Date()));
93
		model.put("collectedFrom", collectedFromEntry);
94
		model.put("hostedBy", hostedByEntry);
95

  
96
		return VelocityEngineUtils.mergeTemplateIntoString(ve, "/eu/dnetlib/openaire/directindex/indexRecord.xml.vm", "UTF-8", model);
97
	}
98

  
99
	private synchronized static DatasourceEntry getDatasourceInfo(final String dsId, final OpenAIRESubmitterUtils utils) throws ISLookUpException {
100
		if (StringUtils
101
			.isBlank(dsId)) {
102
			return new DatasourceEntry("openaire____::1256f046-bf1f-4afc-8b47-d0b147148b18", "Unknown Repository", "unknown_____");
103
		}
104

  
105
		if (!cached_datasources.containsKey(dsId)) {
106

  
107
			final DatasourceEntry ds = utils.findDatasource(dsId);
108

  
109
			if (ds == null || StringUtils.isBlank(ds.getName()) || StringUtils.isBlank(ds.getPrefix())) {
110
				log.error("Invalid datasource id: " + dsId);
111
				throw new ISLookUpException("Invalid datasource id: " + dsId);
112
			} else {
113
				cached_datasources.put(dsId, ds);
114
			}
115
		}
116

  
117
		return cached_datasources.get(dsId);
118

  
119
	}
120

  
121
	private synchronized static Map<String, String> getVocabulary(final String voc, final ISLookUpService lookupService) throws ISLookUpException {
122

  
123
		if (DateUtils.now() - last_cache_update < TimeUnit.MINUTES.toMillis(15) && cached_vocabularies.containsKey(voc)) {
124
			return cached_vocabularies.get(voc);
125
		} else {
126
			final String query = "collection('/db/DRIVER/VocabularyDSResources/VocabularyDSResourceType')[.//VOCABULARY_NAME/@code='" + voc
127
				+ "']//TERM/concat(@code, ' @@@ ', @english_name)";
128

  
129
			final Map<String, String> map = new HashMap<>();
130
			for (final String s : lookupService.quickSearchProfile(query)) {
131
				final String[] arr = s.split("@@@");
132
				map.put(arr[0].trim(), arr[1].trim());
133
			}
134

  
135
			cached_vocabularies.put(voc, map);
136

  
137
			last_cache_update = DateUtils.now();
138

  
139
			return map;
140
		}
141
	}
142

  
143
	private synchronized static Map<String, String> getContexts(final ISLookUpService lookupService) throws ISLookUpException {
144
		if (DateUtils.now() - last_cache_update > TimeUnit.MINUTES.toMillis(15) || cached_contexts.isEmpty()) {
145
			final String query =
146
				"collection('/db/DRIVER/ContextDSResources/ContextDSResourceType')[.//context/@type='community' or .//context/@type='ri']//*[name()='context' or name()='category' or name()='concept']/concat(@id, ' @@@ ', @label)";
147

  
148
			cached_contexts.clear();
149
			for (final String s : lookupService.quickSearchProfile(query)) {
150
				final String[] arr = s.split("@@@");
151
				cached_contexts.put(arr[0].trim(), arr[1].trim());
152
			}
153
			last_cache_update = DateUtils.now();
154
		}
155
		return cached_contexts;
156
	}
157

  
158
	private static String calculateOpenaireId(final String originalId, final DatasourceEntry collectedFromEntry) {
159
		return collectedFromEntry.getPrefix() + "::" + Hashing.md5(originalId);
160
	}
161

  
162
	public static String calculateOpenaireId(final String originalId, final String collectedFromId, final OpenAIRESubmitterUtils utils)
163
		throws ISLookUpException {
164
		return calculateOpenaireId(originalId, getDatasourceInfo(collectedFromId, utils));
165
	}
166

  
167
	public OpenAIRESubmitterUtils getUtils() {
168
		return utils;
169
	}
170

  
171
	public void setUtils(final OpenAIRESubmitterUtils utils) {
172
		this.utils = utils;
173
	}
174
}
modules/dnet-directindex-api/tags/dnet-directindex-api-4.0.0/src/main/java/eu/dnetlib/openaire/directindex/objects/DsmDatasourceInfo.java
1
package eu.dnetlib.openaire.directindex.objects;
2

  
3
import java.io.Serializable;
4

  
5
public class DsmDatasourceInfo implements Serializable {
6

  
7
	private static final long serialVersionUID = -593392381920400974L;
8

  
9
	private String id;
10
	private String officialname;
11
	private String namespaceprefix;
12

  
13
	public String getId() {
14
		return id;
15
	}
16

  
17
	public void setId(final String id) {
18
		this.id = id;
19
	}
20

  
21
	public String getOfficialname() {
22
		return officialname;
23
	}
24

  
25
	public void setOfficialname(final String officialname) {
26
		this.officialname = officialname;
27
	}
28

  
29
	public String getNamespaceprefix() {
30
		return namespaceprefix;
31
	}
32

  
33
	public void setNamespaceprefix(final String namespaceprefix) {
34
		this.namespaceprefix = namespaceprefix;
35
	}
36

  
37
}
modules/dnet-directindex-api/tags/dnet-directindex-api-4.0.0/src/main/java/eu/dnetlib/openaire/directindex/objects/DsmSearchRequest.java
1
package eu.dnetlib.openaire.directindex.objects;
2

  
3
import java.io.Serializable;
4

  
5
public class DsmSearchRequest implements Serializable {
6

  
7
	private static final long serialVersionUID = -2532361140043817319L;
8

  
9
	private String id;
10

  
11
	public DsmSearchRequest() {}
12

  
13
	public DsmSearchRequest(final String id) {
14
		this.id = id;
15
	}
16

  
17
	public String getId() {
18
		return id;
19
	}
20

  
21
	public void setId(final String id) {
22
		this.id = id;
23
	}
24
}
modules/dnet-directindex-api/tags/dnet-directindex-api-4.0.0/src/main/java/eu/dnetlib/openaire/directindex/objects/DsmSearchResponse.java
1
package eu.dnetlib.openaire.directindex.objects;
2

  
3
import java.io.Serializable;
4
import java.util.List;
5

  
6
public class DsmSearchResponse implements Serializable {
7

  
8
	private static final long serialVersionUID = 8944122902111813747L;
9

  
10
	private List<DsmDatasourceInfo> datasourceInfo;
11

  
12
	public List<DsmDatasourceInfo> getDatasourceInfo() {
13
		return datasourceInfo;
14
	}
15

  
16
	public void setDatasourceInfo(final List<DsmDatasourceInfo> datasourceInfo) {
17
		this.datasourceInfo = datasourceInfo;
18
	}
19
}
modules/dnet-directindex-api/tags/dnet-directindex-api-4.0.0/src/main/java/eu/dnetlib/openaire/directindex/objects/ResultEntry.java
1
package eu.dnetlib.openaire.directindex.objects;
2

  
3
import com.google.gson.Gson;
4
import eu.dnetlib.enabling.is.lookup.rmi.ISLookUpException;
5
import eu.dnetlib.enabling.is.lookup.rmi.ISLookUpService;
6
import eu.dnetlib.miscutils.datetime.DateUtils;
7
import eu.dnetlib.miscutils.functional.hash.Hashing;
8
import eu.dnetlib.miscutils.functional.string.EscapeXml;
9
import eu.dnetlib.openaire.directindex.api.DirecIndexApiException;
10
import eu.dnetlib.openaire.directindex.api.OpenAIRESubmitterUtils;
11
import io.swagger.annotations.ApiModelProperty;
12
import org.apache.commons.lang.StringUtils;
13
import org.apache.commons.logging.Log;
14
import org.apache.commons.logging.LogFactory;
15
import org.apache.velocity.app.VelocityEngine;
16
import org.springframework.ui.velocity.VelocityEngineUtils;
17

  
18
import java.text.SimpleDateFormat;
19
import java.util.*;
20
import java.util.concurrent.TimeUnit;
21

  
22
/**
23
 * Created by michele on 02/12/15.
24
 */
25
public class ResultEntry {
26

  
27

  
28
	private String openaireId;
29
	private String originalId;
30
	private String title;
31
	private List<String> authors = new ArrayList<>();
32
	private String publisher;
33
	private String description;
34
	private String language;
35
	private List<PidEntry> pids = new ArrayList<>();
36
	/**
37
	 * @Deprecated: use accessRightCode
38
	 */
39
	@Deprecated
40
	private String licenseCode;
41
	private String accessRightCode;
42
	private String embargoEndDate;
43
	/**
44
	 * One of publication, dataset, software, other. Default value is publication.
45
	 */
46
	private String type = "publication";
47
	private String resourceType;
48
	private String url;
49
	private String collectedFromId;
50
	private String hostedById;
51

  
52
	// String according to the EGI context profile, example: egi::classification::natsc::math
53
	private List<String> contexts = new ArrayList<>();
54

  
55
	// String according to openaire guidelines:
56
	// info:eu-repo/grantAgreement/Funder/FundingProgram/ProjectID/[Jurisdiction]/[ProjectName]/[ProjectAcronym]
57
	private List<String> linksToProjects = new ArrayList<>();
58

  
59
	private static final Log log = LogFactory.getLog(ResultEntry.class);
60

  
61
	public ResultEntry() {}
62

  
63
	public String getOpenaireId() {
64
		return openaireId;
65
	}
66

  
67
	public void setOpenaireId(final String openaireId) {
68
		this.openaireId = openaireId;
69
	}
70

  
71
	public String getOriginalId() {
72
		return originalId;
73
	}
74

  
75
	public void setOriginalId(final String originalId) {
76
		this.originalId = originalId;
77
	}
78

  
79
	@ApiModelProperty(required = true)
80
	public String getTitle() {
81
		return title;
82
	}
83

  
84
	public void setTitle(final String title) {
85
		this.title = title;
86
	}
87

  
88
	public List<String> getAuthors() {
89
		return authors;
90
	}
91

  
92
	public void setAuthors(final List<String> authors) {
93
		this.authors = authors;
94
	}
95

  
96
	public String getPublisher() {
97
		return publisher;
98
	}
99

  
100
	public void setPublisher(final String publisher) {
101
		this.publisher = publisher;
102
	}
103

  
104
	public String getDescription() {
105
		return description;
106
	}
107

  
108
	public void setDescription(final String description) {
109
		this.description = description;
110
	}
111

  
112
	@ApiModelProperty(value = "ISO Alpha-3 code. E.g. 'eng', 'ita'")
113
	public String getLanguage() {
114
		return language;
115
	}
116

  
117
	public void setLanguage(final String language) {
118
		this.language = language;
119
	}
120

  
121
	public List<PidEntry> getPids() {
122
		return pids;
123
	}
124

  
125
	public void setPids(final List<PidEntry> pids) {
126
		this.pids = pids;
127
	}
128

  
129
	@Deprecated
130
	@ApiModelProperty(required = false, allowableValues = "OPEN, CLOSED, RESTRICTED, EMBARGO, UNKNOWN, OTHER, OPEN SOURCE")
131
	public String getLicenseCode() {
132
		return licenseCode;
133
	}
134
	@Deprecated
135
	public void setLicenseCode(final String licenseCode) {
136
		this.licenseCode = licenseCode;
137
	}
138

  
139
	/**
140
	 * Set required = true when the deprecated licenseCode is not used anymore by our client and it is removed
141
	 * @return access rights code
142
	 */
143
	@ApiModelProperty(required = false, allowableValues = "OPEN, CLOSED, RESTRICTED, EMBARGO, UNKNOWN, OTHER, OPEN SOURCE")
144
	public String getAccessRightCode() {
145
		return accessRightCode;
146
	}
147

  
148
	public void setAccessRightCode(final String accessRightCode) {
149
		this.accessRightCode = accessRightCode;
150
	}
151

  
152
	@ApiModelProperty(required = true, value = "Use 001 for articles, 021 for datasets, 0029 for software. See: http://api.openaire.eu/vocabularies/dnet:publication_resource for all the available resource types.")
153
	public String getResourceType() {
154
		return resourceType;
155
	}
156

  
157
	public void setResourceType(final String resourceType) {
158
		this.resourceType = resourceType;
159
	}
160

  
161
	@ApiModelProperty(required = true)
162
	public String getUrl() {
163
		return url;
164
	}
165

  
166
	public void setUrl(final String url) {
167
		this.url = url;
168
	}
169

  
170
	@ApiModelProperty(required = true, value = "Use opendoar___::2659 for Zenodo Publications; re3data_____::r3d100010468 for Zenodo datasets; infrastruct::openaire for OpenAIRE portal.")
171
	public String getCollectedFromId() {
172
		return collectedFromId;
173
	}
174

  
175
	public void setCollectedFromId(final String collectedFromId) {
176
		this.collectedFromId = collectedFromId;
177
	}
178

  
179
	public String getHostedById() {
180
		return hostedById;
181
	}
182

  
183
	public void setHostedById(final String hostedById) {
184
		this.hostedById = hostedById;
185
	}
186

  
187
	@ApiModelProperty(value = "E.g. fet, egi::classification::natsc::math::pure, egi::projects::EMI")
188
	public List<String> getContexts() {
189
		return contexts;
190
	}
191

  
192
	public void setContexts(final List<String> contexts) {
193
		this.contexts = contexts;
194
	}
195

  
196
	@ApiModelProperty(value = "E.g. info:eu-repo/grantAgreement/EC/FP7/283595/EU//OpenAIREplus")
197
	public List<String> getLinksToProjects() {
198
		return linksToProjects;
199
	}
200

  
201
	public void setLinksToProjects(final List<String> linksToProjects) {
202
		this.linksToProjects = linksToProjects;
203
	}
204

  
205
	@ApiModelProperty(allowableValues = "publication, dataset, software, other")
206
	public String getType() {
207
		return type;
208
	}
209

  
210
	public void setType(final String type) {
211
		this.type = type;
212
	}
213

  
214
	public String getEmbargoEndDate() {
215
		return embargoEndDate;
216
	}
217

  
218
	public void setEmbargoEndDate(final String embargoEndDate) {
219
		this.embargoEndDate = embargoEndDate;
220
	}
221

  
222
	@Override
223
	public String toString() {
224
		return new Gson().toJson(this);
225
	}
226

  
227
	public String getAnyId() {
228
		return StringUtils.isNotBlank(openaireId) ? openaireId : originalId;
229
	}
230
}
modules/dnet-directindex-api/tags/dnet-directindex-api-4.0.0/src/main/java/eu/dnetlib/openaire/directindex/objects/ZenodoContextList.java
1
package eu.dnetlib.openaire.directindex.objects;
2

  
3
import java.util.ArrayList;
4
import java.util.List;
5
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
6

  
7
@JsonIgnoreProperties(ignoreUnknown = true)
8
public class ZenodoContextList {
9

  
10

  
11
        private String zenodoid;
12

  
13

  
14
        private List<String> openAirecommunitylist;
15

  
16

  
17

  
18
        public List<String> getOpenAirecommunitylist() {
19
            return openAirecommunitylist;
20
        }
21

  
22
        public void setOpenAirecommunitylist(List<String> openAirecommunitylist) {
23
            this.openAirecommunitylist = openAirecommunitylist;
24

  
25
        }
26

  
27
        public String getZenodoid() {
28
            return zenodoid;
29
        }
30

  
31
        public void setZenodoid(String zenodoid) {
32
            this.zenodoid = zenodoid;
33

  
34
        }
35

  
36

  
37

  
38
    }
39

  
40

  
41

  
modules/dnet-directindex-api/tags/dnet-directindex-api-4.0.0/src/main/java/eu/dnetlib/openaire/directindex/objects/DatasourceEntry.java
1
package eu.dnetlib.openaire.directindex.objects;
2

  
3
import eu.dnetlib.miscutils.functional.hash.Hashing;
4
import org.apache.commons.lang.StringUtils;
5

  
6
/**
7
 * Created by michele on 02/12/15.
8
 */
9
public class DatasourceEntry {
10

  
11
	private String id;
12
	private String name;
13
	private String prefix;
14

  
15
	public DatasourceEntry() {
16
	}
17

  
18
	public DatasourceEntry(final String id, final String name, final String prefix) {
19
		this.id = id;
20
		this.name = name;
21
		this.prefix = prefix;
22
	}
23

  
24
	public String getId() {
25
		return id;
26
	}
27

  
28
	public void setId(final String id) {
29
		this.id = id;
30
	}
31

  
32
	public String getName() {
33
		return name;
34
	}
35

  
36
	public void setName(final String name) {
37
		this.name = name;
38
	}
39

  
40
	public String getPrefix() {
41
		return prefix;
42
	}
43

  
44
	public void setPrefix(final String prefix) {
45
		this.prefix = prefix;
46
	}
47

  
48
	public String calculateOpenaireId() {
49
		if (StringUtils.isNotBlank(id)) {
50
			final String[] arr = id.split("::");
51
			if (arr.length == 2) {
52
				return String.format("%s::%s", arr[0], Hashing.md5(arr[1]));
53
			}
54
		}
55
		return "";
56
	}
57
}
modules/dnet-directindex-api/tags/dnet-directindex-api-4.0.0/src/main/java/eu/dnetlib/openaire/directindex/objects/PidEntry.java
1
package eu.dnetlib.openaire.directindex.objects;
2

  
3
import io.swagger.annotations.ApiModelProperty;
4

  
5
/**
6
 * Created by michele on 02/12/15.
7
 */
8
public class PidEntry {
9

  
10
	private String type;
11
	private String value;
12

  
13
	public PidEntry() {
14
	}
15

  
16
	public PidEntry(final String type, final String value) {
17
		this.type = type;
18
		this.value = value;
19
	}
20

  
21
	@ApiModelProperty(required = true, value = "E.g. doi, pmc, urn. See http://api.openaire.eu/vocabularies/dnet:pid_types")
22
	public String getType() {
23
		return type;
24
	}
25

  
26
	public void setType(final String type) {
27
		this.type = type;
28
	}
29

  
30
	@ApiModelProperty(required = true)
31
	public String getValue() {
32
		return value;
33
	}
34

  
35
	public void setValue(final String value) {
36
		this.value = value;
37
	}
38
}
modules/dnet-directindex-api/tags/dnet-directindex-api-4.0.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

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

  
9
import org.apache.commons.lang.exception.ExceptionUtils;
10
import org.apache.commons.logging.Log;
11
import org.apache.commons.logging.LogFactory;
12
import org.apache.solr.client.solrj.impl.CloudSolrClient;
13
import org.apache.solr.common.SolrInputDocument;
14
import org.apache.velocity.app.VelocityEngine;
15
import org.springframework.beans.factory.annotation.Autowired;
16
import org.springframework.beans.factory.annotation.Value;
17
import org.springframework.http.HttpStatus;
18
import org.springframework.stereotype.Controller;
19
import org.springframework.web.bind.annotation.ExceptionHandler;
20
import org.springframework.web.bind.annotation.PathVariable;
21
import org.springframework.web.bind.annotation.RequestBody;
22
import org.springframework.web.bind.annotation.RequestMapping;
23
import org.springframework.web.bind.annotation.RequestMethod;
24
import org.springframework.web.bind.annotation.RequestParam;
25
import org.springframework.web.bind.annotation.ResponseBody;
26
import org.springframework.web.bind.annotation.ResponseStatus;
27

  
28
import com.google.gson.Gson;
29

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

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

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

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

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

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

  
57
	@Resource
58
	private UniqueServiceLocator serviceLocator;
59

  
60
	@Resource
61
	private OafToIndexRecordFactory oafToIndexRecordFactory;
62

  
63
	@Resource
64
	private RecentResultsQueue recentResultsQueue;
65

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

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

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

  
75
	@Autowired
76
	private IndexDSRetriever indexDSRetriever;
77

  
78
	private OpenAIRESubmitterUtils utils;
79

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

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

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

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

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

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

  
126
	}
127

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

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

  
143
		return deleteResult(openaireId);
144
	}
145

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

  
... This diff was truncated because it exceeds the maximum size that can be displayed.

Also available in: Unified diff