Revision 30740
Added by Alessia Bardi about 10 years ago
modules/cnr-openaire-exporter/tags/cnr-openaire-exporter-2.0.0/deploy.info | ||
---|---|---|
1 |
{"type_source": "SVN", |
|
2 |
"goal": "package -U -T 4C source:jar", |
|
3 |
"url": "http://svn-public.driver.research-infrastructures.eu/driver/dnet40/modules/cnr-openaire-exporter/trunk/", |
|
4 |
"deploy_repository": "dnet4-snapshots", |
|
5 |
"version": "4", |
|
6 |
"mail": "alessia.bardi@isti.cnr.it", |
|
7 |
"deploy_repository_url": "http://maven.research-infrastructures.eu/nexus/content/repositories/dnet4-snapshots", "name": "cnr-openaire-exporter"} |
modules/cnr-openaire-exporter/tags/cnr-openaire-exporter-2.0.0/src/test/java/eu/dnetlib/openaire/exporter/DSpaceTest.java | ||
---|---|---|
1 |
package eu.dnetlib.openaire.exporter; |
|
2 |
|
|
3 |
import java.io.IOException; |
|
4 |
import java.io.StringWriter; |
|
5 |
|
|
6 |
import org.apache.commons.io.IOUtils; |
|
7 |
import org.junit.Before; |
|
8 |
import org.junit.Test; |
|
9 |
import org.springframework.core.io.ClassPathResource; |
|
10 |
import org.springframework.core.io.Resource; |
|
11 |
|
|
12 |
import eu.dnetlib.miscutils.functional.xml.ApplyXslt; |
|
13 |
|
|
14 |
public class DSpaceTest { |
|
15 |
|
|
16 |
private String inputXML = "<projects><project><FIELD name=\"grant_agreement_number\">GRANTID1</FIELD><FIELD name=\"title\">Project title 1</FIELD><FIELD name=\"acronym\">ACRO1</FIELD></project><project><FIELD name=\"grant_agreement_number\">GRANTID2</FIELD><FIELD name=\"title\">Project title 2</FIELD><FIELD name=\"acronym\">ACRO 2</FIELD></project></projects>"; |
|
17 |
private Resource wtProject = new ClassPathResource("eu/dnetlib/openaire/exporter/WT-project.xml"); |
|
18 |
|
|
19 |
private Resource dspaceXslt; |
|
20 |
|
|
21 |
@Before |
|
22 |
public void setUp() throws Exception { |
|
23 |
dspaceXslt = new ClassPathResource("xslt/projects_dspace.xslt", getClass()); |
|
24 |
} |
|
25 |
|
|
26 |
@Test |
|
27 |
public void test() { |
|
28 |
ApplyXslt applyXslt = new ApplyXslt(dspaceXslt); |
|
29 |
String result = applyXslt.evaluate(inputXML); |
|
30 |
System.out.println(result); |
|
31 |
} |
|
32 |
|
|
33 |
@Test |
|
34 |
public void testWTdspace() throws IOException { |
|
35 |
ApplyXslt applyXslt = new ApplyXslt(dspaceXslt); |
|
36 |
StringWriter w = new StringWriter(); |
|
37 |
IOUtils.copy(wtProject.getInputStream(), w); |
|
38 |
String result = applyXslt.evaluate(w.toString()); |
|
39 |
System.out.println(result); |
|
40 |
} |
|
41 |
|
|
42 |
} |
modules/cnr-openaire-exporter/tags/cnr-openaire-exporter-2.0.0/src/test/java/eu/dnetlib/openaire/exporter/EPrintsTest.java | ||
---|---|---|
1 |
package eu.dnetlib.openaire.exporter; |
|
2 |
|
|
3 |
import java.io.IOException; |
|
4 |
import java.io.StringWriter; |
|
5 |
|
|
6 |
import org.apache.commons.io.IOUtils; |
|
7 |
import org.junit.Before; |
|
8 |
import org.junit.Test; |
|
9 |
import org.springframework.core.io.ClassPathResource; |
|
10 |
import org.springframework.core.io.Resource; |
|
11 |
|
|
12 |
import eu.dnetlib.miscutils.functional.xml.ApplyXslt; |
|
13 |
|
|
14 |
public class EPrintsTest { |
|
15 |
|
|
16 |
private String inputXML = "<projects><project><FIELD name=\"grant_agreement_number\">GRANTID1</FIELD><FIELD name=\"title\">Project title 1</FIELD><FIELD name=\"acronym\">ACRO1</FIELD></project><project><FIELD name=\"grant_agreement_number\">GRANTID2</FIELD><FIELD name=\"title\">Project title 2</FIELD><FIELD name=\"acronym\">ACRO 2</FIELD></project></projects>"; |
|
17 |
private Resource wtProject = new ClassPathResource("eu/dnetlib/openaire/exporter/WT-project.xml"); |
|
18 |
|
|
19 |
private Resource ePrintsXslt; |
|
20 |
|
|
21 |
@Before |
|
22 |
public void setUp() throws Exception { |
|
23 |
ePrintsXslt = new ClassPathResource("xslt/projects_eprints.xslt", getClass()); |
|
24 |
} |
|
25 |
|
|
26 |
@Test |
|
27 |
public void test() { |
|
28 |
ApplyXslt applyXslt = new ApplyXslt(ePrintsXslt); |
|
29 |
String result = applyXslt.evaluate(inputXML); |
|
30 |
assertTab(result); |
|
31 |
} |
|
32 |
|
|
33 |
@Test |
|
34 |
public void testWTePrints() throws IOException { |
|
35 |
ApplyXslt applyXslt = new ApplyXslt(ePrintsXslt); |
|
36 |
StringWriter w = new StringWriter(); |
|
37 |
IOUtils.copy(wtProject.getInputStream(), w); |
|
38 |
String res = applyXslt.evaluate(w.toString()); |
|
39 |
assertTab(res); |
|
40 |
} |
|
41 |
|
|
42 |
private void assertTab(final String str) { |
|
43 |
String[] splitOnTab = str.split("\t"); |
|
44 |
org.junit.Assert.assertTrue(splitOnTab.length > 1); |
|
45 |
System.out.println(splitOnTab[0]); |
|
46 |
System.out.println("According to the Java split function, now there is a tab, followed by:"); |
|
47 |
System.out.println(splitOnTab[1]); |
|
48 |
} |
|
49 |
} |
modules/cnr-openaire-exporter/tags/cnr-openaire-exporter-2.0.0/src/test/java/eu/dnetlib/openaire/exporter/ProjectsControllerTest.java | ||
---|---|---|
1 |
package eu.dnetlib.openaire.exporter; |
|
2 |
|
|
3 |
import static org.junit.Assert.assertEquals; |
|
4 |
|
|
5 |
import java.io.IOException; |
|
6 |
import java.io.StringWriter; |
|
7 |
|
|
8 |
import org.apache.commons.io.IOUtils; |
|
9 |
import org.junit.Before; |
|
10 |
import org.junit.Test; |
|
11 |
import org.springframework.core.io.ClassPathResource; |
|
12 |
import org.springframework.core.io.Resource; |
|
13 |
|
|
14 |
import eu.dnetlib.miscutils.functional.xml.ApplyXslt; |
|
15 |
|
|
16 |
public class ProjectsControllerTest { |
|
17 |
|
|
18 |
private ProjectsController controller; |
|
19 |
private ProjectQueryParams params; |
|
20 |
private String expectedFP7Query = "select p.acronym as acronym, p.title as title, regexp_replace(p.id, '^corda_______::' , '') as grant_agreement_number, p.startdate as start_date, p.enddate as end_date, f1.name as subdivision, f2.name as specificprogramme, f3.name as fundingprogramme from projects p left outer join project_funding pf on (p.id = pf.project) left outer join funding_funding ff1 on (pf.funding = ff1.funding1) left outer join funding_funding ff2 on (ff1.funding2 = ff2.funding1) left outer join fundings f1 on (f1.id = ff1.funding1) left outer join fundings f2 on (f2.id = ff2.funding1) left outer join fundings f3 on (f3.id = ff2.funding2) where f3.id = 'corda_______::FP7' AND f3.name = 'FP7'"; |
|
21 |
private String expectedWTQuery = "select p.acronym as acronym, p.title as title, regexp_replace(p.id, '^welcometrust::' , '') as grant_agreement_number, p.startdate as start_date, p.enddate as end_date, f1.name as specificprogramme, f2.name as fundingprogramme from projects p left outer join project_funding pf on (p.id = pf.project) left outer join funding_funding ff1 on (pf.funding = ff1.funding1) left outer join fundings f1 on (f1.id = ff1.funding1) left outer join fundings f2 on (f2.id = ff1.funding2) where f2.id = 'wt::WT' AND f2.name = 'WT'"; |
|
22 |
|
|
23 |
private Resource wtProject = new ClassPathResource("eu/dnetlib/openaire/exporter/WT-project.xml"); |
|
24 |
private Resource eprintsXSLT = new ClassPathResource("eu/dnetlib/openaire/exporter/xslt/projects_eprints.xslt"); |
|
25 |
private Resource dspaceXSLT = new ClassPathResource("eu/dnetlib/openaire/exporter/xslt/projects_dspace.xslt"); |
|
26 |
|
|
27 |
@Before |
|
28 |
public void setup() { |
|
29 |
controller = new ProjectsController(); |
|
30 |
params = new ProjectQueryParams(); |
|
31 |
} |
|
32 |
|
|
33 |
@Test |
|
34 |
public void testObtainFP7Query() { |
|
35 |
params.setFundingProgramme("FP7"); |
|
36 |
String res = controller.obtainFP7Query(params); |
|
37 |
System.out.println(res); |
|
38 |
assertEquals(expectedFP7Query, res); |
|
39 |
} |
|
40 |
|
|
41 |
@Test |
|
42 |
public void testObtainWellcomeTrustQuery() { |
|
43 |
params.setFundingProgramme("WT"); |
|
44 |
String res = controller.obtainWellcomeTrustQuery(params); |
|
45 |
System.out.println(res); |
|
46 |
assertEquals(expectedWTQuery, res); |
|
47 |
} |
|
48 |
|
|
49 |
@Test |
|
50 |
public void testWTDspace() throws IOException { |
|
51 |
params.setFundingProgramme("WT"); |
|
52 |
StringWriter w = new StringWriter(); |
|
53 |
IOUtils.copy(wtProject.getInputStream(), w); |
|
54 |
ApplyXslt applyDSpace = new ApplyXslt(dspaceXSLT); |
|
55 |
String res = applyDSpace.evaluate(w.toString()); |
|
56 |
|
|
57 |
System.out.println("<?xml version='1.0' encoding='UTF-8'?>\n\n" + "<form-value-pairs>\n" + " <value-pairs value-pairs-name='" |
|
58 |
+ params.getFundingProgramme() + "projects' dc-term='relation'>\n"); |
|
59 |
System.out.println(res); |
|
60 |
System.out.println(" </value-pairs>\n" + "</form-value-pairs>\n"); |
|
61 |
} |
|
62 |
|
|
63 |
@Test |
|
64 |
public void testWTePrints() throws IOException { |
|
65 |
params.setFundingProgramme("WT"); |
|
66 |
StringWriter w = new StringWriter(); |
|
67 |
IOUtils.copy(wtProject.getInputStream(), w); |
|
68 |
ApplyXslt applyDSpace = new ApplyXslt(eprintsXSLT); |
|
69 |
String res = applyDSpace.evaluate(w.toString()); |
|
70 |
System.out.println(res); |
|
71 |
} |
|
72 |
|
|
73 |
} |
modules/cnr-openaire-exporter/tags/cnr-openaire-exporter-2.0.0/src/test/resources/eu/dnetlib/openaire/exporter/WT-project.xml | ||
---|---|---|
1 |
<ROW> |
|
2 |
<FIELD name="end_date">2013-07-29</FIELD> |
|
3 |
<FIELD name="title">EYEDIO DIGI - DEVELOPMENT OF AN INNOVATIVE, AFFORDABLE, EASY TO USE, HANDHELD RETINAL IMAGING PRODUCT FOR THE DIAGNOSIS OF DIABETIC RETINOPATHY.</FIELD> |
|
4 |
<FIELD name="fundingprogramme">WT</FIELD> |
|
5 |
<FIELD name="acronym">UNKNOWN</FIELD> |
|
6 |
<FIELD name="grant_agreement_number">098241</FIELD> |
|
7 |
<FIELD name="specificprogramme">Technology Transfer Division</FIELD> |
|
8 |
<FIELD name="start_date">2012-01-30</FIELD> |
|
9 |
</ROW> |
modules/cnr-openaire-exporter/tags/cnr-openaire-exporter-2.0.0/src/main/java/eu/dnetlib/openaire/exporter/ProjectQueryParams.java | ||
---|---|---|
1 |
package eu.dnetlib.openaire.exporter; |
|
2 |
|
|
3 |
import java.util.regex.Pattern; |
|
4 |
|
|
5 |
import org.apache.commons.logging.Log; |
|
6 |
import org.apache.commons.logging.LogFactory; |
|
7 |
|
|
8 |
public class ProjectQueryParams { |
|
9 |
private String fundingProgramme = null; |
|
10 |
private String fundingStream = null; |
|
11 |
private String scientficArea = null; |
|
12 |
private String startFrom = null; |
|
13 |
private String startUntil = null; |
|
14 |
private String endFrom = null; |
|
15 |
private String endUntil = null; |
|
16 |
|
|
17 |
private static final Log log = LogFactory.getLog(ProjectQueryParams.class); // NOPMD by marko on 11/24/08 5:02 PM |
|
18 |
|
|
19 |
public String getFundingProgramme() { |
|
20 |
return fundingProgramme; |
|
21 |
} |
|
22 |
public void setFundingProgramme(String fundingProgramme) { |
|
23 |
this.fundingProgramme = verifyParam(fundingProgramme); |
|
24 |
} |
|
25 |
public String getSpecificProgramme() { |
|
26 |
return fundingStream; |
|
27 |
} |
|
28 |
public void setSpecificProgramme(String specificProgramme) { |
|
29 |
this.fundingStream = verifyParam(specificProgramme); |
|
30 |
} |
|
31 |
public String getSubdivision() { |
|
32 |
return scientficArea; |
|
33 |
} |
|
34 |
public void setSubdivision(String subdivision) { |
|
35 |
this.scientficArea = verifyParam(subdivision); |
|
36 |
} |
|
37 |
public String getStartFrom() { |
|
38 |
return startFrom; |
|
39 |
} |
|
40 |
public void setStartFrom(String startFrom) { |
|
41 |
this.startFrom = verifyParam(startFrom); |
|
42 |
} |
|
43 |
public String getStartUntil() { |
|
44 |
return startUntil; |
|
45 |
} |
|
46 |
public void setStartUntil(String startUntil) { |
|
47 |
this.startUntil = verifyParam(startUntil); |
|
48 |
} |
|
49 |
public String getEndFrom() { |
|
50 |
return endFrom; |
|
51 |
} |
|
52 |
public void setEndFrom(String endFrom) { |
|
53 |
this.endFrom = verifyParam(endFrom); |
|
54 |
} |
|
55 |
public String getEndUntil() { |
|
56 |
return endUntil; |
|
57 |
} |
|
58 |
public void setEndUntil(String endUntil) { |
|
59 |
this.endUntil = verifyParam(endUntil); |
|
60 |
} |
|
61 |
|
|
62 |
private String verifyParam(String p) { |
|
63 |
Pattern pattern = Pattern.compile("(\\w|\\-){1,32}"); |
|
64 |
|
|
65 |
log.debug("TESTING SQL PARAM:" + p); |
|
66 |
if (p != null && !pattern.matcher(p).matches()) |
|
67 |
throw new IllegalArgumentException("Parameter contains an invalid character"); |
|
68 |
log.debug("TEST OK"); |
|
69 |
|
|
70 |
return p; |
|
71 |
} |
|
72 |
|
|
73 |
} |
modules/cnr-openaire-exporter/tags/cnr-openaire-exporter-2.0.0/src/main/java/eu/dnetlib/openaire/exporter/ProjectQueryParamsFactory.java | ||
---|---|---|
1 |
package eu.dnetlib.openaire.exporter; |
|
2 |
|
|
3 |
import javax.servlet.http.HttpServletRequest; |
|
4 |
|
|
5 |
public class ProjectQueryParamsFactory { |
|
6 |
|
|
7 |
private static final String BASE_PATH = "/openaire/export/"; |
|
8 |
private static final String NO_FILTER = "ALL"; |
|
9 |
|
|
10 |
public ProjectQueryParams generateParams(final HttpServletRequest request, final String startFrom, final String startUntil, final String endFrom, final String endUntil) { |
|
11 |
ProjectQueryParams params = new ProjectQueryParams(); |
|
12 |
|
|
13 |
String[] arr = request.getPathInfo().replace(BASE_PATH, "").split("\\/"); |
|
14 |
if (arr.length != 5) throw new IllegalArgumentException("Invalid url"); |
|
15 |
|
|
16 |
params.setFundingProgramme(arr[0]); |
|
17 |
params.setSpecificProgramme(NO_FILTER.equals(arr[1]) ? null : arr[1]); |
|
18 |
params.setSubdivision(NO_FILTER.equals(arr[2]) ? null : arr[2]); |
|
19 |
// NB: arr[3] should be 'projects' |
|
20 |
// NB: arr[4] should be '[file].do' |
|
21 |
params.setStartFrom(startFrom); |
|
22 |
params.setStartUntil(startUntil); |
|
23 |
params.setEndFrom(endFrom); |
|
24 |
params.setEndUntil(endUntil); |
|
25 |
|
|
26 |
return params; |
|
27 |
} |
|
28 |
|
|
29 |
} |
modules/cnr-openaire-exporter/tags/cnr-openaire-exporter-2.0.0/src/main/java/eu/dnetlib/openaire/exporter/ProjectsController.java | ||
---|---|---|
1 |
package eu.dnetlib.openaire.exporter; |
|
2 |
|
|
3 |
import java.io.IOException; |
|
4 |
import java.io.OutputStream; |
|
5 |
import java.io.StringReader; |
|
6 |
|
|
7 |
import javax.servlet.ServletOutputStream; |
|
8 |
import javax.servlet.ServletResponse; |
|
9 |
import javax.servlet.http.HttpServletRequest; |
|
10 |
import javax.xml.ws.wsaddressing.W3CEndpointReference; |
|
11 |
|
|
12 |
import org.apache.commons.io.IOUtils; |
|
13 |
import org.apache.commons.logging.Log; |
|
14 |
import org.apache.commons.logging.LogFactory; |
|
15 |
import org.springframework.beans.factory.annotation.Autowired; |
|
16 |
import org.springframework.beans.factory.annotation.Value; |
|
17 |
import org.springframework.core.io.Resource; |
|
18 |
import org.springframework.stereotype.Controller; |
|
19 |
import org.springframework.web.bind.annotation.RequestMapping; |
|
20 |
import org.springframework.web.bind.annotation.RequestParam; |
|
21 |
|
|
22 |
import eu.dnetlib.enabling.database.rmi.DatabaseService; |
|
23 |
import eu.dnetlib.enabling.resultset.client.IterableResultSetClient; |
|
24 |
import eu.dnetlib.enabling.resultset.client.ResultSetClientFactory; |
|
25 |
import eu.dnetlib.enabling.tools.ServiceLocator; |
|
26 |
import eu.dnetlib.miscutils.collections.MappedCollection; |
|
27 |
import eu.dnetlib.miscutils.functional.xml.ApplyXslt; |
|
28 |
|
|
29 |
@Controller |
|
30 |
public class ProjectsController { |
|
31 |
|
|
32 |
private enum Funder { |
|
33 |
FP7, WT |
|
34 |
} |
|
35 |
|
|
36 |
@javax.annotation.Resource |
|
37 |
private ServiceLocator<DatabaseService> dbServiceLocator; |
|
38 |
|
|
39 |
@Value("${dnet.openaire.db.name}") |
|
40 |
private String dbName; |
|
41 |
@Value("${openaire.exporter.dspace.xslt}") |
|
42 |
private Resource dspaceXslt; |
|
43 |
@Value("${openaire.exporter.eprints.xslt}") |
|
44 |
private Resource eprintsXslt; |
|
45 |
|
|
46 |
@Autowired |
|
47 |
private ResultSetClientFactory resultSetClientFactory; |
|
48 |
@Autowired |
|
49 |
private ProjectQueryParamsFactory projectQueryParamsFactory; |
|
50 |
|
|
51 |
private static final Log log = LogFactory.getLog(ProjectsController.class); // NOPMD by marko on 11/24/08 5:02 PM |
|
52 |
|
|
53 |
@RequestMapping(value = "/openaire/export/**/project/dspace.do") |
|
54 |
void processDspace(final HttpServletRequest request, |
|
55 |
final ServletResponse response, |
|
56 |
@RequestParam(value = "startFrom", required = false) final String startFrom, |
|
57 |
@RequestParam(value = "startUntil", required = false) final String startUntil, |
|
58 |
@RequestParam(value = "endFrom", required = false) final String endFrom, |
|
59 |
@RequestParam(value = "endUntil", required = false) final String endUntil) throws Exception { |
|
60 |
|
|
61 |
response.setContentType("text/xml"); |
|
62 |
|
|
63 |
ProjectQueryParams params = projectQueryParamsFactory.generateParams(request, startFrom, startUntil, endFrom, endUntil); |
|
64 |
|
|
65 |
ServletOutputStream out = response.getOutputStream(); |
|
66 |
|
|
67 |
String head = "<?xml version='1.0' encoding='UTF-8'?>\n\n" + "<form-value-pairs>\n" + " <value-pairs value-pairs-name='" + params.getFundingProgramme() |
|
68 |
+ "projects' dc-term='relation'>\n"; |
|
69 |
|
|
70 |
String tail = " </value-pairs>\n" + "</form-value-pairs>\n"; |
|
71 |
|
|
72 |
IOUtils.copy(new StringReader(head), out); |
|
73 |
emit(out, dspaceXslt, obtainQuery(params)); |
|
74 |
IOUtils.copy(new StringReader(tail), out); |
|
75 |
} |
|
76 |
|
|
77 |
@RequestMapping(value = "/openaire/export/**/project/eprints.do") |
|
78 |
void processEprints(final HttpServletRequest request, |
|
79 |
final ServletResponse response, |
|
80 |
@RequestParam(value = "startFrom", required = false) final String startFrom, |
|
81 |
@RequestParam(value = "startUntil", required = false) final String startUntil, |
|
82 |
@RequestParam(value = "endFrom", required = false) final String endFrom, |
|
83 |
@RequestParam(value = "endUntil", required = false) final String endUntil) throws Exception { |
|
84 |
|
|
85 |
response.setContentType("text/html"); |
|
86 |
emit(response.getOutputStream(), eprintsXslt, obtainQuery(projectQueryParamsFactory.generateParams(request, startFrom, startUntil, endFrom, endUntil))); |
|
87 |
} |
|
88 |
|
|
89 |
/** |
|
90 |
* Creates the query on the fundingProgramme specified in the given parameters. |
|
91 |
* |
|
92 |
* @param params |
|
93 |
* request parameters |
|
94 |
* @return the query string |
|
95 |
* @throws IllegalArgumentException |
|
96 |
* if the funding programme is not recognized |
|
97 |
*/ |
|
98 |
private String obtainQuery(final ProjectQueryParams params) throws IllegalArgumentException { |
|
99 |
String funder = params.getFundingProgramme(); |
|
100 |
switch (Funder.valueOf(funder)) { |
|
101 |
case FP7: |
|
102 |
return obtainFP7Query(params); |
|
103 |
case WT: |
|
104 |
return obtainWellcomeTrustQuery(params); |
|
105 |
default: |
|
106 |
throw new IllegalArgumentException("Invalid Funder " + funder); |
|
107 |
|
|
108 |
} |
|
109 |
} |
|
110 |
|
|
111 |
/** |
|
112 |
* Creates the query on FP7 |
|
113 |
* |
|
114 |
* @param params |
|
115 |
* @return the query string |
|
116 |
*/ |
|
117 |
protected String obtainFP7Query(final ProjectQueryParams params) { |
|
118 |
String query = "select " + "p.acronym as acronym, " + "p.title as title, " |
|
119 |
+ "regexp_replace(p.id, '^corda_______::' , '') as grant_agreement_number, " + "p.startdate as start_date, " + "p.enddate as end_date, " |
|
120 |
+ "f1.name as subdivision, " + "f2.name as specificprogramme, " + "f3.name as fundingprogramme " + "from projects p " |
|
121 |
+ "left outer join project_funding pf on (p.id = pf.project) " + "left outer join funding_funding ff1 on (pf.funding = ff1.funding1) " |
|
122 |
+ "left outer join funding_funding ff2 on (ff1.funding2 = ff2.funding1) " + "left outer join fundings f1 on (f1.id = ff1.funding1) " |
|
123 |
+ "left outer join fundings f2 on (f2.id = ff2.funding1) " + "left outer join fundings f3 on (f3.id = ff2.funding2) " |
|
124 |
+ "where f3.id = 'corda_______::FP7' "; |
|
125 |
|
|
126 |
if (params.getSubdivision() != null) { |
|
127 |
query += "AND f1.name = '" + params.getSubdivision() + "'"; |
|
128 |
} |
|
129 |
if (params.getSpecificProgramme() != null) { |
|
130 |
query += "AND f2.name = '" + params.getSpecificProgramme() + "'"; |
|
131 |
} |
|
132 |
if (params.getFundingProgramme() != null) { |
|
133 |
query += "AND f3.name = '" + params.getFundingProgramme() + "'"; |
|
134 |
} |
|
135 |
|
|
136 |
query = setDateParameters(query, params); |
|
137 |
|
|
138 |
log.info("Executing query: " + query); |
|
139 |
|
|
140 |
return query; |
|
141 |
} |
|
142 |
|
|
143 |
/** |
|
144 |
* Creates the query on WT |
|
145 |
* |
|
146 |
* @param params |
|
147 |
* @return the query string |
|
148 |
*/ |
|
149 |
protected String obtainWellcomeTrustQuery(final ProjectQueryParams params) { |
|
150 |
String query = "select p.acronym as acronym, p.title as title, regexp_replace(p.id, '^welcometrust::' , '') as grant_agreement_number, " |
|
151 |
+ "p.startdate as start_date, p.enddate as end_date, f1.name as specificprogramme, f2.name as fundingprogramme " |
|
152 |
+ "from projects p left outer join project_funding pf on (p.id = pf.project) " |
|
153 |
+ "left outer join funding_funding ff1 on (pf.funding = ff1.funding1) " + "left outer join fundings f1 on (f1.id = ff1.funding1) " |
|
154 |
+ "left outer join fundings f2 on (f2.id = ff1.funding2) " + "where f2.id = 'wt::WT' "; |
|
155 |
|
|
156 |
if (params.getSpecificProgramme() != null) { |
|
157 |
query += "AND f1.name = '" + params.getSpecificProgramme() + "'"; |
|
158 |
} |
|
159 |
if (params.getFundingProgramme() != null) { |
|
160 |
query += "AND f2.name = '" + params.getFundingProgramme() + "'"; |
|
161 |
} |
|
162 |
|
|
163 |
query = setDateParameters(query, params); |
|
164 |
log.info("Executing query: " + query); |
|
165 |
|
|
166 |
return query; |
|
167 |
} |
|
168 |
|
|
169 |
void emit(final OutputStream out, final Resource xslt, final String query) throws IOException { |
|
170 |
W3CEndpointReference epr = dbServiceLocator.getService().searchSQL(dbName, query); |
|
171 |
|
|
172 |
IterableResultSetClient iter = resultSetClientFactory.getClient(epr); |
|
173 |
|
|
174 |
for (String s : new MappedCollection<String, String>(iter, new ApplyXslt(xslt))) { |
|
175 |
out.write(s.getBytes()); |
|
176 |
} |
|
177 |
} |
|
178 |
|
|
179 |
private String setDateParameters(final String query, final ProjectQueryParams params) { |
|
180 |
String queryWithDates = query; |
|
181 |
if (params.getStartFrom() != null) { |
|
182 |
queryWithDates += "AND p.startdate >= '" + params.getStartFrom() + "'"; |
|
183 |
} |
|
184 |
if (params.getStartUntil() != null) { |
|
185 |
queryWithDates += "AND p.startdate <= '" + params.getStartUntil() + "'"; |
|
186 |
} |
|
187 |
if (params.getEndFrom() != null) { |
|
188 |
queryWithDates += "AND p.enddate >= '" + params.getEndFrom() + "'"; |
|
189 |
} |
|
190 |
if (params.getEndUntil() != null) { |
|
191 |
queryWithDates += "AND p.enddate <= '" + params.getEndUntil() + "'"; |
|
192 |
} |
|
193 |
return queryWithDates; |
|
194 |
} |
|
195 |
|
|
196 |
public String getDbName() { |
|
197 |
return dbName; |
|
198 |
} |
|
199 |
|
|
200 |
public void setDbName(final String dbName) { |
|
201 |
this.dbName = dbName; |
|
202 |
} |
|
203 |
|
|
204 |
public Resource getDspaceXslt() { |
|
205 |
return dspaceXslt; |
|
206 |
} |
|
207 |
|
|
208 |
public void setDspaceXslt(final Resource dspaceXslt) { |
|
209 |
this.dspaceXslt = dspaceXslt; |
|
210 |
} |
|
211 |
|
|
212 |
public Resource getEprintsXslt() { |
|
213 |
return eprintsXslt; |
|
214 |
} |
|
215 |
|
|
216 |
public void setEprintsXslt(final Resource eprintsXslt) { |
|
217 |
this.eprintsXslt = eprintsXslt; |
|
218 |
} |
|
219 |
|
|
220 |
public ServiceLocator<DatabaseService> getDbServiceLocator() { |
|
221 |
return dbServiceLocator; |
|
222 |
} |
|
223 |
|
|
224 |
public void setDbServiceLocator(final ServiceLocator<DatabaseService> dbServiceLocator) { |
|
225 |
this.dbServiceLocator = dbServiceLocator; |
|
226 |
} |
|
227 |
|
|
228 |
public ProjectQueryParamsFactory getProjectQueryParamsFactory() { |
|
229 |
return projectQueryParamsFactory; |
|
230 |
} |
|
231 |
|
|
232 |
public void setProjectQueryParamsFactory(final ProjectQueryParamsFactory projectQueryParamsFactory) { |
|
233 |
this.projectQueryParamsFactory = projectQueryParamsFactory; |
|
234 |
} |
|
235 |
} |
modules/cnr-openaire-exporter/tags/cnr-openaire-exporter-2.0.0/src/main/resources/eu/dnetlib/openaire/exporter/webContext-openaire-exporter.xml | ||
---|---|---|
1 |
<beans xmlns="http://www.springframework.org/schema/beans" |
|
2 |
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:p="http://www.springframework.org/schema/p" |
|
3 |
xmlns:context="http://www.springframework.org/schema/context" |
|
4 |
xmlns:util="http://www.springframework.org/schema/util" |
|
5 |
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd |
|
6 |
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd |
|
7 |
http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util.xsd"> |
|
8 |
|
|
9 |
<alias name="${openaire.exporter.db.locator}" alias="dbServiceLocator" /> |
|
10 |
|
|
11 |
<bean id="projectQueryParamsFactory" class="eu.dnetlib.openaire.exporter.ProjectQueryParamsFactory" /> |
|
12 |
|
|
13 |
<bean id="dbDynamicServiceLocator" name="dbDynamicServiceLocator" |
|
14 |
class="eu.dnetlib.enabling.tools.DynamicServiceLocator" |
|
15 |
p:serviceResolver-ref="serviceResolver" p:lookUpLocator-ref="lookupLocator" |
|
16 |
p:clazz="eu.dnetlib.enabling.database.rmi.DatabaseService" /> |
|
17 |
|
|
18 |
<bean id="dbStaticServiceLocator" name="dbStaticServiceLocator" |
|
19 |
class="eu.dnetlib.enabling.tools.StaticServiceLocator" p:service-ref="databaseService" /> |
|
20 |
|
|
21 |
</beans> |
modules/cnr-openaire-exporter/tags/cnr-openaire-exporter-2.0.0/src/main/resources/eu/dnetlib/openaire/exporter/applicationContext-openaire-exporter.properties | ||
---|---|---|
1 |
openaire.exporter.dspace.xslt=classpath:/eu/dnetlib/openaire/exporter/xslt/projects_dspace.xslt |
|
2 |
openaire.exporter.eprints.xslt=classpath:/eu/dnetlib/openaire/exporter/xslt/projects_eprints.xslt |
|
3 |
#Choose between: dbDynamicServiceLocator or dbStaticServiceLocator |
|
4 |
openaire.exporter.db.locator = dbStaticServiceLocator |
modules/cnr-openaire-exporter/tags/cnr-openaire-exporter-2.0.0/src/main/resources/eu/dnetlib/openaire/exporter/xslt/projects_dspace.xslt | ||
---|---|---|
1 |
<?xml version="1.0" encoding="UTF-8"?> |
|
2 |
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" |
|
3 |
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" exclude-result-prefixes="xsl xsi"> |
|
4 |
|
|
5 |
<xsl:output omit-xml-declaration="yes" standalone="omit" indent="yes"/> |
|
6 |
|
|
7 |
<xsl:template match="/"> |
|
8 |
<xsl:variable name="id" select="//FIELD[@name='grant_agreement_number']" /> |
|
9 |
<xsl:variable name="title" select="//FIELD[@name='title']" /> |
|
10 |
<xsl:variable name="acronym" select="//FIELD[@name='acronym']" /> |
|
11 |
<xsl:variable name="fundingProgramme" select="//FIELD[@name='fundingprogramme']" /> |
|
12 |
<xsl:variable name="idnamespace"> |
|
13 |
<xsl:choose> |
|
14 |
<xsl:when test="$fundingProgramme = 'FP7'">info:eu-repo/grantAgreement/EC/FP7/</xsl:when> |
|
15 |
<xsl:when test="$fundingProgramme = 'WT'">info:eu-repo/grantAgreement/WT/</xsl:when> |
|
16 |
<xsl:otherwise>info:eu-repo/grantAgreement/</xsl:otherwise> |
|
17 |
</xsl:choose> |
|
18 |
</xsl:variable> |
|
19 |
<pair> |
|
20 |
<displayed-value><xsl:value-of select="concat($id, ' - ', $acronym, ' - ', $title)" /></displayed-value> |
|
21 |
<stored-value><xsl:value-of select="concat($idnamespace, $id)" /></stored-value> |
|
22 |
</pair> |
|
23 |
</xsl:template> |
|
24 |
|
|
25 |
</xsl:stylesheet> |
modules/cnr-openaire-exporter/tags/cnr-openaire-exporter-2.0.0/src/main/resources/eu/dnetlib/openaire/exporter/xslt/projects_eprints.xslt | ||
---|---|---|
1 |
<?xml version="1.0" encoding="UTF-8"?> |
|
2 |
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" |
|
3 |
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" exclude-result-prefixes="xsl xsi"> |
|
4 |
|
|
5 |
<!-- DO NOT REINDENT THIS FILE: IT IS IMPORTANT THAT EACH PROJECT IS ON ONE SINGLE LINE --> |
|
6 |
<xsl:output omit-xml-declaration="yes" standalone="omit" indent="no"/> |
|
7 |
|
|
8 |
<xsl:template match="/"> |
|
9 |
<xsl:variable name="id" select="//FIELD[@name='grant_agreement_number']" /> |
|
10 |
<xsl:variable name="title" select="//FIELD[@name='title']" /> |
|
11 |
<xsl:variable name="acronym" select="//FIELD[@name='acronym']" /> |
|
12 |
<xsl:variable name="fundingProgramme" select="//FIELD[@name='fundingprogramme']" /> |
|
13 |
<xsl:choose> |
|
14 |
<xsl:when test="$fundingProgramme = 'FP7'"><xsl:value-of select="concat($acronym, ' - ', $title, '	')" /><li style='border-right: solid 50px #30FF30' ><xsl:value-of select="concat($id, ' - ', $acronym, ' - ', $title)" /><ul><li id="for:value:component:_fp7_project_id"><xsl:value-of select="concat('info:eu-repo/grantAgreement/EC/FP7/', $id)" /></li></ul></li><xsl:text> |
|
15 |
</xsl:text></xsl:when> |
|
16 |
<xsl:otherwise><xsl:value-of select="concat($acronym, ' - ', $title, '	')" /><li style='border-right: solid 50px #30FF30' ><xsl:value-of select="concat($id, ' - ', $acronym, ' - ', $title)" /><ul><li id="for:value:component:_wt_project_id"><xsl:value-of select="concat('info:eu-repo/grantAgreement/WT/', $id)" /></li></ul></li><xsl:text> |
|
17 |
</xsl:text></xsl:otherwise> |
|
18 |
</xsl:choose> |
|
19 |
</xsl:template> |
|
20 |
|
|
21 |
|
|
22 |
</xsl:stylesheet> |
modules/cnr-openaire-exporter/tags/cnr-openaire-exporter-2.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>dnet-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>cnr-openaire-exporter</artifactId> |
|
12 |
<packaging>jar</packaging> |
|
13 |
<version>2.0.0</version> |
|
14 |
<scm> |
|
15 |
<developerConnection>scm:svn:https://svn.driver.research-infrastructures.eu/driver/dnet40/modules/cnr-openaire-exporter/tags/cnr-openaire-exporter-2.0.0</developerConnection> |
|
16 |
</scm> |
|
17 |
<dependencies> |
|
18 |
<dependency> |
|
19 |
<groupId>eu.dnetlib</groupId> |
|
20 |
<artifactId>cnr-service-common</artifactId> |
|
21 |
<version>[1.0.0,2.0.0)</version> |
|
22 |
</dependency> |
|
23 |
<dependency> |
|
24 |
<groupId>eu.dnetlib</groupId> |
|
25 |
<artifactId>cnr-resultset-client</artifactId> |
|
26 |
<version>[1.0.0,2.0.0)</version> |
|
27 |
</dependency> |
|
28 |
<dependency> |
|
29 |
<groupId>eu.dnetlib</groupId> |
|
30 |
<artifactId>cnr-enabling-database-api</artifactId> |
|
31 |
<version>[1.0.0,2.0.0)</version> |
|
32 |
</dependency> |
|
33 |
<dependency> |
|
34 |
<groupId>javax.servlet</groupId> |
|
35 |
<artifactId>javax.servlet-api</artifactId> |
|
36 |
<version>${javax.servlet.version}</version> |
|
37 |
<scope>provided</scope> |
|
38 |
</dependency> |
|
39 |
<dependency> |
|
40 |
<groupId>junit</groupId> |
|
41 |
<artifactId>junit</artifactId> |
|
42 |
<version>${junit.version}</version> |
|
43 |
<scope>test</scope> |
|
44 |
</dependency> |
|
45 |
</dependencies> |
|
46 |
</project> |
Also available in: Unified diff
[maven-release-plugin] copy for tag cnr-openaire-exporter-2.0.0