Project

General

Profile

« Previous | Next » 

Revision 51088

reorganized packages

View differences:

modules/dnet-openaire-exporter/trunk/src/test/java/eu/dnetlib/openaire/exporter/model/project/ProjectDetailsTest.java
1
package eu.dnetlib.openaire.exporter.model.project;
2

  
3
import java.io.IOException;
4

  
5
import org.junit.Test;
6

  
7
/**
8
 * Created by claudio on 05/07/2017.
9
 */
10
public class ProjectDetailsTest {
11

  
12
	@Test
13
	public void testCSV() throws IOException {
14

  
15
		final ProjectDetails p = ProjectDetails.fromCSV(
16
				"arc_________::ANZCCART,,ANZCCART,{},\"[\"\"\\u003cfundingtree\\u003e\\n      \\u003cfunder\\u003e\\n         \\u003cid\\u003earc_________::ARC\\u003c/id\\u003e\\n         \\u003cshortname\\u003eARC\\u003c/shortname\\u003e\\n         \\u003cname\\u003eAustralian Research Council (ARC)\\u003c/name\\u003e\\n         \\u003cjurisdiction\\u003eAU\\u003c/jurisdiction\\u003e\\n      \\u003c/funder\\u003e\\n      \\u003cfunding_level_0\\u003e\\n         \\u003cid\\u003earc_________::ARC::Special Research initiative (Australian and New Zealand Council for the Care of Animals in Research and Teaching)\\u003c/id\\u003e\\n         \\u003cname\\u003eSpecial Research initiative (Australian and New Zealand Council for the Care of Animals in Research and Teaching)\\u003c/name\\u003e\\n         \\u003cdescription\\u003eSpecial Research initiative (Australian and New Zealand Council for the Care of Animals in Research and Teaching)\\u003c/description\\u003e\\n         \\u003cparent/\\u003e\\n         \\u003cclass\\u003earc:fundingStream\\u003c/class\\u003e\\n      \\u003c/funding_level_0\\u003e\\n   \\u003c/fundingtree\\u003e\"\"]\"");
17

  
18
		System.out.println(p.asJson());
19

  
20
		System.out.println(p.asCSV());
21

  
22

  
23
	}
24

  
25
}
modules/dnet-openaire-exporter/trunk/src/test/java/eu/dnetlib/openaire/exporter/project/ProjectsControllerTest.java
1
package eu.dnetlib.openaire.exporter.project;
2

  
3
import java.io.IOException;
4

  
5
import org.antlr.stringtemplate.StringTemplate;
6
import org.apache.commons.io.IOUtils;
7
import org.apache.commons.logging.Log;
8
import org.apache.commons.logging.LogFactory;
9
import org.junit.Before;
10
import org.junit.Ignore;
11
import org.junit.Test;
12
import org.junit.runner.RunWith;
13
import org.springframework.boot.test.context.SpringBootTest;
14
import org.springframework.core.io.ClassPathResource;
15
import org.springframework.core.io.Resource;
16
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
17

  
18
import static org.junit.Assert.assertEquals;
19

  
20
@Ignore
21
@SpringBootTest
22
@RunWith(SpringJUnit4ClassRunner.class)
23
public class ProjectsControllerTest {
24

  
25
	private static final Log log = LogFactory.getLog(ProjectsControllerTest.class);
26
	private String queryTemplate = "/eu/dnetlib/openaire/exporter/sql/projects_fundings.sql.st";
27

  
28
	private Resource expectedQueryTemplate = new ClassPathResource("/eu/dnetlib/openaire/exporter/sql/expected_projects_fundings.sql.st");
29

  
30
	private ProjectsController controller;
31
	private ProjectQueryParams params;
32

  
33
	@Before
34
	public void setup() {
35
		controller = new ProjectsController();
36
		Resource template = new ClassPathResource(queryTemplate);
37

  
38
		//TODO reimplement bean injection for testing
39
		//controller.setProjectsFundingQueryTemplate(template);
40
		params = new ProjectQueryParams();
41
	}
42

  
43
	@Test
44
	public void testObtainFP7Query() throws IllegalArgumentException, IOException {
45
		params.setFundingProgramme("FP7");
46
		params.setFundingPath(null);
47
		String res = controller.obtainQuery(params);
48
		final StringTemplate st = new StringTemplate(IOUtils.toString(expectedQueryTemplate.getInputStream(),  ProjectsController.UTF8));
49
		st.setAttribute("fundingprefix", "ec__________::EC::FP7");
50
		log.debug(res);
51
		log.debug(st);
52
		assertEquals(st.toString(), res);
53
	}
54

  
55
	@Test
56
	public void testObtainFP7QuerySP1() throws IllegalArgumentException, IOException {
57
		params.setFundingProgramme("FP7");
58
		params.setFundingPath("SP1");
59
		String res = controller.obtainQuery(params);
60
		final StringTemplate st = new StringTemplate(IOUtils.toString(expectedQueryTemplate.getInputStream(),  ProjectsController.UTF8));
61
		st.setAttribute("fundingprefix", "ec__________::EC::FP7::SP1");
62
		log.debug(res);
63
		assertEquals(st.toString(), res);
64
	}
65

  
66
	@Test
67
	public void testObtainFP7QueryHealth() throws IllegalArgumentException, IOException {
68
		params.setFundingProgramme("FP7");
69
		params.setFundingPath("SP1::HEALTH");
70
		String res = controller.obtainQuery(params);
71
		final StringTemplate st = new StringTemplate(IOUtils.toString(expectedQueryTemplate.getInputStream(),  ProjectsController.UTF8));
72
		st.setAttribute("fundingprefix", "ec__________::EC::FP7::SP1::HEALTH");
73
		log.debug(res);
74
		assertEquals(st.toString(), res);
75
	}
76

  
77
	@Test
78
	public void testObtainFP7QueryHealth2() throws IllegalArgumentException, IOException {
79
		params.setFundingProgramme("FP7");
80
		params.setFundingPath("%::HEALTH");
81
		String res = controller.obtainQuery(params);
82
		final StringTemplate st = new StringTemplate(IOUtils.toString(expectedQueryTemplate.getInputStream(),  ProjectsController.UTF8));
83
		st.setAttribute("fundingprefix", "ec__________::EC::FP7::%::HEALTH");
84
		log.debug(res);
85
		assertEquals(st.toString(), res);
86
	}
87

  
88
	@Test
89
	public void testObtainWellcomeTrustQuery() throws IllegalArgumentException, IOException {
90
		params.setFundingProgramme("WT");
91
		params.setFundingPath(null);
92
		String res = controller.obtainQuery(params);
93
		final StringTemplate st = new StringTemplate(IOUtils.toString(expectedQueryTemplate.getInputStream(),  ProjectsController.UTF8));
94
		st.setAttribute("fundingprefix", "wt__________::WT");
95
		log.debug(res);
96
		assertEquals(st.toString(), res);
97
	}
98

  
99
	@Test
100
	public void testObtainFCTQuery() throws IllegalArgumentException, IOException {
101
		params.setFundingProgramme("FCT");
102
		params.setFundingPath(null);
103
		String res = controller.obtainQuery(params);
104
		final StringTemplate st = new StringTemplate(IOUtils.toString(expectedQueryTemplate.getInputStream(),  ProjectsController.UTF8));
105
		st.setAttribute("fundingprefix", "fct_________::FCT");
106
		log.debug(res);
107
		assertEquals(st.toString(), res);
108
	}
109

  
110
	@Test
111
	public void testQueryWithDateParams() throws IllegalArgumentException, IOException {
112
		params.setFundingProgramme("WT");
113
		params.setFundingPath(null);
114
		params.setStartFrom("2015-05-04");
115
		String res = controller.obtainQuery(params);
116
		log.debug(res);
117
		final StringTemplate st = new StringTemplate(IOUtils.toString(expectedQueryTemplate.getInputStream(),  ProjectsController.UTF8));
118
		st.setAttribute("fundingprefix", "wt__________::WT");
119
		String q = st.toString() + " AND startdate >= '2015-05-04'";
120
		assertEquals(q, res);
121
	}
122

  
123
	@Test
124
	public void testObtainSNSFQuery() throws IllegalArgumentException, IOException {
125
		params.setFundingProgramme("SNSF");
126
		params.setFundingPath(null);
127
		String res = controller.obtainQuery(params);
128
		final StringTemplate st = new StringTemplate(IOUtils.toString(expectedQueryTemplate.getInputStream(),  ProjectsController.UTF8));
129
		st.setAttribute("fundingprefix", "snsf________::SNSF");
130
		log.debug(res);
131
		assertEquals(st.toString(), res);
132
	}
133

  
134
}
modules/dnet-openaire-exporter/trunk/src/test/java/eu/dnetlib/openaire/exporter/project/ProjectQueryParamsTest.java
1
package eu.dnetlib.openaire.exporter.project;
2

  
3
import eu.dnetlib.openaire.exporter.project.ProjectQueryParams;
4
import org.junit.Before;
5
import org.junit.Test;
6

  
7
import static org.junit.Assert.assertEquals;
8

  
9
public class ProjectQueryParamsTest {
10

  
11
	private ProjectQueryParams queryParams;
12

  
13
	@Before
14
	public void setUp() throws Exception {
15
		queryParams = new ProjectQueryParams();
16

  
17
	}
18

  
19
	@Test
20
	public void testVerifyParamWhiteSpace() {
21
		queryParams.verifyParam("Discovery Projects");
22
	}
23

  
24
	@Test
25
	public void testVerifyParamPercentage() {
26
		queryParams.verifyParam("Discovery%20Projects");
27
	}
28

  
29
	@Test
30
	public void testVerifyDateParam(){
31
		String correctDate = "2012-03-04";
32
		assertEquals(correctDate, queryParams.verifyDateParam(correctDate));
33

  
34
	}
35

  
36
	@Test(expected=IllegalArgumentException.class)
37
	public void testVerifyDateParamException(){
38
		String wrongDate = "12-12-12";
39
		queryParams.verifyDateParam(wrongDate);
40

  
41
	}
42
}
modules/dnet-openaire-exporter/trunk/src/test/java/eu/dnetlib/openaire/exporter/funders/FunderContextClientTest.java
1
package eu.dnetlib.openaire.exporter.funders;
2

  
3
import java.io.IOException;
4
import java.nio.charset.Charset;
5
import java.util.concurrent.LinkedBlockingQueue;
6

  
7
import com.google.gson.Gson;
8
import com.google.gson.GsonBuilder;
9
import eu.dnetlib.openaire.exporter.funders.context.Context;
10
import eu.dnetlib.openaire.exporter.funders.context.MappingUtils;
11
import eu.dnetlib.openaire.exporter.funders.model.FunderDetails;
12
import org.apache.commons.io.IOUtils;
13
import org.junit.Before;
14
import org.junit.Test;
15

  
16
import static org.junit.Assert.assertFalse;
17
import static org.junit.Assert.assertNotNull;
18

  
19
public class FunderContextClientTest {
20

  
21
	private FunderDao fDao;
22

  
23
	@Before
24
	public void setUp() {
25
		fDao = new FunderDao();
26
	}
27

  
28
	@Test
29
	public void testParseContextProfile() throws IOException {
30
		final String contextProfile = IOUtils.toString(getClass().getResourceAsStream("ec-fp7.xml"), Charset.defaultCharset());
31
		final Context context = MappingUtils.parseContext(contextProfile, new LinkedBlockingQueue<>());
32

  
33
		assertNotNull(context);
34
		assertNotNull(context.getId());
35

  
36
		final Gson gson = new GsonBuilder().setPrettyPrinting().create();
37
		final String json = gson.toJson(context);
38
		assertNotNull(json);
39
		assertFalse(json.isEmpty());
40

  
41
		//System.out.println(gson.toJson(gson.fromJson(json, Context.class)));
42

  
43
		final FunderDetails funderDetails = MappingUtils.asFunderDetails(context);
44
		//System.out.println(gson.toJson(funderDetails));
45

  
46
	}
47

  
48
}
modules/dnet-openaire-exporter/trunk/src/test/java/eu/dnetlib/openaire/exporter/datasource/DatasourceApiControllerTest.java
1
package eu.dnetlib.openaire.exporter.datasource;
2

  
3
import java.nio.charset.Charset;
4
import java.util.List;
5

  
6
import eu.dnetlib.openaire.exporter.vocabularies.Country;
7
import org.junit.Ignore;
8
import org.junit.Test;
9
import org.junit.runner.RunWith;
10
import org.springframework.beans.factory.annotation.Autowired;
11
import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest;
12
import org.springframework.boot.test.mock.mockito.MockBean;
13
import org.springframework.http.MediaType;
14
import org.springframework.test.context.junit4.SpringRunner;
15
import org.springframework.test.web.servlet.MockMvc;
16

  
17
import static java.util.Collections.singletonList;
18
import static org.hamcrest.Matchers.hasSize;
19
import static org.hamcrest.core.Is.is;
20
import static org.mockito.BDDMockito.given;
21
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
22
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath;
23
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
24

  
25
@RunWith(SpringRunner.class)
26
@WebMvcTest(DatasourcesApiController.class)
27
public class DatasourceApiControllerTest {
28

  
29
	public static final MediaType APPLICATION_JSON_UTF8 = new MediaType(
30
			MediaType.APPLICATION_JSON.getType(),
31
			MediaType.APPLICATION_JSON.getSubtype(),
32
			Charset.forName("utf8"));
33

  
34
	@Autowired
35
	private MockMvc mvc;
36

  
37
	@MockBean
38
	private DatasourcesApiController dsController;
39

  
40
	@Test
41
	@Ignore
42
	public void listCountries() throws Exception {
43
		final Country c = new Country("it", "Italy");
44
		final List<Country> countries = singletonList(c);
45

  
46
		given(dsController.listCountries()).willReturn(countries);
47

  
48
		mvc.perform(get("/ds/countries")
49
				.contentType(APPLICATION_JSON_UTF8))
50
				.andExpect(status().isOk())
51
				.andExpect(jsonPath("$", hasSize(1)))
52
				.andExpect(jsonPath("$[0].code", is(c.getCode())))
53
				.andExpect(jsonPath("$[0].name", is(c.getName())));
54
	}
55

  
56
}
modules/dnet-openaire-exporter/trunk/src/test/resources/eu/dnetlib/openaire/exporter/sql/expected_projects_fundings.sql.st
1
SELECT
2
	funder,
