Project

General

Profile

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
    ContextUtils contextUtils = null;
65

    
66

    
67
    @Before
68
	public void init() throws Exception {
69
		BasicConfigurator.configure();
70
        ApplicationContext context = new ClassPathXmlApplicationContext("eu/dnetlib/data/claims/springContext-claims.xml");
71

    
72
        directIndexHandler = context.getBean(DirectIndexHandler.class);
73
        projectHandler = context.getBean(ProjectHandler.class);
74
        fetchProjectHandler = context.getBean(FetchProjectHandler.class);
75

    
76
        externalRecordHandler = context.getBean(ExternalRecordHandler.class);
77
        indexResultHandler = context.getBean(IndexResultHandler.class);
78
        resultHandler = context.getBean(ResultHandler.class);
79
        claimHandler = context.getBean(ClaimHandler.class);
80
        sqlDAO = context.getBean(SqlDAO.class);
81
        sqlStore = context.getBean(SqlStore.class);
82
        queryGenerator = context.getBean(QueryGenerator.class);
83
        fetchClaimHandler = context.getBean(FetchClaimHandler.class);
84
        claimValidation = context.getBean(ClaimValidation.class);
85

    
86
        emailSender = context.getBean(EmailSender.class);
87
        contextUtils = context.getBean(ContextUtils.class);
88

    
89
        assertNotNull(sqlDAO);
90

    
91
	}
92
    @Test
93
    public void testRollback(){
94
        List <String> commands = new ArrayList<String>();
95
        commands.add("UPDATE claim SET claimedBy = 'argirok1' WHERE  id = 93");
96
        commands.add("EXCEPTION");
97
        commands.add("UPDATE claim SET claimedBy = 'argirok2' WHERE  id = 95");
98
        try {
99
            sqlStore.executeUpdateWithRollback(commands);
100
        } catch (Exception e) {
101
            log.error("",e);
102
        }
103
    }
104
    @Test
105
    public void testJson(){
106
        Claim claim = new Claim();
107
        Project project= new Project();
108
        claim.setDate(Calendar.getInstance().getTime());
109
        claim.setId("claimId");
110
        claim.setUserMail("claim mail");
111

    
112
        project.setFunderName("EC");
113
        project.setOpenaireId("openaireID1234");
114
        project.setName("PrTitle");
115
        claim.setSource(project);
116
        Result result = new Result();
117
        result.setAccessRights("accessRights");
118
        result.setCollectedFrom("collectedFrom");
119
        result.setExternalUrl("external_url");
120
        result.setOpenaireId("openaire_id");
121
        result.setTitle("title");
122
        result.setResultType("type");
123
        result.setMetadataRecord("xmlString");
124
        claim.setTarget(result);
125
        System.out.println("test");
126
        System.out.println(JsonldBuilder.toJsonld(claim));
127
    }
128

    
129
    @Test
