1
|
package eu.dnetlib.data.claims;
|
2
|
|
3
|
/**
|
4
|
* Created by Eri on 18/11/2015.
|
5
|
*/
|
6
|
|
7
|
|
8
|
import eu.dnetlib.data.claims.entity.Claim;
|
9
|
import eu.dnetlib.data.claims.entity.OpenaireEntity;
|
10
|
import eu.dnetlib.data.claims.entity.Project;
|
11
|
import eu.dnetlib.data.claims.entity.Result;
|
12
|
import eu.dnetlib.data.claims.handler.*;
|
13
|
import eu.dnetlib.data.claims.parser.ExternalRecordParser;
|
14
|
import eu.dnetlib.data.claims.sql.SQLStoreException;
|
15
|
import eu.dnetlib.data.claims.sql.SqlDAO;
|
16
|
import eu.dnetlib.data.claims.sql.SqlStore;
|
17
|
import eu.dnetlib.data.claims.utils.*;
|
18
|
import eu.dnetlib.data.emailSender.EmailSender;
|
19
|
import org.apache.log4j.BasicConfigurator;
|
20
|
import org.apache.log4j.Logger;
|
21
|
import org.junit.Before;
|
22
|
import org.junit.Test;
|
23
|
import org.junit.runner.RunWith;
|
24
|
import org.springframework.context.ApplicationContext;
|
25
|
import org.springframework.context.annotation.PropertySource;
|
26
|
import org.springframework.context.support.ClassPathXmlApplicationContext;
|
27
|
import org.springframework.test.context.ContextConfiguration;
|
28
|
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
29
|
|
30
|
import java.sql.ResultSet;
|
31
|
import java.util.ArrayList;
|
32
|
import java.util.Calendar;
|
33
|
import java.util.List;
|
34
|
|
35
|
import static junit.framework.Assert.assertNotNull;
|
36
|
|
37
|
/**
|
38
|
* @author eri
|
39
|
*/
|
40
|
@RunWith(SpringJUnit4ClassRunner.class)
|
41
|
@ContextConfiguration(locations = {"springContext-claims.xml"})
|
42
|
@PropertySource("springContext-claims.properties")
|
43
|
public class TestClass {
|
44
|
private Logger log = Logger.getLogger(this.getClass());
|
45
|
|
46
|
|
47
|
private SqlDAO sqlDAO;
|
48
|
private SqlStore sqlStore;
|
49
|
|
50
|
private QueryGenerator queryGenerator;
|
51
|
|
52
|
ProjectHandler projectHandler = null;
|
53
|
DirectIndexHandler directIndexHandler = null;
|
54
|
FetchProjectHandler fetchProjectHandler = null;
|
55
|
IndexResultHandler indexResultHandler = null;
|
56
|
ExternalRecordHandler externalRecordHandler = null;
|
57
|
ResultHandler resultHandler = null;
|
58
|
|
59
|
FetchClaimHandler fetchClaimHandler = null;
|
60
|
ClaimHandler claimHandler = null;
|
61
|
ClaimValidation claimValidation = null;
|
62
|
|
63
|
EmailSender emailSender = null;
|
64
|
|
65
|
|
66
|
@Before
|
67
|
public void init() throws Exception {
|
68
|
BasicConfigurator.configure();
|
69
|
ApplicationContext context = new ClassPathXmlApplicationContext("eu/dnetlib/data/claims/springContext-claims.xml");
|
70
|
|
71
|
directIndexHandler = context.getBean(DirectIndexHandler.class);
|
72
|
projectHandler = context.getBean(ProjectHandler.class);
|
73
|
fetchProjectHandler = context.getBean(FetchProjectHandler.class);
|
74
|
|
75
|
externalRecordHandler = context.getBean(ExternalRecordHandler.class);
|
76
|
indexResultHandler = context.getBean(IndexResultHandler.class);
|
77
|
resultHandler = context.getBean(ResultHandler.class);
|
78
|
claimHandler = context.getBean(ClaimHandler.class);
|
79
|
sqlDAO = context.getBean(SqlDAO.class);
|
80
|
sqlStore = context.getBean(SqlStore.class);
|
81
|
queryGenerator = context.getBean(QueryGenerator.class);
|
82
|
fetchClaimHandler = context.getBean(FetchClaimHandler.class);
|
83
|
claimValidation = context.getBean(ClaimValidation.class);
|
84
|
|
85
|
emailSender = context.getBean(EmailSender.class);
|
86
|
|
87
|
assertNotNull(sqlDAO);
|
88
|
|
89
|
}
|
90
|
@Test
|
91
|
public void testRollback(){
|
92
|
List <String> commands = new ArrayList<String>();
|
93
|
commands.add("UPDATE claim SET claimedBy = 'argirok1' WHERE id = 93");
|
94
|
commands.add("EXCEPTION");
|
95
|
commands.add("UPDATE claim SET claimedBy = 'argirok2' WHERE id = 95");
|
96
|
try {
|
97
|
sqlStore.executeUpdateWithRollback(commands);
|
98
|
} catch (Exception e) {
|
99
|
log.error("",e);
|
100
|
}
|
101
|
}
|
102
|
@Test
|
103
|
public void testJson(){
|
104
|
Claim claim = new Claim();
|
105
|
Project project= new Project();
|
106
|
claim.setDate(Calendar.getInstance().getTime());
|
107
|
claim.setId("claimId");
|
108
|
claim.setUserMail("claim mail");
|
109
|
|
110
|
project.setFunderName("EC");
|
111
|
project.setOpenaireId("openaireID1234");
|
112
|
project.setName("PrTitle");
|
113
|
claim.setSource(project);
|
114
|
Result result = new Result();
|
115
|
result.setAccessRights("accessRights");
|
116
|
result.setCollectedFrom("collectedFrom");
|
117
|
result.setExternalUrl("external_url");
|
118
|
result.setOpenaireId("openaire_id");
|
119
|
result.setTitle("title");
|
120
|
result.setResultType("type");
|
121
|
result.setMetadataRecord("xmlString");
|
122
|
claim.setTarget(result);
|
123
|
System.out.println("test");
|
124
|
System.out.println(JsonldBuilder.toJsonld(claim));
|
125
|
}
|
126
|
|
127
|
@Test
|
128
|
public void testFetch() throws Exception {
|
129
|
|
130
|
try {
|
131
|
List<Claim> claims = null;
|
132
|
List<String> types= new ArrayList<String>();
|
133
|
// types.add(ClaimUtils.CONTEXT);
|
134
|
// types.add(ClaimUtils.PROJECT);
|
135
|
// types.add(ClaimUtils.DATASET);
|
136
|
types.add(ClaimUtils.PUBLICATION);
|
137
|
|
138
|
|
139
|
// claims = fetchClaimHandler.fetchClaimsByUser("argirok_1@hotmail.com",1,0,types, false);
|
140
|
claims = fetchClaimHandler.fetchClaimsByContext("egi",100,0,null,"claim.claim_date",false,types,false);
|
141
|
// (String openaireId, Integer limit, Integer offset, String keyword, String orderField, boolean descending, List<String> types, boolean addCurationInfo) throws Exception, SQLStoreException {
|
142
|
// claims = fetchClaimHandler.fetchClaimsByUser("argirok@di.uoa.gr",3,0,null,"claim.claim_date",false,types,false);
|
143
|
//
|
144
|
// claims = fetchClaimHandler.fetchClaimsByProject("corda_______::ab9c77ce02967b24fc9c1a74276e4677",5,0);
|
145
|
// claims = fetchClaimHandler.fetchClaimsByProject("corda__h2020::94c962e736df90a5075a7f660ba3d7f6",12,0,null, "claim.claim_date",false,types,true);
|
146
|
//claims = fetchClaimHandler.fetchClaimsByToken("corda__h2020::94c962e736df90a5075a7f660ba3d7f6","argiro@gmail.com",12,0,null, "claim.claim_date",false,types,false);
|
147
|
|
148
|
// claims = fetchClaimHandler.fetchClaimsByDate("2016-01-14 14:53:50","2016-04-21",10,0);
|
149
|
// claims = fetchClaimHandler.fetchClaimsByDate("2016-01-14 14:53:50","2017-04-21",10,0,"", "source",true,types, false);
|
150
|
// // 2016-04-20 14:53:50.276
|
151
|
// claims = fetchClaimHandler.fetchClaimsByContext("egi::country::gr",5,0,null,"claim.claim_date",false,types);
|
152
|
// claims = fetchClaimHandler.fetchAllClaims(5,3);
|
153
|
// claims = fetchClaimHandler.fetchClaimsByResult("od_______233::235960bb401207cb9595a79a1bc8e867",5,0,null, "claim.claim_date",false,types);
|
154
|
// claims = fetchClaimHandler.fetchClaimsByFunder("fct_________::FCT",5,0);
|
155
|
// claims= fetchClaimHandler.fetchClaimsByUser("kiatrop@di.uoa.gr",20,0,types);
|
156
|
// claims = fetchClaimHandler.fetchAllClaims(10,0,"","date",true,types);
|
157
|
|
158
|
System.out.println(fetchClaimHandler.claims2JSON(claims)+"\n\n\n "+claims.size());
|
159
|
// Claim claim = fetchClaimHandler.fetchClaimById("5821");
|
160
|
// System.out.println(fetchClaimHandler.claim2JSON(claim) );
|
161
|
// System.out.println("ALL:"+fetchClaimHandler.countClaimsByUser("argirok@di.uoa.gr","EGI", types));
|
162
|
System.out.println("ALL:"+fetchClaimHandler.countClaimsByContext("egi",null, types));
|
163
|
// System.out.println("ALL:"+fetchClaimHandler.countClaimsByProject("corda_______::ab9c77ce02967b24fc9c1a74276e4677",null,types));
|
164
|
|
165
|
// System.out.println("ALL:"+fetchClaimHandler.countAllClaims("", types));
|
166
|
// +"\n Project: "+fetchClaimHandler.countClaimsByProject("corda_______::ab9c77ce02967b24fc9c1a74276e4677")+
|
167
|
// " \n Result:"+fetchClaimHandler.countClaimsByResult("dedup_wf_001::541b1cef0d38d519e98a3b7a5b60bc75")+" \n Context:"+fetchClaimHandler.countClaimsByContext("egi::country::de")
|
168
|
// +" \n Date:"+fetchClaimHandler.countClaimsByDate("2014-04-14","2015-04-14")+" \n Funder:"+fetchClaimHandler.countClaimsByFunder("fct_________::FCT"));
|
169
|
} catch (Exception e) {
|
170
|
log.error("",e);
|
171
|
} catch (SQLStoreException e) {
|
172
|
e.printStackTrace();
|
173
|
}
|
174
|
}
|
175
|
@Test
|
176
|
public void testContext(){
|
177
|
System.out.print(ContextUtils.fetchContextById("egi::organisation::uom", false));
|
178
|
}
|
179
|
@Test
|
180
|
public void testInsert() throws Exception, SQLStoreException {
|
181
|
//acm_________::31e0e5e7cbd6e2556336d7e795f55c49
|
182
|
//dedup_wf_001::64ca1e3a4d1590456ad3dd7df8a18cd7
|
183
|
/*
|
184
|
claimedBy argirok_1@hotmail.com
|
185
|
sourceId corda_______::2c37878a0cede85dbbd1081bb9b4a2f8
|
186
|
sourceType project
|
187
|
sourceCollectedFrom openaire
|
188
|
sourceAccessRights OPEN
|
189
|
sourceEmbargoEndDate
|
190
|
targetId 10.1007/978-3-540-76323-9_4
|
191
|
targetType software
|
192
|
targetCollectedFrom crossref
|
193
|
targetAccessRights EMBARGO
|
194
|
targetEmbargoEndDate 2028-11-10T13:55:47.935Z
|
195
|
*/
|
196
|
// String id=claimHandler.buildAndInsertClaim("argirok_1@hotmail.com", "project", "corda__h2020::94c962e736df90a5075a7f660ba3d7f6", "openaire", "OPEN", null,"software", "10.1007/978-3-540-76323-9_4", "crossref", "EMBARGO","2028-11-10T13:55:47.935Z");
|
197
|
// String id=claimHandler.buildAndInsertClaim("argirok@di.uoa.gr", "project", "corda__h2020::94c962e736df90a5075a7f660ba3d7f6", "openaire", "OPEN", null,"publication", "0000-0002-9414-646X-21755327", "orcid", "EMBARGO","2028-11-10T13:55:47.935Z");
|
198
|
String id=claimHandler.buildAndInsertClaim("argirok@di.uoa.gr", "project", "corda__h2020::94c962e736df90a5075a7f660ba3d7f6", "openaire", "OPEN", null,"publication", "10.5555/987654", "crossref", "EMBARGO","2028-11-10T13:55:47.935Z");
|
199
|
|
200
|
|
201
|
// String id=claimHandler.buildAndInsertClaim("argirok@di.uoa.gr", "context", "egi::country::gr",
|
202
|
// "openaire", null, null,"dataset", "10.4225/41/55A111BDE741C", "datacite", "OPEN","2017-05-01");
|
203
|
}
|
204
|
@Test
|
205
|
public void testDelete() throws Exception, SQLStoreException {
|
206
|
|
207
|
// claimHandler.deleteClaim("argirok@di.uoa.gr","2876");
|
208
|
// claimHandler.deleteClaim("argirok@di.uoa.gr","3101");
|
209
|
}
|
210
|
|
211
|
@Test
|
212
|
public void testJob() throws Exception, SQLStoreException {
|
213
|
String selectcountDMFClaims =" Select count(*) from claims where type='dmf2actions' and xml NOT ILIKE '%<oaf:concept%' ";
|
214
|
String selectCountConceptClaims =" Select count(*) from claims where ( type='dmf2actions' or type='updates2actions' ) and xml LIKE '%<oaf:concept%' ";
|
215
|
String selectCountRelationClaims =" Select count(*) from claims where type='rels2actions' ";
|
216
|
|
217
|
ResultSet rs = sqlDAO.executePreparedQuery(selectCountConceptClaims);
|
218
|
|
219
|
while(rs.next()) {
|
220
|
log.info("Concept claims: "+rs.getInt(1));
|
221
|
}
|
222
|
rs = sqlDAO.executePreparedQuery(selectCountRelationClaims);
|
223
|
|
224
|
while(rs.next()) {
|
225
|
log.info("Relation claims: "+rs.getInt(1));
|
226
|
}
|
227
|
rs = sqlDAO.executePreparedQuery("Select count(*) from claim");
|
228
|
|
229
|
while(rs.next()) {
|
230
|
log.info("Migrated claims: "+rs.getInt(1));
|
231
|
}
|
232
|
rs = sqlDAO.executePreparedQuery("Select count(*) from result");
|
233
|
|
234
|
while(rs.next()) {
|
235
|
log.info("Results: "+rs.getInt(1));
|
236
|
}
|
237
|
|
238
|
}
|
239
|
|
240
|
@Test
|
241
|
public void testHttpRequest() throws Exception {
|
242
|
SearchUtils searchUtils= new SearchUtils();
|
243
|
log.info(searchUtils.fetchPublicationXmlFromIndex("doajarticles::eb8a123eb82b25013b0001d0e2d1842b", false));
|
244
|
log.info(searchUtils.fetchDatasetXmlFromIndex("doajarticles::eb8a123eb82b25013b0001d0e2d1842b", false));
|
245
|
}
|
246
|
|
247
|
@Test
|
248
|
public void testXpath() throws Exception {
|
249
|
Result r=indexResultHandler.fetchResultById("dedup_wf_001::88a1eedd1ffce63dccf51d8ce2053c85", false);
|
250
|
}
|
251
|
|
252
|
@Test
|
253
|
public void testSoftwareXpath() throws Exception {
|
254
|
// http://scoobydoo.di.uoa.gr:5000/search/software?softwareId=datacite____%3A%3Aabe9e916b29d028789d7ae3c6f79f254
|
255
|
Result r=indexResultHandler.fetchSoftwareById("datacite____::abe9e916b29d028789d7ae3c6f79f254", false);
|
256
|
if(r!=null){
|
257
|
System.out.println(r.toString());
|
258
|
}
|
259
|
|
260
|
}
|
261
|
@Test
|
262
|
public void testPublicationXpath() throws Exception {
|
263
|
Result r=indexResultHandler.fetchPublicationById("od________18::5acd89ab4df2b877a7a208ea2a123a87", false);
|
264
|
if(r!=null){
|
265
|
System.out.println(r.toString());
|
266
|
}
|
267
|
|
268
|
}
|
269
|
|
270
|
@Test
|
271
|
public void dropClaimTables() throws Exception {
|
272
|
// sqlDAO.executeUpdateQuery(queryGenerator.generateDeleteClaimTablesQuery());
|
273
|
}
|
274
|
@Test
|
275
|
public void createClaimTables() throws Exception {
|
276
|
// sqlDAO.executeUpdateQuery(queryGenerator.generateCreateClaimTablesQuery());
|
277
|
}
|
278
|
|
279
|
|
280
|
@Test
|
281
|
public void buildProject() throws Exception {
|
282
|
String id = "arc_________::089188bbc5db213fb2b00a0d93043fc4";
|
283
|
Project pr = projectHandler.fetchProjectByID(id,false);
|
284
|
log.info(pr.toString());
|
285
|
id="corda_______::404d91e07cd4d32fddd8fc636ad4daf7";
|
286
|
pr = projectHandler.fetchProjectByID(id, false);
|
287
|
log.info(pr.toString());
|
288
|
|
289
|
}
|
290
|
|
291
|
|
292
|
@Test
|
293
|
public void buildOpenaireResult() throws Exception {
|
294
|
|
295
|
|
296
|
OpenaireEntity r= claimHandler.buildOpenaireEntity("dedup_wf_001::9e19149f2ece7129e63638a6a52cf468",ClaimUtils.DATASET,ClaimUtils.OPENAIRE,null, null);
|
297
|
log.info(r);
|
298
|
|
299
|
}
|
300
|
@Test
|
301
|
public void buildOpenaireProject() throws Exception {
|
302
|
String projetcId = "corda_______::2c37878a0cede85dbbd1081bb9b4a2f8";
|
303
|
OpenaireEntity r= claimHandler.buildOpenaireEntity(projetcId,ClaimUtils.PROJECT,ClaimUtils.OPENAIRE,null, null);
|
304
|
log.info(r);
|
305
|
|
306
|
}
|
307
|
@Test
|
308
|
public void testProject() throws Exception, SQLStoreException {
|
309
|
// List<String> mails = new ArrayList<String>();
|
310
|
// mails.add("test1@mail.com");
|
311
|
// mails.add("test2@mail.com");
|
312
|
// mails.add("test3@mail.com");
|
313
|
// sqlDAO.executePreparedQuery(queryGenerator.generateInsertProjectQuery("123","test project","TEstP","","","",mails));
|
314
|
System.out.println("\n"+this.fetchProjectHandler.fetchContactEmailsByProjectId("corda__h2020::94c962e736df90a5075a7f660ba3d7f6")+"\n");
|
315
|
List<String> mails = new ArrayList<String>();
|
316
|
mails.add("test11111@mail.com");
|
317
|
mails.add("test122222@mail.com");
|
318
|
this.projectHandler.updateContactEmailsByProjectId("123",mails);
|
319
|
// System.out.println("\n"+this.projectHandler.fetchContactEmailsByProjectId("123")+"\n");
|
320
|
// String token = UUID.randomUUID().toString();
|
321
|
// this.projectHandler.updateTokenByProjectId("123",token);
|
322
|
|
323
|
|
324
|
|
325
|
}
|
326
|
@Test
|
327
|
public void testMD5() throws Exception {
|
328
|
String id = "10.1016/j.engstruct.2013.03.014";
|
329
|
String createdId = ExternalRecordParser.createOpenaireId(id);
|
330
|
String openaireId = "userclaim___::07ec9eb2278a11e352e3fa93a621411d";
|
331
|
System.out.println(createdId );
|
332
|
|
333
|
}
|
334
|
@Test
|
335
|
public void testCuration() throws Exception, SQLStoreException {
|
336
|
// boolean updated = claimHandler.updateClaimCurationInfo("argiro@gmail.com","1",true);
|
337
|
// System.out.println(updated);
|
338
|
}
|
339
|
/*
|
340
|
@Test
|
341
|
public void testFetchProjectIdByTokenAndEmail() throws Exception, SQLStoreException {
|
342
|
String openaireId = this.fetchProjectHandler.fetchProjectIdByTokenAndEmail("dedc6979-1967-4ea2-a2ad-5135f95285ae", "test11111@mail.com");
|
343
|
System.out.println(openaireId);
|
344
|
}
|
345
|
|
346
|
@Test
|
347
|
public void testFetchProjectIdByToken() throws Exception, SQLStoreException {
|
348
|
String openaireId = this.fetchProjectHandler.fetchProjectIdByToken("dedc6979-1967-4ea2-a2ad-5135f95285ae");
|
349
|
System.out.println(openaireId);
|
350
|
}
|
351
|
*/
|
352
|
@Test
|
353
|
public void directIndexClaim() throws Exception {
|
354
|
System.out.println(this.claimValidation.getPathToSaveReport());
|
355
|
String json = "{\"originalId\":\"userclaim____::d1e668dc81fa714aa98a558d9ce515fa\",\"title\":\"Expression of Ik6 and Ik8 Isoforms and Their Association with Relapse and Death in Mexican Children with Acute Lymphoblastic Leukemia\",\"authors\":[\"Reyes-León Adriana\",\"Juárez-Velázquez Rocío\",\"Medrano-Hernández Alma\",\"Cuenca-Roldán Teresa\",\"Salas-Labadía Consuelo\",\"del Pilar Navarrete-Meneses María\",\"Rivera-Luna Roberto\",\"López-Hernández Gerardo\",\"Paredes-Aguilera Rogelio\",\"Pérez-Vera Patricia\"],\"publisher\":\"Public Library of Science (PLoS)\",\"type\":\"publication\",\"pids\":[{\"type\":\"doi\",\"value\":\"10.1371/journal.pone.0130756\"}],\"licenseCode\":\"OPEN\",\"resourceType\":\"0001\",\"url\":\"http://dx.doi.org/10.1371/journal.pone.0130756\",\"hostedById\":\"openaire____::1256f046-bf1f-4afc-8b47-d0b147148b18\",\"collectedFromId\":\"openaire____::crossref\",\"contexts\":[\"egi::country::gr\"]}";
|
356
|
// System.out.println("\n\nFeed Response is: "+directIndexHandler.insertRecord(json));
|
357
|
|
358
|
// System.out.println("\n\nDelete Response is: "+directIndexHandler.deleteRecord("userclaim___::d1e668dc81fa714aa98a558d9ce515fa","openaire____::crossref"));
|
359
|
}
|
360
|
|
361
|
// To run following tests about email: claim notifications, set all the properties inside project folder
|
362
|
@Test
|
363
|
public void forceSendEmailNotifications() throws Exception {
|
364
|
//emailSender.run();
|
365
|
}
|
366
|
|
367
|
@Test
|
368
|
public void testEmail() throws Exception {
|
369
|
ArrayList<String> list = new ArrayList<String>();
|
370
|
list.add("konstantinagalouni@gmail.com");
|
371
|
list.add("argirok@di.uoa.gr");
|
372
|
// emailSender.send("openaire_id_test", "openaire_name_test", "community", list);
|
373
|
}
|
374
|
|
375
|
}
|