3
	jurisdiction,
4
	fundingpathid,
5
	acronym,
6
	title,
7
	code,
8
	startdate,
9
	enddate
10
FROM projects_api
11
WHERE fundingpathid like '$fundingprefix$%'
modules/dnet-openaire-exporter/trunk/src/test/resources/eu/dnetlib/openaire/exporter/funders/ec-fp7.xml
1
<RESOURCE_PROFILE xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
2
	<HEADER>
3
		<RESOURCE_IDENTIFIER value="40093bfb-22af-4188-9cb6-a43923dfd878_Q29udGV4dERTUmVzb3VyY2VzL0NvbnRleHREU1Jlc291cmNlVHlwZQ=="/>
4
		<RESOURCE_TYPE value="ContextDSResourceType"/>
5
		<RESOURCE_KIND value="ContextDSResources"/>
6
		<RESOURCE_URI value=""/>
7
		<DATE_OF_CREATION value="2017-11-26T21:23:48+00:00"/>
8
	</HEADER>
9
	<BODY>
10
		<CONFIGURATION>
11
			<context id="EC" label="European Commission" type="funding">
12
				<param name="prova">PROVA</param>
13
				<category claim="false" id="EC::FP7" label="SEVENTH FRAMEWORK PROGRAMME">
14
					<param name="name">FP7</param>
15
					<param name="openaireId">ec__________::EC::FP7</param>
16
					<param name="class">ec:frameworkprogram</param>
17
					<concept claim="false" id="EC::FP7::SP3" label="SP3-People">
18
						<param name="name">SP3</param>
19
						<param name="openaireId">ec__________::EC::FP7::SP3</param>
20
						<param name="class">ec:specificprogram</param>
21
						<concept claim="false" id="EC::FP7::SP3::PEOPLE" label="Marie-Curie Actions">
22
							<param name="name">PEOPLE</param>
23
							<param name="openaireId">ec__________::EC::FP7::SP3::PEOPLE</param>
24
							<param name="class">ec:program</param>
25
						</concept>
26
					</concept>
27
					<concept claim="false" id="EC::FP7::SP1" label="SP1-Cooperation">
28
						<param name="name">SP1</param>
29
						<param name="openaireId">ec__________::EC::FP7::SP1</param>
30
						<param name="class">ec:specificprogram</param>
31
						<concept claim="false" id="EC::FP7::SP1::ENERGY" label="Energy">