130
    public void testFetch() throws Exception {
131

    
132
        try {
133
            List<Claim> claims = null;
134
            List<String> types= new ArrayList<String>();
135
//            types.add(ClaimUtils.CONTEXT);
136
//            types.add(ClaimUtils.PROJECT);
137
//          types.add(ClaimUtils.DATASET);
138
            types.add(ClaimUtils.PUBLICATION);
139

    
140

    
141
//            claims = fetchClaimHandler.fetchClaimsByUser("argirok_1@hotmail.com",1,0,types, false);
142
            claims = fetchClaimHandler.fetchClaimsByContext("egi",100,0,null,"claim.claim_date",false,types,false);
143
//            (String openaireId, Integer limit, Integer offset, String keyword, String orderField, boolean descending, List<String> types, boolean addCurationInfo) throws Exception, SQLStoreException {
144
//            claims = fetchClaimHandler.fetchClaimsByUser("argirok@di.uoa.gr",3,0,null,"claim.claim_date",false,types,false);
145
//
146
//            claims = fetchClaimHandler.fetchClaimsByProject("corda_______::ab9c77ce02967b24fc9c1a74276e4677",5,0);
147
//            claims = fetchClaimHandler.fetchClaimsByProject("corda__h2020::94c962e736df90a5075a7f660ba3d7f6",12,0,null, "claim.claim_date",false,types,true);
148
            //claims = fetchClaimHandler.fetchClaimsByToken("corda__h2020::94c962e736df90a5075a7f660ba3d7f6","argiro@gmail.com",12,0,null, "claim.claim_date",false,types,false);
149

    
150
//            claims = fetchClaimHandler.fetchClaimsByDate("2016-01-14 14:53:50","2016-04-21",10,0);
151
//            claims = fetchClaimHandler.fetchClaimsByDate("2016-01-14 14:53:50","2017-04-21",10,0,"", "source",true,types, false);
152
//            // 2016-04-20 14:53:50.276
153
//            claims = fetchClaimHandler.fetchClaimsByContext("egi::country::gr",5,0,null,"claim.claim_date",false,types);
154
//            claims = fetchClaimHandler.fetchAllClaims(5,3);
155
//            claims = fetchClaimHandler.fetchClaimsByResult("od_______233::235960bb401207cb9595a79a1bc8e867",5,0,null, "claim.claim_date",false,types);
156
//            claims = fetchClaimHandler.fetchClaimsByFunder("fct_________::FCT",5,0);
157
//            claims= fetchClaimHandler.fetchClaimsByUser("kiatrop@di.uoa.gr",20,0,types);
158
//            claims = fetchClaimHandler.fetchAllClaims(10,0,"","date",true,types);
159

    
160
            System.out.println(fetchClaimHandler.claims2JSON(claims)+"\n\n\n "+claims.size());
161
//          Claim claim = fetchClaimHandler.fetchClaimById("5821");
162
//          System.out.println(fetchClaimHandler.claim2JSON(claim) );
163
//          System.out.println("ALL:"+fetchClaimHandler.countClaimsByUser("argirok@di.uoa.gr","EGI", types));
164
          System.out.println("ALL:"+fetchClaimHandler.countClaimsByContext("egi",null, types));
165
//            System.out.println("ALL:"+fetchClaimHandler.countClaimsByProject("corda_______::ab9c77ce02967b24fc9c1a74276e4677",null,types));
166

    
167
//        System.out.println("ALL:"+fetchClaimHandler.countAllClaims("", types));
168
//                +"\n Project: "+fetchClaimHandler.countClaimsByProject("corda_______::ab9c77ce02967b24fc9c1a74276e4677")+
169
//                " \n Result:"+fetchClaimHandler.countClaimsByResult("dedup_wf_001::541b1cef0d38d519e98a3b7a5b60bc75")+" \n Context:"+fetchClaimHandler.countClaimsByContext("egi::country::de")
170
//        +" \n Date:"+fetchClaimHandler.countClaimsByDate("2014-04-14","2015-04-14")+" \n Funder:"+fetchClaimHandler.countClaimsByFunder("fct_________::FCT"));
171
        } catch (Exception e) {
172
            log.error("",e);
173
        } catch (SQLStoreException e) {
174
            e.printStackTrace();
175
        }
176
    }
177
    @Test
178
    public void testContext(){
179

    
180
        System.out.print(contextUtils.fetchContextById("egi::organisation::uom"));
181
    }
182
    @Test
183
    public void testInsert() throws Exception, SQLStoreException {
184
 //acm_________::31e0e5e7cbd6e2556336d7e795f55c49
185
//dedup_wf_001::64ca1e3a4d1590456ad3dd7df8a18cd7
186
 /*
187
claimedBy	argirok_1@hotmail.com
188
sourceId	corda_______::2c37878a0cede85dbbd1081bb9b4a2f8
189
sourceType	project
190
sourceCollectedFrom	openaire
191
sourceAccessRights	OPEN
192
sourceEmbargoEndDate
193
targetId	10.1007/978-3-540-76323-9_4
194
targetType	software
195
targetCollectedFrom	crossref
196
targetAccessRights	EMBARGO
197
targetEmbargoEndDate	2028-11-10T13:55:47.935Z
198
  */
199
//        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");
200
//        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");
201
//        {user:argirok@di.uoa.gr, sourceType:project, sourceId:corda_______::2c37878a0cede85dbbd1081bb9b4a2f8, sourceCollectedFrom:openaire, sourceAccessRights:OPEN, sourceEmbargoDate:null,
202
//        targetType:publication, targetId:0000-0002-3477-3082-5288650, targetCollectedFrom:orcid, targetAccessRights:OPEN, targetEmbargoDate:null}
203
//        String id=claimHandler.buildAndInsertClaim("argirok@di.uoa.gr", "project", "corda_______::2c37878a0cede85dbbd1081bb9b4a2f8",  "openaire", "OPEN", null,"publication",                "0000-0002-3477-3082-5288651", "orcid", "OPEN",null, "development_explore");
204

    
205

    
206
//        String id=claimHandler.buildAndInsertClaim("argirok@di.uoa.gr", "context", "egi::country::gr",
207
//                "openaire", null, null,"dataset", "10.4225/41/55A111BDE741C", "datacite", "OPEN","2017-05-01","development_explore");
208
    }
