Project

General

Profile

« Previous | Next » 

Revision 48294

Delete file when claim is deleted and result has no other links| change semantics | change the openaireId generation

View differences:

modules/uoa-claims/trunk/src/test/java/eu/dnetlib/data/claims/migration/parser/ExternalParserTest.java
256 256
        Assert.assertNull(result.getEmbargoEndDate());
257 257

  
258 258
    }
259
    @Test
260
    public void testMD5() throws Exception {
261
        String id = "10.1016/j.engstruct.2013.03.014";
262
        String createdId = ExternalRecordParser.createOpenaireId(id);
263
        String openaireId = "userclaim___::07ec9eb2278a11e352e3fa93a621411d";
264
        Assert.assertEquals(createdId,openaireId);
265

  
266
    }
259 267
}
modules/uoa-claims/trunk/src/main/java/eu/dnetlib/data/claims/migration/Migration.java
351 351
        try {
352 352
            migration.claimHandler.getQueryGenerator().setMigrationTable("claims_view");
353 353
            List<Claim> claims = null;
354
            claims = migration.createContextRelationClaims();
355
//            claims = migration.createRelationsClaims();
354
//            claims = migration.createContextRelationClaims();
355
            claims = migration.createRelationsClaims();
356 356

  
357 357
            migration.printStatistics(claims);
358 358
            migration.saveClaims(claims);
modules/uoa-claims/trunk/src/main/java/eu/dnetlib/data/claims/migration/parser/ExternalRecordParser.java
271 271
        }
272 272
            return result;
273 273
    }