32
							<param name="name">ENERGY</param>
33
							<param name="openaireId">ec__________::EC::FP7::SP1::ENERGY</param>
34
							<param name="class">ec:program</param>
35
						</concept>
36
						<concept claim="false" id="EC::FP7::SP1::ENV" label="Environment (including Climate Change)">
37
							<param name="name">ENV</param>
38
							<param name="openaireId">ec__________::EC::FP7::SP1::ENV</param>
39
							<param name="class">ec:program</param>
40
						</concept>
41
						<concept claim="false" id="EC::FP7::SP1::TPT" label="Transport (including Aeronautics)">
42
							<param name="name">TPT</param>
43
							<param name="openaireId">ec__________::EC::FP7::SP1::TPT</param>
44
							<param name="class">ec:program</param>
45
						</concept>
46
						<concept claim="false" id="EC::FP7::SP1::NMP" label="Nanosciences, Nanotechnologies, Materials and new Production Technologies - NMP">
47
							<param name="name">NMP</param>
48
							<param name="openaireId">ec__________::EC::FP7::SP1::NMP</param>
49
							<param name="class">ec:program</param>
50
						</concept>
51
						<concept claim="false" id="EC::FP7::SP1::SP1-JTI" label="Joint Technology Initiatives (Annex IV-SP1)">
52
							<param name="name">SP1-JTI</param>
53
							<param name="openaireId">ec__________::EC::FP7::SP1::SP1-JTI</param>
54
							<param name="class">ec:program</param>
55
						</concept>
56
						<concept claim="false" id="EC::FP7::SP1::HEALTH" label="Health">
57
							<param name="name">HEALTH</param>
58
							<param name="openaireId">ec__________::EC::FP7::SP1::HEALTH</param>
59
							<param name="class">ec:program</param>
60
						</concept>
61
						<concept claim="false" id="EC::FP7::SP1::ICT" label="Information and Communication Technologies">
62
							<param name="name">ICT</param>
63
							<param name="openaireId">ec__________::EC::FP7::SP1::ICT</param>
64
							<param name="class">ec:program</param>
65
						</concept>
66
						<concept claim="false" id="EC::FP7::SP1::KBBE" label="Food, Agriculture and Fisheries, and Biotechnology">
67
							<param name="name">KBBE</param>
68
							<param name="openaireId">ec__________::EC::FP7::SP1::KBBE</param>
69
							<param name="class">ec:program</param>
70
						</concept>
71
						<concept claim="false" id="EC::FP7::SP1::SEC" label="Security">
72
							<param name="name">SEC</param>
73
							<param name="openaireId">ec__________::EC::FP7::SP1::SEC</param>
74
							<param name="class">ec:program</param>
75
						</concept>
76
						<concept claim="false" id="EC::FP7::SP1::SSH" label="Socio-economic sciences and Humanities">
77
							<param name="name">SSH</param>
78
							<param name="openaireId">ec__________::EC::FP7::SP1::SSH</param>
79
							<param name="class">ec:program</param>
80
						</concept>
81
						<concept claim="false" id="EC::FP7::SP1::SPA" label="Space">
82
							<param name="name">SPA</param>
83
							<param name="openaireId">ec__________::EC::FP7::SP1::SPA</param>
84
							<param name="class">ec:program</param>
85
						</concept>
86
						<concept claim="false" id="EC::FP7::SP1::GA" label="General Activities">
87
							<param name="name">GA</param>
88
							<param name="openaireId">ec__________::EC::FP7::SP1::GA</param>
89
							<param name="class">ec:program</param>
90
						</concept>
91
					</concept>
92
					<concept claim="false" id="EC::FP7::SP2" label="SP2-Ideas">
93
						<param name="name">SP2</param>
94
						<param name="openaireId">ec__________::EC::FP7::SP2</param>
95
						<param name="class">ec:specificprogram</param>
96
						<concept claim="false" id="EC::FP7::SP2::ERC" label="ERC">
97
							<param name="name">ERC</param>
98
							<param name="openaireId">ec__________::EC::FP7::SP2::ERC</param>
99
							<param name="class">ec:program</param>
100
						</concept>
101
					</concept>
102
					<concept claim="false" id="EC::FP7::SP4" label="SP4-Capacities">
103
						<param name="name">SP4</param>
104
						<param name="openaireId">ec__________::EC::FP7::SP4</param>
105
						<param name="class">ec:specificprogram</param>
106
						<concept claim="false" id="EC::FP7::SP4::SME" label="Research for the benefit of SMEs">
107
							<param name="name">SME</param>
108
							<param name="openaireId">ec__________::EC::FP7::SP4::SME</param>
109
							<param name="class">ec:program</param>
110
						</concept>
111
						<concept claim="false" id="EC::FP7::SP4::INFRA" label="Research Infrastructures">
112
							<param name="name">INFRA</param>
113
							<param name="openaireId">ec__________::EC::FP7::SP4::INFRA</param>
114
							<param name="class">ec:program</param>
115
						</concept>
116
						<concept claim="false" id="EC::FP7::SP4::SiS" label="Science in Society">
117
							<param name="name">SiS</param>
118
							<param name="openaireId">ec__________::EC::FP7::SP4::SiS</param>
119
							<param name="class">ec:program</param>
120
						</concept>
121
						<concept claim="false" id="EC::FP7::SP4::REGIONS" label="Regions of Knowledge">
122
							<param name="name">REGIONS</param>
123
							<param name="openaireId">ec__________::EC::FP7::SP4::REGIONS</param>
124
							<param name="class">ec:program</param>
125
						</concept>
126
						<concept claim="false" id="EC::FP7::SP4::REGPOT" label="Research Potential">
127
							<param name="name">REGPOT</param>
128
							<param name="openaireId">ec__________::EC::FP7::SP4::REGPOT</param>
129
							<param name="class">ec:program</param>
130
						</concept>
131
						<concept claim="false" id="EC::FP7::SP4::INCO" label="Activities of International Cooperation">
132
							<param name="name">INCO</param>
133
							<param name="openaireId">ec__________::EC::FP7::SP4::INCO</param>
134
							<param name="class">ec:program</param>
135
						</concept>
136
						<concept claim="false" id="EC::FP7::SP4::COH" label="Support for the coherent development of research policies">
137
							<param name="name">COH</param>
138
							<param name="openaireId">ec__________::EC::FP7::SP4::COH</param>
139
							<param name="class">ec:program</param>
140
						</concept>
141
					</concept>
142
					<concept claim="false" id="EC::FP7::SP5" label="SP5-Euratom">
143
						<param name="name">SP5</param>
144
						<param name="openaireId">ec__________::EC::FP7::SP5</param>
145
						<param name="class">ec:specificprogram</param>
146
						<concept claim="false" id="EC::FP7::SP5::Fission" label="Nuclear Fission and Radiation Protection">
147
							<param name="name">Fission</param>
148
							<param name="openaireId">ec__________::EC::FP7::SP5::Fission</param>
149
							<param name="class">ec:program</param>
150
						</concept>
151
						<concept claim="false" id="EC::FP7::SP5::Fusion" label="Fusion Energy">
152
							<param name="name">Fusion</param>
153
							<param name="openaireId">ec__________::EC::FP7::SP5::Fusion</param>
154
							<param name="class">ec:program</param>
155
						</concept>
156
					</concept>
157
					<concept claim="false" id="EC::FP7::UNKNOWN" label=" ">
158
						<param name="name">UNKNOWN</param>
159
						<param name="openaireId">ec__________::EC::FP7::UNKNOWN</param>
160
						<param name="class">ec:specificprogram</param>
161
						<concept claim="false" id="EC::FP7::UNKNOWN::UNKNOWN" label=" ">
162
							<param name="name">UNKNOWN</param>
163
							<param name="openaireId">ec__________::EC::FP7::UNKNOWN::UNKNOWN</param>
164
							<param name="class">ec:program</param>
165
						</concept>
166
					</concept>
167
				</category>
168
				<category claim="false" id="EC::H2020" label="Horizon 2020 Framework Programme">
169
					<param name="name">H2020</param>
170
					<param name="openaireId">ec__________::EC::H2020</param>
171
					<param name="class">ec:h2020fundings</param>
172
					<concept claim="false" id="EC::H2020::MSCA-IF-EF-ST" label="Standard European Fellowships">
173
						<param name="name">MSCA-IF-EF-ST</param>
174
						<param name="openaireId">ec__________::EC::H2020::MSCA-IF-EF-ST</param>