209
    @Test
210
    public void testDelete() throws Exception, SQLStoreException {
211

    
212
//            claimHandler.deleteClaim("argirok@di.uoa.gr","2876");
213
//        claimHandler.deleteClaim("argirok@di.uoa.gr","3101");
214
        }
215

    
216
    @Test
217
	public void testJob() throws Exception, SQLStoreException {
218
        String selectcountDMFClaims =" Select count(*) from claims  where type='dmf2actions' and xml NOT ILIKE '%<oaf:concept%' ";
219
        String selectCountConceptClaims =" Select count(*) from claims  where ( type='dmf2actions' or type='updates2actions' ) and xml LIKE '%<oaf:concept%' ";
220
        String selectCountRelationClaims =" Select count(*) from claims  where type='rels2actions'  ";
221

    
222
        ResultSet rs = sqlDAO.executePreparedQuery(selectCountConceptClaims);
223

    
224
        while(rs.next()) {
225
            log.info("Concept claims: "+rs.getInt(1));
226
        }
227
         rs = sqlDAO.executePreparedQuery(selectCountRelationClaims);
228

    
229
        while(rs.next()) {
230
            log.info("Relation claims: "+rs.getInt(1));
231
        }
232
         rs = sqlDAO.executePreparedQuery("Select count(*) from claim");
233

    
234
        while(rs.next()) {
235
            log.info("Migrated claims: "+rs.getInt(1));
236
        }
237
        rs = sqlDAO.executePreparedQuery("Select count(*) from result");
238

    
239
        while(rs.next()) {
240
            log.info("Results: "+rs.getInt(1));
241
        }
242

    
243
	}
244

    
245
    @Test
246
    public void testHttpRequest() throws Exception {
247
        SearchUtils searchUtils= new SearchUtils();
248
        log.info(searchUtils.fetchPublicationXmlFromIndex("doajarticles::eb8a123eb82b25013b0001d0e2d1842b"));
249
        log.info(searchUtils.fetchDatasetXmlFromIndex("doajarticles::eb8a123eb82b25013b0001d0e2d1842b"));
250
    }
251

    
252
    @Test
253
    public void testXpath() throws Exception {
254
            Result r=indexResultHandler.fetchResultById("dedup_wf_001::88a1eedd1ffce63dccf51d8ce2053c85");
255
     }
256

    
257
    @Test
258
    public void testSoftwareXpath() throws Exception {
259
//        http://scoobydoo.di.uoa.gr:5000/search/software?softwareId=datacite____%3A%3Aabe9e916b29d028789d7ae3c6f79f254
260
        Result r=indexResultHandler.fetchSoftwareById("datacite____::abe9e916b29d028789d7ae3c6f79f254");
261
        if(r!=null){
262
            System.out.println(r.toString());
263
        }
264

    
265
    }
266
    @Test
267
    public void testPublicationXpath() throws Exception {
268
        Result r=indexResultHandler.fetchPublicationById("od________18::5acd89ab4df2b877a7a208ea2a123a87");
269
        if(r!=null){
270
            System.out.println(r.toString());
271
        }
272

    
273
    }
274

    
275
    @Test
276
    public void dropClaimTables() throws Exception {
277
//        sqlDAO.executeUpdateQuery(queryGenerator.generateDeleteClaimTablesQuery());
278
    }
279
    @Test
280
    public void createClaimTables() throws Exception {
281
//        sqlDAO.executeUpdateQuery(queryGenerator.generateCreateClaimTablesQuery());
282
    }
283

    
284

    
285
    @Test
286
    public void buildProject() throws Exception {
287
        String id = "arc_________::089188bbc5db213fb2b00a0d93043fc4";
288
        Project pr = projectHandler.fetchProjectByID(id);
289
        log.info(pr.toString());
290
        id="corda_______::404d91e07cd4d32fddd8fc636ad4daf7";
291
        pr = projectHandler.fetchProjectByID(id);
292
        log.info(pr.toString());
293

    
294
    }
