1
|
package eu.dnetlib.data.claimsDemo;
|
2
|
|
3
|
/**
|
4
|
* Created by Eri on 18/11/2015.
|
5
|
*/
|
6
|
|
7
|
|
8
|
//import eu.dnetlib.data.claims.migration.Claim;
|
9
|
|
10
|
import eu.dnetlib.data.claims.migration.*;
|
11
|
import org.apache.log4j.BasicConfigurator;
|
12
|
import org.apache.log4j.Logger;
|
13
|
import org.junit.Before;
|
14
|
import org.junit.Test;
|
15
|
import org.junit.runner.RunWith;
|
16
|
import org.springframework.beans.factory.annotation.Autowired;
|
17
|
import org.springframework.test.context.ContextConfiguration;
|
18
|
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
19
|
import org.xml.sax.SAXException;
|
20
|
|
21
|
import javax.xml.parsers.ParserConfigurationException;
|
22
|
import javax.xml.xpath.XPathExpressionException;
|
23
|
import java.io.IOException;
|
24
|
import java.sql.ResultSet;
|
25
|
|
26
|
import static junit.framework.Assert.assertNotNull;
|
27
|
|
28
|
/**
|
29
|
* @author eri
|
30
|
*/
|
31
|
@RunWith(SpringJUnit4ClassRunner.class)
|
32
|
@ContextConfiguration(locations = {"springContext-claimsDemo.xml"})
|
33
|
|
34
|
public class TestClass {
|
35
|
private Logger log = Logger.getLogger(this.getClass());
|
36
|
|
37
|
@Autowired
|
38
|
private ClaimBuilder claimBuilder;
|
39
|
|
40
|
@Autowired
|
41
|
private QueryBuilder queryBuilder;
|
42
|
|
43
|
@Autowired
|
44
|
private SqlDAO sqlDAO;
|
45
|
|
46
|
@Autowired
|
47
|
private QueryGenerator queryGenerator;
|
48
|
|
49
|
|
50
|
@Before
|
51
|
public void init() throws Exception {
|
52
|
BasicConfigurator.configure();
|
53
|
assertNotNull(sqlDAO);
|
54
|
assertNotNull(claimBuilder);
|
55
|
assertNotNull(queryBuilder);
|
56
|
|
57
|
}
|
58
|
|
59
|
|
60
|
@Test
|
61
|
public void testJob() throws Exception {
|
62
|
|
63
|
log.info(queryGenerator.generateSelectAllClaimsQuery(1));
|
64
|
|
65
|
|
66
|
}
|
67
|
|
68
|
@Test
|
69
|
public void transformClaims() throws Exception {
|
70
|
queryBuilder.getAndTransformAllClaims(1, false);
|
71
|
}
|
72
|
|
73
|
@Test
|
74
|
public void getRelationClaims() throws Exception {
|
75
|
queryBuilder.getAndTransformRelationClaims(1, false);
|
76
|
}
|
77
|
@Test
|
78
|
public void getPartOfRelationClaims() throws Exception {
|
79
|
//2750 total
|
80
|
queryBuilder.getAndTransformRelationClaims("3956", "169519", 250, false);
|
81
|
}
|
82
|
//selectRelationClaimsWithDatacite
|
83
|
@Test
|
84
|
public void selectRelationClaimsWithDatacite() throws Exception {
|
85
|
//18 total
|
86
|
ResultSet rs=sqlDAO.executePreparedQuery(queryGenerator.generateSelectRelationClaimsWithResultidLikeQuery("datacite", 18));
|
87
|
queryBuilder.transformRelationClaims(rs, true);
|
88
|
}
|
89
|
@Test
|
90
|
public void getDMFClaims() throws Exception {
|
91
|
queryBuilder.getAndTransformDMFClaims(1);
|
92
|
}
|
93
|
|
94
|
|
95
|
@Test
|
96
|
public void buildResultById() throws Exception {
|
97
|
// String id="datacite____::c33d24d689a29abb39f5261876c2a3ed";
|
98
|
String id="dedup_wf_001::3e38e7854dc6dce12a4e46e2f9d4d034";
|
99
|
Result r= new Result();
|
100
|
r.setOpenaireId(id);
|
101
|
r.setResultType("publication");
|
102
|
ParsingClaimUtils.buildResult(r,"",false);
|
103
|
log.info((r.isFound()?r.toString():"NOT found in search.."));
|
104
|
Result r2= new Result();
|
105
|
r2.setOpenaireId(id);
|
106
|
r2.setResultType("publication");
|
107
|
ParsingClaimUtils.buildResult(r2,"",true);
|
108
|
log.info((r2.isFound()?r2.toString():"NOT found in API.."));
|
109
|
}
|
110
|
@Test
|
111
|
public void getConceptDMFClaims() throws Exception {
|
112
|
//total 203
|
113
|
queryBuilder.getAndTransformConceptClaims(1, false);
|
114
|
}
|
115
|
@Test
|
116
|
public void testHttpRequest() throws Exception {
|
117
|
SearchUtils searchUtils= new SearchUtils();
|
118
|
log.info(searchUtils.getResult("doajarticles::eb8a123eb82b25013b0001d0e2d1842b"));
|
119
|
}
|
120
|
|
121
|
@Test
|
122
|
public void testXpath() throws ParserConfigurationException, IOException, SAXException, XPathExpressionException {
|
123
|
|
124
|
SearchUtils searchUtils= new SearchUtils();
|
125
|
log.info(searchUtils.getResultSearchUrl("dedup_wf_001::88a1eedd1ffce63dccf51d8ce2053c85"));
|
126
|
ParsingClaimUtils parsingClaimUtils= new ParsingClaimUtils(searchUtils.getProjectSearchUrl("dedup_wf_001::88a1eedd1ffce63dccf51d8ce2053c85"),true);
|
127
|
log.info("***bestlicense:"+parsingClaimUtils.getValueFromXMLAtrribute("bestlicense"));
|
128
|
log.info("***embargoendyear:"+parsingClaimUtils.getValueFromXMLAtrribute("embargoendyear"));
|
129
|
log.info("***embargoendyear:"+parsingClaimUtils.getValueFromXMLAtrribute("embargoendyear"));
|
130
|
log.info("***Title:"+parsingClaimUtils.getValueFromXMLAtrribute("title"));
|
131
|
log.info("***resulttypename:"+parsingClaimUtils.getValueFromXMLAtrribute("resulttypename"));
|
132
|
|
133
|
}
|
134
|
|
135
|
@Test
|
136
|
public void testParsingDMF() throws IOException, SAXException, ParserConfigurationException {
|
137
|
Result r=ParsingClaimUtils.getResultFromDMF("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" +
|
138
|
"<record xmlns:dc=\"http://purl.org/dc/elements/1.1/\" xmlns:prov=\"http://www.openarchives.org/OAI/2.0/provenance\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:dri=\"http://www.driver-repository.eu/namespace/dri\" xmlns:dr=\"http://www.driver-repository.eu/namespace/dr\" xmlns:oaf=\"http://namespace.openaire.eu/oaf\">\n" +
|
139
|
" <header xmlns=\"http://namespace.openaire.eu/\">\n" +
|
140
|
" <dri:objIdentifier>crossref____::47593e13b24bcdd0f3d5573499f1d3a9</dri:objIdentifier>\n" +
|
141
|
" <dri:recordIdentifier>10.1088/0004-637X/761/1/34</dri:recordIdentifier>\n" +
|
142
|
" <dri:dateOfCollection></dri:dateOfCollection>\n" +
|
143
|
" <dri:mdFormat></dri:mdFormat>\n" +
|
144
|
" <dri:mdFormatInterpretation></dri:mdFormatInterpretation>\n" +
|
145
|
" <dri:repositoryId></dri:repositoryId>\n" +
|
146
|
" <dr:objectIdentifier></dr:objectIdentifier>\n" +
|
147
|
" <dr:dateOfCollection>2014-10-10T14:59:49+00:00</dr:dateOfCollection>\n" +
|
148
|
" <oaf:datasourceprefix>crossref____</oaf:datasourceprefix>\n" +
|
149
|
" </header>\n" +
|
150
|
" <metadata xmlns=\"http://namespace.openaire.eu/\">\n" +
|
151
|
" <dc:dateAccepted>2012-01-01T00:00:00Z</dc:dateAccepted>\n" +
|
152
|
" <dc:identifier>http://stacks.iop.org/0004-637X/761/i=1/a=34?key=crossref.d14dae8ac205453af63561a69c108e13</dc:identifier>\n" +
|
153
|
" <dc:title>A THREE-DIMENSIONAL VIEW OF THE REMNANT OF NOVA PERSEI 1901 (GK Per)</dc:title>\n" +
|
154
|
" <oaf:collectedDatasourceid>openaire____::crossref</oaf:collectedDatasourceid>\n" +
|
155
|
" <oaf:accesscreateClaimTablesrights></oaf:accessrights>\n" +
|
156
|
" <oaf:hostedBy name=\"Unknown Repository\" id=\"openaire____::1256f046-bf1f-4afc-8b47-d0b147148b18\"/>\n" +
|
157
|
" <oaf:collectedFrom name=\"Crossref\" id=\"openaire____::crossref\" />\n" +
|
158
|
"\n" +
|
159
|
" <dc:creator>Liimets, T.</dc:creator>\n" +
|
160
|
" generateCreateClaimTablesQuery <dc:creator>Corradi, R. L. M.</dc:creator>\n" +
|
161
|
" <dc:creator>Santander-García, M.</dc:creator>\n" +
|
162
|
" <dc:creator>Villaver, E.</dc:creator>\n" +
|
163
|
" <dc:creator>Rodríguez-Gil, P.</dc:creator>\n" +
|
164
|
" <dc:creator>Verro, K.</dc:creator>\n" +
|
165
|
" <dc:creator>Kolka, I.</dc:creator>\n" +
|
166
|
"\n" +
|
167
|
" <dc:identifier identifierType=\"doi\">10.1088/0004-637X/761/1/34</dc:identifier>\n" +
|
168
|
" <dr:CobjIdentifier>10.1088/0004-637X/761/1/34</dr:CobjIdentifier>\n" +
|
169
|
" </metadata>\n" +
|
170
|
"</record>");
|
171
|
log.info(r.toString());
|
172
|
|
173
|
}
|
174
|
@Test
|
175
|
public void dropClaimTables() throws Exception {
|
176
|
// queryBuilder.dropClaimTables();
|
177
|
}
|
178
|
@Test
|
179
|
public void createClaimTables() throws Exception {
|
180
|
// queryBuilder.generateCreateClaimTablesQuery();
|
181
|
}
|
182
|
@Test
|
183
|
public void testGetAndTransformClaimById() throws Exception {
|
184
|
//dmf context 168702
|
185
|
//168202 orcid dmf
|
186
|
//169473 doi dmf168823
|
187
|
|
188
|
queryBuilder.getAndTransformClaimById("168025", false);
|
189
|
}
|
190
|
|
191
|
@Test
|
192
|
public void validDoiTest() throws Exception {
|
193
|
//10.1523/JNEUROSCI.2900-11.2012
|
194
|
String doi="10.1523/JNEUROSCI.2900-11.2012";
|
195
|
String tr_doi=doi=ClaimValidation.isValidDoi(doi);
|
196
|
System.out.println("Initial doi:"+doi+" "+((doi.equals(tr_doi))?"":" Transformed to"+tr_doi));
|
197
|
|
198
|
}
|
199
|
@Test
|
200
|
public void buildResultFromAPI() throws Exception {
|
201
|
String id="dedup_wf_001::3e38e7854dc6dce12a4e46e2f9d4d034";
|
202
|
Result r = new Result();
|
203
|
r.setOpenaireId(id);
|
204
|
r.setResultType(ClaimUtils.PUBLICATION);
|
205
|
ParsingClaimUtils.buildResult(r,"",true);
|
206
|
System.out.println(r.toString());
|
207
|
|
208
|
}
|
209
|
@Test
|
210
|
public void buildProject() throws Exception {
|
211
|
String id="arc_________::089188bbc5db213fb2b00a0d93043fc4";
|
212
|
id="corda_______::404d91e07cd4d32fddd8fc636ad4daf7";
|
213
|
Project p= ParsingClaimUtils.buildProject(id, "", false);
|
214
|
log.info((p.isFound()?p.toString():"NOT found in search.."));
|
215
|
|
216
|
Project p2= ParsingClaimUtils.buildProject(id, "", true);
|
217
|
log.info((p2.isFound() ? p2.toString() : "NOT found in API.."));
|
218
|
|
219
|
}
|
220
|
@Test
|
221
|
public void test() throws Exception {
|
222
|
Result r = new Result();
|
223
|
r.setOrcidworkid("0000-0002-5119-1682-19500512");
|
224
|
ParsingClaimUtils.getXmlfromOrcid(r);
|
225
|
log.info(r.toString());
|
226
|
}
|
227
|
|
228
|
@Test
|
229
|
public void testQueries() throws Exception {
|
230
|
ResultSet rs=sqlDAO.executePreparedQuery(queryGenerator.generateSelectRelationClaimByIdQuery("169149"));
|
231
|
log.info(queryGenerator.generateSelectRelationClaimByIdQuery("169149"));
|
232
|
while(rs.next()){
|
233
|
// log.info(rs.getString("xml"));
|
234
|
Claim claim= claimBuilder.getRelationClaim(rs);
|
235
|
log.info(claim.toString());
|
236
|
//log.info(JsonldBuilder.toJsonld(claim));
|
237
|
|
238
|
}
|
239
|
}
|
240
|
|
241
|
}
|