175
						<param name="class">ec:h2020toas</param>
176
					</concept>
177
					<concept claim="false" id="EC::H2020::H2020-EEN-SGA" label="Specific Grant Agreement  Enterprise Europe Network (EEN)">
178
						<param name="name">H2020-EEN-SGA</param>
179
						<param name="openaireId">ec__________::EC::H2020::H2020-EEN-SGA</param>
180
						<param name="class">ec:h2020toas</param>
181
					</concept>
182
					<concept claim="false" id="EC::H2020::RIA" label="Research and Innovation action">
183
						<param name="name">RIA</param>
184
						<param name="openaireId">ec__________::EC::H2020::RIA</param>
185
						<param name="class">ec:h2020toas</param>
186
					</concept>
187
					<concept claim="false" id="EC::H2020::ERC" label="European Research Council">
188
						<param name="name">ERC</param>
189
						<param name="openaireId">ec__________::EC::H2020::ERC</param>
190
						<param name="class">ec:h2020fundings</param>
191
						<concept claim="false" id="EC::H2020::ERC::ERC-POC" label="Proof of Concept Grant">
192
							<param name="name">ERC-POC</param>
193
							<param name="openaireId">ec__________::EC::H2020::ERC::ERC-POC</param>
194
							<param name="class">ec:h2020toas</param>
195
						</concept>
196
						<concept claim="false" id="EC::H2020::ERC::ERC-STG" label="Starting Grant">
197
							<param name="name">ERC-STG</param>
198
							<param name="openaireId">ec__________::EC::H2020::ERC::ERC-STG</param>
199
							<param name="class">ec:h2020toas</param>
200
						</concept>
201
						<concept claim="false" id="EC::H2020::ERC::ERC-ADG" label="Advanced Grant">
202
							<param name="name">ERC-ADG</param>
203
							<param name="openaireId">ec__________::EC::H2020::ERC::ERC-ADG</param>
204
							<param name="class">ec:h2020toas</param>
205
						</concept>
206
						<concept claim="false" id="EC::H2020::ERC::ERC-COG" label="Consolidator Grant">
207
							<param name="name">ERC-COG</param>
208
							<param name="openaireId">ec__________::EC::H2020::ERC::ERC-COG</param>
209
							<param name="class">ec:h2020toas</param>
210
						</concept>
211
						<concept claim="false" id="EC::H2020::ERC::ERC-LVG" label="ERC low value grant">
212
							<param name="name">ERC-LVG</param>
213
							<param name="openaireId">ec__________::EC::H2020::ERC::ERC-LVG</param>
214
							<param name="class">ec:h2020toas</param>
215
						</concept>
216
					</concept>
217
					<concept claim="false" id="EC::H2020::MSCA-ITN-ETN" label="European Training Networks">
218
						<param name="name">MSCA-ITN-ETN</param>
219
						<param name="openaireId">ec__________::EC::H2020::MSCA-ITN-ETN</param>
220
						<param name="class">ec:h2020toas</param>
221
					</concept>
222
					<concept claim="false" id="EC::H2020::MSCA-IF-GF" label="Global Fellowships">
223
						<param name="name">MSCA-IF-GF</param>
224
						<param name="openaireId">ec__________::EC::H2020::MSCA-IF-GF</param>
225
						<param name="class">ec:h2020toas</param>
226
					</concept>
227
					<concept claim="false" id="EC::H2020::SME-2" label="SME instrument phase 2">
228
						<param name="name">SME-2</param>
229
						<param name="openaireId">ec__________::EC::H2020::SME-2</param>
230
						<param name="class">ec:h2020toas</param>
231
					</concept>
232
					<concept claim="false" id="EC::H2020::SESAR-IA" label="Innovation action">
233
						<param name="name">SESAR-IA</param>
234
						<param name="openaireId">ec__________::EC::H2020::SESAR-IA</param>
235
						<param name="class">ec:h2020toas</param>
236
					</concept>
237
					<concept claim="false" id="EC::H2020::MSCA-RISE" label="RISE">
238
						<param name="name">MSCA-RISE</param>
239
						<param name="openaireId">ec__________::EC::H2020::MSCA-RISE</param>
240
						<param name="class">ec:h2020toas</param>
241
					</concept>
242
					<concept claim="false" id="EC::H2020::IA" label="Innovation action">
243
						<param name="name">IA</param>
244
						<param name="openaireId">ec__________::EC::H2020::IA</param>
245
						<param name="class">ec:h2020toas</param>
246
					</concept>
247
					<concept claim="false" id="EC::H2020::CSA" label="Coordination and support action">
248
						<param name="name">CSA</param>
249
						<param name="openaireId">ec__________::EC::H2020::CSA</param>
250
						<param name="class">ec:h2020toas</param>
251
					</concept>
252
					<concept claim="false" id="EC::H2020::MSCA-COFUND-DP" label="Doctoral programmes">
253
						<param name="name">MSCA-COFUND-DP</param>
254
						<param name="openaireId">ec__________::EC::H2020::MSCA-COFUND-DP</param>
255
						<param name="class">ec:h2020toas</param>
256
					</concept>
257
					<concept claim="false" id="EC::H2020::SME-1" label="SME instrument phase 1">
258
						<param name="name">SME-1</param>
259
						<param name="openaireId">ec__________::EC::H2020::SME-1</param>
260
						<param name="class">ec:h2020toas</param>
261
					</concept>
262
					<concept claim="false" id="EC::H2020::Shift2Rail-RIA" label="Research and Innovation action">
263
						<param name="name">Shift2Rail-RIA</param>
264
						<param name="openaireId">ec__________::EC::H2020::Shift2Rail-RIA</param>
265
						<param name="class">ec:h2020toas</param>
266
					</concept>
267
					<concept claim="false" id="EC::H2020::CS2-IA" label="Innovation action">
268
						<param name="name">CS2-IA</param>
269
						<param name="openaireId">ec__________::EC::H2020::CS2-IA</param>
270
						<param name="class">ec:h2020toas</param>
271
					</concept>
272
					<concept claim="false" id="EC::H2020::CS2-RIA" label="Research and Innovation action">
273
						<param name="name">CS2-RIA</param>
274
						<param name="openaireId">ec__________::EC::H2020::CS2-RIA</param>
275
						<param name="class">ec:h2020toas</param>
276
					</concept>
277
					<concept claim="false" id="EC::H2020::MSCA-ITN-EID" label="European Industrial Doctorates">
278
						<param name="name">MSCA-ITN-EID</param>
279
						<param name="openaireId">ec__________::EC::H2020::MSCA-ITN-EID</param>
280
						<param name="class">ec:h2020toas</param>
281
					</concept>
282
					<concept claim="false" id="EC::H2020::MSCA-IF-EF-RI" label="Reintegration panel">
283
						<param name="name">MSCA-IF-EF-RI</param>
284
						<param name="openaireId">ec__________::EC::H2020::MSCA-IF-EF-RI</param>
285
						<param name="class">ec:h2020toas</param>
286
					</concept>
287
					<concept claim="false" id="EC::H2020::FCH2-RIA" label="Research and Innovation action">
288
						<param name="name">FCH2-RIA</param>
289
						<param name="openaireId">ec__________::EC::H2020::FCH2-RIA</param>
290
						<param name="class">ec:h2020toas</param>
291
					</concept>
292
					<concept claim="false" id="EC::H2020::ERA-NET-Cofund" label="ERA-NET Cofund">
293
						<param name="name">ERA-NET-Cofund</param>
294
						<param name="openaireId">ec__________::EC::H2020::ERA-NET-Cofund</param>
295
						<param name="class">ec:h2020toas</param>
296
					</concept>
297
					<concept claim="false" id="EC::H2020::SESAR-CSA" label="Coordination and Support Action">
298
						<param name="name">SESAR-CSA</param>
299
						<param name="openaireId">ec__________::EC::H2020::SESAR-CSA</param>
300
						<param name="class">ec:h2020toas</param>
301
					</concept>
302
					<concept claim="false" id="EC::H2020::SESAR-RIA" label="Research and Innovation action">
303
						<param name="name">SESAR-RIA</param>
304
						<param name="openaireId">ec__________::EC::H2020::SESAR-RIA</param>
305
						<param name="class">ec:h2020toas</param>
306
					</concept>
307
					<concept claim="false" id="EC::H2020::BBI-RIA" label="Bio-based Industries Research and Innovation action">
308
						<param name="name">BBI-RIA</param>