274
    private static String createOpenaireId(String id){
274
    public static String createOpenaireId(String id){
275 275
        System.out.println("createOpenaireId from id:" +id);
276 276
        if(id==null){
277 277
            return null;
......
282 282
            m = MessageDigest.getInstance("MD5");
283 283
            m.update(id.getBytes(),0,id.length());
284 284
            openaireId = new BigInteger(1,m.digest()).toString(16);
285
            while(openaireId.length() < 32 ){
286
                openaireId = "0"+openaireId;
287
            }
285 288
        } catch (NoSuchAlgorithmException e) {
286 289
            logger.error("Couldn't instatiate md5 algorithm",e);
287 290
        }
288
        openaireId ="user:claim__"+openaireId;
291
        openaireId ="userclaim___::"+openaireId;
289 292
        return openaireId;
290 293
    }
291 294

  
modules/uoa-claims/trunk/src/main/java/eu/dnetlib/data/claims/migration/handler/ContextRelationHandler.java
21 21

  
22 22
    public List<ContextRelation> fetchAllConceptRelations() throws Exception, SQLStoreException {
23 23
        List<ContextRelation> relations = null;
24
//          ResultSet rs = sqlDAO.executePreparedQuery(queryGenerator.generateQueryForTesting(-1,"169112"));
25 24
        ResultSet rs = sqlDAO.executePreparedQuery(queryGenerator.generateSelectConceptClaimsEnrichedWithDMFClaimsQuery(-1));
26 25
//        ResultSet rs = sqlDAO.executePreparedQuery(queryGenerator.generateSelectConceptClaimsForLattestClaimsQuery(-1));
27 26

  
modules/uoa-claims/trunk/src/main/java/eu/dnetlib/data/claims/migration/handler/ClaimHandler.java
259 259
            String sourceId =rs.getString(3);
260 260
            String targetType =rs.getString(4);
261 261
            String targetId =rs.getString(5);
262
            this.checkRecordFile(sourceType, sourceId);
263
            this.checkRecordFile(targetType, targetId);
264

  
262 265
            ArrayList<Object> params2 = new ArrayList<>();
263 266
            String query2 = queryGenerator.generateDeleteFullClaimQuery(claimId,user,sourceType,sourceId,targetType,targetId, params2);
264 267
            sqlDAO.executeUpdateQuery(query2, params2);
......
268 271
        rs.close();
269 272
    }
270 273

  
274
    public void checkRecordFile(String type, String id) throws SQLStoreException, SQLException {
275
        if(type.equals("publication") || type.equals("dataset")){
276
            this.resultHandler.deleteRecordFile(type,id);
277
        }
278
    }
271 279
    public boolean deleteClaim(String claimId) throws Exception, SQLStoreException {
272 280

  
273 281
        ArrayList<Object> params = new ArrayList<>();
modules/uoa-claims/trunk/src/main/java/eu/dnetlib/data/claims/migration/handler/ResultHandler.java
3 3
import eu.dnetlib.data.claims.migration.entity.Result;
4 4
import eu.dnetlib.data.claimsDemo.ClaimUtils;
5 5
import eu.dnetlib.data.claimsDemo.QueryGenerator;
6
import eu.dnetlib.data.claimsDemo.SQLStoreException;
6 7
import eu.dnetlib.data.claimsDemo.SqlDAO;
7 8
import org.apache.commons.io.FileUtils;
8 9
import org.apache.log4j.Logger;
9 10

  
10 11
import java.io.File;
11 12
import java.io.IOException;
13
import java.sql.ResultSet;
14
import java.sql.SQLException;
12 15

  
13 16
/**
14 17
 * Created by kiatrop on 5/2/2016.
......
55 58
        return type+"/"+datasource+"/"+openaireId.replace("/","*");
56 59

  
57 60
    }
61
    public void deleteRecordFile(String type, String id) throws SQLStoreException, SQLException {
62
            ResultSet rs = sqlDAO.executePreparedQuery(queryGenerator.generateCountClaimsForResultQuery(id));
63
            if(rs.next()){
64
                Integer count =  rs.getInt(1);
65
                log.debug("Count is:" + count );
66

  
67
                if(count != null && count ==1){
68
                    ResultSet rs1 = sqlDAO.executePreparedQuery(queryGenerator.generateSelectResultSource(id));
69
                    if(rs1.next()){
70
                        String source =  rs1.getString(1);
71

  
72
                        log.debug("source is:" + source );
73
                        String path=createExportPath(type, source, id);
74
                         File file = new File(this.pathToSaveRecord+path);
75
                        log.debug("path is:" + path );
76

  
77

  
78
                        if (file.delete()) {
79
                            log.info(file.getName() + " is deleted!");
80
                        } else {
81
                            log.warn("Delete operation is failed for file "+ this.pathToSaveRecord+path);
82
                        }
83
                    }else{
84
                        log.error("Couldn't get result source for result with id : "+ id );
85

  
86
                    }
87

  
88
                }else{
89
                    log.info("This metadata file cannot be removed (count="+count+") for result with id : "+ id );
90
                }
91
            }else{
92
                log.error("Couldn't fetch claims count for result with id : "+ id );
93
            }
94
    }
95

  
58 96
    public SqlDAO getSqlDAO() {
59 97
        return sqlDAO;
60 98
    }
modules/uoa-claims/trunk/src/main/java/eu/dnetlib/data/claimsDemo/TestClass.java
18 18
import eu.dnetlib.data.claims.migration.entity.Result;
19 19
import eu.dnetlib.data.claims.migration.handler.*;
20 20
import eu.dnetlib.data.claims.migration.parser.DMFParser;
21
import eu.dnetlib.data.claims.migration.parser.ExternalRecordParser;
21 22
import org.apache.log4j.BasicConfigurator;
22 23
import org.apache.log4j.Logger;
23 24
import org.junit.Before;
......
35 36
import javax.xml.parsers.ParserConfigurationException;
36 37
import javax.xml.transform.TransformerException;
37 38
import javax.xml.xpath.XPathExpressionException;
39
import java.io.File;
38 40
import java.io.IOException;
39 41
import java.math.BigInteger;
40 42
import java.security.MessageDigest;
......
194 196
//        String id=claimHandler.buildAndInsertClaim("argirok@di.uoa.gr", "project", "corda_______::2c37878a0cede85dbbd1081bb9b4a2f8", "openaire", "OPEN", null,"dataset", "10.5281/ZENODO.154647", "datacite", "EMBARGO","2017-05-01");
195 197

  
196 198

  
197
        String id=claimHandler.buildAndInsertClaim("argirok@di.uoa.gr", "context", "egi::country::gr",
198
                "openaire", null, null,"dataset", "10.4225/41/55A111BDE741C", "datacite", "OPEN","2017-05-01");
199
//        String id=claimHandler.buildAndInsertClaim("argirok@di.uoa.gr", "context", "egi::country::gr",
200
//                "openaire", null, null,"dataset", "10.4225/41/55A111BDE741C", "datacite", "OPEN","2017-05-01");
199 201
    }
200 202
    @Test
201
    public void testDelete() throws Exception {
203
    public void testDelete() throws Exception, SQLStoreException {
202 204

  
203
//            claimHandler.deleteClaim("argirok@di.uoa.gr","94");
205
//            claimHandler.deleteClaim("argirok@di.uoa.gr","2876");
204 206
//        claimHandler.deleteClaim("argirok@di.uoa.gr","3101");
205 207
        }
206 208

  
......
393 395
        List<String> mails = new ArrayList<String>();
394 396
        mails.add("test11111@mail.com");
395 397
        mails.add("test122222@mail.com");
396
//        this.projectHandler.updateContactEmailsByProjectId("123",mails);
398
        this.projectHandler.updateContactEmailsByProjectId("123",mails);
397 399
//        System.out.println("\n"+this.projectHandler.fetchContactEmailsByProjectId("123")+"\n");
398 400
//        String token = UUID.randomUUID().toString();
399 401
//        this.projectHandler.updateTokenByProjectId("123",token);
......
403 405
    }
404 406
    @Test
405 407
    public void testMD5() throws Exception {
406
        String id = "10.1371/journal.pone.0130756";
407
        MessageDigest m = MessageDigest.getInstance("MD5");
408
        m.update(id.getBytes(), 0, id.length());
409
        id = new BigInteger(1, m.digest()).toString(16);
410
        System.out.println(id);
411
        System.out.println(this.resultHandler.getPathToSaveRecord());
408
        String id = "10.1016/j.engstruct.2013.03.014";
409
        String createdId = ExternalRecordParser.createOpenaireId(id);
410
        String openaireId = "userclaim___::07ec9eb2278a11e352e3fa93a621411d";
411
        System.out.println(createdId );
412 412

  
413 413
    }
414 414
    @Test
415 415
    public void testCuration() throws Exception, SQLStoreException {
416
        boolean updated = claimHandler.updateClaimCurationInfo("argiro@gmail.com","1",true);
417
        System.out.println(updated);
416
//        boolean updated = claimHandler.updateClaimCurationInfo("argiro@gmail.com","1",true);
417
//        System.out.println(updated);
418 418
    }
419 419

  
420 420
    @Test
......
426 426
    @Test
427 427
    public void directIndexClaim() throws Exception {
428 428
        System.out.println(this.claimValidation.getPathToSaveReport());
429
        String json = "{\"originalId\":\"user:claim__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\"]}";
429
        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\"]}";
430 430
//        System.out.println("\n\nFeed Response is: "+directIndexHandler.insertRecord(json));
431 431

  
432
//        System.out.println("\n\nDelete Response is: "+directIndexHandler.deleteRecord("user:claim__d1e668dc81fa714aa98a558d9ce515fa","openaire____::crossref"));
432
//        System.out.println("\n\nDelete Response is: "+directIndexHandler.deleteRecord("userclaim___::d1e668dc81fa714aa98a558d9ce515fa","openaire____::crossref"));
433 433
    }
434 434

  
435 435
}
modules/uoa-claims/trunk/src/main/java/eu/dnetlib/data/claimsDemo/QueryGenerator.java
318 318
     */
319 319
    private String createSemanticsType(String sourceType,String targetType){
320 320
        String semantics=null;
321
        if((targetType.equals(ClaimUtils.PUBLICATION)||targetType.equals(ClaimUtils.DATASET))&&(sourceType.equals(ClaimUtils.PUBLICATION)||sourceType.equals(ClaimUtils.DATASET))){
322
            semantics="resultResult_"+targetType+sourceType+"_isRelatedTo";
321
        if((targetType.equals(ClaimUtils.PUBLICATION))&&(sourceType.equals(ClaimUtils.DATASET))){
322
            semantics="resultResult_publicationDataset_isRelatedTo";
323 323
        }
324
        else if(targetType.equals(ClaimUtils.DATASET)&&sourceType.equals(ClaimUtils.PUBLICATION)){
325
            semantics="resultResult_publicationDataset_isRelatedTo";
326
        }
327
        else  if((targetType.equals(ClaimUtils.PUBLICATION))&&(sourceType.equals(ClaimUtils.PUBLICATION))){
328
            semantics="resultResult_supplement_isSupplementedBy";
329
        }
330
        else if(targetType.equals(ClaimUtils.DATASET)&&sourceType.equals(ClaimUtils.DATASET)){
331
            semantics="resultResult_supplement_isSupplementTo";
332
        }
324 333
        else if((targetType.equals(ClaimUtils.PUBLICATION)||targetType.equals(ClaimUtils.DATASET))&&(sourceType.equals(ClaimUtils.PROJECT))){
325 334
            semantics= "resultProject_outcome_produces";  //"resultProject_outcome_isProducedBy";
326 335
        }
......
446 455
                "        curated_by text,\n" +
447 456
                "        approved boolean DEFAULT TRUE,\n" +
448 457
                "        claim_status varchar(30),\n" +
449
                "        semantics varchar(60)\n" +
458
                "        semantics varchar(60) NOT NULL\n" +
450 459
                ");\n" +
451 460
                "\n" +
452 461
                "CREATE TABLE has_source_context(\n" +
......
939 948
        return query;
940 949
    }
941 950

  
951
    public String  generateCountClaimsForResultQuery(String resultId){
952
        return " Select count(*) from claim where source_id = '"+ resultId +"' or target_id = '"+resultId+"' ";
953
    }
954
    public String  generateSelectResultSource(String resultId){
955
        return " Select collected_from from result where openaire_id = '"+ resultId +"' ";
956
    }
957

  
942 958
    /**
943 959
     * Select form a has_source_* or has_target_* table
944 960
     * ...
......
985 1001
        String query =" ";
986 1002
        return " Select id, source_type, source_id, target_type, target_id from claim where id = ?::int and claimedBy = ? ";
987 1003
    }
1004

  
988 1005
    public String  generateSelectClaimQuery(String id, ArrayList<Object> params){
989 1006

  
990 1007
        params.add(id);
modules/uoa-claims/trunk/src/main/resources/eu/dnetlib/data/claims/migration/springContext-claimsDemo.properties
1 1

  
2 2
services.claimsDemo.db.driverClassName = org.postgresql.Driver
3
services.claimsDemo.db.url = jdbc:postgresql://scoobydoo.di.uoa.gr:5432/claimsnewschema
4
services.claimsDemo.db.username = invalid_username
5
services.claimsDemo.db.password = invalid_password
3
services.claimsDemo.db.url = jdbc:postgresql://scoobydoo.di.uoa.gr:5432/claims_beta_last
4
services.claimsDemo.db.username = postgres
5
services.claimsDemo.db.password = snowflakes
6 6
services.claimsDemo.directClaim.APIURL = http://beta.services.openaire.eu:8280/is/mvc/api/publications
7 7

  
8 8
#email properties
......
14 14
services.claims.mail.angularUrl = http://duffy.di.uoa.gr:3000/claims-project-manager?token=
15 15
services.claims.mail.specialRecipients = invalid_recipient@email.com
16 16

  
17
services.claimsDemo.results.pathToSaveRecord = /home/argirok/claims/records/
18
services.claimsDemo.reports.pathToSaveReport = /home/argirok/claims/reports/
17
services.claimsDemo.results.pathToSaveRecord = /home/argirok/claims_beta/records/
18
services.claimsDemo.reports.pathToSaveReport = /home/argirok/claims_beta/reports/

Also available in: Unified diff