295

    
296

    
297
    @Test
298
    public void buildOpenaireResult() throws Exception {
299

    
300

    
301
        OpenaireEntity r= claimHandler.buildOpenaireEntity("dedup_wf_001::9e19149f2ece7129e63638a6a52cf468",ClaimUtils.DATASET,ClaimUtils.OPENAIRE,null, null);
302
        log.info(r);
303

    
304
    }
305
    @Test
306
    public void buildOpenaireProject() throws Exception {
307
        String projetcId = "corda_______::2c37878a0cede85dbbd1081bb9b4a2f8";
308
        OpenaireEntity r= claimHandler.buildOpenaireEntity(projetcId,ClaimUtils.PROJECT,ClaimUtils.OPENAIRE,null, null);
309
        log.info(r);
310

    
311
    }
312
    @Test
313
    public void testProject() throws Exception, SQLStoreException {
314
//        List<String> mails = new ArrayList<String>();
315
//        mails.add("test1@mail.com");
316
//        mails.add("test2@mail.com");
317
//        mails.add("test3@mail.com");
318
//        sqlDAO.executePreparedQuery(queryGenerator.generateInsertProjectQuery("123","test project","TEstP","","","",mails));
319
        System.out.println("\n"+this.fetchProjectHandler.fetchContactEmailsByProjectId("corda__h2020::94c962e736df90a5075a7f660ba3d7f6")+"\n");
320
        List<String> mails = new ArrayList<String>();
321
        mails.add("test11111@mail.com");
322
        mails.add("test122222@mail.com");
323
        this.projectHandler.updateContactEmailsByProjectId("123",mails);
324
//        System.out.println("\n"+this.projectHandler.fetchContactEmailsByProjectId("123")+"\n");
325
//        String token = UUID.randomUUID().toString();
326
//        this.projectHandler.updateTokenByProjectId("123",token);
327

    
328

    
329

    
330
    }
331
    @Test
332
    public void testMD5() throws Exception {
333
        String id = "10.1016/j.engstruct.2013.03.014";
334
        String createdId = ExternalRecordParser.createOpenaireId(id);
335
        String openaireId = "userclaim___::07ec9eb2278a11e352e3fa93a621411d";
336
        System.out.println(createdId );
337

    
338
    }
339
    @Test
340
    public void testCuration() throws Exception, SQLStoreException {
341
//        boolean updated = claimHandler.updateClaimCurationInfo("argiro@gmail.com","1",true);
342
//        System.out.println(updated);
343
    }
344
/*
345
    @Test
346
    public void testFetchProjectIdByTokenAndEmail() throws Exception, SQLStoreException {
347
        String openaireId = this.fetchProjectHandler.fetchProjectIdByTokenAndEmail("dedc6979-1967-4ea2-a2ad-5135f95285ae", "test11111@mail.com");
348
        System.out.println(openaireId);
349
    }
350

    
351
    @Test
352
    public void testFetchProjectIdByToken() throws Exception, SQLStoreException {
353
        String openaireId = this.fetchProjectHandler.fetchProjectIdByToken("dedc6979-1967-4ea2-a2ad-5135f95285ae");
354
        System.out.println(openaireId);
355
    }
356
*/
357
    @Test
358
    public void directIndexClaim() throws Exception {
359
        System.out.println(this.claimValidation.getPathToSaveReport());
360
        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\"]}";
361
//        System.out.println("\n\nFeed Response is: "+directIndexHandler.insertRecord(json));
362

    
363
//        System.out.println("\n\nDelete Response is: "+directIndexHandler.deleteRecord("userclaim___::d1e668dc81fa714aa98a558d9ce515fa","openaire____::crossref"));
364
    }
365

    
366
    // To run following tests about email: claim notifications, set all the properties inside project folder
367
    @Test
368
    public void forceSendEmailNotifications() throws Exception {
369
        //emailSender.run();
370
    }
371

    
372
    @Test
373
    public void testEmail() throws Exception {
374
        ArrayList<String> list = new ArrayList<String>();
375
        list.add("konstantinagalouni@gmail.com");
376
        list.add("argirok@di.uoa.gr");
377
//        emailSender.send("openaire_id_test", "openaire_name_test", "community", list);
378
    }
379

    
380
}
    (1-1/1)