309
						<param name="openaireId">ec__________::EC::H2020::BBI-RIA</param>
310
						<param name="class">ec:h2020toas</param>
311
					</concept>
312
					<concept claim="false" id="EC::H2020::MSCA-COFUND-FP" label="Fellowship programmes">
313
						<param name="name">MSCA-COFUND-FP</param>
314
						<param name="openaireId">ec__________::EC::H2020::MSCA-COFUND-FP</param>
315
						<param name="class">ec:h2020toas</param>
316
					</concept>
317
					<concept claim="false" id="EC::H2020::CSA-LS" label="CSA Lump sum">
318
						<param name="name">CSA-LS</param>
319
						<param name="openaireId">ec__________::EC::H2020::CSA-LS</param>
320
						<param name="class">ec:h2020toas</param>
321
					</concept>
322
					<concept claim="false" id="EC::H2020::COFUND-PCP" label="COFUND (PCP)">
323
						<param name="name">COFUND-PCP</param>
324
						<param name="openaireId">ec__________::EC::H2020::COFUND-PCP</param>
325
						<param name="class">ec:h2020toas</param>
326
					</concept>
327
					<concept claim="false" id="EC::H2020::ECSEL-RIA" label="ECSEL Research and Innovation Action">
328
						<param name="name">ECSEL-RIA</param>
329
						<param name="openaireId">ec__________::EC::H2020::ECSEL-RIA</param>
330
						<param name="class">ec:h2020toas</param>
331
					</concept>
332
					<concept claim="false" id="EC::H2020::SGA-CSA" label="Specific Grant agreement and Coordination and Support Action">
333
						<param name="name">SGA-CSA</param>
334
						<param name="openaireId">ec__________::EC::H2020::SGA-CSA</param>
335
						<param name="class">ec:h2020toas</param>
336
					</concept>
337
					<concept claim="false" id="EC::H2020::MSCA-ITN-EJD" label="European Joint Doctorates">
338
						<param name="name">MSCA-ITN-EJD</param>
339
						<param name="openaireId">ec__________::EC::H2020::MSCA-ITN-EJD</param>
340
						<param name="class">ec:h2020toas</param>
341
					</concept>
342
					<concept claim="false" id="EC::H2020::MSCA-IF-EF-CAR" label="Career Restart panel">
343
						<param name="name">MSCA-IF-EF-CAR</param>
344
						<param name="openaireId">ec__________::EC::H2020::MSCA-IF-EF-CAR</param>
345
						<param name="class">ec:h2020toas</param>
346
					</concept>
347
					<concept claim="false" id="EC::H2020::BBI-IA-DEMO" label="Bio-based Industries Innovation action - Demonstration">
348
						<param name="name">BBI-IA-DEMO</param>
349
						<param name="openaireId">ec__________::EC::H2020::BBI-IA-DEMO</param>
350
						<param name="class">ec:h2020toas</param>
351
					</concept>
352
					<concept claim="false" id="EC::H2020::IMI2-RIA" label="Research and Innovation action">
353
						<param name="name">IMI2-RIA</param>
354
						<param name="openaireId">ec__________::EC::H2020::IMI2-RIA</param>
355
						<param name="class">ec:h2020toas</param>
356
					</concept>
357
					<concept claim="false" id="EC::H2020::MSCA-IF-EF-SE" label="Society and Enterprise panel">
358
						<param name="name">MSCA-IF-EF-SE</param>
359
						<param name="openaireId">ec__________::EC::H2020::MSCA-IF-EF-SE</param>
360
						<param name="class">ec:h2020toas</param>
361
					</concept>
362
					<concept claim="false" id="EC::H2020::FCH2-IA" label="Innovation action">
363
						<param name="name">FCH2-IA</param>
364
						<param name="openaireId">ec__________::EC::H2020::FCH2-IA</param>
365
						<param name="class">ec:h2020toas</param>
366
					</concept>
367
					<concept claim="false" id="EC::H2020::BBI-IA-FLAG" label="Bio-based Industries Innovation action - Flagship">
368
						<param name="name">BBI-IA-FLAG</param>
369
						<param name="openaireId">ec__________::EC::H2020::BBI-IA-FLAG</param>
370
						<param name="class">ec:h2020toas</param>
371
					</concept>
372
					<concept claim="false" id="EC::H2020::ECSEL-IA" label="ECSEL Innovation Action">
373
						<param name="name">ECSEL-IA</param>
374
						<param name="openaireId">ec__________::EC::H2020::ECSEL-IA</param>
375
						<param name="class">ec:h2020toas</param>
376
					</concept>
377
					<concept claim="false" id="EC::H2020::BBI-CSA" label="Bio-based Industries Coordination and Support action">
378
						<param name="name">BBI-CSA</param>
379
						<param name="openaireId">ec__________::EC::H2020::BBI-CSA</param>
380
						<param name="class">ec:h2020toas</param>
381
					</concept>
382
					<concept claim="false" id="EC::H2020::IMI2-CSA" label="Coordination &amp; support action">
383
						<param name="name">IMI2-CSA</param>
384
						<param name="openaireId">ec__________::EC::H2020::IMI2-CSA</param>
385
						<param name="class">ec:h2020toas</param>
386
					</concept>
387
					<concept claim="false" id="EC::H2020::PCP" label="Pre-Commercial Procurement">
388
						<param name="name">PCP</param>
389
						<param name="openaireId">ec__________::EC::H2020::PCP</param>
390
						<param name="class">ec:h2020toas</param>
391
					</concept>
392
					<concept claim="false" id="EC::H2020::CS2-CSA" label="Coordination &amp; support action">
393
						<param name="name">CS2-CSA</param>
394
						<param name="openaireId">ec__________::EC::H2020::CS2-CSA</param>
395
						<param name="class">ec:h2020toas</param>
396
					</concept>
397
					<concept claim="false" id="EC::H2020::FCH2-CSA" label="Coordination &amp; support action">
398
						<param name="name">FCH2-CSA</param>
399
						<param name="openaireId">ec__________::EC::H2020::FCH2-CSA</param>
400
						<param name="class">ec:h2020toas</param>
401
					</concept>
402
					<concept claim="false" id="EC::H2020::COFUND-EJP" label="COFUND (European Joint Programme)">
403
						<param name="name">COFUND-EJP</param>
404
						<param name="openaireId">ec__________::EC::H2020::COFUND-EJP</param>
405
						<param name="class">ec:h2020toas</param>
406
					</concept>
407
					<concept claim="false" id="EC::H2020::SGA-RIA" label="SGA-RIA">
408
						<param name="name">SGA-RIA</param>
409
						<param name="openaireId">ec__________::EC::H2020::SGA-RIA</param>
410
						<param name="class">ec:h2020toas</param>
411
					</concept>
412
					<concept claim="false" id="EC::H2020::Shift2Rail-IA" label="Innovation action">
413
						<param name="name">Shift2Rail-IA</param>
414
						<param name="openaireId">ec__________::EC::H2020::Shift2Rail-IA</param>
415
						<param name="class">ec:h2020toas</param>
416
					</concept>
417
					<concept claim="false" id="EC::H2020::Shift2Rail-CSA" label="Coordination and Support action">
418
						<param name="name">Shift2Rail-CSA</param>
419
						<param name="openaireId">ec__________::EC::H2020::Shift2Rail-CSA</param>
420
						<param name="class">ec:h2020toas</param>
421
					</concept>
422
					<concept claim="false" id="EC::H2020::PPI" label="Public Procurement of Innovative solutions">
423
						<param name="name">PPI</param>
424
						<param name="openaireId">ec__________::EC::H2020::PPI</param>
425
						<param name="class">ec:h2020toas</param>
426
					</concept>
427
					<concept claim="false" id="EC::H2020::COFUND-PPI" label="COFUND (PPI)">
428
						<param name="name">COFUND-PPI</param>
429
						<param name="openaireId">ec__________::EC::H2020::COFUND-PPI</param>
430
						<param name="class">ec:h2020toas</param>
431
					</concept>
432
				</category>
433
			</context>
434
		</CONFIGURATION>
435
		<STATUS/>
436
		<SECURITY_PARAMETERS/>
437
	</BODY>
438
</RESOURCE_PROFILE>
modules/dnet-openaire-exporter/trunk/src/main/java/eu/dnetlib/swagger/configuration/SwaggerDocumentationConfig.java
1
package eu.dnetlib.swagger.configuration;
2

  
3
import eu.dnetlib.OpenaireExporterConfig;
4
import eu.dnetlib.OpenaireExporterConfig.Swagger;
5
import eu.dnetlib.openaire.exporter.community.CommunityApiController;
6
import eu.dnetlib.openaire.exporter.datasource.DatasourcesApiController;
7
import eu.dnetlib.openaire.exporter.funders.FundersApiController;
8
import eu.dnetlib.openaire.exporter.model.project.ProjectApi;
9
import eu.dnetlib.openaire.exporter.project.ProjectsController;
10
import org.apache.commons.logging.Log;
11
import org.apache.commons.logging.LogFactory;
12
import org.springframework.beans.factory.annotation.Autowired;
13
import org.springframework.context.annotation.Bean;
14
import org.springframework.context.annotation.Configuration;
15
import springfox.documentation.builders.ApiInfoBuilder;
16
import springfox.documentation.service.ApiInfo;
17
import springfox.documentation.service.Contact;
18
import springfox.documentation.spi.DocumentationType;
19
import springfox.documentation.spring.web.plugins.Docket;
20
import springfox.documentation.swagger2.annotations.EnableSwagger2;
21

  
22
import static springfox.documentation.builders.RequestHandlerSelectors.basePackage;
23

  
24
@Configuration
25
@EnableSwagger2
26
public class SwaggerDocumentationConfig {
27

  
28
	private static final Log log = LogFactory.getLog(SwaggerDocumentationConfig.class);
29

  
30
	@Autowired
31
	private OpenaireExporterConfig config;
32

  
33
    @Bean
34
    public Docket dsm() {
35
        return _docket(
36
        		"Datasource Manager",
37
		        DatasourcesApiController.class.getPackage().getName(),
38
		        config.getSwaggerDsm());
39
    }
40

  
41
	@Bean
42
	public Docket projects() {
43
		return _docket(
44
				"OpenAIRE Projects",
45
				ProjectsController.class.getPackage().getName(),
46
				config.getSwaggerProjects());
47
	}
48

  
49
	@Bean
50
	public Docket funders() {
51
		return _docket(
52
				"OpenAIRE Funders",
53
				FundersApiController.class.getPackage().getName(),
54
				config.getSwaggerFunders());
55
	}
56

  
57
	@Bean
58
	public Docket communities() {
59
		return _docket(
60
				"OpenAIRE Communities",
61
				CommunityApiController.class.getPackage().getName(),
62
				config.getSwaggerCommunities());
63
	}
64

  
65
	private Docket _docket(final String groupName, final String controllerPackage, final Swagger swag) {
66
		return new Docket(DocumentationType.SWAGGER_2)
67
				.groupName(groupName)
68
				.select()
69
				.apis(basePackage(controllerPackage))
70
				.build()
71
				.directModelSubstitute(org.joda.time.LocalDate.class, java.sql.Date.class)
72
				.directModelSubstitute(org.joda.time.DateTime.class, java.util.Date.class)
73
				.apiInfo(apiInfo(swag));
74
	}
75

  
76
	private ApiInfo apiInfo(final Swagger swag) {
77
		return new ApiInfoBuilder()
78
				.title(swag.getApiTitle())
79
				.description(swag.getApiDescription())
80
				.license(swag.getApiLicense())
81
				.licenseUrl(swag.getApiLicenseUrl())
82
				.termsOfServiceUrl("")
83
				.version("1.0.0")
84
				.contact(new Contact(
85
						swag.getApiContactName(),
86
						swag.getApiContactUrl(),
87
						swag.getApiContactEmail()))
88
				.build();
89
	}
90

  
91
}
modules/dnet-openaire-exporter/trunk/src/main/java/eu/dnetlib/swagger/configuration/RFC3339DateFormat.java
1
package eu.dnetlib.swagger.configuration;
2

  
3
import java.text.FieldPosition;
4
import java.util.Date;
5

  
6
import com.fasterxml.jackson.databind.util.ISO8601DateFormat;
7
import com.fasterxml.jackson.databind.util.ISO8601Utils;
8

  
9
public class RFC3339DateFormat extends ISO8601DateFormat {
10

  
11
  // Same as ISO8601DateFormat but serializing milliseconds.
12
  @Override
13
  public StringBuffer format(Date date, StringBuffer toAppendTo, FieldPosition fieldPosition) {
14
    String value = ISO8601Utils.format(date, true);
15
    toAppendTo.append(value);
16
    return toAppendTo;
17
  }
18

  
19
}
modules/dnet-openaire-exporter/trunk/src/main/java/eu/dnetlib/openaire/exporter/community/CommunityApiCore.java
1
package eu.dnetlib.openaire.exporter.community;
2

  
3
import java.io.IOException;
4
import java.util.List;
5
import java.util.Map;
6
import java.util.function.Function;
7
import java.util.stream.Collectors;
8

  
9
import com.google.common.base.Functions;
10
import com.google.common.base.Joiner;
11
import com.google.common.collect.Lists;
12
import eu.dnetlib.openaire.exporter.datasource.clients.ISClient;
13
import eu.dnetlib.openaire.exporter.funders.context.Category;
14
import eu.dnetlib.openaire.exporter.funders.context.Concept;
15
import eu.dnetlib.openaire.exporter.funders.context.Context;
16
import org.apache.commons.lang3.StringUtils;
17
import org.apache.commons.logging.Log;
18
import org.apache.commons.logging.LogFactory;
19
import org.springframework.beans.factory.annotation.Autowired;
20
import org.springframework.stereotype.Component;
21

  
22
import static eu.dnetlib.openaire.exporter.community.CommunityConstants.*;
23

  
24
@Component
25
public class CommunityApiCore {
26

  
27
	private static final Log log = LogFactory.getLog(CommunityApiCore.class);
28

  
29
	@Autowired
30
	private ISClient isClient;
31

  
32
	public List<CommunitySummary> listCommunities() throws CommunityException {
33
		return getContextMap().values().stream()
34
				.filter(context -> !communityBlackList.contains(context.getId()))
35
				.map(CommunityMappingUtils::asCommunitySummary)
36
				.collect(Collectors.toList());
37
	}
38

  
39
	public CommunityDetails getCommunity(final String id) throws CommunityException, CommunityNotFoundException {
40
		final Context context = getContextMap().get(id);
41
		if (context == null || CommunityConstants.communityBlackList.contains(id)) {
42
			throw new CommunityNotFoundException(String.format("community '%s' does not exist", id));
43
		}
44
		return CommunityMappingUtils.asCommunityProfile(context);
45
	}
46

  
47
	public void setCommunity(final String id, final CommunityWritableProperties details) throws CommunityException, CommunityNotFoundException {
48

  
49
		getCommunity(id); // ensure the community exists.
50

  
51
		isClient.updateContextAttribute(id, CLABEL, details.getShortName());
52
		isClient.updateContextParam(id, CSUMMARY_NAME, details.getName());
53
		isClient.updateContextParam(id, CSUMMARY_DESCRIPTION, details.getDescription());
54
		isClient.updateContextParam(id, CSUMMARY_LOGOURL, details.getLogoUrl());
55
		isClient.updateContextParam(id, CSUMMARY_MANAGER, Joiner.on(CSV_DELIMITER).join(details.getManagers()));
56
		isClient.updateContextParam(id, CPROFILE_SUBJECT, Joiner.on(CSV_DELIMITER).join(details.getSubjects()));
57
	}
58

  
59
	public List<CommunityProject> getCommunityProjects(final String id) throws CommunityException, CommunityNotFoundException {
60
		getCommunity(id); // ensure the community exists.
61
		return _getCommunityInfo(id, PROJECTS_ID_SUFFIX, c -> CommunityMappingUtils.asCommunityProject(id, c));
62
	}
63

  
64
	public void addCommunityProject(final String id, final CommunityProject project) throws CommunityException, CommunityNotFoundException {
65
		if (!StringUtils.equalsIgnoreCase(id, project.getCommunityId())) {
66
			throw new CommunityException("parameters 'id' and project.communityId must be coherent");
67
		}
68

  
69
		if (StringUtils.isBlank(project.getId())) {
70
			throw new CommunityException("parameter 'id' must be non empty");
71
		}
72

  
73
		final Map<String, CommunityProject> projects = getCommunityProjectMap(id);
74

  
75
		if (projects.containsKey(project.getId())) {
76
			throw new CommunityException(String.format("project '%s' already defined in context '%s'", project.getId(), id));
77
		}
78

  
79
		isClient.addConcept(id, id + PROJECTS_ID_SUFFIX, CommunityMappingUtils.asProjectXML(id, project));
80
	}
81

  
82
	public void removeCommunityProject(final String id, final String projectId) throws CommunityException, CommunityNotFoundException {
83
		final Map<String, CommunityProject> projects = getCommunityProjectMap(id);
84
		if (!projects.containsKey(projectId)) {
85
			throw new CommunityNotFoundException(String.format("project '%s' doesn't exist within context '%s'", projectId, id));
86
		}
87
		isClient.removeConcept(
88
				id,
89
				id + PROJECTS_ID_SUFFIX,
90
				id + PROJECTS_ID_SUFFIX + ID_SEPARATOR + projectId);
91
	}
92

  
93
	public List<CommunityContentprovider> getCommunityContentproviders(final String id) throws CommunityException, CommunityNotFoundException {
94
		getCommunity(id); // ensure the community exists.
95
		return _getCommunityInfo(id, CONTENTPROVIDERS_ID_SUFFIX, c -> CommunityMappingUtils.asCommunityDataprovider(id, c));
96
	}
97

  
98
	public void addCommunityContentprovider(final String id, final CommunityContentprovider cp) throws CommunityException, CommunityNotFoundException {
99
		if (!StringUtils.equalsIgnoreCase(id, cp.getCommunityId())) {
100
			throw new CommunityException("parameters 'id' and cp.communityId must be coherent");
101
		}
102

  
103
		if (StringUtils.isBlank(cp.getId())) {
104
			throw new CommunityException("parameter 'id' must be non empty");
105
		}
106

  
107
		final Map<String, CommunityContentprovider> cps = getCommunityContentproviderMap(id);
108

  
109
		if (cps.containsKey(cp.getId())) {
110
			throw new CommunityException(String.format("content provider '%s' already defined in context '%s'", cp.getId(), id));
111
		}
112
		isClient.addConcept(id, id + CONTENTPROVIDERS_ID_SUFFIX, CommunityMappingUtils.asContentProviderXML(id, cp));
113
	}
114

  
115
	public void removeCommunityContentProvider(final String id, final String contentproviderId) throws CommunityException, CommunityNotFoundException {
116
		final Map<String, CommunityContentprovider> providers = getCommunityContentproviderMap(id);
117
		if (!providers.containsKey(contentproviderId)) {
118
			throw new CommunityNotFoundException(String.format("content provider '%s' doesn't exist within context '%s'", contentproviderId, id));
119
		}
120
		isClient.removeConcept(
121
				id,
122
				id + CONTENTPROVIDERS_ID_SUFFIX,
123
				id + CONTENTPROVIDERS_ID_SUFFIX + ID_SEPARATOR + contentproviderId);
124
	}
125

  
126
	// HELPERS
127

  
128
	private Map<String, CommunityProject> getCommunityProjectMap(final String id) throws CommunityException, CommunityNotFoundException {
129
		return getCommunityProjects(id).stream()
130
				.collect(Collectors.toMap(
131
						CommunityProject::getId,
132
						Functions.identity(),
133
						(p1, p2) -> {
134
							log.warn("duplicate project found! " + p1.getId());
135
							return p2;
136
						}));
137
	}
138

  
139
	private Map<String, CommunityContentprovider> getCommunityContentproviderMap(final String id) throws CommunityException, CommunityNotFoundException {
140
		return getCommunityContentproviders(id).stream()
141
				.collect(Collectors.toMap(
142
						CommunityContentprovider::getId,
143
						Functions.identity(),
144
						(cp1, cp2) -> {
145
							log.warn("duplicate content provider found! " + cp1.getId());
146
							return cp2;
147
						}));
148
	}
149

  
150
	private Map<String, Context> getContextMap() throws CommunityException {
151
		try {
152
			return isClient.getCommunityContextMap();
153
		} catch (IOException e) {
154
			throw new CommunityException(e);
155
		}
156
	}
157

  
158
	private <R> List<R> _getCommunityInfo(final String id, final String idSuffix, final Function<Concept, R> mapping) throws CommunityException {
159
		final Map<String, Context> contextMap = getContextMap();
160
		final Context context = contextMap.get(id);
161
		if (context != null) {
162
			final Map<String, Category> categories = context.getCategories();
163
			final Category category = categories.get(id + idSuffix);
164
			if (category != null) {
165
				return category.getConcepts().stream()
166
						.map(mapping)
167
						.collect(Collectors.toList());
168
			}
169
		}
170
		return Lists.newArrayList();
171
	}
172

  
173
}
modules/dnet-openaire-exporter/trunk/src/main/java/eu/dnetlib/openaire/exporter/community/CommunityDetails.java
1
package eu.dnetlib.openaire.exporter.community;
2

  
3
import java.util.Date;
4
import java.util.List;
5

  
6
import com.fasterxml.jackson.annotation.JsonAutoDetect;
7
import io.swagger.annotations.ApiModelProperty;
8

  
9
@JsonAutoDetect
10
public class CommunityDetails extends CommunitySummary {
11

  
12
	@ApiModelProperty("")
13
	private String type;
14

  
15
	@ApiModelProperty("date of creation for this community")
16
	private Date creationDate;
17

  
18
	@ApiModelProperty("list of subjects (keywords) that characterise this community")
19
	private List<String> subjects;
20

  
21
	public CommunityDetails() {
22
	}
23

  
24
	public CommunityDetails(final CommunitySummary summary) {
25
		super(summary);
26
	}
27

  
28
	public String getType() {
29
		return type;
30
	}
31

  
32
	public void setType(final String type) {
33
		this.type = type;
34
	}
35

  
36
	public Date getCreationDate() {
37
		return creationDate;
38
	}
39

  
40
	public void setCreationDate(final Date creationDate) {
41
		this.creationDate = creationDate;
42
	}
43

  
44
	public List<String> getSubjects() {
45
		return subjects;
46
	}
47

  
48
	public void setSubjects(final List<String> subjects) {
49
		this.subjects = subjects;
50
	}
51
}
modules/dnet-openaire-exporter/trunk/src/main/java/eu/dnetlib/openaire/exporter/community/CommunityContentprovider.java
1
package eu.dnetlib.openaire.exporter.community;
2

  
3
import javax.validation.constraints.NotNull;
4

  
5
import com.fasterxml.jackson.annotation.JsonAutoDetect;
6
import io.swagger.annotations.ApiModelProperty;
7

  
8
@JsonAutoDetect
9
public class CommunityContentprovider {
10

  
11
	@ApiModelProperty(value = "OpenAIRE identifier for this content provider, if available", required = false)
12
	private String openaireId;
13

  
14
	@NotNull
15
	@ApiModelProperty(value = "the community identifier this content provider belongs to", required = true)
16
	private String communityId;
17

  
18
	@NotNull
19
	@ApiModelProperty(value = "identifies this content provider within the context it belongs to", required = true)
20
	private String id;
21

  
22
	@ApiModelProperty(value = "content provider name", required = false)
23
	private String name;
24

  
25
	@NotNull
26
	@ApiModelProperty(value = "content provider official name", required = true)
27
	private String officialname;
28

  
29
	public String getOpenaireId() {
30
		return openaireId;
31
	}
32

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

  
37
	public String getCommunityId() {
38
		return communityId;
39
	}
40

  
41
	public void setCommunityId(final String communityId) {
42
		this.communityId = communityId;
43
	}
44

  
45
	public String getId() {
46
		return id;
47
	}
48

  
49
	public void setId(final String id) {
50
		this.id = id;
51
	}
52

  
53
	public String getName() {
54
		return name;
55
	}
56

  
57
	public void setName(final String name) {
58
		this.name = name;
59
	}
60

  
61
	public String getOfficialname() {
62
		return officialname;
63
	}
64

  
65
	public void setOfficialname(final String officialname) {
66
		this.officialname = officialname;
67
	}
68

  
69
}
modules/dnet-openaire-exporter/trunk/src/main/java/eu/dnetlib/openaire/exporter/community/CommunityWritableProperties.java
1
package eu.dnetlib.openaire.exporter.community;
2

  
3
import java.util.List;
4

  
5
import com.fasterxml.jackson.annotation.JsonAutoDetect;
6
import io.swagger.annotations.ApiModelProperty;
7

  
8
@JsonAutoDetect
9
public class CommunityWritableProperties {
10

  
11
	@ApiModelProperty("community name")
12
	private String name;
13

  
14
	@ApiModelProperty("community short name")
15
	private String shortName;
16

  
17
	@ApiModelProperty("community description")
18
	private String description;
19

  
20
	@ApiModelProperty("http url for the community logo")
21
	private String logoUrl;
22

  
23
	@ApiModelProperty("list of community manager emails")
24
	private List<String> managers;
25

  
26
	@ApiModelProperty("list of subjects (keywords) that characterise this community")
27
	private List<String> subjects;
28

  
29
	public String getName() {
30
		return name;
31
	}
32

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

  
37
	public String getShortName() {
38
		return shortName;
39
	}
40

  
41
	public void setShortName(final String shortName) {
42
		this.shortName = shortName;
43
	}
44

  
45
	public String getDescription() {
46
		return description;
47
	}
48

  
49
	public void setDescription(final String description) {
50
		this.description = description;
51
	}
52

  
53
	public List<String> getManagers() {
54
		return managers;
55
	}
56

  
57
	public void setManagers(final List<String> managers) {
58
		this.managers = managers;
59
	}
60

  
61
	public String getLogoUrl() {
62
		return logoUrl;
63
	}
64

  
65
	public void setLogoUrl(final String logoUrl) {
66
		this.logoUrl = logoUrl;
67
	}
68

  
69
	public List<String> getSubjects() {
70
		return subjects;
71
	}
72

  
73
	public void setSubjects(final List<String> subjects) {
74
		this.subjects = subjects;
75
	}
76
}
modules/dnet-openaire-exporter/trunk/src/main/java/eu/dnetlib/openaire/exporter/community/CommunityProject.java
1
package eu.dnetlib.openaire.exporter.community;
2

  
3
import com.fasterxml.jackson.annotation.JsonAutoDetect;
4
import io.swagger.annotations.ApiModelProperty;
5

  
6
@JsonAutoDetect
7
public class CommunityProject {
8

  
9
	@ApiModelProperty(value = "OpenAIRE identifier for this project, if available", required = false)
10
	private String openaireId;
11

  
12
	@ApiModelProperty(value = "the community identifier this project belongs to", required = true)
13
	private String communityId;
14

  
15
	@ApiModelProperty(value = "identifies this project within the context it belongs to", required = true)
16
	private String id;
17

  
18
	@ApiModelProperty(value = "project name", required = true)
19
	private String name;
20

  
21
	@ApiModelProperty(value = "project acronym", required = false)
22
	private String acronym;
23

  
24
	@ApiModelProperty(value = "project funder", required = true)
25
	private String funder;
26

  
27
	@ApiModelProperty(value = "project grant id", required = true)
28
	private String grantId;
29

  
30
	public String getOpenaireId() {
31
		return openaireId;
32
	}
33

  
34
	public void setOpenaireId(final String openaireId) {
35
		this.openaireId = openaireId;
36
	}
37

  
38
	public String getCommunityId() {
39
		return communityId;
40
	}
41

  
42
	public void setCommunityId(final String communityId) {
43
		this.communityId = communityId;
44
	}
45

  
46
	public String getId() {
47
		return id;
48
	}
49

  
50
	public void setId(final String id) {
51
		this.id = id;
52
	}
53

  
54
	public String getName() {
55
		return name;
56
	}
57

  
58
	public void setName(final String name) {
59
		this.name = name;
60
	}
61

  
62
	public String getAcronym() {
63
		return acronym;
64
	}
65

  
66
	public void setAcronym(final String acronym) {
67
		this.acronym = acronym;
68
	}
69

  
70
	public String getFunder() {
71
		return funder;
72
	}
73

  
74
	public void setFunder(final String funder) {
75
		this.funder = funder;
76
	}
77

  
78
	public String getGrantId() {
79
		return grantId;
80
	}
81

  
82
	public void setGrantId(final String grantId) {
83
		this.grantId = grantId;
84
	}
85

  
86
}
modules/dnet-openaire-exporter/trunk/src/main/java/eu/dnetlib/openaire/exporter/community/CommunityNotFoundException.java
1
package eu.dnetlib.openaire.exporter.community;
2

  
3
import org.springframework.http.HttpStatus;
4
import org.springframework.web.bind.annotation.ResponseBody;
5
import org.springframework.web.bind.annotation.ResponseStatus;
6

  
7
@ResponseBody
8
@ResponseStatus(value = HttpStatus.NOT_FOUND)
9
public class CommunityNotFoundException extends Exception {
10

  
11
	public CommunityNotFoundException(final String msg) {
12
		super(msg);
13
	}
14

  
15
	public CommunityNotFoundException(final Exception e) {
16
		super(e);
17
	}
18
}
modules/dnet-openaire-exporter/trunk/src/main/java/eu/dnetlib/openaire/exporter/community/CommunityConstants.java
1
package eu.dnetlib.openaire.exporter.community;
2

  
3
import java.util.Set;
4

  
5
import com.google.common.collect.Sets;
6

  
7
public class CommunityConstants {
8

  
9
	public final static Set<String> communityBlackList = Sets.newHashSet("fet-fp7", "fet-h2020");
10

  
11
	// common
12
	public final static String OPENAIRE_ID = "openaireId";
13
	public final static String PIPE_SEPARATOR = "||";
14
	public final static String ID_SEPARATOR = "::";
15
	public final static String CSV_DELIMITER = ", ";
16
	public final static String CLABEL = "label";
17

  
18
	// id suffixes
19
	public final static String PROJECTS_ID_SUFFIX = ID_SEPARATOR + "projects";
20
	public final static String CONTENTPROVIDERS_ID_SUFFIX = ID_SEPARATOR + "contentproviders";
21

  
22
	// community summary
23
	public final static String CSUMMARY_DESCRIPTION = "description";
24
	public final static String CSUMMARY_LOGOURL = "logourl";
25
	public final static String CSUMMARY_NAME = "name";
26
	public final static String CSUMMARY_MANAGER = "manager";
27

  
28
	// community profile
29
	public final static String CPROFILE_SUBJECT = "subject";
30

  
31
	// community project
32
	public final static String CPROJECT_FUNDER = "funder";
33
	public final static String CPROJECT_NUMBER = "CD_PROJECT_NUMBER";
34
	public final static String CPROJECT_FULLNAME = "projectfullname";
35
	public final static String CPROJECT_ACRONYM = "projectacronym";
36

  
37
	// community content provider
38
	public final static String CCONTENTPROVIDER_NAME = "name";
39
	public final static String CCONTENTPROVIDER_OFFICIALNAME = "officialname";
40

  
41
}
modules/dnet-openaire-exporter/trunk/src/main/java/eu/dnetlib/openaire/exporter/community/CommunityMappingUtils.java
1
package eu.dnetlib.openaire.exporter.community;
2

  
3
import java.util.List;
4
import java.util.Map;
5
import java.util.Optional;
6
import java.util.stream.Collectors;
7
import java.util.stream.Stream;
8

  
9
import com.google.common.escape.Escaper;
10
import com.google.common.xml.XmlEscapers;
11
import eu.dnetlib.openaire.exporter.funders.context.Concept;
12
import eu.dnetlib.openaire.exporter.funders.context.Context;
13
import eu.dnetlib.openaire.exporter.funders.context.Param;
14
import org.apache.commons.lang3.StringUtils;
15

  
16
import static eu.dnetlib.openaire.exporter.Utils.escape;
17
import static eu.dnetlib.openaire.exporter.community.CommunityConstants.*;
18

  
19
public class CommunityMappingUtils {
20

  
21
	public static CommunitySummary asCommunitySummary(final Context c) {
22
		final CommunitySummary summary = new CommunitySummary();
23

  
24
		summary.setId(c.getId());
25
		summary.setShortName(c.getLabel());
26
		summary.setQueryId(c.getId() + PIPE_SEPARATOR + c.getLabel());
27

  
28
		final Map<String, List<Param>> params = c.getParams();
29
		if (params.containsKey(CSUMMARY_DESCRIPTION)) {
30
			summary.setDescription(asCsv(params.get(CSUMMARY_DESCRIPTION)));
31
		}
32
		if (params.containsKey(CSUMMARY_LOGOURL)) {
33
			summary.setLogoUrl(asCsv(params.get(CSUMMARY_LOGOURL)));
34
		}
35
		if (params.containsKey(CSUMMARY_NAME)) {
36
			summary.setName(asCsv(params.get(CSUMMARY_NAME)));
37
		}
38
		if (params.containsKey(CSUMMARY_MANAGER)) {
... This diff was truncated because it exceeds the maximum size that can be displayed.

Also available in: Unified diff